diff --git a/lib/manager/npm/post-update/lerna.ts b/lib/manager/npm/post-update/lerna.ts index d449ac198ff6a85daa668fea11c29cf6f63df2e4..8136af093b3161334ddc9bc158c347c81228b776 100644 --- a/lib/manager/npm/post-update/lerna.ts +++ b/lib/manager/npm/post-update/lerna.ts @@ -48,7 +48,7 @@ export async function generateLockFiles( if (global.trustLevel === 'high' && config.ignoreScripts !== false) { cmdOptions = cmdOptions.replace('--ignore-scripts ', ''); } - const tagConstraint = await getNodeConstraint(config.packageFile); + const tagConstraint = await getNodeConstraint(config); const execOptions: ExecOptions = { cwd, extraEnv: { diff --git a/lib/manager/npm/post-update/node-version.spec.ts b/lib/manager/npm/post-update/node-version.spec.ts index af76ab43ec3a65b6c65575d7b42b48ec2bc9e903..f287dbbccc0b65c5488fd73a36f53229fb2c3446 100644 --- a/lib/manager/npm/post-update/node-version.spec.ts +++ b/lib/manager/npm/post-update/node-version.spec.ts @@ -10,20 +10,20 @@ describe('getNodeConstraint', () => { fs.readLocalFile.mockResolvedValueOnce(null); fs.readLocalFile.mockResolvedValueOnce(null); fs.readLocalFile.mockResolvedValueOnce('{"engines":{"node":"^12.16.0"}}'); - const res = await getNodeConstraint('package.json'); + const res = await getNodeConstraint({ packageFile: 'package.json' }); expect(res).toEqual('^12.16.0'); }); it('returns .node-version value', async () => { fs.readLocalFile = jest.fn(); fs.readLocalFile.mockResolvedValueOnce(null); fs.readLocalFile.mockResolvedValueOnce('12.16.1\n'); - const res = await getNodeConstraint('package.json'); + const res = await getNodeConstraint({ packageFile: 'package.json' }); expect(res).toEqual('12.16.1'); }); it('returns .nvmrc value', async () => { fs.readLocalFile = jest.fn(); fs.readLocalFile.mockResolvedValueOnce('12.16.2\n'); - const res = await getNodeConstraint('package.json'); + const res = await getNodeConstraint({ packageFile: 'package.json' }); expect(res).toEqual('12.16.2'); }); it('ignores unusable ranges in dotfiles', async () => { @@ -31,7 +31,7 @@ describe('getNodeConstraint', () => { fs.readLocalFile.mockResolvedValueOnce('latest'); fs.readLocalFile.mockResolvedValueOnce('lts'); fs.readLocalFile.mockResolvedValueOnce('{"engines":{"node":"^12.16.0"}}'); - const res = await getNodeConstraint('package.json'); + const res = await getNodeConstraint({ packageFile: 'package.json' }); expect(res).toEqual('^12.16.0'); }); it('returns no constraint', async () => { @@ -39,7 +39,7 @@ describe('getNodeConstraint', () => { fs.readLocalFile.mockResolvedValueOnce(null); fs.readLocalFile.mockResolvedValueOnce(null); fs.readLocalFile.mockResolvedValueOnce('{}'); - const res = await getNodeConstraint('package.json'); + const res = await getNodeConstraint({ packageFile: 'package.json' }); expect(res).toBeNull(); }); }); diff --git a/lib/manager/npm/post-update/node-version.ts b/lib/manager/npm/post-update/node-version.ts index 28936276c935123be69c918da06a97a0f10b418f..2c664e2a8e992a8faf60a0e3f0cb4b65c7dae294 100644 --- a/lib/manager/npm/post-update/node-version.ts +++ b/lib/manager/npm/post-update/node-version.ts @@ -1,6 +1,7 @@ import { validRange } from 'semver'; import { logger } from '../../../logger'; import { getSiblingFileName, readLocalFile } from '../../../util/fs'; +import { PostUpdateConfig } from '../../common'; async function getNodeFile(filename: string): Promise<string> | null { try { @@ -34,12 +35,13 @@ async function getPackageJsonConstraint( } export async function getNodeConstraint( - filename: string + config: PostUpdateConfig ): Promise<string> | null { + const { packageFile } = config; const constraint = - (await getNodeFile(getSiblingFileName(filename, '.nvmrc'))) || - (await getNodeFile(getSiblingFileName(filename, '.node-version'))) || - (await getPackageJsonConstraint(filename)); + (await getNodeFile(getSiblingFileName(packageFile, '.nvmrc'))) || + (await getNodeFile(getSiblingFileName(packageFile, '.node-version'))) || + (await getPackageJsonConstraint(packageFile)); if (!constraint) { logger.debug('No node constraint found - using latest'); } diff --git a/lib/manager/npm/post-update/npm.ts b/lib/manager/npm/post-update/npm.ts index 18511f8180fbd19e2cf2e9e65edf947859fb4914..26c3daf0943f00b382ea6d5cde21247867c5d03a 100644 --- a/lib/manager/npm/post-update/npm.ts +++ b/lib/manager/npm/post-update/npm.ts @@ -37,7 +37,7 @@ export async function generateLockFile( logger.debug('Updating lock file only'); cmdOptions += '--package-lock-only --no-audit'; } - const tagConstraint = await getNodeConstraint(config.packageFile); + const tagConstraint = await getNodeConstraint(config); const execOptions: ExecOptions = { cwd, extraEnv: { diff --git a/lib/manager/npm/post-update/pnpm.ts b/lib/manager/npm/post-update/pnpm.ts index aba81ac352996f15dc072f7276fd8a01b8d95ffd..bec674a9b45c40cd15aa53da3372be6f0d6b792f 100644 --- a/lib/manager/npm/post-update/pnpm.ts +++ b/lib/manager/npm/post-update/pnpm.ts @@ -24,7 +24,7 @@ export async function generateLockFile( let cmd = 'pnpm'; try { const preCommands = ['npm i -g pnpm']; - const tagConstraint = await getNodeConstraint(config.packageFile); + const tagConstraint = await getNodeConstraint(config); const execOptions: ExecOptions = { cwd, extraEnv: { diff --git a/lib/manager/npm/post-update/yarn.ts b/lib/manager/npm/post-update/yarn.ts index 44f19d48b1084883352c34a40882858a03707861..8833651c55cee3fa99109b84819f894e643e2da0 100644 --- a/lib/manager/npm/post-update/yarn.ts +++ b/lib/manager/npm/post-update/yarn.ts @@ -57,7 +57,7 @@ export async function generateLockFile( if (global.trustLevel !== 'high' || config.ignoreScripts) { cmdOptions += ' --ignore-scripts --ignore-engines --ignore-platform'; } - const tagConstraint = await getNodeConstraint(config.packageFile); + const tagConstraint = await getNodeConstraint(config); const execOptions: ExecOptions = { cwd, extraEnv: {