@stencil/core 2.17.1 → 2.17.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.
Files changed (40) hide show
  1. package/cli/config-flags.d.ts +12 -4
  2. package/cli/index.cjs +110 -71
  3. package/cli/index.d.ts +1 -1
  4. package/cli/index.js +110 -71
  5. package/cli/package.json +1 -1
  6. package/compiler/package.json +1 -1
  7. package/compiler/stencil.js +343 -61
  8. package/compiler/stencil.min.js +2 -2
  9. package/dependencies.json +1 -1
  10. package/dev-server/client/index.js +1 -1
  11. package/dev-server/client/package.json +1 -1
  12. package/dev-server/connector.html +2 -2
  13. package/dev-server/index.js +1 -1
  14. package/dev-server/package.json +1 -1
  15. package/dev-server/server-process.js +2 -2
  16. package/internal/app-data/package.json +1 -1
  17. package/internal/client/css-shim.js +1 -1
  18. package/internal/client/dom.js +1 -1
  19. package/internal/client/index.js +1 -1
  20. package/internal/client/package.json +1 -1
  21. package/internal/client/patch-browser.js +1 -1
  22. package/internal/client/patch-esm.js +1 -1
  23. package/internal/client/shadow-css.js +1 -1
  24. package/internal/hydrate/package.json +1 -1
  25. package/internal/package.json +1 -1
  26. package/internal/stencil-private.d.ts +12 -2
  27. package/internal/stencil-public-compiler.d.ts +1 -1
  28. package/internal/testing/package.json +1 -1
  29. package/mock-doc/index.cjs +41 -3
  30. package/mock-doc/index.d.ts +15 -0
  31. package/mock-doc/index.js +41 -3
  32. package/mock-doc/package.json +1 -1
  33. package/package.json +1 -1
  34. package/screenshot/package.json +1 -1
  35. package/sys/node/index.js +1 -1
  36. package/sys/node/package.json +1 -1
  37. package/sys/node/worker.js +1 -1
  38. package/testing/index.js +37 -22
  39. package/testing/mocks.d.ts +7 -6
  40. package/testing/package.json +1 -1
package/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil CLI v2.17.1 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI v2.17.3 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  /**
5
5
  * This sets the log level hierarchy for our terminal logger, ranging from
@@ -498,45 +498,53 @@ const CLI_ARG_ALIASES = {
498
498
  port: 'p',
499
499
  version: 'v',
500
500
  };
501
-
502
501
  /**
503
- * Parse command line arguments into a structured `ConfigFlags` object
502
+ * Helper function for initializing a `ConfigFlags` object. Provide any overrides
503
+ * for default values and off you go!
504
504
  *
505
- * @param args an array of config flags
506
- * @param sys an optional compiler system
507
- * @returns a structured ConfigFlags object
505
+ * @param init an object with any overrides for default values
506
+ * @returns a complete CLI flag object
508
507
  */
