@stencil/core 2.16.1-0 → 2.17.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 (50) hide show
  1. package/cli/config-flags.d.ts +102 -0
  2. package/cli/index.cjs +697 -224
  3. package/cli/index.d.ts +2 -1
  4. package/cli/index.js +697 -224
  5. package/cli/package.json +1 -1
  6. package/compiler/package.json +1 -1
  7. package/compiler/stencil.js +856 -290
  8. package/compiler/stencil.min.js +2 -2
  9. package/dependencies.json +1 -1
  10. package/dev-server/client/index.js +1 -1
  11. package/dev-server/client/package.json +1 -1
  12. package/dev-server/connector.html +2 -2
  13. package/dev-server/index.js +1 -1
  14. package/dev-server/package.json +1 -1
  15. package/dev-server/server-process.js +2 -2
  16. package/internal/app-data/package.json +1 -1
  17. package/internal/client/css-shim.js +1 -1
  18. package/internal/client/dom.js +1 -1
  19. package/internal/client/index.js +11 -6
  20. package/internal/client/package.json +1 -1
  21. package/internal/client/patch-browser.js +1 -1
  22. package/internal/client/patch-esm.js +1 -1
  23. package/internal/client/shadow-css.js +1 -1
  24. package/internal/hydrate/index.js +2 -2
  25. package/internal/hydrate/package.json +1 -1
  26. package/internal/package.json +1 -1
  27. package/internal/stencil-private.d.ts +6 -2
  28. package/internal/stencil-public-compiler.d.ts +67 -48
  29. package/internal/testing/index.js +1 -1
  30. package/internal/testing/package.json +1 -1
  31. package/mock-doc/index.cjs +140 -5
  32. package/mock-doc/index.d.ts +76 -1
  33. package/mock-doc/index.js +140 -5
  34. package/mock-doc/package.json +1 -1
  35. package/package.json +2 -1
  36. package/screenshot/package.json +1 -1
  37. package/sys/node/index.js +325 -314
  38. package/sys/node/package.json +1 -1
  39. package/sys/node/worker.js +1 -1
  40. package/testing/index.d.ts +1 -1
  41. package/testing/index.js +436 -381
  42. package/testing/jest/jest-config.d.ts +1 -1
  43. package/testing/jest/jest-runner.d.ts +3 -2
  44. package/testing/jest/jest-screenshot.d.ts +1 -1
  45. package/testing/mocks.d.ts +48 -3
  46. package/testing/package.json +1 -1
  47. package/testing/puppeteer/puppeteer-browser.d.ts +2 -2
  48. package/testing/test/testing-utils.spec.d.ts +1 -0
  49. package/testing/testing-utils.d.ts +74 -2
  50. package/testing/testing.d.ts +2 -2
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil Compiler v2.16.1-0 | MIT Licensed | https://stenciljs.com
2
+ Stencil Compiler v2.17.1 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  (function(exports) {
5
5
  'use strict';
@@ -727,12 +727,27 @@ const trimFalsy = (data) => {
727
727
  return arr;
728
728
  };
729
729
 
730
- const toLowerCase = (str) => str.toLowerCase();
731
- const toDashCase = (str) => toLowerCase(str
732
- .replace(/([A-Z0-9])/g, (g) => ' ' + g[0])
730
+ /**
731
+ * Convert a string from PascalCase to dash-case
732
+ *
733
+ * @param str the string to convert
734
+ * @returns a converted string
735
+ */
736
+ const toDashCase = (str) => str
737
+ .replace(/([A-Z0-9])/g, (match) => ` ${match[0]}`)
733
738
  .trim()
734
- .replace(/ /g, '-'));
735
- const dashToPascalCase$1 = (str) => toLowerCase(str)
739
+ .split(' ')
740
+ .join('-')
741
+ .toLowerCase();
742
+ /**
743
+ * Convert a string from dash-case / kebab-case to PascalCase (or CamelCase,
744
+ * or whatever you call it!)
745
+ *
746
+ * @param str a string to convert
747
+ * @returns a converted string
748
+ */
749
+ const dashToPascalCase$1 = (str) => str
750
+ .toLowerCase()
736
751
  .split('-')
737
752
  .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
738
753
  .join('');
@@ -789,8 +804,8 @@ const pluck = (obj, keys) => {
789
804
  return final;
790
805
  }, {});
791
806
  };
792
- const isBoolean$1 = (v) => typeof v === 'boolean';
793
807
  const isDefined = (v) => v !== null && v !== undefined;
808
+ const isBoolean$1 = (v) => typeof v === 'boolean';
794
809
  const isFunction = (v) => typeof v === 'function';
795
810
  const isNumber$1 = (v) => typeof v === 'number';
796
811
  const isObject$4 = (val) => val != null && typeof val === 'object' && Array.isArray(val) === false;
@@ -1631,7 +1646,7 @@ const isDtsFile$1 = (filePath) => {
1631
1646
  /**
1632
1647
  * Generate the preamble to be placed atop the main file of the build
1633
1648
  * @param config the Stencil configuration file
1634
- * @return the generated preamble
1649
+ * @returns the generated preamble
1635
1650
  */
1636
1651
  const generatePreamble = (config) => {
1637
1652
  const { preamble } = config;
@@ -1697,38 +1712,30 @@ const readPackageJson = async (config, compilerCtx, buildCtx) => {
1697
1712
  }
1698
1713
  }
1699
1714
  };
