pnpm 7.13.0 → 7.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node_modules/.modules.yaml +3 -3
- package/dist/node_modules/.pnpm/lock.yaml +46 -44
- package/dist/node_modules/@npmcli/fs/lib/common/owner-sync.js +8 -4
- package/dist/node_modules/@npmcli/fs/lib/common/owner.js +8 -4
- package/dist/node_modules/@npmcli/fs/lib/index.js +1 -1
- package/dist/node_modules/@npmcli/fs/lib/mkdir.js +19 -0
- package/dist/node_modules/@npmcli/fs/lib/with-temp-dir.js +4 -2
- package/dist/node_modules/@npmcli/fs/package.json +4 -4
- package/dist/node_modules/@npmcli/move-file/lib/index.js +16 -6
- package/dist/node_modules/@npmcli/move-file/package.json +3 -3
- package/dist/node_modules/are-we-there-yet/lib/tracker-group.js +1 -1
- package/dist/node_modules/are-we-there-yet/package.json +12 -13
- package/dist/node_modules/cacache/lib/content/read.js +1 -1
- package/dist/node_modules/cacache/lib/content/write.js +2 -0
- package/dist/node_modules/cacache/lib/entry-index.js +1 -0
- package/dist/node_modules/cacache/lib/get.js +1 -0
- package/dist/node_modules/cacache/package.json +2 -2
- package/dist/node_modules/ip/lib/ip.js +54 -59
- package/dist/node_modules/ip/package.json +1 -1
- package/dist/node_modules/lru-cache/index.js +21 -8
- package/dist/node_modules/lru-cache/package.json +3 -2
- package/dist/node_modules/make-fetch-happen/lib/cache/entry.js +2 -0
- package/dist/node_modules/make-fetch-happen/package.json +1 -1
- package/dist/node_modules/minipass-fetch/lib/body.js +13 -11
- package/dist/node_modules/minipass-fetch/package.json +4 -3
- package/dist/node_modules/node-gyp/addon.gypi +5 -0
- package/dist/node_modules/node-gyp/gyp/.github/workflows/Python_tests.yml +3 -3
- package/dist/node_modules/node-gyp/gyp/.github/workflows/node-gyp.yml +5 -5
- package/dist/node_modules/node-gyp/gyp/.github/workflows/nodejs-windows.yml +2 -2
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +12 -0
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/common.py +9 -3
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +1 -1
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +191 -26
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +7 -4
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2 -2
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/input.py +7 -14
- package/dist/node_modules/node-gyp/gyp/setup.py +1 -1
- package/dist/node_modules/node-gyp/gyp/test_gyp.py +1 -0
- package/dist/node_modules/node-gyp/gyp/tools/pretty_gyp.py +1 -1
- package/dist/node_modules/node-gyp/lib/build.js +2 -0
- package/dist/node_modules/node-gyp/lib/configure.js +45 -4
- package/dist/node_modules/node-gyp/package.json +2 -2
- package/dist/node_modules/node-gyp/update-gyp.py +19 -1
- package/dist/node_modules/nopt/bin/nopt.js +41 -39
- package/dist/node_modules/nopt/lib/nopt.js +222 -148
- package/dist/node_modules/nopt/package.json +27 -8
- package/dist/node_modules/socks/.eslintrc.cjs +11 -0
- package/dist/node_modules/socks/build/client/socksclient.js +8 -6
- package/dist/node_modules/socks/build/client/socksclient.js.map +1 -1
- package/dist/node_modules/socks/build/common/receivebuffer.js.map +1 -1
- package/dist/node_modules/socks/build/common/util.js +0 -1
- package/dist/node_modules/socks/build/common/util.js.map +1 -1
- package/dist/node_modules/socks/build/index.js +5 -1
- package/dist/node_modules/socks/build/index.js.map +1 -1
- package/dist/node_modules/socks/package.json +12 -37
- package/dist/node_modules/unique-filename/{index.js → lib/index.js} +0 -1
- package/dist/node_modules/unique-filename/package.json +29 -8
- package/dist/node_modules/unique-slug/{index.js → lib/index.js} +2 -2
- package/dist/node_modules/unique-slug/package.json +28 -7
- package/dist/pnpm.cjs +690 -625
- package/package.json +5 -5
- package/dist/node_modules/@npmcli/fs/lib/common/file-url-to-path/index.js +0 -17
- package/dist/node_modules/@npmcli/fs/lib/common/file-url-to-path/polyfill.js +0 -121
- package/dist/node_modules/@npmcli/fs/lib/mkdir/index.js +0 -29
- package/dist/node_modules/@npmcli/fs/lib/mkdir/polyfill.js +0 -81
|
@@ -1,130 +1,147 @@
|
|
|
1
1
|
// info about each config option.
|
|
2
2
|
|
|
3
3
|
var debug = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG
|
|
4
|
-
? function () {
|
|
4
|
+
? function () {
|
|
5
|
+
console.error.apply(console, arguments)
|
|
6
|
+
}
|
|
5
7
|
: function () {}
|
|
6
8
|
|
|
7
|
-
var url = require(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
var url = require('url')
|
|
10
|
+
var path = require('path')
|
|
11
|
+
var Stream = require('stream').Stream
|
|
12
|
+
var abbrev = require('abbrev')
|
|
13
|
+
var os = require('os')
|
|
12
14
|
|
|
13
15
|
module.exports = exports = nopt
|
|
14
16
|
exports.clean = clean
|
|
15
17
|
|
|
16
18
|
exports.typeDefs =
|
|
17
|
-
{ String
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
{ String: { type: String, validate: validateString },
|
|
20
|
+
Boolean: { type: Boolean, validate: validateBoolean },
|
|
21
|
+
url: { type: url, validate: validateUrl },
|
|
22
|
+
Number: { type: Number, validate: validateNumber },
|
|
23
|
+
path: { type: path, validate: validatePath },
|
|
24
|
+
Stream: { type: Stream, validate: validateStream },
|
|
25
|
+
Date: { type: Date, validate: validateDate },
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
function nopt (types, shorthands, args, slice) {
|
|
27
29
|
args = args || process.argv
|
|
28
30
|
types = types || {}
|
|
29
31
|
shorthands = shorthands || {}
|
|
30
|
-
if (typeof slice !==
|
|
32
|
+
if (typeof slice !== 'number') {
|
|
33
|
+
slice = 2
|
|
34
|
+
}
|
|
31
35
|
|
|
32
36
|
debug(types, shorthands, args, slice)
|
|
33
37
|
|
|
34
38
|
args = args.slice(slice)
|
|
35
39
|
var data = {}
|
|
36
|
-
|
|
37
|
-
,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
40
|
+
var argv = {
|
|
41
|
+
remain: [],
|
|
42
|
+
cooked: args,
|
|
43
|
+
original: args.slice(0),
|
|
44
|
+
}
|
|
42
45
|
|
|
43
46
|
parse(args, data, argv.remain, types, shorthands)
|
|
44
47
|
// now data is full
|
|
45
48
|
clean(data, types, exports.typeDefs)
|
|
46
49
|
data.argv = argv
|
|
47
50
|
Object.defineProperty(data.argv, 'toString', { value: function () {
|
|
48
|
-
return this.original.map(JSON.stringify).join(
|
|
49
|
-
},
|
|
51
|
+
return this.original.map(JSON.stringify).join(' ')
|
|
52
|
+
},
|
|
53
|
+
enumerable: false })
|
|
50
54
|
return data
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
function clean (data, types, typeDefs) {
|
|
54
58
|
typeDefs = typeDefs || exports.typeDefs
|
|
55
59
|
var remove = {}
|
|
56
|
-
|
|
60
|
+
var typeDefault = [false, true, null, String, Array]
|
|
57
61
|
|
|
58
62
|
Object.keys(data).forEach(function (k) {
|
|
59
|
-
if (k ===
|
|
63
|
+
if (k === 'argv') {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
60
66
|
var val = data[k]
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!isArray)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (!
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
var isArray = Array.isArray(val)
|
|
68
|
+
var type = types[k]
|
|
69
|
+
if (!isArray) {
|
|
70
|
+
val = [val]
|
|
71
|
+
}
|
|
72
|
+
if (!type) {
|
|
73
|
+
type = typeDefault
|
|
74
|
+
}
|
|
75
|
+
if (type === Array) {
|
|
76
|
+
type = typeDefault.concat(Array)
|
|
77
|
+
}
|
|
78
|
+
if (!Array.isArray(type)) {
|
|
79
|
+
type = [type]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
debug('val=%j', val)
|
|
83
|
+
debug('types=', type)
|
|
84
|
+
val = val.map(function (v) {
|
|
71
85
|
// if it's an unknown value, then parse false/true/null/numbers/dates
|
|
72
|
-
if (typeof
|
|
73
|
-
debug(
|
|
74
|
-
|
|
75
|
-
if ((
|
|
76
|
-
|| (
|
|
86
|
+
if (typeof v === 'string') {
|
|
87
|
+
debug('string %j', v)
|
|
88
|
+
v = v.trim()
|
|
89
|
+
if ((v === 'null' && ~type.indexOf(null))
|
|
90
|
+
|| (v === 'true' &&
|
|
77
91
|
(~type.indexOf(true) || ~type.indexOf(Boolean)))
|
|
78
|
-
|| (
|
|
92
|
+
|| (v === 'false' &&
|
|
79
93
|
(~type.indexOf(false) || ~type.indexOf(Boolean)))) {
|
|
80
|
-
|
|
81
|
-
debug(
|
|
82
|
-
} else if (~type.indexOf(Number) && !isNaN(
|
|
83
|
-
debug(
|
|
84
|
-
|
|
85
|
-
} else if (~type.indexOf(Date) && !isNaN(Date.parse(
|
|
86
|
-
debug(
|
|
87
|
-
|
|
94
|
+
v = JSON.parse(v)
|
|
95
|
+
debug('jsonable %j', v)
|
|
96
|
+
} else if (~type.indexOf(Number) && !isNaN(v)) {
|
|
97
|
+
debug('convert to number', v)
|
|
98
|
+
v = +v
|
|
99
|
+
} else if (~type.indexOf(Date) && !isNaN(Date.parse(v))) {
|
|
100
|
+
debug('convert to date', v)
|
|
101
|
+
v = new Date(v)
|
|
88
102
|
}
|
|
89
103
|
}
|
|
90
104
|
|
|
91
|
-
if (!
|
|
92
|
-
return
|
|
105
|
+
if (!Object.prototype.hasOwnProperty.call(types, k)) {
|
|
106
|
+
return v
|
|
93
107
|
}
|
|
94
108
|
|
|
95
109
|
// allow `--no-blah` to set 'blah' to null if null is allowed
|
|
96
|
-
if (
|
|
110
|
+
if (v === false && ~type.indexOf(null) &&
|
|
97
111
|
!(~type.indexOf(false) || ~type.indexOf(Boolean))) {
|
|
98
|
-
|
|
112
|
+
v = null
|
|
99
113
|
}
|
|
100
114
|
|
|
101
115
|
var d = {}
|
|
102
|
-
d[k] =
|
|
103
|
-
debug(
|
|
104
|
-
if (!validate(d, k,
|
|
116
|
+
d[k] = v
|
|
117
|
+
debug('prevalidated val', d, v, types[k])
|
|
118
|
+
if (!validate(d, k, v, types[k], typeDefs)) {
|
|
105
119
|
if (exports.invalidHandler) {
|
|
106
|
-
exports.invalidHandler(k,
|
|
120
|
+
exports.invalidHandler(k, v, types[k], data)
|
|
107
121
|
} else if (exports.invalidHandler !== false) {
|
|
108
|
-
debug(
|
|
122
|
+
debug('invalid: ' + k + '=' + v, types[k])
|
|
109
123
|
}
|
|
110
124
|
return remove
|
|
111
125
|
}
|
|
112
|
-
debug(
|
|
126
|
+
debug('validated v', d, v, types[k])
|
|
113
127
|
return d[k]
|
|
114
|
-
}).filter(function (
|
|
128
|
+
}).filter(function (v) {
|
|
129
|
+
return v !== remove
|
|
130
|
+
})
|
|
115
131
|
|
|
116
132
|
// if we allow Array specifically, then an empty array is how we
|
|
117
133
|
// express 'no value here', not null. Allow it.
|
|
118
134
|
if (!val.length && type.indexOf(Array) === -1) {
|
|
119
135
|
debug('VAL HAS NO LENGTH, DELETE IT', val, k, type.indexOf(Array))
|
|
120
136
|
delete data[k]
|
|
121
|
-
}
|
|
122
|
-
else if (isArray) {
|
|
137
|
+
} else if (isArray) {
|
|
123
138
|
debug(isArray, data[k], val)
|
|
124
139
|
data[k] = val
|
|
125
|
-
} else
|
|
140
|
+
} else {
|
|
141
|
+
data[k] = val[0]
|
|
142
|
+
}
|
|
126
143
|
|
|
127
|
-
debug(
|
|
144
|
+
debug('k=%s val=%j', k, val, data[k])
|
|
128
145
|
})
|
|
129
146
|
}
|
|
130
147
|
|
|
@@ -133,17 +150,21 @@ function validateString (data, k, val) {
|
|
|
133
150
|
}
|
|
134
151
|
|
|
135
152
|
function validatePath (data, k, val) {
|
|
136
|
-
if (val === true)
|
|
137
|
-
|
|
153
|
+
if (val === true) {
|
|
154
|
+
return false
|
|
155
|
+
}
|
|
156
|
+
if (val === null) {
|
|
157
|
+
return true
|
|
158
|
+
}
|
|
138
159
|
|
|
139
160
|
val = String(val)
|
|
140
161
|
|
|
141
|
-
var isWin
|
|
142
|
-
|
|
143
|
-
|
|
162
|
+
var isWin = process.platform === 'win32'
|
|
163
|
+
var homePattern = isWin ? /^~(\/|\\)/ : /^~\//
|
|
164
|
+
var home = os.homedir()
|
|
144
165
|
|
|
145
166
|
if (home && val.match(homePattern)) {
|
|
146
|
-
data[k] = path.resolve(home, val.
|
|
167
|
+
data[k] = path.resolve(home, val.slice(2))
|
|
147
168
|
} else {
|
|
148
169
|
data[k] = path.resolve(val)
|
|
149
170
|
}
|
|
@@ -151,63 +172,92 @@ function validatePath (data, k, val) {
|
|
|
151
172
|
}
|
|
152
173
|
|
|
153
174
|
function validateNumber (data, k, val) {
|
|
154
|
-
debug(
|
|
155
|
-
if (isNaN(val))
|
|
175
|
+
debug('validate Number %j %j %j', k, val, isNaN(val))
|
|
176
|
+
if (isNaN(val)) {
|
|
177
|
+
return false
|
|
178
|
+
}
|
|
156
179
|
data[k] = +val
|
|
157
180
|
}
|
|
158
181
|
|
|
159
182
|
function validateDate (data, k, val) {
|
|
160
183
|
var s = Date.parse(val)
|
|
161
|
-
debug(
|
|
162
|
-
if (isNaN(s))
|
|
184
|
+
debug('validate Date %j %j %j', k, val, s)
|
|
185
|
+
if (isNaN(s)) {
|
|
186
|
+
return false
|
|
187
|
+
}
|
|
163
188
|
data[k] = new Date(val)
|
|
164
189
|
}
|
|
165
190
|
|
|
166
191
|
function validateBoolean (data, k, val) {
|
|
167
|
-
if (val instanceof Boolean)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
192
|
+
if (val instanceof Boolean) {
|
|
193
|
+
val = val.valueOf()
|
|
194
|
+
} else if (typeof val === 'string') {
|
|
195
|
+
if (!isNaN(val)) {
|
|
196
|
+
val = !!(+val)
|
|
197
|
+
} else if (val === 'null' || val === 'false') {
|
|
198
|
+
val = false
|
|
199
|
+
} else {
|
|
200
|
+
val = true
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
val = !!val
|
|
204
|
+
}
|
|
173
205
|
data[k] = val
|
|
174
206
|
}
|
|
175
207
|
|
|
176
208
|
function validateUrl (data, k, val) {
|
|
209
|
+
// Changing this would be a breaking change in the npm cli
|
|
210
|
+
/* eslint-disable-next-line node/no-deprecated-api */
|
|
177
211
|
val = url.parse(String(val))
|
|
178
|
-
if (!val.host)
|
|
212
|
+
if (!val.host) {
|
|
213
|
+
return false
|
|
214
|
+
}
|
|
179
215
|
data[k] = val.href
|
|
180
216
|
}
|
|
181
217
|
|
|
182
218
|
function validateStream (data, k, val) {
|
|
183
|
-
if (!(val instanceof Stream))
|
|
219
|
+
if (!(val instanceof Stream)) {
|
|
220
|
+
return false
|
|
221
|
+
}
|
|
184
222
|
data[k] = val
|
|
185
223
|
}
|
|
186
224
|
|
|
187
225
|
function validate (data, k, val, type, typeDefs) {
|
|
188
226
|
// arrays are lists of types.
|
|
189
227
|
if (Array.isArray(type)) {
|
|
190
|
-
for (
|
|
191
|
-
if (type[i] === Array)
|
|
192
|
-
|
|
228
|
+
for (let i = 0, l = type.length; i < l; i++) {
|
|
229
|
+
if (type[i] === Array) {
|
|
230
|
+
continue
|
|
231
|
+
}
|
|
232
|
+
if (validate(data, k, val, type[i], typeDefs)) {
|
|
233
|
+
return true
|
|
234
|
+
}
|
|
193
235
|
}
|
|
194
236
|
delete data[k]
|
|
195
237
|
return false
|
|
196
238
|
}
|
|
197
239
|
|
|
198
240
|
// an array of anything?
|
|
199
|
-
if (type === Array)
|
|
241
|
+
if (type === Array) {
|
|
242
|
+
return true
|
|
243
|
+
}
|
|
200
244
|
|
|
245
|
+
// Original comment:
|
|
201
246
|
// NaN is poisonous. Means that something is not allowed.
|
|
247
|
+
// New comment: Changing this to an isNaN check breaks a lot of tests.
|
|
248
|
+
// Something is being assumed here that is not actually what happens in
|
|
249
|
+
// practice. Fixing it is outside the scope of getting linting to pass in
|
|
250
|
+
// this repo. Leaving as-is for now.
|
|
251
|
+
/* eslint-disable-next-line no-self-compare */
|
|
202
252
|
if (type !== type) {
|
|
203
|
-
debug(
|
|
253
|
+
debug('Poison NaN', k, val, type)
|
|
204
254
|
delete data[k]
|
|
205
255
|
return false
|
|
206
256
|
}
|
|
207
257
|
|
|
208
258
|
// explicit list of values
|
|
209
259
|
if (val === type) {
|
|
210
|
-
debug(
|
|
260
|
+
debug('Explicitly allowed %j', val)
|
|
211
261
|
// if (isArray) (data[k] = data[k] || []).push(val)
|
|
212
262
|
// else data[k] = val
|
|
213
263
|
data[k] = val
|
|
@@ -216,14 +266,17 @@ function validate (data, k, val, type, typeDefs) {
|
|
|
216
266
|
|
|
217
267
|
// now go through the list of typeDefs, validate against each one.
|
|
218
268
|
var ok = false
|
|
219
|
-
|
|
220
|
-
for (
|
|
221
|
-
debug(
|
|
269
|
+
var types = Object.keys(typeDefs)
|
|
270
|
+
for (let i = 0, l = types.length; i < l; i++) {
|
|
271
|
+
debug('test type %j %j %j', k, val, types[i])
|
|
222
272
|
var t = typeDefs[types[i]]
|
|
223
|
-
if (t &&
|
|
224
|
-
(
|
|
273
|
+
if (t && (
|
|
274
|
+
(type && type.name && t.type && t.type.name) ?
|
|
275
|
+
(type.name === t.type.name) :
|
|
276
|
+
(type === t.type)
|
|
277
|
+
)) {
|
|
225
278
|
var d = {}
|
|
226
|
-
ok =
|
|
279
|
+
ok = t.validate(d, k, val) !== false
|
|
227
280
|
val = d[k]
|
|
228
281
|
if (ok) {
|
|
229
282
|
// if (isArray) (data[k] = data[k] || []).push(val)
|
|
@@ -233,60 +286,63 @@ function validate (data, k, val, type, typeDefs) {
|
|
|
233
286
|
}
|
|
234
287
|
}
|
|
235
288
|
}
|
|
236
|
-
debug(
|
|
289
|
+
debug('OK? %j (%j %j %j)', ok, k, val, types[types.length - 1])
|
|
237
290
|
|
|
238
|
-
if (!ok)
|
|
291
|
+
if (!ok) {
|
|
292
|
+
delete data[k]
|
|
293
|
+
}
|
|
239
294
|
return ok
|
|
240
295
|
}
|
|
241
296
|
|
|
242
297
|
function parse (args, data, remain, types, shorthands) {
|
|
243
|
-
debug(
|
|
298
|
+
debug('parse', args, data, remain)
|
|
244
299
|
|
|
245
|
-
var
|
|
246
|
-
|
|
247
|
-
, shortAbbr = abbrev(Object.keys(shorthands))
|
|
300
|
+
var abbrevs = abbrev(Object.keys(types))
|
|
301
|
+
var shortAbbr = abbrev(Object.keys(shorthands))
|
|
248
302
|
|
|
249
|
-
for (var i = 0; i < args.length; i
|
|
303
|
+
for (var i = 0; i < args.length; i++) {
|
|
250
304
|
var arg = args[i]
|
|
251
|
-
debug(
|
|
305
|
+
debug('arg', arg)
|
|
252
306
|
|
|
253
307
|
if (arg.match(/^-{2,}$/)) {
|
|
254
308
|
// done with keys.
|
|
255
309
|
// the rest are args.
|
|
256
310
|
remain.push.apply(remain, args.slice(i + 1))
|
|
257
|
-
args[i] =
|
|
311
|
+
args[i] = '--'
|
|
258
312
|
break
|
|
259
313
|
}
|
|
260
314
|
var hadEq = false
|
|
261
|
-
if (arg.charAt(0) ===
|
|
315
|
+
if (arg.charAt(0) === '-' && arg.length > 1) {
|
|
262
316
|
var at = arg.indexOf('=')
|
|
263
317
|
if (at > -1) {
|
|
264
318
|
hadEq = true
|
|
265
|
-
var v = arg.
|
|
266
|
-
arg = arg.
|
|
319
|
+
var v = arg.slice(at + 1)
|
|
320
|
+
arg = arg.slice(0, at)
|
|
267
321
|
args.splice(i, 1, arg, v)
|
|
268
322
|
}
|
|
269
323
|
|
|
270
324
|
// see if it's a shorthand
|
|
271
325
|
// if so, splice and back up to re-parse it.
|
|
272
326
|
var shRes = resolveShort(arg, shorthands, shortAbbr, abbrevs)
|
|
273
|
-
debug(
|
|
327
|
+
debug('arg=%j shRes=%j', arg, shRes)
|
|
274
328
|
if (shRes) {
|
|
275
329
|
debug(arg, shRes)
|
|
276
330
|
args.splice.apply(args, [i, 1].concat(shRes))
|
|
277
331
|
if (arg !== shRes[0]) {
|
|
278
|
-
i
|
|
332
|
+
i--
|
|
279
333
|
continue
|
|
280
334
|
}
|
|
281
335
|
}
|
|
282
|
-
arg = arg.replace(/^-+/,
|
|
336
|
+
arg = arg.replace(/^-+/, '')
|
|
283
337
|
var no = null
|
|
284
|
-
while (arg.toLowerCase().indexOf(
|
|
338
|
+
while (arg.toLowerCase().indexOf('no-') === 0) {
|
|
285
339
|
no = !no
|
|
286
|
-
arg = arg.
|
|
340
|
+
arg = arg.slice(3)
|
|
287
341
|
}
|
|
288
342
|
|
|
289
|
-
if (abbrevs[arg])
|
|
343
|
+
if (abbrevs[arg]) {
|
|
344
|
+
arg = abbrevs[arg]
|
|
345
|
+
}
|
|
290
346
|
|
|
291
347
|
var argType = types[arg]
|
|
292
348
|
var isTypeArray = Array.isArray(argType)
|
|
@@ -299,20 +355,24 @@ function parse (args, data, remain, types, shorthands) {
|
|
|
299
355
|
isTypeArray && argType.indexOf(Array) !== -1
|
|
300
356
|
|
|
301
357
|
// allow unknown things to be arrays if specified multiple times.
|
|
302
|
-
if (
|
|
303
|
-
|
|
358
|
+
if (
|
|
359
|
+
!Object.prototype.hasOwnProperty.call(types, arg) &&
|
|
360
|
+
Object.prototype.hasOwnProperty.call(data, arg)
|
|
361
|
+
) {
|
|
362
|
+
if (!Array.isArray(data[arg])) {
|
|
304
363
|
data[arg] = [data[arg]]
|
|
364
|
+
}
|
|
305
365
|
isArray = true
|
|
306
366
|
}
|
|
307
367
|
|
|
308
368
|
var val
|
|
309
|
-
|
|
369
|
+
var la = args[i + 1]
|
|
310
370
|
|
|
311
371
|
var isBool = typeof no === 'boolean' ||
|
|
312
372
|
argType === Boolean ||
|
|
313
373
|
isTypeArray && argType.indexOf(Boolean) !== -1 ||
|
|
314
374
|
(typeof argType === 'undefined' && !hadEq) ||
|
|
315
|
-
(la ===
|
|
375
|
+
(la === 'false' &&
|
|
316
376
|
(argType === null ||
|
|
317
377
|
isTypeArray && ~argType.indexOf(null)))
|
|
318
378
|
|
|
@@ -320,11 +380,13 @@ function parse (args, data, remain, types, shorthands) {
|
|
|
320
380
|
// just set and move along
|
|
321
381
|
val = !no
|
|
322
382
|
// however, also support --bool true or --bool false
|
|
323
|
-
if (la ===
|
|
383
|
+
if (la === 'true' || la === 'false') {
|
|
324
384
|
val = JSON.parse(la)
|
|
325
385
|
la = null
|
|
326
|
-
if (no)
|
|
327
|
-
|
|
386
|
+
if (no) {
|
|
387
|
+
val = !val
|
|
388
|
+
}
|
|
389
|
+
i++
|
|
328
390
|
}
|
|
329
391
|
|
|
330
392
|
// also support "foo":[Boolean, "bar"] and "--foo bar"
|
|
@@ -332,49 +394,55 @@ function parse (args, data, remain, types, shorthands) {
|
|
|
332
394
|
if (~argType.indexOf(la)) {
|
|
333
395
|
// an explicit type
|
|
334
396
|
val = la
|
|
335
|
-
i
|
|
336
|
-
} else if (
|
|
397
|
+
i++
|
|
398
|
+
} else if (la === 'null' && ~argType.indexOf(null)) {
|
|
337
399
|
// null allowed
|
|
338
400
|
val = null
|
|
339
|
-
i
|
|
340
|
-
} else if (
|
|
401
|
+
i++
|
|
402
|
+
} else if (!la.match(/^-{2,}[^-]/) &&
|
|
341
403
|
!isNaN(la) &&
|
|
342
|
-
~argType.indexOf(Number)
|
|
404
|
+
~argType.indexOf(Number)) {
|
|
343
405
|
// number
|
|
344
406
|
val = +la
|
|
345
|
-
i
|
|
346
|
-
} else if (
|
|
407
|
+
i++
|
|
408
|
+
} else if (!la.match(/^-[^-]/) && ~argType.indexOf(String)) {
|
|
347
409
|
// string
|
|
348
410
|
val = la
|
|
349
|
-
i
|
|
411
|
+
i++
|
|
350
412
|
}
|
|
351
413
|
}
|
|
352
414
|
|
|
353
|
-
if (isArray)
|
|
354
|
-
|
|
415
|
+
if (isArray) {
|
|
416
|
+
(data[arg] = data[arg] || []).push(val)
|
|
417
|
+
} else {
|
|
418
|
+
data[arg] = val
|
|
419
|
+
}
|
|
355
420
|
|
|
356
421
|
continue
|
|
357
422
|
}
|
|
358
423
|
|
|
359
424
|
if (argType === String) {
|
|
360
425
|
if (la === undefined) {
|
|
361
|
-
la =
|
|
426
|
+
la = ''
|
|
362
427
|
} else if (la.match(/^-{1,2}[^-]+/)) {
|
|
363
|
-
la =
|
|
364
|
-
i
|
|
428
|
+
la = ''
|
|
429
|
+
i--
|
|
365
430
|
}
|
|
366
431
|
}
|
|
367
432
|
|
|
368
433
|
if (la && la.match(/^-{2,}$/)) {
|
|
369
434
|
la = undefined
|
|
370
|
-
i
|
|
435
|
+
i--
|
|
371
436
|
}
|
|
372
437
|
|
|
373
438
|
val = la === undefined ? true : la
|
|
374
|
-
if (isArray)
|
|
375
|
-
|
|
439
|
+
if (isArray) {
|
|
440
|
+
(data[arg] = data[arg] || []).push(val)
|
|
441
|
+
} else {
|
|
442
|
+
data[arg] = val
|
|
443
|
+
}
|
|
376
444
|
|
|
377
|
-
i
|
|
445
|
+
i++
|
|
378
446
|
continue
|
|
379
447
|
}
|
|
380
448
|
remain.push(arg)
|
|
@@ -389,14 +457,16 @@ function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
|
|
|
389
457
|
arg = arg.replace(/^-+/, '')
|
|
390
458
|
|
|
391
459
|
// if it's an exact known option, then don't go any further
|
|
392
|
-
if (abbrevs[arg] === arg)
|
|
460
|
+
if (abbrevs[arg] === arg) {
|
|
393
461
|
return null
|
|
462
|
+
}
|
|
394
463
|
|
|
395
464
|
// if it's an exact known shortopt, same deal
|
|
396
465
|
if (shorthands[arg]) {
|
|
397
466
|
// make it an array, if it's a list of words
|
|
398
|
-
if (shorthands[arg] && !Array.isArray(shorthands[arg]))
|
|
467
|
+
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
|
|
399
468
|
shorthands[arg] = shorthands[arg].split(/\s+/)
|
|
469
|
+
}
|
|
400
470
|
|
|
401
471
|
return shorthands[arg]
|
|
402
472
|
}
|
|
@@ -406,7 +476,7 @@ function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
|
|
|
406
476
|
if (!singles) {
|
|
407
477
|
singles = Object.keys(shorthands).filter(function (s) {
|
|
408
478
|
return s.length === 1
|
|
409
|
-
}).reduce(function (l,r) {
|
|
479
|
+
}).reduce(function (l, r) {
|
|
410
480
|
l[r] = true
|
|
411
481
|
return l
|
|
412
482
|
}, {})
|
|
@@ -414,28 +484,32 @@ function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
|
|
|
414
484
|
debug('shorthand singles', singles)
|
|
415
485
|
}
|
|
416
486
|
|
|
417
|
-
var chrs = arg.split(
|
|
487
|
+
var chrs = arg.split('').filter(function (c) {
|
|
418
488
|
return singles[c]
|
|
419
489
|
})
|
|
420
490
|
|
|
421
|
-
if (chrs.join(
|
|
422
|
-
return
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
491
|
+
if (chrs.join('') === arg) {
|
|
492
|
+
return chrs.map(function (c) {
|
|
493
|
+
return shorthands[c]
|
|
494
|
+
}).reduce(function (l, r) {
|
|
495
|
+
return l.concat(r)
|
|
496
|
+
}, [])
|
|
497
|
+
}
|
|
427
498
|
|
|
428
499
|
// if it's an arg abbrev, and not a literal shorthand, then prefer the arg
|
|
429
|
-
if (abbrevs[arg] && !shorthands[arg])
|
|
500
|
+
if (abbrevs[arg] && !shorthands[arg]) {
|
|
430
501
|
return null
|
|
502
|
+
}
|
|
431
503
|
|
|
432
504
|
// if it's an abbr for a shorthand, then use that
|
|
433
|
-
if (shortAbbr[arg])
|
|
505
|
+
if (shortAbbr[arg]) {
|
|
434
506
|
arg = shortAbbr[arg]
|
|
507
|
+
}
|
|
435
508
|
|
|
436
509
|
// make it an array, if it's a list of words
|
|
437
|
-
if (shorthands[arg] && !Array.isArray(shorthands[arg]))
|
|
510
|
+
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
|
|
438
511
|
shorthands[arg] = shorthands[arg].split(/\s+/)
|
|
512
|
+
}
|
|
439
513
|
|
|
440
514
|
return shorthands[arg]
|
|
441
515
|
}
|