Skip to content

Commit a0900bd

Browse files
authored
fix(ls): respect --include-workspace-root (#4481)
1 parent 45fc297 commit a0900bd

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

lib/commands/ls.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ class LS extends ArboristWorkspaceCmd {
9595
return true
9696
}
9797

98+
if (this.npm.flatOptions.includeWorkspaceRoot
99+
&& !edge.to.isWorkspace) {
100+
return true
101+
}
102+
98103
if (edge.from.isProjectRoot) {
99-
return edge.to &&
100-
edge.to.isWorkspace &&
101-
wsNodes.includes(edge.to.target)
104+
return (edge.to
105+
&& edge.to.isWorkspace
106+
&& wsNodes.includes(edge.to.target))
102107
}
103108

104109
return true

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,15 @@ [email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
504504
505505
`
506506

507+
exports[`test/lib/commands/ls.js TAP ls loading a tree containing workspaces > should inlude root and specified workspace 1`] = `
508+
[email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
509+
510+
511+
512+
513+
514+
`
515+
507516
exports[`test/lib/commands/ls.js TAP ls loading a tree containing workspaces > should list --all workspaces properly 1`] = `
508517
[email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
509518
@@ -515,7 +524,8 @@ [email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
515524
516525
517526
+-- [email protected] -> ./group/e
518-
\`-- [email protected] -> ./group/f
527+
+-- [email protected] -> ./group/f
528+
519529
520530
`
521531

@@ -529,7 +539,8 @@ [email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
529539
530540
531541
+-- [email protected] -> ./group/e
532-
\`-- [email protected] -> ./group/f
542+
+-- [email protected] -> ./group/f
543+
533544
534545
`
535546

@@ -543,13 +554,14 @@ exports[`test/lib/commands/ls.js TAP ls loading a tree containing workspaces > s
543554
+-- [[email protected] -> ./d
544555
| \`-- [email protected]
545556
+-- [[email protected] -> ./group/e
546-
\`-- [[email protected] -> ./group/f
557+
+-- [[email protected] -> ./group/f
558+
\`-- [email protected]
547559

548560
`
549561

550562
exports[`test/lib/commands/ls.js TAP ls loading a tree containing workspaces > should not list workspaces with --no-workspaces 1`] = `
551563
[[email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
552-
[0m\`-- (empty)[0m
564+
553565

554566
`
555567

test/lib/commands/ls.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,7 @@ t.test('ls', t => {
13841384
name: 'workspaces-tree',
13851385
version: '1.0.0',
13861386
workspaces: ['./a', './b', './d', './group/*'],
1387+
dependencies: { pacote: '1.0.0' },
13871388
}),
13881389
node_modules: {
13891390
a: t.fixture('symlink', '../a'),
@@ -1412,6 +1413,9 @@ t.test('ls', t => {
14121413
baz: {
14131414
'package.json': JSON.stringify({ name: 'baz', version: '1.0.0' }),
14141415
},
1416+
pacote: {
1417+
'package.json': JSON.stringify({ name: 'pacote', version: '1.0.0' }),
1418+
},
14151419
},
14161420
a: {
14171421
'package.json': JSON.stringify({
@@ -1469,6 +1473,7 @@ t.test('ls', t => {
14691473
npm.flatOptions.workspacesEnabled = false
14701474
await ls.exec([])
14711475
t.matchSnapshot(redactCwd(result), 'should not list workspaces with --no-workspaces')
1476+
14721477
config.all = true
14731478
config.depth = Infinity
14741479
npm.color = false
@@ -1495,6 +1500,12 @@ t.test('ls', t => {
14951500

14961501
t.matchSnapshot(redactCwd(result), 'should filter using workspace config')
14971502

1503+
// filter out a single workspace and include root
1504+
npm.flatOptions.includeWorkspaceRoot = true
1505+
await ls.execWorkspaces([], ['d'])
1506+
t.matchSnapshot(redactCwd(result), 'should inlude root and specified workspace')
1507+
npm.flatOptions.includeWorkspaceRoot = false
1508+
14981509
// filter out a workspace by parent path
14991510
await ls.execWorkspaces([], ['./group'])
15001511

0 commit comments

Comments
 (0)