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

fix(unpublish): bubble up all errors parsing local package.json #7049

Merged
merged 1 commit into from
Dec 1, 2023
Merged
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
14 changes: 9 additions & 5 deletions lib/commands/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
// 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
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/lib/commands/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
},
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)

Expand Down