From 52114b75e83db8a5e08f23889cce41c89af9eb93 Mon Sep 17 00:00:00 2001 From: Ruy Adorno <ruyadorno@hotmail.com> Date: Mon, 28 Sep 2020 14:50:15 -0400 Subject: [PATCH] fix: listing deps of a linked dep npm ls was failing to properly follow symlink targets in order to find its dependencies to get printed output. PR-URL: https://github.com/npm/cli/pull/1871 Credit: @ruyadorno Close: #1871 Reviewed-by: @nlf --- lib/ls.js | 2 +- tap-snapshots/test-lib-ls.js-TAP.test.js | 1 + test/lib/ls.js | 13 +++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ls.js b/lib/ls.js index 5ea6e94badb75..d55cdfb455cba 100644 --- a/lib/ls.js +++ b/lib/ls.js @@ -428,7 +428,7 @@ const ls = async (args) => { !(node instanceof Arborist.Node) || (node[_depth] > depthToPrint) return (shouldSkipChildren) ? [] - : [...node.edgesOut.values()] + : [...(node.target || node).edgesOut.values()] .filter(filterByEdgesTypes({ dev, development, diff --git a/tap-snapshots/test-lib-ls.js-TAP.test.js b/tap-snapshots/test-lib-ls.js-TAP.test.js index 6dc4d9a7137dc..cded6fa5a6333 100644 --- a/tap-snapshots/test-lib-ls.js-TAP.test.js +++ b/tap-snapshots/test-lib-ls.js-TAP.test.js @@ -453,6 +453,7 @@ filter-by-child-of-missing-dep@1.0.0 {CWD}/ls-ls-loading-a-tree-containing-works exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should list workspaces properly 1`] = ` filter-by-child-of-missing-dep@1.0.0 {CWD}/ls-ls-loading-a-tree-containing-workspaces +-- a@1.0.0 -> {CWD}/ls-ls-loading-a-tree-containing-workspaces/a +| \`-- c@1.0.0 \`-- b@1.0.0 -> {CWD}/ls-ls-loading-a-tree-containing-workspaces/b ` diff --git a/test/lib/ls.js b/test/lib/ls.js index f968f406fe7be..db4ba81eecc17 100644 --- a/test/lib/ls.js +++ b/test/lib/ls.js @@ -1396,12 +1396,21 @@ t.test('ls', (t) => { }), node_modules: { a: t.fixture('symlink', '../a'), - b: t.fixture('symlink', '../b') + b: t.fixture('symlink', '../b'), + c: { + 'package.json': JSON.stringify({ + name: 'c', + version: '1.0.0' + }) + } }, a: { 'package.json': JSON.stringify({ name: 'a', - version: '1.0.0' + version: '1.0.0', + dependencies: { + c: '^1.0.0' + } }) }, b: {