diff --git a/.changeset/chilly-maps-care.md b/.changeset/chilly-maps-care.md new file mode 100644 index 000000000..303c5f655 --- /dev/null +++ b/.changeset/chilly-maps-care.md @@ -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 diff --git a/.changeset/moody-dodos-rescue.md b/.changeset/moody-dodos-rescue.md new file mode 100644 index 000000000..da40719d7 --- /dev/null +++ b/.changeset/moody-dodos-rescue.md @@ -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 diff --git a/docs/docs/testing.md b/docs/docs/testing.md index a12da4e8c..e618af0b2 100644 --- a/docs/docs/testing.md +++ b/docs/docs/testing.md @@ -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, }; ``` diff --git a/fixtures/jest-test/jest.config.js b/fixtures/jest-test/jest.config.js index 6d5c038d8..aa28edea2 100644 --- a/fixtures/jest-test/jest.config.js +++ b/fixtures/jest-test/jest.config.js @@ -1,4 +1,6 @@ +const { preset } = require('sku/config/jest'); + /** @type {import('jest').Config} */ module.exports = { - preset: 'sku/config/jest', + preset, }; diff --git a/packages/sku/config/jest/index.d.ts b/packages/sku/config/jest/index.d.ts new file mode 100644 index 000000000..22d0ff1f6 --- /dev/null +++ b/packages/sku/config/jest/index.d.ts @@ -0,0 +1 @@ +export const preset: string; diff --git a/packages/sku/config/jest/index.js b/packages/sku/config/jest/index.js new file mode 100644 index 000000000..2afc9a421 --- /dev/null +++ b/packages/sku/config/jest/index.js @@ -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, +}; diff --git a/packages/sku/package.json b/packages/sku/package.json index d4a57613d..ca1766b3f 100644 --- a/packages/sku/package.json +++ b/packages/sku/package.json @@ -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", diff --git a/packages/sku/scripts/test.js b/packages/sku/scripts/test.js index e08abf912..1b7e65688 100644 --- a/packages/sku/scripts/test.js +++ b/packages/sku/scripts/test.js @@ -1,4 +1,3 @@ -const path = require('node:path'); const debug = require('debug'); const jest = require('jest'); @@ -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'); diff --git a/packages/sku/webpack-plugin.js b/packages/sku/webpack-plugin.js deleted file mode 100644 index b610b2ab6..000000000 --- a/packages/sku/webpack-plugin.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./config/webpack/plugins/sku-webpack-plugin'); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 15bb702c7..640497fec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -854,9 +854,6 @@ importers: serve-handler: specifier: ^6.1.3 version: 6.1.5 - sku: - specifier: workspace:* - version: link:../packages/sku wait-on: specifier: ^7.0.0 version: 7.2.0(debug@4.3.5) diff --git a/test-utils/package.json b/test-utils/package.json index e2a57c6d3..5bd9224c1 100644 --- a/test-utils/package.json +++ b/test-utils/package.json @@ -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" }, diff --git a/test-utils/process.ts b/test-utils/process.ts index 0b1db72a3..148b1863c 100644 --- a/test-utils/process.ts +++ b/test-utils/process.ts @@ -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,