From 6977f89c388a94600f0e77ef825afa166f43916a Mon Sep 17 00:00:00 2001 From: Vlad Sirenko Date: Tue, 23 Jan 2024 22:25:48 -0800 Subject: [PATCH 1/2] small optimization --- lib/cli-entry.js | 3 +-- lib/npm.js | 3 +-- lib/utils/replace-info.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/cli-entry.js b/lib/cli-entry.js index aad06e0690385..57c60f5558558 100644 --- a/lib/cli-entry.js +++ b/lib/cli-entry.js @@ -4,7 +4,6 @@ module.exports = async (process, validateEngines) => { // set it here so that regardless of what happens later, we don't // leak any private CLI configs to other programs - process.title = 'npm' // if npm is called as "npmg" or "npm_g", then run in global mode. if (process.argv[1][process.argv[1].length - 1] === 'g') { @@ -57,7 +56,7 @@ module.exports = async (process, validateEngines) => { process.exitCode = 1 return exitHandler() } - + setTimeout(() => process.title = npm.title) await npm.exec(cmd) return exitHandler() } catch (err) { diff --git a/lib/npm.js b/lib/npm.js index 0a023f4ac8a30..89c2f6d123387 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -12,7 +12,6 @@ const LogFile = require('./utils/log-file.js') const Timers = require('./utils/timers.js') const Display = require('./utils/display.js') const log = require('./utils/log-shim') -const replaceInfo = require('./utils/replace-info.js') const updateNotifier = require('./utils/update-notifier.js') const pkg = require('../package.json') const { deref } = require('./utils/cmd-list.js') @@ -177,7 +176,6 @@ class Npm { } set title (t) { - process.title = t this.#title = t } @@ -227,6 +225,7 @@ class Npm { // note: this MUST be shorter than the actual argv length, because it // uses the same memory, so node will truncate it if it's too long. this.time('npm:load:setTitle', () => { + const replaceInfo = require('./utils/replace-info.js') const { parsedArgv: { cooked, remain } } = this.config this.argv = remain // Secrets are mostly in configs, so title is set using only the positional args diff --git a/lib/utils/replace-info.js b/lib/utils/replace-info.js index b9ce61935ffb7..d38a8f2fd8176 100644 --- a/lib/utils/replace-info.js +++ b/lib/utils/replace-info.js @@ -1,4 +1,4 @@ -const { cleanUrl } = require('npm-registry-fetch') +const cleanUrl = require('npm-registry-fetch/lib/clean-url') const isString = (v) => typeof v === 'string' // split on \s|= similar to how nopt parses options From f5d35fe55717bd3d1df90bb00e6ae34a93f19f82 Mon Sep 17 00:00:00 2001 From: Vlad Sirenko Date: Wed, 24 Jan 2024 13:05:38 -0800 Subject: [PATCH 2/2] return title --- lib/cli-entry.js | 2 +- lib/npm.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cli-entry.js b/lib/cli-entry.js index 57c60f5558558..03fb7530ae404 100644 --- a/lib/cli-entry.js +++ b/lib/cli-entry.js @@ -4,6 +4,7 @@ module.exports = async (process, validateEngines) => { // set it here so that regardless of what happens later, we don't // leak any private CLI configs to other programs + process.title = 'npm' // if npm is called as "npmg" or "npm_g", then run in global mode. if (process.argv[1][process.argv[1].length - 1] === 'g') { @@ -56,7 +57,6 @@ module.exports = async (process, validateEngines) => { process.exitCode = 1 return exitHandler() } - setTimeout(() => process.title = npm.title) await npm.exec(cmd) return exitHandler() } catch (err) { diff --git a/lib/npm.js b/lib/npm.js index 89c2f6d123387..cc9fc4c696889 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -176,6 +176,7 @@ class Npm { } set title (t) { + process.title = t this.#title = t }