@hubspot/cms-dev-server 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/index.js +41 -5
  2. package/dist/internalSsr.js +55 -3
  3. package/dist/run.js +155 -42
  4. package/package.json +3 -3
  5. package/types/createViteDevServer.d.ts +1 -1
  6. package/dist/components/ModulesList.js +0 -14
  7. package/dist/components/PartialsList.js +0 -13
  8. package/dist/createDevServer.js +0 -164
  9. package/dist/createDevServerConfiguration.js +0 -155
  10. package/dist/createViteDevServer.js +0 -52
  11. package/dist/lib/cli.js +0 -27
  12. package/dist/lib/debug.js +0 -2
  13. package/dist/lib/errors.js +0 -22
  14. package/dist/lib/fullOriginalUrlFromRequest.js +0 -3
  15. package/dist/lib/getDevServerConfiguration.js +0 -63
  16. package/dist/lib/httpsRedirectingServer.js +0 -48
  17. package/dist/lib/moduleGraph.js +0 -11
  18. package/dist/lib/proxyHelpers.js +0 -70
  19. package/dist/lib/proxyHelpers.test.js +0 -136
  20. package/dist/lib/renderComponentWithCSS.js +0 -26
  21. package/dist/lib/renderHelpers.js +0 -45
  22. package/dist/lib/renderModule.js +0 -56
  23. package/dist/lib/renderPartial.js +0 -15
  24. package/dist/lib/templates.js +0 -66
  25. package/dist/proxyPage/constants.js +0 -1
  26. package/dist/proxyPage/fetchContentMetadata.js +0 -59
  27. package/dist/proxyPage/fetchDomains.js +0 -29
  28. package/dist/proxyPage/fetchPreviewInfo.js +0 -37
  29. package/dist/proxyPage/proxyPage.js +0 -174
  30. package/dist/proxyPage/renderLocalError.js +0 -27
  31. package/dist/proxyPage/utils.js +0 -38
  32. package/dist/routes/createDevServerRoutes.js +0 -43
  33. package/dist/routes/homeRouteHandler.js +0 -12
  34. package/dist/routes/linksToAllModulesRouteHandler.js +0 -10
  35. package/dist/routes/linksToAllPartialsRouteHandler.js +0 -10
  36. package/dist/routes/module.js +0 -41
  37. package/dist/routes/partial.js +0 -30
  38. package/dist/routes/proxyPageResourceRedirect.js +0 -22
  39. package/dist/routes/proxyPageRouteHandler.js +0 -40
  40. package/dist/routes/proxyPathPageResourceRedirect.js +0 -36
  41. package/dist/routes/proxyPathPageRouteHandler.js +0 -43
  42. package/dist/shadowDevServer/createShadowDevServerRoutes.js +0 -63
  43. package/dist/shadowDevServer/startShadowDevServer.js +0 -31
  44. package/dist/storybook/getFieldsArgTypes.js +0 -54
  45. package/dist/storybook/getFieldsArgTypes.test.js +0 -91
  46. package/dist/storybook/getNestedFieldObjectForArgs.js +0 -22
  47. package/dist/storybook/getNestedFieldObjectForArgs.test.js +0 -40
  48. package/dist/storybook/main.js +0 -31
  49. package/dist/storybook/moduleStory.js +0 -61
  50. package/dist/storybook/preview.js +0 -9
  51. package/dist/storybook/types.js +0 -1
package/dist/run.js CHANGED
@@ -148,9 +148,13 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
148
148
  indent
149
149
  )}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
150
150
  };
151
+ function isUngatedFor(gates, gate) {
152
+ return gates.includes(gate);
153
+ }
151
154
  var viteRoot;
152
155
  var viteCommand;
