Skip to content

Commit 42ca59e

Browse files
nlfruyadorno
authored andcommitted
fix(ls): do not exit with error when all problems are extraneous deps
PR-URL: #3086 Credit: @nlf Close: #3086 Reviewed-by: @wraithgar, @ruyadorno
1 parent a4e7f4e commit 42ca59e

File tree

3 files changed

+12
-44
lines changed

3 files changed

+12
-44
lines changed

lib/ls.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ class LS extends BaseCommand {
166166
)
167167
}
168168

169-
if (problems.size) {
169+
const shouldThrow = problems.size &&
170+
![...problems].every(problem => problem.startsWith('extraneous:'))
171+
172+
if (shouldThrow) {
170173
throw Object.assign(
171174
new Error([...problems].join(EOL)),
172175
{ code: 'ELSPROBLEMS' }

tap-snapshots/test/lib/ls.js.test.cjs

-12
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,6 @@ exports[`test/lib/ls.js TAP ls --parseable json read problems > should print emp
226226
{CWD}/tap-testdir-ls-ls---parseable-json-read-problems
227227
`
228228

229-
exports[`test/lib/ls.js TAP ls --parseable missing package.json > should log all extraneous deps on error msg 1`] = `
230-
extraneous: [email protected] {CWD}/tap-testdir-ls-ls---parseable-missing-package.json/node_modules/bar
231-
extraneous: [email protected] {CWD}/tap-testdir-ls-ls---parseable-missing-package.json/node_modules/foo
232-
extraneous: [email protected] {CWD}/tap-testdir-ls-ls---parseable-missing-package.json/node_modules/lorem
233-
`
234-
235229
exports[`test/lib/ls.js TAP ls --parseable missing package.json > should output parseable missing name/version of top-level package 1`] = `
236230
{CWD}/tap-testdir-ls-ls---parseable-missing-package.json
237231
{CWD}/tap-testdir-ls-ls---parseable-missing-package.json/node_modules/bar
@@ -458,12 +452,6 @@ [email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-cont
458452
459453
`
460454

461-
exports[`test/lib/ls.js TAP ls missing package.json > should log all extraneous deps on error msg 1`] = `
462-
extraneous: [email protected] {CWD}/tap-testdir-ls-ls-missing-package.json/node_modules/bar
463-
extraneous: [email protected] {CWD}/tap-testdir-ls-ls-missing-package.json/node_modules/foo
464-
extraneous: [email protected] {CWD}/tap-testdir-ls-ls-missing-package.json/node_modules/lorem
465-
`
466-
467455
exports[`test/lib/ls.js TAP ls missing package.json > should output tree missing name/version of top-level package 1`] = `
468456
{CWD}/tap-testdir-ls-ls-missing-package.json
469457
+-- [email protected] extraneous

test/lib/ls.js

+8-31
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ t.test('ls', (t) => {
149149
...simpleNmFixture,
150150
})
151151
ls.exec([], (err) => {
152-
t.match(err.code, 'ELSPROBLEMS', 'should have ELSPROBLEMS error code')
153-
t.matchSnapshot(
154-
redactCwd(err.message),
155-
'should log all extraneous deps on error msg'
156-
)
152+
t.error(err) // should not error for extraneous
157153
t.matchSnapshot(redactCwd(result), 'should output tree missing name/version of top-level package')
158154
t.end()
159155
})
@@ -171,12 +167,7 @@ t.test('ls', (t) => {
171167
...simpleNmFixture,
172168
})
173169
ls.exec([], (err) => {
174-
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
175-
t.equal(
176-
redactCwd(err.message),
177-
'extraneous: [email protected] {CWD}/tap-testdir-ls-ls-extraneous-deps/node_modules/lorem',
178-
'should log extraneous dep as error'
179-
)
170+
t.error(err) // should not error for extraneous
180171
t.matchSnapshot(redactCwd(result), 'should output containing problems info')
181172
t.end()
182173
})
@@ -1410,7 +1401,7 @@ t.test('ls', (t) => {
14101401
})
14111402

14121403
ls.exec(['c'], (err) => {
1413-
t.match(err.code, 'ELSPROBLEMS', 'should have ELSPROBLEMS error code')
1404+
t.error(err) // should not error for extraneous
14141405
t.matchSnapshot(redactCwd(result), 'should print tree and not duplicate child of missing items')
14151406
t.end()
14161407
})
@@ -1570,11 +1561,7 @@ t.test('ls --parseable', (t) => {
15701561
...simpleNmFixture,
15711562
})
15721563
ls.exec([], (err) => {
1573-
t.match(err.code, 'ELSPROBLEMS', 'should have ELSPROBLEMS error code')
1574-
t.matchSnapshot(
1575-
redactCwd(err.message),
1576-
'should log all extraneous deps on error msg'
1577-
)
1564+
t.error(err) // should not error for extraneous
15781565
t.matchSnapshot(redactCwd(result), 'should output parseable missing name/version of top-level package')
15791566
t.end()
15801567
})
@@ -1592,7 +1579,7 @@ t.test('ls --parseable', (t) => {
15921579
...simpleNmFixture,
15931580
})
15941581
ls.exec([], (err) => {
1595-
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
1582+
t.error(err) // should not error for extraneous
15961583
t.matchSnapshot(redactCwd(result), 'should output containing problems info')
15971584
t.end()
15981585
})
@@ -1973,8 +1960,7 @@ t.test('ls --parseable', (t) => {
19731960
...simpleNmFixture,
19741961
})
19751962
ls.exec([], (err) => {
1976-
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
1977-
t.match(redactCwd(err.message), 'extraneous: [email protected] {CWD}/tap-testdir-ls-ls---parseable---long-with-extraneous-deps/node_modules/lorem', 'should have error code')
1963+
t.error(err) // should not error for extraneous
19781964
t.matchSnapshot(redactCwd(result), 'should output long parseable output with extraneous info')
19791965
t.end()
19801966
})
@@ -2414,7 +2400,7 @@ t.test('ls --json', (t) => {
24142400
...simpleNmFixture,
24152401
})
24162402
ls.exec([], (err) => {
2417-
t.match(err, { code: 'ELSPROBLEMS' }, 'should list dep problems')
2403+
t.error(err) // should not error for extraneous
24182404
t.same(
24192405
jsonParse(result),
24202406
{
@@ -2470,16 +2456,7 @@ t.test('ls --json', (t) => {
24702456
...simpleNmFixture,
24712457
})
24722458
ls.exec([], (err) => {
2473-
t.equal(
2474-
redactCwd(err.message),
2475-
'extraneous: [email protected] {CWD}/tap-testdir-ls-ls---json-extraneous-deps/node_modules/lorem',
2476-
'should log extraneous dep as error'
2477-
)
2478-
t.equal(
2479-
err.code,
2480-
'ELSPROBLEMS',
2481-
'should have ELSPROBLEMS error code'
2482-
)
2459+
t.error(err) // should not error for extraneous
24832460
t.same(
24842461
jsonParse(result),
24852462
{

0 commit comments

Comments
 (0)