@hubspot/cms-dev-server 0.18.2 → 0.18.5

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.
@@ -1,4 +1,4 @@
1
- // ../cms-js-internal/dist/basicUtils.js
1
+ // ../cms-js-internal/dist/types-BXr0V0Zd.js
2
2
  import path from "path";
3
3
  import { createHash } from "crypto";
4
4
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
@@ -535,7 +535,7 @@ function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplem
535
535
  return result;
536
536
  }
537
537
  var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
538
- const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
538
+ const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x2) => !!x2);
539
539
  if (sharedStateIDs.length > 0) {
540
540
  const indentString = " ".repeat(indent);
541
541
  const stateByID = {};
@@ -646,8 +646,9 @@ function noncePlaceholderPlugin() {
646
646
  }
647
647
  var traverse = _traverse.default;
648
648
  var CMS_MODULE_COMPONENT_NAME = "Module";
649
+ var DND_AREA_COMPONENT_NAME = "DndArea";
649
650
  var PLUGIN_NAME = "findCmsModules";
650
- function findCmsModules(cmsModules = {}) {
651
+ function findCmsModules(buildContentDescriptors = {}) {
651
652
  let config;
652
653
  return {
653
654
  enforce: "pre",
@@ -659,20 +660,20 @@ function findCmsModules(cmsModules = {}) {
659
660
  const moduleInfo = this.getModuleInfo(id);
660
661
  if (shouldSkipModule(config, moduleInfo, code))
661
662
  return null;
662
- const { localCmsModules, moduleUsed } = analyzeSourceCodeUsages(
663
+ const contentDescriptors = analyzeSourceCodeUsages(
663
664
  this,
664
665
  moduleInfo,
665
666
  config,
666
667
  code
667
668
  );
668
- if (!moduleUsed) {
669
- return null;
669
+ if (Object.keys(contentDescriptors.dndAreas).length > 0 || Object.keys(contentDescriptors.modules).length > 0) {
670
+ return {
671
+ meta: {
672
+ findCmsModules: contentDescriptors
673
+ }
674
+ };
670
675
  }
671
- return {
672
- meta: {
673
- findCmsModules: localCmsModules
674
- }
675
- };
676
+ return null;
676
677
  },
677
678
  buildEnd(error) {
678
679
  if (error)
@@ -711,7 +712,7 @@ function findCmsModules(cmsModules = {}) {
711
712
  ${JSON.stringify(modulesWithinModules, null, 2)}
712
713
  `);
713
714
  }
714
- Object.assign(cmsModules, relativeEntryPointCmsModuleMap);
715
+ Object.assign(buildContentDescriptors, relativeEntryPointCmsModuleMap);
715
716
  }
716
717
  };
717
718
  }
@@ -725,14 +726,16 @@ function convertEntryPointPathsToRelative(config, entryPointsCmsModuleMap) {
725
726
  }
726
727
  function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap) {
727
728
  const relativeEntries = Object.entries(entryPointsCmsModuleMap).map(
728
- ([entryPointPath, islandCmsModules]) => {
729
+ ([entryPointPath, islandContentDescriptors]) => {
729
730
  const islandCmsModuleUsage = Object.fromEntries(
730
- Object.entries(islandCmsModules).map(([islandPath, cmsModule]) => {
731
- return [
732
- toRelativePath(config, islandPath).replace("?client-entry", ""),
733
- cmsModule
734
- ];
735
- })
731
+ Object.entries(islandContentDescriptors).map(
732
+ ([islandPath, contentDescriptors]) => {
733
+ return [
734
+ toRelativePath(config, islandPath).replace("?client-entry", ""),
735
+ contentDescriptors
736
+ ];
737
+ }
738
+ )
736
739
  );
737
740
  return [toRelativePath(config, entryPointPath), islandCmsModuleUsage];
738
741
  }
@@ -744,7 +747,7 @@ function toRelativePath(config, path2) {
744
747
  }
745
748
  function shouldSkipModule(config, moduleInfo, code) {
746
749
  const isExternal = config.command !== "serve" && moduleInfo.isExternal;
747
- return isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME);
750
+ return isExternal || !moduleInfo.id.startsWith(config.root) || !(code.includes(CMS_MODULE_COMPONENT_NAME) || code.includes(DND_AREA_COMPONENT_NAME));
748
751
  }
749
752
  function getEntryPoints(ctx, config) {
750
753
  return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
@@ -774,9 +777,9 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
774
777
  sourceType: "module",
775
778
  plugins: ["jsx", "typescript"]
776
779
  });
777
- const localCmsModules = {};
778
- let moduleUsed = false;
780
+ const contentDescriptors = { modules: {}, dndAreas: {} };
779
781
  let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
782
+ let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
780
783
  traverse(sourceAst, {
781
784
  ImportDeclaration(path2) {
782
785
  if (t.isStringLiteral(path2.node.source, {
@@ -788,69 +791,96 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
788
791
  })) {
789
792
  moduleComponentLocalImportName = specifier.local.name;
790
793
  }
794
+ if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
795
+ name: DND_AREA_COMPONENT_NAME
796
+ })) {
797
+ dndAreaComponentLocalImportName = specifier.local.name;
798
+ }
791
799
  }
792
800
  }
793
801
  },
794
802
  JSXOpeningElement(path2) {
795
- if (!t.isJSXIdentifier(path2.node.name, {
803
+ if (t.isJSXIdentifier(path2.node.name, {
796
804
  name: moduleComponentLocalImportName
797
805
  })) {
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;
806
+ let cmsModuleName;
807
+ let cmsModulePath;
808
+ let cmsModuleLabel;
809
+ for (const prop of path2.node.attributes) {
810
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
811
+ cmsModuleName = prop.value.value;
812
+ continue;
813
+ }
814
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
815
+ cmsModulePath = prop.value.value;
816
+ continue;
817
+ }
818
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
819
+ cmsModuleLabel = prop.value.value;
820
+ continue;
821
+ }
822
+ ctx.error(
823
+ new Error(
824
+ `Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
825
+ )
826
+ );
808
827
  }
809
- if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
810
- cmsModulePath = prop.value.value;
811
- continue;
828
+ const cmsModuleProps = {
829
+ name: cmsModuleName,
830
+ path: cmsModulePath
831
+ };
832
+ if (cmsModuleLabel) {
833
+ cmsModuleProps.label = cmsModuleLabel;
812
834
  }
813
- if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
814
- cmsModuleLabel = prop.value.value;
815
- continue;
835
+ if (Object.hasOwn(contentDescriptors.modules, cmsModuleProps.name)) {
836
+ ctx.error(
837
+ new Error(
838
+ `Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
839
+ )
840
+ );
816
841
  }
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;
842
+ contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
829
843
  }
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
- );
844
+ if (t.isJSXIdentifier(path2.node.name, {
845
+ name: dndAreaComponentLocalImportName
846
+ })) {
847
+ let dndAreaName;
848
+ for (const prop of path2.node.attributes) {
849
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
850
+ dndAreaName = prop.value.value;
851
+ continue;
852
+ }
853
+ ctx.error(
854
+ new Error(
855
+ `Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" must a primitive string`
856
+ )
857
+ );
858
+ }
859
+ const dndArea = {
860
+ name: dndAreaName
861
+ };
862
+ if (Object.hasOwn(contentDescriptors.dndAreas, dndArea.name)) {
863
+ ctx.error(
864
+ new Error(
865
+ `Error: multiple <${DND_AREA_COMPONENT_NAME} /> with duplicate name: ${dndArea.name}`
866
+ )
867
+ );
868
+ }
869
+ contentDescriptors.dndAreas[dndArea.name] = dndArea;
836
870
  }
837
- localCmsModules[cmsModuleProps.name] = cmsModuleProps;
838
871
  }
839
872
  });
840
- return {
841
- moduleUsed,
842
- localCmsModules
843
- };
873
+ return contentDescriptors;
844
874
  }
