Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ class LS extends ArboristWorkspaceCmd {
}

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))
|| (this.npm.flatOptions.includeWorkspaceRoot
&& !edge.to.isWorkspace)
}

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 @@ [email protected] {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`] = `
[email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
+-- [email protected] -> ./d
| \`-- [email protected]
| \`-- [email protected]
\`-- [email protected]

`

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

`

Expand All @@ -529,7 +539,8 @@ [email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
| \`-- [email protected]
| \`-- [email protected]
+-- [email protected] -> ./group/e
\`-- [email protected] -> ./group/f
+-- [email protected] -> ./group/f
\`-- [email protected]

`

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

`

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

`

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