Skip to content

Commit

Permalink
fix(vercel): clamp runtime config to valid node versions (#2819)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpearson committed Nov 1, 2024
1 parent e3a2d6f commit 68ed727
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/presets/vercel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@ import type {
VercelServerlessFunctionConfig,
} from "./types";

// https://vercel.com/docs/functions/runtimes/node-js/node-js-versions
const SUPPORTED_NODE_VERSIONS = [16, 18, 20];

function getSystemNodeVersion() {
const systemNodeVersion = Number.parseInt(
process.versions.node.split(".")[0]
);

return Number.isNaN(systemNodeVersion) ? 20 : systemNodeVersion;
}

export async function generateFunctionFiles(nitro: Nitro) {
const buildConfigPath = resolve(nitro.options.output.dir, "config.json");
const buildConfig = generateBuildConfig(nitro);
await writeFile(buildConfigPath, JSON.stringify(buildConfig, null, 2));

const systemNodeVersion = process.versions.node.split(".")[0];
const runtimeVersion = `nodejs${systemNodeVersion}.x`;
const systemNodeVersion = getSystemNodeVersion();
const usedNodeVersion =
SUPPORTED_NODE_VERSIONS.find((version) => version >= systemNodeVersion) ??
SUPPORTED_NODE_VERSIONS.at(-1);

const runtimeVersion = `nodejs${usedNodeVersion}.x`;
const functionConfigPath = resolve(
nitro.options.output.serverDir,
".vc-config.json"
Expand Down

0 comments on commit 68ed727

Please sign in to comment.