@stencil/core 2.19.2-0 → 2.19.3

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/cli/index.js CHANGED
@@ -1,18 +1,6 @@
1
1
  /*!
2
- Stencil CLI v2.19.2-0 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI v2.19.3 | MIT Licensed | https://stenciljs.com
3
3
  */
4
- /**
5
- * Convert a string from PascalCase to dash-case
6
- *
7
- * @param str the string to convert
8
- * @returns a converted string
9
- */
10
- const toDashCase = (str) => str
11
- .replace(/([A-Z0-9])/g, (match) => ` ${match[0]}`)
12
- .trim()
13
- .split(' ')
14
- .join('-')
15
- .toLowerCase();
16
4
  /**
17
5
  * Convert a string from dash-case / kebab-case to PascalCase (or CamelCase,
18
6
  * or whatever you call it!)
@@ -25,6 +13,16 @@ const dashToPascalCase = (str) => str
25
13
  .split('-')
26
14
  .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
27
15
  .join('');
16
+ /**
17
+ * Convert a string to 'camelCase'
18
+ *
19
+ * @param str the string to convert
20
+ * @returns the converted string
21
+ */
22
+ const toCamelCase = (str) => {
23
+ const pascalCase = dashToPascalCase(str);
24
+ return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
25
+ };
28
26
  const isFunction = (v) => typeof v === 'function';
29
27
  const isString = (v) => typeof v === 'string';
30
28
 
@@ -336,7 +334,7 @@ const LOG_LEVELS = ['debug', 'info', 'warn', 'error'];
336
334
  /**
337
335
  * All the Boolean options supported by the Stencil CLI
338
336
  */
