-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure build trace is correct with extra entries (#28667)
* Ensure build trace is correct with extra entries * lint-fix * fix check on windows
- Loading branch information
Showing
6 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/integration/build-trace-extra-entries/content/hello.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello": "world" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
export function getData() { | ||
return JSON.parse( | ||
fs.readFileSync(path.join(process.cwd(), 'content/hello.json'), 'utf8') | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const path = require('path') | ||
|
||
module.exports = { | ||
experimental: { | ||
nftTracing: true, | ||
}, | ||
webpack(cfg, { isServer }) { | ||
console.log(cfg.entry) | ||
const origEntry = cfg.entry | ||
cfg.entry = async () => { | ||
const origEntries = await origEntry() | ||
|
||
if (isServer) { | ||
const curEntry = origEntries['pages/_app'] | ||
origEntries['pages/_app'] = [ | ||
path.resolve('lib/get-data.js'), | ||
...curEntry, | ||
] | ||
console.log(origEntries) | ||
} | ||
return origEntries | ||
} | ||
return cfg | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return 'index page' | ||
} |
32 changes: 32 additions & 0 deletions
32
test/integration/build-trace-extra-entries/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-env jest */ | ||
|
||
import fs from 'fs-extra' | ||
import { join } from 'path' | ||
import { nextBuild } from 'next-test-utils' | ||
|
||
jest.setTimeout(1000 * 60) | ||
|
||
const appDir = join(__dirname, '..') | ||
|
||
describe('build trace with extra entries', () => { | ||
it('should build and trace correctly', async () => { | ||
const result = await nextBuild(appDir, undefined, { | ||
cwd: appDir, | ||
}) | ||
expect(result.code).toBe(0) | ||
|
||
const appTrace = await fs.readJSON( | ||
join(appDir, '.next/server/pages/_app.js.nft.json') | ||
) | ||
const indexTrace = await fs.readJSON( | ||
join(appDir, '.next/server/pages/index.js.nft.json') | ||
) | ||
|
||
expect(appTrace.files.some((file) => file.endsWith('hello.json'))).toBe( | ||
true | ||
) | ||
expect( | ||
indexTrace.files.some((file) => file.endsWith('hello.json')) | ||
).toBeFalsy() | ||
}) | ||
}) |