From bf097f1d0fdddd56644ea5a988aadcb1bbf025d2 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 4 Nov 2021 20:09:37 -0500 Subject: [PATCH] Update resolving for node_modules trace pass (#30985) * Update resolving for node_modules trace pass * Update test --- .../webpack/plugins/next-trace-entrypoints-plugin.ts | 11 ++--------- run-tests.js | 4 +--- test/e2e/prerender-native-module.test.ts | 3 +++ test/e2e/prerender.test.ts | 5 +++++ test/integration/jsconfig-baseurl/test/index.test.js | 6 ++++++ test/integration/jsconfig-paths/test/index.test.js | 6 ++++++ test/integration/production/test/index.test.js | 12 ++++++------ 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts b/packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts index b87eceac0d460..88e59a4ca03fc 100644 --- a/packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts +++ b/packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts @@ -114,8 +114,7 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance { assets: any, span: Span, readlink: any, - stat: any, - doResolve: any + stat: any ) { const outputPath = compilation.outputOptions.path @@ -173,11 +172,6 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance { }, readlink, stat, - resolve: doResolve - ? (id, parent, job, isCjs) => { - return doResolve(id, parent, job, !isCjs) - } - : undefined, ignore: [...TRACE_IGNORES, ...this.excludeFiles], mixedModules: true, }) @@ -455,8 +449,7 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance { assets, traceEntrypointsPluginSpan, readlink, - stat, - doResolve + stat ) .then(() => callback()) .catch((err) => callback(err)) diff --git a/run-tests.js b/run-tests.js index f29744997bba9..c73651fe8781b 100644 --- a/run-tests.js +++ b/run-tests.js @@ -250,11 +250,9 @@ async function main() { ...process.env, // run tests in headless mode by default HEADLESS: 'true', + TRACE_PLAYWRIGHT: 'true', ...(isFinalRun ? { - // only trace on final run as previous traces - // are removed anyways - TRACE_PLAYWRIGHT: 'true', // Events can be finicky in CI. This switches to a more // reliable polling method. // CHOKIDAR_USEPOLLING: 'true', diff --git a/test/e2e/prerender-native-module.test.ts b/test/e2e/prerender-native-module.test.ts index 512e0f0143218..c23b1d2d05cd0 100644 --- a/test/e2e/prerender-native-module.test.ts +++ b/test/e2e/prerender-native-module.test.ts @@ -84,6 +84,9 @@ describe('prerender native module', () => { /node_modules\/sqlite3\/.*?\.js/, /node_modules\/sqlite3\/.*?\.node/, /node_modules\/sqlite\/.*?\.js/, + /node_modules\/next/, + /next\/router\.js/, + /next\/dist\/client\/router\.js/, /\/data\.sqlite/, ], notTests: [], diff --git a/test/e2e/prerender.test.ts b/test/e2e/prerender.test.ts index d3daf8e4759a2..9e82de16ddf2e 100644 --- a/test/e2e/prerender.test.ts +++ b/test/e2e/prerender.test.ts @@ -1832,6 +1832,7 @@ describe('Prerender', () => { /node_modules\/react\/index\.js/, /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, + /node_modules\/next/, ], notTests: [], }, @@ -1843,6 +1844,7 @@ describe('Prerender', () => { /node_modules\/react\/index\.js/, /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, + /node_modules\/next/, /\/world.txt/, ], notTests: [ @@ -1858,6 +1860,9 @@ describe('Prerender', () => { /node_modules\/react\/index\.js/, /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, + /node_modules\/next/, + /next\/router\.js/, + /next\/dist\/client\/router\.js/, /node_modules\/@firebase\/firestore\/.*?\.js/, ], notTests: [/\/world.txt/], diff --git a/test/integration/jsconfig-baseurl/test/index.test.js b/test/integration/jsconfig-baseurl/test/index.test.js index 64740b6c1fdaf..dfa84094b6b7f 100644 --- a/test/integration/jsconfig-baseurl/test/index.test.js +++ b/test/integration/jsconfig-baseurl/test/index.test.js @@ -71,6 +71,12 @@ describe('TypeScript Features', () => { const helloTrace = await fs.readJSON( join(appDir, '.next/server/pages/hello.js.nft.json') ) + const appTrace = await fs.readJSON( + join(appDir, '.next/server/pages/_app.js.nft.json') + ) + expect( + appTrace.files.some((file) => file.includes('node_modules/next')) + ).toBe(true) expect( helloTrace.files.some((file) => file.includes('components/world.js')) ).toBe(true) diff --git a/test/integration/jsconfig-paths/test/index.test.js b/test/integration/jsconfig-paths/test/index.test.js index 543f79aaf468b..d793cc0bbef2a 100644 --- a/test/integration/jsconfig-paths/test/index.test.js +++ b/test/integration/jsconfig-paths/test/index.test.js @@ -85,6 +85,9 @@ describe('TypeScript Features', () => { await nextBuild(appDir) }) it('should trace correctly', async () => { + const appTrace = await fs.readJSON( + join(appDir, '.next/server/pages/_app.js.nft.json') + ) const singleAliasTrace = await fs.readJSON( join(appDir, '.next/server/pages/single-alias.js.nft.json') ) @@ -100,6 +103,9 @@ describe('TypeScript Features', () => { const basicAliasTrace = await fs.readJSON( join(appDir, '.next/server/pages/basic-alias.js.nft.json') ) + expect( + appTrace.files.some((file) => file.includes('node_modules/next')) + ).toBe(true) expect( singleAliasTrace.files.some((file) => file.includes('components/hello.js') diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index 5e250deedae9a..4c887a89ab975 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -130,6 +130,7 @@ describe('Production Usage', () => { /node_modules\/react\/index\.js/, /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, + /node_modules\/next/, /next\/link\.js/, /next\/dist\/client\/link\.js/, /next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/, @@ -146,6 +147,7 @@ describe('Production Usage', () => { /node_modules\/react\/index\.js/, /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, + /node_modules\/next/, /next\/link\.js/, /next\/dist\/client\/link\.js/, /next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/, @@ -160,6 +162,7 @@ describe('Production Usage', () => { /node_modules\/react\/index\.js/, /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, + /node_modules\/next/, /next\/link\.js/, /next\/dist\/client\/link\.js/, /next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/, @@ -167,12 +170,7 @@ describe('Production Usage', () => { /node_modules\/nanoid\/url-alphabet\/index\.js/, /node_modules\/es5-ext\/array\/#\/clear\.js/, ], - notTests: [ - /node_modules\/nanoid\/index\.cjs/, - /next\/dist\/pages\/_error\.js/, - /next\/error\.js/, - /\0/, - ], + notTests: [/next\/dist\/pages\/_error\.js/, /next\/error\.js/, /\0/], }, { page: '/counter', @@ -183,6 +181,7 @@ describe('Production Usage', () => { /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, /node_modules\/react\/cjs\/react\.development\.js/, + /node_modules\/next/, /next\/router\.js/, /next\/dist\/client\/router\.js/, /next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/, @@ -197,6 +196,7 @@ describe('Production Usage', () => { /node_modules\/react\/index\.js/, /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, + /node_modules\/next/, /next\/link\.js/, /next\/dist\/client\/link\.js/, /next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/,