Unverified Commit 7ca958de authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update to latest @vercel/nft and leverage new reason types (#35446)

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: https://github.com/vercel/next.js/pull/35338
parent f62766f3
...@@ -68,11 +68,13 @@ function getFilesMapFromReasons( ...@@ -68,11 +68,13 @@ function getFilesMapFromReasons(
for (const file of fileList!) { for (const file of fileList!) {
const reason = reasons!.get(file) const reason = reasons!.get(file)
const isInitial =
reason?.type.length === 1 && reason.type.includes('initial')
if ( if (
!reason || !reason ||
!reason.parents || !reason.parents ||
(reason.type === 'initial' && reason.parents.size === 0) (isInitial && reason.parents.size === 0)
) { ) {
continue continue
} }
...@@ -360,8 +362,10 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance { ...@@ -360,8 +362,10 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
(file) => { (file) => {
file = nodePath.join(this.tracingRoot, file) file = nodePath.join(this.tracingRoot, file)
const depMod = depModMap.get(file) const depMod = depModMap.get(file)
const isAsset = reasons.get(file)?.type.includes('asset')
return ( return (
!isAsset &&
Array.isArray(depMod?.loaders) && Array.isArray(depMod?.loaders) &&
depMod.loaders.length > 0 depMod.loaders.length > 0
) )
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -161,7 +161,7 @@ ...@@ -161,7 +161,7 @@
"@types/webpack-sources1": "npm:@types/webpack-sources@0.1.5", "@types/webpack-sources1": "npm:@types/webpack-sources@0.1.5",
"@types/ws": "8.2.0", "@types/ws": "8.2.0",
"@vercel/ncc": "0.33.1", "@vercel/ncc": "0.33.1",
"@vercel/nft": "0.17.5", "@vercel/nft": "0.18.0",
"acorn": "8.5.0", "acorn": "8.5.0",
"amphtml-validator": "1.0.35", "amphtml-validator": "1.0.35",
"arg": "4.1.0", "arg": "4.1.0",
......
import fs from 'fs'
import path from 'path'
import data from '../../static/hello.json'
export default (req, res) => { export default (req, res) => {
console.log({
importedData: data,
fsLoadedData: fs.readFileSync(
path.join(process.cwd(), 'static', 'hello.json'),
'utf8'
),
})
res.end('API index works') res.end('API index works')
} }
...@@ -51,7 +51,7 @@ describe('Production Usage', () => { ...@@ -51,7 +51,7 @@ describe('Production Usage', () => {
appPort = await findPort() appPort = await findPort()
context.appPort = appPort context.appPort = appPort
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort, { cwd: appDir })
output = (result.stderr || '') + (result.stdout || '') output = (result.stderr || '') + (result.stdout || '')
console.log(output) console.log(output)
...@@ -223,6 +223,17 @@ describe('Production Usage', () => { ...@@ -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) { for (const check of checks) {
......
...@@ -5624,10 +5624,10 @@ ...@@ -5624,10 +5624,10 @@
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.1.tgz#b240080a3c1ded9446a30955a06a79851bb38f71" resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.1.tgz#b240080a3c1ded9446a30955a06a79851bb38f71"
integrity sha512-Mlsps/P0PLZwsCFtSol23FGqT3FhBGb4B1AuGQ52JTAtXhak+b0Fh/4T55r0/SVQPeRiX9pNItOEHwakGPmZYA== integrity sha512-Mlsps/P0PLZwsCFtSol23FGqT3FhBGb4B1AuGQ52JTAtXhak+b0Fh/4T55r0/SVQPeRiX9pNItOEHwakGPmZYA==
"@vercel/nft@0.17.5": "@vercel/nft@0.18.0":
version "0.17.5" version "0.18.0"
resolved "https://registry.yarnpkg.com/@vercel/nft/-/nft-0.17.5.tgz#eab288a3786b8bd6fc08c0ef0b70d162984d1643" resolved "https://registry.yarnpkg.com/@vercel/nft/-/nft-0.18.0.tgz#3a489036e53af529f8c1247a9910e92a696ebb8e"
integrity sha512-6n4uXmfkcHAmkI4rJlwFJb8yvWuH6uDOi5qme0yGC1B/KmWJ66dERupdAj9uj7eEmgM7N3bKNY5zOYE7cKZE1g== integrity sha512-FFzpmYC4hu/nnh3bm+dVWRYq59jN7ogW8hcuzKeWnXjDqtWDawn9oGnOgMFsKdqtI40RJuscPko/kzFh62ukOw==
dependencies: dependencies:
"@mapbox/node-pre-gyp" "^1.0.5" "@mapbox/node-pre-gyp" "^1.0.5"
acorn "^8.6.0" acorn "^8.6.0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment