@hubspot/cms-dev-server 1.2.77 → 1.2.79

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.
@@ -10,7 +10,7 @@ import { createServer as createViteServer } from "vite";
10
10
  import { createRequire } from "module";
11
11
  import { default as react } from "@vitejs/plugin-react";
12
12
 
13
- // ../cms-js-internal/dist/types-B-d4FeeE.js
13
+ // ../cms-js-internal/dist/types-Dvw_fW6p.js
14
14
  import path from "path";
15
15
  var viteRoot;
16
16
  var viteCommand;
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { createServer as createViteServer } from "vite";
3
3
  import { createRequire } from "module";
4
4
  import { default as react } from "@vitejs/plugin-react";
5
5
 
6
- // ../cms-js-internal/dist/types-B-d4FeeE.js
6
+ // ../cms-js-internal/dist/types-Dvw_fW6p.js
7
7
  import path from "path";
8
8
  import { createHash } from "crypto";
9
9
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
@@ -254,6 +254,13 @@ function isFullHeightPreviewEnabled(config) {
254
254
  }
255
255
  return false;
256
256
  }
257
+ function isLocalUiDisabled(config) {
258
+ var _a;
259
+ if ("devServer" in config) {
260
+ return ((_a = config.devServer) == null ? void 0 : _a.disableLocalUi) ?? false;
261
+ }
262
+ return false;
263
+ }
257
264
  var ENABLED_FEATURES_GATE_MAP = {
258
265
  "cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules",
259
266
  "PortalsAccessIdentity:DesignManager:UrlSigning": "PortalsAccessIdentity:DesignManager:UrlSigning"
@@ -1650,7 +1657,7 @@ function trackUsage(action) {
1650
1657
  eventName: EVENT_NAME,
1651
1658
  action,
1652
1659
  nodeVersion: getNodeVersionData(),
1653
- version: "1.2.77",
1660
+ version: "1.2.79",
1654
1661
  os: getPlatform()
1655
1662
  };
1656
1663
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -3090,8 +3097,84 @@ function extractRelevantCss(cssText) {
3090
3097
  return output;
3091
3098
  }
3092
3099
 
3100
+ // src/lib/htmlExtract.ts
3101
+ import { parse as parse2, serializeOuter } from "parse5";
3102
+ function parseHtml(html) {
3103
+ return parse2(html);
3104
+ }
3105
+ function isElement(node) {
3106
+ return typeof node.tagName === "string";
3107
+ }
3108
+ function getAttr(node, name) {
3109
+ var _a, _b;
3110
+ return (_b = (_a = node.attrs) == null ? void 0 : _a.find((a) => a.name === name)) == null ? void 0 : _b.value;
3111
+ }
3112
+ function findFirst(node, predicate) {
3113
+ if (predicate(node))
3114
+ return node;
3115
+ if (node.childNodes) {
3116
+ for (const child of node.childNodes) {
3117
+ const match = findFirst(child, predicate);
3118
+ if (match)
3119
+ return match;
3120
+ }
3121
+ }
3122
+ return null;
3123
+ }
3124
+ function findAll(node, predicate) {
3125
+ const out = [];
3126
+ const visit = (n) => {
3127
+ var _a;
3128
+ if (predicate(n))
3129
+ out.push(n);
3130
+ (_a = n.childNodes) == null ? void 0 : _a.forEach(visit);
3131
+ };
3132
+ visit(node);
3133
+ return out;
3134
+ }
3135
+ function textContent(node) {
3136
+ let out = "";
3137
+ const visit = (n) => {
3138
+ var _a;
3139
+ if (n.nodeName === "#text" && typeof n.value === "string")
3140
+ out += n.value;
3141
+ (_a = n.childNodes) == null ? void 0 : _a.forEach(visit);
3142
+ };
3143
+ visit(node);
3144
+ return out;
3145
+ }
3146
+ function hasAncestor(node, predicate) {
3147
+ let p = node.parentNode;
3148
+ while (p) {
3149
+ if (predicate(p))
3150
+ return true;
3151
+ p = p.parentNode ?? null;
3152
+ }
3153
+ return false;
3154
+ }
3155
+ function extractModuleOuterHtml(root) {
3156
+ const el = findFirst(
3157
+ root,
3158
+ (n) => isElement(n) && n.tagName === "div" && getAttr(n, "data-hs-cos-type") === "module"
3159
+ );
3160
+ if (!el) {
3161
+ throw new Error(
3162
+ 'module node (div[data-hs-cos-type="module"]) not found in preview HTML'
3163
+ );
3164
+ }
3165
+ return serializeOuter(el);
3166
+ }
3167
+ function extractStyleText(root, opts = {}) {
3168
+ let styles = findAll(root, (n) => isElement(n) && n.tagName === "style");
3169
+ if (opts.headOnly) {
3170
+ styles = styles.filter(
3171
+ (s) => hasAncestor(s, (a) => isElement(a) && a.tagName === "head")
3172
+ );
3173
+ }
3174
+ return styles.map((s) => textContent(s)).join("\n");
3175
+ }
3176
+
3093
3177
  // src/lib/renderModulePreview.ts
3094
- import jsdom from "jsdom";
3095
3178
  var DEFAULT_SECTION_VARIANT = "section1";
3096
3179
  var _webDefaultStylesCss = null;
3097
3180
  function getWebDefaultStylesCss(metaUrl) {
@@ -3153,7 +3236,6 @@ async function signedGet(authedPortalId, unsignedUrl, headers, gates) {
3153
3236
  }
3154
3237
  return await response.text();
3155
3238
  }
3156
- var { JSDOM } = jsdom;
3157
3239
  async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue, gates) {
3158
3240
  const moduleInfoQueryParams = new URLSearchParams({
3159
3241
  portalId: `${authedPortalId}`
@@ -3206,13 +3288,9 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
3206
3288
  }
3207
3289
  }
3208
3290
  }
3209
- const dom = new JSDOM(modulePreviewHtml);
3210
- const modulePreviewContent = dom.window.document.querySelector(
3211
- 'div[data-hs-cos-type="module"]'
3212
- ).outerHTML;
3213
- const allStyleContent = Array.from(
3214
- dom.window.document.querySelectorAll("style")
3215
- ).map((element) => element.textContent || "").join("\n");
3291
+ const previewDoc = parseHtml(modulePreviewHtml);
3292
+ const modulePreviewContent = extractModuleOuterHtml(previewDoc);
3293
+ const allStyleContent = extractStyleText(previewDoc);
3216
3294
  const filteredCss = extractRelevantCss(allStyleContent);
3217
3295
  const cssNeeded = filteredCss ? `<style>${filteredCss}</style>` : "";
3218
3296
  return { html: modulePreviewContent, cssNeeded };
@@ -3337,10 +3415,9 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3337
3415
  );
3338
3416
  }
3339
3417
  localRenderPlaceholders[0].json.props.fieldValues = localFieldValues;
3340
- const previewDom = new JSDOM(templatePreview);
3341
- const allStyleContent = Array.from(
3342
- previewDom.window.document.querySelectorAll("head style")
3343
- ).map((element) => element.textContent || "").join("\n");
3418
+ const allStyleContent = extractStyleText(parseHtml(templatePreview), {
3419
+ headOnly: true
3420
+ });
3344
3421
  const filteredCss = extractRelevantCss(allStyleContent);
3345
3422
  const themeVariablesCss = filteredCss ? `<style data-hs-styles="theme-variables">${filteredCss}</style>` : "";
3346
3423
  const webDefaultStylesCss = meta.editor_version === "2.0" ? getWebDefaultStylesCss(import.meta.url) : "";
@@ -4679,7 +4756,7 @@ async function getDevServerUIData(appLocals) {
4679
4756
  runCommand: `${runCommand} ${scriptName}`
4680
4757
  })
