@stencil/core 2.19.2 → 2.20.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.
- package/cli/config-flags.d.ts +31 -19
- package/cli/index.cjs +359 -188
- package/cli/index.js +359 -188
- package/cli/package.json +1 -1
- package/compiler/lib.dom.d.ts +130 -185
- package/compiler/lib.dom.iterable.d.ts +1 -11
- package/compiler/lib.es2015.collection.d.ts +62 -1
- package/compiler/lib.es2015.proxy.d.ts +91 -2
- package/compiler/lib.es2017.intl.d.ts +16 -1
- package/compiler/lib.es2020.intl.d.ts +30 -5
- package/compiler/lib.es2021.intl.d.ts +11 -3
- package/compiler/lib.es2022.d.ts +1 -0
- package/compiler/lib.es2022.error.d.ts +2 -2
- package/compiler/lib.es2022.sharedmemory.d.ts +27 -0
- package/compiler/lib.es5.d.ts +13 -1
- package/compiler/lib.esnext.intl.d.ts +5 -1
- package/compiler/lib.webworker.d.ts +56 -29
- package/compiler/lib.webworker.iterable.d.ts +1 -1
- package/compiler/package.json +1 -1
- package/compiler/stencil.js +22740 -22830
- package/compiler/stencil.min.js +2 -2
- package/dependencies.json +2 -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/hydrate/runner.d.ts +1 -1
- package/internal/package.json +1 -1
- package/internal/testing/package.json +1 -1
- package/mock-doc/index.cjs +6 -6
- package/mock-doc/index.js +6 -6
- package/mock-doc/package.json +1 -1
- package/package.json +16 -16
- 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 +13 -11
- package/testing/package.json +1 -1
package/cli/index.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
Stencil CLI v2.
|
|
2
|
+
Stencil CLI v2.20.0 | 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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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
|
|
568
|
-
* module. Handles leading dashes on arguments, aliases that are
|
|
569
|
-
* small number of arguments, and parsing values for non-boolean
|
|
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
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
-
*
|
|
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
|
|
594
|
-
*
|
|
595
|
-
* @param
|
|
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
|
|
598
|
-
//
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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
|
-
*
|
|
686
|
+
* Normalize a 'negative' flag name, just to do a little pre-processing before
|
|
687
|
+
* we pass it to `setCLIArg`.
|
|
624
688
|
*
|
|
625
|
-
* @param
|
|
626
|
-
* @
|
|
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
|
|
630
|
-
|
|
631
|
-
|
|
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
|
-
*
|
|
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
|
|
648
|
-
|
|
649
|
-
|
|
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
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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
|
-
|
|
670
|
-
if (
|
|
671
|
-
if (
|
|
672
|
-
|
|
673
|
-
|
|
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
|
-
|
|
677
|
-
|
|
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
|
-
|
|
703
|
-
*
|
|
704
|
-
* the
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
if (
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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
|
-
|
|
753
|
-
|
|
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, ...
|
|
804
|
-
|
|
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.
|
|
968
|
+
version: "2.20.0",
|
|
819
969
|
main: "compiler/stencil.js",
|
|
820
970
|
resources: [
|
|
821
971
|
"package.json",
|
|
@@ -877,6 +1027,7 @@ const dependencies = [
|
|
|
877
1027
|
"compiler/lib.es2022.full.d.ts",
|
|
878
1028
|
"compiler/lib.es2022.intl.d.ts",
|
|
879
1029
|
"compiler/lib.es2022.object.d.ts",
|
|
1030
|
+
"compiler/lib.es2022.sharedmemory.d.ts",
|
|
880
1031
|
"compiler/lib.es2022.string.d.ts",
|
|
881
1032
|
"compiler/lib.es5.d.ts",
|
|
882
1033
|
"compiler/lib.es6.d.ts",
|
|
@@ -927,7 +1078,7 @@ const dependencies = [
|
|
|
927
1078
|
},
|
|
928
1079
|
{
|
|
929
1080
|
name: "typescript",
|
|
930
|
-
version: "4.
|
|
1081
|
+
version: "4.8.4",
|
|
931
1082
|
main: "lib/typescript.js"
|
|
932
1083
|
}
|
|
933
1084
|
];
|
|
@@ -1562,7 +1713,16 @@ const CONFIG_PROPS_TO_ANONYMIZE = [
|
|
|
1562
1713
|
// Props we delete entirely from the config for telemetry
|
|
1563
1714
|
//
|
|
1564
1715
|
// TODO(STENCIL-469): Investigate improving anonymization for tsCompilerOptions and devServer
|
|
1565
|
-
const CONFIG_PROPS_TO_DELETE = [
|
|
1716
|
+
const CONFIG_PROPS_TO_DELETE = [
|
|
1717
|
+
'commonjs',
|
|
1718
|
+
'devServer',
|
|
1719
|
+
'env',
|
|
1720
|
+
'logger',
|
|
1721
|
+
'rollupConfig',
|
|
1722
|
+
'sys',
|
|
1723
|
+
'testing',
|
|
1724
|
+
'tsCompilerOptions',
|
|
1725
|
+
];
|
|
1566
1726
|
/**
|
|
1567
1727
|
* Anonymize the config for telemetry, replacing potentially revealing config props
|
|
1568
1728
|
* with a placeholder string if they are present (this lets us still track how frequently
|
|
@@ -1873,13 +2033,24 @@ const taskGenerate = async (coreCompiler, config) => {
|
|
|
1873
2033
|
const { prompt } = await import('../sys/node/prompts.js');
|
|
1874
2034
|
const input = config.flags.unknownArgs.find((arg) => !arg.startsWith('-')) ||
|
|
1875
2035
|
(await prompt({ name: 'tagName', type: 'text', message: 'Component tag name (dash-case):' })).tagName;
|
|
2036
|
+
if (undefined === input) {
|
|
2037
|
+
// in some shells (e.g. Windows PowerShell), hitting Ctrl+C results in a TypeError printed to the console.
|
|
2038
|
+
// explicitly return here to avoid printing the error message.
|
|
2039
|
+
return;
|
|
2040
|
+
}
|
|
1876
2041
|
const { dir, base: componentName } = path.parse(input);
|
|
1877
2042
|
const tagError = validateComponentTag(componentName);
|
|
1878
2043
|
if (tagError) {
|
|
1879
2044
|
config.logger.error(tagError);
|
|
1880
2045
|
return config.sys.exit(1);
|
|
1881
2046
|
}
|
|
1882
|
-
const
|
|
2047
|
+
const filesToGenerateExt = await chooseFilesToGenerate();
|
|
2048
|
+
if (undefined === filesToGenerateExt) {
|
|
2049
|
+
// in some shells (e.g. Windows PowerShell), hitting Ctrl+C results in a TypeError printed to the console.
|
|
2050
|
+
// explicitly return here to avoid printing the error message.
|
|
2051
|
+
return;
|
|
2052
|
+
}
|
|
2053
|
+
const extensionsToGenerate = ['tsx', ...filesToGenerateExt];
|
|
1883
2054
|
const testFolder = extensionsToGenerate.some(isTest) ? 'test' : '';
|
|
1884
2055
|
const outDir = path.join(absoluteSrcDir, 'components', dir, componentName);
|
|
1885
2056
|
await config.sys.createDir(path.join(outDir, testFolder), { recursive: true });
|