@stencil/core 2.16.1 → 2.17.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 (39) hide show
  1. package/cli/index.cjs +96 -6
  2. package/cli/index.js +96 -6
  3. package/cli/package.json +1 -1
  4. package/compiler/package.json +1 -1
  5. package/compiler/stencil.js +524 -121
  6. package/compiler/stencil.min.js +2 -2
  7. package/dependencies.json +1 -1
  8. package/dev-server/client/index.js +1 -1
  9. package/dev-server/client/package.json +1 -1
  10. package/dev-server/connector.html +2 -2
  11. package/dev-server/index.js +1 -1
  12. package/dev-server/package.json +1 -1
  13. package/dev-server/server-process.js +2 -2
  14. package/internal/app-data/package.json +1 -1
  15. package/internal/client/css-shim.js +1 -1
  16. package/internal/client/dom.js +1 -1
  17. package/internal/client/index.js +1 -1
  18. package/internal/client/package.json +1 -1
  19. package/internal/client/patch-browser.js +1 -1
  20. package/internal/client/patch-esm.js +1 -1
  21. package/internal/client/shadow-css.js +1 -1
  22. package/internal/hydrate/package.json +1 -1
  23. package/internal/package.json +1 -1
  24. package/internal/stencil-private.d.ts +4 -0
  25. package/internal/stencil-public-compiler.d.ts +2 -2
  26. package/internal/testing/package.json +1 -1
  27. package/mock-doc/index.cjs +140 -5
  28. package/mock-doc/index.d.ts +76 -1
  29. package/mock-doc/index.js +140 -5
  30. package/mock-doc/package.json +1 -1
  31. package/package.json +1 -1
  32. package/screenshot/package.json +1 -1
  33. package/sys/node/index.js +325 -314
  34. package/sys/node/package.json +1 -1
  35. package/sys/node/worker.js +1 -1
  36. package/testing/index.d.ts +1 -1
  37. package/testing/index.js +406 -367
  38. package/testing/mocks.d.ts +22 -2
  39. package/testing/package.json +1 -1
package/cli/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil CLI (CommonJS) v2.16.1 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI (CommonJS) v2.17.0 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  'use strict';
5
5
 
