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(ls): no error for extraneous deps #3086

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/ls.js
Expand Up @@ -166,7 +166,10 @@ class LS extends BaseCommand {
)
}

if (problems.size) {
const shouldThrow = problems.size &&
![...problems].every(problem => problem.startsWith('extraneous:'))

if (shouldThrow) {
throw Object.assign(
new Error([...problems].join(EOL)),
{ code: 'ELSPROBLEMS' }
Expand Down
12 changes: 0 additions & 12 deletions tap-snapshots/test/lib/ls.js.test.cjs
Expand Up @@ -226,12 +226,6 @@ exports[`test/lib/ls.js TAP ls --parseable json read problems > should print emp
{CWD}/tap-testdir-ls-ls---parseable-json-read-problems
`

exports[`test/lib/ls.js TAP ls --parseable missing package.json > should log all extraneous deps on error msg 1`] = `
extraneous: bar@1.0.0 {CWD}/tap-testdir-ls-ls---parseable-missing-package.json/node_modules/bar
extraneous: foo@1.0.0 {CWD}/tap-testdir-ls-ls---parseable-missing-package.json/node_modules/foo
extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---parseable-missing-package.json/node_modules/lorem
`

exports[`test/lib/ls.js TAP ls --parseable missing package.json > should output parseable missing name/version of top-level package 1`] = `
{CWD}/tap-testdir-ls-ls---parseable-missing-package.json
{CWD}/tap-testdir-ls-ls---parseable-missing-package.json/node_modules/bar
Expand Down Expand Up @@ -458,12 +452,6 @@ filter-by-child-of-missing-dep@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-cont

`

exports[`test/lib/ls.js TAP ls missing package.json > should log all extraneous deps on error msg 1`] = `
extraneous: bar@1.0.0 {CWD}/tap-testdir-ls-ls-missing-package.json/node_modules/bar
extraneous: foo@1.0.0 {CWD}/tap-testdir-ls-ls-missing-package.json/node_modules/foo
extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls-missing-package.json/node_modules/lorem
`

exports[`test/lib/ls.js TAP ls missing package.json > should output tree missing name/version of top-level package 1`] = `
{CWD}/tap-testdir-ls-ls-missing-package.json
+-- bar@1.0.0 extraneous
Expand Down
39 changes: 8 additions & 31 deletions test/lib/ls.js
Expand Up @@ -149,11 +149,7 @@ t.test('ls', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
t.match(err.code, 'ELSPROBLEMS', 'should have ELSPROBLEMS error code')
t.matchSnapshot(
redactCwd(err.message),
'should log all extraneous deps on error msg'
)
t.error(err) // should not error for extraneous
t.matchSnapshot(redactCwd(result), 'should output tree missing name/version of top-level package')
t.end()
})
Expand All @@ -171,12 +167,7 @@ t.test('ls', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
t.equal(
redactCwd(err.message),
'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls-extraneous-deps/node_modules/lorem',
'should log extraneous dep as error'
)
t.error(err) // should not error for extraneous
t.matchSnapshot(redactCwd(result), 'should output containing problems info')
t.end()
})
Expand Down Expand Up @@ -1410,7 +1401,7 @@ t.test('ls', (t) => {
})

ls.exec(['c'], (err) => {
t.match(err.code, 'ELSPROBLEMS', 'should have ELSPROBLEMS error code')
t.error(err) // should not error for extraneous
t.matchSnapshot(redactCwd(result), 'should print tree and not duplicate child of missing items')
t.end()
})
Expand Down Expand Up @@ -1570,11 +1561,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
t.match(err.code, 'ELSPROBLEMS', 'should have ELSPROBLEMS error code')
t.matchSnapshot(
redactCwd(err.message),
'should log all extraneous deps on error msg'
)
t.error(err) // should not error for extraneous
t.matchSnapshot(redactCwd(result), 'should output parseable missing name/version of top-level package')
t.end()
})
Expand All @@ -1592,7 +1579,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
t.error(err) // should not error for extraneous
t.matchSnapshot(redactCwd(result), 'should output containing problems info')
t.end()
})
Expand Down Expand Up @@ -1973,8 +1960,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
t.match(redactCwd(err.message), 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---parseable---long-with-extraneous-deps/node_modules/lorem', 'should have error code')
t.error(err) // should not error for extraneous
t.matchSnapshot(redactCwd(result), 'should output long parseable output with extraneous info')
t.end()
})
Expand Down Expand Up @@ -2414,7 +2400,7 @@ t.test('ls --json', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
t.match(err, { code: 'ELSPROBLEMS' }, 'should list dep problems')
t.error(err) // should not error for extraneous
t.same(
jsonParse(result),
{
Expand Down Expand Up @@ -2470,16 +2456,7 @@ t.test('ls --json', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
t.equal(
redactCwd(err.message),
'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---json-extraneous-deps/node_modules/lorem',
'should log extraneous dep as error'
)
t.equal(
err.code,
'ELSPROBLEMS',
'should have ELSPROBLEMS error code'
)
t.error(err) // should not error for extraneous
t.same(
jsonParse(result),
{
Expand Down