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() }) })