diff options
author | Ruy Adorno <ruyadorno@hotmail.com> | 2021-05-21 20:22:51 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-05-27 17:24:12 +0300 |
commit | 4a4fbe33c51413adcd558b4af6f1e204b1b87e41 (patch) | |
tree | af8624d65414bfcf89c68e5ebfcc2aa5b8170201 /lib | |
parent | 64b13dd1082b6ca7eac4e8e329bfdd8cd8daf157 (diff) |
fix(publish): skip private workspaces
Allow users to publish all workspaces with `npm publish --ws` while also
skipping any workspace that might have been intentionally marked as
private, using `"private": true` in its package.json file.
Fixes: https://github.com/npm/cli/issues/3268
PR-URL: https://github.com/npm/cli/pull/3285
Credit: @ruyadorno
Close: #3285
Reviewed-by: @wraithgar
Diffstat (limited to 'lib')
-rw-r--r-- | lib/publish.js | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/publish.js b/lib/publish.js index 1693ea7d9..3cb8b0627 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -7,6 +7,7 @@ const runScript = require('@npmcli/run-script') const pacote = require('pacote') const npa = require('npm-package-arg') const npmFetch = require('npm-registry-fetch') +const chalk = require('chalk') const otplease = require('./utils/otplease.js') const { getContents, logTar } = require('./utils/tar.js') @@ -154,10 +155,29 @@ class Publish extends BaseCommand { const results = {} const json = this.npm.config.get('json') const silent = log.level === 'silent' + const noop = a => a + const color = this.npm.color ? chalk : { green: noop, bold: noop } const workspaces = await getWorkspaces(filters, { path: this.npm.localPrefix }) + for (const [name, workspace] of workspaces.entries()) { - const pkgContents = await this.publish([workspace]) + let pkgContents + try { + pkgContents = await this.publish([workspace]) + } catch (err) { + if (err.code === 'EPRIVATE') { + log.warn( + 'publish', + `Skipping workspace ${ + color.green(name) + }, marked as ${ + color.bold('private') + }` + ) + continue + } + throw err + } // This needs to be in-line w/ the rest of the output that non-JSON // publish generates if (!silent && !json) |