Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: npm ls now respects --include-workspace-root #4481

Merged
merged 2 commits into from
Mar 2, 2022
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
fritzy marked this conversation as resolved.
Show resolved Hide resolved
&& 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