update electron to v43
All checks were successful
Android Build / publish (push) Successful in 55s
Linux Build / publish (push) Successful in 1m6s

This commit is contained in:
olcxja 2026-07-09 22:38:33 +02:00
commit fb6c8b6ee9
5385 changed files with 513060 additions and 123058 deletions

15
electron/node_modules/nopt/README.md generated vendored
View file

@ -141,14 +141,15 @@ config object and remove its invalid properties.
## Error Handling
By default, nopt outputs a warning to standard error when invalid values for
known options are found. You can change this behavior by assigning a method
to `nopt.invalidHandler`. This method will be called with
the offending `nopt.invalidHandler(key, val, types)`.
By default nopt logs debug messages if `DEBUG_NOPT` or `NOPT_DEBUG` are set in the environment.
If no `nopt.invalidHandler` is assigned, then it will console.error
its whining. If it is assigned to boolean `false` then the warning is
suppressed.
You can assign the following methods to `nopt` for a more granular notification of invalid, unknown, and expanding options:
`nopt.invalidHandler(key, value, type, data)` - Called when a value is invalid for its option.
`nopt.unknownHandler(key, next)` - Called when an option is found that has no configuration. In certain situations the next option on the command line will be parsed on its own instead of as part of the unknown option. In this case `next` will contain that option.
`nopt.abbrevHandler(short, long)` - Called when an option is automatically translated via abbreviations.
You can also set any of these to `false` to disable the debugging messages that they generate.
## Abbreviations

View file

