diff --git a/config/release-it.json b/config/release-it.json index 7cb17c9b..835e3fd3 100644 --- a/config/release-it.json +++ b/config/release-it.json @@ -27,6 +27,7 @@ "otp": null, "ignoreVersion": false, "allowSameVersion": false, + "versionArgs": [], "skipChecks": false, "timeout": 10 }, diff --git a/docs/npm.md b/docs/npm.md index 57201e86..2784fa47 100644 --- a/docs/npm.md +++ b/docs/npm.md @@ -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 diff --git a/lib/plugin/npm/npm.js b/lib/plugin/npm/npm.js index 3524d477..8765b473 100644 --- a/lib/plugin/npm/npm.js +++ b/lib/plugin/npm/npm.js @@ -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' }); } diff --git a/test/npm.js b/test/npm.js index 727baab6..94606507 100644 --- a/test/npm.js +++ b/test/npm.js @@ -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/); +});