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

Function compile

packages/node/src/build.ts:151–402  ·  view source on GitHub ↗
(
  workPath: string,
  baseDir: string,
  entrypointPath: string,
  config: Config,
  meta: Meta,
  nodeVersion: NodeVersion,
  isEdgeFunction: boolean
)

Source from the content-addressed store, hash-verified

149}
150
151async function compile(
152 workPath: string,
153 baseDir: string,
154 entrypointPath: string,
155 config: Config,
156 meta: Meta,
157 nodeVersion: NodeVersion,
158 isEdgeFunction: boolean
159): Promise<{
160 preparedFiles: Files;
161 shouldAddSourcemapSupport: boolean;
162}> {
163 const inputFiles = new Set<string>([entrypointPath]);
164 const preparedFiles: Files = {};
165 const sourceCache = new Map<string, string | Buffer | null>();
166 const fsCache = new Map<string, File>();
167 const tsCompiled = new Set<string>();
168 const pkgCache = new Map<string, { type?: string }>();
169
170 let shouldAddSourcemapSupport = false;
171
172 if (config.includeFiles) {
173 const includeFiles =
174 typeof config.includeFiles === 'string'
175 ? [config.includeFiles]
176 : config.includeFiles;
177
178 for (const pattern of includeFiles) {
179 const files = await glob(pattern, workPath);
180 await Promise.all(
181 Object.values(files).map(async entry => {
182 const { fsPath } = entry;
183 const relPath = relative(baseDir, fsPath);
184 fsCache.set(relPath, entry);
185 preparedFiles[relPath] = entry;
186 })
187 );
188 }
189 }
190
191 let tsCompile: Register;
192 function compileTypeScript(path: string, source: string): string {
193 const relPath = relative(baseDir, path);
194 if (!tsCompile) {
195 tsCompile = register({
196 basePath: workPath, // The base is the same as root now.json dir
197 project: path, // Resolve tsconfig.json from entrypoint dir
198 files: true, // Include all files such as global `.d.ts`
199 nodeVersionMajor: nodeVersion.major,
200 });
201 }
202 const { code, map } = tsCompile(source, path);
203 tsCompiled.add(relPath);
204 preparedFiles[renameTStoJS(relPath) + '.map'] = new FileBlob({
205 data: JSON.stringify(map),
206 });
207 source = code;
208 shouldAddSourcemapSupport = true;

Callers 1

buildFunction · 0.70

Calls 15

globFunction · 0.90
relativeFunction · 0.90
isBunVersionFunction · 0.90
debugFunction · 0.90
isSymbolicLinkFunction · 0.90
walkParentDirsFunction · 0.90
nodeFileTraceFunction · 0.85
renameTStoJSFunction · 0.85
filterMethod · 0.80
resolveFunction · 0.70
getMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected