@stencil/core 2.14.0 → 2.15.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/bin/stencil +19 -13
  2. package/cli/index.cjs +2 -2
  3. package/cli/index.js +2 -2
  4. package/cli/package.json +1 -1
  5. package/compiler/package.json +1 -1
  6. package/compiler/stencil.js +325 -49
  7. package/compiler/stencil.min.js +2 -2
  8. package/dependencies.json +1 -1
  9. package/dev-server/client/index.js +1 -1
  10. package/dev-server/client/package.json +1 -1
  11. package/dev-server/connector.html +2 -2
  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 +1 -1
  17. package/internal/client/dom.js +1 -1
  18. package/internal/client/index.js +5 -2
  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/shadow-css.js +1 -1
  23. package/internal/hydrate/index.js +3 -1
  24. package/internal/hydrate/package.json +1 -1
  25. package/internal/hydrate/runner.d.ts +1 -1
  26. package/internal/package.json +1 -1
  27. package/internal/stencil-public-compiler.d.ts +18 -14
  28. package/internal/testing/index.js +3 -1
  29. package/internal/testing/package.json +1 -1
  30. package/mock-doc/index.cjs +1 -1
  31. package/mock-doc/index.js +1 -1
  32. package/mock-doc/package.json +1 -1
  33. package/package.json +4 -4
  34. package/screenshot/package.json +1 -1
  35. package/sys/node/index.js +1 -1
  36. package/sys/node/package.json +1 -1
  37. package/sys/node/worker.js +1 -1
  38. package/testing/index.js +2 -2
  39. package/testing/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil Compiler v2.14.0 | MIT Licensed | https://stenciljs.com
