Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(version): allow passing multiple npmClientArgs as CSV #429

Merged
merged 1 commit into from Dec 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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