1715
+ /**
1716
+ * Parse a string read from a `package.json` file
1717
+ * @param pkgJsonStr the string read from a `package.json` file
1718
+ * @param pkgJsonFilePath the path to the already read `package.json` file
1719
+ * @returns the results of parsing the provided contents of the `package.json` file
1720
+ */
1700
1721
  const parsePackageJson = (pkgJsonStr, pkgJsonFilePath) => {
1701
- if (isString$1(pkgJsonFilePath)) {
1702
- return parseJson(pkgJsonStr, pkgJsonFilePath);
1703
- }
1704
- return null;
1705
- };
1706
- const parseJson = (jsonStr, filePath) => {
1707
- const rtn = {
1722
+ const parseResult = {
1708
1723
  diagnostic: null,
1709
1724
  data: null,
1710
- filePath,
1725
+ filePath: pkgJsonFilePath,
1711
1726
  };
1712
- if (isString$1(jsonStr)) {
1713
- try {
1714
- rtn.data = JSON.parse(jsonStr);
1715
- }
1716
- catch (e) {
1717
- rtn.diagnostic = buildError();
1718
- rtn.diagnostic.absFilePath = filePath;
1719
- rtn.diagnostic.header = `Error Parsing JSON`;
1720
- if (e instanceof Error) {
1721
- rtn.diagnostic.messageText = e.message;
1722
- }
1723
- }
1727
+ try {
1728
+ parseResult.data = JSON.parse(pkgJsonStr);
1724
1729
  }
1725
- else {
1726
- rtn.diagnostic = buildError();
1727
- rtn.diagnostic.absFilePath = filePath;
1728
- rtn.diagnostic.header = `Error Parsing JSON`;
1729
- rtn.diagnostic.messageText = `Invalid JSON input to parse`;
1730
+ catch (e) {
1731
+ parseResult.diagnostic = buildError();
1732
+ parseResult.diagnostic.absFilePath = isString$1(pkgJsonFilePath) ? pkgJsonFilePath : undefined;
1733
+ parseResult.diagnostic.header = `Error Parsing JSON`;
1734
+ if (e instanceof Error) {
1735
+ parseResult.diagnostic.messageText = e.message;
1736
+ }
1730
1737
  }
1731
- return rtn;
1738
+ return parseResult;
1732
1739
  };
1733
1740
  const SKIP_DEPS = ['@stencil/core'];
1734
1741
 
@@ -2034,10 +2041,14 @@ const buildEvents = () => {
2034
2041
  };
2035
2042
  };
2036
2043
 
2044
+ /**
2045
+ * Creates an instance of a logger
2046
+ * @returns the new logger instance
2047
+ */
2037
2048
  const createLogger = () => {
2038
2049
  let useColors = IS_BROWSER_ENV;
2039
2050
  let level = 'info';
2040
- const logger = {
2051
+ return {
2041
2052
  enableColors: (uc) => (useColors = uc),
2042
2053
  getLevel: () => level,
2043
2054
  setLevel: (l) => (level = l),
@@ -2064,7 +2075,6 @@ const createLogger = () => {
2064
2075
  diagnostics.forEach((diagnostic) => logDiagnostic(diagnostic, useColors));
2065
2076
  },
2066
2077
  };
2067
- return logger;
2068
2078
  };
2069
2079
  const logDiagnostic = (diagnostic, useColors) => {
2070
2080
  let color = BLUE;
@@ -2354,8 +2364,16 @@ const getPackageDirPath = (p, moduleId) => {
2354
2364
  return null;
2355
2365
  };
2356
2366
 
2367
+ /**
2368
+ * A fetch wrapper which dispatches to `sys.fetch` if present, and otherwise
2369
+ * uses `global.fetch`.
2370
+ *
2371
+ * @param sys a compiler system object
2372
+ * @param input a `RequestInfo` object
2373
+ * @param init an optional `RequestInit` object
2374
+ * @returns a Promise wrapping a response
2375
+ */
2357
2376
  const httpFetch = (sys, input, init) => {
2358
- console.trace(input);
2359
2377
  if (sys && isFunction(sys.fetch)) {
2360
2378
  return sys.fetch(input, init);
2361
2379
  }
@@ -2363,10 +2381,16 @@ const httpFetch = (sys, input, init) => {
2363
2381
  };
2364
2382
  const packageVersions = new Map();
2365
2383
  const known404Urls = new Set();
2366
- const getStencilRootUrl = (compilerExe) => new URL('../', compilerExe).href;
2367
- const getStencilModuleUrl = (compilerExe, p) => {
2368
- p = normalizePath$1(p);
2369
- let parts = p.split('/');
2384
+ /**
2385
+ * Get the URL for a Stencil module given the path to the compiler
2386
+ *
2387
+ * @param compilerExe the path to the compiler executable
2388
+ * @param path the path to the module or file in question
2389
+ * @returns a URL for the file of interest
2390
+ */
2391
+ const getStencilModuleUrl = (compilerExe, path) => {
2392
+ path = normalizePath$1(path);
2393
+ let parts = path.split('/');
2370
2394
  const nmIndex = parts.lastIndexOf('node_modules');
2371
2395
  if (nmIndex > -1 && nmIndex < parts.length - 1) {
2372
2396
  parts = parts.slice(nmIndex + 1);
@@ -2376,9 +2400,10 @@ const getStencilModuleUrl = (compilerExe, p) => {
2376
2400
  else {
2377
2401
  parts = parts.slice(1);
2378
2402
  }
2379
- p = parts.join('/');
2403
+ path = parts.join('/');
2380
2404
  }
2381
- return new URL('./' + p, getStencilRootUrl(compilerExe)).href;
2405
+ const stencilRootUrl = new URL('../', compilerExe).href;
2406
+ return new URL('./' + path, stencilRootUrl).href;
2382
2407
  };
2383
2408
  const getCommonDirUrl = (sys, pkgVersions, dirPath, fileName) => getNodeModuleFetchUrl(sys, pkgVersions, dirPath) + '/' + fileName;
2384
2409
  const getNodeModuleFetchUrl = (sys, pkgVersions, filePath) => {
@@ -4027,7 +4052,7 @@ const createCustomResolverAsync = (sys, inMemoryFs, exts) => {
4027
4052
  };
4028
4053
  };
4029
4054
 
4030
- const buildId = '20220603032000';
4055
+ const buildId = '20220711170106';
4031
4056
  const minfyJsId = 'terser5.6.1_7';
4032
4057
  const optimizeCssId = 'autoprefixer10.2.5_postcss8.2.13_7';
4033
4058
  const parse5Version = '6.0.1';
@@ -4035,8 +4060,8 @@ const rollupVersion = '2.42.3';
4035
4060
  const sizzleVersion = '2.42.3';
4036
4061
  const terserVersion = '5.6.1';
4037
4062
  const typescriptVersion = '4.5.4';
4038
- const vermoji = '🌸';
4039
- const version$3 = '2.16.1-0';
4063
+ const vermoji = '😊';
4064
+ const version$3 = '2.17.1';
4040
4065
  const versions = {
4041
4066
  stencil: version$3,
4042
4067
  parse5: parse5Version,
@@ -4585,6 +4610,17 @@ const createSystem = (c) => {
4585
4610
  };
4586
4611
 
4587
4612
  let cssProcessor;
4613
+ /**
4614
+ * Autoprefix a CSS string, adding vendor prefixes to make sure that what
4615
+ * is written in the CSS will render correctly in our range of supported browsers.
4616
+ * This function uses PostCSS in compbination with the Autoprefix plugin to
4617
+ * automatically add vendor prefixes based on a list of browsers which we want
4618
+ * to support.
4619
+ *
4620
+ * @param cssText the text to be prefixed
4621
+ * @param opts an optional param with options for Autoprefixer
4622
+ * @returns a Promise wrapping some prefixed CSS as well as diagnostics
4623
+ */
4588
4624
  const autoprefixCss = async (cssText, opts) => {
4589
4625
  const output = {
4590
4626
  output: cssText,
@@ -4594,7 +4630,7 @@ const autoprefixCss = async (cssText, opts) => {
4594
4630
  return output;
4595
4631
  }
4596
4632
  try {
4597
- const autoprefixerOpts = opts != null && typeof opts === 'object' ? opts : DEFAULT_AUTOPREFIX_LEGACY;
4633
+ const autoprefixerOpts = opts != null && typeof opts === 'object' ? opts : DEFAULT_AUTOPREFIX_OPTIONS;
4598
4634
  const processor = getProcessor(autoprefixerOpts);
4599
4635
  const result = await processor.process(cssText, { map: null });
4600
4636
  result.warnings().forEach((warning) => {
@@ -4650,6 +4686,12 @@ const autoprefixCss = async (cssText, opts) => {
4650
4686
  }
4651
4687
  return output;
4652
4688
  };
4689
+ /**
4690
+ * Get the processor for PostCSS and the Autoprefixer plugin
4691
+ *
4692
+ * @param autoprefixerOpts Options for Autoprefixer
4693
+ * @returns postCSS with the Autoprefixer plugin applied
4694
+ */
4653
4695
  const getProcessor = (autoprefixerOpts) => {
4654
4696
  const { postcss, autoprefixer } = requireFunc('../sys/node/autoprefixer.js');
4655
4697
  if (!cssProcessor) {
@@ -4657,7 +4699,19 @@ const getProcessor = (autoprefixerOpts) => {
4657
4699
  }
4658
4700
  return cssProcessor;
4659
4701
  };
4660
- const DEFAULT_AUTOPREFIX_LEGACY = {
4702
+ /**
4703
+ * Default options for the Autoprefixer PostCSS plugin. See the documentation:
4704
+ * https://github.com/postcss/autoprefixer#options for a complete list.
4705
+ *
4706
+ * This default option set will:
4707
+ *
4708
+ * - override the default browser list (`overrideBrowserslist`)
4709
+ * - turn off the visual cascade (`cascade`)
4710
+ * - disable auto-removing outdated prefixes (`remove`)
4711
+ * - set `flexbox` to `"no-2009"`, which limits prefixing for flexbox to the
4712
+ * final and IE 10 versions of the specification
4713
+ */
4714
+ const DEFAULT_AUTOPREFIX_OPTIONS = {
4661
4715
  overrideBrowserslist: ['last 2 versions', 'iOS >= 9', 'Android >= 4.4', 'Explorer >= 11', 'ExplorerMobile >= 11'],
4662
4716
  cascade: false,
4663
4717
  remove: false,
@@ -5453,6 +5507,13 @@ const resolveStylesheetUrl = async (nodes, resolveUrl, resolved) => {
5453
5507
  }
5454
5508
  };
5455
5509
 
5510
+ /**
5511
+ * Optimize a CSS file, optionally running an autoprefixer and a minifier
5512
+ * depending on the options set on the input options argument.
5513
+ *
5514
+ * @param inputOpts input CSS options
5515
+ * @returns a promise wrapping the optimized output
5516
+ */
5456
5517
  const optimizeCss$1 = async (inputOpts) => {
5457
5518
  let result = {
5458
5519
  output: inputOpts.input,
@@ -10986,6 +11047,16 @@ MagicString$2.prototype.trimStart = function trimStart (charType) {
10986
11047
  return this;
10987
11048
  };
10988
11049
 
11050
+ /**
11051
+ * Parse CSS docstrings that Stencil supports, as documented here:
11052
+ * https://stenciljs.com/docs/docs-json#css-variables
11053
+ *
11054
+ * Docstrings found in the supplied style text will be added to the
11055
+ * `styleDocs` param
11056
+ *
11057
+ * @param styleDocs the array to hold formatted CSS docstrings
11058
+ * @param styleText the CSS text we're working with
11059
+ */
10989
11060
  function parseStyleDocs(styleDocs, styleText) {
10990
11061
  if (typeof styleText !== 'string') {
10991
11062
  return;
@@ -11002,10 +11073,18 @@ function parseStyleDocs(styleDocs, styleText) {
11002
11073
  styleText = styleText.substring(endIndex + CSS_DOC_END.length);
11003
11074
  }
11004
11075
  }
11076
+ /**
11077
+ * Parse a CSS comment string and insert it into the provided array of
11078
+ * style docstrings.
11079
+ *
11080
+ * @param styleDocs an array which will be modified with the docstring
11081
+ * @param comment the comment string
11082
+ */
11005
11083
  function parseCssComment(styleDocs, comment) {
11006
11084
  /**
11007
11085
  * @prop --max-width: Max width of the alert
11008
11086
  */
11087
+ // (the above is an example of what these comments might look like)
11009
11088
  const lines = comment.split(/\r?\n/).map((line) => {
11010
11089
  line = line.trim();
11011
11090
  while (line.startsWith('*')) {
@@ -11033,11 +11112,19 @@ function parseCssComment(styleDocs, comment) {
11033
11112
  styleDocs.push(cssDoc);
11034
11113
  }
11035
11114
  });
11036
- return styleDocs;
11037
11115
  }
11038
- const CSS_DOC_START = `/**`;
11039
- const CSS_DOC_END = `*/`;
11040
- const CSS_PROP_ANNOTATION = `@prop`;
11116
+ /**
11117
+ * Opening syntax for a CSS docstring
11118
+ */
11119
+ const CSS_DOC_START = '/**';
11120
+ /**
11121
+ * Closing syntax for a CSS docstring
11122
+ */
11123
+ const CSS_DOC_END = '*/';
11124
+ /**
11125
+ * The `@prop` annotation we support within CSS docstrings
11126
+ */
11127
+ const CSS_PROP_ANNOTATION = '@prop';
11041
11128
 
11042
11129
  /**
11043
11130
  * @license
@@ -11490,6 +11577,12 @@ const parseImportPath = (importPath) => {
11490
11577
  return parsedPath;
11491
11578
  };
11492
11579
 
11580
+ /**
11581
+ * Strip out comments from some CSS
11582
+ *
11583
+ * @param input the string we'd like to de-comment
11584
+ * @returns de-commented CSS!
11585
+ */
11493
11586
  const stripCssComments = (input) => {
11494
11587
  let isInsideString = null;
11495
11588
  let currentCharacter = '';
@@ -11526,6 +11619,53 @@ const stripCssComments = (input) => {
11526
11619
  return returnValue;
11527
11620
  };
11528
11621
 
11622
+ /**
11623
+ * A regular expression for matching CSS import statements
11624
+ *
11625
+ * According to https://developer.mozilla.org/en-US/docs/Web/CSS/@import
11626
+ * the formal grammar for CSS import statements is:
11627
+ *
11628
+ * ```
11629
+ * @import [ <url> | <string> ]
11630
+ * [ supports( [ <supports-condition> | <declaration> ] ) ]?
11631
+ * <media-query-list>? ;
11632
+ * ```
11633
+ *
11634
+ * Thus the string literal `"@import"` will be followed by a `<url>` or a
11635
+ * `<string>`, where a `<url>` may be a relative or absolute URL _or_ a `url()`
11636
+ * function.
11637
+ *
11638
+ * Thus the regular expression needs to match:
11639
+ *
11640
+ * - the string `"@import
11641
+ * - any amount of whitespace
11642
+ * - a URL, comprised of:
11643
+ * - an optional `url(` function opener
11644
+ * - a non-greedy match on any characters (to match the argument to the URL
11645
+ * function)
11646
+ * - an optional `)` closing paren on the `url()` function
11647
+ * - trailing characters after the URL, given by anything which doesn't match
11648
+ * the line-terminator `;`
11649
+ * - this can match media queries, support conditions, and so on
11650
+ * - a line-terminating semicolon
11651
+ *
11652
+ * The regex has 4 capture groups:
11653
+ *
11654
+ * 1. `@import`
11655
+ * 2. `url(`
11656
+ * 3. characters after `url(`
11657
+ * 4. all characters other than `;`, greedily matching
11658
+ *
11659
+ * We typically only care about group 4 here.
11660
+ */
11661
+ const CSS_IMPORT_RE = /(@import)\s+(url\()?\s?(.*?)\s?\)?([^;]*);?/gi;
11662
+ /**
11663
+ * Our main entry point to this module. This performs an async transformation
11664
+ * of CSS input to ESM.
11665
+ *
11666
+ * @param input CSS input to be transformed to ESM
11667
+ * @returns a promise wrapping transformed ESM output
11668
+ */
11529
11669
  const transformCssToEsm = async (input) => {
11530
11670
  const results = transformCssToEsmModule(input);
11531
11671
  const optimizeResults = await optimizeCss$1({
@@ -11542,10 +11682,22 @@ const transformCssToEsm = async (input) => {
11542
11682
  results.styleText = optimizeResults.output;
11543
11683
  return generateTransformCssToEsm(input, results);
11544
11684
  };
11685
+ /**
11686
+ * A sync function for transforming input CSS to ESM
11687
+ *
11688
+ * @param input the input CSS we're going to transform
11689
+ * @returns transformed ESM output
11690
+ */
11545
11691
  const transformCssToEsmSync = (input) => {
11546
11692
  const results = transformCssToEsmModule(input);
11547
11693
  return generateTransformCssToEsm(input, results);
11548
11694
  };
11695
+ /**
11696
+ * Performs the actual transformation from CSS to ESM
11697
+ *
11698
+ * @param input input CSS to be transformed
11699
+ * @returns ESM output
11700
+ */
11549
11701
  const transformCssToEsmModule = (input) => {
11550
11702
  const results = {
11551
11703
  styleText: input.input,
@@ -11590,6 +11742,14 @@ const transformCssToEsmModule = (input) => {
11590
11742
  }
11591
11743
  return results;
11592
11744
  };
11745
+ /**
11746
+ * Updated the `output` property on `results` with appropriate import statements for
11747
+ * the CSS import tree and the module type.
11748
+ *
11749
+ * @param input the CSS to ESM transform input
11750
+ * @param results the corresponding output
11751
+ * @returns the modified ESM output
11752
+ */
11593
11753
  const generateTransformCssToEsm = (input, results) => {
11594
11754
  const s = new MagicString$2('');
11595
11755
  if (input.module === 'cjs') {
@@ -11619,6 +11779,15 @@ const generateTransformCssToEsm = (input, results) => {
11619
11779
  results.output = s.toString();
11620
11780
  return results;
11621
11781
  };
11782
+ /**
11783
+ * Get all of the CSS imports in a file
11784
+ *
11785
+ * @param varNames a set into which new names will be added
11786
+ * @param cssText the CSS text in question
11787
+ * @param filePath the file path to the file in question
11788
+ * @param modeName the current mode name
11789
+ * @returns an array of import objects
11790
+ */
11622
11791
  const getCssToEsmImports = (varNames, cssText, filePath, modeName) => {
11623
11792
  const cssImports = [];
11624
11793
  if (!cssText.includes('@import')) {
@@ -11660,10 +11829,22 @@ const getCssToEsmImports = (varNames, cssText, filePath, modeName) => {
11660
11829
  }
11661
11830
  return cssImports;
11662
11831
  };
11663
- const CSS_IMPORT_RE = /(@import)\s+(url\()?\s?(.*?)\s?\)?([^;]*);?/gi;
11832
+ /**
11833
+ * Check if a module URL is a css node module
11834
+ *
11835
+ * @param url to check
11836
+ * @returns whether or not it's a Css node module
11837
+ */
11664
11838
  const isCssNodeModule$1 = (url) => {
11665
11839
  return url.startsWith('~');
11666
11840
  };
11841
+ /**
11842
+ * Check if a given import is a local import or not (i.e. check that it
11843
+ * is not importing from some other domain)
11844
+ *
11845
+ * @param srcImport the import to check
11846
+ * @returns whether it's local or not
11847
+ */
11667
11848
  const isLocalCssImport$1 = (srcImport) => {
11668
11849
  srcImport = srcImport.toLowerCase();
11669
11850
  if (srcImport.includes('url(')) {
@@ -11676,6 +11857,13 @@ const isLocalCssImport$1 = (srcImport) => {
11676
11857
  }
11677
11858
  return true;
11678
11859
  };
11860
+ /**
11861
+ * Given a file path and a mode name, create an appropriate variable name
11862
+ *
11863
+ * @param filePath the path we want to use
11864
+ * @param modeName the name for the current style mode (i.e. `md` or `ios` on Ionic)
11865
+ * @returns an appropriate Css var name
11866
+ */
11679
11867
  const createCssVarName = (filePath, modeName) => {
11680
11868
  let varName = path$5.basename(filePath);
11681
11869
  if (modeName && modeName !== DEFAULT_STYLE_MODE && !varName.includes(modeName)) {
@@ -15663,6 +15851,9 @@ class MockElement extends MockNode {
15663
15851
  this.shadowRoot = shadowRoot;
15664
15852
  return shadowRoot;
15665
15853
  }
15854
+ blur() {
15855
+ /**/
15856
+ }
15666
15857
  get shadowRoot() {
15667
15858
  return this.__shadowRoot || null;
15668
15859
  }
@@ -15731,6 +15922,7 @@ class MockElement extends MockNode {
15731
15922
  get firstElementChild() {
15732
15923
  return this.children[0] || null;
15733
15924
  }
15925
+ focus(_options) { }
15734
15926
  getAttribute(attrName) {
15735
15927
  if (attrName === 'style') {
15736
15928
  if (this.__style != null && this.__style.length > 0) {
@@ -16634,7 +16826,28 @@ function createElementNS(ownerDocument, namespaceURI, tagName) {
16634
16826
  return createElement(ownerDocument, tagName);
16635
16827
  }
16636
16828
  else if (namespaceURI === 'http://www.w3.org/2000/svg') {
16637
- return new MockSVGElement(ownerDocument, tagName);
16829
+ switch (tagName.toLowerCase()) {
16830
+ case 'text':
16831
+ case 'tspan':
16832
+ case 'tref':
16833
+ case 'altglyph':
16834
+ case 'textpath':
16835
+ return new MockSVGTextContentElement(ownerDocument, tagName);
16836
+ case 'circle':
16837
+ case 'ellipse':
16838
+ case 'image':
16839
+ case 'line':
16840
+ case 'path':
16841
+ case 'polygon':
16842
+ case 'polyline':
16843
+ case 'rect':
16844
+ case 'use':
16845
+ return new MockSVGGraphicsElement(ownerDocument, tagName);
16846
+ case 'svg':
16847
+ return new MockSVGSVGElement(ownerDocument, tagName);
16848
+ default:
16849
+ return new MockSVGElement(ownerDocument, tagName);
16850
+ }
16638
16851
  }
16639
16852
  else {
16640
16853
  return new MockElement(ownerDocument, tagName);
@@ -16781,6 +16994,98 @@ class MockScriptElement extends MockHTMLElement {
16781
16994
  patchPropAttributes(MockScriptElement.prototype, {
16782
16995
  type: String,
16783
16996
  });
16997
+ class MockDOMMatrix {
16998
+ constructor() {
16999
+ this.a = 1;
17000
+ this.b = 0;
17001
+ this.c = 0;
17002
+ this.d = 1;
17003
+ this.e = 0;
17004
+ this.f = 0;
17005
+ this.m11 = 1;
17006
+ this.m12 = 0;
17007
+ this.m13 = 0;
17008
+ this.m14 = 0;
17009
+ this.m21 = 0;
17010
+ this.m22 = 1;
17011
+ this.m23 = 0;
17012
+ this.m24 = 0;
17013
+ this.m31 = 0;
17014
+ this.m32 = 0;
17015
+ this.m33 = 1;
17016
+ this.m34 = 0;
17017
+ this.m41 = 0;
17018
+ this.m42 = 0;
17019
+ this.m43 = 0;
17020
+ this.m44 = 1;
17021
+ this.is2D = true;
17022
+ this.isIdentity = true;
17023
+ }
17024
+ static fromMatrix() {
17025
+ return new MockDOMMatrix();
17026
+ }
17027
+ inverse() {
17028
+ return new MockDOMMatrix();
17029
+ }
17030
+ flipX() {
17031
+ return new MockDOMMatrix();
17032
+ }
17033
+ flipY() {
17034
+ return new MockDOMMatrix();
17035
+ }
17036
+ multiply() {
17037
+ return new MockDOMMatrix();
17038
+ }
17039
+ rotate() {
17040
+ return new MockDOMMatrix();
17041
+ }
17042
+ rotateAxisAngle() {
17043
+ return new MockDOMMatrix();
17044
+ }
17045
+ rotateFromVector() {
17046
+ return new MockDOMMatrix();
17047
+ }
17048
+ scale() {
17049
+ return new MockDOMMatrix();
17050
+ }
17051
+ scaleNonUniform() {
17052
+ return new MockDOMMatrix();
17053
+ }
17054
+ skewX() {
17055
+ return new MockDOMMatrix();
17056
+ }
17057
+ skewY() {
17058
+ return new MockDOMMatrix();
17059
+ }
17060
+ toJSON() { }
17061
+ toString() { }
17062
+ transformPoint() {
17063
+ return new MockDOMPoint();
17064
+ }
17065
+ translate() {
17066
+ return new MockDOMMatrix();
17067
+ }
17068
+ }
17069
+ class MockDOMPoint {
17070
+ constructor() {
17071
+ this.w = 1;
17072
+ this.x = 0;
17073
+ this.y = 0;
17074
+ this.z = 0;
17075
+ }
17076
+ toJSON() { }
17077
+ matrixTransform() {
17078
+ return new MockDOMMatrix();
17079
+ }
17080
+ }
17081
+ class MockSVGRect {
17082
+ constructor() {
17083
+ this.height = 10;
17084
+ this.width = 10;
17085
+ this.x = 0;
17086
+ this.y = 0;
17087
+ }
17088
+ }
16784
17089
  class MockStyleElement extends MockHTMLElement {
16785
17090
  constructor(ownerDocument) {
16786
17091
  super(ownerDocument, 'style');
@@ -16813,9 +17118,6 @@ class MockSVGElement extends MockElement {
16813
17118
  get viewportElement() {
16814
17119
  return null;
16815
17120
  }
16816
- focus() {
16817
- /**/
16818
- }
16819
17121
  onunload() {
16820
17122
  /**/
16821
17123
  }
@@ -16833,6 +17135,27 @@ class MockSVGElement extends MockElement {
16833
17135
  return 0;
16834
17136
  }
16835
17137
  }
17138
+ class MockSVGGraphicsElement extends MockSVGElement {
17139
+ getBBox(_options) {
17140
+ return new MockSVGRect();
17141
+ }
17142
+ getCTM() {
17143
+ return new MockDOMMatrix();
17144
+ }
17145
+ getScreenCTM() {
17146
+ return new MockDOMMatrix();
17147
+ }
17148
+ }
17149
+ class MockSVGSVGElement extends MockSVGGraphicsElement {
17150
+ createSVGPoint() {
17151
+ return new MockDOMPoint();
17152
+ }
17153
+ }
17154
+ class MockSVGTextContentElement extends MockSVGGraphicsElement {
17155
+ getComputedTextLength() {
17156
+ return 0;
17157
+ }
17158
+ }
16836
17159
  class MockBaseElement extends MockHTMLElement {
16837
17160
  constructor(ownerDocument) {
16838
17161
  super(ownerDocument, 'base');
@@ -18580,48 +18903,88 @@ const emptyOutputTargets = async (config, compilerCtx, buildCtx) => {
18580
18903
  timeSpan.finish('cleaning dirs finished');
18581
18904
  };
18582
18905
 
18906
+ /**
18907
+ * Parse CSS imports into an object which contains a manifest of imports and a
18908
+ * stylesheet with all imports resolved and concatenated.
18909
+ *
18910
+ * @param config the current config
18911
+ * @param compilerCtx the compiler context (we need filesystem access)
18912
+ * @param buildCtx the build context, we'll need access to diagnostics
18913
+ * @param srcFilePath the source filepath
18914
+ * @param resolvedFilePath the resolved filepath
18915
+ * @param styleText style text we start with
18916
+ * @param styleDocs optional array of style document objects
18917
+ * @returns an object with concatenated styleText and imports
18918
+ */
18583
18919
  const parseCssImports = async (config, compilerCtx, buildCtx, srcFilePath, resolvedFilePath, styleText, styleDocs) => {
18584
18920
  const isCssEntry = resolvedFilePath.toLowerCase().endsWith('.css');
18585
18921
  const allCssImports = [];
18586
- const concatStyleText = await updateCssImports(config, compilerCtx, buildCtx, isCssEntry, srcFilePath, resolvedFilePath, styleText, allCssImports, new Set(), styleDocs);
18922
+ // a Set of previously-resolved file paths that we add to as we traverse the
18923
+ // import tree (to avoid a possible circular dependency and infinite loop)
18924
+ const resolvedFilePaths = new Set();
18925
+ const concatStyleText = await resolveAndFlattenImports(srcFilePath, resolvedFilePath, styleText);
18587
18926
  return {
18588
18927
  imports: allCssImports,
18589
18928
  styleText: concatStyleText,
18590
18929
  };
18591
- };
18592
- const updateCssImports = async (config, compilerCtx, buildCtx, isCssEntry, srcFilePath, resolvedFilePath, styleText, allCssImports, noLoop, styleDocs) => {
18593
- if (noLoop.has(resolvedFilePath)) {
18594
- return styleText;
18595
- }
18596
- noLoop.add(resolvedFilePath);
18597
- if (styleDocs != null) {
18598
- parseStyleDocs(styleDocs, styleText);
18599
- }
18600
- const cssImports = await getCssImports(config, compilerCtx, buildCtx, resolvedFilePath, styleText);
18601
- if (cssImports.length === 0) {
18602
- return styleText;
18603
- }
18604
- for (const cssImport of cssImports) {
18605
- if (!allCssImports.includes(cssImport.filePath)) {
18606
- allCssImports.push(cssImport.filePath);
18930
+ /**
18931
+ * Resolve and flatten all imports for a given CSS file, recursively crawling
18932
+ * the tree of imports to resolve them all and produce a concatenated
18933
+ * stylesheet. We declare this function here, within `parseCssImports`, in order
18934
+ * to get access to `compilerCtx`, `buildCtx`, and more without having to pass
18935
+ * a whole bunch of arguments.
18936
+ *
18937
+ * @param srcFilePath the source filepath
18938
+ * @param resolvedFilePath the resolved filepath
18939
+ * @param styleText style text we start with*
18940
+ * @returns concatenated styles assembled from the various imported stylesheets
18941
+ */
18942
+ async function resolveAndFlattenImports(srcFilePath, resolvedFilePath, styleText) {
18943
+ // if we've seen this path before we early return
18944
+ if (resolvedFilePaths.has(resolvedFilePath)) {
18945
+ return styleText;
18607
18946
  }
18608
- }
18609
- await Promise.all(cssImports.map(async (cssImportData) => {
18610
- await concatCssImport(config, compilerCtx, buildCtx, isCssEntry, srcFilePath, cssImportData, allCssImports, noLoop, styleDocs);
18611
- }));
18612
- return replaceImportDeclarations(styleText, cssImports, isCssEntry);
18613
- };
18614
- const concatCssImport = async (config, compilerCtx, buildCtx, isCssEntry, srcFilePath, cssImportData, allCssImports, noLoop, styleDocs) => {
18615
- cssImportData.styleText = await loadStyleText(compilerCtx, cssImportData);
18616
- if (typeof cssImportData.styleText === 'string') {
18617
- cssImportData.styleText = await updateCssImports(config, compilerCtx, buildCtx, isCssEntry, cssImportData.filePath, cssImportData.filePath, cssImportData.styleText, allCssImports, noLoop, styleDocs);
18618
- }
18619
- else {
18620
- const err = buildError(buildCtx.diagnostics);
18621
- err.messageText = `Unable to read css import: ${cssImportData.srcImport}`;
18622
- err.absFilePath = srcFilePath;
18947
+ resolvedFilePaths.add(resolvedFilePath);
18948
+ if (styleDocs != null) {
18949
+ parseStyleDocs(styleDocs, styleText);
18950
+ }
18951
+ const cssImports = await getCssImports(config, compilerCtx, buildCtx, resolvedFilePath, styleText);
18952
+ if (cssImports.length === 0) {
18953
+ return styleText;
18954
+ }
18955
+ // add any newly-found imports to the 'global' list
18956
+ for (const cssImport of cssImports) {
18957
+ if (!allCssImports.includes(cssImport.filePath)) {
18958
+ allCssImports.push(cssImport.filePath);
18959
+ }
18960
+ }
18961
+ // Recur down the tree of CSS imports, resolving all the imports in
18962
+ // the children of the current file (and, by extension, in their children
18963
+ // and so on)
18964
+ await Promise.all(cssImports.map(async (cssImportData) => {
18965
+ cssImportData.styleText = await loadStyleText(compilerCtx, cssImportData);
18966
+ if (typeof cssImportData.styleText === 'string') {
18967
+ cssImportData.styleText = await resolveAndFlattenImports(cssImportData.filePath, cssImportData.filePath, cssImportData.styleText);
18968
+ }
18969
+ else {
18970
+ // we had some error loading the file from disk, so write a diagnostic
18971
+ const err = buildError(buildCtx.diagnostics);
18972
+ err.messageText = `Unable to read css import: ${cssImportData.srcImport}`;
18973
+ err.absFilePath = srcFilePath;
18974
+ }
18975
+ }));
18976
+ // replace import statements with the actual CSS code in children modules
18977
+ return replaceImportDeclarations(styleText, cssImports, isCssEntry);
18623
18978
  }
18624
18979
  };
18980
+ /**
18981
+ * Load the style text for a CSS file from disk, based on the filepaths set in
18982
+ * our import data.
18983
+ *
18984
+ * @param compilerCtx the compiler context
18985
+ * @param cssImportData the import data for the file we want to read
18986
+ * @returns the contents of the file, if it can be read without error
18987
+ */
18625
18988
  const loadStyleText = async (compilerCtx, cssImportData) => {
18626
18989
  let styleText = null;
18627
18990
  try {
@@ -18637,7 +19000,18 @@ const loadStyleText = async (compilerCtx, cssImportData) => {
18637
19000
  }
18638
19001
  return styleText;
18639
19002
  };
19003
+ /**
19004
+ * Get a manifest of all the CSS imports in a given CSS file
19005
+ *
19006
+ * @param config the current config
19007
+ * @param compilerCtx the compiler context (we need the filesystem)
19008
+ * @param buildCtx the build context, in case we need to set a diagnostic
19009
+ * @param filePath the filepath we're working with
19010
+ * @param styleText the CSS for which we want to retrieve import data
19011
+ * @returns a Promise wrapping a list of CSS import data objects
19012
+ */
18640
19013
  const getCssImports = async (config, compilerCtx, buildCtx, filePath, styleText) => {
19014
+ var _a;
18641
19015
  const imports = [];
18642
19016
  if (!styleText.includes('@import')) {
18643
19017
  // no @import at all, so don't bother
@@ -18645,13 +19019,14 @@ const getCssImports = async (config, compilerCtx, buildCtx, filePath, styleText)
18645
19019
  }
18646
19020
  styleText = stripCssComments(styleText);
18647
19021
  const dir = dirname(filePath);
18648
- const importeeExt = filePath.split('.').pop().toLowerCase();
19022
+ const importeeExt = ((_a = filePath.split('.').pop()) !== null && _a !== void 0 ? _a : '').toLowerCase();
18649
19023
  let r;
18650
19024
  const IMPORT_RE = /(@import)\s+(url\()?\s?(.*?)\s?\)?([^;]*);?/gi;
18651
19025
  while ((r = IMPORT_RE.exec(styleText))) {
18652
19026
  const cssImportData = {
18653
19027
  srcImport: r[0],
18654
19028
  url: r[4].replace(/[\"\'\)]/g, ''),
19029
+ filePath: '',
18655
19030
  };
18656
19031
  if (!isLocalCssImport(cssImportData.srcImport)) {
18657
19032
  // do nothing for @import url(http://external.css)
@@ -18678,7 +19053,10 @@ const getCssImports = async (config, compilerCtx, buildCtx, filePath, styleText)
18678
19053
  cssImportData.altFilePath = normalizePath$1(join(dirPath, fileName));
18679
19054
  }
18680
19055
  }
18681
- if (typeof cssImportData.filePath === 'string') {
19056
+ // we set `filePath` to `""` when the object is created above, so if it
19057
+ // hasn't been changed in the intervening conditionals then we didn't resolve
19058
+ // a filepath for it.
19059
+ if (cssImportData.filePath !== '') {
18682
19060
  imports.push(cssImportData);
18683
19061
  }
18684
19062
  }
@@ -18720,6 +19098,16 @@ const isLocalCssImport = (srcImport) => {
18720
19098
  }
18721
19099
  return true;
18722
19100
  };
19101
+ /**
19102
+ * Replace import declarations (like '@import "foobar";') with the actual CSS
19103
+ * written in the imported module, allowing us to produce a single file from a
19104
+ * tree of stylesheets.
19105
+ *
19106
+ * @param styleText the text within which we want to replace @import statements
19107
+ * @param cssImports information about imported modules
19108
+ * @param isCssEntry whether we're dealing with a CSS file
19109
+ * @returns an updated string with the requisite substitutions
19110
+ */
18723
19111
  const replaceImportDeclarations = (styleText, cssImports, isCssEntry) => {
18724
19112
  for (const cssImport of cssImports) {
18725
19113
  if (isCssEntry) {
@@ -41053,6 +41441,7 @@ const createComponentExport = (cmp) => {
41053
41441
  * using the `dist-custom-elements` output target may have a single 'entry point' for each file containing a component.
41054
41442
  * Each of those files will be independently resolved and loaded by this plugin for further processing by Rollup later
41055
41443
  * in the bundling process.
41444
+ *
41056
41445
  * @param entries the Stencil project files to process. It should be noted that the keys in this object may not
41057
41446
  * necessarily be an absolute or relative path to a file, but may be a Rollup Virtual Module (which begin with \0).
41058
41447
  * @returns the rollup plugin that loads and process a Stencil project's entry points
@@ -41221,9 +41610,9 @@ const fetchUrlSync = (url) => {
41221
41610
  return undefined;
41222
41611
  };
41223
41612
 
41224
- const patchTsSystemFileSystem = (config, stencilSys, inMemoryFs, tsSys) => {
41613
+ const patchTsSystemFileSystem = (config, compilerSys, inMemoryFs, tsSys) => {
41225
41614
  const realpath = (path) => {
41226
- const rp = stencilSys.realpathSync(path);
41615
+ const rp = compilerSys.realpathSync(path);
41227
41616
  if (isString$1(rp)) {
41228
41617
  return rp;
41229
41618
  }
@@ -41231,7 +41620,7 @@ const patchTsSystemFileSystem = (config, stencilSys, inMemoryFs, tsSys) => {
41231
41620
  };
41232
41621
  const getAccessibleFileSystemEntries = (path) => {
41233
41622
  try {
41234
- const entries = stencilSys.readDirSync(path || '.').sort();
41623
+ const entries = compilerSys.readDirSync(path || '.').sort();
41235
41624
  const files = [];
41236
41625
  const directories = [];
41237
41626
  for (const absPath of entries) {
@@ -41256,13 +41645,13 @@ const patchTsSystemFileSystem = (config, stencilSys, inMemoryFs, tsSys) => {
41256
41645
  }
41257
41646
  };
41258
41647
  tsSys.createDirectory = (p) => {
41259
- stencilSys.createDirSync(p, { recursive: true });
41648
+ compilerSys.createDirSync(p, { recursive: true });
41260
41649
  };
41261
41650
  tsSys.directoryExists = (p) => {
41262
41651
  const s = inMemoryFs.statSync(p);
41263
41652
  return s.isDirectory;
41264
41653
  };
41265
- tsSys.exit = stencilSys.exit;
41654
+ tsSys.exit = compilerSys.exit;
41266
41655
  tsSys.fileExists = (p) => {
41267
41656
  let filePath = p;
41268
41657
  if (isRemoteUrl(p)) {
@@ -41271,17 +41660,17 @@ const patchTsSystemFileSystem = (config, stencilSys, inMemoryFs, tsSys) => {
41271
41660
  const s = inMemoryFs.statSync(filePath);
41272
41661
  return !!(s && s.isFile);
41273
41662
  };
41274
- tsSys.getCurrentDirectory = stencilSys.getCurrentDirectory;
41275
- tsSys.getExecutingFilePath = stencilSys.getCompilerExecutingPath;
41663
+ tsSys.getCurrentDirectory = compilerSys.getCurrentDirectory;
41664
+ tsSys.getExecutingFilePath = compilerSys.getCompilerExecutingPath;
41276
41665
  tsSys.getDirectories = (p) => {
41277
- const items = stencilSys.readDirSync(p);
41666
+ const items = compilerSys.readDirSync(p);
41278
41667
  return items.filter((itemPath) => {
41279
41668
  const s = inMemoryFs.statSync(itemPath);
41280
41669
  return !!(s && s.exists && s.isDirectory);
41281
41670
  });
41282
41671
  };
41283
41672
  tsSys.readDirectory = (path, extensions, exclude, include, depth) => {
41284
- const cwd = stencilSys.getCurrentDirectory();
41673
+ const cwd = compilerSys.getCurrentDirectory();
41285
41674
  // TODO(STENCIL-344): Replace `matchFiles` with a function that is publicly exposed
41286
41675
  return t.matchFiles(path, extensions, exclude, include, IS_CASE_SENSITIVE_FILE_NAMES, cwd, depth, getAccessibleFileSystemEntries, realpath);
41287
41676
  };
@@ -41308,9 +41697,9 @@ const patchTsSystemFileSystem = (config, stencilSys, inMemoryFs, tsSys) => {
41308
41697
  tsSys.writeFile = (p, data) => inMemoryFs.writeFile(p, data);
41309
41698
  return tsSys;
41310
41699
  };
41311
- const patchTsSystemWatch = (stencilSys, tsSys) => {
41700
+ const patchTsSystemWatch = (compilerSystem, tsSys) => {
41312
41701
  tsSys.watchDirectory = (p, cb, recursive) => {
41313
- const watcher = stencilSys.watchDirectory(p, (filePath) => {
41702
+ const watcher = compilerSystem.watchDirectory(p, (filePath) => {
41314
41703
  cb(filePath);
41315
41704
  }, recursive);
41316
41705
  return {
@@ -41320,7 +41709,7 @@ const patchTsSystemWatch = (stencilSys, tsSys) => {
41320
41709
  };
41321
41710
  };
41322
41711
  tsSys.watchFile = (p, cb) => {
41323
- const watcher = stencilSys.watchFile(p, (filePath, eventKind) => {
41712
+ const watcher = compilerSystem.watchFile(p, (filePath, eventKind) => {
41324
41713
  if (eventKind === 'fileAdd') {
41325
41714
  cb(filePath, t.FileWatcherEventKind.Created);
41326
41715
  }
@@ -41528,7 +41917,7 @@ const createCustomResolverSync = (sys, inMemoryFs, exts) => {
41528
41917
  * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d121716ed123957f6a86f8985eb013fcaddab345/types/node/globals.d.ts#L183-L188
41529
41918
  * in mind.
41530
41919
  * @param err the entity to check the type of
41531
- * @return true if the provided value is an instance of `ErrnoException`, `false` otherwise
41920
+ * @returns true if the provided value is an instance of `ErrnoException`, `false` otherwise
41532
41921
  */
41533
41922
  function isErrnoException(err) {
41534
41923
  return err instanceof Error && err.hasOwnProperty('code');
@@ -55573,6 +55962,9 @@ const updateStencilCoreImports = (updatedCoreImportPath) => {
55573
55962
  };
55574
55963
  };
55575
55964
  };
55965
+ /**
55966
+ * A set of imports which we don't want to remove from an output file
55967
+ */
55576
55968
  const KEEP_IMPORTS = new Set([
55577
55969
  'h',
55578
55970
  'setMode',
@@ -55592,37 +55984,75 @@ const KEEP_IMPORTS = new Set([
55592
55984
  'setErrorHandler',
55593
55985
  ]);
55594
55986
 
55987
+ /**
55988
+ * Main output target function for `dist-custom-elements`. This function just
55989
+ * does some organizational work to call the other functions in this module,
55990
+ * which do actual work of generating the rollup configuration, creating an
55991
+ * entry chunk, running, the build, etc.
55992
+ *
55993
+ * @param config the user-supplied compiler configuration we're using
55994
+ * @param compilerCtx the current compiler context
55995
+ * @param buildCtx the current build context
55996
+ * @returns an empty Promise which won't resolve until the work is done!
55997
+ */
55595
55998
  const outputCustomElements = async (config, compilerCtx, buildCtx) => {
55999
+ var _a;
55596
56000
  if (!config.buildDist) {
55597
56001
  return;
55598
56002
  }
55599
- const outputTargets = config.outputTargets.filter(isOutputTargetDistCustomElements);
56003
+ const outputTargets = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).filter(isOutputTargetDistCustomElements);
55600
56004
  if (outputTargets.length === 0) {
55601
56005
  return;
55602
56006
  }
55603
56007
  const bundlingEventMessage = 'generate custom elements';
55604
56008
  const timespan = buildCtx.createTimeSpan(`${bundlingEventMessage} started`);
55605
- await Promise.all(outputTargets.map((o) => bundleCustomElements$1(config, compilerCtx, buildCtx, o)));
56009
+ await Promise.all(outputTargets.map((target) => bundleCustomElements$1(config, compilerCtx, buildCtx, target)));
55606
56010
  timespan.finish(`${bundlingEventMessage} finished`);
55607
56011
  };
56012
+ /**
56013
+ * Get bundle options for our current build and compiler context which we'll use
56014
+ * to generate a Rollup build and so on.
56015
+ *
56016
+ * @param config user-supplied Stencil configuration
56017
+ * @param buildCtx the current build context
56018
+ * @param compilerCtx the current compiler context
56019
+ * @param outputTarget the outputTarget we're currently dealing with
56020
+ * @returns bundle options suitable for generating a rollup configuration
56021
+ */
56022
+ const getBundleOptions = (config, buildCtx, compilerCtx, outputTarget) => ({
56023
+ id: 'customElements',
56024
+ platform: 'client',
56025
+ conditionals: getCustomElementsBuildConditionals(config, buildCtx.components),
56026
+ customTransformers: getCustomElementCustomTransformer(config, compilerCtx, buildCtx.components, outputTarget),
56027
+ externalRuntime: !!outputTarget.externalRuntime,
56028
+ inlineWorkers: true,
56029
+ inputs: {
56030
+ // Here we prefix our index chunk with '\0' to tell Rollup that we're
56031
+ // going to be using virtual modules with this module. A leading '\0'
56032
+ // prevents other plugins from messing with the module. We generate a
56033
+ // string for the index chunk below in the `loader` property.
56034
+ //
56035
+ // @see {@link https://rollupjs.org/guide/en/#conventions} for more info.
56036
+ index: '\0core',
56037
+ },
56038
+ loader: {
56039
+ '\0core': generateEntryPoint$1(outputTarget),
56040
+ },
56041
+ inlineDynamicImports: outputTarget.inlineDynamicImports,
56042
+ preserveEntrySignatures: 'allow-extension',
56043
+ });
56044
+ /**
56045
+ * Get bundle options for rollup, run the rollup build, optionally minify the
56046
+ * output, and write files to disk.
56047
+ * @param config user-supplied Stencil configuration
56048
+ * @param buildCtx the current build context
56049
+ * @param compilerCtx the current compiler context
56050
+ * @param outputTarget the outputTarget we're currently dealing with
56051
+ * @returns an empty promise
56052
+ */
55608
56053
  const bundleCustomElements$1 = async (config, compilerCtx, buildCtx, outputTarget) => {
55609
56054
  try {
55610
- const bundleOpts = {
55611
- id: 'customElements',
55612
- platform: 'client',
55613
- conditionals: getCustomElementsBuildConditionals(config, buildCtx.components),
55614
- customTransformers: getCustomElementCustomTransformer(config, compilerCtx, buildCtx.components, outputTarget),
55615
- externalRuntime: !!outputTarget.externalRuntime,
55616
- inlineWorkers: true,
55617
- inputs: {
55618
- index: '\0core',
55619
- },
55620
- loader: {
55621
- '\0core': generateEntryPoint$1(outputTarget),
55622
- },
55623
- inlineDynamicImports: outputTarget.inlineDynamicImports,
55624
- preserveEntrySignatures: 'allow-extension',
55625
- };
56055
+ const bundleOpts = getBundleOptions(config, buildCtx, compilerCtx, outputTarget);
55626
56056
  addCustomElementInputs(buildCtx, bundleOpts);
55627
56057
  const build = await bundleOutput(config, compilerCtx, buildCtx, bundleOpts);
55628
56058
  if (build) {
@@ -55635,6 +56065,18 @@ const bundleCustomElements$1 = async (config, compilerCtx, buildCtx, outputTarge
55635
56065
  hoistTransitiveImports: false,
55636
56066
  preferConst: true,
55637
56067
  });
56068
+ // the output target should have been validated at this point - as a result, we expect this field
56069
+ // to have been backfilled if it wasn't provided
56070
+ const outputTargetDir = outputTarget.dir;
56071
+ // besides, if it isn't here we do a diagnostic and an early return
56072
+ if (!isString$1(outputTargetDir)) {
56073
+ buildCtx.diagnostics.push({
56074
+ level: 'error',
56075
+ type: 'build',
56076
+ messageText: 'dist-custom-elements output target provided with no output target directory!',
56077
+ });
56078
+ return;
56079
+ }
55638
56080
  const minify = outputTarget.externalRuntime || outputTarget.minify !== true ? false : config.minifyJs;
55639
56081
  const files = rollupOutput.output.map(async (bundle) => {
55640
56082
  if (bundle.type === 'chunk') {
@@ -55649,15 +56091,15 @@ const bundleCustomElements$1 = async (config, compilerCtx, buildCtx, outputTarge
55649
56091
  buildCtx.diagnostics.push(...optimizeResults.diagnostics);
55650
56092
  if (!hasError(optimizeResults.diagnostics) && typeof optimizeResults.output === 'string') {
55651
56093
  code = optimizeResults.output;
55652
- sourceMap = optimizeResults.sourceMap;
55653
56094
  }
55654
- if (sourceMap) {
56095
+ if (optimizeResults.sourceMap) {
56096
+ sourceMap = optimizeResults.sourceMap;
55655
56097
  code = code + getSourceMappingUrlForEndOfFile(bundle.fileName);
55656
- await compilerCtx.fs.writeFile(join(outputTarget.dir, bundle.fileName + '.map'), JSON.stringify(sourceMap), {
56098
+ await compilerCtx.fs.writeFile(join(outputTargetDir, bundle.fileName + '.map'), JSON.stringify(sourceMap), {
55657
56099
  outputTargetType: outputTarget.type,
55658
56100
  });
55659
56101
  }
55660
- await compilerCtx.fs.writeFile(join(outputTarget.dir, bundle.fileName), code, {
56102
+ await compilerCtx.fs.writeFile(join(outputTargetDir, bundle.fileName), code, {
55661
56103
  outputTargetType: outputTarget.type,
55662
56104
  });
55663
56105
  }
@@ -55676,6 +56118,8 @@ const bundleCustomElements$1 = async (config, compilerCtx, buildCtx, outputTarge
55676
56118
  */
55677
56119
  const addCustomElementInputs = (buildCtx, bundleOpts) => {
55678
56120
  const components = buildCtx.components;
56121
+ // an array to store the imports of these modules that we're going to add to our entry chunk
56122
+ const indexImports = [];
55679
56123
  components.forEach((cmp) => {
55680
56124
  const exp = [];
55681
56125
  const exportName = dashToPascalCase$1(cmp.tagName);
@@ -55684,16 +56128,25 @@ const addCustomElementInputs = (buildCtx, bundleOpts) => {
55684
56128
  const coreKey = `\0${exportName}`;
55685
56129
  if (cmp.isPlain) {
55686
56130
  exp.push(`export { ${importName} as ${exportName} } from '${cmp.sourceFilePath}';`);
56131
+ indexImports.push(`export { {${exportName} } from '${coreKey}';`);
55687
56132
  }
55688
56133
  else {
55689
56134
  // the `importName` may collide with the `exportName`, alias it just in case it does with `importAs`
55690
56135
  exp.push(`import { ${importName} as ${importAs}, defineCustomElement as cmpDefCustomEle } from '${cmp.sourceFilePath}';`);
55691
56136
  exp.push(`export const ${exportName} = ${importAs};`);
55692
56137
  exp.push(`export const defineCustomElement = cmpDefCustomEle;`);
56138
+ // Here we push an export (with a rename for `defineCustomElement` for
56139
+ // this component onto our array which references the `coreKey` (prefixed
56140
+ // with `\0`). We have to do this so that our import is referencing the
56141
+ // correct virtual module, if we instead referenced, for instance,
56142
+ // `cmp.sourceFilePath`, we would end up with duplicated modules in our
56143
+ // output.
56144
+ indexImports.push(`export { ${exportName}, defineCustomElement as defineCustomElement${exportName} } from '${coreKey}';`);
55693
56145
  }
55694
56146
  bundleOpts.inputs[cmp.tagName] = coreKey;
55695
56147
  bundleOpts.loader[coreKey] = exp.join('\n');
55696
56148
  });
56149
+ bundleOpts.loader['\0core'] += indexImports.join('\n');
55697
56150
  };
55698
56151
  /**
55699
56152
  * Generate the entrypoint (`index.ts` file) contents for the `dist-custom-elements` output target
@@ -55711,6 +56164,7 @@ const generateEntryPoint$1 = (outputTarget) => {
55711
56164
  /**
55712
56165
  * Get the series of custom transformers that will be applied to a Stencil project's source code during the TypeScript
55713
56166
  * transpilation process
56167
+ *
55714
56168
  * @param config the configuration for the Stencil project
55715
56169
  * @param compilerCtx the current compiler context
55716
56170
  * @param components the components that will be compiled as a part of the current build
@@ -57502,6 +57956,16 @@ const lazyComponentTransform = (compilerCtx, transformOpts) => {
57502
57956
  };
57503
57957
  };
57504
57958
 
57959
+ /**
57960
+ * Generate rollup output based on a rollup build and a series of options.
57961
+ *
57962
+ * @param build a rollup build
57963
+ * @param options output options for rollup
57964
+ * @param config a user-supplied configuration object
57965
+ * @param entryModules a list of entry modules, for checking which chunks
57966
+ * contain components
57967
+ * @returns a Promise wrapping either build results or `null`
57968
+ */
57505
57969
  const generateRollupOutput = async (build, options, config, entryModules) => {
57506
57970
  if (build == null) {
57507
57971
  return null;
@@ -57509,7 +57973,7 @@ const generateRollupOutput = async (build, options, config, entryModules) => {
57509
57973
  const { output } = await build.generate(options);
57510
57974
  return output.map((chunk) => {
57511
57975
  if (chunk.type === 'chunk') {
57512
- const isCore = Object.keys(chunk.modules).some((m) => m.includes('@stencil/core'));
57976
+ const isCore = Object.keys(chunk.modules).some((m) => m.includes(STENCIL_CORE_ID));
57513
57977
  return {
57514
57978
  type: 'chunk',
57515
57979
  fileName: chunk.fileName,
@@ -58008,7 +58472,8 @@ const getSystemLoader = async (config, compilerCtx, corePath, includePolyfills)
58008
58472
 
58009
58473
  var resourcesUrl = scriptElm ? scriptElm.getAttribute('data-resources-url') || scriptElm.src : '';
58010
58474
  var start = function() {
58011
- var url = new URL('${corePath}', new URL(resourcesUrl, window.location.origin));
58475
+ // if src is not present then origin is "null", and new URL() throws TypeError: Failed to construct 'URL': Invalid base URL
58476
+ var url = new URL('${corePath}', new URL(resourcesUrl, window.location.origin !== 'null' ? window.location.origin : undefined));
58012
58477
  System.import(url.href);
58013
58478
  };
58014
58479
 
@@ -59702,29 +60167,38 @@ const relDts$1 = (fromPath, dtsPath) => {
59702
60167
  * @param config the Stencil configuration associated with the project being compiled
59703
60168
  * @param compilerCtx the current compiler context
59704
60169
  * @param buildCtx the context associated with the current build
59705
- * @param distDtsFilePath the path to a type declaration file (.d.ts) that is being generated for the output target.
59706
- * This path is not necessarily the `components.d.ts` file that is found in the root of a project's `src` directory.
60170
+ * @param typesDir the path to the directory where type declarations are saved
59707
60171
  */
59708
- const generateCustomElementsTypes = async (config, compilerCtx, buildCtx, distDtsFilePath) => {
59709
- const outputTargets = config.outputTargets.filter(isOutputTargetDistCustomElements);
59710
- await Promise.all(outputTargets.map((outputTarget) => generateCustomElementsTypesOutput(config, compilerCtx, buildCtx, distDtsFilePath, outputTarget)));
60172
+ const generateCustomElementsTypes = async (config, compilerCtx, buildCtx, typesDir) => {
60173
+ var _a;
60174
+ const outputTargets = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).filter(isOutputTargetDistCustomElements);
60175
+ await Promise.all(outputTargets.map((outputTarget) => generateCustomElementsTypesOutput(config, compilerCtx, buildCtx, typesDir, outputTarget)));
59711
60176
  };
59712
60177
  /**
59713
60178
  * Generates types for a single `dist-custom-elements` output target definition in a Stencil project's configuration
60179
+ *
59714
60180
  * @param config the Stencil configuration associated with the project being compiled
59715
60181
  * @param compilerCtx the current compiler context
59716
60182
  * @param buildCtx the context associated with the current build
59717
- * @param distDtsFilePath the path to a type declaration file (.d.ts) that is being generated for the output target.
59718
- * This path is not necessarily the `components.d.ts` file that is found in the root of a project's `src` directory.
60183
+ * @param typesDir path to the directory where type declarations are saved
59719
60184
  * @param outputTarget the output target for which types are being currently generated
59720
60185
  */
59721
- const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx, distDtsFilePath, outputTarget) => {
60186
+ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx, typesDir, outputTarget) => {
60187
+ // the path where we're going to write the typedef for the whole dist-custom-elements output
59722
60188
  const customElementsDtsPath = join(outputTarget.dir, 'index.d.ts');
59723
- const componentsDtsRelPath = relDts(outputTarget.dir, distDtsFilePath);
60189
+ // the directory where types for the individual components are written
60190
+ const componentsTypeDirectoryPath = relative$1(outputTarget.dir, join(typesDir, 'components'));
60191
+ const components = buildCtx.components.filter((m) => !m.isCollectionDependency);
59724
60192
  const code = [
59725
60193
  `/* ${config.namespace} custom elements */`,
59726
- ``,
59727
- `import type { Components, JSX } from "${componentsDtsRelPath}";`,
60194
+ ...components.map((component) => {
60195
+ const exportName = dashToPascalCase$1(component.tagName);
60196
+ const importName = component.componentClassName;
60197
+ // typedefs for individual components can be found under paths like
60198
+ // $TYPES_DIR/components/my-component/my-component.d.ts
60199
+ const componentDTSPath = join(componentsTypeDirectoryPath, component.tagName, component.tagName);
60200
+ return `export { ${importName} as ${exportName} } from '${componentDTSPath}';`;
60201
+ }),
59728
60202
  ``,
59729
60203
  `/**`,
59730
60204
  ` * Used to manually set the base path where assets can be found.`,
@@ -59744,10 +60218,8 @@ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx,
59744
60218
  ` rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;`,
59745
60219
  `}`,
59746
60220
  `export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;`,
59747
- ``,
59748
- `export type { Components, JSX };`,
59749
- ``,
59750
60221
  ];
60222
+ const componentsDtsRelPath = relDts(outputTarget.dir, join(typesDir, 'components.d.ts'));
59751
60223
  const usersIndexJsPath = join(config.srcDir, 'index.ts');
59752
60224
  const hasUserIndex = await compilerCtx.fs.access(usersIndexJsPath);
59753
60225
  if (hasUserIndex) {
@@ -59760,7 +60232,6 @@ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx,
59760
60232
  await compilerCtx.fs.writeFile(customElementsDtsPath, code.join('\n') + `\n`, {
59761
60233
  outputTargetType: outputTarget.type,
59762
60234
  });
59763
- const components = buildCtx.components.filter((m) => !m.isCollectionDependency);
59764
60235
  await Promise.all(components.map(async (cmp) => {
59765
60236
  const dtsCode = generateCustomElementType(componentsDtsRelPath, cmp);
59766
60237
  const fileName = `${cmp.tagName}.d.ts`;
@@ -59834,20 +60305,21 @@ const generateTypesOutput = async (config, compilerCtx, buildCtx, outputTarget)
59834
60305
  const srcDtsFiles = srcDirItems.filter((srcItem) => srcItem.isFile && isDtsFile$1(srcItem.absPath));
59835
60306
  // Copy .d.ts files from src to dist
59836
60307
  // In addition, all references to @stencil/core are replaced
59837
- let distDtsFilePath;
59838
- await Promise.all(srcDtsFiles.map(async (srcDtsFile) => {
60308
+ const copiedDTSFilePaths = await Promise.all(srcDtsFiles.map(async (srcDtsFile) => {
59839
60309
  const relPath = relative$1(config.srcDir, srcDtsFile.absPath);
59840
60310
  const distPath = join(outputTarget.typesDir, relPath);
59841
60311
  const originalDtsContent = await compilerCtx.fs.readFile(srcDtsFile.absPath);
59842
60312
  const distDtsContent = updateStencilTypesImports(outputTarget.typesDir, distPath, originalDtsContent);
59843
60313
  await compilerCtx.fs.writeFile(distPath, distDtsContent);
59844
- distDtsFilePath = distPath;
60314
+ return distPath;
59845
60315
  }));
60316
+ const distDtsFilePath = copiedDTSFilePaths.slice(-1)[0];
59846
60317
  const distPath = outputTarget.typesDir;
59847
60318
  await generateAppTypes(config, compilerCtx, buildCtx, distPath);
60319
+ const { typesDir } = outputTarget;
59848
60320
  if (distDtsFilePath) {
59849
- await generateCustomElementsTypes(config, compilerCtx, buildCtx, distDtsFilePath);
59850
60321
  await generateCustomElementsBundleTypes(config, compilerCtx, buildCtx, distDtsFilePath);
60322
+ await generateCustomElementsTypes(config, compilerCtx, buildCtx, typesDir);
59851
60323
  }
59852
60324
  };
59853
60325
 
@@ -63642,37 +64114,76 @@ const filesChanged = (buildCtx) => {
63642
64114
  // files changed include updated, added and deleted
63643
64115
  return unique([...buildCtx.filesUpdated, ...buildCtx.filesAdded, ...buildCtx.filesDeleted]).sort();
63644
64116
  };
63645
- const scriptsAdded = (buildCtx) => {
63646
- // collect all the scripts that were added
63647
- return buildCtx.filesAdded
63648
- .filter((f) => {
63649
- return SCRIPT_EXT.some((ext) => f.endsWith(ext.toLowerCase()));
63650
- })
63651
- .map((f) => basename(f));
63652
- };
63653
- const scriptsDeleted = (buildCtx) => {
63654
- // collect all the scripts that were deleted
63655
- return buildCtx.filesDeleted
63656
- .filter((f) => {
63657
- return SCRIPT_EXT.some((ext) => f.endsWith(ext.toLowerCase()));
63658
- })
63659
- .map((f) => basename(f));
63660
- };
63661
- const hasScriptChanges = (buildCtx) => {
63662
- return buildCtx.filesChanged.some((f) => {
63663
- const ext = getExt(f);
63664
- return SCRIPT_EXT.includes(ext);
63665
- });
63666
- };
63667
- const hasStyleChanges = (buildCtx) => {
63668
- return buildCtx.filesChanged.some((f) => {
63669
- const ext = getExt(f);
63670
- return STYLE_EXT.includes(ext);
63671
- });
63672
- };
64117
+ /**
64118
+ * Unary helper function mapping string to string and wrapping `basename`,
64119
+ * which normally takes two string arguments. This means it cannot be passed
64120
+ * to `Array.prototype.map`, but this little helper can!
64121
+ *
64122
+ * @param filePath a filepath to check out
64123
+ * @returns the basename for that filepath
64124
+ */
64125
+ const unaryBasename = (filePath) => basename(filePath);
64126
+ /**
64127
+ * Get the file extension for a path
64128
+ *
64129
+ * @param filePath a path
64130
+ * @returns the file extension (well, characters after the last `'.'`)
64131
+ */
63673
64132
  const getExt = (filePath) => filePath.split('.').pop().toLowerCase();
64133
+ /**
64134
+ * Script extensions which we want to be able to recognize
64135
+ */
63674
64136
  const SCRIPT_EXT = ['ts', 'tsx', 'js', 'jsx'];
64137
+ /**
64138
+ * Helper to check if a filepath has a script extension
64139
+ *
64140
+ * @param filePath a file extension
64141
+ * @returns whether the filepath has a script extension or not
64142
+ */
64143
+ const hasScriptExt = (filePath) => SCRIPT_EXT.includes(getExt(filePath));
63675
64144
  const STYLE_EXT = ['css', 'scss', 'sass', 'pcss', 'styl', 'stylus', 'less'];
64145
+ /**
64146
+ * Helper to check if a filepath has a style extension
64147
+ *
64148
+ * @param filePath a file extension to check
64149
+ * @returns whether the filepath has a style extension or not
64150
+ */
64151
+ const hasStyleExt = (filePath) => STYLE_EXT.includes(getExt(filePath));
64152
+ /**
64153
+ * Get all scripts from a build context that were added
64154
+ *
64155
+ * @param buildCtx the build context
64156
+ * @returns an array of filepaths that were added
64157
+ */
64158
+ const scriptsAdded = (buildCtx) => buildCtx.filesAdded.filter(hasScriptExt).map(unaryBasename);
64159
+ /**
64160
+ * Get all scripts from a build context that were deleted
64161
+ *
64162
+ * @param buildCtx the build context
64163
+ * @returns an array of deleted filepaths
64164
+ */
64165
+ const scriptsDeleted = (buildCtx) => buildCtx.filesDeleted.filter(hasScriptExt).map(unaryBasename);
64166
+ /**
64167
+ * Check whether a build has script changes
64168
+ *
64169
+ * @param buildCtx the build context
64170
+ * @returns whether or not there are script changes
64171
+ */
64172
+ const hasScriptChanges = (buildCtx) => buildCtx.filesChanged.some(hasScriptExt);
64173
+ /**
64174
+ * Check whether a build has style changes
64175
+ *
64176
+ * @param buildCtx the build context
64177
+ * @returns whether or not there are style changes
64178
+ */
64179
+ const hasStyleChanges = (buildCtx) => buildCtx.filesChanged.some(hasStyleExt);
64180
+ /**
64181
+ * Check whether a build has html changes
64182
+ *
64183
+ * @param config the current config
64184
+ * @param buildCtx the build context
64185
+ * @returns whether or not HTML files were changed
64186
+ */
63676
64187
  const hasHtmlChanges = (config, buildCtx) => {
63677
64188
  const anyHtmlChanged = buildCtx.filesChanged.some((f) => f.toLowerCase().endsWith('.html'));
63678
64189
  if (anyHtmlChanged) {
@@ -63887,15 +64398,14 @@ const updateCompilerCtxCache = (config, compilerCtx, path, kind) => {
63887
64398
  };
63888
64399
 
63889
64400
  const getConfig = (userConfig) => {
63890
- const config = { ...userConfig };
63891
- if (!config.logger) {
63892
- config.logger = createLogger();
63893
- }
64401
+ var _a, _b;
64402
+ const flags = (_a = userConfig.flags) !== null && _a !== void 0 ? _a : {};
64403
+ const logger = (_b = userConfig.logger) !== null && _b !== void 0 ? _b : createLogger();
64404
+ const config = { ...userConfig, flags, logger };
63894
64405
  if (!config.sys) {
63895
64406
  config.sys = createSystem({ logger: config.logger });
63896
64407
  }
63897
64408
  setPlatformPath(config.sys.platformPath);
63898
- config.flags = config.flags || {};
63899
64409
  if (config.flags.debug || config.flags.verbose) {
63900
64410
  config.logLevel = 'debug';
63901
64411
  }
@@ -63916,14 +64426,15 @@ const patchFs = (userSys) => {
63916
64426
 
63917
64427
  /**
63918
64428
  * Generate a Stencil compiler instance
63919
- * @param config a Stencil configuration to apply to the compiler instance
64429
+ * @param userConfig a user-provided Stencil configuration to apply to the compiler instance
63920
64430
  * @returns a new instance of a Stencil compiler
64431
+ * @public
63921
64432
  */
63922
- const createCompiler = async (config) => {
64433
+ const createCompiler = async (userConfig) => {
63923
64434
  // actual compiler code
63924
64435
  // could be in a web worker on the browser
63925
64436
  // or the main thread in node
63926
- config = getConfig(config);
64437
+ const config = getConfig(userConfig);
63927
64438
  const diagnostics = [];
63928
64439
  const sys = config.sys;
63929
64440
  const compilerCtx = new CompilerContext();
@@ -64599,7 +65110,7 @@ const getComponentPathContent = (componentGraph, outputTarget) => {
64599
65110
  const dependencies = [
64600
65111
  {
64601
65112
  name: "@stencil/core",
64602
- version: "2.16.1-0",
65113
+ version: "2.17.1",
64603
65114
  main: "compiler/stencil.js",
64604
65115
  resources: [
64605
65116
  "package.json",
@@ -64771,11 +65282,11 @@ const getUserConfigName = (config, correctConfigName) => {
64771
65282
  };
64772
65283
 
64773
65284
  const validateDevServer = (config, diagnostics) => {
64774
- var _a, _b, _c, _d, _e, _f, _g;
65285
+ var _a, _b, _c, _d, _e;
64775
65286
  if ((config.devServer === null || config.devServer) === false) {
64776
65287
  return undefined;
64777
65288
  }
64778
- const flags = (_a = config.flags) !== null && _a !== void 0 ? _a : {};
65289
+ const { flags } = config;
64779
65290
  const devServer = { ...config.devServer };
64780
65291
  if (flags.address && isString$1(flags.address)) {
64781
65292
  devServer.address = flags.address;
@@ -64833,14 +65344,14 @@ const validateDevServer = (config, diagnostics) => {
64833
65344
  if (!isBoolean$1(devServer.websocket)) {
64834
65345
  devServer.websocket = true;
64835
65346
  }
64836
- if ((_b = config === null || config === void 0 ? void 0 : config.flags) === null || _b === void 0 ? void 0 : _b.ssr) {
65347
+ if (flags.ssr) {
64837
65348
  devServer.ssr = true;
64838
65349
  }
64839
65350
  else {
64840
65351
  devServer.ssr = !!devServer.ssr;
64841
65352
  }
64842
65353
  if (devServer.ssr) {
64843
- const wwwOutput = ((_c = config.outputTargets) !== null && _c !== void 0 ? _c : []).find(isOutputTargetWww);
65354
+ const wwwOutput = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).find(isOutputTargetWww);
64844
65355
  devServer.prerenderConfig = wwwOutput === null || wwwOutput === void 0 ? void 0 : wwwOutput.prerenderConfig;
64845
65356
  }
64846
65357
  if (isString$1(config.srcIndexHtml)) {
@@ -64866,15 +65377,15 @@ const validateDevServer = (config, diagnostics) => {
64866
65377
  }
64867
65378
  let serveDir;
64868
65379
  let basePath;
64869
- const wwwOutputTarget = ((_d = config.outputTargets) !== null && _d !== void 0 ? _d : []).find(isOutputTargetWww);
65380
+ const wwwOutputTarget = ((_b = config.outputTargets) !== null && _b !== void 0 ? _b : []).find(isOutputTargetWww);
64870
65381
  if (wwwOutputTarget) {
64871
- const baseUrl = new URL((_e = wwwOutputTarget.baseUrl) !== null && _e !== void 0 ? _e : '', 'http://config.stenciljs.com');
65382
+ const baseUrl = new URL((_c = wwwOutputTarget.baseUrl) !== null && _c !== void 0 ? _c : '', 'http://config.stenciljs.com');
64872
65383
  basePath = baseUrl.pathname;
64873
- serveDir = (_f = wwwOutputTarget.appDir) !== null && _f !== void 0 ? _f : '';
65384
+ serveDir = (_d = wwwOutputTarget.appDir) !== null && _d !== void 0 ? _d : '';
64874
65385
  }
64875
65386
  else {
64876
65387
  basePath = '';
64877
- serveDir = (_g = config.rootDir) !== null && _g !== void 0 ? _g : '';
65388
+ serveDir = (_e = config.rootDir) !== null && _e !== void 0 ? _e : '';
64878
65389
  }
64879
65390
  if (!isString$1(basePath) || basePath.trim() === '') {
64880
65391
  basePath = `/`;
@@ -65008,11 +65519,19 @@ const validateHydrated = (config) => {
65008
65519
  return hydratedFlag;
65009
65520
  };
65010
65521
 
65522
+ /**
65523
+ * Validate and return DIST_COLLECTION output targets, ensuring that the `dir`
65524
+ * property is set on them.
65525
+ *
65526
+ * @param config the user-supplied configuration object
65527
+ * @param userOutputs an array of output targets
65528
+ * @returns an array of validated DIST_COLLECTION output targets
65529
+ */
65011
65530
  const validateCollection = (config, userOutputs) => {
65012
- return userOutputs.filter(isOutputTargetDistCollection).map((o) => {
65531
+ return userOutputs.filter(isOutputTargetDistCollection).map((outputTarget) => {
65013
65532
  return {
65014
- ...o,
65015
- dir: getAbsolutePath(config, o.dir || 'dist/collection'),
65533
+ ...outputTarget,
65534
+ dir: getAbsolutePath(config, outputTarget.dir || 'dist/collection'),
65016
65535
  };
65017
65536
  });
65018
65537
  };
@@ -65346,7 +65865,7 @@ const validateHydrateScript = (config, userOutputs) => {
65346
65865
  // we don't already have a hydrate output target
65347
65866
  // let's still see if we require one because of other output targets
65348
65867
  const hasWwwOutput = userOutputs.filter(isOutputTargetWww).some((o) => isString$1(o.indexHtml));
65349
- const shouldBuildHydrate = (config === null || config === void 0 ? void 0 : config.flags.prerender) || (config === null || config === void 0 ? void 0 : config.flags.ssr);
65868
+ const shouldBuildHydrate = config.flags.prerender || config.flags.ssr;
65350
65869
  if (hasWwwOutput && shouldBuildHydrate) {
65351
65870
  // we're prerendering a www output target, so we'll need a hydrate app
65352
65871
  let hydrateDir;
@@ -65422,7 +65941,7 @@ const validateStats = (userConfig, userOutputs) => {
65422
65941
  };
65423
65942
 
65424
65943
  const validatePrerender = (config, diagnostics, outputTarget) => {
65425
- if (!config.flags || (!config.flags.ssr && !config.flags.prerender && config.flags.task !== 'prerender')) {
65944
+ if (!config.flags.ssr && !config.flags.prerender && config.flags.task !== 'prerender') {
65426
65945
  return;
65427
65946
  }
65428
65947
  outputTarget.baseUrl = normalizePath$1(outputTarget.baseUrl);
@@ -65447,8 +65966,6 @@ const validatePrerender = (config, diagnostics, outputTarget) => {
65447
65966
  }
65448
65967
  };
65449
65968
 
65450
- const HOST_CONFIG_FILENAME = 'host.config.json';
65451
-
65452
65969
  const validateServiceWorker = (config, outputTarget) => {
65453
65970
  if (outputTarget.serviceWorker === false) {
65454
65971
  return;
@@ -65501,14 +66018,15 @@ const validateServiceWorker = (config, outputTarget) => {
65501
66018
  }
65502
66019
  };
65503
66020
  const addGlobIgnores = (config, globIgnores) => {
65504
- globIgnores.push(`**/${HOST_CONFIG_FILENAME}`, `**/*.system.entry.js`, `**/*.system.js`, `**/${config.fsNamespace}.js`, `**/${config.fsNamespace}.esm.js`, `**/${config.fsNamespace}.css`);
66021
+ globIgnores.push(`**/host.config.json`, // the filename of the host configuration
66022
+ `**/*.system.entry.js`, `**/*.system.js`, `**/${config.fsNamespace}.js`, `**/${config.fsNamespace}.esm.js`, `**/${config.fsNamespace}.css`);
65505
66023
  };
65506
66024
  const DEFAULT_GLOB_PATTERNS = ['*.html', '**/*.{js,css,json}'];
65507
66025
  const DEFAULT_FILENAME = 'sw.js';
65508
66026
 
65509
66027
  const validateWww = (config, diagnostics, userOutputs) => {
65510
66028
  const hasOutputTargets = userOutputs.length > 0;
65511
- const hasE2eTests = !!(config.flags && config.flags.e2e);
66029
+ const hasE2eTests = !!config.flags.e2e;
65512
66030
  const userWwwOutputs = userOutputs.filter(isOutputTargetWww);
65513
66031
  if (!hasOutputTargets ||
65514
66032
  (hasE2eTests && !userOutputs.some(isOutputTargetWww) && !userOutputs.some(isOutputTargetDist))) {
@@ -65762,7 +66280,7 @@ const DEFAULT_ROLLUP_CONFIG = {
65762
66280
  const validateTesting = (config, diagnostics) => {
65763
66281
  var _a;
65764
66282
  const testing = (config.testing = Object.assign({}, config.testing || {}));
65765
- if (!config.flags || (!config.flags.e2e && !config.flags.spec)) {
66283
+ if (!config.flags.e2e && !config.flags.spec) {
65766
66284
  return;
65767
66285
  }
65768
66286
  let configPathDir = config.configPath;
@@ -65800,7 +66318,7 @@ const validateTesting = (config, diagnostics) => {
65800
66318
  else {
65801
66319
  testing.rootDir = config.rootDir;
65802
66320
  }
65803
- if (config.flags && typeof config.flags.screenshotConnector === 'string') {
66321
+ if (typeof config.flags.screenshotConnector === 'string') {
65804
66322
  testing.screenshotConnector = config.flags.screenshotConnector;
65805
66323
  }
65806
66324
  if (typeof testing.screenshotConnector === 'string') {
@@ -65922,13 +66440,11 @@ const validateWorkers = (config) => {
65922
66440
  if (typeof config.maxConcurrentWorkers !== 'number') {
65923
66441
  config.maxConcurrentWorkers = 8;
65924
66442
  }
65925
- if (config.flags) {
65926
- if (typeof config.flags.maxWorkers === 'number') {
65927
- config.maxConcurrentWorkers = config.flags.maxWorkers;
65928
- }
65929
- else if (config.flags.ci) {
65930
- config.maxConcurrentWorkers = 4;
65931
- }
66443
+ if (typeof config.flags.maxWorkers === 'number') {
66444
+ config.maxConcurrentWorkers = config.flags.maxWorkers;
66445
+ }
66446
+ else if (config.flags.ci) {
66447
+ config.maxConcurrentWorkers = 4;
65932
66448
  }
65933
66449
  config.maxConcurrentWorkers = Math.max(Math.min(config.maxConcurrentWorkers, 16), 0);
65934
66450
  if (config.devServer) {
@@ -65942,111 +66458,119 @@ const validateWorkers = (config) => {
65942
66458
  * `UnvalidatedConfig` to a `Config`.
65943
66459
  *
65944
66460
  * @param userConfig an unvalidated config that we've gotten from a user
66461
+ * @param bootstrapConfig the initial configuration provided by the user (or generated by Stencil) used to bootstrap
66462
+ * configuration loading and validation
65945
66463
  * @returns an object with config and diagnostics props
65946
66464
  */
65947
- const validateConfig = (userConfig = {}) => {
66465
+ const validateConfig = (userConfig = {}, bootstrapConfig) => {
65948
66466
  const config = Object.assign({}, userConfig || {}); // not positive it's json safe
65949
66467
  const diagnostics = [];
65950
- // copy flags (we know it'll be json safe)
65951
- config.flags = JSON.parse(JSON.stringify(config.flags || {}));
66468
+ const logger = bootstrapConfig.logger || config.logger || createLogger();
66469
+ const validatedConfig = {
66470
+ ...config,
66471
+ // flags _should_ be JSON safe
66472
+ flags: JSON.parse(JSON.stringify(config.flags || {})),
66473
+ logger,
66474
+ };
65952
66475
  // default devMode false
65953
- if (config.flags.prod) {
65954
- config.devMode = false;
65955
- }
65956
- else if (config.flags.dev) {
65957
- config.devMode = true;
65958
- }
65959
- else if (!isBoolean$1(config.devMode)) {
65960
- config.devMode = DEFAULT_DEV_MODE;
65961
- }
65962
- config.extras = config.extras || {};
65963
- config.extras.appendChildSlotFix = !!config.extras.appendChildSlotFix;
65964
- config.extras.cloneNodeFix = !!config.extras.cloneNodeFix;
65965
- config.extras.cssVarsShim = !!config.extras.cssVarsShim;
65966
- config.extras.dynamicImportShim = !!config.extras.dynamicImportShim;
65967
- config.extras.lifecycleDOMEvents = !!config.extras.lifecycleDOMEvents;
65968
- config.extras.safari10 = !!config.extras.safari10;
65969
- config.extras.scriptDataOpts = !!config.extras.scriptDataOpts;
65970
- config.extras.shadowDomShim = !!config.extras.shadowDomShim;
65971
- config.extras.slotChildNodesFix = !!config.extras.slotChildNodesFix;
65972
- config.extras.initializeNextTick = !!config.extras.initializeNextTick;
65973
- config.extras.tagNameTransform = !!config.extras.tagNameTransform;
65974
- config.buildEs5 = config.buildEs5 === true || (!config.devMode && config.buildEs5 === 'prod');
65975
- setBooleanConfig(config, 'minifyCss', null, !config.devMode);
65976
- setBooleanConfig(config, 'minifyJs', null, !config.devMode);
65977
- setBooleanConfig(config, 'sourceMap', null, typeof config.sourceMap === 'undefined' ? false : config.sourceMap);
65978
- setBooleanConfig(config, 'watch', 'watch', false);
65979
- setBooleanConfig(config, 'buildDocs', 'docs', !config.devMode);
65980
- setBooleanConfig(config, 'buildDist', 'esm', !config.devMode || config.buildEs5);
65981
- setBooleanConfig(config, 'profile', 'profile', config.devMode);
65982
- setBooleanConfig(config, 'writeLog', 'log', false);
65983
- setBooleanConfig(config, 'buildAppCore', null, true);
65984
- setBooleanConfig(config, 'autoprefixCss', null, config.buildEs5);
65985
- setBooleanConfig(config, 'validateTypes', null, !config._isTesting);
65986
- setBooleanConfig(config, 'allowInlineScripts', null, true);
65987
- if (!isString$1(config.taskQueue)) {
65988
- config.taskQueue = 'async';
66476
+ if (validatedConfig.flags.prod) {
66477
+ validatedConfig.devMode = false;
66478
+ }
66479
+ else if (validatedConfig.flags.dev) {
66480
+ validatedConfig.devMode = true;
66481
+ }
66482
+ else if (!isBoolean$1(validatedConfig.devMode)) {
66483
+ validatedConfig.devMode = DEFAULT_DEV_MODE;
66484
+ }
66485
+ validatedConfig.extras = validatedConfig.extras || {};
66486
+ validatedConfig.extras.appendChildSlotFix = !!validatedConfig.extras.appendChildSlotFix;
66487
+ validatedConfig.extras.cloneNodeFix = !!validatedConfig.extras.cloneNodeFix;
66488
+ validatedConfig.extras.cssVarsShim = !!validatedConfig.extras.cssVarsShim;
66489
+ validatedConfig.extras.dynamicImportShim = !!validatedConfig.extras.dynamicImportShim;
66490
+ validatedConfig.extras.lifecycleDOMEvents = !!validatedConfig.extras.lifecycleDOMEvents;
66491
+ validatedConfig.extras.safari10 = !!validatedConfig.extras.safari10;
66492
+ validatedConfig.extras.scriptDataOpts = !!validatedConfig.extras.scriptDataOpts;
66493
+ validatedConfig.extras.shadowDomShim = !!validatedConfig.extras.shadowDomShim;
66494
+ validatedConfig.extras.slotChildNodesFix = !!validatedConfig.extras.slotChildNodesFix;
66495
+ validatedConfig.extras.initializeNextTick = !!validatedConfig.extras.initializeNextTick;
66496
+ validatedConfig.extras.tagNameTransform = !!validatedConfig.extras.tagNameTransform;
66497
+ validatedConfig.buildEs5 =
66498
+ validatedConfig.buildEs5 === true || (!validatedConfig.devMode && validatedConfig.buildEs5 === 'prod');
66499
+ setBooleanConfig(validatedConfig, 'minifyCss', null, !validatedConfig.devMode);
66500
+ setBooleanConfig(validatedConfig, 'minifyJs', null, !validatedConfig.devMode);
66501
+ setBooleanConfig(validatedConfig, 'sourceMap', null, typeof validatedConfig.sourceMap === 'undefined' ? false : validatedConfig.sourceMap);
66502
+ setBooleanConfig(validatedConfig, 'watch', 'watch', false);
66503
+ setBooleanConfig(validatedConfig, 'buildDocs', 'docs', !validatedConfig.devMode);
66504
+ setBooleanConfig(validatedConfig, 'buildDist', 'esm', !validatedConfig.devMode || validatedConfig.buildEs5);
66505
+ setBooleanConfig(validatedConfig, 'profile', 'profile', validatedConfig.devMode);
66506
+ setBooleanConfig(validatedConfig, 'writeLog', 'log', false);
66507
+ setBooleanConfig(validatedConfig, 'buildAppCore', null, true);
66508
+ setBooleanConfig(validatedConfig, 'autoprefixCss', null, validatedConfig.buildEs5);
66509
+ setBooleanConfig(validatedConfig, 'validateTypes', null, !validatedConfig._isTesting);
66510
+ setBooleanConfig(validatedConfig, 'allowInlineScripts', null, true);
66511
+ if (!isString$1(validatedConfig.taskQueue)) {
66512
+ validatedConfig.taskQueue = 'async';
65989
66513
  }
65990
66514
  // hash file names
65991
- if (!isBoolean$1(config.hashFileNames)) {
65992
- config.hashFileNames = !config.devMode;
66515
+ if (!isBoolean$1(validatedConfig.hashFileNames)) {
66516
+ validatedConfig.hashFileNames = !validatedConfig.devMode;
65993
66517
  }
65994
- if (!isNumber$1(config.hashedFileNameLength)) {
65995
- config.hashedFileNameLength = DEFAULT_HASHED_FILENAME_LENTH;
66518
+ if (!isNumber$1(validatedConfig.hashedFileNameLength)) {
66519
+ validatedConfig.hashedFileNameLength = DEFAULT_HASHED_FILENAME_LENTH;
65996
66520
  }
65997
- if (config.hashedFileNameLength < MIN_HASHED_FILENAME_LENTH) {
66521
+ if (validatedConfig.hashedFileNameLength < MIN_HASHED_FILENAME_LENTH) {
65998
66522
  const err = buildError(diagnostics);
65999
- err.messageText = `config.hashedFileNameLength must be at least ${MIN_HASHED_FILENAME_LENTH} characters`;
66523
+ err.messageText = `validatedConfig.hashedFileNameLength must be at least ${MIN_HASHED_FILENAME_LENTH} characters`;
66000
66524
  }
66001
- if (config.hashedFileNameLength > MAX_HASHED_FILENAME_LENTH) {
66525
+ if (validatedConfig.hashedFileNameLength > MAX_HASHED_FILENAME_LENTH) {
66002
66526
  const err = buildError(diagnostics);
66003
- err.messageText = `config.hashedFileNameLength cannot be more than ${MAX_HASHED_FILENAME_LENTH} characters`;
66527
+ err.messageText = `validatedConfig.hashedFileNameLength cannot be more than ${MAX_HASHED_FILENAME_LENTH} characters`;
66004
66528
  }
66005
- if (!config.env) {
66006
- config.env = {};
66529
+ if (!validatedConfig.env) {
66530
+ validatedConfig.env = {};
66007
66531
  }
66008
66532
  // get a good namespace
66009
- validateNamespace(config, diagnostics);
66533
+ validateNamespace(validatedConfig, diagnostics);
66010
66534
  // figure out all of the config paths and absolute paths
66011
- validatePaths(config);
66535
+ validatePaths(validatedConfig);
66012
66536
  // outputTargets
66013
- validateOutputTargets(config, diagnostics);
66537
+ validateOutputTargets(validatedConfig, diagnostics);
66014
66538
  // plugins
66015
- validatePlugins(config, diagnostics);
66539
+ validatePlugins(validatedConfig, diagnostics);
66016
66540
  // rollup config
66017
- validateRollupConfig(config);
66541
+ validateRollupConfig(validatedConfig);
66018
66542
  // dev server
66019
- config.devServer = validateDevServer(config, diagnostics);
66543
+ validatedConfig.devServer = validateDevServer(validatedConfig, diagnostics);
66020
66544
  // testing
66021
- validateTesting(config, diagnostics);
66545
+ validateTesting(validatedConfig, diagnostics);
66022
66546
  // hydrate flag
66023
- config.hydratedFlag = validateHydrated(config);
66547
+ validatedConfig.hydratedFlag = validateHydrated(validatedConfig);
66024
66548
  // bundles
66025
- if (Array.isArray(config.bundles)) {
66026
- config.bundles = sortBy(config.bundles, (a) => a.components.length);
66549
+ if (Array.isArray(validatedConfig.bundles)) {
66550
+ validatedConfig.bundles = sortBy(validatedConfig.bundles, (a) => a.components.length);
66027
66551
  }
66028
66552
  else {
66029
- config.bundles = [];
66553
+ validatedConfig.bundles = [];
66030
66554
  }
66031
66555
  // validate how many workers we can use
66032
- validateWorkers(config);
66556
+ validateWorkers(validatedConfig);
66033
66557
  // default devInspector to whatever devMode is
66034
- setBooleanConfig(config, 'devInspector', null, config.devMode);
66035
- if (!config._isTesting) {
66036
- validateDistNamespace(config, diagnostics);
66558
+ setBooleanConfig(validatedConfig, 'devInspector', null, validatedConfig.devMode);
66559
+ if (!validatedConfig._isTesting) {
66560
+ validateDistNamespace(validatedConfig, diagnostics);
66037
66561
  }
66038
- setBooleanConfig(config, 'enableCache', 'cache', true);
66039
- if (!Array.isArray(config.watchIgnoredRegex) && config.watchIgnoredRegex != null) {
66040
- config.watchIgnoredRegex = [config.watchIgnoredRegex];
66562
+ setBooleanConfig(validatedConfig, 'enableCache', 'cache', true);
66563
+ if (!Array.isArray(validatedConfig.watchIgnoredRegex) && validatedConfig.watchIgnoredRegex != null) {
66564
+ validatedConfig.watchIgnoredRegex = [validatedConfig.watchIgnoredRegex];
66041
66565
  }
66042
- config.watchIgnoredRegex = (config.watchIgnoredRegex || []).reduce((arr, reg) => {
66566
+ validatedConfig.watchIgnoredRegex = (validatedConfig.watchIgnoredRegex || []).reduce((arr, reg) => {
66043
66567
  if (reg instanceof RegExp) {
66044
66568
  arr.push(reg);
66045
66569
  }
66046
66570
  return arr;
66047
66571
  }, []);
66048
66572
  return {
66049
- config,
66573
+ config: validatedConfig,
66050
66574
  diagnostics,
66051
66575
  };
66052
66576
  };
@@ -66197,6 +66721,21 @@ const createDefaultTsConfig = (config) => JSON.stringify({
66197
66721
  const hasSrcDirectoryInclude = (includeProp, src) => Array.isArray(includeProp) && includeProp.includes(src);
66198
66722
  const hasStencilConfigInclude = (includeProp) => Array.isArray(includeProp) && includeProp.includes('stencil.config.ts');
66199
66723
 
66724
+ /**
66725
+ * Load and validate a configuration to use throughout the lifetime of any Stencil task (build, test, etc.).
66726
+ *
66727
+ * Users can provide configurations multiple ways simultaneously:
66728
+ * - as an object of the `init` argument to this function
66729
+ * - through a path to a configuration file that exists on disk
66730
+ *
66731
+ * In the case of both being present, the two configurations will be merged. The fields of the former will take precedence
66732
+ * over the fields of the latter.
66733
+ *
66734
+ * @param init the initial configuration provided by the user (or generated by Stencil) used to bootstrap configuration
66735
+ * loading and validation
66736
+ * @returns the results of loading a configuration
66737
+ * @public
66738
+ */
66200
66739
  const loadConfig = async (init = {}) => {
66201
66740
  const results = {
66202
66741
  config: null,
@@ -66210,6 +66749,7 @@ const loadConfig = async (init = {}) => {
66210
66749
  extends: null,
66211
66750
  },
66212
66751
  };
66752
+ const unknownConfig = {};
66213
66753
  try {
66214
66754
  const sys = init.sys || createSystem();
66215
66755
  const config = init.config || {};
@@ -66218,22 +66758,21 @@ const loadConfig = async (init = {}) => {
66218
66758
  if (hasError(results.diagnostics)) {
66219
66759
  return results;
66220
66760
  }
66221
- if (loadedConfigFile != null) {
66761
+ if (loadedConfigFile !== null) {
66222
66762
  // merge the user's config object into their loaded config file
66223
66763
  configPath = loadedConfigFile.configPath;
66224
- results.config = { ...loadedConfigFile, ...config };
66225
- results.config.configPath = configPath;
66226
- results.config.rootDir = normalizePath$1(dirname(configPath));
66764
+ unknownConfig.config = { ...loadedConfigFile, ...config };
66765
+ unknownConfig.config.configPath = configPath;
66766
+ unknownConfig.config.rootDir = normalizePath$1(dirname(configPath));
66227
66767
  }
66228
66768
  else {
66229
66769
  // no stencil.config.ts or .js file, which is fine
66230
- // #0CJS ¯\_(ツ)_/¯
66231
- results.config = { ...config };
66232
- results.config.configPath = null;
66233
- results.config.rootDir = normalizePath$1(sys.getCurrentDirectory());
66770
+ unknownConfig.config = { ...config };
66771
+ unknownConfig.config.configPath = null;
66772
+ unknownConfig.config.rootDir = normalizePath$1(sys.getCurrentDirectory());
66234
66773
  }
66235
- results.config.sys = sys;
66236
- const validated = validateConfig(results.config);
66774
+ unknownConfig.config.sys = sys;
66775
+ const validated = validateConfig(unknownConfig.config, init);
66237
66776
  results.diagnostics.push(...validated.diagnostics);
66238
66777
  if (hasError(results.diagnostics)) {
66239
66778
  return results;
@@ -66248,7 +66787,6 @@ const loadConfig = async (init = {}) => {
66248
66787
  else if (typeof results.config.logLevel !== 'string') {
66249
66788
  results.config.logLevel = 'info';
66250
66789
  }
66251
- results.config.logger = init.logger || results.config.logger || createLogger();
66252
66790
  results.config.logger.setLevel(results.config.logLevel);
66253
66791
  if (!hasError(results.diagnostics)) {
66254
66792
  const tsConfigResults = await validateTsConfig(results.config, sys, init);
@@ -66268,6 +66806,15 @@ const loadConfig = async (init = {}) => {
66268
66806
  }
66269
66807
  return results;
66270
66808
  };
66809
+ /**
66810
+ * Load a Stencil configuration file from disk
66811
+ * @param sys the underlying System entity to use to interact with the operating system
66812
+ * @param diagnostics a series of diagnostics used to track errors & warnings throughout the loading process. Entries
66813
+ * may be added to this list in the event of an error.
66814
+ * @param configPath the path to the configuration file to load
66815
+ * @returns an unvalidated configuration. In the event of an error, additional diagnostics may be pushed to the
66816
+ * provided `diagnostics` argument and `null` will be returned.
66817
+ */
66271
66818
  const loadConfigFile = async (sys, diagnostics, configPath) => {
66272
66819
  let config = null;
66273
66820
  if (isString$1(configPath)) {
@@ -66287,6 +66834,15 @@ const loadConfigFile = async (sys, diagnostics, configPath) => {
66287
66834
  }
66288
66835
  return config;
66289
66836
  };
66837
+ /**
66838
+ * Load the configuration file, based on the environment that Stencil is being run in
66839
+ * @param sys the underlying System entity to use to interact with the operating system
66840
+ * @param diagnostics a series of diagnostics used to track errors & warnings throughout the loading process. Entries
66841
+ * may be added to this list in the event of an error.
66842
+ * @param configFilePath the path to the configuration file to load
66843
+ * @returns an unvalidated configuration. In the event of an error, additional diagnostics may be pushed to the
66844
+ * provided `diagnostics` argument and `null` will be returned.
66845
+ */
66290
66846
  const evaluateConfigFile = async (sys, diagnostics, configFilePath) => {
66291
66847
  let configFileData = null;
66292
66848
  try {
@@ -66311,6 +66867,16 @@ const evaluateConfigFile = async (sys, diagnostics, configFilePath) => {
66311
66867
  }
66312
66868
  return configFileData;
66313
66869
  };
66870
+ /**
66871
+ * Transpiles the provided TypeScript source text into JavaScript.
66872
+ *
66873
+ * This function is intended to be used on a `stencil.config.ts` file
66874
+ *
66875
+ * @param diagnostics a collection of compiler diagnostics to check as a part of the compilation process
66876
+ * @param sourceText the text to transpile
66877
+ * @param filePath the name of the file to transpile
66878
+ * @returns the transpiled text. If there are any diagnostics in the provided collection, the provided source is returned
66879
+ */
66314
66880
  const transpileTypedConfig = (diagnostics, sourceText, filePath) => {
66315
66881
  // let's transpile an awesome stencil.config.ts file into
66316
66882
  // a boring stencil.config.js file