Skip to content

Commit eac1bf2

Browse files
authored
fix(ls): when filtering workspaces, make sure the edge has a to before checking if its a workspace (#5164)
1 parent 58cc362 commit eac1bf2

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

lib/commands/ls.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class LS extends ArboristWorkspaceCmd {
9292
}
9393

9494
if (this.npm.flatOptions.includeWorkspaceRoot
95-
&& !edge.to.isWorkspace) {
95+
&& edge.to && !edge.to.isWorkspace) {
9696
return true
9797
}
9898

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

+7
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,13 @@ [email protected] {CWD}/tap-testdir-ls-ls-with-no-args-dedupe-entries-and-not
678678
679679
`
680680

681+
exports[`test/lib/commands/ls.js TAP ls workspace and missing optional dep > should omit missing optional dep 1`] = `
682+
root@ {CWD}/tap-testdir-ls-ls-workspace-and-missing-optional-dep
683+
+-- [email protected] -> ./baz
684+
685+
686+
`
687+
681688
exports[`test/lib/commands/ls.js TAP show multiple invalid reasons > ls result 1`] = `
682689
[email protected] {cwd}/tap-testdir-ls-show-multiple-invalid-reasons
683690
+-- [email protected] invalid: "^2.0.0" from the root project

test/lib/commands/ls.js

+38
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,44 @@ t.test('ls', t => {
178178
)
179179
})
180180

181+
t.test('workspace and missing optional dep', async t => {
182+
npm.prefix = npm.localPrefix = t.testdir({
183+
'package.json': JSON.stringify({
184+
name: 'root',
185+
dependencies: {
186+
foo: '^1.0.0',
187+
},
188+
optionalDependencies: {
189+
bar: '^1.0.0',
190+
},
191+
workspaces: ['./baz'],
192+
}),
193+
baz: {
194+
'package.json': JSON.stringify({
195+
name: 'baz',
196+
version: '1.0.0',
197+
}),
198+
},
199+
node_modules: {
200+
baz: t.fixture('symlink', '../baz'),
201+
foo: {
202+
'package.json': JSON.stringify({
203+
name: 'foo',
204+
version: '1.0.0',
205+
}),
206+
},
207+
},
208+
})
209+
210+
npm.flatOptions.includeWorkspaceRoot = true
211+
t.teardown(() => {
212+
delete npm.flatOptions.includeWorkspaceRoot
213+
})
214+
215+
await ls.execWorkspaces([], ['baz'])
216+
t.matchSnapshot(redactCwd(result), 'should omit missing optional dep')
217+
})
218+
181219
t.test('extraneous deps', async t => {
182220
npm.prefix = t.testdir({
183221
'package.json': JSON.stringify({

0 commit comments

Comments
 (0)