@rslib/core 0.7.1 → 0.8.0

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.
@@ -51,6 +51,7 @@ declare class Argument {
51
51
  variadic: boolean;
52
52
  defaultValue?: any;
53
53
  defaultValueDescription?: string;
54
+ parseArg?: <T>(value: string, previous: T) => T;
54
55
  argChoices?: string[];
55
56
 
56
57
  /**
@@ -109,6 +110,7 @@ declare class Option {
109
110
  parseArg?: <T>(value: string, previous: T) => T;
110
111
  hidden: boolean;
111
112
  argChoices?: string[];
113
+ helpGroupHeading?: string;
112
114
 
113
115
  constructor(flags: string, description?: string);
114
116
 
@@ -192,6 +194,11 @@ declare class Option {
192
194
  */
193
195
  attributeName(): string;
194
196
 
197
+ /**
198
+ * Set the help group heading.
199
+ */
200
+ helpGroup(heading: string): this;
201
+
195
202
  /**
196
203
  * Return whether a boolean option.
197
204
  *
@@ -313,6 +320,20 @@ declare class Help {
313
320
  helper: Help,
314
321
  ): string;
315
322
 
323
+ /**
324
+ * Format a list of items, given a heading and an array of formatted items.
325
+ */
326
+ formatItemList(heading: string, items: string[], helper: Help): string[];
327
+
328
+ /**
329
+ * Group items by their help group heading.
330
+ */
331
+ groupItems<T extends Command | Option>(
332
+ unsortedItems: T[],
333
+ visibleItems: T[],
334
+ getGroup: (item: T) => string,
335
+ ): Map<string, T[]>;
336
+
316
337
  /** Generate the built-in help text. */
317
338
  formatHelp(cmd: Command, helper: Help): string;
318
339
  }
@@ -466,7 +487,7 @@ declare class Command {
466
487
  argument<T>(
467
488
  flags: string,
468
489
  description: string,
469
- fn: (value: string, previous: T) => T,
490
+ parseArg: (value: string, previous: T) => T,
470
491
  defaultValue?: T,
471
492
  ): this;
472
493
  argument(name: string, description?: string, defaultValue?: unknown): this;
@@ -968,6 +989,53 @@ declare class Command {
968
989
  */
969
990
  executableDir(): string | null;
970
991
 
992
+ /**
993
+ * Set the help group heading for this subcommand in parent command's help.
994
+ *
995
+ * @returns `this` command for chaining
996
+ */
997
+ helpGroup(heading: string): this;
998
+ /**
999
+ * Get the help group heading for this subcommand in parent command's help.
1000
+ */
1001
+ helpGroup(): string;
1002
+
1003
+ /**
1004
+ * Set the default help group heading for subcommands added to this command.
1005
+ * (This does not override a group set directly on the subcommand using .helpGroup().)
1006
+ *
1007
+ * @example
1008
+ * program.commandsGroup('Development Commands:);
1009
+ * program.command('watch')...
1010
+ * program.command('lint')...
1011
+ * ...
1012
+ *
1013
+ * @returns `this` command for chaining
1014
+ */
1015
+ commandsGroup(heading: string): this;
1016
+ /**
1017
+ * Get the default help group heading for subcommands added to this command.
1018
+ */
1019
+ commandsGroup(): string;
1020
+
1021
+ /**
1022
+ * Set the default help group heading for options added to this command.
1023
+ * (This does not override a group set directly on the option using .helpGroup().)
1024
+ *
1025
+ * @example
1026
+ * program
1027
+ * .optionsGroup('Development Options:')
1028
+ * .option('-d, --debug', 'output extra debugging')
1029
+ * .option('-p, --profile', 'output profiling information')
1030
+ *
1031
+ * @returns `this` command for chaining
1032
+ */
1033
+ optionsGroup(heading: string): this;
1034
+ /**
1035
+ * Get the default help group heading for options added to this command.
1036
+ */
1037
+ optionsGroup(): string;
1038
+
971
1039
  /**
972
1040
  * Output help information for this command.
973
1041
  *
@@ -41,10 +41,10 @@ module.exports = require("node:process");
41
41
 
42
42
  /***/ }),
43
43
 
44
- /***/ 277:
44
+ /***/ 455:
45
45
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
46
46
 
47
- const { InvalidArgumentError } = __nccwpck_require__(910);
47
+ const { InvalidArgumentError } = __nccwpck_require__(552);
48
48
 
49
49
  class Argument {
50
50
  /**
@@ -197,7 +197,7 @@ exports.humanReadableArgName = humanReadableArgName;
197
197
 
198
198
  /***/ }),
199
199
 
200
- /***/ 393:
200
+ /***/ 199:
201
201
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
202
202
 
203
203
  const EventEmitter = (__nccwpck_require__(474).EventEmitter);
@@ -206,11 +206,11 @@ const path = __nccwpck_require__(760);
206
206
  const fs = __nccwpck_require__(24);
207
207
  const process = __nccwpck_require__(708);
208
208
 
209
- const { Argument, humanReadableArgName } = __nccwpck_require__(277);
210
- const { CommanderError } = __nccwpck_require__(910);
211
- const { Help, stripColor } = __nccwpck_require__(945);
212
- const { Option, DualOptions } = __nccwpck_require__(823);
213
- const { suggestSimilar } = __nccwpck_require__(461);
209
+ const { Argument, humanReadableArgName } = __nccwpck_require__(455);
210
+ const { CommanderError } = __nccwpck_require__(552);
211
+ const { Help, stripColor } = __nccwpck_require__(615);
212
+ const { Option, DualOptions } = __nccwpck_require__(513);
213
+ const { suggestSimilar } = __nccwpck_require__(155);
214
214
 
215
215
  class Command extends EventEmitter {
216
216
  /**
@@ -282,6 +282,12 @@ class Command extends EventEmitter {
282
282
  /** @type {Command} */
283
283
  this._helpCommand = undefined; // lazy initialised, inherited
284
284
  this._helpConfiguration = {};
285
+ /** @type {string | undefined} */
286
+ this._helpGroupHeading = undefined; // soft initialised when added to parent
287
+ /** @type {string | undefined} */
288
+ this._defaultCommandGroup = undefined;
289
+ /** @type {string | undefined} */
290
+ this._defaultOptionGroup = undefined;
285
291
  }
286
292
 
287
293
  /**
@@ -441,7 +447,11 @@ class Command extends EventEmitter {
441
447
  configureOutput(configuration) {
442
448
  if (configuration === undefined) return this._outputConfiguration;
443
449
 
444
- Object.assign(this._outputConfiguration, configuration);
450
+ this._outputConfiguration = Object.assign(
451
+ {},
452
+ this._outputConfiguration,
453
+ configuration,
454
+ );
445
455
  return this;
446
456
  }
447
457
 
@@ -522,16 +532,16 @@ class Command extends EventEmitter {
522
532
  *
523
533
  * @param {string} name
524
534
  * @param {string} [description]
525
- * @param {(Function|*)} [fn] - custom argument processing function
535
+ * @param {(Function|*)} [parseArg] - custom argument processing function or default value
526
536
  * @param {*} [defaultValue]
527
537
  * @return {Command} `this` command for chaining
528
538
  */
