Skip to content

Commit

Permalink
Add npm.versionArgs option
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 4, 2022
1 parent 4040727 commit 5efc57f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/release-it.json
Expand Up @@ -27,6 +27,7 @@
"otp": null,
"ignoreVersion": false,
"allowSameVersion": false,
"versionArgs": [],
"skipChecks": false,
"timeout": 10
},
Expand Down
16 changes: 14 additions & 2 deletions docs/npm.md
Expand Up @@ -94,10 +94,22 @@ basically defeats the purpose of 2FA (also, the OTP expires after a short period
Use `npm.publishPath` to publish only a specific folder. For example, set `npm.publishPath` to `"dist"`. The default
value is the current (root) folder (`"."`).

## Allow same version
## Extra arguments

Use `npm.versionArgs` and/or `npm.publishArgs` to pass extra arguments to `npm version` and `npm publish`, respectively.
Example:

```json
{
"npm": {
"versionArgs": ["--allow-same-version", "--workspaces-update=false"],
"publishArgs": ["--include-workspace-root"]
}
}
```

Use `npm.allowSameVersion` to prevent throwing error when setting the new version to the same value as the current
version.
version. This option may become deprecated, it is recommended to use `versionArgs` for this.

## Monorepos

Expand Down
5 changes: 3 additions & 2 deletions lib/plugin/npm/npm.js
Expand Up @@ -83,8 +83,9 @@ class npm extends Plugin {

if (!this.config.isIncrement) return false;

const allowSameVersion = this.options.allowSameVersion ? ' --allow-same-version' : '';
const task = () => this.exec(`npm version ${version} --no-git-tag-version${allowSameVersion}`);
const { versionArgs, allowSameVersion } = this.options;
const args = [version, '--no-git-tag-version', allowSameVersion && '--allow-same-version', ...fixArgs(versionArgs)];
const task = () => this.exec(`npm version ${args.filter(Boolean).join(' ')}`);
return this.spinner.show({ task, label: 'npm version' });
}

Expand Down
9 changes: 9 additions & 0 deletions test/npm.js
Expand Up @@ -356,3 +356,12 @@ test('should add allow-same-version argument', async t => {
const version = exec.args.filter(arg => arg[0].startsWith('npm version'));
t.regex(version[0][0], / --allow-same-version/);
});

test('should add version arguments', async t => {
const options = { npm: { skipChecks: true, versionArgs: ['--workspaces-update=false', '--allow-same-version'] } };
const npmClient = factory(npm, { options });
const exec = sinon.stub(npmClient.shell, 'exec').resolves();
await runTasks(npmClient);
const version = exec.args.filter(arg => arg[0].startsWith('npm version'));
t.regex(version[0][0], / --workspaces-update=false --allow-same-version/);
});

0 comments on commit 5efc57f

Please sign in to comment.