2
+ Stencil Compiler v2.15.0 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  (function(exports) {
5
5
  'use strict';
@@ -1599,6 +1599,12 @@ const createJsVarName = (fileName) => {
1599
1599
  }
1600
1600
  return fileName;
1601
1601
  };
1602
+ /**
1603
+ * Determines if a given file path points to a type declaration file (ending in .d.ts) or not. This function is
1604
+ * case-insensitive in its heuristics.
1605
+ * @param filePath the path to check
1606
+ * @returns `true` if the given `filePath` points to a type declaration file, `false` otherwise
1607
+ */
1602
1608
  const isDtsFile$1 = (filePath) => {
1603
1609
  const parts = filePath.toLowerCase().split('.');
1604
1610
  if (parts.length > 2) {
@@ -3967,7 +3973,7 @@ const createCustomResolverAsync = (sys, inMemoryFs, exts) => {
3967
3973
  };
3968
3974
  };
3969
3975
 
3970
- const buildId = '20220214175725';
3976
+ const buildId = '20220328165835';
3971
3977
  const minfyJsId = 'terser5.6.1_7';
3972
3978
  const optimizeCssId = 'autoprefixer10.2.5_postcss8.2.8_7';
3973
3979
  const parse5Version = '6.0.1';
@@ -3975,8 +3981,8 @@ const rollupVersion = '2.42.3';
3975
3981
  const sizzleVersion = '2.42.3';
3976
3982
  const terserVersion = '5.6.1';
3977
3983
  const typescriptVersion = '4.5.4';
3978
- const vermoji = '💫';
3979
- const version$3 = '2.14.0';
3984
+ const vermoji = '';
3985
+ const version$3 = '2.15.0';
3980
3986
  const versions = {
3981
3987
  stencil: version$3,
3982
3988
  parse5: parse5Version,
@@ -40941,9 +40947,24 @@ const createComponentExport = (cmp) => {
40941
40947
  return `export { ${originalClassName} as ${underscoredClassName} } from '${filePath}';`;
40942
40948
  };
40943
40949
 
40950
+ /**
40951
+ * Rollup plugin that aids in resolving the entry points (1 or more files) for a Stencil project. For example, a project
40952
+ * using the `dist-custom-elements` output target may have a single 'entry point' for each file containing a component.
40953
+ * Each of those files will be independently resolved and loaded by this plugin for further processing by Rollup later
40954
+ * in the bundling process.
40955
+ * @param entries the Stencil project files to process. It should be noted that the keys in this object may not
40956
+ * necessarily be an absolute or relative path to a file, but may be a Rollup Virtual Module (which begin with \0).
40957
+ * @returns the rollup plugin that loads and process a Stencil project's entry points
40958
+ */
40944
40959
  const loaderPlugin = (entries = {}) => {
40945
40960
  return {
40946
40961
  name: 'stencilLoaderPlugin',
40962
+ /**
40963
+ * A rollup build hook for resolving the imports of individual Stencil project files. This hook only resolves
40964
+ * modules that are contained in the plugin's `entries` argument. [Source](https://rollupjs.org/guide/en/#resolveid)
40965
+ * @param id the importee to resolve
40966
+ * @returns a string that resolves an import to some id, null otherwise
40967
+ */
40947
40968
  resolveId(id) {
40948
40969
  if (id in entries) {
40949
40970
  return {
@@ -40952,6 +40973,12 @@ const loaderPlugin = (entries = {}) => {
40952
40973
  }
40953
40974
  return null;
40954
40975
  },
40976
+ /**
40977
+ * A rollup build hook for loading individual Stencil project files [Source](https://rollupjs.org/guide/en/#load)
40978
+ * @param id the path of the module to load. It should be noted that the keys in this object may not necessarily
40979
+ * be an absolute or relative path to a file, but may be a Rollup Virtual Module.
40980
+ * @returns the module matched, null otherwise
40981
+ */
40955
40982
  load(id) {
40956
40983
  if (id in entries) {
40957
40984
  return entries[id];
@@ -41569,9 +41596,22 @@ const getTsResolveExtension = (p) => {
41569
41596
  };
41570
41597
  const shouldPatchRemoteTypeScript = (compilerExe) => !IS_NODE_ENV && isRemoteUrl(compilerExe);
41571
41598
 
41599
+ /**
41600
+ * Rollup plugin that aids in resolving the TypeScript files and performing the transpilation step.
41601
+ * @param compilerCtx the current compiler context
41602
+ * @param bundleOpts Rollup bundling options to apply during TypeScript compilation
41603
+ * @param config the Stencil configuration for the project
41604
+ * @returns the rollup plugin for handling TypeScript files.
41605
+ */
41572
41606
  const typescriptPlugin = (compilerCtx, bundleOpts, config) => {
41573
41607
  return {
41574
41608
  name: `${bundleOpts.id}TypescriptPlugin`,
41609
+ /**
41610
+ * A rollup build hook for loading TypeScript files and their associated source maps (if they exist).
41611
+ * [Source](https://rollupjs.org/guide/en/#load)
41612
+ * @param id the path of the file to load
41613
+ * @returns the module matched (with its sourcemap if it exists), null otherwise
41614
+ */
41575
41615
  load(id) {
41576
41616
  if (isAbsolute$1(id)) {
41577
41617
  const fsFilePath = normalizeFsPath(id);
@@ -41587,6 +41627,13 @@ const typescriptPlugin = (compilerCtx, bundleOpts, config) => {
41587
41627
  }
41588
41628
  return null;
41589
41629
  },
41630
+ /**
41631
+ * Performs TypeScript compilation/transpilation, including applying any transformations against the Abstract Syntax
41632
+ * Tree (AST) specific to stencil
41633
+ * @param _code the code to modify, unused
41634
+ * @param id module's identifier
41635
+ * @returns the transpiled code, with its associated sourcemap. null otherwise
41636
+ */
41590
41637
  transform(_code, id) {
41591
41638
  if (isAbsolute$1(id)) {
41592
41639
  const fsFilePath = normalizeFsPath(id);
@@ -53750,6 +53797,14 @@ const bundleOutput = async (config, compilerCtx, buildCtx, bundleOpts) => {
53750
53797
  }
53751
53798
  return undefined;
53752
53799
  };
53800
+ /**
53801
+ * Build the rollup options that will be used to transpile, minify, and otherwise transform a Stencil project
53802
+ * @param config the Stencil configuration for the project
53803
+ * @param compilerCtx the current compiler context
53804
+ * @param buildCtx a context object containing information about the current build
53805
+ * @param bundleOpts Rollup bundling options to apply to the base configuration setup by this function
53806
+ * @returns the rollup options to be used
53807
+ */
53753
53808
  const getRollupOptions = (config, compilerCtx, buildCtx, bundleOpts) => {
53754
53809
  var _a;
53755
53810
  const customResolveOptions = createCustomResolverAsync(config.sys, compilerCtx.fs, [
@@ -54554,11 +54609,46 @@ const addModuleMetadataProxies = (tsSourceFile, moduleFile) => {
54554
54609
  const addComponentMetadataProxy = (compilerMeta) => {
54555
54610
  return t.createStatement(createComponentMetadataProxy(compilerMeta));
54556
54611
  };
54612
+ /**
54613
+ * Create a call expression for wrapping a component in a proxy. This call expression takes a form:
54614
+ * ```ts
54615
+ * PROXY_CUSTOM_ELEMENT(ComponentClassName, Metadata);
54616
+ * ```
54617
+ * where
54618
+ * - `PROXY_CUSTOM_ELEMENT` is a Stencil internal identifier that will be replaced with the name of the actual function
54619
+ * name at compile name
54620
+ * - `ComponentClassName` is the name Stencil component's class
54621
+ * - `Metadata` is the compiler metadata associated with the Stencil component
54622
+ *
54623
+ * @param compilerMeta compiler metadata associated with the component to be wrapped in a proxy
54624
+ * @returns the generated call expression
54625
+ */
54557
54626
  const createComponentMetadataProxy = (compilerMeta) => {
54558
54627
  const compactMeta = formatComponentRuntimeMeta(compilerMeta, true);
54559
- const literalCmpClassName = t.createIdentifier(compilerMeta.componentClassName);
54628
+ const literalCmpClassName = t.factory.createIdentifier(compilerMeta.componentClassName);
54629
+ const literalMeta = convertValueToLiteral(compactMeta);
54630
+ return t.factory.createCallExpression(t.factory.createIdentifier(PROXY_CUSTOM_ELEMENT), [], [literalCmpClassName, literalMeta]);
54631
+ };
54632
+ /**
54633
+ * Create a call expression for wrapping a component represented as an anonymous class in a proxy. This call expression
54634
+ * takes a form:
54635
+ * ```ts
54636
+ * PROXY_CUSTOM_ELEMENT(Clazz, Metadata);
54637
+ * ```
54638
+ * where
54639
+ * - `PROXY_CUSTOM_ELEMENT` is a Stencil internal identifier that will be replaced with the name of the actual function
54640
+ * name at compile name
54641
+ * - `Clazz` is an anonymous class to be proxied
54642
+ * - `Metadata` is the compiler metadata associated with the Stencil component
54643
+ *
54644
+ * @param compilerMeta compiler metadata associated with the component to be wrapped in a proxy
54645
+ * @param clazz the anonymous class to proxy
54646
+ * @returns the generated call expression
54647
+ */
54648
+ const createAnonymousClassMetadataProxy = (compilerMeta, clazz) => {
54649
+ const compactMeta = formatComponentRuntimeMeta(compilerMeta, true);
54560
54650
  const literalMeta = convertValueToLiteral(compactMeta);
54561
- return t.createCall(t.createIdentifier(PROXY_CUSTOM_ELEMENT), [], [literalCmpClassName, literalMeta]);
54651
+ return t.factory.createCallExpression(t.factory.createIdentifier(PROXY_CUSTOM_ELEMENT), [], [clazz, literalMeta]);
54562
54652
  };
54563
54653
 
54564
54654
  const defineCustomElement = (tsSourceFile, moduleFile, transformOpts) => {
@@ -54833,7 +54923,7 @@ const createConstClass = (transformOpts, classNode, heritageClauses, members) =>
54833
54923
  }
54834
54924
  return t.createVariableStatement(constModifiers, t.createVariableDeclarationList([
54835
54925
  t.createVariableDeclaration(className, undefined, t.createClassExpression(classModifiers, undefined, classNode.typeParameters, heritageClauses, members)),
54836
- ], t.NodeFlags.Let));
54926
+ ], t.NodeFlags.Const));
54837
54927
  };
54838
54928
 
54839
54929
  const addCreateEvents = (moduleFile, cmp) => {
@@ -55114,16 +55204,9 @@ const addDefineCustomElementFunctions = (compilerCtx, components, outputTarget)
55114
55204
  const newStatements = [];
55115
55205
  const caseStatements = [];
55116
55206
  const tagNames = [];
55117
- addCoreRuntimeApi(moduleFile, RUNTIME_APIS.proxyCustomElement);
55118
55207
  if (moduleFile.cmps.length) {
55119
55208
  const principalComponent = moduleFile.cmps[0];
55120
55209
  tagNames.push(principalComponent.tagName);
55121
- // wraps the initial component class in a `proxyCustomElement` wrapper.
55122
- // This is what will be exported and called from the `defineCustomElement` call.
55123
- const proxyDefinition = createComponentMetadataProxy(principalComponent);
55124
- const metaExpression = t.factory.createExpressionStatement(t.factory.createBinaryExpression(t.factory.createIdentifier(principalComponent.componentClassName), t.factory.createToken(t.SyntaxKind.EqualsToken), proxyDefinition));
55125
- newStatements.push(metaExpression);
55126
- t.addSyntheticLeadingComment(proxyDefinition, t.SyntaxKind.MultiLineCommentTrivia, '@__PURE__', false);
55127
55210
  // define the current component - `customElements.define(tagName, MyProxiedComponent);`
55128
55211
  const customElementsDefineCallExpression = t.factory.createCallExpression(t.factory.createPropertyAccessExpression(t.factory.createIdentifier('customElements'), 'define'), undefined, [t.factory.createIdentifier('tagName'), t.factory.createIdentifier(principalComponent.componentClassName)]);
55129
55212
  // create a `case` block that defines the current component. We'll add them to our switch statement later.
@@ -55240,6 +55323,71 @@ function createAutoDefinitionExpression(componentName) {
55240
55323
  ]));
55241
55324
  }
55242
55325
 
55326
+ /**
55327
+ * Proxy custom elements for the `dist-custom-elements` output target. This function searches for a Stencil component's
55328
+ * class initializer (found on the righthand side of the '=' operator):
55329
+ *
55330
+ * ```ts
55331
+ * const MyComponent = class extends HTMLElement { // Implementation omitted }
55332
+ * ```
55333
+ *
55334
+ * and wraps the initializer into a `proxyCustomElement` call:
55335
+ *
55336
+ * ```ts
55337
+ * const MyComponent = proxyCustomElement(class extends HTMLElement { // Implementation omitted }, componentMetadata);
55338
+ * ```
55339
+ *
55340
+ * This is to work around an issue where treeshaking does not work for webpack users, whose details are captured in full
55341
+ * in [this issue on the webpack GitHub repo](https://github.com/webpack/webpack/issues/14963).
55342
+ *
55343
+ * @param compilerCtx current compiler context
55344
+ * @param transformOpts transpilation options for the current build
55345
+ * @returns a TypeScript AST transformer factory function that performs the above described transformation
55346
+ */
55347
+ const proxyCustomElement = (compilerCtx, transformOpts) => {
55348
+ return () => {
55349
+ return (tsSourceFile) => {
55350
+ const moduleFile = getModuleFromSourceFile(compilerCtx, tsSourceFile);
55351
+ if (!moduleFile.cmps.length) {
55352
+ return tsSourceFile;
55353
+ }
55354
+ const principalComponent = moduleFile.cmps[0];
55355
+ for (let [stmtIndex, stmt] of tsSourceFile.statements.entries()) {
55356
+ if (t.isVariableStatement(stmt)) {
55357
+ for (let [declarationIndex, declaration] of stmt.declarationList.declarations.entries()) {
55358
+ if (declaration.name.getText() !== principalComponent.componentClassName) {
55359
+ continue;
55360
+ }
55361
+ // wrap the Stencil component's class declaration in a component proxy
55362
+ const proxyCreationCall = createAnonymousClassMetadataProxy(principalComponent, declaration.initializer);
55363
+ t.addSyntheticLeadingComment(proxyCreationCall, t.SyntaxKind.MultiLineCommentTrivia, '@__PURE__', false);
55364
+ // update the component's variable declaration to use the new initializer
55365
+ const proxiedComponentDeclaration = t.factory.updateVariableDeclaration(declaration, declaration.name, declaration.exclamationToken, declaration.type, proxyCreationCall);
55366
+ // update the declaration list that contains the updated variable declaration
55367
+ const updatedDeclarationList = t.factory.updateVariableDeclarationList(stmt.declarationList, [
55368
+ ...stmt.declarationList.declarations.slice(0, declarationIndex),
55369
+ proxiedComponentDeclaration,
55370
+ ...stmt.declarationList.declarations.slice(declarationIndex + 1),
55371
+ ]);
55372
+ // update the variable statement containing the updated declaration list
55373
+ const updatedVariableStatement = t.factory.updateVariableStatement(stmt, [t.factory.createModifier(t.SyntaxKind.ExportKeyword)], updatedDeclarationList);
55374
+ // update the source file's statements to use the new variable statement
55375
+ tsSourceFile = t.factory.updateSourceFile(tsSourceFile, [
55376
+ ...tsSourceFile.statements.slice(0, stmtIndex),
55377
+ updatedVariableStatement,
55378
+ ...tsSourceFile.statements.slice(stmtIndex + 1),
55379
+ ]);
55380
+ // finally, ensure that the proxyCustomElement function is imported
55381
+ tsSourceFile = addImports(transformOpts, tsSourceFile, [RUNTIME_APIS.proxyCustomElement], transformOpts.coreImportPath);
55382
+ return tsSourceFile;
55383
+ }
55384
+ }
55385
+ }
55386
+ return tsSourceFile;
55387
+ };
55388
+ };
55389
+ };
55390
+
55243
55391
  const updateStencilCoreImports = (updatedCoreImportPath) => {
55244
55392
  return () => {
55245
55393
  return (tsSourceFile) => {
@@ -55314,19 +55462,19 @@ const bundleCustomElements$1 = async (config, compilerCtx, buildCtx, outputTarge
55314
55462
  id: 'customElements',
55315
55463
  platform: 'client',
55316
55464
  conditionals: getCustomElementsBuildConditionals(config, buildCtx.components),
55317
- customTransformers: getCustomElementBundleCustomTransformer$1(config, compilerCtx, buildCtx.components, outputTarget),
55465
+ customTransformers: getCustomElementCustomTransformer(config, compilerCtx, buildCtx.components, outputTarget),
55318
55466
  externalRuntime: !!outputTarget.externalRuntime,
55319
55467
  inlineWorkers: true,
55320
55468
  inputs: {
55321
55469
  index: '\0core',
55322
55470
  },
55323
55471
  loader: {
55324
- '\0core': generateEntryPoint$1(outputTarget, buildCtx),
55472
+ '\0core': generateEntryPoint$1(outputTarget),
55325
55473
  },
55326
55474
  inlineDynamicImports: outputTarget.inlineDynamicImports,
55327
55475
  preserveEntrySignatures: 'allow-extension',
55328
55476
  };
55329
- addCustomElementInputs(outputTarget, buildCtx, bundleOpts);
55477
+ addCustomElementInputs(buildCtx, bundleOpts);
55330
55478
  const build = await bundleOutput(config, compilerCtx, buildCtx, bundleOpts);
55331
55479
  if (build) {
55332
55480
  const rollupOutput = await build.generate({
@@ -55372,7 +55520,12 @@ const bundleCustomElements$1 = async (config, compilerCtx, buildCtx, outputTarge
55372
55520
  catchError(buildCtx.diagnostics, e);
55373
55521
  }
55374
55522
  };
55375
- const addCustomElementInputs = (_outputTarget, buildCtx, bundleOpts) => {
55523
+ /**
55524
+ * Create the virtual modules/input modules for the `dist-custom-elements` output target.
55525
+ * @param buildCtx the context for the current build
55526
+ * @param bundleOpts the bundle options to store the virtual modules under. acts as an output parameter
55527
+ */
55528
+ const addCustomElementInputs = (buildCtx, bundleOpts) => {
55376
55529
  const components = buildCtx.components;
55377
55530
  components.forEach((cmp) => {
55378
55531
  const exp = [];
@@ -55384,6 +55537,7 @@ const addCustomElementInputs = (_outputTarget, buildCtx, bundleOpts) => {
55384
55537
  exp.push(`export { ${importName} as ${exportName} } from '${cmp.sourceFilePath}';`);
55385
55538
  }
55386
55539
  else {
55540
+ // the `importName` may collide with the `exportName`, alias it just in case it does with `importAs`
55387
55541
  exp.push(`import { ${importName} as ${importAs}, defineCustomElement as cmpDefCustomEle } from '${cmp.sourceFilePath}';`);
55388
55542
  exp.push(`export const ${exportName} = ${importAs};`);
55389
55543
  exp.push(`export const defineCustomElement = cmpDefCustomEle;`);
@@ -55392,16 +55546,29 @@ const addCustomElementInputs = (_outputTarget, buildCtx, bundleOpts) => {
55392
55546
  bundleOpts.loader[coreKey] = exp.join('\n');
55393
55547
  });
55394
55548
  };
55395
- const generateEntryPoint$1 = (outputTarget, _buildCtx) => {
55549
+ /**
55550
+ * Generate the entrypoint (`index.ts` file) contents for the `dist-custom-elements` output target
55551
+ * @param outputTarget the output target's configuration
55552
+ * @returns the stringified contents to be placed in the entrypoint
55553
+ */
55554
+ const generateEntryPoint$1 = (outputTarget) => {
55396
55555
  const imp = [];
55397
- const exp = [];
55398
55556
  imp.push(`export { setAssetPath, setPlatformOptions } from '${STENCIL_INTERNAL_CLIENT_ID}';`, `export * from '${USER_INDEX_ENTRY_ID}';`);
55399
55557
  if (outputTarget.includeGlobalScripts !== false) {
55400
55558
  imp.push(`import { globalScripts } from '${STENCIL_APP_GLOBALS_ID}';`, `globalScripts();`);
55401
55559
  }
55402
- return [...imp, ...exp].join('\n') + '\n';
55560
+ return imp.join('\n') + '\n';
55403
55561
  };
55404
- const getCustomElementBundleCustomTransformer$1 = (config, compilerCtx, components, outputTarget) => {
55562
+ /**
55563
+ * Get the series of custom transformers that will be applied to a Stencil project's source code during the TypeScript
55564
+ * transpilation process
55565
+ * @param config the configuration for the Stencil project
55566
+ * @param compilerCtx the current compiler context
55567
+ * @param components the components that will be compiled as a part of the current build
55568
+ * @param outputTarget the output target configuration
55569
+ * @returns a list of transformers to use in the transpilation process
55570
+ */
55571
+ const getCustomElementCustomTransformer = (config, compilerCtx, components, outputTarget) => {
55405
55572
  const transformOpts = {
55406
55573
  coreImportPath: STENCIL_INTERNAL_CLIENT_ID,
55407
55574
  componentExport: null,
@@ -55415,6 +55582,7 @@ const getCustomElementBundleCustomTransformer$1 = (config, compilerCtx, componen
55415
55582
  addDefineCustomElementFunctions(compilerCtx, components, outputTarget),
55416
55583
  updateStencilCoreImports(transformOpts.coreImportPath),
55417
55584
  nativeComponentTransform(compilerCtx, transformOpts),
55585
+ proxyCustomElement(compilerCtx, transformOpts),
55418
55586
  removeCollectionImports(compilerCtx),
55419
55587
  ];
55420
55588
  };
@@ -58675,8 +58843,18 @@ const serializeCollectionDependencies = (compilerCtx) => {
58675
58843
  return sortBy(collectionDeps, (item) => item.name);
58676
58844
  };
58677
58845
 
58846
+ /**
58847
+ * Update a type declaration file's import declarations using the module `@stencil/core`
58848
+ * @param typesDir the directory where type declaration files are expected to exist
58849
+ * @param dtsFilePath the path of the type declaration file being updated, used to derive the correct import declaration
58850
+ * module
58851
+ * @param dtsContent the content of a type declaration file to update
58852
+ * @returns the updated type declaration file contents
58853
+ */
58678
58854
  const updateStencilTypesImports = (typesDir, dtsFilePath, dtsContent) => {
58679
58855
  const dir = dirname(dtsFilePath);
58856
+ // determine the relative path between the directory of the .d.ts file and the types directory. this value may result
58857
+ // in '.' if they are the same
58680
58858
  const relPath = relative$1(dir, typesDir);
58681
58859
  let coreDtsPath = join(relPath, CORE_FILENAME);
58682
58860
  if (!coreDtsPath.startsWith('.')) {
@@ -58689,6 +58867,12 @@ const updateStencilTypesImports = (typesDir, dtsFilePath, dtsContent) => {
58689
58867
  }
58690
58868
  return dtsContent;
58691
58869
  };
58870
+ /**
58871
+ * Writes Stencil core typings file to disk for a dist-* output target
58872
+ * @param config the Stencil configuration associated with the project being compiled
58873
+ * @param compilerCtx the current compiler context
58874
+ * @returns
58875
+ */
58692
58876
  const copyStencilCoreDts = async (config, compilerCtx) => {
58693
58877
  const typesOutputTargets = config.outputTargets.filter(isOutputTargetDistTypes).filter((o) => o.typesDir);
58694
58878
  const srcStencilDtsPath = join(config.sys.getCompilerExecutingPath(), '..', '..', 'internal', CORE_DTS);
@@ -58771,21 +58955,21 @@ const generatePropTypes = (cmpMeta) => {
58771
58955
  };
58772
58956
 
58773
58957
  /**
58774
- * Generate a string based on the types that are defined within a component.
58775
- *
58958
+ * Generate a string based on the types that are defined within a component
58776
58959
  * @param cmp the metadata for the component that a type definition string is generated for
58777
- * @param importPath the path of the component file
58960
+ * @param areTypesInternal `true` if types being generated are for a project's internal purposes, `false` otherwise
58961
+ * @returns the generated types string alongside additional metadata
58778
58962
  */
58779
- const generateComponentTypes = (cmp, internal) => {
58963
+ const generateComponentTypes = (cmp, areTypesInternal) => {
58780
58964
  const tagName = cmp.tagName.toLowerCase();
58781
58965
  const tagNameAsPascal = dashToPascalCase$1(tagName);
58782
58966
  const htmlElementName = `HTML${tagNameAsPascal}Element`;
58783
58967
  const propAttributes = generatePropTypes(cmp);
58784
58968
  const methodAttributes = generateMethodTypes(cmp.methods);
58785
58969
  const eventAttributes = generateEventTypes(cmp.events);
58786
- const componentAttributes = attributesToMultiLineString([...propAttributes, ...methodAttributes], false, internal);
58970
+ const componentAttributes = attributesToMultiLineString([...propAttributes, ...methodAttributes], false, areTypesInternal);
58787
58971
  const isDep = cmp.isCollectionDependency;
58788
- const jsxAttributes = attributesToMultiLineString([...propAttributes, ...eventAttributes], true, internal);
58972
+ const jsxAttributes = attributesToMultiLineString([...propAttributes, ...eventAttributes], true, areTypesInternal);
58789
58973
  const element = [
58790
58974
  ` interface ${htmlElementName} extends Components.${tagNameAsPascal}, HTMLStencilElement {`,
58791
58975
  ` }`,
@@ -58827,13 +59011,12 @@ const attributesToMultiLineString = (attributes, jsxAttributes, internal) => {
58827
59011
  };
58828
59012
 
58829
59013
  /**
58830
- * Find all referenced types by a component and add them to the importDataObj and return the newly
58831
- * updated importDataObj
58832
- *
59014
+ * Find all referenced types by a component and add them to the `importDataObj` parameter
58833
59015
  * @param importDataObj key/value of type import file, each value is an array of imported types
58834
- * @param cmpMeta the metadata for the component that is referencing the types
59016
+ * @param allTypes an output parameter containing a map of seen types and the number of times the type has been seen
59017
+ * @param cmp the metadata associated with the component whose types are being inspected
58835
59018
  * @param filePath the path of the component file
58836
- * @param config general config that all of stencil uses
59019
+ * @returns the updated import data
58837
59020
  */
58838
59021
  const updateReferenceTypeImports = (importDataObj, allTypes, cmp, filePath) => {
58839
59022
  const updateImportReferences = updateImportReferenceFactory(allTypes, filePath);
@@ -58890,16 +59073,25 @@ const updateImportReferenceFactory = (allTypes, filePath) => {
58890
59073
  };
58891
59074
  };
58892
59075
 
59076
+ /**
59077
+ * Generates and writes a `components.d.ts` file to disk. This file may be written to the `src` directory of a project,
59078
+ * or be written to a directory that is meant to be distributed (e.g. the output directory of `dist-custom-elements`).
59079
+ * @param config the Stencil configuration associated with the project being compiled
59080
+ * @param compilerCtx the current compiler context
59081
+ * @param buildCtx the context associated with the current build
59082
+ * @param destination the relative directory in the filesystem to write the type declaration file to
59083
+ * @returns `true` if the type declaration file written to disk has changed, `false` otherwise
59084
+ */
58893
59085
  const generateAppTypes = async (config, compilerCtx, buildCtx, destination) => {
58894
59086
  // only gather components that are still root ts files we've found and have component metadata
58895
59087
  // the compilerCtx cache may still have files that may have been deleted/renamed
58896
59088
  const timespan = buildCtx.createTimeSpan(`generated app types started`, true);
58897
- const internal = destination === 'src';
59089
+ const areTypesInternal = destination === 'src';
58898
59090
  // Generate d.ts files for component types
58899
- let componentTypesFileContent = generateComponentTypesFile(config, buildCtx, internal);
59091
+ let componentTypesFileContent = generateComponentTypesFile(config, buildCtx, areTypesInternal);
58900
59092
  // immediately write the components.d.ts file to disk and put it into fs memory
58901
59093
  let componentsDtsFilePath = getComponentsDtsSrcFilePath(config);
58902
- if (!internal) {
59094
+ if (!areTypesInternal) {
58903
59095
  componentsDtsFilePath = resolve$1(destination, GENERATED_DTS$1);
58904
59096
  componentTypesFileContent = updateStencilTypesImports(destination, componentsDtsFilePath, componentTypesFileContent);
58905
59097
  }
@@ -58915,18 +59107,20 @@ const generateAppTypes = async (config, compilerCtx, buildCtx, destination) => {
58915
59107
  return hasComponentsDtsChanged;
58916
59108
  };
58917
59109
  /**
58918
- * Generate the component.d.ts file that contains types for all components
58919
- * @param config the project build configuration
58920
- * @param options compiler options from tsconfig
59110
+ * Generates a `component.d.ts` file's contents, which contains the typings for all components in a Stencil project
59111
+ * @param config the Stencil configuration associated with the project being compiled
59112
+ * @param buildCtx the context associated with the current build
59113
+ * @param areTypesInternal determines if non-exported type definitions are being generated or not
59114
+ * @returns the contents of the `components.d.ts` file
58921
59115
  */
58922
- const generateComponentTypesFile = (config, buildCtx, internal) => {
59116
+ const generateComponentTypesFile = (config, buildCtx, areTypesInternal) => {
58923
59117
  let typeImportData = {};
58924
59118
  const c = [];
58925
59119
  const allTypes = new Map();
58926
59120
  const components = buildCtx.components.filter((m) => !m.isCollectionDependency);
58927
59121
  const modules = components.map((cmp) => {
58928
59122
  typeImportData = updateReferenceTypeImports(typeImportData, allTypes, cmp, cmp.sourceFilePath);
58929
- return generateComponentTypes(cmp, internal);
59123
+ return generateComponentTypes(cmp, areTypesInternal);
58930
59124
  });
58931
59125
  c.push(COMPONENTS_DTS_HEADER);
58932
59126
  c.push(`import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";`);
@@ -59057,10 +59251,28 @@ const relDts$1 = (fromPath, dtsPath) => {
59057
59251
  return normalizePath$1(dtsPath.replace('.d.ts', ''));
59058
59252
  };
59059
59253
 
59254
+ /**
59255
+ * Entrypoint for generating types for one or more `dist-custom-elements` output targets defined in a Stencil project's
59256
+ * configuration
59257
+ * @param config the Stencil configuration associated with the project being compiled
59258
+ * @param compilerCtx the current compiler context
59259
+ * @param buildCtx the context associated with the current build
59260
+ * @param distDtsFilePath the path to a type declaration file (.d.ts) that is being generated for the output target.
59261
+ * This path is not necessarily the `components.d.ts` file that is found in the root of a project's `src` directory.
59262
+ */
59060
59263
  const generateCustomElementsTypes = async (config, compilerCtx, buildCtx, distDtsFilePath) => {
59061
59264
  const outputTargets = config.outputTargets.filter(isOutputTargetDistCustomElements);
59062
59265
  await Promise.all(outputTargets.map((outputTarget) => generateCustomElementsTypesOutput(config, compilerCtx, buildCtx, distDtsFilePath, outputTarget)));
59063
59266
  };
59267
+ /**
59268
+ * Generates types for a single `dist-custom-elements` output target definition in a Stencil project's configuration
59269
+ * @param config the Stencil configuration associated with the project being compiled
59270
+ * @param compilerCtx the current compiler context
59271
+ * @param buildCtx the context associated with the current build
59272
+ * @param distDtsFilePath the path to a type declaration file (.d.ts) that is being generated for the output target.
59273
+ * This path is not necessarily the `components.d.ts` file that is found in the root of a project's `src` directory.
59274
+ * @param outputTarget the output target for which types are being currently generated
59275
+ */
59064
59276
  const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx, distDtsFilePath, outputTarget) => {
59065
59277
  const customElementsDtsPath = join(outputTarget.dir, 'index.d.ts');
59066
59278
  const componentsDtsRelPath = relDts(outputTarget.dir, distDtsFilePath);
@@ -59076,7 +59288,7 @@ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx,
59076
59288
  ` * "setAssetPath(document.currentScript.src)", or using a bundler's replace plugin to`,
59077
59289
  ` * dynamically set the path at build time, such as "setAssetPath(process.env.ASSET_PATH)".`,
59078
59290
  ` * But do note that this configuration depends on how your script is bundled, or lack of`,
59079
- ` * bunding, and where your assets can be loaded from. Additionally custom bundling`,
59291
+ ` * bundling, and where your assets can be loaded from. Additionally custom bundling`,
59080
59292
  ` * will have to ensure the static assets are copied to its build directory.`,
59081
59293
  ` */`,
59082
59294
  `export declare const setAssetPath: (path: string) => void;`,
@@ -59111,6 +59323,13 @@ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx,
59111
59323
  await compilerCtx.fs.writeFile(filePath, dtsCode, { outputTargetType: outputTarget.type });
59112
59324
  }));
59113
59325
  };
59326
+ /**
59327
+ * Generate a type declaration file for a specific Stencil component
59328
+ * @param componentsDtsRelPath the path to a root type declaration file from which commonly used entities can be
59329
+ * referenced from in the newly generated file
59330
+ * @param cmp the component to generate the type declaration file for
59331
+ * @returns the contents of the type declaration file for the provided `cmp`
59332
+ */
59114
59333
  const generateCustomElementType = (componentsDtsRelPath, cmp) => {
59115
59334
  const tagNameAsPascal = dashToPascalCase$1(cmp.tagName);
59116
59335
  const o = [
@@ -59129,6 +59348,13 @@ const generateCustomElementType = (componentsDtsRelPath, cmp) => {
59129
59348
  ];
59130
59349
  return o.join('\n');
59131
59350
  };
59351
+ /**
59352
+ * Determines the relative path between two provided paths. If a type declaration file extension is present on
59353
+ * `dtsPath`, it will be removed from the computed relative path.
59354
+ * @param fromPath the path from which to start at
59355
+ * @param dtsPath the destination path
59356
+ * @returns the relative path from the provided `fromPath` to the `dtsPath`
59357
+ */
59132
59358
  const relDts = (fromPath, dtsPath) => {
59133
59359
  dtsPath = relative$1(fromPath, dtsPath);
59134
59360
  if (!dtsPath.startsWith('.')) {
@@ -59137,13 +59363,28 @@ const relDts = (fromPath, dtsPath) => {
59137
59363
  return normalizePath$1(dtsPath.replace('.d.ts', ''));
59138
59364
  };
59139
59365
 
59366
+ /**
59367
+ * For a single output target, generate types, then copy the Stencil core type declaration file
59368
+ * @param config the Stencil configuration associated with the project being compiled
59369
+ * @param compilerCtx the current compiler context
59370
+ * @param buildCtx the context associated with the current build
59371
+ * @param outputTarget the output target to generate types for
59372
+ */
59140
59373
  const generateTypes = async (config, compilerCtx, buildCtx, outputTarget) => {
59141
59374
  if (!buildCtx.hasError) {
59142
59375
  await generateTypesOutput(config, compilerCtx, buildCtx, outputTarget);
59143
59376
  await copyStencilCoreDts(config, compilerCtx);
59144
59377
  }
59145
59378
  };
59379
+ /**
59380
+ * Generate type definition files and write them to a dist directory
59381
+ * @param config the Stencil configuration associated with the project being compiled
59382
+ * @param compilerCtx the current compiler context
59383
+ * @param buildCtx the context associated with the current build
59384
+ * @param outputTarget the output target to generate types for
59385
+ */
59146
59386
  const generateTypesOutput = async (config, compilerCtx, buildCtx, outputTarget) => {
59387
+ // get all type declaration files in a project's src/ directory
59147
59388
  const srcDirItems = await compilerCtx.fs.readdir(config.srcDir, { recursive: false });
59148
59389
  const srcDtsFiles = srcDirItems.filter((srcItem) => srcItem.isFile && isDtsFile$1(srcItem.absPath));
59149
59390
  // Copy .d.ts files from src to dist
@@ -59165,6 +59406,12 @@ const generateTypesOutput = async (config, compilerCtx, buildCtx, outputTarget)
59165
59406
  }
59166
59407
  };
59167
59408
 
59409
+ /**
59410
+ * Entrypoint for generating types for all output targets
59411
+ * @param config the Stencil configuration associated with the project being compiled
59412
+ * @param compilerCtx the current compiler context
59413
+ * @param buildCtx the context associated with the current build
59414
+ */
59168
59415
  const outputTypes = async (config, compilerCtx, buildCtx) => {
59169
59416
  const outputTargets = config.outputTargets.filter(isOutputTargetDistTypes);
59170
59417
  if (outputTargets.length === 0) {
@@ -63816,7 +64063,7 @@ const getComponentPathContent = (componentGraph, outputTarget) => {
63816
64063
  const dependencies = [
63817
64064
  {
63818
64065
  name: "@stencil/core",
63819
- version: "2.14.0",
64066
+ version: "2.15.0",
63820
64067
  main: "compiler/stencil.js",
63821
64068
  resources: [
63822
64069
  "package.json",
@@ -64207,11 +64454,20 @@ const validateCopy = (copy, defaultCopy = []) => {
64207
64454
  return unique(copy, (task) => `${task.src}:${task.dest}:${task.keepDirStructure}`);
64208
64455
  };
64209
64456
 
64457
+ /**
64458
+ * Validate one or more `dist-custom-elements` output targets. Validation of an output target may involve back-filling
64459
+ * fields that are omitted with sensible defaults and/or creating additional supporting output targets that were not
64460
+ * explicitly defined by the user
64461
+ * @param config the Stencil configuration associated with the project being compiled
64462
+ * @param userOutputs the output target(s) specified by the user
64463
+ * @returns the validated output target(s)
64464
+ */
64210
64465
  const validateCustomElement = (config, userOutputs) => {
64211
- return userOutputs.filter(isOutputTargetDistCustomElements).reduce((arr, o) => {
64466
+ const defaultDir = 'dist';
64467
+ return userOutputs.filter(isOutputTargetDistCustomElements).reduce((outputs, o) => {
64212
64468
  const outputTarget = {
64213
64469
  ...o,
64214
- dir: getAbsolutePath(config, o.dir || 'dist/components'),
64470
+ dir: getAbsolutePath(config, o.dir || join(defaultDir, 'components')),
64215
64471
  };
64216
64472
  if (!isBoolean$1(outputTarget.empty)) {
64217
64473
  outputTarget.empty = true;
@@ -64219,16 +64475,25 @@ const validateCustomElement = (config, userOutputs) => {
64219
64475
  if (!isBoolean$1(outputTarget.externalRuntime)) {
64220
64476
  outputTarget.externalRuntime = true;
64221
64477
  }
64478
+ // unlike other output targets, Stencil does not allow users to define the output location of types at this time
64479
+ if (outputTarget.generateTypeDeclarations) {
64480
+ const typesDirectory = getAbsolutePath(config, join(defaultDir, 'types'));
64481
+ outputs.push({
64482
+ type: DIST_TYPES,
64483
+ dir: outputTarget.dir,
64484
+ typesDir: typesDirectory,
64485
+ });
64486
+ }
64222
64487
  outputTarget.copy = validateCopy(outputTarget.copy, []);
64223
64488
  if (outputTarget.copy.length > 0) {
64224
- arr.push({
64489
+ outputs.push({
64225
64490
  type: COPY,
64226
64491
  dir: config.rootDir,
64227
64492
  copy: [...outputTarget.copy],
64228
64493
  });
64229
64494
  }
64230
- arr.push(outputTarget);
64231
- return arr;
64495
+ outputs.push(outputTarget);
64496
+ return outputs;
64232
64497
  }, []);
64233
64498
  };
64234
64499
 
@@ -65002,7 +65267,18 @@ const validateTesting = (config, diagnostics) => {
65002
65267
  testing.pixelmatchThreshold = DEFAULT_PIXEL_MATCH_THRESHOLD;
65003
65268
  }
65004
65269
  if (testing.testRegex === undefined) {
65005
- testing.testRegex = '(/__tests__/.*|\\.?(test|spec|e2e))\\.(tsx?|ts?|jsx?|js?)$';
65270
+ /**
65271
+ * The test regex covers cases of:
65272
+ * - files under a `__tests__` directory
65273
+ * - the case where a test file has a name such as `test.ts`, `spec.ts` or `e2e.ts`.
65274
+ * - these files can use any of the following file extensions: .ts, .tsx, .js, .jsx.
65275
+ * - this regex only handles the entire path of a file, e.g. `/some/path/e2e.ts`
65276
+ * - the case where a test file ends with `.test.ts`, `.spec.ts`, or `.e2e.ts`.
65277
+ * - these files can use any of the following file extensions: .ts, .tsx, .js, .jsx.
65278
+ * - this regex case shall match file names such as `my-cmp.spec.ts`, `test.spec.ts`
65279
+ * - this regex case shall not match file names such as `attest.ts`, `bespec.ts`
65280
+ */
65281
+ testing.testRegex = '(/__tests__/.*|(\\.|/)(test|spec|e2e))\\.[jt]sx?$';
65006
65282
  }
65007
65283
  if (Array.isArray(testing.testMatch)) {
65008
65284
  delete testing.testRegex;