@@ -532,7 +532,7 @@ const getNpmConfigEnvArgs = (sys) => {
532
532
  const dependencies = [
533
533
  {
534
534
  name: "@stencil/core",
535
- version: "2.16.1",
535
+ version: "2.17.0",
536
536
  main: "compiler/stencil.js",
537
537
  resources: [
538
538
  "package.json",
@@ -967,7 +967,9 @@ async function updateConfig(sys, newOptions) {
967
967
  return await writeConfig(sys, Object.assign(config, newOptions));
968
968
  }
969
969
 
970
+ const isOutputTargetHydrate = (o) => o.type === DIST_HYDRATE_SCRIPT;
970
971
  const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
972
+ const DIST_HYDRATE_SCRIPT = 'dist-hydrate-script';
971
973
  const DOCS_CUSTOM = 'docs-custom';
972
974
  const DOCS_JSON = 'docs-json';
973
975
  const DOCS_README = 'docs-readme';
@@ -995,6 +997,7 @@ async function telemetryBuildFinishedAction(sys, config, logger, coreCompiler, r
995
997
  }
996
998
  /**
997
999
  * A function to wrap a compiler task function around. Will send telemetry if, and only if, the machine allows.
1000
+ *
998
1001
  * @param sys The system where the command is invoked
999
1002
  * @param config The config passed into the Stencil command
1000
1003
  * @param logger The tool used to do logging
@@ -1040,6 +1043,16 @@ async function getActiveTargets(config) {
1040
1043
  const result = config.outputTargets.map((t) => t.type);
1041
1044
  return Array.from(new Set(result));
1042
1045
  }
1046
+ /**
1047
+ * Prepare data for telemetry
1048
+ *
1049
+ * @param coreCompiler the core compiler
1050
+ * @param config the current Stencil config
1051
+ * @param sys the compiler system instance in use
1052
+ * @param duration_ms the duration of the action being tracked
1053
+ * @param component_count the number of components being built (optional)
1054
+ * @returns a Promise wrapping data for the telemetry endpoint
1055
+ */
1043
1056
  const prepareData = async (coreCompiler, config, sys, duration_ms, component_count = undefined) => {
1044
1057
  const { typescript, rollup } = coreCompiler.versions || { typescript: 'unknown', rollup: 'unknown' };
1045
1058
  const { packages, packagesNoVersions } = await getInstalledPackages(sys, config);
@@ -1052,6 +1065,7 @@ const prepareData = async (coreCompiler, config, sys, duration_ms, component_cou
1052
1065
  const cpu_model = sys.details.cpuModel;
1053
1066
  const build = coreCompiler.buildId || 'unknown';
1054
1067
  const has_app_pwa_config = hasAppTarget(config);
1068
+ const anonymizedConfig = anonymizeConfigForTelemetry(config);
1055
1069
  return {
1056
1070
  yarn,
1057
1071
  duration_ms,
@@ -1071,12 +1085,83 @@ const prepareData = async (coreCompiler, config, sys, duration_ms, component_cou
1071
1085
  typescript,
1072
1086
  rollup,
1073
1087
  has_app_pwa_config,
1088
+ config: anonymizedConfig,
1074
1089
  };
1075
1090
  };
1091
+ // props in output targets for which we retain their original values when
1092
+ // preparing a config for telemetry
1093
+ //
1094
+ // we omit the values of all other fields on output targets.
1095
+ const OUTPUT_TARGET_KEYS_TO_KEEP = ['type'];
1096
+ // top-level config props that we anonymize for telemetry
1097
+ const CONFIG_PROPS_TO_ANONYMIZE = [
1098
+ 'rootDir',
1099
+ 'fsNamespace',
1100
+ 'packageJsonFilePath',
1101
+ 'namespace',
1102
+ 'srcDir',
1103
+ 'srcIndexHtml',
1104
+ 'buildLogFilePath',
1105
+ 'cacheDir',
1106
+ 'configPath',
1107
+ 'tsconfig',
1108
+ ];
1109
+ // Props we delete entirely from the config for telemetry
1110
+ //
1111
+ // TODO(STENCIL-469): Investigate improving anonymization for tsCompilerOptions and devServer
1112
+ const CONFIG_PROPS_TO_DELETE = ['sys', 'logger', 'tsCompilerOptions', 'devServer'];
1113
+ /**
1114
+ * Anonymize the config for telemetry, replacing potentially revealing config props
1115
+ * with a placeholder string if they are present (this lets us still track how frequently
1116
+ * these config options are being used)
1117
+ *
1118
+ * @param config the config to anonymize
1119
+ * @returns an anonymized copy of the same config
1120
+ */
1121
+ const anonymizeConfigForTelemetry = (config) => {
1122
+ var _a;
1123
+ const anonymizedConfig = { ...config };
1124
+ for (const prop of CONFIG_PROPS_TO_ANONYMIZE) {
1125
+ if (anonymizedConfig[prop] !== undefined) {
1126
+ anonymizedConfig[prop] = 'omitted';
1127
+ }
1128
+ }
1129
+ anonymizedConfig.outputTargets = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).map((target) => {
1130
+ // Anonymize the outputTargets on our configuration, taking advantage of the
1131
+ // optional 2nd argument to `JSON.stringify`. If anything is not a string
1132
+ // we retain it so that any nested properties are handled, else we check
1133
+ // whether it's in our 'keep' list to decide whether to keep it or replace it
1134
+ // with `"omitted"`.
1135
+ const anonymizedOT = JSON.parse(JSON.stringify(target, (key, value) => {
1136
+ if (!(typeof value === 'string')) {
1137
+ return value;
1138
+ }
1139
+ if (OUTPUT_TARGET_KEYS_TO_KEEP.includes(key)) {
1140
+ return value;
1141
+ }
1142
+ return 'omitted';
1143
+ }));
1144
+ // this prop has to be handled separately because it is an array
1145
+ // so the replace function above will be called with all of its
1146
+ // members, giving us `["omitted", "omitted", ...]`.
1147
+ //
1148
+ // Instead, we check for its presence and manually copy over.
1149
+ if (isOutputTargetHydrate(target) && target.external) {
1150
+ anonymizedOT['external'] = target.external.concat();
1151
+ }
1152
+ return anonymizedOT;
1153
+ });
1154
+ // TODO(STENCIL-469): Investigate improving anonymization for tsCompilerOptions and devServer
1155
+ for (const prop of CONFIG_PROPS_TO_DELETE) {
1156
+ delete anonymizedConfig[prop];
1157
+ }
1158
+ return anonymizedConfig;
1159
+ };
1076
1160
  /**
1077
1161
  * Reads package-lock.json, yarn.lock, and package.json files in order to cross-reference
1078
1162
  * the dependencies and devDependencies properties. Pulls up the current installed version
1079
1163
  * of each package under the @stencil, @ionic, and @capacitor scopes.
1164
+ *
1080
1165
  * @param sys the system instance where telemetry is invoked
1081
1166
  * @param config the Stencil configuration associated with the current task that triggered telemetry
1082
1167
  * @returns an object listing all dev and production dependencies under the aforementioned scopes
@@ -1159,6 +1244,7 @@ function sanitizeDeclaredVersion(version) {
1159
1244
  }
1160
1245
  /**
1161
1246
  * If telemetry is enabled, send a metric to an external data store
1247
+ *
1162
1248
  * @param sys the system instance where telemetry is invoked
1163
1249
  * @param config the Stencil configuration associated with the current task that triggered telemetry
1164
1250
  * @param name the name of a trackable metric. Note this name is not necessarily a scalar value to track, like
@@ -1174,10 +1260,11 @@ async function sendMetric(sys, config, name, value) {
1174
1260
  value,
1175
1261
  session_id,
1176
1262
  };
1177
- await sendTelemetry(sys, config, { type: 'telemetry', message });
1263
+ await sendTelemetry(sys, config, message);
1178
1264
  }
1179
1265
  /**
1180
1266
  * Used to read the config file's tokens.telemetry property.
1267
+ *
1181
1268
  * @param sys The system where the command is invoked
1182
1269
  * @returns string
1183
1270
  */
@@ -1199,7 +1286,7 @@ async function sendTelemetry(sys, config, data) {
1199
1286
  try {
1200
1287
  const now = new Date().toISOString();
1201
1288
  const body = {
1202
- metrics: [data.message],
1289
+ metrics: [data],
1203
1290
  sent_at: now,
1204
1291
  };
1205
1292
  // This request is only made if telemetry is on.
@@ -1211,7 +1298,7 @@ async function sendTelemetry(sys, config, data) {
1211
1298
  body: JSON.stringify(body),
1212
1299
  });
1213
1300
  hasVerbose(config) &&
1214
- console.debug('\nSent %O metric to events service (status: %O)', data.message.name, response.status, '\n');
1301
+ console.debug('\nSent %O metric to events service (status: %O)', data.name, response.status, '\n');
1215
1302
  if (response.status !== 204) {
1216
1303
  hasVerbose(config) &&
1217
1304
  console.debug('\nBad response from events service. Request body: %O', response.body.toString(), '\n');
@@ -1362,7 +1449,10 @@ const taskGenerate = async (coreCompiler, config) => {
1362
1449
  if (!writtenFiles) {
1363
1450
  return config.sys.exit(1);
1364
1451
  }
1365
- // TODO(STENCIL-424): Investigate moving these console.log calls to config.logger.info
1452
+ // We use `console.log` here rather than our `config.logger` because we don't want
1453
+ // our TUI messages to be prefixed with timestamps and so on.
1454
+ //
1455
+ // See STENCIL-424 for details.
1366
1456
  console.log();
1367
1457
  console.log(`${config.logger.gray('$')} stencil generate ${input}`);
1368
1458
  console.log();
package/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil CLI v2.16.1 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI v2.17.0 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  const toLowerCase = (str) => str.toLowerCase();
5
5
  const dashToPascalCase = (str) => toLowerCase(str)
@@ -508,7 +508,7 @@ const getNpmConfigEnvArgs = (sys) => {
508
508
  const dependencies = [
509
509
  {
510
510
  name: "@stencil/core",
511
- version: "2.16.1",
511
+ version: "2.17.0",
512
512
  main: "compiler/stencil.js",
513
513
  resources: [
514
514
  "package.json",
@@ -943,7 +943,9 @@ async function updateConfig(sys, newOptions) {
943
943
  return await writeConfig(sys, Object.assign(config, newOptions));
944
944
  }
945
945
 
946
+ const isOutputTargetHydrate = (o) => o.type === DIST_HYDRATE_SCRIPT;
946
947
  const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
948
+ const DIST_HYDRATE_SCRIPT = 'dist-hydrate-script';
947
949
  const DOCS_CUSTOM = 'docs-custom';
948
950
  const DOCS_JSON = 'docs-json';
949
951
  const DOCS_README = 'docs-readme';
@@ -971,6 +973,7 @@ async function telemetryBuildFinishedAction(sys, config, logger, coreCompiler, r
971
973
  }
972
974
  /**
973
975
  * A function to wrap a compiler task function around. Will send telemetry if, and only if, the machine allows.
976
+ *
974
977
  * @param sys The system where the command is invoked
975
978
  * @param config The config passed into the Stencil command
976
979
  * @param logger The tool used to do logging
@@ -1016,6 +1019,16 @@ async function getActiveTargets(config) {
1016
1019
  const result = config.outputTargets.map((t) => t.type);
1017
1020
  return Array.from(new Set(result));
1018
1021
  }
1022
+ /**
1023
+ * Prepare data for telemetry
1024
+ *
1025
+ * @param coreCompiler the core compiler
1026
+ * @param config the current Stencil config
1027
+ * @param sys the compiler system instance in use
1028
+ * @param duration_ms the duration of the action being tracked
1029
+ * @param component_count the number of components being built (optional)
1030
+ * @returns a Promise wrapping data for the telemetry endpoint
1031
+ */
1019
1032
  const prepareData = async (coreCompiler, config, sys, duration_ms, component_count = undefined) => {
1020
1033
  const { typescript, rollup } = coreCompiler.versions || { typescript: 'unknown', rollup: 'unknown' };
1021
1034
  const { packages, packagesNoVersions } = await getInstalledPackages(sys, config);
@@ -1028,6 +1041,7 @@ const prepareData = async (coreCompiler, config, sys, duration_ms, component_cou
1028
1041
  const cpu_model = sys.details.cpuModel;
1029
1042
  const build = coreCompiler.buildId || 'unknown';
1030
1043
  const has_app_pwa_config = hasAppTarget(config);
1044
+ const anonymizedConfig = anonymizeConfigForTelemetry(config);
1031
1045
  return {
1032
1046
  yarn,
1033
1047
  duration_ms,
@@ -1047,12 +1061,83 @@ const prepareData = async (coreCompiler, config, sys, duration_ms, component_cou
1047
1061
  typescript,
1048
1062
  rollup,
1049
1063
  has_app_pwa_config,
1064
+ config: anonymizedConfig,
1050
1065
  };
1051
1066
  };
1067
+ // props in output targets for which we retain their original values when
1068
+ // preparing a config for telemetry
1069
+ //
1070
+ // we omit the values of all other fields on output targets.
1071
+ const OUTPUT_TARGET_KEYS_TO_KEEP = ['type'];
1072
+ // top-level config props that we anonymize for telemetry
1073
+ const CONFIG_PROPS_TO_ANONYMIZE = [
1074
+ 'rootDir',
1075
+ 'fsNamespace',
1076
+ 'packageJsonFilePath',
1077
+ 'namespace',
1078
+ 'srcDir',
1079
+ 'srcIndexHtml',
1080
+ 'buildLogFilePath',
1081
+ 'cacheDir',
1082
+ 'configPath',
1083
+ 'tsconfig',
1084
+ ];
1085
+ // Props we delete entirely from the config for telemetry
1086
+ //
1087
+ // TODO(STENCIL-469): Investigate improving anonymization for tsCompilerOptions and devServer
1088
+ const CONFIG_PROPS_TO_DELETE = ['sys', 'logger', 'tsCompilerOptions', 'devServer'];
1089
+ /**
1090
+ * Anonymize the config for telemetry, replacing potentially revealing config props
1091
+ * with a placeholder string if they are present (this lets us still track how frequently
1092
+ * these config options are being used)
1093
+ *
1094
+ * @param config the config to anonymize
1095
+ * @returns an anonymized copy of the same config
1096
+ */
1097
+ const anonymizeConfigForTelemetry = (config) => {
1098
+ var _a;
1099
+ const anonymizedConfig = { ...config };
1100
+ for (const prop of CONFIG_PROPS_TO_ANONYMIZE) {
1101
+ if (anonymizedConfig[prop] !== undefined) {
1102
+ anonymizedConfig[prop] = 'omitted';
1103
+ }
1104
+ }
1105
+ anonymizedConfig.outputTargets = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).map((target) => {
1106
+ // Anonymize the outputTargets on our configuration, taking advantage of the
1107
+ // optional 2nd argument to `JSON.stringify`. If anything is not a string
1108
+ // we retain it so that any nested properties are handled, else we check
1109
+ // whether it's in our 'keep' list to decide whether to keep it or replace it
1110
+ // with `"omitted"`.
1111
+ const anonymizedOT = JSON.parse(JSON.stringify(target, (key, value) => {
1112
+ if (!(typeof value === 'string')) {
1113
+ return value;
1114
+ }
1115
+ if (OUTPUT_TARGET_KEYS_TO_KEEP.includes(key)) {
1116
+ return value;
1117
+ }
1118
+ return 'omitted';
1119
+ }));
1120
+ // this prop has to be handled separately because it is an array
1121
+ // so the replace function above will be called with all of its
1122
+ // members, giving us `["omitted", "omitted", ...]`.
1123
+ //
1124
+ // Instead, we check for its presence and manually copy over.
1125
+ if (isOutputTargetHydrate(target) && target.external) {
1126
+ anonymizedOT['external'] = target.external.concat();
1127
+ }
1128
+ return anonymizedOT;
1129
+ });
1130
+ // TODO(STENCIL-469): Investigate improving anonymization for tsCompilerOptions and devServer
1131
+ for (const prop of CONFIG_PROPS_TO_DELETE) {
1132
+ delete anonymizedConfig[prop];
1133
+ }
1134
+ return anonymizedConfig;
1135
+ };
1052
1136
  /**
1053
1137
  * Reads package-lock.json, yarn.lock, and package.json files in order to cross-reference
1054
1138
  * the dependencies and devDependencies properties. Pulls up the current installed version
1055
1139
  * of each package under the @stencil, @ionic, and @capacitor scopes.
1140
+ *
1056
1141
  * @param sys the system instance where telemetry is invoked
1057
1142
  * @param config the Stencil configuration associated with the current task that triggered telemetry
1058
1143
  * @returns an object listing all dev and production dependencies under the aforementioned scopes
@@ -1135,6 +1220,7 @@ function sanitizeDeclaredVersion(version) {
1135
1220
  }
1136
1221
  /**
1137
1222
  * If telemetry is enabled, send a metric to an external data store
1223
+ *
1138
1224
  * @param sys the system instance where telemetry is invoked
1139
1225
  * @param config the Stencil configuration associated with the current task that triggered telemetry
1140
1226
  * @param name the name of a trackable metric. Note this name is not necessarily a scalar value to track, like
@@ -1150,10 +1236,11 @@ async function sendMetric(sys, config, name, value) {
1150
1236
  value,
1151
1237
  session_id,
1152
1238
  };
1153
- await sendTelemetry(sys, config, { type: 'telemetry', message });
1239
+ await sendTelemetry(sys, config, message);
1154
1240
  }
1155
1241
  /**
1156
1242
  * Used to read the config file's tokens.telemetry property.
1243
+ *
1157
1244
  * @param sys The system where the command is invoked
1158
1245
  * @returns string
1159
1246
  */
@@ -1175,7 +1262,7 @@ async function sendTelemetry(sys, config, data) {
1175
1262
  try {
1176
1263
  const now = new Date().toISOString();
1177
1264
  const body = {
1178
- metrics: [data.message],
1265
+ metrics: [data],
1179
1266
  sent_at: now,
1180
1267
  };
1181
1268
  // This request is only made if telemetry is on.
@@ -1187,7 +1274,7 @@ async function sendTelemetry(sys, config, data) {
1187
1274
  body: JSON.stringify(body),
1188
1275
  });
1189
1276
  hasVerbose(config) &&
1190
- console.debug('\nSent %O metric to events service (status: %O)', data.message.name, response.status, '\n');
1277
+ console.debug('\nSent %O metric to events service (status: %O)', data.name, response.status, '\n');
1191
1278
  if (response.status !== 204) {
1192
1279
  hasVerbose(config) &&
1193
1280
  console.debug('\nBad response from events service. Request body: %O', response.body.toString(), '\n');
@@ -1338,7 +1425,10 @@ const taskGenerate = async (coreCompiler, config) => {
1338
1425
  if (!writtenFiles) {
1339
1426
  return config.sys.exit(1);
1340
1427
  }
1341
- // TODO(STENCIL-424): Investigate moving these console.log calls to config.logger.info
1428
+ // We use `console.log` here rather than our `config.logger` because we don't want
1429
+ // our TUI messages to be prefixed with timestamps and so on.
1430
+ //
1431
+ // See STENCIL-424 for details.
1342
1432
  console.log();
1343
1433
  console.log(`${config.logger.gray('$')} stencil generate ${input}`);
1344
1434
  console.log();
package/cli/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core/cli",
3
- "version": "2.16.1",
3
+ "version": "2.17.0",
4
4
  "description": "Stencil CLI.",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core/compiler",
3
- "version": "2.16.1",
3
+ "version": "2.17.0",
4
4
  "description": "Stencil Compiler.",
5
5
  "main": "./stencil.js",
6
6
  "types": "./stencil.d.ts",