@hubspot/cms-dev-server 0.4.3 → 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 +35 -5
  2. package/dist/internalSsr.js +47 -3
  3. package/dist/run.js +113 -35
  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/index.js CHANGED
@@ -19,7 +19,9 @@ import { cloneElement } from "react";
19
19
  import { renderToStaticMarkup } from "react-dom/server";
20
20
  var viteRoot;
21
21
  var viteCommand;
22
- function resolveIslandPlugin() {
22
+ function resolveIslandPlugin({
23
+ sharedDepsEnabled
24
+ }) {
23
25
  return {
24
26
  enforce: "pre",
25
27
  name: "resolve-islands",
@@ -30,16 +32,21 @@ function resolveIslandPlugin() {
30
32
  load(id) {
31
33
  if (id.endsWith("?island") || id.endsWith("?client")) {
32
34
  const [idWithNoParam] = id.split("?");
35
+ const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
33
36
  const componentExtension = path.extname(idWithNoParam);
34
37
  const componentFilenameWithNoExtension = path.basename(
35
38
  idWithNoParam,
36
39
  componentExtension
37
40
  );
38
41
  const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
42
+ let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
43
+ if (sharedDepsEnabled) {
44
+ moduleId = moduleId.concat("?client-entry");
45
+ }
39
46
  return `
40
- const moduleId = '${viteCommand === "serve" ? idWithNoParam : modulePath}';
47
+ const moduleId = '${moduleId}';
41
48
 
42
- const lazyComponent = () => import('${idWithNoParam}');
49
+ const lazyComponent = () => import('${islandModuleImportPath}');
43
50
  lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
44
51
  lazyComponent.moduleId = moduleId;
45
52
 
@@ -50,10 +57,32 @@ function resolveIslandPlugin() {
50
57
  }
51
58
  };
52
59
  }
60
+ function clientIslandEntryPlugin() {
61
+ return {
62
+ enforce: "pre",
63
+ name: "client-island-entry-plugin",
64
+ load(id) {
65
+ if (id.endsWith("?client-entry")) {
66
+ const [idWithNoParam] = id.split("?");
67
+ return `
68
+ import { clientRenderIsland } from '@hubspot/cms-components';
69
+ import Component from '${idWithNoParam}';
70
+
71
+ export function render(island) {
72
+ return clientRenderIsland(island, Component)
73
+ }
74
+
75
+ export default Component;
76
+ `;
77
+ }
78
+ return null;
79
+ }
80
+ };
81
+ }
53
82
 
54
83
  // src/createViteDevServer.ts
55
84
  import mkcert from "vite-plugin-mkcert";
56
- async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = []) {
85
+ async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], sharedDepsEnabled) {
57
86
  const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
58
87
  `${proxyDomain}.localhost`,
59
88
  `${proxyDomain}.hslocal.net`
@@ -85,7 +114,8 @@ async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [
85
114
  plugins: [
86
115
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
87
116
  react(),
88
- resolveIslandPlugin()
117
+ sharedDepsEnabled && clientIslandEntryPlugin(),
118
+ resolveIslandPlugin({ sharedDepsEnabled })
89
119
  ],
90
120
  css: {
91
121
  postcss: webRoot
@@ -152,7 +152,9 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
152
152
  };
153
153
  var viteRoot;
154
154
  var viteCommand;
155
- function resolveIslandPlugin() {
155
+ function resolveIslandPlugin({
156
+ sharedDepsEnabled
157
+ }) {
156
158
  return {
157
159
  enforce: "pre",
158
160
  name: "resolve-islands",
@@ -163,16 +165,21 @@ function resolveIslandPlugin() {
163
165
  load(id) {
164
166
  if (id.endsWith("?island") || id.endsWith("?client")) {
165
167
  const [idWithNoParam] = id.split("?");
168
+ const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
166
169
  const componentExtension = path.extname(idWithNoParam);
167
170
  const componentFilenameWithNoExtension = path.basename(
168
171
  idWithNoParam,
169
172
  componentExtension
170
173
  );
171
174
  const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
175
+ let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
176
+ if (sharedDepsEnabled) {
177
+ moduleId = moduleId.concat("?client-entry");
178
+ }
172
179
  return `
173
- const moduleId = '${viteCommand === "serve" ? idWithNoParam : modulePath}';
180
+ const moduleId = '${moduleId}';
174
181
 
175
- const lazyComponent = () => import('${idWithNoParam}');
182
+ const lazyComponent = () => import('${islandModuleImportPath}');
176
183
  lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
177
184
  lazyComponent.moduleId = moduleId;
178
185
 
@@ -183,6 +190,28 @@ function resolveIslandPlugin() {
183
190
  }
184
191
  };
185
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
+ }
186
215
  var promiseForNewWritableStream = () => {
187
216
  const chunks = [];
188
217
  const writableStream = new stream.Writable();
@@ -290,6 +319,18 @@ var removeComponentExtension = (componentPath) => {
290
319
  }
291
320
  return componentPath.slice(0, -1 * ext.length);
292
321
  };
322
+ var COMBINED_REACT_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/react/v18";
323
+ var ISLAND_RUNTIME_CONFIG_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/island-runtime/v1";
324
+ function getCombinedReactUrl() {
325
+ const hsEnv = process.env.HS_ENV;
326
+ const fileVersion = hsEnv === "prod" ? `react-combined.mjs` : "react-combined-qa.mjs";
327
+ return `${COMBINED_REACT_BASE_PATH}/${fileVersion}`;
328
+ }
329
+ function getIslandRuntimeConfigUrl() {
330
+ const hsEnv = process.env.HS_ENV;
331
+ const fileVersion = hsEnv === "prod" ? `island-runtime.mjs` : "island-runtime-qa.mjs";
332
+ return `${ISLAND_RUNTIME_CONFIG_BASE_PATH}/${fileVersion}`;
333
+ }
293
334
  var findAllComponentsIn = (webRoot, componentsFolder, includeSubdirIndexJS) => {
294
335
  const fullComponentsFolderPath = joinPosix(webRoot, componentsFolder);
295
336
  const componentsByName = {};
@@ -399,13 +440,16 @@ export {
399
440
  MODULE_FOLDER_PATH,
400
441
  VIRTUAL_CONFIG_SETUP,
401
442
  VIRTUAL_ISLAND_RUNTIME,
443
+ clientIslandEntryPlugin,
402
444
  collectCssInDev,
403
445
  collectCssModules,
404
446
  createIslandsGlobalJsForClientInDev,
405
447
  findAllComponentsIn_default as findAllComponentsIn,
406
448
  findAllModulesInRoot,
407
449
  findAllPartialsInRoot,
450
+ getCombinedReactUrl,
408
451
  getComponentExtension,
452
+ getIslandRuntimeConfigUrl,
409
453
  getIslandUrls,
410
454
  getServerGlobalsToInject,
411
455
  hasComponentExtension,
package/dist/run.js CHANGED
@@ -150,7 +150,9 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
150
150
  };
151
151
  var viteRoot;
152
152
  var viteCommand;
153
- function resolveIslandPlugin() {
153
+ function resolveIslandPlugin({
154
+ sharedDepsEnabled
155
+ }) {
154
156
  return {
155
157
  enforce: "pre",
156
158
  name: "resolve-islands",
@@ -161,16 +163,21 @@ function resolveIslandPlugin() {
161
163
  load(id) {
162
164
  if (id.endsWith("?island") || id.endsWith("?client")) {
163
165
  const [idWithNoParam] = id.split("?");
166
+ const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
164
167
  const componentExtension = path.extname(idWithNoParam);
165
168
  const componentFilenameWithNoExtension = path.basename(
166
169
  idWithNoParam,
167
170
  componentExtension
168
171
  );
169
172
  const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
173
+ let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
174
+ if (sharedDepsEnabled) {
175
+ moduleId = moduleId.concat("?client-entry");
176
+ }
170
177
  return `
171
- const moduleId = '${viteCommand === "serve" ? idWithNoParam : modulePath}';
178
+ const moduleId = '${moduleId}';
172
179
 
173
- const lazyComponent = () => import('${idWithNoParam}');
180
+ const lazyComponent = () => import('${islandModuleImportPath}');
174
181
  lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
175
182
  lazyComponent.moduleId = moduleId;
176
183
 
@@ -181,6 +188,28 @@ function resolveIslandPlugin() {
181
188
  }
182
189
  };
183
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
+ }
184
213
  var promiseForNewWritableStream = () => {
185
214
  const chunks = [];
186
215
  const writableStream = new stream.Writable();
@@ -508,7 +537,18 @@ var renderPartial_default = renderPartial;
508
537
  // src/lib/templates.ts
509
538
  import { promises as fsPromises } from "fs";
510
539
  var { readFile } = fsPromises;
511
- 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
+ }
512
552
  return `<script type="module">
513
553
  import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
514
554
  initConfigSingletonFromJSON(window.__hsEnvConfig);
@@ -528,7 +568,7 @@ var createdPlainHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
528
568
  <!--bodyend-->`
529
569
  );
530
570
  };
531
- var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock) => {
571
+ var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock, sharedDepsEnabled) => {
532
572
  let htmlTemplate = await createdPlainHtmlTemplate(
533
573
  baseTemplatePath,
534
574
  title,
@@ -537,14 +577,14 @@ var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
537
577
  htmlTemplate = htmlTemplate.replace(
538
578
  "<!--bodyend-->",
539
579
  `
540
- ${generateIslandSetupScriptBlock()}
580
+ ${generateIslandSetupScriptBlock(sharedDepsEnabled)}
541
581
  <!-- ISLAND_RUNTIME_AND_SETUP_SCRIPT_BLOCK -->
542
582
  <!--islandsglobal-->
543
583
  `
544
584
  );
545
585
  return htmlTemplate;
546
586
  };
547
- var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, title, renderContext, viteServer) => {
587
+ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, title, renderContext, viteServer, sharedDepsEnabled) => {
548
588
  let htmlTemplate;
549
589
  if (renderContext.islands.length) {
550
590
  const globalScriptBlock = getServerGlobalsToInject(
@@ -554,7 +594,8 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
554
594
  htmlTemplate = await createIslandHtmlTemplate(
555
595
  baseTemplatePath,
556
596
  title,
557
- globalScriptBlock
597
+ globalScriptBlock,
598
+ sharedDepsEnabled
558
599
  );
559
600
  htmlTemplate = htmlTemplate.replace(
560
601
  "<!--islandsglobal-->",
@@ -580,12 +621,12 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
580
621
  }
581
622
  return viteServer.transformIndexHtml(url3, htmlTemplate);
582
623
  };
583
- var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerRequestData, viteServer) => {
624
+ var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerRequestData, viteServer, sharedDepsEnabled) => {
584
625
  const internalSsrPath = packagePath(import.meta.url, "internalSsr");
585
626
  const { createIslandsGlobalJsForClientInDev: createIslandsGlobalJsForClientInDev2 } = await viteServer.ssrLoadModule(internalSsrPath);
586
627
  const islandRuntimeScript = await viteServer.transformIndexHtml(
587
628
  "/",
588
- generateIslandSetupScriptBlock()
629
+ generateIslandSetupScriptBlock(sharedDepsEnabled)
589
630
  );
590
631
  return `${islandRuntimeScript}
591
632
  <script>${createIslandsGlobalJsForClientInDev2(
@@ -600,7 +641,14 @@ var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerReque
600
641
  // src/routes/partial.ts
601
642
  import { buildStaticEnvConfig } from "@hubspot/cms-components/config";
602
643
  var partialRouteHandler = async (request2, response) => {
603
- 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;
604
652
  const partialName = request2.params.partial;
605
653
  const baseTemplatePath = packagePath(
606
654
  import.meta.url,
@@ -632,7 +680,8 @@ var partialRouteHandler = async (request2, response) => {
632
680
  request2.originalUrl,
633
681
  `Partial: ${partialPath}`,
634
682
  renderContext,
635
- viteServer
683
+ viteServer,
684
+ sharedDepsEnabled
636
685
  );
637
686
  const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
638
687
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
@@ -788,7 +837,14 @@ var renderModule_default = renderModule;
788
837
 
789
838
  // src/routes/module.ts
790
839
  var moduleRouteHandler = async (request2, response) => {
791
- 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;
792
848
  const moduleName = request2.params.moduleName;
793
849
  const baseTemplatePath = packagePath(
794
850
  import.meta.url,
@@ -832,7 +888,8 @@ var moduleRouteHandler = async (request2, response) => {
832
888
  request2.originalUrl,
833
889
  `Module: ${modulePath}`,
834
890
  renderContext,
835
- viteServer
891
+ viteServer,
892
+ sharedDepsEnabled
836
893
  );
837
894
  const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
838
895
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
@@ -1125,7 +1182,7 @@ import {
1125
1182
  import {
1126
1183
  mergeServerRequestData_internal
1127
1184
  } from "@hubspot/cms-components";
1128
- var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId) => {
1185
+ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName) => {
1129
1186
  const url3 = new URL(urlToProxy);
1130
1187
  console.log(`Proxying request to ${url3.href}`, {
1131
1188
  previewKey,
@@ -1143,7 +1200,8 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId) =>
1143
1200
  proxiedQueryParams = {
1144
1201
  ...proxiedQueryParams,
1145
1202
  hs_preview: `${previewKey}-${contentId}`,
1146
- hsLocalProxy: true
1203
+ hsLocalProxy: true,
1204
+ hsLocalProxyProject: `@projects/${projectName}`
1147
1205
  };
1148
1206
  const result = hsGet2(accountId, {
1149
1207
  baseUrl: url3.origin,
@@ -1203,7 +1261,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
1203
1261
  throw new Error(`Unimplemented render of ${placeholderPath}.`);
1204
1262
  }
1205
1263
  };
1206
- 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) {
1207
1265
  let accountId;
1208
1266
  let proxyEnv;
1209
1267
  try {
@@ -1231,7 +1289,8 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1231
1289
  accountId,
1232
1290
  urlToProxy,
1233
1291
  previewKey,
1234
- contentId
1292
+ contentId,
1293
+ projectName
1235
1294
  );
1236
1295
  const environmentConfig = buildStaticEnvConfig3(
1237
1296
  portalId,
@@ -1315,7 +1374,8 @@ ${html}`;
1315
1374
  const islandRuntimeAndGlobalScriptHtml = await getIslandRuntimeAndGlobalToInject(
1316
1375
  sortedIslandRoots,
1317
1376
  mergedPerRequestState,
1318
- viteServer
1377
+ viteServer,
1378
+ sharedDepsEnabled
1319
1379
  );
1320
1380
  response.write(islandRuntimeAndGlobalScriptHtml);
1321
1381
  }
@@ -1338,7 +1398,13 @@ ${error.stack}`
1338
1398
 
1339
1399
  // src/routes/proxyPageRouteHandler.ts
1340
1400
  async function proxyPageRouteHandler(request2, response, next) {
1341
- 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;
1342
1408
  if (!request2.accepts().includes("text/html")) {
1343
1409
  return response.sendStatus(404);
1344
1410
  }
@@ -1374,6 +1440,7 @@ async function proxyPageRouteHandler(request2, response, next) {
1374
1440
  viteServer,
1375
1441
  projectName,
1376
1442
  projectComponentPath,
1443
+ sharedDepsEnabled,
1377
1444
  urlToProxy,
1378
1445
  fullOriginalUrl
1379
1446
  );
@@ -1434,7 +1501,8 @@ async function proxyPathPageRouteHandler(request2, response, next) {
1434
1501
  devServerHost,
1435
1502
  devServerPort,
1436
1503
  projectName,
1437
- projectComponentPath
1504
+ projectComponentPath,
1505
+ sharedDepsEnabled
1438
1506
  } = request2.app.locals;
1439
1507
  if (!request2.accepts().includes("text/html")) {
1440
1508
  return response.sendStatus(404);
@@ -1490,6 +1558,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
1490
1558
  viteServer,
1491
1559
  projectName,
1492
1560
  projectComponentPath,
1561
+ sharedDepsEnabled,
1493
1562
  proxyPageUrl.href,
1494
1563
  proxyPageUrl.href
1495
1564
  );
@@ -1576,7 +1645,7 @@ import express from "express";
1576
1645
  import { Router as Router2 } from "express";
1577
1646
  import { getAccountId as getAccountId2 } from "@hubspot/cli-lib/lib/config.js";
1578
1647
  import cors from "cors";
1579
- function getShadowDevServerCheckHandler(devServerPort) {
1648
+ function getShadowDevServerCheckHandler(devServerPort, projectName) {
1580
1649
  return async function shadowDevServerCheckHandler(request2, response) {
1581
1650
  const { query } = request2;
1582
1651
  if (query) {
@@ -1614,7 +1683,8 @@ function getShadowDevServerCheckHandler(devServerPort) {
1614
1683
  accountId,
1615
1684
  pageUrl,
1616
1685
  previewKey,
1617
- contentId
1686
+ contentId,
1687
+ projectName
1618
1688
  );
1619
1689
  const localRenderPlaceholders = findLocalRenderPlaceholders(pageHtml);
1620
1690
  if (localRenderPlaceholders.length) {
@@ -1637,19 +1707,19 @@ ${error.stack}`
1637
1707
  }
1638
1708
  };
1639
1709
  }
1640
- async function createShadowDevServerRoutes(devServerPort) {
1710
+ async function createShadowDevServerRoutes(devServerPort, projectName) {
1641
1711
  const shadowDevServerRoutes = Router2();
1642
1712
  shadowDevServerRoutes.get(
1643
1713
  "/check-if-local-dev-server",
1644
1714
  cors(),
1645
- getShadowDevServerCheckHandler(devServerPort)
1715
+ getShadowDevServerCheckHandler(devServerPort, projectName)
1646
1716
  );
1647
1717
  return shadowDevServerRoutes;
1648
1718
  }
1649
1719
 
1650
1720
  // src/shadowDevServer/startShadowDevServer.ts
1651
1721
  var testNetServer = net.createServer();
1652
- async function startShadowDevServer(devServerPort, shadowPort) {
1722
+ async function startShadowDevServer(devServerPort, shadowPort, projectName) {
1653
1723
  const portIsTaken = await new Promise((res, rej) => {
1654
1724
  console.log(`Starting proxy link server on port ${shadowPort}`);
1655
1725
  testNetServer.once("error", (err) => {
@@ -1675,14 +1745,17 @@ async function startShadowDevServer(devServerPort, shadowPort) {
1675
1745
  }
1676
1746
  const shadowDevServer = express();
1677
1747
  shadowDevServer.listen(shadowPort);
1678
- shadowDevServer.use("/", await createShadowDevServerRoutes(devServerPort));
1748
+ shadowDevServer.use(
1749
+ "/",
1750
+ await createShadowDevServerRoutes(devServerPort, projectName)
1751
+ );
1679
1752
  }
1680
1753
 
1681
1754
  // src/createViteDevServer.ts
1682
1755
  import { createServer as createViteServer } from "vite";
1683
1756
  import { default as react } from "@vitejs/plugin-react";
1684
1757
  import mkcert from "vite-plugin-mkcert";
1685
- async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = []) {
1758
+ async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [], sharedDepsEnabled) {
1686
1759
  const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
1687
1760
  `${proxyDomain}.localhost`,
1688
1761
  `${proxyDomain}.hslocal.net`
@@ -1714,7 +1787,8 @@ async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy =
1714
1787
  plugins: [
1715
1788
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
1716
1789
  react(),
1717
- resolveIslandPlugin()
1790
+ sharedDepsEnabled && clientIslandEntryPlugin(),
1791
+ resolveIslandPlugin({ sharedDepsEnabled })
1718
1792
  ],
1719
1793
  css: {
1720
1794
  postcss: webRoot2
@@ -1827,6 +1901,7 @@ var BASE_PATH = "/";
1827
1901
  var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
1828
1902
  var SHADOW_PORT = 1442;
1829
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);
1830
1905
  async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2, hubspotCliAccountNameOption2, sslEnabledOption2) {
1831
1906
  console.log(
1832
1907
  "Warning: this is a prerelease and requires specific HubSpot account configuration to work"
@@ -1887,11 +1962,15 @@ Local proxy functionality will not work without setting up authentication.`
1887
1962
  absoluteWebRoot,
1888
1963
  PORT,
1889
1964
  sslEnabledOption2,
1890
- domainsToProxy
1965
+ domainsToProxy,
1966
+ SHARED_DEPS_ENABLED
1891
1967
  );
1892
1968
  const viteHTTPSConfig = viteServer.config.server.https;
1893
1969
  const httpsKey = viteHTTPSConfig ? viteHTTPSConfig.key : null;
1894
1970
  const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
1971
+ const projectName = getProjectNameFromHSConfig(
1972
+ path7.join(webRoot2, "../hsproject.json")
1973
+ );
1895
1974
  const httpServers = [];
1896
1975
  const expressServer = express2();
1897
1976
  expressServer.locals.devServerHost = "hslocal.net";
@@ -1903,9 +1982,8 @@ Local proxy functionality will not work without setting up authentication.`
1903
1982
  expressServer.locals.authedHublet = authedHublet;
1904
1983
  expressServer.locals.storybookEnabled = storybook2;
1905
1984
  expressServer.locals.storybookPort = STORYBOOK_PORT;
1906
- expressServer.locals.projectName = getProjectNameFromHSConfig(
1907
- path7.join(webRoot2, "../hsproject.json")
1908
- );
1985
+ expressServer.locals.projectName = projectName;
1986
+ expressServer.locals.sharedDepsEnabled = SHARED_DEPS_ENABLED;
1909
1987
  expressServer.locals.projectComponentPath = webRootProjectComponentFolder;
1910
1988
  expressServer.use(bodyParser.json());
1911
1989
  expressServer.use(
@@ -1931,7 +2009,7 @@ Local proxy functionality will not work without setting up authentication.`
1931
2009
  httpServer.listen(PORT);
1932
2010
  httpServers.push(httpServer);
1933
2011
  }
1934
- startShadowDevServer(PORT, SHADOW_PORT);
2012
+ startShadowDevServer(PORT, SHADOW_PORT, projectName);
1935
2013
  let extraServerInfo = "";
1936
2014
  const protocol = sslEnabledOption2 ? "https" : "http";
1937
2015
  if (authedPortalId) {
@@ -1942,7 +2020,7 @@ Local proxy functionality will not work without setting up authentication.`
1942
2020
  }
1943
2021
  console.log(
1944
2022
  `
1945
- 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})
1946
2024
  `
1947
2025
  );
1948
2026
  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.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.3",
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",
@@ -95,5 +95,5 @@
95
95
  "publishConfig": {
96
96
  "access": "public"
97
97
  },
98
- "gitHead": "7d2696951f3aeeae3085382ebe1a66ba94ecc748"
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
- }