Skip to content

Commit

Permalink
Update to latest @vercel/nft and leverage new reason types (#35446)
Browse files Browse the repository at this point in the history
Currently we ignore any files that are traced and handled by a webpack loader to prevent including webpack specific files although users may attempt reading files directly using `fs` even if they are handled by webpack so this leverages the new reason types in `@vercel/nft` to only ignore if it is solely imported. 

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

x-ref: #35338
  • Loading branch information
ijjk committed Mar 18, 2022
1 parent f62766f commit 7ca958d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
Expand Up @@ -68,11 +68,13 @@ function getFilesMapFromReasons(

for (const file of fileList!) {
const reason = reasons!.get(file)
const isInitial =
reason?.type.length === 1 && reason.type.includes('initial')

if (
!reason ||
!reason.parents ||
(reason.type === 'initial' && reason.parents.size === 0)
(isInitial && reason.parents.size === 0)
) {
continue
}
Expand Down Expand Up @@ -360,8 +362,10 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
(file) => {
file = nodePath.join(this.tracingRoot, file)
const depMod = depModMap.get(file)
const isAsset = reasons.get(file)?.type.includes('asset')

return (
!isAsset &&
Array.isArray(depMod?.loaders) &&
depMod.loaders.length > 0
)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/compiled/@vercel/nft/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/next/package.json
Expand Up @@ -161,7 +161,7 @@
"@types/webpack-sources1": "npm:@types/webpack-sources@0.1.5",
"@types/ws": "8.2.0",
"@vercel/ncc": "0.33.1",
"@vercel/nft": "0.17.5",
"@vercel/nft": "0.18.0",
"acorn": "8.5.0",
"amphtml-validator": "1.0.35",
"arg": "4.1.0",
Expand Down
11 changes: 11 additions & 0 deletions test/integration/production/pages/api/index.js
@@ -1,3 +1,14 @@
import fs from 'fs'
import path from 'path'
import data from '../../static/hello.json'

export default (req, res) => {
console.log({
importedData: data,
fsLoadedData: fs.readFileSync(
path.join(process.cwd(), 'static', 'hello.json'),
'utf8'
),
})
res.end('API index works')
}
1 change: 1 addition & 0 deletions test/integration/production/static/hello.json
@@ -0,0 +1 @@
{ "hello": "world" }
13 changes: 12 additions & 1 deletion test/integration/production/test/index.test.js
Expand Up @@ -51,7 +51,7 @@ describe('Production Usage', () => {

appPort = await findPort()
context.appPort = appPort
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, { cwd: appDir })
output = (result.stderr || '') + (result.stdout || '')
console.log(output)

Expand Down Expand Up @@ -223,6 +223,17 @@ describe('Production Usage', () => {
/!/,
],
},
{
page: '/api',
tests: [/webpack-runtime\.js/, /static\/hello\.json/],
notTests: [
/next\/dist\/server\/next\.js/,
/next\/dist\/bin/,
/\0/,
/\?/,
/!/,
],
},
]

for (const check of checks) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -5624,10 +5624,10 @@
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.1.tgz#b240080a3c1ded9446a30955a06a79851bb38f71"
integrity sha512-Mlsps/P0PLZwsCFtSol23FGqT3FhBGb4B1AuGQ52JTAtXhak+b0Fh/4T55r0/SVQPeRiX9pNItOEHwakGPmZYA==

"@vercel/nft@0.17.5":
version "0.17.5"
resolved "https://registry.yarnpkg.com/@vercel/nft/-/nft-0.17.5.tgz#eab288a3786b8bd6fc08c0ef0b70d162984d1643"
integrity sha512-6n4uXmfkcHAmkI4rJlwFJb8yvWuH6uDOi5qme0yGC1B/KmWJ66dERupdAj9uj7eEmgM7N3bKNY5zOYE7cKZE1g==
"@vercel/nft@0.18.0":
version "0.18.0"
resolved "https://registry.yarnpkg.com/@vercel/nft/-/nft-0.18.0.tgz#3a489036e53af529f8c1247a9910e92a696ebb8e"
integrity sha512-FFzpmYC4hu/nnh3bm+dVWRYq59jN7ogW8hcuzKeWnXjDqtWDawn9oGnOgMFsKdqtI40RJuscPko/kzFh62ukOw==
dependencies:
"@mapbox/node-pre-gyp" "^1.0.5"
acorn "^8.6.0"
Expand Down

0 comments on commit 7ca958d

Please sign in to comment.