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: when filtering workspaces, make sure the edge has a to before checking if its a workspace #5164

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class LS extends ArboristWorkspaceCmd {
}

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

Expand Down
7 changes: 7 additions & 0 deletions tap-snapshots/test/lib/commands/ls.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,13 @@ [email protected] {CWD}/tap-testdir-ls-ls-with-no-args-dedupe-entries-and-not

`

exports[`test/lib/commands/ls.js TAP ls workspace and missing optional dep > should omit missing optional dep 1`] = `
root@ {CWD}/tap-testdir-ls-ls-workspace-and-missing-optional-dep
+-- [email protected] -> ./baz
\`-- [email protected]

`

exports[`test/lib/commands/ls.js TAP show multiple invalid reasons > ls result 1`] = `
[email protected] {cwd}/tap-testdir-ls-show-multiple-invalid-reasons
+-- [email protected] invalid: "^2.0.0" from the root project
Expand Down
38 changes: 38 additions & 0 deletions test/lib/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,44 @@ t.test('ls', t => {
)
})

t.test('workspace and missing optional dep', async t => {
npm.prefix = npm.localPrefix = t.testdir({
'package.json': JSON.stringify({
name: 'root',
dependencies: {
foo: '^1.0.0',
},
optionalDependencies: {
bar: '^1.0.0',
},
workspaces: ['./baz'],
}),
baz: {
'package.json': JSON.stringify({
name: 'baz',
version: '1.0.0',
}),
},
node_modules: {
baz: t.fixture('symlink', '../baz'),
foo: {
'package.json': JSON.stringify({
name: 'foo',
version: '1.0.0',
}),
},
},
})

npm.flatOptions.includeWorkspaceRoot = true
t.teardown(() => {
delete npm.flatOptions.includeWorkspaceRoot
})

await ls.execWorkspaces([], ['baz'])
t.matchSnapshot(redactCwd(result), 'should omit missing optional dep')
})

t.test('extraneous deps', async t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
Expand Down