+41
-0
lines changedFilter options
+41
-0
lines changed Original file line number Diff line number Diff line change
@@ -2547,6 +2547,7 @@ exports[`test/lib/docs.js TAP shorthands > docs 1`] = `
2547
2547
* \`--help\`: \`--usage\`
2548
2548
* \`-v\`: \`--version\`
2549
2549
* \`-w\`: \`--workspace\`
2550
+
* \`--ws\`: \`--workspaces\`
2550
2551
* \`-y\`: \`--yes\`
2551
2552
`
2552
2553
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ const shorthands = {
55
55
readonly: ['--read-only'],
56
56
reg: ['--registry'],
57
57
iwr: ['--include-workspace-root'],
58
+
ws: ['--workspaces'],
58
59
...definitionProps.shorthands,
59
60
}
60
61
Original file line number Diff line number Diff line change
@@ -15,6 +15,14 @@ const {
15
15
mkdir,
16
16
} = require('node:fs/promises')
17
17
18
+
// TODO these need to be either be ignored when parsing env, formalized as config, or not exported to the env in the first place. For now this list is just to suppress warnings till we can pay off this tech debt.
19
+
const internalEnv = [
20
+
'global-prefix',
21
+
'local-prefix',
22
+
'npm-version',
23
+
'node-gyp',
24
+
]
25
+
18
26
const fileExists = (...p) => stat(resolve(...p))
19
27
.then((st) => st.isFile())
20
28
.catch(() => false)
@@ -349,6 +357,11 @@ class Config {
349
357
}
350
358
351
359
loadCLI () {
360
+
for (const s of Object.keys(this.shorthands)) {
361
+
if (s.length > 1 && this.argv.includes(`-${s}`)) {
362
+
log.warn(`-${s} is not a valid single-hyphen cli flag and will be removed in the future`)
363
+
}
364
+
}
352
365
nopt.invalidHandler = (k, val, type) =>
353
366
this.invalidHandler(k, val, type, 'command line options', 'cli')
354
367
const conf = nopt(this.types, this.shorthands, this.argv)
@@ -580,6 +593,9 @@ class Config {
580
593
581
594
#checkUnknown (where, key) {
582
595
if (!this.definitions[key]) {
596
+
if (internalEnv.includes(key)) {
597
+
return
598
+
}
583
599
if (!key.includes(':')) {
584
600
log.warn(`Unknown ${where} config "${where === 'cli' ? '--' : ''}${key}". This will stop working in the next major version of npm.`)
585
601
return
Original file line number Diff line number Diff line change
@@ -1519,3 +1519,26 @@ t.test('catch project config prefix error', async t => {
1519
1519
'error', 'config', `prefix cannot be changed from project config: ${path}`,
1520
1520
]], 'Expected error logged')
1521
1521
})
1522
+
1523
+
t.test('invalid single hyphen warnings', async t => {
1524
+
const path = t.testdir()
1525
+
const logs = []
1526
+
const logHandler = (...args) => logs.push(args)
1527
+
process.on('log', logHandler)
1528
+
t.teardown(() => process.off('log', logHandler))
1529
+
const config = new Config({
1530
+
npmPath: `${path}/npm`,
1531
+
env: {},
1532
+
argv: [process.execPath, __filename, '-ws', '-iwr'],
1533
+
cwd: path,
1534
+
shorthands,
1535
+
definitions,
1536
+
nerfDarts,
1537
+
})
1538
+
await config.load()
1539
+
const filtered = logs.filter(l => l[0] === 'warn')
1540
+
t.match(filtered, [
1541
+
['warn', '-iwr is not a valid single-hyphen cli flag and will be removed in the future'],
1542
+
['warn', '-ws is not a valid single-hyphen cli flag and will be removed in the future'],
1543
+
], 'Warns about single hyphen configs')
1544
+
})
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4