@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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil CLI v2.8.0 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI v2.10.0 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  const toLowerCase = (str) => str.toLowerCase();
5
5
  const dashToPascalCase = (str) => toLowerCase(str)
@@ -461,7 +461,7 @@ const getNpmConfigEnvArgs = (sys) => {
461
461
  const dependencies = [
462
462
  {
463
463
  name: "@stencil/core",
464
- version: "2.8.0",
464
+ version: "2.10.0",
465
465
  main: "compiler/stencil.js",
466
466
  resources: [
467
467
  "package.json",
@@ -509,6 +509,11 @@ const dependencies = [
509
509
  "compiler/lib.es2020.sharedmemory.d.ts",
510
510
  "compiler/lib.es2020.string.d.ts",
511
511
  "compiler/lib.es2020.symbol.wellknown.d.ts",
512
+ "compiler/lib.es2021.d.ts",
513
+ "compiler/lib.es2021.full.d.ts",
514
+ "compiler/lib.es2021.promise.d.ts",
515
+ "compiler/lib.es2021.string.d.ts",
516
+ "compiler/lib.es2021.weakref.d.ts",
512
517
  "compiler/lib.es5.d.ts",
513
518
  "compiler/lib.es6.d.ts",
514
519
  "compiler/lib.esnext.d.ts",
@@ -558,7 +563,7 @@ const dependencies = [
558
563
  },
559
564
  {
560
565
  name: "typescript",
561
- version: "4.2.3",
566
+ version: "4.3.5",
562
567
  main: "lib/typescript.js"
563
568
  }
564
569
  ];
@@ -771,82 +776,6 @@ const taskWatch = async (coreCompiler, config) => {
771
776
  }
772
777
  };
773
778
 
774
- class StencilCLIConfig {
775
- constructor(options) {
776
- this._args = (options === null || options === void 0 ? void 0 : options.args) || [];
777
- this._logger = options === null || options === void 0 ? void 0 : options.logger;
778
- this._sys = options === null || options === void 0 ? void 0 : options.sys;
779
- this._flags = (options === null || options === void 0 ? void 0 : options.flags) || undefined;
780
- this._validatedConfig = (options === null || options === void 0 ? void 0 : options.validatedConfig) || undefined;
781
- }
782
- static getInstance(options) {
783
- if (!StencilCLIConfig.instance) {
784
- StencilCLIConfig.instance = new StencilCLIConfig(options);
785
- }
786
- return StencilCLIConfig.instance;
787
- }
788
- resetInstance() {
789
- delete StencilCLIConfig.instance;
790
- }
791
- get logger() {
792
- return this._logger;
793
- }
794
- set logger(logger) {
795
- this._logger = logger;
796
- }
797
- get sys() {
798
- return this._sys;
799
- }
800
- set sys(sys) {
801
- this._sys = sys;
802
- }
803
- get args() {
804
- return this._args;
805
- }
806
- set args(args) {
807
- this._args = args;
808
- }
809
- get task() {
810
- return this._task;
811
- }
812
- set task(task) {
813
- this._task = task;
814
- }
815
- get flags() {
816
- return this._flags;
817
- }
818
- set flags(flags) {
819
- this._flags = flags;
820
- }
821
- get coreCompiler() {
822
- return this._coreCompiler;
823
- }
824
- set coreCompiler(coreCompiler) {
825
- this._coreCompiler = coreCompiler;
826
- }
827
- get validatedConfig() {
828
- return this._validatedConfig;
829
- }
830
- set validatedConfig(validatedConfig) {
831
- this._validatedConfig = validatedConfig;
832
- }
833
- }
834
- function initializeStencilCLIConfig(options) {
835
- return StencilCLIConfig.getInstance(options);
836
- }
837
- function getStencilCLIConfig() {
838
- return StencilCLIConfig.getInstance();
839
- }
840
- function getCompilerSystem() {
841
- return getStencilCLIConfig().sys;
842
- }
843
- function getLogger() {
844
- return getStencilCLIConfig().logger;
845
- }
846
- function getCoreCompiler() {
847
- return getStencilCLIConfig().coreCompiler;
848
- }
849
-
850
779
  const tryFn = async (fn, ...args) => {
851
780
  try {
852
781
  return await fn(...args);
@@ -856,12 +785,12 @@ const tryFn = async (fn, ...args) => {
856
785
  }
857
786
  return null;
858
787
  };
859
- const isInteractive = (object) => {
860
- var _a, _b;
788
+ const isInteractive = (sys, config, object) => {
789
+ var _a;
861
790
  const terminalInfo = object ||
862
791
  Object.freeze({
863
- tty: getCompilerSystem().isTTY() ? true : false,
864
- 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),
792
+ tty: sys.isTTY() ? true : false,
793
+ 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),
865
794
  });
866
795
  return terminalInfo.tty && !terminalInfo.ci;
867
796
  };
@@ -876,93 +805,134 @@ function uuidv4() {
876
805
  }
877
806
  /**
878
807
  * Reads and parses a JSON file from the given `path`
808
+ * @param sys The system where the command is invoked
879
809
  * @param path the path on the file system to read and parse
880
810
  * @returns the parsed JSON
881
811
  */
882
- async function readJson(path) {
883
- const file = await getCompilerSystem().readFile(path);
812
+ async function readJson(sys, path) {
813
+ const file = await sys.readFile(path);
884
814
  return !!file && JSON.parse(file);
885
815
  }
886
- function hasDebug() {
887
- return getStencilCLIConfig().flags.debug;
816
+ /**
817
+ * Does the command have the debug flag?
818
+ * @param config The config passed into the Stencil command
819
+ * @returns true if --debug has been passed, otherwise false
820
+ */
821
+ function hasDebug(config) {
822
+ return config.flags.debug;
888
823
  }
889
- function hasVerbose() {
890
- return getStencilCLIConfig().flags.verbose && hasDebug();
824
+ /**
825
+ * Does the command have the verbose and debug flags?
826
+ * @param config The config passed into the Stencil command
827
+ * @returns true if both --debug and --verbose have been passed, otherwise false
828
+ */
829
+ function hasVerbose(config) {
830
+ return config.flags.verbose && hasDebug(config);
891
831
  }
892
832
 
893
833
  /**
894
834
  * Used to determine if tracking should occur.
835
+ * @param config The config passed into the Stencil command
836
+ * @param sys The system where the command is invoked
895
837
  * @param ci whether or not the process is running in a Continuous Integration (CI) environment
896
838
  * @returns true if telemetry should be sent, false otherwise
897
839
  */
898
- async function shouldTrack(ci) {
899
- return !ci && isInteractive() && (await checkTelemetry());
840
+ async function shouldTrack(config, sys, ci) {
841
+ return !ci && isInteractive(sys, config) && (await checkTelemetry(sys));
900
842
  }
901
843
 
902
844
  const isTest$1 = () => process.env.JEST_WORKER_ID !== undefined;
903
- const defaultConfig = () => getCompilerSystem().resolvePath(`${getCompilerSystem().homeDir()}/.ionic/${isTest$1() ? 'tmp-config.json' : 'config.json'}`);
904
- const defaultConfigDirectory = () => getCompilerSystem().resolvePath(`${getCompilerSystem().homeDir()}/.ionic`);
845
+ const defaultConfig = (sys) => sys.resolvePath(`${sys.homeDir()}/.ionic/${isTest$1() ? 'tmp-config.json' : 'config.json'}`);
846
+ const defaultConfigDirectory = (sys) => sys.resolvePath(`${sys.homeDir()}/.ionic`);
905
847
  /**
906
- * Reads an Ionic configuration file from disk, parses it, and performs any necessary corrections to it if ceratin
848
+ * Reads an Ionic configuration file from disk, parses it, and performs any necessary corrections to it if certain
907
849
  * values are deemed to be malformed
850
+ * @param sys The system where the command is invoked
908
851
  * @returns the config read from disk that has been potentially been updated
909
852
  */
910
- async function readConfig() {
911
- let config = await readJson(defaultConfig());
853
+ async function readConfig(sys) {
854
+ let config = await readJson(sys, defaultConfig(sys));
912
855
  if (!config) {
913
856
  config = {
914
857
  'tokens.telemetry': uuidv4(),
915
858
  'telemetry.stencil': true,
916
859
  };
917
- await writeConfig(config);
860
+ await writeConfig(sys, config);
918
861
  }
919
862
  else if (!UUID_REGEX.test(config['tokens.telemetry'])) {
920
863
  const newUuid = uuidv4();
921
- await writeConfig({ ...config, 'tokens.telemetry': newUuid });
864
+ await writeConfig(sys, { ...config, 'tokens.telemetry': newUuid });
922
865
  config['tokens.telemetry'] = newUuid;
923
866
  }
924
867
  return config;
925
868
  }
926
- async function writeConfig(config) {
869
+ /**
870
+ * Writes an Ionic configuration file to disk.
871
+ * @param sys The system where the command is invoked
872
+ * @param config The config passed into the Stencil command
873
+ * @returns boolean If the command was successful
874
+ */
875
+ async function writeConfig(sys, config) {
927
876
  let result = false;
928
877
  try {
929
- await getCompilerSystem().createDir(defaultConfigDirectory(), { recursive: true });
930
- await getCompilerSystem().writeFile(defaultConfig(), JSON.stringify(config, null, 2));
878
+ await sys.createDir(defaultConfigDirectory(sys), { recursive: true });
879
+ await sys.writeFile(defaultConfig(sys), JSON.stringify(config, null, 2));
931
880
  result = true;
932
881
  }
933
882
  catch (error) {
934
- console.error(`Stencil Telemetry: couldn't write configuration file to ${defaultConfig()} - ${error}.`);
883
+ console.error(`Stencil Telemetry: couldn't write configuration file to ${defaultConfig(sys)} - ${error}.`);
935
884
  }
936
885
  return result;
937
886
  }
938
- async function updateConfig(newOptions) {
939
- const config = await readConfig();
940
- return await writeConfig(Object.assign(config, newOptions));
887
+ /**
888
+ * Update a subset of the Ionic config.
889
+ * @param sys The system where the command is invoked
890
+ * @param newOptions The new options to save
891
+ * @returns boolean If the command was successful
892
+ */
893
+ async function updateConfig(sys, newOptions) {
894
+ const config = await readConfig(sys);
895
+ return await writeConfig(sys, Object.assign(config, newOptions));
941
896
  }
942
897
 
898
+ const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
899
+ const DOCS_CUSTOM = 'docs-custom';
900
+ const DOCS_JSON = `docs-json`;
901
+ const DOCS_README = `docs-readme`;
902
+ const DOCS_VSCODE = `docs-vscode`;
903
+ const WWW = `www`;
904
+
943
905
  /**
944
906
  * Used to within taskBuild to provide the component_count property.
907
+ *
908
+ * @param sys The system where the command is invoked
909
+ * @param config The config passed into the Stencil command
910
+ * @param logger The tool used to do logging
911
+ * @param coreCompiler The compiler used to do builds
945
912
  * @param result The results of a compiler build.
946
913
  */
947
- async function telemetryBuildFinishedAction(result) {
948
- const { flags, logger } = getStencilCLIConfig();
949
- const tracking = await shouldTrack(flags.ci);
914
+ async function telemetryBuildFinishedAction(sys, config, logger, coreCompiler, result) {
915
+ const tracking = await shouldTrack(config, sys, config.flags.ci);
950
916
  if (!tracking) {
951
917
  return;
952
918
  }
953
919
  const component_count = Object.keys(result.componentGraph).length;
954
- const data = await prepareData(result.duration, component_count);
955
- await sendMetric('stencil_cli_command', data);
920
+ const data = await prepareData(coreCompiler, config, sys, result.duration, component_count);
921
+ await sendMetric(sys, config, 'stencil_cli_command', data);
956
922
  logger.debug(`${logger.blue('Telemetry')}: ${logger.gray(JSON.stringify(data))}`);
957
923
  }
958
924
  /**
959
925
  * A function to wrap a compiler task function around. Will send telemetry if, and only if, the machine allows.
926
+ * @param sys The system where the command is invoked
927
+ * @param config The config passed into the Stencil command
928
+ * @param logger The tool used to do logging
929
+ * @param coreCompiler The compiler used to do builds
960
930
  * @param action A Promise-based function to call in order to get the duration of any given command.
961
931
  * @returns void
962
932
  */
963
- async function telemetryAction(action) {
964
- const { flags, logger } = getStencilCLIConfig();
965
- const tracking = await shouldTrack(!!flags.ci);
933
+ async function telemetryAction(sys, config, logger, coreCompiler, action) {
934
+ var _a;
935
+ const tracking = await shouldTrack(config, sys, !!((_a = config === null || config === void 0 ? void 0 : config.flags) === null || _a === void 0 ? void 0 : _a.ci));
966
936
  let duration = undefined;
967
937
  let error;
968
938
  if (action) {
@@ -977,51 +947,51 @@ async function telemetryAction(action) {
977
947
  duration = end.getTime() - start.getTime();
978
948
  }
979
949
  // We'll get componentCount details inside the taskBuild, so let's not send two messages.
980
- if (!tracking || (flags.task == 'build' && !flags.args.includes('--watch'))) {
950
+ if (!tracking || (config.flags.task == 'build' && !config.flags.args.includes('--watch'))) {
981
951
  return;
982
952
  }
983
- const data = await prepareData(duration);
984
- await sendMetric('stencil_cli_command', data);
953
+ const data = await prepareData(coreCompiler, config, sys, duration);
954
+ await sendMetric(sys, config, 'stencil_cli_command', data);
985
955
  logger.debug(`${logger.blue('Telemetry')}: ${logger.gray(JSON.stringify(data))}`);
986
956
  if (error) {
987
957
  throw error;
988
958
  }
989
959
  }
990
- function hasAppTarget() {
991
- return getStencilCLIConfig().validatedConfig.config.outputTargets.some((target) => target.type === 'www' && (!!target.serviceWorker || (!!target.baseUrl && target.baseUrl !== '/')));
960
+ function hasAppTarget(config) {
961
+ return config.outputTargets.some((target) => target.type === WWW && (!!target.serviceWorker || (!!target.baseUrl && target.baseUrl !== '/')));
992
962
  }
993
- function isUsingYarn() {
963
+ function isUsingYarn(sys) {
994
964
  var _a;
995
- return ((_a = getCompilerSystem().getEnvironmentVar('npm_execpath')) === null || _a === void 0 ? void 0 : _a.includes('yarn')) || false;
965
+ return ((_a = sys.getEnvironmentVar('npm_execpath')) === null || _a === void 0 ? void 0 : _a.includes('yarn')) || false;
996
966
  }
997
- async function getActiveTargets() {
998
- const result = getStencilCLIConfig().validatedConfig.config.outputTargets.map((t) => t.type);
967
+ async function getActiveTargets(config) {
968
+ const result = config.outputTargets.map((t) => t.type);
999
969
  return Array.from(new Set(result));
1000
970
  }
1001
- const prepareData = async (duration_ms, component_count = undefined) => {
1002
- var _a, _b, _c;
1003
- const { flags, sys } = getStencilCLIConfig();
1004
- const { typescript, rollup } = ((_a = getCoreCompiler()) === null || _a === void 0 ? void 0 : _a.versions) || { typescript: 'unknown', rollup: 'unknown' };
1005
- const packages = await getInstalledPackages();
1006
- const targets = await getActiveTargets();
1007
- const yarn = isUsingYarn();
1008
- const stencil = ((_b = getCoreCompiler()) === null || _b === void 0 ? void 0 : _b.version) || 'unknown';
971
+ const prepareData = async (coreCompiler, config, sys, duration_ms, component_count = undefined) => {
972
+ const { typescript, rollup } = coreCompiler.versions || { typescript: 'unknown', rollup: 'unknown' };
973
+ const { packages, packagesNoVersions } = await getInstalledPackages(sys, config);
974
+ const targets = await getActiveTargets(config);
975
+ const yarn = isUsingYarn(sys);
976
+ const stencil = coreCompiler.version || 'unknown';
1009
977
  const system = `${sys.name} ${sys.version}`;
1010
978
  const os_name = sys.details.platform;
1011
979
  const os_version = sys.details.release;
1012
980
  const cpu_model = sys.details.cpuModel;
1013
- const build = ((_c = getCoreCompiler()) === null || _c === void 0 ? void 0 : _c.buildId) || 'unknown';
1014
- const has_app_pwa_config = hasAppTarget();
981
+ const build = coreCompiler.buildId || 'unknown';
982
+ const has_app_pwa_config = hasAppTarget(config);
1015
983
  return {
1016
984
  yarn,
1017
985
  duration_ms,
1018
986
  component_count,
1019
987
  targets,
1020
988
  packages,
1021
- arguments: flags.args,
1022
- task: flags.task,
989
+ packages_no_versions: packagesNoVersions,
990
+ arguments: config.flags.args,
991
+ task: config.flags.task,
1023
992
  stencil,
1024
993
  system,
994
+ system_major: getMajorVersion(system),
1025
995
  os_name,
1026
996
  os_version,
1027
997
  cpu_model,
@@ -1032,41 +1002,92 @@ const prepareData = async (duration_ms, component_count = undefined) => {
1032
1002
  };
1033
1003
  };
1034
1004
  /**
1035
- * 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.
1005
+ * Reads package-lock.json, yarn.lock, and package.json files in order to cross reference
1006
+ * the dependencies and devDependencies properties. Pulls up the current installed version
1007
+ * of each package under the @stencil, @ionic, and @capacitor scopes.
1036
1008
  * @returns string[]
1037
1009
  */
1038
- async function getInstalledPackages() {
1010
+ async function getInstalledPackages(sys, config) {
1011
+ let packages = [];
1012
+ let packagesNoVersions = [];
1013
+ const yarn = isUsingYarn(sys);
1039
1014
  try {
1040
1015
  // Read package.json and package-lock.json
1041
- const appRootDir = getCompilerSystem().getCurrentDirectory();
1042
- const packageJson = await tryFn(readJson, getCompilerSystem().resolvePath(appRootDir + '/package.json'));
1043
- const packageLockJson = await tryFn(readJson, getCompilerSystem().resolvePath(appRootDir + '/package-lock.json'));
1016
+ const appRootDir = sys.getCurrentDirectory();
1017
+ const packageJson = await tryFn(readJson, sys, sys.resolvePath(appRootDir + '/package.json'));
1044
1018
  // They don't have a package.json for some reason? Eject button.
1045
1019
  if (!packageJson) {
1046
- return [];
1020
+ return { packages, packagesNoVersions };
1047
1021
  }
1048
- const packages = Object.entries({
1022
+ const rawPackages = Object.entries({
1049
1023
  ...packageJson.devDependencies,
1050
1024
  ...packageJson.dependencies,
1051
1025
  });
1052
1026
  // Collect packages only in the stencil, ionic, or capacitor org's:
1053
1027
  // https://www.npmjs.com/org/stencil
1054
- const ionicPackages = packages.filter(([k]) => k.startsWith('@stencil/') || k.startsWith('@ionic/') || k.startsWith('@capacitor/'));
1055
- const versions = packageLockJson
1056
- ? 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}`; })
1057
- : ionicPackages.map(([k, v]) => `${k}@${v}`);
1058
- return versions;
1028
+ const ionicPackages = rawPackages.filter(([k]) => k.startsWith('@stencil/') || k.startsWith('@ionic/') || k.startsWith('@capacitor/'));
1029
+ try {
1030
+ packages = yarn ? await yarnPackages(sys, ionicPackages) : await npmPackages(sys, ionicPackages);
1031
+ }
1032
+ catch (e) {
1033
+ packages = ionicPackages.map(([k, v]) => `${k}@${v.replace('^', '')}`);
1034
+ }
1035
+ packagesNoVersions = ionicPackages.map(([k]) => `${k}`);
1036
+ return { packages, packagesNoVersions };
1059
1037
  }
1060
1038
  catch (err) {
1061
- hasDebug() && console.error(err);
1062
- return [];
1039
+ hasDebug(config) && console.error(err);
1040
+ return { packages, packagesNoVersions };
1063
1041
  }
1064
1042
  }
1043
+ /**
1044
+ * Visits the npm lock file to find the exact versions that are installed
1045
+ * @param sys The system where the command is invoked
1046
+ * @param ionicPackages a list of the found packages matching `@stencil`, `@capacitor`, or `@ionic` from the package.json file.
1047
+ * @returns an array of strings of all the packages and their versions.
1048
+ */
1049
+ async function npmPackages(sys, ionicPackages) {
1050
+ const appRootDir = sys.getCurrentDirectory();
1051
+ const packageLockJson = await tryFn(readJson, sys, sys.resolvePath(appRootDir + '/package-lock.json'));
1052
+ return ionicPackages.map(([k, v]) => {
1053
+ var _a, _b, _c, _d;
1054
+ 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;
1055
+ version = version.includes('file:') ? sanitizeDeclaredVersion(v) : version;
1056
+ return `${k}@${version}`;
1057
+ });
1058
+ }
1059
+ /**
1060
+ * Visits the yarn lock file to find the exact versions that are installed
1061
+ * @param sys The system where the command is invoked
1062
+ * @param ionicPackages a list of the found packages matching `@stencil`, `@capacitor`, or `@ionic` from the package.json file.
1063
+ * @returns an array of strings of all the packages and their versions.
1064
+ */
1065
+ async function yarnPackages(sys, ionicPackages) {
1066
+ const appRootDir = sys.getCurrentDirectory();
1067
+ const yarnLock = sys.readFileSync(sys.resolvePath(appRootDir + '/yarn.lock'));
1068
+ const yarnLockYml = sys.parseYarnLockFile(yarnLock);
1069
+ return ionicPackages.map(([k, v]) => {
1070
+ var _a;
1071
+ const identifiedVersion = `${k}@${v}`;
1072
+ let version = (_a = yarnLockYml.object[identifiedVersion]) === null || _a === void 0 ? void 0 : _a.version;
1073
+ version = version.includes('undefined') ? sanitizeDeclaredVersion(identifiedVersion) : version;
1074
+ return `${k}@${version}`;
1075
+ });
1076
+ }
1077
+ /**
1078
+ * This function is used for fallback purposes, where an npm or yarn lock file doesn't exist in the consumers directory.
1079
+ * This will strip away '*', '^' and '~' from the declared package versions in a package.json.
1080
+ * @param version the raw semver pattern identifier version string
1081
+ * @returns a cleaned up representation without any qualifiers
1082
+ */
1083
+ function sanitizeDeclaredVersion(version) {
1084
+ return version.replace(/[*^~]/g, '');
1085
+ }
1065
1086
  /**
1066
1087
  * If telemetry is enabled, send a metric via IPC to a forked process for uploading.
1067
1088
  */
1068
- async function sendMetric(name, value) {
1069
- const session_id = await getTelemetryToken();
1089
+ async function sendMetric(sys, config, name, value) {
1090
+ const session_id = await getTelemetryToken(sys);
1070
1091
  const message = {
1071
1092
  name,
1072
1093
  timestamp: new Date().toISOString(),
@@ -1074,25 +1095,28 @@ async function sendMetric(name, value) {
1074
1095
  value,
1075
1096
  session_id,
1076
1097
  };
1077
- await sendTelemetry({ type: 'telemetry', message });
1098
+ await sendTelemetry(sys, config, { type: 'telemetry', message });
1078
1099
  }
1079
1100
  /**
1080
1101
  * Used to read the config file's tokens.telemetry property.
1102
+ * @param sys The system where the command is invoked
1081
1103
  * @returns string
1082
1104
  */
1083
- async function getTelemetryToken() {
1084
- const config = await readConfig();
1105
+ async function getTelemetryToken(sys) {
1106
+ const config = await readConfig(sys);
1085
1107
  if (config['tokens.telemetry'] === undefined) {
1086
1108
  config['tokens.telemetry'] = uuidv4();
1087
- await writeConfig(config);
1109
+ await writeConfig(sys, config);
1088
1110
  }
1089
1111
  return config['tokens.telemetry'];
1090
1112
  }
1091
1113
  /**
1092
1114
  * Issues a request to the telemetry server.
1115
+ * @param sys The system where the command is invoked
1116
+ * @param config The config passed into the Stencil command
1093
1117
  * @param data Data to be tracked
1094
1118
  */
1095
- async function sendTelemetry(data) {
1119
+ async function sendTelemetry(sys, config, data) {
1096
1120
  try {
1097
1121
  const now = new Date().toISOString();
1098
1122
  const body = {
@@ -1100,52 +1124,64 @@ async function sendTelemetry(data) {
1100
1124
  sent_at: now,
1101
1125
  };
1102
1126
  // This request is only made if telemetry is on.
1103
- const response = await getCompilerSystem().fetch('https://api.ionicjs.com/events/metrics', {
1127
+ const response = await sys.fetch('https://api.ionicjs.com/events/metrics', {
1104
1128
  method: 'POST',
1105
1129
  headers: {
1106
1130
  'Content-Type': 'application/json',
1107
1131
  },
1108
1132
  body: JSON.stringify(body),
1109
1133
  });
1110
- hasVerbose() &&
1134
+ hasVerbose(config) &&
1111
1135
  console.debug('\nSent %O metric to events service (status: %O)', data.message.name, response.status, '\n');
1112
1136
  if (response.status !== 204) {
1113
- hasVerbose() &&
1137
+ hasVerbose(config) &&
1114
1138
  console.debug('\nBad response from events service. Request body: %O', response.body.toString(), '\n');
1115
1139
  }
1116
1140
  }
1117
1141
  catch (e) {
1118
- hasVerbose() && console.debug('Telemetry request failed:', e);
1142
+ hasVerbose(config) && console.debug('Telemetry request failed:', e);
1119
1143
  }
1120
1144
  }
1121
1145
  /**
1122
1146
  * Checks if telemetry is enabled on this machine
1147
+ * @param sys The system where the command is invoked
1123
1148
  * @returns true if telemetry is enabled, false otherwise
1124
1149
  */
1125
- async function checkTelemetry() {
1126
- const config = await readConfig();
1150
+ async function checkTelemetry(sys) {
1151
+ const config = await readConfig(sys);
1127
1152
  if (config['telemetry.stencil'] === undefined) {
1128
1153
  config['telemetry.stencil'] = true;
1129
- await writeConfig(config);
1154
+ await writeConfig(sys, config);
1130
1155
  }
1131
1156
  return config['telemetry.stencil'];
1132
1157
  }
1133
1158
  /**
1134
1159
  * Writes to the config file, enabling telemetry for this machine.
1160
+ * @param sys The system where the command is invoked
1135
1161
  * @returns true if writing the file was successful, false otherwise
1136
1162
  */
1137
- async function enableTelemetry() {
1138
- return await updateConfig({ 'telemetry.stencil': true });
1163
+ async function enableTelemetry(sys) {
1164
+ return await updateConfig(sys, { 'telemetry.stencil': true });
1139
1165
  }
1140
1166
  /**
1141
1167
  * Writes to the config file, disabling telemetry for this machine.
1168
+ * @param sys The system where the command is invoked
1142
1169
  * @returns true if writing the file was successful, false otherwise
1143
1170
  */
1144
- async function disableTelemetry() {
1145
- return await updateConfig({ 'telemetry.stencil': false });
1171
+ async function disableTelemetry(sys) {
1172
+ return await updateConfig(sys, { 'telemetry.stencil': false });
1173
+ }
1174
+ /**
1175
+ * Takes in a semver string in order to return the major version.
1176
+ * @param version The fully qualified semver version
1177
+ * @returns a string of the major version
1178
+ */
1179
+ function getMajorVersion(version) {
1180
+ const parts = version.split('.');
1181
+ return parts[0];
1146
1182
  }
1147
1183
 
1148
- const taskBuild = async (coreCompiler, config) => {
1184
+ const taskBuild = async (coreCompiler, config, sys) => {
1149
1185
  if (config.flags.watch) {
1150
1186
  // watch build
1151
1187
  await taskWatch(coreCompiler, config);
@@ -1158,7 +1194,10 @@ const taskBuild = async (coreCompiler, config) => {
1158
1194
  const versionChecker = startCheckVersion(config, coreCompiler.version);
1159
1195
  const compiler = await coreCompiler.createCompiler(config);
1160
1196
  const results = await compiler.build();
1161
- await telemetryBuildFinishedAction(results);
1197
+ // TODO(STENCIL-148) make this parameter no longer optional, remove the surrounding if statement
1198
+ if (sys) {
1199
+ await telemetryBuildFinishedAction(sys, config, config.logger, coreCompiler, results);
1200
+ }
1162
1201
  await compiler.destroy();
1163
1202
  if (results.hasError) {
1164
1203
  exitCode = 1;
@@ -1181,12 +1220,6 @@ const taskBuild = async (coreCompiler, config) => {
1181
1220
  }
1182
1221
  };
1183
1222
 
1184
- const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
1185
- const DOCS_CUSTOM = 'docs-custom';
1186
- const DOCS_JSON = `docs-json`;
1187
- const DOCS_README = `docs-readme`;
1188
- const DOCS_VSCODE = `docs-vscode`;
1189
-
1190
1223
  const taskDocs = async (coreCompiler, config) => {
1191
1224
  config.devServer = null;
1192
1225
  config.outputTargets = config.outputTargets.filter(isOutputTargetDocs);
@@ -1197,9 +1230,7 @@ const taskDocs = async (coreCompiler, config) => {
1197
1230
  await compiler.destroy();
1198
1231
  };
1199
1232
 
1200
- const IS_DENO_ENV = typeof Deno !== 'undefined';
1201
- const IS_NODE_ENV = !IS_DENO_ENV &&
1202
- typeof global !== 'undefined' &&
1233
+ const IS_NODE_ENV = typeof global !== 'undefined' &&
1203
1234
  typeof require === 'function' &&
1204
1235
  !!global.process &&
1205
1236
  typeof __filename === 'string' &&
@@ -1371,25 +1402,24 @@ describe('${name}', () => {
1371
1402
  */
1372
1403
  const toPascalCase = (str) => str.split('-').reduce((res, part) => res + part[0].toUpperCase() + part.substr(1), '');
1373
1404
 
1374
- const taskTelemetry = async () => {
1375
- const logger = getLogger();
1376
- const prompt = logger.dim(getCompilerSystem().details.platform === 'windows' ? '>' : '$');
1377
- const isEnabling = getStencilCLIConfig().flags.args.includes('on');
1378
- const isDisabling = getStencilCLIConfig().flags.args.includes('off');
1405
+ const taskTelemetry = async (config, sys, logger) => {
1406
+ const prompt = logger.dim(sys.details.platform === 'windows' ? '>' : '$');
1407
+ const isEnabling = config.flags.args.includes('on');
1408
+ const isDisabling = config.flags.args.includes('off');
1379
1409
  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')}`;
1380
1410
  const THANK_YOU = `Thank you for helping to make Stencil better! 💖`;
1381
1411
  const ENABLED_MESSAGE = `${logger.green('Enabled')}. ${THANK_YOU}\n\n`;
1382
1412
  const DISABLED_MESSAGE = `${logger.red('Disabled')}\n\n`;
1383
- const hasTelemetry = await checkTelemetry();
1413
+ const hasTelemetry = await checkTelemetry(sys);
1384
1414
  if (isEnabling) {
1385
- const result = await enableTelemetry();
1415
+ const result = await enableTelemetry(sys);
1386
1416
  result
1387
1417
  ? console.log(`\n ${logger.bold('Telemetry is now ') + ENABLED_MESSAGE}`)
1388
1418
  : console.log(`Something went wrong when enabling Telemetry.`);
1389
1419
  return;
1390
1420
  }
1391
1421
  if (isDisabling) {
1392
- const result = await disableTelemetry();
1422
+ const result = await disableTelemetry(sys);
1393
1423
  result
1394
1424
  ? console.log(`\n ${logger.bold('Telemetry is now ') + DISABLED_MESSAGE}`)
1395
1425
  : console.log(`Something went wrong when disabling Telemetry.`);
@@ -1404,9 +1434,7 @@ const taskTelemetry = async () => {
1404
1434
  `);
1405
1435
  };
1406
1436
 
1407
- const taskHelp = async () => {
1408
- const logger = getLogger();
1409
- const sys = getCompilerSystem();
1437
+ const taskHelp = async (config, logger, sys) => {
1410
1438
  const prompt = logger.dim(sys.details.platform === 'windows' ? '>' : '$');
1411
1439
  console.log(`
1412
1440
  ${logger.bold('Build:')} ${logger.dim('Build components for development or production.')}
@@ -1437,11 +1465,13 @@ const taskHelp = async () => {
1437
1465
  ${prompt} ${logger.green('stencil generate')} or ${logger.green('stencil g')}
1438
1466
 
1439
1467
  `);
1440
- await taskTelemetry();
1468
+ // TODO(STENCIL-148) make this parameter no longer optional, remove the surrounding if statement
1469
+ if (sys) {
1470
+ await taskTelemetry(config, sys, logger);
1471
+ }
1441
1472
  console.log(`
1442
1473
  ${logger.bold('Examples:')}
1443
1474
 
1444
-
1445
1475
  ${prompt} ${logger.green('stencil build --dev --watch --serve')}
1446
1476
  ${prompt} ${logger.green('stencil build --prerender')}
1447
1477
  ${prompt} ${logger.green('stencil test --spec --e2e')}
@@ -1542,8 +1572,6 @@ const taskTest = async (config) => {
1542
1572
 
1543
1573
  const run = async (init) => {
1544
1574
  const { args, logger, sys } = init;
1545
- // Initialize the singleton so we can use this throughout the lifecycle of the CLI.
1546
- const stencilCLIConfig = initializeStencilCLIConfig({ args, logger, sys });
1547
1575
  try {
1548
1576
  const flags = parseFlags(args, sys);
1549
1577
  const task = flags.task;
@@ -1556,13 +1584,8 @@ const run = async (init) => {
1556
1584
  if (isFunction(sys.applyGlobalPatch)) {
1557
1585
  sys.applyGlobalPatch(sys.getCurrentDirectory());
1558
1586
  }
1559
- // Update singleton with modifications
1560
- stencilCLIConfig.logger = logger;
1561
- stencilCLIConfig.task = task;
1562
- stencilCLIConfig.sys = sys;
1563
- stencilCLIConfig.flags = flags;
1564
1587
  if (task === 'help' || flags.help) {
1565
- taskHelp();
1588
+ await taskHelp({ flags: { task: 'help', args }, outputTargets: [] }, logger, sys);
1566
1589
  return;
1567
1590
  }
1568
1591
  startupLog(logger, task);
@@ -1581,7 +1604,6 @@ const run = async (init) => {
1581
1604
  return sys.exit(1);
1582
1605
  }
1583
1606
  const coreCompiler = await loadCoreCompiler(sys);
1584
- stencilCLIConfig.coreCompiler = coreCompiler;
1585
1607
  if (task === 'version' || flags.version) {
1586
1608
  console.log(coreCompiler.version);
1587
1609
  return;
@@ -1589,7 +1611,7 @@ const run = async (init) => {
1589
1611
  startupLogVersion(logger, task, coreCompiler);
1590
1612
  loadedCompilerLog(sys, logger, flags, coreCompiler);
1591
1613
  if (task === 'info') {
1592
- await telemetryAction(async () => {
1614
+ await telemetryAction(sys, { flags: { task: 'info' }, outputTargets: [] }, logger, coreCompiler, async () => {
1593
1615
  await taskInfo(coreCompiler, sys, logger);
1594
1616
  });
1595
1617
  return;
@@ -1608,13 +1630,12 @@ const run = async (init) => {
1608
1630
  return sys.exit(1);
1609
1631
  }
1610
1632
  }
1611
- stencilCLIConfig.validatedConfig = validated;
1612
1633
  if (isFunction(sys.applyGlobalPatch)) {
1613
1634
  sys.applyGlobalPatch(validated.config.rootDir);
1614
1635
  }
1615
1636
  await sys.ensureResources({ rootDir: validated.config.rootDir, logger, dependencies: dependencies });
1616
- await telemetryAction(async () => {
1617
- await runTask(coreCompiler, validated.config, task);
1637
+ await telemetryAction(sys, validated.config, logger, coreCompiler, async () => {
1638
+ await runTask(coreCompiler, validated.config, task, sys);
1618
1639
  });
1619
1640
  }
1620
1641
  catch (e) {
@@ -1624,12 +1645,12 @@ const run = async (init) => {
1624
1645
  }
1625
1646
  }
1626
1647
  };
1627
- const runTask = async (coreCompiler, config, task) => {
1628
- config.flags = config.flags || {};
1648
+ const runTask = async (coreCompiler, config, task, sys) => {
1649
+ config.flags = config.flags || { task };
1629
1650
  config.outputTargets = config.outputTargets || [];
1630
1651
  switch (task) {
1631
1652
  case 'build':
1632
- await taskBuild(coreCompiler, config);
1653
+ await taskBuild(coreCompiler, config, sys);
1633
1654
  break;
1634
1655
  case 'docs':
1635
1656
  await taskDocs(coreCompiler, config);
@@ -1639,7 +1660,7 @@ const runTask = async (coreCompiler, config, task) => {
1639
1660
  await taskGenerate(coreCompiler, config);
1640
1661
  break;
1641
1662
  case 'help':
1642
- taskHelp();
1663
+ taskHelp(config, config.logger, sys);
1643
1664
  break;
1644
1665
  case 'prerender':
1645
1666
  await taskPrerender(coreCompiler, config);
@@ -1648,7 +1669,10 @@ const runTask = async (coreCompiler, config, task) => {
1648
1669
  await taskServe(config);
1649
1670
  break;
1650
1671
  case 'telemetry':
1651
- await taskTelemetry();
1672
+ // TODO(STENCIL-148) make this parameter no longer optional, remove the surrounding if statement
1673
+ if (sys) {
1674
+ await taskTelemetry(config, sys, config.logger);
1675
+ }
1652
1676
  break;
1653
1677
  case 'test':
1654
1678
  await taskTest(config);
@@ -1658,9 +1682,10 @@ const runTask = async (coreCompiler, config, task) => {
1658
1682
  break;
1659
1683
  default:
1660
1684
  config.logger.error(`${config.logger.emoji('❌ ')}Invalid stencil command, please see the options below:`);
1661
- taskHelp();
1685
+ taskHelp(config, config.logger, sys);
1662
1686
  return config.sys.exit(1);
1663
1687
  }
1664
1688
  };
1665
1689
 
1666
1690
  export { parseFlags, run, runTask };
1691
+ //# sourceMappingURL=index.js.map