From 19e125ea4acee8110bbee7ae7839a2d2e97b2ca1 Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Sun, 12 Jun 2022 21:45:37 +0200 Subject: [PATCH 01/13] Fixed bug in "npm show" --- lib/commands/view.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/commands/view.js b/lib/commands/view.js index efb298a03bc35..2f04163bbc6f7 100644 --- a/lib/commands/view.js +++ b/lib/commands/view.js @@ -236,6 +236,15 @@ class View extends BaseCommand { } }) + //No data has been pushed because no data is matching the specified version + if (data.length == 0) { + const er = new Error(`No match found for version ${version}`) + er.statusCode = 402 + er.code = 'E404' + er.pkgid = pckmnt._id + throw er + } + if ( !this.npm.config.get('json') && args.length === 1 && From d8afc9f0d5f9752bb64b842a72b218fde86d8809 Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 09:42:48 +0200 Subject: [PATCH 02/13] Update lib/commands/view.js Co-authored-by: Jordan Harband --- lib/commands/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/view.js b/lib/commands/view.js index 2f04163bbc6f7..5e244ebe4b7c9 100644 --- a/lib/commands/view.js +++ b/lib/commands/view.js @@ -239,7 +239,7 @@ class View extends BaseCommand { //No data has been pushed because no data is matching the specified version if (data.length == 0) { const er = new Error(`No match found for version ${version}`) - er.statusCode = 402 + er.statusCode = 404 er.code = 'E404' er.pkgid = pckmnt._id throw er From ad110847ef2573007515f247ca574a620fbf02ad Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 18:04:38 +0200 Subject: [PATCH 03/13] fixed linting errors --- lib/commands/view.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/commands/view.js b/lib/commands/view.js index 2f04163bbc6f7..dbfe837d57698 100644 --- a/lib/commands/view.js +++ b/lib/commands/view.js @@ -218,7 +218,7 @@ class View extends BaseCommand { const versions = pckmnt.versions || {} pckmnt.versions = Object.keys(versions).sort(semver.compareLoose) - // remove readme unless we asked for it + // remove readme unless we asked for it if (args.indexOf('readme') === -1) { delete pckmnt.readme } @@ -236,8 +236,8 @@ class View extends BaseCommand { } }) - //No data has been pushed because no data is matching the specified version - if (data.length == 0) { + // No data has been pushed because no data is matching the specified version + if (data.length === 0) { const er = new Error(`No match found for version ${version}`) er.statusCode = 402 er.code = 'E404' From 2abbd4d8c67f657c729cca8c16f8e164bb90cc77 Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 20:09:05 +0200 Subject: [PATCH 04/13] added check if versions exist --- lib/commands/view.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/commands/view.js b/lib/commands/view.js index dbfe837d57698..172b554d08d61 100644 --- a/lib/commands/view.js +++ b/lib/commands/view.js @@ -237,9 +237,9 @@ class View extends BaseCommand { }) // No data has been pushed because no data is matching the specified version - if (data.length === 0) { + if (data.length === 0 && versions.length !== 0) { const er = new Error(`No match found for version ${version}`) - er.statusCode = 402 + er.statusCode = 404 er.code = 'E404' er.pkgid = pckmnt._id throw er From 8653b05c4618e56ca73d0ca990cf0e44ab33d6b6 Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 20:22:01 +0200 Subject: [PATCH 05/13] changed to check for latest --- lib/commands/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/view.js b/lib/commands/view.js index 172b554d08d61..73cd0e0a423e4 100644 --- a/lib/commands/view.js +++ b/lib/commands/view.js @@ -237,7 +237,7 @@ class View extends BaseCommand { }) // No data has been pushed because no data is matching the specified version - if (data.length === 0 && versions.length !== 0) { + if (data.length === 0 && version !== "latest") { const er = new Error(`No match found for version ${version}`) er.statusCode = 404 er.code = 'E404' From 39df374add92393a1ba3e5bf94d4be4b9bb67d27 Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 20:32:58 +0200 Subject: [PATCH 06/13] Update lib/commands/view.js One space too many Co-authored-by: Jordan Harband --- lib/commands/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/view.js b/lib/commands/view.js index 73cd0e0a423e4..063fd477041e2 100644 --- a/lib/commands/view.js +++ b/lib/commands/view.js @@ -236,7 +236,7 @@ class View extends BaseCommand { } }) - // No data has been pushed because no data is matching the specified version + // No data has been pushed because no data is matching the specified version if (data.length === 0 && version !== "latest") { const er = new Error(`No match found for version ${version}`) er.statusCode = 404 From 10fadbc47854ae36f2ec516694c15a6c4c268a5b Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 21:05:19 +0200 Subject: [PATCH 07/13] Changed double quotes to singles --- lib/commands/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/view.js b/lib/commands/view.js index 063fd477041e2..876e440b7d6b6 100644 --- a/lib/commands/view.js +++ b/lib/commands/view.js @@ -237,7 +237,7 @@ class View extends BaseCommand { }) // No data has been pushed because no data is matching the specified version - if (data.length === 0 && version !== "latest") { + if (data.length === 0 && version !== 'latest') { const er = new Error(`No match found for version ${version}`) er.statusCode = 404 er.code = 'E404' From 7674df27637161828b74f1a2321134fef620f518 Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 22:14:48 +0200 Subject: [PATCH 08/13] Delete 2022-06-12T19_00_57_659Z-debug-0.log --- .../2022-06-12T19_00_57_659Z-debug-0.log | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 test/lib/commands/tap-testdir-config-completion-sandbox/cache/_logs/2022-06-12T19_00_57_659Z-debug-0.log diff --git a/test/lib/commands/tap-testdir-config-completion-sandbox/cache/_logs/2022-06-12T19_00_57_659Z-debug-0.log b/test/lib/commands/tap-testdir-config-completion-sandbox/cache/_logs/2022-06-12T19_00_57_659Z-debug-0.log deleted file mode 100644 index fd347a62464a2..0000000000000 --- a/test/lib/commands/tap-testdir-config-completion-sandbox/cache/_logs/2022-06-12T19_00_57_659Z-debug-0.log +++ /dev/null @@ -1,30 +0,0 @@ -0 timing npm:load:whichnode Completed in 1ms -1 timing config:load:defaults Completed in 0ms -2 timing config:load:file:C:\Users\kuhn-\Documents\Github\npm.cli\npmrc Completed in 2ms -3 timing config:load:builtin Completed in 2ms -4 timing config:load:cli Completed in 2ms -5 timing config:load:env Completed in 0ms -6 timing config:load:file:C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\project\.npmrc Completed in 0ms -7 timing config:load:project Completed in 0ms -8 timing config:load:file:C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\home\.npmrc Completed in 0ms -9 timing config:load:user Completed in 1ms -10 timing config:load:file:C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\global\npmrc Completed in 0ms -11 timing config:load:global Completed in 1ms -12 timing config:load:validate Completed in 0ms -13 timing config:load:credentials Completed in 0ms -14 timing config:load:setEnvs Completed in 0ms -15 timing config:load Completed in 8ms -16 timing npm:load:configload Completed in 8ms -17 timing npm:load:mkdirpcache Completed in 1ms -18 timing npm:load:mkdirplogs Completed in 2ms -19 verbose title npm config -20 verbose argv "--prefix" "C:\\Users\\kuhn-\\Documents\\Github\\npm.cli\\test\\lib\\commands\\tap-testdir-config-completion-sandbox\\project" "--userconfig" "C:\\Users\\kuhn-\\Documents\\Github\\npm.cli\\test\\lib\\commands\\tap-testdir-config-completion-sandbox\\home\\.npmrc" "--globalconfig" "C:\\Users\\kuhn-\\Documents\\Github\\npm.cli\\test\\lib\\commands\\tap-testdir-config-completion-sandbox\\global\\npmrc" "--cache" "C:\\Users\\kuhn-\\Documents\\Github\\npm.cli\\test\\lib\\commands\\tap-testdir-config-completion-sandbox\\cache" "config" -21 timing npm:load:setTitle Completed in 1ms -22 timing config:load:flatten Completed in 4ms -23 timing npm:load:display Completed in 6ms -24 verbose logfile logs-max:10 dir:C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\cache\_logs -25 verbose logfile C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\cache\_logs\2022-06-12T19_00_57_659Z-debug-0.log -26 timing npm:load:logFile Completed in 7ms -27 timing npm:load:timers Completed in 0ms -28 timing npm:load:configScope Completed in 0ms -29 timing npm:load Completed in 27ms From 6739ae73eb1d2805ba03ef824ad59371652b6082 Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 22:15:18 +0200 Subject: [PATCH 09/13] Delete 2022-06-12T19_00_57_809Z-debug-0.log --- .../2022-06-12T19_00_57_809Z-debug-0.log | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 test/lib/commands/tap-testdir-config-completion-sandbox/cache/_logs/2022-06-12T19_00_57_809Z-debug-0.log diff --git a/test/lib/commands/tap-testdir-config-completion-sandbox/cache/_logs/2022-06-12T19_00_57_809Z-debug-0.log b/test/lib/commands/tap-testdir-config-completion-sandbox/cache/_logs/2022-06-12T19_00_57_809Z-debug-0.log deleted file mode 100644 index 40ff620fd9bfb..0000000000000 --- a/test/lib/commands/tap-testdir-config-completion-sandbox/cache/_logs/2022-06-12T19_00_57_809Z-debug-0.log +++ /dev/null @@ -1,30 +0,0 @@ -0 timing npm:load:whichnode Completed in 1ms -1 timing config:load:defaults Completed in 0ms -2 timing config:load:file:C:\Users\kuhn-\Documents\Github\npm.cli\npmrc Completed in 2ms -3 timing config:load:builtin Completed in 2ms -4 timing config:load:cli Completed in 1ms -5 timing config:load:env Completed in 0ms -6 timing config:load:file:C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\project\.npmrc Completed in 1ms -7 timing config:load:project Completed in 1ms -8 timing config:load:file:C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\home\.npmrc Completed in 0ms -9 timing config:load:user Completed in 0ms -10 timing config:load:file:C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\global\npmrc Completed in 0ms -11 timing config:load:global Completed in 0ms -12 timing config:load:validate Completed in 0ms -13 timing config:load:credentials Completed in 0ms -14 timing config:load:setEnvs Completed in 1ms -15 timing config:load Completed in 6ms -16 timing npm:load:configload Completed in 6ms -17 timing npm:load:mkdirpcache Completed in 1ms -18 timing npm:load:mkdirplogs Completed in 1ms -19 verbose title npm config set foo -20 verbose argv "--prefix" "C:\\Users\\kuhn-\\Documents\\Github\\npm.cli\\test\\lib\\commands\\tap-testdir-config-completion-sandbox\\project" "--userconfig" "C:\\Users\\kuhn-\\Documents\\Github\\npm.cli\\test\\lib\\commands\\tap-testdir-config-completion-sandbox\\home\\.npmrc" "--globalconfig" "C:\\Users\\kuhn-\\Documents\\Github\\npm.cli\\test\\lib\\commands\\tap-testdir-config-completion-sandbox\\global\\npmrc" "--cache" "C:\\Users\\kuhn-\\Documents\\Github\\npm.cli\\test\\lib\\commands\\tap-testdir-config-completion-sandbox\\cache" "config" "set" "foo" -21 timing npm:load:setTitle Completed in 2ms -22 timing config:load:flatten Completed in 3ms -23 timing npm:load:display Completed in 4ms -24 verbose logfile logs-max:10 dir:C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\cache\_logs -25 verbose logfile C:\Users\kuhn-\Documents\Github\npm.cli\test\lib\commands\tap-testdir-config-completion-sandbox\cache\_logs\2022-06-12T19_00_57_809Z-debug-0.log -26 timing npm:load:logFile Completed in 4ms -27 timing npm:load:timers Completed in 0ms -28 timing npm:load:configScope Completed in 0ms -29 timing npm:load Completed in 21ms From 3f4290149560d060b4b59dfd5b2f8378b339c2ab Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 22:16:09 +0200 Subject: [PATCH 10/13] Delete package.json --- .../prefix/package.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test/lib/tap-testdir-npm-implicit-workspace-accept/prefix/package.json diff --git a/test/lib/tap-testdir-npm-implicit-workspace-accept/prefix/package.json b/test/lib/tap-testdir-npm-implicit-workspace-accept/prefix/package.json deleted file mode 100644 index c6ed9e019e8b5..0000000000000 --- a/test/lib/tap-testdir-npm-implicit-workspace-accept/prefix/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"root","version":"1.0.0","workspaces":["./packages/a"]} \ No newline at end of file From 6754d605575f163bdd5fce57be8ff892aa4f15e0 Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 22:16:16 +0200 Subject: [PATCH 11/13] Delete package.json --- .../prefix/packages/a/package.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test/lib/tap-testdir-npm-implicit-workspace-accept/prefix/packages/a/package.json diff --git a/test/lib/tap-testdir-npm-implicit-workspace-accept/prefix/packages/a/package.json b/test/lib/tap-testdir-npm-implicit-workspace-accept/prefix/packages/a/package.json deleted file mode 100644 index b59be03f13c8c..0000000000000 --- a/test/lib/tap-testdir-npm-implicit-workspace-accept/prefix/packages/a/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"a","version":"1.0.0","scripts":{"test":"echo test a"}} \ No newline at end of file From 367beb43f925e451304fcf81543d06af5ad9eb33 Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Mon, 13 Jun 2022 22:17:17 +0200 Subject: [PATCH 12/13] changed space for linting --- lib/commands/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/view.js b/lib/commands/view.js index 876e440b7d6b6..0acccc0522d36 100644 --- a/lib/commands/view.js +++ b/lib/commands/view.js @@ -218,7 +218,7 @@ class View extends BaseCommand { const versions = pckmnt.versions || {} pckmnt.versions = Object.keys(versions).sort(semver.compareLoose) - // remove readme unless we asked for it + // remove readme unless we asked for it if (args.indexOf('readme') === -1) { delete pckmnt.readme } From 9ee8be7405826824344c1974328ec5a71cc8c6df Mon Sep 17 00:00:00 2001 From: Lukas Kuhn Date: Tue, 14 Jun 2022 10:59:39 +0200 Subject: [PATCH 13/13] added test coverage for the bug fix --- test/lib/commands/view.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/lib/commands/view.js b/test/lib/commands/view.js index da823db5d7507..c2010f9c78008 100644 --- a/test/lib/commands/view.js +++ b/test/lib/commands/view.js @@ -464,6 +464,15 @@ t.test('throws when unpublished', async t => { ) }) +t.test('throws when version not matched', async t => { + const { npm } = await loadMockNpm(t) + await t.rejects( + npm.exec('view', ['blue@2.0.0']), + { code: 'E404', pkgid: 'blue@2.0.0', message: 'No match found for version 2.0.0' } + ) +}) + + t.test('workspaces', async t => { const prefixDir = { 'package.json': JSON.stringify({