Skip to content

Commit f0f6265

Browse files
committed
1 parent 63f2fd7 commit f0f6265

File tree

10 files changed

+56
-169
lines changed

10 files changed

+56
-169
lines changed

node_modules/.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@
150150
!/node-gyp/node_modules/tar
151151
!/node-gyp/node_modules/yallist
152152
!/nopt
153-
!/nopt/node_modules/
154-
/nopt/node_modules/*
155-
!/nopt/node_modules/abbrev
156153
!/normalize-package-data
157154
!/npm-audit-report
158155
!/npm-bundled

node_modules/nopt/lib/nopt-lib.js

+40-5
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

+4
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

-46
This file was deleted.

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

-50
This file was deleted.

node_modules/nopt/node_modules/abbrev/package.json

-43
This file was deleted.

node_modules/nopt/package.json

+4-4
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

+6-16
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"minipass-pipeline": "^1.2.4",
126126
"ms": "^2.1.2",
127127
"node-gyp": "^11.0.0",
128-
"nopt": "^8.0.0",
128+
"nopt": "^8.1.0",
129129
"normalize-package-data": "^7.0.0",
130130
"npm-audit-report": "^6.0.0",
131131
"npm-install-checks": "^7.1.1",
@@ -12310,13 +12310,13 @@
1231012310
"license": "MIT"
1231112311
},
1231212312
"node_modules/nopt": {
12313-
"version": "8.0.0",
12314-
"resolved": "https://registry.npmjs.org/nopt/-/nopt-8.0.0.tgz",
12315-
"integrity": "sha512-1L/fTJ4UmV/lUxT2Uf006pfZKTvAgCF+chz+0OgBHO8u2Z67pE7AaAUUj7CJy0lXqHmymUvGFt6NE9R3HER0yw==",
12313+
"version": "8.1.0",
12314+
"resolved": "https://registry.npmjs.org/nopt/-/nopt-8.1.0.tgz",
12315+
"integrity": "sha512-ieGu42u/Qsa4TFktmaKEwM6MQH0pOWnaB3htzh0JRtx84+Mebc0cbZYN5bC+6WTZ4+77xrL9Pn5m7CV6VIkV7A==",
1231612316
"inBundle": true,
1231712317
"license": "ISC",
1231812318
"dependencies": {
12319-
"abbrev": "^2.0.0"
12319+
"abbrev": "^3.0.0"
1232012320
},
1232112321
"bin": {
1232212322
"nopt": "bin/nopt.js"
@@ -12325,16 +12325,6 @@
1232512325
"node": "^18.17.0 || >=20.5.0"
1232612326
}
1232712327
},
12328-
"node_modules/nopt/node_modules/abbrev": {
12329-
"version": "2.0.0",
12330-
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-2.0.0.tgz",
12331-
"integrity": "sha512-6/mh1E2u2YgEsCHdY0Yx5oW+61gZU+1vXaoiHHrpKeuRNNgFvS+/jrwHiQhB5apAf5oB7UB7E19ol2R2LKH8hQ==",
12332-
"inBundle": true,
12333-
"license": "ISC",
12334-
"engines": {
12335-
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
12336-
}
12337-
},
1233812328
"node_modules/normalize-package-data": {
1233912329
"version": "7.0.0",
1234012330
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-7.0.0.tgz",
@@ -18815,7 +18805,7 @@
1881518805
"@npmcli/package-json": "^6.0.1",
1881618806
"ci-info": "^4.0.0",
1881718807
"ini": "^5.0.0",
18818-
"nopt": "^8.0.0",
18808+
"nopt": "^8.1.0",
1881918809
"proc-log": "^5.0.0",
1882018810
"semver": "^7.3.5",
1882118811
"walk-up-path": "^4.0.0"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"minipass-pipeline": "^1.2.4",
9393
"ms": "^2.1.2",
9494
"node-gyp": "^11.0.0",
95-
"nopt": "^8.0.0",
95+
"nopt": "^8.1.0",
9696
"normalize-package-data": "^7.0.0",
9797
"npm-audit-report": "^6.0.0",
9898
"npm-install-checks": "^7.1.1",

workspaces/config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@npmcli/package-json": "^6.0.1",
4242
"ci-info": "^4.0.0",
4343
"ini": "^5.0.0",
44-
"nopt": "^8.0.0",
44+
"nopt": "^8.1.0",
4545
"proc-log": "^5.0.0",
4646
"semver": "^7.3.5",
4747
"walk-up-path": "^4.0.0"

0 commit comments

Comments
 (0)