@hubspot/cms-dev-server 0.15.8 → 0.15.9

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.
@@ -36,15 +36,13 @@ function namespaceModulePropsShape(props) {
36
36
  import * as dotProp from "dot-prop";
37
37
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
38
38
  import * as cmsComponents from "@hubspot/cms-components";
39
- import React, { isValidElement, cloneElement } from "react";
39
+ import { isValidElement, cloneElement } from "react";
40
40
  var { setProperty, getProperty, hasProperty } = dotProp;
41
41
  var {
42
42
  createServerRenderContextV2: createServerRenderContextV22,
43
43
  createServerRenderContext: createServerRenderContext2,
44
44
  renderServerSidePropsWithAsyncLocalStoreContext
45
45
  } = cmsComponents;
46
- var CMS_COMPONENTS = "@hubspot/cms-components";
47
- var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
48
46
  function renderFieldsJSX(fieldsJSX) {
49
47
  let moduleJson;
50
48
  const outputCallback = (callbackJson) => {
@@ -454,7 +454,6 @@ ${groupEnd}</script>
454
454
  // ../cms-js-internal/dist/index.js
455
455
  var dist_exports = {};
456
456
  __export(dist_exports, {
457
- AUTO_GEN_COMMENT: () => AUTO_GEN_COMMENT,
458
457
  COMPONENT_EXTENSIONS: () => COMPONENT_EXTENSIONS,
459
458
  CSS_LANGS_RE: () => CSS_LANGS_RE,
460
459
  ENABLED_FEATURES_GATE_MAP: () => ENABLED_FEATURES_GATE_MAP,
@@ -464,11 +463,9 @@ __export(dist_exports, {
464
463
  VIRTUAL_CONFIG_SETUP: () => VIRTUAL_CONFIG_SETUP,
465
464
  VIRTUAL_ISLAND_RUNTIME: () => VIRTUAL_ISLAND_RUNTIME,
466
465
  areBuildHealthChecksEnabled: () => areBuildHealthChecksEnabled,
467
- buildTypeFromField: () => buildTypeFromField,
468
466
  clientIslandEntryPlugin: () => clientIslandEntryPlugin,
469
467
  collectCssInDev: () => collectCssInDev,
470
468
  collectCssModules: () => collectCssModules,
471
- constructFinalType: () => constructFinalType,
472
469
  createIslandsGlobalJsForClientInDev: () => createIslandsGlobalJsForClientInDev,
473
470
  doHealthChecksFailTheBuild: () => doHealthChecksFailTheBuild,
474
471
  escapeForInlineJS: () => escapeForInlineJS,
@@ -483,7 +480,6 @@ __export(dist_exports, {
483
480
  getComponentExtension: () => getComponentExtension,
484
481
  getEntryPointHash: () => getEntryPointHash,
485
482
  getEntryPointHashWithIndexSuffix: () => getEntryPointHashWithIndexSuffix,
486
- getFieldTypes: () => getFieldTypes,
487
483
  getIslandRuntimeConfigUrl: () => getIslandRuntimeConfigUrl,
488
484
  getIslandUrls: () => getIslandUrls,
489
485
  getServerGlobalsToInject: () => getServerGlobalsToInject,
@@ -510,8 +506,7 @@ __export(dist_exports, {
510
506
  serializeIslandDataForInlineScript: () => serializeIslandDataForInlineScript,
511
507
  setIn: () => setIn,
512
508
  ungatedAtBuildTimeFor: () => ungatedAtBuildTimeFor,
513
- virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId,
514
- writeFieldsType: () => writeFieldsType
509
+ virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
515
510
  });
516
511
  import * as dotProp from "dot-prop";
517
512
  import { jsx } from "react/jsx-runtime";
@@ -519,9 +514,7 @@ import stream from "stream";
519
514
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
520
515
  import * as cmsComponents from "@hubspot/cms-components";
521
516
  import { ServerRenderContext } from "@hubspot/cms-components";
522
- import { writeFileSync } from "fs";
523
- import ts from "typescript";
524
- import React, { isValidElement, cloneElement } from "react";
517
+ import { isValidElement, cloneElement } from "react";
525
518
  function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
526
519
  if (!supplementalFieldValues) {
527
520
  return supplementalFieldValues;
@@ -647,171 +640,6 @@ async function renderOnServer(elements, renderContext = bootStrapRenderContext()
647
640
  }
648
641
  return { html, renderContext };
649
642
  }
650
- function getFieldEntries(fields) {
651
- if (isValidElement(fields)) {
652
- const fieldsJSX = getChildrenAsArray(fields);
653
- return getReactFieldEntries(fieldsJSX);
654
- } else if (Array.isArray(fields)) {
655
- return getJSONFieldEntries(fields);
656
- }
657
- return void 0;
658
- }
659
- function getReactFieldEntries(fields) {
660
- const validTypeNames = Object.values(fieldTypeNameByType);
661
- if (!Array.isArray(fields)) {
662
- return;
663
- }
664
- return fields.filter((field) => field.props && field.props.name).map((field) => {
665
- const elName = getElementName(field);
666
- const fieldType = getJSXFieldType(getElementName(field));
667
- if (!validTypeNames.includes(fieldType)) {
668
- return void 0;
669
- }
670
- const { name, default: hasDefault } = field.props;
671
- const isRepeater = elName === "RepeatedFieldGroup";
672
- const entry = {
673
- type: fieldType,
674
- name,
675
- hasDefault: !!hasDefault,
676
- isRepeater,
677
- children: []
678
- };
679
- if (fieldType === "GroupFieldType") {
680
- const childrenArray = getChildrenAsArray(field);
681
- const children = getReactFieldEntries(childrenArray);
682
- return {
683
- ...entry,
684
- children
685
- };
686
- }
687
- return entry;
688
- }).filter((entry) => entry !== void 0);
689
- }
690
- function getJSONFieldEntries(fields) {
691
- if (!Array.isArray(fields)) {
692
- return;
693
- }
694
- return fields.filter((field) => field.name && field.type).map((field) => {
695
- const { name, type } = field;
696
- const fieldType = fieldTypeNameByType[type];
697
- if (!fieldType) {
698
- return void 0;
699
- }
700
- const entry = {
701
- type: fieldType,
702
- name,
703
- isRepeater: "occurrence" in field,
704
- hasDefault: !!field.default,
705
- children: []
706
- };
707
- if (fieldType === "GroupFieldType" && "children" in field) {
708
- const children = getJSONFieldEntries(field.children);
709
- return { ...entry, children };
710
- }
711
- return entry;
712
- }).filter((entry) => entry !== void 0);
713
- }
714
- function getImportDeclaration(imports, moduleSpecifier) {
715
- const importSpecifiers = Array.from(imports).map(
716
- (importName) => ts.factory.createImportSpecifier(
717
- true,
718
- void 0,
719
- ts.factory.createIdentifier(importName)
720
- )
721
- );
722
- const namedImports = ts.factory.createNamedImports(importSpecifiers);
723
- return ts.factory.createImportDeclaration(
724
- [],
725
- [],
726
- ts.factory.createImportClause(false, void 0, namedImports),
727
- ts.factory.createStringLiteral(moduleSpecifier)
728
- );
729
- }
730
- function getFieldTypes(fields) {
731
- const imports = ["DefaultValues"];
732
- const types = fields.map((field) => {
733
- if (field.children) {
734
- const childrenResult = getFieldTypes(field.children);
735
- imports.push(...childrenResult.imports);
736
- if (childrenResult.types.length) {
737
- const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
738
- const childrenPropertySignature = createPropertySignature(
739
- "children",
740
- subType
741
- );
742
- const { type: type2, imports: newImports2 } = buildTypeFromField(
743
- field,
744
- field.isRepeater ? subType : childrenPropertySignature
745
- );
746
- imports.push(...newImports2);
747
- return type2;
748
- }
749
- }
750
- const { type, imports: newImports } = buildTypeFromField(field);
751
- imports.push(...newImports);
752
- return type;
753
- });
754
- return { types, imports: Array.from(new Set(imports)) };
755
- }
756
- function constructFinalType(fields, typeName) {
757
- const { types, imports } = getFieldTypes(fields);
758
- const importDeclaration = getImportDeclaration(
759
- imports,
760
- CMS_COMPONENTS_FIELD_TYPES
761
- );
762
- const baseType = ts.factory.createTypeAliasDeclaration(
763
- [],
764
- [],
765
- "",
766
- void 0,
767
- ts.factory.createTypeLiteralNode(types)
768
- );
769
- const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
770
- baseType.type
771
- ]);
772
- const finalType = ts.factory.createTypeAliasDeclaration(
773
- [],
774
- [],
775
- typeName,
776
- void 0,
777
- wrappedType
778
- );
779
- const defaultExport = ts.factory.createExportDefault(
780
- ts.factory.createIdentifier(typeName)
781
- );
782
- return [importDeclaration, finalType, defaultExport];
783
- }
784
- function writeFieldsType(fields, fileName, typeName) {
785
- const entries = getFieldEntries(fields);
786
- if (!entries) {
787
- return false;
788
- }
789
- try {
790
- const file = ts.createSourceFile(
791
- fileName,
792
- "",
793
- ts.ScriptTarget.ESNext,
794
- false,
795
- ts.ScriptKind.TS
796
- );
797
- const printer = ts.createPrinter();
798
- const nodes = constructFinalType(entries, typeName);
799
- const comments = [
800
- AUTO_GEN_COMMENT,
801
- "Removing the above comment will disable type generation for this module",
802
- "This file was created by @hubspot/cms-dev-server, for more information see https://github.hubspot.com/cms-react/reference/js-modules.html#module-fields"
803
- ].map((comment) => `// ${comment}`);
804
- const typeResult = nodes.map(
805
- (node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
806
- );
807
- const result = [...comments, ...typeResult].join("\n");
808
- writeFileSync(fileName, result);
809
- return true;
810
- } catch (e) {
811
- console.error(e);
812
- return false;
813
- }
814
- }
815
643
  function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
816
644
  if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
817
645
  prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
@@ -887,7 +715,7 @@ function renderFieldsToJson(fields, moduleName) {
887
715
  throw e;
888
716
  }
889
717
  }
890
- var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext, fieldTypeNameByType, getChildrenAsArray, getJSXFieldType, getElementName, OVERRIDE_TYPE, REQUIRED_TYPE, REPEATED_VAR, DEFAULT_VALUES_TYPE, CMS_COMPONENTS, CMS_COMPONENTS_FIELD_TYPES, AUTO_GEN_COMMENT, createPropertySignature, buildTypeFromField;
718
+ var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext;
891
719
  var init_dist = __esm({
892
720
  "../cms-js-internal/dist/index.js"() {
893
721
  init_basicUtils();
@@ -1038,100 +866,6 @@ ${indentString}`);
1038
866
  }) : createServerRenderContext2("", null);
1039
867
  return renderContext;
1040
868
  };
1041
- fieldTypeNameByType = {
1042
- alignment: "AlignmentFieldType",
1043
- audioplayer: "AudioFieldType",
1044
- backgroundimage: "BackgroundImageFieldType",
1045
- blog: "BlogFieldType",
1046
- boolean: "BooleanFieldType",
1047
- border: "BorderFieldType",
1048
- choice: "ChoiceFieldType",
1049
- color: "ColorFieldType",
1050
- crmobject: "CrmObjectFieldType",
1051
- cta: "CtaFieldType",
1052
- date: "DateFieldType",
1053
- datetime: "DateTimeFieldType",
1054
- email: "EmailFieldType",
1055
- embed: "EmbedFieldType",
1056
- file: "FileFieldType",
1057
- followupemail: "FollowUpEmailFieldType",
1058
- font: "FontFieldType",
1059
- form: "FormFieldType",
1060
- gradient: "GradientFieldType",
1061
- group: "GroupFieldType",
1062
- html: "HtmlFieldType",
1063
- hubdbrow: "HubDbRowFieldType",
1064
- hubdbtable: "HubDbTableFieldType",
1065
- hubl: "HublFieldType",
1066
- icon: "IconFieldType",
1067
- image: "ImageFieldType",
1068
- link: "LinkFieldType",
1069
- logo: "LogoFieldType",
1070
- meeting: "MeetingFieldType",
1071
- menu: "MenuFieldType",
1072
- number: "NumberFieldType",
1073
- page: "PageFieldType",
1074
- payment: "PaymentFieldType",
1075
- podcast: "PodcastFieldType",
1076
- richtext: "RichTextFieldType",
1077
- salesforcecampaign: "SfdcCamapaignFieldType",
1078
- simplemenu: "SimpleMenuFieldType",
1079
- spacing: "SpacingFieldType",
1080
- survey: "SurveyFieldType",
1081
- tag: "TagFieldType",
1082
- textalignment: "TextAlignmentFieldType",
1083
- text: "TextFieldType",
1084
- url: "UrlFieldType",
1085
- video: "VideoFieldType",
1086
- workflow: "WorkflowFieldType"
1087
- };
1088
- getChildrenAsArray = (element) => React.Children.toArray(element.props.children);
1089
- getJSXFieldType = (fieldFunctionName) => {
1090
- switch (fieldFunctionName) {
1091
- case "RepeatedFieldGroup":
1092
- case "FieldGroup":
1093
- return "GroupFieldType";
1094
- default:
1095
- return `${fieldFunctionName}Type`;
1096
- }
1097
- };
1098
- getElementName = (element) => typeof element.type === "string" ? element.type : element.type.name || null;
1099
- OVERRIDE_TYPE = "Override";
1100
- REQUIRED_TYPE = "Required";
1101
- REPEATED_VAR = "_repeater";
1102
- DEFAULT_VALUES_TYPE = "DefaultValues";
1103
- CMS_COMPONENTS = "@hubspot/cms-components";
1104
- CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
1105
- AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
1106
- createPropertySignature = (identifier, type) => ts.factory.createPropertySignature([], identifier, void 0, type);
1107
- buildTypeFromField = (field, additionalNode) => {
1108
- const imports = [field.type];
1109
- const identifier = ts.factory.createIdentifier(field.name);
1110
- const baseType = ts.factory.createTypeReferenceNode(field.type);
1111
- const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
1112
- baseType
1113
- ]);
1114
- let finalType = field.hasDefault ? requiredType : baseType;
1115
- if (additionalNode) {
1116
- const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
1117
- const repeaterName = ts.factory.createLiteralTypeNode(
1118
- ts.factory.createStringLiteral(REPEATED_VAR)
1119
- );
1120
- if (!field.isRepeater) {
1121
- imports.push(OVERRIDE_TYPE);
1122
- }
1123
- finalType = field.isRepeater ? ts.factory.createTypeReferenceNode("Array", [
1124
- ts.factory.createTypeReferenceNode("Record", [
1125
- repeaterName,
1126
- typeLiteral
1127
- ])
1128
- ]) : ts.factory.createTypeReferenceNode(OVERRIDE_TYPE, [
1129
- finalType,
1130
- typeLiteral
1131
- ]);
1132
- }
1133
- return { type: createPropertySignature(identifier, finalType), imports };
1134
- };
1135
869
  }
1136
870
  });
1137
871
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.15.8",
3
+ "version": "0.15.9",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@hubspot/cli-lib": "^3.0.12",
29
- "@hubspot/cms-components": "^0.15.8",
29
+ "@hubspot/cms-components": "^0.15.9",
30
30
  "@inquirer/select": "^2.0.0",
31
31
  "@originjs/vite-plugin-commonjs": "^1.0.3",
32
32
  "@storybook/addon-actions": "7.0.7",
@@ -108,5 +108,5 @@
108
108
  "publishConfig": {
109
109
  "access": "public"
110
110
  },
111
- "gitHead": "9a5e9512c41af68242b0be979cffd0420a37fe8f"
111
+ "gitHead": "cfcc32d943ef0221d9c7a8f191a908538018c583"
112
112
  }