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

Function getSupportedNodeVersion

packages/build-utils/src/fs/node-version.ts:128–198  ·  view source on GitHub ↗
(
  engineRange: string | undefined,
  isAuto = false,
  availableVersions?: NodeVersionMajor[]
)

Source from the content-addressed store, hash-verified

126}
127
128export async function getSupportedNodeVersion(
129 engineRange: string | undefined,
130 isAuto = false,
131 availableVersions?: NodeVersionMajor[]
132): Promise<NodeVersion> {
133 let selection: NodeVersion | undefined;
134
135 if (engineRange) {
136 const found =
137 validRange(engineRange) &&
138 getOptions().some(o => {
139 // the array is already in order so return the first
140 // match which will be the newest version of node
141 selection = o;
142 return (
143 intersects(o.range, engineRange) &&
144 (availableVersions?.length
145 ? availableVersions.includes(o.major)
146 : true)
147 );
148 });
149 if (!found) {
150 throw new NowBuildError({
151 code: 'BUILD_UTILS_NODE_VERSION_INVALID',
152 link: 'https://vercel.link/node-version',
153 message: `Found invalid or discontinued Node.js Version: "${engineRange}". ${getHint(
154 isAuto,
155 availableVersions
156 )}`,
157 });
158 }
159 }
160
161 if (!selection) {
162 selection = getLatestNodeVersion(availableVersions);
163 }
164
165 if (selection.state === 'discontinued') {
166 const intro = `Node.js Version "${selection.range}" is discontinued and must be upgraded.`;
167 throw new NowBuildError({
168 code: 'BUILD_UTILS_NODE_VERSION_DISCONTINUED',
169 link: 'https://vercel.link/node-version',
170 message: `${intro} ${getHint(isAuto)}`,
171 });
172 }
173
174 debug(`Selected Node.js ${selection.range}`);
175
176 if (selection.state === 'deprecated') {
177 const d = selection.formattedDate;
178 // formattedDate should never be undefined because the check for deprecated
179 // expects that discontinueDate is set but this check is done for completeness
180 if (d) {
181 console.warn(
182 `Error: Node.js version ${
183 selection.range
184 } is deprecated. Deployments created on or after ${d} will fail to build. ${getHint(
185 isAuto

Callers 5

handleInitDeploymentFunction · 0.90
handleDefaultDeployFunction · 0.90
unit.test.tsFile · 0.90
getNodeVersionFunction · 0.90
testDeploymentFunction · 0.85

Calls 4

getOptionsFunction · 0.85
getHintFunction · 0.85
getLatestNodeVersionFunction · 0.85
debugFunction · 0.50

Tested by

no test coverage detected