339
- const BOOLEAN_CLI_ARGS = [
337
+ const BOOLEAN_CLI_FLAGS = [
340
338
  'build',
341
339
  'cache',
342
340
  'checkVersion',
@@ -419,7 +417,7 @@ const BOOLEAN_CLI_ARGS = [
419
417
  /**
420
418
  * All the Number options supported by the Stencil CLI
421
419
  */
422
- const NUMBER_CLI_ARGS = [
420
+ const NUMBER_CLI_FLAGS = [
423
421
  'port',
424
422
  // JEST CLI ARGS
425
423
  'maxConcurrency',
@@ -428,7 +426,7 @@ const NUMBER_CLI_ARGS = [
428
426
  /**
429
427
  * All the String options supported by the Stencil CLI
430
428
  */
431
- const STRING_CLI_ARGS = [
429
+ const STRING_CLI_FLAGS = [
432
430
  'address',
433
431
  'config',
434
432
  'docsApi',
@@ -467,7 +465,8 @@ const STRING_CLI_ARGS = [
467
465
  'testURL',
468
466
  'timers',
469
467
  'transform',
470
- // ARRAY ARGS
468
+ ];
469
+ const STRING_ARRAY_CLI_FLAGS = [
471
470
  'collectCoverageOnlyFrom',
472
471
  'coveragePathIgnorePatterns',
473
472
  'coverageReporters',
@@ -496,7 +495,7 @@ const STRING_CLI_ARGS = [
496
495
  * `maxWorkers` is an argument which is used both by Stencil _and_ by Jest,
497
496
  * which means that we need to support parsing both string and number values.
498
497
  */
499
- const STRING_NUMBER_CLI_ARGS = ['maxWorkers'];
498
+ const STRING_NUMBER_CLI_FLAGS = ['maxWorkers'];
500
499
  /**
501
500
  * All the LogLevel-type options supported by the Stencil CLI
502
501
  *
@@ -504,16 +503,21 @@ const STRING_NUMBER_CLI_ARGS = ['maxWorkers'];
504
503
  * but this approach lets us make sure that we're handling all
505
504
  * our arguments in a type-safe way.
506
505
  */
507
- const LOG_LEVEL_CLI_ARGS = ['logLevel'];
506
+ const LOG_LEVEL_CLI_FLAGS = ['logLevel'];
508
507
  /**
509
508
  * For a small subset of CLI options we support a short alias e.g. `'h'` for `'help'`
510
509
  */
511
- const CLI_ARG_ALIASES = {
512
- config: 'c',
513
- help: 'h',
514
- port: 'p',
515
- version: 'v',
510
+ const CLI_FLAG_ALIASES = {
511
+ c: 'config',
512
+ h: 'help',
513
+ p: 'port',
514
+ v: 'version',
516
515
  };
516
+ /**
517
+ * A regular expression which can be used to match a CLI flag for one of our
518
+ * short aliases.
519
+ */
520
+ const CLI_FLAG_REGEX = new RegExp(`^-[chpv]{1}$`);
517
521
  /**
518
522
  * Helper function for initializing a `ConfigFlags` object. Provide any overrides
519
523
  * for default values and off you go!
@@ -546,8 +550,14 @@ const parseFlags = (args, _sys) => {
546
550
  flags.args = Array.isArray(args) ? args.slice() : [];
547
551
  if (flags.args.length > 0 && flags.args[0] && !flags.args[0].startsWith('-')) {
548
552
  flags.task = flags.args[0];
553
+ // if the first argument was a "task" (like `build`, `test`, etc) then
554
+ // we go on to parse the _rest_ of the CLI args
555
+ parseArgs(flags, args.slice(1));
556
+ }
557
+ else {
558
+ // we didn't find a leading flag, so we should just parse them all
559
+ parseArgs(flags, flags.args);
549
560
  }
550
- parseArgs(flags, flags.args);
551
561
  if (flags.task != null) {
552
562
  const i = flags.args.indexOf(flags.task);
553
563
  if (i > -1) {
@@ -564,120 +574,259 @@ const parseFlags = (args, _sys) => {
564
574
  return flags;
565
575
  };
566
576
  /**
567
- * Parse command line arguments that are enumerated in the `config-flags`
568
- * module. Handles leading dashes on arguments, aliases that are defined for a
569
- * small number of arguments, and parsing values for non-boolean arguments
570
- * (e.g. port number for the dev server).
577
+ * Parse the supported command line flags which are enumerated in the
578
+ * `config-flags` module. Handles leading dashes on arguments, aliases that are
579
+ * defined for a small number of arguments, and parsing values for non-boolean
580
+ * arguments (e.g. port number for the dev server).
581
+ *
582
+ * This parses the following grammar:
583
+ *
584
+ * CLIArguments → ""
585
+ * | CLITerm ( " " CLITerm )* ;
586
+ * CLITerm → EqualsArg
587
+ * | AliasEqualsArg
588
+ * | AliasArg
589
+ * | NegativeDashArg
590
+ * | NegativeArg
591
+ * | SimpleArg ;
592
+ * EqualsArg → "--" ArgName "=" CLIValue ;
593
+ * AliasEqualsArg → "-" AliasName "=" CLIValue ;
594
+ * AliasArg → "-" AliasName ( " " CLIValue )? ;
595
+ * NegativeDashArg → "--no-" ArgName ;
596
+ * NegativeArg → "--no" ArgName ;
597
+ * SimpleArg → "--" ArgName ( " " CLIValue )? ;
598
+ * ArgName → /^[a-zA-Z-]+$/ ;
599
+ * AliasName → /^[a-z]{1}$/ ;
600
+ * CLIValue → '"' /^[a-zA-Z0-9]+$/ '"'
601
+ * | /^[a-zA-Z0-9]+$/ ;
602
+ *
603
+ * There are additional constraints (not shown in the grammar for brevity's sake)
604
+ * on the type of `CLIValue` which will be associated with a particular argument.
605
+ * We enforce this by declaring lists of boolean, string, etc arguments and
606
+ * checking the types of values before setting them.
607
+ *
608
+ * We don't need to turn the list of CLI arg tokens into any kind of
609
+ * intermediate representation since we aren't concerned with doing anything
610
+ * other than setting the correct values on our ConfigFlags object. So we just
611
+ * parse the array of string arguments using a recursive-descent approach
612
+ * (which is not very deep since our grammar is pretty simple) and make the
613
+ * modifications we need to make to the {@link ConfigFlags} object as we go.
571
614
  *
572
615
  * @param flags a ConfigFlags object to which parsed arguments will be added
573
616
  * @param args an array of command-line arguments to parse
574
617
  */
575
618
  const parseArgs = (flags, args) => {
576
- BOOLEAN_CLI_ARGS.forEach((argName) => parseBooleanArg(flags, args, argName));
577
- STRING_CLI_ARGS.forEach((argName) => parseStringArg(flags, args, argName));
578
- NUMBER_CLI_ARGS.forEach((argName) => parseNumberArg(flags, args, argName));
579
- STRING_NUMBER_CLI_ARGS.forEach((argName) => parseStringNumberArg(flags, args, argName));
580
- LOG_LEVEL_CLI_ARGS.forEach((argName) => parseLogLevelArg(flags, args, argName));
619
+ const argsCopy = args.concat();
620
+ while (argsCopy.length > 0) {
621
+ // there are still unprocessed args to deal with
622
+ parseCLITerm(flags, argsCopy);
623
+ }
581
624
  };
582
625
  /**
583
- * Parse a boolean CLI argument. For these, we support the following formats:
584
- *
585
- * - `--booleanArg`
586
- * - `--boolean-arg`
587
- * - `--noBooleanArg`
588
- * - `--no-boolean-arg`
589
- *
590
- * The final two variants should be parsed to a value of `false` on the config
591
- * object.
626
+ * Given an array of CLI arguments, parse it and perform a series of side
627
+ * effects (setting values on the provided `ConfigFlags` object).
592
628
  *
593
- * @param flags the config flags object, while we'll modify
594
- * @param args our CLI arguments
595
- * @param configCaseName the argument we want to look at right now
629
+ * @param flags a {@link ConfigFlags} object which is updated as we parse the CLI
630
+ * arguments
631
+ * @param args a list of args to work through. This function (and some functions
632
+ * it calls) calls `Array.prototype.shift` to get the next argument to look at,
633
+ * so this parameter will be modified.
596
634
  */
597
- const parseBooleanArg = (flags, args, configCaseName) => {
598
- // we support both dash-case and PascalCase versions of the parameter
599
- // argName is 'configCase' version which can be found in BOOLEAN_ARG_OPTS
600
- const alias = CLI_ARG_ALIASES[configCaseName];
601
- const dashCaseName = toDashCase(configCaseName);
602
- if (typeof flags[configCaseName] !== 'boolean') {
603
- flags[configCaseName] = null;
604
- }
605
- args.forEach((cmdArg) => {
606
- let value;
607
- if (cmdArg === `--${configCaseName}` || cmdArg === `--${dashCaseName}`) {
608
- value = true;
609
- }
610
- else if (cmdArg === `--no-${dashCaseName}` || cmdArg === `--no${dashToPascalCase(dashCaseName)}`) {
611
- value = false;
612
- }
613
- else if (alias && cmdArg === `-${alias}`) {
614
- value = true;
615
- }
616
- if (value !== undefined && cmdArg !== undefined) {
617
- flags[configCaseName] = value;
618
- flags.knownArgs.push(cmdArg);
619
- }
620
- });
635
+ const parseCLITerm = (flags, args) => {
636
+ // pull off the first arg from the argument array
637
+ const arg = args.shift();
638
+ // array is empty, we're done!
639
+ if (arg === undefined)
640
+ return;
641
+ // EqualsArg → "--" ArgName "=" CLIValue ;
642
+ if (arg.startsWith('--') && arg.includes('=')) {
643
+ // we're dealing with an EqualsArg, we have a special helper for that
644
+ const [originalArg, value] = parseEqualsArg(arg);
645
+ setCLIArg(flags, arg.split('=')[0], normalizeFlagName(originalArg), value);
646
+ }
647
+ // AliasEqualsArg → "-" AliasName "=" CLIValue ;
648
+ else if (arg.startsWith('-') && arg.includes('=')) {
649
+ // we're dealing with an AliasEqualsArg, we have a special helper for that
650
+ const [originalArg, value] = parseEqualsArg(arg);
651
+ setCLIArg(flags, arg.split('=')[0], normalizeFlagName(originalArg), value);
652
+ }
653
+ // AliasArg → "-" AliasName ( " " CLIValue )? ;
654
+ else if (CLI_FLAG_REGEX.test(arg)) {
655
+ // this is a short alias, like `-c` for Config
656
+ setCLIArg(flags, arg, normalizeFlagName(arg), parseCLIValue(args));
657
+ }
658
+ // NegativeDashArg → "--no-" ArgName ;
659
+ else if (arg.startsWith('--no-') && arg.length > '--no-'.length) {
660
+ // this is a `NegativeDashArg` term, so we need to normalize the negative
661
+ // flag name and then set an appropriate value
662
+ const normalized = normalizeNegativeFlagName(arg);
663
+ setCLIArg(flags, arg, normalized, '');
664
+ }
665
+ // NegativeArg → "--no" ArgName ;
666
+ else if (arg.startsWith('--no') &&
667
+ !readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizeFlagName(arg)) &&
668
+ readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizeNegativeFlagName(arg))) {
669
+ // possibly dealing with a `NegativeArg` here. There is a little ambiguity
670
+ // here because we have arguments that already begin with `no` like
671
+ // `notify`, so we need to test if a normalized form of the raw argument is
672
+ // a valid and supported boolean flag.
673
+ setCLIArg(flags, arg, normalizeNegativeFlagName(arg), '');
674
+ }
675
+ // SimpleArg → "--" ArgName ( " " CLIValue )? ;
676
+ else if (arg.startsWith('--') && arg.length > '--'.length) {
677
+ setCLIArg(flags, arg, normalizeFlagName(arg), parseCLIValue(args));
678
+ }
679
+ // if we get here it is not an argument in our list of supported arguments.
680
+ // This doesn't necessarily mean we want to report an error or anything
681
+ // though! Instead, with unknown / unrecognized arguments we stick them into
682
+ // the `unknownArgs` array, which is used when we pass CLI args to Jest, for
683
+ // instance. So we just return void here.
621
684
  };
622
685
  /**
623
- * Parse a string CLI argument
686
+ * Normalize a 'negative' flag name, just to do a little pre-processing before
687
+ * we pass it to `setCLIArg`.
624
688
  *
625
- * @param flags the config flags object, while we'll modify
626
- * @param args our CLI arguments
627
- * @param configCaseName the argument we want to look at right now
689
+ * @param flagName the flag name to normalize
690
+ * @returns a normalized flag name
628
691
  */
629
- const parseStringArg = (flags, args, configCaseName) => {
630
- if (typeof flags[configCaseName] !== 'string') {
631
- flags[configCaseName] = null;
632
- }
633
- const { value, matchingArg } = getValue(args, configCaseName);
634
- if (value !== undefined && matchingArg !== undefined) {
635
- flags[configCaseName] = value;
636
- flags.knownArgs.push(matchingArg);
637
- flags.knownArgs.push(value);
638
- }
692
+ const normalizeNegativeFlagName = (flagName) => {
693
+ const trimmed = flagName.replace(/^--no[-]?/, '');
694
+ return normalizeFlagName(trimmed.charAt(0).toLowerCase() + trimmed.slice(1));
639
695
  };
640
696
  /**
641
- * Parse a number CLI argument
697
+ * Normalize a flag name by:
698
+ *
699
+ * - replacing any leading dashes (`--foo` -> `foo`)
700
+ * - converting `dash-case` to camelCase (if necessary)
701
+ *
702
+ * Normalizing in this context basically means converting the various
703
+ * supported flag spelling variants to the variant defined in our lists of
704
+ * supported arguments (e.g. BOOLEAN_CLI_FLAGS, etc). So, for instance,
705
+ * `--log-level` should be converted to `logLevel`.
706
+ *
707
+ * @param flagName the flag name to normalize
708
+ * @returns a normalized flag name
642
709
  *
643
- * @param flags the config flags object, while we'll modify
644
- * @param args our CLI arguments
645
- * @param configCaseName the argument we want to look at right now
646
710
  */
647
- const parseNumberArg = (flags, args, configCaseName) => {
648
- if (typeof flags[configCaseName] !== 'number') {
649
- flags[configCaseName] = null;
650
- }
651
- const { value, matchingArg } = getValue(args, configCaseName);
652
- if (value !== undefined && matchingArg !== undefined) {
653
- flags[configCaseName] = parseInt(value, 10);
654
- flags.knownArgs.push(matchingArg);
655
- flags.knownArgs.push(value);
656
- }
711
+ const normalizeFlagName = (flagName) => {
712
+ const trimmed = flagName.replace(/^-+/, '');
713
+ return trimmed.includes('-') ? toCamelCase(trimmed) : trimmed;
657
714
  };
658
715
  /**
659
- * Parse a CLI argument which may be either a string or a number
660
- *
661
- * @param flags the config flags object, while we'll modify
662
- * @param args our CLI arguments
663
- * @param configCaseName the argument we want to look at right now
664
- */
665
- const parseStringNumberArg = (flags, args, configCaseName) => {
666
- if (!['number', 'string'].includes(typeof flags[configCaseName])) {
667
- flags[configCaseName] = null;
716
+ * Set a value on a provided {@link ConfigFlags} object, given an argument
717
+ * name and a raw string value. This function dispatches to other functions
718
+ * which make sure that the string value can be properly parsed into a JS
719
+ * runtime value of the right type (e.g. number, string, etc).
720
+ *
721
+ * @throws if a value cannot be parsed to the right type for a given flag
722
+ * @param flags a {@link ConfigFlags} object
723
+ * @param rawArg the raw argument name matched by the parser
724
+ * @param normalizedArg an argument with leading control characters (`--`,
725
+ * `--no-`, etc) removed
726
+ * @param value the raw value to be set onto the config flags object
727
+ */
728
+ const setCLIArg = (flags, rawArg, normalizedArg, value) => {
729
+ normalizedArg = dereferenceAlias(normalizedArg);
730
+ // We're setting a boolean!
731
+ if (readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizedArg)) {
732
+ flags[normalizedArg] =
733
+ typeof value === 'string'
734
+ ? Boolean(value)
735
+ : // no value was supplied, default to true
736
+ true;
737
+ flags.knownArgs.push(rawArg);
738
+ }
739
+ // We're setting a string!
740
+ else if (readOnlyArrayHasStringMember(STRING_CLI_FLAGS, normalizedArg)) {
741
+ if (typeof value === 'string') {
742
+ flags[normalizedArg] = value;
743
+ flags.knownArgs.push(rawArg);
744
+ flags.knownArgs.push(value);
745
+ }
746
+ else {
747
+ throwCLIParsingError(rawArg, 'expected a string argument but received nothing');
748
+ }
749
+ }
750
+ // We're setting a string, but it's one where the user can pass multiple values,
751
+ // like `--reporters="default" --reporters="jest-junit"`
752
+ else if (readOnlyArrayHasStringMember(STRING_ARRAY_CLI_FLAGS, normalizedArg)) {
753
+ if (typeof value === 'string') {
754
+ if (!Array.isArray(flags[normalizedArg])) {
755
+ flags[normalizedArg] = [];
756
+ }
757
+ const targetArray = flags[normalizedArg];
758
+ // this is irritating, but TS doesn't know that the `!Array.isArray`
759
+ // check above guarantees we have an array to work with here, and it
760
+ // doesn't want to narrow the type of `flags[normalizedArg]`, so we need
761
+ // to grab a reference to that array and then `Array.isArray` that. Bah!
762
+ if (Array.isArray(targetArray)) {
763
+ targetArray.push(value);
764
+ flags.knownArgs.push(rawArg);
765
+ flags.knownArgs.push(value);
766
+ }
767
+ }
768
+ else {
769
+ throwCLIParsingError(rawArg, 'expected a string argument but received nothing');
770
+ }
668
771
  }
669
- const { value, matchingArg } = getValue(args, configCaseName);
670
- if (value !== undefined && matchingArg !== undefined) {
671
- if (CLI_ARG_STRING_REGEX.test(value)) {
672
- // if it matches the regex we treat it like a string
673
- flags[configCaseName] = value;
772
+ // We're setting a number!
773
+ else if (readOnlyArrayHasStringMember(NUMBER_CLI_FLAGS, normalizedArg)) {
774
+ if (typeof value === 'string') {
775
+ const parsed = parseInt(value, 10);
776
+ if (isNaN(parsed)) {
777
+ throwNumberParsingError(rawArg, value);
778
+ }
779
+ else {
780
+ flags[normalizedArg] = parsed;
781
+ flags.knownArgs.push(rawArg);
782
+ flags.knownArgs.push(value);
783
+ }
674
784
  }
675
785
  else {
676
- // it was a number, great!
677
- flags[configCaseName] = Number(value);
786
+ throwCLIParsingError(rawArg, 'expected a number argument but received nothing');
787
+ }
788
+ }
789
+ // We're setting a value which could be either a string _or_ a number
790
+ else if (readOnlyArrayHasStringMember(STRING_NUMBER_CLI_FLAGS, normalizedArg)) {
791
+ if (typeof value === 'string') {
792
+ if (CLI_ARG_STRING_REGEX.test(value)) {
793
+ // if it matches the regex we treat it like a string
794
+ flags[normalizedArg] = value;
795
+ }
796
+ else {
797
+ const parsed = Number(value);
798
+ if (isNaN(parsed)) {
799
+ // parsing didn't go so well, we gotta get out of here
800
+ // this is unlikely given our regex guard above
801
+ // but hey, this is ultimately JS so let's be safe
802
+ throwNumberParsingError(rawArg, value);
803
+ }
804
+ else {
805
+ flags[normalizedArg] = parsed;
806
+ }
807
+ }
808
+ flags.knownArgs.push(rawArg);
809
+ flags.knownArgs.push(value);
810
+ }
811
+ else {
812
+ throwCLIParsingError(rawArg, 'expected a string or a number but received nothing');
813
+ }
814
+ }
815
+ // We're setting the log level, which can only be a set of specific string values
816
+ else if (readOnlyArrayHasStringMember(LOG_LEVEL_CLI_FLAGS, normalizedArg)) {
817
+ if (typeof value === 'string') {
818
+ if (isLogLevel(value)) {
819
+ flags[normalizedArg] = value;
820
+ flags.knownArgs.push(rawArg);
821
+ flags.knownArgs.push(value);
822
+ }
823
+ else {
824
+ throwCLIParsingError(rawArg, `expected to receive a valid log level but received "${String(value)}"`);
825
+ }
826
+ }
827
+ else {
828
+ throwCLIParsingError(rawArg, 'expected to receive a valid log level but received nothing');
678
829
  }
679
- flags.knownArgs.push(matchingArg);
680
- flags.knownArgs.push(value);
681
830
  }
682
831
  };
683
832
  /**
@@ -698,73 +847,34 @@ const parseStringNumberArg = (flags, args, configCaseName) => {
698
847
  * to a number.
699
848
  */
700
849
  const CLI_ARG_STRING_REGEX = /[^\d\.Ee\+\-]+/g;
701
- /**
702
- * Parse a LogLevel CLI argument. These can be only a specific
703
- * set of strings, so this function takes care of validating that
704
- * the value is correct.
705
- *
706
- * @param flags the config flags object, while we'll modify
707
- * @param args our CLI arguments
708
- * @param configCaseName the argument we want to look at right now
709
- */
710
- const parseLogLevelArg = (flags, args, configCaseName) => {
711
- if (typeof flags[configCaseName] !== 'string') {
712
- flags[configCaseName] = null;
713
- }
714
- const { value, matchingArg } = getValue(args, configCaseName);
715
- if (value !== undefined && matchingArg !== undefined && isLogLevel(value)) {
716
- flags[configCaseName] = value;
717
- flags.knownArgs.push(matchingArg);
718
- flags.knownArgs.push(value);
719
- }
720
- };
721
- /**
722
- * Helper for pulling values out from the raw array of CLI arguments. This logic
723
- * is shared between a few different types of CLI args.
724
- *
725
- * We look for arguments in the following formats:
726
- *
727
- * - `--my-cli-argument value`
728
- * - `--my-cli-argument=value`
729
- * - `--myCliArgument value`
730
- * - `--myCliArgument=value`
731
- *
732
- * We also check for shortened aliases, which we define for a few arguments.
733
- *
734
- * @param args the CLI args we're dealing with
735
- * @param configCaseName the ConfigFlag key which we're looking to pull out a value for
736
- * @returns the value for the flag as well as the exact string which it matched from
737
- * the user input.
738
- */
739
- const getValue = (args, configCaseName) => {
740
- // for some CLI args we have a short alias, like 'c' for 'config'
741
- const alias = CLI_ARG_ALIASES[configCaseName];
742
- // we support supplying arguments in both dash-case and configCase
743
- // for ease of use
744
- const dashCaseName = toDashCase(configCaseName);
745
- let value;
746
- let matchingArg;
747
- args.forEach((arg, i) => {
748
- if (arg.startsWith(`--${dashCaseName}=`) || arg.startsWith(`--${configCaseName}=`)) {
749
- // our argument was passed at the command-line in the format --argName=arg-value
750
- [matchingArg, value] = parseEqualsArg(arg);
850
+ const Empty = Symbol('Empty');
851
+ /**
852
+ * A little helper which tries to parse a CLI value (as opposed to a flag) off
853
+ * of the argument array.
854
+ *
855
+ * We support a variety of different argument formats, but all of them start
856
+ * with `-`, so we can check the first character to test whether the next token
857
+ * in our array of CLI arguments is a flag name or a value.
858
+ *
859
+ * @param args an array of CLI args
860
+ * @returns either a string result or an Empty sentinel
861
+ */
862
+ const parseCLIValue = (args) => {
863
+ // it's possible the arguments array is empty, if so, return empty
864
+ if (args[0] === undefined) {
865
+ return Empty;
866
+ }
867
+ // all we're concerned with here is that it does not start with `"-"`,
868
+ // which would indicate it should be parsed as a CLI flag and not a value.
869
+ if (!args[0].startsWith('-')) {
870
+ // It's not a flag, so we return the value and defer any specific parsing
871
+ // until later on.
872
+ const value = args.shift();
873
+ if (typeof value === 'string') {
874
+ return value;
751
875
  }
752
- else if (arg === `--${dashCaseName}` || arg === `--${configCaseName}`) {
753
- // the next value in the array is assumed to be a value for this argument
754
- value = args[i + 1];
755
- matchingArg = arg;
756
- }
757
- else if (alias) {
758
- if (arg.startsWith(`-${alias}=`)) {
759
- [matchingArg, value] = parseEqualsArg(arg);
760
- }
761
- else if (arg === `-${alias}`) {
762
- value = args[i + 1];
763
- matchingArg = arg;
764
- }
765
- }
766
- });
767
- return { value, matchingArg };
876
+ }
877
+ return Empty;
768
878
  };
769
879
  /**
770
880
  * Parse an 'equals' argument, which is a CLI argument-value pair in the
@@ -800,8 +910,9 @@ const getValue = (args, configCaseName) => {
800
910
  * @returns a tuple containing the arg name and the value (if present)
801
911
  */
802
912
  const parseEqualsArg = (arg) => {
803
- const [originalArg, ...value] = arg.split('=');
804
- return [originalArg, value.join('=')];
913
+ const [originalArg, ...splitSections] = arg.split('=');
914
+ const value = splitSections.join('=');
915
+ return [originalArg, value === '' ? Empty : value];
805
916
  };
806
917
  /**
807
918
  * Small helper for getting type-system-level assurance that a `string` can be
@@ -811,11 +922,50 @@ const parseEqualsArg = (arg) => {
811
922
  * @returns whether this is a `LogLevel`
812
923
  */
813
924
  const isLogLevel = (maybeLogLevel) => readOnlyArrayHasStringMember(LOG_LEVELS, maybeLogLevel);
925
+ /**
926
+ * A little helper for constructing and throwing an error message with info
927
+ * about what went wrong
928
+ *
929
+ * @param flag the flag which encountered the error
930
+ * @param message a message specific to the error which was encountered
931
+ */
932
+ const throwCLIParsingError = (flag, message) => {
933
+ throw new Error(`when parsing CLI flag "${flag}": ${message}`);
934
+ };
935
+ /**
936
+ * Throw a specific error for the situation where we ran into an issue parsing
937
+ * a number.
938
+ *
939
+ * @param flag the flag for which we encountered the issue
940
+ * @param value what we were trying to parse
941
+ */
942
+ const throwNumberParsingError = (flag, value) => {
943
+ throwCLIParsingError(flag, `expected a number but received "${value}"`);
944
+ };
945
+ /**
946
+ * A little helper to 'dereference' a flag alias, which if you squint a little
947
+ * you can think of like a pointer to a full flag name. Thus 'c' is like a
948
+ * pointer to 'config', so here we're doing something like `*c`. Of course, this
949
+ * being JS, this is just a metaphor!
950
+ *
951
+ * If no 'dereference' is found for the possible alias we just return the
952
+ * passed string unmodified.
953
+ *
954
+ * @param maybeAlias a string which _could_ be an alias to a full flag name
955
+ * @returns the full aliased flag name, if found, or the passed string if not
956
+ */
957
+ const dereferenceAlias = (maybeAlias) => {
958
+ const possibleDereference = CLI_FLAG_ALIASES[maybeAlias];
959
+ if (typeof possibleDereference === 'string') {
960
+ return possibleDereference;
961
+ }
962
+ return maybeAlias;
963
+ };
814
964
 
815
965
  const dependencies = [
816
966
  {
817
967
  name: "@stencil/core",
818
- version: "2.19.2-0",
968
+ version: "2.19.3",
819
969
  main: "compiler/stencil.js",
820
970
  resources: [
821
971
  "package.json",
@@ -1562,7 +1712,16 @@ const CONFIG_PROPS_TO_ANONYMIZE = [
1562
1712
  // Props we delete entirely from the config for telemetry
1563
1713
  //
1564
1714
  // TODO(STENCIL-469): Investigate improving anonymization for tsCompilerOptions and devServer
1565
- const CONFIG_PROPS_TO_DELETE = ['sys', 'logger', 'tsCompilerOptions', 'devServer'];
1715
+ const CONFIG_PROPS_TO_DELETE = [
1716
+ 'commonjs',
1717
+ 'devServer',
1718
+ 'env',
1719
+ 'logger',
1720
+ 'rollupConfig',
1721
+ 'sys',
1722
+ 'testing',
1723
+ 'tsCompilerOptions',
1724
+ ];
1566
1725
  /**
1567
1726
  * Anonymize the config for telemetry, replacing potentially revealing config props
1568
1727
  * with a placeholder string if they are present (this lets us still track how frequently
@@ -1873,13 +2032,24 @@ const taskGenerate = async (coreCompiler, config) => {
1873
2032
  const { prompt } = await import('../sys/node/prompts.js');
1874
2033
  const input = config.flags.unknownArgs.find((arg) => !arg.startsWith('-')) ||
1875
2034
  (await prompt({ name: 'tagName', type: 'text', message: 'Component tag name (dash-case):' })).tagName;
2035
+ if (undefined === input) {
2036
+ // in some shells (e.g. Windows PowerShell), hitting Ctrl+C results in a TypeError printed to the console.
2037
+ // explicitly return here to avoid printing the error message.
2038
+ return;
2039
+ }
1876
2040
  const { dir, base: componentName } = path.parse(input);
1877
2041
  const tagError = validateComponentTag(componentName);
1878
2042
  if (tagError) {
1879
2043
  config.logger.error(tagError);
1880
2044
  return config.sys.exit(1);
1881
2045
  }
1882
- const extensionsToGenerate = ['tsx', ...(await chooseFilesToGenerate())];
2046
+ const filesToGenerateExt = await chooseFilesToGenerate();
2047
+ if (undefined === filesToGenerateExt) {
2048
+ // in some shells (e.g. Windows PowerShell), hitting Ctrl+C results in a TypeError printed to the console.
2049
+ // explicitly return here to avoid printing the error message.
2050
+ return;
2051
+ }
2052
+ const extensionsToGenerate = ['tsx', ...filesToGenerateExt];
1883
2053
  const testFolder = extensionsToGenerate.some(isTest) ? 'test' : '';
1884
2054
  const outDir = path.join(absoluteSrcDir, 'components', dir, componentName);
1885
2055
  await config.sys.createDir(path.join(outDir, testFolder), { recursive: true });