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(
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
}
......@@ -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
)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -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",
......
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')
}
......@@ -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)
......@@ -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) {
......
......@@ -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"
......
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