@stencil/core 2.8.1 → 2.11.0-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.
Files changed (72) hide show
  1. package/cli/index.cjs +239 -209
  2. package/cli/index.js +239 -209
  3. package/cli/package.json +1 -1
  4. package/compiler/lib.dom.d.ts +263 -648
  5. package/compiler/lib.dom.iterable.d.ts +1 -5
  6. package/compiler/lib.es2015.core.d.ts +2 -2
  7. package/compiler/lib.es2015.iterable.d.ts +1 -1
  8. package/compiler/lib.es2015.symbol.wellknown.d.ts +10 -10
  9. package/compiler/lib.es2018.asynciterable.d.ts +1 -1
  10. package/compiler/lib.es2020.bigint.d.ts +1 -1
  11. package/compiler/lib.es2020.intl.d.ts +6 -7
  12. package/compiler/lib.es2020.symbol.wellknown.d.ts +1 -1
  13. package/compiler/lib.es2021.d.ts +24 -0
  14. package/compiler/lib.es2021.full.d.ts +25 -0
  15. package/compiler/lib.es2021.promise.d.ts +43 -0
  16. package/compiler/lib.es2021.string.d.ts +35 -0
  17. package/compiler/lib.es2021.weakref.d.ts +75 -0
  18. package/compiler/lib.es5.d.ts +9 -9
  19. package/compiler/lib.esnext.d.ts +1 -4
  20. package/compiler/lib.esnext.promise.d.ts +26 -26
  21. package/compiler/lib.esnext.string.d.ts +18 -18
  22. package/compiler/lib.esnext.weakref.d.ts +58 -58
  23. package/compiler/lib.webworker.d.ts +98 -153
  24. package/compiler/lib.webworker.iterable.d.ts +1 -1
  25. package/compiler/package.json +1 -1
  26. package/compiler/stencil.js +1244 -456
  27. package/compiler/stencil.min.js +2 -2
  28. package/dependencies.json +6 -1
  29. package/dev-server/client/index.js +1 -1
  30. package/dev-server/client/package.json +1 -1
  31. package/dev-server/connector.html +2 -2
  32. package/dev-server/index.js +1 -1
  33. package/dev-server/package.json +1 -1
  34. package/dev-server/server-process.js +2 -2
  35. package/internal/app-data/package.json +1 -1
  36. package/internal/client/css-shim.js +1 -1
  37. package/internal/client/dom.js +1 -1
  38. package/internal/client/index.js +119 -102
  39. package/internal/client/package.json +1 -1
  40. package/internal/client/patch-browser.js +1 -1
  41. package/internal/client/patch-esm.js +1 -1
  42. package/internal/client/shadow-css.js +9 -10
  43. package/internal/hydrate/index.js +44 -40
  44. package/internal/hydrate/package.json +1 -1
  45. package/internal/hydrate/shadow-css.js +59 -62
  46. package/internal/index.js +1 -0
  47. package/internal/package.json +1 -1
  48. package/internal/stencil-private.d.ts +125 -5
  49. package/internal/stencil-public-compiler.d.ts +15 -2
  50. package/internal/testing/index.js +54 -47
  51. package/internal/testing/package.json +1 -1
  52. package/internal/testing/shadow-css.js +54 -57
  53. package/mock-doc/index.cjs +4 -1
  54. package/mock-doc/index.d.ts +7 -6
  55. package/mock-doc/index.js +4 -1
  56. package/mock-doc/package.json +1 -1
  57. package/package.json +16 -6
  58. package/readme.md +2 -2
  59. package/screenshot/index.js +1 -1
  60. package/screenshot/package.json +1 -1
  61. package/sys/node/index.js +4435 -425
  62. package/sys/node/package.json +1 -1
  63. package/sys/node/worker.js +1 -1
  64. package/testing/index.js +23 -18
  65. package/testing/mocks.d.ts +1 -5
  66. package/testing/package.json +1 -1
  67. package/testing/testing-sys.d.ts +6 -1
  68. package/bin/cli.ts +0 -20
  69. package/screenshot/index.js.map +0 -1
  70. package/sys/deno/index.js +0 -1791
  71. package/sys/deno/node-compat.js +0 -2654
  72. package/sys/deno/worker.js +0 -44
package/cli/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil CLI (CommonJS) v2.8.1 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI (CommonJS) v2.11.0-0 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  'use strict';
5
5
 
@@ -230,6 +230,11 @@ const pathComponents = (path, rootLength) => {
230
230
  return [root, ...rest];
231
231
  };
232
232
 
