@stencil/core 2.17.0 → 2.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/cli/config-flags.d.ts +110 -0
  2. package/cli/index.cjs +675 -253
  3. package/cli/index.d.ts +3 -2
  4. package/cli/index.js +675 -253
  5. package/cli/package.json +1 -1
  6. package/compiler/package.json +1 -1
  7. package/compiler/stencil.js +676 -226
  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 +14 -4
  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 +41 -3
  32. package/mock-doc/index.d.ts +15 -0
  33. package/mock-doc/index.js +41 -3
  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 +4 -4
  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 +71 -40
  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 +28 -2
  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.17.0 | MIT Licensed | https://stenciljs.com
2
+ Stencil Compiler v2.17.2 | 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;
@@ -883,24 +898,37 @@ const buildWarn = (diagnostics) => {
883
898
  diagnostics.push(diagnostic);
884
899
  return diagnostic;
885
900
  };
886
- const buildJsonFileError = (compilerCtx, diagnostics, jsonFilePath, msg, pkgKey) => {
901
+ /**
902
+ * Create a diagnostic message suited for representing an error in a JSON
903
+ * file. This includes information about the exact lines in the JSON file which
904
+ * caused the error and the path to the file.
905
+ *
906
+ * @param compilerCtx the current compiler context
907
+ * @param diagnostics a list of diagnostics used as a return param
908
+ * @param jsonFilePath the path to the JSON file where the error occurred
909
+ * @param msg the error message
910
+ * @param jsonField the key for the field which caused the error, used for finding
911
+ * the error line in the original JSON file
912
+ * @returns a reference to the newly-created diagnostic
913
+ */
914
+ const buildJsonFileError = (compilerCtx, diagnostics, jsonFilePath, msg, jsonField) => {
887
915
  const err = buildError(diagnostics);
888
916
  err.messageText = msg;
889
917
  err.absFilePath = jsonFilePath;
890
- if (typeof pkgKey === 'string') {
918
+ if (typeof jsonField === 'string') {
891
919
  try {
892
920
  const jsonStr = compilerCtx.fs.readFileSync(jsonFilePath);
893
921
  const lines = jsonStr.replace(/\r/g, '\n').split('\n');
894
922
  for (let i = 0; i < lines.length; i++) {
895
923
  const txtLine = lines[i];
896
- const txtIndex = txtLine.indexOf(pkgKey);
924
+ const txtIndex = txtLine.indexOf(jsonField);
897
925
  if (txtIndex > -1) {
898
926
  const warnLine = {
899
927
  lineIndex: i,
900
928
  lineNumber: i + 1,
901
929
  text: txtLine,
902
930
  errorCharStart: txtIndex,
903
- errorLength: pkgKey.length,
931
+ errorLength: jsonField.length,
904
932
  };
905
933
  err.lineNumber = warnLine.lineNumber;
906
934
  err.columnNumber = txtIndex + 1;
@@ -1631,7 +1659,7 @@ const isDtsFile$1 = (filePath) => {
1631
1659
  /**
1632
1660
  * Generate the preamble to be placed atop the main file of the build
1633
1661
  * @param config the Stencil configuration file
1634
- * @return the generated preamble
1662
+ * @returns the generated preamble
1635
1663
  */
1636
1664
  const generatePreamble = (config) => {
1637
1665
  const { preamble } = config;
@@ -2026,10 +2054,14 @@ const buildEvents = () => {
2026
2054
  };
2027
2055
  };
2028
2056
 
2057
+ /**
2058
+ * Creates an instance of a logger
2059
+ * @returns the new logger instance
2060
+ */
2029
2061
  const createLogger = () => {
2030
2062
  let useColors = IS_BROWSER_ENV;
2031
2063
  let level = 'info';
2032
- const logger = {
2064
+ return {
2033
2065
  enableColors: (uc) => (useColors = uc),
2034
2066
  getLevel: () => level,
2035
2067
  setLevel: (l) => (level = l),
@@ -2056,7 +2088,6 @@ const createLogger = () => {
2056
2088
  diagnostics.forEach((diagnostic) => logDiagnostic(diagnostic, useColors));
2057
2089
  },
2058
2090
  };
2059
- return logger;
2060
2091
  };
2061
2092
  const logDiagnostic = (diagnostic, useColors) => {
2062
2093
  let color = BLUE;
@@ -2346,8 +2377,16 @@ const getPackageDirPath = (p, moduleId) => {
2346
2377
  return null;
2347
2378
  };
2348
2379
 
2380
+ /**
2381
+ * A fetch wrapper which dispatches to `sys.fetch` if present, and otherwise
2382
+ * uses `global.fetch`.
2383
+ *
2384
+ * @param sys a compiler system object
2385
+ * @param input a `RequestInfo` object
2386
+ * @param init an optional `RequestInit` object
2387
+ * @returns a Promise wrapping a response
2388
+ */
2349
2389
  const httpFetch = (sys, input, init) => {
2350
- console.trace(input);
2351
2390
  if (sys && isFunction(sys.fetch)) {
2352
2391
  return sys.fetch(input, init);
2353
2392
  }
@@ -2355,10 +2394,16 @@ const httpFetch = (sys, input, init) => {
2355
2394
  };
2356
2395
  const packageVersions = new Map();
2357
2396
  const known404Urls = new Set();
2358
- const getStencilRootUrl = (compilerExe) => new URL('../', compilerExe).href;
2359
- const getStencilModuleUrl = (compilerExe, p) => {
2360
- p = normalizePath$1(p);
2361
- let parts = p.split('/');
2397
+ /**
2398
+ * Get the URL for a Stencil module given the path to the compiler
2399
+ *
2400
+ * @param compilerExe the path to the compiler executable
2401
+ * @param path the path to the module or file in question
2402
+ * @returns a URL for the file of interest
2403
+ */
2404
+ const getStencilModuleUrl = (compilerExe, path) => {
2405
+ path = normalizePath$1(path);
2406
+ let parts = path.split('/');
2362
2407
  const nmIndex = parts.lastIndexOf('node_modules');
2363
2408
  if (nmIndex > -1 && nmIndex < parts.length - 1) {
2364
2409
  parts = parts.slice(nmIndex + 1);
@@ -2368,9 +2413,10 @@ const getStencilModuleUrl = (compilerExe, p) => {
2368
2413
  else {
2369
2414
  parts = parts.slice(1);
2370
2415
  }
2371
- p = parts.join('/');
2416
+ path = parts.join('/');
2372
2417
  }
2373
- return new URL('./' + p, getStencilRootUrl(compilerExe)).href;
2418
+ const stencilRootUrl = new URL('../', compilerExe).href;
2419
+ return new URL('./' + path, stencilRootUrl).href;
2374
2420
  };
2375
2421
  const getCommonDirUrl = (sys, pkgVersions, dirPath, fileName) => getNodeModuleFetchUrl(sys, pkgVersions, dirPath) + '/' + fileName;
2376
2422
  const getNodeModuleFetchUrl = (sys, pkgVersions, filePath) => {
@@ -4019,7 +4065,7 @@ const createCustomResolverAsync = (sys, inMemoryFs, exts) => {
4019
4065
  };
4020
4066
  };
4021
4067
 
4022
- const buildId = '20220621172432';
4068
+ const buildId = '20220801155719';
4023
4069
  const minfyJsId = 'terser5.6.1_7';
4024
4070
  const optimizeCssId = 'autoprefixer10.2.5_postcss8.2.13_7';
4025
4071
  const parse5Version = '6.0.1';
@@ -4027,8 +4073,8 @@ const rollupVersion = '2.42.3';
4027
4073
  const sizzleVersion = '2.42.3';
4028
4074
  const terserVersion = '5.6.1';
4029
4075
  const typescriptVersion = '4.5.4';
4030
- const vermoji = '🚂';
4031
- const version$3 = '2.17.0';
4076
+ const vermoji = '🍤';
4077
+ const version$3 = '2.17.2';
4032
4078
  const versions = {
4033
4079
  stencil: version$3,
4034
4080
  parse5: parse5Version,
@@ -4577,6 +4623,17 @@ const createSystem = (c) => {
4577
4623
  };
4578
4624
 
4579
4625
  let cssProcessor;
4626
+ /**
4627
+ * Autoprefix a CSS string, adding vendor prefixes to make sure that what
4628
+ * is written in the CSS will render correctly in our range of supported browsers.
4629
+ * This function uses PostCSS in compbination with the Autoprefix plugin to
4630
+ * automatically add vendor prefixes based on a list of browsers which we want
4631
+ * to support.
4632
+ *
4633
+ * @param cssText the text to be prefixed
4634
+ * @param opts an optional param with options for Autoprefixer
4635
+ * @returns a Promise wrapping some prefixed CSS as well as diagnostics
4636
+ */
4580
4637
  const autoprefixCss = async (cssText, opts) => {
4581
4638
  const output = {
4582
4639
  output: cssText,
@@ -4586,7 +4643,7 @@ const autoprefixCss = async (cssText, opts) => {
4586
4643
  return output;
4587
4644
  }
4588
4645
  try {
4589
- const autoprefixerOpts = opts != null && typeof opts === 'object' ? opts : DEFAULT_AUTOPREFIX_LEGACY;
4646
+ const autoprefixerOpts = opts != null && typeof opts === 'object' ? opts : DEFAULT_AUTOPREFIX_OPTIONS;
4590
4647
  const processor = getProcessor(autoprefixerOpts);
4591
4648
  const result = await processor.process(cssText, { map: null });
4592
4649
  result.warnings().forEach((warning) => {
@@ -4642,6 +4699,12 @@ const autoprefixCss = async (cssText, opts) => {
4642
4699
  }
4643
4700
  return output;
4644
4701
  };
4702
+ /**
4703
+ * Get the processor for PostCSS and the Autoprefixer plugin
4704
+ *
4705
+ * @param autoprefixerOpts Options for Autoprefixer
4706
+ * @returns postCSS with the Autoprefixer plugin applied
4707
+ */
4645
4708
  const getProcessor = (autoprefixerOpts) => {
4646
4709
  const { postcss, autoprefixer } = requireFunc('../sys/node/autoprefixer.js');
4647
4710
  if (!cssProcessor) {
@@ -4649,7 +4712,19 @@ const getProcessor = (autoprefixerOpts) => {
4649
4712
  }
4650
4713
  return cssProcessor;
4651
4714
  };
4652
- const DEFAULT_AUTOPREFIX_LEGACY = {
4715
+ /**
4716
+ * Default options for the Autoprefixer PostCSS plugin. See the documentation:
4717
+ * https://github.com/postcss/autoprefixer#options for a complete list.
4718
+ *
4719
+ * This default option set will:
4720
+ *
4721
+ * - override the default browser list (`overrideBrowserslist`)
4722
+ * - turn off the visual cascade (`cascade`)
4723
+ * - disable auto-removing outdated prefixes (`remove`)
4724
+ * - set `flexbox` to `"no-2009"`, which limits prefixing for flexbox to the
4725
+ * final and IE 10 versions of the specification
4726
+ */
4727
+ const DEFAULT_AUTOPREFIX_OPTIONS = {
4653
4728
  overrideBrowserslist: ['last 2 versions', 'iOS >= 9', 'Android >= 4.4', 'Explorer >= 11', 'ExplorerMobile >= 11'],
4654
4729
  cascade: false,
4655
4730
  remove: false,
@@ -5445,6 +5520,13 @@ const resolveStylesheetUrl = async (nodes, resolveUrl, resolved) => {
5445
5520
  }
5446
5521
  };
5447
5522
 
5523
+ /**
5524
+ * Optimize a CSS file, optionally running an autoprefixer and a minifier
5525
+ * depending on the options set on the input options argument.
5526
+ *
5527
+ * @param inputOpts input CSS options
5528
+ * @returns a promise wrapping the optimized output
5529
+ */
5448
5530
  const optimizeCss$1 = async (inputOpts) => {
5449
5531
  let result = {
5450
5532
  output: inputOpts.input,
@@ -11508,6 +11590,12 @@ const parseImportPath = (importPath) => {
11508
11590
  return parsedPath;
11509
11591
  };
11510
11592
 
11593
+ /**
11594
+ * Strip out comments from some CSS
11595
+ *
11596
+ * @param input the string we'd like to de-comment
11597
+ * @returns de-commented CSS!
11598
+ */
11511
11599
  const stripCssComments = (input) => {
11512
11600
  let isInsideString = null;
11513
11601
  let currentCharacter = '';
@@ -14864,6 +14952,25 @@ class MockMouseEvent extends MockEvent {
14864
14952
  }
14865
14953
  }
14866
14954
  }
14955
+ class MockUIEvent extends MockEvent {
14956
+ constructor(type, uiEventInitDic) {
14957
+ super(type);
14958
+ this.detail = null;
14959
+ this.view = null;
14960
+ if (uiEventInitDic != null) {
14961
+ Object.assign(this, uiEventInitDic);
14962
+ }
14963
+ }
14964
+ }
14965
+ class MockFocusEvent extends MockUIEvent {
14966
+ constructor(type, focusEventInitDic) {
14967
+ super(type);
14968
+ this.relatedTarget = null;
14969
+ if (focusEventInitDic != null) {
14970
+ Object.assign(this, focusEventInitDic);
14971
+ }
14972
+ }
14973
+ }
14867
14974
  class MockEventListener {
14868
14975
  constructor(type, handler) {
14869
14976
  this.type = type;
@@ -15777,7 +15884,7 @@ class MockElement extends MockNode {
15777
15884
  return shadowRoot;
15778
15885
  }
15779
15886
  blur() {
15780
- /**/
15887
+ dispatchEvent(this, new MockFocusEvent('blur', { relatedTarget: null, bubbles: true, cancelable: true, composed: true }));
15781
15888
  }
15782
15889
  get shadowRoot() {
15783
15890
  return this.__shadowRoot || null;
@@ -15847,7 +15954,9 @@ class MockElement extends MockNode {
15847
15954
  get firstElementChild() {
15848
15955
  return this.children[0] || null;
15849
15956
  }
15850
- focus(_options) { }
15957
+ focus(_options) {
15958
+ dispatchEvent(this, new MockFocusEvent('focus', { relatedTarget: null, bubbles: true, cancelable: true, composed: true }));
15959
+ }
15851
15960
  getAttribute(attrName) {
15852
15961
  if (attrName === 'style') {
15853
15962
  if (this.__style != null && this.__style.length > 0) {
@@ -16192,6 +16301,9 @@ class MockElement extends MockNode {
16192
16301
  set title(value) {
16193
16302
  this.setAttributeNS(null, 'title', value);
16194
16303
  }
16304
+ animate() {
16305
+ /**/
16306
+ }
16195
16307
  onanimationstart() {
16196
16308
  /**/
16197
16309
  }
@@ -16456,6 +16568,18 @@ class MockElement extends MockNode {
16456
16568
  onwheel() {
16457
16569
  /**/
16458
16570
  }
16571
+ requestFullscreen() {
16572
+ /**/
16573
+ }
16574
+ scrollBy() {
16575
+ /**/
16576
+ }
16577
+ scrollTo() {
16578
+ /**/
16579
+ }
16580
+ scrollIntoView() {
16581
+ /**/
16582
+ }
16459
16583
  toString(opts) {
16460
16584
  return serializeNodeToHtml(this, opts);
16461
16585
  }
@@ -17497,6 +17621,7 @@ const GLOBAL_CONSTRUCTORS = [
17497
17621
  ['CustomEvent', MockCustomEvent],
17498
17622
  ['Event', MockEvent],
17499
17623
  ['Headers', MockHeaders],
17624
+ ['FocusEvent', MockFocusEvent],
17500
17625
  ['KeyboardEvent', MockKeyboardEvent],
17501
17626
  ['MouseEvent', MockMouseEvent],
17502
17627
  ['Request', MockRequest],
@@ -18828,48 +18953,88 @@ const emptyOutputTargets = async (config, compilerCtx, buildCtx) => {
18828
18953
  timeSpan.finish('cleaning dirs finished');
18829
18954
  };
18830
18955
 
18956
+ /**
18957
+ * Parse CSS imports into an object which contains a manifest of imports and a
18958
+ * stylesheet with all imports resolved and concatenated.
18959
+ *
18960
+ * @param config the current config
18961
+ * @param compilerCtx the compiler context (we need filesystem access)
18962
+ * @param buildCtx the build context, we'll need access to diagnostics
18963
+ * @param srcFilePath the source filepath
18964
+ * @param resolvedFilePath the resolved filepath
18965
+ * @param styleText style text we start with
18966
+ * @param styleDocs optional array of style document objects
18967
+ * @returns an object with concatenated styleText and imports
18968
+ */
18831
18969
  const parseCssImports = async (config, compilerCtx, buildCtx, srcFilePath, resolvedFilePath, styleText, styleDocs) => {
18832
18970
  const isCssEntry = resolvedFilePath.toLowerCase().endsWith('.css');
18833
18971
  const allCssImports = [];
18834
- const concatStyleText = await updateCssImports(config, compilerCtx, buildCtx, isCssEntry, srcFilePath, resolvedFilePath, styleText, allCssImports, new Set(), styleDocs);
18972
+ // a Set of previously-resolved file paths that we add to as we traverse the
18973
+ // import tree (to avoid a possible circular dependency and infinite loop)
18974
+ const resolvedFilePaths = new Set();
18975
+ const concatStyleText = await resolveAndFlattenImports(srcFilePath, resolvedFilePath, styleText);
18835
18976
  return {
18836
18977
  imports: allCssImports,
18837
18978
  styleText: concatStyleText,
18838
18979
  };
18839
- };
18840
- const updateCssImports = async (config, compilerCtx, buildCtx, isCssEntry, srcFilePath, resolvedFilePath, styleText, allCssImports, noLoop, styleDocs) => {
18841
- if (noLoop.has(resolvedFilePath)) {
18842
- return styleText;
18843
- }
18844
- noLoop.add(resolvedFilePath);
18845
- if (styleDocs != null) {
18846
- parseStyleDocs(styleDocs, styleText);
18847
- }
18848
- const cssImports = await getCssImports(config, compilerCtx, buildCtx, resolvedFilePath, styleText);
18849
- if (cssImports.length === 0) {
18850
- return styleText;
18851
- }
18852
- for (const cssImport of cssImports) {
18853
- if (!allCssImports.includes(cssImport.filePath)) {
18854
- allCssImports.push(cssImport.filePath);
18980
+ /**
18981
+ * Resolve and flatten all imports for a given CSS file, recursively crawling
18982
+ * the tree of imports to resolve them all and produce a concatenated
18983
+ * stylesheet. We declare this function here, within `parseCssImports`, in order
18984
+ * to get access to `compilerCtx`, `buildCtx`, and more without having to pass
18985
+ * a whole bunch of arguments.
18986
+ *
18987
+ * @param srcFilePath the source filepath
18988
+ * @param resolvedFilePath the resolved filepath
18989
+ * @param styleText style text we start with*
18990
+ * @returns concatenated styles assembled from the various imported stylesheets
18991
+ */
18992
+ async function resolveAndFlattenImports(srcFilePath, resolvedFilePath, styleText) {
18993
+ // if we've seen this path before we early return
18994
+ if (resolvedFilePaths.has(resolvedFilePath)) {
18995
+ return styleText;
18855
18996
  }
18856
- }
18857
- await Promise.all(cssImports.map(async (cssImportData) => {
18858
- await concatCssImport(config, compilerCtx, buildCtx, isCssEntry, srcFilePath, cssImportData, allCssImports, noLoop, styleDocs);
18859
- }));
18860
- return replaceImportDeclarations(styleText, cssImports, isCssEntry);
18861
- };
18862
- const concatCssImport = async (config, compilerCtx, buildCtx, isCssEntry, srcFilePath, cssImportData, allCssImports, noLoop, styleDocs) => {
18863
- cssImportData.styleText = await loadStyleText(compilerCtx, cssImportData);
18864
- if (typeof cssImportData.styleText === 'string') {
18865
- cssImportData.styleText = await updateCssImports(config, compilerCtx, buildCtx, isCssEntry, cssImportData.filePath, cssImportData.filePath, cssImportData.styleText, allCssImports, noLoop, styleDocs);
18866
- }
18867
- else {
18868
- const err = buildError(buildCtx.diagnostics);
18869
- err.messageText = `Unable to read css import: ${cssImportData.srcImport}`;
18870
- err.absFilePath = srcFilePath;
18997
+ resolvedFilePaths.add(resolvedFilePath);
18998
+ if (styleDocs != null) {
18999
+ parseStyleDocs(styleDocs, styleText);
19000
+ }
19001
+ const cssImports = await getCssImports(config, compilerCtx, buildCtx, resolvedFilePath, styleText);
19002
+ if (cssImports.length === 0) {
19003
+ return styleText;
19004
+ }
19005
+ // add any newly-found imports to the 'global' list
19006
+ for (const cssImport of cssImports) {
19007
+ if (!allCssImports.includes(cssImport.filePath)) {
19008
+ allCssImports.push(cssImport.filePath);
19009
+ }
19010
+ }
19011
+ // Recur down the tree of CSS imports, resolving all the imports in
19012
+ // the children of the current file (and, by extension, in their children
19013
+ // and so on)
19014
+ await Promise.all(cssImports.map(async (cssImportData) => {
19015
+ cssImportData.styleText = await loadStyleText(compilerCtx, cssImportData);
19016
+ if (typeof cssImportData.styleText === 'string') {
19017
+ cssImportData.styleText = await resolveAndFlattenImports(cssImportData.filePath, cssImportData.filePath, cssImportData.styleText);
19018
+ }
19019
+ else {
19020
+ // we had some error loading the file from disk, so write a diagnostic
19021
+ const err = buildError(buildCtx.diagnostics);
19022
+ err.messageText = `Unable to read css import: ${cssImportData.srcImport}`;
19023
+ err.absFilePath = srcFilePath;
19024
+ }
19025
+ }));
19026
+ // replace import statements with the actual CSS code in children modules
19027
+ return replaceImportDeclarations(styleText, cssImports, isCssEntry);
18871
19028
  }
18872
19029
  };
19030
+ /**
19031
+ * Load the style text for a CSS file from disk, based on the filepaths set in
19032
+ * our import data.
19033
+ *
19034
+ * @param compilerCtx the compiler context
19035
+ * @param cssImportData the import data for the file we want to read
19036
+ * @returns the contents of the file, if it can be read without error
19037
+ */
18873
19038
  const loadStyleText = async (compilerCtx, cssImportData) => {
18874
19039
  let styleText = null;
18875
19040
  try {
@@ -18885,7 +19050,18 @@ const loadStyleText = async (compilerCtx, cssImportData) => {
18885
19050
  }
18886
19051
  return styleText;
18887
19052
  };
19053
+ /**
19054
+ * Get a manifest of all the CSS imports in a given CSS file
19055
+ *
19056
+ * @param config the current config
19057
+ * @param compilerCtx the compiler context (we need the filesystem)
19058
+ * @param buildCtx the build context, in case we need to set a diagnostic
19059
+ * @param filePath the filepath we're working with
19060
+ * @param styleText the CSS for which we want to retrieve import data
19061
+ * @returns a Promise wrapping a list of CSS import data objects
19062
+ */
18888
19063
  const getCssImports = async (config, compilerCtx, buildCtx, filePath, styleText) => {
19064
+ var _a;
18889
19065
  const imports = [];
18890
19066
  if (!styleText.includes('@import')) {
18891
19067
  // no @import at all, so don't bother
@@ -18893,13 +19069,14 @@ const getCssImports = async (config, compilerCtx, buildCtx, filePath, styleText)
18893
19069
  }
18894
19070
  styleText = stripCssComments(styleText);
18895
19071
  const dir = dirname(filePath);
18896
- const importeeExt = filePath.split('.').pop().toLowerCase();
19072
+ const importeeExt = ((_a = filePath.split('.').pop()) !== null && _a !== void 0 ? _a : '').toLowerCase();
18897
19073
  let r;
18898
19074
  const IMPORT_RE = /(@import)\s+(url\()?\s?(.*?)\s?\)?([^;]*);?/gi;
18899
19075
  while ((r = IMPORT_RE.exec(styleText))) {
18900
19076
  const cssImportData = {
18901
19077
  srcImport: r[0],
18902
19078
  url: r[4].replace(/[\"\'\)]/g, ''),
19079
+ filePath: '',
18903
19080
  };
18904
19081
  if (!isLocalCssImport(cssImportData.srcImport)) {
18905
19082
  // do nothing for @import url(http://external.css)
@@ -18926,7 +19103,10 @@ const getCssImports = async (config, compilerCtx, buildCtx, filePath, styleText)
18926
19103
  cssImportData.altFilePath = normalizePath$1(join(dirPath, fileName));
18927
19104
  }
18928
19105
  }
18929
- if (typeof cssImportData.filePath === 'string') {
19106
+ // we set `filePath` to `""` when the object is created above, so if it
19107
+ // hasn't been changed in the intervening conditionals then we didn't resolve
19108
+ // a filepath for it.
19109
+ if (cssImportData.filePath !== '') {
18930
19110
  imports.push(cssImportData);
18931
19111
  }
18932
19112
  }
@@ -18968,6 +19148,16 @@ const isLocalCssImport = (srcImport) => {
18968
19148
  }
18969
19149
  return true;
18970
19150
  };
19151
+ /**
19152
+ * Replace import declarations (like '@import "foobar";') with the actual CSS
19153
+ * written in the imported module, allowing us to produce a single file from a
19154
+ * tree of stylesheets.
19155
+ *
19156
+ * @param styleText the text within which we want to replace @import statements
19157
+ * @param cssImports information about imported modules
19158
+ * @param isCssEntry whether we're dealing with a CSS file
19159
+ * @returns an updated string with the requisite substitutions
19160
+ */
18971
19161
  const replaceImportDeclarations = (styleText, cssImports, isCssEntry) => {
18972
19162
  for (const cssImport of cssImports) {
18973
19163
  if (isCssEntry) {
@@ -41777,7 +41967,7 @@ const createCustomResolverSync = (sys, inMemoryFs, exts) => {
41777
41967
  * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d121716ed123957f6a86f8985eb013fcaddab345/types/node/globals.d.ts#L183-L188
41778
41968
  * in mind.
41779
41969
  * @param err the entity to check the type of
41780
- * @return true if the provided value is an instance of `ErrnoException`, `false` otherwise
41970
+ * @returns true if the provided value is an instance of `ErrnoException`, `false` otherwise
41781
41971
  */
41782
41972
  function isErrnoException(err) {
41783
41973
  return err instanceof Error && err.hasOwnProperty('code');
@@ -54447,6 +54637,23 @@ const isMemberPrivate = (member) => {
54447
54637
  }
54448
54638
  return false;
54449
54639
  };
54640
+ /**
54641
+ * Convert a JavaScript value to the TypeScript Intermediate Representation
54642
+ * (IR) for a literal Abstract Syntax Tree (AST) node with that same value. The
54643
+ * value to convert may be a primitive type like `string`, `boolean`, etc or
54644
+ * may be an `Object`, `Array`, etc.
54645
+ *
54646
+ * Note that this function takes a param (`refs`) with a default value,
54647
+ * normally a value should _not_ be passed for this parameter since it is
54648
+ * intended to be used for recursive calls.
54649
+ *
54650
+ * @param val the value to convert
54651
+ * @param refs a set of references, used in recursive calls to avoid
54652
+ * circular references when creating object literal IR instances. **note that
54653
+ * you shouldn't pass this parameter unless you know what you're doing!**
54654
+ * @returns TypeScript IR for a literal corresponding to the JavaScript value
54655
+ * with which the function was called
54656
+ */
54450
54657
  const convertValueToLiteral = (val, refs = null) => {
54451
54658
  if (refs == null) {
54452
54659
  refs = new WeakSet();
@@ -54477,12 +54684,39 @@ const convertValueToLiteral = (val, refs = null) => {
54477
54684
  }
54478
54685
  return t.createLiteral(val);
54479
54686
  };
54687
+ /**
54688
+ * Convert a JavaScript Array instance to TypeScript's Intermediate
54689
+ * Representation (IR) for an array literal. This is done by recursively using
54690
+ * {@link convertValueToLiteral} to create a new array consisting of the
54691
+ * TypeScript IR of each element in the array to be converted, and then creating
54692
+ * the TypeScript IR for _that_ array.
54693
+ *
54694
+ * @param list the array instance to convert
54695
+ * @param refs a set of references to objects, used when converting objects to
54696
+ * avoid circular references
54697
+ * @returns TypeScript IR for the array we want to convert
54698
+ */
54480
54699
  const arrayToArrayLiteral = (list, refs) => {
54481
54700
  const newList = list.map((l) => {
54482
54701
  return convertValueToLiteral(l, refs);
54483
54702
  });
54484
54703
  return t.createArrayLiteral(newList);
54485
54704
  };
54705
+ /**
54706
+ * Convert a JavaScript object (i.e. an object existing at runtime) to the
54707
+ * corresponding TypeScript Intermediate Representation (IR)
54708
+ * ({@see ts.ObjectLiteralExpression}) for an object literal. This function
54709
+ * takes an argument holding a `WeakSet` of references to objects which is
54710
+ * used to avoid circular references. Objects that are converted in this
54711
+ * function are added to the set, and if an object is already present then an
54712
+ * `undefined` literal (in TypeScript IR) is returned instead of another
54713
+ * object literal, as continuing to convert a circular reference would, well,
54714
+ * never end!
54715
+ *
54716
+ * @param obj the JavaScript object to convert to TypeScript IR
54717
+ * @param refs a set of references to objects, used to avoid circular references
54718
+ * @returns a TypeScript object literal expression
54719
+ */
54486
54720
  const objectToObjectLiteral = (obj, refs) => {
54487
54721
  if (refs.has(obj)) {
54488
54722
  return t.createIdentifier('undefined');
@@ -55850,17 +56084,16 @@ const KEEP_IMPORTS = new Set([
55850
56084
  * which do actual work of generating the rollup configuration, creating an
55851
56085
  * entry chunk, running, the build, etc.
55852
56086
  *
55853
- * @param config the user-supplied compiler configuration we're using
56087
+ * @param config the validated compiler configuration we're using
55854
56088
  * @param compilerCtx the current compiler context
55855
56089
  * @param buildCtx the current build context
55856
56090
  * @returns an empty Promise which won't resolve until the work is done!
55857
56091
  */
55858
56092
  const outputCustomElements = async (config, compilerCtx, buildCtx) => {
55859
- var _a;
55860
56093
  if (!config.buildDist) {
55861
56094
  return;
55862
56095
  }
55863
- const outputTargets = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).filter(isOutputTargetDistCustomElements);
56096
+ const outputTargets = config.outputTargets.filter(isOutputTargetDistCustomElements);
55864
56097
  if (outputTargets.length === 0) {
55865
56098
  return;
55866
56099
  }
@@ -55873,7 +56106,7 @@ const outputCustomElements = async (config, compilerCtx, buildCtx) => {
55873
56106
  * Get bundle options for our current build and compiler context which we'll use
55874
56107
  * to generate a Rollup build and so on.
55875
56108
  *
55876
- * @param config user-supplied Stencil configuration
56109
+ * @param config a validated Stencil configuration object
55877
56110
  * @param buildCtx the current build context
55878
56111
  * @param compilerCtx the current compiler context
55879
56112
  * @param outputTarget the outputTarget we're currently dealing with
@@ -55904,9 +56137,10 @@ const getBundleOptions = (config, buildCtx, compilerCtx, outputTarget) => ({
55904
56137
  /**
55905
56138
  * Get bundle options for rollup, run the rollup build, optionally minify the
55906
56139
  * output, and write files to disk.
55907
- * @param config user-supplied Stencil configuration
55908
- * @param buildCtx the current build context
56140
+ *
56141
+ * @param config the validated Stencil configuration we're using
55909
56142
  * @param compilerCtx the current compiler context
56143
+ * @param buildCtx the current build context
55910
56144
  * @param outputTarget the outputTarget we're currently dealing with
55911
56145
  * @returns an empty promise
55912
56146
  */
@@ -55995,7 +56229,7 @@ const addCustomElementInputs = (buildCtx, bundleOpts) => {
55995
56229
  exp.push(`import { ${importName} as ${importAs}, defineCustomElement as cmpDefCustomEle } from '${cmp.sourceFilePath}';`);
55996
56230
  exp.push(`export const ${exportName} = ${importAs};`);
55997
56231
  exp.push(`export const defineCustomElement = cmpDefCustomEle;`);
55998
- // Here we push an export (with a rename for `defineCustomElement` for
56232
+ // Here we push an export (with a rename for `defineCustomElement`) for
55999
56233
  // this component onto our array which references the `coreKey` (prefixed
56000
56234
  // with `\0`). We have to do this so that our import is referencing the
56001
56235
  // correct virtual module, if we instead referenced, for instance,
@@ -57816,6 +58050,16 @@ const lazyComponentTransform = (compilerCtx, transformOpts) => {
57816
58050
  };
57817
58051
  };
57818
58052
 
58053
+ /**
58054
+ * Generate rollup output based on a rollup build and a series of options.
58055
+ *
58056
+ * @param build a rollup build
58057
+ * @param options output options for rollup
58058
+ * @param config a user-supplied configuration object
58059
+ * @param entryModules a list of entry modules, for checking which chunks
58060
+ * contain components
58061
+ * @returns a Promise wrapping either build results or `null`
58062
+ */
57819
58063
  const generateRollupOutput = async (build, options, config, entryModules) => {
57820
58064
  if (build == null) {
57821
58065
  return null;
@@ -57823,7 +58067,7 @@ const generateRollupOutput = async (build, options, config, entryModules) => {
57823
58067
  const { output } = await build.generate(options);
57824
58068
  return output.map((chunk) => {
57825
58069
  if (chunk.type === 'chunk') {
57826
- const isCore = Object.keys(chunk.modules).some((m) => m.includes('@stencil/core'));
58070
+ const isCore = Object.keys(chunk.modules).some((m) => m.includes(STENCIL_CORE_ID));
57827
58071
  return {
57828
58072
  type: 'chunk',
57829
58073
  fileName: chunk.fileName,
@@ -58322,7 +58566,8 @@ const getSystemLoader = async (config, compilerCtx, corePath, includePolyfills)
58322
58566
 
58323
58567
  var resourcesUrl = scriptElm ? scriptElm.getAttribute('data-resources-url') || scriptElm.src : '';
58324
58568
  var start = function() {
58325
- var url = new URL('${corePath}', new URL(resourcesUrl, window.location.origin));
58569
+ // if src is not present then origin is "null", and new URL() throws TypeError: Failed to construct 'URL': Invalid base URL
58570
+ var url = new URL('${corePath}', new URL(resourcesUrl, window.location.origin !== 'null' ? window.location.origin : undefined));
58326
58571
  System.import(url.href);
58327
58572
  };
58328
58573
 
@@ -60019,8 +60264,7 @@ const relDts$1 = (fromPath, dtsPath) => {
60019
60264
  * @param typesDir the path to the directory where type declarations are saved
60020
60265
  */
60021
60266
  const generateCustomElementsTypes = async (config, compilerCtx, buildCtx, typesDir) => {
60022
- var _a;
60023
- const outputTargets = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).filter(isOutputTargetDistCustomElements);
60267
+ const outputTargets = config.outputTargets.filter(isOutputTargetDistCustomElements);
60024
60268
  await Promise.all(outputTargets.map((outputTarget) => generateCustomElementsTypesOutput(config, compilerCtx, buildCtx, typesDir, outputTarget)));
60025
60269
  };
60026
60270
  /**
@@ -60036,7 +60280,7 @@ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx,
60036
60280
  // the path where we're going to write the typedef for the whole dist-custom-elements output
60037
60281
  const customElementsDtsPath = join(outputTarget.dir, 'index.d.ts');
60038
60282
  // the directory where types for the individual components are written
60039
- const componentsTypeDirectoryPath = relative$1(outputTarget.dir, join(typesDir, 'components'));
60283
+ const componentsTypeDirectoryRelPath = relative$1(outputTarget.dir, typesDir);
60040
60284
  const components = buildCtx.components.filter((m) => !m.isCollectionDependency);
60041
60285
  const code = [
60042
60286
  `/* ${config.namespace} custom elements */`,
@@ -60045,7 +60289,14 @@ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx,
60045
60289
  const importName = component.componentClassName;
60046
60290
  // typedefs for individual components can be found under paths like
60047
60291
  // $TYPES_DIR/components/my-component/my-component.d.ts
60048
- const componentDTSPath = join(componentsTypeDirectoryPath, component.tagName, component.tagName);
60292
+ //
60293
+ // To construct this path we:
60294
+ //
60295
+ // - get the relative path to the component's source file from the source directory
60296
+ // - join that relative path to the relative path from the `index.d.ts` file to the
60297
+ // directory where typedefs are saved
60298
+ const componentSourceRelPath = relative$1(config.srcDir, component.sourceFilePath).replace('.tsx', '');
60299
+ const componentDTSPath = join(componentsTypeDirectoryRelPath, componentSourceRelPath);
60049
60300
  return `export { ${importName} as ${exportName} } from '${componentDTSPath}';`;
60050
60301
  }),
60051
60302
  ``,
@@ -61948,6 +62199,16 @@ const parseModuleImport = (config, compilerCtx, buildCtx, moduleFile, dirPath, i
61948
62199
  }
61949
62200
  };
61950
62201
 
62202
+ /**
62203
+ * Update an instance of TypeScript's Intermediate Representation (IR) for a
62204
+ * class declaration ({@link ts.ClassDeclaration}) with a static getter for the
62205
+ * compiler metadata that we produce as part of the compilation process.
62206
+ *
62207
+ * @param cmpNode an instance of the TypeScript IR for a class declaration (i.e.
62208
+ * a stencil component) to be updated
62209
+ * @param cmpMeta the component metadata corresponding to that component
62210
+ * @returns the updated typescript class declaration
62211
+ */
61951
62212
  const addComponentMetaStatic = (cmpNode, cmpMeta) => {
61952
62213
  const publicCompilerMeta = getPublicCompilerMeta(cmpMeta);
61953
62214
  const cmpMetaStaticProp = createStaticGetter('COMPILER_META', convertValueToLiteral(publicCompilerMeta));
@@ -62079,6 +62340,14 @@ const parseStaticEvents = (staticMembers) => {
62079
62340
  });
62080
62341
  };
62081
62342
 
62343
+ /**
62344
+ * Parse a list of {@link ts.ClassElement} objects representing static props
62345
+ * into a list of our own Intermediate Representation (IR) of properties on
62346
+ * components.
62347
+ *
62348
+ * @param staticMembers TypeScript IR for the properties on our component
62349
+ * @returns a manifest of compiler properties in our own Stencil IR
62350
+ */
62082
62351
  const parseStaticProps = (staticMembers) => {
62083
62352
  const parsedProps = getStaticValue(staticMembers, 'properties');
62084
62353
  if (!parsedProps) {
@@ -62315,7 +62584,22 @@ const setComponentBuildConditionals = (cmpMeta) => {
62315
62584
  !cmpMeta.hasMember && !cmpMeta.hasStyle && !cmpMeta.hasLifecycle && !cmpMeta.hasListener && !cmpMeta.hasVdomRender;
62316
62585
  };
62317
62586
 
62318
- const parseStaticComponentMeta = (compilerCtx, typeChecker, cmpNode, moduleFile, nodeMap, transformOpts) => {
62587
+ /**
62588
+ * Given an instance of TypeScript's Intermediate Representation (IR) for a
62589
+ * class declaration ({@see ts.ClassDeclaration}) which represents a Stencil
62590
+ * component class declaration, parse and format various pieces of data about
62591
+ * static class members which we use in the compilation process
62592
+ *
62593
+ * @param compilerCtx the current compiler context
62594
+ * @param typeChecker a TypeScript type checker instance
62595
+ * @param cmpNode the TypeScript class declaration for the component
62596
+ * @param moduleFile Stencil's IR for a module, used here as an out param
62597
+ * @param transformOpts options which control various aspects of the
62598
+ * transformation
62599
+ * @returns the TypeScript class declaration IR instance with which the
62600
+ * function was called
62601
+ */
62602
+ const parseStaticComponentMeta = (compilerCtx, typeChecker, cmpNode, moduleFile, transformOpts) => {
62319
62603
  if (cmpNode.members == null) {
62320
62604
  return cmpNode;
62321
62605
  }
@@ -62432,7 +62716,7 @@ const parseStaticComponentMeta = (compilerCtx, typeChecker, cmpNode, moduleFile,
62432
62716
  // add to module map
62433
62717
  moduleFile.cmps.push(cmp);
62434
62718
  // add to node map
62435
- nodeMap.set(cmpNode, cmp);
62719
+ compilerCtx.nodeMap.set(cmpNode, cmp);
62436
62720
  return cmpNode;
62437
62721
  };
62438
62722
  const parseVirtualProps = (docs) => {
@@ -62500,7 +62784,7 @@ const updateModule = (config, compilerCtx, buildCtx, tsSourceFile, sourceFileTex
62500
62784
  compilerCtx.changedModules.add(moduleFile.sourceFilePath);
62501
62785
  const visitNode = (node) => {
62502
62786
  if (t.isClassDeclaration(node)) {
62503
- parseStaticComponentMeta(compilerCtx, typeChecker, node, moduleFile, compilerCtx.nodeMap);
62787
+ parseStaticComponentMeta(compilerCtx, typeChecker, node, moduleFile);
62504
62788
  return;
62505
62789
  }
62506
62790
  else if (t.isImportDeclaration(node)) {
@@ -62661,6 +62945,15 @@ const outputServiceWorkers = async (config, buildCtx) => {
62661
62945
  }
62662
62946
  };
62663
62947
 
62948
+ /**
62949
+ * Validate the package.json file for a project, checking that various fields
62950
+ * are set correctly for the currently-configured output targets.
62951
+ *
62952
+ * @param config the user-supplied Stencil config
62953
+ * @param compilerCtx the compiler context
62954
+ * @param buildCtx the build context
62955
+ * @returns an empty Promise
62956
+ */
62664
62957
  const validateBuildPackageJson = async (config, compilerCtx, buildCtx) => {
62665
62958
  if (config.watch) {
62666
62959
  return;
@@ -62668,26 +62961,41 @@ const validateBuildPackageJson = async (config, compilerCtx, buildCtx) => {
62668
62961
  if (buildCtx.packageJson == null) {
62669
62962
  return;
62670
62963
  }
62671
- const outputTargets = config.outputTargets.filter(isOutputTargetDistCollection);
62964
+ const distCollectionOutputTargets = config.outputTargets.filter(isOutputTargetDistCollection);
62672
62965
  const typesOutputTargets = config.outputTargets.filter(isOutputTargetDistTypes);
62673
62966
  await Promise.all([
62674
- ...outputTargets.map((outputsTarget) => {
62675
- return validatePackageJsonOutput(config, compilerCtx, buildCtx, outputsTarget);
62676
- }),
62677
- ...typesOutputTargets.map((outputTarget) => {
62678
- return validateTypes(config, compilerCtx, buildCtx, outputTarget);
62679
- }),
62967
+ ...distCollectionOutputTargets.map((distCollectionOT) => validateDistCollectionPkgJson(config, compilerCtx, buildCtx, distCollectionOT)),
62968
+ ...typesOutputTargets.map((typesOT) => validateTypes(config, compilerCtx, buildCtx, typesOT)),
62969
+ validateModule(config, compilerCtx, buildCtx),
62680
62970
  ]);
62681
62971
  };
62682
- const validatePackageJsonOutput = async (config, compilerCtx, buildCtx, outputTarget) => {
62972
+ /**
62973
+ * Validate package.json contents for the `DIST_COLLECTION` output target,
62974
+ * checking that various fields like `files`, `main`, and so on are set
62975
+ * correctly.
62976
+ *
62977
+ * @param config the stencil config
62978
+ * @param compilerCtx the current compiler context
62979
+ * @param buildCtx the current build context
62980
+ * @param outputTarget a DIST_COLLECTION output target
62981
+ */
62982
+ const validateDistCollectionPkgJson = async (config, compilerCtx, buildCtx, outputTarget) => {
62683
62983
  await Promise.all([
62684
62984
  validatePackageFiles(config, compilerCtx, buildCtx, outputTarget),
62685
62985
  validateMain(config, compilerCtx, buildCtx, outputTarget),
62686
- validateModule(config, compilerCtx, buildCtx, outputTarget),
62687
62986
  validateCollection$1(config, compilerCtx, buildCtx, outputTarget),
62688
62987
  validateBrowser(config, compilerCtx, buildCtx),
62689
62988
  ]);
62690
62989
  };
62990
+ /**
62991
+ * Validate that the `files` field in `package.json` contains directories and
62992
+ * files that are necessary for the `DIST_COLLECTION` output target.
62993
+ *
62994
+ * @param config the stencil config
62995
+ * @param compilerCtx the current compiler context
62996
+ * @param buildCtx the current build context
62997
+ * @param outputTarget a DIST_COLLECTION output target
62998
+ */
62691
62999
  const validatePackageFiles = async (config, compilerCtx, buildCtx, outputTarget) => {
62692
63000
  if (!config.devMode && Array.isArray(buildCtx.packageJson.files)) {
62693
63001
  const actualDistDir = normalizePath$1(relative$1(config.rootDir, outputTarget.dir));
@@ -62711,6 +63019,15 @@ const validatePackageFiles = async (config, compilerCtx, buildCtx, outputTarget)
62711
63019
  }));
62712
63020
  }
62713
63021
  };
63022
+ /**
63023
+ * Check that the `main` field is set correctly in `package.json` for the
63024
+ * `DIST_COLLECTION` output target.
63025
+ *
63026
+ * @param config the stencil config
63027
+ * @param compilerCtx the current compiler context
63028
+ * @param buildCtx the current build context
63029
+ * @param outputTarget a DIST_COLLECTION output target
63030
+ */
62714
63031
  const validateMain = (config, compilerCtx, buildCtx, outputTarget) => {
62715
63032
  const mainAbs = join(outputTarget.dir, 'index.cjs.js');
62716
63033
  const mainRel = relative$1(config.rootDir, mainAbs);
@@ -62723,26 +63040,76 @@ const validateMain = (config, compilerCtx, buildCtx, outputTarget) => {
62723
63040
  packageJsonWarn(config, compilerCtx, buildCtx, msg, `"main"`);
62724
63041
  }
62725
63042
  };
62726
- const validateModule = (config, compilerCtx, buildCtx, outputTarget) => {
62727
- const customElementsOutput = config.outputTargets.find(isOutputTargetDistCustomElementsBundle);
63043
+ /**
63044
+ * Validate the package.json 'module' field, taking into account output targets
63045
+ * and other configuration details. This will look for a value for the `module`
63046
+ * field. If not present it will set a relevant warning message with an
63047
+ * output-target specific recommended value. If it is present and is not equal
63048
+ * to that recommended value it will set a different warning message.
63049
+ *
63050
+ * @param config the current user-supplied configuration
63051
+ * @param compilerCtx the compiler context
63052
+ * @param buildCtx the build context
63053
+ * @returns an empty Promise
63054
+ */
63055
+ const validateModule = async (config, compilerCtx, buildCtx) => {
62728
63056
  const currentModule = buildCtx.packageJson.module;
62729
- const distAbs = join(outputTarget.dir, 'index.js');
62730
- const distRel = relative$1(config.rootDir, distAbs);
62731
- let recommendedRelPath = distRel;
62732
- if (customElementsOutput) {
62733
- const customElementsAbs = join(customElementsOutput.dir, 'index.js');
62734
- recommendedRelPath = relative$1(config.rootDir, customElementsAbs);
62735
- }
63057
+ const recommendedRelPath = recommendedModulePath(config);
62736
63058
  if (!isString$1(currentModule)) {
62737
- const msg = `package.json "module" property is required when generating a distribution. It's recommended to set the "module" property to: ${recommendedRelPath}`;
63059
+ let msg = 'package.json "module" property is required when generating a distribution.';
63060
+ if (recommendedRelPath !== null) {
63061
+ msg += ` It's recommended to set the "module" property to: ${normalizePath$1(recommendedRelPath)}`;
63062
+ }
62738
63063
  packageJsonWarn(config, compilerCtx, buildCtx, msg, `"module"`);
63064
+ return;
62739
63065
  }
62740
- else if (normalizePath$1(currentModule) !== normalizePath$1(recommendedRelPath) &&
62741
- normalizePath$1(currentModule) !== normalizePath$1(distRel)) {
62742
- const msg = `package.json "module" property is set to "${currentModule}". It's recommended to set the "module" property to: ${recommendedRelPath}`;
63066
+ if (recommendedRelPath !== null && normalizePath$1(recommendedRelPath) !== normalizePath$1(currentModule)) {
63067
+ const msg = `package.json "module" property is set to "${currentModule}". It's recommended to set the "module" property to: ${normalizePath$1(recommendedRelPath)}`;
62743
63068
  packageJsonWarn(config, compilerCtx, buildCtx, msg, `"module"`);
62744
63069
  }
62745
63070
  };
63071
+ /**
63072
+ * Get the recommended `"module"` path for `package.json` given the output
63073
+ * targets that a user has set on their config.
63074
+ *
63075
+ * @param config the user-supplied Stencil configuration
63076
+ * @returns a recommended module path or a null value to indicate no default
63077
+ * value is supplied
63078
+ */
63079
+ function recommendedModulePath(config) {
63080
+ const customElementsBundleOT = config.outputTargets.find(isOutputTargetDistCustomElementsBundle);
63081
+ const customElementsOT = config.outputTargets.find(isOutputTargetDistCustomElements);
63082
+ const distCollectionOT = config.outputTargets.find(isOutputTargetDistCollection);
63083
+ // If we're using `dist-custom-elements` then the preferred "module" field
63084
+ // value is `$OUTPUT_DIR/components/index.js`
63085
+ //
63086
+ // Additionally, the `DIST_CUSTOM_ELEMENTS` output target should override
63087
+ // `DIST_CUSTOM_ELEMENTS_BUNDLE` and `DIST_COLLECTION` output targets if
63088
+ // they're also set, so we return first with this one.
63089
+ if (customElementsOT) {
63090
+ const componentsIndexAbs = join(customElementsOT.dir, 'components', 'index.js');
63091
+ return relative$1(config.rootDir, componentsIndexAbs);
63092
+ }
63093
+ if (customElementsBundleOT) {
63094
+ const customElementsAbs = join(customElementsBundleOT.dir, 'index.js');
63095
+ return relative$1(config.rootDir, customElementsAbs);
63096
+ }
63097
+ if (distCollectionOT) {
63098
+ return relative$1(config.rootDir, join(distCollectionOT.dir, 'index.js'));
63099
+ }
63100
+ // if no output target for which we define a recommended output target is set
63101
+ // we return `null`
63102
+ return null;
63103
+ }
63104
+ /**
63105
+ * Check that the `types` field is set correctly in `package.json` for the
63106
+ * `DIST_COLLECTION` output target.
63107
+ *
63108
+ * @param config the stencil config
63109
+ * @param compilerCtx the current compiler context
63110
+ * @param buildCtx the current build context
63111
+ * @param outputTarget a DIST_COLLECTION output target
63112
+ */
62746
63113
  const validateTypes = async (config, compilerCtx, buildCtx, outputTarget) => {
62747
63114
  const typesAbs = getComponentsDtsTypesFilePath(outputTarget);
62748
63115
  const recommendedPath = relative$1(config.rootDir, typesAbs);
@@ -62766,6 +63133,15 @@ const validateTypes = async (config, compilerCtx, buildCtx, outputTarget) => {
62766
63133
  }
62767
63134
  }
62768
63135
  };
63136
+ /**
63137
+ * Check that the `collection` field is set correctly in `package.json` for the
63138
+ * `DIST_COLLECTION` output target.
63139
+ *
63140
+ * @param config the stencil config
63141
+ * @param compilerCtx the current compiler context
63142
+ * @param buildCtx the current build context
63143
+ * @param outputTarget a DIST_COLLECTION output target
63144
+ */
62769
63145
  const validateCollection$1 = (config, compilerCtx, buildCtx, outputTarget) => {
62770
63146
  if (outputTarget.collectionDir) {
62771
63147
  const collectionRel = join(relative$1(config.rootDir, outputTarget.collectionDir), COLLECTION_MANIFEST_FILE_NAME);
@@ -62775,19 +63151,51 @@ const validateCollection$1 = (config, compilerCtx, buildCtx, outputTarget) => {
62775
63151
  }
62776
63152
  }
62777
63153
  };
63154
+ /**
63155
+ * Check that the `browser` field is set correctly in `package.json` for the
63156
+ * `DIST_COLLECTION` output target.
63157
+ *
63158
+ * @param config the stencil config
63159
+ * @param compilerCtx the current compiler context
63160
+ * @param buildCtx the current build context
63161
+ */
62778
63162
  const validateBrowser = (config, compilerCtx, buildCtx) => {
62779
63163
  if (isString$1(buildCtx.packageJson.browser)) {
62780
63164
  const msg = `package.json "browser" property is set to "${buildCtx.packageJson.browser}". However, for maximum compatibility with all bundlers it's recommended to not set the "browser" property and instead ensure both "module" and "main" properties are set.`;
62781
63165
  packageJsonWarn(config, compilerCtx, buildCtx, msg, `"browser"`);
62782
63166
  }
62783
63167
  };
62784
- const packageJsonError = (config, compilerCtx, buildCtx, msg, warnKey) => {
62785
- const err = buildJsonFileError(compilerCtx, buildCtx.diagnostics, config.packageJsonFilePath, msg, warnKey);
63168
+ /**
63169
+ * Build a diagnostic for an error resulting from a particular field in a
63170
+ * package.json file
63171
+ *
63172
+ * @param config the stencil config
63173
+ * @param compilerCtx the current compiler context
63174
+ * @param buildCtx the current build context
63175
+ * @param msg an error string
63176
+ * @param jsonField the key for the field which caused the error, used for
63177
+ * finding the error line in the original JSON file
63178
+ * @returns a diagnostic object
63179
+ */
63180
+ const packageJsonError = (config, compilerCtx, buildCtx, msg, jsonField) => {
63181
+ const err = buildJsonFileError(compilerCtx, buildCtx.diagnostics, config.packageJsonFilePath, msg, jsonField);
62786
63182
  err.header = `Package Json`;
62787
63183
  return err;
62788
63184
  };
62789
- const packageJsonWarn = (config, compilerCtx, buildCtx, msg, warnKey) => {
62790
- const warn = buildJsonFileError(compilerCtx, buildCtx.diagnostics, config.packageJsonFilePath, msg, warnKey);
63185
+ /**
63186
+ * Build a diagnostic for a warning resulting from a particular field in a
63187
+ * package.json file
63188
+ *
63189
+ * @param config the stencil config
63190
+ * @param compilerCtx the current compiler context
63191
+ * @param buildCtx the current build context
63192
+ * @param msg an error string
63193
+ * @param jsonField the key for the field which caused the error, used for
63194
+ * finding the error line in the original JSON file
63195
+ * @returns a diagnostic object
63196
+ */
63197
+ const packageJsonWarn = (config, compilerCtx, buildCtx, msg, jsonField) => {
63198
+ const warn = buildJsonFileError(compilerCtx, buildCtx.diagnostics, config.packageJsonFilePath, msg, jsonField);
62791
63199
  warn.header = `Package Json`;
62792
63200
  warn.level = 'warn';
62793
63201
  return warn;
@@ -64246,16 +64654,38 @@ const updateCompilerCtxCache = (config, compilerCtx, path, kind) => {
64246
64654
  }
64247
64655
  };
64248
64656
 
64657
+ /**
64658
+ * All the Boolean options supported by the Stencil CLI
64659
+ */
64660
+ /**
64661
+ * Helper function for initializing a `ConfigFlags` object. Provide any overrides
64662
+ * for default values and off you go!
64663
+ *
64664
+ * @param init an object with any overrides for default values
64665
+ * @returns a complete CLI flag object
64666
+ */
64667
+ const createConfigFlags = (init = {}) => {
64668
+ const flags = {
64669
+ task: null,
64670
+ args: [],
64671
+ knownArgs: [],
64672
+ unknownArgs: [],
64673
+ ...init,
64674
+ };
64675
+ return flags;
64676
+ };
64677
+
64249
64678
  const getConfig = (userConfig) => {
64250
- const config = { ...userConfig };
64251
- if (!config.logger) {
64252
- config.logger = createLogger();
64253
- }
64254
- if (!config.sys) {
64255
- config.sys = createSystem({ logger: config.logger });
64256
- }
64679
+ var _a, _b, _c, _d;
64680
+ const logger = (_a = userConfig.logger) !== null && _a !== void 0 ? _a : createLogger();
64681
+ const config = {
64682
+ ...userConfig,
64683
+ flags: createConfigFlags((_b = userConfig.flags) !== null && _b !== void 0 ? _b : {}),
64684
+ logger,
64685
+ outputTargets: (_c = userConfig.outputTargets) !== null && _c !== void 0 ? _c : [],
64686
+ sys: (_d = userConfig.sys) !== null && _d !== void 0 ? _d : createSystem({ logger }),
64687
+ };
64257
64688
  setPlatformPath(config.sys.platformPath);
64258
- config.flags = config.flags || {};
64259
64689
  if (config.flags.debug || config.flags.verbose) {
64260
64690
  config.logLevel = 'debug';
64261
64691
  }
@@ -64276,14 +64706,15 @@ const patchFs = (userSys) => {
64276
64706
 
64277
64707
  /**
64278
64708
  * Generate a Stencil compiler instance
64279
- * @param config a Stencil configuration to apply to the compiler instance
64709
+ * @param userConfig a user-provided Stencil configuration to apply to the compiler instance
64280
64710
  * @returns a new instance of a Stencil compiler
64711
+ * @public
64281
64712
  */
64282
- const createCompiler = async (config) => {
64713
+ const createCompiler = async (userConfig) => {
64283
64714
  // actual compiler code
64284
64715
  // could be in a web worker on the browser
64285
64716
  // or the main thread in node
64286
- config = getConfig(config);
64717
+ const config = getConfig(userConfig);
64287
64718
  const diagnostics = [];
64288
64719
  const sys = config.sys;
64289
64720
  const compilerCtx = new CompilerContext();
@@ -64959,7 +65390,7 @@ const getComponentPathContent = (componentGraph, outputTarget) => {
64959
65390
  const dependencies = [
64960
65391
  {
64961
65392
  name: "@stencil/core",
64962
- version: "2.17.0",
65393
+ version: "2.17.2",
64963
65394
  main: "compiler/stencil.js",
64964
65395
  resources: [
64965
65396
  "package.json",
@@ -65131,11 +65562,11 @@ const getUserConfigName = (config, correctConfigName) => {
65131
65562
  };
65132
65563
 
65133
65564
  const validateDevServer = (config, diagnostics) => {
65134
- var _a, _b, _c, _d, _e, _f, _g;
65565
+ var _a, _b, _c, _d, _e;
65135
65566
  if ((config.devServer === null || config.devServer) === false) {
65136
65567
  return undefined;
65137
65568
  }
65138
- const flags = (_a = config.flags) !== null && _a !== void 0 ? _a : {};
65569
+ const { flags } = config;
65139
65570
  const devServer = { ...config.devServer };
65140
65571
  if (flags.address && isString$1(flags.address)) {
65141
65572
  devServer.address = flags.address;
@@ -65193,14 +65624,14 @@ const validateDevServer = (config, diagnostics) => {
65193
65624
  if (!isBoolean$1(devServer.websocket)) {
65194
65625
  devServer.websocket = true;
65195
65626
  }
65196
- if ((_b = config === null || config === void 0 ? void 0 : config.flags) === null || _b === void 0 ? void 0 : _b.ssr) {
65627
+ if (flags.ssr) {
65197
65628
  devServer.ssr = true;
65198
65629
  }
65199
65630
  else {
65200
65631
  devServer.ssr = !!devServer.ssr;
65201
65632
  }
65202
65633
  if (devServer.ssr) {
65203
- const wwwOutput = ((_c = config.outputTargets) !== null && _c !== void 0 ? _c : []).find(isOutputTargetWww);
65634
+ const wwwOutput = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).find(isOutputTargetWww);
65204
65635
  devServer.prerenderConfig = wwwOutput === null || wwwOutput === void 0 ? void 0 : wwwOutput.prerenderConfig;
65205
65636
  }
65206
65637
  if (isString$1(config.srcIndexHtml)) {
@@ -65226,15 +65657,15 @@ const validateDevServer = (config, diagnostics) => {
65226
65657
  }
65227
65658
  let serveDir;
65228
65659
  let basePath;
65229
- const wwwOutputTarget = ((_d = config.outputTargets) !== null && _d !== void 0 ? _d : []).find(isOutputTargetWww);
65660
+ const wwwOutputTarget = ((_b = config.outputTargets) !== null && _b !== void 0 ? _b : []).find(isOutputTargetWww);
65230
65661
  if (wwwOutputTarget) {
65231
- const baseUrl = new URL((_e = wwwOutputTarget.baseUrl) !== null && _e !== void 0 ? _e : '', 'http://config.stenciljs.com');
65662
+ const baseUrl = new URL((_c = wwwOutputTarget.baseUrl) !== null && _c !== void 0 ? _c : '', 'http://config.stenciljs.com');
65232
65663
  basePath = baseUrl.pathname;
65233
- serveDir = (_f = wwwOutputTarget.appDir) !== null && _f !== void 0 ? _f : '';
65664
+ serveDir = (_d = wwwOutputTarget.appDir) !== null && _d !== void 0 ? _d : '';
65234
65665
  }
65235
65666
  else {
65236
65667
  basePath = '';
65237
- serveDir = (_g = config.rootDir) !== null && _g !== void 0 ? _g : '';
65668
+ serveDir = (_e = config.rootDir) !== null && _e !== void 0 ? _e : '';
65238
65669
  }
65239
65670
  if (!isString$1(basePath) || basePath.trim() === '') {
65240
65671
  basePath = `/`;
@@ -65368,11 +65799,19 @@ const validateHydrated = (config) => {
65368
65799
  return hydratedFlag;
65369
65800
  };
65370
65801
 
65802
+ /**
65803
+ * Validate and return DIST_COLLECTION output targets, ensuring that the `dir`
65804
+ * property is set on them.
65805
+ *
65806
+ * @param config the user-supplied configuration object
65807
+ * @param userOutputs an array of output targets
65808
+ * @returns an array of validated DIST_COLLECTION output targets
65809
+ */
65371
65810
  const validateCollection = (config, userOutputs) => {
65372
- return userOutputs.filter(isOutputTargetDistCollection).map((o) => {
65811
+ return userOutputs.filter(isOutputTargetDistCollection).map((outputTarget) => {
65373
65812
  return {
65374
- ...o,
65375
- dir: getAbsolutePath(config, o.dir || 'dist/collection'),
65813
+ ...outputTarget,
65814
+ dir: getAbsolutePath(config, outputTarget.dir || 'dist/collection'),
65376
65815
  };
65377
65816
  });
65378
65817
  };
@@ -65706,7 +66145,7 @@ const validateHydrateScript = (config, userOutputs) => {
65706
66145
  // we don't already have a hydrate output target
65707
66146
  // let's still see if we require one because of other output targets
65708
66147
  const hasWwwOutput = userOutputs.filter(isOutputTargetWww).some((o) => isString$1(o.indexHtml));
65709
- const shouldBuildHydrate = (config === null || config === void 0 ? void 0 : config.flags.prerender) || (config === null || config === void 0 ? void 0 : config.flags.ssr);
66148
+ const shouldBuildHydrate = config.flags.prerender || config.flags.ssr;
65710
66149
  if (hasWwwOutput && shouldBuildHydrate) {
65711
66150
  // we're prerendering a www output target, so we'll need a hydrate app
65712
66151
  let hydrateDir;
@@ -65782,7 +66221,7 @@ const validateStats = (userConfig, userOutputs) => {
65782
66221
  };
65783
66222
 
65784
66223
  const validatePrerender = (config, diagnostics, outputTarget) => {
65785
- if (!config.flags || (!config.flags.ssr && !config.flags.prerender && config.flags.task !== 'prerender')) {
66224
+ if (!config.flags.ssr && !config.flags.prerender && config.flags.task !== 'prerender') {
65786
66225
  return;
65787
66226
  }
65788
66227
  outputTarget.baseUrl = normalizePath$1(outputTarget.baseUrl);
@@ -65807,8 +66246,6 @@ const validatePrerender = (config, diagnostics, outputTarget) => {
65807
66246
  }
65808
66247
  };
65809
66248
 
65810
- const HOST_CONFIG_FILENAME = 'host.config.json';
65811
-
65812
66249
  const validateServiceWorker = (config, outputTarget) => {
65813
66250
  if (outputTarget.serviceWorker === false) {
65814
66251
  return;
@@ -65861,14 +66298,15 @@ const validateServiceWorker = (config, outputTarget) => {
65861
66298
  }
65862
66299
  };
65863
66300
  const addGlobIgnores = (config, globIgnores) => {
65864
- globIgnores.push(`**/${HOST_CONFIG_FILENAME}`, `**/*.system.entry.js`, `**/*.system.js`, `**/${config.fsNamespace}.js`, `**/${config.fsNamespace}.esm.js`, `**/${config.fsNamespace}.css`);
66301
+ globIgnores.push(`**/host.config.json`, // the filename of the host configuration
66302
+ `**/*.system.entry.js`, `**/*.system.js`, `**/${config.fsNamespace}.js`, `**/${config.fsNamespace}.esm.js`, `**/${config.fsNamespace}.css`);
65865
66303
  };
65866
66304
  const DEFAULT_GLOB_PATTERNS = ['*.html', '**/*.{js,css,json}'];
65867
66305
  const DEFAULT_FILENAME = 'sw.js';
65868
66306
 
65869
66307
  const validateWww = (config, diagnostics, userOutputs) => {
65870
66308
  const hasOutputTargets = userOutputs.length > 0;
65871
- const hasE2eTests = !!(config.flags && config.flags.e2e);
66309
+ const hasE2eTests = !!config.flags.e2e;
65872
66310
  const userWwwOutputs = userOutputs.filter(isOutputTargetWww);
65873
66311
  if (!hasOutputTargets ||
65874
66312
  (hasE2eTests && !userOutputs.some(isOutputTargetWww) && !userOutputs.some(isOutputTargetDist))) {
@@ -66122,7 +66560,7 @@ const DEFAULT_ROLLUP_CONFIG = {
66122
66560
  const validateTesting = (config, diagnostics) => {
66123
66561
  var _a;
66124
66562
  const testing = (config.testing = Object.assign({}, config.testing || {}));
66125
- if (!config.flags || (!config.flags.e2e && !config.flags.spec)) {
66563
+ if (!config.flags.e2e && !config.flags.spec) {
66126
66564
  return;
66127
66565
  }
66128
66566
  let configPathDir = config.configPath;
@@ -66160,7 +66598,7 @@ const validateTesting = (config, diagnostics) => {
66160
66598
  else {
66161
66599
  testing.rootDir = config.rootDir;
66162
66600
  }
66163
- if (config.flags && typeof config.flags.screenshotConnector === 'string') {
66601
+ if (typeof config.flags.screenshotConnector === 'string') {
66164
66602
  testing.screenshotConnector = config.flags.screenshotConnector;
66165
66603
  }
66166
66604
  if (typeof testing.screenshotConnector === 'string') {
@@ -66282,13 +66720,11 @@ const validateWorkers = (config) => {
66282
66720
  if (typeof config.maxConcurrentWorkers !== 'number') {
66283
66721
  config.maxConcurrentWorkers = 8;
66284
66722
  }
66285
- if (config.flags) {
66286
- if (typeof config.flags.maxWorkers === 'number') {
66287
- config.maxConcurrentWorkers = config.flags.maxWorkers;
66288
- }
66289
- else if (config.flags.ci) {
66290
- config.maxConcurrentWorkers = 4;
66291
- }
66723
+ if (typeof config.flags.maxWorkers === 'number') {
66724
+ config.maxConcurrentWorkers = config.flags.maxWorkers;
66725
+ }
66726
+ else if (config.flags.ci) {
66727
+ config.maxConcurrentWorkers = 4;
66292
66728
  }
66293
66729
  config.maxConcurrentWorkers = Math.max(Math.min(config.maxConcurrentWorkers, 16), 0);
66294
66730
  if (config.devServer) {
@@ -66302,111 +66738,122 @@ const validateWorkers = (config) => {
66302
66738
  * `UnvalidatedConfig` to a `Config`.
66303
66739
  *
66304
66740
  * @param userConfig an unvalidated config that we've gotten from a user
66741
+ * @param bootstrapConfig the initial configuration provided by the user (or generated by Stencil) used to bootstrap
66742
+ * configuration loading and validation
66305
66743
  * @returns an object with config and diagnostics props
66306
66744
  */
66307
- const validateConfig = (userConfig = {}) => {
66308
- const config = Object.assign({}, userConfig || {}); // not positive it's json safe
66745
+ const validateConfig = (userConfig = {}, bootstrapConfig) => {
66746
+ var _a, _b, _c;
66747
+ const config = Object.assign({}, userConfig); // not positive it's json safe
66309
66748
  const diagnostics = [];
66310
- // copy flags (we know it'll be json safe)
66311
- config.flags = JSON.parse(JSON.stringify(config.flags || {}));
66749
+ const logger = bootstrapConfig.logger || config.logger || createLogger();
66750
+ const validatedConfig = {
66751
+ ...config,
66752
+ // flags _should_ be JSON safe
66753
+ flags: JSON.parse(JSON.stringify(config.flags || {})),
66754
+ logger,
66755
+ outputTargets: (_a = config.outputTargets) !== null && _a !== void 0 ? _a : [],
66756
+ sys: (_c = (_b = config.sys) !== null && _b !== void 0 ? _b : bootstrapConfig.sys) !== null && _c !== void 0 ? _c : createSystem({ logger }),
66757
+ };
66312
66758
  // default devMode false
66313
- if (config.flags.prod) {
66314
- config.devMode = false;
66315
- }
66316
- else if (config.flags.dev) {
66317
- config.devMode = true;
66318
- }
66319
- else if (!isBoolean$1(config.devMode)) {
66320
- config.devMode = DEFAULT_DEV_MODE;
66321
- }
66322
- config.extras = config.extras || {};
66323
- config.extras.appendChildSlotFix = !!config.extras.appendChildSlotFix;
66324
- config.extras.cloneNodeFix = !!config.extras.cloneNodeFix;
66325
- config.extras.cssVarsShim = !!config.extras.cssVarsShim;
66326
- config.extras.dynamicImportShim = !!config.extras.dynamicImportShim;
66327
- config.extras.lifecycleDOMEvents = !!config.extras.lifecycleDOMEvents;
66328
- config.extras.safari10 = !!config.extras.safari10;
66329
- config.extras.scriptDataOpts = !!config.extras.scriptDataOpts;
66330
- config.extras.shadowDomShim = !!config.extras.shadowDomShim;
66331
- config.extras.slotChildNodesFix = !!config.extras.slotChildNodesFix;
66332
- config.extras.initializeNextTick = !!config.extras.initializeNextTick;
66333
- config.extras.tagNameTransform = !!config.extras.tagNameTransform;
66334
- config.buildEs5 = config.buildEs5 === true || (!config.devMode && config.buildEs5 === 'prod');
66335
- setBooleanConfig(config, 'minifyCss', null, !config.devMode);
66336
- setBooleanConfig(config, 'minifyJs', null, !config.devMode);
66337
- setBooleanConfig(config, 'sourceMap', null, typeof config.sourceMap === 'undefined' ? false : config.sourceMap);
66338
- setBooleanConfig(config, 'watch', 'watch', false);
66339
- setBooleanConfig(config, 'buildDocs', 'docs', !config.devMode);
66340
- setBooleanConfig(config, 'buildDist', 'esm', !config.devMode || config.buildEs5);
66341
- setBooleanConfig(config, 'profile', 'profile', config.devMode);
66342
- setBooleanConfig(config, 'writeLog', 'log', false);
66343
- setBooleanConfig(config, 'buildAppCore', null, true);
66344
- setBooleanConfig(config, 'autoprefixCss', null, config.buildEs5);
66345
- setBooleanConfig(config, 'validateTypes', null, !config._isTesting);
66346
- setBooleanConfig(config, 'allowInlineScripts', null, true);
66347
- if (!isString$1(config.taskQueue)) {
66348
- config.taskQueue = 'async';
66759
+ if (validatedConfig.flags.prod) {
66760
+ validatedConfig.devMode = false;
66761
+ }
66762
+ else if (validatedConfig.flags.dev) {
66763
+ validatedConfig.devMode = true;
66764
+ }
66765
+ else if (!isBoolean$1(validatedConfig.devMode)) {
66766
+ validatedConfig.devMode = DEFAULT_DEV_MODE;
66767
+ }
66768
+ validatedConfig.extras = validatedConfig.extras || {};
66769
+ validatedConfig.extras.appendChildSlotFix = !!validatedConfig.extras.appendChildSlotFix;
66770
+ validatedConfig.extras.cloneNodeFix = !!validatedConfig.extras.cloneNodeFix;
66771
+ validatedConfig.extras.cssVarsShim = !!validatedConfig.extras.cssVarsShim;
66772
+ validatedConfig.extras.dynamicImportShim = !!validatedConfig.extras.dynamicImportShim;
66773
+ validatedConfig.extras.lifecycleDOMEvents = !!validatedConfig.extras.lifecycleDOMEvents;
66774
+ validatedConfig.extras.safari10 = !!validatedConfig.extras.safari10;
66775
+ validatedConfig.extras.scriptDataOpts = !!validatedConfig.extras.scriptDataOpts;
66776
+ validatedConfig.extras.shadowDomShim = !!validatedConfig.extras.shadowDomShim;
66777
+ validatedConfig.extras.slotChildNodesFix = !!validatedConfig.extras.slotChildNodesFix;
66778
+ validatedConfig.extras.initializeNextTick = !!validatedConfig.extras.initializeNextTick;
66779
+ validatedConfig.extras.tagNameTransform = !!validatedConfig.extras.tagNameTransform;
66780
+ validatedConfig.buildEs5 =
66781
+ validatedConfig.buildEs5 === true || (!validatedConfig.devMode && validatedConfig.buildEs5 === 'prod');
66782
+ setBooleanConfig(validatedConfig, 'minifyCss', null, !validatedConfig.devMode);
66783
+ setBooleanConfig(validatedConfig, 'minifyJs', null, !validatedConfig.devMode);
66784
+ setBooleanConfig(validatedConfig, 'sourceMap', null, typeof validatedConfig.sourceMap === 'undefined' ? false : validatedConfig.sourceMap);
66785
+ setBooleanConfig(validatedConfig, 'watch', 'watch', false);
66786
+ setBooleanConfig(validatedConfig, 'buildDocs', 'docs', !validatedConfig.devMode);
66787
+ setBooleanConfig(validatedConfig, 'buildDist', 'esm', !validatedConfig.devMode || validatedConfig.buildEs5);
66788
+ setBooleanConfig(validatedConfig, 'profile', 'profile', validatedConfig.devMode);
66789
+ setBooleanConfig(validatedConfig, 'writeLog', 'log', false);
66790
+ setBooleanConfig(validatedConfig, 'buildAppCore', null, true);
66791
+ setBooleanConfig(validatedConfig, 'autoprefixCss', null, validatedConfig.buildEs5);
66792
+ setBooleanConfig(validatedConfig, 'validateTypes', null, !validatedConfig._isTesting);
66793
+ setBooleanConfig(validatedConfig, 'allowInlineScripts', null, true);
66794
+ if (!isString$1(validatedConfig.taskQueue)) {
66795
+ validatedConfig.taskQueue = 'async';
66349
66796
  }
66350
66797
  // hash file names
66351
- if (!isBoolean$1(config.hashFileNames)) {
66352
- config.hashFileNames = !config.devMode;
66798
+ if (!isBoolean$1(validatedConfig.hashFileNames)) {
66799
+ validatedConfig.hashFileNames = !validatedConfig.devMode;
66353
66800
  }
66354
- if (!isNumber$1(config.hashedFileNameLength)) {
66355
- config.hashedFileNameLength = DEFAULT_HASHED_FILENAME_LENTH;
66801
+ if (!isNumber$1(validatedConfig.hashedFileNameLength)) {
66802
+ validatedConfig.hashedFileNameLength = DEFAULT_HASHED_FILENAME_LENTH;
66356
66803
  }
66357
- if (config.hashedFileNameLength < MIN_HASHED_FILENAME_LENTH) {
66804
+ if (validatedConfig.hashedFileNameLength < MIN_HASHED_FILENAME_LENTH) {
66358
66805
  const err = buildError(diagnostics);
66359
- err.messageText = `config.hashedFileNameLength must be at least ${MIN_HASHED_FILENAME_LENTH} characters`;
66806
+ err.messageText = `validatedConfig.hashedFileNameLength must be at least ${MIN_HASHED_FILENAME_LENTH} characters`;
66360
66807
  }
66361
- if (config.hashedFileNameLength > MAX_HASHED_FILENAME_LENTH) {
66808
+ if (validatedConfig.hashedFileNameLength > MAX_HASHED_FILENAME_LENTH) {
66362
66809
  const err = buildError(diagnostics);
66363
- err.messageText = `config.hashedFileNameLength cannot be more than ${MAX_HASHED_FILENAME_LENTH} characters`;
66810
+ err.messageText = `validatedConfig.hashedFileNameLength cannot be more than ${MAX_HASHED_FILENAME_LENTH} characters`;
66364
66811
  }
66365
- if (!config.env) {
66366
- config.env = {};
66812
+ if (!validatedConfig.env) {
66813
+ validatedConfig.env = {};
66367
66814
  }
66368
66815
  // get a good namespace
66369
- validateNamespace(config, diagnostics);
66816
+ validateNamespace(validatedConfig, diagnostics);
66370
66817
  // figure out all of the config paths and absolute paths
66371
- validatePaths(config);
66818
+ validatePaths(validatedConfig);
66372
66819
  // outputTargets
66373
- validateOutputTargets(config, diagnostics);
66820
+ validateOutputTargets(validatedConfig, diagnostics);
66374
66821
  // plugins
66375
- validatePlugins(config, diagnostics);
66822
+ validatePlugins(validatedConfig, diagnostics);
66376
66823
  // rollup config
66377
- validateRollupConfig(config);
66824
+ validateRollupConfig(validatedConfig);
66378
66825
  // dev server
66379
- config.devServer = validateDevServer(config, diagnostics);
66826
+ validatedConfig.devServer = validateDevServer(validatedConfig, diagnostics);
66380
66827
  // testing
66381
- validateTesting(config, diagnostics);
66828
+ validateTesting(validatedConfig, diagnostics);
66382
66829
  // hydrate flag
66383
- config.hydratedFlag = validateHydrated(config);
66830
+ validatedConfig.hydratedFlag = validateHydrated(validatedConfig);
66384
66831
  // bundles
66385
- if (Array.isArray(config.bundles)) {
66386
- config.bundles = sortBy(config.bundles, (a) => a.components.length);
66832
+ if (Array.isArray(validatedConfig.bundles)) {
66833
+ validatedConfig.bundles = sortBy(validatedConfig.bundles, (a) => a.components.length);
66387
66834
  }
66388
66835
  else {
66389
- config.bundles = [];
66836
+ validatedConfig.bundles = [];
66390
66837
  }
66391
66838
  // validate how many workers we can use
66392
- validateWorkers(config);
66839
+ validateWorkers(validatedConfig);
66393
66840
  // default devInspector to whatever devMode is
66394
- setBooleanConfig(config, 'devInspector', null, config.devMode);
66395
- if (!config._isTesting) {
66396
- validateDistNamespace(config, diagnostics);
66841
+ setBooleanConfig(validatedConfig, 'devInspector', null, validatedConfig.devMode);
66842
+ if (!validatedConfig._isTesting) {
66843
+ validateDistNamespace(validatedConfig, diagnostics);
66397
66844
  }
66398
- setBooleanConfig(config, 'enableCache', 'cache', true);
66399
- if (!Array.isArray(config.watchIgnoredRegex) && config.watchIgnoredRegex != null) {
66400
- config.watchIgnoredRegex = [config.watchIgnoredRegex];
66845
+ setBooleanConfig(validatedConfig, 'enableCache', 'cache', true);
66846
+ if (!Array.isArray(validatedConfig.watchIgnoredRegex) && validatedConfig.watchIgnoredRegex != null) {
66847
+ validatedConfig.watchIgnoredRegex = [validatedConfig.watchIgnoredRegex];
66401
66848
  }
66402
- config.watchIgnoredRegex = (config.watchIgnoredRegex || []).reduce((arr, reg) => {
66849
+ validatedConfig.watchIgnoredRegex = (validatedConfig.watchIgnoredRegex || []).reduce((arr, reg) => {
66403
66850
  if (reg instanceof RegExp) {
66404
66851
  arr.push(reg);
66405
66852
  }
66406
66853
  return arr;
66407
66854
  }, []);
66408
66855
  return {
66409
- config,
66856
+ config: validatedConfig,
66410
66857
  diagnostics,
66411
66858
  };
66412
66859
  };
@@ -66573,6 +67020,7 @@ const hasStencilConfigInclude = (includeProp) => Array.isArray(includeProp) && i
66573
67020
  * @public
66574
67021
  */
66575
67022
  const loadConfig = async (init = {}) => {
67023
+ var _a;
66576
67024
  const results = {
66577
67025
  config: null,
66578
67026
  diagnostics: [],
@@ -66585,30 +67033,33 @@ const loadConfig = async (init = {}) => {
66585
67033
  extends: null,
66586
67034
  },
66587
67035
  };
67036
+ const unknownConfig = {};
66588
67037
  try {
66589
- const sys = init.sys || createSystem();
66590
67038
  const config = init.config || {};
66591
67039
  let configPath = init.configPath || config.configPath;
67040
+ // Pull the {@link CompilerSystem} out of the initialization object, or create one if it does not exist.
67041
+ // This entity is needed to load the project's configuration (and therefore needs to be created before it can be
67042
+ // attached to a configuration entity, validated or otherwise)
67043
+ const sys = (_a = init.sys) !== null && _a !== void 0 ? _a : createSystem();
66592
67044
  const loadedConfigFile = await loadConfigFile(sys, results.diagnostics, configPath);
66593
67045
  if (hasError(results.diagnostics)) {
66594
67046
  return results;
66595
67047
  }
66596
- if (loadedConfigFile != null) {
67048
+ if (loadedConfigFile !== null) {
66597
67049
  // merge the user's config object into their loaded config file
66598
67050
  configPath = loadedConfigFile.configPath;
66599
- results.config = { ...loadedConfigFile, ...config };
66600
- results.config.configPath = configPath;
66601
- results.config.rootDir = normalizePath$1(dirname(configPath));
67051
+ unknownConfig.config = { ...loadedConfigFile, ...config };
67052
+ unknownConfig.config.configPath = configPath;
67053
+ unknownConfig.config.rootDir = normalizePath$1(dirname(configPath));
66602
67054
  }
66603
67055
  else {
66604
67056
  // no stencil.config.ts or .js file, which is fine
66605
- // #0CJS ¯\_(ツ)_/¯
66606
- results.config = { ...config };
66607
- results.config.configPath = null;
66608
- results.config.rootDir = normalizePath$1(sys.getCurrentDirectory());
67057
+ unknownConfig.config = { ...config };
67058
+ unknownConfig.config.configPath = null;
67059
+ unknownConfig.config.rootDir = normalizePath$1(sys.getCurrentDirectory());
66609
67060
  }
66610
- results.config.sys = sys;
66611
- const validated = validateConfig(results.config);
67061
+ unknownConfig.config.sys = sys;
67062
+ const validated = validateConfig(unknownConfig.config, init);
66612
67063
  results.diagnostics.push(...validated.diagnostics);
66613
67064
  if (hasError(results.diagnostics)) {
66614
67065
  return results;
@@ -66623,7 +67074,6 @@ const loadConfig = async (init = {}) => {
66623
67074
  else if (typeof results.config.logLevel !== 'string') {
66624
67075
  results.config.logLevel = 'info';
66625
67076
  }
66626
- results.config.logger = init.logger || results.config.logger || createLogger();
66627
67077
  results.config.logger.setLevel(results.config.logLevel);
66628
67078
  if (!hasError(results.diagnostics)) {
66629
67079
  const tsConfigResults = await validateTsConfig(results.config, sys, init);
@@ -66882,7 +67332,7 @@ const convertStaticToMeta = (config, compilerCtx, buildCtx, typeChecker, collect
66882
67332
  let moduleFile;
66883
67333
  const visitNode = (node) => {
66884
67334
  if (t.isClassDeclaration(node)) {
66885
- return parseStaticComponentMeta(compilerCtx, typeChecker, node, moduleFile, compilerCtx.nodeMap, transformOpts);
67335
+ return parseStaticComponentMeta(compilerCtx, typeChecker, node, moduleFile, transformOpts);
66886
67336
  }
66887
67337
  else if (t.isImportDeclaration(node)) {
66888
67338
  parseModuleImport(config, compilerCtx, buildCtx, moduleFile, dirPath, node, !transformOpts.isolatedModules);