From 7dba84f9db40d89102be64d0d25da2a8a507b796 Mon Sep 17 00:00:00 2001 From: 1Aron Date: Wed, 7 Dec 2022 23:41:40 +0800 Subject: [PATCH 1/3] feat: additional arguments `publishArgs` and `versionArgs` for npm commands --- lib/prepare.js | 5 +++-- lib/publish.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/prepare.js b/lib/prepare.js index d232eb21..e58d36fd 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -2,14 +2,15 @@ const path = require('path'); const {move} = require('fs-extra'); const execa = require('execa'); -module.exports = async (npmrc, {tarballDir, pkgRoot}, {cwd, env, stdout, stderr, nextRelease: {version}, logger}) => { +module.exports = async (npmrc, {tarballDir, pkgRoot, versionArgs}, {cwd, env, stdout, stderr, nextRelease: {version}, logger}) => { const basePath = pkgRoot ? path.resolve(cwd, pkgRoot) : cwd; logger.log('Write version %s to package.json in %s', version, basePath); const versionResult = execa( 'npm', - ['version', version, '--userconfig', npmrc, '--no-git-tag-version', '--allow-same-version'], + ['version', version, '--userconfig', npmrc, '--no-git-tag-version', '--allow-same-version'] + .concat(versionArgs || []), { cwd: basePath, env, diff --git a/lib/publish.js b/lib/publish.js index ff3af007..d9c6017a 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -4,7 +4,7 @@ const getRegistry = require('./get-registry'); const getChannel = require('./get-channel'); const getReleaseInfo = require('./get-release-info'); -module.exports = async (npmrc, {npmPublish, pkgRoot}, pkg, context) => { +module.exports = async (npmrc, {npmPublish, pkgRoot, publishArgs}, pkg, context) => { const { cwd, env, @@ -22,7 +22,8 @@ module.exports = async (npmrc, {npmPublish, pkgRoot}, pkg, context) => { logger.log(`Publishing version ${version} to npm registry on dist-tag ${distTag}`); const result = execa( 'npm', - ['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry], + ['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry] + .concat(publishArgs || []), {cwd, env, preferLocal: true} ); result.stdout.pipe(stdout, {end: false}); From df3c07914990f01c3f6709589c90f2d7efe15e7a Mon Sep 17 00:00:00 2001 From: 1Aron Date: Wed, 7 Dec 2022 23:44:18 +0800 Subject: [PATCH 2/3] docs(readme): new options `publishArgs` and `versionArgs` --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1188eaa6..46f7ee98 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ Use either `NPM_TOKEN` for token authentication or `NPM_USERNAME`, `NPM_PASSWORD | `npmPublish` | Whether to publish the `npm` package to the registry. If `false` the `package.json` version will still be updated. | `false` if the `package.json` [private](https://docs.npmjs.com/files/package.json#private) property is `true`, `true` otherwise. | | `pkgRoot` | Directory path to publish. | `.` | | `tarballDir` | Directory path in which to write the package tarball. If `false` the tarball is not be kept on the file system. | `false` | +| `publishArgs` | Additional arguments for executing the `npm publish` command. For example, to specify a workspace `['--workspace', 'packages']` | `[]` | +| `versionArgs` | Additional arguments for executing the `npm version` command. For example, to specify a workspace `['--workspace', 'packages']` | `[]` | **Note**: The `pkgRoot` directory must contain a `package.json`. The version will be updated only in the `package.json` and `npm-shrinkwrap.json` within the `pkgRoot` directory. From 3403d17318ef8d904d6d59cdfb66e2144a06fcbe Mon Sep 17 00:00:00 2001 From: 1Aron Date: Wed, 7 Dec 2022 23:47:23 +0800 Subject: [PATCH 3/3] style: `npm run lint -- --fix` --- lib/prepare.js | 11 ++++++++--- lib/publish.js | 3 +-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/prepare.js b/lib/prepare.js index e58d36fd..416bbf61 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -2,15 +2,20 @@ const path = require('path'); const {move} = require('fs-extra'); const execa = require('execa'); -module.exports = async (npmrc, {tarballDir, pkgRoot, versionArgs}, {cwd, env, stdout, stderr, nextRelease: {version}, logger}) => { +module.exports = async ( + npmrc, + {tarballDir, pkgRoot, versionArgs}, + {cwd, env, stdout, stderr, nextRelease: {version}, logger} +) => { const basePath = pkgRoot ? path.resolve(cwd, pkgRoot) : cwd; logger.log('Write version %s to package.json in %s', version, basePath); const versionResult = execa( 'npm', - ['version', version, '--userconfig', npmrc, '--no-git-tag-version', '--allow-same-version'] - .concat(versionArgs || []), + ['version', version, '--userconfig', npmrc, '--no-git-tag-version', '--allow-same-version'].concat( + versionArgs || [] + ), { cwd: basePath, env, diff --git a/lib/publish.js b/lib/publish.js index d9c6017a..44d03571 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -22,8 +22,7 @@ module.exports = async (npmrc, {npmPublish, pkgRoot, publishArgs}, pkg, context) logger.log(`Publishing version ${version} to npm registry on dist-tag ${distTag}`); const result = execa( 'npm', - ['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry] - .concat(publishArgs || []), + ['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry].concat(publishArgs || []), {cwd, env, preferLocal: true} ); result.stdout.pipe(stdout, {end: false});