509
- const parseFlags = (args, sys) => {
508
+ const createConfigFlags = (init = {}) => {
510
509
  const flags = {
511
510
  task: null,
512
511
  args: [],
513
512
  knownArgs: [],
514
513
  unknownArgs: [],
514
+ ...init,
515
515
  };
516
+ return flags;
517
+ };
518
+
519
+ /**
520
+ * Parse command line arguments into a structured `ConfigFlags` object
521
+ *
522
+ * @param args an array of CLI flags
523
+ * @param _sys an optional compiler system
524
+ * @returns a structured ConfigFlags object
525
+ */
526
+ const parseFlags = (args, _sys) => {
527
+ // TODO(STENCIL-509): remove the _sys parameter here ^^ (for v3)
528
+ const flags = createConfigFlags();
516
529
  // cmd line has more priority over npm scripts cmd
517
530
  flags.args = Array.isArray(args) ? args.slice() : [];
518
531
  if (flags.args.length > 0 && flags.args[0] && !flags.args[0].startsWith('-')) {
519
532
  flags.task = flags.args[0];
520
533
  }
521
534
  parseArgs(flags, flags.args);
522
- if (sys && sys.name === 'node') {
523
- const envArgs = getNpmConfigEnvArgs(sys);
524
- parseArgs(flags, envArgs);
525
- envArgs.forEach((envArg) => {
526
- if (!flags.args.includes(envArg)) {
527
- flags.args.push(envArg);
528
- }
529
- });
530
- }
531
535
  if (flags.task != null) {
532
536
  const i = flags.args.indexOf(flags.task);
533
537
  if (i > -1) {
534
538
  flags.args.splice(i, 1);
535
539
  }
536
540
  }
537
- flags.unknownArgs = flags.args.filter((arg) => {
538
- return !flags.knownArgs.includes(arg);
539
- });
541
+ // to find unknown / unrecognized arguments we filter `args`, including only
542
+ // arguments whose normalized form is not found in `knownArgs`. `knownArgs`
543
+ // is populated during the call to `parseArgs` above. For arguments like
544
+ // `--foobar` the string `"--foobar"` will be added, while for more
545
+ // complicated arguments like `--bizBoz=bop` or `--bizBoz bop` just the
546
+ // string `"--bizBoz"` will be added.
547
+ flags.unknownArgs = flags.args.filter((arg) => !flags.knownArgs.includes(parseEqualsArg(arg)[0]));
540
548
  return flags;
541
549
  };
542
550
  /**
@@ -722,17 +730,17 @@ const getValue = (args, configCaseName) => {
722
730
  let matchingArg;
723
731
  args.forEach((arg, i) => {
724
732
  if (arg.startsWith(`--${dashCaseName}=`) || arg.startsWith(`--${configCaseName}=`)) {
725
- value = getEqualsValue(arg);
726
- matchingArg = arg;
733
+ // our argument was passed at the command-line in the format --argName=arg-value
734
+ [matchingArg, value] = parseEqualsArg(arg);
727
735
  }
728
736
  else if (arg === `--${dashCaseName}` || arg === `--${configCaseName}`) {
737
+ // the next value in the array is assumed to be a value for this argument
729
738
  value = args[i + 1];
730
739
  matchingArg = arg;
731
740
  }
732
741
  else if (alias) {
733
742
  if (arg.startsWith(`-${alias}=`)) {
734
- value = getEqualsValue(arg);
735
- matchingArg = arg;
743
+ [matchingArg, value] = parseEqualsArg(arg);
736
744
  }
737
745
  else if (arg === `-${alias}`) {
738
746
  value = args[i + 1];
@@ -743,13 +751,42 @@ const getValue = (args, configCaseName) => {
743
751
  return { value, matchingArg };
744
752
  };
745
753
  /**
746
- * When a parameter is set in the format `--foobar=12` at the CLI (as opposed to
747
- * `--foobar 12`) we want to get the value after the `=` sign
754
+ * Parse an 'equals' argument, which is a CLI argument-value pair in the
755
+ * format `--foobar=12` (as opposed to a space-separated format like
756
+ * `--foobar 12`).
757
+ *
758
+ * To parse this we split on the `=`, returning the first part as the argument
759
+ * name and the second part as the value. We join the value on `"="` in case
760
+ * there is another `"="` in the argument.
761
+ *
762
+ * This function is safe to call with any arg, and can therefore be used as
763
+ * an argument 'normalizer'. If CLI argument is not an 'equals' argument then
764
+ * the return value will be a tuple of the original argument and an empty
765
+ * string `""` for the value.
766
+ *
767
+ * In code terms, if you do:
748
768
  *
749
- * @param commandArgument the arg in question
750
- * @returns the value after the `=`
769
+ * ```ts
770
+ * const [arg, value] = parseEqualsArg("--myArgument")
771
+ * ```
772
+ *
773
+ * Then `arg` will be `"--myArgument"` and `value` will be `""`, whereas if
774
+ * you do:
775
+ *
776
+ *
777
+ * ```ts
778
+ * const [arg, value] = parseEqualsArg("--myArgument=myValue")
779
+ * ```
780
+ *
781
+ * Then `arg` will be `"--myArgument"` and `value` will be `"myValue"`.
782
+ *
783
+ * @param arg the arg in question
784
+ * @returns a tuple containing the arg name and the value (if present)
751
785
  */
752
- const getEqualsValue = (commandArgument) => commandArgument.split('=').slice(1).join('=');
786
+ const parseEqualsArg = (arg) => {
787
+ const [originalArg, ...value] = arg.split('=');
788
+ return [originalArg, value.join('=')];
789
+ };
753
790
  /**
754
791
  * Small helper for getting type-system-level assurance that a `string` can be
755
792
  * narrowed to a `LogLevel`
@@ -764,27 +801,11 @@ const isLogLevel = (maybeLogLevel) =>
764
801
  //
765
802
  // see microsoft/TypeScript#31018 for some discussion of this
766
803
  LOG_LEVELS.includes(maybeLogLevel);
767
- const getNpmConfigEnvArgs = (sys) => {
768
- // process.env.npm_config_argv
769
- // {"remain":["4444"],"cooked":["run","serve","--port","4444"],"original":["run","serve","--port","4444"]}
770
- let args = [];
771
- try {
772
- const npmConfigArgs = sys.getEnvironmentVar('npm_config_argv');
773
- if (npmConfigArgs) {
774
- args = JSON.parse(npmConfigArgs).original;
775
- if (args[0] === 'run') {
776
- args = args.slice(2);
777
- }
778
- }
779
- }
780
- catch (e) { }
781
- return args;
782
- };
783
804
 
784
805
  const dependencies = [
785
806
  {
786
807
  name: "@stencil/core",
787
- version: "2.17.1",
808
+ version: "2.17.3",
788
809
  main: "compiler/stencil.js",
789
810
  resources: [
790
811
  "package.json",
@@ -1280,6 +1301,15 @@ async function telemetryAction(sys, config, coreCompiler, action) {
1280
1301
  throw error;
1281
1302
  }
1282
1303
  }
1304
+ /**
1305
+ * Helper function to determine if a Stencil configuration builds an application.
1306
+ *
1307
+ * This function is a rough approximation whether an application is generated as a part of a Stencil build, based on
1308
+ * contents of the project's `stencil.config.ts` file.
1309
+ *
1310
+ * @param config the configuration used by the Stencil project
1311
+ * @returns true if we believe the project generates an application, false otherwise
1312
+ */
1283
1313
  function hasAppTarget(config) {
1284
1314
  return config.outputTargets.some((target) => target.type === WWW && (!!target.serviceWorker || (!!target.baseUrl && target.baseUrl !== '/')));
1285
1315
  }
@@ -1287,7 +1317,15 @@ function isUsingYarn(sys) {
1287
1317
  var _a;
1288
1318
  return ((_a = sys.getEnvironmentVar('npm_execpath')) === null || _a === void 0 ? void 0 : _a.includes('yarn')) || false;
1289
1319
  }
1290
- async function getActiveTargets(config) {
1320
+ /**
1321
+ * Build a list of the different types of output targets used in a Stencil configuration.
1322
+ *
1323
+ * Duplicate entries will not be returned from the list
1324
+ *
1325
+ * @param config the configuration used by the Stencil project
1326
+ * @returns a unique list of output target types found in the Stencil configuration
1327
+ */
1328
+ function getActiveTargets(config) {
1291
1329
  const result = config.outputTargets.map((t) => t.type);
1292
1330
  return Array.from(new Set(result));
1293
1331
  }
@@ -1304,7 +1342,7 @@ async function getActiveTargets(config) {
1304
1342
  const prepareData = async (coreCompiler, config, sys, duration_ms, component_count = undefined) => {
1305
1343
  const { typescript, rollup } = coreCompiler.versions || { typescript: 'unknown', rollup: 'unknown' };
1306
1344
  const { packages, packagesNoVersions } = await getInstalledPackages(sys, config);
1307
- const targets = await getActiveTargets(config);
1345
+ const targets = getActiveTargets(config);
1308
1346
  const yarn = isUsingYarn(sys);
1309
1347
  const stencil = coreCompiler.version || 'unknown';
1310
1348
  const system = `${sys.name} ${sys.version}`;
@@ -1367,14 +1405,13 @@ const CONFIG_PROPS_TO_DELETE = ['sys', 'logger', 'tsCompilerOptions', 'devServer
1367
1405
  * @returns an anonymized copy of the same config
1368
1406
  */
1369
1407
  const anonymizeConfigForTelemetry = (config) => {
1370
- var _a;
1371
1408
  const anonymizedConfig = { ...config };
1372
1409
  for (const prop of CONFIG_PROPS_TO_ANONYMIZE) {
1373
1410
  if (anonymizedConfig[prop] !== undefined) {
1374
1411
  anonymizedConfig[prop] = 'omitted';
1375
1412
  }
1376
1413
  }
1377
- anonymizedConfig.outputTargets = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).map((target) => {
1414
+ anonymizedConfig.outputTargets = config.outputTargets.map((target) => {
1378
1415
  // Anonymize the outputTargets on our configuration, taking advantage of the
1379
1416
  // optional 2nd argument to `JSON.stringify`. If anything is not a string
1380
1417
  // we retain it so that any nested properties are handled, else we check
@@ -1595,7 +1632,7 @@ function getMajorVersion(version) {
1595
1632
  return parts[0];
1596
1633
  }
1597
1634
 
1598
- const taskBuild = async (coreCompiler, config, sys) => {
1635
+ const taskBuild = async (coreCompiler, config) => {
1599
1636
  if (config.flags.watch) {
1600
1637
  // watch build
1601
1638
  await taskWatch(coreCompiler, config);
@@ -1608,10 +1645,7 @@ const taskBuild = async (coreCompiler, config, sys) => {
1608
1645
  const versionChecker = startCheckVersion(config, coreCompiler.version);
1609
1646
  const compiler = await coreCompiler.createCompiler(config);
1610
1647
  const results = await compiler.build();
1611
- // TODO(STENCIL-148) make this parameter no longer optional, remove the surrounding if statement
1612
- if (sys) {
1613
- await telemetryBuildFinishedAction(sys, config, coreCompiler, results);
1614
- }
1648
+ await telemetryBuildFinishedAction(config.sys, config, coreCompiler, results);
1615
1649
  await compiler.destroy();
1616
1650
  if (results.hasError) {
1617
1651
  exitCode = 1;
@@ -1977,10 +2011,7 @@ const taskHelp = async (flags, logger, sys) => {
1977
2011
  ${prompt} ${logger.green('stencil generate')} or ${logger.green('stencil g')}
1978
2012
 
1979
2013
  `);
1980
- // TODO(STENCIL-148) make this parameter no longer optional, remove the surrounding if statement
1981
- if (sys) {
1982
- await taskTelemetry(flags, sys, logger);
1983
- }
2014
+ await taskTelemetry(flags, sys, logger);
1984
2015
  console.log(`
1985
2016
  ${logger.bold('Examples:')}
1986
2017
 
@@ -2178,7 +2209,7 @@ const BLUE = `#3498db`;
2178
2209
  const run = async (init) => {
2179
2210
  const { args, logger, sys } = init;
2180
2211
  try {
2181
- const flags = parseFlags(args, sys);
2212
+ const flags = parseFlags(args);
2182
2213
  const task = flags.task;
2183
2214
  if (flags.debug || flags.verbose) {
2184
2215
  logger.setLevel('debug');
@@ -2190,7 +2221,7 @@ const run = async (init) => {
2190
2221
  sys.applyGlobalPatch(sys.getCurrentDirectory());
2191
2222
  }
2192
2223
  if (task === 'help' || flags.help) {
2193
- await taskHelp({ task: 'help', args }, logger, sys);
2224
+ await taskHelp(createConfigFlags({ task: 'help', args }), logger, sys);
2194
2225
  return;
2195
2226
  }
2196
2227
  startupLog(logger, task);
@@ -2216,9 +2247,7 @@ const run = async (init) => {
2216
2247
  startupLogVersion(logger, task, coreCompiler);
2217
2248
  loadedCompilerLog(sys, logger, flags, coreCompiler);
2218
2249
  if (task === 'info') {
2219
- await telemetryAction(sys, { flags: { task: 'info' }, logger }, coreCompiler, async () => {
2220
- await taskInfo(coreCompiler, sys, logger);
2221
- });
2250
+ taskInfo(coreCompiler, sys, logger);
2222
2251
  return;
2223
2252
  }
2224
2253
  const validated = await coreCompiler.loadConfig({
@@ -2251,14 +2280,27 @@ const run = async (init) => {
2251
2280
  }
2252
2281
  }
2253
2282
  };
2283
+ /**
2284
+ * Run a specified task
2285
+ * @param coreCompiler an instance of a minimal, bootstrap compiler for running the specified task
2286
+ * @param config a configuration for the Stencil project to apply to the task run
2287
+ * @param task the task to run
2288
+ * @param sys the {@link CompilerSystem} for interacting with the operating system
2289
+ * @public
2290
+ */
2254
2291
  const runTask = async (coreCompiler, config, task, sys) => {
2255
- var _a, _b;
2292
+ var _a, _b, _c;
2256
2293
  const logger = (_a = config.logger) !== null && _a !== void 0 ? _a : createLogger();
2257
- const strictConfig = { ...config, flags: (_b = { ...config.flags }) !== null && _b !== void 0 ? _b : { task }, logger };
2258
- strictConfig.outputTargets = strictConfig.outputTargets || [];
2294
+ const strictConfig = {
2295
+ ...config,
2296
+ flags: createConfigFlags((_b = config.flags) !== null && _b !== void 0 ? _b : { task }),
2297
+ logger,
2298
+ outputTargets: (_c = config.outputTargets) !== null && _c !== void 0 ? _c : [],
2299
+ sys: sys !== null && sys !== void 0 ? sys : coreCompiler.createSystem({ logger }),
2300
+ };
2259
2301
  switch (task) {
2260
2302
  case 'build':
2261
- await taskBuild(coreCompiler, strictConfig, sys);
2303
+ await taskBuild(coreCompiler, strictConfig);
2262
2304
  break;
2263
2305
  case 'docs':
2264
2306
  await taskDocs(coreCompiler, strictConfig);
@@ -2277,10 +2319,7 @@ const runTask = async (coreCompiler, config, task, sys) => {
2277
2319
  await taskServe(strictConfig);
2278
2320
  break;
2279
2321
  case 'telemetry':
2280
- // TODO(STENCIL-148) make this parameter no longer optional, remove the surrounding if statement
2281
- if (sys) {
2282
- await taskTelemetry(strictConfig.flags, sys, strictConfig.logger);
2283
- }
2322
+ await taskTelemetry(strictConfig.flags, sys, strictConfig.logger);
2284
2323
  break;
2285
2324
  case 'test':
2286
2325
  await taskTest(strictConfig);
package/cli/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core/cli",
3
- "version": "2.17.1",
3
+ "version": "2.17.3",
4
4
  "description": "Stencil CLI.",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core/compiler",
3
- "version": "2.17.1",
3
+ "version": "2.17.3",
4
4
  "description": "Stencil Compiler.",
5
5
  "main": "./stencil.js",
6
6
  "types": "./stencil.d.ts",