@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/config-flags.d.ts +31 -19
- package/cli/index.cjs +357 -187
- package/cli/index.js +357 -187
- package/cli/package.json +1 -1
- package/compiler/package.json +1 -1
- package/compiler/stencil.js +363 -526
- package/compiler/stencil.min.js +2 -2
- package/dependencies.json +1 -1
- package/dev-server/client/index.js +1 -1
- package/dev-server/client/package.json +1 -1
- package/dev-server/connector.html +2 -2
- package/dev-server/index.js +1 -1
- package/dev-server/package.json +1 -1
- package/dev-server/server-process.js +2 -2
- package/internal/app-data/package.json +1 -1
- package/internal/client/css-shim.js +1 -1
- package/internal/client/dom.js +1 -1
- package/internal/client/index.js +1 -1
- package/internal/client/package.json +1 -1
- package/internal/client/patch-browser.js +1 -1
- package/internal/client/patch-esm.js +1 -1
- package/internal/client/shadow-css.js +1 -1
- package/internal/hydrate/package.json +1 -1
- package/internal/package.json +1 -1
- package/internal/testing/package.json +1 -1
- package/mock-doc/index.cjs +1 -1
- package/mock-doc/index.js +1 -1
- package/mock-doc/package.json +1 -1
- package/package.json +4 -4
- package/screenshot/package.json +1 -1
- package/sys/node/autoprefixer.js +2 -2
- package/sys/node/index.js +1 -1
- package/sys/node/package.json +1 -1
- package/sys/node/worker.js +1 -1
- package/testing/index.js +2 -2
- package/testing/package.json +1 -1
package/cli/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
Stencil CLI (CommonJS) v2.19.
|
|
2
|
+
Stencil CLI (CommonJS) v2.19.3 | MIT Licensed | https://stenciljs.com
|
|
3
3
|
*/
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
@@ -25,18 +25,6 @@ function _interopNamespace(e) {
|
|
|
25
25
|
return Object.freeze(n);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
* Convert a string from PascalCase to dash-case
|
|
30
|
-
*
|
|
31
|
-
* @param str the string to convert
|
|
32
|
-
* @returns a converted string
|
|
33
|
-
*/
|
|
34
|
-
const toDashCase = (str) => str
|
|
35
|
-
.replace(/([A-Z0-9])/g, (match) => ` ${match[0]}`)
|
|
36
|
-
.trim()
|
|
37
|
-
.split(' ')
|
|
38
|
-
.join('-')
|
|
39
|
-
.toLowerCase();
|
|
40
28
|
/**
|
|
41
29
|
* Convert a string from dash-case / kebab-case to PascalCase (or CamelCase,
|
|
42
30
|
* or whatever you call it!)
|
|
@@ -49,6 +37,16 @@ const dashToPascalCase = (str) => str
|
|
|
49
37
|
.split('-')
|
|
50
38
|
.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
|
|
51
39
|
.join('');
|
|
40
|
+
/**
|
|
41
|
+
* Convert a string to 'camelCase'
|
|
42
|
+
*
|
|
43
|
+
* @param str the string to convert
|
|
44
|
+
* @returns the converted string
|
|
45
|
+
*/
|
|
46
|
+
const toCamelCase = (str) => {
|
|
47
|
+
const pascalCase = dashToPascalCase(str);
|
|
48
|
+
return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
|
|
49
|
+
};
|
|
52
50
|
const isFunction = (v) => typeof v === 'function';
|
|
53
51
|
const isString = (v) => typeof v === 'string';
|
|
54
52
|
|
|
@@ -360,7 +358,7 @@ const LOG_LEVELS = ['debug', 'info', 'warn', 'error'];
|
|
|
360
358
|
/**
|
|
361
359
|
* All the Boolean options supported by the Stencil CLI
|
|
362
360
|
*/
|
|
363
|
-
const
|
|
361
|
+
const BOOLEAN_CLI_FLAGS = [
|
|
364
362
|
'build',
|
|
365
363
|
'cache',
|
|
366
364
|
'checkVersion',
|
|
@@ -443,7 +441,7 @@ const BOOLEAN_CLI_ARGS = [
|
|
|
443
441
|
/**
|
|
444
442
|
* All the Number options supported by the Stencil CLI
|
|
445
443
|
*/
|
|
446
|
-
const
|
|
444
|
+
const NUMBER_CLI_FLAGS = [
|
|
447
445
|
'port',
|
|
448
446
|
// JEST CLI ARGS
|
|
449
447
|
'maxConcurrency',
|
|
@@ -452,7 +450,7 @@ const NUMBER_CLI_ARGS = [
|
|
|
452
450
|
/**
|
|
453
451
|
* All the String options supported by the Stencil CLI
|
|
454
452
|
*/
|
|
455
|
-
const
|
|
453
|
+
const STRING_CLI_FLAGS = [
|
|
456
454
|
'address',
|
|
457
455
|
'config',
|
|
458
456
|
'docsApi',
|
|
@@ -491,7 +489,8 @@ const STRING_CLI_ARGS = [
|
|
|
491
489
|
'testURL',
|
|
492
490
|
'timers',
|
|
493
491
|
'transform',
|
|
494
|
-
|
|
492
|
+
];
|
|
493
|
+
const STRING_ARRAY_CLI_FLAGS = [
|
|
495
494
|
'collectCoverageOnlyFrom',
|
|
496
495
|
'coveragePathIgnorePatterns',
|
|
497
496
|
'coverageReporters',
|
|
@@ -520,7 +519,7 @@ const STRING_CLI_ARGS = [
|
|
|
520
519
|
* `maxWorkers` is an argument which is used both by Stencil _and_ by Jest,
|
|
521
520
|
* which means that we need to support parsing both string and number values.
|
|
522
521
|
*/
|
|
523
|
-
const
|
|
522
|
+
const STRING_NUMBER_CLI_FLAGS = ['maxWorkers'];
|
|
524
523
|
/**
|
|
525
524
|
* All the LogLevel-type options supported by the Stencil CLI
|
|
526
525
|
*
|
|
@@ -528,16 +527,21 @@ const STRING_NUMBER_CLI_ARGS = ['maxWorkers'];
|
|
|
528
527
|
* but this approach lets us make sure that we're handling all
|
|
529
528
|
* our arguments in a type-safe way.
|
|
530
529
|
*/
|
|
531
|
-
const
|
|
530
|
+
const LOG_LEVEL_CLI_FLAGS = ['logLevel'];
|
|
532
531
|
/**
|
|
533
532
|
* For a small subset of CLI options we support a short alias e.g. `'h'` for `'help'`
|
|
534
533
|
*/
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
534
|
+
const CLI_FLAG_ALIASES = {
|
|
535
|
+
c: 'config',
|
|
536
|
+
h: 'help',
|
|
537
|
+
p: 'port',
|
|
538
|
+
v: 'version',
|
|
540
539
|
};
|
|
540
|
+
/**
|
|
541
|
+
* A regular expression which can be used to match a CLI flag for one of our
|
|
542
|
+
* short aliases.
|
|
543
|
+
*/
|
|
544
|
+
const CLI_FLAG_REGEX = new RegExp(`^-[chpv]{1}$`);
|
|
541
545
|
/**
|
|
542
546
|
* Helper function for initializing a `ConfigFlags` object. Provide any overrides
|
|
543
547
|
* for default values and off you go!
|
|
@@ -570,8 +574,14 @@ const parseFlags = (args, _sys) => {
|
|
|
570
574
|
flags.args = Array.isArray(args) ? args.slice() : [];
|
|
571
575
|
if (flags.args.length > 0 && flags.args[0] && !flags.args[0].startsWith('-')) {
|
|
572
576
|
flags.task = flags.args[0];
|
|
577
|
+
// if the first argument was a "task" (like `build`, `test`, etc) then
|
|
578
|
+
// we go on to parse the _rest_ of the CLI args
|
|
579
|
+
parseArgs(flags, args.slice(1));
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
// we didn't find a leading flag, so we should just parse them all
|
|
583
|
+
parseArgs(flags, flags.args);
|
|
573
584
|
}
|
|
574
|
-
parseArgs(flags, flags.args);
|
|
575
585
|
if (flags.task != null) {
|
|
576
586
|
const i = flags.args.indexOf(flags.task);
|
|
577
587
|
if (i > -1) {
|
|
@@ -588,120 +598,259 @@ const parseFlags = (args, _sys) => {
|
|
|
588
598
|
return flags;
|
|
589
599
|
};
|
|
590
600
|
/**
|
|
591
|
-
* Parse command line
|
|
592
|
-
* module. Handles leading dashes on arguments, aliases that are
|
|
593
|
-
* small number of arguments, and parsing values for non-boolean
|
|
594
|
-
* (e.g. port number for the dev server).
|
|
601
|
+
* Parse the supported command line flags which are enumerated in the
|
|
602
|
+
* `config-flags` module. Handles leading dashes on arguments, aliases that are
|
|
603
|
+
* defined for a small number of arguments, and parsing values for non-boolean
|
|
604
|
+
* arguments (e.g. port number for the dev server).
|
|
605
|
+
*
|
|
606
|
+
* This parses the following grammar:
|
|
607
|
+
*
|
|
608
|
+
* CLIArguments → ""
|
|
609
|
+
* | CLITerm ( " " CLITerm )* ;
|
|
610
|
+
* CLITerm → EqualsArg
|
|
611
|
+
* | AliasEqualsArg
|
|
612
|
+
* | AliasArg
|
|
613
|
+
* | NegativeDashArg
|
|
614
|
+
* | NegativeArg
|
|
615
|
+
* | SimpleArg ;
|
|
616
|
+
* EqualsArg → "--" ArgName "=" CLIValue ;
|
|
617
|
+
* AliasEqualsArg → "-" AliasName "=" CLIValue ;
|
|
618
|
+
* AliasArg → "-" AliasName ( " " CLIValue )? ;
|
|
619
|
+
* NegativeDashArg → "--no-" ArgName ;
|
|
620
|
+
* NegativeArg → "--no" ArgName ;
|
|
621
|
+
* SimpleArg → "--" ArgName ( " " CLIValue )? ;
|
|
622
|
+
* ArgName → /^[a-zA-Z-]+$/ ;
|
|
623
|
+
* AliasName → /^[a-z]{1}$/ ;
|
|
624
|
+
* CLIValue → '"' /^[a-zA-Z0-9]+$/ '"'
|
|
625
|
+
* | /^[a-zA-Z0-9]+$/ ;
|
|
626
|
+
*
|
|
627
|
+
* There are additional constraints (not shown in the grammar for brevity's sake)
|
|
628
|
+
* on the type of `CLIValue` which will be associated with a particular argument.
|
|
629
|
+
* We enforce this by declaring lists of boolean, string, etc arguments and
|
|
630
|
+
* checking the types of values before setting them.
|
|
631
|
+
*
|
|
632
|
+
* We don't need to turn the list of CLI arg tokens into any kind of
|
|
633
|
+
* intermediate representation since we aren't concerned with doing anything
|
|
634
|
+
* other than setting the correct values on our ConfigFlags object. So we just
|
|
635
|
+
* parse the array of string arguments using a recursive-descent approach
|
|
636
|
+
* (which is not very deep since our grammar is pretty simple) and make the
|
|
637
|
+
* modifications we need to make to the {@link ConfigFlags} object as we go.
|
|
595
638
|
*
|
|
596
639
|
* @param flags a ConfigFlags object to which parsed arguments will be added
|
|
597
640
|
* @param args an array of command-line arguments to parse
|
|
598
641
|
*/
|
|
599
642
|
const parseArgs = (flags, args) => {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
643
|
+
const argsCopy = args.concat();
|
|
644
|
+
while (argsCopy.length > 0) {
|
|
645
|
+
// there are still unprocessed args to deal with
|
|
646
|
+
parseCLITerm(flags, argsCopy);
|
|
647
|
+
}
|
|
605
648
|
};
|
|
606
649
|
/**
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
* - `--booleanArg`
|
|
610
|
-
* - `--boolean-arg`
|
|
611
|
-
* - `--noBooleanArg`
|
|
612
|
-
* - `--no-boolean-arg`
|
|
613
|
-
*
|
|
614
|
-
* The final two variants should be parsed to a value of `false` on the config
|
|
615
|
-
* object.
|
|
650
|
+
* Given an array of CLI arguments, parse it and perform a series of side
|
|
651
|
+
* effects (setting values on the provided `ConfigFlags` object).
|
|
616
652
|
*
|
|
617
|
-
* @param flags
|
|
618
|
-
*
|
|
619
|
-
* @param
|
|
653
|
+
* @param flags a {@link ConfigFlags} object which is updated as we parse the CLI
|
|
654
|
+
* arguments
|
|
655
|
+
* @param args a list of args to work through. This function (and some functions
|
|
656
|
+
* it calls) calls `Array.prototype.shift` to get the next argument to look at,
|
|
657
|
+
* so this parameter will be modified.
|
|
620
658
|
*/
|
|
621
|
-
const
|
|
622
|
-
//
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
659
|
+
const parseCLITerm = (flags, args) => {
|
|
660
|
+
// pull off the first arg from the argument array
|
|
661
|
+
const arg = args.shift();
|
|
662
|
+
// array is empty, we're done!
|
|
663
|
+
if (arg === undefined)
|
|
664
|
+
return;
|
|
665
|
+
// EqualsArg → "--" ArgName "=" CLIValue ;
|
|
666
|
+
if (arg.startsWith('--') && arg.includes('=')) {
|
|
667
|
+
// we're dealing with an EqualsArg, we have a special helper for that
|
|
668
|
+
const [originalArg, value] = parseEqualsArg(arg);
|
|
669
|
+
setCLIArg(flags, arg.split('=')[0], normalizeFlagName(originalArg), value);
|
|
670
|
+
}
|
|
671
|
+
// AliasEqualsArg → "-" AliasName "=" CLIValue ;
|
|
672
|
+
else if (arg.startsWith('-') && arg.includes('=')) {
|
|
673
|
+
// we're dealing with an AliasEqualsArg, we have a special helper for that
|
|
674
|
+
const [originalArg, value] = parseEqualsArg(arg);
|
|
675
|
+
setCLIArg(flags, arg.split('=')[0], normalizeFlagName(originalArg), value);
|
|
676
|
+
}
|
|
677
|
+
// AliasArg → "-" AliasName ( " " CLIValue )? ;
|
|
678
|
+
else if (CLI_FLAG_REGEX.test(arg)) {
|
|
679
|
+
// this is a short alias, like `-c` for Config
|
|
680
|
+
setCLIArg(flags, arg, normalizeFlagName(arg), parseCLIValue(args));
|
|
681
|
+
}
|
|
682
|
+
// NegativeDashArg → "--no-" ArgName ;
|
|
683
|
+
else if (arg.startsWith('--no-') && arg.length > '--no-'.length) {
|
|
684
|
+
// this is a `NegativeDashArg` term, so we need to normalize the negative
|
|
685
|
+
// flag name and then set an appropriate value
|
|
686
|
+
const normalized = normalizeNegativeFlagName(arg);
|
|
687
|
+
setCLIArg(flags, arg, normalized, '');
|
|
688
|
+
}
|
|
689
|
+
// NegativeArg → "--no" ArgName ;
|
|
690
|
+
else if (arg.startsWith('--no') &&
|
|
691
|
+
!readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizeFlagName(arg)) &&
|
|
692
|
+
readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizeNegativeFlagName(arg))) {
|
|
693
|
+
// possibly dealing with a `NegativeArg` here. There is a little ambiguity
|
|
694
|
+
// here because we have arguments that already begin with `no` like
|
|
695
|
+
// `notify`, so we need to test if a normalized form of the raw argument is
|
|
696
|
+
// a valid and supported boolean flag.
|
|
697
|
+
setCLIArg(flags, arg, normalizeNegativeFlagName(arg), '');
|
|
698
|
+
}
|
|
699
|
+
// SimpleArg → "--" ArgName ( " " CLIValue )? ;
|
|
700
|
+
else if (arg.startsWith('--') && arg.length > '--'.length) {
|
|
701
|
+
setCLIArg(flags, arg, normalizeFlagName(arg), parseCLIValue(args));
|
|
702
|
+
}
|
|
703
|
+
// if we get here it is not an argument in our list of supported arguments.
|
|
704
|
+
// This doesn't necessarily mean we want to report an error or anything
|
|
705
|
+
// though! Instead, with unknown / unrecognized arguments we stick them into
|
|
706
|
+
// the `unknownArgs` array, which is used when we pass CLI args to Jest, for
|
|
707
|
+
// instance. So we just return void here.
|
|
645
708
|
};
|
|
646
709
|
/**
|
|
647
|
-
*
|
|
710
|
+
* Normalize a 'negative' flag name, just to do a little pre-processing before
|
|
711
|
+
* we pass it to `setCLIArg`.
|
|
648
712
|
*
|
|
649
|
-
* @param
|
|
650
|
-
* @
|
|
651
|
-
* @param configCaseName the argument we want to look at right now
|
|
713
|
+
* @param flagName the flag name to normalize
|
|
714
|
+
* @returns a normalized flag name
|
|
652
715
|
*/
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
const { value, matchingArg } = getValue(args, configCaseName);
|
|
658
|
-
if (value !== undefined && matchingArg !== undefined) {
|
|
659
|
-
flags[configCaseName] = value;
|
|
660
|
-
flags.knownArgs.push(matchingArg);
|
|
661
|
-
flags.knownArgs.push(value);
|
|
662
|
-
}
|
|
716
|
+
const normalizeNegativeFlagName = (flagName) => {
|
|
717
|
+
const trimmed = flagName.replace(/^--no[-]?/, '');
|
|
718
|
+
return normalizeFlagName(trimmed.charAt(0).toLowerCase() + trimmed.slice(1));
|
|
663
719
|
};
|
|
664
720
|
/**
|
|
665
|
-
*
|
|
721
|
+
* Normalize a flag name by:
|
|
722
|
+
*
|
|
723
|
+
* - replacing any leading dashes (`--foo` -> `foo`)
|
|
724
|
+
* - converting `dash-case` to camelCase (if necessary)
|
|
725
|
+
*
|
|
726
|
+
* Normalizing in this context basically means converting the various
|
|
727
|
+
* supported flag spelling variants to the variant defined in our lists of
|
|
728
|
+
* supported arguments (e.g. BOOLEAN_CLI_FLAGS, etc). So, for instance,
|
|
729
|
+
* `--log-level` should be converted to `logLevel`.
|
|
730
|
+
*
|
|
731
|
+
* @param flagName the flag name to normalize
|
|
732
|
+
* @returns a normalized flag name
|
|
666
733
|
*
|
|
667
|
-
* @param flags the config flags object, while we'll modify
|
|
668
|
-
* @param args our CLI arguments
|
|
669
|
-
* @param configCaseName the argument we want to look at right now
|
|
670
734
|
*/
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
675
|
-
const { value, matchingArg } = getValue(args, configCaseName);
|
|
676
|
-
if (value !== undefined && matchingArg !== undefined) {
|
|
677
|
-
flags[configCaseName] = parseInt(value, 10);
|
|
678
|
-
flags.knownArgs.push(matchingArg);
|
|
679
|
-
flags.knownArgs.push(value);
|
|
680
|
-
}
|
|
735
|
+
const normalizeFlagName = (flagName) => {
|
|
736
|
+
const trimmed = flagName.replace(/^-+/, '');
|
|
737
|
+
return trimmed.includes('-') ? toCamelCase(trimmed) : trimmed;
|
|
681
738
|
};
|
|
682
739
|
/**
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
740
|
+
* Set a value on a provided {@link ConfigFlags} object, given an argument
|
|
741
|
+
* name and a raw string value. This function dispatches to other functions
|
|
742
|
+
* which make sure that the string value can be properly parsed into a JS
|
|
743
|
+
* runtime value of the right type (e.g. number, string, etc).
|
|
744
|
+
*
|
|
745
|
+
* @throws if a value cannot be parsed to the right type for a given flag
|
|
746
|
+
* @param flags a {@link ConfigFlags} object
|
|
747
|
+
* @param rawArg the raw argument name matched by the parser
|
|
748
|
+
* @param normalizedArg an argument with leading control characters (`--`,
|
|
749
|
+
* `--no-`, etc) removed
|
|
750
|
+
* @param value the raw value to be set onto the config flags object
|
|
751
|
+
*/
|
|
752
|
+
const setCLIArg = (flags, rawArg, normalizedArg, value) => {
|
|
753
|
+
normalizedArg = dereferenceAlias(normalizedArg);
|
|
754
|
+
// We're setting a boolean!
|
|
755
|
+
if (readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizedArg)) {
|
|
756
|
+
flags[normalizedArg] =
|
|
757
|
+
typeof value === 'string'
|
|
758
|
+
? Boolean(value)
|
|
759
|
+
: // no value was supplied, default to true
|
|
760
|
+
true;
|
|
761
|
+
flags.knownArgs.push(rawArg);
|
|
762
|
+
}
|
|
763
|
+
// We're setting a string!
|
|
764
|
+
else if (readOnlyArrayHasStringMember(STRING_CLI_FLAGS, normalizedArg)) {
|
|
765
|
+
if (typeof value === 'string') {
|
|
766
|
+
flags[normalizedArg] = value;
|
|
767
|
+
flags.knownArgs.push(rawArg);
|
|
768
|
+
flags.knownArgs.push(value);
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
throwCLIParsingError(rawArg, 'expected a string argument but received nothing');
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
// We're setting a string, but it's one where the user can pass multiple values,
|
|
775
|
+
// like `--reporters="default" --reporters="jest-junit"`
|
|
776
|
+
else if (readOnlyArrayHasStringMember(STRING_ARRAY_CLI_FLAGS, normalizedArg)) {
|
|
777
|
+
if (typeof value === 'string') {
|
|
778
|
+
if (!Array.isArray(flags[normalizedArg])) {
|
|
779
|
+
flags[normalizedArg] = [];
|
|
780
|
+
}
|
|
781
|
+
const targetArray = flags[normalizedArg];
|
|
782
|
+
// this is irritating, but TS doesn't know that the `!Array.isArray`
|
|
783
|
+
// check above guarantees we have an array to work with here, and it
|
|
784
|
+
// doesn't want to narrow the type of `flags[normalizedArg]`, so we need
|
|
785
|
+
// to grab a reference to that array and then `Array.isArray` that. Bah!
|
|
786
|
+
if (Array.isArray(targetArray)) {
|
|
787
|
+
targetArray.push(value);
|
|
788
|
+
flags.knownArgs.push(rawArg);
|
|
789
|
+
flags.knownArgs.push(value);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
throwCLIParsingError(rawArg, 'expected a string argument but received nothing');
|
|
794
|
+
}
|
|
692
795
|
}
|
|
693
|
-
|
|
694
|
-
if (
|
|
695
|
-
if (
|
|
696
|
-
|
|
697
|
-
|
|
796
|
+
// We're setting a number!
|
|
797
|
+
else if (readOnlyArrayHasStringMember(NUMBER_CLI_FLAGS, normalizedArg)) {
|
|
798
|
+
if (typeof value === 'string') {
|
|
799
|
+
const parsed = parseInt(value, 10);
|
|
800
|
+
if (isNaN(parsed)) {
|
|
801
|
+
throwNumberParsingError(rawArg, value);
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
flags[normalizedArg] = parsed;
|
|
805
|
+
flags.knownArgs.push(rawArg);
|
|
806
|
+
flags.knownArgs.push(value);
|
|
807
|
+
}
|
|
698
808
|
}
|
|
699
809
|
else {
|
|
700
|
-
|
|
701
|
-
|
|
810
|
+
throwCLIParsingError(rawArg, 'expected a number argument but received nothing');
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
// We're setting a value which could be either a string _or_ a number
|
|
814
|
+
else if (readOnlyArrayHasStringMember(STRING_NUMBER_CLI_FLAGS, normalizedArg)) {
|
|
815
|
+
if (typeof value === 'string') {
|
|
816
|
+
if (CLI_ARG_STRING_REGEX.test(value)) {
|
|
817
|
+
// if it matches the regex we treat it like a string
|
|
818
|
+
flags[normalizedArg] = value;
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
const parsed = Number(value);
|
|
822
|
+
if (isNaN(parsed)) {
|
|
823
|
+
// parsing didn't go so well, we gotta get out of here
|
|
824
|
+
// this is unlikely given our regex guard above
|
|
825
|
+
// but hey, this is ultimately JS so let's be safe
|
|
826
|
+
throwNumberParsingError(rawArg, value);
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
flags[normalizedArg] = parsed;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
flags.knownArgs.push(rawArg);
|
|
833
|
+
flags.knownArgs.push(value);
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
throwCLIParsingError(rawArg, 'expected a string or a number but received nothing');
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
// We're setting the log level, which can only be a set of specific string values
|
|
840
|
+
else if (readOnlyArrayHasStringMember(LOG_LEVEL_CLI_FLAGS, normalizedArg)) {
|
|
841
|
+
if (typeof value === 'string') {
|
|
842
|
+
if (isLogLevel(value)) {
|
|
843
|
+
flags[normalizedArg] = value;
|
|
844
|
+
flags.knownArgs.push(rawArg);
|
|
845
|
+
flags.knownArgs.push(value);
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
throwCLIParsingError(rawArg, `expected to receive a valid log level but received "${String(value)}"`);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
else {
|
|
852
|
+
throwCLIParsingError(rawArg, 'expected to receive a valid log level but received nothing');
|
|
702
853
|
}
|
|
703
|
-
flags.knownArgs.push(matchingArg);
|
|
704
|
-
flags.knownArgs.push(value);
|
|
705
854
|
}
|
|
706
855
|
};
|
|
707
856
|
/**
|
|
@@ -722,73 +871,34 @@ const parseStringNumberArg = (flags, args, configCaseName) => {
|
|
|
722
871
|
* to a number.
|
|
723
872
|
*/
|
|
724
873
|
const CLI_ARG_STRING_REGEX = /[^\d\.Ee\+\-]+/g;
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
*
|
|
728
|
-
* the
|
|
729
|
-
*
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
if (
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
*
|
|
751
|
-
* - `--my-cli-argument value`
|
|
752
|
-
* - `--my-cli-argument=value`
|
|
753
|
-
* - `--myCliArgument value`
|
|
754
|
-
* - `--myCliArgument=value`
|
|
755
|
-
*
|
|
756
|
-
* We also check for shortened aliases, which we define for a few arguments.
|
|
757
|
-
*
|
|
758
|
-
* @param args the CLI args we're dealing with
|
|
759
|
-
* @param configCaseName the ConfigFlag key which we're looking to pull out a value for
|
|
760
|
-
* @returns the value for the flag as well as the exact string which it matched from
|
|
761
|
-
* the user input.
|
|
762
|
-
*/
|
|
763
|
-
const getValue = (args, configCaseName) => {
|
|
764
|
-
// for some CLI args we have a short alias, like 'c' for 'config'
|
|
765
|
-
const alias = CLI_ARG_ALIASES[configCaseName];
|
|
766
|
-
// we support supplying arguments in both dash-case and configCase
|
|
767
|
-
// for ease of use
|
|
768
|
-
const dashCaseName = toDashCase(configCaseName);
|
|
769
|
-
let value;
|
|
770
|
-
let matchingArg;
|
|
771
|
-
args.forEach((arg, i) => {
|
|
772
|
-
if (arg.startsWith(`--${dashCaseName}=`) || arg.startsWith(`--${configCaseName}=`)) {
|
|
773
|
-
// our argument was passed at the command-line in the format --argName=arg-value
|
|
774
|
-
[matchingArg, value] = parseEqualsArg(arg);
|
|
874
|
+
const Empty = Symbol('Empty');
|
|
875
|
+
/**
|
|
876
|
+
* A little helper which tries to parse a CLI value (as opposed to a flag) off
|
|
877
|
+
* of the argument array.
|
|
878
|
+
*
|
|
879
|
+
* We support a variety of different argument formats, but all of them start
|
|
880
|
+
* with `-`, so we can check the first character to test whether the next token
|
|
881
|
+
* in our array of CLI arguments is a flag name or a value.
|
|
882
|
+
*
|
|
883
|
+
* @param args an array of CLI args
|
|
884
|
+
* @returns either a string result or an Empty sentinel
|
|
885
|
+
*/
|
|
886
|
+
const parseCLIValue = (args) => {
|
|
887
|
+
// it's possible the arguments array is empty, if so, return empty
|
|
888
|
+
if (args[0] === undefined) {
|
|
889
|
+
return Empty;
|
|
890
|
+
}
|
|
891
|
+
// all we're concerned with here is that it does not start with `"-"`,
|
|
892
|
+
// which would indicate it should be parsed as a CLI flag and not a value.
|
|
893
|
+
if (!args[0].startsWith('-')) {
|
|
894
|
+
// It's not a flag, so we return the value and defer any specific parsing
|
|
895
|
+
// until later on.
|
|
896
|
+
const value = args.shift();
|
|
897
|
+
if (typeof value === 'string') {
|
|
898
|
+
return value;
|
|
775
899
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
value = args[i + 1];
|
|
779
|
-
matchingArg = arg;
|
|
780
|
-
}
|
|
781
|
-
else if (alias) {
|
|
782
|
-
if (arg.startsWith(`-${alias}=`)) {
|
|
783
|
-
[matchingArg, value] = parseEqualsArg(arg);
|
|
784
|
-
}
|
|
785
|
-
else if (arg === `-${alias}`) {
|
|
786
|
-
value = args[i + 1];
|
|
787
|
-
matchingArg = arg;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
});
|
|
791
|
-
return { value, matchingArg };
|
|
900
|
+
}
|
|
901
|
+
return Empty;
|
|
792
902
|
};
|
|
793
903
|
/**
|
|
794
904
|
* Parse an 'equals' argument, which is a CLI argument-value pair in the
|
|
@@ -824,8 +934,9 @@ const getValue = (args, configCaseName) => {
|
|
|
824
934
|
* @returns a tuple containing the arg name and the value (if present)
|
|
825
935
|
*/
|
|
826
936
|
const parseEqualsArg = (arg) => {
|
|
827
|
-
const [originalArg, ...
|
|
828
|
-
|
|
937
|
+
const [originalArg, ...splitSections] = arg.split('=');
|
|
938
|
+
const value = splitSections.join('=');
|
|
939
|
+
return [originalArg, value === '' ? Empty : value];
|
|
829
940
|
};
|
|
830
941
|
/**
|
|
831
942
|
* Small helper for getting type-system-level assurance that a `string` can be
|
|
@@ -835,11 +946,50 @@ const parseEqualsArg = (arg) => {
|
|
|
835
946
|
* @returns whether this is a `LogLevel`
|
|
836
947
|
*/
|
|
837
948
|
const isLogLevel = (maybeLogLevel) => readOnlyArrayHasStringMember(LOG_LEVELS, maybeLogLevel);
|
|
949
|
+
/**
|
|
950
|
+
* A little helper for constructing and throwing an error message with info
|
|
951
|
+
* about what went wrong
|
|
952
|
+
*
|
|
953
|
+
* @param flag the flag which encountered the error
|
|
954
|
+
* @param message a message specific to the error which was encountered
|
|
955
|
+
*/
|
|
956
|
+
const throwCLIParsingError = (flag, message) => {
|
|
957
|
+
throw new Error(`when parsing CLI flag "${flag}": ${message}`);
|
|
958
|
+
};
|
|
959
|
+
/**
|
|
960
|
+
* Throw a specific error for the situation where we ran into an issue parsing
|
|
961
|
+
* a number.
|
|
962
|
+
*
|
|
963
|
+
* @param flag the flag for which we encountered the issue
|
|
964
|
+
* @param value what we were trying to parse
|
|
965
|
+
*/
|
|
966
|
+
const throwNumberParsingError = (flag, value) => {
|
|
967
|
+
throwCLIParsingError(flag, `expected a number but received "${value}"`);
|
|
968
|
+
};
|
|
969
|
+
/**
|
|
970
|
+
* A little helper to 'dereference' a flag alias, which if you squint a little
|
|
971
|
+
* you can think of like a pointer to a full flag name. Thus 'c' is like a
|
|
972
|
+
* pointer to 'config', so here we're doing something like `*c`. Of course, this
|
|
973
|
+
* being JS, this is just a metaphor!
|
|
974
|
+
*
|
|
975
|
+
* If no 'dereference' is found for the possible alias we just return the
|
|
976
|
+
* passed string unmodified.
|
|
977
|
+
*
|
|
978
|
+
* @param maybeAlias a string which _could_ be an alias to a full flag name
|
|
979
|
+
* @returns the full aliased flag name, if found, or the passed string if not
|
|
980
|
+
*/
|
|
981
|
+
const dereferenceAlias = (maybeAlias) => {
|
|
982
|
+
const possibleDereference = CLI_FLAG_ALIASES[maybeAlias];
|
|
983
|
+
if (typeof possibleDereference === 'string') {
|
|
984
|
+
return possibleDereference;
|
|
985
|
+
}
|
|
986
|
+
return maybeAlias;
|
|
987
|
+
};
|
|
838
988
|
|
|
839
989
|
const dependencies = [
|
|
840
990
|
{
|
|
841
991
|
name: "@stencil/core",
|
|
842
|
-
version: "2.19.
|
|
992
|
+
version: "2.19.3",
|
|
843
993
|
main: "compiler/stencil.js",
|
|
844
994
|
resources: [
|
|
845
995
|
"package.json",
|
|
@@ -1586,7 +1736,16 @@ const CONFIG_PROPS_TO_ANONYMIZE = [
|
|
|
1586
1736
|
// Props we delete entirely from the config for telemetry
|
|
1587
1737
|
//
|
|
1588
1738
|
// TODO(STENCIL-469): Investigate improving anonymization for tsCompilerOptions and devServer
|
|
1589
|
-
const CONFIG_PROPS_TO_DELETE = [
|
|
1739
|
+
const CONFIG_PROPS_TO_DELETE = [
|
|
1740
|
+
'commonjs',
|
|
1741
|
+
'devServer',
|
|
1742
|
+
'env',
|
|
1743
|
+
'logger',
|
|
1744
|
+
'rollupConfig',
|
|
1745
|
+
'sys',
|
|
1746
|
+
'testing',
|
|
1747
|
+
'tsCompilerOptions',
|
|
1748
|
+
];
|
|
1590
1749
|
/**
|
|
1591
1750
|
* Anonymize the config for telemetry, replacing potentially revealing config props
|
|
1592
1751
|
* with a placeholder string if they are present (this lets us still track how frequently
|
|
@@ -1897,13 +2056,24 @@ const taskGenerate = async (coreCompiler, config) => {
|
|
|
1897
2056
|
const { prompt } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('../sys/node/prompts.js')); });
|
|
1898
2057
|
const input = config.flags.unknownArgs.find((arg) => !arg.startsWith('-')) ||
|
|
1899
2058
|
(await prompt({ name: 'tagName', type: 'text', message: 'Component tag name (dash-case):' })).tagName;
|
|
2059
|
+
if (undefined === input) {
|
|
2060
|
+
// in some shells (e.g. Windows PowerShell), hitting Ctrl+C results in a TypeError printed to the console.
|
|
2061
|
+
// explicitly return here to avoid printing the error message.
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
1900
2064
|
const { dir, base: componentName } = path.parse(input);
|
|
1901
2065
|
const tagError = validateComponentTag(componentName);
|
|
1902
2066
|
if (tagError) {
|
|
1903
2067
|
config.logger.error(tagError);
|
|
1904
2068
|
return config.sys.exit(1);
|
|
1905
2069
|
}
|
|
1906
|
-
const
|
|
2070
|
+
const filesToGenerateExt = await chooseFilesToGenerate();
|
|
2071
|
+
if (undefined === filesToGenerateExt) {
|
|
2072
|
+
// in some shells (e.g. Windows PowerShell), hitting Ctrl+C results in a TypeError printed to the console.
|
|
2073
|
+
// explicitly return here to avoid printing the error message.
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
const extensionsToGenerate = ['tsx', ...filesToGenerateExt];
|
|
1907
2077
|
const testFolder = extensionsToGenerate.some(isTest) ? 'test' : '';
|
|
1908
2078
|
const outDir = path.join(absoluteSrcDir, 'components', dir, componentName);
|
|
1909
2079
|
await config.sys.createDir(path.join(outDir, testFolder), { recursive: true });
|