@@ -13,6 +13,7 @@ const path = require('path');
1313const chalk = require ( 'chalk' ) ;
1414const { sync : readPkg } = require ( 'read-pkg' ) ;
1515const stringLength = require ( 'string-length' ) ;
16+ const webpack = require ( 'webpack' ) ;
1617const nodeExternals = require ( 'webpack-node-externals' ) ;
1718const rootPackage = require ( '../package.json' ) ;
1819
@@ -62,7 +63,9 @@ function getPackages() {
6263 Object . assign ( mem , { [ curr . replace ( / \. j s $ / , '' ) ] : 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
131134module . 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+
133147function 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 }
0 commit comments