@stencil/core 2.17.4 → 2.18.1

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 (88) hide show
  1. package/cli/index.cjs +285 -220
  2. package/cli/index.d.ts +1 -0
  3. package/cli/index.js +285 -220
  4. package/cli/package.json +1 -1
  5. package/compiler/lib.dom.d.ts +620 -89
  6. package/compiler/lib.dom.iterable.d.ts +27 -3
  7. package/compiler/lib.es2015.core.d.ts +3 -3
  8. package/compiler/lib.es2015.iterable.d.ts +2 -1
  9. package/compiler/lib.es2015.reflect.d.ts +1 -1
  10. package/compiler/lib.es2020.bigint.d.ts +7 -5
  11. package/compiler/lib.es2020.d.ts +2 -0
  12. package/compiler/lib.es2020.date.d.ts +44 -0
  13. package/compiler/lib.es2020.intl.d.ts +51 -11
  14. package/compiler/lib.es2020.number.d.ts +30 -0
  15. package/compiler/lib.es2021.intl.d.ts +106 -4
  16. package/compiler/lib.es2022.array.d.ts +123 -0
  17. package/compiler/lib.es2022.d.ts +26 -0
  18. package/compiler/lib.es2022.error.d.ts +75 -0
  19. package/compiler/lib.es2022.full.d.ts +25 -0
  20. package/compiler/lib.es2022.intl.d.ts +111 -0
  21. package/compiler/lib.es2022.object.d.ts +28 -0
  22. package/compiler/lib.es2022.string.d.ts +27 -0
  23. package/compiler/lib.es5.d.ts +25 -19
  24. package/compiler/lib.esnext.d.ts +1 -1
  25. package/compiler/lib.esnext.intl.d.ts +4 -1
  26. package/compiler/lib.webworker.d.ts +236 -40
  27. package/compiler/lib.webworker.iterable.d.ts +10 -3
  28. package/compiler/package.json +1 -1
  29. package/compiler/stencil.d.ts +2 -2
  30. package/compiler/stencil.js +47263 -45624
  31. package/compiler/stencil.min.js +2 -2
  32. package/compiler/sys/in-memory-fs.d.ts +218 -0
  33. package/dependencies.json +10 -1
  34. package/dev-server/client/index.d.ts +2 -2
  35. package/dev-server/client/index.js +241 -241
  36. package/dev-server/client/package.json +1 -1
  37. package/dev-server/connector.html +3 -3
  38. package/dev-server/index.d.ts +1 -1
  39. package/dev-server/index.js +2 -2
  40. package/dev-server/package.json +1 -1
  41. package/dev-server/server-process.js +1198 -1167
  42. package/internal/app-data/package.json +1 -1
  43. package/internal/client/css-shim.js +2 -2
  44. package/internal/client/dom.js +1 -1
  45. package/internal/client/index.js +1022 -824
  46. package/internal/client/package.json +1 -1
  47. package/internal/client/patch-browser.js +1 -1
  48. package/internal/client/patch-esm.js +1 -1
  49. package/internal/client/polyfills/css-shim.js +1 -1
  50. package/internal/client/shadow-css.js +1 -1
  51. package/internal/hydrate/index.js +119 -119
  52. package/internal/hydrate/package.json +1 -1
  53. package/internal/hydrate/runner.d.ts +1 -1
  54. package/internal/hydrate/runner.js +100 -100
  55. package/internal/package.json +1 -1
  56. package/internal/stencil-core/index.d.ts +8 -10
  57. package/internal/stencil-private.d.ts +77 -138
  58. package/internal/stencil-public-compiler.d.ts +44 -10
  59. package/internal/stencil-public-runtime.d.ts +15 -4
  60. package/internal/testing/index.js +148 -148
  61. package/internal/testing/package.json +1 -1
  62. package/mock-doc/index.cjs +534 -518
  63. package/mock-doc/index.d.ts +13 -12
  64. package/mock-doc/index.js +534 -518
  65. package/mock-doc/package.json +1 -1
  66. package/package.json +23 -32
  67. package/readme.md +27 -33
  68. package/screenshot/index.d.ts +1 -1
  69. package/screenshot/index.js +13 -13
  70. package/screenshot/package.json +1 -1
  71. package/screenshot/pixel-match.js +983 -849
  72. package/sys/node/glob.js +1 -1
  73. package/sys/node/index.d.ts +2 -0
  74. package/sys/node/index.js +374 -373
  75. package/sys/node/package.json +1 -1
  76. package/sys/node/worker.js +1 -1
  77. package/testing/index.d.ts +6 -6
  78. package/testing/index.js +427 -441
  79. package/testing/jest/jest-config.d.ts +1 -1
  80. package/testing/matchers/index.d.ts +3 -3
  81. package/testing/mock-fetch.d.ts +1 -1
  82. package/testing/mocks.d.ts +2 -2
  83. package/testing/package.json +1 -1
  84. package/testing/puppeteer/puppeteer-element.d.ts +2 -2
  85. package/testing/puppeteer/puppeteer-events.d.ts +1 -1
  86. package/testing/testing-logger.d.ts +1 -1
  87. package/testing/testing-utils.d.ts +5 -4
  88. package/testing/testing.d.ts +1 -1
package/cli/index.js CHANGED
@@ -1,29 +1,6 @@
1
1
  /*!
2
- Stencil CLI v2.17.4 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI v2.18.1 | MIT Licensed | https://stenciljs.com
3
3
  */
