Skip to content

Commit

Permalink
feat(version): allow passing multiple npmClientArgs as CSV (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Dec 22, 2022
1 parent 1144974 commit 0f32a95
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
35 changes: 35 additions & 0 deletions packages/version/README.md
Expand Up @@ -98,6 +98,7 @@ Running `lerna version --conventional-commits` without the above flags will rele
- [`--no-private`](#--no-private)
- [`--no-push`](#--no-push)
- [`--no-manually-update-root-lockfile`](#--no-manually-update-root-lockfile)
- [`--npm-client-args`](#--npm-client-args)
- [`--preid`](#--preid)
- [`--remote-client <type>`](#--remote-client-type)
- [`--signoff-git-commit`](#--signoff-git-commit) (new)
Expand Down Expand Up @@ -584,6 +585,40 @@ lerna version --no-manually-update-root-lockfile

A newer and better option is to this use the new flag [--sync-workspace-lock](#--sync-workspace-lock) which will to rely on your package manager client to do the work (via `install lockfile-only`) which is a lot more reliable, future proof and requires a lot less code in Lerna-Lite itself.

### `--npm-client-args`

This option allows arguments to be passed to the `npm install` that `lerna version` performs to update the lockfile (when `--sync-workspace-lock` is enabled).

For example:

```sh
lerna version 3.3.3 --sync-workspace-lock --npm-client-args=--legacy-peer-deps
lerna version 3.3.3 --sync-workspace-lock --npm-client-args="--legacy-peer-deps,--force"
lerna version 3.3.3 --sync-workspace-lock --npm-client-args="--legacy-peer-deps --force"
```

This can also be set in `lerna.json`:

```json
{
...
"npmClientArgs": ["--legacy-peer-deps", "--production"]
}
```

or specifically for the version command:

```json
{
...
"command": {
"version": {
"npmClientArgs": ["--legacy-peer-deps", "--production"]
}
}
}
```

### `--preid`

```sh
Expand Down
14 changes: 14 additions & 0 deletions packages/version/src/__tests__/update-lockfile-version.spec.ts
Expand Up @@ -153,6 +153,20 @@ describe('run install lockfile-only', () => {
expect(execSpy).toHaveBeenCalledWith('npm', ['install', '--package-lock-only', '--legacy-peer-deps'], { cwd });
expect(lockFileOutput).toBe('package-lock.json');
});

it(`should update project root lockfile by calling npm script "npm install --legacy-peer-deps,--force" with multiple npm client arguments provided as CSV`, async () => {
const execSpy = jest.spyOn(core, 'exec');
const execSyncSpy = jest.spyOn(core, 'execSync').mockReturnValue('8.5.0');
const cwd = await initFixture('lockfile-version2');

const lockFileOutput = await runInstallLockFileOnly('npm', cwd, ['--legacy-peer-deps,--force']);

expect(execSyncSpy).toHaveBeenCalled();
expect(execSpy).toHaveBeenCalledWith('npm', ['install', '--package-lock-only', '--legacy-peer-deps', '--force'], {
cwd,
});
expect(lockFileOutput).toBe('package-lock.json');
});
});

describe('pnpm client', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/version/src/lib/update-lockfile-version.ts
Expand Up @@ -127,10 +127,15 @@ export function updateNpmLockFileVersion2(obj: any, pkgName: string, newVersion:
export async function runInstallLockFileOnly(
npmClient: 'npm' | 'pnpm' | 'yarn',
cwd: string,
npmClientArgs: string[]
npmArgs: string[]
): Promise<string | undefined> {
let inputLockfileName = '';
let outputLockfileName: string | undefined;
const npmClientArgsRaw = npmArgs || [];
const npmClientArgs: string[] = npmClientArgsRaw.reduce(
(args, arg) => args.concat(arg.split(/\s|,/)),
[] as string[]
);

switch (npmClient) {
case 'pnpm':
Expand Down

0 comments on commit 0f32a95

Please sign in to comment.