Skip to content

Commit 5ef6c04

Browse files
committed
stuff
1 parent a0eb7e1 commit 5ef6c04

File tree

27 files changed

+493
-529
lines changed

27 files changed

+493
-529
lines changed

DEPENDENCIES.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ graph LR;
191191
npmcli-config-->npmcli-arborist["@npmcli/arborist"];
192192
npmcli-config-->npmcli-eslint-config["@npmcli/eslint-config"];
193193
npmcli-config-->npmcli-map-workspaces["@npmcli/map-workspaces"];
194+
npmcli-config-->npmcli-mock-globals["@npmcli/mock-globals"];
195+
npmcli-config-->npmcli-promise-spawn["@npmcli/promise-spawn"];
194196
npmcli-config-->npmcli-template-oss["@npmcli/template-oss"];
195197
npmcli-config-->proc-log;
196198
npmcli-config-->read-package-json-fast;
@@ -630,11 +632,14 @@ graph LR;
630632
npmcli-arborist-->walk-up-path;
631633
npmcli-config-->ci-info;
632634
npmcli-config-->ini;
635+
npmcli-config-->isaacs-string-locale-compare["@isaacs/string-locale-compare"];
633636
npmcli-config-->nopt;
634637
npmcli-config-->npm-registry-fetch;
635638
npmcli-config-->npmcli-arborist["@npmcli/arborist"];
636639
npmcli-config-->npmcli-eslint-config["@npmcli/eslint-config"];
637640
npmcli-config-->npmcli-map-workspaces["@npmcli/map-workspaces"];
641+
npmcli-config-->npmcli-mock-globals["@npmcli/mock-globals"];
642+
npmcli-config-->npmcli-promise-spawn["@npmcli/promise-spawn"];
638643
npmcli-config-->npmcli-template-oss["@npmcli/template-oss"];
639644
npmcli-config-->proc-log;
640645
npmcli-config-->read-package-json-fast;
@@ -800,5 +805,5 @@ packages higher up the chain.
800805
- npm-registry-fetch, libnpmversion
801806
- @npmcli/git, make-fetch-happen, init-package-json
802807
- @npmcli/installed-package-contents, @npmcli/map-workspaces, cacache, npm-pick-manifest, @npmcli/run-script, read-package-json, promzard
803-
- @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, npm-packlist, normalize-package-data, @npmcli/package-json, bin-links, nopt, npmlog, parse-conflict-json, read, @npmcli/mock-globals
808+
- @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, npm-packlist, normalize-package-data, @npmcli/package-json, bin-links, nopt, npmlog, parse-conflict-json, @npmcli/mock-globals, read
804809
- semver, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, fs-minipass, ssri, unique-slug, @npmcli/promise-spawn, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, ignore-walk, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, are-we-there-yet, gauge, treeverse, @npmcli/eslint-config, @npmcli/template-oss, minify-registry-metadata, ini, @npmcli/disparity-colors, mute-stream, npm-audit-report, npm-user-validate

bin/npx-cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const removed = new Set([
2424
...removedOpts,
2525
])
2626

27-
const { definitions, shorthands, configKeys } = require('@npmcli/config')
28-
const npmSwitches = configKeys.filter(k => definitions[k].isBoolean)
27+
const { definitions, shorthands, definitionKeys } = require('@npmcli/config')
28+
const npmSwitches = definitionKeys.filter(k => definitions[k].hasNonBoolean)
2929

