@hubspot/cms-dev-server 0.16.18 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/generateJsonFromJsx.js +297 -172
  2. package/dist/index.js +4766 -176
  3. package/dist/internalSsr.js +260 -151
  4. package/dist/run.js +1989 -503
  5. package/dist/storybook-main/main.js +261 -152
  6. package/package.json +14 -10
  7. package/types/api/designmanager.d.ts +31 -0
  8. package/types/api/session.d.ts +2 -0
  9. package/types/components/HubLModulesList.d.ts +4 -0
  10. package/types/components/HubLTemplatesList.d.ts +4 -0
  11. package/types/components/ModulesList.d.ts +5 -0
  12. package/types/components/PartialsList.d.ts +4 -0
  13. package/types/createAppServer.d.ts +2 -0
  14. package/types/createDevServer.d.ts +5 -0
  15. package/types/createViteDevServer.d.ts +3 -0
  16. package/types/fileManager.d.ts +4 -0
  17. package/types/index.d.ts +1 -0
  18. package/types/lib/configHelpers.d.ts +2 -0
  19. package/types/lib/criticalDevErrorsToServerMessages.d.ts +4 -0
  20. package/types/lib/debug.d.ts +1 -0
  21. package/types/lib/errors.d.ts +6 -0
  22. package/types/lib/fetchModuleGraphQLData.d.ts +24 -0
  23. package/types/lib/fullOriginalUrlFromRequest.d.ts +2 -0
  24. package/types/lib/gates.d.ts +2 -0
  25. package/types/lib/getJSRenderingGates.d.ts +8 -0
  26. package/types/lib/httpsRedirectingServer.d.ts +11 -0
  27. package/types/lib/logColors.d.ts +6 -0
  28. package/types/lib/moduleGraph.d.ts +1 -0
  29. package/types/lib/packagePath.d.ts +1 -0
  30. package/types/lib/pathHelpers.d.ts +3 -0
  31. package/types/lib/previewUtils.d.ts +22 -0
  32. package/types/lib/proxyHelpers.d.ts +29 -0
  33. package/types/lib/renderComponentWithCSS.d.ts +14 -0
  34. package/types/lib/renderHelpers.d.ts +1 -0
  35. package/types/lib/renderModule.d.ts +11 -0
  36. package/types/lib/renderModulePreview.d.ts +5 -0
  37. package/types/lib/renderPartial.d.ts +5 -0
  38. package/types/lib/templates.d.ts +4 -0
  39. package/types/lib/trackUsage.d.ts +3 -0
  40. package/types/lib/validateHSPlatform.d.ts +3 -0
  41. package/types/lib/watchFieldsUpdates.d.ts +22 -0
  42. package/types/proxyPage/constants.d.ts +1 -0
  43. package/types/proxyPage/fetchContentMetadata.d.ts +7 -0
  44. package/types/proxyPage/fetchDomains.d.ts +9 -0
  45. package/types/proxyPage/fetchPreviewInfo.d.ts +6 -0
  46. package/types/proxyPage/proxyPage.d.ts +11 -0
  47. package/types/proxyPage/renderLocalError.d.ts +2 -0
  48. package/types/proxyPage/utils.d.ts +4 -0
  49. package/types/routes/createDevServerRoutes.d.ts +3 -0
  50. package/types/routes/homeRouteHandler.d.ts +3 -0
  51. package/types/routes/hublModuleRouteHandler.d.ts +2 -0
  52. package/types/routes/hublTemplateRouteHandler.d.ts +2 -0
  53. package/types/routes/linksToAllModulesRouteHandler.d.ts +2 -0
  54. package/types/routes/linksToAllPartialsRouteHandler.d.ts +2 -0
  55. package/types/routes/meta.d.ts +2 -0
  56. package/types/routes/module.d.ts +3 -0
  57. package/types/routes/modulePreviewRouteHandler.d.ts +3 -0
  58. package/types/routes/partial.d.ts +2 -0
  59. package/types/routes/proxyPageResourceRedirect.d.ts +2 -0
  60. package/types/routes/proxyPageRouteHandler.d.ts +2 -0
  61. package/types/routes/proxyPathPageResourceRedirect.d.ts +2 -0
  62. package/types/routes/proxyPathPageRouteHandler.d.ts +2 -0
  63. package/types/routes/proxyServerlessHandler.d.ts +2 -0
  64. package/types/routes/remoteFsDirtyHandler.d.ts +2 -0
  65. package/types/shadowDevServer/createShadowDevServerRoutes.d.ts +2 -0
  66. package/types/shadowDevServer/startShadowDevServer.d.ts +2 -0
  67. package/dist/generateJsonFromJsx.js.map +0 -7
  68. package/dist/index.js.map +0 -7
  69. package/dist/internalSsr.js.map +0 -7
  70. package/dist/island-runtime.js.map +0 -7
  71. package/dist/run.js.map +0 -7
  72. package/dist/storybook/index.js.map +0 -7
  73. package/dist/storybook-main/main.js.map +0 -7
  74. package/dist/storybook-main/preview.js.map +0 -7
  75. package/types/island-runtime.d.ts +0 -2
