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

Function getNodeVersion

packages/build-utils/src/fs/run-user-scripts.ts:342–447  ·  view source on GitHub ↗
(
  destPath: string,
  fallbackVersion = process.env.VERCEL_PROJECT_SETTINGS_NODE_VERSION,
  config: Config = {},
  meta: Meta = {},
  availableVersions = getAvailableNodeVersions()
)

Source from the content-addressed store, hash-verified

340}
341
342export async function getNodeVersion(
343 destPath: string,
344 fallbackVersion = process.env.VERCEL_PROJECT_SETTINGS_NODE_VERSION,
345 config: Config = {},
346 meta: Meta = {},
347 availableVersions = getAvailableNodeVersions()
348): Promise<NodeVersion | BunVersion> {
349 // All the different versions/sources to consider
350 const { packageJson } = await findPackageJson(destPath, true);
351 const packageJsonNodeVersion = packageJson?.engines?.node;
352 const packageJsonBunVersion = packageJson?.engines?.bun;
353
354 const latestNodeVersion = getLatestNodeVersion(availableVersions);
355
356 // Determine the target runtime
357 let targetRuntime: 'node' | 'bun';
358 if (packageJsonNodeVersion && packageJsonBunVersion) {
359 // If package.json specifies both Node and Bun
360 if (config.bunVersion) {
361 // if vercel.json specifies a bun version, use bun
362 targetRuntime = 'bun';
363 console.warn(
364 `Warning detected "engines": { "node": ..., "bun": ... } in \`package.json\`. Since "bunVersion" is set in \`vercel.json\`, using "bun".`
365 );
366 } else {
367 // otherwise default to node
368 targetRuntime = 'node';
369 console.warn(
370 `Warning detected "engines": { "node": ..., "bun": ... } in \`package.json\`. Defaulting to "node".`
371 );
372 }
373 } else if (packageJsonNodeVersion) {
374 targetRuntime = 'node';
375 if (config.bunVersion) {
376 console.warn(
377 `Warning detected "engines": { "node": ... } in \`package.json\` and "bunVersion" in \`vercel.json\`. \`package.json\` takes precedence, using "node".`
378 );
379 }
380 } else if (packageJsonBunVersion || config.bunVersion) {
381 targetRuntime = 'bun';
382 } else {
383 // If no target runtime is determined, fallback to the configured node version
384 targetRuntime = 'node';
385 }
386
387 // For `vercel dev`, return the latest node or bun version
388 if (meta.isDev) {
389 if (targetRuntime === 'node') {
390 // Use the system-installed version of `node` in PATH for `vercel dev`
391 latestNodeVersion.runtime = 'nodejs';
392 return latestNodeVersion;
393 } else {
394 // Hard coded for now...
395 return getSupportedBunVersion('1.x');
396 }
397 }
398
399 // Get the version for the target runtime

Callers 11

buildFunction · 0.90
buildFunction · 0.90
buildFunction · 0.90
buildFunction · 0.90
writeHandlerFunction · 0.90
writeVCConfigFunction · 0.90
buildFunction · 0.90
unit.test.tsFile · 0.90
buildFunction · 0.90
buildFunction · 0.90
downloadInstallAndBundleFunction · 0.90

Calls 5

getAvailableNodeVersionsFunction · 0.90
getLatestNodeVersionFunction · 0.90
getSupportedBunVersionFunction · 0.90
getSupportedNodeVersionFunction · 0.90
findPackageJsonFunction · 0.85

Tested by

no test coverage detected