From 0d5fc17cabc982acca121d7cb9e480d70ff4386b Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 10 Feb 2022 09:26:38 +0100 Subject: [PATCH] deal with entry points [skip ci] --- packages/jest-circus/package.json | 2 +- .../jest-circus/{runner.js => src/runner.ts} | 5 +-- packages/pretty-format/package.json | 2 +- packages/pretty-format/src/ConvertAnsi.ts | 8 +++++ scripts/buildUtils.js | 34 ++++++++++++++++--- 5 files changed, 42 insertions(+), 9 deletions(-) rename packages/jest-circus/{runner.js => src/runner.ts} (71%) create mode 100644 packages/pretty-format/src/ConvertAnsi.ts diff --git a/packages/jest-circus/package.json b/packages/jest-circus/package.json index 2af0ca3d196b..9e83af3945e5 100644 --- a/packages/jest-circus/package.json +++ b/packages/jest-circus/package.json @@ -15,7 +15,7 @@ "default": "./build/index.js" }, "./package.json": "./package.json", - "./runner": "./runner.js" + "./runner": "./build/runner.js" }, "dependencies": { "@jest/environment": "^28.0.0-alpha.8", diff --git a/packages/jest-circus/runner.js b/packages/jest-circus/src/runner.ts similarity index 71% rename from packages/jest-circus/runner.js rename to packages/jest-circus/src/runner.ts index f61fd88826c7..26cdf3d29f9e 100644 --- a/packages/jest-circus/runner.js +++ b/packages/jest-circus/src/runner.ts @@ -6,5 +6,6 @@ */ // Allow people to use `jest-circus/runner` as a runner. -const runner = require('./build/legacy-code-todo-rewrite/jestAdapter').default; -module.exports = runner; +import runner from './legacy-code-todo-rewrite/jestAdapter'; + +export default runner; diff --git a/packages/pretty-format/package.json b/packages/pretty-format/package.json index 2d40b5cf389a..43c765ac5e40 100644 --- a/packages/pretty-format/package.json +++ b/packages/pretty-format/package.json @@ -16,7 +16,7 @@ "default": "./build/index.js" }, "./package.json": "./package.json", - "./ConvertAnsi": "./build/plugins/ConvertAnsi.js" + "./ConvertAnsi": "./build/ConvertAnsi.js" }, "author": "James Kyle ", "dependencies": { diff --git a/packages/pretty-format/src/ConvertAnsi.ts b/packages/pretty-format/src/ConvertAnsi.ts new file mode 100644 index 000000000000..b3647fab9957 --- /dev/null +++ b/packages/pretty-format/src/ConvertAnsi.ts @@ -0,0 +1,8 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +export {test, serialize} from './plugins/ConvertAnsi'; diff --git a/scripts/buildUtils.js b/scripts/buildUtils.js index 5e74094f225b..5cd66661c706 100644 --- a/scripts/buildUtils.js +++ b/scripts/buildUtils.js @@ -62,12 +62,12 @@ function getPackages() { Object.assign(mem, {[curr.replace(/\.js$/, '')]: curr}), {}, ), - ...(pkg.name === 'jest-circus' ? {'./runner': './runner.js'} : {}), + ...(pkg.name === 'jest-circus' ? {'./runner': './build/runner.js'} : {}), ...(pkg.name === 'expect' ? {'./build/matchers': './build/matchers.js'} : {}), ...(pkg.name === 'pretty-format' - ? {'./ConvertAnsi': './build/plugins/ConvertAnsi.js'} + ? {'./ConvertAnsi': './build/ConvertAnsi.js'} : {}), }, `Package "${pkg.name}" does not export correct files`, @@ -163,7 +163,7 @@ function createWebpackConfigs() { }); } - const extraEntries = + const workerEntriesEntries = pkg.name === 'jest-worker' ? { processChild: path.resolve( @@ -183,6 +183,29 @@ function createWebpackConfigs() { ? {testWorker: path.resolve(packageDir, './src/testWorker.ts')} : {}; + const extraEntryPoints = + // skip expect for now + pkg.name === 'expect' + ? {} + : Object.keys(pkg.exports) + .filter( + key => + key !== '.' && + key !== './package.json' && + !key.startsWith('./bin'), + ) + .reduce((previousValue, currentValue) => { + return { + ...previousValue, + // skip `./` + [currentValue.slice(2)]: path.resolve( + packageDir, + './src', + `${currentValue}.ts`, + ), + }; + }, {}); + return { packageDir, pkg, @@ -190,7 +213,8 @@ function createWebpackConfigs() { devtool: false, entry: { index: input, - ...extraEntries, + ...workerEntriesEntries, + ...extraEntryPoints, }, externals: nodeExternals(), mode: 'production', @@ -212,7 +236,7 @@ function createWebpackConfigs() { }, path: path.resolve(packageDir, 'build'), }, - plugins: [new IgnoreDynamicRequire(extraEntries)], + plugins: [new IgnoreDynamicRequire(workerEntriesEntries)], resolve: { extensions: ['.ts', '.js'], },