From 73fbd698bd94321544c1dce45784ab7f57263177 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 25 Oct 2021 18:38:30 -0500 Subject: [PATCH] Fix trace case with tsconfig/jsconfig baseUrl (#30286) --- .../plugins/next-trace-entrypoints-plugin.ts | 2 + .../jsconfig-baseurl/test/index.test.js | 18 +++++++ .../jsconfig-paths/test/index.test.js | 47 +++++++++++++++++++ 3 files changed, 67 insertions(+) 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 3364606950e6bc9..154930d9fb4c4b3 100644 --- a/packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts +++ b/packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts @@ -476,10 +476,12 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance { const CJS_RESOLVE_OPTIONS = { ...NODE_RESOLVE_OPTIONS, + modules: undefined, extensions: undefined, } const ESM_RESOLVE_OPTIONS = { ...NODE_ESM_RESOLVE_OPTIONS, + modules: undefined, extensions: undefined, } diff --git a/test/integration/jsconfig-baseurl/test/index.test.js b/test/integration/jsconfig-baseurl/test/index.test.js index 77d58eda7f0662b..64740b6c1fdaf55 100644 --- a/test/integration/jsconfig-baseurl/test/index.test.js +++ b/test/integration/jsconfig-baseurl/test/index.test.js @@ -8,6 +8,7 @@ import { findPort, launchApp, killApp, + nextBuild, check, } from 'next-test-utils' @@ -61,4 +62,21 @@ describe('TypeScript Features', () => { expect(found).toBe(true) }) }) + + describe('should build', () => { + beforeAll(async () => { + await nextBuild(appDir) + }) + it('should trace correctly', async () => { + const helloTrace = await fs.readJSON( + join(appDir, '.next/server/pages/hello.js.nft.json') + ) + expect( + helloTrace.files.some((file) => file.includes('components/world.js')) + ).toBe(true) + expect( + helloTrace.files.some((file) => file.includes('react/index.js')) + ).toBe(true) + }) + }) }) diff --git a/test/integration/jsconfig-paths/test/index.test.js b/test/integration/jsconfig-paths/test/index.test.js index 595cf5fba936333..543f79aaf468b1f 100644 --- a/test/integration/jsconfig-paths/test/index.test.js +++ b/test/integration/jsconfig-paths/test/index.test.js @@ -7,6 +7,7 @@ import { renderViaHTTP, findPort, launchApp, + nextBuild, killApp, check, } from 'next-test-utils' @@ -78,4 +79,50 @@ describe('TypeScript Features', () => { expect(found).toBe(true) }) }) + + describe('should build', () => { + beforeAll(async () => { + await nextBuild(appDir) + }) + it('should trace correctly', async () => { + const singleAliasTrace = await fs.readJSON( + join(appDir, '.next/server/pages/single-alias.js.nft.json') + ) + const wildcardAliasTrace = await fs.readJSON( + join(appDir, '.next/server/pages/wildcard-alias.js.nft.json') + ) + const resolveOrderTrace = await fs.readJSON( + join(appDir, '.next/server/pages/resolve-order.js.nft.json') + ) + const resolveFallbackTrace = await fs.readJSON( + join(appDir, '.next/server/pages/resolve-fallback.js.nft.json') + ) + const basicAliasTrace = await fs.readJSON( + join(appDir, '.next/server/pages/basic-alias.js.nft.json') + ) + expect( + singleAliasTrace.files.some((file) => + file.includes('components/hello.js') + ) + ).toBe(true) + expect( + wildcardAliasTrace.files.some((file) => + file.includes('mypackage/myfile.js') + ) + ).toBe(true) + expect( + resolveOrderTrace.files.some((file) => file.includes('lib/a/api.js')) + ).toBe(true) + expect( + resolveFallbackTrace.files.some((file) => + file.includes('lib/b/b-only.js') + ) + ).toBe(true) + expect( + basicAliasTrace.files.some((file) => + file.includes('components/world.js') + ) + ).toBe(true) + }) + }) })