4681
4758
  ) : [];
4682
- reactModules = projectName ? await mapReactModules(modulesData, themeWebRoot, appViteServer) : [];
4759
+ reactModules = projectName && appViteServer ? await mapReactModules(modulesData, themeWebRoot, appViteServer) : [];
4683
4760
  }
4684
4761
  let hubLModuleData = { objects: [] };
4685
4762
  let hubLTemplateData = { objects: [] };
@@ -4738,6 +4815,11 @@ var appServerRouteHandler = async (req, res, __next) => {
4738
4815
  const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
4739
4816
  render = ssrRender;
4740
4817
  } else {
4818
+ if (!appViteServer) {
4819
+ throw new Error(
4820
+ "appViteServer is required to render the dev server UI in development"
4821
+ );
4822
+ }
4741
4823
  template = await appViteServer.transformIndexHtml(url3, template);
4742
4824
  render = (await appViteServer.ssrLoadModule(serverEntryPath)).render;
4743
4825
  }
@@ -4788,12 +4870,14 @@ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
4788
4870
  if (isProd2) {
4789
4871
  const distAssetsPath = path13.join(appWebRoot, "assets");
4790
4872
  devServerApp.use("/assets", expressStatic(distAssetsPath));
4791
- } else {
4873
+ } else if (appViteServer) {
4792
4874
  devServerApp.use("/local", appViteServer.middlewares);
4793
4875
  }
4794
4876
  devServerApp.use(viteServer.middlewares);
4795
4877
  devServerApp.use("/api", createAppServerAPIRoutes_default());
4796
- devServerApp.get("/", appServerRouteHandler_default);
4878
+ if (appViteServer) {
4879
+ devServerApp.get("/", appServerRouteHandler_default);
4880
+ }
4797
4881
  devServerApp.get("/legacy", legacyRouteHandler_default);
4798
4882
  devServerApp.get("/proxy", proxyPathPageRouteHandler);
4799
4883
  devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