529
- argument(name, description, fn, defaultValue) {
539
+ argument(name, description, parseArg, defaultValue) {
530
540
  const argument = this.createArgument(name, description);
531
- if (typeof fn === 'function') {
532
- argument.default(defaultValue).argParser(fn);
541
+ if (typeof parseArg === 'function') {
542
+ argument.default(defaultValue).argParser(parseArg);
533
543
  } else {
534
- argument.default(fn);
544
+ argument.default(parseArg);
535
545
  }
536
546
  this.addArgument(argument);
537
547
  return this;
@@ -602,11 +612,15 @@ class Command extends EventEmitter {
602
612
  helpCommand(enableOrNameAndArgs, description) {
603
613
  if (typeof enableOrNameAndArgs === 'boolean') {
604
614
  this._addImplicitHelpCommand = enableOrNameAndArgs;
615
+ if (enableOrNameAndArgs && this._defaultCommandGroup) {
616
+ // make the command to store the group
617
+ this._initCommandGroup(this._getHelpCommand());
618
+ }
605
619
  return this;
606
620
  }
607
621
 
608
- enableOrNameAndArgs = enableOrNameAndArgs ?? 'help [command]';
609
- const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
622
+ const nameAndArgs = enableOrNameAndArgs ?? 'help [command]';
623
+ const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
610
624
  const helpDescription = description ?? 'display help for command';
611
625
 
612
626
  const helpCommand = this.createCommand(helpName);
@@ -616,6 +630,8 @@ class Command extends EventEmitter {
616
630
 
617
631
  this._addImplicitHelpCommand = true;
618
632
  this._helpCommand = helpCommand;
633
+ // init group unless lazy create
634
+ if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
619
635
 
620
636
  return this;
621
637
  }
@@ -637,6 +653,7 @@ class Command extends EventEmitter {
637
653
 
638
654
  this._addImplicitHelpCommand = true;
639
655
  this._helpCommand = helpCommand;
656
+ this._initCommandGroup(helpCommand);
640
657
  return this;
641
658
  }
642
659
 
@@ -815,6 +832,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
815
832
  - already used by option '${matchingOption.flags}'`);
816
833
  }
817
834
 
835
+ this._initOptionGroup(option);
818
836
  this.options.push(option);
819
837
  }
820
838
 
@@ -842,6 +860,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
842
860
  );
843
861
  }
844
862
 
863
+ this._initCommandGroup(command);
845
864
  this.commands.push(command);
846
865
  }
847
866
 
@@ -1939,6 +1958,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
1939
1958
  return arg.length > 1 && arg[0] === '-';
1940
1959
  }
1941
1960
 
1961
+ const negativeNumberArg = (arg) => {
1962
+ // return false if not a negative number
1963
+ if (!/^-\d*\.?\d+(e[+-]?\d+)?$/.test(arg)) return false;
1964
+ // negative number is ok unless digit used as an option in command hierarchy
1965
+ return !this._getCommandAndAncestors().some((cmd) =>
1966
+ cmd.options
1967
+ .map((opt) => opt.short)
1968
+ .some((short) => /^-\d$/.test(short)),
1969
+ );
1970
+ };
1971
+
1942
1972
  // parse options
1943
1973
  let activeVariadicOption = null;
1944
1974
  while (args.length) {
@@ -1951,7 +1981,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
1951
1981
  break;
1952
1982
  }
1953
1983
 
1954
- if (activeVariadicOption && !maybeOption(arg)) {
1984
+ if (
1985
+ activeVariadicOption &&
1986
+ (!maybeOption(arg) || negativeNumberArg(arg))
1987
+ ) {
1955
1988
  this.emit(`option:${activeVariadicOption.name()}`, arg);
1956
1989
  continue;
1957
1990
  }
@@ -1968,7 +2001,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
1968
2001
  } else if (option.optional) {
1969
2002
  let value = null;
1970
2003
  // historical behaviour is optional value is following arg unless an option
1971
- if (args.length > 0 && !maybeOption(args[0])) {
2004
+ if (
2005
+ args.length > 0 &&
2006
+ (!maybeOption(args[0]) || negativeNumberArg(args[0]))
2007
+ ) {
1972
2008
  value = args.shift();
1973
2009
  }
1974
2010
  this.emit(`option:${option.name()}`, value);
@@ -2014,7 +2050,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
2014
2050
  // Might be a command-argument, or subcommand option, or unknown option, or help command or option.
2015
2051
 
2016
2052
  // An unknown option means further arguments also classified as unknown so can be reprocessed by subcommands.
2017
- if (maybeOption(arg)) {
2053
+ // A negative number in a leaf command is not an unknown option.
2054
+ if (
2055
+ dest === operands &&
2056
+ maybeOption(arg) &&
2057
+ !(this.commands.length === 0 && negativeNumberArg(arg))
2058
+ ) {
2018
2059
  dest = unknown;
2019
2060
  }
2020
2061
 
@@ -2496,6 +2537,75 @@ Expecting one of '${allowedValues.join("', '")}'`);
2496
2537
  return this;
2497
2538
  }
2498
2539
 
2540
+ /**
2541
+ * Set/get the help group heading for this subcommand in parent command's help.
2542
+ *
2543
+ * @param {string} [heading]
2544
+ * @return {Command | string}
2545
+ */
2546
+
2547
+ helpGroup(heading) {
2548
+ if (heading === undefined) return this._helpGroupHeading ?? '';
2549
+ this._helpGroupHeading = heading;
2550
+ return this;
2551
+ }
2552
+
2553
+ /**
2554
+ * Set/get the default help group heading for subcommands added to this command.
2555
+ * (This does not override a group set directly on the subcommand using .helpGroup().)
2556
+ *
2557
+ * @example
2558
+ * program.commandsGroup('Development Commands:);
2559
+ * program.command('watch')...
2560
+ * program.command('lint')...
2561
+ * ...
2562
+ *
2563
+ * @param {string} [heading]
2564
+ * @returns {Command | string}
2565
+ */
2566
+ commandsGroup(heading) {
2567
+ if (heading === undefined) return this._defaultCommandGroup ?? '';
2568
+ this._defaultCommandGroup = heading;
2569
+ return this;
2570
+ }
2571
+
2572
+ /**
2573
+ * Set/get the default help group heading for options added to this command.
2574
+ * (This does not override a group set directly on the option using .helpGroup().)
2575
+ *
2576
+ * @example
2577
+ * program
2578
+ * .optionsGroup('Development Options:')
2579
+ * .option('-d, --debug', 'output extra debugging')
2580
+ * .option('-p, --profile', 'output profiling information')
2581
+ *
2582
+ * @param {string} [heading]
2583
+ * @returns {Command | string}
2584
+ */
2585
+ optionsGroup(heading) {
2586
+ if (heading === undefined) return this._defaultOptionGroup ?? '';
2587
+ this._defaultOptionGroup = heading;
2588
+ return this;
2589
+ }
2590
+
2591
+ /**
2592
+ * @param {Option} option
2593
+ * @private
2594
+ */
2595
+ _initOptionGroup(option) {
2596
+ if (this._defaultOptionGroup && !option.helpGroupHeading)
2597
+ option.helpGroup(this._defaultOptionGroup);
2598
+ }
2599
+
2600
+ /**
2601
+ * @param {Command} cmd
2602
+ * @private
2603
+ */
2604
+ _initCommandGroup(cmd) {
2605
+ if (this._defaultCommandGroup && !cmd.helpGroup())
2606
+ cmd.helpGroup(this._defaultCommandGroup);
2607
+ }
2608
+
2499
2609
  /**
2500
2610
  * Set the name of the command from script filename, such as process.argv[1],
2501
2611
  * or require.main.filename, or __filename.
@@ -2650,12 +2760,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
2650
2760
  */
2651
2761
 
2652
2762
  helpOption(flags, description) {
2653
- // Support disabling built-in help option.
2763
+ // Support enabling/disabling built-in help option.
2654
2764
  if (typeof flags === 'boolean') {
2655
- // true is not an expected value. Do something sensible but no unit-test.
2656
- // istanbul ignore if
2657
2765
  if (flags) {
2658
- this._helpOption = this._helpOption ?? undefined; // preserve existing option
2766
+ if (this._helpOption === null) this._helpOption = undefined; // reenable
2767
+ if (this._defaultOptionGroup) {
2768
+ // make the option to store the group
2769
+ this._initOptionGroup(this._getHelpOption());
2770
+ }
2659
2771
  } else {
2660
2772
  this._helpOption = null; // disable
2661
2773
  }
@@ -2663,9 +2775,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
2663
2775
  }
2664
2776
 
2665
2777
  // Customise flags and description.
2666
- flags = flags ?? '-h, --help';
2667
- description = description ?? 'display help for command';
2668
- this._helpOption = this.createOption(flags, description);
2778
+ this._helpOption = this.createOption(
2779
+ flags ?? '-h, --help',
2780
+ description ?? 'display help for command',
2781
+ );
2782
+ // init group unless lazy create
2783
+ if (flags || description) this._initOptionGroup(this._helpOption);
2669
2784
 
2670
2785
  return this;
2671
2786
  }
@@ -2694,6 +2809,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2694
2809
  */
2695
2810
  addHelpOption(option) {
2696
2811
  this._helpOption = option;
2812
+ this._initOptionGroup(option);
2697
2813
  return this;
2698
2814
  }
2699
2815
 
@@ -2866,7 +2982,7 @@ exports.useColor = useColor; // exporting for tests
2866
2982
 
2867
2983
  /***/ }),
2868
2984
 
2869
- /***/ 910:
2985
+ /***/ 552:
2870
2986
  /***/ ((__unused_webpack_module, exports) => {
2871
2987
 
2872
2988
  /**
@@ -2912,10 +3028,10 @@ exports.InvalidArgumentError = InvalidArgumentError;
2912
3028
 
2913
3029
  /***/ }),
2914
3030
 
2915
- /***/ 945:
3031
+ /***/ 615:
2916
3032
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
2917
3033
 
2918
- const { humanReadableArgName } = __nccwpck_require__(277);
3034
+ const { humanReadableArgName } = __nccwpck_require__(455);
2919
3035
 
2920
3036
  /**
2921
3037
  * TypeScript import types for JSDoc, used by Visual Studio Code IntelliSense and `npm run typescript-checkJS`
@@ -3269,7 +3385,11 @@ class Help {
3269
3385
  extraInfo.push(`env: ${option.envVar}`);
3270
3386
  }
3271
3387
  if (extraInfo.length > 0) {
3272
- return `${option.description} (${extraInfo.join(', ')})`;
3388
+ const extraDescription = `(${extraInfo.join(', ')})`;
3389
+ if (option.description) {
3390
+ return `${option.description} ${extraDescription}`;
3391
+ }
3392
+ return extraDescription;
3273
3393
  }
3274
3394
 
3275
3395
  return option.description;
@@ -3305,6 +3425,46 @@ class Help {
3305
3425
  return argument.description;
3306
3426
  }
3307
3427
 
3428
+ /**
3429
+ * Format a list of items, given a heading and an array of formatted items.
3430
+ *
3431
+ * @param {string} heading
3432
+ * @param {string[]} items
3433
+ * @param {Help} helper
3434
+ * @returns string[]
3435
+ */
3436
+ formatItemList(heading, items, helper) {
3437
+ if (items.length === 0) return [];
3438
+
3439
+ return [helper.styleTitle(heading), ...items, ''];
3440
+ }
3441
+
3442
+ /**
3443
+ * Group items by their help group heading.
3444
+ *
3445
+ * @param {Command[] | Option[]} unsortedItems
3446
+ * @param {Command[] | Option[]} visibleItems
3447
+ * @param {Function} getGroup
3448
+ * @returns {Map<string, Command[] | Option[]>}
3449
+ */
3450
+ groupItems(unsortedItems, visibleItems, getGroup) {
3451
+ const result = new Map();
3452
+ // Add groups in order of appearance in unsortedItems.
3453
+ unsortedItems.forEach((item) => {
3454
+ const group = getGroup(item);
3455
+ if (!result.has(group)) result.set(group, []);
3456
+ });
3457
+ // Add items in order of appearance in visibleItems.
3458
+ visibleItems.forEach((item) => {
3459
+ const group = getGroup(item);
3460
+ if (!result.has(group)) {
3461
+ result.set(group, []);
3462
+ }
3463
+ result.get(group).push(item);
3464
+ });
3465
+ return result;
3466
+ }
3467
+
3308
3468
  /**
3309
3469
  * Generate the built-in help text.
3310
3470
  *
@@ -3346,28 +3506,25 @@ class Help {
3346
3506
  helper.styleArgumentDescription(helper.argumentDescription(argument)),
3347
3507
  );
3348
3508
  });
3349
- if (argumentList.length > 0) {
3350
- output = output.concat([
3351
- helper.styleTitle('Arguments:'),
3352
- ...argumentList,
3353
- '',
3354
- ]);
3355
- }
3509
+ output = output.concat(
3510
+ this.formatItemList('Arguments:', argumentList, helper),
3511
+ );
3356
3512
 
3357
3513
  // Options
3358
- const optionList = helper.visibleOptions(cmd).map((option) => {
3359
- return callFormatItem(
3360
- helper.styleOptionTerm(helper.optionTerm(option)),
3361
- helper.styleOptionDescription(helper.optionDescription(option)),
3362
- );
3514
+ const optionGroups = this.groupItems(
3515
+ cmd.options,
3516
+ helper.visibleOptions(cmd),
3517
+ (option) => option.helpGroupHeading ?? 'Options:',
3518
+ );
3519
+ optionGroups.forEach((options, group) => {
3520
+ const optionList = options.map((option) => {
3521
+ return callFormatItem(
3522
+ helper.styleOptionTerm(helper.optionTerm(option)),
3523
+ helper.styleOptionDescription(helper.optionDescription(option)),
3524
+ );
3525
+ });
3526
+ output = output.concat(this.formatItemList(group, optionList, helper));
3363
3527
  });
3364
- if (optionList.length > 0) {
3365
- output = output.concat([
3366
- helper.styleTitle('Options:'),
3367
- ...optionList,
3368
- '',
3369
- ]);
3370
- }
3371
3528
 
3372
3529
  if (helper.showGlobalOptions) {
3373
3530
  const globalOptionList = helper
@@ -3378,29 +3535,26 @@ class Help {
3378
3535
  helper.styleOptionDescription(helper.optionDescription(option)),
3379
3536
  );
3380
3537
  });
3381
- if (globalOptionList.length > 0) {
3382
- output = output.concat([
3383
- helper.styleTitle('Global Options:'),
3384
- ...globalOptionList,
3385
- '',
3386
- ]);
3387
- }
3538
+ output = output.concat(
3539
+ this.formatItemList('Global Options:', globalOptionList, helper),
3540
+ );
3388
3541
  }
3389
3542
 
3390
3543
  // Commands
3391
- const commandList = helper.visibleCommands(cmd).map((cmd) => {
3392
- return callFormatItem(
3393
- helper.styleSubcommandTerm(helper.subcommandTerm(cmd)),
3394
- helper.styleSubcommandDescription(helper.subcommandDescription(cmd)),
3395
- );
3544
+ const commandGroups = this.groupItems(
3545
+ cmd.commands,
3546
+ helper.visibleCommands(cmd),
3547
+ (sub) => sub.helpGroup() || 'Commands:',
3548
+ );
3549
+ commandGroups.forEach((commands, group) => {
3550
+ const commandList = commands.map((sub) => {
3551
+ return callFormatItem(
3552
+ helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
3553
+ helper.styleSubcommandDescription(helper.subcommandDescription(sub)),
3554
+ );
3555
+ });
3556
+ output = output.concat(this.formatItemList(group, commandList, helper));
3396
3557
  });
3397
- if (commandList.length > 0) {
3398
- output = output.concat([
3399
- helper.styleTitle('Commands:'),
3400
- ...commandList,
3401
- '',
3402
- ]);
3403
- }
3404
3558
 
3405
3559
  return output.join('\n');
3406
3560
  }
@@ -3628,10 +3782,10 @@ exports.stripColor = stripColor;
3628
3782
 
3629
3783
  /***/ }),
