Skip to content

Commit de5718b

Browse files
committed
ensure vm-secific chunks are separate
1 parent 0d5fc17 commit de5718b

File tree

3 files changed

+67
-36
lines changed

3 files changed

+67
-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.js

+64-24
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const path = require('path');
1313
const chalk = require('chalk');
1414
const {sync: readPkg} = require('read-pkg');
1515
const stringLength = require('string-length');
16+
const webpack = require('webpack');
1617
const nodeExternals = require('webpack-node-externals');
1718
const rootPackage = require('../package.json');
1819

@@ -62,7 +63,9 @@ function getPackages() {
6263
Object.assign(mem, {[curr.replace(/\.js$/, '')]: curr}),
6364
{},
6465
),
65-
...(pkg.name === 'jest-circus' ? {'./runner': './build/runner.js'} : {}),
66+
...(pkg.name === 'jest-circus'
67+
? {'./runner': './build/runner.js'}
68+
: {}),
6669
...(pkg.name === 'expect'
6770
? {'./build/matchers': './build/matchers.js'}
6871
: {}),
@@ -130,6 +133,17 @@ module.exports.PACKAGES_DIR = PACKAGES_DIR;
130133

131134
module.exports.INLINE_REQUIRE_EXCLUDE_LIST = INLINE_REQUIRE_EXCLUDE_LIST;
132135

136+
const copyrightSnippet = `
137+
/**
138+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
139+
*
140+
* This source code is licensed under the MIT license found in the
141+
* LICENSE file in the root directory of this source tree.
142+
*/
143+
`.trim();
144+
145+
module.exports.copyrightSnippet = copyrightSnippet;
146+
133147
function createWebpackConfigs() {
134148
const babelConfig = require('../babel.config.js');
135149
const packages = getPackages();
@@ -163,7 +177,7 @@ function createWebpackConfigs() {
163177
});
164178
}
165179

166-
const workerEntriesEntries =
180+
const separateChunks =
167181
pkg.name === 'jest-worker'
168182
? {
169183
processChild: path.resolve(
@@ -181,6 +195,27 @@ function createWebpackConfigs() {
181195
? {CoverageWorker: path.resolve(packageDir, './src/CoverageWorker.ts')}
182196
: pkg.name === 'jest-runner'
183197
? {testWorker: path.resolve(packageDir, './src/testWorker.ts')}
198+
: pkg.name === 'jest-circus'
199+
? {
200+
jestAdapterInit: path.resolve(
201+
packageDir,
202+
'./src/legacy-code-todo-rewrite/jestAdapterInit.ts',
203+
),
204+
}
205+
: pkg.name === 'jest-jasmine2'
206+
? {
207+
'jasmine/jasmineLight': path.resolve(
208+
packageDir,
209+
'./src/jasmine/jasmineLight.ts',
210+
),
211+
jestExpect: path.resolve(packageDir, './src/jestExpect.ts'),
212+
setup_jest_globals: path.resolve(
213+
packageDir,
214+
'./src/setup_jest_globals.ts',
215+
),
216+
}
217+
: pkg.name === 'jest-repl'
218+
? {repl: path.resolve(packageDir, './src/cli/repl.ts')}
184219
: {};
185220

186221
const extraEntryPoints =
@@ -210,10 +245,11 @@ function createWebpackConfigs() {
210245
packageDir,
211246
pkg,
212247
webpackConfig: {
248+
context: packageDir,
213249
devtool: false,
214250
entry: {
215251
index: input,
216-
...workerEntriesEntries,
252+
...separateChunks,
217253
...extraEntryPoints,
218254
},
219255
externals: nodeExternals(),
@@ -229,14 +265,20 @@ function createWebpackConfigs() {
229265
},
230266
],
231267
},
268+
optimization: {
269+
moduleIds: 'named',
270+
},
232271
output: {
233272
filename: '[name].js',
234273
library: {
235274
type: 'commonjs2',
236275
},
237276
path: path.resolve(packageDir, 'build'),
238277
},
239-
plugins: [new IgnoreDynamicRequire(workerEntriesEntries)],
278+
plugins: [
279+
new webpack.BannerPlugin(copyrightSnippet),
280+
new IgnoreDynamicRequire(separateChunks),
281+
],
240282
resolve: {
241283
extensions: ['.ts', '.js'],
242284
},
@@ -260,30 +302,28 @@ class IgnoreDynamicRequire {
260302
.for('javascript/auto')
261303
.tap('IgnoreDynamicRequire', parser => {
262304
// This is a SyncBailHook, so returning anything stops the parser, and nothing (undefined) allows to continue
263-
const ignoreRequireCallExpression = expression => {
264-
if (expression.arguments.length === 0) {
265-
return undefined;
266-
}
267-
const arg = parser.evaluateExpression(expression.arguments[0]);
268-
if (arg.isString() && !arg.string.startsWith('.')) {
269-
return true;
270-
}
271-
if (!arg.isString() && !arg.isConditional()) {
272-
return true;
273-
}
274-
275-
if (arg.isString() && this.separateFiles.has(arg.string)) {
276-
return true;
277-
}
278-
return undefined;
279-
};
280-
281305
parser.hooks.call
282306
.for('require')
283-
.tap('IgnoreDynamicRequire', ignoreRequireCallExpression);
307+
.tap('IgnoreDynamicRequire', expression => {
308+
if (expression.arguments.length === 0) {
309+
return undefined;
310+
}
311+
const arg = parser.evaluateExpression(expression.arguments[0]);
312+
if (arg.isString() && !arg.string.startsWith('.')) {
313+
return true;
314+
}
315+
if (!arg.isString() && !arg.isConditional()) {
316+
return true;
317+
}
318+
319+
if (arg.isString() && this.separateFiles.has(arg.string)) {
320+
return true;
321+
}
322+
return undefined;
323+
});
284324
parser.hooks.call
285325
.for('require.resolve')
286-
.tap('IgnoreDynamicRequire', ignoreRequireCallExpression);
326+
.tap('IgnoreDynamicRequire', () => true);
287327
});
288328
});
289329
}

scripts/bundleTs.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,14 @@ const chalk = require('chalk');
1818
const {sync: pkgDir} = require('pkg-dir');
1919
const prettier = require('prettier');
2020
const rimraf = require('rimraf');
21-
const {getPackages} = require('./buildUtils');
21+
const {copyrightSnippet, getPackages} = require('./buildUtils');
2222

2323
const prettierConfig = prettier.resolveConfig.sync(
2424
__filename.replace(/\.js$/, '.d.ts'),
2525
);
2626

2727
const typescriptCompilerFolder = pkgDir(require.resolve('typescript'));
2828

29-
const copyrightSnippet = `
30-
/**
31-
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
32-
*
33-
* This source code is licensed under the MIT license found in the
34-
* LICENSE file in the root directory of this source tree.
35-
*/
36-
`.trim();
37-
3829
(async () => {
3930
const packages = getPackages();
4031

0 commit comments

Comments
 (0)