From b890f043e51aa1003e46a3322c84799468117e61 Mon Sep 17 00:00:00 2001 From: nlf Date: Wed, 13 Jul 2022 15:22:37 -0700 Subject: [PATCH] fix: when filtering workspaces, make sure the edge has a to before checking if its a workspace --- lib/commands/ls.js | 2 +- .../test/lib/commands/ls.js.test.cjs | 7 ++++ test/lib/commands/ls.js | 38 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/commands/ls.js b/lib/commands/ls.js index d3932072b7d34..073ca0c6992e8 100644 --- a/lib/commands/ls.js +++ b/lib/commands/ls.js @@ -92,7 +92,7 @@ class LS extends ArboristWorkspaceCmd { } if (this.npm.flatOptions.includeWorkspaceRoot - && !edge.to.isWorkspace) { + && edge.to && !edge.to.isWorkspace) { return true } diff --git a/tap-snapshots/test/lib/commands/ls.js.test.cjs b/tap-snapshots/test/lib/commands/ls.js.test.cjs index a10d37ab92881..9b6749acfe3bb 100644 --- a/tap-snapshots/test/lib/commands/ls.js.test.cjs +++ b/tap-snapshots/test/lib/commands/ls.js.test.cjs @@ -678,6 +678,13 @@ dedupe-entries@1.0.0 {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 ++-- baz@1.0.0 -> ./baz +\`-- foo@1.0.0 + +` + exports[`test/lib/commands/ls.js TAP show multiple invalid reasons > ls result 1`] = ` test-npm-ls@1.0.0 {cwd}/tap-testdir-ls-show-multiple-invalid-reasons +-- cat@1.0.0 invalid: "^2.0.0" from the root project diff --git a/test/lib/commands/ls.js b/test/lib/commands/ls.js index 412d5ce6532a0..f4cd4ef33d58e 100644 --- a/test/lib/commands/ls.js +++ b/test/lib/commands/ls.js @@ -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({