@@ -319,12 +319,16 @@ var GATES = [
319
319
  "CMS:JSRenderer:ModuleHubl",
320
320
  "CMS:JSRenderer:RemoveCjsPlugin",
321
321
  "CMS:JSRenderer:RemoveMockClientEntryPlugin",
322
- "CMS:JSRenderer:AnalyzeCmsModules"
322
+ "CMS:JSRenderer:AnalyzeCmsModules",
323
+ "CMS:JSRenderer:ClientOnlySupplementalFieldSerialization",
324
+ "CMS:React:UnifiedThemePreview"
323
325
  ];
324
326
  var ENABLED_FEATURES_GATE_MAP = {
325
327
  "cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
326
328
  "cms:jsr:RemoveCjsPlugin": "CMS:JSRenderer:RemoveCjsPlugin",
327
- "cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
329
+ "cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules",
330
+ "cms:jsr:clientOnlySupplementalFieldSerialization": "CMS:JSRenderer:ClientOnlySupplementalFieldSerialization",
331
+ "cms:react:unifiedThemePreview": "CMS:React:UnifiedThemePreview"
328
332
  };
329
333
  function isUngatedFor(gates, gate) {
330
334
  return gates.includes(gate);
@@ -457,7 +461,7 @@ import * as cmsComponents from "@hubspot/cms-components";
457
461
  import { ServerRenderContext } from "@hubspot/cms-components";
458
462
  import { isValidElement, cloneElement } from "react";
459
463
  var { setProperty, getProperty, hasProperty } = dotProp;
460
- var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
464
+ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint, isUngatedForClientOnlySupplementalFieldSerialization = false) => {
461
465
  const islandsArrayToSerialize = tweakedIslandsArray.map(
462
466
  ({
463
467
  id,
@@ -499,6 +503,9 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestD
499
503
  if (filteredSupplementalFieldValues) {
500
504
  output.supplementalFieldValues = filteredSupplementalFieldValues;
501
505
  }
506
+ if (isUngatedForClientOnlySupplementalFieldSerialization && output.clientOnly) {
507
+ output.supplementalFieldValues = supplementalFieldValues;
508
+ }
502
509
  return output;
503
510
  }
504
511
  );
@@ -594,7 +601,7 @@ function getPerServerRequestUrls(perServerRequestData, viteDevServer) {
594
601
  });
595
602
  return perServerRequestDataWithUrls;
596
603
  }