@ -1,7 +1,8 @@
#!/usr/bin/env node
var nopt = require('../lib/nopt')
var path = require('path')
var types = { num: Number,
const nopt = require('../lib/nopt')
const path = require('path')
console.log('parsed', nopt({
num: Number,
bool: Boolean,
help: Boolean,
list: Array,
@ -13,8 +14,8 @@ var types = { num: Number,
config: Boolean,
length: Number,
file: path,
}
var shorthands = { s: ['--str', 'astring'],
}, {
s: ['--str', 'astring'],
b: ['--bool'],
nb: ['--no-bool'],
tft: ['--bool-list', '--no-bool-list', '--bool-list', 'true'],
@ -25,32 +26,4 @@ var shorthands = { s: ['--str', 'astring'],
c: ['--config'],
l: ['--length'],
f: ['--file'],
}
var parsed = nopt(types
, shorthands
, process.argv
, 2)
console.log('parsed', parsed)
if (parsed.help) {
console.log('')
console.log('nopt cli tester')
console.log('')
console.log('types')
console.log(Object.keys(types).map(function M (t) {
var type = types[t]
if (Array.isArray(type)) {
return [t, type.map(function (mappedType) {
return mappedType.name
})]
}
return [t, type && type.name]
}).reduce(function (s, i) {
s[i[0]] = i[1]
return s
}, {}))
console.log('')
console.log('shorthands')
console.log(shorthands)
}
}, process.argv, 2))

5
electron/node_modules/nopt/lib/debug.js generated vendored Normal file
View file

@ -0,0 +1,5 @@
/* istanbul ignore next */
module.exports = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG
// eslint-disable-next-line no-console
? (...a) => console.error(...a)
: () => {}

514
electron/node_modules/nopt/lib/nopt-lib.js generated vendored Normal file
View file

@ -0,0 +1,514 @@
const abbrev = require('abbrev')
const debug = require('./debug')
const defaultTypeDefs = require('./type-defs')
const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
const getType = (k, { types, dynamicTypes }) => {
let hasType = hasOwn(types, k)
let type = types[k]
if (!hasType && typeof dynamicTypes === 'function') {
const matchedType = dynamicTypes(k)
if (matchedType !== undefined) {
type = matchedType
hasType = true
}
}
return [hasType, type]
}
const isTypeDef = (type, def) => def && type === def
const hasTypeDef = (type, def) => def && type.indexOf(def) !== -1
const doesNotHaveTypeDef = (type, def) => def && !hasTypeDef(type, def)
function nopt (args, {
types,
shorthands,
typeDefs,
invalidHandler, // opt is configured but its value does not validate against given type
unknownHandler, // opt is not configured
abbrevHandler, // opt is being expanded via abbrev
typeDefault,
dynamicTypes,
} = {}) {
debug(types, shorthands, args, typeDefs)
const data = {}
const argv = {
remain: [],
cooked: args,
original: args.slice(0),
}
parse(args, data, argv.remain, {
typeDefs, types, dynamicTypes, shorthands, unknownHandler, abbrevHandler,
})
// now data is full
clean(data, { types, dynamicTypes, typeDefs, invalidHandler, typeDefault })
data.argv = argv
Object.defineProperty(data.argv, 'toString', {
value: function () {
return this.original.map(JSON.stringify).join(' ')
},
enumerable: false,
})
return data
}
function clean (data, {
types = {},
typeDefs = {},
dynamicTypes,
invalidHandler,
typeDefault,
} = {}) {
const StringType = typeDefs.String?.type
const NumberType = typeDefs.Number?.type
const ArrayType = typeDefs.Array?.type
const BooleanType = typeDefs.Boolean?.type
const DateType = typeDefs.Date?.type
const hasTypeDefault = typeof typeDefault !== 'undefined'
if (!hasTypeDefault) {
typeDefault = [false, true, null]
if (StringType) {
typeDefault.push(StringType)
}
if (ArrayType) {
typeDefault.push(ArrayType)
}
}
const remove = {}
Object.keys(data).forEach((k) => {
if (k === 'argv') {
return
}
let val = data[k]
debug('val=%j', val)
const isArray = Array.isArray(val)
let [hasType, rawType] = getType(k, { types, dynamicTypes })
let type = rawType
if (!isArray) {
val = [val]
}
if (!type) {
type = typeDefault
}
if (isTypeDef(type, ArrayType)) {
type = typeDefault.concat(ArrayType)
}
if (!Array.isArray(type)) {
type = [type]
}
debug('val=%j', val)
debug('types=', type)
val = val.map((v) => {
// if it's an unknown value, then parse false/true/null/numbers/dates
if (typeof v === 'string') {
debug('string %j', v)
v = v.trim()
if ((v === 'null' && ~type.indexOf(null))
|| (v === 'true' &&
(~type.indexOf(true) || hasTypeDef(type, BooleanType)))
|| (v === 'false' &&
(~type.indexOf(false) || hasTypeDef(type, BooleanType)))) {
v = JSON.parse(v)
debug('jsonable %j', v)
} else if (hasTypeDef(type, NumberType) && !isNaN(v)) {
debug('convert to number', v)
v = +v
} else if (hasTypeDef(type, DateType) && !isNaN(Date.parse(v))) {
debug('convert to date', v)
v = new Date(v)
}
}
if (!hasType) {
if (!hasTypeDefault) {
return v
}
// if the default type has been passed in then we want to validate the
// unknown data key instead of bailing out earlier. we also set the raw
// type which is passed to the invalid handler so that it can be
// determined if during validation if it is unknown vs invalid
rawType = typeDefault
}
// allow `--no-blah` to set 'blah' to null if null is allowed
if (v === false && ~type.indexOf(null) &&
!(~type.indexOf(false) || hasTypeDef(type, BooleanType))) {
v = null
}
const d = {}
d[k] = v
debug('prevalidated val', d, v, rawType)
if (!validate(d, k, v, rawType, { typeDefs })) {
if (invalidHandler) {
invalidHandler(k, v, rawType, data)
} else if (invalidHandler !== false) {
debug('invalid: ' + k + '=' + v, rawType)
}
return remove
}
debug('validated v', d, v, rawType)
return d[k]
}).filter((v) => v !== remove)
// if we allow Array specifically, then an empty array is how we
// express 'no value here', not null. Allow it.
if (!val.length && doesNotHaveTypeDef(type, ArrayType)) {
debug('VAL HAS NO LENGTH, DELETE IT', val, k, type.indexOf(ArrayType))
delete data[k]
} else if (isArray) {
debug(isArray, data[k], val)
data[k] = val
} else {
data[k] = val[0]
}
debug('k=%s val=%j', k, val, data[k])
})
}
function validate (data, k, val, type, { typeDefs } = {}) {
const ArrayType = typeDefs?.Array?.type
// arrays are lists of types.
if (Array.isArray(type)) {
for (let i = 0, l = type.length; i < l; i++) {
if (isTypeDef(type[i], ArrayType)) {
continue
}
if (validate(data, k, val, type[i], { typeDefs })) {
return true
}
}
delete data[k]
return false
}
// an array of anything?
if (isTypeDef(type, ArrayType)) {
return true
}
// Original comment:
// NaN is poisonous. Means that something is not allowed.
// New comment: Changing this to an isNaN check breaks a lot of tests.
// Something is being assumed here that is not actually what happens in
// practice. Fixing it is outside the scope of getting linting to pass in
// this repo. Leaving as-is for now.
/* eslint-disable-next-line no-self-compare */
if (type !== type) {
debug('Poison NaN', k, val, type)
delete data[k]
return false
}
// explicit list of values
if (val === type) {
debug('Explicitly allowed %j', val)
data[k] = val
return true
}
// now go through the list of typeDefs, validate against each one.
let ok = false
const types = Object.keys(typeDefs)
for (let i = 0, l = types.length; i < l; i++) {
debug('test type %j %j %j', k, val, types[i])
const t = typeDefs[types[i]]
if (t && (
(type && type.name && t.type && t.type.name) ?
(type.name === t.type.name) :
(type === t.type)
)) {
const d = {}
ok = t.validate(d, k, val) !== false
val = d[k]
if (ok) {
data[k] = val
break
}
}
}
debug('OK? %j (%j %j %j)', ok, k, val, types[types.length - 1])
if (!ok) {
delete data[k]
}
return ok
}
function parse (args, data, remain, {
types = {},
typeDefs = {},
shorthands = {},
dynamicTypes,
unknownHandler,
abbrevHandler,
} = {}) {
const StringType = typeDefs.String?.type
const NumberType = typeDefs.Number?.type
const ArrayType = typeDefs.Array?.type
const BooleanType = typeDefs.Boolean?.type
debug('parse', args, data, remain)
const abbrevs = abbrev(Object.keys(types))
debug('abbrevs=%j', abbrevs)
const shortAbbr = abbrev(Object.keys(shorthands))
for (let i = 0; i < args.length; i++) {
let arg = args[i]
debug('arg', arg)
if (arg.match(/^-{2,}$/)) {
// done with keys.
// the rest are args.
remain.push.apply(remain, args.slice(i + 1))
args[i] = '--'
break
}
let hadEq = false
if (arg.charAt(0) === '-' && arg.length > 1) {
const at = arg.indexOf('=')
if (at > -1) {
hadEq = true
const v = arg.slice(at + 1)
arg = arg.slice(0, at)
args.splice(i, 1, arg, v)
}
// see if it's a shorthand
// if so, splice and back up to re-parse it.
const shRes = resolveShort(arg, shortAbbr, abbrevs, { shorthands, abbrevHandler })
debug('arg=%j shRes=%j', arg, shRes)
if (shRes) {
args.splice.apply(args, [i, 1].concat(shRes))
if (arg !== shRes[0]) {
i--
continue
}
}
arg = arg.replace(/^-+/, '')
let no = null
while (arg.toLowerCase().indexOf('no-') === 0) {
no = !no
arg = arg.slice(3)
}
// abbrev includes the original full string in its abbrev list
if (abbrevs[arg] && abbrevs[arg] !== arg) {
if (abbrevHandler) {
abbrevHandler(arg, abbrevs[arg])
} else if (abbrevHandler !== false) {
debug(`abbrev: ${arg} -> ${abbrevs[arg]}`)
}
arg = abbrevs[arg]
}
let [hasType, argType] = getType(arg, { types, dynamicTypes })
let isTypeArray = Array.isArray(argType)
if (isTypeArray && argType.length === 1) {
isTypeArray = false
argType = argType[0]
}
let isArray = isTypeDef(argType, ArrayType) ||
isTypeArray && hasTypeDef(argType, ArrayType)
// allow unknown things to be arrays if specified multiple times.
if (!hasType && hasOwn(data, arg)) {
if (!Array.isArray(data[arg])) {
data[arg] = [data[arg]]
}
isArray = true
}
let val
let la = args[i + 1]
const isBool = typeof no === 'boolean' ||
isTypeDef(argType, BooleanType) ||
isTypeArray && hasTypeDef(argType, BooleanType) ||
(typeof argType === 'undefined' && !hadEq) ||
(la === 'false' &&
(argType === null ||
isTypeArray && ~argType.indexOf(null)))
if (typeof argType === 'undefined') {
// la is going to unexpectedly be parsed outside the context of this arg
const hangingLa = !hadEq && la && !la?.startsWith('-') && !['true', 'false'].includes(la)
if (unknownHandler) {
if (hangingLa) {
unknownHandler(arg, la)
} else {
unknownHandler(arg)
}
} else if (unknownHandler !== false) {
debug(`unknown: ${arg}`)
if (hangingLa) {
debug(`unknown: ${la} parsed as normal opt`)
}
}
}
if (isBool) {
// just set and move along
val = !no
// however, also support --bool true or --bool false
if (la === 'true' || la === 'false') {
val = JSON.parse(la)
la = null
if (no) {
val = !val
}
i++
}
// also support "foo":[Boolean, "bar"] and "--foo bar"
if (isTypeArray && la) {
if (~argType.indexOf(la)) {
// an explicit type
val = la
i++
} else if (la === 'null' && ~argType.indexOf(null)) {
// null allowed
val = null
i++
} else if (!la.match(/^-{2,}[^-]/) &&
!isNaN(la) &&
hasTypeDef(argType, NumberType)) {
// number
val = +la
i++
} else if (!la.match(/^-[^-]/) && hasTypeDef(argType, StringType)) {
// string
val = la
i++
}
}
if (isArray) {
(data[arg] = data[arg] || []).push(val)
} else {
data[arg] = val
}
continue
}
if (isTypeDef(argType, StringType)) {
if (la === undefined) {
la = ''
} else if (la.match(/^-{1,2}[^-]+/)) {
la = ''
i--
}
}
if (la && la.match(/^-{2,}$/)) {
la = undefined
i--
}
val = la === undefined ? true : la
if (isArray) {
(data[arg] = data[arg] || []).push(val)
} else {
data[arg] = val
}
i++
continue
}
remain.push(arg)
}
}
const SINGLES = Symbol('singles')
const singleCharacters = (arg, shorthands) => {
let singles = shorthands[SINGLES]
if (!singles) {
singles = Object.keys(shorthands).filter((s) => s.length === 1).reduce((l, r) => {
l[r] = true
return l
}, {})
shorthands[SINGLES] = singles
debug('shorthand singles', singles)
}
const chrs = arg.split('').filter((c) => singles[c])
return chrs.join('') === arg ? chrs : null
}
function resolveShort (arg, ...rest) {
const { abbrevHandler, types = {}, shorthands = {} } = rest.length ? rest.pop() : {}
const shortAbbr = rest[0] ?? abbrev(Object.keys(shorthands))
const abbrevs = rest[1] ?? abbrev(Object.keys(types))
// handle single-char shorthands glommed together, like
// npm ls -glp, but only if there is one dash, and only if
// all of the chars are single-char shorthands, and it's
// not a match to some other abbrev.
arg = arg.replace(/^-+/, '')
// if it's an exact known option, then don't go any further
if (abbrevs[arg] === arg) {
return null
}
// if it's an exact known shortopt, same deal
if (shorthands[arg]) {
// make it an array, if it's a list of words
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
shorthands[arg] = shorthands[arg].split(/\s+/)
}
return shorthands[arg]
}
// first check to see if this arg is a set of single-char shorthands
const chrs = singleCharacters(arg, shorthands)
if (chrs) {
return chrs.map((c) => shorthands[c]).reduce((l, r) => l.concat(r), [])
}
// if it's an arg abbrev, and not a literal shorthand, then prefer the arg
if (abbrevs[arg] && !shorthands[arg]) {
return null
}
// if it's an abbr for a shorthand, then use that
// exact match has already happened so we don't need to account for that here
if (shortAbbr[arg]) {
if (abbrevHandler) {
abbrevHandler(arg, shortAbbr[arg])
} else if (abbrevHandler !== false) {
debug(`abbrev: ${arg} -> ${shortAbbr[arg]}`)
}
arg = shortAbbr[arg]
}
// make it an array, if it's a list of words
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
shorthands[arg] = shorthands[arg].split(/\s+/)
}
return shorthands[arg]
}
module.exports = {
nopt,
clean,
parse,
validate,
resolveShort,
typeDefs: defaultTypeDefs,
}

