From ce4724a3835ded9a4a29d8d67323f925461155e5 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Mon, 19 Oct 2020 08:07:29 +1300 Subject: [PATCH] fix: check `result` when determining exit code of `ls ` PR-URL: https://github.com/npm/cli/pull/1986 Credit: @G-Rath Close: #1986 Reviewed-by: @ruyadorno --- lib/ls.js | 2 +- test/lib/ls.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ls.js b/lib/ls.js index d55cdfb455cba..2dd6e4d4e8ac3 100644 --- a/lib/ls.js +++ b/lib/ls.js @@ -488,7 +488,7 @@ const ls = async (args) => { ) // if filtering items, should exit with error code on no results - if (!tree[_include] && args.length) { + if (result && !result[_include] && args.length) { process.exitCode = 1 } diff --git a/test/lib/ls.js b/test/lib/ls.js index db4ba81eecc17..6a91e8c3520cd 100644 --- a/test/lib/ls.js +++ b/test/lib/ls.js @@ -2476,6 +2476,11 @@ t.test('ls --json', (t) => { }, 'should output json contaning only occurences of filtered by package' ) + t.equal( + process.exitCode, + 0, + 'should exit with error code 0' + ) t.end() }) })