597
- var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent, prettyPrint) => {
604
+ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent, prettyPrint, isUngatedForClientOnlySupplementalFieldSerialization = false) => {
598
605
  const islands = getIslandUrls(roots, viteDevServer);
599
606
  const perServerRequestDataWithUrls = getPerServerRequestUrls(
600
607
  perServerRequestData,
@@ -606,7 +613,8 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
606
613
  islands,
607
614
  perServerRequestData,
608
615
  indent,
609
- prettyPrint
616
+ prettyPrint,
617
+ isUngatedForClientOnlySupplementalFieldSerialization
610
618
  )}${writeSharedStateToJsGlobal(
611
619
  islands,
612
620
  perServerRequestDataWithUrls,
@@ -638,6 +646,7 @@ function noncePlaceholderPlugin() {
638
646
  }
639
647
  var traverse = _traverse.default;
640
648
  var CMS_MODULE_COMPONENT_NAME = "Module";
649
+ var PLUGIN_NAME = "findCmsModules";
641
650
  function findCmsModules(cmsModules = {}) {
642
651
  let config;
643
652
  return {
@@ -648,80 +657,14 @@ function findCmsModules(cmsModules = {}) {
648
657
  },
649
658
  transform(code, id) {
650
659
  const moduleInfo = this.getModuleInfo(id);
651
- const isExternal = config.command === "serve" ? false : moduleInfo.isExternal;
652
- if (isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME)) {
660
+ if (shouldSkipModule(config, moduleInfo, code))
653
661
  return null;
654
- }
655
- const localCmsModules = {};
656
- const sourceAst = parser.parse(code, {
657
- sourceType: "module",
658
- plugins: ["jsx", "typescript"]
659
- });
660
- let moduleLocalImportName = CMS_MODULE_COMPONENT_NAME;
661
- let moduleUsed = false;
662
- const pluginError = this.error.bind(this);
663
- traverse(sourceAst, {
664
- ImportDeclaration(path2) {
665
- if (!t.isStringLiteral(path2.node.source, {
666
- value: "@hubspot/cms-components"
667
- })) {
668
- return null;
669
- }
670
- for (const specifier of path2.node.specifiers) {
671
- if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
672
- name: CMS_MODULE_COMPONENT_NAME
673
- })) {
674
- moduleLocalImportName = specifier.local.name;
675
- }
676
- }
677
- },
678
- JSXOpeningElement(path2) {
679
- if (!t.isJSXIdentifier(path2.node.name, {
680
- name: moduleLocalImportName
681
- })) {
682
- return null;
683
- }
684
- moduleUsed = true;
685
- let cmsModuleName;
686
- let cmsModulePath;
687
- let cmsModuleLabel;
688
- for (const prop of path2.node.attributes) {
689
- if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
690
- cmsModuleName = prop.value.value;
691
- continue;
692
- }
693
- if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
694
- cmsModulePath = prop.value.value;
695
- continue;
696
- }
697
- if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
698
- cmsModuleLabel = prop.value.value;
699
- continue;
700
- }
701
- pluginError(
702
- new Error(
703
- `Error: ${id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
704
- )
705
- );
706
- return null;
707
- }
708
- const cmsModuleProps = {
709
- name: cmsModuleName,
710
- path: cmsModulePath
711
- };
712
- if (cmsModuleLabel) {
713
- cmsModuleProps.label = cmsModuleLabel;
714
- }
715
- if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
716
- pluginError(
717
- new Error(
718
- `Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
719
- )
720
- );
721
- }
722
- localCmsModules[cmsModuleProps.name] = cmsModuleProps;
723
- }
724
- });
662
+ const { localCmsModules, moduleUsed } = analyzeSourceCodeUsages(
663
+ this,
664
+ moduleInfo,
665
+ config,
666
+ code
667
+ );
725
668
  if (!moduleUsed) {
726
669
  return null;
727
670
  }