@@ -4899,7 +4983,7 @@ async function createShadowDevServerRoutes(devServerPort, themePath) {
4899
4983
 
4900
4984
  // src/shadowDevServer/startShadowDevServer.ts
4901
4985
  var testNetServer = net.createServer();
4902
- async function startShadowDevServer(devServerPort, shadowPort, themePath) {
4986
+ async function startShadowDevServer(devServerPort, shadowPort, themePath, host) {
4903
4987
  const portIsTaken = await new Promise((res, rej) => {
4904
4988
  console.log(`Starting proxy link server on port ${shadowPort}`);
4905
4989
  testNetServer.once("error", (err) => {
@@ -4918,13 +5002,13 @@ async function startShadowDevServer(devServerPort, shadowPort, themePath) {
4918
5002
  testNetServer.once("close", () => {
4919
5003
  res(false);
4920
5004
  });
4921
- testNetServer.listen(shadowPort);
5005
+ testNetServer.listen(shadowPort, host);
4922
5006
  });
4923
5007
  if (portIsTaken) {
4924
5008
  return;
4925
5009
  }
4926
5010
  const shadowDevServer = express();
4927
- shadowDevServer.listen(shadowPort);
5011
+ shadowDevServer.listen(shadowPort, host);
4928
5012
  shadowDevServer.use(
4929
5013
  "/",
4930
5014
  await createShadowDevServerRoutes(devServerPort, themePath)
@@ -5307,7 +5391,6 @@ async function fetchWebsiteDomainNames(portalId) {
5307
5391
  // src/lib/validateHSPlatform.ts
5308
5392
  import path15 from "path";
5309
5393
  import fs7 from "fs";
5310
- import select from "@inquirer/select";
5311
5394
  import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
5312
5395
  var HSPROJECT_JSON = "hsproject.json";
5313
5396
  function checkFileExists(filePath) {
@@ -5330,7 +5413,7 @@ function findHSProjectJson(startPath) {
5330
5413
  );
5331
5414
  return null;
5332
5415
  }
5333
- async function validateHSPlatform(projectConfigPath, portalId) {
5416
+ async function validateHSPlatform(projectConfigPath, portalId, deferSelection) {
5334
5417
  if (projectConfigPath === null) {
5335
5418
  console.log(
5336
5419
  `Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
@@ -5354,29 +5437,37 @@ async function validateHSPlatform(projectConfigPath, portalId) {
5354
5437
  return false;
5355
5438
  }
5356
5439
  if (platformVersion === void 0 || !platformVersionResult.activePlatformVersions.includes(platformVersion)) {
5357
- const answer = await select({
5358
- message: 'Your local "hsproject.json" does not have a valid platform version, please select a valid platform version. You can read more about Platform Versioning here https://developers.hubspot.com/docs/platform/platform-versioning',
5359
- choices: platformVersionResult.activePlatformVersions.map(
5360
- (versionNumber) => ({
5361
- name: versionNumber,
5362
- value: versionNumber
5363
- })
5364
- )
5365
- });
5366
- hsProjectJSONData.platformVersion = answer;
5367
- try {
5368
- fs7.writeFileSync(
5369
- projectConfigPath,
5370
- JSON.stringify(hsProjectJSONData, void 0, 2),
5371
- "utf8"
5372
- );
5373
- return true;
5374
- } catch (e) {
5375
- console.error(
5376
- `unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
5377
- );
5440
+ const promptAndWrite = async () => {
5441
+ const { default: select } = await import("@inquirer/select");
5442
+ const answer = await select({
5443
+ message: 'Your local "hsproject.json" does not have a valid platform version, please select a valid platform version. You can read more about Platform Versioning here https://developers.hubspot.com/docs/platform/platform-versioning',
5444
+ choices: platformVersionResult.activePlatformVersions.map(
5445
+ (versionNumber) => ({
5446
+ name: versionNumber,
5447
+ value: versionNumber
5448
+ })
5449
+ )
5450
+ });
5451
+ hsProjectJSONData.platformVersion = answer;
5452
+ try {
5453
+ fs7.writeFileSync(
5454
+ projectConfigPath,
5455
+ JSON.stringify(hsProjectJSONData, void 0, 2),
5456
+ "utf8"
5457
+ );
5458
+ return true;
5459
+ } catch (e) {
5460
+ console.error(
5461
+ `unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
5462
+ );
5463
+ return false;
5464
+ }
5465
+ };
5466
+ if (deferSelection) {
5467
+ deferSelection(promptAndWrite);
5378
5468
  return false;
5379
5469
  }
5470
+ return promptAndWrite();
5380
5471
  }
5381
5472
  return true;
5382
5473
  }
@@ -5754,6 +5845,7 @@ function getSecretNamesFromConfig(config) {
5754
5845
  // src/createDevServer.ts
5755
5846
  var BASE_PATH = "/";
5756
5847
  var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
5848
+ var DEV_SERVER_HOST = process.env.CMS_DEV_SERVER_HOST || "127.0.0.1";
5757
5849
  var SHADOW_PORT = 1442;
5758
5850
  var STORYBOOK_PORT = process.env.STORYBOOK_PORT ? parseInt(process.env.STORYBOOK_PORT, 10) : 3123;
5759
5851
  function getWebRootProjectComponentFolder(absoluteWebRoot, projectConfigPath) {
@@ -5823,22 +5915,46 @@ async function createDevServer(webRoot, storybook, hubspotCliConfigPathOption, h
5823
5915
  }
5824
5916
  authedEnv = env2;
5825
5917
  personalAccessKey = (account == null ? void 0 : account.authType) === PERSONAL_ACCESS_KEY_AUTH_METHOD.value ? account == null ? void 0 : account.personalAccessKey : null;
5826
- if (personalAccessKey) {
5918
+ } else {
5919
+ console.warn(
5920
+ `Couldn't find an account to use, make sure there is hubspot.config.yaml in this folder (or a parent).
5921
+ If needed you can refer to another config file with --config.
5922
+
5923
+ Local proxy functionality and module preview routes will not work without setting up authentication. You can work purely on modules locally at "/module/[module_name]", however the experience may be degraded due to missing account data.`
5924
+ );
5925
+ secretNames = secretNamesFromConfig;
5926
+ }
5927
+ setTrackingInfo(authedPortalId, authedEnv);
5928
+ sendTrackingRequest("start-dev-server");
5929
+ const absoluteWebRoot = normalizePath10(path17.resolve(process.cwd(), webRoot));
5930
+ const projectConfigPath = findHSProjectJson(absoluteWebRoot);
5931
+ const webRootProjectComponentFolder = getWebRootProjectComponentFolder(
5932
+ absoluteWebRoot,
5933
+ projectConfigPath
5934
+ );
5935
+ let domainsToProxy = [];
5936
+ let authedHublet = "na1";
5937
+ let platformVersionPrompt = null;
5938
+ const bootTasks = [];
5939
+ if (isValid && personalAccessKey) {
5940
+ const portalId = authedPortalId;
5941
+ const env2 = authedEnv;
5942
+ const pak = personalAccessKey;
5943
+ bootTasks.push(async () => {
5827
5944
  try {
5828
- jsRenderingGates = await getJsRenderingGates(
5829
- authedPortalId,
5830
- authedEnv,
5831
- personalAccessKey
5832
- );
5945
+ jsRenderingGates = await getJsRenderingGates(portalId, env2, pak);
5833
5946
  } catch (e) {
5834
5947
  console.warn(
5835
5948
  `Unable to get gating information. Gated features will not be available in the local dev server.`
5836
5949
  );
5837
5950
  }
5838
- }
5839
- if (cmsAssetConfig) {
5951
+ });
5952
+ }
5953
+ if (isValid && cmsAssetConfig) {
5954
+ const portalId = authedPortalId;
5955
+ bootTasks.push(async () => {
5840
5956
  try {
5841
- const secretsResponse = (await fetchSecrets(authedPortalId)).data;
5957
+ const secretsResponse = (await fetchSecrets(portalId)).data;
5842
5958
  if (secretNamesFromConfig && secretsResponse) {
5843
5959
  secretNames = secretsResponse.results.filter(
5844
5960
  (secretName) => secretNamesFromConfig.includes(secretName)
@@ -5858,54 +5974,51 @@ async function createDevServer(webRoot, storybook, hubspotCliConfigPathOption, h
5858
5974
  handleSecretsError(e);
5859
5975
  console.log(e);
5860
5976
  }
5861
- }
5862
- } else {
5863
- console.warn(
5864
- `Couldn't find an account to use, make sure there is hubspot.config.yaml in this folder (or a parent).
5865
- If needed you can refer to another config file with --config.
5866
-
5867
- Local proxy functionality and module preview routes will not work without setting up authentication. You can work purely on modules locally at "/module/[module_name]", however the experience may be degraded due to missing account data.`
5868
- );
5869
- secretNames = secretNamesFromConfig;
5977
+ });
5870
5978
  }
5871
- setTrackingInfo(authedPortalId, authedEnv);
5872
- sendTrackingRequest("start-dev-server");
5873
- let domainsToProxy = [];
5874
5979
  if (authedPortalId) {
5875
- try {
5876
- const portalDomains = await fetchWebsiteDomainNames(authedPortalId);
5877
- domainsToProxy = (process.env.DOMAINS_TO_PROXY || "").split(",").filter((d) => !!d);
5878
- domainsToProxy = [...domainsToProxy, ...portalDomains];
5879
- } catch (e) {
5880
- if (e instanceof MissingScopeError) {
5881
- logMissingScopeWarning(e);
5882
- } else {
5883
- const failedDomainFetchMessages = [
5884
- "Failed to fetch the portal's domains, as a result:",
5885
- "- HTTPS proxying won't work with them.",
5886
- "- Proxying to serverless functions won't work."
5887
- ].map((msg) => wrapMessageInColor("yellow", msg)).join("\n");
5888
- console.warn(failedDomainFetchMessages);
5980
+ const portalId = authedPortalId;
5981
+ bootTasks.push(async () => {
5982
+ try {
5983
+ const portalDomains = await fetchWebsiteDomainNames(portalId);
5984
+ domainsToProxy = (process.env.DOMAINS_TO_PROXY || "").split(",").filter((d) => !!d);
5985
+ domainsToProxy = [...domainsToProxy, ...portalDomains];
5986
+ } catch (e) {
5987
+ if (e instanceof MissingScopeError) {
5988
+ logMissingScopeWarning(e);
5989
+ } else {
5990
+ const failedDomainFetchMessages = [
5991
+ "Failed to fetch the portal's domains, as a result:",
5992
+ "- HTTPS proxying won't work with them.",
5993
+ "- Proxying to serverless functions won't work."
5994
+ ].map((msg) => wrapMessageInColor("yellow", msg)).join("\n");
5995
+ console.warn(failedDomainFetchMessages);
5996
+ }
5889
5997
  }
5890
- }
5891
- }
5892
- let authedHublet;
5893
- try {
5894
- const accountInformation = (await hsCliHttp12.get(authedPortalId, {
5895
- url: "/account-info/v3/details"
5896
- })).data;
5897
- authedHublet = accountInformation.dataHostingLocation;
5898
- } catch (e) {
5899
- authedHublet = "na1";
5998
+ });
5999
+ bootTasks.push(async () => {
6000
+ try {
6001
+ const accountInformation = (await hsCliHttp12.get(portalId, {
6002
+ url: "/account-info/v3/details"
6003
+ })).data;
6004
+ authedHublet = accountInformation.dataHostingLocation;
6005
+ } catch (e) {
6006
+ authedHublet = "na1";
6007
+ }
6008
+ });
6009
+ bootTasks.push(async () => {
6010
+ await validateHSPlatform(
6011
+ projectConfigPath,
6012
+ portalId,
6013
+ (promptAndWrite) => {
6014
+ platformVersionPrompt = promptAndWrite;
6015
+ }
6016
+ );
6017
+ });
5900
6018
  }
5901
- const absoluteWebRoot = normalizePath10(path17.resolve(process.cwd(), webRoot));
5902
- const projectConfigPath = findHSProjectJson(absoluteWebRoot);
5903
- const webRootProjectComponentFolder = getWebRootProjectComponentFolder(
5904
- absoluteWebRoot,
5905
- projectConfigPath
5906
- );
5907
- if (authedPortalId) {
5908
- await validateHSPlatform(projectConfigPath, authedPortalId);
6019
+ await Promise.all(bootTasks.map((task) => task()));
6020
+ if (platformVersionPrompt) {
6021
+ await platformVersionPrompt();
5909
6022
  }
5910
6023
  let _localPreviewToken = null;
5911
6024
  let _tokenStatus;
@@ -5958,11 +6071,8 @@ Local proxy functionality and module preview routes will not work without settin
5958
6071
  if (true) {
5959
6072
  appWebRoot = path17.join(__dirname, "app");
5960
6073
  }
5961
- const appViteServer = await createAppServer_default(
5962
- appWebRoot,
5963
- PORT,
5964
- sslEnabledOption
5965
- );
6074
+ const skipUiServer = isLocalUiDisabled(cmsAssetConfig);
6075
+ const appViteServer = skipUiServer ? null : await createAppServer_default(appWebRoot, PORT, sslEnabledOption);
5966
6076
  const appLocals = {
5967
6077
  themeWebRoot: absoluteWebRoot,
5968
6078
  authedPortalId,
@@ -5991,7 +6101,7 @@ Local proxy functionality and module preview routes will not work without settin
5991
6101
  { key: httpsKey, cert: httpsCert },
5992
6102
  expressServer
5993
6103
  );
5994
- server.listen(PORT);
6104
+ server.listen(PORT, DEV_SERVER_HOST);
5995
6105
  httpServers.push(server);
5996
6106
  httpServers.push(innerHTTPServer);
5997
6107
  httpServers.push(innerHTTPSServer);
@@ -6001,14 +6111,15 @@ Local proxy functionality and module preview routes will not work without settin
6001
6111
  }
6002
6112
  } else {
6003
6113
  const httpServer = http3.createServer(expressServer);
6004
- httpServer.listen(PORT);
6114
+ httpServer.listen(PORT, DEV_SERVER_HOST);
6005
6115
  httpServers.push(httpServer);
6006
6116
  }
6007
6117
  if (!process.env.IN_CODESANDBOX && !process.env.CODESANDBOX_HOST) {
6008
6118
  startShadowDevServer(
6009
6119
  PORT,
6010
6120
  SHADOW_PORT,
6011
- themePreviewOptions ? themePreviewOptions.dest : ""
6121
+ themePreviewOptions ? themePreviewOptions.dest : "",
6122
+ DEV_SERVER_HOST
6012
6123
  );
6013
6124
  }
6014
6125
  let extraServerInfo = "";
@@ -6100,7 +6211,7 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
6100
6211
  return Promise.allSettled([
6101
6212
  ...serverClosePromises,
6102
6213
  viteServer.close(),
6103
- appViteServer.close()
6214
+ appViteServer ? appViteServer.close() : Promise.resolve()
6104
6215
  ]);
6105
6216
  }
6106
6217
  };
@@ -1,4 +1,4 @@
1
- // ../cms-js-internal/dist/types-B-d4FeeE.js
1
+ // ../cms-js-internal/dist/types-Dvw_fW6p.js
2
2
  import path from "path";
3
3
  import { createHash } from "crypto";
4
4
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
@@ -373,6 +373,13 @@ function isFullHeightPreviewEnabled(config) {
373
373
  }
374
374
  return false;
375
375
  }
376
+ function isLocalUiDisabled(config) {
377
+ var _a;
378
+ if ("devServer" in config) {
379
+ return ((_a = config.devServer) == null ? void 0 : _a.disableLocalUi) ?? false;
380
+ }
381
+ return false;
382
+ }
376
383
  var BUILD_INFO_PATH = "/build-info.json";
377
384
  function getBuildInfo(buildDir) {
378
385
  try {
@@ -1294,6 +1301,7 @@ export {
1294
1301
  hasComponentExtension,
1295
1302
  includesHublDataReference,
1296
1303
  isFullHeightPreviewEnabled,
1304
+ isLocalUiDisabled,
1297
1305
  isStorybookStory,
1298
1306
  isStylesheetAsset,
1299
1307
  isUngatedFor,
@@ -44,10 +44,14 @@ function isValidHostname(hostname) {
44
44
  (label) => label.length >= 1 && label.length <= 63 && !label.startsWith("-") && !label.endsWith("-")
45
45
  );
46
46
  }
47
+ var LOCAL_DEV_HOSTNAMES = ["localhost", "127.0.0.1", "0.0.0.0", "[::1]"];
47
48
  function getSecureOverrideUrl(path) {
48
49
  const currentUrl = new URL(window.location.toString());
49
50
  const overrideHost = currentUrl.searchParams.get("hsDebugOverridePublicHost");
50
51
  try {
52
+ if (!LOCAL_DEV_HOSTNAMES.includes(currentUrl.hostname)) {
53
+ throw new Error("Override host is only allowed in local development");
54
+ }
51
55
  if (!overrideHost) {
52
56
  throw new Error("No override host provided");
53
57
  }
package/dist/run.js CHANGED
@@ -45,7 +45,6 @@ import { createIgnoreFilter } from "@hubspot/local-dev-lib/ignoreRules";
45
45
  import { isAllowedExtension } from "@hubspot/local-dev-lib/path";
46
46
  import { isConvertableFieldJs } from "@hubspot/local-dev-lib/cms/handleFieldsJS";
47
47
  import { escapeRegExp } from "@hubspot/local-dev-lib/escapeRegExp";
48
- import inquirer from "inquirer";
49
48
  import { getThemeJSONPath } from "@hubspot/local-dev-lib/cms/themes";
50
49
  import findup from "findup-sync";
51
50
  import { getAbsoluteFilePath } from "@hubspot/local-dev-lib/path";
@@ -357,7 +356,8 @@ async function getUploadableFileList(src, convertFields) {
357
356
  }
358
357
  return uploadableFiles;
359
358
  }
360
- function promptUser(promptConfig) {
359
+ async function promptUser(promptConfig) {
360
+ const { default: inquirer } = await import("inquirer");
361
361
  const prompt = inquirer.createPromptModule();
362
362
  return prompt(promptConfig);
363
363
  }
@@ -896,7 +896,7 @@ function packagePath(metaUrl, projectPath) {
896
896
  );
897
897
  }
898
898
 
899
- // ../cms-js-internal/dist/types-B-d4FeeE.js
899
+ // ../cms-js-internal/dist/types-Dvw_fW6p.js
900
900
  import path4 from "path";
901
901
  import { createHash } from "crypto";
902
902
  import fs3, { readFileSync, existsSync as existsSync2, readdirSync, lstatSync } from "fs";
@@ -1147,6 +1147,13 @@ function isFullHeightPreviewEnabled(config) {
1147
1147
  }
1148
1148
  return false;
1149
1149
  }
1150
+ function isLocalUiDisabled(config) {
1151
+ var _a;
1152
+ if ("devServer" in config) {
1153
+ return ((_a = config.devServer) == null ? void 0 : _a.disableLocalUi) ?? false;
1154
+ }
1155
+ return false;
1156
+ }
1150
1157
  var ENABLED_FEATURES_GATE_MAP = {
1151
1158
  "cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules",
1152
1159
  "PortalsAccessIdentity:DesignManager:UrlSigning": "PortalsAccessIdentity:DesignManager:UrlSigning"
@@ -2255,7 +2262,7 @@ function trackUsage(action) {
2255
2262
  eventName: EVENT_NAME,
2256
2263
  action,
2257
2264
  nodeVersion: getNodeVersionData(),
2258
- version: "1.2.77",
2265
+ version: "1.2.79",
2259
2266
  os: getPlatform()
2260
2267
  };
2261
2268
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -3695,8 +3702,84 @@ function extractRelevantCss(cssText) {
3695
3702
  return output;
3696
3703
  }
3697
3704
 
3705
+ // src/lib/htmlExtract.ts
3706
+ import { parse as parse2, serializeOuter } from "parse5";
3707
+ function parseHtml(html) {
3708
+ return parse2(html);
3709
+ }
3710
+ function isElement(node) {
3711
+ return typeof node.tagName === "string";
3712
+ }
3713
+ function getAttr(node, name) {
3714
+ var _a, _b;
3715
+ return (_b = (_a = node.attrs) == null ? void 0 : _a.find((a) => a.name === name)) == null ? void 0 : _b.value;
3716
+ }
3717
+ function findFirst(node, predicate) {
3718
+ if (predicate(node))
3719
+ return node;
3720
+ if (node.childNodes) {
3721
+ for (const child of node.childNodes) {
3722
+ const match = findFirst(child, predicate);
3723
+ if (match)
3724
+ return match;
3725
+ }
3726
+ }
3727
+ return null;
3728
+ }
3729
+ function findAll(node, predicate) {
3730
+ const out = [];
3731
+ const visit = (n) => {
3732
+ var _a;
3733
+ if (predicate(n))
3734
+ out.push(n);
3735
+ (_a = n.childNodes) == null ? void 0 : _a.forEach(visit);
3736
+ };
3737
+ visit(node);
3738
+ return out;
3739
+ }
3740
+ function textContent(node) {
3741
+ let out = "";
3742
+ const visit = (n) => {
3743
+ var _a;
3744
+ if (n.nodeName === "#text" && typeof n.value === "string")
3745
+ out += n.value;
3746
+ (_a = n.childNodes) == null ? void 0 : _a.forEach(visit);
3747
+ };
3748
+ visit(node);
3749
+ return out;
3750
+ }
3751
+ function hasAncestor(node, predicate) {
3752
+ let p = node.parentNode;
3753
+ while (p) {
3754
+ if (predicate(p))
3755
+ return true;
3756
+ p = p.parentNode ?? null;
3757
+ }
3758
+ return false;
3759
+ }
3760
+ function extractModuleOuterHtml(root) {
3761
+ const el = findFirst(
3762
+ root,
3763
+ (n) => isElement(n) && n.tagName === "div" && getAttr(n, "data-hs-cos-type") === "module"
3764
+ );
3765
+ if (!el) {
3766
+ throw new Error(
3767
+ 'module node (div[data-hs-cos-type="module"]) not found in preview HTML'
3768
+ );
3769
+ }
3770
+ return serializeOuter(el);
3771
+ }
3772
+ function extractStyleText(root, opts = {}) {
3773
+ let styles = findAll(root, (n) => isElement(n) && n.tagName === "style");
3774
+ if (opts.headOnly) {
3775
+ styles = styles.filter(
3776
+ (s) => hasAncestor(s, (a) => isElement(a) && a.tagName === "head")
3777
+ );
3778
+ }
3779
+ return styles.map((s) => textContent(s)).join("\n");
3780
+ }
3781
+
3698
3782
  // src/lib/renderModulePreview.ts
3699
- import jsdom from "jsdom";
3700
3783
  var DEFAULT_SECTION_VARIANT = "section1";
3701
3784
  var _webDefaultStylesCss = null;
3702
3785
  function getWebDefaultStylesCss(metaUrl) {
@@ -3758,7 +3841,6 @@ async function signedGet(authedPortalId, unsignedUrl, headers, gates) {
3758
3841
  }
3759
3842
  return await response.text();
3760
3843
  }
3761
- var { JSDOM } = jsdom;
3762
3844
  async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue, gates) {
3763
3845
  const moduleInfoQueryParams = new URLSearchParams({
3764
3846
  portalId: `${authedPortalId}`
@@ -3811,13 +3893,9 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
3811
3893
  }
3812
3894
  }
3813
3895
  }
3814
- const dom = new JSDOM(modulePreviewHtml);
3815
- const modulePreviewContent = dom.window.document.querySelector(
3816
- 'div[data-hs-cos-type="module"]'
3817
- ).outerHTML;
3818
- const allStyleContent = Array.from(
3819
- dom.window.document.querySelectorAll("style")
3820
- ).map((element) => element.textContent || "").join("\n");
3896
+ const previewDoc = parseHtml(modulePreviewHtml);
3897
+ const modulePreviewContent = extractModuleOuterHtml(previewDoc);
3898
+ const allStyleContent = extractStyleText(previewDoc);
3821
3899
  const filteredCss = extractRelevantCss(allStyleContent);
3822
3900
  const cssNeeded = filteredCss ? `<style>${filteredCss}</style>` : "";
3823
3901
  return { html: modulePreviewContent, cssNeeded };
@@ -3942,10 +4020,9 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3942
4020
  );
3943
4021
  }
3944
4022
  localRenderPlaceholders[0].json.props.fieldValues = localFieldValues;
3945
- const previewDom = new JSDOM(templatePreview);
3946
- const allStyleContent = Array.from(
3947
- previewDom.window.document.querySelectorAll("head style")
3948
- ).map((element) => element.textContent || "").join("\n");
4023
+ const allStyleContent = extractStyleText(parseHtml(templatePreview), {
4024
+ headOnly: true
4025
+ });
3949
4026
  const filteredCss = extractRelevantCss(allStyleContent);
3950
4027
  const themeVariablesCss = filteredCss ? `<style data-hs-styles="theme-variables">${filteredCss}</style>` : "";
3951
4028
  const webDefaultStylesCss = meta.editor_version === "2.0" ? getWebDefaultStylesCss(import.meta.url) : "";
@@ -5503,7 +5580,7 @@ async function getDevServerUIData(appLocals) {
5503
5580
  runCommand: `${runCommand} ${scriptName}`
5504
5581
  })
5505
5582
  ) : [];
5506
- reactModules = projectName ? await mapReactModules(modulesData, themeWebRoot, appViteServer) : [];
5583
+ reactModules = projectName && appViteServer ? await mapReactModules(modulesData, themeWebRoot, appViteServer) : [];
5507
5584
  }
5508
5585
  let hubLModuleData = { objects: [] };
5509
5586
  let hubLTemplateData = { objects: [] };
@@ -5562,6 +5639,11 @@ var appServerRouteHandler = async (req, res, __next) => {
5562
5639
  const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
5563
5640
  render = ssrRender;
5564
5641
  } else {
5642
+ if (!appViteServer) {
5643
+ throw new Error(
5644
+ "appViteServer is required to render the dev server UI in development"
5645
+ );
5646
+ }
5565
5647
  template = await appViteServer.transformIndexHtml(url3, template);
5566
5648
  render = (await appViteServer.ssrLoadModule(serverEntryPath)).render;
5567
5649
  }
@@ -5612,12 +5694,14 @@ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
5612
5694
  if (isProd2) {
5613
5695
  const distAssetsPath = path15.join(appWebRoot, "assets");
5614
5696
  devServerApp.use("/assets", expressStatic(distAssetsPath));
5615
- } else {
5697
+ } else if (appViteServer) {
5616
5698
  devServerApp.use("/local", appViteServer.middlewares);
5617
5699
  }
5618
5700
  devServerApp.use(viteServer.middlewares);
5619
5701
  devServerApp.use("/api", createAppServerAPIRoutes_default());
5620
- devServerApp.get("/", appServerRouteHandler_default);
5702
+ if (appViteServer) {
5703
+ devServerApp.get("/", appServerRouteHandler_default);
5704
+ }
5621
5705
  devServerApp.get("/legacy", legacyRouteHandler_default);
5622
5706
  devServerApp.get("/proxy", proxyPathPageRouteHandler);
5623
5707
  devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
@@ -5723,7 +5807,7 @@ async function createShadowDevServerRoutes(devServerPort, themePath) {
5723
5807
 
5724
5808
  // src/shadowDevServer/startShadowDevServer.ts
5725
5809
  var testNetServer = net.createServer();
5726
- async function startShadowDevServer(devServerPort, shadowPort, themePath) {
5810
+ async function startShadowDevServer(devServerPort, shadowPort, themePath, host) {
5727
5811
  const portIsTaken = await new Promise((res, rej) => {
5728
5812
  console.log(`Starting proxy link server on port ${shadowPort}`);
5729
5813
  testNetServer.once("error", (err) => {
@@ -5742,13 +5826,13 @@ async function startShadowDevServer(devServerPort, shadowPort, themePath) {
5742
5826
  testNetServer.once("close", () => {
5743
5827
  res(false);
5744
5828
  });
5745
- testNetServer.listen(shadowPort);
5829
+ testNetServer.listen(shadowPort, host);
5746
5830
  });
5747
5831
  if (portIsTaken) {
5748
5832
  return;
5749
5833
  }
5750
5834
  const shadowDevServer = express();
5751
- shadowDevServer.listen(shadowPort);
5835
+ shadowDevServer.listen(shadowPort, host);
5752
5836
  shadowDevServer.use(
5753
5837
  "/",
5754
5838
  await createShadowDevServerRoutes(devServerPort, themePath)
@@ -5976,7 +6060,6 @@ async function fetchWebsiteDomainNames(portalId) {
5976
6060
  // src/lib/validateHSPlatform.ts
5977
6061
  import path16 from "path";
5978
6062
  import fs8 from "fs";
5979
- import select from "@inquirer/select";
5980
6063
  import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
5981
6064
  var HSPROJECT_JSON = "hsproject.json";
5982
6065
  function checkFileExists(filePath) {
@@ -5999,7 +6082,7 @@ function findHSProjectJson(startPath) {
5999
6082
  );
6000
6083
  return null;
6001
6084
  }
6002
- async function validateHSPlatform(projectConfigPath, portalId) {
6085
+ async function validateHSPlatform(projectConfigPath, portalId, deferSelection) {
6003
6086
  if (projectConfigPath === null) {
6004
6087
  console.log(
6005
6088
  `Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
@@ -6023,29 +6106,37 @@ async function validateHSPlatform(projectConfigPath, portalId) {
6023
6106
  return false;
6024
6107
  }
6025
6108
  if (platformVersion === void 0 || !platformVersionResult.activePlatformVersions.includes(platformVersion)) {
6026
- const answer = await select({
6027
- message: 'Your local "hsproject.json" does not have a valid platform version, please select a valid platform version. You can read more about Platform Versioning here https://developers.hubspot.com/docs/platform/platform-versioning',
6028
- choices: platformVersionResult.activePlatformVersions.map(
6029
- (versionNumber) => ({
6030
- name: versionNumber,
6031
- value: versionNumber
6032
- })
6033
- )
6034
- });
6035
- hsProjectJSONData.platformVersion = answer;
6036
- try {
6037
- fs8.writeFileSync(
6038
- projectConfigPath,
6039
- JSON.stringify(hsProjectJSONData, void 0, 2),
6040
- "utf8"
6041
- );
6042
- return true;
6043
- } catch (e) {
6044
- console.error(
6045
- `unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
6046
- );
6109
+ const promptAndWrite = async () => {
6110
+ const { default: select } = await import("@inquirer/select");
6111
+ const answer = await select({
6112
+ message: 'Your local "hsproject.json" does not have a valid platform version, please select a valid platform version. You can read more about Platform Versioning here https://developers.hubspot.com/docs/platform/platform-versioning',
6113
+ choices: platformVersionResult.activePlatformVersions.map(
6114
+ (versionNumber) => ({
6115
+ name: versionNumber,
6116
+ value: versionNumber
6117
+ })
6118
+ )
6119
+ });
6120
+ hsProjectJSONData.platformVersion = answer;
6121
+ try {
6122
+ fs8.writeFileSync(
6123
+ projectConfigPath,
6124
+ JSON.stringify(hsProjectJSONData, void 0, 2),
6125
+ "utf8"
6126
+ );
6127
+ return true;
6128
+ } catch (e) {
6129
+ console.error(
6130
+ `unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
6131
+ );
6132
+ return false;
6133
+ }
6134
+ };
6135
+ if (deferSelection) {
6136
+ deferSelection(promptAndWrite);
6047
6137
  return false;
6048
6138
  }
6139
+ return promptAndWrite();
6049
6140
  }
6050
6141
  return true;
6051
6142
  }
@@ -6423,6 +6514,7 @@ function getSecretNamesFromConfig(config) {
6423
6514
  // src/createDevServer.ts
6424
6515
  var BASE_PATH = "/";
6425
6516
  var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
6517
+ var DEV_SERVER_HOST = process.env.CMS_DEV_SERVER_HOST || "127.0.0.1";
6426
6518
  var SHADOW_PORT = 1442;
6427
6519
  var STORYBOOK_PORT = process.env.STORYBOOK_PORT ? parseInt(process.env.STORYBOOK_PORT, 10) : 3123;
6428
6520
  function getWebRootProjectComponentFolder(absoluteWebRoot, projectConfigPath) {
@@ -6492,22 +6584,46 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
6492
6584
  }
6493
6585
  authedEnv = env2;
6494
6586
  personalAccessKey = (account == null ? void 0 : account.authType) === PERSONAL_ACCESS_KEY_AUTH_METHOD.value ? account == null ? void 0 : account.personalAccessKey : null;
6495
- if (personalAccessKey) {
6587
+ } else {
6588
+ console.warn(
6589
+ `Couldn't find an account to use, make sure there is hubspot.config.yaml in this folder (or a parent).
6590
+ If needed you can refer to another config file with --config.
6591
+
6592
+ Local proxy functionality and module preview routes will not work without setting up authentication. You can work purely on modules locally at "/module/[module_name]", however the experience may be degraded due to missing account data.`
6593
+ );
6594
+ secretNames = secretNamesFromConfig;
6595
+ }
6596
+ setTrackingInfo(authedPortalId, authedEnv);
6597
+ sendTrackingRequest("start-dev-server");
6598
+ const absoluteWebRoot = normalizePath10(path18.resolve(process.cwd(), webRoot2));
6599
+ const projectConfigPath = findHSProjectJson(absoluteWebRoot);
6600
+ const webRootProjectComponentFolder = getWebRootProjectComponentFolder(
6601
+ absoluteWebRoot,
6602
+ projectConfigPath
6603
+ );
6604
+ let domainsToProxy = [];
6605
+ let authedHublet = "na1";
6606
+ let platformVersionPrompt = null;
6607
+ const bootTasks = [];
6608
+ if (isValid && personalAccessKey) {
6609
+ const portalId = authedPortalId;
6610
+ const env2 = authedEnv;
6611
+ const pak = personalAccessKey;
6612
+ bootTasks.push(async () => {
6496
6613
  try {
6497
- jsRenderingGates = await getJsRenderingGates(
6498
- authedPortalId,
6499
- authedEnv,
6500
- personalAccessKey
6501
- );
6614
+ jsRenderingGates = await getJsRenderingGates(portalId, env2, pak);
6502
6615
  } catch (e) {
6503
6616
  console.warn(
6504
6617
  `Unable to get gating information. Gated features will not be available in the local dev server.`
6505
6618
  );
6506
6619
  }
6507
- }
6508
- if (cmsAssetConfig) {
6620
+ });
6621
+ }
6622
+ if (isValid && cmsAssetConfig) {
6623
+ const portalId = authedPortalId;
6624
+ bootTasks.push(async () => {
6509
6625
  try {
6510
- const secretsResponse = (await fetchSecrets(authedPortalId)).data;
6626
+ const secretsResponse = (await fetchSecrets(portalId)).data;
6511
6627
  if (secretNamesFromConfig && secretsResponse) {
6512
6628
  secretNames = secretsResponse.results.filter(
6513
6629
  (secretName) => secretNamesFromConfig.includes(secretName)
@@ -6527,54 +6643,51 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
6527
6643
  handleSecretsError(e);
6528
6644
  console.log(e);
6529
6645
  }
6530
- }
6531
- } else {
6532
- console.warn(
6533
- `Couldn't find an account to use, make sure there is hubspot.config.yaml in this folder (or a parent).
6534
- If needed you can refer to another config file with --config.
6535
-
6536
- Local proxy functionality and module preview routes will not work without setting up authentication. You can work purely on modules locally at "/module/[module_name]", however the experience may be degraded due to missing account data.`
6537
- );
6538
- secretNames = secretNamesFromConfig;
6646
+ });
6539
6647
  }
6540
- setTrackingInfo(authedPortalId, authedEnv);
6541
- sendTrackingRequest("start-dev-server");
6542
- let domainsToProxy = [];
6543
6648
  if (authedPortalId) {
6544
- try {
6545
- const portalDomains = await fetchWebsiteDomainNames(authedPortalId);
6546
- domainsToProxy = (process.env.DOMAINS_TO_PROXY || "").split(",").filter((d) => !!d);
6547
- domainsToProxy = [...domainsToProxy, ...portalDomains];
6548
- } catch (e) {
6549
- if (e instanceof MissingScopeError) {
6550
- logMissingScopeWarning(e);
6551
- } else {
6552
- const failedDomainFetchMessages = [
6553
- "Failed to fetch the portal's domains, as a result:",
6554
- "- HTTPS proxying won't work with them.",
6555
- "- Proxying to serverless functions won't work."
6556
- ].map((msg) => wrapMessageInColor("yellow", msg)).join("\n");
6557
- console.warn(failedDomainFetchMessages);
6649
+ const portalId = authedPortalId;
6650
+ bootTasks.push(async () => {
6651
+ try {
6652
+ const portalDomains = await fetchWebsiteDomainNames(portalId);
6653
+ domainsToProxy = (process.env.DOMAINS_TO_PROXY || "").split(",").filter((d) => !!d);
6654
+ domainsToProxy = [...domainsToProxy, ...portalDomains];
6655
+ } catch (e) {
6656
+ if (e instanceof MissingScopeError) {
6657
+ logMissingScopeWarning(e);
6658
+ } else {
6659
+ const failedDomainFetchMessages = [
6660
+ "Failed to fetch the portal's domains, as a result:",
6661
+ "- HTTPS proxying won't work with them.",
6662
+ "- Proxying to serverless functions won't work."
6663
+ ].map((msg) => wrapMessageInColor("yellow", msg)).join("\n");
6664
+ console.warn(failedDomainFetchMessages);
6665
+ }
6558
6666
  }
6559
- }
6560
- }
6561
- let authedHublet;
6562
- try {
6563
- const accountInformation = (await hsCliHttp12.get(authedPortalId, {
6564
- url: "/account-info/v3/details"
6565
- })).data;
6566
- authedHublet = accountInformation.dataHostingLocation;
6567
- } catch (e) {
6568
- authedHublet = "na1";
6667
+ });
6668
+ bootTasks.push(async () => {
6669
+ try {
6670
+ const accountInformation = (await hsCliHttp12.get(portalId, {
6671
+ url: "/account-info/v3/details"
6672
+ })).data;
6673
+ authedHublet = accountInformation.dataHostingLocation;
6674
+ } catch (e) {
6675
+ authedHublet = "na1";
6676
+ }
6677
+ });
6678
+ bootTasks.push(async () => {
6679
+ await validateHSPlatform(
6680
+ projectConfigPath,
6681
+ portalId,
6682
+ (promptAndWrite) => {
6683
+ platformVersionPrompt = promptAndWrite;
6684
+ }
6685
+ );
6686
+ });
6569
6687
  }
6570
- const absoluteWebRoot = normalizePath10(path18.resolve(process.cwd(), webRoot2));
6571
- const projectConfigPath = findHSProjectJson(absoluteWebRoot);
6572
- const webRootProjectComponentFolder = getWebRootProjectComponentFolder(
6573
- absoluteWebRoot,
6574
- projectConfigPath
6575
- );
6576
- if (authedPortalId) {
6577
- await validateHSPlatform(projectConfigPath, authedPortalId);
6688
+ await Promise.all(bootTasks.map((task) => task()));
6689
+ if (platformVersionPrompt) {
6690
+ await platformVersionPrompt();
6578
6691
  }
6579
6692
  let _localPreviewToken = null;
6580
6693
  let _tokenStatus;
@@ -6627,11 +6740,8 @@ Local proxy functionality and module preview routes will not work without settin
6627
6740
  if (true) {
6628
6741
  appWebRoot = path18.join(__dirname, "app");
6629
6742
  }
6630
- const appViteServer = await createAppServer_default(
6631
- appWebRoot,
6632
- PORT,
6633
- sslEnabledOption2
6634
- );
6743
+ const skipUiServer = isLocalUiDisabled(cmsAssetConfig);
6744
+ const appViteServer = skipUiServer ? null : await createAppServer_default(appWebRoot, PORT, sslEnabledOption2);
6635
6745
  const appLocals = {
6636
6746
  themeWebRoot: absoluteWebRoot,
6637
6747
  authedPortalId,
@@ -6660,7 +6770,7 @@ Local proxy functionality and module preview routes will not work without settin
6660
6770
  { key: httpsKey, cert: httpsCert },
6661
6771
  expressServer
6662
6772
  );
6663
- server.listen(PORT);
6773
+ server.listen(PORT, DEV_SERVER_HOST);
6664
6774
  httpServers.push(server);
6665
6775
  httpServers.push(innerHTTPServer);
6666
6776
  httpServers.push(innerHTTPSServer);
@@ -6670,14 +6780,15 @@ Local proxy functionality and module preview routes will not work without settin
6670
6780
  }
6671
6781
  } else {
6672
6782
  const httpServer = http3.createServer(expressServer);
6673
- httpServer.listen(PORT);
6783
+ httpServer.listen(PORT, DEV_SERVER_HOST);
6674
6784
  httpServers.push(httpServer);
6675
6785
  }
6676
6786
  if (!process.env.IN_CODESANDBOX && !process.env.CODESANDBOX_HOST) {
6677
6787
  startShadowDevServer(
6678
6788
  PORT,
6679
6789
  SHADOW_PORT,
6680
- themePreviewOptions2 ? themePreviewOptions2.dest : ""
6790
+ themePreviewOptions2 ? themePreviewOptions2.dest : "",
6791
+ DEV_SERVER_HOST
6681
6792
  );
6682
6793
  }
6683
6794
  let extraServerInfo = "";
@@ -6769,7 +6880,7 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
6769
6880
  return Promise.allSettled([
6770
6881
  ...serverClosePromises,
6771
6882
  viteServer.close(),
6772
- appViteServer.close()
6883
+ appViteServer ? appViteServer.close() : Promise.resolve()
6773
6884
  ]);
6774
6885
  }
6775
6886
  };
@@ -1,7 +1,7 @@
1
1
  // src/storybook/moduleStory.tsx
2
2
  import { useEffect } from "react";
3
3
 
4
- // ../cms-js-internal/dist/types-B-d4FeeE.js
4
+ // ../cms-js-internal/dist/types-Dvw_fW6p.js
5
5
  function namespaceModulePropsShape(props) {
6
6
  const {
7
7
  dataQueryResult,
@@ -8,7 +8,7 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
 
11
- // ../cms-js-internal/dist/types-B-d4FeeE.js
11
+ // ../cms-js-internal/dist/types-Dvw_fW6p.js
12
12
  import path from "path";
13
13
  import { createHash } from "crypto";
14
14
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
@@ -267,6 +267,13 @@ function isFullHeightPreviewEnabled(config) {
267
267
  }
268
268
  return false;
269
269
  }
270
+ function isLocalUiDisabled(config) {
271
+ var _a;
272
+ if ("devServer" in config) {
273
+ return ((_a = config.devServer) == null ? void 0 : _a.disableLocalUi) ?? false;
274
+ }
275
+ return false;
276
+ }
270
277
  function getBuildInfo(buildDir) {
271
278
  try {
272
279
  const buildInfo = JSON.parse(
@@ -385,8 +392,8 @@ function isStylesheetAsset(staticAsset) {
385
392
  return staticAsset.type === "stylesheet";
386
393
  }
387
394
  var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, TEMPLATE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, badInlineJsChars, inlineJsEscapeChars, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, removeIndexFromPath, removeIndexOrTrailingJsFromPath, HEALTHCHECKS_ENABLED_DEFAULT, HEALTHCHECKS_STRICT_DEFAULT, BUILD_INFO_PATH, GATES, ENABLED_FEATURES_GATE_MAP, findAllComponentsIn;
388
- var init_types_B_d4FeeE = __esm({
389
- "../cms-js-internal/dist/types-B-d4FeeE.js"() {
395
+ var init_types_Dvw_fW6p = __esm({
396
+ "../cms-js-internal/dist/types-Dvw_fW6p.js"() {
390
397
  COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
391
398
  ENTRY_POINTS_PATH = "components/partials/";
392
399
  MODULE_FOLDER_PATH = "components/modules/";
@@ -589,6 +596,7 @@ __export(dist_exports, {
589
596
  hasComponentExtension: () => hasComponentExtension,
590
597
  includesHublDataReference: () => includesHublDataReference,
591
598
  isFullHeightPreviewEnabled: () => isFullHeightPreviewEnabled,
599
+ isLocalUiDisabled: () => isLocalUiDisabled,
592
600
  isStorybookStory: () => isStorybookStory,
593
601
  isStylesheetAsset: () => isStylesheetAsset,
594
602
  isUngatedFor: () => isUngatedFor,
@@ -1176,8 +1184,8 @@ function GlobalPartialSlot(props) {
1176
1184
  var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, traverse, CMS_MODULE_COMPONENT_NAME, DND_AREA_COMPONENT_NAME, PLUGIN_NAME, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext;
1177
1185
  var init_dist = __esm({
1178
1186
  "../cms-js-internal/dist/index.js"() {
1179
- init_types_B_d4FeeE();
1180
- init_types_B_d4FeeE();
1187
+ init_types_Dvw_fW6p();
1188
+ init_types_Dvw_fW6p();
1181
1189
  ({ setProperty, getProperty, hasProperty } = dotProp);
1182
1190
  serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
1183
1191
  const islandsArrayToSerialize = tweakedIslandsArray.map(
@@ -7,7 +7,7 @@ import { createServer as createViteServer, normalizePath as normalizePath2 } fro
7
7
  import { createRequire } from "module";
8
8
  import { default as react } from "@vitejs/plugin-react";
9
9
 
10
- // ../cms-js-internal/dist/types-B-d4FeeE.js
10
+ // ../cms-js-internal/dist/types-Dvw_fW6p.js
11
11
  import path from "path";
12
12
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
13
13
  import { join } from "path/posix";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
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.2.77",
32
+ "@hubspot/cms-components": "^1.2.79",
33
33
  "@hubspot/local-dev-lib": "5.10.1",
34
34
  "@inquirer/select": "^2.0.0",
35
35
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -65,6 +65,7 @@
65
65
  "jsdom": "^25.0.1",
66
66
  "lucide-react": "^0.454.0",
67
67
  "node-fetch": "^3.3.0",
68
+ "parse5": "^7.1.2",
68
69
  "react": "18.3.1",
69
70
  "react-dom": "18.3.1",
70
71
  "storybook": "^8.6.15",
@@ -0,0 +1,8 @@
1
+ export declare function debugAuthContext(
2
+ authedPortalId: number,
3
+ cookieValue: string
4
+ ): Promise<void>;
5
+ export declare function compareUrls(
6
+ originalUrl: string,
7
+ signedUrl: string
8
+ ): void;
@@ -51,7 +51,7 @@ export interface AppLocals {
51
51
  sslEnabled: boolean;
52
52
  fieldBuilderEnabled: boolean;
53
53
  appWebRoot: string;
54
- appViteServer: ViteDevServer;
54
+ appViteServer: ViteDevServer | null;
55
55
  }
56
56
  export declare const templateTypeMap: Record<number, string>;
57
57
  export declare function normalizeHubLModules(modules: HubLModule[], projectName: string): ModuleData[];
@@ -0,0 +1,27 @@
1
+ declare type P5Node = {
2
+ nodeName: string;
3
+ tagName?: string;
4
+ value?: string;
5
+ attrs?: Array<{
6
+ name: string;
7
+ value: string;
8
+ }>;
9
+ childNodes?: P5Node[];
10
+ parentNode?: P5Node | null;
11
+ };
12
+ export declare type ParsedHtml = P5Node;
13
+ export declare function parseHtml(html: string): ParsedHtml;
14
+ /**
15
+ * Serialized outer HTML of the first `<div data-hs-cos-type="module">`.
16
+ * Mirrors the old `querySelector('div[data-hs-cos-type="module"]').outerHTML`.
17
+ */
18
+ export declare function extractModuleOuterHtml(root: ParsedHtml): string;
19
+ /**
20
+ * Concatenated text of `<style>` tags. With `headOnly`, only those under
21
+ * `<head>` (mirrors `querySelectorAll('head style')`); otherwise all of them
22
+ * (mirrors `querySelectorAll('style')`).
23
+ */
24
+ export declare function extractStyleText(root: ParsedHtml, opts?: {
25
+ headOnly?: boolean;
26
+ }): string;
27
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function getLocalComponentsPath(): string;
2
+ export declare function shouldUseLocalComponents(): boolean;
@@ -1,3 +1,3 @@
1
1
  export declare function checkFileExists(filePath: string): boolean;
2
2
  export declare function findHSProjectJson(startPath: any): string | null;
3
- export default function validateHSPlatform(projectConfigPath: string, portalId: number): Promise<Boolean>;
3
+ export default function validateHSPlatform(projectConfigPath: string, portalId: number, deferSelection?: (promptAndWrite: () => Promise<boolean>) => void): Promise<Boolean>;
@@ -0,0 +1,18 @@
1
+ import { ViteDevServer } from 'vite';
2
+ /**
3
+ * Processes HTML to find remote assets and replace with Vite-managed URLs
4
+ */
5
+ export declare function processRemoteAssets(
6
+ html: string,
7
+ viteServer: ViteDevServer
8
+ ): Promise<string>;
9
+ /**
10
+ * Vite plugin to handle remote assets
11
+ */
12
+ export declare function remoteAssetsPlugin(): {
13
+ name: string;
14
+ apply: 'serve';
15
+ configResolved(config: any): void;
16
+ resolveId(id: string): string;
17
+ load(id: string): Promise<string>;
18
+ };
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function hubspotStaticAssetsPlugin(): Plugin;
@@ -0,0 +1,10 @@
1
+ import { ViteDevServer, Plugin } from 'vite';
2
+ /**
3
+ * Create a self-contained plugin with proper caching
4
+ */
5
+ export declare function remoteAssetsPlugin(): Plugin & {
6
+ processRemoteAssets: (
7
+ html: string,
8
+ viteServer: ViteDevServer
9
+ ) => Promise<string>;
10
+ };
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Plugin that provides URL signing capabilities
4
+ * Uses internal signing mechanisms when available, with fallback for public environments
5
+ */
6
+ export default function requestSigningPlugin(): Plugin;
@@ -0,0 +1,13 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ export declare function handleGetModulePages(
3
+ req: Request,
4
+ res: Response,
5
+ next: NextFunction
6
+ ): Promise<Response<any, Record<string, any>>>;
7
+ export declare function handleOpenFile(
8
+ req: Request,
9
+ res: Response,
10
+ next: NextFunction
11
+ ): Response<any, Record<string, any>>;
12
+ export declare function createAppServerRoutes(): import('express-serve-static-core').Router;
13
+ export default createAppServerRoutes;
@@ -0,0 +1,7 @@
1
+ import { Request, Response } from 'express';
2
+ declare const homeRouteHandler: (
3
+ request: Request,
4
+ response: Response,
5
+ next: Function
6
+ ) => Promise<void>;
7
+ export default homeRouteHandler;
@@ -1 +1 @@
1
- export default function startShadowDevServer(devServerPort: number, shadowPort: number, themePath: string): Promise<void>;
1
+ export default function startShadowDevServer(devServerPort: number, shadowPort: number, themePath: string, host: string): Promise<void>;