Skip to content

Commit

Permalink
fix(ls): respect --include-workspace-root (#4481)
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzy committed Mar 2, 2022
1 parent 45fc297 commit a0900bd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
11 changes: 8 additions & 3 deletions lib/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ class LS extends ArboristWorkspaceCmd {
return true
}

if (this.npm.flatOptions.includeWorkspaceRoot
&& !edge.to.isWorkspace) {
return true
}

if (edge.from.isProjectRoot) {
return edge.to &&
edge.to.isWorkspace &&
wsNodes.includes(edge.to.target)
return (edge.to
&& edge.to.isWorkspace
&& wsNodes.includes(edge.to.target))
}

return true
Expand Down
20 changes: 16 additions & 4 deletions tap-snapshots/test/lib/commands/ls.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,15 @@ workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
`

exports[`test/lib/commands/ls.js TAP ls loading a tree containing workspaces > should inlude root and specified workspace 1`] = `
workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
+-- d@1.0.0 -> ./d
| \`-- foo@1.1.1
| \`-- bar@1.0.0
\`-- pacote@1.0.0
`

exports[`test/lib/commands/ls.js TAP ls loading a tree containing workspaces > should list --all workspaces properly 1`] = `
workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
+-- a@1.0.0 -> ./a
Expand All @@ -515,7 +524,8 @@ workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
| \`-- foo@1.1.1
| \`-- bar@1.0.0
+-- e@1.0.0 -> ./group/e
\`-- f@1.0.0 -> ./group/f
+-- f@1.0.0 -> ./group/f
\`-- pacote@1.0.0
`

Expand All @@ -529,7 +539,8 @@ workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
| \`-- foo@1.1.1
| \`-- bar@1.0.0
+-- e@1.0.0 -> ./group/e
\`-- f@1.0.0 -> ./group/f
+-- f@1.0.0 -> ./group/f
\`-- pacote@1.0.0
`

Expand All @@ -543,13 +554,14 @@ exports[`test/lib/commands/ls.js TAP ls loading a tree containing workspaces > s
+-- d@1.0.0 -> ./d
| \`-- foo@1.1.1
+-- e@1.0.0 -> ./group/e
\`-- f@1.0.0 -> ./group/f
+-- f@1.0.0 -> ./group/f
\`-- pacote@1.0.0

`

exports[`test/lib/commands/ls.js TAP ls loading a tree containing workspaces > should not list workspaces with --no-workspaces 1`] = `
workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
[0m\`-- (empty)[0m
[0m\`-- pacote@1.0.0[0m

`

Expand Down
11 changes: 11 additions & 0 deletions test/lib/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,7 @@ t.test('ls', t => {
name: 'workspaces-tree',
version: '1.0.0',
workspaces: ['./a', './b', './d', './group/*'],
dependencies: { pacote: '1.0.0' },
}),
node_modules: {
a: t.fixture('symlink', '../a'),
Expand Down Expand Up @@ -1412,6 +1413,9 @@ t.test('ls', t => {
baz: {
'package.json': JSON.stringify({ name: 'baz', version: '1.0.0' }),
},
pacote: {
'package.json': JSON.stringify({ name: 'pacote', version: '1.0.0' }),
},
},
a: {
'package.json': JSON.stringify({
Expand Down Expand Up @@ -1469,6 +1473,7 @@ t.test('ls', t => {
npm.flatOptions.workspacesEnabled = false
await ls.exec([])
t.matchSnapshot(redactCwd(result), 'should not list workspaces with --no-workspaces')

config.all = true
config.depth = Infinity
npm.color = false
Expand All @@ -1495,6 +1500,12 @@ t.test('ls', t => {

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

// filter out a single workspace and include root
npm.flatOptions.includeWorkspaceRoot = true
await ls.execWorkspaces([], ['d'])
t.matchSnapshot(redactCwd(result), 'should inlude root and specified workspace')
npm.flatOptions.includeWorkspaceRoot = false

// filter out a workspace by parent path
await ls.execWorkspaces([], ['./group'])

Expand Down

0 comments on commit a0900bd

Please sign in to comment.