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