mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 04:22:01 +00:00
[build-utils] Fix warn for ignored project settings node version (#11550)
There were scenarios where the warning "Node.js Version defined in your Project Settings ("18.x") will not apply" would not be triggered. For example:
1. Project Setting is 18.x
2. package.json has "engines.node": ">=18.x"
3. semver.intersects('18.x', '>=18.x') // => true (In this [code path](8ea93839cc/packages/build-utils/src/fs/run-user-scripts.ts (L258))) -> No warning message that Node.js Version was changed
4. After the error message we evaluate the latest node Version to use (20.x) in getSupportedNodeVersion()(this [code path](8ea93839cc/packages/build-utils/src/fs/run-user-scripts.ts (L274)))
5. User doesn't get notified that we changed the node version to something different than their project setting
This fixes that scenario by getting the supported node version first.
This commit is contained in:
5
.changeset/clean-ears-agree.md
Normal file
5
.changeset/clean-ears-agree.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@vercel/build-utils': patch
|
||||
---
|
||||
|
||||
Fix triggering of ignored project settings node version warning
|
||||
@@ -251,15 +251,24 @@ export async function getNodeVersion(
|
||||
return { ...latest, runtime: 'nodejs' };
|
||||
}
|
||||
const { packageJson } = await scanParentDirs(destPath, true);
|
||||
let nodeVersion = config.nodeVersion || nodeVersionFallback;
|
||||
let isAuto = true;
|
||||
const nodeVersion = config.nodeVersion || nodeVersionFallback;
|
||||
|
||||
const pkgJsonNodeVersion = packageJson?.engines?.node;
|
||||
const nodeVersionToUse = await getSupportedNodeVersion(
|
||||
pkgJsonNodeVersion || nodeVersion,
|
||||
!pkgJsonNodeVersion,
|
||||
availableVersions
|
||||
);
|
||||
|
||||
if (packageJson?.engines?.node) {
|
||||
const { node } = packageJson.engines;
|
||||
if (nodeVersion && validRange(node) && !intersects(nodeVersion, node)) {
|
||||
if (nodeVersion && !intersects(nodeVersion, nodeVersionToUse.range)) {
|
||||
console.warn(
|
||||
`Warning: Due to "engines": { "node": "${node}" } in your \`package.json\` file, the Node.js Version defined in your Project Settings ("${nodeVersion}") will not apply. Learn More: http://vercel.link/node-version`
|
||||
);
|
||||
} else if (coerce(node)?.raw === node) {
|
||||
}
|
||||
|
||||
if (coerce(node)?.raw === node) {
|
||||
console.warn(
|
||||
`Warning: Detected "engines": { "node": "${node}" } in your \`package.json\` with major.minor.patch, but only major Node.js Version can be selected. Learn More: http://vercel.link/node-version`
|
||||
);
|
||||
@@ -268,10 +277,8 @@ export async function getNodeVersion(
|
||||
`Warning: Detected "engines": { "node": "${node}" } in your \`package.json\` that will automatically upgrade when a new major Node.js Version is released. Learn More: http://vercel.link/node-version`
|
||||
);
|
||||
}
|
||||
nodeVersion = node;
|
||||
isAuto = false;
|
||||
}
|
||||
return getSupportedNodeVersion(nodeVersion, isAuto, availableVersions);
|
||||
return nodeVersionToUse;
|
||||
}
|
||||
|
||||
export async function scanParentDirs(
|
||||
|
||||
15
packages/build-utils/test/unit.test.ts
vendored
15
packages/build-utils/test/unit.test.ts
vendored
@@ -221,6 +221,21 @@ it('should warn when package.json engines is greater than', async () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should warn when project settings gets overrided', async () => {
|
||||
expect(
|
||||
await getNodeVersion(
|
||||
path.join(__dirname, 'pkg-engine-node-greaterthan'),
|
||||
undefined,
|
||||
{ nodeVersion: '16.x' },
|
||||
{}
|
||||
)
|
||||
).toHaveProperty('range', '20.x');
|
||||
expect(warningMessages).toStrictEqual([
|
||||
'Warning: Due to "engines": { "node": ">=16" } in your `package.json` file, the Node.js Version defined in your Project Settings ("16.x") will not apply. Learn More: http://vercel.link/node-version',
|
||||
'Warning: Detected "engines": { "node": ">=16" } in your `package.json` that will automatically upgrade when a new major Node.js Version is released. Learn More: http://vercel.link/node-version',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not warn when package.json engines matches project setting from config', async () => {
|
||||
expect(
|
||||
await getNodeVersion(
|
||||
|
||||
Reference in New Issue
Block a user