4
- /**
5
- * This sets the log level hierarchy for our terminal logger, ranging from
6
- * most to least verbose.
7
- *
8
- * Ordering the levels like this lets us easily check whether we should log a
9
- * message at a given time. For instance, if the log level is set to `'warn'`,
10
- * then anything passed to the logger with level `'warn'` or `'error'` should
11
- * be logged, but we should _not_ log anything with level `'info'` or `'debug'`.
12
- *
13
- * If we have a current log level `currentLevel` and a message with level
14
- * `msgLevel` is passed to the logger, we can determine whether or not we should
15
- * log it by checking if the log level on the message is further up or at the
16
- * same level in the hierarchy than `currentLevel`, like so:
17
- *
18
- * ```ts
19
- * LOG_LEVELS.indexOf(msgLevel) >= LOG_LEVELS.indexOf(currentLevel)
20
- * ```
21
- *
22
- * NOTE: for the reasons described above, do not change the order of the entries
23
- * in this array without good reason!
24
- */
25
- const LOG_LEVELS = ['debug', 'info', 'warn', 'error'];
26
-
27
4
  /**
28
5
  * Convert a string from PascalCase to dash-case
29
6
  *
@@ -199,18 +176,18 @@ const getEncodedRootLength = (path) => {
199
176
  return 0;
200
177
  const ch0 = path.charCodeAt(0);
201
178
  // POSIX or UNC
202
- if (ch0 === 47 /* slash */ || ch0 === 92 /* backslash */) {
179
+ if (ch0 === 47 /* CharacterCodes.slash */ || ch0 === 92 /* CharacterCodes.backslash */) {
203
180
  if (path.charCodeAt(1) !== ch0)
204
181
  return 1; // POSIX: "/" (or non-normalized "\")
205
- const p1 = path.indexOf(ch0 === 47 /* slash */ ? '/' : altDirectorySeparator, 2);
182
+ const p1 = path.indexOf(ch0 === 47 /* CharacterCodes.slash */ ? '/' : altDirectorySeparator, 2);
206
183
  if (p1 < 0)
207
184
  return path.length; // UNC: "//server" or "\\server"
208
185
  return p1 + 1; // UNC: "//server/" or "\\server\"
209
186
  }
210
187
  // DOS
211
- if (isVolumeCharacter(ch0) && path.charCodeAt(1) === 58 /* colon */) {
188
+ if (isVolumeCharacter(ch0) && path.charCodeAt(1) === 58 /* CharacterCodes.colon */) {
212
189
  const ch2 = path.charCodeAt(2);
213
- if (ch2 === 47 /* slash */ || ch2 === 92 /* backslash */)
190
+ if (ch2 === 47 /* CharacterCodes.slash */ || ch2 === 92 /* CharacterCodes.backslash */)
214
191
  return 3; // DOS: "c:/" or "c:\"
215
192
  if (path.length === 2)
216
193
  return 2; // DOS: "c:" (but not "c:d")
@@ -232,7 +209,7 @@ const getEncodedRootLength = (path) => {
232
209
  isVolumeCharacter(path.charCodeAt(authorityEnd + 1))) {
233
210
  const volumeSeparatorEnd = getFileUrlVolumeSeparatorEnd(path, authorityEnd + 2);
234
211
  if (volumeSeparatorEnd !== -1) {
235
- if (path.charCodeAt(volumeSeparatorEnd) === 47 /* slash */) {
212
+ if (path.charCodeAt(volumeSeparatorEnd) === 47 /* CharacterCodes.slash */) {
236
213
  // URL: "file:///c:/", "file://localhost/c:/", "file:///c%3a/", "file://localhost/c%3a/"
237
214
  return ~(volumeSeparatorEnd + 1);
238
215
  }
@@ -250,15 +227,15 @@ const getEncodedRootLength = (path) => {
250
227
  // relative
251
228
  return 0;
252
229
  };
253
- const isVolumeCharacter = (charCode) => (charCode >= 97 /* a */ && charCode <= 122 /* z */) ||
254
- (charCode >= 65 /* A */ && charCode <= 90 /* Z */);
230
+ const isVolumeCharacter = (charCode) => (charCode >= 97 /* CharacterCodes.a */ && charCode <= 122 /* CharacterCodes.z */) ||
231
+ (charCode >= 65 /* CharacterCodes.A */ && charCode <= 90 /* CharacterCodes.Z */);
255
232
  const getFileUrlVolumeSeparatorEnd = (url, start) => {
256
233
  const ch0 = url.charCodeAt(start);
257
- if (ch0 === 58 /* colon */)
234
+ if (ch0 === 58 /* CharacterCodes.colon */)
258
235
  return start + 1;
259
- if (ch0 === 37 /* percent */ && url.charCodeAt(start + 1) === 51 /* _3 */) {
236
+ if (ch0 === 37 /* CharacterCodes.percent */ && url.charCodeAt(start + 1) === 51 /* CharacterCodes._3 */) {
260
237
  const ch2 = url.charCodeAt(start + 2);
261
- if (ch2 === 97 /* a */ || ch2 === 65 /* A */)
238
+ if (ch2 === 97 /* CharacterCodes.a */ || ch2 === 65 /* CharacterCodes.A */)
262
239
  return start + 3;
263
240
  }
264
241
  return -1;
@@ -273,6 +250,22 @@ const pathComponents = (path, rootLength) => {
273
250
  return [root, ...rest];
274
251
  };
275
252
 
253
+ /**
254
+ * Check whether a string is a member of a ReadonlyArray<string>
255
+ *
256
+ * We need a little helper for this because unfortunately `includes` is typed
257
+ * on `ReadonlyArray<T>` as `(el: T): boolean` so a `string` cannot be passed
258
+ * to `includes` on a `ReadonlyArray` 😢 thus we have a little helper function
259
+ * where we do the type coercion just once.
260
+ *
261
+ * see microsoft/TypeScript#31018 for some discussion of this
262
+ *
263
+ * @param readOnlyArray the array we're checking
264
+ * @param maybeMember a value which is possibly a member of the array
265
+ * @returns whether the array contains the member or not
266
+ */
267
+ const readOnlyArrayHasStringMember = (readOnlyArray, maybeMember) => readOnlyArray.includes(maybeMember);
268
+
276
269
  /**
277
270
  * Validates that a component tag meets required naming conventions to be used for a web component
278
271
  * @param tag the tag to validate
@@ -317,6 +310,29 @@ const validateComponentTag = (tag) => {
317
310
  return undefined;
318
311
  };
319
312
 
313
+ /**
314
+ * This sets the log level hierarchy for our terminal logger, ranging from
315
+ * most to least verbose.
316
+ *
317
+ * Ordering the levels like this lets us easily check whether we should log a
318
+ * message at a given time. For instance, if the log level is set to `'warn'`,
319
+ * then anything passed to the logger with level `'warn'` or `'error'` should
320
+ * be logged, but we should _not_ log anything with level `'info'` or `'debug'`.
321
+ *
322
+ * If we have a current log level `currentLevel` and a message with level
323
+ * `msgLevel` is passed to the logger, we can determine whether or not we should
324
+ * log it by checking if the log level on the message is further up or at the
325
+ * same level in the hierarchy than `currentLevel`, like so:
326
+ *
327
+ * ```ts
328
+ * LOG_LEVELS.indexOf(msgLevel) >= LOG_LEVELS.indexOf(currentLevel)
329
+ * ```
330
+ *
331
+ * NOTE: for the reasons described above, do not change the order of the entries
332
+ * in this array without good reason!
333
+ */
334
+ const LOG_LEVELS = ['debug', 'info', 'warn', 'error'];
335
+
320
336
  /**
321
337
  * All the Boolean options supported by the Stencil CLI
322
338
  */
@@ -794,18 +810,12 @@ const parseEqualsArg = (arg) => {
794
810
  * @param maybeLogLevel the string to check
795
811
  * @returns whether this is a `LogLevel`
796
812
  */
797
- const isLogLevel = (maybeLogLevel) =>
798
- // unfortunately `includes` is typed on `ReadonlyArray<T>` as `(el: T):
799
- // boolean` so a `string` cannot be passed to `includes` on a
800
- // `ReadonlyArray` 😢 thus we `as any`
801
- //
802
- // see microsoft/TypeScript#31018 for some discussion of this
803
- LOG_LEVELS.includes(maybeLogLevel);
813
+ const isLogLevel = (maybeLogLevel) => readOnlyArrayHasStringMember(LOG_LEVELS, maybeLogLevel);
804
814
 
805
815
  const dependencies = [
806
816
  {
807
817
  name: "@stencil/core",
808
- version: "2.17.4",
818
+ version: "2.18.1",
809
819
  main: "compiler/stencil.js",
810
820
  resources: [
811
821
  "package.json",
@@ -847,8 +857,10 @@ const dependencies = [
847
857
  "compiler/lib.es2019.symbol.d.ts",
848
858
  "compiler/lib.es2020.bigint.d.ts",
849
859
  "compiler/lib.es2020.d.ts",
860
+ "compiler/lib.es2020.date.d.ts",
850
861
  "compiler/lib.es2020.full.d.ts",
851
862
  "compiler/lib.es2020.intl.d.ts",
863
+ "compiler/lib.es2020.number.d.ts",
852
864
  "compiler/lib.es2020.promise.d.ts",
853
865
  "compiler/lib.es2020.sharedmemory.d.ts",
854
866
  "compiler/lib.es2020.string.d.ts",
@@ -859,6 +871,13 @@ const dependencies = [
859
871
  "compiler/lib.es2021.promise.d.ts",
860
872
  "compiler/lib.es2021.string.d.ts",
861
873
  "compiler/lib.es2021.weakref.d.ts",
874
+ "compiler/lib.es2022.array.d.ts",
875
+ "compiler/lib.es2022.d.ts",
876
+ "compiler/lib.es2022.error.d.ts",
877
+ "compiler/lib.es2022.full.d.ts",
878
+ "compiler/lib.es2022.intl.d.ts",
879
+ "compiler/lib.es2022.object.d.ts",
880
+ "compiler/lib.es2022.string.d.ts",
862
881
  "compiler/lib.es5.d.ts",
863
882
  "compiler/lib.es6.d.ts",
864
883
  "compiler/lib.esnext.d.ts",
@@ -908,11 +927,107 @@ const dependencies = [
908
927
  },
909
928
  {
910
929
  name: "typescript",
911
- version: "4.5.4",
930
+ version: "4.7.4",
912
931
  main: "lib/typescript.js"
913
932
  }
914
933
  ];
915
934
 
935
+ const IS_NODE_ENV = typeof global !== 'undefined' &&
936
+ typeof require === 'function' &&
937
+ !!global.process &&
938
+ typeof __filename === 'string' &&
939
+ (!global.origin || typeof global.origin !== 'string');
940
+ const IS_BROWSER_ENV = typeof location !== 'undefined' && typeof navigator !== 'undefined' && typeof XMLHttpRequest !== 'undefined';
941
+
942
+ /**
943
+ * Creates an instance of a logger
944
+ * @returns the new logger instance
945
+ */
946
+ const createLogger = () => {
947
+ let useColors = IS_BROWSER_ENV;
948
+ let level = 'info';
949
+ return {
950
+ enableColors: (uc) => (useColors = uc),
951
+ getLevel: () => level,
952
+ setLevel: (l) => (level = l),
953
+ emoji: (e) => e,
954
+ info: console.log.bind(console),
955
+ warn: console.warn.bind(console),
956
+ error: console.error.bind(console),
957
+ debug: console.debug.bind(console),
958
+ red: (msg) => msg,
959
+ green: (msg) => msg,
960
+ yellow: (msg) => msg,
961
+ blue: (msg) => msg,
962
+ magenta: (msg) => msg,
963
+ cyan: (msg) => msg,
964
+ gray: (msg) => msg,
965
+ bold: (msg) => msg,
966
+ dim: (msg) => msg,
967
+ bgRed: (msg) => msg,
968
+ createTimeSpan: (_startMsg, _debug = false) => ({
969
+ duration: () => 0,
970
+ finish: () => 0,
971
+ }),
972
+ printDiagnostics(diagnostics) {
973
+ diagnostics.forEach((diagnostic) => logDiagnostic(diagnostic, useColors));
974
+ },
975
+ };
976
+ };
977
+ const logDiagnostic = (diagnostic, useColors) => {
978
+ let color = BLUE;
979
+ let prefix = 'Build';
980
+ let msg = '';
981
+ if (diagnostic.level === 'error') {
982
+ color = RED;
983
+ prefix = 'Error';
984
+ }
985
+ else if (diagnostic.level === 'warn') {
986
+ color = YELLOW;
987
+ prefix = 'Warning';
988
+ }
989
+ if (diagnostic.header) {
990
+ prefix = diagnostic.header;
991
+ }
992
+ const filePath = diagnostic.relFilePath || diagnostic.absFilePath;
993
+ if (filePath) {
994
+ msg += filePath;
995
+ if (typeof diagnostic.lineNumber === 'number' && diagnostic.lineNumber > 0) {
996
+ msg += ', line ' + diagnostic.lineNumber;
997
+ if (typeof diagnostic.columnNumber === 'number' && diagnostic.columnNumber > 0) {
998
+ msg += ', column ' + diagnostic.columnNumber;
999
+ }
1000
+ }
1001
+ msg += '\n';
1002
+ }
1003
+ msg += diagnostic.messageText;
1004
+ if (diagnostic.lines && diagnostic.lines.length > 0) {
1005
+ diagnostic.lines.forEach((l) => {
1006
+ msg += '\n' + l.lineNumber + ': ' + l.text;
1007
+ });
1008
+ msg += '\n';
1009
+ }
1010
+ if (useColors) {
1011
+ const styledPrefix = [
1012
+ '%c' + prefix,
1013
+ `background: ${color}; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;`,
1014
+ ];
1015
+ console.log(...styledPrefix, msg);
1016
+ }
1017
+ else if (diagnostic.level === 'error') {
1018
+ console.error(msg);
1019
+ }
1020
+ else if (diagnostic.level === 'warn') {
1021
+ console.warn(msg);
1022
+ }
1023
+ else {
1024
+ console.log(msg);
1025
+ }
1026
+ };
1027
+ const YELLOW = `#f39c12`;
1028
+ const RED = `#c0392b`;
1029
+ const BLUE = `#3498db`;
1030
+
916
1031
  /**
917
1032
  * Attempt to find a Stencil configuration file on the file system
918
1033
  * @param opts the options needed to find the configuration file
@@ -921,11 +1036,7 @@ const dependencies = [
921
1036
  const findConfig = async (opts) => {
922
1037
  const sys = opts.sys;
923
1038
  const cwd = sys.getCurrentDirectory();
924
- const results = {
925
- configPath: null,
926
- rootDir: normalizePath(cwd),
927
- diagnostics: [],
928
- };
1039
+ const rootDir = normalizePath(cwd);
929
1040
  let configPath = opts.configPath;
930
1041
  if (isString(configPath)) {
931
1042
  if (!sys.platformPath.isAbsolute(configPath)) {
@@ -940,8 +1051,13 @@ const findConfig = async (opts) => {
940
1051
  }
941
1052
  else {
942
1053
  // nothing was passed in, use the current working directory
943
- configPath = results.rootDir;
1054
+ configPath = rootDir;
944
1055
  }
1056
+ const results = {
1057
+ configPath,
1058
+ rootDir: normalizePath(cwd),
1059
+ diagnostics: [],
1060
+ };
945
1061
  const stat = await sys.stat(configPath);
946
1062
  if (stat.error) {
947
1063
  const diagnostic = buildError(results.diagnostics);
@@ -974,12 +1090,33 @@ const loadCoreCompiler = async (sys) => {
974
1090
  return globalThis.stencil;
975
1091
  };
976
1092
 
1093
+ /**
1094
+ * Log the name of this package (`@stencil/core`) to an output stream
1095
+ *
1096
+ * The output stream is determined by the {@link Logger} instance that is provided as an argument to this function
1097
+ *
1098
+ * The name of the package may not be logged, by design, for certain `task` types and logging levels
1099
+ *
1100
+ * @param logger the logging entity to use to output the name of the package
1101
+ * @param task the current task
1102
+ */
977
1103
  const startupLog = (logger, task) => {
978
1104
  if (task === 'info' || task === 'serve' || task === 'version') {
979
1105
  return;
980
1106
  }
981
1107
  logger.info(logger.cyan(`@stencil/core`));
982
1108
  };
1109
+ /**
1110
+ * Log this package's version to an output stream
1111
+ *
1112
+ * The output stream is determined by the {@link Logger} instance that is provided as an argument to this function
1113
+ *
1114
+ * The package version may not be logged, by design, for certain `task` types and logging levels
1115
+ *
1116
+ * @param logger the logging entity to use for output
1117
+ * @param task the current task
1118
+ * @param coreCompiler the compiler instance to derive version information from
1119
+ */
983
1120
  const startupLogVersion = (logger, task, coreCompiler) => {
984
1121
  if (task === 'info' || task === 'serve' || task === 'version') {
985
1122
  return;
@@ -995,11 +1132,25 @@ const startupLogVersion = (logger, task, coreCompiler) => {
995
1132
  startupMsg += logger.emoji(' ' + coreCompiler.vermoji);
996
1133
  logger.info(startupMsg);
997
1134
  };
1135
+ /**
1136
+ * Log details from a {@link CompilerSystem} used by Stencil to an output stream
1137
+ *
1138
+ * The output stream is determined by the {@link Logger} instance that is provided as an argument to this function
1139
+ *
1140
+ * @param sys the `CompilerSystem` to report details on
1141
+ * @param logger the logging entity to use for output
1142
+ * @param flags user set flags for the current invocation of Stencil
1143
+ * @param coreCompiler the compiler instance being used for this invocation of Stencil
1144
+ */
998
1145
  const loadedCompilerLog = (sys, logger, flags, coreCompiler) => {
999
1146
  const sysDetails = sys.details;
1000
1147
  const runtimeInfo = `${sys.name} ${sys.version}`;
1001
- const platformInfo = `${sysDetails.platform}, ${sysDetails.cpuModel}`;
1002
- const statsInfo = `cpus: ${sys.hardwareConcurrency}, freemem: ${Math.round(sysDetails.freemem() / 1000000)}MB, totalmem: ${Math.round(sysDetails.totalmem / 1000000)}MB`;
1148
+ const platformInfo = sysDetails
1149
+ ? `${sysDetails.platform}, ${sysDetails.cpuModel}`
1150
+ : `Unknown Platform, Unknown CPU Model`;
1151
+ const statsInfo = sysDetails
1152
+ ? `cpus: ${sys.hardwareConcurrency}, freemem: ${Math.round(sysDetails.freemem() / 1000000)}MB, totalmem: ${Math.round(sysDetails.totalmem / 1000000)}MB`
1153
+ : 'Unknown CPU Core Count, Unknown Memory';
1003
1154
  if (logger.getLevel() === 'debug') {
1004
1155
  logger.debug(runtimeInfo);
1005
1156
  logger.debug(platformInfo);
@@ -1013,6 +1164,14 @@ const loadedCompilerLog = (sys, logger, flags, coreCompiler) => {
1013
1164
  logger.info(statsInfo);
1014
1165
  }
1015
1166
  };
1167
+ /**
1168
+ * Log various warnings to an output stream
1169
+ *
1170
+ * The output stream is determined by the {@link Logger} instance attached to the `config` argument to this function
1171
+ *
1172
+ * @param coreCompiler the compiler instance being used for this invocation of Stencil
1173
+ * @param config a validated configuration object to be used for this run of Stencil
1174
+ */
1016
1175
  const startupCompilerLog = (coreCompiler, config) => {
1017
1176
  if (config.suppressLogs === true) {
1018
1177
  return;
@@ -1034,6 +1193,21 @@ const startupCompilerLog = (coreCompiler, config) => {
1034
1193
  }
1035
1194
  };
1036
1195
 
1196
+ const startCheckVersion = async (config, currentVersion) => {
1197
+ if (config.devMode && !config.flags.ci && !currentVersion.includes('-dev.') && isFunction(config.sys.checkVersion)) {
1198
+ return config.sys.checkVersion(config.logger, currentVersion);
1199
+ }
1200
+ return null;
1201
+ };
1202
+ const printCheckVersionResults = async (versionChecker) => {
1203
+ if (versionChecker) {
1204
+ const checkVersionResults = await versionChecker;
1205
+ if (isFunction(checkVersionResults)) {
1206
+ checkVersionResults();
1207
+ }
1208
+ }
1209
+ };
1210
+
1037
1211
  const taskPrerender = async (coreCompiler, config) => {
1038
1212
  startupCompilerLog(coreCompiler, config);
1039
1213
  const hydrateAppFilePath = config.flags.unknownArgs[0];
@@ -1065,21 +1239,6 @@ const runPrerenderTask = async (coreCompiler, config, hydrateAppFilePath, compon
1065
1239
  return diagnostics;
1066
1240
  };
1067
1241
 
1068
- const startCheckVersion = async (config, currentVersion) => {
1069
- if (config.devMode && !config.flags.ci && !currentVersion.includes('-dev.') && isFunction(config.sys.checkVersion)) {
1070
- return config.sys.checkVersion(config.logger, currentVersion);
1071
- }
1072
- return null;
1073
- };
1074
- const printCheckVersionResults = async (versionChecker) => {
1075
- if (versionChecker) {
1076
- const checkVersionResults = await versionChecker;
1077
- if (isFunction(checkVersionResults)) {
1078
- checkVersionResults();
1079
- }
1080
- }
1081
- };
1082
-
1083
1242
  const taskWatch = async (coreCompiler, config) => {
1084
1243
  let devServer = null;
1085
1244
  let exitCode = 0;
@@ -1126,6 +1285,15 @@ const taskWatch = async (coreCompiler, config) => {
1126
1285
  }
1127
1286
  };
1128
1287
 
1288
+ const isOutputTargetHydrate = (o) => o.type === DIST_HYDRATE_SCRIPT;
1289
+ const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
1290
+ const DIST_HYDRATE_SCRIPT = 'dist-hydrate-script';
1291
+ const DOCS_CUSTOM = 'docs-custom';
1292
+ const DOCS_JSON = 'docs-json';
1293
+ const DOCS_README = 'docs-readme';
1294
+ const DOCS_VSCODE = 'docs-vscode';
1295
+ const WWW = 'www';
1296
+
1129
1297
  const tryFn = async (fn, ...args) => {
1130
1298
  try {
1131
1299
  return await fn(...args);
@@ -1139,7 +1307,7 @@ const isInteractive = (sys, flags, object) => {
1139
1307
  const terminalInfo = object ||
1140
1308
  Object.freeze({
1141
1309
  tty: sys.isTTY() ? true : false,
1142
- ci: ['CI', 'BUILD_ID', 'BUILD_NUMBER', 'BITBUCKET_COMMIT', 'CODEBUILD_BUILD_ARN'].filter((v) => !!sys.getEnvironmentVar(v)).length > 0 || !!flags.ci,
1310
+ ci: ['CI', 'BUILD_ID', 'BUILD_NUMBER', 'BITBUCKET_COMMIT', 'CODEBUILD_BUILD_ARN'].filter((v) => { var _a; return !!((_a = sys.getEnvironmentVar) === null || _a === void 0 ? void 0 : _a.call(sys, v)); }).length > 0 || !!flags.ci,
1143
1311
  });
1144
1312
  return terminalInfo.tty && !terminalInfo.ci;
1145
1313
  };
@@ -1168,7 +1336,7 @@ async function readJson(sys, path) {
1168
1336
  * @returns true if --debug has been passed, otherwise false
1169
1337
  */
1170
1338
  function hasDebug(flags) {
1171
- return flags.debug;
1339
+ return !!flags.debug;
1172
1340
  }
1173
1341
  /**
1174
1342
  * Does the command have the verbose and debug flags?
@@ -1176,18 +1344,7 @@ function hasDebug(flags) {
1176
1344
  * @returns true if both --debug and --verbose have been passed, otherwise false
1177
1345
  */
1178
1346
  function hasVerbose(flags) {
1179
- return flags.verbose && hasDebug(flags);
1180
- }
1181
-
1182
- /**
1183
- * Used to determine if tracking should occur.
1184
- * @param config The config passed into the Stencil command
1185
- * @param sys The system where the command is invoked
1186
- * @param ci whether or not the process is running in a Continuous Integration (CI) environment
1187
- * @returns true if telemetry should be sent, false otherwise
1188
- */
1189
- async function shouldTrack(config, sys, ci) {
1190
- return !ci && isInteractive(sys, config.flags) && (await checkTelemetry(sys));
1347
+ return !!flags.verbose && hasDebug(flags);
1191
1348
  }
1192
1349
 
1193
1350
  const isTest$1 = () => process.env.JEST_WORKER_ID !== undefined;
@@ -1208,7 +1365,7 @@ async function readConfig(sys) {
1208
1365
  };
1209
1366
  await writeConfig(sys, config);
1210
1367
  }
1211
- else if (!UUID_REGEX.test(config['tokens.telemetry'])) {
1368
+ else if (!config['tokens.telemetry'] || !UUID_REGEX.test(config['tokens.telemetry'])) {
1212
1369
  const newUuid = uuidv4();
1213
1370
  await writeConfig(sys, { ...config, 'tokens.telemetry': newUuid });
1214
1371
  config['tokens.telemetry'] = newUuid;
@@ -1244,14 +1401,16 @@ async function updateConfig(sys, newOptions) {
1244
1401
  return await writeConfig(sys, Object.assign(config, newOptions));
1245
1402
  }
1246
1403
 
1247
- const isOutputTargetHydrate = (o) => o.type === DIST_HYDRATE_SCRIPT;
1248
- const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
1249
- const DIST_HYDRATE_SCRIPT = 'dist-hydrate-script';
1250
- const DOCS_CUSTOM = 'docs-custom';
1251
- const DOCS_JSON = 'docs-json';
1252
- const DOCS_README = 'docs-readme';
1253
- const DOCS_VSCODE = 'docs-vscode';
1254
- const WWW = 'www';
1404
+ /**
1405
+ * Used to determine if tracking should occur.
1406
+ * @param config The config passed into the Stencil command
1407
+ * @param sys The system where the command is invoked
1408
+ * @param ci whether or not the process is running in a Continuous Integration (CI) environment
1409
+ * @returns true if telemetry should be sent, false otherwise
1410
+ */
1411
+ async function shouldTrack(config, sys, ci) {
1412
+ return !ci && isInteractive(sys, config.flags) && (await checkTelemetry(sys));
1413
+ }
1255
1414
 
1256
1415
  /**
1257
1416
  * Used to within taskBuild to provide the component_count property.
@@ -1262,11 +1421,11 @@ const WWW = 'www';
1262
1421
  * @param result The results of a compiler build.
1263
1422
  */
1264
1423
  async function telemetryBuildFinishedAction(sys, config, coreCompiler, result) {
1265
- const tracking = await shouldTrack(config, sys, config.flags.ci);
1424
+ const tracking = await shouldTrack(config, sys, !!config.flags.ci);
1266
1425
  if (!tracking) {
1267
1426
  return;
1268
1427
  }
1269
- const component_count = Object.keys(result.componentGraph).length;
1428
+ const component_count = result.componentGraph ? Object.keys(result.componentGraph).length : undefined;
1270
1429
  const data = await prepareData(coreCompiler, config, sys, result.duration, component_count);
1271
1430
  await sendMetric(sys, config, 'stencil_cli_command', data);
1272
1431
  config.logger.debug(`${config.logger.blue('Telemetry')}: ${config.logger.gray(JSON.stringify(data))}`);
@@ -1345,15 +1504,16 @@ function getActiveTargets(config) {
1345
1504
  * @returns a Promise wrapping data for the telemetry endpoint
1346
1505
  */
1347
1506
  const prepareData = async (coreCompiler, config, sys, duration_ms, component_count = undefined) => {
1507
+ var _a, _b, _c;
1348
1508
  const { typescript, rollup } = coreCompiler.versions || { typescript: 'unknown', rollup: 'unknown' };
1349
1509
  const { packages, packagesNoVersions } = await getInstalledPackages(sys, config);
1350
1510
  const targets = getActiveTargets(config);
1351
1511
  const yarn = isUsingYarn(sys);
1352
1512
  const stencil = coreCompiler.version || 'unknown';
1353
1513
  const system = `${sys.name} ${sys.version}`;
1354
- const os_name = sys.details.platform;
1355
- const os_version = sys.details.release;
1356
- const cpu_model = sys.details.cpuModel;
1514
+ const os_name = (_a = sys.details) === null || _a === void 0 ? void 0 : _a.platform;
1515
+ const os_version = (_b = sys.details) === null || _b === void 0 ? void 0 : _b.release;
1516
+ const cpu_model = (_c = sys.details) === null || _c === void 0 ? void 0 : _c.cpuModel;
1357
1517
  const build = coreCompiler.buildId || 'unknown';
1358
1518
  const has_app_pwa_config = hasAppTarget(config);
1359
1519
  const anonymizedConfig = anonymizeConfigForTelemetry(config);
@@ -1683,13 +1843,6 @@ const taskDocs = async (coreCompiler, config) => {
1683
1843
  await compiler.destroy();
1684
1844
  };
1685
1845
 
1686
- const IS_NODE_ENV = typeof global !== 'undefined' &&
1687
- typeof require === 'function' &&
1688
- !!global.process &&
1689
- typeof __filename === 'string' &&
1690
- (!global.origin || typeof global.origin !== 'string');
1691
- const IS_BROWSER_ENV = typeof location !== 'undefined' && typeof navigator !== 'undefined' && typeof XMLHttpRequest !== 'undefined';
1692
-
1693
1846
  /**
1694
1847
  * Task to generate component boilerplate and write it to disk. This task can
1695
1848
  * cause the program to exit with an error under various circumstances, such as
@@ -1950,7 +2103,7 @@ const taskTelemetry = async (flags, sys, logger) => {
1950
2103
  const prompt = logger.dim(sys.details.platform === 'windows' ? '>' : '$');
1951
2104
  const isEnabling = flags.args.includes('on');
1952
2105
  const isDisabling = flags.args.includes('off');
1953
- 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')}`;
2106
+ const INFORMATION = `Opt in or out of telemetry. Information about the data we collect is available on our website: ${logger.bold('https://stenciljs.com/telemetry')}`;
1954
2107
  const THANK_YOU = `Thank you for helping to make Stencil better! 💖`;
1955
2108
  const ENABLED_MESSAGE = `${logger.green('Enabled')}. ${THANK_YOU}\n\n`;
1956
2109
  const DISABLED_MESSAGE = `${logger.red('Disabled')}\n\n`;
@@ -2081,32 +2234,32 @@ const taskTest = async (config) => {
2081
2234
  config.logger.error(`"test" command is currently only implemented for a NodeJS environment`);
2082
2235
  return config.sys.exit(1);
2083
2236
  }
2084
- try {
2085
- config.buildDocs = false;
2086
- const testingRunOpts = {
2087
- e2e: !!config.flags.e2e,
2088
- screenshot: !!config.flags.screenshot,
2089
- spec: !!config.flags.spec,
2090
- updateScreenshot: !!config.flags.updateScreenshot,
2091
- };
2092
- // always ensure we have jest modules installed
2093
- const ensureModuleIds = ['@types/jest', 'jest', 'jest-cli'];
2094
- if (testingRunOpts.e2e) {
2095
- // if it's an e2e test, also make sure we're got
2096
- // puppeteer modules installed and if browserExecutablePath is provided don't download Chromium use only puppeteer-core instead
2097
- const puppeteer = config.testing.browserExecutablePath ? 'puppeteer-core' : 'puppeteer';
2098
- ensureModuleIds.push(puppeteer);
2099
- if (testingRunOpts.screenshot) {
2100
- // ensure we've got pixelmatch for screenshots
2101
- config.logger.warn(config.logger.yellow(`EXPERIMENTAL: screenshot visual diff testing is currently under heavy development and has not reached a stable status. However, any assistance testing would be appreciated.`));
2102
- }
2103
- }
2104
- // ensure we've got the required modules installed
2105
- const diagnostics = await config.sys.lazyRequire.ensure(config.rootDir, ensureModuleIds);
2106
- if (diagnostics.length > 0) {
2107
- config.logger.printDiagnostics(diagnostics);
2108
- return config.sys.exit(1);
2237
+ config.buildDocs = false;
2238
+ const testingRunOpts = {
2239
+ e2e: !!config.flags.e2e,
2240
+ screenshot: !!config.flags.screenshot,
2241
+ spec: !!config.flags.spec,
2242
+ updateScreenshot: !!config.flags.updateScreenshot,
2243
+ };
2244
+ // always ensure we have jest modules installed
2245
+ const ensureModuleIds = ['@types/jest', 'jest', 'jest-cli'];
2246
+ if (testingRunOpts.e2e) {
2247
+ // if it's an e2e test, also make sure we're got
2248
+ // puppeteer modules installed and if browserExecutablePath is provided don't download Chromium use only puppeteer-core instead
2249
+ const puppeteer = config.testing.browserExecutablePath ? 'puppeteer-core' : 'puppeteer';
2250
+ ensureModuleIds.push(puppeteer);
2251
+ if (testingRunOpts.screenshot) {
2252
+ // ensure we've got pixelmatch for screenshots
2253
+ config.logger.warn(config.logger.yellow(`EXPERIMENTAL: screenshot visual diff testing is currently under heavy development and has not reached a stable status. However, any assistance testing would be appreciated.`));
2109
2254
  }
2255
+ }
2256
+ // ensure we've got the required modules installed
2257
+ const diagnostics = await config.sys.lazyRequire.ensure(config.rootDir, ensureModuleIds);
2258
+ if (diagnostics.length > 0) {
2259
+ config.logger.printDiagnostics(diagnostics);
2260
+ return config.sys.exit(1);
2261
+ }
2262
+ try {
2110
2263
  // let's test!
2111
2264
  const { createTesting } = await import('../testing/index.js');
2112
2265
  const testing = await createTesting(config);
@@ -2122,95 +2275,6 @@ const taskTest = async (config) => {
2122
2275
  }
2123
2276
  };
2124
2277
 
2125
- /**
2126
- * Creates an instance of a logger
2127
- * @returns the new logger instance
2128
- */
2129
- const createLogger = () => {
2130
- let useColors = IS_BROWSER_ENV;
2131
- let level = 'info';
2132
- return {
2133
- enableColors: (uc) => (useColors = uc),
2134
- getLevel: () => level,
2135
- setLevel: (l) => (level = l),
2136
- emoji: (e) => e,
2137
- info: console.log.bind(console),
2138
- warn: console.warn.bind(console),
2139
- error: console.error.bind(console),
2140
- debug: console.debug.bind(console),
2141
- red: (msg) => msg,
2142
- green: (msg) => msg,
2143
- yellow: (msg) => msg,
2144
- blue: (msg) => msg,
2145
- magenta: (msg) => msg,
2146
- cyan: (msg) => msg,
2147
- gray: (msg) => msg,
2148
- bold: (msg) => msg,
2149
- dim: (msg) => msg,
2150
- bgRed: (msg) => msg,
2151
- createTimeSpan: (_startMsg, _debug = false) => ({
2152
- duration: () => 0,
2153
- finish: () => 0,
2154
- }),
2155
- printDiagnostics(diagnostics) {
2156
- diagnostics.forEach((diagnostic) => logDiagnostic(diagnostic, useColors));
2157
- },
2158
- };
2159
- };
2160
- const logDiagnostic = (diagnostic, useColors) => {
2161
- let color = BLUE;
2162
- let prefix = 'Build';
2163
- let msg = '';
2164
- if (diagnostic.level === 'error') {
2165
- color = RED;
2166
- prefix = 'Error';
2167
- }
2168
- else if (diagnostic.level === 'warn') {
2169
- color = YELLOW;
2170
- prefix = 'Warning';
2171
- }
2172
- if (diagnostic.header) {
2173
- prefix = diagnostic.header;
2174
- }
2175
- const filePath = diagnostic.relFilePath || diagnostic.absFilePath;
2176
- if (filePath) {
2177
- msg += filePath;
2178
- if (typeof diagnostic.lineNumber === 'number' && diagnostic.lineNumber > 0) {
2179
- msg += ', line ' + diagnostic.lineNumber;
2180
- if (typeof diagnostic.columnNumber === 'number' && diagnostic.columnNumber > 0) {
2181
- msg += ', column ' + diagnostic.columnNumber;
2182
- }
2183
- }
2184
- msg += '\n';
2185
- }
2186
- msg += diagnostic.messageText;
2187
- if (diagnostic.lines && diagnostic.lines.length > 0) {
2188
- diagnostic.lines.forEach((l) => {
2189
- msg += '\n' + l.lineNumber + ': ' + l.text;
2190
- });
2191
- msg += '\n';
2192
- }
2193
- if (useColors) {
2194
- const styledPrefix = [
2195
- '%c' + prefix,
2196
- `background: ${color}; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;`,
2197
- ];
2198
- console.log(...styledPrefix, msg);
2199
- }
2200
- else if (diagnostic.level === 'error') {
2201
- console.error(msg);
2202
- }
2203
- else if (diagnostic.level === 'warn') {
2204
- console.warn(msg);
2205
- }
2206
- else {
2207
- console.log(msg);
2208
- }
2209
- };
2210
- const YELLOW = `#f39c12`;
2211
- const RED = `#c0392b`;
2212
- const BLUE = `#3498db`;
2213
-
2214
2278
  const run = async (init) => {
2215
2279
  const { args, logger, sys } = init;
2216
2280
  try {
@@ -2225,7 +2289,7 @@ const run = async (init) => {
2225
2289
  if (isFunction(sys.applyGlobalPatch)) {
2226
2290
  sys.applyGlobalPatch(sys.getCurrentDirectory());
2227
2291
  }
2228
- if (task === 'help' || flags.help) {
2292
+ if (!task || task === 'help' || flags.help) {
2229
2293
  await taskHelp(createConfigFlags({ task: 'help', args }), logger, sys);
2230
2294
  return;
2231
2295
  }
@@ -2294,15 +2358,16 @@ const run = async (init) => {
2294
2358
  * @public
2295
2359
  */
2296
2360
  const runTask = async (coreCompiler, config, task, sys) => {
2297
- var _a, _b, _c, _d, _e;
2361
+ var _a, _b, _c, _d, _e, _f;
2298
2362
  const logger = (_a = config.logger) !== null && _a !== void 0 ? _a : createLogger();
2299
2363
  const strictConfig = {
2300
2364
  ...config,
2301
2365
  flags: createConfigFlags((_b = config.flags) !== null && _b !== void 0 ? _b : { task }),
2302
2366
  logger,
2303
2367
  outputTargets: (_c = config.outputTargets) !== null && _c !== void 0 ? _c : [],
2304
- sys: (_d = sys !== null && sys !== void 0 ? sys : config.sys) !== null && _d !== void 0 ? _d : coreCompiler.createSystem({ logger }),
2305
- testing: (_e = config.testing) !== null && _e !== void 0 ? _e : {},
2368
+ rootDir: (_d = config.rootDir) !== null && _d !== void 0 ? _d : '/',
2369
+ sys: (_e = sys !== null && sys !== void 0 ? sys : config.sys) !== null && _e !== void 0 ? _e : coreCompiler.createSystem({ logger }),
2370
+ testing: (_f = config.testing) !== null && _f !== void 0 ? _f : {},
2306
2371
  };
2307
2372
  switch (task) {
2308
2373
  case 'build':