3630
3784
 
3631
- /***/ 823:
3785
+ /***/ 513:
3632
3786
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
3633
3787
 
3634
- const { InvalidArgumentError } = __nccwpck_require__(910);
3788
+ const { InvalidArgumentError } = __nccwpck_require__(552);
3635
3789
 
3636
3790
  class Option {
3637
3791
  /**
@@ -3666,6 +3820,7 @@ class Option {
3666
3820
  this.argChoices = undefined;
3667
3821
  this.conflictsWith = [];
3668
3822
  this.implied = undefined;
3823
+ this.helpGroupHeading = undefined; // soft initialised when option added to command
3669
3824
  }
3670
3825
 
3671
3826
  /**
@@ -3852,6 +4007,17 @@ class Option {
3852
4007
  return camelcase(this.name());
3853
4008
  }
3854
4009
 
4010
+ /**
4011
+ * Set the help group heading.
4012
+ *
4013
+ * @param {string} heading
4014
+ * @return {Option}
4015
+ */
4016
+ helpGroup(heading) {
4017
+ this.helpGroupHeading = heading;
4018
+ return this;
4019
+ }
4020
+
3855
4021
  /**
3856
4022
  * Check if `arg` matches the short or long flag.
3857
4023
  *
@@ -4002,7 +4168,7 @@ exports.DualOptions = DualOptions;
4002
4168
 
4003
4169
  /***/ }),
