@hubspot/cms-dev-server 1.0.6 → 1.0.7

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/run.js CHANGED
@@ -758,7 +758,7 @@ async function buildThemePreviewOptions(webRoot2, isUsingLocalWorkspace = false)
758
758
  }
759
759
 
760
760
  // src/createDevServer.ts
761
- import path16 from "path";
761
+ import path17 from "path";
762
762
  import url2 from "url";
763
763
  import express2 from "express";
764
764
  import http3 from "http";
@@ -1405,8 +1405,8 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
1405
1405
  );
1406
1406
  return Object.fromEntries(relativeEntries);
1407
1407
  }
1408
- function toRelativePath(config, path17) {
1409
- return path17.replace(`${config.root}/`, "");
1408
+ function toRelativePath(config, path18) {
1409
+ return path18.replace(`${config.root}/`, "");
1410
1410
  }
1411
1411
  function shouldAnalyzeModule(config, moduleInfo, code) {
1412
1412
  const [fileId, __] = moduleInfo.id.split("?");
@@ -1449,11 +1449,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
1449
1449
  let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
1450
1450
  let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
1451
1451
  traverse(sourceAst, {
1452
- ImportDeclaration(path17) {
1453
- if (t.isStringLiteral(path17.node.source, {
1452
+ ImportDeclaration(path18) {
1453
+ if (t.isStringLiteral(path18.node.source, {
1454
1454
  value: "@hubspot/cms-components"
1455
1455
  })) {
1456
- for (const specifier of path17.node.specifiers) {
1456
+ for (const specifier of path18.node.specifiers) {
1457
1457
  if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
1458
1458
  name: CMS_MODULE_COMPONENT_NAME
1459
1459
  })) {
@@ -1467,14 +1467,14 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
1467
1467
  }
1468
1468
  }
1469
1469
  },
1470
- JSXOpeningElement(path17) {
1471
- if (t.isJSXIdentifier(path17.node.name, {
1470
+ JSXOpeningElement(path18) {
1471
+ if (t.isJSXIdentifier(path18.node.name, {
1472
1472
  name: moduleComponentLocalImportName
1473
1473
  })) {
1474
1474
  let cmsModuleName;
1475
1475
  let cmsModulePath;
1476
1476
  let cmsModuleLabel;
1477
- for (const prop of path17.node.attributes) {
1477
+ for (const prop of path18.node.attributes) {
1478
1478
  if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
1479
1479
  cmsModuleName = prop.value.value;
1480
1480
  continue;
@@ -1509,11 +1509,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
1509
1509
  }
1510
1510
  contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
1511
1511
  }
1512
- if (t.isJSXIdentifier(path17.node.name, {
1512
+ if (t.isJSXIdentifier(path18.node.name, {
1513
1513
  name: dndAreaComponentLocalImportName
1514
1514
  })) {
1515
1515
  let dndAreaName;
1516
- for (const prop of path17.node.attributes) {
1516
+ for (const prop of path18.node.attributes) {
1517
1517
  if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
1518
1518
  dndAreaName = prop.value.value;
1519
1519
  continue;
@@ -2097,7 +2097,7 @@ function trackUsage(action) {
2097
2097
  eventName: EVENT_NAME,
2098
2098
  action,
2099
2099
  nodeVersion: getNodeVersionData(),
2100
- version: "1.0.6",
2100
+ version: "1.0.7",
2101
2101
  os: getPlatform()
2102
2102
  };
2103
2103
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -2170,12 +2170,12 @@ var findLocalRenderPlaceholders = (body) => {
2170
2170
  );
2171
2171
  offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
2172
2172
  if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
2173
- const path17 = body.substring(
2173
+ const path18 = body.substring(
2174
2174
  startOffset + localJsRenderStartString.length,
2175
2175
  pathEndOffset
2176
2176
  );
2177
2177
  offsetSoFar = pathEndOffset + 1;
2178
- if (startOffset >= 0 && path17) {
2178
+ if (startOffset >= 0 && path18) {
2179
2179
  const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
2180
2180
  const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
2181
2181
  offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
@@ -2200,7 +2200,7 @@ var findLocalRenderPlaceholders = (body) => {
2200
2200
  result.push({
2201
2201
  startOffset,
2202
2202
  endOffset: endOffset + localJsRenderEndString.length,
2203
- path: path17,
2203
+ path: path18,
2204
2204
  json
2205
2205
  });
2206
2206
  }
@@ -2579,9 +2579,9 @@ var customColors = [
2579
2579
  ];
2580
2580
  var Converter = new AnsiToHtmlConverter({ colors: customColors });
2581
2581
  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;`;
2582
- var renderLocalError_default = (path17, error) => {
2582
+ var renderLocalError_default = (path18, error) => {
2583
2583
  const stackWithColorClasses = Converter.toHtml(error.stack);
2584
- return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path17}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
2584
+ return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path18}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
2585
2585
  };
2586
2586
 
2587
2587
  // src/proxyPage/fetchPreviewInfo.ts
@@ -4144,18 +4144,18 @@ async function fetchPreviewTemplates(accountId, previewToken) {
4144
4144
  url: `${DESIGN_MANAGER_API_PATH}/templates/local-preview?previewToken=${previewToken}`
4145
4145
  })).data;
4146
4146
  }
4147
- async function fetchModuleByPath(accountId, path17) {
4147
+ async function fetchModuleByPath(accountId, path18) {
4148
4148
  return (await hsCliHttp8.get(accountId, {
4149
- url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${path17}?portalId=${accountId}`
4149
+ url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${path18}?portalId=${accountId}`
4150
4150
  })).data;
4151
4151
  }
4152
- async function fetchTemplateByPath(accountId, path17) {
4152
+ async function fetchTemplateByPath(accountId, path18) {
4153
4153
  return (await hsCliHttp8.get(accountId, {
4154
- url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${path17}?portalId=${accountId}`
4154
+ url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${path18}?portalId=${accountId}`
4155
4155
  })).data;
4156
4156
  }
4157
- async function fetchModulePageDependencies(accountId, path17) {
4158
- const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${path17}`;
4157
+ async function fetchModulePageDependencies(accountId, path18) {
4158
+ const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${path18}`;
4159
4159
  return (await hsCliHttp8.get(accountId, { url: url3 })).data;
4160
4160
  }
4161
4161
 
@@ -4172,9 +4172,9 @@ function isCodedFile(filePath) {
4172
4172
  return TEMPLATE_EXTENSION_REGEX.test(filePath);
4173
4173
  }
4174
4174
 
4175
- // src/routes/homeRouteHandler.tsx
4175
+ // src/routes/legacyRouteHandler.tsx
4176
4176
  import { Fragment, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
4177
- var homeRouteHandler = async (request2, response, next) => {
4177
+ var legacyRouteHandler = async (request2, response, next) => {
4178
4178
  const domainToProxy = getSubDomainFromValidLocalDomain(request2.hostname);
4179
4179
  if (domainToProxy) {
4180
4180
  next();
@@ -4219,7 +4219,7 @@ var homeRouteHandler = async (request2, response, next) => {
4219
4219
  );
4220
4220
  response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
4221
4221
  };
4222
- var homeRouteHandler_default = homeRouteHandler;
4222
+ var legacyRouteHandler_default = legacyRouteHandler;
4223
4223
 
4224
4224
  // src/routes/proxyPathPageRouteHandler.tsx
4225
4225
  import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
@@ -4645,8 +4645,61 @@ function buildTemplateIndex() {
4645
4645
  `);
4646
4646
  }
4647
4647
 
4648
- // src/routes/createDevServerRoutes.ts
4648
+ // src/routes/createAppServerAPIRoutes.ts
4649
+ import { Router } from "express";
4650
+ import { spawn } from "child_process";
4651
+ function getOpenCommand() {
4652
+ switch (process.platform) {
4653
+ case "darwin":
4654
+ return "open";
4655
+ case "win32":
4656
+ return "start";
4657
+ default:
4658
+ return "xdg-open";
4659
+ }
4660
+ }
4661
+ async function handleGetModulePages(req, res, next) {
4662
+ const { path: path18, portalId } = req.query;
4663
+ if (!path18 || !portalId) {
4664
+ return res.status(400).json({ error: "Missing required parameters" });
4665
+ }
4666
+ try {
4667
+ sendTrackingRequest("handle-module-dependencies");
4668
+ const data = await fetchModulePageDependencies(
4669
+ Number(portalId),
4670
+ path18
4671
+ );
4672
+ res.json(data);
4673
+ } catch (err) {
4674
+ next(err);
4675
+ }
4676
+ }
4677
+ function handleOpenFile(req, res, next) {
4678
+ const { path: path18 } = req.query;
4679
+ if (!path18) {
4680
+ return res.status(400).json({ error: "Missing required parameters" });
4681
+ }
4682
+ try {
4683
+ sendTrackingRequest("handle-open-file");
4684
+ const command = getOpenCommand();
4685
+ spawn(command, [path18], { detached: true }).unref();
4686
+ res.sendStatus(200);
4687
+ } catch (err) {
4688
+ next(err);
4689
+ }
4690
+ }
4691
+ function createAppServerAPIRoutes() {
4692
+ const router = Router();
4693
+ router.get("/module-pages", handleGetModulePages);
4694
+ router.get("/open-file", handleOpenFile);
4695
+ return router;
4696
+ }
4697
+ var createAppServerAPIRoutes_default = createAppServerAPIRoutes;
4698
+
4699
+ // src/routes/appServerRouteHandler.ts
4649
4700
  import fs5 from "node:fs/promises";
4701
+ import path13 from "path";
4702
+ import { pathToFileURL } from "url";
4650
4703
 
4651
4704
  // src/lib/getDevServerUIData.ts
4652
4705
  import path12 from "path";
@@ -4792,13 +4845,16 @@ var templateTypeMap = {
4792
4845
  14: "Backup Unsubscribe",
4793
4846
  27: "Search Results"
4794
4847
  };
4795
- function mapReactModules(modules, themeWebRoot, viteServer) {
4848
+ function mapReactModules(modules, themeWebRoot, appViteServer) {
4796
4849
  return Promise.all(
4797
4850
  modules.moduleNames.map(async (name, index) => {
4798
4851
  const modulePath = normalizePath9(
4799
4852
  path12.resolve(themeWebRoot, "components/modules/", name)
4800
4853
  );
4801
- const fieldsJson = await renderModuleFieldsJson_default(viteServer, modulePath);
4854
+ const fieldsJson = await renderModuleFieldsJson_default(
4855
+ appViteServer,
4856
+ modulePath
4857
+ );
4802
4858
  return {
4803
4859
  name,
4804
4860
  type: "react" /* REACT */,
@@ -4848,7 +4904,7 @@ function detectPackageManager(projectRoot) {
4848
4904
  return "pnpm";
4849
4905
  return "npm";
4850
4906
  }
4851
- async function getDevServerUIData(reqLocals, viteServer) {
4907
+ async function getDevServerUIData(appLocals) {
4852
4908
  const {
4853
4909
  themeWebRoot,
4854
4910
  authedEnv,
@@ -4857,8 +4913,9 @@ async function getDevServerUIData(reqLocals, viteServer) {
4857
4913
  localPreviewToken,
4858
4914
  webRootProjectComponentFolder,
4859
4915
  sslEnabled,
4860
- fieldBuilderEnabled: fieldBuilderEnabled2
4861
- } = reqLocals;
4916
+ fieldBuilderEnabled: fieldBuilderEnabled2,
4917
+ appViteServer
4918
+ } = appLocals;
4862
4919
  const packageJson = getPackageJson(themeWebRoot);
4863
4920
  const packageManager = detectPackageManager(themeWebRoot);
4864
4921
  const runCommand = packageManager === "yarn" ? "yarn" : `${packageManager} run`;
@@ -4874,7 +4931,7 @@ async function getDevServerUIData(reqLocals, viteServer) {
4874
4931
  const reactModules = await mapReactModules(
4875
4932
  modulesData,
4876
4933
  themeWebRoot,
4877
- viteServer
4934
+ appViteServer
4878
4935
  );
4879
4936
  let hubLModuleData = { objects: [] };
4880
4937
  let hubLTemplateData = { objects: [] };
@@ -4905,71 +4962,53 @@ async function getDevServerUIData(reqLocals, viteServer) {
4905
4962
  fieldBuilderEnabled: fieldBuilderEnabled2
4906
4963
  };
4907
4964
  }
4908
- var getDevServerUIData_default = getDevServerUIData;
4909
4965
 
4910
- // src/routes/createAppServerRoutes.ts
4911
- import { Router } from "express";
4912
- import { spawn } from "child_process";
4913
- function getOpenCommand() {
4914
- switch (process.platform) {
4915
- case "darwin":
4916
- return "open";
4917
- case "win32":
4918
- return "start";
4919
- default:
4920
- return "xdg-open";
4921
- }
4922
- }
4923
- async function handleGetModulePages(req, res, next) {
4924
- const { path: path17, portalId } = req.query;
4925
- if (!path17 || !portalId) {
4926
- return res.status(400).json({ error: "Missing required parameters" });
4927
- }
4966
+ // src/routes/appServerRouteHandler.ts
4967
+ var isProd = true;
4968
+ var appServerRouteHandler = async (req, res, __next) => {
4928
4969
  try {
4929
- sendTrackingRequest("handle-module-dependencies");
4930
- const data = await fetchModulePageDependencies(
4931
- Number(portalId),
4932
- path17
4970
+ sendTrackingRequest("view-index-route");
4971
+ const appLocals = req.app.locals.appLocals;
4972
+ const { appWebRoot, appViteServer } = appLocals;
4973
+ const initialProps = await getDevServerUIData(appLocals);
4974
+ const url3 = req.originalUrl.replace("/", "");
4975
+ const templatePath = path13.join(appWebRoot, "index.html");
4976
+ const serverEntryPath = isProd ? path13.join(appWebRoot, "server/serverEntry.js") : path13.join(appWebRoot, "serverEntry.tsx");
4977
+ let render;
4978
+ let template = await fs5.readFile(path13.join(templatePath), "utf-8");
4979
+ if (isProd) {
4980
+ const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
4981
+ render = ssrRender;
4982
+ } else {
4983
+ template = await appViteServer.transformIndexHtml(url3, template);
4984
+ render = (await appViteServer.ssrLoadModule(serverEntryPath)).render;
4985
+ }
4986
+ const rendered = await render(initialProps);
4987
+ const html = template.replace(`<!--app-head-->`, rendered.head ?? "").replace(`<!--app-html-->`, rendered.html ?? "").replace(
4988
+ `<!--app-script-->`,
4989
+ `<script>window.__hsInitialProps = ${JSON.stringify(
4990
+ initialProps
4991
+ )};</script>` ?? ""
4933
4992
  );
4934
- res.json(data);
4935
- } catch (err) {
4936
- next(err);
4937
- }
4938
- }
4939
- function handleOpenFile(req, res, next) {
4940
- const { path: path17 } = req.query;
4941
- if (!path17) {
4942
- return res.status(400).json({ error: "Missing required parameters" });
4943
- }
4944
- try {
4945
- sendTrackingRequest("handle-open-file");
4946
- const command = getOpenCommand();
4947
- spawn(command, [path17], { detached: true }).unref();
4948
- res.sendStatus(200);
4949
- } catch (err) {
4950
- next(err);
4993
+ res.status(200).set({ "Content-Type": "text/html" }).send(html);
4994
+ } catch (e) {
4995
+ const { appViteServer } = req.app.locals.appLocals;
4996
+ appViteServer == null ? void 0 : appViteServer.ssrFixStacktrace(e);
4997
+ console.log(e.stack);
4998
+ res.status(500).end(e.stack);
4951
4999
  }
4952
- }
4953
- function createAppServerRoutes() {
4954
- const router = Router();
4955
- router.get("/module-pages", handleGetModulePages);
4956
- router.get("/open-file", handleOpenFile);
4957
- return router;
4958
- }
4959
- var createAppServerRoutes_default = createAppServerRoutes;
5000
+ };
5001
+ var appServerRouteHandler_default = appServerRouteHandler;
4960
5002
 
4961
5003
  // src/routes/createDevServerRoutes.ts
4962
- import path13 from "path";
4963
- import { fileURLToPath, pathToFileURL } from "url";
4964
- var __filename = fileURLToPath(import.meta.url);
4965
- var __dirname = path13.dirname(__filename);
4966
- var isProd = true;
5004
+ import path14 from "path";
5005
+ var isProd2 = true;
4967
5006
  var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
4968
5007
  (domain2) => `storybook.${domain2}`
4969
5008
  );
4970
- var createDevServerRoutes = async (viteServer, storybookPort, appServerConfig) => {
5009
+ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
4971
5010
  const devServerApp = Router2();
4972
- const { appServer, reqLocals } = appServerConfig || {};
5011
+ const { appViteServer, appWebRoot } = appLocals || {};
4973
5012
  devServerApp.use((request2, response, next) => {
4974
5013
  const { method, url: url3, hostname } = request2;
4975
5014
  debug(`${method}:${hostname}${url3}`);
@@ -4987,46 +5026,20 @@ var createDevServerRoutes = async (viteServer, storybookPort, appServerConfig) =
4987
5026
  );
4988
5027
  }
4989
5028
  devServerApp.use(urlencoded());
4990
- const appWebRoot = isProd ? path13.join(__dirname, "app") : appServerConfig == null ? void 0 : appServerConfig.appWebRoot;
4991
- if (isProd) {
4992
- const distAssetsPath = path13.join(appWebRoot, "assets");
5029
+ if (isProd2) {
5030
+ const distAssetsPath = path14.join(appWebRoot, "assets");
4993
5031
  devServerApp.use("/assets", expressStatic(distAssetsPath));
4994
5032
  } else {
4995
- devServerApp.use(appServer.middlewares);
5033
+ devServerApp.use(appViteServer.middlewares);
4996
5034
  }
4997
5035
  devServerApp.use(viteServer.middlewares);
4998
- devServerApp.use("/api", createAppServerRoutes_default());
4999
- devServerApp.get("/", async (req, res) => {
5000
- try {
5001
- sendTrackingRequest("view-index-route");
5002
- const initialProps = await getDevServerUIData_default(reqLocals, viteServer);
5003
- const url3 = req.originalUrl.replace("/", "");
5004
- const templatePath = path13.join(appWebRoot, "index.html");
5005
- const serverEntryPath = isProd ? path13.join(appWebRoot, "server/serverEntry.js") : path13.join(appWebRoot, "serverEntry.tsx");
5006
- let render;
5007
- let template = await fs5.readFile(path13.join(templatePath), "utf-8");
5008
- if (isProd) {
5009
- const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
5010
- render = ssrRender;
5011
- } else {
5012
- template = await appServer.transformIndexHtml(url3, template);
5013
- render = (await appServer.ssrLoadModule(serverEntryPath)).render;
5014
- }
5015
- const rendered = await render(initialProps);
5016
- const html = template.replace(`<!--app-head-->`, rendered.head ?? "").replace(`<!--app-html-->`, rendered.html ?? "").replace(
5017
- `<!--app-script-->`,
5018
- `<script>window.__hsInitialProps = ${JSON.stringify(
5019
- initialProps
5020
- )};</script>` ?? ""
5021
- );
5022
- res.status(200).set({ "Content-Type": "text/html" }).send(html);
5023
- } catch (e) {
5024
- appServer == null ? void 0 : appServer.ssrFixStacktrace(e);
5025
- console.log(e.stack);
5026
- res.status(500).end(e.stack);
5027
- }
5028
- });
5029
- devServerApp.get("/legacy", homeRouteHandler_default);
5036
+ devServerApp.use("/api", createAppServerAPIRoutes_default());
5037
+ if (appLocals.projectName) {
5038
+ devServerApp.get("/", appServerRouteHandler_default);
5039
+ devServerApp.get("/legacy", legacyRouteHandler_default);
5040
+ } else {
5041
+ devServerApp.get("/", legacyRouteHandler_default);
5042
+ }
5030
5043
  devServerApp.get("/proxy", proxyPathPageRouteHandler);
5031
5044
  devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
5032
5045
  devServerApp.get("/partial/:partial", partial_default);
@@ -5379,7 +5392,7 @@ async function fetchWebsiteDomainNames(portalId) {
5379
5392
  }
5380
5393
 
5381
5394
  // src/lib/validateHSPlatform.ts
5382
- import path14 from "path";
5395
+ import path15 from "path";
5383
5396
  import fs6 from "fs";
5384
5397
  import select from "@inquirer/select";
5385
5398
  import { http as hsCliHttp13 } from "@hubspot/local-dev-lib/http";
@@ -5391,12 +5404,12 @@ function findHSProjectJson(startPath) {
5391
5404
  let currentDir = startPath;
5392
5405
  let dirLevel = 0;
5393
5406
  const maxDirLevel = 4;
5394
- while (path14.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
5395
- const filePath = path14.join(currentDir, HSPROJECT_JSON);
5407
+ while (path15.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
5408
+ const filePath = path15.join(currentDir, HSPROJECT_JSON);
5396
5409
  if (checkFileExists(filePath)) {
5397
5410
  return filePath;
5398
5411
  }
5399
- currentDir = path14.dirname(currentDir);
5412
+ currentDir = path15.dirname(currentDir);
5400
5413
  dirLevel++;
5401
5414
  }
5402
5415
  console.log(
@@ -5702,7 +5715,7 @@ function writeFieldsType(fields, fileName, typeName) {
5702
5715
 
5703
5716
  // src/lib/watchFieldsUpdates.ts
5704
5717
  import fs7 from "fs";
5705
- import path15 from "path";
5718
+ import path16 from "path";
5706
5719
  import readline from "readline";
5707
5720
  var lastSerializedFieldsCache = {};
5708
5721
  var formatAsTypeName = (str) => {
@@ -5714,9 +5727,9 @@ var isInModulesFolder = (filePath, projectRoot) => {
5714
5727
  const getEntryPathFromId = (id) => {
5715
5728
  return id.startsWith(projectRoot) ? id.replace(`${projectRoot}/`, "") : "";
5716
5729
  };
5717
- const currentModuleId = path15.normalize(filePath);
5730
+ const currentModuleId = path16.normalize(filePath);
5718
5731
  const moduleEntryPath = getEntryPathFromId(currentModuleId);
5719
- const subFolderTokens = moduleEntryPath.split(path15.sep);
5732
+ const subFolderTokens = moduleEntryPath.split(path16.sep);
5720
5733
  return {
5721
5734
  inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
5722
5735
  isRootModuleFile: subFolderTokens.length === 3
@@ -5743,10 +5756,10 @@ var getIndexFile = (filePath, projectRoot) => {
5743
5756
  return void 0;
5744
5757
  if (isRootModuleFile)
5745
5758
  return { indexFilePath: filePath, isRootModuleFile };
5746
- const dir = path15.dirname(filePath);
5759
+ const dir = path16.dirname(filePath);
5747
5760
  const files = fs7.readdirSync(dir);
5748
5761
  const indexFileName = files.find((file) => file.startsWith("index."));
5749
- return indexFileName ? { indexFilePath: path15.join(dir, indexFileName), isRootModuleFile } : void 0;
5762
+ return indexFileName ? { indexFilePath: path16.join(dir, indexFileName), isRootModuleFile } : void 0;
5750
5763
  };
5751
5764
  var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
5752
5765
  let indexFile;
@@ -5770,7 +5783,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
5770
5783
  if (!indexInfo)
5771
5784
  return;
5772
5785
  const { indexFilePath, isRootModuleFile } = indexInfo;
5773
- const indexFileName = path15.parse(indexFilePath).name;
5786
+ const indexFileName = path16.parse(indexFilePath).name;
5774
5787
  const isTypeFile = filePath.endsWith(".types.ts");
5775
5788
  if (isTypeFile)
5776
5789
  return;
@@ -5781,7 +5794,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
5781
5794
  );
5782
5795
  if (fields) {
5783
5796
  const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
5784
- const typeFilePath = path15.join(path15.dirname(filePath), typeFileName);
5797
+ const typeFilePath = path16.join(path16.dirname(filePath), typeFileName);
5785
5798
  const lastSerializedFields = lastSerializedFieldsCache[typeFilePath];
5786
5799
  const serializedFields = JSON.stringify(fields);
5787
5800
  if (lastSerializedFields === serializedFields)
@@ -5789,7 +5802,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
5789
5802
  const hasAutoGenComment = await fileContainsAutoGenComment(typeFilePath);
5790
5803
  if (!hasAutoGenComment)
5791
5804
  return;
5792
- const moduleFolderName = path15.basename(path15.dirname(filePath));
5805
+ const moduleFolderName = path16.basename(path16.dirname(filePath));
5793
5806
  const outputTypeName = formatAsTypeName(moduleFolderName);
5794
5807
  const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
5795
5808
  if (didSucceed) {
@@ -5805,7 +5818,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
5805
5818
  var startFieldsTypeGenWatcher = (viteServer, projectRoot) => {
5806
5819
  const { moduleSubpaths } = findAllModulesInRoot(projectRoot);
5807
5820
  moduleSubpaths.forEach((modulePath) => {
5808
- const resolvedPath = path15.resolve(projectRoot, modulePath);
5821
+ const resolvedPath = path16.resolve(projectRoot, modulePath);
5809
5822
  maybeUpdateFields(resolvedPath, viteServer, projectRoot);
5810
5823
  });
5811
5824
  const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
@@ -5943,7 +5956,7 @@ Local proxy functionality and module preview routes will not work without settin
5943
5956
  } catch (e) {
5944
5957
  authedHublet = "na1";
5945
5958
  }
5946
- const absoluteWebRoot = normalizePath10(path16.resolve(process.cwd(), webRoot2));
5959
+ const absoluteWebRoot = normalizePath10(path17.resolve(process.cwd(), webRoot2));
5947
5960
  const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, "").split("/").slice(-2);
5948
5961
  const projectConfigPath = findHSProjectJson(absoluteWebRoot);
5949
5962
  if (authedPortalId) {
@@ -5995,9 +6008,17 @@ Local proxy functionality and module preview routes will not work without settin
5995
6008
  expressServer.locals.domainsToProxy = domainsToProxy;
5996
6009
  expressServer.locals.localPreviewToken = _localPreviewToken;
5997
6010
  expressServer.use(bodyParser.json());
5998
- const __dirname2 = path16.dirname(url2.fileURLToPath(new URL(import.meta.url)));
5999
- const appWebRoot = normalizePath10(path16.resolve(__dirname2, "../app"));
6000
- const reqLocals = {
6011
+ const __dirname = path17.dirname(url2.fileURLToPath(new URL(import.meta.url)));
6012
+ let appWebRoot = normalizePath10(path17.resolve(__dirname, "../app"));
6013
+ if (true) {
6014
+ appWebRoot = path17.join(__dirname, "app");
6015
+ }
6016
+ const appViteServer = await createAppServer_default(
6017
+ appWebRoot,
6018
+ PORT,
6019
+ sslEnabledOption2
6020
+ );
6021
+ const appLocals = {
6001
6022
  themeWebRoot: absoluteWebRoot,
6002
6023
  authedPortalId,
6003
6024
  authedEnv,
@@ -6006,24 +6027,17 @@ Local proxy functionality and module preview routes will not work without settin
6006
6027
  webRootProjectComponentFolder,
6007
6028
  localPreviewToken: _localPreviewToken,
6008
6029
  sslEnabled: sslEnabledOption2,
6009
- fieldBuilderEnabled: fieldBuilderEnabled2
6010
- };
6011
- const appServer = await createAppServer_default(
6030
+ fieldBuilderEnabled: fieldBuilderEnabled2,
6012
6031
  appWebRoot,
6013
- PORT,
6014
- sslEnabledOption2
6015
- );
6016
- const appServerConfig = {
6017
- appServer,
6018
- reqLocals,
6019
- appWebRoot
6032
+ appViteServer
6020
6033
  };
6034
+ expressServer.locals.appLocals = appLocals;
6021
6035
  expressServer.use(
6022
6036
  BASE_PATH,
6023
6037
  await createDevServerRoutes_default(
6024
6038
  viteServer,
6025
- storybook2 ? STORYBOOK_PORT : null,
6026
- appServerConfig
6039
+ appLocals,
6040
+ storybook2 ? STORYBOOK_PORT : null
6027
6041
  )
6028
6042
  );
6029
6043
  if (sslEnabledOption2) {
@@ -6066,8 +6080,8 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
6066
6080
  `
6067
6081
  );
6068
6082
  if (storybook2) {
6069
- const packageRoot = path16.dirname(url2.fileURLToPath(import.meta.url));
6070
- const configPath = path16.resolve(packageRoot, "./storybook-main");
6083
+ const packageRoot = path17.dirname(url2.fileURLToPath(import.meta.url));
6084
+ const configPath = path17.resolve(packageRoot, "./storybook-main");
6071
6085
  sendTrackingRequest("start-storybook");
6072
6086
  const storybookProcess = spawn2(
6073
6087
  "sb",
@@ -6087,7 +6101,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
6087
6101
  portalId: authedPortalId.toString(),
6088
6102
  hsEnv: authedEnv,
6089
6103
  hublet: authedHublet,
6090
- WEB_ROOT: path16.join(webRoot2, "components")
6104
+ WEB_ROOT: path17.join(webRoot2, "components")
6091
6105
  }
6092
6106
  }
6093
6107
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -29,7 +29,7 @@
29
29
  "@babel/parser": "^7.25.3",
30
30
  "@babel/traverse": "^7.25.3",
31
31
  "@babel/types": "^7.25.2",
32
- "@hubspot/cms-components": "^1.0.6",
32
+ "@hubspot/cms-components": "^1.0.7",
33
33
  "@hubspot/local-dev-lib": "2.0.1",
34
34
  "@inquirer/select": "^2.0.0",
35
35
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -131,5 +131,5 @@
131
131
  "publishConfig": {
132
132
  "access": "public"
133
133
  },
134
- "gitHead": "df338807efcf22bb5ce9b59c2473010cea96bab7"
134
+ "gitHead": "46df6c8d1a6a0ae518ace99d475d736e02d63b73"
135
135
  }
@@ -0,0 +1,5 @@
1
+ export declare const API_ERRORS: {
2
+ readonly MISSING_PARAMS: "MISSING_PARAMS";
3
+ readonly FETCH_FAILED: "FETCH_FAILED";
4
+ };
5
+ export declare type ApiError = (typeof API_ERRORS)[keyof typeof API_ERRORS];
@@ -0,0 +1,2 @@
1
+ import { InlineConfig } from 'vite';
2
+ export declare function createAppViteConfig(webRoot: string, port: number): InlineConfig;
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ export declare function getDevServerCommandLineOptions(argv: NodeJS.Process['argv']): {
3
+ hubspotCliConfigPathOption: string;
4
+ hubspotCliAccountNameOption: string;
5
+ sslEnabledOption: boolean;
6
+ storybook: boolean;
7
+ fieldGenEnabledOption: boolean;
8
+ webRoot: string;
9
+ resetSession: boolean;
10
+ };
11
+ export declare function buildThemePreviewOptions(webRoot: string): Promise<{
12
+ filePaths: string[];
13
+ startProgressBar: (numFiles: any) => {
14
+ onAttemptCallback: () => void;
15
+ onSuccessCallback: () => void;
16
+ onFirstErrorCallback: () => void;
17
+ onRetryCallback: () => void;
18
+ onFinalErrorCallback: () => any;
19
+ onFinishCallback: (results: any) => void;
20
+ };
21
+ dest: any;
22
+ }>;
@@ -0,0 +1,14 @@
1
+ export declare function determineSrcAndDest(): Promise<{
2
+ absoluteSrc: any;
3
+ dest: any;
4
+ }>;
5
+ export declare function getUploadableFileList(src: any, convertFields: any): Promise<any[]>;
6
+ export declare function fieldsJsPrompt(filePath: any, projectDir: any, skipFiles?: any[]): Promise<any[]>;
7
+ export declare function logError(error: any, context?: {}): void;
8
+ export declare class ApiErrorContext {
9
+ accountId: any;
10
+ request: any;
11
+ payload: any;
12
+ projectName: any;
13
+ constructor(props?: any);
14
+ }