MCPcopy Create free account
hub / github.com/vercel/vercel / nodeFileTrace

Function nodeFileTrace

packages/backends/src/cervel/node-file-trace.ts:12–102  ·  view source on GitHub ↗
(args: NodeFileTraceOptions)

Source from the content-addressed store, hash-verified

10import type { NodeFileTraceOptions } from './types.js';
11
12export const nodeFileTrace = async (args: NodeFileTraceOptions) => {
13 const { span } = args;
14 const files: Files = {};
15 const { tracedPaths } = args;
16
17 // Rolldown builds source files into the outDir, node_modules are not included.
18 const compiledSourceFiles = await glob('**/*', {
19 cwd: args.outDir,
20 follow: true,
21 includeDirectories: true,
22 });
23 for (const file of Object.keys(compiledSourceFiles)) {
24 files[file] = compiledSourceFiles[file];
25 }
26
27 /**
28 * While we're not using NFT to process source code, we are using it
29 * to tree shake node deps, and include any fs reads for files that are
30 * not part of the traced paths or compiled source files.
31 * Most of this is identical to the `@vercel/node` implementation
32 */
33 const runNft = () =>
34 nft(Array.from(tracedPaths), {
35 base: args.repoRootPath,
36 processCwd: args.workPath,
37 ts: true,
38 mixedModules: true,
39 moduleSyncCatchall: true,
40 async resolve(id, parent, job, cjsResolve) {
41 return nftResolveDependency(id, parent, job, cjsResolve);
42 },
43 async readFile(fsPath) {
44 try {
45 let source: string | Buffer = await readFile(fsPath);
46
47 // NFT doesn't support TypeScript, so we need to transform the source code.
48 if (
49 (fsPath.endsWith('.ts') && !fsPath.endsWith('.d.ts')) ||
50 fsPath.endsWith('.tsx') ||
51 fsPath.endsWith('.mts') ||
52 fsPath.endsWith('.cts')
53 ) {
54 const transformResult = await transform(fsPath, source.toString());
55 source = transformResult.code;
56 }
57
58 return source;
59 } catch (error: unknown) {
60 if (
61 isNativeError(error) &&
62 'code' in error &&
63 (error.code === 'ENOENT' || error.code === 'EISDIR')
64 ) {
65 return null;
66 }
67 throw error;
68 }
69 },

Callers 10

createRenderNodeFunctionFunction · 0.85
createRenderEdgeFunctionFunction · 0.85
traceEdgeFilesFunction · 0.85
traceNodeFilesFunction · 0.85
buildFunction · 0.85
rolldownFunction · 0.85
runNftFunction · 0.85
serverBuildFunction · 0.85
buildFunction · 0.85
compileFunction · 0.85

Calls 9

globFunction · 0.90
debugFunction · 0.90
relativeFunction · 0.85
childMethod · 0.80
keysMethod · 0.45
traceMethod · 0.45
deleteMethod · 0.45
isSymbolicLinkMethod · 0.45
isFileMethod · 0.45

Tested by

no test coverage detected