From fa7c9f6a597b156c5a505491746c15521a7470db Mon Sep 17 00:00:00 2001 From: "jj@jjsweb.site" Date: Fri, 3 Sep 2021 10:48:53 -0500 Subject: [PATCH] Ensure build trace handles mixed modules --- .../plugins/next-trace-entrypoints-plugin.ts | 1 + .../{ => app}/content/hello.json | 0 .../build-trace-extra-entries/app/lib/fetch-data.js | 5 +++++ .../{ => app}/lib/get-data.js | 0 .../{ => app}/next.config.js | 2 +- .../app/node_modules/some-cms/index.js | 5 +++++ .../app/node_modules/some-cms/package.json | 4 ++++ .../build-trace-extra-entries/app/pages/index.js | 13 +++++++++++++ .../build-trace-extra-entries/pages/index.js | 3 --- .../build-trace-extra-entries/test/index.test.js | 5 ++++- 10 files changed, 33 insertions(+), 5 deletions(-) rename test/integration/build-trace-extra-entries/{ => app}/content/hello.json (100%) create mode 100644 test/integration/build-trace-extra-entries/app/lib/fetch-data.js rename test/integration/build-trace-extra-entries/{ => app}/lib/get-data.js (100%) rename test/integration/build-trace-extra-entries/{ => app}/next.config.js (90%) create mode 100644 test/integration/build-trace-extra-entries/app/node_modules/some-cms/index.js create mode 100644 test/integration/build-trace-extra-entries/app/node_modules/some-cms/package.json create mode 100644 test/integration/build-trace-extra-entries/app/pages/index.js delete mode 100644 test/integration/build-trace-extra-entries/pages/index.js 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 e228934e9ea3d..d5060ccb4423f 100644 --- a/packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts +++ b/packages/next/build/webpack/plugins/next-trace-entrypoints-plugin.ts @@ -253,6 +253,7 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { readlink, stat, ignore: [...TRACE_IGNORES, ...this.excludeFiles], + mixedModules: true, }) const tracedDeps: string[] = [] diff --git a/test/integration/build-trace-extra-entries/content/hello.json b/test/integration/build-trace-extra-entries/app/content/hello.json similarity index 100% rename from test/integration/build-trace-extra-entries/content/hello.json rename to test/integration/build-trace-extra-entries/app/content/hello.json diff --git a/test/integration/build-trace-extra-entries/app/lib/fetch-data.js b/test/integration/build-trace-extra-entries/app/lib/fetch-data.js new file mode 100644 index 0000000000000..ac348866e5dd7 --- /dev/null +++ b/test/integration/build-trace-extra-entries/app/lib/fetch-data.js @@ -0,0 +1,5 @@ +const getCmsData = require('some-cms') + +export function fetchData() { + return getCmsData() +} diff --git a/test/integration/build-trace-extra-entries/lib/get-data.js b/test/integration/build-trace-extra-entries/app/lib/get-data.js similarity index 100% rename from test/integration/build-trace-extra-entries/lib/get-data.js rename to test/integration/build-trace-extra-entries/app/lib/get-data.js diff --git a/test/integration/build-trace-extra-entries/next.config.js b/test/integration/build-trace-extra-entries/app/next.config.js similarity index 90% rename from test/integration/build-trace-extra-entries/next.config.js rename to test/integration/build-trace-extra-entries/app/next.config.js index 9cac96cfac31d..dfc78e3a84d63 100644 --- a/test/integration/build-trace-extra-entries/next.config.js +++ b/test/integration/build-trace-extra-entries/app/next.config.js @@ -13,7 +13,7 @@ module.exports = { if (isServer) { const curEntry = origEntries['pages/_app'] origEntries['pages/_app'] = [ - path.resolve('lib/get-data.js'), + path.join(__dirname, 'lib/get-data.js'), ...curEntry, ] console.log(origEntries) diff --git a/test/integration/build-trace-extra-entries/app/node_modules/some-cms/index.js b/test/integration/build-trace-extra-entries/app/node_modules/some-cms/index.js new file mode 100644 index 0000000000000..ce3b888523549 --- /dev/null +++ b/test/integration/build-trace-extra-entries/app/node_modules/some-cms/index.js @@ -0,0 +1,5 @@ +function getCmsData() { + return 'hello' +} + +module.exports = getCmsData diff --git a/test/integration/build-trace-extra-entries/app/node_modules/some-cms/package.json b/test/integration/build-trace-extra-entries/app/node_modules/some-cms/package.json new file mode 100644 index 0000000000000..5a348ce17878b --- /dev/null +++ b/test/integration/build-trace-extra-entries/app/node_modules/some-cms/package.json @@ -0,0 +1,4 @@ +{ + "name": "some-cms", + "main": "./index.js" +} diff --git a/test/integration/build-trace-extra-entries/app/pages/index.js b/test/integration/build-trace-extra-entries/app/pages/index.js new file mode 100644 index 0000000000000..73cb171d26ae3 --- /dev/null +++ b/test/integration/build-trace-extra-entries/app/pages/index.js @@ -0,0 +1,13 @@ +import { fetchData } from '../lib/fetch-data' + +export default function Page() { + return 'index page' +} + +export function getStaticProps() { + fetchData() + + return { + props: {}, + } +} diff --git a/test/integration/build-trace-extra-entries/pages/index.js b/test/integration/build-trace-extra-entries/pages/index.js deleted file mode 100644 index 76c8a590e002c..0000000000000 --- a/test/integration/build-trace-extra-entries/pages/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function Page() { - return 'index page' -} diff --git a/test/integration/build-trace-extra-entries/test/index.test.js b/test/integration/build-trace-extra-entries/test/index.test.js index e53dbbc0caea2..fc1f69694f0c5 100644 --- a/test/integration/build-trace-extra-entries/test/index.test.js +++ b/test/integration/build-trace-extra-entries/test/index.test.js @@ -6,7 +6,7 @@ import { nextBuild } from 'next-test-utils' jest.setTimeout(1000 * 60) -const appDir = join(__dirname, '..') +const appDir = join(__dirname, '../app') describe('build trace with extra entries', () => { it('should build and trace correctly', async () => { @@ -28,5 +28,8 @@ describe('build trace with extra entries', () => { expect( indexTrace.files.some((file) => file.endsWith('hello.json')) ).toBeFalsy() + expect( + indexTrace.files.some((file) => file.includes('some-cms/index.js')) + ).toBe(true) }) })