233
+ /**
234
+ * Validates that a component tag meets required naming conventions to be used for a web component
235
+ * @param tag the tag to validate
236
+ * @returns an error message if the tag has an invalid name, undefined if the tag name passes all checks
237
+ */
233
238
  const validateComponentTag = (tag) => {
234
239
  if (tag !== tag.trim()) {
235
240
  return `Tag can not contain white spaces`;
@@ -485,7 +490,7 @@ const getNpmConfigEnvArgs = (sys) => {
485
490
  const dependencies = [
486
491
  {
487
492
  name: "@stencil/core",
488
- version: "2.8.1",
493
+ version: "2.11.0-0",
489
494
  main: "compiler/stencil.js",
490
495
  resources: [
491
496
  "package.json",
@@ -533,6 +538,11 @@ const dependencies = [
533
538
  "compiler/lib.es2020.sharedmemory.d.ts",
534
539
  "compiler/lib.es2020.string.d.ts",
535
540
  "compiler/lib.es2020.symbol.wellknown.d.ts",
541
+ "compiler/lib.es2021.d.ts",
542
+ "compiler/lib.es2021.full.d.ts",
543
+ "compiler/lib.es2021.promise.d.ts",
544
+ "compiler/lib.es2021.string.d.ts",
545
+ "compiler/lib.es2021.weakref.d.ts",
536
546
  "compiler/lib.es5.d.ts",
537
547
  "compiler/lib.es6.d.ts",
538
548
  "compiler/lib.esnext.d.ts",
@@ -582,7 +592,7 @@ const dependencies = [
582
592
  },
583
593
  {
584
594
  name: "typescript",
585
- version: "4.2.3",
595
+ version: "4.3.5",
586
596
  main: "lib/typescript.js"
587
597
  }
588
598
  ];
@@ -795,82 +805,6 @@ const taskWatch = async (coreCompiler, config) => {
795
805
  }
796
806
  };
797
807
 
798
- class StencilCLIConfig {
799
- constructor(options) {
800
- this._args = (options === null || options === void 0 ? void 0 : options.args) || [];
801
- this._logger = options === null || options === void 0 ? void 0 : options.logger;
802
- this._sys = options === null || options === void 0 ? void 0 : options.sys;
803
- this._flags = (options === null || options === void 0 ? void 0 : options.flags) || undefined;
804
- this._validatedConfig = (options === null || options === void 0 ? void 0 : options.validatedConfig) || undefined;
805
- }
806
- static getInstance(options) {
807
- if (!StencilCLIConfig.instance) {
808
- StencilCLIConfig.instance = new StencilCLIConfig(options);
809
- }
810
- return StencilCLIConfig.instance;
811
- }
812
- resetInstance() {
813
- delete StencilCLIConfig.instance;
814
- }
815
- get logger() {
816
- return this._logger;
817
- }
818
- set logger(logger) {
819
- this._logger = logger;
820
- }
821
- get sys() {
822
- return this._sys;
823
- }
824
- set sys(sys) {
825
- this._sys = sys;
826
- }
827
- get args() {
828
- return this._args;
829
- }
830
- set args(args) {
831
- this._args = args;
832
- }
833
- get task() {
834
- return this._task;
835
- }
836
- set task(task) {
837
- this._task = task;
838
- }
839
- get flags() {
840
- return this._flags;
841
- }
842
- set flags(flags) {
843
- this._flags = flags;
844
- }
845
- get coreCompiler() {
846
- return this._coreCompiler;
847
- }
848
- set coreCompiler(coreCompiler) {
849
- this._coreCompiler = coreCompiler;
850
- }
851
- get validatedConfig() {
852
- return this._validatedConfig;
853
- }
854
- set validatedConfig(validatedConfig) {
855
- this._validatedConfig = validatedConfig;
856
- }
857
- }
858
- function initializeStencilCLIConfig(options) {
859
- return StencilCLIConfig.getInstance(options);
860
- }
861
- function getStencilCLIConfig() {
862
- return StencilCLIConfig.getInstance();
863
- }
864
- function getCompilerSystem() {
865
- return getStencilCLIConfig().sys;
866
- }
867
- function getLogger() {
868
- return getStencilCLIConfig().logger;
869
- }
870
- function getCoreCompiler() {
871
- return getStencilCLIConfig().coreCompiler;
872
- }
873
-
874
808
  const tryFn = async (fn, ...args) => {
875
809
  try {
876
810
  return await fn(...args);
@@ -880,12 +814,12 @@ const tryFn = async (fn, ...args) => {
880
814
  }
881
815
  return null;
882
816
  };
883
- const isInteractive = (object) => {
884
- var _a, _b;
817
+ const isInteractive = (sys, config, object) => {
818
+ var _a;
885
819
  const terminalInfo = object ||
886
820
  Object.freeze({
887
- tty: getCompilerSystem().isTTY() ? true : false,
888
- ci: ['CI', 'BUILD_ID', 'BUILD_NUMBER', 'BITBUCKET_COMMIT', 'CODEBUILD_BUILD_ARN'].filter((v) => !!getCompilerSystem().getEnvironmentVar(v)).length > 0 || !!((_b = (_a = getStencilCLIConfig()) === null || _a === void 0 ? void 0 : _a.flags) === null || _b === void 0 ? void 0 : _b.ci),
821
+ tty: sys.isTTY() ? true : false,
822
+ ci: ['CI', 'BUILD_ID', 'BUILD_NUMBER', 'BITBUCKET_COMMIT', 'CODEBUILD_BUILD_ARN'].filter((v) => !!sys.getEnvironmentVar(v)).length > 0 || !!((_a = config.flags) === null || _a === void 0 ? void 0 : _a.ci),
889
823
  });
890
824
  return terminalInfo.tty && !terminalInfo.ci;
891
825
  };
@@ -900,93 +834,134 @@ function uuidv4() {
900
834
  }
901
835
  /**
902
836
  * Reads and parses a JSON file from the given `path`
837
+ * @param sys The system where the command is invoked
903
838
  * @param path the path on the file system to read and parse
904
839
  * @returns the parsed JSON
905
840
  */
906
- async function readJson(path) {
907
- const file = await getCompilerSystem().readFile(path);
841
+ async function readJson(sys, path) {
842
+ const file = await sys.readFile(path);
908
843
  return !!file && JSON.parse(file);
909
844
  }
910
- function hasDebug() {
911
- return getStencilCLIConfig().flags.debug;
845
+ /**
846
+ * Does the command have the debug flag?
847
+ * @param config The config passed into the Stencil command
848
+ * @returns true if --debug has been passed, otherwise false
849
+ */
850
+ function hasDebug(config) {
851
+ return config.flags.debug;
912
852
  }
913
- function hasVerbose() {
914
- return getStencilCLIConfig().flags.verbose && hasDebug();
853
+ /**
854
+ * Does the command have the verbose and debug flags?
855
+ * @param config The config passed into the Stencil command
856
+ * @returns true if both --debug and --verbose have been passed, otherwise false
857
+ */
858
+ function hasVerbose(config) {
859
+ return config.flags.verbose && hasDebug(config);
915
860
  }
916
861
 
917
862
  /**
918
863
  * Used to determine if tracking should occur.
864
+ * @param config The config passed into the Stencil command
865
+ * @param sys The system where the command is invoked
919
866
  * @param ci whether or not the process is running in a Continuous Integration (CI) environment
920
867
  * @returns true if telemetry should be sent, false otherwise
921
868
  */
922
- async function shouldTrack(ci) {
923
- return !ci && isInteractive() && (await checkTelemetry());
869
+ async function shouldTrack(config, sys, ci) {
870
+ return !ci && isInteractive(sys, config) && (await checkTelemetry(sys));
924
871
  }
925
872
 
926
873
  const isTest$1 = () => process.env.JEST_WORKER_ID !== undefined;
927
- const defaultConfig = () => getCompilerSystem().resolvePath(`${getCompilerSystem().homeDir()}/.ionic/${isTest$1() ? 'tmp-config.json' : 'config.json'}`);
928
- const defaultConfigDirectory = () => getCompilerSystem().resolvePath(`${getCompilerSystem().homeDir()}/.ionic`);
874
+ const defaultConfig = (sys) => sys.resolvePath(`${sys.homeDir()}/.ionic/${isTest$1() ? 'tmp-config.json' : 'config.json'}`);
875
+ const defaultConfigDirectory = (sys) => sys.resolvePath(`${sys.homeDir()}/.ionic`);
929
876
  /**
930
- * Reads an Ionic configuration file from disk, parses it, and performs any necessary corrections to it if ceratin
877
+ * Reads an Ionic configuration file from disk, parses it, and performs any necessary corrections to it if certain
931
878
  * values are deemed to be malformed
879
+ * @param sys The system where the command is invoked
932
880
  * @returns the config read from disk that has been potentially been updated
933
881
  */
934
- async function readConfig() {
935
- let config = await readJson(defaultConfig());
882
+ async function readConfig(sys) {
883
+ let config = await readJson(sys, defaultConfig(sys));
936
884
  if (!config) {
937
885
  config = {
938
886
  'tokens.telemetry': uuidv4(),
939
887
  'telemetry.stencil': true,
940
888
  };
941
- await writeConfig(config);
889
+ await writeConfig(sys, config);
942
890
  }
943
891
  else if (!UUID_REGEX.test(config['tokens.telemetry'])) {
944
892
  const newUuid = uuidv4();
945
- await writeConfig({ ...config, 'tokens.telemetry': newUuid });
893
+ await writeConfig(sys, { ...config, 'tokens.telemetry': newUuid });
946
894
  config['tokens.telemetry'] = newUuid;
947
895
  }
948
896
  return config;
949
897
  }
950
- async function writeConfig(config) {
898
+ /**
899
+ * Writes an Ionic configuration file to disk.
900
+ * @param sys The system where the command is invoked
901
+ * @param config The config passed into the Stencil command
902
+ * @returns boolean If the command was successful
903
+ */
904
+ async function writeConfig(sys, config) {
951
905
  let result = false;
952
906
  try {
953
- await getCompilerSystem().createDir(defaultConfigDirectory(), { recursive: true });
954
- await getCompilerSystem().writeFile(defaultConfig(), JSON.stringify(config, null, 2));
907
+ await sys.createDir(defaultConfigDirectory(sys), { recursive: true });
908
+ await sys.writeFile(defaultConfig(sys), JSON.stringify(config, null, 2));
955
909
  result = true;
956
910
  }
957
911
  catch (error) {
958
- console.error(`Stencil Telemetry: couldn't write configuration file to ${defaultConfig()} - ${error}.`);
912
+ console.error(`Stencil Telemetry: couldn't write configuration file to ${defaultConfig(sys)} - ${error}.`);
959
913
  }
960
914
  return result;
961
915
  }
962
- async function updateConfig(newOptions) {
963
- const config = await readConfig();
964
- return await writeConfig(Object.assign(config, newOptions));
916
+ /**
917
+ * Update a subset of the Ionic config.
918
+ * @param sys The system where the command is invoked
919
+ * @param newOptions The new options to save
920
+ * @returns boolean If the command was successful
921
+ */
922
+ async function updateConfig(sys, newOptions) {
923
+ const config = await readConfig(sys);
924
+ return await writeConfig(sys, Object.assign(config, newOptions));
965
925
  }
966
926
 
927
+ const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
928
+ const DOCS_CUSTOM = 'docs-custom';
929
+ const DOCS_JSON = `docs-json`;
930
+ const DOCS_README = `docs-readme`;
931
+ const DOCS_VSCODE = `docs-vscode`;
932
+ const WWW = `www`;
933
+
967
934
  /**
968
935
  * Used to within taskBuild to provide the component_count property.
936
+ *
937
+ * @param sys The system where the command is invoked
938
+ * @param config The config passed into the Stencil command
939
+ * @param logger The tool used to do logging
940
+ * @param coreCompiler The compiler used to do builds
969
941
  * @param result The results of a compiler build.
970
942
  */
971
- async function telemetryBuildFinishedAction(result) {
972
- const { flags, logger } = getStencilCLIConfig();
973
- const tracking = await shouldTrack(flags.ci);
943
+ async function telemetryBuildFinishedAction(sys, config, logger, coreCompiler, result) {
944
+ const tracking = await shouldTrack(config, sys, config.flags.ci);
974
945
  if (!tracking) {
975
946
  return;
976
947
  }
977
948
  const component_count = Object.keys(result.componentGraph).length;
978
- const data = await prepareData(result.duration, component_count);
979
- await sendMetric('stencil_cli_command', data);
949
+ const data = await prepareData(coreCompiler, config, sys, result.duration, component_count);
950
+ await sendMetric(sys, config, 'stencil_cli_command', data);
980
951
  logger.debug(`${logger.blue('Telemetry')}: ${logger.gray(JSON.stringify(data))}`);
981
952
  }
982
953
  /**
983
954
  * A function to wrap a compiler task function around. Will send telemetry if, and only if, the machine allows.
955
+ * @param sys The system where the command is invoked
956
+ * @param config The config passed into the Stencil command
957
+ * @param logger The tool used to do logging
958
+ * @param coreCompiler The compiler used to do builds
984
959
  * @param action A Promise-based function to call in order to get the duration of any given command.
985
960
  * @returns void
986
961
  */
987
- async function telemetryAction(action) {
988
- const { flags, logger } = getStencilCLIConfig();
989
- const tracking = await shouldTrack(!!flags.ci);
962
+ async function telemetryAction(sys, config, logger, coreCompiler, action) {
963
+ var _a;
964
+ const tracking = await shouldTrack(config, sys, !!((_a = config === null || config === void 0 ? void 0 : config.flags) === null || _a === void 0 ? void 0 : _a.ci));
990
965
  let duration = undefined;
991
966
  let error;
992
967
  if (action) {
@@ -1001,51 +976,51 @@ async function telemetryAction(action) {
1001
976
  duration = end.getTime() - start.getTime();
1002
977
  }
1003
978
  // We'll get componentCount details inside the taskBuild, so let's not send two messages.
1004
- if (!tracking || (flags.task == 'build' && !flags.args.includes('--watch'))) {
979
+ if (!tracking || (config.flags.task == 'build' && !config.flags.args.includes('--watch'))) {
1005
980
  return;
1006
981
  }
1007
- const data = await prepareData(duration);
1008
- await sendMetric('stencil_cli_command', data);
982
+ const data = await prepareData(coreCompiler, config, sys, duration);
983
+ await sendMetric(sys, config, 'stencil_cli_command', data);
1009
984
  logger.debug(`${logger.blue('Telemetry')}: ${logger.gray(JSON.stringify(data))}`);
1010
985
  if (error) {
1011
986
  throw error;
1012
987
  }
1013
988
  }
1014
- function hasAppTarget() {
1015
- return getStencilCLIConfig().validatedConfig.config.outputTargets.some((target) => target.type === 'www' && (!!target.serviceWorker || (!!target.baseUrl && target.baseUrl !== '/')));
989
+ function hasAppTarget(config) {
990
+ return config.outputTargets.some((target) => target.type === WWW && (!!target.serviceWorker || (!!target.baseUrl && target.baseUrl !== '/')));
1016
991
  }
1017
- function isUsingYarn() {
992
+ function isUsingYarn(sys) {
1018
993
  var _a;
1019
- return ((_a = getCompilerSystem().getEnvironmentVar('npm_execpath')) === null || _a === void 0 ? void 0 : _a.includes('yarn')) || false;
994
+ return ((_a = sys.getEnvironmentVar('npm_execpath')) === null || _a === void 0 ? void 0 : _a.includes('yarn')) || false;
1020
995
  }
1021
- async function getActiveTargets() {
1022
- const result = getStencilCLIConfig().validatedConfig.config.outputTargets.map((t) => t.type);
996
+ async function getActiveTargets(config) {
997
+ const result = config.outputTargets.map((t) => t.type);
1023
998
  return Array.from(new Set(result));
1024
999
  }
1025
- const prepareData = async (duration_ms, component_count = undefined) => {
1026
- var _a, _b, _c;
1027
- const { flags, sys } = getStencilCLIConfig();
1028
- const { typescript, rollup } = ((_a = getCoreCompiler()) === null || _a === void 0 ? void 0 : _a.versions) || { typescript: 'unknown', rollup: 'unknown' };
1029
- const packages = await getInstalledPackages();
1030
- const targets = await getActiveTargets();
1031
- const yarn = isUsingYarn();
1032
- const stencil = ((_b = getCoreCompiler()) === null || _b === void 0 ? void 0 : _b.version) || 'unknown';
1000
+ const prepareData = async (coreCompiler, config, sys, duration_ms, component_count = undefined) => {
1001
+ const { typescript, rollup } = coreCompiler.versions || { typescript: 'unknown', rollup: 'unknown' };
1002
+ const { packages, packagesNoVersions } = await getInstalledPackages(sys, config);
1003
+ const targets = await getActiveTargets(config);
1004
+ const yarn = isUsingYarn(sys);
1005
+ const stencil = coreCompiler.version || 'unknown';
1033
1006
  const system = `${sys.name} ${sys.version}`;
1034
1007
  const os_name = sys.details.platform;
1035
1008
  const os_version = sys.details.release;
1036
1009
  const cpu_model = sys.details.cpuModel;
1037
- const build = ((_c = getCoreCompiler()) === null || _c === void 0 ? void 0 : _c.buildId) || 'unknown';
1038
- const has_app_pwa_config = hasAppTarget();
1010
+ const build = coreCompiler.buildId || 'unknown';
1011
+ const has_app_pwa_config = hasAppTarget(config);
1039
1012
  return {
1040
1013
  yarn,
1041
1014
  duration_ms,
1042
1015
  component_count,
1043
1016
  targets,
1044
1017
  packages,
1045
- arguments: flags.args,
1046
- task: flags.task,
1018
+ packages_no_versions: packagesNoVersions,
1019
+ arguments: config.flags.args,
1020
+ task: config.flags.task,
1047
1021
  stencil,
1048
1022
  system,
1023
+ system_major: getMajorVersion(system),
1049
1024
  os_name,
1050
1025
  os_version,
1051
1026
  cpu_model,
@@ -1056,41 +1031,92 @@ const prepareData = async (duration_ms, component_count = undefined) => {
1056
1031
  };
1057
1032
  };
1058
1033
  /**
1059
- * Reads package-lock.json and package.json files in order to cross references the dependencies and devDependencies properties. Pull the current installed version of each package under the @stencil, @ionic, and @capacitor scopes.
1034
+ * Reads package-lock.json, yarn.lock, and package.json files in order to cross reference
1035
+ * the dependencies and devDependencies properties. Pulls up the current installed version
1036
+ * of each package under the @stencil, @ionic, and @capacitor scopes.
1060
1037
  * @returns string[]
1061
1038
  */
1062
- async function getInstalledPackages() {
1039
+ async function getInstalledPackages(sys, config) {
1040
+ let packages = [];
1041
+ let packagesNoVersions = [];
1042
+ const yarn = isUsingYarn(sys);
1063
1043
  try {
1064
1044
  // Read package.json and package-lock.json
1065
- const appRootDir = getCompilerSystem().getCurrentDirectory();
1066
- const packageJson = await tryFn(readJson, getCompilerSystem().resolvePath(appRootDir + '/package.json'));
1067
- const packageLockJson = await tryFn(readJson, getCompilerSystem().resolvePath(appRootDir + '/package-lock.json'));
1045
+ const appRootDir = sys.getCurrentDirectory();
1046
+ const packageJson = await tryFn(readJson, sys, sys.resolvePath(appRootDir + '/package.json'));
1068
1047
  // They don't have a package.json for some reason? Eject button.
1069
1048
  if (!packageJson) {
1070
- return [];
1049
+ return { packages, packagesNoVersions };
1071
1050
  }
1072
- const packages = Object.entries({
1051
+ const rawPackages = Object.entries({
1073
1052
  ...packageJson.devDependencies,
1074
1053
  ...packageJson.dependencies,
1075
1054
  });
1076
1055
  // Collect packages only in the stencil, ionic, or capacitor org's:
1077
1056
  // https://www.npmjs.com/org/stencil
1078
- const ionicPackages = packages.filter(([k]) => k.startsWith('@stencil/') || k.startsWith('@ionic/') || k.startsWith('@capacitor/'));
1079
- const versions = packageLockJson
1080
- ? ionicPackages.map(([k, v]) => { var _a, _b, _c, _d; return `${k}@${(_d = (_b = (_a = packageLockJson === null || packageLockJson === void 0 ? void 0 : packageLockJson.dependencies[k]) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : (_c = packageLockJson === null || packageLockJson === void 0 ? void 0 : packageLockJson.devDependencies[k]) === null || _c === void 0 ? void 0 : _c.version) !== null && _d !== void 0 ? _d : v}`; })
1081
- : ionicPackages.map(([k, v]) => `${k}@${v}`);
1082
- return versions;
1057
+ const ionicPackages = rawPackages.filter(([k]) => k.startsWith('@stencil/') || k.startsWith('@ionic/') || k.startsWith('@capacitor/'));
1058
+ try {
1059
+ packages = yarn ? await yarnPackages(sys, ionicPackages) : await npmPackages(sys, ionicPackages);
1060
+ }
1061
+ catch (e) {
1062
+ packages = ionicPackages.map(([k, v]) => `${k}@${v.replace('^', '')}`);
1063
+ }
1064
+ packagesNoVersions = ionicPackages.map(([k]) => `${k}`);
1065
+ return { packages, packagesNoVersions };
1083
1066
  }
1084
1067
  catch (err) {
1085
- hasDebug() && console.error(err);
1086
- return [];
1068
+ hasDebug(config) && console.error(err);
1069
+ return { packages, packagesNoVersions };
1087
1070
  }
1088
1071
  }
1072
+ /**
1073
+ * Visits the npm lock file to find the exact versions that are installed
1074
+ * @param sys The system where the command is invoked
1075
+ * @param ionicPackages a list of the found packages matching `@stencil`, `@capacitor`, or `@ionic` from the package.json file.
1076
+ * @returns an array of strings of all the packages and their versions.
1077
+ */
1078
+ async function npmPackages(sys, ionicPackages) {
1079
+ const appRootDir = sys.getCurrentDirectory();
1080
+ const packageLockJson = await tryFn(readJson, sys, sys.resolvePath(appRootDir + '/package-lock.json'));
1081
+ return ionicPackages.map(([k, v]) => {
1082
+ var _a, _b, _c, _d;
1083
+ let version = (_d = (_b = (_a = packageLockJson === null || packageLockJson === void 0 ? void 0 : packageLockJson.dependencies[k]) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : (_c = packageLockJson === null || packageLockJson === void 0 ? void 0 : packageLockJson.devDependencies[k]) === null || _c === void 0 ? void 0 : _c.version) !== null && _d !== void 0 ? _d : v;
1084
+ version = version.includes('file:') ? sanitizeDeclaredVersion(v) : version;
1085
+ return `${k}@${version}`;
1086
+ });
1087
+ }
1088
+ /**
1089
+ * Visits the yarn lock file to find the exact versions that are installed
1090
+ * @param sys The system where the command is invoked
1091
+ * @param ionicPackages a list of the found packages matching `@stencil`, `@capacitor`, or `@ionic` from the package.json file.
1092
+ * @returns an array of strings of all the packages and their versions.
1093
+ */
1094
+ async function yarnPackages(sys, ionicPackages) {
1095
+ const appRootDir = sys.getCurrentDirectory();
1096
+ const yarnLock = sys.readFileSync(sys.resolvePath(appRootDir + '/yarn.lock'));
1097
+ const yarnLockYml = sys.parseYarnLockFile(yarnLock);
1098
+ return ionicPackages.map(([k, v]) => {
1099
+ var _a;
1100
+ const identifiedVersion = `${k}@${v}`;
1101
+ let version = (_a = yarnLockYml.object[identifiedVersion]) === null || _a === void 0 ? void 0 : _a.version;
1102
+ version = version.includes('undefined') ? sanitizeDeclaredVersion(identifiedVersion) : version;
1103
+ return `${k}@${version}`;
1104
+ });
1105
+ }
1106
+ /**
1107
+ * This function is used for fallback purposes, where an npm or yarn lock file doesn't exist in the consumers directory.
1108
+ * This will strip away '*', '^' and '~' from the declared package versions in a package.json.
1109
+ * @param version the raw semver pattern identifier version string
1110
+ * @returns a cleaned up representation without any qualifiers
1111
+ */
1112
+ function sanitizeDeclaredVersion(version) {
1113
+ return version.replace(/[*^~]/g, '');
1114
+ }
1089
1115
  /**
1090
1116
  * If telemetry is enabled, send a metric via IPC to a forked process for uploading.
1091
1117
  */
1092
- async function sendMetric(name, value) {
1093
- const session_id = await getTelemetryToken();
1118
+ async function sendMetric(sys, config, name, value) {
1119
+ const session_id = await getTelemetryToken(sys);
1094
1120
  const message = {
1095
1121
  name,
1096
1122
  timestamp: new Date().toISOString(),
@@ -1098,25 +1124,28 @@ async function sendMetric(name, value) {
1098
1124
  value,
1099
1125
  session_id,
1100
1126
  };
1101
- await sendTelemetry({ type: 'telemetry', message });
1127
+ await sendTelemetry(sys, config, { type: 'telemetry', message });
1102
1128
  }
1103
1129
  /**
1104
1130
  * Used to read the config file's tokens.telemetry property.
1131
+ * @param sys The system where the command is invoked
1105
1132
  * @returns string
1106
1133
  */
1107
- async function getTelemetryToken() {
1108
- const config = await readConfig();
1134
+ async function getTelemetryToken(sys) {
1135
+ const config = await readConfig(sys);
1109
1136
  if (config['tokens.telemetry'] === undefined) {
1110
1137
  config['tokens.telemetry'] = uuidv4();
1111
- await writeConfig(config);
1138
+ await writeConfig(sys, config);
1112
1139
  }
1113
1140
  return config['tokens.telemetry'];
1114
1141
  }
1115
1142
  /**
1116
1143
  * Issues a request to the telemetry server.
1144
+ * @param sys The system where the command is invoked
1145
+ * @param config The config passed into the Stencil command
1117
1146
  * @param data Data to be tracked
1118
1147
  */
1119
- async function sendTelemetry(data) {
1148
+ async function sendTelemetry(sys, config, data) {
1120
1149
  try {
1121
1150
  const now = new Date().toISOString();
1122
1151
  const body = {
@@ -1124,52 +1153,64 @@ async function sendTelemetry(data) {
1124
1153
  sent_at: now,
1125
1154
  };
1126
1155
  // This request is only made if telemetry is on.
1127
- const response = await getCompilerSystem().fetch('https://api.ionicjs.com/events/metrics', {
1156
+ const response = await sys.fetch('https://api.ionicjs.com/events/metrics', {
1128
1157
  method: 'POST',
1129
1158
  headers: {
1130
1159
  'Content-Type': 'application/json',
1131
1160
  },
1132
1161
  body: JSON.stringify(body),
1133
1162
  });
1134
- hasVerbose() &&
1163
+ hasVerbose(config) &&
1135
1164
  console.debug('\nSent %O metric to events service (status: %O)', data.message.name, response.status, '\n');
1136
1165
  if (response.status !== 204) {
1137
- hasVerbose() &&
1166
+ hasVerbose(config) &&
1138
1167
  console.debug('\nBad response from events service. Request body: %O', response.body.toString(), '\n');
1139
1168
  }
1140
1169
  }
1141
1170
  catch (e) {
1142
- hasVerbose() && console.debug('Telemetry request failed:', e);
1171
+ hasVerbose(config) && console.debug('Telemetry request failed:', e);
1143
1172
  }
1144
1173
  }
1145
1174
  /**
1146
1175
  * Checks if telemetry is enabled on this machine
1176
+ * @param sys The system where the command is invoked
1147
1177
  * @returns true if telemetry is enabled, false otherwise
1148
1178
  */
1149
- async function checkTelemetry() {
1150
- const config = await readConfig();
1179
+ async function checkTelemetry(sys) {
1180
+ const config = await readConfig(sys);
1151
1181
  if (config['telemetry.stencil'] === undefined) {
1152
1182
  config['telemetry.stencil'] = true;
1153
- await writeConfig(config);
1183
+ await writeConfig(sys, config);
1154
1184
  }
1155
1185
  return config['telemetry.stencil'];
1156
1186
  }
1157
1187
  /**
1158
1188
  * Writes to the config file, enabling telemetry for this machine.
1189
+ * @param sys The system where the command is invoked
1159
1190
  * @returns true if writing the file was successful, false otherwise
1160
1191
  */
1161
- async function enableTelemetry() {
1162
- return await updateConfig({ 'telemetry.stencil': true });
1192
+ async function enableTelemetry(sys) {
1193
+ return await updateConfig(sys, { 'telemetry.stencil': true });
1163
1194
  }
1164
1195
  /**
1165
1196
  * Writes to the config file, disabling telemetry for this machine.
1197
+ * @param sys The system where the command is invoked
1166
1198
  * @returns true if writing the file was successful, false otherwise
1167
1199
  */
1168
- async function disableTelemetry() {
1169
- return await updateConfig({ 'telemetry.stencil': false });
1200
+ async function disableTelemetry(sys) {
1201
+ return await updateConfig(sys, { 'telemetry.stencil': false });
1202
+ }
1203
+ /**
1204
+ * Takes in a semver string in order to return the major version.
1205
+ * @param version The fully qualified semver version
1206
+ * @returns a string of the major version
1207
+ */
1208
+ function getMajorVersion(version) {
1209
+ const parts = version.split('.');
1210
+ return parts[0];
1170
1211
  }
1171
1212
 
1172
- const taskBuild = async (coreCompiler, config) => {
1213
+ const taskBuild = async (coreCompiler, config, sys) => {
1173
1214
  if (config.flags.watch) {
1174
1215
  // watch build
1175
1216
  await taskWatch(coreCompiler, config);
@@ -1182,7 +1223,10 @@ const taskBuild = async (coreCompiler, config) => {
1182
1223
  const versionChecker = startCheckVersion(config, coreCompiler.version);
1183
1224
  const compiler = await coreCompiler.createCompiler(config);
1184
1225
  const results = await compiler.build();
1185
- await telemetryBuildFinishedAction(results);
1226
+ // TODO(STENCIL-148) make this parameter no longer optional, remove the surrounding if statement
1227
+ if (sys) {
1228
+ await telemetryBuildFinishedAction(sys, config, config.logger, coreCompiler, results);
1229
+ }
1186
1230
  await compiler.destroy();
1187
1231
  if (results.hasError) {
1188
1232
  exitCode = 1;
@@ -1205,12 +1249,6 @@ const taskBuild = async (coreCompiler, config) => {
1205
1249
  }
1206
1250
  };
1207
1251
 
1208
- const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
1209
- const DOCS_CUSTOM = 'docs-custom';
1210
- const DOCS_JSON = `docs-json`;
1211
- const DOCS_README = `docs-readme`;
1212
- const DOCS_VSCODE = `docs-vscode`;
1213
-
1214
1252
  const taskDocs = async (coreCompiler, config) => {
1215
1253
  config.devServer = null;
1216
1254
  config.outputTargets = config.outputTargets.filter(isOutputTargetDocs);
@@ -1221,9 +1259,7 @@ const taskDocs = async (coreCompiler, config) => {
1221
1259
  await compiler.destroy();
1222
1260
  };
1223
1261
 
1224
- const IS_DENO_ENV = typeof Deno !== 'undefined';
1225
- const IS_NODE_ENV = !IS_DENO_ENV &&
1226
- typeof global !== 'undefined' &&
1262
+ const IS_NODE_ENV = typeof global !== 'undefined' &&
1227
1263
  typeof require === 'function' &&
1228
1264
  !!global.process &&
1229
1265
  typeof __filename === 'string' &&
@@ -1395,25 +1431,24 @@ describe('${name}', () => {
1395
1431
  */
1396
1432
  const toPascalCase = (str) => str.split('-').reduce((res, part) => res + part[0].toUpperCase() + part.substr(1), '');
1397
1433
 
1398
- const taskTelemetry = async () => {
1399
- const logger = getLogger();
1400
- const prompt = logger.dim(getCompilerSystem().details.platform === 'windows' ? '>' : '$');
1401
- const isEnabling = getStencilCLIConfig().flags.args.includes('on');
1402
- const isDisabling = getStencilCLIConfig().flags.args.includes('off');
1434
+ const taskTelemetry = async (config, sys, logger) => {
1435
+ const prompt = logger.dim(sys.details.platform === 'windows' ? '>' : '$');
1436
+ const isEnabling = config.flags.args.includes('on');
1437
+ const isDisabling = config.flags.args.includes('off');
1403
1438
  const INFORMATION = `Opt in or our of telemetry. Information about the data we collect is available on our website: ${logger.bold('https://stenciljs.com/telemetry')}`;
1404
1439
  const THANK_YOU = `Thank you for helping to make Stencil better! 💖`;
1405
1440
  const ENABLED_MESSAGE = `${logger.green('Enabled')}. ${THANK_YOU}\n\n`;
1406
1441
  const DISABLED_MESSAGE = `${logger.red('Disabled')}\n\n`;
1407
- const hasTelemetry = await checkTelemetry();
1442
+ const hasTelemetry = await checkTelemetry(sys);
1408
1443
  if (isEnabling) {
1409
- const result = await enableTelemetry();
1444
+ const result = await enableTelemetry(sys);
1410
1445
  result
1411
1446
  ? console.log(`\n ${logger.bold('Telemetry is now ') + ENABLED_MESSAGE}`)
1412
1447
  : console.log(`Something went wrong when enabling Telemetry.`);
1413
1448
  return;
1414
1449
  }
1415
1450
  if (isDisabling) {
1416
- const result = await disableTelemetry();
1451
+ const result = await disableTelemetry(sys);
1417
1452
  result
1418
1453
  ? console.log(`\n ${logger.bold('Telemetry is now ') + DISABLED_MESSAGE}`)
1419
1454
  : console.log(`Something went wrong when disabling Telemetry.`);
@@ -1428,9 +1463,7 @@ const taskTelemetry = async () => {
1428
1463
  `);
1429
1464
  };
1430
1465
 
1431
- const taskHelp = async () => {
1432
- const logger = getLogger();
1433
- const sys = getCompilerSystem();
1466
+ const taskHelp = async (config, logger, sys) => {
1434
1467
  const prompt = logger.dim(sys.details.platform === 'windows' ? '>' : '$');
1435
1468
  console.log(`
1436
1469
  ${logger.bold('Build:')} ${logger.dim('Build components for development or production.')}
@@ -1461,11 +1494,13 @@ const taskHelp = async () => {
1461
1494
  ${prompt} ${logger.green('stencil generate')} or ${logger.green('stencil g')}
1462
1495
 
1463
1496
  `);
1464
- await taskTelemetry();
1497
+ // TODO(STENCIL-148) make this parameter no longer optional, remove the surrounding if statement
1498
+ if (sys) {
1499
+ await taskTelemetry(config, sys, logger);
1500
+ }
1465
1501
  console.log(`
1466
1502
  ${logger.bold('Examples:')}
1467
1503
 
1468
-
1469
1504
  ${prompt} ${logger.green('stencil build --dev --watch --serve')}
1470
1505
  ${prompt} ${logger.green('stencil build --prerender')}
1471
1506
  ${prompt} ${logger.green('stencil test --spec --e2e')}
@@ -1566,8 +1601,6 @@ const taskTest = async (config) => {
1566
1601
 
1567
1602
  const run = async (init) => {
1568
1603
  const { args, logger, sys } = init;
1569
- // Initialize the singleton so we can use this throughout the lifecycle of the CLI.
1570
- const stencilCLIConfig = initializeStencilCLIConfig({ args, logger, sys });
1571
1604
  try {
1572
1605
  const flags = parseFlags(args, sys);
1573
1606
  const task = flags.task;
@@ -1580,13 +1613,8 @@ const run = async (init) => {
1580
1613
  if (isFunction(sys.applyGlobalPatch)) {
1581
1614
  sys.applyGlobalPatch(sys.getCurrentDirectory());
1582
1615
  }
1583
- // Update singleton with modifications
1584
- stencilCLIConfig.logger = logger;
1585
- stencilCLIConfig.task = task;
1586
- stencilCLIConfig.sys = sys;
1587
- stencilCLIConfig.flags = flags;
1588
1616
  if (task === 'help' || flags.help) {
1589
- taskHelp();
1617
+ await taskHelp({ flags: { task: 'help', args }, outputTargets: [] }, logger, sys);
1590
1618
  return;
1591
1619
  }
1592
1620
  startupLog(logger, task);
@@ -1605,7 +1633,6 @@ const run = async (init) => {
1605
1633
  return sys.exit(1);
1606
1634
  }
1607
1635
  const coreCompiler = await loadCoreCompiler(sys);
1608
- stencilCLIConfig.coreCompiler = coreCompiler;
1609
1636
  if (task === 'version' || flags.version) {
1610
1637
  console.log(coreCompiler.version);
1611
1638
  return;
@@ -1613,7 +1640,7 @@ const run = async (init) => {
1613
1640
  startupLogVersion(logger, task, coreCompiler);
1614
1641
  loadedCompilerLog(sys, logger, flags, coreCompiler);
1615
1642
  if (task === 'info') {
1616
- await telemetryAction(async () => {
1643
+ await telemetryAction(sys, { flags: { task: 'info' }, outputTargets: [] }, logger, coreCompiler, async () => {
1617
1644
  await taskInfo(coreCompiler, sys, logger);
1618
1645
  });
1619
1646
  return;
@@ -1632,13 +1659,12 @@ const run = async (init) => {
1632
1659
  return sys.exit(1);
1633
1660
  }
1634
1661
  }
1635
- stencilCLIConfig.validatedConfig = validated;
1636
1662
  if (isFunction(sys.applyGlobalPatch)) {
1637
1663
  sys.applyGlobalPatch(validated.config.rootDir);
1638
1664
  }
1639
1665
  await sys.ensureResources({ rootDir: validated.config.rootDir, logger, dependencies: dependencies });
1640
- await telemetryAction(async () => {
1641
- await runTask(coreCompiler, validated.config, task);
1666
+ await telemetryAction(sys, validated.config, logger, coreCompiler, async () => {
1667
+ await runTask(coreCompiler, validated.config, task, sys);
1642
1668
  });
1643
1669
  }
1644
1670
  catch (e) {
@@ -1648,12 +1674,12 @@ const run = async (init) => {
1648
1674
  }
1649
1675
  }
1650
1676
  };
1651
- const runTask = async (coreCompiler, config, task) => {
1652
- config.flags = config.flags || {};
1677
+ const runTask = async (coreCompiler, config, task, sys) => {
1678
+ config.flags = config.flags || { task };
1653
1679
  config.outputTargets = config.outputTargets || [];
1654
1680
  switch (task) {
1655
1681
  case 'build':
1656
- await taskBuild(coreCompiler, config);
1682
+ await taskBuild(coreCompiler, config, sys);
1657
1683
  break;
1658
1684
  case 'docs':
1659
1685
  await taskDocs(coreCompiler, config);
@@ -1663,7 +1689,7 @@ const runTask = async (coreCompiler, config, task) => {
1663
1689
  await taskGenerate(coreCompiler, config);
1664
1690
  break;
1665
1691
  case 'help':
1666
- taskHelp();
1692
+ taskHelp(config, config.logger, sys);
1667
1693
  break;
1668
1694
  case 'prerender':
1669
1695
  await taskPrerender(coreCompiler, config);
@@ -1672,7 +1698,10 @@ const runTask = async (coreCompiler, config, task) => {
1672
1698
  await taskServe(config);
1673
1699
  break;
1674
1700
  case 'telemetry':
1675
- await taskTelemetry();
1701
+ // TODO(STENCIL-148) make this parameter no longer optional, remove the surrounding if statement
1702
+ if (sys) {
1703
+ await taskTelemetry(config, sys, config.logger);
1704
+ }
1676
1705
  break;
1677
1706
  case 'test':
1678
1707
  await taskTest(config);
@@ -1682,7 +1711,7 @@ const runTask = async (coreCompiler, config, task) => {
1682
1711
  break;
1683
1712
  default:
1684
1713
  config.logger.error(`${config.logger.emoji('❌ ')}Invalid stencil command, please see the options below:`);
1685
- taskHelp();
1714
+ taskHelp(config, config.logger, sys);
1686
1715
  return config.sys.exit(1);
1687
1716
  }
1688
1717
  };
@@ -1690,3 +1719,4 @@ const runTask = async (coreCompiler, config, task) => {
1690
1719
  exports.parseFlags = parseFlags;
1691
1720
  exports.run = run;
1692
1721
  exports.runTask = runTask;
1722
+ //# sourceMappingURL=index.cjs.map