From 09b456f2d776e2757956d2b9869febd1e01a1076 Mon Sep 17 00:00:00 2001 From: nlf Date: Wed, 7 Oct 2020 08:03:12 -0700 Subject: [PATCH] @npmcli/config@1.2.1 PR-URL: https://github.com/npm/cli/pull/1919 Credit: @nlf Close: #1919 Reviewed-by: @ruyadorno --- node_modules/@npmcli/config/lib/get-user-agent.js | 13 +++++++++++++ node_modules/@npmcli/config/lib/index.js | 11 +++++++++++ node_modules/@npmcli/config/package.json | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- 5 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 node_modules/@npmcli/config/lib/get-user-agent.js diff --git a/node_modules/@npmcli/config/lib/get-user-agent.js b/node_modules/@npmcli/config/lib/get-user-agent.js new file mode 100644 index 0000000000000..c3d3c7a1bf3de --- /dev/null +++ b/node_modules/@npmcli/config/lib/get-user-agent.js @@ -0,0 +1,13 @@ +// Accepts a config object, returns a user-agent string +const getUserAgent = (config) => { + const ciName = config.get('ci-name') + return (config.get('user-agent') || '') + .replace(/\{node-version\}/gi, config.get('node-version')) + .replace(/\{npm-version\}/gi, config.get('npm-version')) + .replace(/\{platform\}/gi, process.platform) + .replace(/\{arch\}/gi, process.arch) + .replace(/\{ci\}/gi, ciName ? `ci/${ciName}` : '') + .trim() +} + +module.exports = getUserAgent diff --git a/node_modules/@npmcli/config/lib/index.js b/node_modules/@npmcli/config/lib/index.js index af19e720f866b..a80b976a00081 100644 --- a/node_modules/@npmcli/config/lib/index.js +++ b/node_modules/@npmcli/config/lib/index.js @@ -47,6 +47,7 @@ const envReplace = require('./env-replace.js') const parseField = require('./parse-field.js') const typeDescription = require('./type-description.js') const setEnvs = require('./set-envs.js') +const getUserAgent = require('./get-user-agent.js') // types that can be saved back to const confFileTypes = new Set([ @@ -244,6 +245,10 @@ class Config { // set proper globalPrefix now that everything is loaded this.globalPrefix = this.get('prefix') + process.emit('time', 'config:load:setUserAgent') + this.setUserAgent() + process.emit('timeEnd', 'config:load:setUserAgent') + process.emit('time', 'config:load:setEnvs') this.setEnvs() process.emit('timeEnd', 'config:load:setEnvs') @@ -694,6 +699,12 @@ class Config { }) } + // the user-agent configuration is a template that gets populated + // with some variables, that takes place here + setUserAgent () { + this.set('user-agent', getUserAgent(this)) + } + // set up the environment object we have with npm_config_* environs // for all configs that are different from their default values, and // set EDITOR and HOME. diff --git a/node_modules/@npmcli/config/package.json b/node_modules/@npmcli/config/package.json index b16d2f286efaa..ef22e7bb0e713 100644 --- a/node_modules/@npmcli/config/package.json +++ b/node_modules/@npmcli/config/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/config", - "version": "1.1.8", + "version": "1.2.1", "files": [ "lib" ], diff --git a/package-lock.json b/package-lock.json index 22c08c486d182..aadc2812c0c6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -78,7 +78,7 @@ "dependencies": { "@npmcli/arborist": "^0.0.32", "@npmcli/ci-detect": "^1.2.0", - "@npmcli/config": "^1.1.8", + "@npmcli/config": "^1.2.1", "@npmcli/run-script": "^1.7.0", "abbrev": "~1.1.1", "ansicolors": "~0.3.2", @@ -417,9 +417,9 @@ "inBundle": true }, "node_modules/@npmcli/config": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/@npmcli/config/-/config-1.1.8.tgz", - "integrity": "sha512-hUHm14SXdn4E2JHdWGt4meejDMVsyIDUoDLxxXgoHOTmOQQUv654zf+afNRTOAV1UqvLuAJDu+WtpZvveU0grQ==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@npmcli/config/-/config-1.2.1.tgz", + "integrity": "sha512-alNV1uD+Ms5LIX08e+imTmHbyzQCMEyU3nS29SQuX3lQsl93xf0sNW3JnHTGGcBxZlX5z0pRaAu5XtE94rdS9g==", "inBundle": true, "dependencies": { "ini": "^1.3.5", @@ -8547,9 +8547,9 @@ "integrity": "sha512-oN3y7FAROHhrAt7Rr7PnTSwrHrZVRTS2ZbyxeQwSSYD0ifwM3YNgQqbaRmjcWoPyq77MjchusjJDspbzMmip1Q==" }, "@npmcli/config": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/@npmcli/config/-/config-1.1.8.tgz", - "integrity": "sha512-hUHm14SXdn4E2JHdWGt4meejDMVsyIDUoDLxxXgoHOTmOQQUv654zf+afNRTOAV1UqvLuAJDu+WtpZvveU0grQ==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@npmcli/config/-/config-1.2.1.tgz", + "integrity": "sha512-alNV1uD+Ms5LIX08e+imTmHbyzQCMEyU3nS29SQuX3lQsl93xf0sNW3JnHTGGcBxZlX5z0pRaAu5XtE94rdS9g==", "requires": { "ini": "^1.3.5", "mkdirp-infer-owner": "^2.0.0", diff --git a/package.json b/package.json index e58880013d02c..403ee49272aa7 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "dependencies": { "@npmcli/arborist": "^0.0.32", "@npmcli/ci-detect": "^1.2.0", - "@npmcli/config": "^1.1.8", + "@npmcli/config": "^1.2.1", "@npmcli/run-script": "^1.7.0", "abbrev": "~1.1.1", "ansicolors": "~0.3.2",