From 1d639807fb8ee2386be5d982015dd7f462d57fdb Mon Sep 17 00:00:00 2001 From: lazerg Date: Fri, 23 Oct 2026 14:37:36 +0500 Subject: [PATCH 1/2] fix(ls): handle missing root deps with --workspaces=false --- lib/commands/ls.js | 1 + .../test/lib/commands/ls.js.test.cjs | 6 +++ test/lib/commands/ls.js | 39 +++++++++++++++++++ 3 files changed, 46 insertions(+) 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..d19c9b4dcf9e3 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 omit missing optional dep and 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..7e0d17d4fe4db 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 omit missing optional dep and workspaces') + }) + t.test('extraneous deps', async t => { const { result, ls } = await mockLs(t, { config: {}, From aa70859fb95a0aa0aae3ea67350cde02835c899b Mon Sep 17 00:00:00 2001 From: lazerg Date: Fri, 23 Oct 2026 14:49:46 +0500 Subject: [PATCH 2/2] test(ls): fix snapshot label for --workspaces=false missing dep test --- tap-snapshots/test/lib/commands/ls.js.test.cjs | 2 +- test/lib/commands/ls.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tap-snapshots/test/lib/commands/ls.js.test.cjs b/tap-snapshots/test/lib/commands/ls.js.test.cjs index d19c9b4dcf9e3..f3ce81d65383f 100644 --- a/tap-snapshots/test/lib/commands/ls.js.test.cjs +++ b/tap-snapshots/test/lib/commands/ls.js.test.cjs @@ -549,7 +549,7 @@ 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 omit missing optional dep and workspaces 1`] = ` +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 diff --git a/test/lib/commands/ls.js b/test/lib/commands/ls.js index 7e0d17d4fe4db..f8eb8e011c0b9 100644 --- a/test/lib/commands/ls.js +++ b/test/lib/commands/ls.js @@ -241,7 +241,7 @@ t.test('ls', async t => { }) await ls.exec([]) - t.matchSnapshot(cleanCwd(result()), 'should omit missing optional dep and workspaces') + t.matchSnapshot(cleanCwd(result()), 'should list missing optional dep and omit workspaces') }) t.test('extraneous deps', async t => {