845
875
  function findCmsModuleUsages(ctx, moduleId, processed = /* @__PURE__ */ new Set(), result = {}) {
846
876
  if (Object.hasOwn(result, moduleId)) {
847
877
  return result[moduleId];
848
878
  }
849
879
  const moduleInfo = ctx.getModuleInfo(moduleId);
850
- let entryPointModules = null;
880
+ let entryPointContentDescriptors = null;
851
881
  if (Object.hasOwn(moduleInfo.meta, PLUGIN_NAME)) {
852
- entryPointModules = {
853
- ...entryPointModules,
882
+ entryPointContentDescriptors = {
883
+ ...entryPointContentDescriptors,
854
884
  ...moduleInfo.meta[PLUGIN_NAME]
855
885
  };
856
886
  }
@@ -868,17 +898,17 @@ function findCmsModuleUsages(ctx, moduleId, processed = /* @__PURE__ */ new Set(
868
898
  result
869
899
  );
870
900
  if (importedResult) {
871
- entryPointModules = {
872
- ...entryPointModules,
901
+ entryPointContentDescriptors = {
902
+ ...entryPointContentDescriptors,
873
903
  ...importedResult
874
904
  };
875
905
  }
876
906
  }
877
- if (entryPointModules) {
878
- result[moduleId] = entryPointModules;
907
+ if (entryPointContentDescriptors) {
908
+ result[moduleId] = entryPointContentDescriptors;
879
909
  }
880
910
  processed.add(moduleId);
881
- return entryPointModules;
911
+ return entryPointContentDescriptors;
882
912
  }
883
913
  function findIslandCmsModuleUsage(ctx, moduleId, processedIslands = /* @__PURE__ */ new Set(), islandModuleResults = {}, processed = /* @__PURE__ */ new Set(), results = {}) {
884
914
  processedIslands.add(moduleId);
@@ -1094,9 +1124,9 @@ function renderFieldsToJson(fields, moduleName) {
1094
1124
  );
1095
1125
  }
1096
1126
  return fieldsJSON;
1097
- } catch (e) {
1098
- e.message = `Error when rendering fields for ${moduleName}: ${e.message}`;
1099
- throw e;
1127
+ } catch (e2) {
1128
+ e2.message = `Error when rendering fields for ${moduleName}: ${e2.message}`;
1129
+ throw e2;
1100
1130
  }
1101
1131
  }
1102
1132
  export {