Skip to content

Commit e93d3ef

Browse files
committed
fix(unpublish): bubble up all errors parsing local package.json
If the file is there and there is any error that's always a show stopper
1 parent be4741f commit e93d3ef

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/commands/unpublish.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ class Unpublish extends BaseCommand {
109109
const { content } = await pkgJson.prepare(localPrefix)
110110
manifest = content
111111
} catch (err) {
112-
// we needed the manifest to figure out the package to unpublish
113-
if (!spec) {
114-
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
112+
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
113+
// If there was no spec we needed a local package.json
114+
if (!spec) {
115115
throw this.usageError()
116-
} else {
117-
throw err
118116
}
117+
} else {
118+
// folks should know if ANY local package.json had a parsing error.
119+
// They may be relying on `publishConfig` to be loading and we don't
120+
// want to ignore errors in that case.
121+
throw err
119122
}
120123
}
121124

test/lib/commands/unpublish.js

+17
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ t.test('no args --force error reading package.json', async t => {
6363
)
6464
})
6565

66+
t.test('with args --force error reading package.json', async t => {
67+
const { npm } = await loadMockNpm(t, {
68+
config: {
69+
force: true,
70+
},
71+
prefixDir: {
72+
'package.json': '{ not valid json ]',
73+
},
74+
})
75+
76+
await t.rejects(
77+
npm.exec('unpublish', []),
78+
/Invalid package.json/,
79+
'should throw error from reading package.json'
80+
)
81+
})
82+
6683
t.test('no force entire project', async t => {
6784
const { npm } = await loadMockNpm(t)
6885

0 commit comments

Comments
 (0)