diff --git a/lib/commands/unpublish.js b/lib/commands/unpublish.js index f5568a3540e12..a9c20900534c3 100644 --- a/lib/commands/unpublish.js +++ b/lib/commands/unpublish.js @@ -109,13 +109,17 @@ class Unpublish extends BaseCommand { const { content } = await pkgJson.prepare(localPrefix) manifest = content } catch (err) { - // we needed the manifest to figure out the package to unpublish - if (!spec) { - if (err.code === 'ENOENT' || err.code === 'ENOTDIR') { + if (err.code === 'ENOENT' || err.code === 'ENOTDIR') { + if (!spec) { + // We needed a local package.json to figure out what package to + // unpublish throw this.usageError() - } else { - throw err } + } else { + // folks should know if ANY local package.json had a parsing error. + // They may be relying on `publishConfig` to be loading and we don't + // want to ignore errors in that case. + throw err } } diff --git a/test/lib/commands/unpublish.js b/test/lib/commands/unpublish.js index 044b2cf8c546a..097309393a258 100644 --- a/test/lib/commands/unpublish.js +++ b/test/lib/commands/unpublish.js @@ -63,6 +63,23 @@ t.test('no args --force error reading package.json', async t => { ) }) +t.test('with args --force error reading package.json', async t => { + const { npm } = await loadMockNpm(t, { + config: { + force: true, + }, + prefixDir: { + 'package.json': '{ not valid json ]', + }, + }) + + await t.rejects( + npm.exec('unpublish', [pkg]), + /Invalid package.json/, + 'should throw error from reading package.json' + ) +}) + t.test('no force entire project', async t => { const { npm } = await loadMockNpm(t)