View file

@ -1,515 +1,34 @@
// info about each config option.
const lib = require('./nopt-lib')
const defaultTypeDefs = require('./type-defs')
var debug = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG
? function () {
console.error.apply(console, arguments)
}
: function () {}
var url = require('url')
var path = require('path')
var Stream = require('stream').Stream
var abbrev = require('abbrev')
var os = require('os')
// This is the version of nopt's API that requires setting typeDefs and invalidHandler
// on the required `nopt` object since it is a singleton. 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.
// TODO(breaking): make API only work in non-singleton mode
module.exports = exports = nopt
exports.clean = clean
exports.typeDefs = defaultTypeDefs
exports.lib = lib
exports.typeDefs =
{ String: { type: String, validate: validateString },
Boolean: { type: Boolean, validate: validateBoolean },
url: { type: url, validate: validateUrl },
Number: { type: Number, validate: validateNumber },
path: { type: path, validate: validatePath },
Stream: { type: Stream, validate: validateStream },
Date: { type: Date, validate: validateDate },
}
function nopt (types, shorthands, args, slice) {
args = args || process.argv
types = types || {}
shorthands = shorthands || {}
if (typeof slice !== 'number') {
slice = 2
}
debug(types, shorthands, args, slice)
args = args.slice(slice)
var data = {}
var argv = {
remain: [],
cooked: args,
original: args.slice(0),
}
parse(args, data, argv.remain, types, shorthands)
// now data is full
clean(data, types, exports.typeDefs)
data.argv = argv
Object.defineProperty(data.argv, 'toString', { value: function () {
return this.original.map(JSON.stringify).join(' ')
},
enumerable: false })
return data
}
function clean (data, types, typeDefs) {
typeDefs = typeDefs || exports.typeDefs
var remove = {}
var typeDefault = [false, true, null, String, Array]
Object.keys(data).forEach(function (k) {
if (k === 'argv') {
return
}
var val = data[k]
var isArray = Array.isArray(val)
var type = types[k]
if (!isArray) {
val = [val]
}
if (!type) {
type = typeDefault
}
if (type === Array) {
type = typeDefault.concat(Array)
}
if (!Array.isArray(type)) {
type = [type]
}
debug('val=%j', val)
debug('types=', type)
val = val.map(function (v) {
// if it's an unknown value, then parse false/true/null/numbers/dates
if (typeof v === 'string') {
debug('string %j', v)
v = v.trim()
if ((v === 'null' && ~type.indexOf(null))
|| (v === 'true' &&
(~type.indexOf(true) || ~type.indexOf(Boolean)))
|| (v === 'false' &&
(~type.indexOf(false) || ~type.indexOf(Boolean)))) {
v = JSON.parse(v)
debug('jsonable %j', v)
} else if (~type.indexOf(Number) && !isNaN(v)) {
debug('convert to number', v)
v = +v
} else if (~type.indexOf(Date) && !isNaN(Date.parse(v))) {
debug('convert to date', v)
v = new Date(v)
}
}
if (!Object.prototype.hasOwnProperty.call(types, k)) {
return v
}
// allow `--no-blah` to set 'blah' to null if null is allowed
if (v === false && ~type.indexOf(null) &&
!(~type.indexOf(false) || ~type.indexOf(Boolean))) {
v = null
}
var d = {}
d[k] = v
debug('prevalidated val', d, v, types[k])
if (!validate(d, k, v, types[k], typeDefs)) {
if (exports.invalidHandler) {
exports.invalidHandler(k, v, types[k], data)
} else if (exports.invalidHandler !== false) {
debug('invalid: ' + k + '=' + v, types[k])
}
return remove
}
debug('validated v', d, v, types[k])
return d[k]
}).filter(function (v) {
return v !== remove
})
// if we allow Array specifically, then an empty array is how we
// express 'no value here', not null. Allow it.
if (!val.length && type.indexOf(Array) === -1) {
debug('VAL HAS NO LENGTH, DELETE IT', val, k, type.indexOf(Array))
delete data[k]
} else if (isArray) {
debug(isArray, data[k], val)
data[k] = val
} else {
data[k] = val[0]
}
debug('k=%s val=%j', k, val, data[k])
function nopt (types, shorthands, args = process.argv, slice = 2) {
return lib.nopt(args.slice(slice), {
types: types || {},
shorthands: shorthands || {},
typeDefs: exports.typeDefs,
invalidHandler: exports.invalidHandler,
unknownHandler: exports.unknownHandler,
abbrevHandler: exports.abbrevHandler,
})
}
function validateString (data, k, val) {
data[k] = String(val)
}
function validatePath (data, k, val) {
if (val === true) {
return false
}
if (val === null) {
return true
}
val = String(val)
var isWin = process.platform === 'win32'
var homePattern = isWin ? /^~(\/|\\)/ : /^~\//
var home = os.homedir()
if (home && val.match(homePattern)) {
data[k] = path.resolve(home, val.slice(2))
} else {
data[k] = path.resolve(val)
}
return true
}
function validateNumber (data, k, val) {
debug('validate Number %j %j %j', k, val, isNaN(val))
if (isNaN(val)) {
return false
}
data[k] = +val
}
function validateDate (data, k, val) {
var s = Date.parse(val)
debug('validate Date %j %j %j', k, val, s)
if (isNaN(s)) {
return false
}
data[k] = new Date(val)
}
function validateBoolean (data, k, val) {
if (val instanceof Boolean) {
val = val.valueOf()
} else if (typeof val === 'string') {
if (!isNaN(val)) {
val = !!(+val)
} else if (val === 'null' || val === 'false') {
val = false
} else {
val = true
}
} else {
val = !!val
}
data[k] = val
}
function validateUrl (data, k, val) {
// Changing this would be a breaking change in the npm cli
/* eslint-disable-next-line node/no-deprecated-api */
val = url.parse(String(val))
if (!val.host) {
return false
}
data[k] = val.href
}
function validateStream (data, k, val) {
if (!(val instanceof Stream)) {
return false
}
data[k] = val
}
function validate (data, k, val, type, typeDefs) {
// arrays are lists of types.
if (Array.isArray(type)) {
for (let i = 0, l = type.length; i < l; i++) {
if (type[i] === Array) {
continue
}
if (validate(data, k, val, type[i], typeDefs)) {
return true
}
}
delete data[k]
return false
}
// an array of anything?
if (type === Array) {
return true
}
// Original comment:
// NaN is poisonous. Means that something is not allowed.
// New comment: Changing this to an isNaN check breaks a lot of tests.
// Something is being assumed here that is not actually what happens in
// practice. Fixing it is outside the scope of getting linting to pass in
// this repo. Leaving as-is for now.
/* eslint-disable-next-line no-self-compare */
if (type !== type) {
debug('Poison NaN', k, val, type)
delete data[k]
return false
}
// explicit list of values
if (val === type) {
debug('Explicitly allowed %j', val)
// if (isArray) (data[k] = data[k] || []).push(val)
// else data[k] = val
data[k] = val
return true
}
// now go through the list of typeDefs, validate against each one.
var ok = false
var types = Object.keys(typeDefs)
for (let i = 0, l = types.length; i < l; i++) {
debug('test type %j %j %j', k, val, types[i])
var t = typeDefs[types[i]]
if (t && (
(type && type.name && t.type && t.type.name) ?
(type.name === t.type.name) :
(type === t.type)
)) {
var d = {}
ok = t.validate(d, k, val) !== false
val = d[k]
if (ok) {
// if (isArray) (data[k] = data[k] || []).push(val)
// else data[k] = val
data[k] = val
break
}
}
}
debug('OK? %j (%j %j %j)', ok, k, val, types[types.length - 1])
if (!ok) {
delete data[k]
}
return ok
}
function parse (args, data, remain, types, shorthands) {
debug('parse', args, data, remain)
var abbrevs = abbrev(Object.keys(types))
var shortAbbr = abbrev(Object.keys(shorthands))
for (var i = 0; i < args.length; i++) {
var arg = args[i]
debug('arg', arg)
if (arg.match(/^-{2,}$/)) {
// done with keys.
// the rest are args.
remain.push.apply(remain, args.slice(i + 1))
args[i] = '--'
break
}
var hadEq = false
if (arg.charAt(0) === '-' && arg.length > 1) {
var at = arg.indexOf('=')
if (at > -1) {
hadEq = true
var v = arg.slice(at + 1)
arg = arg.slice(0, at)
args.splice(i, 1, arg, v)
}
// see if it's a shorthand
// if so, splice and back up to re-parse it.
var shRes = resolveShort(arg, shorthands, shortAbbr, abbrevs)
debug('arg=%j shRes=%j', arg, shRes)
if (shRes) {
debug(arg, shRes)
args.splice.apply(args, [i, 1].concat(shRes))
if (arg !== shRes[0]) {
i--
continue
}
}
arg = arg.replace(/^-+/, '')
var no = null
while (arg.toLowerCase().indexOf('no-') === 0) {
no = !no
arg = arg.slice(3)
}
if (abbrevs[arg]) {
arg = abbrevs[arg]
}
var argType = types[arg]
var isTypeArray = Array.isArray(argType)
if (isTypeArray && argType.length === 1) {
isTypeArray = false
argType = argType[0]
}
var isArray = argType === Array ||
isTypeArray && argType.indexOf(Array) !== -1
// allow unknown things to be arrays if specified multiple times.
if (
!Object.prototype.hasOwnProperty.call(types, arg) &&
Object.prototype.hasOwnProperty.call(data, arg)
) {
if (!Array.isArray(data[arg])) {
data[arg] = [data[arg]]
}
isArray = true
}
var val
var la = args[i + 1]
var isBool = typeof no === 'boolean' ||
argType === Boolean ||
isTypeArray && argType.indexOf(Boolean) !== -1 ||
(typeof argType === 'undefined' && !hadEq) ||
(la === 'false' &&
(argType === null ||
isTypeArray && ~argType.indexOf(null)))
if (isBool) {
// just set and move along
val = !no
// however, also support --bool true or --bool false
if (la === 'true' || la === 'false') {
val = JSON.parse(la)
la = null
if (no) {
val = !val
}
i++
}
// also support "foo":[Boolean, "bar"] and "--foo bar"
if (isTypeArray && la) {
if (~argType.indexOf(la)) {
// an explicit type
val = la
i++
} else if (la === 'null' && ~argType.indexOf(null)) {
// null allowed
val = null
i++
} else if (!la.match(/^-{2,}[^-]/) &&
!isNaN(la) &&
~argType.indexOf(Number)) {
// number
val = +la
i++
} else if (!la.match(/^-[^-]/) && ~argType.indexOf(String)) {
// string
val = la
i++
}
}
if (isArray) {
(data[arg] = data[arg] || []).push(val)
} else {
data[arg] = val
}
continue
}
if (argType === String) {
if (la === undefined) {
la = ''
} else if (la.match(/^-{1,2}[^-]+/)) {
la = ''
i--
}
}
if (la && la.match(/^-{2,}$/)) {
la = undefined
i--
}
val = la === undefined ? true : la
if (isArray) {
(data[arg] = data[arg] || []).push(val)
} else {
data[arg] = val
}
i++
continue
}
remain.push(arg)
}
}
function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
// handle single-char shorthands glommed together, like
// npm ls -glp, but only if there is one dash, and only if
// all of the chars are single-char shorthands, and it's
// not a match to some other abbrev.
arg = arg.replace(/^-+/, '')
// if it's an exact known option, then don't go any further
if (abbrevs[arg] === arg) {
return null
}
// if it's an exact known shortopt, same deal
if (shorthands[arg]) {
// make it an array, if it's a list of words
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
shorthands[arg] = shorthands[arg].split(/\s+/)
}
return shorthands[arg]
}
// first check to see if this arg is a set of single-char shorthands
var singles = shorthands.___singles
if (!singles) {
singles = Object.keys(shorthands).filter(function (s) {
return s.length === 1
}).reduce(function (l, r) {
l[r] = true
return l
}, {})
shorthands.___singles = singles
debug('shorthand singles', singles)
}
var chrs = arg.split('').filter(function (c) {
return singles[c]
function clean (data, types, typeDefs = exports.typeDefs) {
return lib.clean(data, {
types: types || {},
typeDefs,
invalidHandler: exports.invalidHandler,
unknownHandler: exports.unknownHandler,
abbrevHandler: exports.abbrevHandler,
})
if (chrs.join('') === arg) {
return chrs.map(function (c) {
return shorthands[c]
}).reduce(function (l, r) {
return l.concat(r)
}, [])
}
// if it's an arg abbrev, and not a literal shorthand, then prefer the arg
if (abbrevs[arg] && !shorthands[arg]) {
return null
}
// if it's an abbr for a shorthand, then use that
if (shortAbbr[arg]) {
arg = shortAbbr[arg]
}
// make it an array, if it's a list of words
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
shorthands[arg] = shorthands[arg].split(/\s+/)
}
return shorthands[arg]
}

91
electron/node_modules/nopt/lib/type-defs.js generated vendored Normal file
View file

@ -0,0 +1,91 @@
const url = require('url')
const path = require('path')
const Stream = require('stream').Stream
const os = require('os')
const debug = require('./debug')
function validateString (data, k, val) {
data[k] = String(val)
}
function validatePath (data, k, val) {
if (val === true) {
return false
}
if (val === null) {
return true
}
val = String(val)
const isWin = process.platform === 'win32'
const homePattern = isWin ? /^~(\/|\\)/ : /^~\//
const home = os.homedir()
if (home && val.match(homePattern)) {
data[k] = path.resolve(home, val.slice(2))
} else {
data[k] = path.resolve(val)
}
return true
}
function validateNumber (data, k, val) {
debug('validate Number %j %j %j', k, val, isNaN(val))
if (isNaN(val)) {
return false
}
data[k] = +val
}
function validateDate (data, k, val) {
const s = Date.parse(val)
debug('validate Date %j %j %j', k, val, s)
if (isNaN(s)) {
return false
}
data[k] = new Date(val)
}
function validateBoolean (data, k, val) {
if (typeof val === 'string') {
if (!isNaN(val)) {
val = !!(+val)
} else if (val === 'null' || val === 'false') {
val = false
} else {
val = true
}
} else {
val = !!val
}
data[k] = val
}
function validateUrl (data, k, val) {
// Changing this would be a breaking change in the npm cli
/* eslint-disable-next-line node/no-deprecated-api */
val = url.parse(String(val))
if (!val.host) {
return false
}
data[k] = val.href
}
function validateStream (data, k, val) {
if (!(val instanceof Stream)) {
return false
}
data[k] = val
}
module.exports = {
String: { type: String, validate: validateString },
Boolean: { type: Boolean, validate: validateBoolean },
url: { type: url, validate: validateUrl },
Number: { type: Number, validate: validateNumber },
path: { type: path, validate: validatePath },
Stream: { type: Stream, validate: validateStream },
Date: { type: Date, validate: validateDate },
Array: { type: Array },
}

View file

@ -1,53 +1,52 @@
{
"name": "nopt",
"version": "6.0.0",
"version": "9.0.0",
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.",
"author": "GitHub Inc.",
"main": "lib/nopt.js",
"scripts": {
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"test": "tap",
"lint": "eslint \"**/*.js\"",
"lint": "npm run eslint",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"lintfix": "npm run eslint -- --fix",
"snap": "tap",
"posttest": "npm run lint"
"posttest": "npm run lint",
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
},
"repository": {
"type": "git",
"url": "https://github.com/npm/nopt.git"
"url": "git+https://github.com/npm/nopt.git"
},
"bin": {
"nopt": "bin/nopt.js"
},
"license": "ISC",
"dependencies": {
"abbrev": "^1.0.0"
"abbrev": "^4.0.0"
},
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "3.5.0",
"@npmcli/eslint-config": "^5.0.0",
"@npmcli/template-oss": "4.27.1",
"tap": "^16.3.0"
},
"tap": {
"lines": 87,
"functions": 91,
"branches": 81,
"statements": 87
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
},
"files": [
"bin/",
"lib/"
],
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
"node": "^20.17.0 || >=22.9.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"windowsCI": false,
"version": "3.5.0"
"version": "4.27.1",
"publish": true
}
}