Skip to content

Commit 471309f

Browse files
author
Michael Smith
committed
deps: nopt@10.0.1
1 parent 40395b8 commit 471309f

18 files changed

Lines changed: 588 additions & 146 deletions

File tree

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

node_modules/@npmcli/run-script/node_modules/nopt/bin/nopt.js renamed to node_modules/node-gyp/node_modules/nopt/bin/nopt.js

File renamed without changes.

node_modules/nopt/lib/debug.js renamed to node_modules/node-gyp/node_modules/nopt/lib/debug.js

File renamed without changes.

node_modules/@npmcli/run-script/node_modules/nopt/lib/nopt-lib.js renamed to node_modules/node-gyp/node_modules/nopt/lib/nopt-lib.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const abbrev = require('abbrev')
2+
const debug = require('./debug')
23
const defaultTypeDefs = require('./type-defs')
34

45
const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
@@ -30,6 +31,8 @@ function nopt (args, {
3031
typeDefault,
3132
dynamicTypes,
3233
} = {}) {
34+
debug(types, shorthands, args, typeDefs)
35+
3336
const data = {}
3437
const argv = {
3538
remain: [],
@@ -86,6 +89,7 @@ function clean (data, {
8689
return
8790
}
8891
let val = data[k]
92+
debug('val=%j', val)
8993
const isArray = Array.isArray(val)
9094
let [hasType, rawType] = getType(k, { types, dynamicTypes })
9195
let type = rawType
@@ -102,19 +106,25 @@ function clean (data, {
102106
type = [type]
103107
}
104108

109+
debug('val=%j', val)
110+
debug('types=', type)
105111
val = val.map((v) => {
106112
// if it's an unknown value, then parse false/true/null/numbers/dates
107113
if (typeof v === 'string') {
114+
debug('string %j', v)
108115
v = v.trim()
109116
if ((v === 'null' && ~type.indexOf(null))
110117
|| (v === 'true' &&
111118
(~type.indexOf(true) || hasTypeDef(type, BooleanType)))
112119
|| (v === 'false' &&
113120
(~type.indexOf(false) || hasTypeDef(type, BooleanType)))) {
114121
v = JSON.parse(v)
122+
debug('jsonable %j', v)
115123
} else if (hasTypeDef(type, NumberType) && !isNaN(v)) {
124+
debug('convert to number', v)
116125
v = +v
117126
} else if (hasTypeDef(type, DateType) && !isNaN(Date.parse(v))) {
127+
debug('convert to date', v)
118128
v = new Date(v)
119129
}
120130
}
@@ -138,24 +148,32 @@ function clean (data, {
138148

139149
const d = {}
140150
d[k] = v
151+
debug('prevalidated val', d, v, rawType)
141152
if (!validate(d, k, v, rawType, { typeDefs })) {
142153
if (invalidHandler) {
143154
invalidHandler(k, v, rawType, data)
155+
} else if (invalidHandler !== false) {
156+
debug('invalid: ' + k + '=' + v, rawType)
144157
}
145158
return remove
146159
}
160+
debug('validated v', d, v, rawType)
147161
return d[k]
148162
}).filter((v) => v !== remove)
149163

150164
// if we allow Array specifically, then an empty array is how we
151165
// express 'no value here', not null. Allow it.
152166
if (!val.length && doesNotHaveTypeDef(type, ArrayType)) {
167+
debug('VAL HAS NO LENGTH, DELETE IT', val, k, type.indexOf(ArrayType))
153168
delete data[k]
154169
} else if (isArray) {
170+
debug(isArray, data[k], val)
155171
data[k] = val
156172
} else {
157173
data[k] = val[0]
158174
}
175+
176+
debug('k=%s val=%j', k, val, data[k])
159177
})
160178
}
161179

@@ -181,21 +199,21 @@ function validate (data, k, val, type, { typeDefs } = {}) {
181199
}
182200

183201
// Original comment:
184-
// NaN is poisonous, it means that something is not allowed.
185-
186-
// New comment:
187-
// Changing this to an isNaN check breaks a lot of tests.
188-
// Something is being assumed here that is not actually what happens in practice.
189-
// Fixing it is outside the scope of getting linting to pass in this repo.
190-
// Leaving as-is for now.
202+
// NaN is poisonous. Means that something is not allowed.
203+
// New comment: Changing this to an isNaN check breaks a lot of tests.
204+
// Something is being assumed here that is not actually what happens in
205+
// practice. Fixing it is outside the scope of getting linting to pass in
206+
// this repo. Leaving as-is for now.
191207
/* eslint-disable-next-line no-self-compare */
192208
if (type !== type) {
209+
debug('Poison NaN', k, val, type)
193210
delete data[k]
194211
return false
195212
}
196213

197214
// explicit list of values
198215
if (val === type) {
216+
debug('Explicitly allowed %j', val)
199217
data[k] = val
200218
return true
201219
}
@@ -204,6 +222,7 @@ function validate (data, k, val, type, { typeDefs } = {}) {
204222
let ok = false
205223
const types = Object.keys(typeDefs)
206224
for (let i = 0, l = types.length; i < l; i++) {
225+
debug('test type %j %j %j', k, val, types[i])
207226
const t = typeDefs[types[i]]
208227
if (t && (
209228
(type && type.name && t.type && t.type.name) ?
@@ -219,6 +238,7 @@ function validate (data, k, val, type, { typeDefs } = {}) {
219238
}
220239
}
221240
}
241+
debug('OK? %j (%j %j %j)', ok, k, val, types[types.length - 1])
222242

223243
if (!ok) {
224244
delete data[k]
@@ -238,11 +258,16 @@ function parse (args, data, remain, {
238258
const NumberType = typeDefs.Number?.type
239259
const ArrayType = typeDefs.Array?.type
240260
const BooleanType = typeDefs.Boolean?.type
261+
262+
debug('parse', args, data, remain)
263+
241264
const abbrevs = abbrev(Object.keys(types))
265+
debug('abbrevs=%j', abbrevs)
242266
const shortAbbr = abbrev(Object.keys(shorthands))
243267

244268
for (let i = 0; i < args.length; i++) {
245269
let arg = args[i]
270+
debug('arg', arg)
246271

247272
if (arg.match(/^-{2,}$/)) {
248273
// done with keys.
@@ -264,6 +289,7 @@ function parse (args, data, remain, {
264289
// see if it's a shorthand
265290
// if so, splice and back up to re-parse it.
266291
const shRes = resolveShort(arg, shortAbbr, abbrevs, { shorthands, abbrevHandler })
292+
debug('arg=%j shRes=%j', arg, shRes)
267293
if (shRes) {
268294
args.splice.apply(args, [i, 1].concat(shRes))
269295
if (arg !== shRes[0]) {
@@ -282,6 +308,8 @@ function parse (args, data, remain, {
282308
if (abbrevs[arg] && abbrevs[arg] !== arg) {
283309
if (abbrevHandler) {
284310
abbrevHandler(arg, abbrevs[arg])
311+
} else if (abbrevHandler !== false) {
312+
debug(`abbrev: ${arg} -> ${abbrevs[arg]}`)
285313
}
286314
arg = abbrevs[arg]
287315
}
@@ -324,6 +352,11 @@ function parse (args, data, remain, {
324352
} else {
325353
unknownHandler(arg)
326354
}
355+
} else if (unknownHandler !== false) {
356+
debug(`unknown: ${arg}`)
357+
if (hangingLa) {
358+
debug(`unknown: ${la} parsed as normal opt`)
359+
}
327360
}
328361
}
329362

@@ -409,6 +442,7 @@ const singleCharacters = (arg, shorthands) => {
409442
return l
410443
}, {})
411444
shorthands[SINGLES] = singles
445+
debug('shorthand singles', singles)
412446
}
413447
const chrs = arg.split('').filter((c) => singles[c])
414448
return chrs.join('') === arg ? chrs : null
@@ -456,6 +490,8 @@ function resolveShort (arg, ...rest) {
456490
if (shortAbbr[arg]) {
457491
if (abbrevHandler) {
458492
abbrevHandler(arg, shortAbbr[arg])
493+
} else if (abbrevHandler !== false) {
494+
debug(`abbrev: ${arg} -> ${shortAbbr[arg]}`)
459495
}
460496
arg = shortAbbr[arg]
461497
}

node_modules/@npmcli/run-script/node_modules/nopt/lib/nopt.js renamed to node_modules/node-gyp/node_modules/nopt/lib/nopt.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const lib = require('./nopt-lib')
22
const defaultTypeDefs = require('./type-defs')
33

4-
// This is the version of nopt's API that requires setting typeDefs and invalidHandler on the required `nopt` object since it is a singleton.
5-
// To not do a breaking change an API that requires all options be passed in is located in `nopt-lib.js` and exported here as lib.
4+
// This is the version of nopt's API that requires setting typeDefs and invalidHandler
5+
// on the required `nopt` object since it is a singleton. To not do a breaking change
6+
// an API that requires all options be passed in is located in `nopt-lib.js` and
7+
// exported here as lib.
68
// TODO(breaking): make API only work in non-singleton mode
79

810
module.exports = exports = nopt

node_modules/@npmcli/run-script/node_modules/nopt/lib/type-defs.js renamed to node_modules/node-gyp/node_modules/nopt/lib/type-defs.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const os = require('node:os')
2-
const path = require('node:path')
3-
const { Stream } = require('node:stream')
4-
const { URL } = require('node:url')
1+
const url = require('url')
2+
const path = require('path')
3+
const Stream = require('stream').Stream
4+
const os = require('os')
5+
const debug = require('./debug')
56

67
function validateString (data, k, val) {
78
data[k] = String(val)
@@ -30,6 +31,7 @@ function validatePath (data, k, val) {
3031
}
3132

3233
function validateNumber (data, k, val) {
34+
debug('validate Number %j %j %j', k, val, isNaN(val))
3335
if (isNaN(val)) {
3436
return false
3537
}
@@ -38,6 +40,7 @@ function validateNumber (data, k, val) {
3840

3941
function validateDate (data, k, val) {
4042
const s = Date.parse(val)
43+
debug('validate Date %j %j %j', k, val, s)
4144
if (isNaN(s)) {
4245
return false
4346
}
@@ -60,11 +63,13 @@ function validateBoolean (data, k, val) {
6063
}
6164

6265
function validateUrl (data, k, val) {
63-
const parsed = URL.parse(String(val))
64-
if (!parsed) {
66+
// Changing this would be a breaking change in the npm cli
67+
/* eslint-disable-next-line node/no-deprecated-api */
68+
val = url.parse(String(val))
69+
if (!val.host) {
6570
return false
6671
}
67-
data[k] = parsed.href
72+
data[k] = val.href
6873
}
6974

7075
function validateStream (data, k, val) {
@@ -77,7 +82,7 @@ function validateStream (data, k, val) {
7782
module.exports = {
7883
String: { type: String, validate: validateString },
7984
Boolean: { type: Boolean, validate: validateBoolean },
80-
url: { type: URL, validate: validateUrl },
85+
url: { type: url, validate: validateUrl },
8186
Number: { type: Number, validate: validateNumber },
8287
path: { type: path, validate: validatePath },
8388
Stream: { type: Stream, validate: validateStream },

node_modules/@npmcli/run-script/node_modules/nopt/package.json renamed to node_modules/node-gyp/node_modules/nopt/package.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
{
22
"name": "nopt",
3-
"version": "10.0.1",
3+
"version": "9.0.0",
44
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.",
55
"author": "GitHub Inc.",
66
"main": "lib/nopt.js",
77
"scripts": {
8-
"test": "node --test './test/**/*.js'",
8+
"test": "tap",
99
"lint": "npm run eslint",
1010
"postlint": "template-oss-check",
1111
"template-oss-apply": "template-oss-apply --force",
1212
"lintfix": "npm run eslint -- --fix",
13-
"snap": "node --test --test-update-snapshots './test/**/*.js'",
13+
"snap": "tap",
1414
"posttest": "npm run lint",
15-
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
16-
"test:node20": "node --test test",
17-
"test:cover": "node --test --experimental-test-coverage --test-timeout=3000 --test-coverage-lines=100 --test-coverage-functions=100 --test-coverage-branches=100 './test/**/*.js'"
15+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
1816
},
1917
"repository": {
2018
"type": "git",
@@ -25,26 +23,30 @@
2523
},
2624
"license": "ISC",
2725
"dependencies": {
28-
"abbrev": "^5.0.0"
26+
"abbrev": "^4.0.0"
2927
},
3028
"devDependencies": {
31-
"@npmcli/eslint-config": "^7.0.0",
32-
"@npmcli/template-oss": "5.1.0"
29+
"@npmcli/eslint-config": "^5.0.0",
30+
"@npmcli/template-oss": "4.27.1",
31+
"tap": "^16.3.0"
32+
},
33+
"tap": {
34+
"nyc-arg": [
35+
"--exclude",
36+
"tap-snapshots/**"
37+
]
3338
},
3439
"files": [
3540
"bin/",
3641
"lib/"
3742
],
3843
"engines": {
39-
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
44+
"node": "^20.17.0 || >=22.9.0"
4045
},
4146
"templateOSS": {
4247
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
4348
"windowsCI": false,
44-
"version": "5.1.0",
45-
"publish": true,
46-
"testRunner": "node:test",
47-
"latestCiVersion": 24,
48-
"updateNpm": false
49+
"version": "4.27.1",
50+
"publish": true
4951
}
5052
}

0 commit comments

Comments
 (0)