3030
// things that don't take a value
3131
const switches = new Set([

lib/commands/completion.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,22 @@
3030
//
3131

3232
const fs = require('fs/promises')
33-
const nopt = require('nopt')
3433
const { resolve } = require('path')
35-
36-
const { definitions, shorthands, types, shortKeys, configKeys } = require('@npmcli/config')
3734
const { aliases, commands, plumbing } = require('../utils/cmd-list.js')
35+
const { isWindowsShell } = require('../utils/is-windows.js')
36+
const {
37+
ConfigData,
38+
Locations,
39+
definitions,
40+
definitionKeys,
41+
shorthands,
42+
shortKeys,
43+
} = require('@npmcli/config')
44+
3845
const aliasNames = Object.keys(aliases)
3946
const fullList = commands.concat(aliasNames).filter(c => !plumbing.includes(c))
40-
const allConfs = configKeys.concat(shortKeys)
41-
const { isWindowsShell } = require('../utils/is-windows.js')
47+
const allConfs = definitionKeys.concat(shortKeys)
48+
4249
const fileExists = (file) => fs.stat(file).then(s => s.isFile()).catch(() => false)
4350

4451
const BaseCommand = require('../base-command.js')
@@ -140,8 +147,8 @@ class Completion extends BaseCommand {
140147
// take a little shortcut and use npm's arg parsing logic.
141148
// don't have to worry about the last arg being implicitly
142149
// boolean'ed, since the last block will catch that.
143-
const parsed = opts.conf =
144-
nopt(types, shorthands, partialWords.slice(0, -1), 0)
150+
const config = new ConfigData(Locations.cli)
151+
const parsed = opts.conf = config.load(partialWords.slice(0, -1))
145152
// check if there's a command already.
146153
const cmd = parsed.argv.remain[1]
147154
if (!cmd) {
@@ -237,7 +244,7 @@ const configCompl = opts => {
237244
const split = word.match(/^(-+)((?:no-)*)(.*)$/)
238245
const dashes = split[1]
239246
const no = split[2]
240-
const flags = configKeys.filter(isFlag)
247+
const flags = definitionKeys.filter(isFlag)
241248
return allConfs.map(c => dashes + c)
242249
.concat(flags.map(f => dashes + (no || 'no-') + f))
243250
}
@@ -253,10 +260,7 @@ const isFlag = word => {
253260
const no = split[2]
254261
const conf = split[3]
255262
const { type } = definitions[conf]
256-
return no ||
257-
type === Boolean ||
258-
(Array.isArray(type) && type.includes(Boolean)) ||
259-
shorthands[conf]
263+
return no || type.isBoolean || shorthands[conf]
260264
}
261265

262266
// complete against the npm commands

lib/commands/config.js

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
const { mkdir, readFile, writeFile } = require('fs/promises')
2-
const { dirname, resolve } = require('path')
3-
const { spawn } = require('child_process')
4-
const { EOL } = require('os')
5-
const ini = require('ini')
1+
const { resolve } = require('path')
62
const localeCompare = require('@isaacs/string-locale-compare')('en')
73
const rpj = require('read-package-json-fast')
84
const log = require('../utils/log-shim.js')
9-
const { keys: configKeys, NerfDarts, definitions, defaults } = require('@npmcli/config')
5+
const { NerfDarts, definitionKeys, definitions } = require('@npmcli/config')
106

117
// take an array of `[key, value, k2=v2, k3, v3, ...]` and turn into
128
// { key: value, k2: v2, k3: v3 }
@@ -88,7 +84,7 @@ class Config extends BaseCommand {
8884
case 'get':
8985
case 'delete':
9086
case 'rm':
91-
return configKeys
87+
return definitionKeys
9288
case 'edit':
9389
case 'list':
9490
case 'ls':
@@ -189,60 +185,9 @@ class Config extends BaseCommand {
189185
}
190186

191187
async edit () {
192-
const e = this.npm.flatOptions.editor
188+
const { editor } = this.npm.flatOptions
193189
const where = this.npm.flatOptions.location
194-
const { file } = this.npm.config.data.get(where)
195-
196-
// save first, just to make sure it's synced up
197-
// this also removes all the comments from the last time we edited it.
198-
await this.npm.config.save(where)
199-
200-
const data = (
201-
await readFile(file, 'utf8').catch(() => '')
202-
).replace(/\r\n/g, '\n')
203-
const entries = Object.entries(defaults)
204-
const defData = entries.reduce((str, [key, val]) => {
205-
const obj = { [key]: val }
206-
const i = ini.stringify(obj)
207-
.replace(/\r\n/g, '\n') // normalizes output from ini.stringify
208-
.replace(/\n$/m, '')
209-
.replace(/^/g, '; ')
210-
.replace(/\n/g, '\n; ')
211-
.split('\n')
212-
return str + '\n' + i
213-
}, '')
214-
215-
const tmpData = `;;;;
216-
; npm ${where}config file: ${file}
217-
; this is a simple ini-formatted file
218-
; lines that start with semi-colons are comments
219-
; run \`npm help 7 config\` for documentation of the various options
220-
;
221-
; Configs like \`@scope:registry\` map a scope to a given registry url.
222-
;
223-
; Configs like \`//<hostname>/:_authToken\` are auth that is restricted
224-
; to the registry host specified.
225-
226-
${data.split('\n').sort(localeCompare).join('\n').trim()}
227-
228-
;;;;
229-
; all available options shown below with default values
230-
;;;;
231-
232-
${defData}
233-
`.split('\n').join(EOL)
234-
await mkdir(dirname(file), { recursive: true })
235-
await writeFile(file, tmpData, 'utf8')
236-
await new Promise((res, rej) => {
237-
const [bin, ...args] = e.split(/\s+/)
238-
const editor = spawn(bin, [...args, file], { stdio: 'inherit' })
239-
editor.on('exit', (code) => {
240-
if (code) {
241-
return rej(new Error(`editor process exited with code: ${code}`))
242-
}
243-
return res()
244-
})
245-
})
190+
await this.npm.config.edit(where, { editor })
246191
}
247192

248193
async fix () {

lib/commands/doctor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const pacote = require('pacote')
77
const { resolve } = require('path')
88
const semver = require('semver')
99
const { promisify } = require('util')
10-
const { Types } = require('@npmcli/config')
10+
const { Locations } = require('@npmcli/config')
1111
const log = require('../utils/log-shim.js')
1212
const ping = require('../utils/ping.js')
1313
const lstat = promisify(fs.lstat)
@@ -362,7 +362,7 @@ class Doctor extends BaseCommand {
362362
}
363363

364364
async checkNpmRegistry () {
365-
const defaultRegistry = this.npm.config.get('registry', Types.default)
365+
const defaultRegistry = this.npm.config.get('registry', Locations.default)
366366
if (this.npm.flatOptions.registry !== defaultRegistry) {
367367
throw `Try \`npm config set registry=${defaultRegistry}\``
368368
} else {

node_modules/@npmcli/promise-spawn/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const open = (_args, opts = {}, extra = {}) => {
131131
let platform = process.platform
132132
// process.platform === 'linux' may actually indicate WSL, if that's the case
133133
// we want to treat things as win32 anyway so the host can open the argument
134-
if (platform === 'linux' && os.release().includes('Microsoft')) {
134+
if (platform === 'linux' && os.release().toLowerCase().includes('microsoft')) {
135135
platform = 'win32'
136136
}
137137

node_modules/@npmcli/promise-spawn/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/promise-spawn",
3-
"version": "6.0.1",
3+
"version": "6.0.2",
44
"files": [
55
"bin/",
66
"lib/"
@@ -32,8 +32,8 @@
3232
},
3333
"devDependencies": {
3434
"@npmcli/eslint-config": "^4.0.0",
35-
"@npmcli/template-oss": "4.8.0",
36-
"minipass": "^3.1.1",
35+
"@npmcli/template-oss": "4.11.0",
36+
"minipass": "^4.0.0",
3737
"spawk": "^1.7.1",
3838
"tap": "^16.0.1"
3939
},
@@ -42,7 +42,7 @@
4242
},
4343
"templateOSS": {
4444
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
45-
"version": "4.8.0"
45+
"version": "4.11.0"
4646
},
4747
"dependencies": {
4848
"which": "^3.0.0"

package-lock.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,9 @@
11551155
},
11561156
"node_modules/@isaacs/string-locale-compare": {
11571157
"version": "1.1.0",
1158-
"inBundle": true,
1159-
"license": "ISC"
1158+
"resolved": "https://registry.npmjs.org/@isaacs/string-locale-compare/-/string-locale-compare-1.1.0.tgz",
1159+
"integrity": "sha512-SQ7Kzhh9+D+ZW9MA0zkYv3VXhIDNx+LzM6EJ+/65I3QY+enU6Itte7E5XX7EWrqLW2FN4n06GWzBnPoC3th2aQ==",
1160+
"inBundle": true
11601161
},
11611162
"node_modules/@istanbuljs/load-nyc-config": {
11621163
"version": "1.1.0",
@@ -2238,9 +2239,10 @@
22382239
}
22392240
},
22402241
"node_modules/@npmcli/promise-spawn": {
2241-
"version": "6.0.1",
2242+
"version": "6.0.2",
2243+
"resolved": "https://registry.npmjs.org/@npmcli/promise-spawn/-/promise-spawn-6.0.2.tgz",
2244+
"integrity": "sha512-gGq0NJkIGSwdbUt4yhdF8ZrmkGKVz9vAdVzpOfnom+V8PLSmSOVhZwbNvZZS1EYcJN5hzzKBxmmVVAInM6HQLg==",
22422245
"inBundle": true,
2243-
"license": "ISC",
22442246
"dependencies": {
22452247
"which": "^3.0.0"
22462248
},
@@ -14391,9 +14393,10 @@
1439114393
"version": "6.1.0",
1439214394
"license": "ISC",
1439314395
"dependencies": {
14396+
"@isaacs/string-locale-compare": "^1.1.0",
1439414397
"@npmcli/arborist": "^6.1.5",
1439514398
"@npmcli/map-workspaces": "^3.0.0",
14396-
"@npmcli/mock-globals": "^1.0.0",
14399+
"@npmcli/promise-spawn": "^6.0.2",
1439714400
"ci-info": "^3.7.1",
1439814401
"ini": "^3.0.0",
1439914402
"nopt": "file:../../../nopt/nopt-7.0.0.tgz",
@@ -14406,6 +14409,7 @@
1440614409
},
1440714410
"devDependencies": {
1440814411
"@npmcli/eslint-config": "^4.0.0",
14412+
"@npmcli/mock-globals": "^1.0.0",
1440914413
"@npmcli/template-oss": "4.11.0",
1441014414
"tap": "^16.3.2"
1441114415
},

0 commit comments

Comments
 (0)