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: additional arguments publishArgs and versionArgs for npm commands #534

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 8 additions & 2 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ 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,
Expand Down
4 changes: 2 additions & 2 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,7 +22,7 @@ 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});
Expand Down