gomtm 0.0.499 → 0.0.533
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/main.js +3522 -0
- package/package.json +20 -8
package/dist/main.js
ADDED
|
@@ -0,0 +1,3522 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {createRequire} from "node:module";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
20
|
+
var __require = createRequire(import.meta.url);
|
|
21
|
+
|
|
22
|
+
// ../../node_modules/commander/lib/error.js
|
|
23
|
+
var require_error = __commonJS((exports) => {
|
|
24
|
+
class CommanderError extends Error {
|
|
25
|
+
constructor(exitCode, code, message) {
|
|
26
|
+
super(message);
|
|
27
|
+
Error.captureStackTrace(this, this.constructor);
|
|
28
|
+
this.name = this.constructor.name;
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.exitCode = exitCode;
|
|
31
|
+
this.nestedError = undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class InvalidArgumentError extends CommanderError {
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super(1, "commander.invalidArgument", message);
|
|
38
|
+
Error.captureStackTrace(this, this.constructor);
|
|
39
|
+
this.name = this.constructor.name;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.CommanderError = CommanderError;
|
|
43
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// ../../node_modules/commander/lib/argument.js
|
|
47
|
+
var require_argument = __commonJS((exports) => {
|
|
48
|
+
var humanReadableArgName = function(arg) {
|
|
49
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
50
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
51
|
+
};
|
|
52
|
+
var { InvalidArgumentError } = require_error();
|
|
53
|
+
|
|
54
|
+
class Argument {
|
|
55
|
+
constructor(name, description) {
|
|
56
|
+
this.description = description || "";
|
|
57
|
+
this.variadic = false;
|
|
58
|
+
this.parseArg = undefined;
|
|
59
|
+
this.defaultValue = undefined;
|
|
60
|
+
this.defaultValueDescription = undefined;
|
|
61
|
+
this.argChoices = undefined;
|
|
62
|
+
switch (name[0]) {
|
|
63
|
+
case "<":
|
|
64
|
+
this.required = true;
|
|
65
|
+
this._name = name.slice(1, -1);
|
|
66
|
+
break;
|
|
67
|
+
case "[":
|
|
68
|
+
this.required = false;
|
|
69
|
+
this._name = name.slice(1, -1);
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
this.required = true;
|
|
73
|
+
this._name = name;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
77
|
+
this.variadic = true;
|
|
78
|
+
this._name = this._name.slice(0, -3);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
name() {
|
|
82
|
+
return this._name;
|
|
83
|
+
}
|
|
84
|
+
_concatValue(value, previous) {
|
|
85
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
86
|
+
return [value];
|
|
87
|
+
}
|
|
88
|
+
return previous.concat(value);
|
|
89
|
+
}
|
|
90
|
+
default(value, description) {
|
|
91
|
+
this.defaultValue = value;
|
|
92
|
+
this.defaultValueDescription = description;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
argParser(fn) {
|
|
96
|
+
this.parseArg = fn;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
choices(values) {
|
|
100
|
+
this.argChoices = values.slice();
|
|
101
|
+
this.parseArg = (arg, previous) => {
|
|
102
|
+
if (!this.argChoices.includes(arg)) {
|
|
103
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
104
|
+
}
|
|
105
|
+
if (this.variadic) {
|
|
106
|
+
return this._concatValue(arg, previous);
|
|
107
|
+
}
|
|
108
|
+
return arg;
|
|
109
|
+
};
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
argRequired() {
|
|
113
|
+
this.required = true;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
argOptional() {
|
|
117
|
+
this.required = false;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.Argument = Argument;
|
|
122
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// ../../node_modules/commander/lib/help.js
|
|
126
|
+
var require_help = __commonJS((exports) => {
|
|
127
|
+
var { humanReadableArgName } = require_argument();
|
|
128
|
+
|
|
129
|
+
class Help {
|
|
130
|
+
constructor() {
|
|
131
|
+
this.helpWidth = undefined;
|
|
132
|
+
this.sortSubcommands = false;
|
|
133
|
+
this.sortOptions = false;
|
|
134
|
+
this.showGlobalOptions = false;
|
|
135
|
+
}
|
|
136
|
+
visibleCommands(cmd) {
|
|
137
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
138
|
+
const helpCommand = cmd._getHelpCommand();
|
|
139
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
140
|
+
visibleCommands.push(helpCommand);
|
|
141
|
+
}
|
|
142
|
+
if (this.sortSubcommands) {
|
|
143
|
+
visibleCommands.sort((a, b) => {
|
|
144
|
+
return a.name().localeCompare(b.name());
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return visibleCommands;
|
|
148
|
+
}
|
|
149
|
+
compareOptions(a, b) {
|
|
150
|
+
const getSortKey = (option) => {
|
|
151
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
152
|
+
};
|
|
153
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
154
|
+
}
|
|
155
|
+
visibleOptions(cmd) {
|
|
156
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
157
|
+
const helpOption = cmd._getHelpOption();
|
|
158
|
+
if (helpOption && !helpOption.hidden) {
|
|
159
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
160
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
161
|
+
if (!removeShort && !removeLong) {
|
|
162
|
+
visibleOptions.push(helpOption);
|
|
163
|
+
} else if (helpOption.long && !removeLong) {
|
|
164
|
+
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
165
|
+
} else if (helpOption.short && !removeShort) {
|
|
166
|
+
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (this.sortOptions) {
|
|
170
|
+
visibleOptions.sort(this.compareOptions);
|
|
171
|
+
}
|
|
172
|
+
return visibleOptions;
|
|
173
|
+
}
|
|
174
|
+
visibleGlobalOptions(cmd) {
|
|
175
|
+
if (!this.showGlobalOptions)
|
|
176
|
+
return [];
|
|
177
|
+
const globalOptions = [];
|
|
178
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
179
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
180
|
+
globalOptions.push(...visibleOptions);
|
|
181
|
+
}
|
|
182
|
+
if (this.sortOptions) {
|
|
183
|
+
globalOptions.sort(this.compareOptions);
|
|
184
|
+
}
|
|
185
|
+
return globalOptions;
|
|
186
|
+
}
|
|
187
|
+
visibleArguments(cmd) {
|
|
188
|
+
if (cmd._argsDescription) {
|
|
189
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
190
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
194
|
+
return cmd.registeredArguments;
|
|
195
|
+
}
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
subcommandTerm(cmd) {
|
|
199
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
200
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
201
|
+
}
|
|
202
|
+
optionTerm(option) {
|
|
203
|
+
return option.flags;
|
|
204
|
+
}
|
|
205
|
+
argumentTerm(argument) {
|
|
206
|
+
return argument.name();
|
|
207
|
+
}
|
|
208
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
209
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
210
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
211
|
+
}, 0);
|
|
212
|
+
}
|
|
213
|
+
longestOptionTermLength(cmd, helper) {
|
|
214
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
215
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
216
|
+
}, 0);
|
|
217
|
+
}
|
|
218
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
219
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
220
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
221
|
+
}, 0);
|
|
222
|
+
}
|
|
223
|
+
longestArgumentTermLength(cmd, helper) {
|
|
224
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
225
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
226
|
+
}, 0);
|
|
227
|
+
}
|
|
228
|
+
commandUsage(cmd) {
|
|
229
|
+
let cmdName = cmd._name;
|
|
230
|
+
if (cmd._aliases[0]) {
|
|
231
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
232
|
+
}
|
|
233
|
+
let ancestorCmdNames = "";
|
|
234
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
235
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
236
|
+
}
|
|
237
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
238
|
+
}
|
|
239
|
+
commandDescription(cmd) {
|
|
240
|
+
return cmd.description();
|
|
241
|
+
}
|
|
242
|
+
subcommandDescription(cmd) {
|
|
243
|
+
return cmd.summary() || cmd.description();
|
|
244
|
+
}
|
|
245
|
+
optionDescription(option) {
|
|
246
|
+
const extraInfo = [];
|
|
247
|
+
if (option.argChoices) {
|
|
248
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
249
|
+
}
|
|
250
|
+
if (option.defaultValue !== undefined) {
|
|
251
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
252
|
+
if (showDefault) {
|
|
253
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
257
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
258
|
+
}
|
|
259
|
+
if (option.envVar !== undefined) {
|
|
260
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
261
|
+
}
|
|
262
|
+
if (extraInfo.length > 0) {
|
|
263
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
264
|
+
}
|
|
265
|
+
return option.description;
|
|
266
|
+
}
|
|
267
|
+
argumentDescription(argument) {
|
|
268
|
+
const extraInfo = [];
|
|
269
|
+
if (argument.argChoices) {
|
|
270
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
271
|
+
}
|
|
272
|
+
if (argument.defaultValue !== undefined) {
|
|
273
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
274
|
+
}
|
|
275
|
+
if (extraInfo.length > 0) {
|
|
276
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
277
|
+
if (argument.description) {
|
|
278
|
+
return `${argument.description} ${extraDescripton}`;
|
|
279
|
+
}
|
|
280
|
+
return extraDescripton;
|
|
281
|
+
}
|
|
282
|
+
return argument.description;
|
|
283
|
+
}
|
|
284
|
+
formatHelp(cmd, helper) {
|
|
285
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
286
|
+
const helpWidth = helper.helpWidth || 80;
|
|
287
|
+
const itemIndentWidth = 2;
|
|
288
|
+
const itemSeparatorWidth = 2;
|
|
289
|
+
function formatItem(term, description) {
|
|
290
|
+
if (description) {
|
|
291
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
292
|
+
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
293
|
+
}
|
|
294
|
+
return term;
|
|
295
|
+
}
|
|
296
|
+
function formatList(textArray) {
|
|
297
|
+
return textArray.join("\n").replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
298
|
+
}
|
|
299
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
300
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
301
|
+
if (commandDescription.length > 0) {
|
|
302
|
+
output = output.concat([
|
|
303
|
+
helper.wrap(commandDescription, helpWidth, 0),
|
|
304
|
+
""
|
|
305
|
+
]);
|
|
306
|
+
}
|
|
307
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
308
|
+
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
309
|
+
});
|
|
310
|
+
if (argumentList.length > 0) {
|
|
311
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
312
|
+
}
|
|
313
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
314
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
315
|
+
});
|
|
316
|
+
if (optionList.length > 0) {
|
|
317
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
318
|
+
}
|
|
319
|
+
if (this.showGlobalOptions) {
|
|
320
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
321
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
322
|
+
});
|
|
323
|
+
if (globalOptionList.length > 0) {
|
|
324
|
+
output = output.concat([
|
|
325
|
+
"Global Options:",
|
|
326
|
+
formatList(globalOptionList),
|
|
327
|
+
""
|
|
328
|
+
]);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
332
|
+
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
333
|
+
});
|
|
334
|
+
if (commandList.length > 0) {
|
|
335
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
336
|
+
}
|
|
337
|
+
return output.join("\n");
|
|
338
|
+
}
|
|
339
|
+
padWidth(cmd, helper) {
|
|
340
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
341
|
+
}
|
|
342
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
343
|
+
const indents = " \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF";
|
|
344
|
+
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
345
|
+
if (str.match(manualIndent))
|
|
346
|
+
return str;
|
|
347
|
+
const columnWidth = width - indent;
|
|
348
|
+
if (columnWidth < minColumnWidth)
|
|
349
|
+
return str;
|
|
350
|
+
const leadingStr = str.slice(0, indent);
|
|
351
|
+
const columnText = str.slice(indent).replace("\r\n", "\n");
|
|
352
|
+
const indentString = " ".repeat(indent);
|
|
353
|
+
const zeroWidthSpace = "\u200B";
|
|
354
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
355
|
+
const regex = new RegExp(`\n|.{1,${columnWidth - 1}}([${breaks}]|\$)|[^${breaks}]+?([${breaks}]|\$)`, "g");
|
|
356
|
+
const lines = columnText.match(regex) || [];
|
|
357
|
+
return leadingStr + lines.map((line, i) => {
|
|
358
|
+
if (line === "\n")
|
|
359
|
+
return "";
|
|
360
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
361
|
+
}).join("\n");
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
exports.Help = Help;
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// ../../node_modules/commander/lib/option.js
|
|
368
|
+
var require_option = __commonJS((exports) => {
|
|
369
|
+
var camelcase = function(str) {
|
|
370
|
+
return str.split("-").reduce((str2, word) => {
|
|
371
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
var splitOptionFlags = function(flags) {
|
|
375
|
+
let shortFlag;
|
|
376
|
+
let longFlag;
|
|
377
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
378
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
379
|
+
shortFlag = flagParts.shift();
|
|
380
|
+
longFlag = flagParts.shift();
|
|
381
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
382
|
+
shortFlag = longFlag;
|
|
383
|
+
longFlag = undefined;
|
|
384
|
+
}
|
|
385
|
+
return { shortFlag, longFlag };
|
|
386
|
+
};
|
|
387
|
+
var { InvalidArgumentError } = require_error();
|
|
388
|
+
|
|
389
|
+
class Option {
|
|
390
|
+
constructor(flags, description) {
|
|
391
|
+
this.flags = flags;
|
|
392
|
+
this.description = description || "";
|
|
393
|
+
this.required = flags.includes("<");
|
|
394
|
+
this.optional = flags.includes("[");
|
|
395
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
396
|
+
this.mandatory = false;
|
|
397
|
+
const optionFlags = splitOptionFlags(flags);
|
|
398
|
+
this.short = optionFlags.shortFlag;
|
|
399
|
+
this.long = optionFlags.longFlag;
|
|
400
|
+
this.negate = false;
|
|
401
|
+
if (this.long) {
|
|
402
|
+
this.negate = this.long.startsWith("--no-");
|
|
403
|
+
}
|
|
404
|
+
this.defaultValue = undefined;
|
|
405
|
+
this.defaultValueDescription = undefined;
|
|
406
|
+
this.presetArg = undefined;
|
|
407
|
+
this.envVar = undefined;
|
|
408
|
+
this.parseArg = undefined;
|
|
409
|
+
this.hidden = false;
|
|
410
|
+
this.argChoices = undefined;
|
|
411
|
+
this.conflictsWith = [];
|
|
412
|
+
this.implied = undefined;
|
|
413
|
+
}
|
|
414
|
+
default(value, description) {
|
|
415
|
+
this.defaultValue = value;
|
|
416
|
+
this.defaultValueDescription = description;
|
|
417
|
+
return this;
|
|
418
|
+
}
|
|
419
|
+
preset(arg) {
|
|
420
|
+
this.presetArg = arg;
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
conflicts(names) {
|
|
424
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
implies(impliedOptionValues) {
|
|
428
|
+
let newImplied = impliedOptionValues;
|
|
429
|
+
if (typeof impliedOptionValues === "string") {
|
|
430
|
+
newImplied = { [impliedOptionValues]: true };
|
|
431
|
+
}
|
|
432
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
435
|
+
env(name) {
|
|
436
|
+
this.envVar = name;
|
|
437
|
+
return this;
|
|
438
|
+
}
|
|
439
|
+
argParser(fn) {
|
|
440
|
+
this.parseArg = fn;
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
makeOptionMandatory(mandatory = true) {
|
|
444
|
+
this.mandatory = !!mandatory;
|
|
445
|
+
return this;
|
|
446
|
+
}
|
|
447
|
+
hideHelp(hide = true) {
|
|
448
|
+
this.hidden = !!hide;
|
|
449
|
+
return this;
|
|
450
|
+
}
|
|
451
|
+
_concatValue(value, previous) {
|
|
452
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
453
|
+
return [value];
|
|
454
|
+
}
|
|
455
|
+
return previous.concat(value);
|
|
456
|
+
}
|
|
457
|
+
choices(values) {
|
|
458
|
+
this.argChoices = values.slice();
|
|
459
|
+
this.parseArg = (arg, previous) => {
|
|
460
|
+
if (!this.argChoices.includes(arg)) {
|
|
461
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
462
|
+
}
|
|
463
|
+
if (this.variadic) {
|
|
464
|
+
return this._concatValue(arg, previous);
|
|
465
|
+
}
|
|
466
|
+
return arg;
|
|
467
|
+
};
|
|
468
|
+
return this;
|
|
469
|
+
}
|
|
470
|
+
name() {
|
|
471
|
+
if (this.long) {
|
|
472
|
+
return this.long.replace(/^--/, "");
|
|
473
|
+
}
|
|
474
|
+
return this.short.replace(/^-/, "");
|
|
475
|
+
}
|
|
476
|
+
attributeName() {
|
|
477
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
478
|
+
}
|
|
479
|
+
is(arg) {
|
|
480
|
+
return this.short === arg || this.long === arg;
|
|
481
|
+
}
|
|
482
|
+
isBoolean() {
|
|
483
|
+
return !this.required && !this.optional && !this.negate;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
class DualOptions {
|
|
488
|
+
constructor(options) {
|
|
489
|
+
this.positiveOptions = new Map;
|
|
490
|
+
this.negativeOptions = new Map;
|
|
491
|
+
this.dualOptions = new Set;
|
|
492
|
+
options.forEach((option) => {
|
|
493
|
+
if (option.negate) {
|
|
494
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
495
|
+
} else {
|
|
496
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
this.negativeOptions.forEach((value, key) => {
|
|
500
|
+
if (this.positiveOptions.has(key)) {
|
|
501
|
+
this.dualOptions.add(key);
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
valueFromOption(value, option) {
|
|
506
|
+
const optionKey = option.attributeName();
|
|
507
|
+
if (!this.dualOptions.has(optionKey))
|
|
508
|
+
return true;
|
|
509
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
510
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
511
|
+
return option.negate === (negativeValue === value);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
exports.Option = Option;
|
|
515
|
+
exports.DualOptions = DualOptions;
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
// ../../node_modules/commander/lib/suggestSimilar.js
|
|
519
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
520
|
+
var editDistance = function(a, b) {
|
|
521
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
522
|
+
return Math.max(a.length, b.length);
|
|
523
|
+
const d = [];
|
|
524
|
+
for (let i = 0;i <= a.length; i++) {
|
|
525
|
+
d[i] = [i];
|
|
526
|
+
}
|
|
527
|
+
for (let j = 0;j <= b.length; j++) {
|
|
528
|
+
d[0][j] = j;
|
|
529
|
+
}
|
|
530
|
+
for (let j = 1;j <= b.length; j++) {
|
|
531
|
+
for (let i = 1;i <= a.length; i++) {
|
|
532
|
+
let cost = 1;
|
|
533
|
+
if (a[i - 1] === b[j - 1]) {
|
|
534
|
+
cost = 0;
|
|
535
|
+
} else {
|
|
536
|
+
cost = 1;
|
|
537
|
+
}
|
|
538
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
539
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
540
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return d[a.length][b.length];
|
|
545
|
+
};
|
|
546
|
+
var suggestSimilar = function(word, candidates) {
|
|
547
|
+
if (!candidates || candidates.length === 0)
|
|
548
|
+
return "";
|
|
549
|
+
candidates = Array.from(new Set(candidates));
|
|
550
|
+
const searchingOptions = word.startsWith("--");
|
|
551
|
+
if (searchingOptions) {
|
|
552
|
+
word = word.slice(2);
|
|
553
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
554
|
+
}
|
|
555
|
+
let similar = [];
|
|
556
|
+
let bestDistance = maxDistance;
|
|
557
|
+
const minSimilarity = 0.4;
|
|
558
|
+
candidates.forEach((candidate) => {
|
|
559
|
+
if (candidate.length <= 1)
|
|
560
|
+
return;
|
|
561
|
+
const distance = editDistance(word, candidate);
|
|
562
|
+
const length = Math.max(word.length, candidate.length);
|
|
563
|
+
const similarity = (length - distance) / length;
|
|
564
|
+
if (similarity > minSimilarity) {
|
|
565
|
+
if (distance < bestDistance) {
|
|
566
|
+
bestDistance = distance;
|
|
567
|
+
similar = [candidate];
|
|
568
|
+
} else if (distance === bestDistance) {
|
|
569
|
+
similar.push(candidate);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
574
|
+
if (searchingOptions) {
|
|
575
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
576
|
+
}
|
|
577
|
+
if (similar.length > 1) {
|
|
578
|
+
return `\n(Did you mean one of ${similar.join(", ")}?)`;
|
|
579
|
+
}
|
|
580
|
+
if (similar.length === 1) {
|
|
581
|
+
return `\n(Did you mean ${similar[0]}?)`;
|
|
582
|
+
}
|
|
583
|
+
return "";
|
|
584
|
+
};
|
|
585
|
+
var maxDistance = 3;
|
|
586
|
+
exports.suggestSimilar = suggestSimilar;
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
// ../../node_modules/commander/lib/command.js
|
|
590
|
+
var require_command = __commonJS((exports) => {
|
|
591
|
+
var incrementNodeInspectorPort = function(args) {
|
|
592
|
+
return args.map((arg) => {
|
|
593
|
+
if (!arg.startsWith("--inspect")) {
|
|
594
|
+
return arg;
|
|
595
|
+
}
|
|
596
|
+
let debugOption;
|
|
597
|
+
let debugHost = "127.0.0.1";
|
|
598
|
+
let debugPort = "9229";
|
|
599
|
+
let match;
|
|
600
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
601
|
+
debugOption = match[1];
|
|
602
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
603
|
+
debugOption = match[1];
|
|
604
|
+
if (/^\d+$/.test(match[3])) {
|
|
605
|
+
debugPort = match[3];
|
|
606
|
+
} else {
|
|
607
|
+
debugHost = match[3];
|
|
608
|
+
}
|
|
609
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
610
|
+
debugOption = match[1];
|
|
611
|
+
debugHost = match[3];
|
|
612
|
+
debugPort = match[4];
|
|
613
|
+
}
|
|
614
|
+
if (debugOption && debugPort !== "0") {
|
|
615
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
616
|
+
}
|
|
617
|
+
return arg;
|
|
618
|
+
});
|
|
619
|
+
};
|
|
620
|
+
var EventEmitter = __require("node:events").EventEmitter;
|
|
621
|
+
var childProcess = __require("node:child_process");
|
|
622
|
+
var path = __require("node:path");
|
|
623
|
+
var fs = __require("node:fs");
|
|
624
|
+
var process2 = __require("node:process");
|
|
625
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
626
|
+
var { CommanderError } = require_error();
|
|
627
|
+
var { Help } = require_help();
|
|
628
|
+
var { Option, DualOptions } = require_option();
|
|
629
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
630
|
+
|
|
631
|
+
class Command extends EventEmitter {
|
|
632
|
+
constructor(name) {
|
|
633
|
+
super();
|
|
634
|
+
this.commands = [];
|
|
635
|
+
this.options = [];
|
|
636
|
+
this.parent = null;
|
|
637
|
+
this._allowUnknownOption = false;
|
|
638
|
+
this._allowExcessArguments = true;
|
|
639
|
+
this.registeredArguments = [];
|
|
640
|
+
this._args = this.registeredArguments;
|
|
641
|
+
this.args = [];
|
|
642
|
+
this.rawArgs = [];
|
|
643
|
+
this.processedArgs = [];
|
|
644
|
+
this._scriptPath = null;
|
|
645
|
+
this._name = name || "";
|
|
646
|
+
this._optionValues = {};
|
|
647
|
+
this._optionValueSources = {};
|
|
648
|
+
this._storeOptionsAsProperties = false;
|
|
649
|
+
this._actionHandler = null;
|
|
650
|
+
this._executableHandler = false;
|
|
651
|
+
this._executableFile = null;
|
|
652
|
+
this._executableDir = null;
|
|
653
|
+
this._defaultCommandName = null;
|
|
654
|
+
this._exitCallback = null;
|
|
655
|
+
this._aliases = [];
|
|
656
|
+
this._combineFlagAndOptionalValue = true;
|
|
657
|
+
this._description = "";
|
|
658
|
+
this._summary = "";
|
|
659
|
+
this._argsDescription = undefined;
|
|
660
|
+
this._enablePositionalOptions = false;
|
|
661
|
+
this._passThroughOptions = false;
|
|
662
|
+
this._lifeCycleHooks = {};
|
|
663
|
+
this._showHelpAfterError = false;
|
|
664
|
+
this._showSuggestionAfterError = true;
|
|
665
|
+
this._outputConfiguration = {
|
|
666
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
667
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
668
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
669
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
670
|
+
outputError: (str, write) => write(str)
|
|
671
|
+
};
|
|
672
|
+
this._hidden = false;
|
|
673
|
+
this._helpOption = undefined;
|
|
674
|
+
this._addImplicitHelpCommand = undefined;
|
|
675
|
+
this._helpCommand = undefined;
|
|
676
|
+
this._helpConfiguration = {};
|
|
677
|
+
}
|
|
678
|
+
copyInheritedSettings(sourceCommand) {
|
|
679
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
680
|
+
this._helpOption = sourceCommand._helpOption;
|
|
681
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
682
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
683
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
684
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
685
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
686
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
687
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
688
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
689
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
690
|
+
return this;
|
|
691
|
+
}
|
|
692
|
+
_getCommandAndAncestors() {
|
|
693
|
+
const result = [];
|
|
694
|
+
for (let command = this;command; command = command.parent) {
|
|
695
|
+
result.push(command);
|
|
696
|
+
}
|
|
697
|
+
return result;
|
|
698
|
+
}
|
|
699
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
700
|
+
let desc = actionOptsOrExecDesc;
|
|
701
|
+
let opts = execOpts;
|
|
702
|
+
if (typeof desc === "object" && desc !== null) {
|
|
703
|
+
opts = desc;
|
|
704
|
+
desc = null;
|
|
705
|
+
}
|
|
706
|
+
opts = opts || {};
|
|
707
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
708
|
+
const cmd = this.createCommand(name);
|
|
709
|
+
if (desc) {
|
|
710
|
+
cmd.description(desc);
|
|
711
|
+
cmd._executableHandler = true;
|
|
712
|
+
}
|
|
713
|
+
if (opts.isDefault)
|
|
714
|
+
this._defaultCommandName = cmd._name;
|
|
715
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
716
|
+
cmd._executableFile = opts.executableFile || null;
|
|
717
|
+
if (args)
|
|
718
|
+
cmd.arguments(args);
|
|
719
|
+
this._registerCommand(cmd);
|
|
720
|
+
cmd.parent = this;
|
|
721
|
+
cmd.copyInheritedSettings(this);
|
|
722
|
+
if (desc)
|
|
723
|
+
return this;
|
|
724
|
+
return cmd;
|
|
725
|
+
}
|
|
726
|
+
createCommand(name) {
|
|
727
|
+
return new Command(name);
|
|
728
|
+
}
|
|
729
|
+
createHelp() {
|
|
730
|
+
return Object.assign(new Help, this.configureHelp());
|
|
731
|
+
}
|
|
732
|
+
configureHelp(configuration) {
|
|
733
|
+
if (configuration === undefined)
|
|
734
|
+
return this._helpConfiguration;
|
|
735
|
+
this._helpConfiguration = configuration;
|
|
736
|
+
return this;
|
|
737
|
+
}
|
|
738
|
+
configureOutput(configuration) {
|
|
739
|
+
if (configuration === undefined)
|
|
740
|
+
return this._outputConfiguration;
|
|
741
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
742
|
+
return this;
|
|
743
|
+
}
|
|
744
|
+
showHelpAfterError(displayHelp = true) {
|
|
745
|
+
if (typeof displayHelp !== "string")
|
|
746
|
+
displayHelp = !!displayHelp;
|
|
747
|
+
this._showHelpAfterError = displayHelp;
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
751
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
752
|
+
return this;
|
|
753
|
+
}
|
|
754
|
+
addCommand(cmd, opts) {
|
|
755
|
+
if (!cmd._name) {
|
|
756
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
757
|
+
- specify the name in Command constructor or using .name()`);
|
|
758
|
+
}
|
|
759
|
+
opts = opts || {};
|
|
760
|
+
if (opts.isDefault)
|
|
761
|
+
this._defaultCommandName = cmd._name;
|
|
762
|
+
if (opts.noHelp || opts.hidden)
|
|
763
|
+
cmd._hidden = true;
|
|
764
|
+
this._registerCommand(cmd);
|
|
765
|
+
cmd.parent = this;
|
|
766
|
+
cmd._checkForBrokenPassThrough();
|
|
767
|
+
return this;
|
|
768
|
+
}
|
|
769
|
+
createArgument(name, description) {
|
|
770
|
+
return new Argument(name, description);
|
|
771
|
+
}
|
|
772
|
+
argument(name, description, fn, defaultValue) {
|
|
773
|
+
const argument = this.createArgument(name, description);
|
|
774
|
+
if (typeof fn === "function") {
|
|
775
|
+
argument.default(defaultValue).argParser(fn);
|
|
776
|
+
} else {
|
|
777
|
+
argument.default(fn);
|
|
778
|
+
}
|
|
779
|
+
this.addArgument(argument);
|
|
780
|
+
return this;
|
|
781
|
+
}
|
|
782
|
+
arguments(names) {
|
|
783
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
784
|
+
this.argument(detail);
|
|
785
|
+
});
|
|
786
|
+
return this;
|
|
787
|
+
}
|
|
788
|
+
addArgument(argument) {
|
|
789
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
790
|
+
if (previousArgument && previousArgument.variadic) {
|
|
791
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
792
|
+
}
|
|
793
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
794
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
795
|
+
}
|
|
796
|
+
this.registeredArguments.push(argument);
|
|
797
|
+
return this;
|
|
798
|
+
}
|
|
799
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
800
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
801
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
802
|
+
return this;
|
|
803
|
+
}
|
|
804
|
+
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
805
|
+
const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
806
|
+
const helpDescription = description ?? "display help for command";
|
|
807
|
+
const helpCommand = this.createCommand(helpName);
|
|
808
|
+
helpCommand.helpOption(false);
|
|
809
|
+
if (helpArgs)
|
|
810
|
+
helpCommand.arguments(helpArgs);
|
|
811
|
+
if (helpDescription)
|
|
812
|
+
helpCommand.description(helpDescription);
|
|
813
|
+
this._addImplicitHelpCommand = true;
|
|
814
|
+
this._helpCommand = helpCommand;
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
818
|
+
if (typeof helpCommand !== "object") {
|
|
819
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
820
|
+
return this;
|
|
821
|
+
}
|
|
822
|
+
this._addImplicitHelpCommand = true;
|
|
823
|
+
this._helpCommand = helpCommand;
|
|
824
|
+
return this;
|
|
825
|
+
}
|
|
826
|
+
_getHelpCommand() {
|
|
827
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
828
|
+
if (hasImplicitHelpCommand) {
|
|
829
|
+
if (this._helpCommand === undefined) {
|
|
830
|
+
this.helpCommand(undefined, undefined);
|
|
831
|
+
}
|
|
832
|
+
return this._helpCommand;
|
|
833
|
+
}
|
|
834
|
+
return null;
|
|
835
|
+
}
|
|
836
|
+
hook(event, listener) {
|
|
837
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
838
|
+
if (!allowedValues.includes(event)) {
|
|
839
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
840
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
841
|
+
}
|
|
842
|
+
if (this._lifeCycleHooks[event]) {
|
|
843
|
+
this._lifeCycleHooks[event].push(listener);
|
|
844
|
+
} else {
|
|
845
|
+
this._lifeCycleHooks[event] = [listener];
|
|
846
|
+
}
|
|
847
|
+
return this;
|
|
848
|
+
}
|
|
849
|
+
exitOverride(fn) {
|
|
850
|
+
if (fn) {
|
|
851
|
+
this._exitCallback = fn;
|
|
852
|
+
} else {
|
|
853
|
+
this._exitCallback = (err) => {
|
|
854
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
855
|
+
throw err;
|
|
856
|
+
} else {
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
return this;
|
|
861
|
+
}
|
|
862
|
+
_exit(exitCode, code, message) {
|
|
863
|
+
if (this._exitCallback) {
|
|
864
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
865
|
+
}
|
|
866
|
+
process2.exit(exitCode);
|
|
867
|
+
}
|
|
868
|
+
action(fn) {
|
|
869
|
+
const listener = (args) => {
|
|
870
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
871
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
872
|
+
if (this._storeOptionsAsProperties) {
|
|
873
|
+
actionArgs[expectedArgsCount] = this;
|
|
874
|
+
} else {
|
|
875
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
876
|
+
}
|
|
877
|
+
actionArgs.push(this);
|
|
878
|
+
return fn.apply(this, actionArgs);
|
|
879
|
+
};
|
|
880
|
+
this._actionHandler = listener;
|
|
881
|
+
return this;
|
|
882
|
+
}
|
|
883
|
+
createOption(flags, description) {
|
|
884
|
+
return new Option(flags, description);
|
|
885
|
+
}
|
|
886
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
887
|
+
try {
|
|
888
|
+
return target.parseArg(value, previous);
|
|
889
|
+
} catch (err) {
|
|
890
|
+
if (err.code === "commander.invalidArgument") {
|
|
891
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
892
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
893
|
+
}
|
|
894
|
+
throw err;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
_registerOption(option) {
|
|
898
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
899
|
+
if (matchingOption) {
|
|
900
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
901
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
902
|
+
- already used by option '${matchingOption.flags}'`);
|
|
903
|
+
}
|
|
904
|
+
this.options.push(option);
|
|
905
|
+
}
|
|
906
|
+
_registerCommand(command) {
|
|
907
|
+
const knownBy = (cmd) => {
|
|
908
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
909
|
+
};
|
|
910
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
911
|
+
if (alreadyUsed) {
|
|
912
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
913
|
+
const newCmd = knownBy(command).join("|");
|
|
914
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
915
|
+
}
|
|
916
|
+
this.commands.push(command);
|
|
917
|
+
}
|
|
918
|
+
addOption(option) {
|
|
919
|
+
this._registerOption(option);
|
|
920
|
+
const oname = option.name();
|
|
921
|
+
const name = option.attributeName();
|
|
922
|
+
if (option.negate) {
|
|
923
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
924
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
925
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
926
|
+
}
|
|
927
|
+
} else if (option.defaultValue !== undefined) {
|
|
928
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
929
|
+
}
|
|
930
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
931
|
+
if (val == null && option.presetArg !== undefined) {
|
|
932
|
+
val = option.presetArg;
|
|
933
|
+
}
|
|
934
|
+
const oldValue = this.getOptionValue(name);
|
|
935
|
+
if (val !== null && option.parseArg) {
|
|
936
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
937
|
+
} else if (val !== null && option.variadic) {
|
|
938
|
+
val = option._concatValue(val, oldValue);
|
|
939
|
+
}
|
|
940
|
+
if (val == null) {
|
|
941
|
+
if (option.negate) {
|
|
942
|
+
val = false;
|
|
943
|
+
} else if (option.isBoolean() || option.optional) {
|
|
944
|
+
val = true;
|
|
945
|
+
} else {
|
|
946
|
+
val = "";
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
950
|
+
};
|
|
951
|
+
this.on("option:" + oname, (val) => {
|
|
952
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
953
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
954
|
+
});
|
|
955
|
+
if (option.envVar) {
|
|
956
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
957
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
958
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
return this;
|
|
962
|
+
}
|
|
963
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
964
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
965
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
966
|
+
}
|
|
967
|
+
const option = this.createOption(flags, description);
|
|
968
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
969
|
+
if (typeof fn === "function") {
|
|
970
|
+
option.default(defaultValue).argParser(fn);
|
|
971
|
+
} else if (fn instanceof RegExp) {
|
|
972
|
+
const regex = fn;
|
|
973
|
+
fn = (val, def) => {
|
|
974
|
+
const m = regex.exec(val);
|
|
975
|
+
return m ? m[0] : def;
|
|
976
|
+
};
|
|
977
|
+
option.default(defaultValue).argParser(fn);
|
|
978
|
+
} else {
|
|
979
|
+
option.default(fn);
|
|
980
|
+
}
|
|
981
|
+
return this.addOption(option);
|
|
982
|
+
}
|
|
983
|
+
option(flags, description, parseArg, defaultValue) {
|
|
984
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
985
|
+
}
|
|
986
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
987
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
988
|
+
}
|
|
989
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
990
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
991
|
+
return this;
|
|
992
|
+
}
|
|
993
|
+
allowUnknownOption(allowUnknown = true) {
|
|
994
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
995
|
+
return this;
|
|
996
|
+
}
|
|
997
|
+
allowExcessArguments(allowExcess = true) {
|
|
998
|
+
this._allowExcessArguments = !!allowExcess;
|
|
999
|
+
return this;
|
|
1000
|
+
}
|
|
1001
|
+
enablePositionalOptions(positional = true) {
|
|
1002
|
+
this._enablePositionalOptions = !!positional;
|
|
1003
|
+
return this;
|
|
1004
|
+
}
|
|
1005
|
+
passThroughOptions(passThrough = true) {
|
|
1006
|
+
this._passThroughOptions = !!passThrough;
|
|
1007
|
+
this._checkForBrokenPassThrough();
|
|
1008
|
+
return this;
|
|
1009
|
+
}
|
|
1010
|
+
_checkForBrokenPassThrough() {
|
|
1011
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
1012
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1016
|
+
if (this.options.length) {
|
|
1017
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1018
|
+
}
|
|
1019
|
+
if (Object.keys(this._optionValues).length) {
|
|
1020
|
+
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
1021
|
+
}
|
|
1022
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1023
|
+
return this;
|
|
1024
|
+
}
|
|
1025
|
+
getOptionValue(key) {
|
|
1026
|
+
if (this._storeOptionsAsProperties) {
|
|
1027
|
+
return this[key];
|
|
1028
|
+
}
|
|
1029
|
+
return this._optionValues[key];
|
|
1030
|
+
}
|
|
1031
|
+
setOptionValue(key, value) {
|
|
1032
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
1033
|
+
}
|
|
1034
|
+
setOptionValueWithSource(key, value, source) {
|
|
1035
|
+
if (this._storeOptionsAsProperties) {
|
|
1036
|
+
this[key] = value;
|
|
1037
|
+
} else {
|
|
1038
|
+
this._optionValues[key] = value;
|
|
1039
|
+
}
|
|
1040
|
+
this._optionValueSources[key] = source;
|
|
1041
|
+
return this;
|
|
1042
|
+
}
|
|
1043
|
+
getOptionValueSource(key) {
|
|
1044
|
+
return this._optionValueSources[key];
|
|
1045
|
+
}
|
|
1046
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1047
|
+
let source;
|
|
1048
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1049
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
1050
|
+
source = cmd.getOptionValueSource(key);
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
return source;
|
|
1054
|
+
}
|
|
1055
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1056
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1057
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1058
|
+
}
|
|
1059
|
+
parseOptions = parseOptions || {};
|
|
1060
|
+
if (argv === undefined && parseOptions.from === undefined) {
|
|
1061
|
+
if (process2.versions?.electron) {
|
|
1062
|
+
parseOptions.from = "electron";
|
|
1063
|
+
}
|
|
1064
|
+
const execArgv = process2.execArgv ?? [];
|
|
1065
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1066
|
+
parseOptions.from = "eval";
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
if (argv === undefined) {
|
|
1070
|
+
argv = process2.argv;
|
|
1071
|
+
}
|
|
1072
|
+
this.rawArgs = argv.slice();
|
|
1073
|
+
let userArgs;
|
|
1074
|
+
switch (parseOptions.from) {
|
|
1075
|
+
case undefined:
|
|
1076
|
+
case "node":
|
|
1077
|
+
this._scriptPath = argv[1];
|
|
1078
|
+
userArgs = argv.slice(2);
|
|
1079
|
+
break;
|
|
1080
|
+
case "electron":
|
|
1081
|
+
if (process2.defaultApp) {
|
|
1082
|
+
this._scriptPath = argv[1];
|
|
1083
|
+
userArgs = argv.slice(2);
|
|
1084
|
+
} else {
|
|
1085
|
+
userArgs = argv.slice(1);
|
|
1086
|
+
}
|
|
1087
|
+
break;
|
|
1088
|
+
case "user":
|
|
1089
|
+
userArgs = argv.slice(0);
|
|
1090
|
+
break;
|
|
1091
|
+
case "eval":
|
|
1092
|
+
userArgs = argv.slice(1);
|
|
1093
|
+
break;
|
|
1094
|
+
default:
|
|
1095
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1096
|
+
}
|
|
1097
|
+
if (!this._name && this._scriptPath)
|
|
1098
|
+
this.nameFromFilename(this._scriptPath);
|
|
1099
|
+
this._name = this._name || "program";
|
|
1100
|
+
return userArgs;
|
|
1101
|
+
}
|
|
1102
|
+
parse(argv, parseOptions) {
|
|
1103
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1104
|
+
this._parseCommand([], userArgs);
|
|
1105
|
+
return this;
|
|
1106
|
+
}
|
|
1107
|
+
async parseAsync(argv, parseOptions) {
|
|
1108
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1109
|
+
await this._parseCommand([], userArgs);
|
|
1110
|
+
return this;
|
|
1111
|
+
}
|
|
1112
|
+
_executeSubCommand(subcommand, args) {
|
|
1113
|
+
args = args.slice();
|
|
1114
|
+
let launchWithNode = false;
|
|
1115
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1116
|
+
function findFile(baseDir, baseName) {
|
|
1117
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1118
|
+
if (fs.existsSync(localBin))
|
|
1119
|
+
return localBin;
|
|
1120
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
1121
|
+
return;
|
|
1122
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1123
|
+
if (foundExt)
|
|
1124
|
+
return `${localBin}${foundExt}`;
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
this._checkForMissingMandatoryOptions();
|
|
1128
|
+
this._checkForConflictingOptions();
|
|
1129
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1130
|
+
let executableDir = this._executableDir || "";
|
|
1131
|
+
if (this._scriptPath) {
|
|
1132
|
+
let resolvedScriptPath;
|
|
1133
|
+
try {
|
|
1134
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1135
|
+
} catch (err) {
|
|
1136
|
+
resolvedScriptPath = this._scriptPath;
|
|
1137
|
+
}
|
|
1138
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1139
|
+
}
|
|
1140
|
+
if (executableDir) {
|
|
1141
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1142
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1143
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1144
|
+
if (legacyName !== this._name) {
|
|
1145
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
executableFile = localFile || executableFile;
|
|
1149
|
+
}
|
|
1150
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1151
|
+
let proc;
|
|
1152
|
+
if (process2.platform !== "win32") {
|
|
1153
|
+
if (launchWithNode) {
|
|
1154
|
+
args.unshift(executableFile);
|
|
1155
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1156
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1157
|
+
} else {
|
|
1158
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1159
|
+
}
|
|
1160
|
+
} else {
|
|
1161
|
+
args.unshift(executableFile);
|
|
1162
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1163
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1164
|
+
}
|
|
1165
|
+
if (!proc.killed) {
|
|
1166
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1167
|
+
signals.forEach((signal) => {
|
|
1168
|
+
process2.on(signal, () => {
|
|
1169
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1170
|
+
proc.kill(signal);
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
const exitCallback = this._exitCallback;
|
|
1176
|
+
proc.on("close", (code) => {
|
|
1177
|
+
code = code ?? 1;
|
|
1178
|
+
if (!exitCallback) {
|
|
1179
|
+
process2.exit(code);
|
|
1180
|
+
} else {
|
|
1181
|
+
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
1182
|
+
}
|
|
1183
|
+
});
|
|
1184
|
+
proc.on("error", (err) => {
|
|
1185
|
+
if (err.code === "ENOENT") {
|
|
1186
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
1187
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1188
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1189
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1190
|
+
- ${executableDirMessage}`;
|
|
1191
|
+
throw new Error(executableMissing);
|
|
1192
|
+
} else if (err.code === "EACCES") {
|
|
1193
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1194
|
+
}
|
|
1195
|
+
if (!exitCallback) {
|
|
1196
|
+
process2.exit(1);
|
|
1197
|
+
} else {
|
|
1198
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1199
|
+
wrappedError.nestedError = err;
|
|
1200
|
+
exitCallback(wrappedError);
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
this.runningCommand = proc;
|
|
1204
|
+
}
|
|
1205
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1206
|
+
const subCommand = this._findCommand(commandName);
|
|
1207
|
+
if (!subCommand)
|
|
1208
|
+
this.help({ error: true });
|
|
1209
|
+
let promiseChain;
|
|
1210
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1211
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1212
|
+
if (subCommand._executableHandler) {
|
|
1213
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1214
|
+
} else {
|
|
1215
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
return promiseChain;
|
|
1219
|
+
}
|
|
1220
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1221
|
+
if (!subcommandName) {
|
|
1222
|
+
this.help();
|
|
1223
|
+
}
|
|
1224
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1225
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1226
|
+
subCommand.help();
|
|
1227
|
+
}
|
|
1228
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
1229
|
+
}
|
|
1230
|
+
_checkNumberOfArguments() {
|
|
1231
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
1232
|
+
if (arg.required && this.args[i] == null) {
|
|
1233
|
+
this.missingArgument(arg.name());
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
1240
|
+
this._excessArguments(this.args);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
_processArguments() {
|
|
1244
|
+
const myParseArg = (argument, value, previous) => {
|
|
1245
|
+
let parsedValue = value;
|
|
1246
|
+
if (value !== null && argument.parseArg) {
|
|
1247
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
1248
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
1249
|
+
}
|
|
1250
|
+
return parsedValue;
|
|
1251
|
+
};
|
|
1252
|
+
this._checkNumberOfArguments();
|
|
1253
|
+
const processedArgs = [];
|
|
1254
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
1255
|
+
let value = declaredArg.defaultValue;
|
|
1256
|
+
if (declaredArg.variadic) {
|
|
1257
|
+
if (index < this.args.length) {
|
|
1258
|
+
value = this.args.slice(index);
|
|
1259
|
+
if (declaredArg.parseArg) {
|
|
1260
|
+
value = value.reduce((processed, v) => {
|
|
1261
|
+
return myParseArg(declaredArg, v, processed);
|
|
1262
|
+
}, declaredArg.defaultValue);
|
|
1263
|
+
}
|
|
1264
|
+
} else if (value === undefined) {
|
|
1265
|
+
value = [];
|
|
1266
|
+
}
|
|
1267
|
+
} else if (index < this.args.length) {
|
|
1268
|
+
value = this.args[index];
|
|
1269
|
+
if (declaredArg.parseArg) {
|
|
1270
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
processedArgs[index] = value;
|
|
1274
|
+
});
|
|
1275
|
+
this.processedArgs = processedArgs;
|
|
1276
|
+
}
|
|
1277
|
+
_chainOrCall(promise, fn) {
|
|
1278
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
1279
|
+
return promise.then(() => fn());
|
|
1280
|
+
}
|
|
1281
|
+
return fn();
|
|
1282
|
+
}
|
|
1283
|
+
_chainOrCallHooks(promise, event) {
|
|
1284
|
+
let result = promise;
|
|
1285
|
+
const hooks = [];
|
|
1286
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1287
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1288
|
+
hooks.push({ hookedCommand, callback });
|
|
1289
|
+
});
|
|
1290
|
+
});
|
|
1291
|
+
if (event === "postAction") {
|
|
1292
|
+
hooks.reverse();
|
|
1293
|
+
}
|
|
1294
|
+
hooks.forEach((hookDetail) => {
|
|
1295
|
+
result = this._chainOrCall(result, () => {
|
|
1296
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1297
|
+
});
|
|
1298
|
+
});
|
|
1299
|
+
return result;
|
|
1300
|
+
}
|
|
1301
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1302
|
+
let result = promise;
|
|
1303
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1304
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1305
|
+
result = this._chainOrCall(result, () => {
|
|
1306
|
+
return hook(this, subCommand);
|
|
1307
|
+
});
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
return result;
|
|
1311
|
+
}
|
|
1312
|
+
_parseCommand(operands, unknown) {
|
|
1313
|
+
const parsed = this.parseOptions(unknown);
|
|
1314
|
+
this._parseOptionsEnv();
|
|
1315
|
+
this._parseOptionsImplied();
|
|
1316
|
+
operands = operands.concat(parsed.operands);
|
|
1317
|
+
unknown = parsed.unknown;
|
|
1318
|
+
this.args = operands.concat(unknown);
|
|
1319
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1320
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1321
|
+
}
|
|
1322
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
1323
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1324
|
+
}
|
|
1325
|
+
if (this._defaultCommandName) {
|
|
1326
|
+
this._outputHelpIfRequested(unknown);
|
|
1327
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1328
|
+
}
|
|
1329
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1330
|
+
this.help({ error: true });
|
|
1331
|
+
}
|
|
1332
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
1333
|
+
this._checkForMissingMandatoryOptions();
|
|
1334
|
+
this._checkForConflictingOptions();
|
|
1335
|
+
const checkForUnknownOptions = () => {
|
|
1336
|
+
if (parsed.unknown.length > 0) {
|
|
1337
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
const commandEvent = `command:${this.name()}`;
|
|
1341
|
+
if (this._actionHandler) {
|
|
1342
|
+
checkForUnknownOptions();
|
|
1343
|
+
this._processArguments();
|
|
1344
|
+
let promiseChain;
|
|
1345
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1346
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
1347
|
+
if (this.parent) {
|
|
1348
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1349
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1353
|
+
return promiseChain;
|
|
1354
|
+
}
|
|
1355
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1356
|
+
checkForUnknownOptions();
|
|
1357
|
+
this._processArguments();
|
|
1358
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1359
|
+
} else if (operands.length) {
|
|
1360
|
+
if (this._findCommand("*")) {
|
|
1361
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1362
|
+
}
|
|
1363
|
+
if (this.listenerCount("command:*")) {
|
|
1364
|
+
this.emit("command:*", operands, unknown);
|
|
1365
|
+
} else if (this.commands.length) {
|
|
1366
|
+
this.unknownCommand();
|
|
1367
|
+
} else {
|
|
1368
|
+
checkForUnknownOptions();
|
|
1369
|
+
this._processArguments();
|
|
1370
|
+
}
|
|
1371
|
+
} else if (this.commands.length) {
|
|
1372
|
+
checkForUnknownOptions();
|
|
1373
|
+
this.help({ error: true });
|
|
1374
|
+
} else {
|
|
1375
|
+
checkForUnknownOptions();
|
|
1376
|
+
this._processArguments();
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
_findCommand(name) {
|
|
1380
|
+
if (!name)
|
|
1381
|
+
return;
|
|
1382
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1383
|
+
}
|
|
1384
|
+
_findOption(arg) {
|
|
1385
|
+
return this.options.find((option) => option.is(arg));
|
|
1386
|
+
}
|
|
1387
|
+
_checkForMissingMandatoryOptions() {
|
|
1388
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1389
|
+
cmd.options.forEach((anOption) => {
|
|
1390
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1391
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
_checkForConflictingLocalOptions() {
|
|
1397
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1398
|
+
const optionKey = option.attributeName();
|
|
1399
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1400
|
+
return false;
|
|
1401
|
+
}
|
|
1402
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1403
|
+
});
|
|
1404
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1405
|
+
optionsWithConflicting.forEach((option) => {
|
|
1406
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1407
|
+
if (conflictingAndDefined) {
|
|
1408
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
_checkForConflictingOptions() {
|
|
1413
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1414
|
+
cmd._checkForConflictingLocalOptions();
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
parseOptions(argv) {
|
|
1418
|
+
const operands = [];
|
|
1419
|
+
const unknown = [];
|
|
1420
|
+
let dest = operands;
|
|
1421
|
+
const args = argv.slice();
|
|
1422
|
+
function maybeOption(arg) {
|
|
1423
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1424
|
+
}
|
|
1425
|
+
let activeVariadicOption = null;
|
|
1426
|
+
while (args.length) {
|
|
1427
|
+
const arg = args.shift();
|
|
1428
|
+
if (arg === "--") {
|
|
1429
|
+
if (dest === unknown)
|
|
1430
|
+
dest.push(arg);
|
|
1431
|
+
dest.push(...args);
|
|
1432
|
+
break;
|
|
1433
|
+
}
|
|
1434
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1435
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1436
|
+
continue;
|
|
1437
|
+
}
|
|
1438
|
+
activeVariadicOption = null;
|
|
1439
|
+
if (maybeOption(arg)) {
|
|
1440
|
+
const option = this._findOption(arg);
|
|
1441
|
+
if (option) {
|
|
1442
|
+
if (option.required) {
|
|
1443
|
+
const value = args.shift();
|
|
1444
|
+
if (value === undefined)
|
|
1445
|
+
this.optionMissingArgument(option);
|
|
1446
|
+
this.emit(`option:${option.name()}`, value);
|
|
1447
|
+
} else if (option.optional) {
|
|
1448
|
+
let value = null;
|
|
1449
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1450
|
+
value = args.shift();
|
|
1451
|
+
}
|
|
1452
|
+
this.emit(`option:${option.name()}`, value);
|
|
1453
|
+
} else {
|
|
1454
|
+
this.emit(`option:${option.name()}`);
|
|
1455
|
+
}
|
|
1456
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1461
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1462
|
+
if (option) {
|
|
1463
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1464
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1465
|
+
} else {
|
|
1466
|
+
this.emit(`option:${option.name()}`);
|
|
1467
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1468
|
+
}
|
|
1469
|
+
continue;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1473
|
+
const index = arg.indexOf("=");
|
|
1474
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1475
|
+
if (option && (option.required || option.optional)) {
|
|
1476
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1477
|
+
continue;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
if (maybeOption(arg)) {
|
|
1481
|
+
dest = unknown;
|
|
1482
|
+
}
|
|
1483
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1484
|
+
if (this._findCommand(arg)) {
|
|
1485
|
+
operands.push(arg);
|
|
1486
|
+
if (args.length > 0)
|
|
1487
|
+
unknown.push(...args);
|
|
1488
|
+
break;
|
|
1489
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1490
|
+
operands.push(arg);
|
|
1491
|
+
if (args.length > 0)
|
|
1492
|
+
operands.push(...args);
|
|
1493
|
+
break;
|
|
1494
|
+
} else if (this._defaultCommandName) {
|
|
1495
|
+
unknown.push(arg);
|
|
1496
|
+
if (args.length > 0)
|
|
1497
|
+
unknown.push(...args);
|
|
1498
|
+
break;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
if (this._passThroughOptions) {
|
|
1502
|
+
dest.push(arg);
|
|
1503
|
+
if (args.length > 0)
|
|
1504
|
+
dest.push(...args);
|
|
1505
|
+
break;
|
|
1506
|
+
}
|
|
1507
|
+
dest.push(arg);
|
|
1508
|
+
}
|
|
1509
|
+
return { operands, unknown };
|
|
1510
|
+
}
|
|
1511
|
+
opts() {
|
|
1512
|
+
if (this._storeOptionsAsProperties) {
|
|
1513
|
+
const result = {};
|
|
1514
|
+
const len = this.options.length;
|
|
1515
|
+
for (let i = 0;i < len; i++) {
|
|
1516
|
+
const key = this.options[i].attributeName();
|
|
1517
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1518
|
+
}
|
|
1519
|
+
return result;
|
|
1520
|
+
}
|
|
1521
|
+
return this._optionValues;
|
|
1522
|
+
}
|
|
1523
|
+
optsWithGlobals() {
|
|
1524
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1525
|
+
}
|
|
1526
|
+
error(message, errorOptions) {
|
|
1527
|
+
this._outputConfiguration.outputError(`${message}\n`, this._outputConfiguration.writeErr);
|
|
1528
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1529
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`);
|
|
1530
|
+
} else if (this._showHelpAfterError) {
|
|
1531
|
+
this._outputConfiguration.writeErr("\n");
|
|
1532
|
+
this.outputHelp({ error: true });
|
|
1533
|
+
}
|
|
1534
|
+
const config = errorOptions || {};
|
|
1535
|
+
const exitCode = config.exitCode || 1;
|
|
1536
|
+
const code = config.code || "commander.error";
|
|
1537
|
+
this._exit(exitCode, code, message);
|
|
1538
|
+
}
|
|
1539
|
+
_parseOptionsEnv() {
|
|
1540
|
+
this.options.forEach((option) => {
|
|
1541
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
1542
|
+
const optionKey = option.attributeName();
|
|
1543
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1544
|
+
if (option.required || option.optional) {
|
|
1545
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1546
|
+
} else {
|
|
1547
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
_parseOptionsImplied() {
|
|
1554
|
+
const dualHelper = new DualOptions(this.options);
|
|
1555
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1556
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1557
|
+
};
|
|
1558
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1559
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1560
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1561
|
+
});
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
missingArgument(name) {
|
|
1565
|
+
const message = `error: missing required argument '${name}'`;
|
|
1566
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1567
|
+
}
|
|
1568
|
+
optionMissingArgument(option) {
|
|
1569
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1570
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1571
|
+
}
|
|
1572
|
+
missingMandatoryOptionValue(option) {
|
|
1573
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1574
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1575
|
+
}
|
|
1576
|
+
_conflictingOption(option, conflictingOption) {
|
|
1577
|
+
const findBestOptionFromValue = (option2) => {
|
|
1578
|
+
const optionKey = option2.attributeName();
|
|
1579
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1580
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1581
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1582
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1583
|
+
return negativeOption;
|
|
1584
|
+
}
|
|
1585
|
+
return positiveOption || option2;
|
|
1586
|
+
};
|
|
1587
|
+
const getErrorMessage = (option2) => {
|
|
1588
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1589
|
+
const optionKey = bestOption.attributeName();
|
|
1590
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1591
|
+
if (source === "env") {
|
|
1592
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1593
|
+
}
|
|
1594
|
+
return `option '${bestOption.flags}'`;
|
|
1595
|
+
};
|
|
1596
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1597
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1598
|
+
}
|
|
1599
|
+
unknownOption(flag) {
|
|
1600
|
+
if (this._allowUnknownOption)
|
|
1601
|
+
return;
|
|
1602
|
+
let suggestion = "";
|
|
1603
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1604
|
+
let candidateFlags = [];
|
|
1605
|
+
let command = this;
|
|
1606
|
+
do {
|
|
1607
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1608
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1609
|
+
command = command.parent;
|
|
1610
|
+
} while (command && !command._enablePositionalOptions);
|
|
1611
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1612
|
+
}
|
|
1613
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1614
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1615
|
+
}
|
|
1616
|
+
_excessArguments(receivedArgs) {
|
|
1617
|
+
if (this._allowExcessArguments)
|
|
1618
|
+
return;
|
|
1619
|
+
const expected = this.registeredArguments.length;
|
|
1620
|
+
const s = expected === 1 ? "" : "s";
|
|
1621
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1622
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1623
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1624
|
+
}
|
|
1625
|
+
unknownCommand() {
|
|
1626
|
+
const unknownName = this.args[0];
|
|
1627
|
+
let suggestion = "";
|
|
1628
|
+
if (this._showSuggestionAfterError) {
|
|
1629
|
+
const candidateNames = [];
|
|
1630
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1631
|
+
candidateNames.push(command.name());
|
|
1632
|
+
if (command.alias())
|
|
1633
|
+
candidateNames.push(command.alias());
|
|
1634
|
+
});
|
|
1635
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1636
|
+
}
|
|
1637
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1638
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1639
|
+
}
|
|
1640
|
+
version(str, flags, description) {
|
|
1641
|
+
if (str === undefined)
|
|
1642
|
+
return this._version;
|
|
1643
|
+
this._version = str;
|
|
1644
|
+
flags = flags || "-V, --version";
|
|
1645
|
+
description = description || "output the version number";
|
|
1646
|
+
const versionOption = this.createOption(flags, description);
|
|
1647
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1648
|
+
this._registerOption(versionOption);
|
|
1649
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1650
|
+
this._outputConfiguration.writeOut(`${str}\n`);
|
|
1651
|
+
this._exit(0, "commander.version", str);
|
|
1652
|
+
});
|
|
1653
|
+
return this;
|
|
1654
|
+
}
|
|
1655
|
+
description(str, argsDescription) {
|
|
1656
|
+
if (str === undefined && argsDescription === undefined)
|
|
1657
|
+
return this._description;
|
|
1658
|
+
this._description = str;
|
|
1659
|
+
if (argsDescription) {
|
|
1660
|
+
this._argsDescription = argsDescription;
|
|
1661
|
+
}
|
|
1662
|
+
return this;
|
|
1663
|
+
}
|
|
1664
|
+
summary(str) {
|
|
1665
|
+
if (str === undefined)
|
|
1666
|
+
return this._summary;
|
|
1667
|
+
this._summary = str;
|
|
1668
|
+
return this;
|
|
1669
|
+
}
|
|
1670
|
+
alias(alias) {
|
|
1671
|
+
if (alias === undefined)
|
|
1672
|
+
return this._aliases[0];
|
|
1673
|
+
let command = this;
|
|
1674
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1675
|
+
command = this.commands[this.commands.length - 1];
|
|
1676
|
+
}
|
|
1677
|
+
if (alias === command._name)
|
|
1678
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1679
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
1680
|
+
if (matchingCommand) {
|
|
1681
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
1682
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
1683
|
+
}
|
|
1684
|
+
command._aliases.push(alias);
|
|
1685
|
+
return this;
|
|
1686
|
+
}
|
|
1687
|
+
aliases(aliases) {
|
|
1688
|
+
if (aliases === undefined)
|
|
1689
|
+
return this._aliases;
|
|
1690
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1691
|
+
return this;
|
|
1692
|
+
}
|
|
1693
|
+
usage(str) {
|
|
1694
|
+
if (str === undefined) {
|
|
1695
|
+
if (this._usage)
|
|
1696
|
+
return this._usage;
|
|
1697
|
+
const args = this.registeredArguments.map((arg) => {
|
|
1698
|
+
return humanReadableArgName(arg);
|
|
1699
|
+
});
|
|
1700
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
1701
|
+
}
|
|
1702
|
+
this._usage = str;
|
|
1703
|
+
return this;
|
|
1704
|
+
}
|
|
1705
|
+
name(str) {
|
|
1706
|
+
if (str === undefined)
|
|
1707
|
+
return this._name;
|
|
1708
|
+
this._name = str;
|
|
1709
|
+
return this;
|
|
1710
|
+
}
|
|
1711
|
+
nameFromFilename(filename) {
|
|
1712
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1713
|
+
return this;
|
|
1714
|
+
}
|
|
1715
|
+
executableDir(path2) {
|
|
1716
|
+
if (path2 === undefined)
|
|
1717
|
+
return this._executableDir;
|
|
1718
|
+
this._executableDir = path2;
|
|
1719
|
+
return this;
|
|
1720
|
+
}
|
|
1721
|
+
helpInformation(contextOptions) {
|
|
1722
|
+
const helper = this.createHelp();
|
|
1723
|
+
if (helper.helpWidth === undefined) {
|
|
1724
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
1725
|
+
}
|
|
1726
|
+
return helper.formatHelp(this, helper);
|
|
1727
|
+
}
|
|
1728
|
+
_getHelpContext(contextOptions) {
|
|
1729
|
+
contextOptions = contextOptions || {};
|
|
1730
|
+
const context = { error: !!contextOptions.error };
|
|
1731
|
+
let write;
|
|
1732
|
+
if (context.error) {
|
|
1733
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1734
|
+
} else {
|
|
1735
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1736
|
+
}
|
|
1737
|
+
context.write = contextOptions.write || write;
|
|
1738
|
+
context.command = this;
|
|
1739
|
+
return context;
|
|
1740
|
+
}
|
|
1741
|
+
outputHelp(contextOptions) {
|
|
1742
|
+
let deprecatedCallback;
|
|
1743
|
+
if (typeof contextOptions === "function") {
|
|
1744
|
+
deprecatedCallback = contextOptions;
|
|
1745
|
+
contextOptions = undefined;
|
|
1746
|
+
}
|
|
1747
|
+
const context = this._getHelpContext(contextOptions);
|
|
1748
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
1749
|
+
this.emit("beforeHelp", context);
|
|
1750
|
+
let helpInformation = this.helpInformation(context);
|
|
1751
|
+
if (deprecatedCallback) {
|
|
1752
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1753
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1754
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
context.write(helpInformation);
|
|
1758
|
+
if (this._getHelpOption()?.long) {
|
|
1759
|
+
this.emit(this._getHelpOption().long);
|
|
1760
|
+
}
|
|
1761
|
+
this.emit("afterHelp", context);
|
|
1762
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
|
|
1763
|
+
}
|
|
1764
|
+
helpOption(flags, description) {
|
|
1765
|
+
if (typeof flags === "boolean") {
|
|
1766
|
+
if (flags) {
|
|
1767
|
+
this._helpOption = this._helpOption ?? undefined;
|
|
1768
|
+
} else {
|
|
1769
|
+
this._helpOption = null;
|
|
1770
|
+
}
|
|
1771
|
+
return this;
|
|
1772
|
+
}
|
|
1773
|
+
flags = flags ?? "-h, --help";
|
|
1774
|
+
description = description ?? "display help for command";
|
|
1775
|
+
this._helpOption = this.createOption(flags, description);
|
|
1776
|
+
return this;
|
|
1777
|
+
}
|
|
1778
|
+
_getHelpOption() {
|
|
1779
|
+
if (this._helpOption === undefined) {
|
|
1780
|
+
this.helpOption(undefined, undefined);
|
|
1781
|
+
}
|
|
1782
|
+
return this._helpOption;
|
|
1783
|
+
}
|
|
1784
|
+
addHelpOption(option) {
|
|
1785
|
+
this._helpOption = option;
|
|
1786
|
+
return this;
|
|
1787
|
+
}
|
|
1788
|
+
help(contextOptions) {
|
|
1789
|
+
this.outputHelp(contextOptions);
|
|
1790
|
+
let exitCode = process2.exitCode || 0;
|
|
1791
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1792
|
+
exitCode = 1;
|
|
1793
|
+
}
|
|
1794
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1795
|
+
}
|
|
1796
|
+
addHelpText(position, text) {
|
|
1797
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1798
|
+
if (!allowedValues.includes(position)) {
|
|
1799
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
1800
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1801
|
+
}
|
|
1802
|
+
const helpEvent = `${position}Help`;
|
|
1803
|
+
this.on(helpEvent, (context) => {
|
|
1804
|
+
let helpStr;
|
|
1805
|
+
if (typeof text === "function") {
|
|
1806
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
1807
|
+
} else {
|
|
1808
|
+
helpStr = text;
|
|
1809
|
+
}
|
|
1810
|
+
if (helpStr) {
|
|
1811
|
+
context.write(`${helpStr}\n`);
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1814
|
+
return this;
|
|
1815
|
+
}
|
|
1816
|
+
_outputHelpIfRequested(args) {
|
|
1817
|
+
const helpOption = this._getHelpOption();
|
|
1818
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
1819
|
+
if (helpRequested) {
|
|
1820
|
+
this.outputHelp();
|
|
1821
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
exports.Command = Command;
|
|
1826
|
+
});
|
|
1827
|
+
|
|
1828
|
+
// ../../node_modules/commander/index.js
|
|
1829
|
+
var require_commander = __commonJS((exports) => {
|
|
1830
|
+
var { Argument } = require_argument();
|
|
1831
|
+
var { Command } = require_command();
|
|
1832
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
1833
|
+
var { Help } = require_help();
|
|
1834
|
+
var { Option } = require_option();
|
|
1835
|
+
exports.program = new Command;
|
|
1836
|
+
exports.createCommand = (name) => new Command(name);
|
|
1837
|
+
exports.createOption = (flags, description) => new Option(flags, description);
|
|
1838
|
+
exports.createArgument = (name, description) => new Argument(name, description);
|
|
1839
|
+
exports.Command = Command;
|
|
1840
|
+
exports.Option = Option;
|
|
1841
|
+
exports.Argument = Argument;
|
|
1842
|
+
exports.Help = Help;
|
|
1843
|
+
exports.CommanderError = CommanderError;
|
|
1844
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1845
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
1846
|
+
});
|
|
1847
|
+
|
|
1848
|
+
// ../../node_modules/dotenv/package.json
|
|
1849
|
+
var require_package = __commonJS((exports, module) => {
|
|
1850
|
+
module.exports = {
|
|
1851
|
+
name: "dotenv",
|
|
1852
|
+
version: "16.4.5",
|
|
1853
|
+
description: "Loads environment variables from .env file",
|
|
1854
|
+
main: "lib/main.js",
|
|
1855
|
+
types: "lib/main.d.ts",
|
|
1856
|
+
exports: {
|
|
1857
|
+
".": {
|
|
1858
|
+
types: "./lib/main.d.ts",
|
|
1859
|
+
require: "./lib/main.js",
|
|
1860
|
+
default: "./lib/main.js"
|
|
1861
|
+
},
|
|
1862
|
+
"./config": "./config.js",
|
|
1863
|
+
"./config.js": "./config.js",
|
|
1864
|
+
"./lib/env-options": "./lib/env-options.js",
|
|
1865
|
+
"./lib/env-options.js": "./lib/env-options.js",
|
|
1866
|
+
"./lib/cli-options": "./lib/cli-options.js",
|
|
1867
|
+
"./lib/cli-options.js": "./lib/cli-options.js",
|
|
1868
|
+
"./package.json": "./package.json"
|
|
1869
|
+
},
|
|
1870
|
+
scripts: {
|
|
1871
|
+
"dts-check": "tsc --project tests/types/tsconfig.json",
|
|
1872
|
+
lint: "standard",
|
|
1873
|
+
"lint-readme": "standard-markdown",
|
|
1874
|
+
pretest: "npm run lint && npm run dts-check",
|
|
1875
|
+
test: "tap tests/*.js --100 -Rspec",
|
|
1876
|
+
"test:coverage": "tap --coverage-report=lcov",
|
|
1877
|
+
prerelease: "npm test",
|
|
1878
|
+
release: "standard-version"
|
|
1879
|
+
},
|
|
1880
|
+
repository: {
|
|
1881
|
+
type: "git",
|
|
1882
|
+
url: "git://github.com/motdotla/dotenv.git"
|
|
1883
|
+
},
|
|
1884
|
+
funding: "https://dotenvx.com",
|
|
1885
|
+
keywords: [
|
|
1886
|
+
"dotenv",
|
|
1887
|
+
"env",
|
|
1888
|
+
".env",
|
|
1889
|
+
"environment",
|
|
1890
|
+
"variables",
|
|
1891
|
+
"config",
|
|
1892
|
+
"settings"
|
|
1893
|
+
],
|
|
1894
|
+
readmeFilename: "README.md",
|
|
1895
|
+
license: "BSD-2-Clause",
|
|
1896
|
+
devDependencies: {
|
|
1897
|
+
"@definitelytyped/dtslint": "^0.0.133",
|
|
1898
|
+
"@types/node": "^18.11.3",
|
|
1899
|
+
decache: "^4.6.1",
|
|
1900
|
+
sinon: "^14.0.1",
|
|
1901
|
+
standard: "^17.0.0",
|
|
1902
|
+
"standard-markdown": "^7.1.0",
|
|
1903
|
+
"standard-version": "^9.5.0",
|
|
1904
|
+
tap: "^16.3.0",
|
|
1905
|
+
tar: "^6.1.11",
|
|
1906
|
+
typescript: "^4.8.4"
|
|
1907
|
+
},
|
|
1908
|
+
engines: {
|
|
1909
|
+
node: ">=12"
|
|
1910
|
+
},
|
|
1911
|
+
browser: {
|
|
1912
|
+
fs: false
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
});
|
|
1916
|
+
|
|
1917
|
+
// ../../node_modules/dotenv/lib/main.js
|
|
1918
|
+
var require_main = __commonJS((exports, module) => {
|
|
1919
|
+
var parse = function(src) {
|
|
1920
|
+
const obj = {};
|
|
1921
|
+
let lines = src.toString();
|
|
1922
|
+
lines = lines.replace(/\r\n?/mg, "\n");
|
|
1923
|
+
let match;
|
|
1924
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
1925
|
+
const key = match[1];
|
|
1926
|
+
let value = match[2] || "";
|
|
1927
|
+
value = value.trim();
|
|
1928
|
+
const maybeQuote = value[0];
|
|
1929
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
1930
|
+
if (maybeQuote === '"') {
|
|
1931
|
+
value = value.replace(/\\n/g, "\n");
|
|
1932
|
+
value = value.replace(/\\r/g, "\r");
|
|
1933
|
+
}
|
|
1934
|
+
obj[key] = value;
|
|
1935
|
+
}
|
|
1936
|
+
return obj;
|
|
1937
|
+
};
|
|
1938
|
+
var _parseVault = function(options) {
|
|
1939
|
+
const vaultPath = _vaultPath(options);
|
|
1940
|
+
const result = DotenvModule.configDotenv({ path: vaultPath });
|
|
1941
|
+
if (!result.parsed) {
|
|
1942
|
+
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
1943
|
+
err.code = "MISSING_DATA";
|
|
1944
|
+
throw err;
|
|
1945
|
+
}
|
|
1946
|
+
const keys = _dotenvKey(options).split(",");
|
|
1947
|
+
const length = keys.length;
|
|
1948
|
+
let decrypted;
|
|
1949
|
+
for (let i = 0;i < length; i++) {
|
|
1950
|
+
try {
|
|
1951
|
+
const key = keys[i].trim();
|
|
1952
|
+
const attrs = _instructions(result, key);
|
|
1953
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
1954
|
+
break;
|
|
1955
|
+
} catch (error) {
|
|
1956
|
+
if (i + 1 >= length) {
|
|
1957
|
+
throw error;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
return DotenvModule.parse(decrypted);
|
|
1962
|
+
};
|
|
1963
|
+
var _log = function(message) {
|
|
1964
|
+
console.log(`[dotenv@${version}][INFO] ${message}`);
|
|
1965
|
+
};
|
|
1966
|
+
var _warn = function(message) {
|
|
1967
|
+
console.log(`[dotenv@${version}][WARN] ${message}`);
|
|
1968
|
+
};
|
|
1969
|
+
var _debug = function(message) {
|
|
1970
|
+
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
1971
|
+
};
|
|
1972
|
+
var _dotenvKey = function(options) {
|
|
1973
|
+
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
|
|
1974
|
+
return options.DOTENV_KEY;
|
|
1975
|
+
}
|
|
1976
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
1977
|
+
return process.env.DOTENV_KEY;
|
|
1978
|
+
}
|
|
1979
|
+
return "";
|
|
1980
|
+
};
|
|
1981
|
+
var _instructions = function(result, dotenvKey) {
|
|
1982
|
+
let uri;
|
|
1983
|
+
try {
|
|
1984
|
+
uri = new URL(dotenvKey);
|
|
1985
|
+
} catch (error) {
|
|
1986
|
+
if (error.code === "ERR_INVALID_URL") {
|
|
1987
|
+
const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
|
|
1988
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
1989
|
+
throw err;
|
|
1990
|
+
}
|
|
1991
|
+
throw error;
|
|
1992
|
+
}
|
|
1993
|
+
const key = uri.password;
|
|
1994
|
+
if (!key) {
|
|
1995
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
1996
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
1997
|
+
throw err;
|
|
1998
|
+
}
|
|
1999
|
+
const environment = uri.searchParams.get("environment");
|
|
2000
|
+
if (!environment) {
|
|
2001
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
2002
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
2003
|
+
throw err;
|
|
2004
|
+
}
|
|
2005
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
2006
|
+
const ciphertext = result.parsed[environmentKey];
|
|
2007
|
+
if (!ciphertext) {
|
|
2008
|
+
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
2009
|
+
err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
|
|
2010
|
+
throw err;
|
|
2011
|
+
}
|
|
2012
|
+
return { ciphertext, key };
|
|
2013
|
+
};
|
|
2014
|
+
var _vaultPath = function(options) {
|
|
2015
|
+
let possibleVaultPath = null;
|
|
2016
|
+
if (options && options.path && options.path.length > 0) {
|
|
2017
|
+
if (Array.isArray(options.path)) {
|
|
2018
|
+
for (const filepath of options.path) {
|
|
2019
|
+
if (fs.existsSync(filepath)) {
|
|
2020
|
+
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
} else {
|
|
2024
|
+
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
2025
|
+
}
|
|
2026
|
+
} else {
|
|
2027
|
+
possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
|
|
2028
|
+
}
|
|
2029
|
+
if (fs.existsSync(possibleVaultPath)) {
|
|
2030
|
+
return possibleVaultPath;
|
|
2031
|
+
}
|
|
2032
|
+
return null;
|
|
2033
|
+
};
|
|
2034
|
+
var _resolveHome = function(envPath) {
|
|
2035
|
+
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
2036
|
+
};
|
|
2037
|
+
var _configVault = function(options) {
|
|
2038
|
+
_log("Loading env from encrypted .env.vault");
|
|
2039
|
+
const parsed = DotenvModule._parseVault(options);
|
|
2040
|
+
let processEnv = process.env;
|
|
2041
|
+
if (options && options.processEnv != null) {
|
|
2042
|
+
processEnv = options.processEnv;
|
|
2043
|
+
}
|
|
2044
|
+
DotenvModule.populate(processEnv, parsed, options);
|
|
2045
|
+
return { parsed };
|
|
2046
|
+
};
|
|
2047
|
+
var configDotenv = function(options) {
|
|
2048
|
+
const dotenvPath = path.resolve(process.cwd(), ".env");
|
|
2049
|
+
let encoding = "utf8";
|
|
2050
|
+
const debug = Boolean(options && options.debug);
|
|
2051
|
+
if (options && options.encoding) {
|
|
2052
|
+
encoding = options.encoding;
|
|
2053
|
+
} else {
|
|
2054
|
+
if (debug) {
|
|
2055
|
+
_debug("No encoding is specified. UTF-8 is used by default");
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
let optionPaths = [dotenvPath];
|
|
2059
|
+
if (options && options.path) {
|
|
2060
|
+
if (!Array.isArray(options.path)) {
|
|
2061
|
+
optionPaths = [_resolveHome(options.path)];
|
|
2062
|
+
} else {
|
|
2063
|
+
optionPaths = [];
|
|
2064
|
+
for (const filepath of options.path) {
|
|
2065
|
+
optionPaths.push(_resolveHome(filepath));
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
let lastError;
|
|
2070
|
+
const parsedAll = {};
|
|
2071
|
+
for (const path2 of optionPaths) {
|
|
2072
|
+
try {
|
|
2073
|
+
const parsed = DotenvModule.parse(fs.readFileSync(path2, { encoding }));
|
|
2074
|
+
DotenvModule.populate(parsedAll, parsed, options);
|
|
2075
|
+
} catch (e) {
|
|
2076
|
+
if (debug) {
|
|
2077
|
+
_debug(`Failed to load ${path2} ${e.message}`);
|
|
2078
|
+
}
|
|
2079
|
+
lastError = e;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
let processEnv = process.env;
|
|
2083
|
+
if (options && options.processEnv != null) {
|
|
2084
|
+
processEnv = options.processEnv;
|
|
2085
|
+
}
|
|
2086
|
+
DotenvModule.populate(processEnv, parsedAll, options);
|
|
2087
|
+
if (lastError) {
|
|
2088
|
+
return { parsed: parsedAll, error: lastError };
|
|
2089
|
+
} else {
|
|
2090
|
+
return { parsed: parsedAll };
|
|
2091
|
+
}
|
|
2092
|
+
};
|
|
2093
|
+
var config = function(options) {
|
|
2094
|
+
if (_dotenvKey(options).length === 0) {
|
|
2095
|
+
return DotenvModule.configDotenv(options);
|
|
2096
|
+
}
|
|
2097
|
+
const vaultPath = _vaultPath(options);
|
|
2098
|
+
if (!vaultPath) {
|
|
2099
|
+
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
2100
|
+
return DotenvModule.configDotenv(options);
|
|
2101
|
+
}
|
|
2102
|
+
return DotenvModule._configVault(options);
|
|
2103
|
+
};
|
|
2104
|
+
var decrypt = function(encrypted, keyStr) {
|
|
2105
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
|
2106
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
|
2107
|
+
const nonce = ciphertext.subarray(0, 12);
|
|
2108
|
+
const authTag = ciphertext.subarray(-16);
|
|
2109
|
+
ciphertext = ciphertext.subarray(12, -16);
|
|
2110
|
+
try {
|
|
2111
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
|
2112
|
+
aesgcm.setAuthTag(authTag);
|
|
2113
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
2114
|
+
} catch (error) {
|
|
2115
|
+
const isRange = error instanceof RangeError;
|
|
2116
|
+
const invalidKeyLength = error.message === "Invalid key length";
|
|
2117
|
+
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
|
2118
|
+
if (isRange || invalidKeyLength) {
|
|
2119
|
+
const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
|
|
2120
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
2121
|
+
throw err;
|
|
2122
|
+
} else if (decryptionFailed) {
|
|
2123
|
+
const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
|
|
2124
|
+
err.code = "DECRYPTION_FAILED";
|
|
2125
|
+
throw err;
|
|
2126
|
+
} else {
|
|
2127
|
+
throw error;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
};
|
|
2131
|
+
var populate = function(processEnv, parsed, options = {}) {
|
|
2132
|
+
const debug = Boolean(options && options.debug);
|
|
2133
|
+
const override = Boolean(options && options.override);
|
|
2134
|
+
if (typeof parsed !== "object") {
|
|
2135
|
+
const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
2136
|
+
err.code = "OBJECT_REQUIRED";
|
|
2137
|
+
throw err;
|
|
2138
|
+
}
|
|
2139
|
+
for (const key of Object.keys(parsed)) {
|
|
2140
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
2141
|
+
if (override === true) {
|
|
2142
|
+
processEnv[key] = parsed[key];
|
|
2143
|
+
}
|
|
2144
|
+
if (debug) {
|
|
2145
|
+
if (override === true) {
|
|
2146
|
+
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
2147
|
+
} else {
|
|
2148
|
+
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
} else {
|
|
2152
|
+
processEnv[key] = parsed[key];
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
var fs = __require("fs");
|
|
2157
|
+
var path = __require("path");
|
|
2158
|
+
var os = __require("os");
|
|
2159
|
+
var crypto = __require("crypto");
|
|
2160
|
+
var packageJson = require_package();
|
|
2161
|
+
var version = packageJson.version;
|
|
2162
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
2163
|
+
var DotenvModule = {
|
|
2164
|
+
configDotenv,
|
|
2165
|
+
_configVault,
|
|
2166
|
+
_parseVault,
|
|
2167
|
+
config,
|
|
2168
|
+
decrypt,
|
|
2169
|
+
parse,
|
|
2170
|
+
populate
|
|
2171
|
+
};
|
|
2172
|
+
exports.configDotenv = DotenvModule.configDotenv;
|
|
2173
|
+
exports._configVault = DotenvModule._configVault;
|
|
2174
|
+
exports._parseVault = DotenvModule._parseVault;
|
|
2175
|
+
exports.config = DotenvModule.config;
|
|
2176
|
+
exports.decrypt = DotenvModule.decrypt;
|
|
2177
|
+
exports.parse = DotenvModule.parse;
|
|
2178
|
+
exports.populate = DotenvModule.populate;
|
|
2179
|
+
module.exports = DotenvModule;
|
|
2180
|
+
});
|
|
2181
|
+
|
|
2182
|
+
// ../../node_modules/semver/semver.js
|
|
2183
|
+
var require_semver = __commonJS((exports, module) => {
|
|
2184
|
+
var tok = function(n) {
|
|
2185
|
+
t[n] = R++;
|
|
2186
|
+
};
|
|
2187
|
+
var makeSafeRe = function(value) {
|
|
2188
|
+
for (var i2 = 0;i2 < safeRegexReplacements.length; i2++) {
|
|
2189
|
+
var token = safeRegexReplacements[i2][0];
|
|
2190
|
+
var max = safeRegexReplacements[i2][1];
|
|
2191
|
+
value = value.split(token + "*").join(token + "{0," + max + "}").split(token + "+").join(token + "{1," + max + "}");
|
|
2192
|
+
}
|
|
2193
|
+
return value;
|
|
2194
|
+
};
|
|
2195
|
+
var parse = function(version, options) {
|
|
2196
|
+
if (!options || typeof options !== "object") {
|
|
2197
|
+
options = {
|
|
2198
|
+
loose: !!options,
|
|
2199
|
+
includePrerelease: false
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
if (version instanceof SemVer) {
|
|
2203
|
+
return version;
|
|
2204
|
+
}
|
|
2205
|
+
if (typeof version !== "string") {
|
|
2206
|
+
return null;
|
|
2207
|
+
}
|
|
2208
|
+
if (version.length > MAX_LENGTH) {
|
|
2209
|
+
return null;
|
|
2210
|
+
}
|
|
2211
|
+
var r = options.loose ? safeRe[t.LOOSE] : safeRe[t.FULL];
|
|
2212
|
+
if (!r.test(version)) {
|
|
2213
|
+
return null;
|
|
2214
|
+
}
|
|
2215
|
+
try {
|
|
2216
|
+
return new SemVer(version, options);
|
|
2217
|
+
} catch (er) {
|
|
2218
|
+
return null;
|
|
2219
|
+
}
|
|
2220
|
+
};
|
|
2221
|
+
var valid = function(version, options) {
|
|
2222
|
+
var v = parse(version, options);
|
|
2223
|
+
return v ? v.version : null;
|
|
2224
|
+
};
|
|
2225
|
+
var clean = function(version, options) {
|
|
2226
|
+
var s = parse(version.trim().replace(/^[=v]+/, ""), options);
|
|
2227
|
+
return s ? s.version : null;
|
|
2228
|
+
};
|
|
2229
|
+
var SemVer = function(version, options) {
|
|
2230
|
+
if (!options || typeof options !== "object") {
|
|
2231
|
+
options = {
|
|
2232
|
+
loose: !!options,
|
|
2233
|
+
includePrerelease: false
|
|
2234
|
+
};
|
|
2235
|
+
}
|
|
2236
|
+
if (version instanceof SemVer) {
|
|
2237
|
+
if (version.loose === options.loose) {
|
|
2238
|
+
return version;
|
|
2239
|
+
} else {
|
|
2240
|
+
version = version.version;
|
|
2241
|
+
}
|
|
2242
|
+
} else if (typeof version !== "string") {
|
|
2243
|
+
throw new TypeError("Invalid Version: " + version);
|
|
2244
|
+
}
|
|
2245
|
+
if (version.length > MAX_LENGTH) {
|
|
2246
|
+
throw new TypeError("version is longer than " + MAX_LENGTH + " characters");
|
|
2247
|
+
}
|
|
2248
|
+
if (!(this instanceof SemVer)) {
|
|
2249
|
+
return new SemVer(version, options);
|
|
2250
|
+
}
|
|
2251
|
+
debug("SemVer", version, options);
|
|
2252
|
+
this.options = options;
|
|
2253
|
+
this.loose = !!options.loose;
|
|
2254
|
+
var m = version.trim().match(options.loose ? safeRe[t.LOOSE] : safeRe[t.FULL]);
|
|
2255
|
+
if (!m) {
|
|
2256
|
+
throw new TypeError("Invalid Version: " + version);
|
|
2257
|
+
}
|
|
2258
|
+
this.raw = version;
|
|
2259
|
+
this.major = +m[1];
|
|
2260
|
+
this.minor = +m[2];
|
|
2261
|
+
this.patch = +m[3];
|
|
2262
|
+
if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
|
|
2263
|
+
throw new TypeError("Invalid major version");
|
|
2264
|
+
}
|
|
2265
|
+
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
|
|
2266
|
+
throw new TypeError("Invalid minor version");
|
|
2267
|
+
}
|
|
2268
|
+
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
|
|
2269
|
+
throw new TypeError("Invalid patch version");
|
|
2270
|
+
}
|
|
2271
|
+
if (!m[4]) {
|
|
2272
|
+
this.prerelease = [];
|
|
2273
|
+
} else {
|
|
2274
|
+
this.prerelease = m[4].split(".").map(function(id) {
|
|
2275
|
+
if (/^[0-9]+$/.test(id)) {
|
|
2276
|
+
var num = +id;
|
|
2277
|
+
if (num >= 0 && num < MAX_SAFE_INTEGER) {
|
|
2278
|
+
return num;
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
return id;
|
|
2282
|
+
});
|
|
2283
|
+
}
|
|
2284
|
+
this.build = m[5] ? m[5].split(".") : [];
|
|
2285
|
+
this.format();
|
|
2286
|
+
};
|
|
2287
|
+
var inc = function(version, release, loose, identifier) {
|
|
2288
|
+
if (typeof loose === "string") {
|
|
2289
|
+
identifier = loose;
|
|
2290
|
+
loose = undefined;
|
|
2291
|
+
}
|
|
2292
|
+
try {
|
|
2293
|
+
return new SemVer(version, loose).inc(release, identifier).version;
|
|
2294
|
+
} catch (er) {
|
|
2295
|
+
return null;
|
|
2296
|
+
}
|
|
2297
|
+
};
|
|
2298
|
+
var diff = function(version1, version2) {
|
|
2299
|
+
if (eq(version1, version2)) {
|
|
2300
|
+
return null;
|
|
2301
|
+
} else {
|
|
2302
|
+
var v1 = parse(version1);
|
|
2303
|
+
var v2 = parse(version2);
|
|
2304
|
+
var prefix = "";
|
|
2305
|
+
if (v1.prerelease.length || v2.prerelease.length) {
|
|
2306
|
+
prefix = "pre";
|
|
2307
|
+
var defaultResult = "prerelease";
|
|
2308
|
+
}
|
|
2309
|
+
for (var key in v1) {
|
|
2310
|
+
if (key === "major" || key === "minor" || key === "patch") {
|
|
2311
|
+
if (v1[key] !== v2[key]) {
|
|
2312
|
+
return prefix + key;
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
return defaultResult;
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2319
|
+
var compareIdentifiers = function(a, b) {
|
|
2320
|
+
var anum = numeric.test(a);
|
|
2321
|
+
var bnum = numeric.test(b);
|
|
2322
|
+
if (anum && bnum) {
|
|
2323
|
+
a = +a;
|
|
2324
|
+
b = +b;
|
|
2325
|
+
}
|
|
2326
|
+
return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
|
|
2327
|
+
};
|
|
2328
|
+
var rcompareIdentifiers = function(a, b) {
|
|
2329
|
+
return compareIdentifiers(b, a);
|
|
2330
|
+
};
|
|
2331
|
+
var major = function(a, loose) {
|
|
2332
|
+
return new SemVer(a, loose).major;
|
|
2333
|
+
};
|
|
2334
|
+
var minor = function(a, loose) {
|
|
2335
|
+
return new SemVer(a, loose).minor;
|
|
2336
|
+
};
|
|
2337
|
+
var patch = function(a, loose) {
|
|
2338
|
+
return new SemVer(a, loose).patch;
|
|
2339
|
+
};
|
|
2340
|
+
var compare = function(a, b, loose) {
|
|
2341
|
+
return new SemVer(a, loose).compare(new SemVer(b, loose));
|
|
2342
|
+
};
|
|
2343
|
+
var compareLoose = function(a, b) {
|
|
2344
|
+
return compare(a, b, true);
|
|
2345
|
+
};
|
|
2346
|
+
var compareBuild = function(a, b, loose) {
|
|
2347
|
+
var versionA = new SemVer(a, loose);
|
|
2348
|
+
var versionB = new SemVer(b, loose);
|
|
2349
|
+
return versionA.compare(versionB) || versionA.compareBuild(versionB);
|
|
2350
|
+
};
|
|
2351
|
+
var rcompare = function(a, b, loose) {
|
|
2352
|
+
return compare(b, a, loose);
|
|
2353
|
+
};
|
|
2354
|
+
var sort = function(list, loose) {
|
|
2355
|
+
return list.sort(function(a, b) {
|
|
2356
|
+
return exports.compareBuild(a, b, loose);
|
|
2357
|
+
});
|
|
2358
|
+
};
|
|
2359
|
+
var rsort = function(list, loose) {
|
|
2360
|
+
return list.sort(function(a, b) {
|
|
2361
|
+
return exports.compareBuild(b, a, loose);
|
|
2362
|
+
});
|
|
2363
|
+
};
|
|
2364
|
+
var gt = function(a, b, loose) {
|
|
2365
|
+
return compare(a, b, loose) > 0;
|
|
2366
|
+
};
|
|
2367
|
+
var lt = function(a, b, loose) {
|
|
2368
|
+
return compare(a, b, loose) < 0;
|
|
2369
|
+
};
|
|
2370
|
+
var eq = function(a, b, loose) {
|
|
2371
|
+
return compare(a, b, loose) === 0;
|
|
2372
|
+
};
|
|
2373
|
+
var neq = function(a, b, loose) {
|
|
2374
|
+
return compare(a, b, loose) !== 0;
|
|
2375
|
+
};
|
|
2376
|
+
var gte = function(a, b, loose) {
|
|
2377
|
+
return compare(a, b, loose) >= 0;
|
|
2378
|
+
};
|
|
2379
|
+
var lte = function(a, b, loose) {
|
|
2380
|
+
return compare(a, b, loose) <= 0;
|
|
2381
|
+
};
|
|
2382
|
+
var cmp = function(a, op, b, loose) {
|
|
2383
|
+
switch (op) {
|
|
2384
|
+
case "===":
|
|
2385
|
+
if (typeof a === "object")
|
|
2386
|
+
a = a.version;
|
|
2387
|
+
if (typeof b === "object")
|
|
2388
|
+
b = b.version;
|
|
2389
|
+
return a === b;
|
|
2390
|
+
case "!==":
|
|
2391
|
+
if (typeof a === "object")
|
|
2392
|
+
a = a.version;
|
|
2393
|
+
if (typeof b === "object")
|
|
2394
|
+
b = b.version;
|
|
2395
|
+
return a !== b;
|
|
2396
|
+
case "":
|
|
2397
|
+
case "=":
|
|
2398
|
+
case "==":
|
|
2399
|
+
return eq(a, b, loose);
|
|
2400
|
+
case "!=":
|
|
2401
|
+
return neq(a, b, loose);
|
|
2402
|
+
case ">":
|
|
2403
|
+
return gt(a, b, loose);
|
|
2404
|
+
case ">=":
|
|
2405
|
+
return gte(a, b, loose);
|
|
2406
|
+
case "<":
|
|
2407
|
+
return lt(a, b, loose);
|
|
2408
|
+
case "<=":
|
|
2409
|
+
return lte(a, b, loose);
|
|
2410
|
+
default:
|
|
2411
|
+
throw new TypeError("Invalid operator: " + op);
|
|
2412
|
+
}
|
|
2413
|
+
};
|
|
2414
|
+
var Comparator = function(comp, options) {
|
|
2415
|
+
if (!options || typeof options !== "object") {
|
|
2416
|
+
options = {
|
|
2417
|
+
loose: !!options,
|
|
2418
|
+
includePrerelease: false
|
|
2419
|
+
};
|
|
2420
|
+
}
|
|
2421
|
+
if (comp instanceof Comparator) {
|
|
2422
|
+
if (comp.loose === !!options.loose) {
|
|
2423
|
+
return comp;
|
|
2424
|
+
} else {
|
|
2425
|
+
comp = comp.value;
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
if (!(this instanceof Comparator)) {
|
|
2429
|
+
return new Comparator(comp, options);
|
|
2430
|
+
}
|
|
2431
|
+
comp = comp.trim().split(/\s+/).join(" ");
|
|
2432
|
+
debug("comparator", comp, options);
|
|
2433
|
+
this.options = options;
|
|
2434
|
+
this.loose = !!options.loose;
|
|
2435
|
+
this.parse(comp);
|
|
2436
|
+
if (this.semver === ANY) {
|
|
2437
|
+
this.value = "";
|
|
2438
|
+
} else {
|
|
2439
|
+
this.value = this.operator + this.semver.version;
|
|
2440
|
+
}
|
|
2441
|
+
debug("comp", this);
|
|
2442
|
+
};
|
|
2443
|
+
var Range = function(range, options) {
|
|
2444
|
+
if (!options || typeof options !== "object") {
|
|
2445
|
+
options = {
|
|
2446
|
+
loose: !!options,
|
|
2447
|
+
includePrerelease: false
|
|
2448
|
+
};
|
|
2449
|
+
}
|
|
2450
|
+
if (range instanceof Range) {
|
|
2451
|
+
if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
|
|
2452
|
+
return range;
|
|
2453
|
+
} else {
|
|
2454
|
+
return new Range(range.raw, options);
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
if (range instanceof Comparator) {
|
|
2458
|
+
return new Range(range.value, options);
|
|
2459
|
+
}
|
|
2460
|
+
if (!(this instanceof Range)) {
|
|
2461
|
+
return new Range(range, options);
|
|
2462
|
+
}
|
|
2463
|
+
this.options = options;
|
|
2464
|
+
this.loose = !!options.loose;
|
|
2465
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
2466
|
+
this.raw = range.trim().split(/\s+/).join(" ");
|
|
2467
|
+
this.set = this.raw.split("||").map(function(range2) {
|
|
2468
|
+
return this.parseRange(range2.trim());
|
|
2469
|
+
}, this).filter(function(c) {
|
|
2470
|
+
return c.length;
|
|
2471
|
+
});
|
|
2472
|
+
if (!this.set.length) {
|
|
2473
|
+
throw new TypeError("Invalid SemVer Range: " + this.raw);
|
|
2474
|
+
}
|
|
2475
|
+
this.format();
|
|
2476
|
+
};
|
|
2477
|
+
var isSatisfiable = function(comparators, options) {
|
|
2478
|
+
var result = true;
|
|
2479
|
+
var remainingComparators = comparators.slice();
|
|
2480
|
+
var testComparator = remainingComparators.pop();
|
|
2481
|
+
while (result && remainingComparators.length) {
|
|
2482
|
+
result = remainingComparators.every(function(otherComparator) {
|
|
2483
|
+
return testComparator.intersects(otherComparator, options);
|
|
2484
|
+
});
|
|
2485
|
+
testComparator = remainingComparators.pop();
|
|
2486
|
+
}
|
|
2487
|
+
return result;
|
|
2488
|
+
};
|
|
2489
|
+
var toComparators = function(range, options) {
|
|
2490
|
+
return new Range(range, options).set.map(function(comp) {
|
|
2491
|
+
return comp.map(function(c) {
|
|
2492
|
+
return c.value;
|
|
2493
|
+
}).join(" ").trim().split(" ");
|
|
2494
|
+
});
|
|
2495
|
+
};
|
|
2496
|
+
var parseComparator = function(comp, options) {
|
|
2497
|
+
debug("comp", comp, options);
|
|
2498
|
+
comp = replaceCarets(comp, options);
|
|
2499
|
+
debug("caret", comp);
|
|
2500
|
+
comp = replaceTildes(comp, options);
|
|
2501
|
+
debug("tildes", comp);
|
|
2502
|
+
comp = replaceXRanges(comp, options);
|
|
2503
|
+
debug("xrange", comp);
|
|
2504
|
+
comp = replaceStars(comp, options);
|
|
2505
|
+
debug("stars", comp);
|
|
2506
|
+
return comp;
|
|
2507
|
+
};
|
|
2508
|
+
var isX = function(id) {
|
|
2509
|
+
return !id || id.toLowerCase() === "x" || id === "*";
|
|
2510
|
+
};
|
|
2511
|
+
var replaceTildes = function(comp, options) {
|
|
2512
|
+
return comp.trim().split(/\s+/).map(function(comp2) {
|
|
2513
|
+
return replaceTilde(comp2, options);
|
|
2514
|
+
}).join(" ");
|
|
2515
|
+
};
|
|
2516
|
+
var replaceTilde = function(comp, options) {
|
|
2517
|
+
var r = options.loose ? safeRe[t.TILDELOOSE] : safeRe[t.TILDE];
|
|
2518
|
+
return comp.replace(r, function(_, M, m, p, pr) {
|
|
2519
|
+
debug("tilde", comp, _, M, m, p, pr);
|
|
2520
|
+
var ret;
|
|
2521
|
+
if (isX(M)) {
|
|
2522
|
+
ret = "";
|
|
2523
|
+
} else if (isX(m)) {
|
|
2524
|
+
ret = ">=" + M + ".0.0 <" + (+M + 1) + ".0.0";
|
|
2525
|
+
} else if (isX(p)) {
|
|
2526
|
+
ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
|
|
2527
|
+
} else if (pr) {
|
|
2528
|
+
debug("replaceTilde pr", pr);
|
|
2529
|
+
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + (+m + 1) + ".0";
|
|
2530
|
+
} else {
|
|
2531
|
+
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + (+m + 1) + ".0";
|
|
2532
|
+
}
|
|
2533
|
+
debug("tilde return", ret);
|
|
2534
|
+
return ret;
|
|
2535
|
+
});
|
|
2536
|
+
};
|
|
2537
|
+
var replaceCarets = function(comp, options) {
|
|
2538
|
+
return comp.trim().split(/\s+/).map(function(comp2) {
|
|
2539
|
+
return replaceCaret(comp2, options);
|
|
2540
|
+
}).join(" ");
|
|
2541
|
+
};
|
|
2542
|
+
var replaceCaret = function(comp, options) {
|
|
2543
|
+
debug("caret", comp, options);
|
|
2544
|
+
var r = options.loose ? safeRe[t.CARETLOOSE] : safeRe[t.CARET];
|
|
2545
|
+
return comp.replace(r, function(_, M, m, p, pr) {
|
|
2546
|
+
debug("caret", comp, _, M, m, p, pr);
|
|
2547
|
+
var ret;
|
|
2548
|
+
if (isX(M)) {
|
|
2549
|
+
ret = "";
|
|
2550
|
+
} else if (isX(m)) {
|
|
2551
|
+
ret = ">=" + M + ".0.0 <" + (+M + 1) + ".0.0";
|
|
2552
|
+
} else if (isX(p)) {
|
|
2553
|
+
if (M === "0") {
|
|
2554
|
+
ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
|
|
2555
|
+
} else {
|
|
2556
|
+
ret = ">=" + M + "." + m + ".0 <" + (+M + 1) + ".0.0";
|
|
2557
|
+
}
|
|
2558
|
+
} else if (pr) {
|
|
2559
|
+
debug("replaceCaret pr", pr);
|
|
2560
|
+
if (M === "0") {
|
|
2561
|
+
if (m === "0") {
|
|
2562
|
+
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + m + "." + (+p + 1);
|
|
2563
|
+
} else {
|
|
2564
|
+
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + (+m + 1) + ".0";
|
|
2565
|
+
}
|
|
2566
|
+
} else {
|
|
2567
|
+
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + (+M + 1) + ".0.0";
|
|
2568
|
+
}
|
|
2569
|
+
} else {
|
|
2570
|
+
debug("no pr");
|
|
2571
|
+
if (M === "0") {
|
|
2572
|
+
if (m === "0") {
|
|
2573
|
+
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + m + "." + (+p + 1);
|
|
2574
|
+
} else {
|
|
2575
|
+
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + (+m + 1) + ".0";
|
|
2576
|
+
}
|
|
2577
|
+
} else {
|
|
2578
|
+
ret = ">=" + M + "." + m + "." + p + " <" + (+M + 1) + ".0.0";
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
debug("caret return", ret);
|
|
2582
|
+
return ret;
|
|
2583
|
+
});
|
|
2584
|
+
};
|
|
2585
|
+
var replaceXRanges = function(comp, options) {
|
|
2586
|
+
debug("replaceXRanges", comp, options);
|
|
2587
|
+
return comp.split(/\s+/).map(function(comp2) {
|
|
2588
|
+
return replaceXRange(comp2, options);
|
|
2589
|
+
}).join(" ");
|
|
2590
|
+
};
|
|
2591
|
+
var replaceXRange = function(comp, options) {
|
|
2592
|
+
comp = comp.trim();
|
|
2593
|
+
var r = options.loose ? safeRe[t.XRANGELOOSE] : safeRe[t.XRANGE];
|
|
2594
|
+
return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
|
|
2595
|
+
debug("xRange", comp, ret, gtlt, M, m, p, pr);
|
|
2596
|
+
var xM = isX(M);
|
|
2597
|
+
var xm = xM || isX(m);
|
|
2598
|
+
var xp = xm || isX(p);
|
|
2599
|
+
var anyX = xp;
|
|
2600
|
+
if (gtlt === "=" && anyX) {
|
|
2601
|
+
gtlt = "";
|
|
2602
|
+
}
|
|
2603
|
+
pr = options.includePrerelease ? "-0" : "";
|
|
2604
|
+
if (xM) {
|
|
2605
|
+
if (gtlt === ">" || gtlt === "<") {
|
|
2606
|
+
ret = "<0.0.0-0";
|
|
2607
|
+
} else {
|
|
2608
|
+
ret = "*";
|
|
2609
|
+
}
|
|
2610
|
+
} else if (gtlt && anyX) {
|
|
2611
|
+
if (xm) {
|
|
2612
|
+
m = 0;
|
|
2613
|
+
}
|
|
2614
|
+
p = 0;
|
|
2615
|
+
if (gtlt === ">") {
|
|
2616
|
+
gtlt = ">=";
|
|
2617
|
+
if (xm) {
|
|
2618
|
+
M = +M + 1;
|
|
2619
|
+
m = 0;
|
|
2620
|
+
p = 0;
|
|
2621
|
+
} else {
|
|
2622
|
+
m = +m + 1;
|
|
2623
|
+
p = 0;
|
|
2624
|
+
}
|
|
2625
|
+
} else if (gtlt === "<=") {
|
|
2626
|
+
gtlt = "<";
|
|
2627
|
+
if (xm) {
|
|
2628
|
+
M = +M + 1;
|
|
2629
|
+
} else {
|
|
2630
|
+
m = +m + 1;
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
ret = gtlt + M + "." + m + "." + p + pr;
|
|
2634
|
+
} else if (xm) {
|
|
2635
|
+
ret = ">=" + M + ".0.0" + pr + " <" + (+M + 1) + ".0.0" + pr;
|
|
2636
|
+
} else if (xp) {
|
|
2637
|
+
ret = ">=" + M + "." + m + ".0" + pr + " <" + M + "." + (+m + 1) + ".0" + pr;
|
|
2638
|
+
}
|
|
2639
|
+
debug("xRange return", ret);
|
|
2640
|
+
return ret;
|
|
2641
|
+
});
|
|
2642
|
+
};
|
|
2643
|
+
var replaceStars = function(comp, options) {
|
|
2644
|
+
debug("replaceStars", comp, options);
|
|
2645
|
+
return comp.trim().replace(safeRe[t.STAR], "");
|
|
2646
|
+
};
|
|
2647
|
+
var hyphenReplace = function($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
|
|
2648
|
+
if (isX(fM)) {
|
|
2649
|
+
from = "";
|
|
2650
|
+
} else if (isX(fm)) {
|
|
2651
|
+
from = ">=" + fM + ".0.0";
|
|
2652
|
+
} else if (isX(fp)) {
|
|
2653
|
+
from = ">=" + fM + "." + fm + ".0";
|
|
2654
|
+
} else {
|
|
2655
|
+
from = ">=" + from;
|
|
2656
|
+
}
|
|
2657
|
+
if (isX(tM)) {
|
|
2658
|
+
to = "";
|
|
2659
|
+
} else if (isX(tm)) {
|
|
2660
|
+
to = "<" + (+tM + 1) + ".0.0";
|
|
2661
|
+
} else if (isX(tp)) {
|
|
2662
|
+
to = "<" + tM + "." + (+tm + 1) + ".0";
|
|
2663
|
+
} else if (tpr) {
|
|
2664
|
+
to = "<=" + tM + "." + tm + "." + tp + "-" + tpr;
|
|
2665
|
+
} else {
|
|
2666
|
+
to = "<=" + to;
|
|
2667
|
+
}
|
|
2668
|
+
return (from + " " + to).trim();
|
|
2669
|
+
};
|
|
2670
|
+
var testSet = function(set, version, options) {
|
|
2671
|
+
for (var i2 = 0;i2 < set.length; i2++) {
|
|
2672
|
+
if (!set[i2].test(version)) {
|
|
2673
|
+
return false;
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
if (version.prerelease.length && !options.includePrerelease) {
|
|
2677
|
+
for (i2 = 0;i2 < set.length; i2++) {
|
|
2678
|
+
debug(set[i2].semver);
|
|
2679
|
+
if (set[i2].semver === ANY) {
|
|
2680
|
+
continue;
|
|
2681
|
+
}
|
|
2682
|
+
if (set[i2].semver.prerelease.length > 0) {
|
|
2683
|
+
var allowed = set[i2].semver;
|
|
2684
|
+
if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) {
|
|
2685
|
+
return true;
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
return false;
|
|
2690
|
+
}
|
|
2691
|
+
return true;
|
|
2692
|
+
};
|
|
2693
|
+
var satisfies = function(version, range, options) {
|
|
2694
|
+
try {
|
|
2695
|
+
range = new Range(range, options);
|
|
2696
|
+
} catch (er) {
|
|
2697
|
+
return false;
|
|
2698
|
+
}
|
|
2699
|
+
return range.test(version);
|
|
2700
|
+
};
|
|
2701
|
+
var maxSatisfying = function(versions, range, options) {
|
|
2702
|
+
var max = null;
|
|
2703
|
+
var maxSV = null;
|
|
2704
|
+
try {
|
|
2705
|
+
var rangeObj = new Range(range, options);
|
|
2706
|
+
} catch (er) {
|
|
2707
|
+
return null;
|
|
2708
|
+
}
|
|
2709
|
+
versions.forEach(function(v) {
|
|
2710
|
+
if (rangeObj.test(v)) {
|
|
2711
|
+
if (!max || maxSV.compare(v) === -1) {
|
|
2712
|
+
max = v;
|
|
2713
|
+
maxSV = new SemVer(max, options);
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
});
|
|
2717
|
+
return max;
|
|
2718
|
+
};
|
|
2719
|
+
var minSatisfying = function(versions, range, options) {
|
|
2720
|
+
var min = null;
|
|
2721
|
+
var minSV = null;
|
|
2722
|
+
try {
|
|
2723
|
+
var rangeObj = new Range(range, options);
|
|
2724
|
+
} catch (er) {
|
|
2725
|
+
return null;
|
|
2726
|
+
}
|
|
2727
|
+
versions.forEach(function(v) {
|
|
2728
|
+
if (rangeObj.test(v)) {
|
|
2729
|
+
if (!min || minSV.compare(v) === 1) {
|
|
2730
|
+
min = v;
|
|
2731
|
+
minSV = new SemVer(min, options);
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
});
|
|
2735
|
+
return min;
|
|
2736
|
+
};
|
|
2737
|
+
var minVersion = function(range, loose) {
|
|
2738
|
+
range = new Range(range, loose);
|
|
2739
|
+
var minver = new SemVer("0.0.0");
|
|
2740
|
+
if (range.test(minver)) {
|
|
2741
|
+
return minver;
|
|
2742
|
+
}
|
|
2743
|
+
minver = new SemVer("0.0.0-0");
|
|
2744
|
+
if (range.test(minver)) {
|
|
2745
|
+
return minver;
|
|
2746
|
+
}
|
|
2747
|
+
minver = null;
|
|
2748
|
+
for (var i2 = 0;i2 < range.set.length; ++i2) {
|
|
2749
|
+
var comparators = range.set[i2];
|
|
2750
|
+
comparators.forEach(function(comparator) {
|
|
2751
|
+
var compver = new SemVer(comparator.semver.version);
|
|
2752
|
+
switch (comparator.operator) {
|
|
2753
|
+
case ">":
|
|
2754
|
+
if (compver.prerelease.length === 0) {
|
|
2755
|
+
compver.patch++;
|
|
2756
|
+
} else {
|
|
2757
|
+
compver.prerelease.push(0);
|
|
2758
|
+
}
|
|
2759
|
+
compver.raw = compver.format();
|
|
2760
|
+
case "":
|
|
2761
|
+
case ">=":
|
|
2762
|
+
if (!minver || gt(minver, compver)) {
|
|
2763
|
+
minver = compver;
|
|
2764
|
+
}
|
|
2765
|
+
break;
|
|
2766
|
+
case "<":
|
|
2767
|
+
case "<=":
|
|
2768
|
+
break;
|
|
2769
|
+
default:
|
|
2770
|
+
throw new Error("Unexpected operation: " + comparator.operator);
|
|
2771
|
+
}
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2774
|
+
if (minver && range.test(minver)) {
|
|
2775
|
+
return minver;
|
|
2776
|
+
}
|
|
2777
|
+
return null;
|
|
2778
|
+
};
|
|
2779
|
+
var validRange = function(range, options) {
|
|
2780
|
+
try {
|
|
2781
|
+
return new Range(range, options).range || "*";
|
|
2782
|
+
} catch (er) {
|
|
2783
|
+
return null;
|
|
2784
|
+
}
|
|
2785
|
+
};
|
|
2786
|
+
var ltr = function(version, range, options) {
|
|
2787
|
+
return outside(version, range, "<", options);
|
|
2788
|
+
};
|
|
2789
|
+
var gtr = function(version, range, options) {
|
|
2790
|
+
return outside(version, range, ">", options);
|
|
2791
|
+
};
|
|
2792
|
+
var outside = function(version, range, hilo, options) {
|
|
2793
|
+
version = new SemVer(version, options);
|
|
2794
|
+
range = new Range(range, options);
|
|
2795
|
+
var gtfn, ltefn, ltfn, comp, ecomp;
|
|
2796
|
+
switch (hilo) {
|
|
2797
|
+
case ">":
|
|
2798
|
+
gtfn = gt;
|
|
2799
|
+
ltefn = lte;
|
|
2800
|
+
ltfn = lt;
|
|
2801
|
+
comp = ">";
|
|
2802
|
+
ecomp = ">=";
|
|
2803
|
+
break;
|
|
2804
|
+
case "<":
|
|
2805
|
+
gtfn = lt;
|
|
2806
|
+
ltefn = gte;
|
|
2807
|
+
ltfn = gt;
|
|
2808
|
+
comp = "<";
|
|
2809
|
+
ecomp = "<=";
|
|
2810
|
+
break;
|
|
2811
|
+
default:
|
|
2812
|
+
throw new TypeError('Must provide a hilo val of "<" or ">"');
|
|
2813
|
+
}
|
|
2814
|
+
if (satisfies(version, range, options)) {
|
|
2815
|
+
return false;
|
|
2816
|
+
}
|
|
2817
|
+
for (var i2 = 0;i2 < range.set.length; ++i2) {
|
|
2818
|
+
var comparators = range.set[i2];
|
|
2819
|
+
var high = null;
|
|
2820
|
+
var low = null;
|
|
2821
|
+
comparators.forEach(function(comparator) {
|
|
2822
|
+
if (comparator.semver === ANY) {
|
|
2823
|
+
comparator = new Comparator(">=0.0.0");
|
|
2824
|
+
}
|
|
2825
|
+
high = high || comparator;
|
|
2826
|
+
low = low || comparator;
|
|
2827
|
+
if (gtfn(comparator.semver, high.semver, options)) {
|
|
2828
|
+
high = comparator;
|
|
2829
|
+
} else if (ltfn(comparator.semver, low.semver, options)) {
|
|
2830
|
+
low = comparator;
|
|
2831
|
+
}
|
|
2832
|
+
});
|
|
2833
|
+
if (high.operator === comp || high.operator === ecomp) {
|
|
2834
|
+
return false;
|
|
2835
|
+
}
|
|
2836
|
+
if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
|
|
2837
|
+
return false;
|
|
2838
|
+
} else if (low.operator === ecomp && ltfn(version, low.semver)) {
|
|
2839
|
+
return false;
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
return true;
|
|
2843
|
+
};
|
|
2844
|
+
var prerelease = function(version, options) {
|
|
2845
|
+
var parsed = parse(version, options);
|
|
2846
|
+
return parsed && parsed.prerelease.length ? parsed.prerelease : null;
|
|
2847
|
+
};
|
|
2848
|
+
var intersects = function(r1, r2, options) {
|
|
2849
|
+
r1 = new Range(r1, options);
|
|
2850
|
+
r2 = new Range(r2, options);
|
|
2851
|
+
return r1.intersects(r2);
|
|
2852
|
+
};
|
|
2853
|
+
var coerce = function(version, options) {
|
|
2854
|
+
if (version instanceof SemVer) {
|
|
2855
|
+
return version;
|
|
2856
|
+
}
|
|
2857
|
+
if (typeof version === "number") {
|
|
2858
|
+
version = String(version);
|
|
2859
|
+
}
|
|
2860
|
+
if (typeof version !== "string") {
|
|
2861
|
+
return null;
|
|
2862
|
+
}
|
|
2863
|
+
options = options || {};
|
|
2864
|
+
var match = null;
|
|
2865
|
+
if (!options.rtl) {
|
|
2866
|
+
match = version.match(safeRe[t.COERCE]);
|
|
2867
|
+
} else {
|
|
2868
|
+
var next;
|
|
2869
|
+
while ((next = safeRe[t.COERCERTL].exec(version)) && (!match || match.index + match[0].length !== version.length)) {
|
|
2870
|
+
if (!match || next.index + next[0].length !== match.index + match[0].length) {
|
|
2871
|
+
match = next;
|
|
2872
|
+
}
|
|
2873
|
+
safeRe[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length;
|
|
2874
|
+
}
|
|
2875
|
+
safeRe[t.COERCERTL].lastIndex = -1;
|
|
2876
|
+
}
|
|
2877
|
+
if (match === null) {
|
|
2878
|
+
return null;
|
|
2879
|
+
}
|
|
2880
|
+
return parse(match[2] + "." + (match[3] || "0") + "." + (match[4] || "0"), options);
|
|
2881
|
+
};
|
|
2882
|
+
exports = module.exports = SemVer;
|
|
2883
|
+
var debug;
|
|
2884
|
+
if (typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
|
|
2885
|
+
debug = function() {
|
|
2886
|
+
var args = Array.prototype.slice.call(arguments, 0);
|
|
2887
|
+
args.unshift("SEMVER");
|
|
2888
|
+
console.log.apply(console, args);
|
|
2889
|
+
};
|
|
2890
|
+
} else {
|
|
2891
|
+
debug = function() {
|
|
2892
|
+
};
|
|
2893
|
+
}
|
|
2894
|
+
exports.SEMVER_SPEC_VERSION = "2.0.0";
|
|
2895
|
+
var MAX_LENGTH = 256;
|
|
2896
|
+
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
|
|
2897
|
+
var MAX_SAFE_COMPONENT_LENGTH = 16;
|
|
2898
|
+
var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
|
|
2899
|
+
var re = exports.re = [];
|
|
2900
|
+
var safeRe = exports.safeRe = [];
|
|
2901
|
+
var src = exports.src = [];
|
|
2902
|
+
var t = exports.tokens = {};
|
|
2903
|
+
var R = 0;
|
|
2904
|
+
var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
|
|
2905
|
+
var safeRegexReplacements = [
|
|
2906
|
+
["\\s", 1],
|
|
2907
|
+
["\\d", MAX_LENGTH],
|
|
2908
|
+
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
|
|
2909
|
+
];
|
|
2910
|
+
tok("NUMERICIDENTIFIER");
|
|
2911
|
+
src[t.NUMERICIDENTIFIER] = "0|[1-9]\\d*";
|
|
2912
|
+
tok("NUMERICIDENTIFIERLOOSE");
|
|
2913
|
+
src[t.NUMERICIDENTIFIERLOOSE] = "\\d+";
|
|
2914
|
+
tok("NONNUMERICIDENTIFIER");
|
|
2915
|
+
src[t.NONNUMERICIDENTIFIER] = "\\d*[a-zA-Z-]" + LETTERDASHNUMBER + "*";
|
|
2916
|
+
tok("MAINVERSION");
|
|
2917
|
+
src[t.MAINVERSION] = "(" + src[t.NUMERICIDENTIFIER] + ")\\." + "(" + src[t.NUMERICIDENTIFIER] + ")\\." + "(" + src[t.NUMERICIDENTIFIER] + ")";
|
|
2918
|
+
tok("MAINVERSIONLOOSE");
|
|
2919
|
+
src[t.MAINVERSIONLOOSE] = "(" + src[t.NUMERICIDENTIFIERLOOSE] + ")\\." + "(" + src[t.NUMERICIDENTIFIERLOOSE] + ")\\." + "(" + src[t.NUMERICIDENTIFIERLOOSE] + ")";
|
|
2920
|
+
tok("PRERELEASEIDENTIFIER");
|
|
2921
|
+
src[t.PRERELEASEIDENTIFIER] = "(?:" + src[t.NUMERICIDENTIFIER] + "|" + src[t.NONNUMERICIDENTIFIER] + ")";
|
|
2922
|
+
tok("PRERELEASEIDENTIFIERLOOSE");
|
|
2923
|
+
src[t.PRERELEASEIDENTIFIERLOOSE] = "(?:" + src[t.NUMERICIDENTIFIERLOOSE] + "|" + src[t.NONNUMERICIDENTIFIER] + ")";
|
|
2924
|
+
tok("PRERELEASE");
|
|
2925
|
+
src[t.PRERELEASE] = "(?:-(" + src[t.PRERELEASEIDENTIFIER] + "(?:\\." + src[t.PRERELEASEIDENTIFIER] + ")*))";
|
|
2926
|
+
tok("PRERELEASELOOSE");
|
|
2927
|
+
src[t.PRERELEASELOOSE] = "(?:-?(" + src[t.PRERELEASEIDENTIFIERLOOSE] + "(?:\\." + src[t.PRERELEASEIDENTIFIERLOOSE] + ")*))";
|
|
2928
|
+
tok("BUILDIDENTIFIER");
|
|
2929
|
+
src[t.BUILDIDENTIFIER] = LETTERDASHNUMBER + "+";
|
|
2930
|
+
tok("BUILD");
|
|
2931
|
+
src[t.BUILD] = "(?:\\+(" + src[t.BUILDIDENTIFIER] + "(?:\\." + src[t.BUILDIDENTIFIER] + ")*))";
|
|
2932
|
+
tok("FULL");
|
|
2933
|
+
tok("FULLPLAIN");
|
|
2934
|
+
src[t.FULLPLAIN] = "v?" + src[t.MAINVERSION] + src[t.PRERELEASE] + "?" + src[t.BUILD] + "?";
|
|
2935
|
+
src[t.FULL] = "^" + src[t.FULLPLAIN] + "$";
|
|
2936
|
+
tok("LOOSEPLAIN");
|
|
2937
|
+
src[t.LOOSEPLAIN] = "[v=\\s]*" + src[t.MAINVERSIONLOOSE] + src[t.PRERELEASELOOSE] + "?" + src[t.BUILD] + "?";
|
|
2938
|
+
tok("LOOSE");
|
|
2939
|
+
src[t.LOOSE] = "^" + src[t.LOOSEPLAIN] + "$";
|
|
2940
|
+
tok("GTLT");
|
|
2941
|
+
src[t.GTLT] = "((?:<|>)?=?)";
|
|
2942
|
+
tok("XRANGEIDENTIFIERLOOSE");
|
|
2943
|
+
src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + "|x|X|\\*";
|
|
2944
|
+
tok("XRANGEIDENTIFIER");
|
|
2945
|
+
src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + "|x|X|\\*";
|
|
2946
|
+
tok("XRANGEPLAIN");
|
|
2947
|
+
src[t.XRANGEPLAIN] = "[v=\\s]*(" + src[t.XRANGEIDENTIFIER] + ")" + "(?:\\.(" + src[t.XRANGEIDENTIFIER] + ")" + "(?:\\.(" + src[t.XRANGEIDENTIFIER] + ")" + "(?:" + src[t.PRERELEASE] + ")?" + src[t.BUILD] + "?" + ")?)?";
|
|
2948
|
+
tok("XRANGEPLAINLOOSE");
|
|
2949
|
+
src[t.XRANGEPLAINLOOSE] = "[v=\\s]*(" + src[t.XRANGEIDENTIFIERLOOSE] + ")" + "(?:\\.(" + src[t.XRANGEIDENTIFIERLOOSE] + ")" + "(?:\\.(" + src[t.XRANGEIDENTIFIERLOOSE] + ")" + "(?:" + src[t.PRERELEASELOOSE] + ")?" + src[t.BUILD] + "?" + ")?)?";
|
|
2950
|
+
tok("XRANGE");
|
|
2951
|
+
src[t.XRANGE] = "^" + src[t.GTLT] + "\\s*" + src[t.XRANGEPLAIN] + "$";
|
|
2952
|
+
tok("XRANGELOOSE");
|
|
2953
|
+
src[t.XRANGELOOSE] = "^" + src[t.GTLT] + "\\s*" + src[t.XRANGEPLAINLOOSE] + "$";
|
|
2954
|
+
tok("COERCE");
|
|
2955
|
+
src[t.COERCE] = "(^|[^\\d])" + "(\\d{1," + MAX_SAFE_COMPONENT_LENGTH + "})" + "(?:\\.(\\d{1," + MAX_SAFE_COMPONENT_LENGTH + "}))?" + "(?:\\.(\\d{1," + MAX_SAFE_COMPONENT_LENGTH + "}))?" + "(?:$|[^\\d])";
|
|
2956
|
+
tok("COERCERTL");
|
|
2957
|
+
re[t.COERCERTL] = new RegExp(src[t.COERCE], "g");
|
|
2958
|
+
safeRe[t.COERCERTL] = new RegExp(makeSafeRe(src[t.COERCE]), "g");
|
|
2959
|
+
tok("LONETILDE");
|
|
2960
|
+
src[t.LONETILDE] = "(?:~>?)";
|
|
2961
|
+
tok("TILDETRIM");
|
|
2962
|
+
src[t.TILDETRIM] = "(\\s*)" + src[t.LONETILDE] + "\\s+";
|
|
2963
|
+
re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], "g");
|
|
2964
|
+
safeRe[t.TILDETRIM] = new RegExp(makeSafeRe(src[t.TILDETRIM]), "g");
|
|
2965
|
+
var tildeTrimReplace = "$1~";
|
|
2966
|
+
tok("TILDE");
|
|
2967
|
+
src[t.TILDE] = "^" + src[t.LONETILDE] + src[t.XRANGEPLAIN] + "$";
|
|
2968
|
+
tok("TILDELOOSE");
|
|
2969
|
+
src[t.TILDELOOSE] = "^" + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + "$";
|
|
2970
|
+
tok("LONECARET");
|
|
2971
|
+
src[t.LONECARET] = "(?:\\^)";
|
|
2972
|
+
tok("CARETTRIM");
|
|
2973
|
+
src[t.CARETTRIM] = "(\\s*)" + src[t.LONECARET] + "\\s+";
|
|
2974
|
+
re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], "g");
|
|
2975
|
+
safeRe[t.CARETTRIM] = new RegExp(makeSafeRe(src[t.CARETTRIM]), "g");
|
|
2976
|
+
var caretTrimReplace = "$1^";
|
|
2977
|
+
tok("CARET");
|
|
2978
|
+
src[t.CARET] = "^" + src[t.LONECARET] + src[t.XRANGEPLAIN] + "$";
|
|
2979
|
+
tok("CARETLOOSE");
|
|
2980
|
+
src[t.CARETLOOSE] = "^" + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + "$";
|
|
2981
|
+
tok("COMPARATORLOOSE");
|
|
2982
|
+
src[t.COMPARATORLOOSE] = "^" + src[t.GTLT] + "\\s*(" + src[t.LOOSEPLAIN] + ")$|^$";
|
|
2983
|
+
tok("COMPARATOR");
|
|
2984
|
+
src[t.COMPARATOR] = "^" + src[t.GTLT] + "\\s*(" + src[t.FULLPLAIN] + ")$|^$";
|
|
2985
|
+
tok("COMPARATORTRIM");
|
|
2986
|
+
src[t.COMPARATORTRIM] = "(\\s*)" + src[t.GTLT] + "\\s*(" + src[t.LOOSEPLAIN] + "|" + src[t.XRANGEPLAIN] + ")";
|
|
2987
|
+
re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], "g");
|
|
2988
|
+
safeRe[t.COMPARATORTRIM] = new RegExp(makeSafeRe(src[t.COMPARATORTRIM]), "g");
|
|
2989
|
+
var comparatorTrimReplace = "$1$2$3";
|
|
2990
|
+
tok("HYPHENRANGE");
|
|
2991
|
+
src[t.HYPHENRANGE] = "^\\s*(" + src[t.XRANGEPLAIN] + ")" + "\\s+-\\s+" + "(" + src[t.XRANGEPLAIN] + ")" + "\\s*$";
|
|
2992
|
+
tok("HYPHENRANGELOOSE");
|
|
2993
|
+
src[t.HYPHENRANGELOOSE] = "^\\s*(" + src[t.XRANGEPLAINLOOSE] + ")" + "\\s+-\\s+" + "(" + src[t.XRANGEPLAINLOOSE] + ")" + "\\s*$";
|
|
2994
|
+
tok("STAR");
|
|
2995
|
+
src[t.STAR] = "(<|>)?=?\\s*\\*";
|
|
2996
|
+
for (i = 0;i < R; i++) {
|
|
2997
|
+
debug(i, src[i]);
|
|
2998
|
+
if (!re[i]) {
|
|
2999
|
+
re[i] = new RegExp(src[i]);
|
|
3000
|
+
safeRe[i] = new RegExp(makeSafeRe(src[i]));
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
var i;
|
|
3004
|
+
exports.parse = parse;
|
|
3005
|
+
exports.valid = valid;
|
|
3006
|
+
exports.clean = clean;
|
|
3007
|
+
exports.SemVer = SemVer;
|
|
3008
|
+
SemVer.prototype.format = function() {
|
|
3009
|
+
this.version = this.major + "." + this.minor + "." + this.patch;
|
|
3010
|
+
if (this.prerelease.length) {
|
|
3011
|
+
this.version += "-" + this.prerelease.join(".");
|
|
3012
|
+
}
|
|
3013
|
+
return this.version;
|
|
3014
|
+
};
|
|
3015
|
+
SemVer.prototype.toString = function() {
|
|
3016
|
+
return this.version;
|
|
3017
|
+
};
|
|
3018
|
+
SemVer.prototype.compare = function(other) {
|
|
3019
|
+
debug("SemVer.compare", this.version, this.options, other);
|
|
3020
|
+
if (!(other instanceof SemVer)) {
|
|
3021
|
+
other = new SemVer(other, this.options);
|
|
3022
|
+
}
|
|
3023
|
+
return this.compareMain(other) || this.comparePre(other);
|
|
3024
|
+
};
|
|
3025
|
+
SemVer.prototype.compareMain = function(other) {
|
|
3026
|
+
if (!(other instanceof SemVer)) {
|
|
3027
|
+
other = new SemVer(other, this.options);
|
|
3028
|
+
}
|
|
3029
|
+
return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
|
|
3030
|
+
};
|
|
3031
|
+
SemVer.prototype.comparePre = function(other) {
|
|
3032
|
+
if (!(other instanceof SemVer)) {
|
|
3033
|
+
other = new SemVer(other, this.options);
|
|
3034
|
+
}
|
|
3035
|
+
if (this.prerelease.length && !other.prerelease.length) {
|
|
3036
|
+
return -1;
|
|
3037
|
+
} else if (!this.prerelease.length && other.prerelease.length) {
|
|
3038
|
+
return 1;
|
|
3039
|
+
} else if (!this.prerelease.length && !other.prerelease.length) {
|
|
3040
|
+
return 0;
|
|
3041
|
+
}
|
|
3042
|
+
var i2 = 0;
|
|
3043
|
+
do {
|
|
3044
|
+
var a = this.prerelease[i2];
|
|
3045
|
+
var b = other.prerelease[i2];
|
|
3046
|
+
debug("prerelease compare", i2, a, b);
|
|
3047
|
+
if (a === undefined && b === undefined) {
|
|
3048
|
+
return 0;
|
|
3049
|
+
} else if (b === undefined) {
|
|
3050
|
+
return 1;
|
|
3051
|
+
} else if (a === undefined) {
|
|
3052
|
+
return -1;
|
|
3053
|
+
} else if (a === b) {
|
|
3054
|
+
continue;
|
|
3055
|
+
} else {
|
|
3056
|
+
return compareIdentifiers(a, b);
|
|
3057
|
+
}
|
|
3058
|
+
} while (++i2);
|
|
3059
|
+
};
|
|
3060
|
+
SemVer.prototype.compareBuild = function(other) {
|
|
3061
|
+
if (!(other instanceof SemVer)) {
|
|
3062
|
+
other = new SemVer(other, this.options);
|
|
3063
|
+
}
|
|
3064
|
+
var i2 = 0;
|
|
3065
|
+
do {
|
|
3066
|
+
var a = this.build[i2];
|
|
3067
|
+
var b = other.build[i2];
|
|
3068
|
+
debug("prerelease compare", i2, a, b);
|
|
3069
|
+
if (a === undefined && b === undefined) {
|
|
3070
|
+
return 0;
|
|
3071
|
+
} else if (b === undefined) {
|
|
3072
|
+
return 1;
|
|
3073
|
+
} else if (a === undefined) {
|
|
3074
|
+
return -1;
|
|
3075
|
+
} else if (a === b) {
|
|
3076
|
+
continue;
|
|
3077
|
+
} else {
|
|
3078
|
+
return compareIdentifiers(a, b);
|
|
3079
|
+
}
|
|
3080
|
+
} while (++i2);
|
|
3081
|
+
};
|
|
3082
|
+
SemVer.prototype.inc = function(release, identifier) {
|
|
3083
|
+
switch (release) {
|
|
3084
|
+
case "premajor":
|
|
3085
|
+
this.prerelease.length = 0;
|
|
3086
|
+
this.patch = 0;
|
|
3087
|
+
this.minor = 0;
|
|
3088
|
+
this.major++;
|
|
3089
|
+
this.inc("pre", identifier);
|
|
3090
|
+
break;
|
|
3091
|
+
case "preminor":
|
|
3092
|
+
this.prerelease.length = 0;
|
|
3093
|
+
this.patch = 0;
|
|
3094
|
+
this.minor++;
|
|
3095
|
+
this.inc("pre", identifier);
|
|
3096
|
+
break;
|
|
3097
|
+
case "prepatch":
|
|
3098
|
+
this.prerelease.length = 0;
|
|
3099
|
+
this.inc("patch", identifier);
|
|
3100
|
+
this.inc("pre", identifier);
|
|
3101
|
+
break;
|
|
3102
|
+
case "prerelease":
|
|
3103
|
+
if (this.prerelease.length === 0) {
|
|
3104
|
+
this.inc("patch", identifier);
|
|
3105
|
+
}
|
|
3106
|
+
this.inc("pre", identifier);
|
|
3107
|
+
break;
|
|
3108
|
+
case "major":
|
|
3109
|
+
if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
|
|
3110
|
+
this.major++;
|
|
3111
|
+
}
|
|
3112
|
+
this.minor = 0;
|
|
3113
|
+
this.patch = 0;
|
|
3114
|
+
this.prerelease = [];
|
|
3115
|
+
break;
|
|
3116
|
+
case "minor":
|
|
3117
|
+
if (this.patch !== 0 || this.prerelease.length === 0) {
|
|
3118
|
+
this.minor++;
|
|
3119
|
+
}
|
|
3120
|
+
this.patch = 0;
|
|
3121
|
+
this.prerelease = [];
|
|
3122
|
+
break;
|
|
3123
|
+
case "patch":
|
|
3124
|
+
if (this.prerelease.length === 0) {
|
|
3125
|
+
this.patch++;
|
|
3126
|
+
}
|
|
3127
|
+
this.prerelease = [];
|
|
3128
|
+
break;
|
|
3129
|
+
case "pre":
|
|
3130
|
+
if (this.prerelease.length === 0) {
|
|
3131
|
+
this.prerelease = [0];
|
|
3132
|
+
} else {
|
|
3133
|
+
var i2 = this.prerelease.length;
|
|
3134
|
+
while (--i2 >= 0) {
|
|
3135
|
+
if (typeof this.prerelease[i2] === "number") {
|
|
3136
|
+
this.prerelease[i2]++;
|
|
3137
|
+
i2 = -2;
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
if (i2 === -1) {
|
|
3141
|
+
this.prerelease.push(0);
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
if (identifier) {
|
|
3145
|
+
if (this.prerelease[0] === identifier) {
|
|
3146
|
+
if (isNaN(this.prerelease[1])) {
|
|
3147
|
+
this.prerelease = [identifier, 0];
|
|
3148
|
+
}
|
|
3149
|
+
} else {
|
|
3150
|
+
this.prerelease = [identifier, 0];
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
break;
|
|
3154
|
+
default:
|
|
3155
|
+
throw new Error("invalid increment argument: " + release);
|
|
3156
|
+
}
|
|
3157
|
+
this.format();
|
|
3158
|
+
this.raw = this.version;
|
|
3159
|
+
return this;
|
|
3160
|
+
};
|
|
3161
|
+
exports.inc = inc;
|
|
3162
|
+
exports.diff = diff;
|
|
3163
|
+
exports.compareIdentifiers = compareIdentifiers;
|
|
3164
|
+
var numeric = /^[0-9]+$/;
|
|
3165
|
+
exports.rcompareIdentifiers = rcompareIdentifiers;
|
|
3166
|
+
exports.major = major;
|
|
3167
|
+
exports.minor = minor;
|
|
3168
|
+
exports.patch = patch;
|
|
3169
|
+
exports.compare = compare;
|
|
3170
|
+
exports.compareLoose = compareLoose;
|
|
3171
|
+
exports.compareBuild = compareBuild;
|
|
3172
|
+
exports.rcompare = rcompare;
|
|
3173
|
+
exports.sort = sort;
|
|
3174
|
+
exports.rsort = rsort;
|
|
3175
|
+
exports.gt = gt;
|
|
3176
|
+
exports.lt = lt;
|
|
3177
|
+
exports.eq = eq;
|
|
3178
|
+
exports.neq = neq;
|
|
3179
|
+
exports.gte = gte;
|
|
3180
|
+
exports.lte = lte;
|
|
3181
|
+
exports.cmp = cmp;
|
|
3182
|
+
exports.Comparator = Comparator;
|
|
3183
|
+
var ANY = {};
|
|
3184
|
+
Comparator.prototype.parse = function(comp) {
|
|
3185
|
+
var r = this.options.loose ? safeRe[t.COMPARATORLOOSE] : safeRe[t.COMPARATOR];
|
|
3186
|
+
var m = comp.match(r);
|
|
3187
|
+
if (!m) {
|
|
3188
|
+
throw new TypeError("Invalid comparator: " + comp);
|
|
3189
|
+
}
|
|
3190
|
+
this.operator = m[1] !== undefined ? m[1] : "";
|
|
3191
|
+
if (this.operator === "=") {
|
|
3192
|
+
this.operator = "";
|
|
3193
|
+
}
|
|
3194
|
+
if (!m[2]) {
|
|
3195
|
+
this.semver = ANY;
|
|
3196
|
+
} else {
|
|
3197
|
+
this.semver = new SemVer(m[2], this.options.loose);
|
|
3198
|
+
}
|
|
3199
|
+
};
|
|
3200
|
+
Comparator.prototype.toString = function() {
|
|
3201
|
+
return this.value;
|
|
3202
|
+
};
|
|
3203
|
+
Comparator.prototype.test = function(version) {
|
|
3204
|
+
debug("Comparator.test", version, this.options.loose);
|
|
3205
|
+
if (this.semver === ANY || version === ANY) {
|
|
3206
|
+
return true;
|
|
3207
|
+
}
|
|
3208
|
+
if (typeof version === "string") {
|
|
3209
|
+
try {
|
|
3210
|
+
version = new SemVer(version, this.options);
|
|
3211
|
+
} catch (er) {
|
|
3212
|
+
return false;
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
return cmp(version, this.operator, this.semver, this.options);
|
|
3216
|
+
};
|
|
3217
|
+
Comparator.prototype.intersects = function(comp, options) {
|
|
3218
|
+
if (!(comp instanceof Comparator)) {
|
|
3219
|
+
throw new TypeError("a Comparator is required");
|
|
3220
|
+
}
|
|
3221
|
+
if (!options || typeof options !== "object") {
|
|
3222
|
+
options = {
|
|
3223
|
+
loose: !!options,
|
|
3224
|
+
includePrerelease: false
|
|
3225
|
+
};
|
|
3226
|
+
}
|
|
3227
|
+
var rangeTmp;
|
|
3228
|
+
if (this.operator === "") {
|
|
3229
|
+
if (this.value === "") {
|
|
3230
|
+
return true;
|
|
3231
|
+
}
|
|
3232
|
+
rangeTmp = new Range(comp.value, options);
|
|
3233
|
+
return satisfies(this.value, rangeTmp, options);
|
|
3234
|
+
} else if (comp.operator === "") {
|
|
3235
|
+
if (comp.value === "") {
|
|
3236
|
+
return true;
|
|
3237
|
+
}
|
|
3238
|
+
rangeTmp = new Range(this.value, options);
|
|
3239
|
+
return satisfies(comp.semver, rangeTmp, options);
|
|
3240
|
+
}
|
|
3241
|
+
var sameDirectionIncreasing = (this.operator === ">=" || this.operator === ">") && (comp.operator === ">=" || comp.operator === ">");
|
|
3242
|
+
var sameDirectionDecreasing = (this.operator === "<=" || this.operator === "<") && (comp.operator === "<=" || comp.operator === "<");
|
|
3243
|
+
var sameSemVer = this.semver.version === comp.semver.version;
|
|
3244
|
+
var differentDirectionsInclusive = (this.operator === ">=" || this.operator === "<=") && (comp.operator === ">=" || comp.operator === "<=");
|
|
3245
|
+
var oppositeDirectionsLessThan = cmp(this.semver, "<", comp.semver, options) && ((this.operator === ">=" || this.operator === ">") && (comp.operator === "<=" || comp.operator === "<"));
|
|
3246
|
+
var oppositeDirectionsGreaterThan = cmp(this.semver, ">", comp.semver, options) && ((this.operator === "<=" || this.operator === "<") && (comp.operator === ">=" || comp.operator === ">"));
|
|
3247
|
+
return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
|
|
3248
|
+
};
|
|
3249
|
+
exports.Range = Range;
|
|
3250
|
+
Range.prototype.format = function() {
|
|
3251
|
+
this.range = this.set.map(function(comps) {
|
|
3252
|
+
return comps.join(" ").trim();
|
|
3253
|
+
}).join("||").trim();
|
|
3254
|
+
return this.range;
|
|
3255
|
+
};
|
|
3256
|
+
Range.prototype.toString = function() {
|
|
3257
|
+
return this.range;
|
|
3258
|
+
};
|
|
3259
|
+
Range.prototype.parseRange = function(range) {
|
|
3260
|
+
var loose = this.options.loose;
|
|
3261
|
+
var hr = loose ? safeRe[t.HYPHENRANGELOOSE] : safeRe[t.HYPHENRANGE];
|
|
3262
|
+
range = range.replace(hr, hyphenReplace);
|
|
3263
|
+
debug("hyphen replace", range);
|
|
3264
|
+
range = range.replace(safeRe[t.COMPARATORTRIM], comparatorTrimReplace);
|
|
3265
|
+
debug("comparator trim", range, safeRe[t.COMPARATORTRIM]);
|
|
3266
|
+
range = range.replace(safeRe[t.TILDETRIM], tildeTrimReplace);
|
|
3267
|
+
range = range.replace(safeRe[t.CARETTRIM], caretTrimReplace);
|
|
3268
|
+
range = range.split(/\s+/).join(" ");
|
|
3269
|
+
var compRe = loose ? safeRe[t.COMPARATORLOOSE] : safeRe[t.COMPARATOR];
|
|
3270
|
+
var set = range.split(" ").map(function(comp) {
|
|
3271
|
+
return parseComparator(comp, this.options);
|
|
3272
|
+
}, this).join(" ").split(/\s+/);
|
|
3273
|
+
if (this.options.loose) {
|
|
3274
|
+
set = set.filter(function(comp) {
|
|
3275
|
+
return !!comp.match(compRe);
|
|
3276
|
+
});
|
|
3277
|
+
}
|
|
3278
|
+
set = set.map(function(comp) {
|
|
3279
|
+
return new Comparator(comp, this.options);
|
|
3280
|
+
}, this);
|
|
3281
|
+
return set;
|
|
3282
|
+
};
|
|
3283
|
+
Range.prototype.intersects = function(range, options) {
|
|
3284
|
+
if (!(range instanceof Range)) {
|
|
3285
|
+
throw new TypeError("a Range is required");
|
|
3286
|
+
}
|
|
3287
|
+
return this.set.some(function(thisComparators) {
|
|
3288
|
+
return isSatisfiable(thisComparators, options) && range.set.some(function(rangeComparators) {
|
|
3289
|
+
return isSatisfiable(rangeComparators, options) && thisComparators.every(function(thisComparator) {
|
|
3290
|
+
return rangeComparators.every(function(rangeComparator) {
|
|
3291
|
+
return thisComparator.intersects(rangeComparator, options);
|
|
3292
|
+
});
|
|
3293
|
+
});
|
|
3294
|
+
});
|
|
3295
|
+
});
|
|
3296
|
+
};
|
|
3297
|
+
exports.toComparators = toComparators;
|
|
3298
|
+
Range.prototype.test = function(version) {
|
|
3299
|
+
if (!version) {
|
|
3300
|
+
return false;
|
|
3301
|
+
}
|
|
3302
|
+
if (typeof version === "string") {
|
|
3303
|
+
try {
|
|
3304
|
+
version = new SemVer(version, this.options);
|
|
3305
|
+
} catch (er) {
|
|
3306
|
+
return false;
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
for (var i2 = 0;i2 < this.set.length; i2++) {
|
|
3310
|
+
if (testSet(this.set[i2], version, this.options)) {
|
|
3311
|
+
return true;
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
return false;
|
|
3315
|
+
};
|
|
3316
|
+
exports.satisfies = satisfies;
|
|
3317
|
+
exports.maxSatisfying = maxSatisfying;
|
|
3318
|
+
exports.minSatisfying = minSatisfying;
|
|
3319
|
+
exports.minVersion = minVersion;
|
|
3320
|
+
exports.validRange = validRange;
|
|
3321
|
+
exports.ltr = ltr;
|
|
3322
|
+
exports.gtr = gtr;
|
|
3323
|
+
exports.outside = outside;
|
|
3324
|
+
exports.prerelease = prerelease;
|
|
3325
|
+
exports.intersects = intersects;
|
|
3326
|
+
exports.coerce = coerce;
|
|
3327
|
+
});
|
|
3328
|
+
|
|
3329
|
+
// src/cli/main.ts
|
|
3330
|
+
import fs from "node:fs";
|
|
3331
|
+
import path from "node:path";
|
|
3332
|
+
|
|
3333
|
+
// ../../node_modules/commander/esm.mjs
|
|
3334
|
+
var import_ = __toESM(require_commander(), 1);
|
|
3335
|
+
var {
|
|
3336
|
+
program,
|
|
3337
|
+
createCommand,
|
|
3338
|
+
createArgument,
|
|
3339
|
+
createOption,
|
|
3340
|
+
CommanderError,
|
|
3341
|
+
InvalidArgumentError,
|
|
3342
|
+
InvalidOptionArgumentError,
|
|
3343
|
+
Command,
|
|
3344
|
+
Argument,
|
|
3345
|
+
Option,
|
|
3346
|
+
Help
|
|
3347
|
+
} = import_.default;
|
|
3348
|
+
|
|
3349
|
+
// src/cli/main.ts
|
|
3350
|
+
var import_dotenv = __toESM(require_main(), 1);
|
|
3351
|
+
|
|
3352
|
+
// src/cli/build.ts
|
|
3353
|
+
import {resolve as resolve2} from "node:path";
|
|
3354
|
+
|
|
3355
|
+
// src/cli/lib/exec.ts
|
|
3356
|
+
import child_process from "node:child_process";
|
|
3357
|
+
import {mkdirSync, openSync} from "node:fs";
|
|
3358
|
+
import {dirname} from "node:path";
|
|
3359
|
+
var exec = (command, options) => {
|
|
3360
|
+
const logFile = options?.logPath;
|
|
3361
|
+
let logStream = process.stdout;
|
|
3362
|
+
if (logFile) {
|
|
3363
|
+
const dirName = dirname(logFile);
|
|
3364
|
+
mkdirSync(dirName, { recursive: true });
|
|
3365
|
+
logStream = openSync(logFile, "a");
|
|
3366
|
+
}
|
|
3367
|
+
return new Promise((resolve, reject) => {
|
|
3368
|
+
try {
|
|
3369
|
+
const childProcess = child_process.spawn(command, {
|
|
3370
|
+
shell: true,
|
|
3371
|
+
stdio: [process.stdin, logStream, logStream],
|
|
3372
|
+
env: { ...process.env, ...options?.env || {} },
|
|
3373
|
+
...options
|
|
3374
|
+
});
|
|
3375
|
+
childProcess.on("error", (e) => {
|
|
3376
|
+
console.log("error", e);
|
|
3377
|
+
reject(e);
|
|
3378
|
+
});
|
|
3379
|
+
childProcess.once("exit", (num) => {
|
|
3380
|
+
if (num !== 0) {
|
|
3381
|
+
console.log("exe \u547D\u4EE4\u51FA\u9519,code=", {
|
|
3382
|
+
code: num,
|
|
3383
|
+
command
|
|
3384
|
+
});
|
|
3385
|
+
reject(num);
|
|
3386
|
+
} else {
|
|
3387
|
+
resolve(num);
|
|
3388
|
+
}
|
|
3389
|
+
});
|
|
3390
|
+
} catch (e) {
|
|
3391
|
+
console.log({ message: "[exec error]", error: e, command });
|
|
3392
|
+
reject(e);
|
|
3393
|
+
}
|
|
3394
|
+
});
|
|
3395
|
+
};
|
|
3396
|
+
|
|
3397
|
+
// src/cli/lib/vercelHelper.ts
|
|
3398
|
+
var import_semver = __toESM(require_semver(), 1);
|
|
3399
|
+
import {
|
|
3400
|
+
existsSync,
|
|
3401
|
+
readFile,
|
|
3402
|
+
readFileSync,
|
|
3403
|
+
readdirSync,
|
|
3404
|
+
writeFile
|
|
3405
|
+
} from "node:fs";
|
|
3406
|
+
import {resolve} from "node:path";
|
|
3407
|
+
function projectRoot(...paths) {
|
|
3408
|
+
if (!_projectDir) {
|
|
3409
|
+
const dirs = [".", "..", "../..", "../../..", "../../../.."];
|
|
3410
|
+
for (const d of dirs) {
|
|
3411
|
+
const package1 = resolve(d, "./package.json");
|
|
3412
|
+
if (existsSync(package1)) {
|
|
3413
|
+
const content1 = JSON.parse(readFileSync(package1).toString());
|
|
3414
|
+
if (content1.name === rootPackageName) {
|
|
3415
|
+
_projectDir = resolve(d);
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
return resolve(_projectDir, ...paths);
|
|
3421
|
+
}
|
|
3422
|
+
async function getWorkspacePackages() {
|
|
3423
|
+
const appsDir = projectRoot(appsDirRoot);
|
|
3424
|
+
const packageDir = projectRoot("packages");
|
|
3425
|
+
const result = await [packageDir, appsDir].flatMap((dir1) => {
|
|
3426
|
+
const appPackages = readdirSync(dir1, { recursive: false }).filter((x) => {
|
|
3427
|
+
const packageJson = resolve(dir1, x.toString(), "package.json");
|
|
3428
|
+
return existsSync(packageJson);
|
|
3429
|
+
}).map((f) => {
|
|
3430
|
+
const a = readFileSync(resolve(dir1, f.toString(), "package.json")).toString();
|
|
3431
|
+
const content = JSON.parse(a);
|
|
3432
|
+
return {
|
|
3433
|
+
name: content.name,
|
|
3434
|
+
version: content.version,
|
|
3435
|
+
dir: resolve(dir1, f.toString())
|
|
3436
|
+
};
|
|
3437
|
+
});
|
|
3438
|
+
return appPackages;
|
|
3439
|
+
});
|
|
3440
|
+
return result;
|
|
3441
|
+
}
|
|
3442
|
+
function patchVersion(packageJsonPath = "package.json") {
|
|
3443
|
+
readFile(packageJsonPath, (err, data) => {
|
|
3444
|
+
if (err)
|
|
3445
|
+
throw err;
|
|
3446
|
+
let packageJsonObj = JSON.parse(data.toString());
|
|
3447
|
+
const versionNumber = packageJsonObj.version;
|
|
3448
|
+
const pathVersion = import_semver.default.patch(versionNumber) + 1;
|
|
3449
|
+
packageJsonObj.version = `${import_semver.default.major(versionNumber)}.${import_semver.default.minor(versionNumber)}.${pathVersion}`;
|
|
3450
|
+
packageJsonObj = JSON.stringify(packageJsonObj, null, 2);
|
|
3451
|
+
writeFile(packageJsonPath, packageJsonObj, (err2) => {
|
|
3452
|
+
if (err2)
|
|
3453
|
+
throw err2;
|
|
3454
|
+
});
|
|
3455
|
+
});
|
|
3456
|
+
}
|
|
3457
|
+
var appsDirRoot = "apps";
|
|
3458
|
+
var rootPackageName = "workspaces";
|
|
3459
|
+
var _projectDir = "";
|
|
3460
|
+
|
|
3461
|
+
// src/cli/build.ts
|
|
3462
|
+
var build = async () => {
|
|
3463
|
+
const result = await Bun.build({
|
|
3464
|
+
entrypoints: ["./src/cli/main.ts"],
|
|
3465
|
+
outdir: "./dist",
|
|
3466
|
+
target: "node",
|
|
3467
|
+
minify: false,
|
|
3468
|
+
external: ["puppeteer", "crawlee", "@cloudflare/next-on-pages"]
|
|
3469
|
+
});
|
|
3470
|
+
console.log("build result", result);
|
|
3471
|
+
const envBuild = {
|
|
3472
|
+
...process.env,
|
|
3473
|
+
NEXT_BUILD_OUTPUT: process.env.NEXT_BUILD_OUTPUT === ".next.dev" ? ".next" : process.env.NEXT_BUILD_OUTPUT
|
|
3474
|
+
};
|
|
3475
|
+
envBuild.NODE_ENV = undefined;
|
|
3476
|
+
await exec("bun run next build", { env: envBuild });
|
|
3477
|
+
await exec(`(git commit -a -m "release" || true)`);
|
|
3478
|
+
const appPackages = await getWorkspacePackages();
|
|
3479
|
+
if (!appPackages.length) {
|
|
3480
|
+
console.log("\u6CA1\u6709 npm package");
|
|
3481
|
+
return;
|
|
3482
|
+
}
|
|
3483
|
+
await Promise.all(appPackages.map(async (p) => {
|
|
3484
|
+
console.log(`\u66F4\u65B0\u53D1\u5E03${p.name}(${p.version})${p.dir}`);
|
|
3485
|
+
patchVersion(resolve2(p.dir, "package.json"));
|
|
3486
|
+
try {
|
|
3487
|
+
await exec("bun run build", { cwd: p.dir });
|
|
3488
|
+
} catch (e) {
|
|
3489
|
+
console.log("\u6784\u5EFA\u5931\u8D25", p);
|
|
3490
|
+
return;
|
|
3491
|
+
}
|
|
3492
|
+
if (process.env.DOCKER_BUILD) {
|
|
3493
|
+
} else {
|
|
3494
|
+
await exec("npm publish", { cwd: p.dir });
|
|
3495
|
+
}
|
|
3496
|
+
}));
|
|
3497
|
+
};
|
|
3498
|
+
|
|
3499
|
+
// src/cli/main.ts
|
|
3500
|
+
var loadEnv = function() {
|
|
3501
|
+
envFiles.forEach((envFile) => {
|
|
3502
|
+
if (fs.existsSync(envFile)) {
|
|
3503
|
+
console.log("load env file:", envFile);
|
|
3504
|
+
const envPath = path.resolve(envFile);
|
|
3505
|
+
const dotenvConfig = import_dotenv.default.config({
|
|
3506
|
+
path: envPath
|
|
3507
|
+
});
|
|
3508
|
+
if (dotenvConfig.error) {
|
|
3509
|
+
throw new Error("parse env error", dotenvConfig.error);
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
});
|
|
3513
|
+
};
|
|
3514
|
+
var envFiles = ["../../env/dev.env", "./env/dev.env", ".env"];
|
|
3515
|
+
(async () => {
|
|
3516
|
+
await loadEnv();
|
|
3517
|
+
program.command("gomtm").action(() => {
|
|
3518
|
+
console.log("gomtm hello");
|
|
3519
|
+
});
|
|
3520
|
+
program.command("build").action(build);
|
|
3521
|
+
program.parse();
|
|
3522
|
+
})();
|