@@ -13,6 +13,7 @@ import chalk from 'chalk';
1313import fs from 'graceful-fs' ;
1414import { sync as readPkg } from 'read-pkg' ;
1515import stringLength from 'string-length' ;
16+ import webpack from 'webpack' ;
1617import nodeExternals from 'webpack-node-externals' ;
1718import babelConfig from '../babel.config.js' ;
1819
@@ -67,7 +68,9 @@ export function getPackages() {
6768 Object . assign ( mem , { [ curr . replace ( / \. j s $ / , '' ) ] : 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) {
127130export const INLINE_REQUIRE_EXCLUDE_LIST =
128131 / p a c k a g e s \/ e x p e c t | ( j e s t - ( c i r c u s | d i f f | g e t - t y p e | j a s m i n e 2 | m a t c h e r - u t i l s | m e s s a g e - u t i l | r e g e x - u t i l | s n a p s h o t ) ) | p r e t t y - f o r m a t \/ / ;
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+
130142export 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 }
0 commit comments