@rsbuild/core 1.0.6 → 1.0.8
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/compiled/css-loader/index.js +20 -20
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/postcss-loader/index.js +8 -8
- package/compiled/rsbuild-dev-middleware/index.js +27 -27
- package/compiled/rspack-chain/index.d.ts +0 -1
- package/compiled/rspack-chain/index.js +67 -67
- package/compiled/rspack-chain/package.json +1 -1
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/compiled/style-loader/index.js +10 -10
- package/dist/index.cjs +3919 -347
- package/dist/index.js +3859 -276
- package/dist-types/configChain.d.ts +0 -8
- package/dist-types/helpers/stats.d.ts +1 -1
- package/package.json +5 -7
- package/compiled/browserslist/index.d.ts +0 -201
- package/compiled/browserslist/index.js +0 -1876
- package/compiled/browserslist/license +0 -20
- package/compiled/browserslist/package.json +0 -1
- package/compiled/commander/index.d.ts +0 -971
- package/compiled/commander/index.js +0 -2190
- package/compiled/commander/license +0 -22
- package/compiled/commander/package.json +0 -1
- package/compiled/dotenv/index.d.ts +0 -157
- package/compiled/dotenv/index.js +0 -336
- package/compiled/dotenv/license +0 -23
- package/compiled/dotenv/package.json +0 -1
- package/compiled/dotenv-expand/index.d.ts +0 -52
- package/compiled/dotenv-expand/index.js +0 -105
- package/compiled/dotenv-expand/license +0 -24
- package/compiled/dotenv-expand/package.json +0 -1
package/dist/index.js
CHANGED
|
@@ -60,6 +60,3077 @@ var init_esm = __esm({
|
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
+
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/error.js
|
|
64
|
+
var require_error = __commonJS({
|
|
65
|
+
"../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/error.js"(exports) {
|
|
66
|
+
"use strict";
|
|
67
|
+
init_esm();
|
|
68
|
+
var CommanderError2 = class extends Error {
|
|
69
|
+
/**
|
|
70
|
+
* Constructs the CommanderError class
|
|
71
|
+
* @param {number} exitCode suggested exit code which could be used with process.exit
|
|
72
|
+
* @param {string} code an id string representing the error
|
|
73
|
+
* @param {string} message human-readable description of the error
|
|
74
|
+
*/
|
|
75
|
+
constructor(exitCode, code, message) {
|
|
76
|
+
super(message);
|
|
77
|
+
Error.captureStackTrace(this, this.constructor);
|
|
78
|
+
this.name = this.constructor.name;
|
|
79
|
+
this.code = code;
|
|
80
|
+
this.exitCode = exitCode;
|
|
81
|
+
this.nestedError = void 0;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var InvalidArgumentError2 = class extends CommanderError2 {
|
|
85
|
+
/**
|
|
86
|
+
* Constructs the InvalidArgumentError class
|
|
87
|
+
* @param {string} [message] explanation of why argument is invalid
|
|
88
|
+
*/
|
|
89
|
+
constructor(message) {
|
|
90
|
+
super(1, "commander.invalidArgument", message);
|
|
91
|
+
Error.captureStackTrace(this, this.constructor);
|
|
92
|
+
this.name = this.constructor.name;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.CommanderError = CommanderError2;
|
|
96
|
+
exports.InvalidArgumentError = InvalidArgumentError2;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/argument.js
|
|
101
|
+
var require_argument = __commonJS({
|
|
102
|
+
"../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/argument.js"(exports) {
|
|
103
|
+
"use strict";
|
|
104
|
+
init_esm();
|
|
105
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
106
|
+
var Argument2 = class {
|
|
107
|
+
/**
|
|
108
|
+
* Initialize a new command argument with the given name and description.
|
|
109
|
+
* The default is that the argument is required, and you can explicitly
|
|
110
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} name
|
|
113
|
+
* @param {string} [description]
|
|
114
|
+
*/
|
|
115
|
+
constructor(name, description) {
|
|
116
|
+
this.description = description || "";
|
|
117
|
+
this.variadic = false;
|
|
118
|
+
this.parseArg = void 0;
|
|
119
|
+
this.defaultValue = void 0;
|
|
120
|
+
this.defaultValueDescription = void 0;
|
|
121
|
+
this.argChoices = void 0;
|
|
122
|
+
switch (name[0]) {
|
|
123
|
+
case "<":
|
|
124
|
+
this.required = true;
|
|
125
|
+
this._name = name.slice(1, -1);
|
|
126
|
+
break;
|
|
127
|
+
case "[":
|
|
128
|
+
this.required = false;
|
|
129
|
+
this._name = name.slice(1, -1);
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
this.required = true;
|
|
133
|
+
this._name = name;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
137
|
+
this.variadic = true;
|
|
138
|
+
this._name = this._name.slice(0, -3);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Return argument name.
|
|
143
|
+
*
|
|
144
|
+
* @return {string}
|
|
145
|
+
*/
|
|
146
|
+
name() {
|
|
147
|
+
return this._name;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* @package
|
|
151
|
+
*/
|
|
152
|
+
_concatValue(value, previous) {
|
|
153
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
154
|
+
return [value];
|
|
155
|
+
}
|
|
156
|
+
return previous.concat(value);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
160
|
+
*
|
|
161
|
+
* @param {*} value
|
|
162
|
+
* @param {string} [description]
|
|
163
|
+
* @return {Argument}
|
|
164
|
+
*/
|
|
165
|
+
default(value, description) {
|
|
166
|
+
this.defaultValue = value;
|
|
167
|
+
this.defaultValueDescription = description;
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Set the custom handler for processing CLI command arguments into argument values.
|
|
172
|
+
*
|
|
173
|
+
* @param {Function} [fn]
|
|
174
|
+
* @return {Argument}
|
|
175
|
+
*/
|
|
176
|
+
argParser(fn) {
|
|
177
|
+
this.parseArg = fn;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Only allow argument value to be one of choices.
|
|
182
|
+
*
|
|
183
|
+
* @param {string[]} values
|
|
184
|
+
* @return {Argument}
|
|
185
|
+
*/
|
|
186
|
+
choices(values) {
|
|
187
|
+
this.argChoices = values.slice();
|
|
188
|
+
this.parseArg = (arg, previous) => {
|
|
189
|
+
if (!this.argChoices.includes(arg)) {
|
|
190
|
+
throw new InvalidArgumentError2(
|
|
191
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
if (this.variadic) {
|
|
195
|
+
return this._concatValue(arg, previous);
|
|
196
|
+
}
|
|
197
|
+
return arg;
|
|
198
|
+
};
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Make argument required.
|
|
203
|
+
*
|
|
204
|
+
* @returns {Argument}
|
|
205
|
+
*/
|
|
206
|
+
argRequired() {
|
|
207
|
+
this.required = true;
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Make argument optional.
|
|
212
|
+
*
|
|
213
|
+
* @returns {Argument}
|
|
214
|
+
*/
|
|
215
|
+
argOptional() {
|
|
216
|
+
this.required = false;
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
function humanReadableArgName(arg) {
|
|
221
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
222
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
223
|
+
}
|
|
224
|
+
exports.Argument = Argument2;
|
|
225
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/help.js
|
|
230
|
+
var require_help = __commonJS({
|
|
231
|
+
"../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/help.js"(exports) {
|
|
232
|
+
"use strict";
|
|
233
|
+
init_esm();
|
|
234
|
+
var { humanReadableArgName } = require_argument();
|
|
235
|
+
var Help2 = class {
|
|
236
|
+
constructor() {
|
|
237
|
+
this.helpWidth = void 0;
|
|
238
|
+
this.sortSubcommands = false;
|
|
239
|
+
this.sortOptions = false;
|
|
240
|
+
this.showGlobalOptions = false;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
244
|
+
*
|
|
245
|
+
* @param {Command} cmd
|
|
246
|
+
* @returns {Command[]}
|
|
247
|
+
*/
|
|
248
|
+
visibleCommands(cmd) {
|
|
249
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
250
|
+
const helpCommand = cmd._getHelpCommand();
|
|
251
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
252
|
+
visibleCommands.push(helpCommand);
|
|
253
|
+
}
|
|
254
|
+
if (this.sortSubcommands) {
|
|
255
|
+
visibleCommands.sort((a, b) => {
|
|
256
|
+
return a.name().localeCompare(b.name());
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return visibleCommands;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Compare options for sort.
|
|
263
|
+
*
|
|
264
|
+
* @param {Option} a
|
|
265
|
+
* @param {Option} b
|
|
266
|
+
* @returns {number}
|
|
267
|
+
*/
|
|
268
|
+
compareOptions(a, b) {
|
|
269
|
+
const getSortKey = (option) => {
|
|
270
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
271
|
+
};
|
|
272
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
276
|
+
*
|
|
277
|
+
* @param {Command} cmd
|
|
278
|
+
* @returns {Option[]}
|
|
279
|
+
*/
|
|
280
|
+
visibleOptions(cmd) {
|
|
281
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
282
|
+
const helpOption = cmd._getHelpOption();
|
|
283
|
+
if (helpOption && !helpOption.hidden) {
|
|
284
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
285
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
286
|
+
if (!removeShort && !removeLong) {
|
|
287
|
+
visibleOptions.push(helpOption);
|
|
288
|
+
} else if (helpOption.long && !removeLong) {
|
|
289
|
+
visibleOptions.push(
|
|
290
|
+
cmd.createOption(helpOption.long, helpOption.description)
|
|
291
|
+
);
|
|
292
|
+
} else if (helpOption.short && !removeShort) {
|
|
293
|
+
visibleOptions.push(
|
|
294
|
+
cmd.createOption(helpOption.short, helpOption.description)
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (this.sortOptions) {
|
|
299
|
+
visibleOptions.sort(this.compareOptions);
|
|
300
|
+
}
|
|
301
|
+
return visibleOptions;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Get an array of the visible global options. (Not including help.)
|
|
305
|
+
*
|
|
306
|
+
* @param {Command} cmd
|
|
307
|
+
* @returns {Option[]}
|
|
308
|
+
*/
|
|
309
|
+
visibleGlobalOptions(cmd) {
|
|
310
|
+
if (!this.showGlobalOptions)
|
|
311
|
+
return [];
|
|
312
|
+
const globalOptions = [];
|
|
313
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
314
|
+
const visibleOptions = ancestorCmd.options.filter(
|
|
315
|
+
(option) => !option.hidden
|
|
316
|
+
);
|
|
317
|
+
globalOptions.push(...visibleOptions);
|
|
318
|
+
}
|
|
319
|
+
if (this.sortOptions) {
|
|
320
|
+
globalOptions.sort(this.compareOptions);
|
|
321
|
+
}
|
|
322
|
+
return globalOptions;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get an array of the arguments if any have a description.
|
|
326
|
+
*
|
|
327
|
+
* @param {Command} cmd
|
|
328
|
+
* @returns {Argument[]}
|
|
329
|
+
*/
|
|
330
|
+
visibleArguments(cmd) {
|
|
331
|
+
if (cmd._argsDescription) {
|
|
332
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
333
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
337
|
+
return cmd.registeredArguments;
|
|
338
|
+
}
|
|
339
|
+
return [];
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Get the command term to show in the list of subcommands.
|
|
343
|
+
*
|
|
344
|
+
* @param {Command} cmd
|
|
345
|
+
* @returns {string}
|
|
346
|
+
*/
|
|
347
|
+
subcommandTerm(cmd) {
|
|
348
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
349
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
|
|
350
|
+
(args ? " " + args : "");
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Get the option term to show in the list of options.
|
|
354
|
+
*
|
|
355
|
+
* @param {Option} option
|
|
356
|
+
* @returns {string}
|
|
357
|
+
*/
|
|
358
|
+
optionTerm(option) {
|
|
359
|
+
return option.flags;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Get the argument term to show in the list of arguments.
|
|
363
|
+
*
|
|
364
|
+
* @param {Argument} argument
|
|
365
|
+
* @returns {string}
|
|
366
|
+
*/
|
|
367
|
+
argumentTerm(argument) {
|
|
368
|
+
return argument.name();
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Get the longest command term length.
|
|
372
|
+
*
|
|
373
|
+
* @param {Command} cmd
|
|
374
|
+
* @param {Help} helper
|
|
375
|
+
* @returns {number}
|
|
376
|
+
*/
|
|
377
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
378
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
379
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
380
|
+
}, 0);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get the longest option term length.
|
|
384
|
+
*
|
|
385
|
+
* @param {Command} cmd
|
|
386
|
+
* @param {Help} helper
|
|
387
|
+
* @returns {number}
|
|
388
|
+
*/
|
|
389
|
+
longestOptionTermLength(cmd, helper) {
|
|
390
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
391
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
392
|
+
}, 0);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Get the longest global option term length.
|
|
396
|
+
*
|
|
397
|
+
* @param {Command} cmd
|
|
398
|
+
* @param {Help} helper
|
|
399
|
+
* @returns {number}
|
|
400
|
+
*/
|
|
401
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
402
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
403
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
404
|
+
}, 0);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Get the longest argument term length.
|
|
408
|
+
*
|
|
409
|
+
* @param {Command} cmd
|
|
410
|
+
* @param {Help} helper
|
|
411
|
+
* @returns {number}
|
|
412
|
+
*/
|
|
413
|
+
longestArgumentTermLength(cmd, helper) {
|
|
414
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
415
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
416
|
+
}, 0);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Get the command usage to be displayed at the top of the built-in help.
|
|
420
|
+
*
|
|
421
|
+
* @param {Command} cmd
|
|
422
|
+
* @returns {string}
|
|
423
|
+
*/
|
|
424
|
+
commandUsage(cmd) {
|
|
425
|
+
let cmdName = cmd._name;
|
|
426
|
+
if (cmd._aliases[0]) {
|
|
427
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
428
|
+
}
|
|
429
|
+
let ancestorCmdNames = "";
|
|
430
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
431
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
432
|
+
}
|
|
433
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Get the description for the command.
|
|
437
|
+
*
|
|
438
|
+
* @param {Command} cmd
|
|
439
|
+
* @returns {string}
|
|
440
|
+
*/
|
|
441
|
+
commandDescription(cmd) {
|
|
442
|
+
return cmd.description();
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Get the subcommand summary to show in the list of subcommands.
|
|
446
|
+
* (Fallback to description for backwards compatibility.)
|
|
447
|
+
*
|
|
448
|
+
* @param {Command} cmd
|
|
449
|
+
* @returns {string}
|
|
450
|
+
*/
|
|
451
|
+
subcommandDescription(cmd) {
|
|
452
|
+
return cmd.summary() || cmd.description();
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Get the option description to show in the list of options.
|
|
456
|
+
*
|
|
457
|
+
* @param {Option} option
|
|
458
|
+
* @return {string}
|
|
459
|
+
*/
|
|
460
|
+
optionDescription(option) {
|
|
461
|
+
const extraInfo = [];
|
|
462
|
+
if (option.argChoices) {
|
|
463
|
+
extraInfo.push(
|
|
464
|
+
// use stringify to match the display of the default value
|
|
465
|
+
`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
if (option.defaultValue !== void 0) {
|
|
469
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
470
|
+
if (showDefault) {
|
|
471
|
+
extraInfo.push(
|
|
472
|
+
`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (option.presetArg !== void 0 && option.optional) {
|
|
477
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
478
|
+
}
|
|
479
|
+
if (option.envVar !== void 0) {
|
|
480
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
481
|
+
}
|
|
482
|
+
if (extraInfo.length > 0) {
|
|
483
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
484
|
+
}
|
|
485
|
+
return option.description;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Get the argument description to show in the list of arguments.
|
|
489
|
+
*
|
|
490
|
+
* @param {Argument} argument
|
|
491
|
+
* @return {string}
|
|
492
|
+
*/
|
|
493
|
+
argumentDescription(argument) {
|
|
494
|
+
const extraInfo = [];
|
|
495
|
+
if (argument.argChoices) {
|
|
496
|
+
extraInfo.push(
|
|
497
|
+
// use stringify to match the display of the default value
|
|
498
|
+
`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
if (argument.defaultValue !== void 0) {
|
|
502
|
+
extraInfo.push(
|
|
503
|
+
`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
if (extraInfo.length > 0) {
|
|
507
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
508
|
+
if (argument.description) {
|
|
509
|
+
return `${argument.description} ${extraDescripton}`;
|
|
510
|
+
}
|
|
511
|
+
return extraDescripton;
|
|
512
|
+
}
|
|
513
|
+
return argument.description;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Generate the built-in help text.
|
|
517
|
+
*
|
|
518
|
+
* @param {Command} cmd
|
|
519
|
+
* @param {Help} helper
|
|
520
|
+
* @returns {string}
|
|
521
|
+
*/
|
|
522
|
+
formatHelp(cmd, helper) {
|
|
523
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
524
|
+
const helpWidth = helper.helpWidth || 80;
|
|
525
|
+
const itemIndentWidth = 2;
|
|
526
|
+
const itemSeparatorWidth = 2;
|
|
527
|
+
function formatItem(term, description) {
|
|
528
|
+
if (description) {
|
|
529
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
530
|
+
return helper.wrap(
|
|
531
|
+
fullText,
|
|
532
|
+
helpWidth - itemIndentWidth,
|
|
533
|
+
termWidth + itemSeparatorWidth
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
return term;
|
|
537
|
+
}
|
|
538
|
+
function formatList(textArray) {
|
|
539
|
+
return textArray.join("\n").replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
540
|
+
}
|
|
541
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
542
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
543
|
+
if (commandDescription.length > 0) {
|
|
544
|
+
output = output.concat([
|
|
545
|
+
helper.wrap(commandDescription, helpWidth, 0),
|
|
546
|
+
""
|
|
547
|
+
]);
|
|
548
|
+
}
|
|
549
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
550
|
+
return formatItem(
|
|
551
|
+
helper.argumentTerm(argument),
|
|
552
|
+
helper.argumentDescription(argument)
|
|
553
|
+
);
|
|
554
|
+
});
|
|
555
|
+
if (argumentList.length > 0) {
|
|
556
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
557
|
+
}
|
|
558
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
559
|
+
return formatItem(
|
|
560
|
+
helper.optionTerm(option),
|
|
561
|
+
helper.optionDescription(option)
|
|
562
|
+
);
|
|
563
|
+
});
|
|
564
|
+
if (optionList.length > 0) {
|
|
565
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
566
|
+
}
|
|
567
|
+
if (this.showGlobalOptions) {
|
|
568
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
569
|
+
return formatItem(
|
|
570
|
+
helper.optionTerm(option),
|
|
571
|
+
helper.optionDescription(option)
|
|
572
|
+
);
|
|
573
|
+
});
|
|
574
|
+
if (globalOptionList.length > 0) {
|
|
575
|
+
output = output.concat([
|
|
576
|
+
"Global Options:",
|
|
577
|
+
formatList(globalOptionList),
|
|
578
|
+
""
|
|
579
|
+
]);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
583
|
+
return formatItem(
|
|
584
|
+
helper.subcommandTerm(cmd2),
|
|
585
|
+
helper.subcommandDescription(cmd2)
|
|
586
|
+
);
|
|
587
|
+
});
|
|
588
|
+
if (commandList.length > 0) {
|
|
589
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
590
|
+
}
|
|
591
|
+
return output.join("\n");
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Calculate the pad width from the maximum term length.
|
|
595
|
+
*
|
|
596
|
+
* @param {Command} cmd
|
|
597
|
+
* @param {Help} helper
|
|
598
|
+
* @returns {number}
|
|
599
|
+
*/
|
|
600
|
+
padWidth(cmd, helper) {
|
|
601
|
+
return Math.max(
|
|
602
|
+
helper.longestOptionTermLength(cmd, helper),
|
|
603
|
+
helper.longestGlobalOptionTermLength(cmd, helper),
|
|
604
|
+
helper.longestSubcommandTermLength(cmd, helper),
|
|
605
|
+
helper.longestArgumentTermLength(cmd, helper)
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Wrap the given string to width characters per line, with lines after the first indented.
|
|
610
|
+
* Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
|
|
611
|
+
*
|
|
612
|
+
* @param {string} str
|
|
613
|
+
* @param {number} width
|
|
614
|
+
* @param {number} indent
|
|
615
|
+
* @param {number} [minColumnWidth=40]
|
|
616
|
+
* @return {string}
|
|
617
|
+
*
|
|
618
|
+
*/
|
|
619
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
620
|
+
const indents = " \\f\\t\\v - \uFEFF";
|
|
621
|
+
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
622
|
+
if (str.match(manualIndent))
|
|
623
|
+
return str;
|
|
624
|
+
const columnWidth = width - indent;
|
|
625
|
+
if (columnWidth < minColumnWidth)
|
|
626
|
+
return str;
|
|
627
|
+
const leadingStr = str.slice(0, indent);
|
|
628
|
+
const columnText = str.slice(indent).replace("\r\n", "\n");
|
|
629
|
+
const indentString = " ".repeat(indent);
|
|
630
|
+
const zeroWidthSpace = "";
|
|
631
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
632
|
+
const regex = new RegExp(
|
|
633
|
+
`
|
|
634
|
+
|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`,
|
|
635
|
+
"g"
|
|
636
|
+
);
|
|
637
|
+
const lines = columnText.match(regex) || [];
|
|
638
|
+
return leadingStr + lines.map((line, i) => {
|
|
639
|
+
if (line === "\n")
|
|
640
|
+
return "";
|
|
641
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
642
|
+
}).join("\n");
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
exports.Help = Help2;
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/option.js
|
|
650
|
+
var require_option = __commonJS({
|
|
651
|
+
"../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/option.js"(exports) {
|
|
652
|
+
"use strict";
|
|
653
|
+
init_esm();
|
|
654
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
655
|
+
var Option2 = class {
|
|
656
|
+
/**
|
|
657
|
+
* Initialize a new `Option` with the given `flags` and `description`.
|
|
658
|
+
*
|
|
659
|
+
* @param {string} flags
|
|
660
|
+
* @param {string} [description]
|
|
661
|
+
*/
|
|
662
|
+
constructor(flags, description) {
|
|
663
|
+
this.flags = flags;
|
|
664
|
+
this.description = description || "";
|
|
665
|
+
this.required = flags.includes("<");
|
|
666
|
+
this.optional = flags.includes("[");
|
|
667
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
668
|
+
this.mandatory = false;
|
|
669
|
+
const optionFlags = splitOptionFlags(flags);
|
|
670
|
+
this.short = optionFlags.shortFlag;
|
|
671
|
+
this.long = optionFlags.longFlag;
|
|
672
|
+
this.negate = false;
|
|
673
|
+
if (this.long) {
|
|
674
|
+
this.negate = this.long.startsWith("--no-");
|
|
675
|
+
}
|
|
676
|
+
this.defaultValue = void 0;
|
|
677
|
+
this.defaultValueDescription = void 0;
|
|
678
|
+
this.presetArg = void 0;
|
|
679
|
+
this.envVar = void 0;
|
|
680
|
+
this.parseArg = void 0;
|
|
681
|
+
this.hidden = false;
|
|
682
|
+
this.argChoices = void 0;
|
|
683
|
+
this.conflictsWith = [];
|
|
684
|
+
this.implied = void 0;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
688
|
+
*
|
|
689
|
+
* @param {*} value
|
|
690
|
+
* @param {string} [description]
|
|
691
|
+
* @return {Option}
|
|
692
|
+
*/
|
|
693
|
+
default(value, description) {
|
|
694
|
+
this.defaultValue = value;
|
|
695
|
+
this.defaultValueDescription = description;
|
|
696
|
+
return this;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Preset to use when option used without option-argument, especially optional but also boolean and negated.
|
|
700
|
+
* The custom processing (parseArg) is called.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* new Option('--color').default('GREYSCALE').preset('RGB');
|
|
704
|
+
* new Option('--donate [amount]').preset('20').argParser(parseFloat);
|
|
705
|
+
*
|
|
706
|
+
* @param {*} arg
|
|
707
|
+
* @return {Option}
|
|
708
|
+
*/
|
|
709
|
+
preset(arg) {
|
|
710
|
+
this.presetArg = arg;
|
|
711
|
+
return this;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Add option name(s) that conflict with this option.
|
|
715
|
+
* An error will be displayed if conflicting options are found during parsing.
|
|
716
|
+
*
|
|
717
|
+
* @example
|
|
718
|
+
* new Option('--rgb').conflicts('cmyk');
|
|
719
|
+
* new Option('--js').conflicts(['ts', 'jsx']);
|
|
720
|
+
*
|
|
721
|
+
* @param {(string | string[])} names
|
|
722
|
+
* @return {Option}
|
|
723
|
+
*/
|
|
724
|
+
conflicts(names) {
|
|
725
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
726
|
+
return this;
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Specify implied option values for when this option is set and the implied options are not.
|
|
730
|
+
*
|
|
731
|
+
* The custom processing (parseArg) is not called on the implied values.
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* program
|
|
735
|
+
* .addOption(new Option('--log', 'write logging information to file'))
|
|
736
|
+
* .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
|
|
737
|
+
*
|
|
738
|
+
* @param {object} impliedOptionValues
|
|
739
|
+
* @return {Option}
|
|
740
|
+
*/
|
|
741
|
+
implies(impliedOptionValues) {
|
|
742
|
+
let newImplied = impliedOptionValues;
|
|
743
|
+
if (typeof impliedOptionValues === "string") {
|
|
744
|
+
newImplied = { [impliedOptionValues]: true };
|
|
745
|
+
}
|
|
746
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
747
|
+
return this;
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Set environment variable to check for option value.
|
|
751
|
+
*
|
|
752
|
+
* An environment variable is only used if when processed the current option value is
|
|
753
|
+
* undefined, or the source of the current value is 'default' or 'config' or 'env'.
|
|
754
|
+
*
|
|
755
|
+
* @param {string} name
|
|
756
|
+
* @return {Option}
|
|
757
|
+
*/
|
|
758
|
+
env(name) {
|
|
759
|
+
this.envVar = name;
|
|
760
|
+
return this;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Set the custom handler for processing CLI option arguments into option values.
|
|
764
|
+
*
|
|
765
|
+
* @param {Function} [fn]
|
|
766
|
+
* @return {Option}
|
|
767
|
+
*/
|
|
768
|
+
argParser(fn) {
|
|
769
|
+
this.parseArg = fn;
|
|
770
|
+
return this;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Whether the option is mandatory and must have a value after parsing.
|
|
774
|
+
*
|
|
775
|
+
* @param {boolean} [mandatory=true]
|
|
776
|
+
* @return {Option}
|
|
777
|
+
*/
|
|
778
|
+
makeOptionMandatory(mandatory = true) {
|
|
779
|
+
this.mandatory = !!mandatory;
|
|
780
|
+
return this;
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Hide option in help.
|
|
784
|
+
*
|
|
785
|
+
* @param {boolean} [hide=true]
|
|
786
|
+
* @return {Option}
|
|
787
|
+
*/
|
|
788
|
+
hideHelp(hide = true) {
|
|
789
|
+
this.hidden = !!hide;
|
|
790
|
+
return this;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* @package
|
|
794
|
+
*/
|
|
795
|
+
_concatValue(value, previous) {
|
|
796
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
797
|
+
return [value];
|
|
798
|
+
}
|
|
799
|
+
return previous.concat(value);
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Only allow option value to be one of choices.
|
|
803
|
+
*
|
|
804
|
+
* @param {string[]} values
|
|
805
|
+
* @return {Option}
|
|
806
|
+
*/
|
|
807
|
+
choices(values) {
|
|
808
|
+
this.argChoices = values.slice();
|
|
809
|
+
this.parseArg = (arg, previous) => {
|
|
810
|
+
if (!this.argChoices.includes(arg)) {
|
|
811
|
+
throw new InvalidArgumentError2(
|
|
812
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
if (this.variadic) {
|
|
816
|
+
return this._concatValue(arg, previous);
|
|
817
|
+
}
|
|
818
|
+
return arg;
|
|
819
|
+
};
|
|
820
|
+
return this;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Return option name.
|
|
824
|
+
*
|
|
825
|
+
* @return {string}
|
|
826
|
+
*/
|
|
827
|
+
name() {
|
|
828
|
+
if (this.long) {
|
|
829
|
+
return this.long.replace(/^--/, "");
|
|
830
|
+
}
|
|
831
|
+
return this.short.replace(/^-/, "");
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Return option name, in a camelcase format that can be used
|
|
835
|
+
* as a object attribute key.
|
|
836
|
+
*
|
|
837
|
+
* @return {string}
|
|
838
|
+
*/
|
|
839
|
+
attributeName() {
|
|
840
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Check if `arg` matches the short or long flag.
|
|
844
|
+
*
|
|
845
|
+
* @param {string} arg
|
|
846
|
+
* @return {boolean}
|
|
847
|
+
* @package
|
|
848
|
+
*/
|
|
849
|
+
is(arg) {
|
|
850
|
+
return this.short === arg || this.long === arg;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Return whether a boolean option.
|
|
854
|
+
*
|
|
855
|
+
* Options are one of boolean, negated, required argument, or optional argument.
|
|
856
|
+
*
|
|
857
|
+
* @return {boolean}
|
|
858
|
+
* @package
|
|
859
|
+
*/
|
|
860
|
+
isBoolean() {
|
|
861
|
+
return !this.required && !this.optional && !this.negate;
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
var DualOptions = class {
|
|
865
|
+
/**
|
|
866
|
+
* @param {Option[]} options
|
|
867
|
+
*/
|
|
868
|
+
constructor(options) {
|
|
869
|
+
this.positiveOptions = /* @__PURE__ */ new Map();
|
|
870
|
+
this.negativeOptions = /* @__PURE__ */ new Map();
|
|
871
|
+
this.dualOptions = /* @__PURE__ */ new Set();
|
|
872
|
+
options.forEach((option) => {
|
|
873
|
+
if (option.negate) {
|
|
874
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
875
|
+
} else {
|
|
876
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
this.negativeOptions.forEach((value, key) => {
|
|
880
|
+
if (this.positiveOptions.has(key)) {
|
|
881
|
+
this.dualOptions.add(key);
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Did the value come from the option, and not from possible matching dual option?
|
|
887
|
+
*
|
|
888
|
+
* @param {*} value
|
|
889
|
+
* @param {Option} option
|
|
890
|
+
* @returns {boolean}
|
|
891
|
+
*/
|
|
892
|
+
valueFromOption(value, option) {
|
|
893
|
+
const optionKey = option.attributeName();
|
|
894
|
+
if (!this.dualOptions.has(optionKey))
|
|
895
|
+
return true;
|
|
896
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
897
|
+
const negativeValue = preset !== void 0 ? preset : false;
|
|
898
|
+
return option.negate === (negativeValue === value);
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
function camelcase(str) {
|
|
902
|
+
return str.split("-").reduce((str2, word) => {
|
|
903
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
function splitOptionFlags(flags) {
|
|
907
|
+
let shortFlag;
|
|
908
|
+
let longFlag;
|
|
909
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
910
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
911
|
+
shortFlag = flagParts.shift();
|
|
912
|
+
longFlag = flagParts.shift();
|
|
913
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
914
|
+
shortFlag = longFlag;
|
|
915
|
+
longFlag = void 0;
|
|
916
|
+
}
|
|
917
|
+
return { shortFlag, longFlag };
|
|
918
|
+
}
|
|
919
|
+
exports.Option = Option2;
|
|
920
|
+
exports.DualOptions = DualOptions;
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/suggestSimilar.js
|
|
925
|
+
var require_suggestSimilar = __commonJS({
|
|
926
|
+
"../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/suggestSimilar.js"(exports) {
|
|
927
|
+
"use strict";
|
|
928
|
+
init_esm();
|
|
929
|
+
var maxDistance = 3;
|
|
930
|
+
function editDistance(a, b) {
|
|
931
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
932
|
+
return Math.max(a.length, b.length);
|
|
933
|
+
const d = [];
|
|
934
|
+
for (let i = 0; i <= a.length; i++) {
|
|
935
|
+
d[i] = [i];
|
|
936
|
+
}
|
|
937
|
+
for (let j = 0; j <= b.length; j++) {
|
|
938
|
+
d[0][j] = j;
|
|
939
|
+
}
|
|
940
|
+
for (let j = 1; j <= b.length; j++) {
|
|
941
|
+
for (let i = 1; i <= a.length; i++) {
|
|
942
|
+
let cost = 1;
|
|
943
|
+
if (a[i - 1] === b[j - 1]) {
|
|
944
|
+
cost = 0;
|
|
945
|
+
} else {
|
|
946
|
+
cost = 1;
|
|
947
|
+
}
|
|
948
|
+
d[i][j] = Math.min(
|
|
949
|
+
d[i - 1][j] + 1,
|
|
950
|
+
// deletion
|
|
951
|
+
d[i][j - 1] + 1,
|
|
952
|
+
// insertion
|
|
953
|
+
d[i - 1][j - 1] + cost
|
|
954
|
+
// substitution
|
|
955
|
+
);
|
|
956
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
957
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
return d[a.length][b.length];
|
|
962
|
+
}
|
|
963
|
+
function suggestSimilar(word, candidates) {
|
|
964
|
+
if (!candidates || candidates.length === 0)
|
|
965
|
+
return "";
|
|
966
|
+
candidates = Array.from(new Set(candidates));
|
|
967
|
+
const searchingOptions = word.startsWith("--");
|
|
968
|
+
if (searchingOptions) {
|
|
969
|
+
word = word.slice(2);
|
|
970
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
971
|
+
}
|
|
972
|
+
let similar = [];
|
|
973
|
+
let bestDistance = maxDistance;
|
|
974
|
+
const minSimilarity = 0.4;
|
|
975
|
+
candidates.forEach((candidate) => {
|
|
976
|
+
if (candidate.length <= 1)
|
|
977
|
+
return;
|
|
978
|
+
const distance = editDistance(word, candidate);
|
|
979
|
+
const length = Math.max(word.length, candidate.length);
|
|
980
|
+
const similarity = (length - distance) / length;
|
|
981
|
+
if (similarity > minSimilarity) {
|
|
982
|
+
if (distance < bestDistance) {
|
|
983
|
+
bestDistance = distance;
|
|
984
|
+
similar = [candidate];
|
|
985
|
+
} else if (distance === bestDistance) {
|
|
986
|
+
similar.push(candidate);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
991
|
+
if (searchingOptions) {
|
|
992
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
993
|
+
}
|
|
994
|
+
if (similar.length > 1) {
|
|
995
|
+
return `
|
|
996
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
997
|
+
}
|
|
998
|
+
if (similar.length === 1) {
|
|
999
|
+
return `
|
|
1000
|
+
(Did you mean ${similar[0]}?)`;
|
|
1001
|
+
}
|
|
1002
|
+
return "";
|
|
1003
|
+
}
|
|
1004
|
+
exports.suggestSimilar = suggestSimilar;
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js
|
|
1009
|
+
var require_command = __commonJS({
|
|
1010
|
+
"../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js"(exports) {
|
|
1011
|
+
"use strict";
|
|
1012
|
+
init_esm();
|
|
1013
|
+
var EventEmitter = __require("events").EventEmitter;
|
|
1014
|
+
var childProcess = __require("child_process");
|
|
1015
|
+
var path22 = __require("path");
|
|
1016
|
+
var fs12 = __require("fs");
|
|
1017
|
+
var process2 = __require("process");
|
|
1018
|
+
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
1019
|
+
var { CommanderError: CommanderError2 } = require_error();
|
|
1020
|
+
var { Help: Help2 } = require_help();
|
|
1021
|
+
var { Option: Option2, DualOptions } = require_option();
|
|
1022
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
1023
|
+
var Command2 = class _Command extends EventEmitter {
|
|
1024
|
+
/**
|
|
1025
|
+
* Initialize a new `Command`.
|
|
1026
|
+
*
|
|
1027
|
+
* @param {string} [name]
|
|
1028
|
+
*/
|
|
1029
|
+
constructor(name) {
|
|
1030
|
+
super();
|
|
1031
|
+
this.commands = [];
|
|
1032
|
+
this.options = [];
|
|
1033
|
+
this.parent = null;
|
|
1034
|
+
this._allowUnknownOption = false;
|
|
1035
|
+
this._allowExcessArguments = true;
|
|
1036
|
+
this.registeredArguments = [];
|
|
1037
|
+
this._args = this.registeredArguments;
|
|
1038
|
+
this.args = [];
|
|
1039
|
+
this.rawArgs = [];
|
|
1040
|
+
this.processedArgs = [];
|
|
1041
|
+
this._scriptPath = null;
|
|
1042
|
+
this._name = name || "";
|
|
1043
|
+
this._optionValues = {};
|
|
1044
|
+
this._optionValueSources = {};
|
|
1045
|
+
this._storeOptionsAsProperties = false;
|
|
1046
|
+
this._actionHandler = null;
|
|
1047
|
+
this._executableHandler = false;
|
|
1048
|
+
this._executableFile = null;
|
|
1049
|
+
this._executableDir = null;
|
|
1050
|
+
this._defaultCommandName = null;
|
|
1051
|
+
this._exitCallback = null;
|
|
1052
|
+
this._aliases = [];
|
|
1053
|
+
this._combineFlagAndOptionalValue = true;
|
|
1054
|
+
this._description = "";
|
|
1055
|
+
this._summary = "";
|
|
1056
|
+
this._argsDescription = void 0;
|
|
1057
|
+
this._enablePositionalOptions = false;
|
|
1058
|
+
this._passThroughOptions = false;
|
|
1059
|
+
this._lifeCycleHooks = {};
|
|
1060
|
+
this._showHelpAfterError = false;
|
|
1061
|
+
this._showSuggestionAfterError = true;
|
|
1062
|
+
this._outputConfiguration = {
|
|
1063
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
1064
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
1065
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : void 0,
|
|
1066
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : void 0,
|
|
1067
|
+
outputError: (str, write) => write(str)
|
|
1068
|
+
};
|
|
1069
|
+
this._hidden = false;
|
|
1070
|
+
this._helpOption = void 0;
|
|
1071
|
+
this._addImplicitHelpCommand = void 0;
|
|
1072
|
+
this._helpCommand = void 0;
|
|
1073
|
+
this._helpConfiguration = {};
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Copy settings that are useful to have in common across root command and subcommands.
|
|
1077
|
+
*
|
|
1078
|
+
* (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
|
|
1079
|
+
*
|
|
1080
|
+
* @param {Command} sourceCommand
|
|
1081
|
+
* @return {Command} `this` command for chaining
|
|
1082
|
+
*/
|
|
1083
|
+
copyInheritedSettings(sourceCommand) {
|
|
1084
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
1085
|
+
this._helpOption = sourceCommand._helpOption;
|
|
1086
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
1087
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
1088
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
1089
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
1090
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
1091
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
1092
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
1093
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
1094
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
1095
|
+
return this;
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* @returns {Command[]}
|
|
1099
|
+
* @private
|
|
1100
|
+
*/
|
|
1101
|
+
_getCommandAndAncestors() {
|
|
1102
|
+
const result = [];
|
|
1103
|
+
for (let command = this; command; command = command.parent) {
|
|
1104
|
+
result.push(command);
|
|
1105
|
+
}
|
|
1106
|
+
return result;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Define a command.
|
|
1110
|
+
*
|
|
1111
|
+
* There are two styles of command: pay attention to where to put the description.
|
|
1112
|
+
*
|
|
1113
|
+
* @example
|
|
1114
|
+
* // Command implemented using action handler (description is supplied separately to `.command`)
|
|
1115
|
+
* program
|
|
1116
|
+
* .command('clone <source> [destination]')
|
|
1117
|
+
* .description('clone a repository into a newly created directory')
|
|
1118
|
+
* .action((source, destination) => {
|
|
1119
|
+
* console.log('clone command called');
|
|
1120
|
+
* });
|
|
1121
|
+
*
|
|
1122
|
+
* // Command implemented using separate executable file (description is second parameter to `.command`)
|
|
1123
|
+
* program
|
|
1124
|
+
* .command('start <service>', 'start named service')
|
|
1125
|
+
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
1126
|
+
*
|
|
1127
|
+
* @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
1128
|
+
* @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
|
|
1129
|
+
* @param {object} [execOpts] - configuration options (for executable)
|
|
1130
|
+
* @return {Command} returns new command for action handler, or `this` for executable command
|
|
1131
|
+
*/
|
|
1132
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
1133
|
+
let desc = actionOptsOrExecDesc;
|
|
1134
|
+
let opts = execOpts;
|
|
1135
|
+
if (typeof desc === "object" && desc !== null) {
|
|
1136
|
+
opts = desc;
|
|
1137
|
+
desc = null;
|
|
1138
|
+
}
|
|
1139
|
+
opts = opts || {};
|
|
1140
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1141
|
+
const cmd = this.createCommand(name);
|
|
1142
|
+
if (desc) {
|
|
1143
|
+
cmd.description(desc);
|
|
1144
|
+
cmd._executableHandler = true;
|
|
1145
|
+
}
|
|
1146
|
+
if (opts.isDefault)
|
|
1147
|
+
this._defaultCommandName = cmd._name;
|
|
1148
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
1149
|
+
cmd._executableFile = opts.executableFile || null;
|
|
1150
|
+
if (args)
|
|
1151
|
+
cmd.arguments(args);
|
|
1152
|
+
this._registerCommand(cmd);
|
|
1153
|
+
cmd.parent = this;
|
|
1154
|
+
cmd.copyInheritedSettings(this);
|
|
1155
|
+
if (desc)
|
|
1156
|
+
return this;
|
|
1157
|
+
return cmd;
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Factory routine to create a new unattached command.
|
|
1161
|
+
*
|
|
1162
|
+
* See .command() for creating an attached subcommand, which uses this routine to
|
|
1163
|
+
* create the command. You can override createCommand to customise subcommands.
|
|
1164
|
+
*
|
|
1165
|
+
* @param {string} [name]
|
|
1166
|
+
* @return {Command} new command
|
|
1167
|
+
*/
|
|
1168
|
+
createCommand(name) {
|
|
1169
|
+
return new _Command(name);
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* You can customise the help with a subclass of Help by overriding createHelp,
|
|
1173
|
+
* or by overriding Help properties using configureHelp().
|
|
1174
|
+
*
|
|
1175
|
+
* @return {Help}
|
|
1176
|
+
*/
|
|
1177
|
+
createHelp() {
|
|
1178
|
+
return Object.assign(new Help2(), this.configureHelp());
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* You can customise the help by overriding Help properties using configureHelp(),
|
|
1182
|
+
* or with a subclass of Help by overriding createHelp().
|
|
1183
|
+
*
|
|
1184
|
+
* @param {object} [configuration] - configuration options
|
|
1185
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1186
|
+
*/
|
|
1187
|
+
configureHelp(configuration) {
|
|
1188
|
+
if (configuration === void 0)
|
|
1189
|
+
return this._helpConfiguration;
|
|
1190
|
+
this._helpConfiguration = configuration;
|
|
1191
|
+
return this;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* The default output goes to stdout and stderr. You can customise this for special
|
|
1195
|
+
* applications. You can also customise the display of errors by overriding outputError.
|
|
1196
|
+
*
|
|
1197
|
+
* The configuration properties are all functions:
|
|
1198
|
+
*
|
|
1199
|
+
* // functions to change where being written, stdout and stderr
|
|
1200
|
+
* writeOut(str)
|
|
1201
|
+
* writeErr(str)
|
|
1202
|
+
* // matching functions to specify width for wrapping help
|
|
1203
|
+
* getOutHelpWidth()
|
|
1204
|
+
* getErrHelpWidth()
|
|
1205
|
+
* // functions based on what is being written out
|
|
1206
|
+
* outputError(str, write) // used for displaying errors, and not used for displaying help
|
|
1207
|
+
*
|
|
1208
|
+
* @param {object} [configuration] - configuration options
|
|
1209
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1210
|
+
*/
|
|
1211
|
+
configureOutput(configuration) {
|
|
1212
|
+
if (configuration === void 0)
|
|
1213
|
+
return this._outputConfiguration;
|
|
1214
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
1215
|
+
return this;
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Display the help or a custom message after an error occurs.
|
|
1219
|
+
*
|
|
1220
|
+
* @param {(boolean|string)} [displayHelp]
|
|
1221
|
+
* @return {Command} `this` command for chaining
|
|
1222
|
+
*/
|
|
1223
|
+
showHelpAfterError(displayHelp = true) {
|
|
1224
|
+
if (typeof displayHelp !== "string")
|
|
1225
|
+
displayHelp = !!displayHelp;
|
|
1226
|
+
this._showHelpAfterError = displayHelp;
|
|
1227
|
+
return this;
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Display suggestion of similar commands for unknown commands, or options for unknown options.
|
|
1231
|
+
*
|
|
1232
|
+
* @param {boolean} [displaySuggestion]
|
|
1233
|
+
* @return {Command} `this` command for chaining
|
|
1234
|
+
*/
|
|
1235
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
1236
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
1237
|
+
return this;
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Add a prepared subcommand.
|
|
1241
|
+
*
|
|
1242
|
+
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
|
1243
|
+
*
|
|
1244
|
+
* @param {Command} cmd - new subcommand
|
|
1245
|
+
* @param {object} [opts] - configuration options
|
|
1246
|
+
* @return {Command} `this` command for chaining
|
|
1247
|
+
*/
|
|
1248
|
+
addCommand(cmd, opts) {
|
|
1249
|
+
if (!cmd._name) {
|
|
1250
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
1251
|
+
- specify the name in Command constructor or using .name()`);
|
|
1252
|
+
}
|
|
1253
|
+
opts = opts || {};
|
|
1254
|
+
if (opts.isDefault)
|
|
1255
|
+
this._defaultCommandName = cmd._name;
|
|
1256
|
+
if (opts.noHelp || opts.hidden)
|
|
1257
|
+
cmd._hidden = true;
|
|
1258
|
+
this._registerCommand(cmd);
|
|
1259
|
+
cmd.parent = this;
|
|
1260
|
+
cmd._checkForBrokenPassThrough();
|
|
1261
|
+
return this;
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Factory routine to create a new unattached argument.
|
|
1265
|
+
*
|
|
1266
|
+
* See .argument() for creating an attached argument, which uses this routine to
|
|
1267
|
+
* create the argument. You can override createArgument to return a custom argument.
|
|
1268
|
+
*
|
|
1269
|
+
* @param {string} name
|
|
1270
|
+
* @param {string} [description]
|
|
1271
|
+
* @return {Argument} new argument
|
|
1272
|
+
*/
|
|
1273
|
+
createArgument(name, description) {
|
|
1274
|
+
return new Argument2(name, description);
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Define argument syntax for command.
|
|
1278
|
+
*
|
|
1279
|
+
* The default is that the argument is required, and you can explicitly
|
|
1280
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
1281
|
+
*
|
|
1282
|
+
* @example
|
|
1283
|
+
* program.argument('<input-file>');
|
|
1284
|
+
* program.argument('[output-file]');
|
|
1285
|
+
*
|
|
1286
|
+
* @param {string} name
|
|
1287
|
+
* @param {string} [description]
|
|
1288
|
+
* @param {(Function|*)} [fn] - custom argument processing function
|
|
1289
|
+
* @param {*} [defaultValue]
|
|
1290
|
+
* @return {Command} `this` command for chaining
|
|
1291
|
+
*/
|
|
1292
|
+
argument(name, description, fn, defaultValue) {
|
|
1293
|
+
const argument = this.createArgument(name, description);
|
|
1294
|
+
if (typeof fn === "function") {
|
|
1295
|
+
argument.default(defaultValue).argParser(fn);
|
|
1296
|
+
} else {
|
|
1297
|
+
argument.default(fn);
|
|
1298
|
+
}
|
|
1299
|
+
this.addArgument(argument);
|
|
1300
|
+
return this;
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Define argument syntax for command, adding multiple at once (without descriptions).
|
|
1304
|
+
*
|
|
1305
|
+
* See also .argument().
|
|
1306
|
+
*
|
|
1307
|
+
* @example
|
|
1308
|
+
* program.arguments('<cmd> [env]');
|
|
1309
|
+
*
|
|
1310
|
+
* @param {string} names
|
|
1311
|
+
* @return {Command} `this` command for chaining
|
|
1312
|
+
*/
|
|
1313
|
+
arguments(names) {
|
|
1314
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
1315
|
+
this.argument(detail);
|
|
1316
|
+
});
|
|
1317
|
+
return this;
|
|
1318
|
+
}
|
|
1319
|
+
/**
|
|
1320
|
+
* Define argument syntax for command, adding a prepared argument.
|
|
1321
|
+
*
|
|
1322
|
+
* @param {Argument} argument
|
|
1323
|
+
* @return {Command} `this` command for chaining
|
|
1324
|
+
*/
|
|
1325
|
+
addArgument(argument) {
|
|
1326
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
1327
|
+
if (previousArgument && previousArgument.variadic) {
|
|
1328
|
+
throw new Error(
|
|
1329
|
+
`only the last argument can be variadic '${previousArgument.name()}'`
|
|
1330
|
+
);
|
|
1331
|
+
}
|
|
1332
|
+
if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
|
|
1333
|
+
throw new Error(
|
|
1334
|
+
`a default value for a required argument is never used: '${argument.name()}'`
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
this.registeredArguments.push(argument);
|
|
1338
|
+
return this;
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
|
|
1342
|
+
*
|
|
1343
|
+
* @example
|
|
1344
|
+
* program.helpCommand('help [cmd]');
|
|
1345
|
+
* program.helpCommand('help [cmd]', 'show help');
|
|
1346
|
+
* program.helpCommand(false); // suppress default help command
|
|
1347
|
+
* program.helpCommand(true); // add help command even if no subcommands
|
|
1348
|
+
*
|
|
1349
|
+
* @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
|
|
1350
|
+
* @param {string} [description] - custom description
|
|
1351
|
+
* @return {Command} `this` command for chaining
|
|
1352
|
+
*/
|
|
1353
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
1354
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
1355
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
1356
|
+
return this;
|
|
1357
|
+
}
|
|
1358
|
+
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
1359
|
+
const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1360
|
+
const helpDescription = description ?? "display help for command";
|
|
1361
|
+
const helpCommand = this.createCommand(helpName);
|
|
1362
|
+
helpCommand.helpOption(false);
|
|
1363
|
+
if (helpArgs)
|
|
1364
|
+
helpCommand.arguments(helpArgs);
|
|
1365
|
+
if (helpDescription)
|
|
1366
|
+
helpCommand.description(helpDescription);
|
|
1367
|
+
this._addImplicitHelpCommand = true;
|
|
1368
|
+
this._helpCommand = helpCommand;
|
|
1369
|
+
return this;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Add prepared custom help command.
|
|
1373
|
+
*
|
|
1374
|
+
* @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
|
|
1375
|
+
* @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
|
|
1376
|
+
* @return {Command} `this` command for chaining
|
|
1377
|
+
*/
|
|
1378
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
1379
|
+
if (typeof helpCommand !== "object") {
|
|
1380
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
1381
|
+
return this;
|
|
1382
|
+
}
|
|
1383
|
+
this._addImplicitHelpCommand = true;
|
|
1384
|
+
this._helpCommand = helpCommand;
|
|
1385
|
+
return this;
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Lazy create help command.
|
|
1389
|
+
*
|
|
1390
|
+
* @return {(Command|null)}
|
|
1391
|
+
* @package
|
|
1392
|
+
*/
|
|
1393
|
+
_getHelpCommand() {
|
|
1394
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
1395
|
+
if (hasImplicitHelpCommand) {
|
|
1396
|
+
if (this._helpCommand === void 0) {
|
|
1397
|
+
this.helpCommand(void 0, void 0);
|
|
1398
|
+
}
|
|
1399
|
+
return this._helpCommand;
|
|
1400
|
+
}
|
|
1401
|
+
return null;
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Add hook for life cycle event.
|
|
1405
|
+
*
|
|
1406
|
+
* @param {string} event
|
|
1407
|
+
* @param {Function} listener
|
|
1408
|
+
* @return {Command} `this` command for chaining
|
|
1409
|
+
*/
|
|
1410
|
+
hook(event, listener) {
|
|
1411
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
1412
|
+
if (!allowedValues.includes(event)) {
|
|
1413
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
1414
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1415
|
+
}
|
|
1416
|
+
if (this._lifeCycleHooks[event]) {
|
|
1417
|
+
this._lifeCycleHooks[event].push(listener);
|
|
1418
|
+
} else {
|
|
1419
|
+
this._lifeCycleHooks[event] = [listener];
|
|
1420
|
+
}
|
|
1421
|
+
return this;
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Register callback to use as replacement for calling process.exit.
|
|
1425
|
+
*
|
|
1426
|
+
* @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
|
|
1427
|
+
* @return {Command} `this` command for chaining
|
|
1428
|
+
*/
|
|
1429
|
+
exitOverride(fn) {
|
|
1430
|
+
if (fn) {
|
|
1431
|
+
this._exitCallback = fn;
|
|
1432
|
+
} else {
|
|
1433
|
+
this._exitCallback = (err) => {
|
|
1434
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
1435
|
+
throw err;
|
|
1436
|
+
} else {
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
return this;
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* Call process.exit, and _exitCallback if defined.
|
|
1444
|
+
*
|
|
1445
|
+
* @param {number} exitCode exit code for using with process.exit
|
|
1446
|
+
* @param {string} code an id string representing the error
|
|
1447
|
+
* @param {string} message human-readable description of the error
|
|
1448
|
+
* @return never
|
|
1449
|
+
* @private
|
|
1450
|
+
*/
|
|
1451
|
+
_exit(exitCode, code, message) {
|
|
1452
|
+
if (this._exitCallback) {
|
|
1453
|
+
this._exitCallback(new CommanderError2(exitCode, code, message));
|
|
1454
|
+
}
|
|
1455
|
+
process2.exit(exitCode);
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Register callback `fn` for the command.
|
|
1459
|
+
*
|
|
1460
|
+
* @example
|
|
1461
|
+
* program
|
|
1462
|
+
* .command('serve')
|
|
1463
|
+
* .description('start service')
|
|
1464
|
+
* .action(function() {
|
|
1465
|
+
* // do work here
|
|
1466
|
+
* });
|
|
1467
|
+
*
|
|
1468
|
+
* @param {Function} fn
|
|
1469
|
+
* @return {Command} `this` command for chaining
|
|
1470
|
+
*/
|
|
1471
|
+
action(fn) {
|
|
1472
|
+
const listener = (args) => {
|
|
1473
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
1474
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
1475
|
+
if (this._storeOptionsAsProperties) {
|
|
1476
|
+
actionArgs[expectedArgsCount] = this;
|
|
1477
|
+
} else {
|
|
1478
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
1479
|
+
}
|
|
1480
|
+
actionArgs.push(this);
|
|
1481
|
+
return fn.apply(this, actionArgs);
|
|
1482
|
+
};
|
|
1483
|
+
this._actionHandler = listener;
|
|
1484
|
+
return this;
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Factory routine to create a new unattached option.
|
|
1488
|
+
*
|
|
1489
|
+
* See .option() for creating an attached option, which uses this routine to
|
|
1490
|
+
* create the option. You can override createOption to return a custom option.
|
|
1491
|
+
*
|
|
1492
|
+
* @param {string} flags
|
|
1493
|
+
* @param {string} [description]
|
|
1494
|
+
* @return {Option} new option
|
|
1495
|
+
*/
|
|
1496
|
+
createOption(flags, description) {
|
|
1497
|
+
return new Option2(flags, description);
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Wrap parseArgs to catch 'commander.invalidArgument'.
|
|
1501
|
+
*
|
|
1502
|
+
* @param {(Option | Argument)} target
|
|
1503
|
+
* @param {string} value
|
|
1504
|
+
* @param {*} previous
|
|
1505
|
+
* @param {string} invalidArgumentMessage
|
|
1506
|
+
* @private
|
|
1507
|
+
*/
|
|
1508
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
1509
|
+
try {
|
|
1510
|
+
return target.parseArg(value, previous);
|
|
1511
|
+
} catch (err) {
|
|
1512
|
+
if (err.code === "commander.invalidArgument") {
|
|
1513
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
1514
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1515
|
+
}
|
|
1516
|
+
throw err;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Check for option flag conflicts.
|
|
1521
|
+
* Register option if no conflicts found, or throw on conflict.
|
|
1522
|
+
*
|
|
1523
|
+
* @param {Option} option
|
|
1524
|
+
* @private
|
|
1525
|
+
*/
|
|
1526
|
+
_registerOption(option) {
|
|
1527
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
1528
|
+
if (matchingOption) {
|
|
1529
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
1530
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1531
|
+
- already used by option '${matchingOption.flags}'`);
|
|
1532
|
+
}
|
|
1533
|
+
this.options.push(option);
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Check for command name and alias conflicts with existing commands.
|
|
1537
|
+
* Register command if no conflicts found, or throw on conflict.
|
|
1538
|
+
*
|
|
1539
|
+
* @param {Command} command
|
|
1540
|
+
* @private
|
|
1541
|
+
*/
|
|
1542
|
+
_registerCommand(command) {
|
|
1543
|
+
const knownBy = (cmd) => {
|
|
1544
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
1545
|
+
};
|
|
1546
|
+
const alreadyUsed = knownBy(command).find(
|
|
1547
|
+
(name) => this._findCommand(name)
|
|
1548
|
+
);
|
|
1549
|
+
if (alreadyUsed) {
|
|
1550
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
1551
|
+
const newCmd = knownBy(command).join("|");
|
|
1552
|
+
throw new Error(
|
|
1553
|
+
`cannot add command '${newCmd}' as already have command '${existingCmd}'`
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
this.commands.push(command);
|
|
1557
|
+
}
|
|
1558
|
+
/**
|
|
1559
|
+
* Add an option.
|
|
1560
|
+
*
|
|
1561
|
+
* @param {Option} option
|
|
1562
|
+
* @return {Command} `this` command for chaining
|
|
1563
|
+
*/
|
|
1564
|
+
addOption(option) {
|
|
1565
|
+
this._registerOption(option);
|
|
1566
|
+
const oname = option.name();
|
|
1567
|
+
const name = option.attributeName();
|
|
1568
|
+
if (option.negate) {
|
|
1569
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
1570
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
1571
|
+
this.setOptionValueWithSource(
|
|
1572
|
+
name,
|
|
1573
|
+
option.defaultValue === void 0 ? true : option.defaultValue,
|
|
1574
|
+
"default"
|
|
1575
|
+
);
|
|
1576
|
+
}
|
|
1577
|
+
} else if (option.defaultValue !== void 0) {
|
|
1578
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
1579
|
+
}
|
|
1580
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
1581
|
+
if (val == null && option.presetArg !== void 0) {
|
|
1582
|
+
val = option.presetArg;
|
|
1583
|
+
}
|
|
1584
|
+
const oldValue = this.getOptionValue(name);
|
|
1585
|
+
if (val !== null && option.parseArg) {
|
|
1586
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1587
|
+
} else if (val !== null && option.variadic) {
|
|
1588
|
+
val = option._concatValue(val, oldValue);
|
|
1589
|
+
}
|
|
1590
|
+
if (val == null) {
|
|
1591
|
+
if (option.negate) {
|
|
1592
|
+
val = false;
|
|
1593
|
+
} else if (option.isBoolean() || option.optional) {
|
|
1594
|
+
val = true;
|
|
1595
|
+
} else {
|
|
1596
|
+
val = "";
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
1600
|
+
};
|
|
1601
|
+
this.on("option:" + oname, (val) => {
|
|
1602
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
1603
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
1604
|
+
});
|
|
1605
|
+
if (option.envVar) {
|
|
1606
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
1607
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
1608
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
return this;
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Internal implementation shared by .option() and .requiredOption()
|
|
1615
|
+
*
|
|
1616
|
+
* @return {Command} `this` command for chaining
|
|
1617
|
+
* @private
|
|
1618
|
+
*/
|
|
1619
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
1620
|
+
if (typeof flags === "object" && flags instanceof Option2) {
|
|
1621
|
+
throw new Error(
|
|
1622
|
+
"To add an Option object use addOption() instead of option() or requiredOption()"
|
|
1623
|
+
);
|
|
1624
|
+
}
|
|
1625
|
+
const option = this.createOption(flags, description);
|
|
1626
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
1627
|
+
if (typeof fn === "function") {
|
|
1628
|
+
option.default(defaultValue).argParser(fn);
|
|
1629
|
+
} else if (fn instanceof RegExp) {
|
|
1630
|
+
const regex = fn;
|
|
1631
|
+
fn = (val, def) => {
|
|
1632
|
+
const m = regex.exec(val);
|
|
1633
|
+
return m ? m[0] : def;
|
|
1634
|
+
};
|
|
1635
|
+
option.default(defaultValue).argParser(fn);
|
|
1636
|
+
} else {
|
|
1637
|
+
option.default(fn);
|
|
1638
|
+
}
|
|
1639
|
+
return this.addOption(option);
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
|
|
1643
|
+
*
|
|
1644
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
|
|
1645
|
+
* option-argument is indicated by `<>` and an optional option-argument by `[]`.
|
|
1646
|
+
*
|
|
1647
|
+
* See the README for more details, and see also addOption() and requiredOption().
|
|
1648
|
+
*
|
|
1649
|
+
* @example
|
|
1650
|
+
* program
|
|
1651
|
+
* .option('-p, --pepper', 'add pepper')
|
|
1652
|
+
* .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
|
|
1653
|
+
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
|
|
1654
|
+
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
|
|
1655
|
+
*
|
|
1656
|
+
* @param {string} flags
|
|
1657
|
+
* @param {string} [description]
|
|
1658
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
1659
|
+
* @param {*} [defaultValue]
|
|
1660
|
+
* @return {Command} `this` command for chaining
|
|
1661
|
+
*/
|
|
1662
|
+
option(flags, description, parseArg, defaultValue) {
|
|
1663
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Add a required option which must have a value after parsing. This usually means
|
|
1667
|
+
* the option must be specified on the command line. (Otherwise the same as .option().)
|
|
1668
|
+
*
|
|
1669
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
|
|
1670
|
+
*
|
|
1671
|
+
* @param {string} flags
|
|
1672
|
+
* @param {string} [description]
|
|
1673
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
1674
|
+
* @param {*} [defaultValue]
|
|
1675
|
+
* @return {Command} `this` command for chaining
|
|
1676
|
+
*/
|
|
1677
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
1678
|
+
return this._optionEx(
|
|
1679
|
+
{ mandatory: true },
|
|
1680
|
+
flags,
|
|
1681
|
+
description,
|
|
1682
|
+
parseArg,
|
|
1683
|
+
defaultValue
|
|
1684
|
+
);
|
|
1685
|
+
}
|
|
1686
|
+
/**
|
|
1687
|
+
* Alter parsing of short flags with optional values.
|
|
1688
|
+
*
|
|
1689
|
+
* @example
|
|
1690
|
+
* // for `.option('-f,--flag [value]'):
|
|
1691
|
+
* program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
1692
|
+
* program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
1693
|
+
*
|
|
1694
|
+
* @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
1695
|
+
* @return {Command} `this` command for chaining
|
|
1696
|
+
*/
|
|
1697
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
1698
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
1699
|
+
return this;
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Allow unknown options on the command line.
|
|
1703
|
+
*
|
|
1704
|
+
* @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
|
|
1705
|
+
* @return {Command} `this` command for chaining
|
|
1706
|
+
*/
|
|
1707
|
+
allowUnknownOption(allowUnknown = true) {
|
|
1708
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
1709
|
+
return this;
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
|
|
1713
|
+
*
|
|
1714
|
+
* @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
|
|
1715
|
+
* @return {Command} `this` command for chaining
|
|
1716
|
+
*/
|
|
1717
|
+
allowExcessArguments(allowExcess = true) {
|
|
1718
|
+
this._allowExcessArguments = !!allowExcess;
|
|
1719
|
+
return this;
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Enable positional options. Positional means global options are specified before subcommands which lets
|
|
1723
|
+
* subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
|
|
1724
|
+
* The default behaviour is non-positional and global options may appear anywhere on the command line.
|
|
1725
|
+
*
|
|
1726
|
+
* @param {boolean} [positional]
|
|
1727
|
+
* @return {Command} `this` command for chaining
|
|
1728
|
+
*/
|
|
1729
|
+
enablePositionalOptions(positional = true) {
|
|
1730
|
+
this._enablePositionalOptions = !!positional;
|
|
1731
|
+
return this;
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Pass through options that come after command-arguments rather than treat them as command-options,
|
|
1735
|
+
* so actual command-options come before command-arguments. Turning this on for a subcommand requires
|
|
1736
|
+
* positional options to have been enabled on the program (parent commands).
|
|
1737
|
+
* The default behaviour is non-positional and options may appear before or after command-arguments.
|
|
1738
|
+
*
|
|
1739
|
+
* @param {boolean} [passThrough] for unknown options.
|
|
1740
|
+
* @return {Command} `this` command for chaining
|
|
1741
|
+
*/
|
|
1742
|
+
passThroughOptions(passThrough = true) {
|
|
1743
|
+
this._passThroughOptions = !!passThrough;
|
|
1744
|
+
this._checkForBrokenPassThrough();
|
|
1745
|
+
return this;
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* @private
|
|
1749
|
+
*/
|
|
1750
|
+
_checkForBrokenPassThrough() {
|
|
1751
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
1752
|
+
throw new Error(
|
|
1753
|
+
`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
|
|
1754
|
+
);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Whether to store option values as properties on command object,
|
|
1759
|
+
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
1760
|
+
*
|
|
1761
|
+
* @param {boolean} [storeAsProperties=true]
|
|
1762
|
+
* @return {Command} `this` command for chaining
|
|
1763
|
+
*/
|
|
1764
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1765
|
+
if (this.options.length) {
|
|
1766
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1767
|
+
}
|
|
1768
|
+
if (Object.keys(this._optionValues).length) {
|
|
1769
|
+
throw new Error(
|
|
1770
|
+
"call .storeOptionsAsProperties() before setting option values"
|
|
1771
|
+
);
|
|
1772
|
+
}
|
|
1773
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1774
|
+
return this;
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Retrieve option value.
|
|
1778
|
+
*
|
|
1779
|
+
* @param {string} key
|
|
1780
|
+
* @return {object} value
|
|
1781
|
+
*/
|
|
1782
|
+
getOptionValue(key) {
|
|
1783
|
+
if (this._storeOptionsAsProperties) {
|
|
1784
|
+
return this[key];
|
|
1785
|
+
}
|
|
1786
|
+
return this._optionValues[key];
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* Store option value.
|
|
1790
|
+
*
|
|
1791
|
+
* @param {string} key
|
|
1792
|
+
* @param {object} value
|
|
1793
|
+
* @return {Command} `this` command for chaining
|
|
1794
|
+
*/
|
|
1795
|
+
setOptionValue(key, value) {
|
|
1796
|
+
return this.setOptionValueWithSource(key, value, void 0);
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Store option value and where the value came from.
|
|
1800
|
+
*
|
|
1801
|
+
* @param {string} key
|
|
1802
|
+
* @param {object} value
|
|
1803
|
+
* @param {string} source - expected values are default/config/env/cli/implied
|
|
1804
|
+
* @return {Command} `this` command for chaining
|
|
1805
|
+
*/
|
|
1806
|
+
setOptionValueWithSource(key, value, source) {
|
|
1807
|
+
if (this._storeOptionsAsProperties) {
|
|
1808
|
+
this[key] = value;
|
|
1809
|
+
} else {
|
|
1810
|
+
this._optionValues[key] = value;
|
|
1811
|
+
}
|
|
1812
|
+
this._optionValueSources[key] = source;
|
|
1813
|
+
return this;
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Get source of option value.
|
|
1817
|
+
* Expected values are default | config | env | cli | implied
|
|
1818
|
+
*
|
|
1819
|
+
* @param {string} key
|
|
1820
|
+
* @return {string}
|
|
1821
|
+
*/
|
|
1822
|
+
getOptionValueSource(key) {
|
|
1823
|
+
return this._optionValueSources[key];
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Get source of option value. See also .optsWithGlobals().
|
|
1827
|
+
* Expected values are default | config | env | cli | implied
|
|
1828
|
+
*
|
|
1829
|
+
* @param {string} key
|
|
1830
|
+
* @return {string}
|
|
1831
|
+
*/
|
|
1832
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1833
|
+
let source;
|
|
1834
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1835
|
+
if (cmd.getOptionValueSource(key) !== void 0) {
|
|
1836
|
+
source = cmd.getOptionValueSource(key);
|
|
1837
|
+
}
|
|
1838
|
+
});
|
|
1839
|
+
return source;
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Get user arguments from implied or explicit arguments.
|
|
1843
|
+
* Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
|
|
1844
|
+
*
|
|
1845
|
+
* @private
|
|
1846
|
+
*/
|
|
1847
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1848
|
+
if (argv !== void 0 && !Array.isArray(argv)) {
|
|
1849
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1850
|
+
}
|
|
1851
|
+
parseOptions = parseOptions || {};
|
|
1852
|
+
if (argv === void 0 && parseOptions.from === void 0) {
|
|
1853
|
+
if (process2.versions?.electron) {
|
|
1854
|
+
parseOptions.from = "electron";
|
|
1855
|
+
}
|
|
1856
|
+
const execArgv = process2.execArgv ?? [];
|
|
1857
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1858
|
+
parseOptions.from = "eval";
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
if (argv === void 0) {
|
|
1862
|
+
argv = process2.argv;
|
|
1863
|
+
}
|
|
1864
|
+
this.rawArgs = argv.slice();
|
|
1865
|
+
let userArgs;
|
|
1866
|
+
switch (parseOptions.from) {
|
|
1867
|
+
case void 0:
|
|
1868
|
+
case "node":
|
|
1869
|
+
this._scriptPath = argv[1];
|
|
1870
|
+
userArgs = argv.slice(2);
|
|
1871
|
+
break;
|
|
1872
|
+
case "electron":
|
|
1873
|
+
if (process2.defaultApp) {
|
|
1874
|
+
this._scriptPath = argv[1];
|
|
1875
|
+
userArgs = argv.slice(2);
|
|
1876
|
+
} else {
|
|
1877
|
+
userArgs = argv.slice(1);
|
|
1878
|
+
}
|
|
1879
|
+
break;
|
|
1880
|
+
case "user":
|
|
1881
|
+
userArgs = argv.slice(0);
|
|
1882
|
+
break;
|
|
1883
|
+
case "eval":
|
|
1884
|
+
userArgs = argv.slice(1);
|
|
1885
|
+
break;
|
|
1886
|
+
default:
|
|
1887
|
+
throw new Error(
|
|
1888
|
+
`unexpected parse option { from: '${parseOptions.from}' }`
|
|
1889
|
+
);
|
|
1890
|
+
}
|
|
1891
|
+
if (!this._name && this._scriptPath)
|
|
1892
|
+
this.nameFromFilename(this._scriptPath);
|
|
1893
|
+
this._name = this._name || "program";
|
|
1894
|
+
return userArgs;
|
|
1895
|
+
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
1898
|
+
*
|
|
1899
|
+
* Use parseAsync instead of parse if any of your action handlers are async.
|
|
1900
|
+
*
|
|
1901
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
1902
|
+
*
|
|
1903
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
1904
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
1905
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
1906
|
+
* - `'user'`: just user arguments
|
|
1907
|
+
*
|
|
1908
|
+
* @example
|
|
1909
|
+
* program.parse(); // parse process.argv and auto-detect electron and special node flags
|
|
1910
|
+
* program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
1911
|
+
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
1912
|
+
*
|
|
1913
|
+
* @param {string[]} [argv] - optional, defaults to process.argv
|
|
1914
|
+
* @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
|
|
1915
|
+
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
|
|
1916
|
+
* @return {Command} `this` command for chaining
|
|
1917
|
+
*/
|
|
1918
|
+
parse(argv, parseOptions) {
|
|
1919
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1920
|
+
this._parseCommand([], userArgs);
|
|
1921
|
+
return this;
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
1925
|
+
*
|
|
1926
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
1927
|
+
*
|
|
1928
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
1929
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
1930
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
1931
|
+
* - `'user'`: just user arguments
|
|
1932
|
+
*
|
|
1933
|
+
* @example
|
|
1934
|
+
* await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
|
|
1935
|
+
* await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
|
|
1936
|
+
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
1937
|
+
*
|
|
1938
|
+
* @param {string[]} [argv]
|
|
1939
|
+
* @param {object} [parseOptions]
|
|
1940
|
+
* @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
|
|
1941
|
+
* @return {Promise}
|
|
1942
|
+
*/
|
|
1943
|
+
async parseAsync(argv, parseOptions) {
|
|
1944
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1945
|
+
await this._parseCommand([], userArgs);
|
|
1946
|
+
return this;
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Execute a sub-command executable.
|
|
1950
|
+
*
|
|
1951
|
+
* @private
|
|
1952
|
+
*/
|
|
1953
|
+
_executeSubCommand(subcommand, args) {
|
|
1954
|
+
args = args.slice();
|
|
1955
|
+
let launchWithNode = false;
|
|
1956
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1957
|
+
function findFile(baseDir, baseName) {
|
|
1958
|
+
const localBin = path22.resolve(baseDir, baseName);
|
|
1959
|
+
if (fs12.existsSync(localBin))
|
|
1960
|
+
return localBin;
|
|
1961
|
+
if (sourceExt.includes(path22.extname(baseName)))
|
|
1962
|
+
return void 0;
|
|
1963
|
+
const foundExt = sourceExt.find(
|
|
1964
|
+
(ext) => fs12.existsSync(`${localBin}${ext}`)
|
|
1965
|
+
);
|
|
1966
|
+
if (foundExt)
|
|
1967
|
+
return `${localBin}${foundExt}`;
|
|
1968
|
+
return void 0;
|
|
1969
|
+
}
|
|
1970
|
+
this._checkForMissingMandatoryOptions();
|
|
1971
|
+
this._checkForConflictingOptions();
|
|
1972
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1973
|
+
let executableDir = this._executableDir || "";
|
|
1974
|
+
if (this._scriptPath) {
|
|
1975
|
+
let resolvedScriptPath;
|
|
1976
|
+
try {
|
|
1977
|
+
resolvedScriptPath = fs12.realpathSync(this._scriptPath);
|
|
1978
|
+
} catch (err) {
|
|
1979
|
+
resolvedScriptPath = this._scriptPath;
|
|
1980
|
+
}
|
|
1981
|
+
executableDir = path22.resolve(
|
|
1982
|
+
path22.dirname(resolvedScriptPath),
|
|
1983
|
+
executableDir
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
if (executableDir) {
|
|
1987
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1988
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1989
|
+
const legacyName = path22.basename(
|
|
1990
|
+
this._scriptPath,
|
|
1991
|
+
path22.extname(this._scriptPath)
|
|
1992
|
+
);
|
|
1993
|
+
if (legacyName !== this._name) {
|
|
1994
|
+
localFile = findFile(
|
|
1995
|
+
executableDir,
|
|
1996
|
+
`${legacyName}-${subcommand._name}`
|
|
1997
|
+
);
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
executableFile = localFile || executableFile;
|
|
2001
|
+
}
|
|
2002
|
+
launchWithNode = sourceExt.includes(path22.extname(executableFile));
|
|
2003
|
+
let proc;
|
|
2004
|
+
if (process2.platform !== "win32") {
|
|
2005
|
+
if (launchWithNode) {
|
|
2006
|
+
args.unshift(executableFile);
|
|
2007
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
2008
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
2009
|
+
} else {
|
|
2010
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
2011
|
+
}
|
|
2012
|
+
} else {
|
|
2013
|
+
args.unshift(executableFile);
|
|
2014
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
2015
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
2016
|
+
}
|
|
2017
|
+
if (!proc.killed) {
|
|
2018
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
2019
|
+
signals.forEach((signal) => {
|
|
2020
|
+
process2.on(signal, () => {
|
|
2021
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
2022
|
+
proc.kill(signal);
|
|
2023
|
+
}
|
|
2024
|
+
});
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
const exitCallback = this._exitCallback;
|
|
2028
|
+
proc.on("close", (code) => {
|
|
2029
|
+
code = code ?? 1;
|
|
2030
|
+
if (!exitCallback) {
|
|
2031
|
+
process2.exit(code);
|
|
2032
|
+
} else {
|
|
2033
|
+
exitCallback(
|
|
2034
|
+
new CommanderError2(
|
|
2035
|
+
code,
|
|
2036
|
+
"commander.executeSubCommandAsync",
|
|
2037
|
+
"(close)"
|
|
2038
|
+
)
|
|
2039
|
+
);
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
proc.on("error", (err) => {
|
|
2043
|
+
if (err.code === "ENOENT") {
|
|
2044
|
+
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";
|
|
2045
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
2046
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
2047
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
2048
|
+
- ${executableDirMessage}`;
|
|
2049
|
+
throw new Error(executableMissing);
|
|
2050
|
+
} else if (err.code === "EACCES") {
|
|
2051
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
2052
|
+
}
|
|
2053
|
+
if (!exitCallback) {
|
|
2054
|
+
process2.exit(1);
|
|
2055
|
+
} else {
|
|
2056
|
+
const wrappedError = new CommanderError2(
|
|
2057
|
+
1,
|
|
2058
|
+
"commander.executeSubCommandAsync",
|
|
2059
|
+
"(error)"
|
|
2060
|
+
);
|
|
2061
|
+
wrappedError.nestedError = err;
|
|
2062
|
+
exitCallback(wrappedError);
|
|
2063
|
+
}
|
|
2064
|
+
});
|
|
2065
|
+
this.runningCommand = proc;
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* @private
|
|
2069
|
+
*/
|
|
2070
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
2071
|
+
const subCommand = this._findCommand(commandName);
|
|
2072
|
+
if (!subCommand)
|
|
2073
|
+
this.help({ error: true });
|
|
2074
|
+
let promiseChain;
|
|
2075
|
+
promiseChain = this._chainOrCallSubCommandHook(
|
|
2076
|
+
promiseChain,
|
|
2077
|
+
subCommand,
|
|
2078
|
+
"preSubcommand"
|
|
2079
|
+
);
|
|
2080
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2081
|
+
if (subCommand._executableHandler) {
|
|
2082
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
2083
|
+
} else {
|
|
2084
|
+
return subCommand._parseCommand(operands, unknown);
|
|
2085
|
+
}
|
|
2086
|
+
});
|
|
2087
|
+
return promiseChain;
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* Invoke help directly if possible, or dispatch if necessary.
|
|
2091
|
+
* e.g. help foo
|
|
2092
|
+
*
|
|
2093
|
+
* @private
|
|
2094
|
+
*/
|
|
2095
|
+
_dispatchHelpCommand(subcommandName) {
|
|
2096
|
+
if (!subcommandName) {
|
|
2097
|
+
this.help();
|
|
2098
|
+
}
|
|
2099
|
+
const subCommand = this._findCommand(subcommandName);
|
|
2100
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
2101
|
+
subCommand.help();
|
|
2102
|
+
}
|
|
2103
|
+
return this._dispatchSubcommand(
|
|
2104
|
+
subcommandName,
|
|
2105
|
+
[],
|
|
2106
|
+
[this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
|
|
2107
|
+
);
|
|
2108
|
+
}
|
|
2109
|
+
/**
|
|
2110
|
+
* Check this.args against expected this.registeredArguments.
|
|
2111
|
+
*
|
|
2112
|
+
* @private
|
|
2113
|
+
*/
|
|
2114
|
+
_checkNumberOfArguments() {
|
|
2115
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
2116
|
+
if (arg.required && this.args[i] == null) {
|
|
2117
|
+
this.missingArgument(arg.name());
|
|
2118
|
+
}
|
|
2119
|
+
});
|
|
2120
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
2121
|
+
return;
|
|
2122
|
+
}
|
|
2123
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
2124
|
+
this._excessArguments(this.args);
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
/**
|
|
2128
|
+
* Process this.args using this.registeredArguments and save as this.processedArgs!
|
|
2129
|
+
*
|
|
2130
|
+
* @private
|
|
2131
|
+
*/
|
|
2132
|
+
_processArguments() {
|
|
2133
|
+
const myParseArg = (argument, value, previous) => {
|
|
2134
|
+
let parsedValue = value;
|
|
2135
|
+
if (value !== null && argument.parseArg) {
|
|
2136
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
2137
|
+
parsedValue = this._callParseArg(
|
|
2138
|
+
argument,
|
|
2139
|
+
value,
|
|
2140
|
+
previous,
|
|
2141
|
+
invalidValueMessage
|
|
2142
|
+
);
|
|
2143
|
+
}
|
|
2144
|
+
return parsedValue;
|
|
2145
|
+
};
|
|
2146
|
+
this._checkNumberOfArguments();
|
|
2147
|
+
const processedArgs = [];
|
|
2148
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
2149
|
+
let value = declaredArg.defaultValue;
|
|
2150
|
+
if (declaredArg.variadic) {
|
|
2151
|
+
if (index < this.args.length) {
|
|
2152
|
+
value = this.args.slice(index);
|
|
2153
|
+
if (declaredArg.parseArg) {
|
|
2154
|
+
value = value.reduce((processed, v) => {
|
|
2155
|
+
return myParseArg(declaredArg, v, processed);
|
|
2156
|
+
}, declaredArg.defaultValue);
|
|
2157
|
+
}
|
|
2158
|
+
} else if (value === void 0) {
|
|
2159
|
+
value = [];
|
|
2160
|
+
}
|
|
2161
|
+
} else if (index < this.args.length) {
|
|
2162
|
+
value = this.args[index];
|
|
2163
|
+
if (declaredArg.parseArg) {
|
|
2164
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
processedArgs[index] = value;
|
|
2168
|
+
});
|
|
2169
|
+
this.processedArgs = processedArgs;
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Once we have a promise we chain, but call synchronously until then.
|
|
2173
|
+
*
|
|
2174
|
+
* @param {(Promise|undefined)} promise
|
|
2175
|
+
* @param {Function} fn
|
|
2176
|
+
* @return {(Promise|undefined)}
|
|
2177
|
+
* @private
|
|
2178
|
+
*/
|
|
2179
|
+
_chainOrCall(promise, fn) {
|
|
2180
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
2181
|
+
return promise.then(() => fn());
|
|
2182
|
+
}
|
|
2183
|
+
return fn();
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
*
|
|
2187
|
+
* @param {(Promise|undefined)} promise
|
|
2188
|
+
* @param {string} event
|
|
2189
|
+
* @return {(Promise|undefined)}
|
|
2190
|
+
* @private
|
|
2191
|
+
*/
|
|
2192
|
+
_chainOrCallHooks(promise, event) {
|
|
2193
|
+
let result = promise;
|
|
2194
|
+
const hooks = [];
|
|
2195
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
|
|
2196
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
2197
|
+
hooks.push({ hookedCommand, callback });
|
|
2198
|
+
});
|
|
2199
|
+
});
|
|
2200
|
+
if (event === "postAction") {
|
|
2201
|
+
hooks.reverse();
|
|
2202
|
+
}
|
|
2203
|
+
hooks.forEach((hookDetail) => {
|
|
2204
|
+
result = this._chainOrCall(result, () => {
|
|
2205
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
2206
|
+
});
|
|
2207
|
+
});
|
|
2208
|
+
return result;
|
|
2209
|
+
}
|
|
2210
|
+
/**
|
|
2211
|
+
*
|
|
2212
|
+
* @param {(Promise|undefined)} promise
|
|
2213
|
+
* @param {Command} subCommand
|
|
2214
|
+
* @param {string} event
|
|
2215
|
+
* @return {(Promise|undefined)}
|
|
2216
|
+
* @private
|
|
2217
|
+
*/
|
|
2218
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
2219
|
+
let result = promise;
|
|
2220
|
+
if (this._lifeCycleHooks[event] !== void 0) {
|
|
2221
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
2222
|
+
result = this._chainOrCall(result, () => {
|
|
2223
|
+
return hook(this, subCommand);
|
|
2224
|
+
});
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
return result;
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Process arguments in context of this command.
|
|
2231
|
+
* Returns action result, in case it is a promise.
|
|
2232
|
+
*
|
|
2233
|
+
* @private
|
|
2234
|
+
*/
|
|
2235
|
+
_parseCommand(operands, unknown) {
|
|
2236
|
+
const parsed = this.parseOptions(unknown);
|
|
2237
|
+
this._parseOptionsEnv();
|
|
2238
|
+
this._parseOptionsImplied();
|
|
2239
|
+
operands = operands.concat(parsed.operands);
|
|
2240
|
+
unknown = parsed.unknown;
|
|
2241
|
+
this.args = operands.concat(unknown);
|
|
2242
|
+
if (operands && this._findCommand(operands[0])) {
|
|
2243
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
2244
|
+
}
|
|
2245
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
2246
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
2247
|
+
}
|
|
2248
|
+
if (this._defaultCommandName) {
|
|
2249
|
+
this._outputHelpIfRequested(unknown);
|
|
2250
|
+
return this._dispatchSubcommand(
|
|
2251
|
+
this._defaultCommandName,
|
|
2252
|
+
operands,
|
|
2253
|
+
unknown
|
|
2254
|
+
);
|
|
2255
|
+
}
|
|
2256
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
2257
|
+
this.help({ error: true });
|
|
2258
|
+
}
|
|
2259
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
2260
|
+
this._checkForMissingMandatoryOptions();
|
|
2261
|
+
this._checkForConflictingOptions();
|
|
2262
|
+
const checkForUnknownOptions = () => {
|
|
2263
|
+
if (parsed.unknown.length > 0) {
|
|
2264
|
+
this.unknownOption(parsed.unknown[0]);
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
const commandEvent = `command:${this.name()}`;
|
|
2268
|
+
if (this._actionHandler) {
|
|
2269
|
+
checkForUnknownOptions();
|
|
2270
|
+
this._processArguments();
|
|
2271
|
+
let promiseChain;
|
|
2272
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
2273
|
+
promiseChain = this._chainOrCall(
|
|
2274
|
+
promiseChain,
|
|
2275
|
+
() => this._actionHandler(this.processedArgs)
|
|
2276
|
+
);
|
|
2277
|
+
if (this.parent) {
|
|
2278
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2279
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
2283
|
+
return promiseChain;
|
|
2284
|
+
}
|
|
2285
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
2286
|
+
checkForUnknownOptions();
|
|
2287
|
+
this._processArguments();
|
|
2288
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2289
|
+
} else if (operands.length) {
|
|
2290
|
+
if (this._findCommand("*")) {
|
|
2291
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
2292
|
+
}
|
|
2293
|
+
if (this.listenerCount("command:*")) {
|
|
2294
|
+
this.emit("command:*", operands, unknown);
|
|
2295
|
+
} else if (this.commands.length) {
|
|
2296
|
+
this.unknownCommand();
|
|
2297
|
+
} else {
|
|
2298
|
+
checkForUnknownOptions();
|
|
2299
|
+
this._processArguments();
|
|
2300
|
+
}
|
|
2301
|
+
} else if (this.commands.length) {
|
|
2302
|
+
checkForUnknownOptions();
|
|
2303
|
+
this.help({ error: true });
|
|
2304
|
+
} else {
|
|
2305
|
+
checkForUnknownOptions();
|
|
2306
|
+
this._processArguments();
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
/**
|
|
2310
|
+
* Find matching command.
|
|
2311
|
+
*
|
|
2312
|
+
* @private
|
|
2313
|
+
* @return {Command | undefined}
|
|
2314
|
+
*/
|
|
2315
|
+
_findCommand(name) {
|
|
2316
|
+
if (!name)
|
|
2317
|
+
return void 0;
|
|
2318
|
+
return this.commands.find(
|
|
2319
|
+
(cmd) => cmd._name === name || cmd._aliases.includes(name)
|
|
2320
|
+
);
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* Return an option matching `arg` if any.
|
|
2324
|
+
*
|
|
2325
|
+
* @param {string} arg
|
|
2326
|
+
* @return {Option}
|
|
2327
|
+
* @package
|
|
2328
|
+
*/
|
|
2329
|
+
_findOption(arg) {
|
|
2330
|
+
return this.options.find((option) => option.is(arg));
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* Display an error message if a mandatory option does not have a value.
|
|
2334
|
+
* Called after checking for help flags in leaf subcommand.
|
|
2335
|
+
*
|
|
2336
|
+
* @private
|
|
2337
|
+
*/
|
|
2338
|
+
_checkForMissingMandatoryOptions() {
|
|
2339
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2340
|
+
cmd.options.forEach((anOption) => {
|
|
2341
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) {
|
|
2342
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
2343
|
+
}
|
|
2344
|
+
});
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Display an error message if conflicting options are used together in this.
|
|
2349
|
+
*
|
|
2350
|
+
* @private
|
|
2351
|
+
*/
|
|
2352
|
+
_checkForConflictingLocalOptions() {
|
|
2353
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
2354
|
+
const optionKey = option.attributeName();
|
|
2355
|
+
if (this.getOptionValue(optionKey) === void 0) {
|
|
2356
|
+
return false;
|
|
2357
|
+
}
|
|
2358
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
2359
|
+
});
|
|
2360
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter(
|
|
2361
|
+
(option) => option.conflictsWith.length > 0
|
|
2362
|
+
);
|
|
2363
|
+
optionsWithConflicting.forEach((option) => {
|
|
2364
|
+
const conflictingAndDefined = definedNonDefaultOptions.find(
|
|
2365
|
+
(defined) => option.conflictsWith.includes(defined.attributeName())
|
|
2366
|
+
);
|
|
2367
|
+
if (conflictingAndDefined) {
|
|
2368
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
2369
|
+
}
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
/**
|
|
2373
|
+
* Display an error message if conflicting options are used together.
|
|
2374
|
+
* Called after checking for help flags in leaf subcommand.
|
|
2375
|
+
*
|
|
2376
|
+
* @private
|
|
2377
|
+
*/
|
|
2378
|
+
_checkForConflictingOptions() {
|
|
2379
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2380
|
+
cmd._checkForConflictingLocalOptions();
|
|
2381
|
+
});
|
|
2382
|
+
}
|
|
2383
|
+
/**
|
|
2384
|
+
* Parse options from `argv` removing known options,
|
|
2385
|
+
* and return argv split into operands and unknown arguments.
|
|
2386
|
+
*
|
|
2387
|
+
* Examples:
|
|
2388
|
+
*
|
|
2389
|
+
* argv => operands, unknown
|
|
2390
|
+
* --known kkk op => [op], []
|
|
2391
|
+
* op --known kkk => [op], []
|
|
2392
|
+
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
2393
|
+
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
2394
|
+
*
|
|
2395
|
+
* @param {string[]} argv
|
|
2396
|
+
* @return {{operands: string[], unknown: string[]}}
|
|
2397
|
+
*/
|
|
2398
|
+
parseOptions(argv) {
|
|
2399
|
+
const operands = [];
|
|
2400
|
+
const unknown = [];
|
|
2401
|
+
let dest = operands;
|
|
2402
|
+
const args = argv.slice();
|
|
2403
|
+
function maybeOption(arg) {
|
|
2404
|
+
return arg.length > 1 && arg[0] === "-";
|
|
2405
|
+
}
|
|
2406
|
+
let activeVariadicOption = null;
|
|
2407
|
+
while (args.length) {
|
|
2408
|
+
const arg = args.shift();
|
|
2409
|
+
if (arg === "--") {
|
|
2410
|
+
if (dest === unknown)
|
|
2411
|
+
dest.push(arg);
|
|
2412
|
+
dest.push(...args);
|
|
2413
|
+
break;
|
|
2414
|
+
}
|
|
2415
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
2416
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
2417
|
+
continue;
|
|
2418
|
+
}
|
|
2419
|
+
activeVariadicOption = null;
|
|
2420
|
+
if (maybeOption(arg)) {
|
|
2421
|
+
const option = this._findOption(arg);
|
|
2422
|
+
if (option) {
|
|
2423
|
+
if (option.required) {
|
|
2424
|
+
const value = args.shift();
|
|
2425
|
+
if (value === void 0)
|
|
2426
|
+
this.optionMissingArgument(option);
|
|
2427
|
+
this.emit(`option:${option.name()}`, value);
|
|
2428
|
+
} else if (option.optional) {
|
|
2429
|
+
let value = null;
|
|
2430
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
2431
|
+
value = args.shift();
|
|
2432
|
+
}
|
|
2433
|
+
this.emit(`option:${option.name()}`, value);
|
|
2434
|
+
} else {
|
|
2435
|
+
this.emit(`option:${option.name()}`);
|
|
2436
|
+
}
|
|
2437
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
2438
|
+
continue;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
2442
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
2443
|
+
if (option) {
|
|
2444
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
2445
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
2446
|
+
} else {
|
|
2447
|
+
this.emit(`option:${option.name()}`);
|
|
2448
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
2449
|
+
}
|
|
2450
|
+
continue;
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
2454
|
+
const index = arg.indexOf("=");
|
|
2455
|
+
const option = this._findOption(arg.slice(0, index));
|
|
2456
|
+
if (option && (option.required || option.optional)) {
|
|
2457
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
2458
|
+
continue;
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
if (maybeOption(arg)) {
|
|
2462
|
+
dest = unknown;
|
|
2463
|
+
}
|
|
2464
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
2465
|
+
if (this._findCommand(arg)) {
|
|
2466
|
+
operands.push(arg);
|
|
2467
|
+
if (args.length > 0)
|
|
2468
|
+
unknown.push(...args);
|
|
2469
|
+
break;
|
|
2470
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
2471
|
+
operands.push(arg);
|
|
2472
|
+
if (args.length > 0)
|
|
2473
|
+
operands.push(...args);
|
|
2474
|
+
break;
|
|
2475
|
+
} else if (this._defaultCommandName) {
|
|
2476
|
+
unknown.push(arg);
|
|
2477
|
+
if (args.length > 0)
|
|
2478
|
+
unknown.push(...args);
|
|
2479
|
+
break;
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
if (this._passThroughOptions) {
|
|
2483
|
+
dest.push(arg);
|
|
2484
|
+
if (args.length > 0)
|
|
2485
|
+
dest.push(...args);
|
|
2486
|
+
break;
|
|
2487
|
+
}
|
|
2488
|
+
dest.push(arg);
|
|
2489
|
+
}
|
|
2490
|
+
return { operands, unknown };
|
|
2491
|
+
}
|
|
2492
|
+
/**
|
|
2493
|
+
* Return an object containing local option values as key-value pairs.
|
|
2494
|
+
*
|
|
2495
|
+
* @return {object}
|
|
2496
|
+
*/
|
|
2497
|
+
opts() {
|
|
2498
|
+
if (this._storeOptionsAsProperties) {
|
|
2499
|
+
const result = {};
|
|
2500
|
+
const len = this.options.length;
|
|
2501
|
+
for (let i = 0; i < len; i++) {
|
|
2502
|
+
const key = this.options[i].attributeName();
|
|
2503
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
2504
|
+
}
|
|
2505
|
+
return result;
|
|
2506
|
+
}
|
|
2507
|
+
return this._optionValues;
|
|
2508
|
+
}
|
|
2509
|
+
/**
|
|
2510
|
+
* Return an object containing merged local and global option values as key-value pairs.
|
|
2511
|
+
*
|
|
2512
|
+
* @return {object}
|
|
2513
|
+
*/
|
|
2514
|
+
optsWithGlobals() {
|
|
2515
|
+
return this._getCommandAndAncestors().reduce(
|
|
2516
|
+
(combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
|
|
2517
|
+
{}
|
|
2518
|
+
);
|
|
2519
|
+
}
|
|
2520
|
+
/**
|
|
2521
|
+
* Display error message and exit (or call exitOverride).
|
|
2522
|
+
*
|
|
2523
|
+
* @param {string} message
|
|
2524
|
+
* @param {object} [errorOptions]
|
|
2525
|
+
* @param {string} [errorOptions.code] - an id string representing the error
|
|
2526
|
+
* @param {number} [errorOptions.exitCode] - used with process.exit
|
|
2527
|
+
*/
|
|
2528
|
+
error(message, errorOptions) {
|
|
2529
|
+
this._outputConfiguration.outputError(
|
|
2530
|
+
`${message}
|
|
2531
|
+
`,
|
|
2532
|
+
this._outputConfiguration.writeErr
|
|
2533
|
+
);
|
|
2534
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
2535
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
2536
|
+
`);
|
|
2537
|
+
} else if (this._showHelpAfterError) {
|
|
2538
|
+
this._outputConfiguration.writeErr("\n");
|
|
2539
|
+
this.outputHelp({ error: true });
|
|
2540
|
+
}
|
|
2541
|
+
const config = errorOptions || {};
|
|
2542
|
+
const exitCode = config.exitCode || 1;
|
|
2543
|
+
const code = config.code || "commander.error";
|
|
2544
|
+
this._exit(exitCode, code, message);
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* Apply any option related environment variables, if option does
|
|
2548
|
+
* not have a value from cli or client code.
|
|
2549
|
+
*
|
|
2550
|
+
* @private
|
|
2551
|
+
*/
|
|
2552
|
+
_parseOptionsEnv() {
|
|
2553
|
+
this.options.forEach((option) => {
|
|
2554
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
2555
|
+
const optionKey = option.attributeName();
|
|
2556
|
+
if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
|
|
2557
|
+
this.getOptionValueSource(optionKey)
|
|
2558
|
+
)) {
|
|
2559
|
+
if (option.required || option.optional) {
|
|
2560
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
2561
|
+
} else {
|
|
2562
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* Apply any implied option values, if option is undefined or default value.
|
|
2570
|
+
*
|
|
2571
|
+
* @private
|
|
2572
|
+
*/
|
|
2573
|
+
_parseOptionsImplied() {
|
|
2574
|
+
const dualHelper = new DualOptions(this.options);
|
|
2575
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
2576
|
+
return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
2577
|
+
};
|
|
2578
|
+
this.options.filter(
|
|
2579
|
+
(option) => option.implied !== void 0 && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(
|
|
2580
|
+
this.getOptionValue(option.attributeName()),
|
|
2581
|
+
option
|
|
2582
|
+
)
|
|
2583
|
+
).forEach((option) => {
|
|
2584
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
2585
|
+
this.setOptionValueWithSource(
|
|
2586
|
+
impliedKey,
|
|
2587
|
+
option.implied[impliedKey],
|
|
2588
|
+
"implied"
|
|
2589
|
+
);
|
|
2590
|
+
});
|
|
2591
|
+
});
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
* Argument `name` is missing.
|
|
2595
|
+
*
|
|
2596
|
+
* @param {string} name
|
|
2597
|
+
* @private
|
|
2598
|
+
*/
|
|
2599
|
+
missingArgument(name) {
|
|
2600
|
+
const message = `error: missing required argument '${name}'`;
|
|
2601
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
2602
|
+
}
|
|
2603
|
+
/**
|
|
2604
|
+
* `Option` is missing an argument.
|
|
2605
|
+
*
|
|
2606
|
+
* @param {Option} option
|
|
2607
|
+
* @private
|
|
2608
|
+
*/
|
|
2609
|
+
optionMissingArgument(option) {
|
|
2610
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
2611
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
2612
|
+
}
|
|
2613
|
+
/**
|
|
2614
|
+
* `Option` does not have a value, and is a mandatory option.
|
|
2615
|
+
*
|
|
2616
|
+
* @param {Option} option
|
|
2617
|
+
* @private
|
|
2618
|
+
*/
|
|
2619
|
+
missingMandatoryOptionValue(option) {
|
|
2620
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
2621
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
2622
|
+
}
|
|
2623
|
+
/**
|
|
2624
|
+
* `Option` conflicts with another option.
|
|
2625
|
+
*
|
|
2626
|
+
* @param {Option} option
|
|
2627
|
+
* @param {Option} conflictingOption
|
|
2628
|
+
* @private
|
|
2629
|
+
*/
|
|
2630
|
+
_conflictingOption(option, conflictingOption) {
|
|
2631
|
+
const findBestOptionFromValue = (option2) => {
|
|
2632
|
+
const optionKey = option2.attributeName();
|
|
2633
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
2634
|
+
const negativeOption = this.options.find(
|
|
2635
|
+
(target) => target.negate && optionKey === target.attributeName()
|
|
2636
|
+
);
|
|
2637
|
+
const positiveOption = this.options.find(
|
|
2638
|
+
(target) => !target.negate && optionKey === target.attributeName()
|
|
2639
|
+
);
|
|
2640
|
+
if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) {
|
|
2641
|
+
return negativeOption;
|
|
2642
|
+
}
|
|
2643
|
+
return positiveOption || option2;
|
|
2644
|
+
};
|
|
2645
|
+
const getErrorMessage = (option2) => {
|
|
2646
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
2647
|
+
const optionKey = bestOption.attributeName();
|
|
2648
|
+
const source = this.getOptionValueSource(optionKey);
|
|
2649
|
+
if (source === "env") {
|
|
2650
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
2651
|
+
}
|
|
2652
|
+
return `option '${bestOption.flags}'`;
|
|
2653
|
+
};
|
|
2654
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
2655
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* Unknown option `flag`.
|
|
2659
|
+
*
|
|
2660
|
+
* @param {string} flag
|
|
2661
|
+
* @private
|
|
2662
|
+
*/
|
|
2663
|
+
unknownOption(flag) {
|
|
2664
|
+
if (this._allowUnknownOption)
|
|
2665
|
+
return;
|
|
2666
|
+
let suggestion = "";
|
|
2667
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
2668
|
+
let candidateFlags = [];
|
|
2669
|
+
let command = this;
|
|
2670
|
+
do {
|
|
2671
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
2672
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
2673
|
+
command = command.parent;
|
|
2674
|
+
} while (command && !command._enablePositionalOptions);
|
|
2675
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
2676
|
+
}
|
|
2677
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
2678
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
2679
|
+
}
|
|
2680
|
+
/**
|
|
2681
|
+
* Excess arguments, more than expected.
|
|
2682
|
+
*
|
|
2683
|
+
* @param {string[]} receivedArgs
|
|
2684
|
+
* @private
|
|
2685
|
+
*/
|
|
2686
|
+
_excessArguments(receivedArgs) {
|
|
2687
|
+
if (this._allowExcessArguments)
|
|
2688
|
+
return;
|
|
2689
|
+
const expected = this.registeredArguments.length;
|
|
2690
|
+
const s = expected === 1 ? "" : "s";
|
|
2691
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
2692
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
2693
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Unknown command.
|
|
2697
|
+
*
|
|
2698
|
+
* @private
|
|
2699
|
+
*/
|
|
2700
|
+
unknownCommand() {
|
|
2701
|
+
const unknownName = this.args[0];
|
|
2702
|
+
let suggestion = "";
|
|
2703
|
+
if (this._showSuggestionAfterError) {
|
|
2704
|
+
const candidateNames = [];
|
|
2705
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
2706
|
+
candidateNames.push(command.name());
|
|
2707
|
+
if (command.alias())
|
|
2708
|
+
candidateNames.push(command.alias());
|
|
2709
|
+
});
|
|
2710
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
2711
|
+
}
|
|
2712
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
2713
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
2714
|
+
}
|
|
2715
|
+
/**
|
|
2716
|
+
* Get or set the program version.
|
|
2717
|
+
*
|
|
2718
|
+
* This method auto-registers the "-V, --version" option which will print the version number.
|
|
2719
|
+
*
|
|
2720
|
+
* You can optionally supply the flags and description to override the defaults.
|
|
2721
|
+
*
|
|
2722
|
+
* @param {string} [str]
|
|
2723
|
+
* @param {string} [flags]
|
|
2724
|
+
* @param {string} [description]
|
|
2725
|
+
* @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
|
|
2726
|
+
*/
|
|
2727
|
+
version(str, flags, description) {
|
|
2728
|
+
if (str === void 0)
|
|
2729
|
+
return this._version;
|
|
2730
|
+
this._version = str;
|
|
2731
|
+
flags = flags || "-V, --version";
|
|
2732
|
+
description = description || "output the version number";
|
|
2733
|
+
const versionOption = this.createOption(flags, description);
|
|
2734
|
+
this._versionOptionName = versionOption.attributeName();
|
|
2735
|
+
this._registerOption(versionOption);
|
|
2736
|
+
this.on("option:" + versionOption.name(), () => {
|
|
2737
|
+
this._outputConfiguration.writeOut(`${str}
|
|
2738
|
+
`);
|
|
2739
|
+
this._exit(0, "commander.version", str);
|
|
2740
|
+
});
|
|
2741
|
+
return this;
|
|
2742
|
+
}
|
|
2743
|
+
/**
|
|
2744
|
+
* Set the description.
|
|
2745
|
+
*
|
|
2746
|
+
* @param {string} [str]
|
|
2747
|
+
* @param {object} [argsDescription]
|
|
2748
|
+
* @return {(string|Command)}
|
|
2749
|
+
*/
|
|
2750
|
+
description(str, argsDescription) {
|
|
2751
|
+
if (str === void 0 && argsDescription === void 0)
|
|
2752
|
+
return this._description;
|
|
2753
|
+
this._description = str;
|
|
2754
|
+
if (argsDescription) {
|
|
2755
|
+
this._argsDescription = argsDescription;
|
|
2756
|
+
}
|
|
2757
|
+
return this;
|
|
2758
|
+
}
|
|
2759
|
+
/**
|
|
2760
|
+
* Set the summary. Used when listed as subcommand of parent.
|
|
2761
|
+
*
|
|
2762
|
+
* @param {string} [str]
|
|
2763
|
+
* @return {(string|Command)}
|
|
2764
|
+
*/
|
|
2765
|
+
summary(str) {
|
|
2766
|
+
if (str === void 0)
|
|
2767
|
+
return this._summary;
|
|
2768
|
+
this._summary = str;
|
|
2769
|
+
return this;
|
|
2770
|
+
}
|
|
2771
|
+
/**
|
|
2772
|
+
* Set an alias for the command.
|
|
2773
|
+
*
|
|
2774
|
+
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
|
2775
|
+
*
|
|
2776
|
+
* @param {string} [alias]
|
|
2777
|
+
* @return {(string|Command)}
|
|
2778
|
+
*/
|
|
2779
|
+
alias(alias) {
|
|
2780
|
+
if (alias === void 0)
|
|
2781
|
+
return this._aliases[0];
|
|
2782
|
+
let command = this;
|
|
2783
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
2784
|
+
command = this.commands[this.commands.length - 1];
|
|
2785
|
+
}
|
|
2786
|
+
if (alias === command._name)
|
|
2787
|
+
throw new Error("Command alias can't be the same as its name");
|
|
2788
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
2789
|
+
if (matchingCommand) {
|
|
2790
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
2791
|
+
throw new Error(
|
|
2792
|
+
`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`
|
|
2793
|
+
);
|
|
2794
|
+
}
|
|
2795
|
+
command._aliases.push(alias);
|
|
2796
|
+
return this;
|
|
2797
|
+
}
|
|
2798
|
+
/**
|
|
2799
|
+
* Set aliases for the command.
|
|
2800
|
+
*
|
|
2801
|
+
* Only the first alias is shown in the auto-generated help.
|
|
2802
|
+
*
|
|
2803
|
+
* @param {string[]} [aliases]
|
|
2804
|
+
* @return {(string[]|Command)}
|
|
2805
|
+
*/
|
|
2806
|
+
aliases(aliases) {
|
|
2807
|
+
if (aliases === void 0)
|
|
2808
|
+
return this._aliases;
|
|
2809
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
2810
|
+
return this;
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* Set / get the command usage `str`.
|
|
2814
|
+
*
|
|
2815
|
+
* @param {string} [str]
|
|
2816
|
+
* @return {(string|Command)}
|
|
2817
|
+
*/
|
|
2818
|
+
usage(str) {
|
|
2819
|
+
if (str === void 0) {
|
|
2820
|
+
if (this._usage)
|
|
2821
|
+
return this._usage;
|
|
2822
|
+
const args = this.registeredArguments.map((arg) => {
|
|
2823
|
+
return humanReadableArgName(arg);
|
|
2824
|
+
});
|
|
2825
|
+
return [].concat(
|
|
2826
|
+
this.options.length || this._helpOption !== null ? "[options]" : [],
|
|
2827
|
+
this.commands.length ? "[command]" : [],
|
|
2828
|
+
this.registeredArguments.length ? args : []
|
|
2829
|
+
).join(" ");
|
|
2830
|
+
}
|
|
2831
|
+
this._usage = str;
|
|
2832
|
+
return this;
|
|
2833
|
+
}
|
|
2834
|
+
/**
|
|
2835
|
+
* Get or set the name of the command.
|
|
2836
|
+
*
|
|
2837
|
+
* @param {string} [str]
|
|
2838
|
+
* @return {(string|Command)}
|
|
2839
|
+
*/
|
|
2840
|
+
name(str) {
|
|
2841
|
+
if (str === void 0)
|
|
2842
|
+
return this._name;
|
|
2843
|
+
this._name = str;
|
|
2844
|
+
return this;
|
|
2845
|
+
}
|
|
2846
|
+
/**
|
|
2847
|
+
* Set the name of the command from script filename, such as process.argv[1],
|
|
2848
|
+
* or require.main.filename, or __filename.
|
|
2849
|
+
*
|
|
2850
|
+
* (Used internally and public although not documented in README.)
|
|
2851
|
+
*
|
|
2852
|
+
* @example
|
|
2853
|
+
* program.nameFromFilename(require.main.filename);
|
|
2854
|
+
*
|
|
2855
|
+
* @param {string} filename
|
|
2856
|
+
* @return {Command}
|
|
2857
|
+
*/
|
|
2858
|
+
nameFromFilename(filename) {
|
|
2859
|
+
this._name = path22.basename(filename, path22.extname(filename));
|
|
2860
|
+
return this;
|
|
2861
|
+
}
|
|
2862
|
+
/**
|
|
2863
|
+
* Get or set the directory for searching for executable subcommands of this command.
|
|
2864
|
+
*
|
|
2865
|
+
* @example
|
|
2866
|
+
* program.executableDir(__dirname);
|
|
2867
|
+
* // or
|
|
2868
|
+
* program.executableDir('subcommands');
|
|
2869
|
+
*
|
|
2870
|
+
* @param {string} [path]
|
|
2871
|
+
* @return {(string|null|Command)}
|
|
2872
|
+
*/
|
|
2873
|
+
executableDir(path23) {
|
|
2874
|
+
if (path23 === void 0)
|
|
2875
|
+
return this._executableDir;
|
|
2876
|
+
this._executableDir = path23;
|
|
2877
|
+
return this;
|
|
2878
|
+
}
|
|
2879
|
+
/**
|
|
2880
|
+
* Return program help documentation.
|
|
2881
|
+
*
|
|
2882
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
|
|
2883
|
+
* @return {string}
|
|
2884
|
+
*/
|
|
2885
|
+
helpInformation(contextOptions) {
|
|
2886
|
+
const helper = this.createHelp();
|
|
2887
|
+
if (helper.helpWidth === void 0) {
|
|
2888
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
2889
|
+
}
|
|
2890
|
+
return helper.formatHelp(this, helper);
|
|
2891
|
+
}
|
|
2892
|
+
/**
|
|
2893
|
+
* @private
|
|
2894
|
+
*/
|
|
2895
|
+
_getHelpContext(contextOptions) {
|
|
2896
|
+
contextOptions = contextOptions || {};
|
|
2897
|
+
const context = { error: !!contextOptions.error };
|
|
2898
|
+
let write;
|
|
2899
|
+
if (context.error) {
|
|
2900
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
2901
|
+
} else {
|
|
2902
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
2903
|
+
}
|
|
2904
|
+
context.write = contextOptions.write || write;
|
|
2905
|
+
context.command = this;
|
|
2906
|
+
return context;
|
|
2907
|
+
}
|
|
2908
|
+
/**
|
|
2909
|
+
* Output help information for this command.
|
|
2910
|
+
*
|
|
2911
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
2912
|
+
*
|
|
2913
|
+
* @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
2914
|
+
*/
|
|
2915
|
+
outputHelp(contextOptions) {
|
|
2916
|
+
let deprecatedCallback;
|
|
2917
|
+
if (typeof contextOptions === "function") {
|
|
2918
|
+
deprecatedCallback = contextOptions;
|
|
2919
|
+
contextOptions = void 0;
|
|
2920
|
+
}
|
|
2921
|
+
const context = this._getHelpContext(contextOptions);
|
|
2922
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
2923
|
+
this.emit("beforeHelp", context);
|
|
2924
|
+
let helpInformation = this.helpInformation(context);
|
|
2925
|
+
if (deprecatedCallback) {
|
|
2926
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
2927
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
2928
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
context.write(helpInformation);
|
|
2932
|
+
if (this._getHelpOption()?.long) {
|
|
2933
|
+
this.emit(this._getHelpOption().long);
|
|
2934
|
+
}
|
|
2935
|
+
this.emit("afterHelp", context);
|
|
2936
|
+
this._getCommandAndAncestors().forEach(
|
|
2937
|
+
(command) => command.emit("afterAllHelp", context)
|
|
2938
|
+
);
|
|
2939
|
+
}
|
|
2940
|
+
/**
|
|
2941
|
+
* You can pass in flags and a description to customise the built-in help option.
|
|
2942
|
+
* Pass in false to disable the built-in help option.
|
|
2943
|
+
*
|
|
2944
|
+
* @example
|
|
2945
|
+
* program.helpOption('-?, --help' 'show help'); // customise
|
|
2946
|
+
* program.helpOption(false); // disable
|
|
2947
|
+
*
|
|
2948
|
+
* @param {(string | boolean)} flags
|
|
2949
|
+
* @param {string} [description]
|
|
2950
|
+
* @return {Command} `this` command for chaining
|
|
2951
|
+
*/
|
|
2952
|
+
helpOption(flags, description) {
|
|
2953
|
+
if (typeof flags === "boolean") {
|
|
2954
|
+
if (flags) {
|
|
2955
|
+
this._helpOption = this._helpOption ?? void 0;
|
|
2956
|
+
} else {
|
|
2957
|
+
this._helpOption = null;
|
|
2958
|
+
}
|
|
2959
|
+
return this;
|
|
2960
|
+
}
|
|
2961
|
+
flags = flags ?? "-h, --help";
|
|
2962
|
+
description = description ?? "display help for command";
|
|
2963
|
+
this._helpOption = this.createOption(flags, description);
|
|
2964
|
+
return this;
|
|
2965
|
+
}
|
|
2966
|
+
/**
|
|
2967
|
+
* Lazy create help option.
|
|
2968
|
+
* Returns null if has been disabled with .helpOption(false).
|
|
2969
|
+
*
|
|
2970
|
+
* @returns {(Option | null)} the help option
|
|
2971
|
+
* @package
|
|
2972
|
+
*/
|
|
2973
|
+
_getHelpOption() {
|
|
2974
|
+
if (this._helpOption === void 0) {
|
|
2975
|
+
this.helpOption(void 0, void 0);
|
|
2976
|
+
}
|
|
2977
|
+
return this._helpOption;
|
|
2978
|
+
}
|
|
2979
|
+
/**
|
|
2980
|
+
* Supply your own option to use for the built-in help option.
|
|
2981
|
+
* This is an alternative to using helpOption() to customise the flags and description etc.
|
|
2982
|
+
*
|
|
2983
|
+
* @param {Option} option
|
|
2984
|
+
* @return {Command} `this` command for chaining
|
|
2985
|
+
*/
|
|
2986
|
+
addHelpOption(option) {
|
|
2987
|
+
this._helpOption = option;
|
|
2988
|
+
return this;
|
|
2989
|
+
}
|
|
2990
|
+
/**
|
|
2991
|
+
* Output help information and exit.
|
|
2992
|
+
*
|
|
2993
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
2994
|
+
*
|
|
2995
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
2996
|
+
*/
|
|
2997
|
+
help(contextOptions) {
|
|
2998
|
+
this.outputHelp(contextOptions);
|
|
2999
|
+
let exitCode = process2.exitCode || 0;
|
|
3000
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
3001
|
+
exitCode = 1;
|
|
3002
|
+
}
|
|
3003
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
3004
|
+
}
|
|
3005
|
+
/**
|
|
3006
|
+
* Add additional text to be displayed with the built-in help.
|
|
3007
|
+
*
|
|
3008
|
+
* Position is 'before' or 'after' to affect just this command,
|
|
3009
|
+
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
3010
|
+
*
|
|
3011
|
+
* @param {string} position - before or after built-in help
|
|
3012
|
+
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
3013
|
+
* @return {Command} `this` command for chaining
|
|
3014
|
+
*/
|
|
3015
|
+
addHelpText(position, text) {
|
|
3016
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
3017
|
+
if (!allowedValues.includes(position)) {
|
|
3018
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
3019
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
3020
|
+
}
|
|
3021
|
+
const helpEvent = `${position}Help`;
|
|
3022
|
+
this.on(helpEvent, (context) => {
|
|
3023
|
+
let helpStr;
|
|
3024
|
+
if (typeof text === "function") {
|
|
3025
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
3026
|
+
} else {
|
|
3027
|
+
helpStr = text;
|
|
3028
|
+
}
|
|
3029
|
+
if (helpStr) {
|
|
3030
|
+
context.write(`${helpStr}
|
|
3031
|
+
`);
|
|
3032
|
+
}
|
|
3033
|
+
});
|
|
3034
|
+
return this;
|
|
3035
|
+
}
|
|
3036
|
+
/**
|
|
3037
|
+
* Output help information if help flags specified
|
|
3038
|
+
*
|
|
3039
|
+
* @param {Array} args - array of options to search for help flags
|
|
3040
|
+
* @private
|
|
3041
|
+
*/
|
|
3042
|
+
_outputHelpIfRequested(args) {
|
|
3043
|
+
const helpOption = this._getHelpOption();
|
|
3044
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
3045
|
+
if (helpRequested) {
|
|
3046
|
+
this.outputHelp();
|
|
3047
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
};
|
|
3051
|
+
function incrementNodeInspectorPort(args) {
|
|
3052
|
+
return args.map((arg) => {
|
|
3053
|
+
if (!arg.startsWith("--inspect")) {
|
|
3054
|
+
return arg;
|
|
3055
|
+
}
|
|
3056
|
+
let debugOption;
|
|
3057
|
+
let debugHost = "127.0.0.1";
|
|
3058
|
+
let debugPort = "9229";
|
|
3059
|
+
let match;
|
|
3060
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
3061
|
+
debugOption = match[1];
|
|
3062
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
3063
|
+
debugOption = match[1];
|
|
3064
|
+
if (/^\d+$/.test(match[3])) {
|
|
3065
|
+
debugPort = match[3];
|
|
3066
|
+
} else {
|
|
3067
|
+
debugHost = match[3];
|
|
3068
|
+
}
|
|
3069
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
3070
|
+
debugOption = match[1];
|
|
3071
|
+
debugHost = match[3];
|
|
3072
|
+
debugPort = match[4];
|
|
3073
|
+
}
|
|
3074
|
+
if (debugOption && debugPort !== "0") {
|
|
3075
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
3076
|
+
}
|
|
3077
|
+
return arg;
|
|
3078
|
+
});
|
|
3079
|
+
}
|
|
3080
|
+
exports.Command = Command2;
|
|
3081
|
+
}
|
|
3082
|
+
});
|
|
3083
|
+
|
|
3084
|
+
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/index.js
|
|
3085
|
+
var require_commander = __commonJS({
|
|
3086
|
+
"../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/index.js"(exports) {
|
|
3087
|
+
"use strict";
|
|
3088
|
+
init_esm();
|
|
3089
|
+
var { Argument: Argument2 } = require_argument();
|
|
3090
|
+
var { Command: Command2 } = require_command();
|
|
3091
|
+
var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
3092
|
+
var { Help: Help2 } = require_help();
|
|
3093
|
+
var { Option: Option2 } = require_option();
|
|
3094
|
+
exports.program = new Command2();
|
|
3095
|
+
exports.createCommand = (name) => new Command2(name);
|
|
3096
|
+
exports.createOption = (flags, description) => new Option2(flags, description);
|
|
3097
|
+
exports.createArgument = (name, description) => new Argument2(name, description);
|
|
3098
|
+
exports.Command = Command2;
|
|
3099
|
+
exports.Option = Option2;
|
|
3100
|
+
exports.Argument = Argument2;
|
|
3101
|
+
exports.Help = Help2;
|
|
3102
|
+
exports.CommanderError = CommanderError2;
|
|
3103
|
+
exports.InvalidArgumentError = InvalidArgumentError2;
|
|
3104
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError2;
|
|
3105
|
+
}
|
|
3106
|
+
});
|
|
3107
|
+
|
|
3108
|
+
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/esm.mjs
|
|
3109
|
+
var import_index, program, createCommand, createArgument, createOption, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Command, Argument, Option, Help;
|
|
3110
|
+
var init_esm2 = __esm({
|
|
3111
|
+
"../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/esm.mjs"() {
|
|
3112
|
+
"use strict";
|
|
3113
|
+
init_esm();
|
|
3114
|
+
import_index = __toESM(require_commander(), 1);
|
|
3115
|
+
({
|
|
3116
|
+
program,
|
|
3117
|
+
createCommand,
|
|
3118
|
+
createArgument,
|
|
3119
|
+
createOption,
|
|
3120
|
+
CommanderError,
|
|
3121
|
+
InvalidArgumentError,
|
|
3122
|
+
InvalidOptionArgumentError,
|
|
3123
|
+
Command: (
|
|
3124
|
+
// deprecated old name
|
|
3125
|
+
Command
|
|
3126
|
+
),
|
|
3127
|
+
Argument,
|
|
3128
|
+
Option,
|
|
3129
|
+
Help
|
|
3130
|
+
} = import_index.default);
|
|
3131
|
+
}
|
|
3132
|
+
});
|
|
3133
|
+
|
|
63
3134
|
// ../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js
|
|
64
3135
|
var require_cjs = __commonJS({
|
|
65
3136
|
"../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js"(exports, module) {
|
|
@@ -285,12 +3356,12 @@ var init_logger = __esm({
|
|
|
285
3356
|
// src/helpers/fs.ts
|
|
286
3357
|
import fs from "fs";
|
|
287
3358
|
import path2 from "path";
|
|
288
|
-
function isEmptyDir(
|
|
289
|
-
const files = fs.readdirSync(
|
|
3359
|
+
function isEmptyDir(path22) {
|
|
3360
|
+
const files = fs.readdirSync(path22);
|
|
290
3361
|
return files.length === 0 || files.length === 1 && files[0] === ".git";
|
|
291
3362
|
}
|
|
292
|
-
async function pathExists(
|
|
293
|
-
return fs.promises.access(
|
|
3363
|
+
async function pathExists(path22) {
|
|
3364
|
+
return fs.promises.access(path22).then(() => true).catch(() => false);
|
|
294
3365
|
}
|
|
295
3366
|
async function isFileExists(file) {
|
|
296
3367
|
return fs.promises.access(file, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
@@ -502,28 +3573,28 @@ function getStatsOptions(compiler) {
|
|
|
502
3573
|
}
|
|
503
3574
|
return compiler.options ? compiler.options.stats : void 0;
|
|
504
3575
|
}
|
|
505
|
-
function formatStats(
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
errors: getAllStatsErrors(statsData),
|
|
516
|
-
warnings: getAllStatsWarnings(statsData)
|
|
517
|
-
},
|
|
518
|
-
// display verbose messages in debug mode
|
|
519
|
-
logger.level === "verbose"
|
|
520
|
-
);
|
|
521
|
-
if (stats.hasErrors()) {
|
|
3576
|
+
function formatStats(statsData, hasErrors) {
|
|
3577
|
+
const verbose = logger.level === "verbose";
|
|
3578
|
+
if (hasErrors) {
|
|
3579
|
+
const { errors } = formatStatsMessages(
|
|
3580
|
+
{
|
|
3581
|
+
errors: getAllStatsErrors(statsData),
|
|
3582
|
+
warnings: []
|
|
3583
|
+
},
|
|
3584
|
+
verbose
|
|
3585
|
+
);
|
|
522
3586
|
return {
|
|
523
3587
|
message: formatErrorMessage(errors),
|
|
524
3588
|
level: "error"
|
|
525
3589
|
};
|
|
526
3590
|
}
|
|
3591
|
+
const { warnings } = formatStatsMessages(
|
|
3592
|
+
{
|
|
3593
|
+
errors: [],
|
|
3594
|
+
warnings: getAllStatsWarnings(statsData)
|
|
3595
|
+
},
|
|
3596
|
+
verbose
|
|
3597
|
+
);
|
|
527
3598
|
if (warnings.length) {
|
|
528
3599
|
const title = color2.bold(color2.yellow("Compile Warning: \n"));
|
|
529
3600
|
return {
|
|
@@ -543,6 +3614,21 @@ var init_stats = __esm({
|
|
|
543
3614
|
init_logger();
|
|
544
3615
|
init_helpers();
|
|
545
3616
|
hintNodePolyfill = (message) => {
|
|
3617
|
+
const getTips = (moduleName2) => {
|
|
3618
|
+
const tips = [
|
|
3619
|
+
`Tip: "${moduleName2}" is a built-in Node.js module. It cannot be imported in client-side code.`,
|
|
3620
|
+
`Check if you need to import Node.js module. If needed, you can use ${color2.cyan("@rsbuild/plugin-node-polyfill")}.`
|
|
3621
|
+
];
|
|
3622
|
+
return `${message}
|
|
3623
|
+
|
|
3624
|
+
${color2.yellow(tips.join("\n"))}`;
|
|
3625
|
+
};
|
|
3626
|
+
const isNodeProtocolError = message.includes(
|
|
3627
|
+
'need an additional plugin to handle "node:" URIs'
|
|
3628
|
+
);
|
|
3629
|
+
if (isNodeProtocolError) {
|
|
3630
|
+
return getTips("node:*");
|
|
3631
|
+
}
|
|
546
3632
|
if (!message.includes(`Can't resolve`)) {
|
|
547
3633
|
return message;
|
|
548
3634
|
}
|
|
@@ -591,14 +3677,8 @@ var init_stats = __esm({
|
|
|
591
3677
|
"vm",
|
|
592
3678
|
"zlib"
|
|
593
3679
|
];
|
|
594
|
-
if (moduleName && nodeModules.includes(moduleName)) {
|
|
595
|
-
|
|
596
|
-
`Tip: "${moduleName}" is a built-in Node.js module and cannot be imported in client-side code.`,
|
|
597
|
-
`Check if you need to import Node.js module. If needed, you can use "@rsbuild/plugin-node-polyfill".`
|
|
598
|
-
];
|
|
599
|
-
return `${message}
|
|
600
|
-
|
|
601
|
-
${color2.yellow(tips.join("\n"))}`;
|
|
3680
|
+
if (moduleName && nodeModules.includes(moduleName)) {
|
|
3681
|
+
return getTips(moduleName);
|
|
602
3682
|
}
|
|
603
3683
|
return message;
|
|
604
3684
|
};
|
|
@@ -787,9 +3867,9 @@ var init_helpers = __esm({
|
|
|
787
3867
|
}
|
|
788
3868
|
return DEFAULT_ASSET_PREFIX;
|
|
789
3869
|
};
|
|
790
|
-
urlJoin = (base,
|
|
3870
|
+
urlJoin = (base, path22) => {
|
|
791
3871
|
const fullUrl = new URL(base);
|
|
792
|
-
fullUrl.pathname = posix.join(fullUrl.pathname,
|
|
3872
|
+
fullUrl.pathname = posix.join(fullUrl.pathname, path22);
|
|
793
3873
|
return fullUrl.toString();
|
|
794
3874
|
};
|
|
795
3875
|
canParse = (url2) => {
|
|
@@ -874,8 +3954,8 @@ var init_mergeConfig = __esm({
|
|
|
874
3954
|
}
|
|
875
3955
|
return OVERRIDE_PATHS.includes(key);
|
|
876
3956
|
};
|
|
877
|
-
merge = (x, y,
|
|
878
|
-
if (isOverridePath(
|
|
3957
|
+
merge = (x, y, path22 = "") => {
|
|
3958
|
+
if (isOverridePath(path22)) {
|
|
879
3959
|
return y ?? x;
|
|
880
3960
|
}
|
|
881
3961
|
if (x === void 0) {
|
|
@@ -900,7 +3980,7 @@ var init_mergeConfig = __esm({
|
|
|
900
3980
|
const merged = {};
|
|
901
3981
|
const keys = /* @__PURE__ */ new Set([...Object.keys(x), ...Object.keys(y)]);
|
|
902
3982
|
for (const key of keys) {
|
|
903
|
-
const childPath =
|
|
3983
|
+
const childPath = path22 ? `${path22}.${key}` : key;
|
|
904
3984
|
merged[key] = merge(x[key], y[key], childPath);
|
|
905
3985
|
}
|
|
906
3986
|
return merged;
|
|
@@ -1012,10 +4092,10 @@ async function watchFiles(files, watchOptions) {
|
|
|
1012
4092
|
}
|
|
1013
4093
|
async function loadConfig({
|
|
1014
4094
|
cwd = process.cwd(),
|
|
1015
|
-
path:
|
|
4095
|
+
path: path22,
|
|
1016
4096
|
envMode
|
|
1017
4097
|
} = {}) {
|
|
1018
|
-
const configFilePath = resolveConfigPath(cwd,
|
|
4098
|
+
const configFilePath = resolveConfigPath(cwd, path22);
|
|
1019
4099
|
if (!configFilePath) {
|
|
1020
4100
|
return {
|
|
1021
4101
|
content: {},
|
|
@@ -1040,13 +4120,13 @@ async function loadConfig({
|
|
|
1040
4120
|
try {
|
|
1041
4121
|
if (configExport === void 0) {
|
|
1042
4122
|
const { default: jiti } = await import("../compiled/jiti/index.js");
|
|
1043
|
-
const
|
|
4123
|
+
const loadConfig3 = jiti(__filename, {
|
|
1044
4124
|
esmResolve: true,
|
|
1045
4125
|
// disable require cache to support restart CLI and read the new config
|
|
1046
4126
|
requireCache: false,
|
|
1047
4127
|
interopDefault: true
|
|
1048
4128
|
});
|
|
1049
|
-
configExport =
|
|
4129
|
+
configExport = loadConfig3(configFilePath);
|
|
1050
4130
|
}
|
|
1051
4131
|
} catch (err) {
|
|
1052
4132
|
logger.error(`Failed to load file with jiti: ${color5.dim(configFilePath)}`);
|
|
@@ -1390,11 +4470,416 @@ var init_config = __esm({
|
|
|
1390
4470
|
}
|
|
1391
4471
|
});
|
|
1392
4472
|
|
|
4473
|
+
// ../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/package.json
|
|
4474
|
+
var require_package = __commonJS({
|
|
4475
|
+
"../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/package.json"(exports, module) {
|
|
4476
|
+
module.exports = {
|
|
4477
|
+
name: "dotenv",
|
|
4478
|
+
version: "16.4.5",
|
|
4479
|
+
description: "Loads environment variables from .env file",
|
|
4480
|
+
main: "lib/main.js",
|
|
4481
|
+
types: "lib/main.d.ts",
|
|
4482
|
+
exports: {
|
|
4483
|
+
".": {
|
|
4484
|
+
types: "./lib/main.d.ts",
|
|
4485
|
+
require: "./lib/main.js",
|
|
4486
|
+
default: "./lib/main.js"
|
|
4487
|
+
},
|
|
4488
|
+
"./config": "./config.js",
|
|
4489
|
+
"./config.js": "./config.js",
|
|
4490
|
+
"./lib/env-options": "./lib/env-options.js",
|
|
4491
|
+
"./lib/env-options.js": "./lib/env-options.js",
|
|
4492
|
+
"./lib/cli-options": "./lib/cli-options.js",
|
|
4493
|
+
"./lib/cli-options.js": "./lib/cli-options.js",
|
|
4494
|
+
"./package.json": "./package.json"
|
|
4495
|
+
},
|
|
4496
|
+
scripts: {
|
|
4497
|
+
"dts-check": "tsc --project tests/types/tsconfig.json",
|
|
4498
|
+
lint: "standard",
|
|
4499
|
+
"lint-readme": "standard-markdown",
|
|
4500
|
+
pretest: "npm run lint && npm run dts-check",
|
|
4501
|
+
test: "tap tests/*.js --100 -Rspec",
|
|
4502
|
+
"test:coverage": "tap --coverage-report=lcov",
|
|
4503
|
+
prerelease: "npm test",
|
|
4504
|
+
release: "standard-version"
|
|
4505
|
+
},
|
|
4506
|
+
repository: {
|
|
4507
|
+
type: "git",
|
|
4508
|
+
url: "git://github.com/motdotla/dotenv.git"
|
|
4509
|
+
},
|
|
4510
|
+
funding: "https://dotenvx.com",
|
|
4511
|
+
keywords: [
|
|
4512
|
+
"dotenv",
|
|
4513
|
+
"env",
|
|
4514
|
+
".env",
|
|
4515
|
+
"environment",
|
|
4516
|
+
"variables",
|
|
4517
|
+
"config",
|
|
4518
|
+
"settings"
|
|
4519
|
+
],
|
|
4520
|
+
readmeFilename: "README.md",
|
|
4521
|
+
license: "BSD-2-Clause",
|
|
4522
|
+
devDependencies: {
|
|
4523
|
+
"@definitelytyped/dtslint": "^0.0.133",
|
|
4524
|
+
"@types/node": "^18.11.3",
|
|
4525
|
+
decache: "^4.6.1",
|
|
4526
|
+
sinon: "^14.0.1",
|
|
4527
|
+
standard: "^17.0.0",
|
|
4528
|
+
"standard-markdown": "^7.1.0",
|
|
4529
|
+
"standard-version": "^9.5.0",
|
|
4530
|
+
tap: "^16.3.0",
|
|
4531
|
+
tar: "^6.1.11",
|
|
4532
|
+
typescript: "^4.8.4"
|
|
4533
|
+
},
|
|
4534
|
+
engines: {
|
|
4535
|
+
node: ">=12"
|
|
4536
|
+
},
|
|
4537
|
+
browser: {
|
|
4538
|
+
fs: false
|
|
4539
|
+
}
|
|
4540
|
+
};
|
|
4541
|
+
}
|
|
4542
|
+
});
|
|
4543
|
+
|
|
4544
|
+
// ../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js
|
|
4545
|
+
var require_main = __commonJS({
|
|
4546
|
+
"../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js"(exports, module) {
|
|
4547
|
+
"use strict";
|
|
4548
|
+
init_esm();
|
|
4549
|
+
var fs12 = __require("fs");
|
|
4550
|
+
var path22 = __require("path");
|
|
4551
|
+
var os2 = __require("os");
|
|
4552
|
+
var crypto3 = __require("crypto");
|
|
4553
|
+
var packageJson = require_package();
|
|
4554
|
+
var version2 = packageJson.version;
|
|
4555
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
4556
|
+
function parse4(src) {
|
|
4557
|
+
const obj = {};
|
|
4558
|
+
let lines = src.toString();
|
|
4559
|
+
lines = lines.replace(/\r\n?/mg, "\n");
|
|
4560
|
+
let match;
|
|
4561
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
4562
|
+
const key = match[1];
|
|
4563
|
+
let value = match[2] || "";
|
|
4564
|
+
value = value.trim();
|
|
4565
|
+
const maybeQuote = value[0];
|
|
4566
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
4567
|
+
if (maybeQuote === '"') {
|
|
4568
|
+
value = value.replace(/\\n/g, "\n");
|
|
4569
|
+
value = value.replace(/\\r/g, "\r");
|
|
4570
|
+
}
|
|
4571
|
+
obj[key] = value;
|
|
4572
|
+
}
|
|
4573
|
+
return obj;
|
|
4574
|
+
}
|
|
4575
|
+
function _parseVault(options) {
|
|
4576
|
+
const vaultPath = _vaultPath(options);
|
|
4577
|
+
const result = DotenvModule.configDotenv({ path: vaultPath });
|
|
4578
|
+
if (!result.parsed) {
|
|
4579
|
+
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
4580
|
+
err.code = "MISSING_DATA";
|
|
4581
|
+
throw err;
|
|
4582
|
+
}
|
|
4583
|
+
const keys = _dotenvKey(options).split(",");
|
|
4584
|
+
const length = keys.length;
|
|
4585
|
+
let decrypted;
|
|
4586
|
+
for (let i = 0; i < length; i++) {
|
|
4587
|
+
try {
|
|
4588
|
+
const key = keys[i].trim();
|
|
4589
|
+
const attrs = _instructions(result, key);
|
|
4590
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
4591
|
+
break;
|
|
4592
|
+
} catch (error) {
|
|
4593
|
+
if (i + 1 >= length) {
|
|
4594
|
+
throw error;
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
return DotenvModule.parse(decrypted);
|
|
4599
|
+
}
|
|
4600
|
+
function _log(message) {
|
|
4601
|
+
console.log(`[dotenv@${version2}][INFO] ${message}`);
|
|
4602
|
+
}
|
|
4603
|
+
function _warn(message) {
|
|
4604
|
+
console.log(`[dotenv@${version2}][WARN] ${message}`);
|
|
4605
|
+
}
|
|
4606
|
+
function _debug(message) {
|
|
4607
|
+
console.log(`[dotenv@${version2}][DEBUG] ${message}`);
|
|
4608
|
+
}
|
|
4609
|
+
function _dotenvKey(options) {
|
|
4610
|
+
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
|
|
4611
|
+
return options.DOTENV_KEY;
|
|
4612
|
+
}
|
|
4613
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
4614
|
+
return process.env.DOTENV_KEY;
|
|
4615
|
+
}
|
|
4616
|
+
return "";
|
|
4617
|
+
}
|
|
4618
|
+
function _instructions(result, dotenvKey) {
|
|
4619
|
+
let uri;
|
|
4620
|
+
try {
|
|
4621
|
+
uri = new URL(dotenvKey);
|
|
4622
|
+
} catch (error) {
|
|
4623
|
+
if (error.code === "ERR_INVALID_URL") {
|
|
4624
|
+
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");
|
|
4625
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
4626
|
+
throw err;
|
|
4627
|
+
}
|
|
4628
|
+
throw error;
|
|
4629
|
+
}
|
|
4630
|
+
const key = uri.password;
|
|
4631
|
+
if (!key) {
|
|
4632
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
4633
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
4634
|
+
throw err;
|
|
4635
|
+
}
|
|
4636
|
+
const environment = uri.searchParams.get("environment");
|
|
4637
|
+
if (!environment) {
|
|
4638
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
4639
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
4640
|
+
throw err;
|
|
4641
|
+
}
|
|
4642
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
4643
|
+
const ciphertext = result.parsed[environmentKey];
|
|
4644
|
+
if (!ciphertext) {
|
|
4645
|
+
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
4646
|
+
err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
|
|
4647
|
+
throw err;
|
|
4648
|
+
}
|
|
4649
|
+
return { ciphertext, key };
|
|
4650
|
+
}
|
|
4651
|
+
function _vaultPath(options) {
|
|
4652
|
+
let possibleVaultPath = null;
|
|
4653
|
+
if (options && options.path && options.path.length > 0) {
|
|
4654
|
+
if (Array.isArray(options.path)) {
|
|
4655
|
+
for (const filepath of options.path) {
|
|
4656
|
+
if (fs12.existsSync(filepath)) {
|
|
4657
|
+
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
} else {
|
|
4661
|
+
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
4662
|
+
}
|
|
4663
|
+
} else {
|
|
4664
|
+
possibleVaultPath = path22.resolve(process.cwd(), ".env.vault");
|
|
4665
|
+
}
|
|
4666
|
+
if (fs12.existsSync(possibleVaultPath)) {
|
|
4667
|
+
return possibleVaultPath;
|
|
4668
|
+
}
|
|
4669
|
+
return null;
|
|
4670
|
+
}
|
|
4671
|
+
function _resolveHome(envPath) {
|
|
4672
|
+
return envPath[0] === "~" ? path22.join(os2.homedir(), envPath.slice(1)) : envPath;
|
|
4673
|
+
}
|
|
4674
|
+
function _configVault(options) {
|
|
4675
|
+
_log("Loading env from encrypted .env.vault");
|
|
4676
|
+
const parsed = DotenvModule._parseVault(options);
|
|
4677
|
+
let processEnv = process.env;
|
|
4678
|
+
if (options && options.processEnv != null) {
|
|
4679
|
+
processEnv = options.processEnv;
|
|
4680
|
+
}
|
|
4681
|
+
DotenvModule.populate(processEnv, parsed, options);
|
|
4682
|
+
return { parsed };
|
|
4683
|
+
}
|
|
4684
|
+
function configDotenv(options) {
|
|
4685
|
+
const dotenvPath = path22.resolve(process.cwd(), ".env");
|
|
4686
|
+
let encoding = "utf8";
|
|
4687
|
+
const debug = Boolean(options && options.debug);
|
|
4688
|
+
if (options && options.encoding) {
|
|
4689
|
+
encoding = options.encoding;
|
|
4690
|
+
} else {
|
|
4691
|
+
if (debug) {
|
|
4692
|
+
_debug("No encoding is specified. UTF-8 is used by default");
|
|
4693
|
+
}
|
|
4694
|
+
}
|
|
4695
|
+
let optionPaths = [dotenvPath];
|
|
4696
|
+
if (options && options.path) {
|
|
4697
|
+
if (!Array.isArray(options.path)) {
|
|
4698
|
+
optionPaths = [_resolveHome(options.path)];
|
|
4699
|
+
} else {
|
|
4700
|
+
optionPaths = [];
|
|
4701
|
+
for (const filepath of options.path) {
|
|
4702
|
+
optionPaths.push(_resolveHome(filepath));
|
|
4703
|
+
}
|
|
4704
|
+
}
|
|
4705
|
+
}
|
|
4706
|
+
let lastError;
|
|
4707
|
+
const parsedAll = {};
|
|
4708
|
+
for (const path23 of optionPaths) {
|
|
4709
|
+
try {
|
|
4710
|
+
const parsed = DotenvModule.parse(fs12.readFileSync(path23, { encoding }));
|
|
4711
|
+
DotenvModule.populate(parsedAll, parsed, options);
|
|
4712
|
+
} catch (e) {
|
|
4713
|
+
if (debug) {
|
|
4714
|
+
_debug(`Failed to load ${path23} ${e.message}`);
|
|
4715
|
+
}
|
|
4716
|
+
lastError = e;
|
|
4717
|
+
}
|
|
4718
|
+
}
|
|
4719
|
+
let processEnv = process.env;
|
|
4720
|
+
if (options && options.processEnv != null) {
|
|
4721
|
+
processEnv = options.processEnv;
|
|
4722
|
+
}
|
|
4723
|
+
DotenvModule.populate(processEnv, parsedAll, options);
|
|
4724
|
+
if (lastError) {
|
|
4725
|
+
return { parsed: parsedAll, error: lastError };
|
|
4726
|
+
} else {
|
|
4727
|
+
return { parsed: parsedAll };
|
|
4728
|
+
}
|
|
4729
|
+
}
|
|
4730
|
+
function config(options) {
|
|
4731
|
+
if (_dotenvKey(options).length === 0) {
|
|
4732
|
+
return DotenvModule.configDotenv(options);
|
|
4733
|
+
}
|
|
4734
|
+
const vaultPath = _vaultPath(options);
|
|
4735
|
+
if (!vaultPath) {
|
|
4736
|
+
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
4737
|
+
return DotenvModule.configDotenv(options);
|
|
4738
|
+
}
|
|
4739
|
+
return DotenvModule._configVault(options);
|
|
4740
|
+
}
|
|
4741
|
+
function decrypt(encrypted, keyStr) {
|
|
4742
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
|
4743
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
|
4744
|
+
const nonce = ciphertext.subarray(0, 12);
|
|
4745
|
+
const authTag = ciphertext.subarray(-16);
|
|
4746
|
+
ciphertext = ciphertext.subarray(12, -16);
|
|
4747
|
+
try {
|
|
4748
|
+
const aesgcm = crypto3.createDecipheriv("aes-256-gcm", key, nonce);
|
|
4749
|
+
aesgcm.setAuthTag(authTag);
|
|
4750
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
4751
|
+
} catch (error) {
|
|
4752
|
+
const isRange = error instanceof RangeError;
|
|
4753
|
+
const invalidKeyLength = error.message === "Invalid key length";
|
|
4754
|
+
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
|
4755
|
+
if (isRange || invalidKeyLength) {
|
|
4756
|
+
const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
|
|
4757
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
4758
|
+
throw err;
|
|
4759
|
+
} else if (decryptionFailed) {
|
|
4760
|
+
const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
|
|
4761
|
+
err.code = "DECRYPTION_FAILED";
|
|
4762
|
+
throw err;
|
|
4763
|
+
} else {
|
|
4764
|
+
throw error;
|
|
4765
|
+
}
|
|
4766
|
+
}
|
|
4767
|
+
}
|
|
4768
|
+
function populate(processEnv, parsed, options = {}) {
|
|
4769
|
+
const debug = Boolean(options && options.debug);
|
|
4770
|
+
const override = Boolean(options && options.override);
|
|
4771
|
+
if (typeof parsed !== "object") {
|
|
4772
|
+
const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
4773
|
+
err.code = "OBJECT_REQUIRED";
|
|
4774
|
+
throw err;
|
|
4775
|
+
}
|
|
4776
|
+
for (const key of Object.keys(parsed)) {
|
|
4777
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
4778
|
+
if (override === true) {
|
|
4779
|
+
processEnv[key] = parsed[key];
|
|
4780
|
+
}
|
|
4781
|
+
if (debug) {
|
|
4782
|
+
if (override === true) {
|
|
4783
|
+
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
4784
|
+
} else {
|
|
4785
|
+
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
4786
|
+
}
|
|
4787
|
+
}
|
|
4788
|
+
} else {
|
|
4789
|
+
processEnv[key] = parsed[key];
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4792
|
+
}
|
|
4793
|
+
var DotenvModule = {
|
|
4794
|
+
configDotenv,
|
|
4795
|
+
_configVault,
|
|
4796
|
+
_parseVault,
|
|
4797
|
+
config,
|
|
4798
|
+
decrypt,
|
|
4799
|
+
parse: parse4,
|
|
4800
|
+
populate
|
|
4801
|
+
};
|
|
4802
|
+
module.exports.configDotenv = DotenvModule.configDotenv;
|
|
4803
|
+
module.exports._configVault = DotenvModule._configVault;
|
|
4804
|
+
module.exports._parseVault = DotenvModule._parseVault;
|
|
4805
|
+
module.exports.config = DotenvModule.config;
|
|
4806
|
+
module.exports.decrypt = DotenvModule.decrypt;
|
|
4807
|
+
module.exports.parse = DotenvModule.parse;
|
|
4808
|
+
module.exports.populate = DotenvModule.populate;
|
|
4809
|
+
module.exports = DotenvModule;
|
|
4810
|
+
}
|
|
4811
|
+
});
|
|
4812
|
+
|
|
4813
|
+
// ../../node_modules/.pnpm/dotenv-expand@11.0.6/node_modules/dotenv-expand/lib/main.js
|
|
4814
|
+
var require_main2 = __commonJS({
|
|
4815
|
+
"../../node_modules/.pnpm/dotenv-expand@11.0.6/node_modules/dotenv-expand/lib/main.js"(exports, module) {
|
|
4816
|
+
"use strict";
|
|
4817
|
+
init_esm();
|
|
4818
|
+
var DOTENV_SUBSTITUTION_REGEX = /(\\)?(\$)(?!\()(\{?)([\w.]+)(?::?-((?:\$\{(?:\$\{(?:\$\{[^}]*\}|[^}])*}|[^}])*}|[^}])+))?(\}?)/gi;
|
|
4819
|
+
function _resolveEscapeSequences(value) {
|
|
4820
|
+
return value.replace(/\\\$/g, "$");
|
|
4821
|
+
}
|
|
4822
|
+
function interpolate(value, processEnv, parsed) {
|
|
4823
|
+
return value.replace(DOTENV_SUBSTITUTION_REGEX, (match, escaped, dollarSign, openBrace, key, defaultValue, closeBrace) => {
|
|
4824
|
+
if (escaped === "\\") {
|
|
4825
|
+
return match.slice(1);
|
|
4826
|
+
} else {
|
|
4827
|
+
if (processEnv[key]) {
|
|
4828
|
+
if (processEnv[key] === parsed[key]) {
|
|
4829
|
+
return processEnv[key];
|
|
4830
|
+
} else {
|
|
4831
|
+
return interpolate(processEnv[key], processEnv, parsed);
|
|
4832
|
+
}
|
|
4833
|
+
}
|
|
4834
|
+
if (parsed[key]) {
|
|
4835
|
+
if (parsed[key] === value) {
|
|
4836
|
+
return parsed[key];
|
|
4837
|
+
} else {
|
|
4838
|
+
return interpolate(parsed[key], processEnv, parsed);
|
|
4839
|
+
}
|
|
4840
|
+
}
|
|
4841
|
+
if (defaultValue) {
|
|
4842
|
+
if (defaultValue.startsWith("$")) {
|
|
4843
|
+
return interpolate(defaultValue, processEnv, parsed);
|
|
4844
|
+
} else {
|
|
4845
|
+
return defaultValue;
|
|
4846
|
+
}
|
|
4847
|
+
}
|
|
4848
|
+
return "";
|
|
4849
|
+
}
|
|
4850
|
+
});
|
|
4851
|
+
}
|
|
4852
|
+
function expand2(options) {
|
|
4853
|
+
let processEnv = process.env;
|
|
4854
|
+
if (options && options.processEnv != null) {
|
|
4855
|
+
processEnv = options.processEnv;
|
|
4856
|
+
}
|
|
4857
|
+
for (const key in options.parsed) {
|
|
4858
|
+
let value = options.parsed[key];
|
|
4859
|
+
const inProcessEnv = Object.prototype.hasOwnProperty.call(processEnv, key);
|
|
4860
|
+
if (inProcessEnv) {
|
|
4861
|
+
if (processEnv[key] === options.parsed[key]) {
|
|
4862
|
+
value = interpolate(value, processEnv, options.parsed);
|
|
4863
|
+
} else {
|
|
4864
|
+
value = processEnv[key];
|
|
4865
|
+
}
|
|
4866
|
+
} else {
|
|
4867
|
+
value = interpolate(value, processEnv, options.parsed);
|
|
4868
|
+
}
|
|
4869
|
+
options.parsed[key] = _resolveEscapeSequences(value);
|
|
4870
|
+
}
|
|
4871
|
+
for (const processKey in options.parsed) {
|
|
4872
|
+
processEnv[processKey] = options.parsed[processKey];
|
|
4873
|
+
}
|
|
4874
|
+
return options;
|
|
4875
|
+
}
|
|
4876
|
+
module.exports.expand = expand2;
|
|
4877
|
+
}
|
|
4878
|
+
});
|
|
4879
|
+
|
|
1393
4880
|
// src/loadEnv.ts
|
|
1394
4881
|
import fs3 from "fs";
|
|
1395
4882
|
import { join as join4 } from "path";
|
|
1396
|
-
import { parse } from "../compiled/dotenv/index.js";
|
|
1397
|
-
import { expand } from "../compiled/dotenv-expand/index.js";
|
|
1398
4883
|
function loadEnv({
|
|
1399
4884
|
cwd = process.cwd(),
|
|
1400
4885
|
mode = getNodeEnv(),
|
|
@@ -1414,12 +4899,12 @@ function loadEnv({
|
|
|
1414
4899
|
const filePaths = filenames.map((filename) => join4(cwd, filename)).filter(isFileSync);
|
|
1415
4900
|
const parsed = {};
|
|
1416
4901
|
for (const envPath of filePaths) {
|
|
1417
|
-
Object.assign(parsed, parse(fs3.readFileSync(envPath)));
|
|
4902
|
+
Object.assign(parsed, (0, import_dotenv.parse)(fs3.readFileSync(envPath)));
|
|
1418
4903
|
}
|
|
1419
4904
|
if (parsed.NODE_ENV) {
|
|
1420
4905
|
process.env.NODE_ENV = parsed.NODE_ENV;
|
|
1421
4906
|
}
|
|
1422
|
-
expand({ parsed });
|
|
4907
|
+
(0, import_dotenv_expand.expand)({ parsed });
|
|
1423
4908
|
const publicVars = {};
|
|
1424
4909
|
for (const key of Object.keys(process.env)) {
|
|
1425
4910
|
if (prefixes.some((prefix) => key.startsWith(prefix))) {
|
|
@@ -1450,14 +4935,216 @@ function loadEnv({
|
|
|
1450
4935
|
publicVars
|
|
1451
4936
|
};
|
|
1452
4937
|
}
|
|
4938
|
+
var import_dotenv, import_dotenv_expand;
|
|
1453
4939
|
var init_loadEnv = __esm({
|
|
1454
4940
|
"src/loadEnv.ts"() {
|
|
1455
4941
|
"use strict";
|
|
1456
4942
|
init_esm();
|
|
4943
|
+
import_dotenv = __toESM(require_main());
|
|
4944
|
+
import_dotenv_expand = __toESM(require_main2());
|
|
1457
4945
|
init_helpers();
|
|
1458
4946
|
}
|
|
1459
4947
|
});
|
|
1460
4948
|
|
|
4949
|
+
// ../../node_modules/.pnpm/browserslist-load-config@0.0.2/node_modules/browserslist-load-config/dist/index.js
|
|
4950
|
+
import fs4 from "fs";
|
|
4951
|
+
import path4 from "path";
|
|
4952
|
+
function isFile(file) {
|
|
4953
|
+
if (file in isFileCache) {
|
|
4954
|
+
return isFileCache[file];
|
|
4955
|
+
}
|
|
4956
|
+
const result = fs4.existsSync(file) && fs4.statSync(file).isFile();
|
|
4957
|
+
isFileCache[file] = result;
|
|
4958
|
+
return result;
|
|
4959
|
+
}
|
|
4960
|
+
function check(section) {
|
|
4961
|
+
const FORMAT = "Browserslist config should be a string or an array of strings with browser queries";
|
|
4962
|
+
if (Array.isArray(section)) {
|
|
4963
|
+
for (let i = 0; i < section.length; i++) {
|
|
4964
|
+
if (typeof section[i] !== "string") {
|
|
4965
|
+
throw new BrowserslistError(FORMAT);
|
|
4966
|
+
}
|
|
4967
|
+
}
|
|
4968
|
+
} else if (typeof section !== "string") {
|
|
4969
|
+
throw new BrowserslistError(FORMAT);
|
|
4970
|
+
}
|
|
4971
|
+
}
|
|
4972
|
+
function parsePackage(file) {
|
|
4973
|
+
const config = JSON.parse(
|
|
4974
|
+
fs4.readFileSync(file).toString().replace(/^\uFEFF/m, "")
|
|
4975
|
+
);
|
|
4976
|
+
if (config.browserlist && !config.browserslist) {
|
|
4977
|
+
throw new BrowserslistError(
|
|
4978
|
+
`\`browserlist\` key instead of \`browserslist\` in ${file}`
|
|
4979
|
+
);
|
|
4980
|
+
}
|
|
4981
|
+
let list = config.browserslist;
|
|
4982
|
+
if (Array.isArray(list) || typeof list === "string") {
|
|
4983
|
+
list = { defaults: list };
|
|
4984
|
+
}
|
|
4985
|
+
for (const i in list) {
|
|
4986
|
+
check(list[i]);
|
|
4987
|
+
}
|
|
4988
|
+
return list;
|
|
4989
|
+
}
|
|
4990
|
+
function parseConfig(string) {
|
|
4991
|
+
const result = { defaults: [] };
|
|
4992
|
+
let sections = ["defaults"];
|
|
4993
|
+
string.toString().replace(/#[^\n]*/g, "").split(/\n|,/).map((line) => line.trim()).filter((line) => line !== "").forEach((line) => {
|
|
4994
|
+
const matched = line.match(IS_SECTION);
|
|
4995
|
+
if (matched) {
|
|
4996
|
+
sections = matched[1].trim().split(" ");
|
|
4997
|
+
sections.forEach((section) => {
|
|
4998
|
+
if (result[section]) {
|
|
4999
|
+
throw new BrowserslistError(
|
|
5000
|
+
`Duplicate section ${section} in Browserslist config`
|
|
5001
|
+
);
|
|
5002
|
+
}
|
|
5003
|
+
result[section] = [];
|
|
5004
|
+
});
|
|
5005
|
+
} else {
|
|
5006
|
+
sections.forEach((section) => {
|
|
5007
|
+
result[section].push(line);
|
|
5008
|
+
});
|
|
5009
|
+
}
|
|
5010
|
+
});
|
|
5011
|
+
return result;
|
|
5012
|
+
}
|
|
5013
|
+
function readConfig(file) {
|
|
5014
|
+
if (!isFile(file)) {
|
|
5015
|
+
throw new BrowserslistError(`Can't read ${file} config`);
|
|
5016
|
+
}
|
|
5017
|
+
return parseConfig(fs4.readFileSync(file, "utf-8"));
|
|
5018
|
+
}
|
|
5019
|
+
function parsePackageOrReadConfig(file) {
|
|
5020
|
+
if (path4.basename(file) === "package.json") {
|
|
5021
|
+
return parsePackage(file);
|
|
5022
|
+
}
|
|
5023
|
+
return readConfig(file);
|
|
5024
|
+
}
|
|
5025
|
+
function pickEnv(config, opts) {
|
|
5026
|
+
if (typeof config !== "object") {
|
|
5027
|
+
return config;
|
|
5028
|
+
}
|
|
5029
|
+
let name;
|
|
5030
|
+
if (typeof opts.env === "string") {
|
|
5031
|
+
name = opts.env;
|
|
5032
|
+
} else if (process.env.BROWSERSLIST_ENV) {
|
|
5033
|
+
name = process.env.BROWSERSLIST_ENV;
|
|
5034
|
+
} else if (process.env.NODE_ENV) {
|
|
5035
|
+
name = process.env.NODE_ENV;
|
|
5036
|
+
} else {
|
|
5037
|
+
name = "production";
|
|
5038
|
+
}
|
|
5039
|
+
return config[name] || config.defaults;
|
|
5040
|
+
}
|
|
5041
|
+
function eachParent(file, callback) {
|
|
5042
|
+
const dir = isFile(file) ? path4.dirname(file) : file;
|
|
5043
|
+
let loc = path4.resolve(dir);
|
|
5044
|
+
do {
|
|
5045
|
+
const result = callback(loc);
|
|
5046
|
+
if (typeof result !== "undefined")
|
|
5047
|
+
return result;
|
|
5048
|
+
} while (loc !== (loc = path4.dirname(loc)));
|
|
5049
|
+
return void 0;
|
|
5050
|
+
}
|
|
5051
|
+
function findConfigFile(from) {
|
|
5052
|
+
return eachParent(from, (dir) => {
|
|
5053
|
+
const config = path4.join(dir, "browserslist");
|
|
5054
|
+
const pkg = path4.join(dir, "package.json");
|
|
5055
|
+
const rc = path4.join(dir, ".browserslistrc");
|
|
5056
|
+
let pkgBrowserslist;
|
|
5057
|
+
if (isFile(pkg)) {
|
|
5058
|
+
try {
|
|
5059
|
+
pkgBrowserslist = parsePackage(pkg);
|
|
5060
|
+
} catch (e) {
|
|
5061
|
+
if (e instanceof BrowserslistError)
|
|
5062
|
+
throw e;
|
|
5063
|
+
console.warn(`[Browserslist] Could not parse ${pkg}. Ignoring it.`);
|
|
5064
|
+
}
|
|
5065
|
+
}
|
|
5066
|
+
if (isFile(config) && pkgBrowserslist) {
|
|
5067
|
+
throw new BrowserslistError(
|
|
5068
|
+
`${dir} contains both browserslist and package.json with browsers`
|
|
5069
|
+
);
|
|
5070
|
+
}
|
|
5071
|
+
if (isFile(rc) && pkgBrowserslist) {
|
|
5072
|
+
throw new BrowserslistError(
|
|
5073
|
+
`${dir} contains both .browserslistrc and package.json with browsers`
|
|
5074
|
+
);
|
|
5075
|
+
}
|
|
5076
|
+
if (isFile(config) && isFile(rc)) {
|
|
5077
|
+
throw new BrowserslistError(
|
|
5078
|
+
`${dir} contains both .browserslistrc and browserslist`
|
|
5079
|
+
);
|
|
5080
|
+
}
|
|
5081
|
+
if (isFile(config)) {
|
|
5082
|
+
return config;
|
|
5083
|
+
}
|
|
5084
|
+
if (isFile(rc)) {
|
|
5085
|
+
return rc;
|
|
5086
|
+
}
|
|
5087
|
+
if (pkgBrowserslist) {
|
|
5088
|
+
return pkg;
|
|
5089
|
+
}
|
|
5090
|
+
});
|
|
5091
|
+
}
|
|
5092
|
+
function findConfig(from) {
|
|
5093
|
+
from = path4.resolve(from);
|
|
5094
|
+
const fromDir = isFile(from) ? path4.dirname(from) : from;
|
|
5095
|
+
if (fromDir in configCache) {
|
|
5096
|
+
return configCache[fromDir];
|
|
5097
|
+
}
|
|
5098
|
+
let resolved;
|
|
5099
|
+
const configFile = findConfigFile(from);
|
|
5100
|
+
if (configFile) {
|
|
5101
|
+
resolved = parsePackageOrReadConfig(configFile);
|
|
5102
|
+
}
|
|
5103
|
+
const configDir = configFile && path4.dirname(configFile);
|
|
5104
|
+
eachParent(from, (dir) => {
|
|
5105
|
+
if (resolved) {
|
|
5106
|
+
configCache[dir] = resolved;
|
|
5107
|
+
}
|
|
5108
|
+
if (dir === configDir) {
|
|
5109
|
+
return null;
|
|
5110
|
+
}
|
|
5111
|
+
});
|
|
5112
|
+
return resolved;
|
|
5113
|
+
}
|
|
5114
|
+
function loadConfig2(opts) {
|
|
5115
|
+
if (opts.config) {
|
|
5116
|
+
return pickEnv(parsePackageOrReadConfig(opts.config), opts);
|
|
5117
|
+
}
|
|
5118
|
+
if (opts.path) {
|
|
5119
|
+
const config = findConfig(opts.path);
|
|
5120
|
+
if (!config) {
|
|
5121
|
+
return void 0;
|
|
5122
|
+
}
|
|
5123
|
+
return pickEnv(config, opts);
|
|
5124
|
+
}
|
|
5125
|
+
return void 0;
|
|
5126
|
+
}
|
|
5127
|
+
var BrowserslistError, isFileCache, IS_SECTION, configCache;
|
|
5128
|
+
var init_dist = __esm({
|
|
5129
|
+
"../../node_modules/.pnpm/browserslist-load-config@0.0.2/node_modules/browserslist-load-config/dist/index.js"() {
|
|
5130
|
+
"use strict";
|
|
5131
|
+
init_esm();
|
|
5132
|
+
BrowserslistError = class _BrowserslistError extends Error {
|
|
5133
|
+
constructor(message) {
|
|
5134
|
+
super(message);
|
|
5135
|
+
this.name = "BrowserslistError";
|
|
5136
|
+
this.browserslist = true;
|
|
5137
|
+
if (Error.captureStackTrace) {
|
|
5138
|
+
Error.captureStackTrace(this, _BrowserslistError);
|
|
5139
|
+
}
|
|
5140
|
+
}
|
|
5141
|
+
};
|
|
5142
|
+
isFileCache = {};
|
|
5143
|
+
IS_SECTION = /^\s*\[(.+)]\s*$/;
|
|
5144
|
+
configCache = {};
|
|
5145
|
+
}
|
|
5146
|
+
});
|
|
5147
|
+
|
|
1461
5148
|
// src/pluginManager.ts
|
|
1462
5149
|
import color6 from "../compiled/picocolors/index.js";
|
|
1463
5150
|
function validatePlugin(plugin) {
|
|
@@ -2242,31 +5929,30 @@ var init_initPlugins = __esm({
|
|
|
2242
5929
|
|
|
2243
5930
|
// src/createContext.ts
|
|
2244
5931
|
import { join as join6 } from "path";
|
|
2245
|
-
import browserslist from "../compiled/browserslist/index.js";
|
|
2246
5932
|
function getAbsoluteDistPath(cwd, config) {
|
|
2247
5933
|
const dirRoot = config.output?.distPath?.root ?? ROOT_DIST_DIR;
|
|
2248
5934
|
return getAbsolutePath(cwd, dirRoot);
|
|
2249
5935
|
}
|
|
2250
|
-
async function getBrowserslist(
|
|
5936
|
+
async function getBrowserslist(path22) {
|
|
2251
5937
|
const env = process.env.NODE_ENV;
|
|
2252
|
-
const cacheKey =
|
|
5938
|
+
const cacheKey = path22 + env;
|
|
2253
5939
|
if (browsersListCache.has(cacheKey)) {
|
|
2254
5940
|
return browsersListCache.get(cacheKey);
|
|
2255
5941
|
}
|
|
2256
|
-
const result =
|
|
5942
|
+
const result = loadConfig2({ path: path22, env });
|
|
2257
5943
|
if (result) {
|
|
2258
5944
|
browsersListCache.set(cacheKey, result);
|
|
2259
5945
|
return result;
|
|
2260
5946
|
}
|
|
2261
5947
|
return null;
|
|
2262
5948
|
}
|
|
2263
|
-
async function getBrowserslistByEnvironment(
|
|
5949
|
+
async function getBrowserslistByEnvironment(path22, config) {
|
|
2264
5950
|
const { target, overrideBrowserslist } = config.output;
|
|
2265
5951
|
if (Array.isArray(overrideBrowserslist)) {
|
|
2266
5952
|
return overrideBrowserslist;
|
|
2267
5953
|
}
|
|
2268
5954
|
if (target === "web" || target === "web-worker") {
|
|
2269
|
-
const browserslistrc = await getBrowserslist(
|
|
5955
|
+
const browserslistrc = await getBrowserslist(path22);
|
|
2270
5956
|
if (browserslistrc) {
|
|
2271
5957
|
return browserslistrc;
|
|
2272
5958
|
}
|
|
@@ -2277,7 +5963,7 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
2277
5963
|
context.environments ||= {};
|
|
2278
5964
|
for (const [index, [name, config]] of Object.entries(configs).entries()) {
|
|
2279
5965
|
const tsconfigPath = config.source.tsconfigPath ? getAbsolutePath(context.rootPath, config.source.tsconfigPath) : void 0;
|
|
2280
|
-
const
|
|
5966
|
+
const browserslist = await getBrowserslistByEnvironment(
|
|
2281
5967
|
context.rootPath,
|
|
2282
5968
|
config
|
|
2283
5969
|
);
|
|
@@ -2288,7 +5974,7 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
2288
5974
|
name,
|
|
2289
5975
|
distPath: getAbsoluteDistPath(context.rootPath, config),
|
|
2290
5976
|
entry,
|
|
2291
|
-
browserslist
|
|
5977
|
+
browserslist,
|
|
2292
5978
|
htmlPaths,
|
|
2293
5979
|
tsconfigPath,
|
|
2294
5980
|
config
|
|
@@ -2342,7 +6028,7 @@ async function createContext(options, userConfig, bundlerType) {
|
|
|
2342
6028
|
const rsbuildConfig = await withDefaultConfig(rootPath, userConfig);
|
|
2343
6029
|
const cachePath = join6(rootPath, "node_modules", ".cache");
|
|
2344
6030
|
return {
|
|
2345
|
-
version: "1.0.
|
|
6031
|
+
version: "1.0.8",
|
|
2346
6032
|
rootPath,
|
|
2347
6033
|
distPath: "",
|
|
2348
6034
|
cachePath,
|
|
@@ -2359,6 +6045,7 @@ var init_createContext = __esm({
|
|
|
2359
6045
|
"src/createContext.ts"() {
|
|
2360
6046
|
"use strict";
|
|
2361
6047
|
init_esm();
|
|
6048
|
+
init_dist();
|
|
2362
6049
|
init_config();
|
|
2363
6050
|
init_constants();
|
|
2364
6051
|
init_path();
|
|
@@ -2590,7 +6277,7 @@ function reduceConfigsMergeContext({
|
|
|
2590
6277
|
return config ?? initial;
|
|
2591
6278
|
}
|
|
2592
6279
|
var isNil, isFunction2, isObject2, isPlainObject2;
|
|
2593
|
-
var
|
|
6280
|
+
var init_dist2 = __esm({
|
|
2594
6281
|
"../../node_modules/.pnpm/reduce-configs@1.0.0/node_modules/reduce-configs/dist/index.js"() {
|
|
2595
6282
|
"use strict";
|
|
2596
6283
|
init_esm();
|
|
@@ -2692,9 +6379,6 @@ var init_configChain = __esm({
|
|
|
2692
6379
|
PUG: "pug",
|
|
2693
6380
|
/** Rule for Vue */
|
|
2694
6381
|
VUE: "vue",
|
|
2695
|
-
// TODO: remove
|
|
2696
|
-
/** Rule for yaml */
|
|
2697
|
-
YAML: "yaml",
|
|
2698
6382
|
/** Rule for wasm */
|
|
2699
6383
|
WASM: "wasm",
|
|
2700
6384
|
/** Rule for svelte */
|
|
@@ -2730,9 +6414,6 @@ var init_configChain = __esm({
|
|
|
2730
6414
|
SWC: "swc",
|
|
2731
6415
|
/** svgr */
|
|
2732
6416
|
SVGR: "svgr",
|
|
2733
|
-
// TODO: remove
|
|
2734
|
-
/** yaml-loader */
|
|
2735
|
-
YAML: "yaml",
|
|
2736
6417
|
/** babel-loader */
|
|
2737
6418
|
BABEL: "babel",
|
|
2738
6419
|
/** style-loader */
|
|
@@ -2760,9 +6441,6 @@ var init_configChain = __esm({
|
|
|
2760
6441
|
COPY: "copy",
|
|
2761
6442
|
/** HtmlRspackPlugin */
|
|
2762
6443
|
HTML: "html",
|
|
2763
|
-
// TODO: remove
|
|
2764
|
-
/** ESLintWebpackPlugin */
|
|
2765
|
-
ESLINT: "eslint",
|
|
2766
6444
|
/** DefinePlugin */
|
|
2767
6445
|
DEFINE: "define",
|
|
2768
6446
|
/** ProgressPlugin */
|
|
@@ -2785,9 +6463,6 @@ var init_configChain = __esm({
|
|
|
2785
6463
|
VUE_LOADER_PLUGIN: "vue-loader-plugin",
|
|
2786
6464
|
/** ReactFastRefreshPlugin */
|
|
2787
6465
|
REACT_FAST_REFRESH: "react-fast-refresh",
|
|
2788
|
-
// TODO: remove
|
|
2789
|
-
/** ProvidePlugin for node polyfill */
|
|
2790
|
-
NODE_POLYFILL_PROVIDE: "node-polyfill-provide",
|
|
2791
6466
|
/** WebpackSRIPlugin */
|
|
2792
6467
|
SUBRESOURCE_INTEGRITY: "subresource-integrity",
|
|
2793
6468
|
/** AutoSetRootFontSizePlugin */
|
|
@@ -2921,7 +6596,7 @@ var init_rspackConfig = __esm({
|
|
|
2921
6596
|
"src/provider/rspackConfig.ts"() {
|
|
2922
6597
|
"use strict";
|
|
2923
6598
|
init_esm();
|
|
2924
|
-
|
|
6599
|
+
init_dist2();
|
|
2925
6600
|
init_configChain();
|
|
2926
6601
|
init_helpers();
|
|
2927
6602
|
init_logger();
|
|
@@ -3166,9 +6841,13 @@ async function createCompiler(options) {
|
|
|
3166
6841
|
compiler.hooks.run.tap("rsbuild:run", logRspackVersion);
|
|
3167
6842
|
}
|
|
3168
6843
|
const done = (stats) => {
|
|
6844
|
+
const statsOptions = getStatsOptions(compiler);
|
|
3169
6845
|
const statsJson = stats.toJson({
|
|
3170
|
-
|
|
3171
|
-
|
|
6846
|
+
children: true,
|
|
6847
|
+
// get the compilation time
|
|
6848
|
+
timings: true,
|
|
6849
|
+
...typeof statsOptions === "string" ? { preset: statsOptions } : { preset: "errors-warnings" },
|
|
6850
|
+
...typeof statsOptions === "object" ? statsOptions : {}
|
|
3172
6851
|
});
|
|
3173
6852
|
const printTime = (c, index) => {
|
|
3174
6853
|
if (c.time) {
|
|
@@ -3178,8 +6857,9 @@ async function createCompiler(options) {
|
|
|
3178
6857
|
logger.ready(`Compiled in ${time}${suffix}`);
|
|
3179
6858
|
}
|
|
3180
6859
|
};
|
|
3181
|
-
|
|
3182
|
-
|
|
6860
|
+
const hasErrors = stats.hasErrors();
|
|
6861
|
+
if (!hasErrors) {
|
|
6862
|
+
if (statsJson.children && statsJson.children.length > 0) {
|
|
3183
6863
|
statsJson.children.forEach((c, index) => {
|
|
3184
6864
|
printTime(c, index);
|
|
3185
6865
|
});
|
|
@@ -3187,7 +6867,7 @@ async function createCompiler(options) {
|
|
|
3187
6867
|
printTime(statsJson, 0);
|
|
3188
6868
|
}
|
|
3189
6869
|
}
|
|
3190
|
-
const { message, level } = formatStats(
|
|
6870
|
+
const { message, level } = formatStats(statsJson, hasErrors);
|
|
3191
6871
|
if (level === "error") {
|
|
3192
6872
|
logger.error(message);
|
|
3193
6873
|
}
|
|
@@ -3265,7 +6945,7 @@ var init_asModule = __esm({
|
|
|
3265
6945
|
});
|
|
3266
6946
|
|
|
3267
6947
|
// src/server/runner/basic.ts
|
|
3268
|
-
import
|
|
6948
|
+
import path5 from "path";
|
|
3269
6949
|
var isRelativePath, getSubPath, BasicRunner;
|
|
3270
6950
|
var init_basic = __esm({
|
|
3271
6951
|
"src/server/runner/basic.ts"() {
|
|
@@ -3321,7 +7001,7 @@ var init_basic = __esm({
|
|
|
3321
7001
|
getFile(modulePath, currentDirectory) {
|
|
3322
7002
|
if (Array.isArray(modulePath)) {
|
|
3323
7003
|
return {
|
|
3324
|
-
path:
|
|
7004
|
+
path: path5.join(currentDirectory, ".array-require.js"),
|
|
3325
7005
|
content: `module.exports = (${modulePath.map((arg) => {
|
|
3326
7006
|
return `require(${JSON.stringify(`./${arg}`)})`;
|
|
3327
7007
|
}).join(", ")});`,
|
|
@@ -3329,7 +7009,7 @@ var init_basic = __esm({
|
|
|
3329
7009
|
};
|
|
3330
7010
|
}
|
|
3331
7011
|
if (isRelativePath(modulePath)) {
|
|
3332
|
-
const p =
|
|
7012
|
+
const p = path5.join(currentDirectory, modulePath);
|
|
3333
7013
|
return {
|
|
3334
7014
|
path: p,
|
|
3335
7015
|
content: this._options.readFileSync(p),
|
|
@@ -3355,7 +7035,7 @@ var init_basic = __esm({
|
|
|
3355
7035
|
});
|
|
3356
7036
|
|
|
3357
7037
|
// src/server/runner/cjs.ts
|
|
3358
|
-
import
|
|
7038
|
+
import path6 from "path";
|
|
3359
7039
|
import vm2 from "vm";
|
|
3360
7040
|
var define, CommonJsRunner;
|
|
3361
7041
|
var init_cjs = __esm({
|
|
@@ -3396,10 +7076,10 @@ var init_cjs = __esm({
|
|
|
3396
7076
|
createModuleScope(requireFn, m, file) {
|
|
3397
7077
|
return {
|
|
3398
7078
|
...this.baseModuleScope,
|
|
3399
|
-
require: requireFn.bind(null,
|
|
7079
|
+
require: requireFn.bind(null, path6.dirname(file.path)),
|
|
3400
7080
|
module: m,
|
|
3401
7081
|
exports: m.exports,
|
|
3402
|
-
__dirname:
|
|
7082
|
+
__dirname: path6.dirname(file.path),
|
|
3403
7083
|
__filename: file.path,
|
|
3404
7084
|
define
|
|
3405
7085
|
};
|
|
@@ -3458,11 +7138,11 @@ var init_type = __esm({
|
|
|
3458
7138
|
});
|
|
3459
7139
|
|
|
3460
7140
|
// src/server/runner/esm.ts
|
|
3461
|
-
import
|
|
7141
|
+
import path7 from "path";
|
|
3462
7142
|
import { fileURLToPath as fileURLToPath2, pathToFileURL } from "url";
|
|
3463
7143
|
import vm3 from "vm";
|
|
3464
7144
|
var EsmRunner;
|
|
3465
|
-
var
|
|
7145
|
+
var init_esm3 = __esm({
|
|
3466
7146
|
"src/server/runner/esm.ts"() {
|
|
3467
7147
|
"use strict";
|
|
3468
7148
|
init_esm();
|
|
@@ -3519,7 +7199,7 @@ var init_esm2 = __esm({
|
|
|
3519
7199
|
meta.url = pathToFileURL(file.path).href;
|
|
3520
7200
|
},
|
|
3521
7201
|
importModuleDynamically: async (specifier, module) => {
|
|
3522
|
-
const result = await _require(
|
|
7202
|
+
const result = await _require(path7.dirname(file.path), specifier, {
|
|
3523
7203
|
esmMode: 1 /* Evaluated */
|
|
3524
7204
|
});
|
|
3525
7205
|
return await asModule(result, module.context);
|
|
@@ -3533,7 +7213,7 @@ var init_esm2 = __esm({
|
|
|
3533
7213
|
await esm.link(async (specifier, referencingModule) => {
|
|
3534
7214
|
return await asModule(
|
|
3535
7215
|
await _require(
|
|
3536
|
-
|
|
7216
|
+
path7.dirname(
|
|
3537
7217
|
referencingModule.identifier ? referencingModule.identifier.slice(esmIdentifier.length + 1) : fileURLToPath2(referencingModule.url)
|
|
3538
7218
|
),
|
|
3539
7219
|
specifier,
|
|
@@ -3566,7 +7246,7 @@ var init_runner = __esm({
|
|
|
3566
7246
|
"src/server/runner/index.ts"() {
|
|
3567
7247
|
"use strict";
|
|
3568
7248
|
init_esm();
|
|
3569
|
-
|
|
7249
|
+
init_esm3();
|
|
3570
7250
|
BasicRunnerFactory = class {
|
|
3571
7251
|
constructor(name) {
|
|
3572
7252
|
this.name = name;
|
|
@@ -3658,7 +7338,7 @@ var init_environment = __esm({
|
|
|
3658
7338
|
});
|
|
3659
7339
|
|
|
3660
7340
|
// src/server/middlewares.ts
|
|
3661
|
-
import
|
|
7341
|
+
import path8 from "path";
|
|
3662
7342
|
import { parse as parse2 } from "url";
|
|
3663
7343
|
import color9 from "../compiled/picocolors/index.js";
|
|
3664
7344
|
var faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, isFileExists2, maybeHTMLRequest, getHtmlCompletionMiddleware, getHtmlFallbackMiddleware;
|
|
@@ -3754,13 +7434,13 @@ var init_middlewares = __esm({
|
|
|
3754
7434
|
};
|
|
3755
7435
|
if (pathname.endsWith("/")) {
|
|
3756
7436
|
const newUrl = `${pathname}index.html`;
|
|
3757
|
-
const filePath =
|
|
7437
|
+
const filePath = path8.join(distPath, newUrl);
|
|
3758
7438
|
if (await isFileExists2(filePath, outputFileSystem)) {
|
|
3759
7439
|
return rewrite(newUrl);
|
|
3760
7440
|
}
|
|
3761
|
-
} else if (!
|
|
7441
|
+
} else if (!path8.extname(pathname)) {
|
|
3762
7442
|
const newUrl = `${pathname}.html`;
|
|
3763
|
-
const filePath =
|
|
7443
|
+
const filePath = path8.join(distPath, newUrl);
|
|
3764
7444
|
if (await isFileExists2(filePath, outputFileSystem)) {
|
|
3765
7445
|
return rewrite(newUrl);
|
|
3766
7446
|
}
|
|
@@ -3773,7 +7453,7 @@ var init_middlewares = __esm({
|
|
|
3773
7453
|
if (!maybeHTMLRequest(req) || "/favicon.ico" === req.url || htmlFallback !== "index") {
|
|
3774
7454
|
return next();
|
|
3775
7455
|
}
|
|
3776
|
-
const filePath =
|
|
7456
|
+
const filePath = path8.join(distPath, "index.html");
|
|
3777
7457
|
if (await isFileExists2(filePath, outputFileSystem)) {
|
|
3778
7458
|
const newUrl = "/index.html";
|
|
3779
7459
|
if (logger.level === "verbose") {
|
|
@@ -4014,8 +7694,8 @@ var init_getDevMiddlewares = __esm({
|
|
|
4014
7694
|
}
|
|
4015
7695
|
middlewares.push((req, res, next) => {
|
|
4016
7696
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
4017
|
-
const
|
|
4018
|
-
if (
|
|
7697
|
+
const path22 = req.url ? url.parse(req.url).pathname : "";
|
|
7698
|
+
if (path22?.includes("hot-update")) {
|
|
4019
7699
|
res.setHeader("Access-Control-Allow-Credentials", "false");
|
|
4020
7700
|
}
|
|
4021
7701
|
const confHeaders = server.headers;
|
|
@@ -5091,7 +8771,7 @@ var devServer_exports = {};
|
|
|
5091
8771
|
__export(devServer_exports, {
|
|
5092
8772
|
createDevServer: () => createDevServer
|
|
5093
8773
|
});
|
|
5094
|
-
import
|
|
8774
|
+
import fs5 from "fs";
|
|
5095
8775
|
async function createDevServer(options, createCompiler2, config, {
|
|
5096
8776
|
compiler: customCompiler,
|
|
5097
8777
|
getPortSilently,
|
|
@@ -5109,7 +8789,7 @@ async function createDevServer(options, createCompiler2, config, {
|
|
|
5109
8789
|
port,
|
|
5110
8790
|
https
|
|
5111
8791
|
};
|
|
5112
|
-
let outputFileSystem =
|
|
8792
|
+
let outputFileSystem = fs5;
|
|
5113
8793
|
let lastStats;
|
|
5114
8794
|
const waitFirstCompileDone = runCompile ? new Promise((resolve2) => {
|
|
5115
8795
|
options.context.hooks.onDevCompileDone.tap(
|
|
@@ -5136,7 +8816,7 @@ async function createDevServer(options, createCompiler2, config, {
|
|
|
5136
8816
|
compiler
|
|
5137
8817
|
});
|
|
5138
8818
|
await compilerDevMiddleware.init();
|
|
5139
|
-
outputFileSystem = (isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) ||
|
|
8819
|
+
outputFileSystem = (isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || fs5;
|
|
5140
8820
|
return {
|
|
5141
8821
|
middleware: compilerDevMiddleware.middleware,
|
|
5142
8822
|
sockWrite: (...args) => compilerDevMiddleware.sockWrite(...args),
|
|
@@ -5174,7 +8854,7 @@ async function createDevServer(options, createCompiler2, config, {
|
|
|
5174
8854
|
if ("readFileSync" in outputFileSystem) {
|
|
5175
8855
|
return outputFileSystem.readFileSync(fileName, "utf-8");
|
|
5176
8856
|
}
|
|
5177
|
-
return
|
|
8857
|
+
return fs5.readFileSync(fileName, "utf-8");
|
|
5178
8858
|
};
|
|
5179
8859
|
const environmentAPI = Object.fromEntries(
|
|
5180
8860
|
Object.entries(options.context.environments).map(([name, environment]) => {
|
|
@@ -5470,7 +9150,7 @@ var basic_exports = {};
|
|
|
5470
9150
|
__export(basic_exports, {
|
|
5471
9151
|
pluginBasic: () => pluginBasic
|
|
5472
9152
|
});
|
|
5473
|
-
import
|
|
9153
|
+
import path9 from "path";
|
|
5474
9154
|
var getJsSourceMap, pluginBasic;
|
|
5475
9155
|
var init_basic2 = __esm({
|
|
5476
9156
|
"src/plugins/basic.ts"() {
|
|
@@ -5511,7 +9191,7 @@ var init_basic2 = __esm({
|
|
|
5511
9191
|
}
|
|
5512
9192
|
if (env === "development") {
|
|
5513
9193
|
chain.output.devtoolModuleFilenameTemplate(
|
|
5514
|
-
(info) =>
|
|
9194
|
+
(info) => path9.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
|
|
5515
9195
|
);
|
|
5516
9196
|
}
|
|
5517
9197
|
process.env.RSPACK_CONFIG_VALIDATE ||= "loose-unrecognized-keys";
|
|
@@ -5581,20 +9261,20 @@ __export(cache_exports, {
|
|
|
5581
9261
|
pluginCache: () => pluginCache
|
|
5582
9262
|
});
|
|
5583
9263
|
import crypto from "crypto";
|
|
5584
|
-
import
|
|
9264
|
+
import fs6 from "fs";
|
|
5585
9265
|
import { isAbsolute as isAbsolute5, join as join10 } from "path";
|
|
5586
9266
|
async function validateCache(cacheDirectory, buildDependencies) {
|
|
5587
9267
|
const configFile = join10(cacheDirectory, "buildDependencies.json");
|
|
5588
9268
|
if (await isFileExists(configFile)) {
|
|
5589
|
-
const rawConfigFile = await
|
|
9269
|
+
const rawConfigFile = await fs6.promises.readFile(configFile, "utf-8");
|
|
5590
9270
|
const prevBuildDependencies = JSON.parse(rawConfigFile);
|
|
5591
9271
|
if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) {
|
|
5592
9272
|
return;
|
|
5593
9273
|
}
|
|
5594
|
-
await
|
|
9274
|
+
await fs6.promises.rm(cacheDirectory, { force: true, recursive: true });
|
|
5595
9275
|
}
|
|
5596
|
-
await
|
|
5597
|
-
await
|
|
9276
|
+
await fs6.promises.mkdir(cacheDirectory, { recursive: true });
|
|
9277
|
+
await fs6.promises.writeFile(configFile, JSON.stringify(buildDependencies));
|
|
5598
9278
|
}
|
|
5599
9279
|
function getDigestHash(digest) {
|
|
5600
9280
|
const fsHash = crypto.createHash("md5");
|
|
@@ -5677,84 +9357,17 @@ var init_cache = __esm({
|
|
|
5677
9357
|
}
|
|
5678
9358
|
});
|
|
5679
9359
|
|
|
5680
|
-
// ../../node_modules/.pnpm/browserslist-to-es-version@1.0.0/node_modules/browserslist-to-es-version/dist/index.js
|
|
5681
|
-
var dist_exports = {};
|
|
5682
|
-
__export(dist_exports, {
|
|
5683
|
-
browserslistToESVersion: () => browserslistToESVersion
|
|
5684
|
-
});
|
|
5685
|
-
import browserslist2 from "../compiled/browserslist/index.js";
|
|
5686
|
-
function browserslistToESVersion(browsers) {
|
|
5687
|
-
const projectBrowsers = browserslist2(browsers, {
|
|
5688
|
-
ignoreUnknownVersions: true
|
|
5689
|
-
});
|
|
5690
|
-
let esVersion = 2018;
|
|
5691
|
-
for (const item of projectBrowsers) {
|
|
5692
|
-
const pairs = item.split(" ");
|
|
5693
|
-
if (pairs.length < 2) {
|
|
5694
|
-
continue;
|
|
5695
|
-
}
|
|
5696
|
-
const browser = renameBrowser(pairs[0]);
|
|
5697
|
-
const version2 = Number(pairs[1].split("-")[0]);
|
|
5698
|
-
if (Number.isNaN(version2)) {
|
|
5699
|
-
continue;
|
|
5700
|
-
}
|
|
5701
|
-
if (browser === "ie" || browser === "android" && version2 < 6) {
|
|
5702
|
-
esVersion = 5;
|
|
5703
|
-
break;
|
|
5704
|
-
}
|
|
5705
|
-
const versions = ES_VERSIONS_MAP[browser];
|
|
5706
|
-
if (!versions) {
|
|
5707
|
-
continue;
|
|
5708
|
-
}
|
|
5709
|
-
if (version2 < versions[0]) {
|
|
5710
|
-
esVersion = Math.min(5, esVersion);
|
|
5711
|
-
} else if (version2 < versions[1]) {
|
|
5712
|
-
esVersion = Math.min(2015, esVersion);
|
|
5713
|
-
} else if (version2 < versions[2]) {
|
|
5714
|
-
esVersion = Math.min(2016, esVersion);
|
|
5715
|
-
} else if (version2 < versions[3]) {
|
|
5716
|
-
esVersion = Math.min(2017, esVersion);
|
|
5717
|
-
}
|
|
5718
|
-
}
|
|
5719
|
-
return esVersion;
|
|
5720
|
-
}
|
|
5721
|
-
var ES_VERSIONS_MAP, renameBrowser;
|
|
5722
|
-
var init_dist2 = __esm({
|
|
5723
|
-
"../../node_modules/.pnpm/browserslist-to-es-version@1.0.0/node_modules/browserslist-to-es-version/dist/index.js"() {
|
|
5724
|
-
"use strict";
|
|
5725
|
-
init_esm();
|
|
5726
|
-
ES_VERSIONS_MAP = {
|
|
5727
|
-
chrome: [51, 52, 57, 64],
|
|
5728
|
-
edge: [15, 15, 15, 79],
|
|
5729
|
-
safari: [10, 10.3, 11, 16.4],
|
|
5730
|
-
firefox: [54, 54, 54, 78],
|
|
5731
|
-
opera: [38, 39, 44, 51],
|
|
5732
|
-
samsung: [5, 6.2, 6.2, 8.2]
|
|
5733
|
-
};
|
|
5734
|
-
renameBrowser = (name) => {
|
|
5735
|
-
return name === "ios_saf" ? "safari" : name;
|
|
5736
|
-
};
|
|
5737
|
-
}
|
|
5738
|
-
});
|
|
5739
|
-
|
|
5740
9360
|
// src/plugins/target.ts
|
|
5741
9361
|
var target_exports = {};
|
|
5742
9362
|
__export(target_exports, {
|
|
5743
9363
|
pluginTarget: () => pluginTarget
|
|
5744
9364
|
});
|
|
5745
|
-
var
|
|
9365
|
+
var pluginTarget;
|
|
5746
9366
|
var init_target = __esm({
|
|
5747
9367
|
"src/plugins/target.ts"() {
|
|
5748
9368
|
"use strict";
|
|
5749
9369
|
init_esm();
|
|
5750
9370
|
init_constants();
|
|
5751
|
-
getESVersion = async (browserslist3) => {
|
|
5752
|
-
const { browserslistToESVersion: browserslistToESVersion2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
|
|
5753
|
-
if (browserslist3.join(",") === DEFAULT_WEB_BROWSERSLIST.join(",")) {
|
|
5754
|
-
return 2017;
|
|
5755
|
-
}
|
|
5756
|
-
return browserslistToESVersion2(browserslist3);
|
|
5757
|
-
};
|
|
5758
9371
|
pluginTarget = () => ({
|
|
5759
9372
|
name: "rsbuild:target",
|
|
5760
9373
|
setup(api) {
|
|
@@ -5765,13 +9378,19 @@ var init_target = __esm({
|
|
|
5765
9378
|
chain.target("node");
|
|
5766
9379
|
return;
|
|
5767
9380
|
}
|
|
5768
|
-
const { browserslist
|
|
5769
|
-
const
|
|
9381
|
+
const { browserslist } = environment;
|
|
9382
|
+
const isDefaultBrowserslist = browserslist.join(",") === DEFAULT_WEB_BROWSERSLIST.join(",");
|
|
5770
9383
|
if (target === "web-worker") {
|
|
5771
|
-
chain.target(
|
|
9384
|
+
chain.target(
|
|
9385
|
+
isDefaultBrowserslist ? ["webworker", "es2017"] : (
|
|
9386
|
+
// TODO: Rspack should support `browserslist:` for webworker target
|
|
9387
|
+
["webworker", "es5"]
|
|
9388
|
+
)
|
|
9389
|
+
);
|
|
5772
9390
|
return;
|
|
5773
9391
|
}
|
|
5774
|
-
|
|
9392
|
+
const esQuery = isDefaultBrowserslist ? "es2017" : `browserslist:${browserslist.join(",")}`;
|
|
9393
|
+
chain.target(["web", esQuery]);
|
|
5775
9394
|
}
|
|
5776
9395
|
});
|
|
5777
9396
|
}
|
|
@@ -5786,7 +9405,7 @@ __export(css_exports, {
|
|
|
5786
9405
|
normalizeCssLoaderOptions: () => normalizeCssLoaderOptions,
|
|
5787
9406
|
pluginCss: () => pluginCss
|
|
5788
9407
|
});
|
|
5789
|
-
import
|
|
9408
|
+
import path10 from "path";
|
|
5790
9409
|
async function loadUserPostcssrc(root) {
|
|
5791
9410
|
const cached = userPostcssrcCache.get(root);
|
|
5792
9411
|
if (cached) {
|
|
@@ -5823,7 +9442,7 @@ async function applyCSSRule({
|
|
|
5823
9442
|
rule.use(CHAIN_ID2.USE.STYLE).loader(getCompiledPath("style-loader")).options(styleLoaderOptions);
|
|
5824
9443
|
}
|
|
5825
9444
|
} else {
|
|
5826
|
-
rule.use(CHAIN_ID2.USE.IGNORE_CSS).loader(
|
|
9445
|
+
rule.use(CHAIN_ID2.USE.IGNORE_CSS).loader(path10.join(LOADER_PATH, "ignoreCssLoader.cjs"));
|
|
5827
9446
|
}
|
|
5828
9447
|
let importLoaders = 0;
|
|
5829
9448
|
rule.use(CHAIN_ID2.USE.CSS).loader(getCompiledPath("css-loader"));
|
|
@@ -5869,7 +9488,7 @@ var init_css = __esm({
|
|
|
5869
9488
|
"use strict";
|
|
5870
9489
|
init_esm();
|
|
5871
9490
|
import_deepmerge2 = __toESM(require_cjs());
|
|
5872
|
-
|
|
9491
|
+
init_dist2();
|
|
5873
9492
|
init_constants();
|
|
5874
9493
|
init_path();
|
|
5875
9494
|
init_pluginHelper();
|
|
@@ -6109,10 +9728,7 @@ function applyFullySpecified({
|
|
|
6109
9728
|
}) {
|
|
6110
9729
|
chain.module.rule(CHAIN_ID2.RULE.MJS).test(/\.m?js/).resolve.set("fullySpecified", false);
|
|
6111
9730
|
}
|
|
6112
|
-
function applyExtensions({
|
|
6113
|
-
chain,
|
|
6114
|
-
tsconfigPath
|
|
6115
|
-
}) {
|
|
9731
|
+
function applyExtensions({ chain }) {
|
|
6116
9732
|
const extensions = [
|
|
6117
9733
|
// most projects are using TypeScript, resolve .ts(x) files first to reduce resolve time.
|
|
6118
9734
|
".ts",
|
|
@@ -6123,11 +9739,6 @@ function applyExtensions({
|
|
|
6123
9739
|
".json"
|
|
6124
9740
|
];
|
|
6125
9741
|
chain.resolve.extensions.merge(extensions);
|
|
6126
|
-
if (tsconfigPath) {
|
|
6127
|
-
chain.resolve.extensionAlias.merge({
|
|
6128
|
-
".js": [".ts", ".tsx", ".js"]
|
|
6129
|
-
});
|
|
6130
|
-
}
|
|
6131
9742
|
}
|
|
6132
9743
|
function applyAlias({
|
|
6133
9744
|
chain,
|
|
@@ -6161,7 +9772,7 @@ var init_resolve = __esm({
|
|
|
6161
9772
|
"src/plugins/resolve.ts"() {
|
|
6162
9773
|
"use strict";
|
|
6163
9774
|
init_esm();
|
|
6164
|
-
|
|
9775
|
+
init_dist2();
|
|
6165
9776
|
init_helpers();
|
|
6166
9777
|
init_path();
|
|
6167
9778
|
pluginResolve = () => ({
|
|
@@ -6171,7 +9782,7 @@ var init_resolve = __esm({
|
|
|
6171
9782
|
order: "pre",
|
|
6172
9783
|
handler: (chain, { environment, CHAIN_ID: CHAIN_ID2 }) => {
|
|
6173
9784
|
const { config, tsconfigPath } = environment;
|
|
6174
|
-
applyExtensions({ chain
|
|
9785
|
+
applyExtensions({ chain });
|
|
6175
9786
|
applyAlias({
|
|
6176
9787
|
chain,
|
|
6177
9788
|
config,
|
|
@@ -6197,8 +9808,8 @@ __export(fileSize_exports, {
|
|
|
6197
9808
|
filterAsset: () => filterAsset,
|
|
6198
9809
|
pluginFileSize: () => pluginFileSize
|
|
6199
9810
|
});
|
|
6200
|
-
import
|
|
6201
|
-
import
|
|
9811
|
+
import fs7 from "fs";
|
|
9812
|
+
import path11 from "path";
|
|
6202
9813
|
import { promisify as promisify2 } from "util";
|
|
6203
9814
|
import zlib2 from "zlib";
|
|
6204
9815
|
import color12 from "../compiled/picocolors/index.js";
|
|
@@ -6229,14 +9840,14 @@ async function printFileSizes(options, stats, rootPath) {
|
|
|
6229
9840
|
}
|
|
6230
9841
|
const formatAsset = async (asset, distPath, distFolder) => {
|
|
6231
9842
|
const fileName = asset.name.split("?")[0];
|
|
6232
|
-
const contents = await
|
|
9843
|
+
const contents = await fs7.promises.readFile(path11.join(distPath, fileName));
|
|
6233
9844
|
const size = contents.length;
|
|
6234
9845
|
const gzippedSize = options.compressed ? await gzipSize(contents) : null;
|
|
6235
9846
|
const gzipSizeLabel = gzippedSize ? getAssetColor(gzippedSize)(calcFileSize(gzippedSize)) : null;
|
|
6236
9847
|
return {
|
|
6237
9848
|
size,
|
|
6238
|
-
folder:
|
|
6239
|
-
name:
|
|
9849
|
+
folder: path11.join(distFolder, path11.dirname(fileName)),
|
|
9850
|
+
name: path11.basename(fileName),
|
|
6240
9851
|
gzippedSize,
|
|
6241
9852
|
sizeLabel: calcFileSize(size),
|
|
6242
9853
|
gzipSizeLabel
|
|
@@ -6260,7 +9871,7 @@ async function printFileSizes(options, stats, rootPath) {
|
|
|
6260
9871
|
const filteredAssets = origin.assets.filter(
|
|
6261
9872
|
(asset) => filterAsset(asset.name)
|
|
6262
9873
|
);
|
|
6263
|
-
const distFolder =
|
|
9874
|
+
const distFolder = path11.relative(rootPath, distPath);
|
|
6264
9875
|
return Promise.all(
|
|
6265
9876
|
filteredAssets.map((asset) => formatAsset(asset, distPath, distFolder))
|
|
6266
9877
|
);
|
|
@@ -6272,7 +9883,7 @@ async function printFileSizes(options, stats, rootPath) {
|
|
|
6272
9883
|
assets.sort((a, b) => a.size - b.size);
|
|
6273
9884
|
const longestLabelLength = Math.max(...assets.map((a) => a.sizeLabel.length));
|
|
6274
9885
|
const longestFileLength = Math.max(
|
|
6275
|
-
...assets.map((a) => (a.folder +
|
|
9886
|
+
...assets.map((a) => (a.folder + path11.sep + a.name).length)
|
|
6276
9887
|
);
|
|
6277
9888
|
if (options.detail !== false) {
|
|
6278
9889
|
logs.push(getHeader(longestFileLength, longestLabelLength, options));
|
|
@@ -6282,7 +9893,7 @@ async function printFileSizes(options, stats, rootPath) {
|
|
|
6282
9893
|
for (const asset of assets) {
|
|
6283
9894
|
let { sizeLabel } = asset;
|
|
6284
9895
|
const { name, folder, gzipSizeLabel } = asset;
|
|
6285
|
-
const fileNameLength = (folder +
|
|
9896
|
+
const fileNameLength = (folder + path11.sep + name).length;
|
|
6286
9897
|
const sizeLength = sizeLabel.length;
|
|
6287
9898
|
totalSize += asset.size;
|
|
6288
9899
|
if (asset.gzippedSize) {
|
|
@@ -6293,7 +9904,7 @@ async function printFileSizes(options, stats, rootPath) {
|
|
|
6293
9904
|
const rightPadding = " ".repeat(longestLabelLength - sizeLength);
|
|
6294
9905
|
sizeLabel += rightPadding;
|
|
6295
9906
|
}
|
|
6296
|
-
let fileNameLabel = color12.dim(asset.folder +
|
|
9907
|
+
let fileNameLabel = color12.dim(asset.folder + path11.sep) + coloringAssetName(asset.name);
|
|
6297
9908
|
if (fileNameLength < longestFileLength) {
|
|
6298
9909
|
const rightPadding = " ".repeat(longestFileLength - fileNameLength);
|
|
6299
9910
|
fileNameLabel += rightPadding;
|
|
@@ -6495,7 +10106,7 @@ __export(asset_exports, {
|
|
|
6495
10106
|
getRegExpForExts: () => getRegExpForExts,
|
|
6496
10107
|
pluginAsset: () => pluginAsset
|
|
6497
10108
|
});
|
|
6498
|
-
import
|
|
10109
|
+
import path12 from "path";
|
|
6499
10110
|
function getRegExpForExts(exts) {
|
|
6500
10111
|
const matcher = exts.map((ext) => ext.trim()).map((ext) => ext.startsWith(".") ? ext.slice(1) : ext).join("|");
|
|
6501
10112
|
return new RegExp(
|
|
@@ -6547,7 +10158,7 @@ var init_asset = __esm({
|
|
|
6547
10158
|
emit,
|
|
6548
10159
|
rule,
|
|
6549
10160
|
maxSize,
|
|
6550
|
-
filename:
|
|
10161
|
+
filename: path12.posix.join(distDir, filename),
|
|
6551
10162
|
assetType
|
|
6552
10163
|
});
|
|
6553
10164
|
};
|
|
@@ -6573,7 +10184,7 @@ __export(RsbuildHtmlPlugin_exports, {
|
|
|
6573
10184
|
RsbuildHtmlPlugin: () => RsbuildHtmlPlugin,
|
|
6574
10185
|
hasTitle: () => hasTitle
|
|
6575
10186
|
});
|
|
6576
|
-
import
|
|
10187
|
+
import path13 from "path";
|
|
6577
10188
|
import { promisify as promisify3 } from "util";
|
|
6578
10189
|
var VOID_TAGS, HEAD_TAGS, FILE_ATTRS, hasTitle, getTagPriority, formatBasicTag, fromBasicTag, formatTags, applyTagConfig, addTitleTag, RsbuildHtmlPlugin;
|
|
6579
10190
|
var init_RsbuildHtmlPlugin = __esm({
|
|
@@ -6730,7 +10341,7 @@ var init_RsbuildHtmlPlugin = __esm({
|
|
|
6730
10341
|
}
|
|
6731
10342
|
apply(compiler) {
|
|
6732
10343
|
const emitFavicon = async (compilation, favicon) => {
|
|
6733
|
-
const name =
|
|
10344
|
+
const name = path13.basename(favicon);
|
|
6734
10345
|
if (compilation.assets[name]) {
|
|
6735
10346
|
return name;
|
|
6736
10347
|
}
|
|
@@ -6739,7 +10350,7 @@ var init_RsbuildHtmlPlugin = __esm({
|
|
|
6739
10350
|
`[RsbuildHtmlPlugin] 'compilation.inputFileSystem' is not available.`
|
|
6740
10351
|
);
|
|
6741
10352
|
}
|
|
6742
|
-
const filename =
|
|
10353
|
+
const filename = path13.resolve(compilation.compiler.context, favicon);
|
|
6743
10354
|
const buf = await promisify3(compilation.inputFileSystem.readFile)(
|
|
6744
10355
|
filename
|
|
6745
10356
|
);
|
|
@@ -6819,8 +10430,8 @@ __export(html_exports, {
|
|
|
6819
10430
|
getTemplate: () => getTemplate,
|
|
6820
10431
|
pluginHtml: () => pluginHtml
|
|
6821
10432
|
});
|
|
6822
|
-
import
|
|
6823
|
-
import
|
|
10433
|
+
import fs8 from "fs";
|
|
10434
|
+
import path14, { isAbsolute as isAbsolute6 } from "path";
|
|
6824
10435
|
import color14 from "../compiled/picocolors/index.js";
|
|
6825
10436
|
function getTitle(entryName, config) {
|
|
6826
10437
|
return reduceConfigsMergeContext({
|
|
@@ -6848,7 +10459,7 @@ async function getTemplate(entryName, config, rootPath) {
|
|
|
6848
10459
|
templateContent: getDefaultTemplateContent(config.html.mountId)
|
|
6849
10460
|
};
|
|
6850
10461
|
}
|
|
6851
|
-
const absolutePath = isAbsolute6(templatePath) ? templatePath :
|
|
10462
|
+
const absolutePath = isAbsolute6(templatePath) ? templatePath : path14.resolve(rootPath, templatePath);
|
|
6852
10463
|
if (!existTemplatePath.has(absolutePath)) {
|
|
6853
10464
|
if (!await isFileExists(absolutePath)) {
|
|
6854
10465
|
throw new Error(
|
|
@@ -6859,7 +10470,7 @@ async function getTemplate(entryName, config, rootPath) {
|
|
|
6859
10470
|
}
|
|
6860
10471
|
existTemplatePath.add(absolutePath);
|
|
6861
10472
|
}
|
|
6862
|
-
const templateContent = await
|
|
10473
|
+
const templateContent = await fs8.promises.readFile(absolutePath, "utf-8");
|
|
6863
10474
|
return {
|
|
6864
10475
|
templatePath: absolutePath,
|
|
6865
10476
|
templateContent
|
|
@@ -6943,7 +10554,7 @@ var init_html = __esm({
|
|
|
6943
10554
|
"src/plugins/html.ts"() {
|
|
6944
10555
|
"use strict";
|
|
6945
10556
|
init_esm();
|
|
6946
|
-
|
|
10557
|
+
init_dist2();
|
|
6947
10558
|
init_helpers();
|
|
6948
10559
|
getDefaultTemplateContent = (mountId) => `<!doctype html><html><head></head><body><div id="${mountId}"></div></body></html>`;
|
|
6949
10560
|
existTemplatePath = /* @__PURE__ */ new Set();
|
|
@@ -7078,7 +10689,7 @@ var appIcon_exports = {};
|
|
|
7078
10689
|
__export(appIcon_exports, {
|
|
7079
10690
|
pluginAppIcon: () => pluginAppIcon
|
|
7080
10691
|
});
|
|
7081
|
-
import
|
|
10692
|
+
import path15 from "path";
|
|
7082
10693
|
import { promisify as promisify4 } from "util";
|
|
7083
10694
|
import { lookup } from "../compiled/mrmime/index.js";
|
|
7084
10695
|
var pluginAppIcon;
|
|
@@ -7111,10 +10722,10 @@ var init_appIcon = __esm({
|
|
|
7111
10722
|
iconFormatMap.set(src, paths2);
|
|
7112
10723
|
return { ...paths2, ...icon };
|
|
7113
10724
|
}
|
|
7114
|
-
const absolutePath =
|
|
7115
|
-
const relativePath =
|
|
10725
|
+
const absolutePath = path15.isAbsolute(src) ? src : path15.join(api.context.rootPath, src);
|
|
10726
|
+
const relativePath = path15.posix.join(
|
|
7116
10727
|
distDir,
|
|
7117
|
-
|
|
10728
|
+
path15.basename(absolutePath)
|
|
7118
10729
|
);
|
|
7119
10730
|
const requestPath = ensureAssetPrefix(relativePath, publicPath);
|
|
7120
10731
|
const paths = {
|
|
@@ -7303,7 +10914,7 @@ var nodeAddons_exports = {};
|
|
|
7303
10914
|
__export(nodeAddons_exports, {
|
|
7304
10915
|
pluginNodeAddons: () => pluginNodeAddons
|
|
7305
10916
|
});
|
|
7306
|
-
import
|
|
10917
|
+
import path16 from "path";
|
|
7307
10918
|
var getFilename3, pluginNodeAddons;
|
|
7308
10919
|
var init_nodeAddons = __esm({
|
|
7309
10920
|
"src/plugins/nodeAddons.ts"() {
|
|
@@ -7312,7 +10923,7 @@ var init_nodeAddons = __esm({
|
|
|
7312
10923
|
getFilename3 = (resourcePath) => {
|
|
7313
10924
|
let basename = "";
|
|
7314
10925
|
if (resourcePath) {
|
|
7315
|
-
const parsed =
|
|
10926
|
+
const parsed = path16.parse(resourcePath);
|
|
7316
10927
|
if (parsed.dir) {
|
|
7317
10928
|
basename = parsed.name;
|
|
7318
10929
|
}
|
|
@@ -7471,35 +11082,7 @@ var init_minimize = __esm({
|
|
|
7471
11082
|
if (minifyCss && isRspack) {
|
|
7472
11083
|
const defaultOptions2 = {
|
|
7473
11084
|
minimizerOptions: {
|
|
7474
|
-
targets: environment.browserslist
|
|
7475
|
-
// TODO: The exclude option of Lightning CSS does not work as expected
|
|
7476
|
-
// so we need to disable all excludes and figure out how to skip the transformation
|
|
7477
|
-
// see: https://github.com/parcel-bundler/lightningcss/issues/792
|
|
7478
|
-
exclude: {
|
|
7479
|
-
nesting: false,
|
|
7480
|
-
notSelectorList: false,
|
|
7481
|
-
dirSelector: false,
|
|
7482
|
-
langSelectorList: false,
|
|
7483
|
-
isSelector: false,
|
|
7484
|
-
textDecorationThicknessPercent: false,
|
|
7485
|
-
mediaIntervalSyntax: false,
|
|
7486
|
-
mediaRangeSyntax: false,
|
|
7487
|
-
customMediaQueries: false,
|
|
7488
|
-
clampFunction: false,
|
|
7489
|
-
colorFunction: false,
|
|
7490
|
-
oklabColors: false,
|
|
7491
|
-
labColors: false,
|
|
7492
|
-
p3Colors: false,
|
|
7493
|
-
hexAlphaColors: false,
|
|
7494
|
-
spaceSeparatedColorNotation: false,
|
|
7495
|
-
fontFamilySystemUi: false,
|
|
7496
|
-
doublePositionGradients: false,
|
|
7497
|
-
vendorPrefixes: false,
|
|
7498
|
-
logicalProperties: false,
|
|
7499
|
-
selectors: false,
|
|
7500
|
-
mediaQueries: false,
|
|
7501
|
-
color: false
|
|
7502
|
-
}
|
|
11085
|
+
targets: environment.browserslist
|
|
7503
11086
|
}
|
|
7504
11087
|
};
|
|
7505
11088
|
const mergedOptions = cssOptions ? (0, import_deepmerge3.default)(
|
|
@@ -7557,8 +11140,8 @@ __export(swc_exports, {
|
|
|
7557
11140
|
applySwcDecoratorConfig: () => applySwcDecoratorConfig,
|
|
7558
11141
|
pluginSwc: () => pluginSwc
|
|
7559
11142
|
});
|
|
7560
|
-
import
|
|
7561
|
-
import
|
|
11143
|
+
import fs9 from "fs";
|
|
11144
|
+
import path17 from "path";
|
|
7562
11145
|
function applyScriptCondition({
|
|
7563
11146
|
rule,
|
|
7564
11147
|
chain,
|
|
@@ -7583,7 +11166,7 @@ function applyScriptCondition({
|
|
|
7583
11166
|
rule.exclude.add(condition);
|
|
7584
11167
|
}
|
|
7585
11168
|
}
|
|
7586
|
-
function getDefaultSwcConfig(
|
|
11169
|
+
function getDefaultSwcConfig(browserslist, cacheRoot) {
|
|
7587
11170
|
return {
|
|
7588
11171
|
jsc: {
|
|
7589
11172
|
externalHelpers: true,
|
|
@@ -7598,14 +11181,14 @@ function getDefaultSwcConfig(browserslist3, cacheRoot) {
|
|
|
7598
11181
|
},
|
|
7599
11182
|
isModule: "unknown",
|
|
7600
11183
|
env: {
|
|
7601
|
-
targets:
|
|
11184
|
+
targets: browserslist
|
|
7602
11185
|
}
|
|
7603
11186
|
};
|
|
7604
11187
|
}
|
|
7605
11188
|
async function applyCoreJs(swcConfig, polyfillMode) {
|
|
7606
11189
|
const coreJsPath = __require.resolve("core-js/package.json");
|
|
7607
11190
|
const version2 = getCoreJsVersion(coreJsPath);
|
|
7608
|
-
const coreJsDir =
|
|
11191
|
+
const coreJsDir = path17.dirname(coreJsPath);
|
|
7609
11192
|
swcConfig.env.coreJs = version2;
|
|
7610
11193
|
if (polyfillMode === "usage") {
|
|
7611
11194
|
swcConfig.env.shippedProposals = true;
|
|
@@ -7644,7 +11227,7 @@ var init_swc = __esm({
|
|
|
7644
11227
|
"use strict";
|
|
7645
11228
|
init_esm();
|
|
7646
11229
|
import_deepmerge4 = __toESM(require_cjs());
|
|
7647
|
-
|
|
11230
|
+
init_dist2();
|
|
7648
11231
|
init_constants();
|
|
7649
11232
|
init_helpers();
|
|
7650
11233
|
builtinSwcLoaderName = "builtin:swc-loader";
|
|
@@ -7654,8 +11237,8 @@ var init_swc = __esm({
|
|
|
7654
11237
|
api.modifyBundlerChain({
|
|
7655
11238
|
order: "pre",
|
|
7656
11239
|
handler: async (chain, { CHAIN_ID: CHAIN_ID2, target, environment }) => {
|
|
7657
|
-
const { config, browserslist
|
|
7658
|
-
const cacheRoot =
|
|
11240
|
+
const { config, browserslist } = environment;
|
|
11241
|
+
const cacheRoot = path17.join(api.context.cachePath, ".swc");
|
|
7659
11242
|
const rule = chain.module.rule(CHAIN_ID2.RULE.JS).test(SCRIPT_REGEX).type("javascript/auto");
|
|
7660
11243
|
const dataUriRule = chain.module.rule(CHAIN_ID2.RULE.JS_DATA_URI).mimetype({
|
|
7661
11244
|
or: ["text/javascript", "application/javascript"]
|
|
@@ -7671,13 +11254,13 @@ var init_swc = __esm({
|
|
|
7671
11254
|
if (api.context.bundlerType === "webpack") {
|
|
7672
11255
|
return;
|
|
7673
11256
|
}
|
|
7674
|
-
const swcConfig = getDefaultSwcConfig(
|
|
11257
|
+
const swcConfig = getDefaultSwcConfig(browserslist, cacheRoot);
|
|
7675
11258
|
applyTransformImport(swcConfig, config.source.transformImport);
|
|
7676
11259
|
applySwcDecoratorConfig(swcConfig, config);
|
|
7677
11260
|
if (swcConfig.jsc?.externalHelpers) {
|
|
7678
11261
|
chain.resolve.alias.set(
|
|
7679
11262
|
"@swc/helpers",
|
|
7680
|
-
|
|
11263
|
+
path17.dirname(__require.resolve("@swc/helpers/package.json"))
|
|
7681
11264
|
);
|
|
7682
11265
|
}
|
|
7683
11266
|
if (isWebTarget(target)) {
|
|
@@ -7705,7 +11288,7 @@ var init_swc = __esm({
|
|
|
7705
11288
|
});
|
|
7706
11289
|
getCoreJsVersion = (corejsPkgPath) => {
|
|
7707
11290
|
try {
|
|
7708
|
-
const rawJson =
|
|
11291
|
+
const rawJson = fs9.readFileSync(corejsPkgPath, "utf-8");
|
|
7709
11292
|
const { version: version2 } = JSON.parse(rawJson);
|
|
7710
11293
|
const [major, minor] = version2.split(".");
|
|
7711
11294
|
return `${major}.${minor}`;
|
|
@@ -7974,7 +11557,7 @@ var inlineChunk_exports = {};
|
|
|
7974
11557
|
__export(inlineChunk_exports, {
|
|
7975
11558
|
pluginInlineChunk: () => pluginInlineChunk
|
|
7976
11559
|
});
|
|
7977
|
-
import
|
|
11560
|
+
import path18 from "path";
|
|
7978
11561
|
import { isRegExp } from "util/types";
|
|
7979
11562
|
function updateSourceMappingURL({
|
|
7980
11563
|
source,
|
|
@@ -7987,7 +11570,7 @@ function updateSourceMappingURL({
|
|
|
7987
11570
|
if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
|
|
7988
11571
|
!devtool.includes("inline") && source.includes("# sourceMappingURL")) {
|
|
7989
11572
|
const prefix = addTrailingSlash(
|
|
7990
|
-
|
|
11573
|
+
path18.join(publicPath, config.output.distPath[type] || "")
|
|
7991
11574
|
);
|
|
7992
11575
|
return source.replace(
|
|
7993
11576
|
/# sourceMappingURL=/,
|
|
@@ -8288,14 +11871,14 @@ var init_extractChunks = __esm({
|
|
|
8288
11871
|
});
|
|
8289
11872
|
|
|
8290
11873
|
// src/rspack/preload/helpers/determineAsValue.ts
|
|
8291
|
-
import
|
|
11874
|
+
import path19 from "path";
|
|
8292
11875
|
import { URL as URL2 } from "url";
|
|
8293
11876
|
function determineAsValue({
|
|
8294
11877
|
href,
|
|
8295
11878
|
file
|
|
8296
11879
|
}) {
|
|
8297
11880
|
const url2 = new URL2(file || href, "https://example.com");
|
|
8298
|
-
const extension =
|
|
11881
|
+
const extension = path19.extname(url2.pathname).slice(1);
|
|
8299
11882
|
if (["css"].includes(extension)) {
|
|
8300
11883
|
return "style";
|
|
8301
11884
|
}
|
|
@@ -8691,7 +12274,7 @@ var server_exports = {};
|
|
|
8691
12274
|
__export(server_exports, {
|
|
8692
12275
|
pluginServer: () => pluginServer
|
|
8693
12276
|
});
|
|
8694
|
-
import
|
|
12277
|
+
import fs10 from "fs";
|
|
8695
12278
|
import { isAbsolute as isAbsolute7, join as join12 } from "path";
|
|
8696
12279
|
var pluginServer;
|
|
8697
12280
|
var init_server = __esm({
|
|
@@ -8728,11 +12311,11 @@ var init_server = __esm({
|
|
|
8728
12311
|
continue;
|
|
8729
12312
|
}
|
|
8730
12313
|
const normalizedPath = isAbsolute7(name) ? name : join12(api.context.rootPath, name);
|
|
8731
|
-
if (!
|
|
12314
|
+
if (!fs10.existsSync(normalizedPath)) {
|
|
8732
12315
|
continue;
|
|
8733
12316
|
}
|
|
8734
12317
|
try {
|
|
8735
|
-
await
|
|
12318
|
+
await fs10.promises.cp(normalizedPath, api.context.distPath, {
|
|
8736
12319
|
recursive: true,
|
|
8737
12320
|
// dereference symlinks
|
|
8738
12321
|
dereference: true
|
|
@@ -9003,9 +12586,9 @@ var rspackProfile_exports = {};
|
|
|
9003
12586
|
__export(rspackProfile_exports, {
|
|
9004
12587
|
pluginRspackProfile: () => pluginRspackProfile
|
|
9005
12588
|
});
|
|
9006
|
-
import
|
|
12589
|
+
import fs11 from "fs";
|
|
9007
12590
|
import inspector from "inspector";
|
|
9008
|
-
import
|
|
12591
|
+
import path20 from "path";
|
|
9009
12592
|
import rspack9 from "@rspack/core";
|
|
9010
12593
|
var stopProfiler, pluginRspackProfile;
|
|
9011
12594
|
var init_rspackProfile = __esm({
|
|
@@ -9022,7 +12605,7 @@ var init_rspackProfile = __esm({
|
|
|
9022
12605
|
logger.error("Failed to generate JS CPU profile:", error);
|
|
9023
12606
|
return;
|
|
9024
12607
|
}
|
|
9025
|
-
|
|
12608
|
+
fs11.writeFileSync(output, JSON.stringify(param.profile));
|
|
9026
12609
|
});
|
|
9027
12610
|
};
|
|
9028
12611
|
pluginRspackProfile = () => ({
|
|
@@ -9042,10 +12625,10 @@ var init_rspackProfile = __esm({
|
|
|
9042
12625
|
const enableCPUProfile = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("CPU");
|
|
9043
12626
|
const enableLogging = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("LOGGING");
|
|
9044
12627
|
const onStart = () => {
|
|
9045
|
-
const profileDir =
|
|
9046
|
-
const traceFilePath =
|
|
9047
|
-
if (!
|
|
9048
|
-
|
|
12628
|
+
const profileDir = path20.join(api.context.distPath, profileDirName);
|
|
12629
|
+
const traceFilePath = path20.join(profileDir, "trace.json");
|
|
12630
|
+
if (!fs11.existsSync(profileDir)) {
|
|
12631
|
+
fs11.mkdirSync(profileDir, { recursive: true });
|
|
9049
12632
|
}
|
|
9050
12633
|
if (enableProfileTrace) {
|
|
9051
12634
|
rspack9.experiments.globalTrace.register(
|
|
@@ -9068,7 +12651,7 @@ var init_rspackProfile = __esm({
|
|
|
9068
12651
|
});
|
|
9069
12652
|
api.onBeforeStartDevServer(onStart);
|
|
9070
12653
|
api.onAfterBuild(async ({ stats }) => {
|
|
9071
|
-
const loggingFilePath =
|
|
12654
|
+
const loggingFilePath = path20.join(
|
|
9072
12655
|
api.context.distPath,
|
|
9073
12656
|
profileDirName,
|
|
9074
12657
|
"logging.json"
|
|
@@ -9079,15 +12662,15 @@ var init_rspackProfile = __esm({
|
|
|
9079
12662
|
logging: "verbose",
|
|
9080
12663
|
loggingTrace: true
|
|
9081
12664
|
});
|
|
9082
|
-
|
|
12665
|
+
fs11.writeFileSync(loggingFilePath, JSON.stringify(logging));
|
|
9083
12666
|
}
|
|
9084
12667
|
});
|
|
9085
12668
|
api.onExit(() => {
|
|
9086
12669
|
if (enableProfileTrace) {
|
|
9087
12670
|
rspack9.experiments.globalTrace.cleanup();
|
|
9088
12671
|
}
|
|
9089
|
-
const profileDir =
|
|
9090
|
-
const cpuProfilePath =
|
|
12672
|
+
const profileDir = path20.join(api.context.distPath, profileDirName);
|
|
12673
|
+
const cpuProfilePath = path20.join(profileDir, "jscpuprofile.json");
|
|
9091
12674
|
stopProfiler(cpuProfilePath, profileSession);
|
|
9092
12675
|
logger.info(`Saved Rspack profile file to ${profileDir}`);
|
|
9093
12676
|
});
|
|
@@ -9466,11 +13049,11 @@ var init_prodServer = __esm({
|
|
|
9466
13049
|
}
|
|
9467
13050
|
async applyStaticAssetMiddleware() {
|
|
9468
13051
|
const {
|
|
9469
|
-
output: { path:
|
|
13052
|
+
output: { path: path22, assetPrefixes },
|
|
9470
13053
|
serverConfig: { htmlFallback }
|
|
9471
13054
|
} = this.options;
|
|
9472
13055
|
const { default: sirv } = await import("../compiled/sirv/index.js");
|
|
9473
|
-
const assetMiddleware = sirv(
|
|
13056
|
+
const assetMiddleware = sirv(path22, {
|
|
9474
13057
|
etag: true,
|
|
9475
13058
|
dev: true,
|
|
9476
13059
|
ignores: ["favicon.ico"],
|
|
@@ -9704,7 +13287,7 @@ var init_createRsbuild = __esm({
|
|
|
9704
13287
|
});
|
|
9705
13288
|
|
|
9706
13289
|
// src/cli/init.ts
|
|
9707
|
-
import
|
|
13290
|
+
import path21 from "path";
|
|
9708
13291
|
async function init({
|
|
9709
13292
|
cliOptions,
|
|
9710
13293
|
isRestart
|
|
@@ -9789,7 +13372,7 @@ var init_init = __esm({
|
|
|
9789
13372
|
commonOpts = {};
|
|
9790
13373
|
getEnvDir = (cwd, envDir) => {
|
|
9791
13374
|
if (envDir) {
|
|
9792
|
-
return
|
|
13375
|
+
return path21.isAbsolute(envDir) ? envDir : path21.resolve(cwd, envDir);
|
|
9793
13376
|
}
|
|
9794
13377
|
return cwd;
|
|
9795
13378
|
};
|
|
@@ -9798,10 +13381,9 @@ var init_init = __esm({
|
|
|
9798
13381
|
|
|
9799
13382
|
// src/cli/commands.ts
|
|
9800
13383
|
import { existsSync } from "fs";
|
|
9801
|
-
import { program } from "../compiled/commander/index.js";
|
|
9802
13384
|
import color16 from "../compiled/picocolors/index.js";
|
|
9803
13385
|
function runCli() {
|
|
9804
|
-
program.name("rsbuild").usage("<command> [options]").version("1.0.
|
|
13386
|
+
program.name("rsbuild").usage("<command> [options]").version("1.0.8");
|
|
9805
13387
|
const devCommand = program.command("dev");
|
|
9806
13388
|
const buildCommand = program.command("build");
|
|
9807
13389
|
const previewCommand = program.command("preview");
|
|
@@ -9881,6 +13463,7 @@ var init_commands = __esm({
|
|
|
9881
13463
|
"src/cli/commands.ts"() {
|
|
9882
13464
|
"use strict";
|
|
9883
13465
|
init_esm();
|
|
13466
|
+
init_esm2();
|
|
9884
13467
|
init_helpers();
|
|
9885
13468
|
init_logger();
|
|
9886
13469
|
init_init();
|
|
@@ -9922,7 +13505,7 @@ function prepareCli() {
|
|
|
9922
13505
|
if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
|
|
9923
13506
|
console.log();
|
|
9924
13507
|
}
|
|
9925
|
-
logger.greet(` ${`Rsbuild v${"1.0.
|
|
13508
|
+
logger.greet(` ${`Rsbuild v${"1.0.8"}`}
|
|
9926
13509
|
`);
|
|
9927
13510
|
}
|
|
9928
13511
|
var init_prepare = __esm({
|
|
@@ -9993,7 +13576,7 @@ init_mergeConfig();
|
|
|
9993
13576
|
init_helpers();
|
|
9994
13577
|
init_constants();
|
|
9995
13578
|
import { rspack as rspack10 } from "@rspack/core";
|
|
9996
|
-
var version = "1.0.
|
|
13579
|
+
var version = "1.0.8";
|
|
9997
13580
|
export {
|
|
9998
13581
|
PLUGIN_CSS_NAME,
|
|
9999
13582
|
PLUGIN_SWC_NAME,
|