153
- function resolveIslandPlugin() {
156
+ function resolveIslandPlugin(gates) {
157
+ const sharedDepsEnabled = isUngatedFor(gates, "CMS:JSRenderer:SharedDeps");
154
158
  return {
155
159
  enforce: "pre",
156
160
  name: "resolve-islands",
@@ -161,16 +165,21 @@ function resolveIslandPlugin() {
161
165
  load(id) {
162
166
  if (id.endsWith("?island") || id.endsWith("?client")) {
163
167
  const [idWithNoParam] = id.split("?");
168
+ const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
164
169
  const componentExtension = path.extname(idWithNoParam);
165
170
  const componentFilenameWithNoExtension = path.basename(
166
171
  idWithNoParam,
167
172
  componentExtension
168
173
  );
169
174
  const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
175
+ let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
176
+ if (sharedDepsEnabled) {
177
+ moduleId = moduleId.concat("?client-entry");
178
+ }
170
179
  return `
171
- const moduleId = '${viteCommand === "serve" ? idWithNoParam : modulePath}';
180
+ const moduleId = '${moduleId}';
172
181
 
173
- const lazyComponent = () => import('${idWithNoParam}');
182
+ const lazyComponent = () => import('${islandModuleImportPath}');
174
183
  lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
175
184
  lazyComponent.moduleId = moduleId;
176
185
 
@@ -181,6 +190,28 @@ function resolveIslandPlugin() {
181
190
  }
182
191
  };
183
192
  }
193
+ function clientIslandEntryPlugin() {
194
+ return {
195
+ enforce: "pre",
196
+ name: "client-island-entry-plugin",
197
+ load(id) {
198
+ if (id.endsWith("?client-entry")) {
199
+ const [idWithNoParam] = id.split("?");
200
+ return `
201
+ import { clientRenderIsland } from '@hubspot/cms-components';
202
+ import Component from '${idWithNoParam}';
203
+
204
+ export function render(island) {
205
+ return clientRenderIsland(island, Component)
206
+ }
207
+
208
+ export default Component;
209
+ `;
210
+ }
211
+ return null;
212
+ }
213
+ };
214
+ }
184
215
  var promiseForNewWritableStream = () => {
185
216
  const chunks = [];
186
217
  const writableStream = new stream.Writable();
@@ -483,10 +514,17 @@ var logPartialInfo = (partialPath, props) => {
483
514
  console.groupEnd();
484
515
  };
485
516
 
517
+ // src/lib/constants.ts
518
+ var Gates = {
519
+ GET_SERVER_SIDE_PROPS: "CMS:JSRenderer:GetServerSideProps"
520
+ };
521
+
486
522
  // src/lib/renderPartial.ts
487
523
  async function renderPartial(viteServer, partialPath, props, pageUrl, environmentConfig) {
488
524
  logPartialInfo(partialPath, props);
525
+ let serverSideProps;
489
526
  const componentModule = await viteServer.ssrLoadModule(partialPath);
527
+ const ungatedForServerSideProps = environmentConfig.getGates().includes(Gates.GET_SERVER_SIDE_PROPS);
490
528
  if (!componentModule) {
491
529
  throw new Error(`Couldn't find partial: ${partialPath}`);
492
530
  }
@@ -494,11 +532,22 @@ async function renderPartial(viteServer, partialPath, props, pageUrl, environmen
494
532
  if (!Component) {
495
533
  throw new Error(`Couldn't find default export on partial: ${partialPath}`);
496
534
  }
535
+ if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
536
+ try {
537
+ serverSideProps = await componentModule.getServerSidePropsUnstable(props);
538
+ if (serverSideProps.constructor !== Object.constructor) {
539
+ throw new Error("getServerSidePropsUnstable must return an object");
540
+ }
541
+ } catch (e) {
542
+ console.log("Error resolving server side props");
543
+ console.error(e);
544
+ }
545
+ }
497
546
  return renderComponentWithCSS_default(
498
547
  viteServer,
499
548
  partialPath,
500
549
  Component,
501
- props,
550
+ { ...props, ...serverSideProps },
502
551
  pageUrl,
503
552
  environmentConfig
504
553
  );
@@ -508,7 +557,18 @@ var renderPartial_default = renderPartial;
508
557
  // src/lib/templates.ts
509
558
  import { promises as fsPromises } from "fs";
510
559
  var { readFile } = fsPromises;
511
- var generateIslandSetupScriptBlock = () => {
560
+ var generateIslandSetupScriptBlock = (gates) => {
561
+ if (isUngatedFor(gates, "CMS:JSRenderer:SharedDeps")) {
562
+ return `<script type="module">
563
+ import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
564
+ initConfigSingletonFromJSON(window.__hsEnvConfig);
565
+ </script>
566
+ <script type="module">
567
+ import { setupIslandHydration } from '@hubspot/cms-components/island-runtime-shared';
568
+ setupIslandHydration();
569
+ </script>
570
+ `;
571
+ }
512
572
  return `<script type="module">
513
573
  import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
514
574
  initConfigSingletonFromJSON(window.__hsEnvConfig);
@@ -528,7 +588,7 @@ var createdPlainHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
528
588
  <!--bodyend-->`
529
589
  );
530
590
  };
531
- var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock) => {
591
+ var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock, gates) => {
532
592
  let htmlTemplate = await createdPlainHtmlTemplate(
533
593
  baseTemplatePath,
534
594
  title,
@@ -537,14 +597,14 @@ var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
537
597
  htmlTemplate = htmlTemplate.replace(
538
598
  "<!--bodyend-->",
539
599
  `
540
- ${generateIslandSetupScriptBlock()}
600
+ ${generateIslandSetupScriptBlock(gates)}
541
601
  <!-- ISLAND_RUNTIME_AND_SETUP_SCRIPT_BLOCK -->
542
602
  <!--islandsglobal-->
543
603
  `
544
604
  );
545
605
  return htmlTemplate;
546
606
  };
547
- var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, title, renderContext, viteServer) => {
607
+ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, title, renderContext, viteServer, jsRenderingGates) => {
548
608
  let htmlTemplate;
549
609
  if (renderContext.islands.length) {
550
610
  const globalScriptBlock = getServerGlobalsToInject(
@@ -554,7 +614,8 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
554
614
  htmlTemplate = await createIslandHtmlTemplate(
555
615
  baseTemplatePath,
556
616
  title,
557
- globalScriptBlock
617
+ globalScriptBlock,
618
+ jsRenderingGates
558
619
  );
559
620
  htmlTemplate = htmlTemplate.replace(
560
621
  "<!--islandsglobal-->",
@@ -580,12 +641,12 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
580
641
  }
581
642
  return viteServer.transformIndexHtml(url3, htmlTemplate);
582
643
  };
583
- var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerRequestData, viteServer) => {
644
+ var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerRequestData, viteServer, gates) => {
584
645
  const internalSsrPath = packagePath(import.meta.url, "internalSsr");
585
646
  const { createIslandsGlobalJsForClientInDev: createIslandsGlobalJsForClientInDev2 } = await viteServer.ssrLoadModule(internalSsrPath);
586
647
  const islandRuntimeScript = await viteServer.transformIndexHtml(
587
648
  "/",
588
- generateIslandSetupScriptBlock()
649
+ generateIslandSetupScriptBlock(gates)
589
650
  );
590
651
  return `${islandRuntimeScript}
591
652
  <script>${createIslandsGlobalJsForClientInDev2(
@@ -600,7 +661,14 @@ var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerReque
600
661
  // src/routes/partial.ts
601
662
  import { buildStaticEnvConfig } from "@hubspot/cms-components/config";
602
663
  var partialRouteHandler = async (request2, response) => {
603
- const { authedPortalId, authedEnv, authedHublet, webRoot: webRoot2, viteServer } = request2.app.locals;
664
+ const {
665
+ authedPortalId,
666
+ authedEnv,
667
+ authedHublet,
668
+ webRoot: webRoot2,
669
+ viteServer,
670
+ jsRenderingGates
671
+ } = request2.app.locals;
604
672
  const partialName = request2.params.partial;
605
673
  const baseTemplatePath = packagePath(
606
674
  import.meta.url,
@@ -613,7 +681,8 @@ var partialRouteHandler = async (request2, response) => {
613
681
  authedPortalId,
614
682
  authedHublet,
615
683
  authedEnv,
616
- false
684
+ false,
685
+ jsRenderingGates
617
686
  );
618
687
  try {
619
688
  const {
@@ -632,7 +701,8 @@ var partialRouteHandler = async (request2, response) => {
632
701
  request2.originalUrl,
633
702
  `Partial: ${partialPath}`,
634
703
  renderContext,
635
- viteServer
704
+ viteServer,
705
+ jsRenderingGates
636
706
  );
637
707
  const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
638
708
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
@@ -739,6 +809,8 @@ var lookForModuleInFolder = async (modulePath, viteServer) => {
739
809
  };
740
810
  async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}, pageUrl, environmentConfig) {
741
811
  console.log("Rendering module", requestedModulePath);
812
+ const ungatedForServerSideProps = environmentConfig.getGates().includes(Gates.GET_SERVER_SIDE_PROPS);
813
+ let serverSideProps;
742
814
  let componentModule;
743
815
  let foundPath;
744
816
  if (!hasComponentExtension(requestedModulePath)) {
@@ -768,11 +840,19 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
768
840
  }
769
841
  const fieldsJSON = renderFieldsToJson(fields);
770
842
  const props = getPropsForModule(fieldsJSON, fieldOverrides);
843
+ if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
844
+ try {
845
+ serverSideProps = await componentModule.getServerSidePropsUnstable(props);
846
+ } catch (e) {
847
+ console.log("Error resolving server side props");
848
+ console.error(e);
849
+ }
850
+ }
771
851
  return renderComponentWithCSS_default(
772
852
  viteServer,
773
853
  foundPath,
774
854
  Component,
775
- props,
855
+ { ...props, ...serverSideProps },
776
856
  pageUrl,
777
857
  environmentConfig
778
858
  );
@@ -788,7 +868,14 @@ var renderModule_default = renderModule;
788
868
 
789
869
  // src/routes/module.ts
790
870
  var moduleRouteHandler = async (request2, response) => {
791
- const { authedPortalId, authedEnv, authedHublet, webRoot: webRoot2, viteServer } = request2.app.locals;
871
+ const {
872
+ authedPortalId,
873
+ authedEnv,
874
+ authedHublet,
875
+ webRoot: webRoot2,
876
+ viteServer,
877
+ jsRenderingGates
878
+ } = request2.app.locals;
792
879
  const moduleName = request2.params.moduleName;
793
880
  const baseTemplatePath = packagePath(
794
881
  import.meta.url,
@@ -813,7 +900,8 @@ var moduleRouteHandler = async (request2, response) => {
813
900
  authedPortalId,
814
901
  authedHublet,
815
902
  authedEnv,
816
- false
903
+ false,
904
+ jsRenderingGates
817
905
  );
818
906
  try {
819
907
  const {
@@ -832,7 +920,8 @@ var moduleRouteHandler = async (request2, response) => {
832
920
  request2.originalUrl,
833
921
  `Module: ${modulePath}`,
834
922
  renderContext,
835
- viteServer
923
+ viteServer,
924
+ jsRenderingGates
836
925
  );
837
926
  const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
838
927
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
@@ -1125,7 +1214,7 @@ import {
1125
1214
  import {
1126
1215
  mergeServerRequestData_internal
1127
1216
  } from "@hubspot/cms-components";
1128
- var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId) => {
1217
+ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName) => {
1129
1218
  const url3 = new URL(urlToProxy);
1130
1219
  console.log(`Proxying request to ${url3.href}`, {
1131
1220
  previewKey,
@@ -1143,7 +1232,8 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId) =>
1143
1232
  proxiedQueryParams = {
1144
1233
  ...proxiedQueryParams,
1145
1234
  hs_preview: `${previewKey}-${contentId}`,
1146
- hsLocalProxy: true
1235
+ hsLocalProxy: true,
1236
+ hsLocalProxyProject: `@projects/${projectName}`
1147
1237
  };
1148
1238
  const result = hsGet2(accountId, {
1149
1239
  baseUrl: url3.origin,
@@ -1203,7 +1293,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
1203
1293
  throw new Error(`Unimplemented render of ${placeholderPath}.`);
1204
1294
  }
1205
1295
  };
1206
- async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2, viteServer, projectName, projectComponentPath, urlToProxy, fullOriginalUrl) {
1296
+ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2, viteServer, projectName, projectComponentPath, jsRenderingGates, urlToProxy, fullOriginalUrl) {
1207
1297
  let accountId;
1208
1298
  let proxyEnv;
1209
1299
  try {
@@ -1231,13 +1321,15 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1231
1321
  accountId,
1232
1322
  urlToProxy,
1233
1323
  previewKey,
1234
- contentId
1324
+ contentId,
1325
+ projectName
1235
1326
  );
1236
1327
  const environmentConfig = buildStaticEnvConfig3(
1237
1328
  portalId,
1238
1329
  hublet,
1239
1330
  proxyEnv,
1240
- false
1331
+ false,
1332
+ jsRenderingGates
1241
1333
  );
1242
1334
  const { sortIslandRootsByPriority } = await viteServer.ssrLoadModule(
1243
1335
  "@hubspot/cms-components"
@@ -1315,7 +1407,8 @@ ${html}`;
1315
1407
  const islandRuntimeAndGlobalScriptHtml = await getIslandRuntimeAndGlobalToInject(
1316
1408
  sortedIslandRoots,
1317
1409
  mergedPerRequestState,
1318
- viteServer
1410
+ viteServer,
1411
+ jsRenderingGates
1319
1412
  );
1320
1413
  response.write(islandRuntimeAndGlobalScriptHtml);
1321
1414
  }
@@ -1338,7 +1431,13 @@ ${error.stack}`
1338
1431
 
1339
1432
  // src/routes/proxyPageRouteHandler.ts
1340
1433
  async function proxyPageRouteHandler(request2, response, next) {
1341
- const { viteServer, webRoot: webRoot2, projectName, projectComponentPath } = request2.app.locals;
1434
+ const {
1435
+ viteServer,
1436
+ webRoot: webRoot2,
1437
+ projectName,
1438
+ projectComponentPath,
1439
+ jsRenderingGates
1440
+ } = request2.app.locals;
1342
1441
  if (!request2.accepts().includes("text/html")) {
1343
1442
  return response.sendStatus(404);
1344
1443
  }
@@ -1374,6 +1473,7 @@ async function proxyPageRouteHandler(request2, response, next) {
1374
1473
  viteServer,
1375
1474
  projectName,
1376
1475
  projectComponentPath,
1476
+ jsRenderingGates,
1377
1477
  urlToProxy,
1378
1478
  fullOriginalUrl
1379
1479
  );
@@ -1431,10 +1531,9 @@ async function proxyPathPageRouteHandler(request2, response, next) {
1431
1531
  const {
1432
1532
  viteServer,
1433
1533
  webRoot: webRoot2,
1434
- devServerHost,
1435
- devServerPort,
1436
1534
  projectName,
1437
- projectComponentPath
1535
+ projectComponentPath,
1536
+ jsRenderingGates
1438
1537
  } = request2.app.locals;
1439
1538
  if (!request2.accepts().includes("text/html")) {
1440
1539
  return response.sendStatus(404);
@@ -1490,6 +1589,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
1490
1589
  viteServer,
1491
1590
  projectName,
1492
1591
  projectComponentPath,
1592
+ jsRenderingGates,
1493
1593
  proxyPageUrl.href,
1494
1594
  proxyPageUrl.href
1495
1595
  );
@@ -1576,7 +1676,7 @@ import express from "express";
1576
1676
  import { Router as Router2 } from "express";
1577
1677
  import { getAccountId as getAccountId2 } from "@hubspot/cli-lib/lib/config.js";
1578
1678
  import cors from "cors";
1579
- function getShadowDevServerCheckHandler(devServerPort) {
1679
+ function getShadowDevServerCheckHandler(devServerPort, projectName) {
1580
1680
  return async function shadowDevServerCheckHandler(request2, response) {
1581
1681
  const { query } = request2;
1582
1682
  if (query) {
@@ -1614,7 +1714,8 @@ function getShadowDevServerCheckHandler(devServerPort) {
1614
1714
  accountId,
1615
1715
  pageUrl,
1616
1716
  previewKey,
1617
- contentId
1717
+ contentId,
1718
+ projectName
1618
1719
  );
1619
1720
  const localRenderPlaceholders = findLocalRenderPlaceholders(pageHtml);
1620
1721
  if (localRenderPlaceholders.length) {
@@ -1637,19 +1738,19 @@ ${error.stack}`
1637
1738
  }
1638
1739
  };
1639
1740
  }
1640
- async function createShadowDevServerRoutes(devServerPort) {
1741
+ async function createShadowDevServerRoutes(devServerPort, projectName) {
1641
1742
  const shadowDevServerRoutes = Router2();
1642
1743
  shadowDevServerRoutes.get(
1643
1744
  "/check-if-local-dev-server",
1644
1745
  cors(),
1645
- getShadowDevServerCheckHandler(devServerPort)
1746
+ getShadowDevServerCheckHandler(devServerPort, projectName)
1646
1747
  );
1647
1748
  return shadowDevServerRoutes;
1648
1749
  }
1649
1750
 
1650
1751
  // src/shadowDevServer/startShadowDevServer.ts
1651
1752
  var testNetServer = net.createServer();
1652
- async function startShadowDevServer(devServerPort, shadowPort) {
1753
+ async function startShadowDevServer(devServerPort, shadowPort, projectName) {
1653
1754
  const portIsTaken = await new Promise((res, rej) => {
1654
1755
  console.log(`Starting proxy link server on port ${shadowPort}`);
1655
1756
  testNetServer.once("error", (err) => {
@@ -1675,14 +1776,21 @@ async function startShadowDevServer(devServerPort, shadowPort) {
1675
1776
  }
1676
1777
  const shadowDevServer = express();
1677
1778
  shadowDevServer.listen(shadowPort);
1678
- shadowDevServer.use("/", await createShadowDevServerRoutes(devServerPort));
1779
+ shadowDevServer.use(
1780
+ "/",
1781
+ await createShadowDevServerRoutes(devServerPort, projectName)
1782
+ );
1679
1783
  }
1680
1784
 
1681
1785
  // src/createViteDevServer.ts
1682
1786
  import { createServer as createViteServer } from "vite";
1683
1787
  import { default as react } from "@vitejs/plugin-react";
1684
1788
  import mkcert from "vite-plugin-mkcert";
1685
- async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = []) {
1789
+ async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [], jsRenderingGates) {
1790
+ const sharedDepsEnabled = isUngatedFor(
1791
+ jsRenderingGates,
1792
+ "CMS:JSRenderer:SharedDeps"
1793
+ );
1686
1794
  const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
1687
1795
  `${proxyDomain}.localhost`,
1688
1796
  `${proxyDomain}.hslocal.net`
@@ -1714,7 +1822,8 @@ async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy =
1714
1822
  plugins: [
1715
1823
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
1716
1824
  react(),
1717
- resolveIslandPlugin()
1825
+ sharedDepsEnabled && clientIslandEntryPlugin(),
1826
+ resolveIslandPlugin(jsRenderingGates)
1718
1827
  ],
1719
1828
  css: {
1720
1829
  postcss: webRoot2
@@ -1864,6 +1973,7 @@ If needed you can refer to another config file with --config.
1864
1973
  Local proxy functionality will not work without setting up authentication.`
1865
1974
  );
1866
1975
  }
1976
+ const jsRenderingGates = process.env.GATES ? process.env.GATES.split(",") : [];
1867
1977
  let domainsToProxy = [];
1868
1978
  if (sslEnabledOption2 && authedPortalId) {
1869
1979
  try {
@@ -1887,11 +1997,15 @@ Local proxy functionality will not work without setting up authentication.`
1887
1997
  absoluteWebRoot,
1888
1998
  PORT,
1889
1999
  sslEnabledOption2,
1890
- domainsToProxy
2000
+ domainsToProxy,
2001
+ jsRenderingGates
1891
2002
  );
1892
2003
  const viteHTTPSConfig = viteServer.config.server.https;
1893
2004
  const httpsKey = viteHTTPSConfig ? viteHTTPSConfig.key : null;
1894
2005
  const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
2006
+ const projectName = getProjectNameFromHSConfig(
2007
+ path7.join(webRoot2, "../hsproject.json")
2008
+ );
1895
2009
  const httpServers = [];
1896
2010
  const expressServer = express2();
1897
2011
  expressServer.locals.devServerHost = "hslocal.net";
@@ -1903,10 +2017,9 @@ Local proxy functionality will not work without setting up authentication.`
1903
2017
  expressServer.locals.authedHublet = authedHublet;
1904
2018
  expressServer.locals.storybookEnabled = storybook2;
1905
2019
  expressServer.locals.storybookPort = STORYBOOK_PORT;
1906
- expressServer.locals.projectName = getProjectNameFromHSConfig(
1907
- path7.join(webRoot2, "../hsproject.json")
1908
- );
2020
+ expressServer.locals.projectName = projectName;
1909
2021
  expressServer.locals.projectComponentPath = webRootProjectComponentFolder;
2022
+ expressServer.locals.jsRenderingGates = jsRenderingGates;
1910
2023
  expressServer.use(bodyParser.json());
1911
2024
  expressServer.use(
1912
2025
  BASE_PATH,
@@ -1931,7 +2044,7 @@ Local proxy functionality will not work without setting up authentication.`
1931
2044
  httpServer.listen(PORT);
1932
2045
  httpServers.push(httpServer);
1933
2046
  }
1934
- startShadowDevServer(PORT, SHADOW_PORT);
2047
+ startShadowDevServer(PORT, SHADOW_PORT, projectName);
1935
2048
  let extraServerInfo = "";
1936
2049
  const protocol = sslEnabledOption2 ? "https" : "http";
1937
2050
  if (authedPortalId) {
@@ -1942,7 +2055,7 @@ Local proxy functionality will not work without setting up authentication.`
1942
2055
  }
1943
2056
  console.log(
1944
2057
  `
1945
- HubSpot CMS dev server hosting: ${expressServer.locals.projectName}/${expressServer.locals.projectComponentPath} (at ${protocol}://hslocal.net:${PORT}${extraServerInfo})
2058
+ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectComponentPath} (at ${protocol}://hslocal.net:${PORT}${extraServerInfo})
1946
2059
  `
1947
2060
  );
1948
2061
  if (storybook2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@hubspot/cli-lib": "^3.0.12",
27
- "@hubspot/cms-components": "^0.4.3",
27
+ "@hubspot/cms-components": "^0.4.5",
28
28
  "@storybook/addon-actions": "^7.0.0-beta.19",
29
29
  "@storybook/addon-essentials": "^7.0.0-beta.19",
30
30
  "@storybook/addon-interactions": "^7.0.0-beta.19",
@@ -95,5 +95,5 @@
95
95
  "publishConfig": {
96
96
  "access": "public"
97
97
  },
98
- "gitHead": "7d2696951f3aeeae3085382ebe1a66ba94ecc748"
98
+ "gitHead": "9848f59886135ea97fc01ada9b04b204fdcad8ca"
99
99
  }
@@ -1,2 +1,2 @@
1
- declare function createViteDevServer(webRoot: string, port: any, sslEnabled: boolean, domainsToProxy?: any[]): Promise<import("vite").ViteDevServer>;
1
+ declare function createViteDevServer(webRoot: string, port: any, sslEnabled: boolean, domainsToProxy: any[], jsRenderingGates: string[]): Promise<import("vite").ViteDevServer>;
2
2
  export default createViteDevServer;
@@ -1,14 +0,0 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- function EmptyModulesList({ webRoot }) {
3
- return (_jsxs("p", { children: ["No modules in ", _jsxs("code", { children: [webRoot, "components/modules"] })] }));
4
- }
5
- function ModuleLinkInLI({ moduleName }) {
6
- return (_jsx("li", { children: _jsx("a", { href: `/module/${moduleName}`, children: moduleName }) }));
7
- }
8
- function ModulesList({ webRoot, moduleNames }) {
9
- if (moduleNames.length === 0) {
10
- return _jsx(EmptyModulesList, { webRoot: webRoot });
11
- }
12
- return (_jsx("ul", { children: moduleNames.map(moduleName => (_jsx(ModuleLinkInLI, { moduleName: moduleName }, moduleName))) }));
13
- }
14
- export default ModulesList;
@@ -1,13 +0,0 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- function EmptyPartialsList({ webRoot }) {
3
- return (_jsxs("p", { children: ["No partials in ", _jsxs("code", { children: [webRoot, "components/partials"] })] }));
4
- }
5
- function PartialLinkInLI({ partialName }) {
6
- return (_jsx("li", { children: _jsx("a", { href: `/partial/${partialName}`, children: partialName }) }));
7
- }
8
- export default function PartialsList({ webRoot, partialNames }) {
9
- if (partialNames.length === 0) {
10
- return _jsx(EmptyPartialsList, { webRoot: webRoot });
11
- }
12
- return (_jsx("ul", { children: partialNames.map(partialName => (_jsx(PartialLinkInLI, { partialName: partialName }, partialName))) }));
13
- }