4004
4170
 
4005
- /***/ 461:
4171
+ /***/ 155:
4006
4172
  /***/ ((__unused_webpack_module, exports) => {
4007
4173
 
4008
4174
  const maxDistance = 3;
@@ -4152,11 +4318,11 @@ var __webpack_exports__ = {};
4152
4318
  // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
4153
4319
  (() => {
4154
4320
  var exports = __webpack_exports__;
4155
- const { Argument } = __nccwpck_require__(277);
4156
- const { Command } = __nccwpck_require__(393);
4157
- const { CommanderError, InvalidArgumentError } = __nccwpck_require__(910);
4158
- const { Help } = __nccwpck_require__(945);
4159
- const { Option } = __nccwpck_require__(823);
4321
+ const { Argument } = __nccwpck_require__(455);
4322
+ const { Command } = __nccwpck_require__(199);
4323
+ const { CommanderError, InvalidArgumentError } = __nccwpck_require__(552);
4324
+ const { Help } = __nccwpck_require__(615);
4325
+ const { Option } = __nccwpck_require__(513);
4160
4326
 
4161
4327
  exports.program = new Command();
4162
4328
 
@@ -1 +1 @@
1
- {"name":"commander","author":"TJ Holowaychuk <tj@vision-media.ca>","version":"13.1.0","license":"MIT","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"commander","author":"TJ Holowaychuk <tj@vision-media.ca>","version":"14.0.0","license":"MIT","types":"index.d.ts","type":"commonjs"}
package/dist/index.js CHANGED
@@ -181,7 +181,7 @@ function prepareCli() {
181
181
  initNodeEnv();
182
182
  const { npm_execpath } = process.env;
183
183
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
184
- __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rslib v0.7.1\n`);
184
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rslib v0.8.0\n`);
185
185
  }
186
186
  const DEFAULT_CONFIG_NAME = 'rslib.config';
187
187
  const DEFAULT_CONFIG_EXTENSIONS = [
@@ -1764,6 +1764,34 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson })=>{
1764
1764
  };
1765
1765
  return config;
1766
1766
  }
1767
+ case 'iife':
1768
+ {
1769
+ if (false === bundle) throw new Error('When using "iife" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.');
1770
+ const config = {
1771
+ tools: {
1772
+ rspack: {
1773
+ module: {
1774
+ parser: {
1775
+ javascript: {
1776
+ importMeta: false
1777
+ }
1778
+ }
1779
+ },
1780
+ output: {
1781
+ iife: true,
1782
+ asyncChunks: false,
1783
+ library: {
1784
+ type: 'modern-module'
1785
+ }
1786
+ },
1787
+ optimization: {
1788
+ nodeEnv: process.env.NODE_ENV
1789
+ }
1790
+ }
1791
+ }
1792
+ };
1793
+ return config;
1794
+ }
1767
1795
  case 'mf':
1768
1796
  if (false === bundle) throw new Error('When using "mf" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.');
1769
1797
  return {
@@ -1849,6 +1877,7 @@ const composeShimsConfig = (format, shims)=>{
1849
1877
  };
1850
1878
  break;
1851
1879
  case 'umd':
1880
+ case 'iife':
1852
1881
  case 'mf':
1853
1882
  break;
1854
1883
  default:
@@ -1865,26 +1894,41 @@ const composeExternalsConfig = (format, externals)=>{
1865
1894
  esm: 'module-import',
1866
1895
  cjs: 'commonjs-import',
1867
1896
  umd: 'umd',
1868
- mf: 'global'
1897
+ mf: 'global',
1898
+ iife: 'global'
1899
+ };
1900
+ const globalObjectMap = {
1901
+ esm: void 0,
1902
+ cjs: void 0,
1903
+ umd: void 0,
1904
+ mf: void 0,
1905
+ iife: 'globalThis'
1869
1906
  };
1907
+ const rspackConfig = {};
1908
+ const rsbuildConfig = {};
1870
1909
  switch(format){
1871
1910
  case 'esm':
1872
1911
  case 'cjs':
1873
1912
  case 'umd':
1874
1913
  case 'mf':
1875
- return {
1876
- output: externals ? {
1877
- externals
1878
- } : {},
1879
- tools: {
1880
- rspack: {
1881
- externalsType: externalsTypeMap[format]
1882
- }
1883
- }
1914
+ case 'iife':
1915
+ rsbuildConfig.output = externals ? {
1916
+ externals
1917
+ } : {};
1918
+ rspackConfig.externalsType = externalsTypeMap[format];
1919
+ if (globalObjectMap[format]) rspackConfig.output = {
1920
+ globalObject: globalObjectMap[format]
1884
1921
  };
1922
+ break;
1885
1923
  default:
1886
1924
  throw new Error(`Unsupported format: ${format}`);
1887
1925
  }
1926
+ return {
1927
+ ...rsbuildConfig,
1928
+ tools: {
1929
+ rspack: rspackConfig
1930
+ }
1931
+ };
1888
1932
  };
1889
1933
  const composeAutoExtensionConfig = (config, format, autoExtension, pkgJson)=>{
1890
1934
  const { jsExtension, dtsExtension } = getDefaultExtension({
@@ -2465,7 +2509,7 @@ const repeatableOption = (value, previous)=>(previous ?? []).concat([
2465
2509
  value
2466
2510
  ]);
2467
2511
  function runCli() {
2468
- __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.name('rslib').usage('<command> [options]').version("0.7.1");
2512
+ __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.name('rslib').usage('<command> [options]').version("0.8.0");
2469
2513
  const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('build');
2470
2514
  const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('inspect');
2471
2515
  const mfDevCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('mf-dev');
@@ -2526,7 +2570,7 @@ function runCli() {
2526
2570
  });
2527
2571
  __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.parse();
2528
2572
  }
2529
- const src_version = "0.7.1";
2573
+ const src_version = "0.8.0";
2530
2574
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger;
2531
2575
  var __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack;
2532
2576
  export { build, defineConfig, inspect, loadConfig, prepareCli, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ as rsbuild, runCli, startMFDevServer, composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, src_version as version, __webpack_exports__logger as logger, __webpack_exports__rspack as rspack };
@@ -1,6 +1,6 @@
1
1
  import type { EnvironmentConfig, OutputConfig, RsbuildConfig, Rspack } from '@rsbuild/core';
2
2
  import type { GetAsyncFunctionFromUnion } from './utils';
3
- export type Format = 'esm' | 'cjs' | 'umd' | 'mf';
3
+ export type Format = 'esm' | 'cjs' | 'umd' | 'mf' | 'iife';
4
4
  export type FixedEcmaVersions = 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023';
5
5
  export type LatestEcmaVersions = 'es2024' | 'esnext';
6
6
  export type EcmaScriptVersion = FixedEcmaVersions | LatestEcmaVersions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "The Rsbuild-based library development tool.",
5
5
  "homepage": "https://lib.rsbuild.dev",
6
6
  "bugs": {
@@ -36,21 +36,21 @@
36
36
  "types.d.ts"
37
37
  ],
38
38
  "dependencies": {
39
- "@rsbuild/core": "1.3.19",
39
+ "@rsbuild/core": "1.3.20",
40
40
  "tinyglobby": "^0.2.13",
41
- "rsbuild-plugin-dts": "0.7.1"
41
+ "rsbuild-plugin-dts": "0.8.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@module-federation/rsbuild-plugin": "^0.13.1",
44
+ "@module-federation/rsbuild-plugin": "^0.14.0",
45
45
  "@types/fs-extra": "^11.0.4",
46
46
  "chokidar": "^4.0.3",
47
- "commander": "^13.1.0",
47
+ "commander": "^14.0.0",
48
48
  "fs-extra": "^11.3.0",
49
- "memfs": "^4.17.1",
49
+ "memfs": "^4.17.2",
50
50
  "picocolors": "1.1.1",
51
51
  "prebundle": "1.3.3",
52
52
  "rsbuild-plugin-publint": "^0.3.2",
53
- "rslib": "npm:@rslib/core@0.6.9",
53
+ "rslib": "npm:@rslib/core@0.7.1",
54
54
  "rslog": "^1.2.3",
55
55
  "tsconfck": "3.1.5",
56
56
  "typescript": "^5.8.3",