@stencil/core 2.14.2 → 2.15.2

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 (43) hide show
  1. package/bin/stencil +14 -15
  2. package/cli/index.cjs +153 -66
  3. package/cli/index.js +153 -66
  4. package/cli/package.json +1 -1
  5. package/compiler/package.json +1 -1
  6. package/compiler/stencil.js +417 -106
  7. package/compiler/stencil.min.js +2 -2
  8. package/dependencies.json +1 -1
  9. package/dev-server/client/index.js +3 -3
  10. package/dev-server/client/package.json +1 -1
  11. package/dev-server/connector.html +3 -3
  12. package/dev-server/index.js +1 -1
  13. package/dev-server/package.json +1 -1
  14. package/dev-server/server-process.js +2 -2
  15. package/internal/app-data/package.json +1 -1
  16. package/internal/client/css-shim.js +2 -2
  17. package/internal/client/dom.js +1 -1
  18. package/internal/client/index.js +1 -1
  19. package/internal/client/package.json +1 -1
  20. package/internal/client/patch-browser.js +1 -1
  21. package/internal/client/patch-esm.js +1 -1
  22. package/internal/client/polyfills/css-shim.js +1 -1
  23. package/internal/client/shadow-css.js +1 -1
  24. package/internal/hydrate/package.json +1 -1
  25. package/internal/hydrate/runner.d.ts +1 -1
  26. package/internal/hydrate/runner.js +1 -1
  27. package/internal/package.json +1 -1
  28. package/internal/stencil-private.d.ts +39 -3
  29. package/internal/stencil-public-compiler.d.ts +21 -15
  30. package/internal/testing/package.json +1 -1
  31. package/mock-doc/index.cjs +13 -3
  32. package/mock-doc/index.d.ts +4 -0
  33. package/mock-doc/index.js +13 -3
  34. package/mock-doc/package.json +1 -1
  35. package/package.json +5 -5
  36. package/screenshot/package.json +1 -1
  37. package/sys/node/autoprefixer.js +1 -1
  38. package/sys/node/index.js +2046 -1338
  39. package/sys/node/node-fetch.js +1 -1
  40. package/sys/node/package.json +1 -1
  41. package/sys/node/worker.js +1 -1
  42. package/testing/index.js +8 -8
  43. package/testing/package.json +1 -1
package/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil CLI v2.14.2 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI v2.15.2 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  const toLowerCase = (str) => str.toLowerCase();
5
5
  const dashToPascalCase = (str) => toLowerCase(str)
@@ -235,15 +235,16 @@ const pathComponents = (path, rootLength) => {
235
235
  * @returns an error message if the tag has an invalid name, undefined if the tag name passes all checks
236
236
  */
237
237
  const validateComponentTag = (tag) => {
238
+ // we want to check this first since we call some String.prototype methods below
239
+ if (typeof tag !== 'string') {
240
+ return `Tag "${tag}" must be a string type`;
241
+ }
238
242
  if (tag !== tag.trim()) {
239
243
  return `Tag can not contain white spaces`;
240
244
  }
241
245
  if (tag !== tag.toLowerCase()) {
242
246
  return `Tag can not contain upper case characters`;
243
247
  }
244
- if (typeof tag !== 'string') {
245
- return `Tag "${tag}" must be a string type`;
246
- }
247
248
  if (tag.length === 0) {
248
249
  return `Received empty tag value`;
249
250
  }
@@ -305,9 +306,19 @@ const parseFlags = (args, sys) => {
305
306
  });
306
307
  return flags;
307
308
  };
