Unverified Commit c3a395ab authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update to latest @vercel/nft and use async fs methods (#29341)

This updates to the latest version of `node-file-trace` and leverages the new async fs handling with webpack. In a follow-up PR we will implement the async resolver to share resolving with webpack as well. 

x-ref: https://github.com/vercel/nft/pull/236
parent f2c266ba
import nodePath from 'path' import nodePath from 'path'
import { Span } from '../../../trace'
import { spans } from './profiling-plugin'
import isError from '../../../lib/is-error'
import { nodeFileTrace } from 'next/dist/compiled/@vercel/nft' import { nodeFileTrace } from 'next/dist/compiled/@vercel/nft'
import { TRACE_OUTPUT_VERSION } from '../../../shared/lib/constants'
import { import {
webpack, webpack,
isWebpack5, isWebpack5,
sources, sources,
} from 'next/dist/compiled/webpack/webpack' } from 'next/dist/compiled/webpack/webpack'
import { TRACE_OUTPUT_VERSION } from '../../../shared/lib/constants'
import { spans } from './profiling-plugin'
import { Span } from '../../../trace'
import isError from '../../../lib/is-error'
const PLUGIN_NAME = 'TraceEntryPointsPlugin' const PLUGIN_NAME = 'TraceEntryPointsPlugin'
const TRACE_IGNORES = [ const TRACE_IGNORES = [
...@@ -147,10 +147,9 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { ...@@ -147,10 +147,9 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
}) })
}) })
// TODO: investigate allowing non-sync fs calls in node-file-trace const readFile = async (
// for better performance path: string
const readFile = (path: string, _span: Span) => { ): Promise<Buffer | string | null> => {
// return span.traceChild('read-file', { path }).traceFn(() => {
const mod = depModMap.get(path) || entryModMap.get(path) const mod = depModMap.get(path) || entryModMap.get(path)
// map the transpiled source when available to avoid // map the transpiled source when available to avoid
...@@ -162,7 +161,15 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { ...@@ -162,7 +161,15 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
} }
try { try {
return compilation.inputFileSystem.readFileSync(path) return await new Promise((resolve, reject) => {
;(
compilation.inputFileSystem
.readFile as typeof import('fs').readFile
)(path, (err, data) => {
if (err) return reject(err)
resolve(data)
})
})
} catch (e) { } catch (e) {
if ( if (
isError(e) && isError(e) &&
...@@ -172,12 +179,18 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { ...@@ -172,12 +179,18 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
} }
throw e throw e
} }
// })
} }
const readlink = (path: string, _span: Span) => { const readlink = async (path: string): Promise<string | null> => {
// return span.traceChild('read-link', { path }).traceFn(() => {
try { try {
return compilation.inputFileSystem.readlinkSync(path) return await new Promise((resolve, reject) => {
;(
compilation.inputFileSystem
.readlink as typeof import('fs').readlink
)(path, (err, link) => {
if (err) return reject(err)
resolve(link)
})
})
} catch (e) { } catch (e) {
if ( if (
isError(e) && isError(e) &&
...@@ -189,19 +202,25 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { ...@@ -189,19 +202,25 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
} }
throw e throw e
} }
// })
} }
const stat = (path: string, _span: Span) => { const stat = async (
// return span.traceChild('stat', { path }).traceFn(() => { path: string
): Promise<import('fs').Stats | null> => {
try { try {
return compilation.inputFileSystem.statSync(path) return await new Promise((resolve, reject) => {
;(
compilation.inputFileSystem.stat as typeof import('fs').stat
)(path, (err, stats) => {
if (err) return reject(err)
resolve(stats)
})
})
} catch (e) { } catch (e) {
if (isError(e) && e.code === 'ENOENT') { if (isError(e) && e.code === 'ENOENT') {
return null return null
} }
throw e throw e
} }
// })
} }
const nftCache = {} const nftCache = {}
...@@ -260,9 +279,9 @@ export class TraceEntryPointsPlugin implements webpack.Plugin { ...@@ -260,9 +279,9 @@ export class TraceEntryPointsPlugin implements webpack.Plugin {
base: root, base: root,
cache: nftCache, cache: nftCache,
processCwd: this.appDir, processCwd: this.appDir,
readFile: (path) => readFile(path, fileTraceSpan), readFile,
readlink: (path) => readlink(path, fileTraceSpan), readlink,
stat: (path) => stat(path, fileTraceSpan), stat,
ignore: [...TRACE_IGNORES, ...this.excludeFiles], ignore: [...TRACE_IGNORES, ...this.excludeFiles],
mixedModules: true, mixedModules: true,
}) })
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -185,7 +185,7 @@ ...@@ -185,7 +185,7 @@
"@types/text-table": "0.2.1", "@types/text-table": "0.2.1",
"@types/webpack-sources1": "npm:@types/webpack-sources@0.1.5", "@types/webpack-sources1": "npm:@types/webpack-sources@0.1.5",
"@vercel/ncc": "0.27.0", "@vercel/ncc": "0.27.0",
"@vercel/nft": "0.12.2", "@vercel/nft": "0.15.0",
"amphtml-validator": "1.0.33", "amphtml-validator": "1.0.33",
"arg": "4.1.0", "arg": "4.1.0",
"async-retry": "1.2.3", "async-retry": "1.2.3",
......
...@@ -737,7 +737,7 @@ export async function ncc_mini_css_extract_plugin(task, opts) { ...@@ -737,7 +737,7 @@ export async function ncc_mini_css_extract_plugin(task, opts) {
externals: { externals: {
...externals, ...externals,
'./index': './index.js', './index': './index.js',
'schema-utils': 'next/dist/compiled/schema-utils3', 'schema-utils': externals['schema-utils3'],
'webpack-sources': externals['webpack-sources1'], 'webpack-sources': externals['webpack-sources1'],
}, },
}) })
......
...@@ -5053,17 +5053,18 @@ ...@@ -5053,17 +5053,18 @@
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.27.0.tgz#c0cfeebb0bebb56052719efa4a0ecc090a932c76" resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.27.0.tgz#c0cfeebb0bebb56052719efa4a0ecc090a932c76"
integrity sha512-DllIJQapnU2YwewIhh/4dYesmMQw3h2cFtabECc/zSJHqUbNa0eJuEkRa6DXbZvh1YPWBtYQoPV17NlDpBw1Vw== integrity sha512-DllIJQapnU2YwewIhh/4dYesmMQw3h2cFtabECc/zSJHqUbNa0eJuEkRa6DXbZvh1YPWBtYQoPV17NlDpBw1Vw==
"@vercel/nft@0.12.2": "@vercel/nft@0.15.0":
version "0.12.2" version "0.15.0"
resolved "https://registry.yarnpkg.com/@vercel/nft/-/nft-0.12.2.tgz#67ea9f231d24639b3783e3e69bef173659972d3b" resolved "https://registry.yarnpkg.com/@vercel/nft/-/nft-0.15.0.tgz#af8b7a8583d6ce3d12334f2ccf9b2c29acfd6e2c"
integrity sha512-H8n44GboVnJaVVX4+WfuOTAaNLDnUIYH4KpMZcXll7KMNIcg0JTd0IFRsIBe/uvuXisqm6nEANp8Tr3/1dlRQw== integrity sha512-ZEEQXTL2yB1Hv9WkcLtLZXV9JKZmg/ttWTt2mwKQeb8DNVwKXBfhV0zSuKGDSl0q1yAutR7PoFCkrh7Myz2aow==
dependencies: dependencies:
"@mapbox/node-pre-gyp" "^1.0.5" "@mapbox/node-pre-gyp" "^1.0.5"
acorn "^8.1.0" acorn "^8.3.0"
acorn-class-fields "^1.0.0" acorn-class-fields "^1.0.0"
acorn-private-class-elements "^1.0.0"
acorn-static-class-features "^1.0.0" acorn-static-class-features "^1.0.0"
bindings "^1.4.0" bindings "^1.4.0"
estree-walker "^0.6.1" estree-walker "2.0.2"
glob "^7.1.3" glob "^7.1.3"
graceful-fs "^4.1.15" graceful-fs "^4.1.15"
micromatch "^4.0.2" micromatch "^4.0.2"
...@@ -5476,17 +5477,12 @@ acorn@^8.0.4: ...@@ -5476,17 +5477,12 @@ acorn@^8.0.4:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.0.4.tgz#7a3ae4191466a6984eee0fe3407a4f3aa9db8354" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.0.4.tgz#7a3ae4191466a6984eee0fe3407a4f3aa9db8354"
integrity sha512-XNP0PqF1XD19ZlLKvB7cMmnZswW4C/03pRHgirB30uSJTaS3A3V1/P4sS3HPvFmjoriPCJQs+JDSbm4bL1TxGQ== integrity sha512-XNP0PqF1XD19ZlLKvB7cMmnZswW4C/03pRHgirB30uSJTaS3A3V1/P4sS3HPvFmjoriPCJQs+JDSbm4bL1TxGQ==
acorn@^8.1.0:
version "8.2.4"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.2.4.tgz#caba24b08185c3b56e3168e97d15ed17f4d31fd0"
integrity sha512-Ibt84YwBDDA890eDiDCEqcbwvHlBvzzDkU2cGBBDDI1QWT12jTiXIOn2CIw5KK4i6N5Z2HUxwYjzriDyqaqqZg==
acorn@^8.2.4: acorn@^8.2.4:
version "8.4.1" version "8.4.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.4.1.tgz#56c36251fc7cabc7096adc18f05afe814321a28c" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.4.1.tgz#56c36251fc7cabc7096adc18f05afe814321a28c"
integrity sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA== integrity sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==
acorn@^8.4.1: acorn@^8.3.0, acorn@^8.4.1:
version "8.5.0" version "8.5.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.5.0.tgz#4512ccb99b3698c752591e9bb4472e38ad43cee2" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.5.0.tgz#4512ccb99b3698c752591e9bb4472e38ad43cee2"
integrity sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q== integrity sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==
...@@ -9114,6 +9110,11 @@ estree-util-is-identifier-name@^1.0.0: ...@@ -9114,6 +9110,11 @@ estree-util-is-identifier-name@^1.0.0:
resolved "https://registry.yarnpkg.com/estree-util-is-identifier-name/-/estree-util-is-identifier-name-1.1.0.tgz#2e3488ea06d9ea2face116058864f6370b37456d" resolved "https://registry.yarnpkg.com/estree-util-is-identifier-name/-/estree-util-is-identifier-name-1.1.0.tgz#2e3488ea06d9ea2face116058864f6370b37456d"
integrity sha512-OVJZ3fGGt9By77Ix9NhaRbzfbDV/2rx9EP7YIDJTmsZSEc5kYn2vWcNccYyahJL2uAQZK2a5Or2i0wtIKTPoRQ== integrity sha512-OVJZ3fGGt9By77Ix9NhaRbzfbDV/2rx9EP7YIDJTmsZSEc5kYn2vWcNccYyahJL2uAQZK2a5Or2i0wtIKTPoRQ==
estree-walker@2.0.2, estree-walker@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==
estree-walker@^0.6.1: estree-walker@^0.6.1:
version "0.6.1" version "0.6.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362" resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362"
...@@ -9123,11 +9124,6 @@ estree-walker@^1.0.1: ...@@ -9123,11 +9124,6 @@ estree-walker@^1.0.1:
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700"
integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==
estree-walker@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==
esutils@^2.0.2: esutils@^2.0.2:
version "2.0.3" version "2.0.3"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
......
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