Skip to content

Commit e9cf30e

Browse files
committed
1 parent 2bedf25 commit e9cf30e

File tree

10 files changed

+54
-168
lines changed

10 files changed

+54
-168
lines changed

DEPENDENCIES.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ graph LR;
491491
npm-->minimatch;
492492
npm-->minipass-pipeline;
493493
npm-->minipass;
494-
npm-->minizlib;
495494
npm-->ms;
496495
npm-->nock;
497496
npm-->node-gyp;

node_modules/.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@
144144
!/node-gyp/node_modules/tar
145145
!/node-gyp/node_modules/yallist
146146
!/nopt
147-
!/nopt/node_modules/
148-
/nopt/node_modules/*
149-
!/nopt/node_modules/abbrev
150147
!/normalize-package-data
151148
!/npm-audit-report
152149
!/npm-bundled

node_modules/nopt/lib/nopt-lib.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ function nopt (args, {
2525
types,
2626
shorthands,
2727
typeDefs,
28-
invalidHandler,
28+
invalidHandler, // opt is configured but its value does not validate against given type
29+
unknownHandler, // opt is not configured
30+
abbrevHandler, // opt is being expanded via abbrev
2931
typeDefault,
3032
dynamicTypes,
3133
} = {}) {
@@ -38,7 +40,9 @@ function nopt (args, {
3840
original: args.slice(0),
3941
}
4042

41-
parse(args, data, argv.remain, { typeDefs, types, dynamicTypes, shorthands })
43+
parse(args, data, argv.remain, {
44+
typeDefs, types, dynamicTypes, shorthands, unknownHandler, abbrevHandler,
45+
})
4246

4347
// now data is full
4448
clean(data, { types, dynamicTypes, typeDefs, invalidHandler, typeDefault })
@@ -247,6 +251,8 @@ function parse (args, data, remain, {
247251
typeDefs = {},
248252
shorthands = {},
249253
dynamicTypes,
254+
unknownHandler,
255+
abbrevHandler,
250256
} = {}) {
251257
const StringType = typeDefs.String?.type
252258
const NumberType = typeDefs.Number?.type
@@ -282,7 +288,7 @@ function parse (args, data, remain, {
282288

283289
// see if it's a shorthand
284290
// if so, splice and back up to re-parse it.
285-
const shRes = resolveShort(arg, shortAbbr, abbrevs, { shorthands })
291+
const shRes = resolveShort(arg, shortAbbr, abbrevs, { shorthands, abbrevHandler })
286292
debug('arg=%j shRes=%j', arg, shRes)
287293
if (shRes) {
288294
args.splice.apply(args, [i, 1].concat(shRes))
@@ -298,7 +304,13 @@ function parse (args, data, remain, {
298304
arg = arg.slice(3)
299305
}
300306

301-
if (abbrevs[arg]) {
307+
// abbrev includes the original full string in its abbrev list
308+
if (abbrevs[arg] && abbrevs[arg] !== arg) {
309+
if (abbrevHandler) {
310+
abbrevHandler(arg, abbrevs[arg])
311+
} else if (abbrevHandler !== false) {
312+
debug(`abbrev: ${arg} -> ${abbrevs[arg]}`)
313+
}
302314
arg = abbrevs[arg]
303315
}
304316

@@ -331,6 +343,23 @@ function parse (args, data, remain, {
331343
(argType === null ||
332344
isTypeArray && ~argType.indexOf(null)))
333345

346+
if (typeof argType === 'undefined') {
347+
// la is going to unexpectedly be parsed outside the context of this arg
348+
const hangingLa = !hadEq && la && !la?.startsWith('-') && !['true', 'false'].includes(la)
349+
if (unknownHandler) {
350+
if (hangingLa) {
351+
unknownHandler(arg, la)
352+
} else {
353+
unknownHandler(arg)
354+
}
355+
} else if (unknownHandler !== false) {
356+
debug(`unknown: ${arg}`)
357+
if (hangingLa) {
358+
debug(`unknown: ${la} parsed as normal opt`)
359+
}
360+
}
361+
}
362+
334363
if (isBool) {
335364
// just set and move along
336365
val = !no
@@ -420,7 +449,7 @@ const singleCharacters = (arg, shorthands) => {
420449
}
421450

422451
function resolveShort (arg, ...rest) {
423-
const { types = {}, shorthands = {} } = rest.length ? rest.pop() : {}
452+
const { abbrevHandler, types = {}, shorthands = {} } = rest.length ? rest.pop() : {}
424453
const shortAbbr = rest[0] ?? abbrev(Object.keys(shorthands))
425454
const abbrevs = rest[1] ?? abbrev(Object.keys(types))
426455

@@ -457,7 +486,13 @@ function resolveShort (arg, ...rest) {
457486
}
458487

459488
// if it's an abbr for a shorthand, then use that
489+
// exact match has already happened so we don't need to account for that here
460490
if (shortAbbr[arg]) {
491+
if (abbrevHandler) {
492+
abbrevHandler(arg, shortAbbr[arg])
493+
} else if (abbrevHandler !== false) {
494+
debug(`abbrev: ${arg} -> ${shortAbbr[arg]}`)
495+
}
461496
arg = shortAbbr[arg]
462497
}
463498

node_modules/nopt/lib/nopt.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function nopt (types, shorthands, args = process.argv, slice = 2) {
1818
shorthands: shorthands || {},
1919
typeDefs: exports.typeDefs,
2020
invalidHandler: exports.invalidHandler,
21+
unknownHandler: exports.unknownHandler,
22+
abbrevHandler: exports.abbrevHandler,
2123
})
2224
}
2325

@@ -26,5 +28,7 @@ function clean (data, types, typeDefs = exports.typeDefs) {
2628
types: types || {},
2729
typeDefs,
2830
invalidHandler: exports.invalidHandler,
31+
unknownHandler: exports.unknownHandler,
32+
abbrevHandler: exports.abbrevHandler,
2933
})
3034
}

node_modules/nopt/node_modules/abbrev/LICENSE

Lines changed: 0 additions & 46 deletions
This file was deleted.

node_modules/nopt/node_modules/abbrev/lib/index.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

node_modules/nopt/node_modules/abbrev/package.json

Lines changed: 0 additions & 43 deletions
This file was deleted.

node_modules/nopt/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nopt",
3-
"version": "8.0.0",
3+
"version": "8.1.0",
44
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.",
55
"author": "GitHub Inc.",
66
"main": "lib/nopt.js",
@@ -23,11 +23,11 @@
2323
},
2424
"license": "ISC",
2525
"dependencies": {
26-
"abbrev": "^2.0.0"
26+
"abbrev": "^3.0.0"
2727
},
2828
"devDependencies": {
2929
"@npmcli/eslint-config": "^5.0.0",
30-
"@npmcli/template-oss": "4.23.3",
30+
"@npmcli/template-oss": "4.23.6",
3131
"tap": "^16.3.0"
3232
},
3333
"tap": {
@@ -46,7 +46,7 @@
4646
"templateOSS": {
4747
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
4848
"windowsCI": false,
49-
"version": "4.23.3",
49+
"version": "4.23.6",
5050
"publish": true
5151
}
5252
}

package-lock.json

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
"minipass-pipeline": "^1.2.4",
129129
"ms": "^2.1.2",
130130
"node-gyp": "^11.2.0",
131-
"nopt": "^8.0.0",
131+
"nopt": "^8.1.0",
132132
"normalize-package-data": "^7.0.0",
133133
"npm-audit-report": "^6.0.0",
134134
"npm-install-checks": "^7.1.1",
@@ -10577,13 +10577,13 @@
1057710577
"license": "MIT"
1057810578
},
1057910579
"node_modules/nopt": {
10580-
"version": "8.0.0",
10581-
"resolved": "https://registry.npmjs.org/nopt/-/nopt-8.0.0.tgz",
10582-
"integrity": "sha512-1L/fTJ4UmV/lUxT2Uf006pfZKTvAgCF+chz+0OgBHO8u2Z67pE7AaAUUj7CJy0lXqHmymUvGFt6NE9R3HER0yw==",
10580+
"version": "8.1.0",
10581+
"resolved": "https://registry.npmjs.org/nopt/-/nopt-8.1.0.tgz",
10582+
"integrity": "sha512-ieGu42u/Qsa4TFktmaKEwM6MQH0pOWnaB3htzh0JRtx84+Mebc0cbZYN5bC+6WTZ4+77xrL9Pn5m7CV6VIkV7A==",
1058310583
"inBundle": true,
1058410584
"license": "ISC",
1058510585
"dependencies": {
10586-
"abbrev": "^2.0.0"
10586+
"abbrev": "^3.0.0"
1058710587
},
1058810588
"bin": {
1058910589
"nopt": "bin/nopt.js"
@@ -10592,16 +10592,6 @@
1059210592
"node": "^18.17.0 || >=20.5.0"
1059310593
}
1059410594
},
10595-
"node_modules/nopt/node_modules/abbrev": {
10596-
"version": "2.0.0",
10597-
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-2.0.0.tgz",
10598-
"integrity": "sha512-6/mh1E2u2YgEsCHdY0Yx5oW+61gZU+1vXaoiHHrpKeuRNNgFvS+/jrwHiQhB5apAf5oB7UB7E19ol2R2LKH8hQ==",
10599-
"inBundle": true,
10600-
"license": "ISC",
10601-
"engines": {
10602-
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
10603-
}
10604-
},
1060510595
"node_modules/normalize-package-data": {
1060610596
"version": "7.0.0",
1060710597
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-7.0.0.tgz",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"minipass-pipeline": "^1.2.4",
9494
"ms": "^2.1.2",
9595
"node-gyp": "^11.2.0",
96-
"nopt": "^8.0.0",
96+
"nopt": "^8.1.0",
9797
"normalize-package-data": "^7.0.0",
9898
"npm-audit-report": "^6.0.0",
9999
"npm-install-checks": "^7.1.1",

0 commit comments

Comments
 (0)