From 013f0262db3e16605820f6117749fd3ebc70f6d1 Mon Sep 17 00:00:00 2001 From: Gar Date: Fri, 25 Jun 2021 07:14:40 -0700 Subject: [PATCH 1/9] fix(exitHandler): write code to logfile This moves the logging of the exit code to before the logfile is written, when the exit handler was not called. This will ensure that the code shows up in the debug logs. PR-URL: https://github.com/npm/cli/pull/3469 Credit: @wraithgar Close: #3469 Reviewed-by: @isaacs --- lib/utils/exit-handler.js | 4 +--- .../test/lib/utils/exit-handler.js.test.cjs | 23 ++++++++----------- test/lib/utils/exit-handler.js | 4 ++++ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/utils/exit-handler.js b/lib/utils/exit-handler.js index dc499f526a208..931527704b9b7 100644 --- a/lib/utils/exit-handler.js +++ b/lib/utils/exit-handler.js @@ -58,6 +58,7 @@ process.on('exit', code => { if (!code) log.info('ok') else { + log.verbose('code', code) if (!exitHandlerCalled) { log.error('', 'Exit handler never called!') console.error('') @@ -66,7 +67,6 @@ process.on('exit', code => { // TODO this doesn't have an npm.config.loaded guard writeLogFile() } - log.verbose('code', code) } // In timing mode we always write the log file if (npm.config && npm.config.loaded && npm.config.get('timing') && !wroteLogFile) @@ -107,8 +107,6 @@ const exit = (code, noLog) => { // background at this point, and this makes sure anything left dangling // for whatever reason gets thrown away, instead of leaving the CLI open process.stdout.write('', () => { - // `|| process.exitCode` supports a single use case, where we set the exit - // code to 1 if npm is called with no arguments process.exit(code) }) } diff --git a/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs b/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs index 0a5ed59a1157c..8cea8ee17e5ea 100644 --- a/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs +++ b/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs @@ -6,18 +6,15 @@ */ 'use strict' exports[`test/lib/utils/exit-handler.js TAP handles unknown error > should have expected log contents for unknown error 1`] = ` -0 verbose code 1 -1 error foo A complete log of this run can be found in: -1 error foo {CWD}/test/lib/utils/tap-testdir-exit-handler/_logs/expecteddate-debug.log -2 verbose stack Error: ERROR -3 verbose cwd {CWD} -4 verbose Foo 1.0.0 -5 verbose argv "/node" "{CWD}/test/lib/utils/exit-handler.js" -6 verbose node v1.0.0 -7 verbose npm v1.0.0 -8 error foo code ERROR -9 error foo ERR ERROR -10 error foo ERR ERROR -11 verbose exit 1 +0 verbose stack Error: ERROR +1 verbose cwd {CWD} +2 verbose Foo 1.0.0 +3 verbose argv "/node" "{CWD}/test/lib/utils/exit-handler.js" +4 verbose node v1.0.0 +5 verbose npm v1.0.0 +6 error foo code ERROR +7 error foo ERR ERROR +8 error foo ERR ERROR +9 verbose exit 1 ` diff --git a/test/lib/utils/exit-handler.js b/test/lib/utils/exit-handler.js index 72f94bfded7b0..06014b67a9754 100644 --- a/test/lib/utils/exit-handler.js +++ b/test/lib/utils/exit-handler.js @@ -109,6 +109,10 @@ process = Object.assign( // in order for tap to exit properly t.teardown(() => { process = _process +}) + +t.afterEach(() => { + // clear out the 'A complete log' message npmlog.record.length = 0 }) From 0dd0341ac9a65a2df8fc262ad9a56b7351f99d66 Mon Sep 17 00:00:00 2001 From: Aluneed <31174087+aluneed@users.noreply.github.com> Date: Mon, 28 Jun 2021 16:53:09 +0800 Subject: [PATCH 2/9] fix(ping): make "npm ping" echo a right time There is no need to make the time divided by 1000 because of the time unit 'ms'. Currently a typical command and response: PS C:\projects> npm ping npm notice PING http://registry.npmjs.org/ npm notice PONG 0.752ms PR-URL: https://github.com/npm/cli/pull/3474 Credit: @aluneed Close: #3474 Reviewed-by: @wraithgar --- lib/ping.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ping.js b/lib/ping.js index 30379377482ec..fbfb177ff87fc 100644 --- a/lib/ping.js +++ b/lib/ping.js @@ -27,7 +27,7 @@ class Ping extends BaseCommand { const start = Date.now() const details = await pingUtil(this.npm.flatOptions) const time = Date.now() - start - log.notice('PONG', `${time / 1000}ms`) + log.notice('PONG', `${time}ms`) if (this.npm.config.get('json')) { this.npm.output(JSON.stringify({ registry: this.npm.config.get('registry'), From d2e298f3cbab278071480f94ff7d916d42cbf43b Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 30 Jun 2021 09:26:57 -0700 Subject: [PATCH 3/9] fix(deprecate): add undeprecate support Setting a deprecation of an empty string is the way to un-deprecate a package, this was accidentally broken in a past refactoring, and is now re-added with a test to ensure it is allowed. PR-URL: https://github.com/npm/cli/pull/3484 Credit: @wraithgar Close: #3484 Reviewed-by: @isaacs --- lib/deprecate.js | 3 ++- test/lib/deprecate.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/deprecate.js b/lib/deprecate.js index ece55e1f40243..156bbf875ea42 100644 --- a/lib/deprecate.js +++ b/lib/deprecate.js @@ -49,7 +49,8 @@ class Deprecate extends BaseCommand { } async deprecate ([pkg, msg]) { - if (!pkg || !msg) + // msg == null becase '' is a valid value, it indicates undeprecate + if (!pkg || msg == null) throw this.usageError() // fetch the data and make sure it exists. diff --git a/test/lib/deprecate.js b/test/lib/deprecate.js index c358fde247955..a69ef6c7796fc 100644 --- a/test/lib/deprecate.js +++ b/test/lib/deprecate.js @@ -78,6 +78,21 @@ t.test('invalid semver range', t => { }) }) +t.test('undeprecate', t => { + deprecate.exec(['foo', ''], (err) => { + if (err) + throw err + t.match(npmFetchBody, { + versions: { + '1.0.0': { deprecated: '' }, + '1.0.1': { deprecated: '' }, + '1.0.1-pre': { deprecated: '' }, + }, + }, 'undeprecates everything') + t.end() + }) +}) + t.test('deprecates given range', t => { t.teardown(() => { npmFetchBody = null From 5f8ccccef9fc19229320df8cbcae9fcea8d31388 Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 30 Jun 2021 08:40:58 -0700 Subject: [PATCH 4/9] chore(tests): clean snapshot for lib/view.js tests Closes https://github.com/npm/cli/issues/1623 PR-URL: https://github.com/npm/cli/pull/3483 Credit: @wraithgar Close: #3483 Reviewed-by: @isaacs --- tap-snapshots/test/lib/view.js.test.cjs | 6 +++--- test/lib/view.js | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tap-snapshots/test/lib/view.js.test.cjs b/tap-snapshots/test/lib/view.js.test.cjs index 9aafe50e41896..41d7a80fe3b16 100644 --- a/tap-snapshots/test/lib/view.js.test.cjs +++ b/tap-snapshots/test/lib/view.js.test.cjs @@ -82,7 +82,7 @@ dist dist-tags: latest: 1.0.0 -published a year ago +published {TIME} ago ` exports[`test/lib/view.js TAP should log info of package in current working dir specific version > must match snapshot 1`] = ` @@ -99,7 +99,7 @@ dist dist-tags: latest: 1.0.0 -published a year ago +published {TIME} ago ` exports[`test/lib/view.js TAP should log package info package from git > must match snapshot 1`] = ` @@ -302,7 +302,7 @@ dist dist-tags: latest: 1.0.0 -published a year ago +published {TIME} ago ` exports[`test/lib/view.js TAP workspaces all workspaces --json > must match snapshot 1`] = ` diff --git a/test/lib/view.js b/test/lib/view.js index 5f2e5a8add5e9..793917adc6476 100644 --- a/test/lib/view.js +++ b/test/lib/view.js @@ -1,5 +1,7 @@ const t = require('tap') +t.cleanSnapshot = str => str.replace(/published .*? ago/g, 'published {TIME} ago') + // run the same as tap does when running directly with node process.stdout.columns = undefined From 9dd32d08e09c21c9a4517161abfc7eed6518faf2 Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 30 Jun 2021 13:38:18 -0700 Subject: [PATCH 5/9] fix(docs): remove npm package config override This is no longer possible, as per [rfc 21](https://github.com/npm/rfcs/blob/latest/implemented/0021-reduce-lifecycle-script-environment.md) PR-URL: https://github.com/npm/cli/pull/3485 Credit: @wraithgar Close: #3485 Reviewed-by: @isaacs --- docs/content/configuring-npm/package-json.md | 8 ++--- docs/content/using-npm/scripts.md | 36 +------------------- 2 files changed, 3 insertions(+), 41 deletions(-) diff --git a/docs/content/configuring-npm/package-json.md b/docs/content/configuring-npm/package-json.md index 3ed0399021447..5cacf68ba175f 100644 --- a/docs/content/configuring-npm/package-json.md +++ b/docs/content/configuring-npm/package-json.md @@ -549,12 +549,8 @@ had the following: } ``` -and then had a "start" command that then referenced the -`npm_package_config_port` environment variable, then the user could -override that by doing `npm config set foo:port 8001`. - -See [`config`](/using-npm/config) and [`scripts`](/using-npm/scripts) for -more on package configs. +It could also have a "start" command that referenced the +`npm_package_config_port` environment variable. ### dependencies diff --git a/docs/content/using-npm/scripts.md b/docs/content/using-npm/scripts.md index 3869334f6cc5a..2072d36c9a4b8 100644 --- a/docs/content/using-npm/scripts.md +++ b/docs/content/using-npm/scripts.md @@ -245,41 +245,7 @@ package.json file, then your package scripts would have the in your code with `process.env.npm_package_name` and `process.env.npm_package_version`, and so on for other fields. -#### configuration - -Configuration parameters are put in the environment with the -`npm_config_` prefix. For instance, you can view the effective `root` -config by checking the `npm_config_root` environment variable. - -#### Special: package.json "config" object - -The package.json "config" keys are overwritten in the environment if -there is a config param of `[@]:`. For example, -if the package.json has this: - -```json -{ - "name" : "foo", - "config" : { - "port" : "8080" - }, - "scripts" : { - "start" : "node server.js" - } -} -``` - -and the server.js is this: - -```javascript -http.createServer(...).listen(process.env.npm_package_config_port) -``` - -then the user could change the behavior by doing: - -```bash - npm config set foo:port 80 - ``` +See [`package-json.md`](/using-npm/package-json) for more on package configs. #### current lifecycle event From a4e095618cda72244a18aaff9d6660b9082a2b84 Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 30 Jun 2021 14:28:06 -0700 Subject: [PATCH 6/9] fix(docs): remove .hooks scripts This is not implemented in npm@7 PR-URL: https://github.com/npm/cli/pull/3486 Credit: @wraithgar Close: #3486 Reviewed-by: @nlf --- docs/content/using-npm/scripts.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/docs/content/using-npm/scripts.md b/docs/content/using-npm/scripts.md index 2072d36c9a4b8..8df9660ca8f4c 100644 --- a/docs/content/using-npm/scripts.md +++ b/docs/content/using-npm/scripts.md @@ -307,19 +307,6 @@ Note that these script files don't have to be nodejs or even javascript programs. They just have to be some kind of executable file. -### Hook Scripts - -If you want to run a specific script at a specific lifecycle event for -ALL packages, then you can use a hook script. - -Place an executable file at `node_modules/.hooks/{eventname}`, and -it'll get run for all packages when they are going through that point -in the package lifecycle for any packages installed in that root. - -Hook scripts are run exactly the same way as package.json scripts. -That is, they are in a separate child process, with the env described -above. - ### Best Practices * Don't exit with a non-zero error code unless you *really* mean it. From 17a44d6b1ac574ba4dd9d51a84027d7970a79af1 Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 1 Jul 2021 10:09:46 -0700 Subject: [PATCH 7/9] docs: changelog for v7.19.1 --- CHANGELOG.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 170a65066c782..f5ebb11ee8124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,38 @@ +## v7.19.1 (2021-07-01) + +### BUG FIXES + +* [`013f0262d`](https://github.com/npm/cli/commit/013f0262db3e16605820f6117749fd3ebc70f6d1) + [#3469](https://github.com/npm/cli/issues/3469) + fix(exitHandler): write code to logfile + ([@wraithgar](https://github.com/wraithgar)) +* [`0dd0341ac`](https://github.com/npm/cli/commit/0dd0341ac9a65a2df8fc262ad9a56b7351f99d66) + [#3474](https://github.com/npm/cli/issues/3474) + fix(ping): make "npm ping" echo a right time + ([@aluneed](https://github.com/aluneed)) +* [`d2e298f3c`](https://github.com/npm/cli/commit/d2e298f3cbab278071480f94ff7d916d42cbf43b) + [#3484](https://github.com/npm/cli/issues/3484) + fix(deprecate): add undeprecate support + ([@wraithgar](https://github.com/wraithgar)) + + ### DOCUMENTATION + +* [`9dd32d08e`](https://github.com/npm/cli/commit/9dd32d08e09c21c9a4517161abfc7eed6518faf2) + [#3485](https://github.com/npm/cli/issues/3485) + fix(docs): remove npm package config override + ([@wraithgar](https://github.com/wraithgar)) +* [`a4e095618`](https://github.com/npm/cli/commit/a4e095618cda72244a18aaff9d6660b9082a2b84) + [#3486](https://github.com/npm/cli/issues/3486) + fix(docs): remove .hooks scripts + ([@wraithgar](https://github.com/wraithgar)) + +### TESTING + +* [`5f8ccccef`](https://github.com/npm/cli/commit/5f8ccccef9fc19229320df8cbcae9fcea8d31388) + [#3483](https://github.com/npm/cli/issues/3483) + chore(tests): clean snapshot for lib/view.js tests + ([@wraithgar](https://github.com/wraithgar)) + ## v7.19.0 (2021-06-24) ### FEATURES From cde931b5b44323825da6449add6c0d9d29f920ba Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 1 Jul 2021 10:10:11 -0700 Subject: [PATCH 8/9] update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 135694a5872ee..e8ac394779953 100644 --- a/AUTHORS +++ b/AUTHORS @@ -785,3 +785,4 @@ Daniel Park Daniel Park Luke Karrys Ivan +Aluneed <31174087+aluneed@users.noreply.github.com> From 665a7bde900d7fbf46aca609b0b9c92b5508a3ea Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 1 Jul 2021 10:10:11 -0700 Subject: [PATCH 9/9] 7.19.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1e86148f91f14..570cded5aa58b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "npm", - "version": "7.19.0", + "version": "7.19.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "npm", - "version": "7.19.0", + "version": "7.19.1", "bundleDependencies": [ "@npmcli/arborist", "@npmcli/ci-detect", diff --git a/package.json b/package.json index 035f30b2be988..73b03991026e1 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "7.19.0", + "version": "7.19.1", "name": "npm", "description": "a package manager for JavaScript", "workspaces": [