Skip to content

Commit f697c50

Browse files
committed
fix(config): remove node-version and npm-version
BREAKING CHANGE: the `node-version` and `npm-version` configs have been removed. These are only used sparingly by arborist to determine if optional dependencies should be installed, and during engines checks (which are only warnings unless `engine-strict` is true.
1 parent d01bb92 commit f697c50

File tree

7 files changed

+21
-68
lines changed

7 files changed

+21
-68
lines changed

lib/npm.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,12 @@ class Npm extends EventEmitter {
311311

312312
get flatOptions () {
313313
const { flat } = this.config
314-
// the Arborist constructor is used almost everywhere we call pacote, it's easiest
315-
// to attach it to flatOptions so it goes everywhere without having to touch every call
314+
// the Arborist constructor is used almost everywhere we call pacote, it's
315+
// easiest to attach it to flatOptions so it goes everywhere without having
316+
// to touch every call
316317
flat.Arborist = Arborist
318+
flat.nodeVersion = process.version
319+
flat.npmVersion = pkg.version
317320
if (this.command) {
318321
flat.npmCommand = this.command
319322
}

lib/utils/config/definitions.js

+3-23
Original file line numberDiff line numberDiff line change
@@ -1314,16 +1314,6 @@ define('node-options', {
13141314
`,
13151315
})
13161316

1317-
define('node-version', {
1318-
default: process.version,
1319-
defaultDescription: 'Node.js `process.version` value',
1320-
type: semver,
1321-
description: `
1322-
The node version to use when checking a package's \`engines\` setting.
1323-
`,
1324-
flatten,
1325-
})
1326-
13271317
define('noproxy', {
13281318
default: '',
13291319
defaultDescription: `
@@ -1344,16 +1334,6 @@ define('noproxy', {
13441334
},
13451335
})
13461336

1347-
define('npm-version', {
1348-
default: npmVersion,
1349-
defaultDescription: 'Output of `npm --version`',
1350-
type: semver,
1351-
description: `
1352-
The npm version to use when checking a package's \`engines\` setting.
1353-
`,
1354-
flatten,
1355-
})
1356-
13571337
define('offline', {
13581338
default: false,
13591339
type: Boolean,
@@ -2044,7 +2024,7 @@ define('tag-version-prefix', {
20442024
type: String,
20452025
description: `
20462026
If set, alters the prefix used when tagging a new version when performing
2047-
a version increment using \`npm-version\`. To remove the prefix
2027+
a version increment using \`npm version\`. To remove the prefix
20482028
altogether, set it to the empty string: \`""\`.
20492029
20502030
Because other tools may rely on the convention that npm version tags look
@@ -2166,8 +2146,8 @@ define('user-agent', {
21662146
inWorkspaces = true
21672147
}
21682148
flatOptions.userAgent =
2169-
value.replace(/\{node-version\}/gi, obj['node-version'])
2170-
.replace(/\{npm-version\}/gi, obj['npm-version'])
2149+
value.replace(/\{node-version\}/gi, process.version)
2150+
.replace(/\{npm-version\}/gi, npmVersion)
21712151
.replace(/\{platform\}/gi, process.platform)
21722152
.replace(/\{arch\}/gi, process.arch)
21732153
.replace(/\{workspaces\}/gi, inWorkspaces)

tap-snapshots/test/lib/commands/config.js.test.cjs

-4
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,9 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
9696
"maxsockets": 15,
9797
"message": "%s",
9898
"node-options": null,
99-
"node-version": "{NODE-VERSION}",
10099
"noproxy": [
101100
""
102101
],
103-
"npm-version": "{NPM-VERSION}",
104102
"offline": false,
105103
"omit": [],
106104
"omit-lockfile-registry-resolved": false,
@@ -252,9 +250,7 @@ maxsockets = 15
252250
message = "%s"
253251
metrics-registry = "https://registry.npmjs.org/"
254252
node-options = null
255-
node-version = "{NODE-VERSION}"
256253
noproxy = [""]
257-
npm-version = "{NPM-VERSION}"
258254
offline = false
259255
omit = []
260256
omit-lockfile-registry-resolved = false

tap-snapshots/test/lib/docs.js.test.cjs

+1-19
Original file line numberDiff line numberDiff line change
@@ -1361,13 +1361,6 @@ Options to pass through to Node.js via the \`NODE_OPTIONS\` environment
13611361
variable. This does not impact how npm itself is executed but it does impact
13621362
how lifecycle scripts are called.
13631363
1364-
#### \`node-version\`
1365-
1366-
* Default: Node.js \`process.version\` value
1367-
* Type: SemVer string
1368-
1369-
The node version to use when checking a package's \`engines\` setting.
1370-
13711364
#### \`noproxy\`
13721365
13731366
* Default: The value of the NO_PROXY environment variable
@@ -1377,13 +1370,6 @@ Domain extensions that should bypass any proxies.
13771370
13781371
Also accepts a comma-delimited string.
13791372
1380-
#### \`npm-version\`
1381-
1382-
* Default: Output of \`npm --version\`
1383-
* Type: SemVer string
1384-
1385-
The npm version to use when checking a package's \`engines\` setting.
1386-
13871373
#### \`offline\`
13881374
13891375
* Default: false
@@ -1792,7 +1778,7 @@ tarball that will be compared with the local files by default.
17921778
* Type: String
17931779
17941780
If set, alters the prefix used when tagging a new version when performing a
1795-
version increment using \`npm-version\`. To remove the prefix altogether, set
1781+
version increment using \`npm version\`. To remove the prefix altogether, set
17961782
it to the empty string: \`""\`.
17971783
17981784
Because other tools may rely on the convention that npm version tags look
@@ -2190,9 +2176,7 @@ Array [
21902176
"maxsockets",
21912177
"message",
21922178
"node-options",
2193-
"node-version",
21942179
"noproxy",
2195-
"npm-version",
21962180
"offline",
21972181
"omit",
21982182
"omit-lockfile-registry-resolved",
@@ -2326,9 +2310,7 @@ Array [
23262310
"loglevel",
23272311
"maxsockets",
23282312
"message",
2329-
"node-version",
23302313
"noproxy",
2331-
"npm-version",
23322314
"offline",
23332315
"omit",
23342316
"omit-lockfile-registry-resolved",

test/fixtures/sandbox.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { promisify } = require('util')
66
const mkdirp = require('mkdirp-infer-owner')
77
const rimraf = promisify(require('rimraf'))
88
const mockLogs = require('./mock-logs')
9+
const pkg = require('../../package.json')
910

1011
const chain = new Map()
1112
const sandboxes = new Map()
@@ -45,8 +46,6 @@ const _logs = Symbol('sandbox.logs')
4546

4647
// these config keys can be redacted widely
4748
const redactedDefaults = [
48-
'node-version',
49-
'npm-version',
5049
'tmp',
5150
]
5251

@@ -155,6 +154,8 @@ class Sandbox extends EventEmitter {
155154
.split(normalize(homedir())).join('{REALHOME}')
156155
.split(this[_proxy].platform).join('{PLATFORM}')
157156
.split(this[_proxy].arch).join('{ARCH}')
157+
.replace(new RegExp(process.version, 'g'), '{NODE-VERSION}')
158+
.replace(new RegExp(pkg.version, 'g'), '{NPM-VERSION}')
158159

159160
// We do the defaults after everything else so that they don't cause the
160161
// other cleaners to miss values we would have clobbered here. For

test/lib/commands/config.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -330,21 +330,21 @@ t.test('config get no args', async t => {
330330
t.test('config get single key', async t => {
331331
const sandbox = new Sandbox(t)
332332

333-
await sandbox.run('config', ['get', 'node-version'])
334-
t.equal(sandbox.output, sandbox.config.get('node-version'), 'should get the value')
333+
await sandbox.run('config', ['get', 'all'])
334+
t.equal(sandbox.output, `${sandbox.config.get('all')}`, 'should get the value')
335335
})
336336

337337
t.test('config get multiple keys', async t => {
338338
const sandbox = new Sandbox(t)
339339

340-
await sandbox.run('config', ['get', 'node-version', 'npm-version'])
340+
await sandbox.run('config', ['get', 'yes', 'all'])
341341
t.ok(
342-
sandbox.output.includes(`node-version=${sandbox.config.get('node-version')}`),
343-
'outputs node-version'
342+
sandbox.output.includes(`yes=${sandbox.config.get('yes')}`),
343+
'outputs yes'
344344
)
345345
t.ok(
346-
sandbox.output.includes(`npm-version=${sandbox.config.get('npm-version')}`),
347-
'outputs npm-version'
346+
sandbox.output.includes(`all=${sandbox.config.get('all')}`),
347+
'outputs all'
348348
)
349349
})
350350

test/lib/utils/config/definitions.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const t = require('tap')
22
const { resolve } = require('path')
33
const mockGlobals = require('../../../fixtures/mock-globals')
4+
const pkg = require('../../../../package.json')
45

56
// have to fake the node version, or else it'll only pass on this one
67
mockGlobals(t, { 'process.version': 'v14.8.0', 'process.env.NODE_ENV': undefined })
@@ -9,14 +10,6 @@ const mockDefs = (mocks = {}) => t.mock('../../../../lib/utils/config/definition
910

1011
const isWin = (isWindows) => ({ '../../../../lib/utils/is-windows.js': { isWindows } })
1112

12-
t.test('node and npm versions', t => {
13-
const definitions = mockDefs()
14-
const pkg = require('../../../../package.json')
15-
t.equal(definitions['npm-version'].default, pkg.version, 'npm-version default')
16-
t.equal(definitions['node-version'].default, process.version, 'node-version default')
17-
t.end()
18-
})
19-
2013
t.test('basic flattening function camelCases from css-case', t => {
2114
const flat = {}
2215
const obj = { 'prefer-online': true }
@@ -745,11 +738,9 @@ t.test('detect CI', t => {
745738
t.test('user-agent', t => {
746739
const obj = {
747740
'user-agent': mockDefs()['user-agent'].default,
748-
'npm-version': '1.2.3',
749-
'node-version': '9.8.7',
750741
}
751742
const flat = {}
752-
const expectNoCI = `npm/1.2.3 node/9.8.7 ` +
743+
const expectNoCI = `npm/${pkg.version} node/${process.version} ` +
753744
`${process.platform} ${process.arch} workspaces/false`
754745
mockDefs()['user-agent'].flatten('user-agent', obj, flat)
755746
t.equal(flat.userAgent, expectNoCI)

0 commit comments

Comments
 (0)