@hubspot/cms-dev-server 0.4.2 → 0.4.4

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 +36 -6
  2. package/dist/internalSsr.js +87 -12
  3. package/dist/run.js +174 -45
  4. package/package.json +4 -4
  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
@@ -69,9 +69,9 @@ import { join as joinPosix } from "path/posix";
69
69
  import { basename } from "path";
70
70
  import { cloneElement } from "react";
71
71
  import { renderToStaticMarkup } from "react-dom/server";
72
- var writeIslandDataToJsGlobal = (tweakedIslandsArray, indent = 0) => {
72
+ var serializeIslandDataToJSON = (tweakedIslandsArray, indent = 0) => {
73
73
  const indentString = new Array(indent).fill(" ").join("");
74
- return `window.__islands = ${JSON.stringify(
74
+ return `${JSON.stringify(
75
75
  tweakedIslandsArray.map(
76
76
  ({
77
77
  id,
@@ -81,24 +81,50 @@ var writeIslandDataToJsGlobal = (tweakedIslandsArray, indent = 0) => {
81
81
  hydrateOn,
82
82
  clientOnly,
83
83
  priority,
84
- url: url3
84
+ url: url3,
85
+ sharedStateID
85
86
  }) => {
86
- return {
87
+ const output = {
87
88
  id,
88
89
  moduleName,
89
90
  moduleId,
90
- props,
91
91
  hydrateOn,
92
92
  clientOnly,
93
93
  priority,
94
+ props,
94
95
  url: url3
95
96
  };
97
+ if (sharedStateID) {
98
+ output.sharedStateID = sharedStateID;
99
+ }
100
+ return output;
96
101
  }
97
102
  ),
98
103
  null,
99
104
  2
100
105
  ).replace(/\n/gm, `
101
- ${indentString}`)};`;
106
+ ${indentString}`)}`;
107
+ };
108
+ var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0) => {
109
+ const indentString = new Array(indent).fill(" ").join("");
110
+ const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
111
+ if (sharedStateIDs.length > 0) {
112
+ const stateByID = {};
113
+ sharedStateIDs.forEach(
114
+ (id) => stateByID[id] = perServerRequestData.get(id)
115
+ );
116
+ const stringifiedState = JSON.stringify(stateByID, null, 2);
117
+ return `
118
+
119
+ var newState = ${stringifiedState};
120
+ if(window.__hsSSInit) {
121
+ window.__hsSSInit = Object.assign(window.__hsSSInit, newState);
122
+ } else {
123
+ window.__hsSSInit = newState;
124
+ }`.replace(/\n/gm, `
125
+ ${indentString}`);
126
+ }
127
+ return "";
102
128
  };
103
129
  function getIslandUrls(roots, viteDevServer) {
104
130
  return roots.map((island) => {
@@ -115,12 +141,18 @@ function getIslandUrls(roots, viteDevServer) {
115
141
  return tweakedIsland;
116
142
  });
117
143
  }
118
- var createIslandsGlobalJsForClientInDev = (roots, viteDevServer, indent) => {
119
- return writeIslandDataToJsGlobal(getIslandUrls(roots, viteDevServer), indent);
144
+ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent) => {
145
+ const islands = getIslandUrls(roots, viteDevServer);
146
+ return `window.__islands = ${serializeIslandDataToJSON(
147
+ islands,
148
+ indent
149
+ )}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
120
150
  };
121
151
  var viteRoot;
122
152
  var viteCommand;
123
- function resolveIslandPlugin() {
153
+ function resolveIslandPlugin({
154
+ sharedDepsEnabled
155
+ }) {
124
156
  return {
125
157
  enforce: "pre",
126
158
  name: "resolve-islands",
@@ -129,18 +161,23 @@ function resolveIslandPlugin() {
129
161
  viteCommand = config.command;
130
162
  },
131
163
  load(id) {
132
- if (id.endsWith("?island")) {
164
+ if (id.endsWith("?island") || id.endsWith("?client")) {
133
165
  const [idWithNoParam] = id.split("?");
166
+ const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
134
167
  const componentExtension = path.extname(idWithNoParam);
135
168
  const componentFilenameWithNoExtension = path.basename(
136
169
  idWithNoParam,
137
170
  componentExtension
138
171
  );
139
172
  const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
173
+ let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
174
+ if (sharedDepsEnabled) {
175
+ moduleId = moduleId.concat("?client-entry");
176
+ }
140
177
  return `
141
- const moduleId = '${viteCommand === "serve" ? idWithNoParam : modulePath}';
178
+ const moduleId = '${moduleId}';
142
179
 
143
- const lazyComponent = () => import('${idWithNoParam}');
180
+ const lazyComponent = () => import('${islandModuleImportPath}');
144
181
  lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
145
182
  lazyComponent.moduleId = moduleId;
146
183
 
@@ -151,6 +188,28 @@ function resolveIslandPlugin() {
151
188
  }
152
189
  };
153
190
  }
191
+ function clientIslandEntryPlugin() {
192
+ return {
193
+ enforce: "pre",
194
+ name: "client-island-entry-plugin",
195
+ load(id) {
196
+ if (id.endsWith("?client-entry")) {
197
+ const [idWithNoParam] = id.split("?");
198
+ return `
199
+ import { clientRenderIsland } from '@hubspot/cms-components';
200
+ import Component from '${idWithNoParam}';
201
+
202
+ export function render(island) {
203
+ return clientRenderIsland(island, Component)
204
+ }
205
+
206
+ export default Component;
207
+ `;
208
+ }
209
+ return null;
210
+ }
211
+ };
212
+ }
154
213
  var promiseForNewWritableStream = () => {
155
214
  const chunks = [];
156
215
  const writableStream = new stream.Writable();
@@ -478,7 +537,18 @@ var renderPartial_default = renderPartial;
478
537
  // src/lib/templates.ts
479
538
  import { promises as fsPromises } from "fs";
480
539
  var { readFile } = fsPromises;
481
- var generateIslandSetupScriptBlock = () => {
540
+ var generateIslandSetupScriptBlock = (sharedDepsEnabled) => {
541
+ if (sharedDepsEnabled) {
542
+ return `<script type="module">
543
+ import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
544
+ initConfigSingletonFromJSON(window.__hsEnvConfig);
545
+ </script>
546
+ <script type="module">
547
+ import { setupIslandHydration } from '@hubspot/cms-components/island-runtime-shared';
548
+ setupIslandHydration();
549
+ </script>
550
+ `;
551
+ }
482
552
  return `<script type="module">
483
553
  import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
484
554
  initConfigSingletonFromJSON(window.__hsEnvConfig);
@@ -498,7 +568,7 @@ var createdPlainHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
498
568
  <!--bodyend-->`
499
569
  );
500
570
  };
501
- var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock) => {
571
+ var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock, sharedDepsEnabled) => {
502
572
  let htmlTemplate = await createdPlainHtmlTemplate(
503
573
  baseTemplatePath,
504
574
  title,
@@ -507,14 +577,14 @@ var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
507
577
  htmlTemplate = htmlTemplate.replace(
508
578
  "<!--bodyend-->",
509
579
  `
510
- ${generateIslandSetupScriptBlock()}
580
+ ${generateIslandSetupScriptBlock(sharedDepsEnabled)}
511
581
  <!-- ISLAND_RUNTIME_AND_SETUP_SCRIPT_BLOCK -->
512
582
  <!--islandsglobal-->
513
583
  `
514
584
  );
515
585
  return htmlTemplate;
516
586
  };
517
- var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, title, renderContext, viteServer) => {
587
+ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, title, renderContext, viteServer, sharedDepsEnabled) => {
518
588
  let htmlTemplate;
519
589
  if (renderContext.islands.length) {
520
590
  const globalScriptBlock = getServerGlobalsToInject(
@@ -524,12 +594,18 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
524
594
  htmlTemplate = await createIslandHtmlTemplate(
525
595
  baseTemplatePath,
526
596
  title,
527
- globalScriptBlock
597
+ globalScriptBlock,
598
+ sharedDepsEnabled
528
599
  );
529
600
  htmlTemplate = htmlTemplate.replace(
530
601
  "<!--islandsglobal-->",
531
602
  `<script>
532
- ${createIslandsGlobalJsForClientInDev(renderContext.islands, viteServer, 4)}
603
+ ${createIslandsGlobalJsForClientInDev(
604
+ renderContext.islands,
605
+ renderContext.perServerRequestData,
606
+ viteServer,
607
+ 4
608
+ )}
533
609
  </script>
534
610
  `
535
611
  );
@@ -545,16 +621,17 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
545
621
  }
546
622
  return viteServer.transformIndexHtml(url3, htmlTemplate);
547
623
  };
548
- var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, viteServer) => {
624
+ var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerRequestData, viteServer, sharedDepsEnabled) => {
549
625
  const internalSsrPath = packagePath(import.meta.url, "internalSsr");
550
626
  const { createIslandsGlobalJsForClientInDev: createIslandsGlobalJsForClientInDev2 } = await viteServer.ssrLoadModule(internalSsrPath);
551
627
  const islandRuntimeScript = await viteServer.transformIndexHtml(
552
628
  "/",
553
- generateIslandSetupScriptBlock()
629
+ generateIslandSetupScriptBlock(sharedDepsEnabled)
554
630
  );
555
631
  return `${islandRuntimeScript}
556
632
  <script>${createIslandsGlobalJsForClientInDev2(
557
633
  sortedIslandRoots,
634
+ perServerRequestData,
558
635
  viteServer,
559
636
  4
560
637
  )}</script>
@@ -564,7 +641,14 @@ var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, viteServer) =>
564
641
  // src/routes/partial.ts
565
642
  import { buildStaticEnvConfig } from "@hubspot/cms-components/config";
566
643
  var partialRouteHandler = async (request2, response) => {
567
- const { authedPortalId, authedEnv, authedHublet, webRoot: webRoot2, viteServer } = request2.app.locals;
644
+ const {
645
+ authedPortalId,
646
+ authedEnv,
647
+ authedHublet,
648
+ webRoot: webRoot2,
649
+ viteServer,
650
+ sharedDepsEnabled
651
+ } = request2.app.locals;
568
652
  const partialName = request2.params.partial;
569
653
  const baseTemplatePath = packagePath(
570
654
  import.meta.url,
@@ -596,7 +680,8 @@ var partialRouteHandler = async (request2, response) => {
596
680
  request2.originalUrl,
597
681
  `Partial: ${partialPath}`,
598
682
  renderContext,
599
- viteServer
683
+ viteServer,
684
+ sharedDepsEnabled
600
685
  );
601
686
  const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
602
687
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
@@ -752,7 +837,14 @@ var renderModule_default = renderModule;
752
837
 
753
838
  // src/routes/module.ts
754
839
  var moduleRouteHandler = async (request2, response) => {
755
- const { authedPortalId, authedEnv, authedHublet, webRoot: webRoot2, viteServer } = request2.app.locals;
840
+ const {
841
+ authedPortalId,
842
+ authedEnv,
843
+ authedHublet,
844
+ webRoot: webRoot2,
845
+ viteServer,
846
+ sharedDepsEnabled
847
+ } = request2.app.locals;
756
848
  const moduleName = request2.params.moduleName;
757
849
  const baseTemplatePath = packagePath(
758
850
  import.meta.url,
@@ -796,7 +888,8 @@ var moduleRouteHandler = async (request2, response) => {
796
888
  request2.originalUrl,
797
889
  `Module: ${modulePath}`,
798
890
  renderContext,
799
- viteServer
891
+ viteServer,
892
+ sharedDepsEnabled
800
893
  );
801
894
  const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
802
895
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
@@ -1086,7 +1179,10 @@ ${error.error.message}`);
1086
1179
  import {
1087
1180
  buildStaticEnvConfig as buildStaticEnvConfig3
1088
1181
  } from "@hubspot/cms-components/config";
1089
- var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId) => {
1182
+ import {
1183
+ mergeServerRequestData_internal
1184
+ } from "@hubspot/cms-components";
1185
+ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName) => {
1090
1186
  const url3 = new URL(urlToProxy);
1091
1187
  console.log(`Proxying request to ${url3.href}`, {
1092
1188
  previewKey,
@@ -1104,7 +1200,8 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId) =>
1104
1200
  proxiedQueryParams = {
1105
1201
  ...proxiedQueryParams,
1106
1202
  hs_preview: `${previewKey}-${contentId}`,
1107
- hsLocalProxy: true
1203
+ hsLocalProxy: true,
1204
+ hsLocalProxyProject: `@projects/${projectName}`
1108
1205
  };
1109
1206
  const result = hsGet2(accountId, {
1110
1207
  baseUrl: url3.origin,
@@ -1164,7 +1261,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
1164
1261
  throw new Error(`Unimplemented render of ${placeholderPath}.`);
1165
1262
  }
1166
1263
  };
1167
- async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2, viteServer, projectName, projectComponentPath, urlToProxy, fullOriginalUrl) {
1264
+ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2, viteServer, projectName, projectComponentPath, sharedDepsEnabled, urlToProxy, fullOriginalUrl) {
1168
1265
  let accountId;
1169
1266
  let proxyEnv;
1170
1267
  try {
@@ -1192,7 +1289,8 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1192
1289
  accountId,
1193
1290
  urlToProxy,
1194
1291
  previewKey,
1195
- contentId
1292
+ contentId,
1293
+ projectName
1196
1294
  );
1197
1295
  const environmentConfig = buildStaticEnvConfig3(
1198
1296
  portalId,
@@ -1207,6 +1305,7 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1207
1305
  const numPlaceholders = localRenderPlaceholders.length;
1208
1306
  let numJsRenderFailures = 0;
1209
1307
  let islands = [];
1308
+ let mergedPerRequestState = /* @__PURE__ */ new Map();
1210
1309
  const renderPromisesByChunkIndex = new Array(
1211
1310
  numPlaceholders
1212
1311
  );
@@ -1237,6 +1336,10 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1237
1336
  if (renderContext.islands.length > 0) {
1238
1337
  islands = islands.concat(renderContext.islands);
1239
1338
  }
1339
+ mergedPerRequestState = mergeServerRequestData_internal(
1340
+ mergedPerRequestState,
1341
+ renderContext.perServerRequestData
1342
+ );
1240
1343
  if (cssNeeded) {
1241
1344
  return `${cssNeeded}
1242
1345
  ${html}`;
@@ -1244,6 +1347,12 @@ ${html}`;
1244
1347
  return html;
1245
1348
  }).catch((e) => {
1246
1349
  numJsRenderFailures += 1;
1350
+ console.log(
1351
+ "Attempted to render",
1352
+ localRenderPlaceholder.path,
1353
+ "with props",
1354
+ localRenderPlaceholder.json
1355
+ );
1247
1356
  console.error(e);
1248
1357
  return renderLocalError_default(localRenderPlaceholder.path, e);
1249
1358
  });
@@ -1264,7 +1373,9 @@ ${html}`;
1264
1373
  const sortedIslandRoots = sortIslandRootsByPriority(islands);
1265
1374
  const islandRuntimeAndGlobalScriptHtml = await getIslandRuntimeAndGlobalToInject(
1266
1375
  sortedIslandRoots,
1267
- viteServer
1376
+ mergedPerRequestState,
1377
+ viteServer,
1378
+ sharedDepsEnabled
1268
1379
  );
1269
1380
  response.write(islandRuntimeAndGlobalScriptHtml);
1270
1381
  }
@@ -1287,7 +1398,13 @@ ${error.stack}`
1287
1398
 
1288
1399
  // src/routes/proxyPageRouteHandler.ts
1289
1400
  async function proxyPageRouteHandler(request2, response, next) {
1290
- const { viteServer, webRoot: webRoot2, projectName, projectComponentPath } = request2.app.locals;
1401
+ const {
1402
+ viteServer,
1403
+ webRoot: webRoot2,
1404
+ projectName,
1405
+ projectComponentPath,
1406
+ sharedDepsEnabled
1407
+ } = request2.app.locals;
1291
1408
  if (!request2.accepts().includes("text/html")) {
1292
1409
  return response.sendStatus(404);
1293
1410
  }
@@ -1323,6 +1440,7 @@ async function proxyPageRouteHandler(request2, response, next) {
1323
1440
  viteServer,
1324
1441
  projectName,
1325
1442
  projectComponentPath,
1443
+ sharedDepsEnabled,
1326
1444
  urlToProxy,
1327
1445
  fullOriginalUrl
1328
1446
  );
@@ -1383,7 +1501,8 @@ async function proxyPathPageRouteHandler(request2, response, next) {
1383
1501
  devServerHost,
1384
1502
  devServerPort,
1385
1503
  projectName,
1386
- projectComponentPath
1504
+ projectComponentPath,
1505
+ sharedDepsEnabled
1387
1506
  } = request2.app.locals;
1388
1507
  if (!request2.accepts().includes("text/html")) {
1389
1508
  return response.sendStatus(404);
@@ -1439,6 +1558,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
1439
1558
  viteServer,
1440
1559
  projectName,
1441
1560
  projectComponentPath,
1561
+ sharedDepsEnabled,
1442
1562
  proxyPageUrl.href,
1443
1563
  proxyPageUrl.href
1444
1564
  );
@@ -1525,7 +1645,7 @@ import express from "express";
1525
1645
  import { Router as Router2 } from "express";
1526
1646
  import { getAccountId as getAccountId2 } from "@hubspot/cli-lib/lib/config.js";
1527
1647
  import cors from "cors";
1528
- function getShadowDevServerCheckHandler(devServerPort) {
1648
+ function getShadowDevServerCheckHandler(devServerPort, projectName) {
1529
1649
  return async function shadowDevServerCheckHandler(request2, response) {
1530
1650
  const { query } = request2;
1531
1651
  if (query) {
@@ -1563,7 +1683,8 @@ function getShadowDevServerCheckHandler(devServerPort) {
1563
1683
  accountId,
1564
1684
  pageUrl,
1565
1685
  previewKey,
1566
- contentId
1686
+ contentId,
1687
+ projectName
1567
1688
  );
1568
1689
  const localRenderPlaceholders = findLocalRenderPlaceholders(pageHtml);
1569
1690
  if (localRenderPlaceholders.length) {
@@ -1586,19 +1707,19 @@ ${error.stack}`
1586
1707
  }
1587
1708
  };
1588
1709
  }
1589
- async function createShadowDevServerRoutes(devServerPort) {
1710
+ async function createShadowDevServerRoutes(devServerPort, projectName) {
1590
1711
  const shadowDevServerRoutes = Router2();
1591
1712
  shadowDevServerRoutes.get(
1592
1713
  "/check-if-local-dev-server",
1593
1714
  cors(),
1594
- getShadowDevServerCheckHandler(devServerPort)
1715
+ getShadowDevServerCheckHandler(devServerPort, projectName)
1595
1716
  );
1596
1717
  return shadowDevServerRoutes;
1597
1718
  }
1598
1719
 
1599
1720
  // src/shadowDevServer/startShadowDevServer.ts
1600
1721
  var testNetServer = net.createServer();
1601
- async function startShadowDevServer(devServerPort, shadowPort) {
1722
+ async function startShadowDevServer(devServerPort, shadowPort, projectName) {
1602
1723
  const portIsTaken = await new Promise((res, rej) => {
1603
1724
  console.log(`Starting proxy link server on port ${shadowPort}`);
1604
1725
  testNetServer.once("error", (err) => {
@@ -1624,14 +1745,17 @@ async function startShadowDevServer(devServerPort, shadowPort) {
1624
1745
  }
1625
1746
  const shadowDevServer = express();
1626
1747
  shadowDevServer.listen(shadowPort);
1627
- shadowDevServer.use("/", await createShadowDevServerRoutes(devServerPort));
1748
+ shadowDevServer.use(
1749
+ "/",
1750
+ await createShadowDevServerRoutes(devServerPort, projectName)
1751
+ );
1628
1752
  }
1629
1753
 
1630
1754
  // src/createViteDevServer.ts
1631
1755
  import { createServer as createViteServer } from "vite";
1632
1756
  import { default as react } from "@vitejs/plugin-react";
1633
1757
  import mkcert from "vite-plugin-mkcert";
1634
- async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = []) {
1758
+ async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [], sharedDepsEnabled) {
1635
1759
  const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
1636
1760
  `${proxyDomain}.localhost`,
1637
1761
  `${proxyDomain}.hslocal.net`
@@ -1663,7 +1787,8 @@ async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy =
1663
1787
  plugins: [
1664
1788
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
1665
1789
  react(),
1666
- resolveIslandPlugin()
1790
+ sharedDepsEnabled && clientIslandEntryPlugin(),
1791
+ resolveIslandPlugin({ sharedDepsEnabled })
1667
1792
  ],
1668
1793
  css: {
1669
1794
  postcss: webRoot2
@@ -1776,6 +1901,7 @@ var BASE_PATH = "/";
1776
1901
  var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
1777
1902
  var SHADOW_PORT = 1442;
1778
1903
  var STORYBOOK_PORT = process.env.STORYBOOK_PORT ? parseInt(process.env.STORYBOOK_PORT, 10) : 3123;
1904
+ var SHARED_DEPS_ENABLED = Boolean(process.env.SHARED_DEPS_ENABLED);
1779
1905
  async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2, hubspotCliAccountNameOption2, sslEnabledOption2) {
1780
1906
  console.log(
1781
1907
  "Warning: this is a prerelease and requires specific HubSpot account configuration to work"
@@ -1836,11 +1962,15 @@ Local proxy functionality will not work without setting up authentication.`
1836
1962
  absoluteWebRoot,
1837
1963
  PORT,
1838
1964
  sslEnabledOption2,
1839
- domainsToProxy
1965
+ domainsToProxy,
1966
+ SHARED_DEPS_ENABLED
1840
1967
  );
1841
1968
  const viteHTTPSConfig = viteServer.config.server.https;
1842
1969
  const httpsKey = viteHTTPSConfig ? viteHTTPSConfig.key : null;
1843
1970
  const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
1971
+ const projectName = getProjectNameFromHSConfig(
1972
+ path7.join(webRoot2, "../hsproject.json")
1973
+ );
1844
1974
  const httpServers = [];
1845
1975
  const expressServer = express2();
1846
1976
  expressServer.locals.devServerHost = "hslocal.net";
@@ -1852,9 +1982,8 @@ Local proxy functionality will not work without setting up authentication.`
1852
1982
  expressServer.locals.authedHublet = authedHublet;
1853
1983
  expressServer.locals.storybookEnabled = storybook2;
1854
1984
  expressServer.locals.storybookPort = STORYBOOK_PORT;
1855
- expressServer.locals.projectName = getProjectNameFromHSConfig(
1856
- path7.join(webRoot2, "../hsproject.json")
1857
- );
1985
+ expressServer.locals.projectName = projectName;
1986
+ expressServer.locals.sharedDepsEnabled = SHARED_DEPS_ENABLED;
1858
1987
  expressServer.locals.projectComponentPath = webRootProjectComponentFolder;
1859
1988
  expressServer.use(bodyParser.json());
1860
1989
  expressServer.use(
@@ -1880,7 +2009,7 @@ Local proxy functionality will not work without setting up authentication.`
1880
2009
  httpServer.listen(PORT);
1881
2010
  httpServers.push(httpServer);
1882
2011
  }
1883
- startShadowDevServer(PORT, SHADOW_PORT);
2012
+ startShadowDevServer(PORT, SHADOW_PORT, projectName);
1884
2013
  let extraServerInfo = "";
1885
2014
  const protocol = sslEnabledOption2 ? "https" : "http";
1886
2015
  if (authedPortalId) {
@@ -1891,7 +2020,7 @@ Local proxy functionality will not work without setting up authentication.`
1891
2020
  }
1892
2021
  console.log(
1893
2022
  `
1894
- HubSpot CMS dev server hosting: ${expressServer.locals.projectName}/${expressServer.locals.projectComponentPath} (at ${protocol}://hslocal.net:${PORT}${extraServerInfo})
2023
+ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectComponentPath} (at ${protocol}://hslocal.net:${PORT}${extraServerInfo})
1895
2024
  `
1896
2025
  );
1897
2026
  if (storybook2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
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.2",
27
+ "@hubspot/cms-components": "^0.4.4",
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",
@@ -77,8 +77,8 @@
77
77
  "types"
78
78
  ],
79
79
  "nodemonConfig": {
80
- "delay": "2000ms",
81
80
  "ext": "js,json,ts,tsx,jsx,html",
81
+ "delay": "2000ms",
82
82
  "ignore": [
83
83
  "testApp/*",
84
84
  "./dist/*"
@@ -95,5 +95,5 @@
95
95
  "publishConfig": {
96
96
  "access": "public"
97
97
  },
98
- "gitHead": "977f3d499c0813345ef95393b6e1c53021429ea6"
98
+ "gitHead": "9db74d3ec8ad75172d137f3d6b51d6e9d63d6e4b"
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[], sharedDepsEnabled: boolean): 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
- }