@@ -734,95 +677,261 @@ function findCmsModules(cmsModules = {}) {
734
677
  buildEnd(error) {
735
678
  if (error)
736
679
  throw error;
737
- const modulesWithCmsModuleUsage = Array.of(
738
- ...this.getModuleIds()
739
- ).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => this.getModuleInfo(moduleId)).filter(
740
- (moduleInfo) => Object.hasOwn(moduleInfo.meta, "findCmsModules")
680
+ const entryPoints = getEntryPoints(this, config);
681
+ const entryPointCmsModuleMap = buildEntryPointsCmsModuleMap(
682
+ this,
683
+ entryPoints
741
684
  );
742
- const moduleToEntryPoints = {};
743
- for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
744
- moduleToEntryPoints[moduleWithCmsModuleUsage.id] = findEntryPoints(
745
- this,
746
- moduleWithCmsModuleUsage
747
- );
748
- }
749
- for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
750
- const usageInModuleEntryPoint = moduleToEntryPoints[moduleWithCmsModuleUsage.id].find((entryPoint) => entryPoint.id.includes("/components/modules"));
751
- if (usageInModuleEntryPoint) {
752
- this.error(`
753
- Error: <${CMS_MODULE_COMPONENT_NAME} /> can only be used in Partials.
754
- Module: ${usageInModuleEntryPoint.id === moduleWithCmsModuleUsage.id ? usageInModuleEntryPoint.id.replace(config.root, "") : `imports: ${moduleWithCmsModuleUsage.id.replace(
755
- config.root,
756
- ""
757
- )}, which`} contains a <${CMS_MODULE_COMPONENT_NAME} />
685
+ const relativeEntryPointCmsModuleMap = convertEntryPointPathsToRelative(
686
+ config,
687
+ entryPointCmsModuleMap
688
+ );
689
+ const entryPointIslandCmsModuleMap = buildEntryPointIslandsCmsModuleMap(
690
+ this,
691
+ entryPoints
692
+ );
693
+ const relativeEntryPointIslandCmsModuleMap = convertEntryPointIslandPathsToRelative(
694
+ config,
695
+ entryPointIslandCmsModuleMap
696
+ );
697
+ if (Object.keys(relativeEntryPointIslandCmsModuleMap).length > 0) {
698
+ this.error(`
699
+ Error: <Module /> cannot be used within <Island />
700
+ Found invalid usages:
701
+ ${JSON.stringify(relativeEntryPointIslandCmsModuleMap, null, 2)}
758
702
  `);
759
- }
760
703
  }
761
- const root = config.root;
762
- for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
763
- const islandsContainingCmsModuleUsage = checkModuleTreeForIslands(
764
- this,
765
- moduleWithCmsModuleUsage
766
- );
767
- if (islandsContainingCmsModuleUsage.length > 0) {
768
- throw new Error(`
769
- <${CMS_MODULE_COMPONENT_NAME} /> cannot be used within islands.
770
- ${formatIslandImporter(
771
- moduleWithCmsModuleUsage.id,
772
- root
773
- )} uses <${CMS_MODULE_COMPONENT_NAME} /> and is used by islands:
774
- ${islandsContainingCmsModuleUsage.map(
775
- (islandModuleInfo) => formatIslandImporter(islandModuleInfo.id, root)
776
- ).join(", ")}
777
- `);
778
- }
704
+ const modulesWithinModules = filterEntryPointsToModules(
705
+ relativeEntryPointCmsModuleMap
706
+ );
707
+ if (Object.keys(modulesWithinModules).length > 0) {
708
+ this.error(`
709
+ Error: <Module /> can only be used in React Partials
710
+ Found invalid usages:
711
+ ${JSON.stringify(modulesWithinModules, null, 2)}
712
+ `);
779
713
  }
780
- for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
781
- const entryPoints = moduleToEntryPoints[moduleWithCmsModuleUsage.id];
782
- for (const entryPoint of entryPoints) {
783
- const relativeEntryPoint = entryPoint.id.replace(root, "");
784
- if (!Object.hasOwn(cmsModules, relativeEntryPoint)) {
785
- cmsModules[relativeEntryPoint] = {};
786
- }
787
- for (const [cmsModuleName, cmsModuleValue] of Object.entries(
788
- moduleWithCmsModuleUsage.meta.findCmsModules
789
- )) {
790
- if (Object.hasOwn(cmsModules[relativeEntryPoint], cmsModuleName)) {
791
- this.error(`Error: duplicate module name: ${cmsModuleName}`);
792
- }
793
- cmsModules[relativeEntryPoint][cmsModuleName] = cmsModuleValue;
714
+ Object.assign(cmsModules, relativeEntryPointCmsModuleMap);
715
+ }
716
+ };
717
+ }
718
+ function convertEntryPointPathsToRelative(config, entryPointsCmsModuleMap) {
719
+ const relativeEntries = Object.entries(entryPointsCmsModuleMap).map(
720
+ ([entryPointPath, cmsModules]) => {
721
+ return [toRelativePath(config, entryPointPath), cmsModules];
722
+ }
723
+ );
724
+ return Object.fromEntries(relativeEntries);
725
+ }
726
+ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap) {
727
+ const relativeEntries = Object.entries(entryPointsCmsModuleMap).map(
728
+ ([entryPointPath, islandCmsModules]) => {
729
+ const islandCmsModuleUsage = Object.fromEntries(
730
+ Object.entries(islandCmsModules).map(([islandPath, cmsModule]) => {
731
+ return [
732
+ toRelativePath(config, islandPath).replace("?client-entry", ""),
733
+ cmsModule
734
+ ];
735
+ })
736
+ );
737
+ return [toRelativePath(config, entryPointPath), islandCmsModuleUsage];
738
+ }
739
+ );
740
+ return Object.fromEntries(relativeEntries);
741
+ }
742
+ function toRelativePath(config, path2) {
743
+ return path2.replace(config.root, "");
744
+ }
745
+ function shouldSkipModule(config, moduleInfo, code) {
746
+ const isExternal = config.command !== "serve" && moduleInfo.isExternal;
747
+ return isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME);
748
+ }
749
+ function getEntryPoints(ctx, config) {
750
+ return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
751
+ }
752
+ function buildEntryPointsCmsModuleMap(ctx, entryPoints) {
753
+ const entryPointCmsModuleUsage = {};
754
+ for (const entryPoint of entryPoints) {
755
+ const result = findCmsModuleUsages(ctx, entryPoint.id);
756
+ if (result) {
757
+ entryPointCmsModuleUsage[entryPoint.id] = result;
758
+ }
759
+ }
760
+ return entryPointCmsModuleUsage;
761
+ }
762
+ function buildEntryPointIslandsCmsModuleMap(ctx, entryPoints) {
763
+ const entryPointIslandsCmsModuleMap = {};
764
+ for (const entryPoint of entryPoints) {
765
+ const result = findIslandCmsModuleUsage(ctx, entryPoint.id);
766
+ if (result) {
767
+ entryPointIslandsCmsModuleMap[entryPoint.id] = result;
768
+ }
769
+ }
770
+ return entryPointIslandsCmsModuleMap;
771
+ }
772
+ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
773
+ const sourceAst = parser.parse(code, {
774
+ sourceType: "module",
775
+ plugins: ["jsx", "typescript"]
776
+ });
777
+ const localCmsModules = {};
778
+ let moduleUsed = false;
779
+ let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
780
+ traverse(sourceAst, {
781
+ ImportDeclaration(path2) {
782
+ if (t.isStringLiteral(path2.node.source, {
783
+ value: "@hubspot/cms-components"
784
+ })) {
785
+ for (const specifier of path2.node.specifiers) {
786
+ if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
787
+ name: CMS_MODULE_COMPONENT_NAME
788
+ })) {
789
+ moduleComponentLocalImportName = specifier.local.name;
794
790
  }
795
791
  }
796
792
  }
793
+ },
794
+ JSXOpeningElement(path2) {
795
+ if (!t.isJSXIdentifier(path2.node.name, {
796
+ name: moduleComponentLocalImportName
797
+ })) {
798
+ return null;
799
+ }
800
+ moduleUsed = true;
801
+ let cmsModuleName;
802
+ let cmsModulePath;
803
+ let cmsModuleLabel;
804
+ for (const prop of path2.node.attributes) {
805
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
806
+ cmsModuleName = prop.value.value;
807
+ continue;
808
+ }
809
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
810
+ cmsModulePath = prop.value.value;
811
+ continue;
812
+ }
813
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
814
+ cmsModuleLabel = prop.value.value;
815
+ continue;
816
+ }
817
+ ctx.error(
818
+ new Error(
819
+ `Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
820
+ )
821
+ );
822
+ }
823
+ const cmsModuleProps = {
824
+ name: cmsModuleName,
825
+ path: cmsModulePath
826
+ };
827
+ if (cmsModuleLabel) {
828
+ cmsModuleProps.label = cmsModuleLabel;
829
+ }
830
+ if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
831
+ ctx.error(
832
+ new Error(
833
+ `Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
834
+ )
835
+ );
836
+ }
837
+ localCmsModules[cmsModuleProps.name] = cmsModuleProps;
797
838
  }
839
+ });
840
+ return {
841
+ moduleUsed,
842
+ localCmsModules
798
843
  };
799
844
  }
800
- function findEntryPoints(ctx, moduleInfo) {
801
- if (moduleInfo.isEntry) {
802
- return [moduleInfo];
845
+ function findCmsModuleUsages(ctx, moduleId, processed = /* @__PURE__ */ new Set(), result = {}) {
846
+ if (Object.hasOwn(result, moduleId)) {
847
+ return result[moduleId];
803
848
  }
804
- const result = [];
805
- for (const importer of moduleInfo.importers) {
806
- const importerModuleInfo = ctx.getModuleInfo(importer);
807
- const entryPoints = findEntryPoints(ctx, importerModuleInfo);
808
- result.push(...entryPoints);
849
+ const moduleInfo = ctx.getModuleInfo(moduleId);
850
+ let entryPointModules = null;
851
+ if (Object.hasOwn(moduleInfo.meta, PLUGIN_NAME)) {
852
+ entryPointModules = {
853
+ ...entryPointModules,
854
+ ...moduleInfo.meta[PLUGIN_NAME]
855
+ };
809
856
  }
810
- return result;
857
+ for (const importedId of [
858
+ ...moduleInfo.importedIds,
859
+ ...moduleInfo.dynamicallyImportedIds
860
+ ]) {
861
+ if (processed.has(importedId)) {
862
+ continue;
863
+ }
864
+ const importedResult = findCmsModuleUsages(
865
+ ctx,
866
+ importedId,
867
+ processed,
868
+ result
869
+ );
870
+ if (importedResult) {
871
+ entryPointModules = {
872
+ ...entryPointModules,
873
+ ...importedResult
874
+ };
875
+ }
876
+ }
877
+ if (entryPointModules) {
878
+ result[moduleId] = entryPointModules;
879
+ }
880
+ processed.add(moduleId);
881
+ return entryPointModules;
811
882
  }
812
- function checkModuleTreeForIslands(ctx, module) {
813
- if (module.id.endsWith("?client-entry")) {
814
- return [module];
883
+ function findIslandCmsModuleUsage(ctx, moduleId, processedIslands = /* @__PURE__ */ new Set(), islandModuleResults = {}, processed = /* @__PURE__ */ new Set(), results = {}) {
884
+ processedIslands.add(moduleId);
885
+ if (Object.hasOwn(islandModuleResults, moduleId)) {
886
+ return islandModuleResults[moduleId];
815
887
  }
816
- const importerResults = [];
817
- for (const importer of module.importers) {
818
- const importerInfo = ctx.getModuleInfo(importer);
819
- const importerResult = checkModuleTreeForIslands(ctx, importerInfo);
820
- importerResults.push(importerResult);
888
+ const moduleInfo = ctx.getModuleInfo(moduleId);
889
+ let resultForModuleId = {};
890
+ if (moduleInfo.id.endsWith("?client-entry")) {
891
+ const mergedDataDependencies = findCmsModuleUsages(
892
+ ctx,
893
+ moduleInfo.id,
894
+ processed,
895
+ results
896
+ );
897
+ if (mergedDataDependencies) {
898
+ resultForModuleId[moduleInfo.id] = mergedDataDependencies;
899
+ }
900
+ }
901
+ for (const importedId of [
902
+ ...moduleInfo.importedIds,
903
+ ...moduleInfo.dynamicallyImportedIds
904
+ ]) {
905
+ if (processedIslands.has(importedId)) {
906
+ continue;
907
+ }
908
+ const importerCmsModuleUsageResult = findIslandCmsModuleUsage(
909
+ ctx,
910
+ importedId,
911
+ processedIslands,
912
+ islandModuleResults,
913
+ processed,
914
+ results
915
+ );
916
+ if (importerCmsModuleUsageResult) {
917
+ resultForModuleId = {
918
+ ...resultForModuleId,
919
+ ...importerCmsModuleUsageResult
920
+ };
921
+ }
821
922
  }
822
- return importerResults.flat();
923
+ if (Object.keys(resultForModuleId).length > 0) {
924
+ islandModuleResults[moduleId] = resultForModuleId;
925
+ return resultForModuleId;
926
+ }
927
+ return null;
823
928
  }
824
- function formatIslandImporter(id, root) {
825
- return id.replace(root, "").replace("?client-entry", "");
929
+ function filterEntryPointsToModules(entryPointCmsModuleMap) {
930
+ return Object.fromEntries(
931
+ Object.entries(entryPointCmsModuleMap).filter(
932
+ ([entryPoint]) => entryPoint.startsWith("/components/modules/")
933
+ )
934
+ );
826
935
  }
827
936
  var promiseForNewWritableStream = () => {
828
937
  const chunks = [];