Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/modules/manager/npm/post-update/node-version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ describe('modules/manager/npm/post-update/node-version', () => {
);
expect(res).toBe('^12.16.3');
});

it('returns from package.json volta', async () => {
const res = await getNodeConstraint(
{},
[],
'',
new Lazy(() => Promise.resolve({ volta: { node: '14.17.0' } })),
);
expect(res).toBe('14.17.0');
});

it('prefers volta over engines', async () => {
const res = await getNodeConstraint(
{},
[],
'',
new Lazy(() =>
Promise.resolve({
volta: { node: '14.17.0' },
engines: { node: '^12.16.3' },
}),
),
);
expect(res).toBe('14.17.0');
});
});

describe('getNodeUpdate()', () => {
Expand Down
22 changes: 18 additions & 4 deletions lib/modules/manager/npm/post-update/node-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,24 @@ async function getNodeFile(filename: string): Promise<string | null> {
async function getPackageJsonConstraint(
pkg: LazyPackageJson,
): Promise<string | null> {
const constraint = (await pkg.getValue()).engines?.node;
if (constraint && semver.validRange(constraint)) {
logger.debug(`Using node constraint "${constraint}" from package.json`);
return constraint;
const pkgJson = await pkg.getValue();
if (pkgJson.volta?.node) {
const constraint = pkgJson.volta.node;
if (semver.validRange(constraint)) {
logger.debug(
`Using node constraint "${constraint}" from package.json volta`,
);
return constraint;
}
}
if (pkgJson.engines?.node) {
const constraint = pkgJson.engines.node;
if (semver.validRange(constraint)) {
logger.debug(
`Using node constraint "${constraint}" from package.json engines`,
);
return constraint;
}
}
return null;
}
Expand Down