From 6fe2bdc25e7961956e5c0067fa4db54ff1bd0dbd Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Tue, 21 Jul 2020 12:36:23 -0400 Subject: [PATCH] fix: npm ls --parseable --long output PR-URL: https://github.com/npm/cli/pull/1547 Credit: @ruyadorno Close: #1547 Reviewed-by: @claudiahdz --- lib/ls.js | 2 +- test/tap/ls.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/ls.js b/lib/ls.js index 78a2b1d791c7d..c333f236bad31 100644 --- a/lib/ls.js +++ b/lib/ls.js @@ -545,7 +545,7 @@ function makeParseable_ (data, long, dir, depth, parent, d) { return data.path + ':' + (data._id || '') + - ':' + (data.realPath !== data.path ? data.realPath : '') + + (data.link && data.link !== data.path ? ':' + data.link : '') + (data.extraneous ? ':EXTRANEOUS' : '') + (data.error && data.path !== path.resolve(npm.globalDir, '..') ? ':ERROR' : '') + (data.invalid ? ':INVALID' : '') + diff --git a/test/tap/ls.js b/test/tap/ls.js index b3bdbc613cbc8..9dd3779b3d170 100644 --- a/test/tap/ls.js +++ b/test/tap/ls.js @@ -169,6 +169,40 @@ test('cleanup', function (t) { t.done() }) +test('ls parseable long', function (t) { + var fixture = new Tacks( + Dir({ + 'npm-test-ls': Dir({ + 'package.json': File({ + name: 'npm-test-ls', + version: '1.0.0', + dependencies: { + 'dep': 'file:../dep' + } + }) + }), + 'dep': Dir({ + 'package.json': File({ + name: 'dep', + version: '1.0.0' + }) + }) + }) + ) + withFixture(t, fixture, function (done) { + common.npm([ + 'ls', '--parseable', '--long' + ], { + cwd: pkgpath + }, function (err, code, stdout, stderr) { + t.ifErr(err, 'ls succeeded') + t.equal(0, code, 'exit 0 on ls') + t.notMatch(stdout, /undefined/, 'must not output undefined for non-symlinked items') + done() + }) + }) +}) + function withFixture (t, fixture, tester) { fixture.create(fixturepath) common.npm(['install'], {