feat(lerna): dynamic npm and yarn versioning

Closes #6369
This commit is contained in:
Rhys Arkins 2020-06-03 08:06:28 +02:00
parent 3a49eeaaf6
commit 098ed9a09c
2 changed files with 23 additions and 4 deletions

View file

@ -70,7 +70,12 @@ describe('generateLockFiles()', () => {
JSON.stringify({ devDependencies: { lerna: '2.0.0' } })
);
const execSnapshots = mockExecAll(exec);
const res = await lernaHelper.generateLockFiles('yarn', 'some-dir', {}, {});
const res = await lernaHelper.generateLockFiles(
'yarn',
'some-dir',
{ compatibility: { yarn: '^1.10.0' } },
{}
);
expect(execSnapshots).toMatchSnapshot();
expect(res.error).toBe(false);
});
@ -87,7 +92,10 @@ describe('generateLockFiles()', () => {
const res = await lernaHelper.generateLockFiles(
'npm',
'some-dir',
{ dockerMapDotfiles: true },
{
dockerMapDotfiles: true,
compatibility: { npm: '^6.0.0' },
},
{}
);
expect(res.error).toBe(false);

View file

@ -1,4 +1,4 @@
import semver from 'semver';
import semver, { validRange } from 'semver';
import { quote } from 'shlex';
import { join } from 'upath';
import { logger } from '../../../logger';
@ -30,12 +30,23 @@ export async function generateLockFiles(
let cmdOptions = '';
try {
if (lernaClient === 'yarn') {
preCommands.push('npm i -g yarn');
let installYarn = 'npm i -g yarn';
const yarnCompatibility = config.compatibility?.yarn;
if (validRange(yarnCompatibility)) {
installYarn += `@${quote(yarnCompatibility)}`;
}
preCommands.push(installYarn);
if (skipInstalls !== false) {
preCommands.push(optimizeCommand);
}
cmdOptions = '--ignore-scripts --ignore-engines --ignore-platform';
} else if (lernaClient === 'npm') {
let installNpm = 'npm i -g npm';
const npmCompatibility = config.compatibility?.npm;
if (validRange(npmCompatibility)) {
installNpm += `@${quote(npmCompatibility)}`;
preCommands.push(installNpm);
}
cmdOptions = '--ignore-scripts --no-audit';
if (skipInstalls !== false) {
cmdOptions += ' --package-lock-only';