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

package unpublished and 404 cleanup #4572

Merged
merged 2 commits into from
Mar 17, 2022
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
2 changes: 1 addition & 1 deletion lib/commands/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class View extends BaseCommand {

if (pckmnt.time && pckmnt.time.unpublished) {
const u = pckmnt.time.unpublished
const er = new Error('Unpublished by ' + u.name + ' on ' + u.time)
const er = new Error(`Unpublished on ${u.time}`)
er.statusCode = 404
er.code = 'E404'
er.pkgid = pckmnt._id
Expand Down
7 changes: 1 addition & 6 deletions lib/utils/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,7 @@ module.exports = (er, npm) => {

const valResult = nameValidator(pkg)

if (valResult.validForNewPackages) {
detail.push([
'404',
'You should bug the author to publish it (or use the name yourself!)',
])
} else {
if (!valResult.validForNewPackages) {
detail.push(['404', 'This package name is not valid, because', ''])

const errorsArray = [...(valResult.errors || []), ...(valResult.warnings || [])]
Expand Down
4 changes: 0 additions & 4 deletions tap-snapshots/test/lib/utils/error-message.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ Object {
"",
"'yolo' is not in this registry.",
],
Array [
"404",
"You should bug the author to publish it (or use the name yourself!)",
],
Array [
"404",
String(
Expand Down
7 changes: 5 additions & 2 deletions test/lib/commands/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ const packument = (nv, opts) => {

const mocks = {
red: {
_id: 'red@1.0.1',
name: 'red',
'dist-tags': {
'1.0.1': {},
},
time: {
unpublished: new Date(),
unpublished: {
time: '2012-12-20T00:00:00.000Z',
},
},
},
blue: {
Expand Down Expand Up @@ -533,7 +536,7 @@ t.test('throws when unpublished', async t => {
const view = new View(npm)
await t.rejects(
view.exec(['red']),
{ code: 'E404' }
{ code: 'E404', pkgid: 'red@1.0.1', message: 'Unpublished on 2012-12-20T00:00:00.000Z' }
)
})

Expand Down