From 32acbb3dc0c72353fb2fd7975b2e82d64b7d12a0 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 24 May 2021 09:51:50 -0700 Subject: [PATCH] fixup! ls: show relative paths from root, not absolute --- lib/ls.js | 5 +-- tap-snapshots/test/lib/ls.js.test.cjs | 46 +++++++++++++-------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/ls.js b/lib/ls.js index 7857827fafe12..d92b73ddfcdbb 100644 --- a/lib/ls.js +++ b/lib/ls.js @@ -1,4 +1,5 @@ -const { resolve, relative } = require('path') +const { resolve, relative, sep } = require('path') +const relativePrefix = `.${sep}` const { EOL } = require('os') const archy = require('archy') @@ -324,7 +325,7 @@ const getHumanOutputItem = (node, { args, color, global, long }) => { : '' ) + (isGitNode(node) ? ` (${node.resolved})` : '') + - (node.isLink ? ` -> ${targetLocation}` : '') + + (node.isLink ? ` -> ${relativePrefix}${targetLocation}` : '') + (long ? `${EOL}${node.package.description || ''}` : '') return augmentItemWithIncludeMetadata(node, { label, nodes: [] }) diff --git a/tap-snapshots/test/lib/ls.js.test.cjs b/tap-snapshots/test/lib/ls.js.test.cjs index d960e7846c8d5..2ed0b4b001376 100644 --- a/tap-snapshots/test/lib/ls.js.test.cjs +++ b/tap-snapshots/test/lib/ls.js.test.cjs @@ -70,7 +70,7 @@ test-npm-ls@1.0.0 {CWD}/tap-testdir-ls-ls---dev exports[`test/lib/ls.js TAP ls --link > should output tree containing linked deps 1`] = ` test-npm-ls@1.0.0 {CWD}/tap-testdir-ls-ls---link -\`-- linked-dep@1.0.0 -> linked-dep +\`-- linked-dep@1.0.0 -> ./linked-dep ` @@ -480,24 +480,24 @@ exports[`test/lib/ls.js TAP ls json read problems > should print empty result 1` exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should filter by parent folder workspace config 1`] = ` workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces -+-- e@1.0.0 -> group/e -\`-- f@1.0.0 -> group/f ++-- e@1.0.0 -> ./group/e +\`-- f@1.0.0 -> ./group/f ` exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should filter single workspace 1`] = ` workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces -+-- a@1.0.0 -> a -| \`-- d@1.0.0 deduped -> d -\`-- d@1.0.0 -> d ++-- a@1.0.0 -> ./a +| \`-- d@1.0.0 deduped -> ./d +\`-- d@1.0.0 -> ./d ` exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should filter using workspace config 1`] = ` workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces -\`-- a@1.0.0 -> a +\`-- a@1.0.0 -> ./a +-- c@1.0.0 - \`-- d@1.0.0 -> d + \`-- d@1.0.0 -> ./d \`-- foo@1.1.1 \`-- bar@1.0.0 @@ -505,34 +505,34 @@ workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should list --all workspaces properly 1`] = ` workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces -+-- a@1.0.0 -> a ++-- a@1.0.0 -> ./a | +-- c@1.0.0 -| \`-- d@1.0.0 deduped -> d -+-- b@1.0.0 -> b -+-- d@1.0.0 -> d +| \`-- d@1.0.0 deduped -> ./d ++-- b@1.0.0 -> ./b ++-- d@1.0.0 -> ./d | \`-- foo@1.1.1 | \`-- bar@1.0.0 -+-- e@1.0.0 -> group/e -\`-- f@1.0.0 -> group/f ++-- e@1.0.0 -> ./group/e +\`-- f@1.0.0 -> ./group/f ` exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should list workspaces properly with default configs 1`] = ` workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces -+-- a@1.0.0 -> a ++-- a@1.0.0 -> ./a | +-- c@1.0.0 -| \`-- d@1.0.0 deduped -> d -+-- b@1.0.0 -> b -+-- d@1.0.0 -> d +| \`-- d@1.0.0 deduped -> ./d ++-- b@1.0.0 -> ./b ++-- d@1.0.0 -> ./d | \`-- foo@1.1.1 -+-- e@1.0.0 -> group/e -\`-- f@1.0.0 -> group/f ++-- e@1.0.0 -> ./group/e +\`-- f@1.0.0 -> ./group/f  ` exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should print all tree and filter by dep within only the ws subtree 1`] = ` workspaces-tree@1.0.0 {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces -\`-- d@1.0.0 -> d +\`-- d@1.0.0 -> ./d \`-- foo@1.1.1 \`-- bar@1.0.0 @@ -567,8 +567,8 @@ test-npm-ls@1.0.0 {CWD}/tap-testdir-ls-ls-no-args exports[`test/lib/ls.js TAP ls print deduped symlinks > should output tree containing linked deps 1`] = ` print-deduped-symlinks@1.0.0 {CWD}/tap-testdir-ls-ls-print-deduped-symlinks +-- a@1.0.0 -| \`-- b@1.0.0 deduped -> b -\`-- b@1.0.0 -> b +| \`-- b@1.0.0 deduped -> ./b +\`-- b@1.0.0 -> ./b `