@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/index.js CHANGED
@@ -17,9 +17,13 @@ import { join as joinPosix } from "path/posix";
17
17
  import { basename } from "path";
18
18
  import { cloneElement } from "react";
19
19
  import { renderToStaticMarkup } from "react-dom/server";
20
+ function isUngatedFor(gates, gate) {
21
+ return gates.includes(gate);
22
+ }
20
23
  var viteRoot;
21
24
  var viteCommand;
22
- function resolveIslandPlugin() {
25
+ function resolveIslandPlugin(gates) {
26
+ const sharedDepsEnabled = isUngatedFor(gates, "CMS:JSRenderer:SharedDeps");
23
27
  return {
24
28
  enforce: "pre",
25
29
  name: "resolve-islands",
@@ -30,16 +34,21 @@ function resolveIslandPlugin() {
30
34
  load(id) {
31
35
  if (id.endsWith("?island") || id.endsWith("?client")) {
32
36
  const [idWithNoParam] = id.split("?");
37
+ const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
33
38
  const componentExtension = path.extname(idWithNoParam);
34
39
  const componentFilenameWithNoExtension = path.basename(
35
40
  idWithNoParam,
36
41
  componentExtension
37
42
  );
38
43
  const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
44
+ let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
45
+ if (sharedDepsEnabled) {
46
+ moduleId = moduleId.concat("?client-entry");
47
+ }
39
48
  return `
40
- const moduleId = '${viteCommand === "serve" ? idWithNoParam : modulePath}';
49
+ const moduleId = '${moduleId}';
41
50
 
42
- const lazyComponent = () => import('${idWithNoParam}');
51
+ const lazyComponent = () => import('${islandModuleImportPath}');
43
52
  lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
44
53
  lazyComponent.moduleId = moduleId;
45
54
 
@@ -50,10 +59,36 @@ function resolveIslandPlugin() {
50
59
  }
51
60
  };
52
61
  }
62
+ function clientIslandEntryPlugin() {
63
+ return {
64
+ enforce: "pre",
65
+ name: "client-island-entry-plugin",
66
+ load(id) {
67
+ if (id.endsWith("?client-entry")) {
68
+ const [idWithNoParam] = id.split("?");
69
+ return `
70
+ import { clientRenderIsland } from '@hubspot/cms-components';
71
+ import Component from '${idWithNoParam}';
72
+
73
+ export function render(island) {
74
+ return clientRenderIsland(island, Component)
75
+ }
76
+
77
+ export default Component;
78
+ `;
79
+ }
80
+ return null;
81
+ }
82
+ };
83
+ }
53
84
 
54
85
  // src/createViteDevServer.ts
55
86
  import mkcert from "vite-plugin-mkcert";
56
- async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = []) {
87
+ async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], jsRenderingGates) {
88
+ const sharedDepsEnabled = isUngatedFor(
89
+ jsRenderingGates,
90
+ "CMS:JSRenderer:SharedDeps"
91
+ );
57
92
  const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
58
93
  `${proxyDomain}.localhost`,
59
94
  `${proxyDomain}.hslocal.net`
@@ -85,7 +120,8 @@ async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [
85
120
  plugins: [
86
121
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
87
122
  react(),
88
- resolveIslandPlugin()
123
+ sharedDepsEnabled && clientIslandEntryPlugin(),
124
+ resolveIslandPlugin(jsRenderingGates)
89
125
  ],
90
126
  css: {
91
127
  postcss: webRoot
@@ -150,9 +150,17 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
150
150
  indent
151
151
  )}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
152
152
  };
153
+ var GATES = [
154
+ "CMS:JSRenderer:SharedDeps",
155
+ "CMS:JSRenderer:GetServerSideProps"
156
+ ];
157
+ function isUngatedFor(gates, gate) {
158
+ return gates.includes(gate);
159
+ }
153
160
  var viteRoot;
154
161
  var viteCommand;
155
- function resolveIslandPlugin() {
162
+ function resolveIslandPlugin(gates) {
163
+ const sharedDepsEnabled = isUngatedFor(gates, "CMS:JSRenderer:SharedDeps");
156
164
  return {
157
165
  enforce: "pre",
158
166
  name: "resolve-islands",
@@ -163,16 +171,21 @@ function resolveIslandPlugin() {
163
171
  load(id) {
164
172
  if (id.endsWith("?island") || id.endsWith("?client")) {
165
173
  const [idWithNoParam] = id.split("?");
174
+ const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
166
175
  const componentExtension = path.extname(idWithNoParam);
167
176
  const componentFilenameWithNoExtension = path.basename(
168
177
  idWithNoParam,
169
178
  componentExtension
170
179
  );
171
180
  const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
181
+ let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
182
+ if (sharedDepsEnabled) {
183
+ moduleId = moduleId.concat("?client-entry");
184
+ }
172
185
  return `
173
- const moduleId = '${viteCommand === "serve" ? idWithNoParam : modulePath}';
186
+ const moduleId = '${moduleId}';
174
187
 
175
- const lazyComponent = () => import('${idWithNoParam}');
188
+ const lazyComponent = () => import('${islandModuleImportPath}');
176
189
  lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
177
190
  lazyComponent.moduleId = moduleId;
178
191
 
@@ -183,6 +196,28 @@ function resolveIslandPlugin() {
183
196
  }
184
197
  };
185
198
  }
199
+ function clientIslandEntryPlugin() {
200
+ return {
201
+ enforce: "pre",
202
+ name: "client-island-entry-plugin",
203
+ load(id) {
204
+ if (id.endsWith("?client-entry")) {
205
+ const [idWithNoParam] = id.split("?");
206
+ return `
207
+ import { clientRenderIsland } from '@hubspot/cms-components';
208
+ import Component from '${idWithNoParam}';
209
+
210
+ export function render(island) {
211
+ return clientRenderIsland(island, Component)
212
+ }
213
+
214
+ export default Component;
215
+ `;
216
+ }
217
+ return null;
218
+ }
219
+ };
220
+ }
186
221
  var promiseForNewWritableStream = () => {
187
222
  const chunks = [];
188
223
  const writableStream = new stream.Writable();
@@ -290,6 +325,18 @@ var removeComponentExtension = (componentPath) => {
290
325
  }
291
326
  return componentPath.slice(0, -1 * ext.length);
292
327
  };
328
+ var COMBINED_REACT_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/react/v18";
329
+ var ISLAND_RUNTIME_CONFIG_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/island-runtime/v1";
330
+ function getCombinedReactUrl() {
331
+ const hsEnv = process.env.HS_ENV;
332
+ const fileVersion = hsEnv === "prod" ? `react-combined.mjs` : "react-combined-qa.mjs";
333
+ return `${COMBINED_REACT_BASE_PATH}/${fileVersion}`;
334
+ }
335
+ function getIslandRuntimeConfigUrl() {
336
+ const hsEnv = process.env.HS_ENV;
337
+ const fileVersion = hsEnv === "prod" ? `island-runtime.mjs` : "island-runtime-qa.mjs";
338
+ return `${ISLAND_RUNTIME_CONFIG_BASE_PATH}/${fileVersion}`;
339
+ }
293
340
  var findAllComponentsIn = (webRoot, componentsFolder, includeSubdirIndexJS) => {
294
341
  const fullComponentsFolderPath = joinPosix(webRoot, componentsFolder);
295
342
  const componentsByName = {};
@@ -396,20 +443,25 @@ function renderFieldsToJson(fields) {
396
443
  export {
397
444
  COMPONENT_EXTENSIONS,
398
445
  ENTRY_POINTS_PATH,
446
+ GATES,
399
447
  MODULE_FOLDER_PATH,
400
448
  VIRTUAL_CONFIG_SETUP,
401
449
  VIRTUAL_ISLAND_RUNTIME,
450
+ clientIslandEntryPlugin,
402
451
  collectCssInDev,
403
452
  collectCssModules,
404
453
  createIslandsGlobalJsForClientInDev,
405
454
  findAllComponentsIn_default as findAllComponentsIn,
406
455
  findAllModulesInRoot,
407
456
  findAllPartialsInRoot,
457
+ getCombinedReactUrl,
408
458
  getComponentExtension,
459
+ getIslandRuntimeConfigUrl,
409
460
  getIslandUrls,
410
461
  getServerGlobalsToInject,
411
462
  hasComponentExtension,
412
463
  isStorybookStory,
464
+ isUngatedFor,
413
465
  removeComponentExtension,
414
466
  renderComponentOnServer,
415
467
  renderFieldsToJson,