diff --git a/lib/commands/ls.js b/lib/commands/ls.js index ac0f4817efec8..2f9c7fca4729c 100644 --- a/lib/commands/ls.js +++ b/lib/commands/ls.js @@ -80,6 +80,7 @@ class LS extends ArboristWorkspaceCmd { const filterBySelectedWorkspaces = edge => { if (!workspacesEnabled && edge.from.isProjectRoot + && edge.to && edge.to.isWorkspace ) { return false diff --git a/tap-snapshots/test/lib/commands/ls.js.test.cjs b/tap-snapshots/test/lib/commands/ls.js.test.cjs index 5ceb233215fc4..f3ce81d65383f 100644 --- a/tap-snapshots/test/lib/commands/ls.js.test.cjs +++ b/tap-snapshots/test/lib/commands/ls.js.test.cjs @@ -549,6 +549,12 @@ test-npm-ls@1.0.0 {CWD}/prefix \`-- dog@1.0.0 ` +exports[`test/lib/commands/ls.js TAP ls no workspaces and missing optional dep > should list missing optional dep and omit workspaces 1`] = ` +root@ {CWD}/prefix ++-- UNMET OPTIONAL DEPENDENCY bar@^1.0.0 +\`-- foo@1.0.0 +` + exports[`test/lib/commands/ls.js TAP ls overridden dep > should contain overridden output 1`] = ` test-overridden@1.0.0 {CWD}/prefix \`-- foo@1.0.0 diff --git a/test/lib/commands/ls.js b/test/lib/commands/ls.js index 9f97d33f8d9ca..f8eb8e011c0b9 100644 --- a/test/lib/commands/ls.js +++ b/test/lib/commands/ls.js @@ -205,6 +205,45 @@ t.test('ls', async t => { t.matchSnapshot(cleanCwd(result()), 'should omit missing optional dep') }) + t.test('no workspaces and missing optional dep', async t => { + const config = { + workspaces: false, + } + const { result, ls } = await mockLs(t, { + config, + prefixDir: { + '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', + }), + }, + }, + }, + }) + + await ls.exec([]) + t.matchSnapshot(cleanCwd(result()), 'should list missing optional dep and omit workspaces') + }) + t.test('extraneous deps', async t => { const { result, ls } = await mockLs(t, { config: {},