Skip to content

Commit 610191f

Browse files
committed
ensure vm-secific chunks are separate
1 parent 0666f8d commit 610191f

File tree

3 files changed

+65
-36
lines changed

3 files changed

+65
-36
lines changed

packages/jest-jasmine2/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export default async function jasmine2(
125125

126126
runtime
127127
.requireInternalModule<typeof import('./jestExpect')>(
128-
path.resolve(__dirname, './jestExpect.js'),
128+
require.resolve('./jestExpect.js'),
129129
)
130130
.default({expand: globalConfig.expand});
131131

@@ -146,7 +146,7 @@ export default async function jasmine2(
146146

147147
const snapshotState: SnapshotState = await runtime
148148
.requireInternalModule<typeof import('./setup_jest_globals')>(
149-
path.resolve(__dirname, './setup_jest_globals.js'),
149+
require.resolve('./setup_jest_globals.js'),
150150
)
151151
.default({
152152
config,

scripts/buildUtils.mjs

+62-24
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import chalk from 'chalk';
1313
import fs from 'graceful-fs';
1414
import {sync as readPkg} from 'read-pkg';
1515
import stringLength from 'string-length';
16+
import webpack from 'webpack';
1617
import nodeExternals from 'webpack-node-externals';
1718
import babelConfig from '../babel.config.js';
1819

@@ -67,7 +68,9 @@ export function getPackages() {
6768
Object.assign(mem, {[curr.replace(/\.js$/, '')]: curr}),
6869
{},
6970
),
70-
...(pkg.name === 'jest-circus' ? {'./runner': './build/runner.js'} : {}),
71+
...(pkg.name === 'jest-circus'
72+
? {'./runner': './build/runner.js'}
73+
: {}),
7174
...(pkg.name === 'expect'
7275
? {'./build/matchers': './build/matchers.js'}
7376
: {}),
@@ -127,6 +130,15 @@ export function adjustToTerminalWidth(str) {
127130
export const INLINE_REQUIRE_EXCLUDE_LIST =
128131
/packages\/expect|(jest-(circus|diff|get-type|jasmine2|matcher-utils|message-util|regex-util|snapshot))|pretty-format\//;
129132

133+
export const copyrightSnippet = `
134+
/**
135+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
136+
*
137+
* This source code is licensed under the MIT license found in the
138+
* LICENSE file in the root directory of this source tree.
139+
*/
140+
`.trim();
141+
130142
export function createWebpackConfigs() {
131143
const packages = getPackages();
132144

@@ -159,7 +171,7 @@ export function createWebpackConfigs() {
159171
});
160172
}
161173

162-
const workerEntriesEntries =
174+
const separateChunks =
163175
pkg.name === 'jest-worker'
164176
? {
165177
processChild: path.resolve(
@@ -177,6 +189,27 @@ export function createWebpackConfigs() {
177189
? {CoverageWorker: path.resolve(packageDir, './src/CoverageWorker.ts')}
178190
: pkg.name === 'jest-runner'
179191
? {testWorker: path.resolve(packageDir, './src/testWorker.ts')}
192+
: pkg.name === 'jest-circus'
193+
? {
194+
jestAdapterInit: path.resolve(
195+
packageDir,
196+
'./src/legacy-code-todo-rewrite/jestAdapterInit.ts',
197+
),
198+
}
199+
: pkg.name === 'jest-jasmine2'
200+
? {
201+
'jasmine/jasmineLight': path.resolve(
202+
packageDir,
203+
'./src/jasmine/jasmineLight.ts',
204+
),
205+
jestExpect: path.resolve(packageDir, './src/jestExpect.ts'),
206+
setup_jest_globals: path.resolve(
207+
packageDir,
208+
'./src/setup_jest_globals.ts',
209+
),
210+
}
211+
: pkg.name === 'jest-repl'
212+
? {repl: path.resolve(packageDir, './src/cli/repl.ts')}
180213
: {};
181214

182215
const extraEntryPoints =
@@ -206,10 +239,11 @@ export function createWebpackConfigs() {
206239
packageDir,
207240
pkg,
208241
webpackConfig: {
242+
context: packageDir,
209243
devtool: false,
210244
entry: {
211245
index: input,
212-
...workerEntriesEntries,
246+
...separateChunks,
213247
...extraEntryPoints,
214248
},
215249
externals: nodeExternals(),
@@ -225,14 +259,20 @@ export function createWebpackConfigs() {
225259
},
226260
],
227261
},
262+
optimization: {
263+
moduleIds: 'named',
264+
},
228265
output: {
229266
filename: '[name].js',
230267
library: {
231268
type: 'commonjs2',
232269
},
233270
path: path.resolve(packageDir, 'build'),
234271
},
235-
plugins: [new IgnoreDynamicRequire(workerEntriesEntries)],
272+
plugins: [
273+
new webpack.BannerPlugin(copyrightSnippet),
274+
new IgnoreDynamicRequire(separateChunks),
275+
],
236276
resolve: {
237277
extensions: ['.ts', '.js'],
238278
},
@@ -256,30 +296,28 @@ class IgnoreDynamicRequire {
256296
.for('javascript/auto')
257297
.tap('IgnoreDynamicRequire', parser => {
258298
// This is a SyncBailHook, so returning anything stops the parser, and nothing (undefined) allows to continue
259-
const ignoreRequireCallExpression = expression => {
260-
if (expression.arguments.length === 0) {
261-
return undefined;
262-
}
263-
const arg = parser.evaluateExpression(expression.arguments[0]);
264-
if (arg.isString() && !arg.string.startsWith('.')) {
265-
return true;
266-
}
267-
if (!arg.isString() && !arg.isConditional()) {
268-
return true;
269-
}
270-
271-
if (arg.isString() && this.separateFiles.has(arg.string)) {
272-
return true;
273-
}
274-
return undefined;
275-
};
276-
277299
parser.hooks.call
278300
.for('require')
279-
.tap('IgnoreDynamicRequire', ignoreRequireCallExpression);
301+
.tap('IgnoreDynamicRequire', expression => {
302+
if (expression.arguments.length === 0) {
303+
return undefined;
304+
}
305+
const arg = parser.evaluateExpression(expression.arguments[0]);
306+
if (arg.isString() && !arg.string.startsWith('.')) {
307+
return true;
308+
}
309+
if (!arg.isString() && !arg.isConditional()) {
310+
return true;
311+
}
312+
313+
if (arg.isString() && this.separateFiles.has(arg.string)) {
314+
return true;
315+
}
316+
return undefined;
317+
});
280318
parser.hooks.call
281319
.for('require.resolve')
282-
.tap('IgnoreDynamicRequire', ignoreRequireCallExpression);
320+
.tap('IgnoreDynamicRequire', () => true);
283321
});
284322
});
285323
}

scripts/bundleTs.mjs

+1-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import fs from 'graceful-fs';
1818
import {sync as pkgDir} from 'pkg-dir';
1919
import prettier from 'prettier';
2020
import rimraf from 'rimraf';
21-
import {getPackages} from './buildUtils.mjs';
21+
import {copyrightSnippet, getPackages} from './buildUtils.mjs';
2222

2323
const prettierConfig = prettier.resolveConfig.sync(
2424
fileURLToPath(import.meta.url).replace(/\.js$/, '.d.ts'),
@@ -27,15 +27,6 @@ const prettierConfig = prettier.resolveConfig.sync(
2727
const require = createRequire(import.meta.url);
2828
const typescriptCompilerFolder = pkgDir(require.resolve('typescript'));
2929

30-
const copyrightSnippet = `
31-
/**
32-
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
33-
*
34-
* This source code is licensed under the MIT license found in the
35-
* LICENSE file in the root directory of this source tree.
36-
*/
37-
`.trim();
38-
3930
const typesNodeReferenceDirective = '/// <reference types="node" />';
4031

4132
const excludedPackages = new Set(['@jest/globals']);

0 commit comments

Comments
 (0)