@hubspot/cms-dev-server 0.18.11 → 0.18.13

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.
package/dist/index.js CHANGED
@@ -584,8 +584,8 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
584
584
  );
585
585
  return Object.fromEntries(relativeEntries);
586
586
  }
587
- function toRelativePath(config, path13) {
588
- return path13.replace(`${config.root}/`, "");
587
+ function toRelativePath(config, path15) {
588
+ return path15.replace(`${config.root}/`, "");
589
589
  }
590
590
  function shouldSkipModule(config, moduleInfo, code) {
591
591
  const isExternal = config.command !== "serve" && moduleInfo.isExternal;
@@ -623,11 +623,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
623
623
  let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
624
624
  let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
625
625
  traverse(sourceAst, {
626
- ImportDeclaration(path13) {
627
- if (t.isStringLiteral(path13.node.source, {
626
+ ImportDeclaration(path15) {
627
+ if (t.isStringLiteral(path15.node.source, {
628
628
  value: "@hubspot/cms-components"
629
629
  })) {
630
- for (const specifier of path13.node.specifiers) {
630
+ for (const specifier of path15.node.specifiers) {
631
631
  if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
632
632
  name: CMS_MODULE_COMPONENT_NAME
633
633
  })) {
@@ -641,14 +641,14 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
641
641
  }
642
642
  }
643
643
  },
644
- JSXOpeningElement(path13) {
645
- if (t.isJSXIdentifier(path13.node.name, {
644
+ JSXOpeningElement(path15) {
645
+ if (t.isJSXIdentifier(path15.node.name, {
646
646
  name: moduleComponentLocalImportName
647
647
  })) {
648
648
  let cmsModuleName;
649
649
  let cmsModulePath;
650
650
  let cmsModuleLabel;
651
- for (const prop of path13.node.attributes) {
651
+ for (const prop of path15.node.attributes) {
652
652
  if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
653
653
  cmsModuleName = prop.value.value;
654
654
  continue;
@@ -683,11 +683,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
683
683
  }
684
684
  contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
685
685
  }
686
- if (t.isJSXIdentifier(path13.node.name, {
686
+ if (t.isJSXIdentifier(path15.node.name, {
687
687
  name: dndAreaComponentLocalImportName
688
688
  })) {
689
689
  let dndAreaName;
690
- for (const prop of path13.node.attributes) {
690
+ for (const prop of path15.node.attributes) {
691
691
  if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
692
692
  dndAreaName = prop.value.value;
693
693
  continue;
@@ -1029,17 +1029,17 @@ Custom origin: ${process.env.VITE_ORIGIN}
1029
1029
  var createViteDevServer_default = createViteDevServer;
1030
1030
 
1031
1031
  // src/createDevServer.ts
1032
- import path12 from "path";
1032
+ import path14 from "path";
1033
1033
  import url2 from "url";
1034
1034
  import express3 from "express";
1035
1035
  import http3 from "http";
1036
1036
  import bodyParser from "body-parser";
1037
1037
  import { spawn } from "child_process";
1038
- import { normalizePath as normalizePath7 } from "vite";
1038
+ import { normalizePath as normalizePath9 } from "vite";
1039
1039
  import { Transform } from "stream";
1040
1040
 
1041
1041
  // src/routes/createDevServerRoutes.ts
1042
- import { Router } from "express";
1042
+ import { Router, urlencoded } from "express";
1043
1043
  import { createProxyMiddleware } from "http-proxy-middleware";
1044
1044
 
1045
1045
  // src/routes/partial.ts
@@ -1455,7 +1455,7 @@ function trackUsage(action) {
1455
1455
  eventName: EVENT_NAME,
1456
1456
  action,
1457
1457
  nodeVersion: getNodeVersionData(),
1458
- version: "0.18.11",
1458
+ version: "0.18.13",
1459
1459
  os: getPlatform()
1460
1460
  };
1461
1461
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -1528,12 +1528,12 @@ var findLocalRenderPlaceholders = (body) => {
1528
1528
  );
1529
1529
  offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
1530
1530
  if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
1531
- const path13 = body.substring(
1531
+ const path15 = body.substring(
1532
1532
  startOffset + localJsRenderStartString.length,
1533
1533
  pathEndOffset
1534
1534
  );
1535
1535
  offsetSoFar = pathEndOffset + 1;
1536
- if (startOffset >= 0 && path13) {
1536
+ if (startOffset >= 0 && path15) {
1537
1537
  const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
1538
1538
  const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
1539
1539
  offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
@@ -1558,7 +1558,7 @@ var findLocalRenderPlaceholders = (body) => {
1558
1558
  result.push({
1559
1559
  startOffset,
1560
1560
  endOffset: endOffset + localJsRenderEndString.length,
1561
- path: path13,
1561
+ path: path15,
1562
1562
  json
1563
1563
  });
1564
1564
  }
@@ -1603,7 +1603,6 @@ import { http as hsCliHttp6 } from "@hubspot/local-dev-lib/http";
1603
1603
 
1604
1604
  // src/lib/renderModule.ts
1605
1605
  import { join as joinPosix2 } from "path/posix";
1606
- import { traverseFieldsJSON } from "@hubspot/cms-components/fields";
1607
1606
  import * as cmsComponents2 from "@hubspot/cms-components";
1608
1607
  import { http as hsCliHttp3 } from "@hubspot/local-dev-lib/http";
1609
1608
 
@@ -1633,6 +1632,16 @@ async function fetchModuleGraphQLData(accountId, query, requestedModulePath, pag
1633
1632
  return dataQueryResult;
1634
1633
  }
1635
1634
 
1635
+ // src/lib/getFieldValuesForModule.ts
1636
+ import { traverseFieldsJSON } from "@hubspot/cms-components/fields";
1637
+ function getFieldValuesForModule(fieldsJSON, fieldOverrides = {}) {
1638
+ const props = {};
1639
+ traverseFieldsJSON(fieldsJSON, fieldOverrides, (fieldPathArray, value) => {
1640
+ setIn(props, fieldPathArray, value);
1641
+ });
1642
+ return props;
1643
+ }
1644
+
1636
1645
  // src/lib/renderModule.ts
1637
1646
  var VALIDATE_FIELDS_ENDPOINT = "/designmanager/v1/modules/validate-fields";
1638
1647
  var VALIDATE_META_ENDPOINT = "/designmanager/v1/modules/validate-meta";
@@ -1849,13 +1858,6 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
1849
1858
  componentModule.unstable_modifyHtml
1850
1859
  ).then(applyFieldsValidationToRenderContext);
1851
1860
  }
1852
- function getFieldValuesForModule(fieldsJSON, fieldOverrides = {}) {
1853
- const props = {};
1854
- traverseFieldsJSON(fieldsJSON, fieldOverrides, (fieldPathArray, value) => {
1855
- setIn(props, fieldPathArray, value);
1856
- });
1857
- return props;
1858
- }
1859
1861
  var renderModule_default = renderModule;
1860
1862
 
1861
1863
  // src/proxyPage/utils.ts
@@ -1935,9 +1937,9 @@ var customColors = [
1935
1937
  ];
1936
1938
  var Converter = new AnsiToHtmlConverter({ colors: customColors });
1937
1939
  var darkErrorStyles = `background-color: #222; color: #ccc; padding: 0.5em; font-family: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace;`;
1938
- var renderLocalError_default = (path13, error) => {
1940
+ var renderLocalError_default = (path15, error) => {
1939
1941
  const stackWithColorClasses = Converter.toHtml(error.stack);
1940
- return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path13}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
1942
+ return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path15}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
1941
1943
  };
1942
1944
 
1943
1945
  // src/proxyPage/fetchPreviewInfo.ts
@@ -2758,7 +2760,7 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
2758
2760
  const cssNeeded = Array.from(dom.window.document.querySelectorAll("style")).map((element) => element.outerHTML).join("");
2759
2761
  return { html: modulePreviewContent, cssNeeded };
2760
2762
  }
2761
- async function renderLocalProjectModulePreview(moduleName, authedPortalId, authedEnv, authedHublet, webRoot, viteServer, jsRenderingGates, projectName, projectComponentPath, fullOriginalUrl, cookieValue) {
2763
+ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authedEnv, authedHublet, webRoot, viteServer, jsRenderingGates, projectName, projectComponentPath, fullOriginalUrl, cookieValue, fieldOverrides = {}) {
2762
2764
  const modulePath = normalizePath3(
2763
2765
  path6.resolve(webRoot, "components/modules/", moduleName)
2764
2766
  );
@@ -2801,6 +2803,10 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
2801
2803
  const internalSsrPath = packagePath(import.meta.url, "internalSsr");
2802
2804
  const { renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath);
2803
2805
  const localFieldsJson = renderFieldsToJson(fields, modulePath);
2806
+ const localFieldValues = getFieldValuesForModule(
2807
+ localFieldsJson,
2808
+ fieldOverrides
2809
+ );
2804
2810
  const localModule = {
2805
2811
  isJsModule: true,
2806
2812
  schemaVersion: 2,
@@ -2841,6 +2847,7 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
2841
2847
  `
2842
2848
  );
2843
2849
  }
2850
+ localRenderPlaceholders[0].json.props.fieldValues = localFieldValues;
2844
2851
  return await renderComponentForPlaceholder(
2845
2852
  0,
2846
2853
  localRenderPlaceholders[0],
@@ -3198,6 +3205,74 @@ ${e.stack}`);
3198
3205
  };
3199
3206
  var module_default = moduleRouteHandler;
3200
3207
 
3208
+ // src/routes/moduleFieldsJson.ts
3209
+ import path9 from "path";
3210
+ import { normalizePath as normalizePath6 } from "vite";
3211
+
3212
+ // src/lib/renderModuleFieldsJson.ts
3213
+ import { join as joinPosix4 } from "path/posix";
3214
+ var lookForModuleInFolder3 = async (modulePath, viteServer) => {
3215
+ let componentModule;
3216
+ const insideFolderPath = joinPosix4(modulePath, "index");
3217
+ try {
3218
+ componentModule = await viteServer.ssrLoadModule(insideFolderPath);
3219
+ } catch (e) {
3220
+ if (!e.message.includes("Failed to load url")) {
3221
+ throw e;
3222
+ }
3223
+ }
3224
+ return [componentModule, insideFolderPath];
3225
+ };
3226
+ async function renderModuleFieldsJson(viteServer, requestedModulePath) {
3227
+ let componentModule;
3228
+ try {
3229
+ if (!hasComponentExtension(requestedModulePath)) {
3230
+ [componentModule] = await lookForModuleInFolder3(
3231
+ requestedModulePath,
3232
+ viteServer
3233
+ );
3234
+ }
3235
+ if (!componentModule) {
3236
+ componentModule = await viteServer.ssrLoadModule(requestedModulePath);
3237
+ }
3238
+ } catch (error) {
3239
+ throw new Error(
3240
+ `Failed to load module ${requestedModulePath}: ${error.message}`
3241
+ );
3242
+ }
3243
+ if (!componentModule) {
3244
+ throw new Error(`Couldn't find module: ${requestedModulePath}`);
3245
+ }
3246
+ const internalSsrPath = packagePath(import.meta.url, "internalSsr");
3247
+ const { renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath);
3248
+ const fieldsJson = renderFieldsToJson(
3249
+ componentModule.fields,
3250
+ requestedModulePath
3251
+ );
3252
+ return fieldsJson;
3253
+ }
3254
+ var renderModuleFieldsJson_default = renderModuleFieldsJson;
3255
+
3256
+ // src/routes/moduleFieldsJson.ts
3257
+ var moduleFieldsJsonRouteHandler = async (request2, response) => {
3258
+ try {
3259
+ sendTrackingRequest("fields-json-route");
3260
+ const { webRoot, viteServer } = request2.app.locals;
3261
+ const { moduleName } = request2.params;
3262
+ const modulePath = normalizePath6(
3263
+ path9.resolve(webRoot, "components/modules/", moduleName)
3264
+ );
3265
+ const fieldsJson = await renderModuleFieldsJson_default(viteServer, modulePath);
3266
+ return response.status(200).set({ "Content-Type": "application/json" }).json(fieldsJson);
3267
+ } catch (error) {
3268
+ console.error("Error processing module fields.json:", error);
3269
+ return response.status(500).json({
3270
+ error: "Failed to process module fields"
3271
+ });
3272
+ }
3273
+ };
3274
+ var moduleFieldsJson_default = moduleFieldsJsonRouteHandler;
3275
+
3201
3276
  // src/proxyPage/fetchContentMetadata.ts
3202
3277
  import http from "http";
3203
3278
  import https from "https";
@@ -3411,16 +3486,20 @@ async function fetchPreviewTemplates(accountId, previewToken) {
3411
3486
  url: `${DESIGN_MANAGER_API_PATH}/templates/local-preview?previewToken=${previewToken}`
3412
3487
  })).data;
3413
3488
  }
3414
- async function fetchModuleByPath(accountId, path13) {
3489
+ async function fetchModuleByPath(accountId, path15) {
3415
3490
  return (await hsCliHttp8.get(accountId, {
3416
- url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${path13}?portalId=${accountId}`
3491
+ url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${path15}?portalId=${accountId}`
3417
3492
  })).data;
3418
3493
  }
3419
- async function fetchTemplateByPath(accountId, path13) {
3494
+ async function fetchTemplateByPath(accountId, path15) {
3420
3495
  return (await hsCliHttp8.get(accountId, {
3421
- url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${path13}?portalId=${accountId}`
3496
+ url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${path15}?portalId=${accountId}`
3422
3497
  })).data;
3423
3498
  }
3499
+ async function fetchModulePageDependencies(accountId, path15) {
3500
+ const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${path15}`;
3501
+ return (await hsCliHttp8.get(accountId, { url: url3 })).data;
3502
+ }
3424
3503
 
3425
3504
  // src/components/HubLTemplatesList.tsx
3426
3505
  import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
@@ -3660,8 +3739,8 @@ function proxyServerlessRequest(req, res, next) {
3660
3739
  }
3661
3740
 
3662
3741
  // src/routes/modulePreviewRouteHandler.ts
3663
- import path9 from "path";
3664
- import { normalizePath as normalizePath6 } from "vite";
3742
+ import path10 from "path";
3743
+ import { normalizePath as normalizePath7 } from "vite";
3665
3744
  async function modulePreviewRouteHandler(request2, response) {
3666
3745
  sendTrackingRequest("view-module-preview-route");
3667
3746
  const {
@@ -3675,9 +3754,46 @@ async function modulePreviewRouteHandler(request2, response) {
3675
3754
  projectComponentPath
3676
3755
  } = request2.app.locals;
3677
3756
  const moduleName = request2.params.moduleName;
3678
- const modulePath = normalizePath6(
3679
- path9.resolve(webRoot, "components/modules/", moduleName)
3757
+ const modulePath = normalizePath7(
3758
+ path10.resolve(webRoot, "components/modules/", moduleName)
3680
3759
  );
3760
+ const PREVIEWER_APP_PARAM = "hsPreviewerApp";
3761
+ let fieldOverrides = {};
3762
+ if (request2.method === "POST" && request2.body) {
3763
+ if (request2.query[PREVIEWER_APP_PARAM] === "module" && request2.body.module_data) {
3764
+ fieldOverrides = request2.body.module_data;
3765
+ } else {
3766
+ fieldOverrides = request2.body;
3767
+ }
3768
+ try {
3769
+ if (typeof fieldOverrides === "string") {
3770
+ const parsedFieldOverrides = JSON.parse(fieldOverrides);
3771
+ if (parsedFieldOverrides && typeof parsedFieldOverrides === "object" && !Array.isArray(parsedFieldOverrides)) {
3772
+ fieldOverrides = parsedFieldOverrides;
3773
+ } else {
3774
+ throw new Error("Parsed field overrides must be an object");
3775
+ }
3776
+ }
3777
+ } catch (e) {
3778
+ console.error(
3779
+ `Error parsing field for module "${moduleName}": ${e.message}`,
3780
+ "\nReceived value:",
3781
+ fieldOverrides
3782
+ );
3783
+ }
3784
+ } else if (request2.query.fields) {
3785
+ try {
3786
+ if (typeof request2.query.fields === "string") {
3787
+ fieldOverrides = JSON.parse(
3788
+ decodeURIComponent(request2.query.fields.replace(/\+/g, "%20"))
3789
+ );
3790
+ }
3791
+ } catch (e) {
3792
+ console.error(
3793
+ `Error parsing field param for module ${moduleName}: ${request2.query.fields}`
3794
+ );
3795
+ }
3796
+ }
3681
3797
  try {
3682
3798
  const {
3683
3799
  html: renderedHtml,
@@ -3695,7 +3811,8 @@ async function modulePreviewRouteHandler(request2, response) {
3695
3811
  projectName,
3696
3812
  projectComponentPath,
3697
3813
  fullOriginalUrlFromRequest(request2),
3698
- request2.get("COOKIE")
3814
+ request2.get("COOKIE"),
3815
+ fieldOverrides
3699
3816
  );
3700
3817
  const baseTemplatePath = packagePath(
3701
3818
  import.meta.url,
@@ -3891,6 +4008,7 @@ var createDevServerRoutes = async (viteServer, storybookPort) => {
3891
4008
  );
3892
4009
  }
3893
4010
  devServerApp.use(viteServer.middlewares);
4011
+ devServerApp.use(urlencoded());
3894
4012
  devServerApp.get("/proxy", proxyPathPageRouteHandler);
3895
4013
  devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
3896
4014
  devServerApp.get("/partial/:partial", partial_default);
@@ -3899,7 +4017,12 @@ var createDevServerRoutes = async (viteServer, storybookPort) => {
3899
4017
  devServerApp.get("/preview/module/:moduleName", modulePreviewRouteHandler_default);
3900
4018
  devServerApp.get("/modules/", linksToAllModulesRouteHandler_default);
3901
4019
  devServerApp.get("/module/:moduleName", module_default);
4020
+ devServerApp.get(
4021
+ "/preview/module/:moduleName/fields.json",
4022
+ moduleFieldsJson_default
4023
+ );
3902
4024
  devServerApp.get("/module/:moduleName/*", module_default);
4025
+ devServerApp.post("/preview/module/:moduleName", modulePreviewRouteHandler_default);
3903
4026
  devServerApp.get("/hublmodule/:modulePath(*)", hublModuleRouteHandler);
3904
4027
  devServerApp.get("/template/:templatePath(*)", templateRouteHandler);
3905
4028
  devServerApp.all("/hs/serverless/*", proxyServerlessRequest);
@@ -4057,33 +4180,67 @@ import { createServer as createViteServer2 } from "vite";
4057
4180
  import { default as react2 } from "@vitejs/plugin-react";
4058
4181
 
4059
4182
  // src/lib/getDevServerUIData.ts
4183
+ import path11 from "path";
4184
+ import { normalizePath as normalizePath8 } from "vite";
4185
+ function mapModulesData(modules, themeWebRoot, viteServer) {
4186
+ return Promise.all(
4187
+ modules.moduleNames.map(async (name, index) => {
4188
+ const modulePath = normalizePath8(
4189
+ path11.resolve(themeWebRoot, "components/modules/", name)
4190
+ );
4191
+ const fieldsJson = await renderModuleFieldsJson_default(viteServer, modulePath);
4192
+ return {
4193
+ name,
4194
+ subPath: modules.moduleSubpaths[index],
4195
+ nameWithExtension: modules.moduleNamesWithExtension[index],
4196
+ fieldsJson
4197
+ };
4198
+ })
4199
+ );
4200
+ }
4201
+ function mapPartialsData(modules) {
4202
+ return modules.partialNames.map((name, index) => ({
4203
+ name,
4204
+ subPath: modules.partialSubpaths[index]
4205
+ }));
4206
+ }
4060
4207
  async function getDevServerUIData(reqLocals) {
4061
4208
  const {
4062
4209
  themeWebRoot,
4063
4210
  authedPortalId,
4064
4211
  projectName,
4065
4212
  localPreviewToken,
4066
- webRootProjectComponentFolder
4213
+ webRootProjectComponentFolder,
4214
+ viteServer
4067
4215
  } = reqLocals;
4068
- const { moduleNames, moduleNamesWithExtension } = findAllModulesInRoot(themeWebRoot);
4069
- const { partialNames } = findAllPartialsInRoot(themeWebRoot);
4070
- const hubLModuleData = await fetchHubLModules(
4071
- authedPortalId,
4072
- localPreviewToken
4073
- );
4074
- const hubLTemplateData = await fetchPreviewTemplates(
4075
- authedPortalId,
4076
- localPreviewToken
4216
+ const modulesData = findAllModulesInRoot(themeWebRoot);
4217
+ const partialsData = findAllPartialsInRoot(themeWebRoot);
4218
+ const mappedModulesData = await mapModulesData(
4219
+ modulesData,
4220
+ themeWebRoot,
4221
+ viteServer
4077
4222
  );
4223
+ let hubLModuleData = { objects: [] };
4224
+ let hubLTemplateData = { objects: [] };
4225
+ if (authedPortalId) {
4226
+ hubLModuleData = await fetchHubLModules(authedPortalId, localPreviewToken);
4227
+ hubLTemplateData = await fetchPreviewTemplates(
4228
+ authedPortalId,
4229
+ localPreviewToken
4230
+ );
4231
+ }
4232
+ const hubLTemplates = (hubLTemplateData == null ? void 0 : hubLTemplateData.objects.filter(
4233
+ (template) => isCodedFile(template.filename)
4234
+ )) || [];
4078
4235
  return {
4079
4236
  authedPortalId,
4080
4237
  projectName,
4081
- moduleNames,
4082
- partialNames,
4238
+ modulesData: mappedModulesData,
4239
+ partialsData: mapPartialsData(partialsData),
4083
4240
  hubLModules: (hubLModuleData == null ? void 0 : hubLModuleData.objects) || [],
4084
- hubLTemplates: (hubLTemplateData == null ? void 0 : hubLTemplateData.objects) || [],
4085
- webRootProjectComponentFolder,
4086
- moduleNamesWithExtension
4241
+ hubLTemplates,
4242
+ themeWebRoot,
4243
+ webRootProjectComponentFolder
4087
4244
  };
4088
4245
  }
4089
4246
  var getDevServerUIData_default = getDevServerUIData;
@@ -4096,7 +4253,11 @@ async function createAppServer(webRoot, reqLocals, port) {
4096
4253
  server: {
4097
4254
  middlewareMode: true,
4098
4255
  host: "hslocal.net",
4099
- origin
4256
+ origin,
4257
+ hmr: {
4258
+ port: port + 1,
4259
+ host: "hslocal.net"
4260
+ }
4100
4261
  },
4101
4262
  appType: "custom",
4102
4263
  root: webRoot,
@@ -4134,14 +4295,32 @@ async function createAppServer(webRoot, reqLocals, port) {
4134
4295
  };
4135
4296
  const viteServer = await createViteServer2(viteConfig);
4136
4297
  app.use(viteServer.middlewares);
4298
+ app.get("/api/module-pages", async (req, res, next) => {
4299
+ const { path: path15, portalId } = req.query;
4300
+ if (!path15 || !portalId) {
4301
+ return res.status(400).json({ error: "Missing required parameters" });
4302
+ }
4303
+ try {
4304
+ const data = await fetchModulePageDependencies(
4305
+ Number(portalId),
4306
+ path15
4307
+ );
4308
+ res.json(data);
4309
+ } catch (err) {
4310
+ next(err);
4311
+ }
4312
+ });
4137
4313
  app.use("*", async (req, res) => {
4138
4314
  try {
4139
- const initialProps = await getDevServerUIData_default(reqLocals);
4315
+ const initialProps = await getDevServerUIData_default({
4316
+ ...reqLocals,
4317
+ viteServer
4318
+ });
4140
4319
  const url3 = req.originalUrl.replace("/", "");
4141
- let template = await fs3.readFile("./app/index.html", "utf-8");
4320
+ let template = await fs3.readFile(`${webRoot}/index.html`, "utf-8");
4142
4321
  template = await viteServer.transformIndexHtml(url3, template);
4143
4322
  const { render } = await viteServer.ssrLoadModule(
4144
- "./app/serverEntry.tsx"
4323
+ `${webRoot}/serverEntry.tsx`
4145
4324
  );
4146
4325
  const rendered = await render(initialProps);
4147
4326
  const html = template.replace(`<!--app-head-->`, rendered.head ?? "").replace(`<!--app-html-->`, rendered.html ?? "").replace(
@@ -4157,6 +4336,10 @@ async function createAppServer(webRoot, reqLocals, port) {
4157
4336
  res.status(500).end(e.stack);
4158
4337
  }
4159
4338
  });
4339
+ app.use((err, req, res, next) => {
4340
+ console.error("API Error:", err);
4341
+ res.status(500).json({ error: "Internal server error" });
4342
+ });
4160
4343
  app.listen(port, () => {
4161
4344
  console.log(`Server started at http://localhost:${port}`);
4162
4345
  });
@@ -4323,7 +4506,7 @@ async function fetchWebsiteDomainNames(portalId) {
4323
4506
  }
4324
4507
 
4325
4508
  // src/lib/validateHSPlatform.ts
4326
- import path10 from "path";
4509
+ import path12 from "path";
4327
4510
  import fs4 from "fs";
4328
4511
  import select from "@inquirer/select";
4329
4512
  import { http as hsCliHttp12 } from "@hubspot/local-dev-lib/http";
@@ -4335,12 +4518,12 @@ function findHSProjectJson(startPath) {
4335
4518
  let currentDir = startPath;
4336
4519
  let dirLevel = 0;
4337
4520
  const maxDirLevel = 4;
4338
- while (path10.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
4339
- const filePath = path10.join(currentDir, HSPROJECT_JSON);
4521
+ while (path12.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
4522
+ const filePath = path12.join(currentDir, HSPROJECT_JSON);
4340
4523
  if (checkFileExists(filePath)) {
4341
4524
  return filePath;
4342
4525
  }
4343
- currentDir = path10.dirname(currentDir);
4526
+ currentDir = path12.dirname(currentDir);
4344
4527
  dirLevel++;
4345
4528
  }
4346
4529
  console.log(
@@ -4646,7 +4829,7 @@ function writeFieldsType(fields, fileName, typeName) {
4646
4829
 
4647
4830
  // src/lib/watchFieldsUpdates.ts
4648
4831
  import fs5 from "fs";
4649
- import path11 from "path";
4832
+ import path13 from "path";
4650
4833
  import readline from "readline";
4651
4834
  var lastSerializedFieldsCache = {};
4652
4835
  var formatAsTypeName = (str) => {
@@ -4658,9 +4841,9 @@ var isInModulesFolder = (filePath, projectRoot) => {
4658
4841
  const getEntryPathFromId = (id) => {
4659
4842
  return id.startsWith(projectRoot) ? id.replace(`${projectRoot}/`, "") : "";
4660
4843
  };
4661
- const currentModuleId = path11.normalize(filePath);
4844
+ const currentModuleId = path13.normalize(filePath);
4662
4845
  const moduleEntryPath = getEntryPathFromId(currentModuleId);
4663
- const subFolderTokens = moduleEntryPath.split(path11.sep);
4846
+ const subFolderTokens = moduleEntryPath.split(path13.sep);
4664
4847
  return {
4665
4848
  inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
4666
4849
  isRootModuleFile: subFolderTokens.length === 3
@@ -4687,10 +4870,10 @@ var getIndexFile = (filePath, projectRoot) => {
4687
4870
  return void 0;
4688
4871
  if (isRootModuleFile)
4689
4872
  return { indexFilePath: filePath, isRootModuleFile };
4690
- const dir = path11.dirname(filePath);
4873
+ const dir = path13.dirname(filePath);
4691
4874
  const files = fs5.readdirSync(dir);
4692
4875
  const indexFileName = files.find((file) => file.startsWith("index."));
4693
- return indexFileName ? { indexFilePath: path11.join(dir, indexFileName), isRootModuleFile } : void 0;
4876
+ return indexFileName ? { indexFilePath: path13.join(dir, indexFileName), isRootModuleFile } : void 0;
4694
4877
  };
4695
4878
  var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
4696
4879
  let indexFile;
@@ -4714,7 +4897,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
4714
4897
  if (!indexInfo)
4715
4898
  return;
4716
4899
  const { indexFilePath, isRootModuleFile } = indexInfo;
4717
- const indexFileName = path11.parse(indexFilePath).name;
4900
+ const indexFileName = path13.parse(indexFilePath).name;
4718
4901
  const isTypeFile = filePath.endsWith(".types.ts");
4719
4902
  if (isTypeFile)
4720
4903
  return;
@@ -4725,7 +4908,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
4725
4908
  );
4726
4909
  if (fields) {
4727
4910
  const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
4728
- const typeFilePath = path11.join(path11.dirname(filePath), typeFileName);
4911
+ const typeFilePath = path13.join(path13.dirname(filePath), typeFileName);
4729
4912
  const lastSerializedFields = lastSerializedFieldsCache[typeFilePath];
4730
4913
  const serializedFields = JSON.stringify(fields);
4731
4914
  if (lastSerializedFields === serializedFields)
@@ -4733,7 +4916,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
4733
4916
  const hasAutoGenComment = await fileContainsAutoGenComment(typeFilePath);
4734
4917
  if (!hasAutoGenComment)
4735
4918
  return;
4736
- const moduleFolderName = path11.basename(path11.dirname(filePath));
4919
+ const moduleFolderName = path13.basename(path13.dirname(filePath));
4737
4920
  const outputTypeName = formatAsTypeName(moduleFolderName);
4738
4921
  const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
4739
4922
  if (didSucceed) {
@@ -4749,7 +4932,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
4749
4932
  var startFieldsTypeGenWatcher = (viteServer, projectRoot) => {
4750
4933
  const { moduleSubpaths } = findAllModulesInRoot(projectRoot);
4751
4934
  moduleSubpaths.forEach((modulePath) => {
4752
- const resolvedPath = path11.resolve(projectRoot, modulePath);
4935
+ const resolvedPath = path13.resolve(projectRoot, modulePath);
4753
4936
  maybeUpdateFields(resolvedPath, viteServer, projectRoot);
4754
4937
  });
4755
4938
  const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
@@ -4887,7 +5070,7 @@ Local proxy functionality and module preview routes will not work without settin
4887
5070
  } catch (e) {
4888
5071
  authedHublet = "na1";
4889
5072
  }
4890
- const absoluteWebRoot = normalizePath7(path12.resolve(process.cwd(), webRoot));
5073
+ const absoluteWebRoot = normalizePath9(path14.resolve(process.cwd(), webRoot));
4891
5074
  const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, "").split("/").slice(-2);
4892
5075
  const projectConfigPath = findHSProjectJson(absoluteWebRoot);
4893
5076
  if (authedPortalId) {
@@ -4979,8 +5162,8 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
4979
5162
  `
4980
5163
  );
4981
5164
  if (showUI) {
4982
- const appWebRoot = path12.join(
4983
- path12.dirname(url2.fileURLToPath(import.meta.url)),
5165
+ const appWebRoot = path14.join(
5166
+ path14.dirname(url2.fileURLToPath(import.meta.url)),
4984
5167
  "../app"
4985
5168
  );
4986
5169
  const reqLocals = {
@@ -4996,8 +5179,8 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
4996
5179
  httpServers.push(appServer);
4997
5180
  }
4998
5181
  if (storybook) {
4999
- const packageRoot = path12.dirname(url2.fileURLToPath(import.meta.url));
5000
- const configPath = path12.resolve(packageRoot, "./storybook-main");
5182
+ const packageRoot = path14.dirname(url2.fileURLToPath(import.meta.url));
5183
+ const configPath = path14.resolve(packageRoot, "./storybook-main");
5001
5184
  sendTrackingRequest("start-storybook");
5002
5185
  const storybookProcess = spawn(
5003
5186
  "sb",
@@ -5017,7 +5200,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
5017
5200
  portalId: authedPortalId.toString(),
5018
5201
  hsEnv: authedEnv,
5019
5202
  hublet: authedHublet,
5020
- WEB_ROOT: path12.join(webRoot, "components")
5203
+ WEB_ROOT: path14.join(webRoot, "components")
5021
5204
  }
5022
5205
  }
5023
5206
  );