mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 12:57:46 +00:00
[now-build-utils] Use latest node if no package.json found (#3587)
In a previous release, we pinned the node version to the project so that we could upgrade new projects to a newer version of Node.js while maintaining backwards compatibility with existing projects. This puts some burden on the user when they're deployment is a year old and their pinned version of Node reaches EOL. Because we currently force the user to add a package.json. This PR changes the behavior so projects are no longer pinned. Instead, newer deployments get the latest Node unless they opt-in and pin via package.json.
This commit is contained in:
@@ -25,10 +25,6 @@ const upstreamProvider =
|
|||||||
'This change is the result of a decision made by an upstream infrastructure provider (AWS).' +
|
'This change is the result of a decision made by an upstream infrastructure provider (AWS).' +
|
||||||
'\nRead more: https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html';
|
'\nRead more: https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html';
|
||||||
|
|
||||||
export function getOldestNodeVersion(): NodeVersion {
|
|
||||||
return allOptions[allOptions.length - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getLatestNodeVersion(): NodeVersion {
|
export function getLatestNodeVersion(): NodeVersion {
|
||||||
return allOptions[0];
|
return allOptions[0];
|
||||||
}
|
}
|
||||||
@@ -41,7 +37,7 @@ export async function getSupportedNodeVersion(
|
|||||||
engineRange?: string,
|
engineRange?: string,
|
||||||
isAuto?: boolean
|
isAuto?: boolean
|
||||||
): Promise<NodeVersion> {
|
): Promise<NodeVersion> {
|
||||||
let selection = getOldestNodeVersion();
|
let selection = getLatestNodeVersion();
|
||||||
|
|
||||||
if (engineRange) {
|
if (engineRange) {
|
||||||
const found = allOptions.some(o => {
|
const found = allOptions.some(o => {
|
||||||
|
|||||||
@@ -139,8 +139,8 @@ export function getSpawnOptions(
|
|||||||
|
|
||||||
export async function getNodeVersion(
|
export async function getNodeVersion(
|
||||||
destPath: string,
|
destPath: string,
|
||||||
minNodeVersion?: string,
|
_nodeVersion?: string,
|
||||||
config?: Config,
|
_config?: Config,
|
||||||
meta?: Meta
|
meta?: Meta
|
||||||
): Promise<NodeVersion> {
|
): Promise<NodeVersion> {
|
||||||
if (meta && meta.isDev) {
|
if (meta && meta.isDev) {
|
||||||
@@ -150,18 +150,10 @@ export async function getNodeVersion(
|
|||||||
}
|
}
|
||||||
const { packageJson } = await scanParentDirs(destPath, true);
|
const { packageJson } = await scanParentDirs(destPath, true);
|
||||||
let range: string | undefined;
|
let range: string | undefined;
|
||||||
let isAuto = false;
|
let isAuto = true;
|
||||||
if (packageJson && packageJson.engines && packageJson.engines.node) {
|
if (packageJson && packageJson.engines && packageJson.engines.node) {
|
||||||
range = packageJson.engines.node;
|
range = packageJson.engines.node;
|
||||||
} else if (minNodeVersion) {
|
isAuto = false;
|
||||||
range = minNodeVersion;
|
|
||||||
isAuto = true;
|
|
||||||
} else if (config && config.nodeVersion) {
|
|
||||||
range = config.nodeVersion;
|
|
||||||
isAuto = true;
|
|
||||||
} else if (config && config.zeroConfig) {
|
|
||||||
range = '10.x';
|
|
||||||
isAuto = true;
|
|
||||||
}
|
}
|
||||||
return getSupportedNodeVersion(range, isAuto);
|
return getSupportedNodeVersion(range, isAuto);
|
||||||
}
|
}
|
||||||
|
|||||||
12
packages/now-build-utils/test/unit.test.js
vendored
12
packages/now-build-utils/test/unit.test.js
vendored
@@ -96,18 +96,6 @@ it('should match all semver ranges', async () => {
|
|||||||
expect(await getSupportedNodeVersion('^10.5.0')).toHaveProperty('major', 10);
|
expect(await getSupportedNodeVersion('^10.5.0')).toHaveProperty('major', 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should select correct node version in getNodeVersion()', async () => {
|
|
||||||
expect(
|
|
||||||
await getNodeVersion('/tmp', undefined, { nodeVersion: '12.x' })
|
|
||||||
).toHaveProperty('major', 12);
|
|
||||||
expect(
|
|
||||||
await getNodeVersion('/tmp', undefined, { nodeVersion: '10.x' })
|
|
||||||
).toHaveProperty('major', 10);
|
|
||||||
expect(
|
|
||||||
await getNodeVersion('/tmp', '10.x', { nodeVersion: '12.x' })
|
|
||||||
).toHaveProperty('major', 10);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should ignore node version in now dev getNodeVersion()', async () => {
|
it('should ignore node version in now dev getNodeVersion()', async () => {
|
||||||
expect(
|
expect(
|
||||||
await getNodeVersion(
|
await getNodeVersion(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "10.0.0 - 10.99.0"
|
"node": "10.0.0 - 10.99.99"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,6 @@ async function runBuildLambda(inputPath) {
|
|||||||
const nowJson = require(nowJsonRef.fsPath);
|
const nowJson = require(nowJsonRef.fsPath);
|
||||||
expect(nowJson.builds.length).toBe(1);
|
expect(nowJson.builds.length).toBe(1);
|
||||||
const build = nowJson.builds[0];
|
const build = nowJson.builds[0];
|
||||||
if (!build.config || !build.config.nodeVersion) {
|
|
||||||
// Mimic api-deployments when a new project is created
|
|
||||||
const nodeVersion = getLatestNodeVersion().range;
|
|
||||||
build.config = { ...build.config, nodeVersion };
|
|
||||||
}
|
|
||||||
expect(build.src.includes('*')).toBeFalsy();
|
expect(build.src.includes('*')).toBeFalsy();
|
||||||
const entrypoint = build.src.replace(/^\//, ''); // strip leftmost slash
|
const entrypoint = build.src.replace(/^\//, ''); // strip leftmost slash
|
||||||
expect(inputFiles[entrypoint]).toBeDefined();
|
expect(inputFiles[entrypoint]).toBeDefined();
|
||||||
|
|||||||
Reference in New Issue
Block a user