309
+ /**
310
+ * Parse command line arguments that are whitelisted via the BOOLEAN_ARG_OPTS,
311
+ * STRING_ARG_OPTS, and NUMBER_ARG_OPTS arrays in this file. Handles leading
312
+ * dashes on arguments, aliases that are defined for a small number of argument
313
+ * types, and parsing values for non-boolean arguments (e.g. port number).
314
+ *
315
+ * @param flags a ConfigFlags object
316
+ * @param args an array of command-line arguments to parse
317
+ * @param knownArgs an array to which all recognized, legal arguments are added
318
+ */
308
319
  const parseArgs = (flags, args, knownArgs) => {
309
- ARG_OPTS.boolean.forEach((booleanName) => {
310
- const alias = ARG_OPTS.alias[booleanName];
320
+ BOOLEAN_ARG_OPTS.forEach((booleanName) => {
321
+ const alias = ARG_OPTS_ALIASES[booleanName];
311
322
  const flagKey = configCase(booleanName);
312
323
  if (typeof flags[flagKey] !== 'boolean') {
313
324
  flags[flagKey] = null;
@@ -335,8 +346,8 @@ const parseArgs = (flags, args, knownArgs) => {
335
346
  }
336
347
  });
337
348
  });
338
- ARG_OPTS.string.forEach((stringName) => {
339
- const alias = ARG_OPTS.alias[stringName];
349
+ STRING_ARG_OPTS.forEach((stringName) => {
350
+ const alias = ARG_OPTS_ALIASES[stringName];
340
351
  const flagKey = configCase(stringName);
341
352
  if (typeof flags[flagKey] !== 'string') {
342
353
  flags[flagKey] = null;
@@ -379,8 +390,8 @@ const parseArgs = (flags, args, knownArgs) => {
379
390
  }
380
391
  }
381
392
  });
382
- ARG_OPTS.number.forEach((numberName) => {
383
- const alias = ARG_OPTS.alias[numberName];
393
+ NUMBER_ARG_OPTS.forEach((numberName) => {
394
+ const alias = ARG_OPTS_ALIASES[numberName];
384
395
  const flagKey = configCase(numberName);
385
396
  if (typeof flags[flagKey] !== 'number') {
386
397
  flags[flagKey] = null;
@@ -424,50 +435,56 @@ const parseArgs = (flags, args, knownArgs) => {
424
435
  };
425
436
  const configCase = (prop) => {
426
437
  prop = dashToPascalCase(prop);
427
- return prop.charAt(0).toLowerCase() + prop.substr(1);
438
+ return prop.charAt(0).toLowerCase() + prop.slice(1);
428
439
  };
429
- const ARG_OPTS = {
430
- boolean: [
431
- 'build',
432
- 'cache',
433
- 'check-version',
434
- 'ci',
435
- 'compare',
436
- 'debug',
437
- 'dev',
438
- 'devtools',
439
- 'docs',
440
- 'e2e',
441
- 'es5',
442
- 'esm',
443
- 'headless',
444
- 'help',
445
- 'log',
446
- 'open',
447
- 'prerender',
448
- 'prerender-external',
449
- 'prod',
450
- 'profile',
451
- 'service-worker',
452
- 'screenshot',
453
- 'serve',
454
- 'skip-node-check',
455
- 'spec',
456
- 'ssr',
457
- 'stats',
458
- 'update-screenshot',
459
- 'verbose',
460
- 'version',
461
- 'watch',
462
- ],
463
- number: ['max-workers', 'port'],
464
- string: ['address', 'config', 'docs-json', 'emulate', 'log-level', 'root', 'screenshot-connector'],
465
- alias: {
466
- config: 'c',
467
- help: 'h',
468
- port: 'p',
469
- version: 'v',
470
- },
440
+ const BOOLEAN_ARG_OPTS = [
441
+ 'build',
442
+ 'cache',
443
+ 'check-version',
444
+ 'ci',
445
+ 'compare',
446
+ 'debug',
447
+ 'dev',
448
+ 'devtools',
449
+ 'docs',
450
+ 'e2e',
451
+ 'es5',
452
+ 'esm',
453
+ 'headless',
454
+ 'help',
455
+ 'log',
456
+ 'open',
457
+ 'prerender',
458
+ 'prerender-external',
459
+ 'prod',
460
+ 'profile',
461
+ 'service-worker',
462
+ 'screenshot',
463
+ 'serve',
464
+ 'skip-node-check',
465
+ 'spec',
466
+ 'ssr',
467
+ 'stats',
468
+ 'update-screenshot',
469
+ 'verbose',
470
+ 'version',
471
+ 'watch',
472
+ ];
473
+ const NUMBER_ARG_OPTS = ['max-workers', 'port'];
474
+ const STRING_ARG_OPTS = [
475
+ 'address',
476
+ 'config',
477
+ 'docs-json',
478
+ 'emulate',
479
+ 'log-level',
480
+ 'root',
481
+ 'screenshot-connector',
482
+ ];
483
+ const ARG_OPTS_ALIASES = {
484
+ config: 'c',
485
+ help: 'h',
486
+ port: 'p',
487
+ version: 'v',
471
488
  };
472
489
  const getNpmConfigEnvArgs = (sys) => {
473
490
  // process.env.npm_config_argv
@@ -489,7 +506,7 @@ const getNpmConfigEnvArgs = (sys) => {
489
506
  const dependencies = [
490
507
  {
491
508
  name: "@stencil/core",
492
- version: "2.14.2",
509
+ version: "2.15.2",
493
510
  main: "compiler/stencil.js",
494
511
  resources: [
495
512
  "package.json",
@@ -1266,7 +1283,14 @@ const IS_NODE_ENV = typeof global !== 'undefined' &&
1266
1283
  (!global.origin || typeof global.origin !== 'string');
1267
1284
 
1268
1285
  /**
1269
- * Task to generate component boilerplate.
1286
+ * Task to generate component boilerplate and write it to disk. This task can
1287
+ * cause the program to exit with an error under various circumstances, such as
1288
+ * being called in an inappropriate place, being asked to overwrite files that
1289
+ * already exist, etc.
1290
+ *
1291
+ * @param coreCompiler the CoreCompiler we're using currently, here we're
1292
+ * mainly accessing the `path` module
1293
+ * @param config the user-supplied config, which we need here to access `.sys`.
1270
1294
  */
1271
1295
  const taskGenerate = async (coreCompiler, config) => {
1272
1296
  if (!IS_NODE_ENV) {
@@ -1296,10 +1320,16 @@ const taskGenerate = async (coreCompiler, config) => {
1296
1320
  const testFolder = extensionsToGenerate.some(isTest) ? 'test' : '';
1297
1321
  const outDir = path.join(absoluteSrcDir, 'components', dir, componentName);
1298
1322
  await config.sys.createDir(path.join(outDir, testFolder), { recursive: true });
1299
- const writtenFiles = await Promise.all(extensionsToGenerate.map((extension) => writeFileByExtension(coreCompiler, config, outDir, componentName, extension, extensionsToGenerate.includes('css')))).catch((error) => config.logger.error(error));
1323
+ const filesToGenerate = extensionsToGenerate.map((extension) => ({
1324
+ extension,
1325
+ path: getFilepathForFile(coreCompiler, outDir, componentName, extension),
1326
+ }));
1327
+ await checkForOverwrite(filesToGenerate, config);
1328
+ const writtenFiles = await Promise.all(filesToGenerate.map((file) => getBoilerplateAndWriteFile(config, componentName, extensionsToGenerate.includes('css'), file))).catch((error) => config.logger.error(error));
1300
1329
  if (!writtenFiles) {
1301
1330
  return config.sys.exit(1);
1302
1331
  }
1332
+ // TODO(STENCIL-424): Investigate moving these console.log calls to config.logger.info
1303
1333
  console.log();
1304
1334
  console.log(`${config.logger.gray('$')} stencil generate ${input}`);
1305
1335
  console.log();
@@ -1309,6 +1339,9 @@ const taskGenerate = async (coreCompiler, config) => {
1309
1339
  };
1310
1340
  /**
1311
1341
  * Show a checkbox prompt to select the files to be generated.
1342
+ *
1343
+ * @returns a read-only array of `GenerableExtension`, the extensions that the user has decided
1344
+ * to generate
1312
1345
  */
1313
1346
  const chooseFilesToGenerate = async () => {
1314
1347
  const { prompt } = await import('../sys/node/prompts.js');
@@ -1324,22 +1357,76 @@ const chooseFilesToGenerate = async () => {
1324
1357
  })).filesToGenerate;
1325
1358
  };
1326
1359
  /**
1327
- * Get a file's boilerplate by its extension and write it to disk.
1360
+ * Get a filepath for a file we want to generate!
1361
+ *
1362
+ * The filepath for a given file depends on the path, the user-supplied
1363
+ * component name, the extension, and whether we're inside of a test directory.
1364
+ *
1365
+ * @param coreCompiler the compiler we're using, here to acces the `.path` module
1366
+ * @param path path to where we're going to generate the component
1367
+ * @param componentName the user-supplied name for the generated component
1368
+ * @param extension the file extension
1369
+ * @returns the full filepath to the component (with a possible `test` directory
1370
+ * added)
1328
1371
  */
1329
- const writeFileByExtension = async (coreCompiler, config, path, name, extension, withCss) => {
1330
- if (isTest(extension)) {
1331
- path = coreCompiler.path.join(path, 'test');
1332
- }
1333
- const outFile = coreCompiler.path.join(path, `${name}.${extension}`);
1334
- const boilerplate = getBoilerplateByExtension(name, extension, withCss);
1335
- await config.sys.writeFile(outFile, boilerplate);
1336
- return outFile;
1372
+ const getFilepathForFile = (coreCompiler, path, componentName, extension) => isTest(extension)
1373
+ ? coreCompiler.path.join(path, 'test', `${componentName}.${extension}`)
1374
+ : coreCompiler.path.join(path, `${componentName}.${extension}`);
1375
+ /**
1376
+ * Get the boilerplate for a file and write it to disk
1377
+ *
1378
+ * @param config the current config, needed for file operations
1379
+ * @param componentName the component name (user-supplied)
1380
+ * @param withCss are we generating CSS?
1381
+ * @param file the file we want to write
1382
+ * @returns a `Promise<string>` which holds the full filepath we've written to,
1383
+ * used to print out a little summary of our activity to the user.
1384
+ */
1385
+ const getBoilerplateAndWriteFile = async (config, componentName, withCss, file) => {
1386
+ const boilerplate = getBoilerplateByExtension(componentName, file.extension, withCss);
1387
+ await config.sys.writeFile(file.path, boilerplate);
1388
+ return file.path;
1389
+ };
1390
+ /**
1391
+ * Check to see if any of the files we plan to write already exist and would
1392
+ * therefore be overwritten if we proceed, because we'd like to not overwrite
1393
+ * people's code!
1394
+ *
1395
+ * This function will check all the filepaths and if it finds any files log an
1396
+ * error and exit with an error code. If it doesn't find anything it will just
1397
+ * peacefully return `Promise<void>`.
1398
+ *
1399
+ * @param files the files we want to check
1400
+ * @param config the Config object, used here to get access to `sys.readFile`
1401
+ */
1402
+ const checkForOverwrite = async (files, config) => {
1403
+ const alreadyPresent = [];
1404
+ await Promise.all(files.map(async ({ path }) => {
1405
+ if ((await config.sys.readFile(path)) !== undefined) {
1406
+ alreadyPresent.push(path);
1407
+ }
1408
+ }));
1409
+ if (alreadyPresent.length > 0) {
1410
+ config.logger.error('Generating code would overwrite the following files:', ...alreadyPresent.map((path) => '\t' + path));
1411
+ await config.sys.exit(1);
1412
+ }
1337
1413
  };
1414
+ /**
1415
+ * Check if an extension is for a test
1416
+ *
1417
+ * @param extension the extension we want to check
1418
+ * @returns a boolean indicating whether or not its a test
1419
+ */
1338
1420
  const isTest = (extension) => {
1339
1421
  return extension === 'e2e.ts' || extension === 'spec.tsx';
1340
1422
  };
1341
1423
  /**
1342
1424
  * Get the boilerplate for a file by its extension.
1425
+ *
1426
+ * @param tagName the name of the component we're generating
1427
+ * @param extension the file extension we want boilerplate for (.css, tsx, etc)
1428
+ * @param withCss a boolean indicating whether we're generating a CSS file
1429
+ * @returns a string container the file boilerplate for the supplied extension
1343
1430
  */
1344
1431
  const getBoilerplateByExtension = (tagName, extension, withCss) => {
1345
1432
  switch (extension) {
@@ -1429,7 +1516,7 @@ describe('${name}', () => {
1429
1516
  /**
1430
1517
  * Convert a dash case string to pascal case.
1431
1518
  */
1432
- const toPascalCase = (str) => str.split('-').reduce((res, part) => res + part[0].toUpperCase() + part.substr(1), '');
1519
+ const toPascalCase = (str) => str.split('-').reduce((res, part) => res + part[0].toUpperCase() + part.slice(1), '');
1433
1520
 
1434
1521
  const taskTelemetry = async (config, sys, logger) => {
1435
1522
  const prompt = logger.dim(sys.details.platform === 'windows' ? '>' : '$');
package/cli/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core/cli",
3
- "version": "2.14.2",
3
+ "version": "2.15.2",
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.14.2",
3
+ "version": "2.15.2",
4
4
  "description": "Stencil Compiler.",
5
5
  "main": "./stencil.js",
6
6
  "types": "./stencil.d.ts",