@stencil/core 2.14.1 → 2.15.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 (41) hide show
  1. package/bin/stencil +19 -13
  2. package/cli/index.cjs +72 -55
  3. package/cli/index.js +72 -55
  4. package/cli/package.json +1 -1
  5. package/compiler/package.json +1 -1
  6. package/compiler/stencil.js +248 -57
  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-public-compiler.d.ts +18 -14
  29. package/internal/testing/package.json +1 -1
  30. package/mock-doc/index.cjs +13 -3
  31. package/mock-doc/index.d.ts +4 -0
  32. package/mock-doc/index.js +13 -3
  33. package/mock-doc/package.json +1 -1
  34. package/package.json +7 -5
  35. package/screenshot/package.json +1 -1
  36. package/sys/node/index.js +11 -11
  37. package/sys/node/node-fetch.js +1 -1
  38. package/sys/node/package.json +1 -1
  39. package/sys/node/worker.js +1 -1
  40. package/testing/index.js +8 -8
  41. package/testing/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil Compiler v2.14.1 | MIT Licensed | https://stenciljs.com
2
+ Stencil Compiler v2.15.1 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  (function(exports) {
5
5
  'use strict';
@@ -872,7 +872,7 @@ const normalizeDiagnostic = (compilerCtx, diagnostic) => {
872
872
  diagnostic.messageText = diagnostic.messageText.message;
873
873
  }
874
874
  else if (typeof diagnostic.messageText === 'string' && diagnostic.messageText.indexOf('Error: ') === 0) {
875
- diagnostic.messageText = diagnostic.messageText.substr(7);
875
+ diagnostic.messageText = diagnostic.messageText.slice(7);
876
876
  }
877
877
  }
878
878
  if (diagnostic.messageText) {
@@ -1161,7 +1161,7 @@ const loadRollupDiagnostics = (config, compilerCtx, buildCtx, rollupError) => {
1161
1161
  };
1162
1162
  diagnostic.lineNumber = errorLine.lineNumber;
1163
1163
  diagnostic.columnNumber = errorLine.errorCharStart;
1164
- const highlightLine = errorLine.text.substr(loc.column);
1164
+ const highlightLine = errorLine.text.slice(loc.column);
1165
1165
  for (let i = 0; i < highlightLine.length; i++) {
1166
1166
  if (charBreak.has(highlightLine.charAt(i))) {
1167
1167
  break;
@@ -1588,7 +1588,7 @@ const createJsVarName = (fileName) => {
1588
1588
  fileName = fileName.replace(/[|;$%@"<>()+,.{}_\!\/\\]/g, '-');
1589
1589
  fileName = dashToPascalCase$1(fileName);
1590
1590
  if (fileName.length > 1) {
1591
- fileName = fileName[0].toLowerCase() + fileName.substr(1);
1591
+ fileName = fileName[0].toLowerCase() + fileName.slice(1);
1592
1592
  }
1593
1593
  else {
1594
1594
  fileName = fileName.toLowerCase();
@@ -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) {
@@ -1705,15 +1711,16 @@ const SKIP_DEPS = ['@stencil/core'];
1705
1711
  * @returns an error message if the tag has an invalid name, undefined if the tag name passes all checks
1706
1712
  */
1707
1713
  const validateComponentTag = (tag) => {
1714
+ // we want to check this first since we call some String.prototype methods below
1715
+ if (typeof tag !== 'string') {
1716
+ return `Tag "${tag}" must be a string type`;
1717
+ }
1708
1718
  if (tag !== tag.trim()) {
1709
1719
  return `Tag can not contain white spaces`;
1710
1720
  }
1711
1721
  if (tag !== tag.toLowerCase()) {
1712
1722
  return `Tag can not contain upper case characters`;
1713
1723
  }
1714
- if (typeof tag !== 'string') {
1715
- return `Tag "${tag}" must be a string type`;
1716
- }
1717
1724
  if (tag.length === 0) {
1718
1725
  return `Received empty tag value`;
1719
1726
  }
@@ -3967,7 +3974,7 @@ const createCustomResolverAsync = (sys, inMemoryFs, exts) => {
3967
3974
  };
3968
3975
  };
3969
3976
 
3970
- const buildId = '20220307172718';
3977
+ const buildId = '20220418164701';
3971
3978
  const minfyJsId = 'terser5.6.1_7';
3972
3979
  const optimizeCssId = 'autoprefixer10.2.5_postcss8.2.8_7';
3973
3980
  const parse5Version = '6.0.1';
@@ -3975,8 +3982,8 @@ const rollupVersion = '2.42.3';
3975
3982
  const sizzleVersion = '2.42.3';
3976
3983
  const terserVersion = '5.6.1';
3977
3984
  const typescriptVersion = '4.5.4';
3978
- const vermoji = '🐦';
3979
- const version$3 = '2.14.1';
3985
+ const vermoji = '🐼';
3986
+ const version$3 = '2.15.1';
3980
3987
  const versions = {
3981
3988
  stencil: version$3,
3982
3989
  parse5: parse5Version,
@@ -4436,7 +4443,7 @@ const createSystem = (c) => {
4436
4443
  const hashArray = Array.from(new Uint8Array(arrayBuffer)); // convert buffer to byte array
4437
4444
  let hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
4438
4445
  if (typeof hashLength === 'number') {
4439
- hashHex = hashHex.substr(0, hashLength);
4446
+ hashHex = hashHex.slice(0, hashLength);
4440
4447
  }
4441
4448
  return hashHex;
4442
4449
  };
@@ -5061,13 +5068,13 @@ const getCssSelectors = (sel) => {
5061
5068
  if (items[i].length === 0)
5062
5069
  continue;
5063
5070
  if (items[i].charAt(0) === '.') {
5064
- SELECTORS.classNames.push(items[i].substr(1));
5071
+ SELECTORS.classNames.push(items[i].slice(1));
5065
5072
  }
5066
5073
  else if (items[i].charAt(0) === '#') {
5067
- SELECTORS.ids.push(items[i].substr(1));
5074
+ SELECTORS.ids.push(items[i].slice(1));
5068
5075
  }
5069
5076
  else if (items[i].charAt(0) === '[') {
5070
- items[i] = items[i].substr(1).split('=')[0].split(']')[0].trim();
5077
+ items[i] = items[i].slice(1).split('=')[0].split(']')[0].trim();
5071
5078
  SELECTORS.attrs.push(items[i].toLowerCase());
5072
5079
  }
5073
5080
  else if (/[a-z]/g.test(items[i].charAt(0))) {
@@ -8656,7 +8663,7 @@ const loadMinifyJsDiagnostics = (sourceText, diagnostics, error) => {
8656
8663
  };
8657
8664
  d.lineNumber = errorLine.lineNumber;
8658
8665
  d.columnNumber = errorLine.errorCharStart;
8659
- const highlightLine = errorLine.text.substr(d.columnNumber);
8666
+ const highlightLine = errorLine.text.slice(d.columnNumber);
8660
8667
  for (let i = 0; i < highlightLine.length; i++) {
8661
8668
  if (MINIFY_CHAR_BREAK.has(highlightLine.charAt(i))) {
8662
8669
  break;
@@ -9510,7 +9517,7 @@ const standardNormalizeHref = (prerenderConfig, diagnostics, url) => {
9510
9517
  // url should NOT have a trailing slash
9511
9518
  if (href.endsWith('/') && url.pathname !== '/') {
9512
9519
  // this has a trailing slash and it's not the root path
9513
- href = href.substr(0, href.length - 1);
9520
+ href = href.slice(0, -1);
9514
9521
  }
9515
9522
  }
9516
9523
  return href;
@@ -14361,7 +14368,7 @@ function toDataAttribute(str) {
14361
14368
  .toLowerCase());
14362
14369
  }
14363
14370
  function dashToPascalCase(str) {
14364
- str = String(str).substr(5);
14371
+ str = String(str).slice(5);
14365
14372
  return str
14366
14373
  .split('-')
14367
14374
  .map((segment, index) => {
@@ -14565,7 +14572,7 @@ function cssCaseToJsCase(str) {
14565
14572
  .split('-')
14566
14573
  .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
14567
14574
  .join('');
14568
- str = str.substr(0, 1).toLowerCase() + str.substr(1);
14575
+ str = str.slice(0, 1).toLowerCase() + str.slice(1);
14569
14576
  }
14570
14577
  return str;
14571
14578
  }
@@ -16918,6 +16925,17 @@ MockElement.prototype.cloneNode = function (deep) {
16918
16925
  return cloned;
16919
16926
  };
16920
16927
 
16928
+ let sharedDocument;
16929
+ function parseHtmlToDocument(html, ownerDocument = null) {
16930
+ if (ownerDocument == null) {
16931
+ if (sharedDocument == null) {
16932
+ sharedDocument = new MockDocument();
16933
+ }
16934
+ ownerDocument = sharedDocument;
16935
+ }
16936
+ return parseDocumentUtil(ownerDocument, html);
16937
+ }
16938
+
16921
16939
  class MockHeaders {
16922
16940
  constructor(init) {
16923
16941
  this._values = [];
@@ -17125,6 +17143,15 @@ class MockResponse {
17125
17143
  }
17126
17144
  }
17127
17145
 
17146
+ class MockDOMParser {
17147
+ parseFromString(htmlToParse, mimeType) {
17148
+ if (mimeType !== 'text/html') {
17149
+ console.error('XML parsing not implemented yet, continuing as html');
17150
+ }
17151
+ return parseHtmlToDocument(htmlToParse);
17152
+ }
17153
+ }
17154
+
17128
17155
  function addGlobalsToWindowPrototype(mockWinPrototype) {
17129
17156
  GLOBAL_CONSTRUCTORS.forEach(([cstrName, Cstr]) => {
17130
17157
  Object.defineProperty(mockWinPrototype, cstrName, {
@@ -17147,6 +17174,7 @@ const GLOBAL_CONSTRUCTORS = [
17147
17174
  ['MouseEvent', MockMouseEvent],
17148
17175
  ['Request', MockRequest],
17149
17176
  ['Response', MockResponse],
17177
+ ['DOMParser', MockDOMParser],
17150
17178
  ['HTMLAnchorElement', MockAnchorElement],
17151
17179
  ['HTMLBaseElement', MockBaseElement],
17152
17180
  ['HTMLButtonElement', MockButtonElement],
@@ -54294,31 +54322,55 @@ const getTextOfPropertyName = (propName) => {
54294
54322
  }
54295
54323
  return undefined;
54296
54324
  };
54325
+ /**
54326
+ * Generate a series of type references for a given AST node
54327
+ * @param baseNode the AST node to pull type references from
54328
+ * @param sourceFile the source file in which the provided `baseNode` exists
54329
+ * @returns the generated series of type references
54330
+ */
54297
54331
  const getAttributeTypeInfo = (baseNode, sourceFile) => {
54298
54332
  const allReferences = {};
54299
- getAllTypeReferences(baseNode).forEach((rt) => {
54300
- allReferences[rt] = getTypeReferenceLocation(rt, sourceFile);
54333
+ getAllTypeReferences(baseNode).forEach((typeName) => {
54334
+ allReferences[typeName] = getTypeReferenceLocation(typeName, sourceFile);
54301
54335
  });
54302
54336
  return allReferences;
54303
54337
  };
54338
+ /**
54339
+ * Get the text-based name from a TypeScript `EntityName`, which is an identifier of some form
54340
+ * @param entity a TypeScript `EntityName` to retrieve the name of an entity from
54341
+ * @returns the entity's name
54342
+ */
54304
54343
  const getEntityName = (entity) => {
54305
54344
  if (t.isIdentifier(entity)) {
54306
54345
  return entity.escapedText.toString();
54307
54346
  }
54308
54347
  else {
54348
+ // We have qualified name - e.g. const x: Foo.Bar.Baz;
54349
+ // Recurse until we find the 'base' of the qualified name
54309
54350
  return getEntityName(entity.left);
54310
54351
  }
54311
54352
  };
54353
+ /**
54354
+ * Recursively walks the provided AST to collect all TypeScript type references that are found
54355
+ * @param node the node to walk to retrieve type information
54356
+ * @returns the collected type references
54357
+ */
54312
54358
  const getAllTypeReferences = (node) => {
54313
54359
  const referencedTypes = [];
54314
54360
  const visit = (node) => {
54361
+ /**
54362
+ * A type reference node will refer to some type T.
54363
+ * e.g: In `const foo: Bar = {...}` the reference node will contain semantic information about `Bar`.
54364
+ * In TypeScript, types that are also keywords (e.g. `number` in `const foo: number`) are not `TypeReferenceNode`s.
54365
+ */
54315
54366
  if (t.isTypeReferenceNode(node)) {
54316
54367
  referencedTypes.push(getEntityName(node.typeName));
54317
54368
  if (node.typeArguments) {
54369
+ // a type may contain types itself (e.g. generics - Foo<Bar>)
54318
54370
  node.typeArguments
54319
- .filter((ta) => t.isTypeReferenceNode(ta))
54320
- .forEach((tr) => {
54321
- const typeName = tr.typeName;
54371
+ .filter((typeArg) => t.isTypeReferenceNode(typeArg))
54372
+ .forEach((typeRef) => {
54373
+ const typeName = typeRef.typeName;
54322
54374
  if (typeName && typeName.escapedText) {
54323
54375
  referencedTypes.push(typeName.escapedText.toString());
54324
54376
  }
@@ -54339,6 +54391,22 @@ const validateReferences = (diagnostics, references, node) => {
54339
54391
  }
54340
54392
  });
54341
54393
  };
54394
+ /**
54395
+ * Determine where a TypeScript type reference originates from. This is accomplished by interrogating the AST node in
54396
+ * which the type's name appears
54397
+ *
54398
+ * A type may originate:
54399
+ * - from the same file where it is used (a type is declared in some file, `foo.ts`, and later used in the same file)
54400
+ * - from another file (I.E. it is imported and should have an import statement somewhere in the file)
54401
+ * - from a global context
54402
+ * - etc.
54403
+ *
54404
+ * The type may be declared using the `type` or `interface` keywords.
54405
+ *
54406
+ * @param typeName the name of the type to find the origination of
54407
+ * @param tsNode the TypeScript AST node being searched for the provided `typeName`
54408
+ * @returns the context stating where the type originates from
54409
+ */
54342
54410
  const getTypeReferenceLocation = (typeName, tsNode) => {
54343
54411
  const sourceFileObj = tsNode.getSourceFile();
54344
54412
  // Loop through all top level imports to find any reference to the type for 'import' reference location
@@ -58837,8 +58905,18 @@ const serializeCollectionDependencies = (compilerCtx) => {
58837
58905
  return sortBy(collectionDeps, (item) => item.name);
58838
58906
  };
58839
58907
 
58908
+ /**
58909
+ * Update a type declaration file's import declarations using the module `@stencil/core`
58910
+ * @param typesDir the directory where type declaration files are expected to exist
58911
+ * @param dtsFilePath the path of the type declaration file being updated, used to derive the correct import declaration
58912
+ * module
58913
+ * @param dtsContent the content of a type declaration file to update
58914
+ * @returns the updated type declaration file contents
58915
+ */
58840
58916
  const updateStencilTypesImports = (typesDir, dtsFilePath, dtsContent) => {
58841
58917
  const dir = dirname(dtsFilePath);
58918
+ // determine the relative path between the directory of the .d.ts file and the types directory. this value may result
58919
+ // in '.' if they are the same
58842
58920
  const relPath = relative$1(dir, typesDir);
58843
58921
  let coreDtsPath = join(relPath, CORE_FILENAME);
58844
58922
  if (!coreDtsPath.startsWith('.')) {
@@ -58851,6 +58929,12 @@ const updateStencilTypesImports = (typesDir, dtsFilePath, dtsContent) => {
58851
58929
  }
58852
58930
  return dtsContent;
58853
58931
  };
58932
+ /**
58933
+ * Writes Stencil core typings file to disk for a dist-* output target
58934
+ * @param config the Stencil configuration associated with the project being compiled
58935
+ * @param compilerCtx the current compiler context
58936
+ * @returns the results of writing one or more type declaration files to disk
58937
+ */
58854
58938
  const copyStencilCoreDts = async (config, compilerCtx) => {
58855
58939
  const typesOutputTargets = config.outputTargets.filter(isOutputTargetDistTypes).filter((o) => o.typesDir);
58856
58940
  const srcStencilDtsPath = join(config.sys.getCompilerExecutingPath(), '..', '..', 'internal', CORE_DTS);
@@ -58883,8 +58967,13 @@ const sortImportNames = (a, b) => {
58883
58967
  return 0;
58884
58968
  };
58885
58969
 
58886
- const generateEventTypes = (cmpEvents) => {
58887
- return cmpEvents.map((cmpEvent) => {
58970
+ /**
58971
+ * Generates the individual event types for all @Event() decorated events in a component
58972
+ * @param cmpMeta component runtime metadata for a single component
58973
+ * @returns the generated type metadata
58974
+ */
58975
+ const generateEventTypes = (cmpMeta) => {
58976
+ return cmpMeta.events.map((cmpEvent) => {
58888
58977
  const name = `on${toTitleCase(cmpEvent.name)}`;
58889
58978
  const type = cmpEvent.complexType.original
58890
58979
  ? `(event: CustomEvent<${cmpEvent.complexType.original}>) => void`
@@ -58900,8 +58989,13 @@ const generateEventTypes = (cmpEvents) => {
58900
58989
  });
58901
58990
  };
58902
58991
 
58903
- const generateMethodTypes = (cmpMethods) => {
58904
- return cmpMethods.map((cmpMethod) => ({
58992
+ /**
58993
+ * Generates the individual event types for all @Method() decorated events in a component
58994
+ * @param cmpMeta component runtime metadata for a single component
58995
+ * @returns the generated type metadata
58996
+ */
58997
+ const generateMethodTypes = (cmpMeta) => {
58998
+ return cmpMeta.methods.map((cmpMethod) => ({
58905
58999
  name: cmpMethod.name,
58906
59000
  type: cmpMethod.complexType.signature,
58907
59001
  optional: false,
@@ -58911,6 +59005,11 @@ const generateMethodTypes = (cmpMethods) => {
58911
59005
  }));
58912
59006
  };
58913
59007
 
59008
+ /**
59009
+ * Generates the individual event types for all @Prop() decorated events in a component
59010
+ * @param cmpMeta component runtime metadata for a single component
59011
+ * @returns the generated type metadata
59012
+ */
58914
59013
  const generatePropTypes = (cmpMeta) => {
58915
59014
  return [
58916
59015
  ...cmpMeta.properties.map((cmpProp) => ({
@@ -58933,21 +59032,21 @@ const generatePropTypes = (cmpMeta) => {
58933
59032
  };
58934
59033
 
58935
59034
  /**
58936
- * Generate a string based on the types that are defined within a component.
58937
- *
59035
+ * Generate a string based on the types that are defined within a component
58938
59036
  * @param cmp the metadata for the component that a type definition string is generated for
58939
- * @param importPath the path of the component file
59037
+ * @param areTypesInternal `true` if types being generated are for a project's internal purposes, `false` otherwise
59038
+ * @returns the generated types string alongside additional metadata
58940
59039
  */
58941
- const generateComponentTypes = (cmp, internal) => {
59040
+ const generateComponentTypes = (cmp, areTypesInternal) => {
58942
59041
  const tagName = cmp.tagName.toLowerCase();
58943
59042
  const tagNameAsPascal = dashToPascalCase$1(tagName);
58944
59043
  const htmlElementName = `HTML${tagNameAsPascal}Element`;
58945
59044
  const propAttributes = generatePropTypes(cmp);
58946
- const methodAttributes = generateMethodTypes(cmp.methods);
58947
- const eventAttributes = generateEventTypes(cmp.events);
58948
- const componentAttributes = attributesToMultiLineString([...propAttributes, ...methodAttributes], false, internal);
59045
+ const methodAttributes = generateMethodTypes(cmp);
59046
+ const eventAttributes = generateEventTypes(cmp);
59047
+ const componentAttributes = attributesToMultiLineString([...propAttributes, ...methodAttributes], false, areTypesInternal);
58949
59048
  const isDep = cmp.isCollectionDependency;
58950
- const jsxAttributes = attributesToMultiLineString([...propAttributes, ...eventAttributes], true, internal);
59049
+ const jsxAttributes = attributesToMultiLineString([...propAttributes, ...eventAttributes], true, areTypesInternal);
58951
59050
  const element = [
58952
59051
  ` interface ${htmlElementName} extends Components.${tagNameAsPascal}, HTMLStencilElement {`,
58953
59052
  ` }`,
@@ -58989,13 +59088,12 @@ const attributesToMultiLineString = (attributes, jsxAttributes, internal) => {
58989
59088
  };
58990
59089
 
58991
59090
  /**
58992
- * Find all referenced types by a component and add them to the importDataObj and return the newly
58993
- * updated importDataObj
58994
- *
59091
+ * Find all referenced types by a component and add them to the `importDataObj` parameter
58995
59092
  * @param importDataObj key/value of type import file, each value is an array of imported types
58996
- * @param cmpMeta the metadata for the component that is referencing the types
59093
+ * @param allTypes an output parameter containing a map of seen types and the number of times the type has been seen
59094
+ * @param cmp the metadata associated with the component whose types are being inspected
58997
59095
  * @param filePath the path of the component file
58998
- * @param config general config that all of stencil uses
59096
+ * @returns the updated import data
58999
59097
  */
59000
59098
  const updateReferenceTypeImports = (importDataObj, allTypes, cmp, filePath) => {
59001
59099
  const updateImportReferences = updateImportReferenceFactory(allTypes, filePath);
@@ -59052,16 +59150,25 @@ const updateImportReferenceFactory = (allTypes, filePath) => {
59052
59150
  };
59053
59151
  };
59054
59152
 
59153
+ /**
59154
+ * Generates and writes a `components.d.ts` file to disk. This file may be written to the `src` directory of a project,
59155
+ * or be written to a directory that is meant to be distributed (e.g. the output directory of `dist-custom-elements`).
59156
+ * @param config the Stencil configuration associated with the project being compiled
59157
+ * @param compilerCtx the current compiler context
59158
+ * @param buildCtx the context associated with the current build
59159
+ * @param destination the relative directory in the filesystem to write the type declaration file to
59160
+ * @returns `true` if the type declaration file written to disk has changed, `false` otherwise
59161
+ */
59055
59162
  const generateAppTypes = async (config, compilerCtx, buildCtx, destination) => {
59056
59163
  // only gather components that are still root ts files we've found and have component metadata
59057
59164
  // the compilerCtx cache may still have files that may have been deleted/renamed
59058
59165
  const timespan = buildCtx.createTimeSpan(`generated app types started`, true);
59059
- const internal = destination === 'src';
59166
+ const areTypesInternal = destination === 'src';
59060
59167
  // Generate d.ts files for component types
59061
- let componentTypesFileContent = generateComponentTypesFile(config, buildCtx, internal);
59168
+ let componentTypesFileContent = generateComponentTypesFile(config, buildCtx, areTypesInternal);
59062
59169
  // immediately write the components.d.ts file to disk and put it into fs memory
59063
59170
  let componentsDtsFilePath = getComponentsDtsSrcFilePath(config);
59064
- if (!internal) {
59171
+ if (!areTypesInternal) {
59065
59172
  componentsDtsFilePath = resolve$1(destination, GENERATED_DTS$1);
59066
59173
  componentTypesFileContent = updateStencilTypesImports(destination, componentsDtsFilePath, componentTypesFileContent);
59067
59174
  }
@@ -59077,18 +59184,20 @@ const generateAppTypes = async (config, compilerCtx, buildCtx, destination) => {
59077
59184
  return hasComponentsDtsChanged;
59078
59185
  };
59079
59186
  /**
59080
- * Generate the component.d.ts file that contains types for all components
59081
- * @param config the project build configuration
59082
- * @param options compiler options from tsconfig
59187
+ * Generates a `component.d.ts` file's contents, which contains the typings for all components in a Stencil project
59188
+ * @param config the Stencil configuration associated with the project being compiled
59189
+ * @param buildCtx the context associated with the current build
59190
+ * @param areTypesInternal determines if non-exported type definitions are being generated or not
59191
+ * @returns the contents of the `components.d.ts` file
59083
59192
  */
59084
- const generateComponentTypesFile = (config, buildCtx, internal) => {
59193
+ const generateComponentTypesFile = (config, buildCtx, areTypesInternal) => {
59085
59194
  let typeImportData = {};
59086
59195
  const c = [];
59087
59196
  const allTypes = new Map();
59088
59197
  const components = buildCtx.components.filter((m) => !m.isCollectionDependency);
59089
59198
  const modules = components.map((cmp) => {
59090
59199
  typeImportData = updateReferenceTypeImports(typeImportData, allTypes, cmp, cmp.sourceFilePath);
59091
- return generateComponentTypes(cmp, internal);
59200
+ return generateComponentTypes(cmp, areTypesInternal);
59092
59201
  });
59093
59202
  c.push(COMPONENTS_DTS_HEADER);
59094
59203
  c.push(`import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";`);
@@ -59219,10 +59328,28 @@ const relDts$1 = (fromPath, dtsPath) => {
59219
59328
  return normalizePath$1(dtsPath.replace('.d.ts', ''));
59220
59329
  };
59221
59330
 
59331
+ /**
59332
+ * Entrypoint for generating types for one or more `dist-custom-elements` output targets defined in a Stencil project's
59333
+ * configuration
59334
+ * @param config the Stencil configuration associated with the project being compiled
59335
+ * @param compilerCtx the current compiler context
59336
+ * @param buildCtx the context associated with the current build
59337
+ * @param distDtsFilePath the path to a type declaration file (.d.ts) that is being generated for the output target.
59338
+ * This path is not necessarily the `components.d.ts` file that is found in the root of a project's `src` directory.
59339
+ */
59222
59340
  const generateCustomElementsTypes = async (config, compilerCtx, buildCtx, distDtsFilePath) => {
59223
59341
  const outputTargets = config.outputTargets.filter(isOutputTargetDistCustomElements);
59224
59342
  await Promise.all(outputTargets.map((outputTarget) => generateCustomElementsTypesOutput(config, compilerCtx, buildCtx, distDtsFilePath, outputTarget)));
59225
59343
  };
59344
+ /**
59345
+ * Generates types for a single `dist-custom-elements` output target definition in a Stencil project's configuration
59346
+ * @param config the Stencil configuration associated with the project being compiled
59347
+ * @param compilerCtx the current compiler context
59348
+ * @param buildCtx the context associated with the current build
59349
+ * @param distDtsFilePath the path to a type declaration file (.d.ts) that is being generated for the output target.
59350
+ * This path is not necessarily the `components.d.ts` file that is found in the root of a project's `src` directory.
59351
+ * @param outputTarget the output target for which types are being currently generated
59352
+ */
59226
59353
  const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx, distDtsFilePath, outputTarget) => {
59227
59354
  const customElementsDtsPath = join(outputTarget.dir, 'index.d.ts');
59228
59355
  const componentsDtsRelPath = relDts(outputTarget.dir, distDtsFilePath);
@@ -59238,7 +59365,7 @@ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx,
59238
59365
  ` * "setAssetPath(document.currentScript.src)", or using a bundler's replace plugin to`,
59239
59366
  ` * dynamically set the path at build time, such as "setAssetPath(process.env.ASSET_PATH)".`,
59240
59367
  ` * But do note that this configuration depends on how your script is bundled, or lack of`,
59241
- ` * bunding, and where your assets can be loaded from. Additionally custom bundling`,
59368
+ ` * bundling, and where your assets can be loaded from. Additionally custom bundling`,
59242
59369
  ` * will have to ensure the static assets are copied to its build directory.`,
59243
59370
  ` */`,
59244
59371
  `export declare const setAssetPath: (path: string) => void;`,
@@ -59273,6 +59400,13 @@ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx,
59273
59400
  await compilerCtx.fs.writeFile(filePath, dtsCode, { outputTargetType: outputTarget.type });
59274
59401
  }));
59275
59402
  };
59403
+ /**
59404
+ * Generate a type declaration file for a specific Stencil component
59405
+ * @param componentsDtsRelPath the path to a root type declaration file from which commonly used entities can be
59406
+ * referenced from in the newly generated file
59407
+ * @param cmp the component to generate the type declaration file for
59408
+ * @returns the contents of the type declaration file for the provided `cmp`
59409
+ */
59276
59410
  const generateCustomElementType = (componentsDtsRelPath, cmp) => {
59277
59411
  const tagNameAsPascal = dashToPascalCase$1(cmp.tagName);
59278
59412
  const o = [
@@ -59291,6 +59425,13 @@ const generateCustomElementType = (componentsDtsRelPath, cmp) => {
59291
59425
  ];
59292
59426
  return o.join('\n');
59293
59427
  };
59428
+ /**
59429
+ * Determines the relative path between two provided paths. If a type declaration file extension is present on
59430
+ * `dtsPath`, it will be removed from the computed relative path.
59431
+ * @param fromPath the path from which to start at
59432
+ * @param dtsPath the destination path
59433
+ * @returns the relative path from the provided `fromPath` to the `dtsPath`
59434
+ */
59294
59435
  const relDts = (fromPath, dtsPath) => {
59295
59436
  dtsPath = relative$1(fromPath, dtsPath);
59296
59437
  if (!dtsPath.startsWith('.')) {
@@ -59299,13 +59440,28 @@ const relDts = (fromPath, dtsPath) => {
59299
59440
  return normalizePath$1(dtsPath.replace('.d.ts', ''));
59300
59441
  };
59301
59442
 
59443
+ /**
59444
+ * For a single output target, generate types, then copy the Stencil core type declaration file
59445
+ * @param config the Stencil configuration associated with the project being compiled
59446
+ * @param compilerCtx the current compiler context
59447
+ * @param buildCtx the context associated with the current build
59448
+ * @param outputTarget the output target to generate types for
59449
+ */
59302
59450
  const generateTypes = async (config, compilerCtx, buildCtx, outputTarget) => {
59303
59451
  if (!buildCtx.hasError) {
59304
59452
  await generateTypesOutput(config, compilerCtx, buildCtx, outputTarget);
59305
59453
  await copyStencilCoreDts(config, compilerCtx);
59306
59454
  }
59307
59455
  };
59456
+ /**
59457
+ * Generate type definition files and write them to a dist directory
59458
+ * @param config the Stencil configuration associated with the project being compiled
59459
+ * @param compilerCtx the current compiler context
59460
+ * @param buildCtx the context associated with the current build
59461
+ * @param outputTarget the output target to generate types for
59462
+ */
59308
59463
  const generateTypesOutput = async (config, compilerCtx, buildCtx, outputTarget) => {
59464
+ // get all type declaration files in a project's src/ directory
59309
59465
  const srcDirItems = await compilerCtx.fs.readdir(config.srcDir, { recursive: false });
59310
59466
  const srcDtsFiles = srcDirItems.filter((srcItem) => srcItem.isFile && isDtsFile$1(srcItem.absPath));
59311
59467
  // Copy .d.ts files from src to dist
@@ -59327,6 +59483,12 @@ const generateTypesOutput = async (config, compilerCtx, buildCtx, outputTarget)
59327
59483
  }
59328
59484
  };
59329
59485
 
59486
+ /**
59487
+ * Entrypoint for generating types for all output targets
59488
+ * @param config the Stencil configuration associated with the project being compiled
59489
+ * @param compilerCtx the current compiler context
59490
+ * @param buildCtx the context associated with the current build
59491
+ */
59330
59492
  const outputTypes = async (config, compilerCtx, buildCtx) => {
59331
59493
  const outputTargets = config.outputTargets.filter(isOutputTargetDistTypes);
59332
59494
  if (outputTargets.length === 0) {
@@ -61981,7 +62143,7 @@ const validateManifestJsonIcon = async (compilerCtx, buildCtx, manifestFilePath,
61981
62143
  return;
61982
62144
  }
61983
62145
  if (iconSrc.startsWith('/')) {
61984
- iconSrc = iconSrc.substr(1);
62146
+ iconSrc = iconSrc.slice(1);
61985
62147
  }
61986
62148
  const manifestDir = dirname(manifestFilePath);
61987
62149
  const iconPath = join(manifestDir, iconSrc);
@@ -63978,7 +64140,7 @@ const getComponentPathContent = (componentGraph, outputTarget) => {
63978
64140
  const dependencies = [
63979
64141
  {
63980
64142
  name: "@stencil/core",
63981
- version: "2.14.1",
64143
+ version: "2.15.1",
63982
64144
  main: "compiler/stencil.js",
63983
64145
  resources: [
63984
64146
  "package.json",
@@ -64369,11 +64531,20 @@ const validateCopy = (copy, defaultCopy = []) => {
64369
64531
  return unique(copy, (task) => `${task.src}:${task.dest}:${task.keepDirStructure}`);
64370
64532
  };
64371
64533
 
64534
+ /**
64535
+ * Validate one or more `dist-custom-elements` output targets. Validation of an output target may involve back-filling
64536
+ * fields that are omitted with sensible defaults and/or creating additional supporting output targets that were not
64537
+ * explicitly defined by the user
64538
+ * @param config the Stencil configuration associated with the project being compiled
64539
+ * @param userOutputs the output target(s) specified by the user
64540
+ * @returns the validated output target(s)
64541
+ */
64372
64542
  const validateCustomElement = (config, userOutputs) => {
64373
- return userOutputs.filter(isOutputTargetDistCustomElements).reduce((arr, o) => {
64543
+ const defaultDir = 'dist';
64544
+ return userOutputs.filter(isOutputTargetDistCustomElements).reduce((outputs, o) => {
64374
64545
  const outputTarget = {
64375
64546
  ...o,
64376
- dir: getAbsolutePath(config, o.dir || 'dist/components'),
64547
+ dir: getAbsolutePath(config, o.dir || join(defaultDir, 'components')),
64377
64548
  };
64378
64549
  if (!isBoolean$1(outputTarget.empty)) {
64379
64550
  outputTarget.empty = true;
@@ -64381,16 +64552,25 @@ const validateCustomElement = (config, userOutputs) => {
64381
64552
  if (!isBoolean$1(outputTarget.externalRuntime)) {
64382
64553
  outputTarget.externalRuntime = true;
64383
64554
  }
64555
+ // unlike other output targets, Stencil does not allow users to define the output location of types at this time
64556
+ if (outputTarget.generateTypeDeclarations) {
64557
+ const typesDirectory = getAbsolutePath(config, join(defaultDir, 'types'));
64558
+ outputs.push({
64559
+ type: DIST_TYPES,
64560
+ dir: outputTarget.dir,
64561
+ typesDir: typesDirectory,
64562
+ });
64563
+ }
64384
64564
  outputTarget.copy = validateCopy(outputTarget.copy, []);
64385
64565
  if (outputTarget.copy.length > 0) {
64386
- arr.push({
64566
+ outputs.push({
64387
64567
  type: COPY,
64388
64568
  dir: config.rootDir,
64389
64569
  copy: [...outputTarget.copy],
64390
64570
  });
64391
64571
  }
64392
- arr.push(outputTarget);
64393
- return arr;
64572
+ outputs.push(outputTarget);
64573
+ return outputs;
64394
64574
  }, []);
64395
64575
  };
64396
64576
 
@@ -65164,7 +65344,18 @@ const validateTesting = (config, diagnostics) => {
65164
65344
  testing.pixelmatchThreshold = DEFAULT_PIXEL_MATCH_THRESHOLD;
65165
65345
  }
65166
65346
  if (testing.testRegex === undefined) {
65167
- testing.testRegex = '(/__tests__/.*|\\.(test|spec|e2e))\\.(tsx|ts|jsx|js)$';
65347
+ /**
65348
+ * The test regex covers cases of:
65349
+ * - files under a `__tests__` directory
65350
+ * - the case where a test file has a name such as `test.ts`, `spec.ts` or `e2e.ts`.
65351
+ * - these files can use any of the following file extensions: .ts, .tsx, .js, .jsx.
65352
+ * - this regex only handles the entire path of a file, e.g. `/some/path/e2e.ts`
65353
+ * - the case where a test file ends with `.test.ts`, `.spec.ts`, or `.e2e.ts`.
65354
+ * - these files can use any of the following file extensions: .ts, .tsx, .js, .jsx.
65355
+ * - this regex case shall match file names such as `my-cmp.spec.ts`, `test.spec.ts`
65356
+ * - this regex case shall not match file names such as `attest.ts`, `bespec.ts`
65357
+ */
65358
+ testing.testRegex = '(/__tests__/.*|(\\.|/)(test|spec|e2e))\\.[jt]sx?$';
65168
65359
  }
65169
65360
  if (Array.isArray(testing.testMatch)) {
65170
65361
  delete testing.testRegex;