Skip to content

Commit

Permalink
sku v13: Explicitly define entrypoints via package.json#exports (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis authored Jul 5, 2024
1 parent 6cf6299 commit 5dba39d
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 18 deletions.
24 changes: 24 additions & 0 deletions .changeset/chilly-maps-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'sku': major
---

Export jest preset path

**BREAKING CHANGE**:

The jest preset is now accessible via a relative path rather than pointing to a module. This may affect users that require a jest config for debugging tests in their CLI. See the [testing documentation] for more information.

**MIGRATION GUIDE**:

```diff
// jest.config.js
+ const { preset } = require('sku/config/jest');

/** @type {import('jest').Config} */
module.exports = {
- preset: 'sku/config/jest',
+ preset,
};
```

[testing documentation]: https://seek-oss.github.io/sku/#/./docs/testing
11 changes: 11 additions & 0 deletions .changeset/moody-dodos-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'sku': major
---

Add explicit package exports

**BREAKING CHANGE**:

Importing from arbitrary subpaths within `sku` is no longer possible. See the [API documentation] for a comprehensive list of `sku`'s API entrypoints.

[API documentation]: https://seek-oss.github.io/sku/#/./docs/api
6 changes: 4 additions & 2 deletions docs/docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ For example, if you're using [React Testing Library](https://testing-library.com
import '@testing-library/jest-dom';
```

sku's Jest configuration can also be used as a [preset](https://jestjs.io/docs/configuration#preset-string), by specifying the `sku/config/jest` preset in your `jest.config.js`:
sku's Jest configuration can also be used as a [preset](https://jestjs.io/docs/configuration#preset-string):

```js
const { preset } = require('sku/config/jest');

/** @type {import('jest').Config} */
module.exports = {
preset: 'sku/config/jest',
preset,
};
```

Expand Down
4 changes: 3 additions & 1 deletion fixtures/jest-test/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { preset } = require('sku/config/jest');

/** @type {import('jest').Config} */
module.exports = {
preset: 'sku/config/jest',
preset,
};
1 change: 1 addition & 0 deletions packages/sku/config/jest/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const preset: string;
8 changes: 8 additions & 0 deletions packages/sku/config/jest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-check

// Relative preset paths must start with `./` or jest complains
const preset = './node_modules/sku/config/jest/jest-preset.js';

module.exports = {
preset,
};
17 changes: 15 additions & 2 deletions packages/sku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@
"name": "sku",
"version": "12.8.1",
"description": "Front-end development toolkit, powered by Webpack, Babel, CSS Modules, Less and Jest",
"main": "index.js",
"types": "./sku-types.d.ts",
"bin": {
"sku": "./bin/sku.js"
},
"exports": {
".": {
"types": "./sku-types.d.ts"
},
"./config/jest": {
"default": "./config/jest/index.js",
"types": "./config/jest/index.d.ts"
},
"./config/storybook": "./config/storybook/index.js",
"./@loadable/component": "./@loadable/component/index.ts",
"./@storybook/react": "./@storybook/react/index.ts",
"./webpack-plugin": "./config/webpack/plugins/sku-webpack-plugin/index.js",
"./package.json": "./package.json"
},
"engines": {
"node": ">=18.12"
},
"scripts": {
"postinstall": "node ./scripts/postinstall.js"
},
"types": "./sku-types.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/seek-oss/sku.git",
Expand Down
9 changes: 3 additions & 6 deletions packages/sku/scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('node:path');
const debug = require('debug');
const jest = require('jest');

Expand All @@ -7,19 +6,17 @@ const { argv, watch } = require('../config/args');
const { runVocabCompile } = require('../lib/runVocab');

const log = debug('sku:jest');
// https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#configuring-your-testing-environment
process.env.IS_REACT_ACT_ENVIRONMENT = true;

(async () => {
await runVocabCompile();

// https://jestjs.io/docs/configuration#preset-string
const jestPreset = require.resolve('../config/jest/jest-preset');
log(`Using Jest preset at ${jestPreset}`);
const { preset } = require('../config/jest');
log(`Using Jest preset at ${preset}`);

const jestArgv = [...argv];

jestArgv.push('--preset', path.dirname(jestPreset));
jestArgv.push('--preset', preset);

if (isCI) {
jestArgv.push('--ci');
Expand Down
1 change: 0 additions & 1 deletion packages/sku/webpack-plugin.js

This file was deleted.

3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"node-dir": "^0.1.17",
"prettier": "^2.8.8",
"serve-handler": "^6.1.3",
"sku": "workspace:*",
"wait-on": "^7.0.0",
"webpack-stats-plugin": "^1.0.3"
},
Expand Down
4 changes: 2 additions & 2 deletions test-utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
type ChildProcess,
type ExecFileOptions,
} from 'node:child_process';
import gracefulSpawn from 'sku/lib/gracefulSpawn';
import gracefulSpawn from '../packages/sku/lib/gracefulSpawn.js';

const execFile = promisify(_execFile);
const skuBin = require.resolve('sku/bin/sku.js');
const skuBin = require.resolve('../packages/sku/bin/sku.js');

export const run = async (
file: string,
Expand Down

0 comments on commit 5dba39d

Please sign in to comment.