@hubspot/cms-dev-server 0.5.0 → 0.6.1

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 (53) hide show
  1. package/dist/index.js +2 -11
  2. package/dist/internalSsr.js +12 -14
  3. package/dist/run.js +68 -31
  4. package/dist/storybook/index.js +61 -46
  5. package/dist/{storybook → storybook-main}/main.js +32 -16
  6. package/dist/storybook-main/preview.js +20 -0
  7. package/package.json +13 -12
  8. package/types/storybook/getFieldsArgTypes.d.ts +1 -7
  9. package/types/storybook/moduleStory.d.ts +5 -2
  10. package/types/storybook/types.d.ts +11 -0
  11. package/dist/components/ModulesList.js +0 -14
  12. package/dist/components/PartialsList.js +0 -13
  13. package/dist/createDevServer.js +0 -162
  14. package/dist/createViteDevServer.js +0 -51
  15. package/dist/lib/cli.js +0 -27
  16. package/dist/lib/debug.js +0 -2
  17. package/dist/lib/errors.js +0 -22
  18. package/dist/lib/fullOriginalUrlFromRequest.js +0 -3
  19. package/dist/lib/httpsRedirectingServer.js +0 -48
  20. package/dist/lib/moduleGraph.js +0 -11
  21. package/dist/lib/proxyHelpers.js +0 -70
  22. package/dist/lib/proxyHelpers.test.js +0 -136
  23. package/dist/lib/renderComponentWithCSS.js +0 -26
  24. package/dist/lib/renderHelpers.js +0 -45
  25. package/dist/lib/renderModule.js +0 -56
  26. package/dist/lib/renderPartial.js +0 -15
  27. package/dist/lib/templates.js +0 -55
  28. package/dist/proxyPage/constants.js +0 -1
  29. package/dist/proxyPage/fetchContentMetadata.js +0 -59
  30. package/dist/proxyPage/fetchDomains.js +0 -29
  31. package/dist/proxyPage/fetchPreviewInfo.js +0 -37
  32. package/dist/proxyPage/proxyPage.js +0 -174
  33. package/dist/proxyPage/renderLocalError.js +0 -27
  34. package/dist/proxyPage/utils.js +0 -38
  35. package/dist/routes/createDevServerRoutes.js +0 -43
  36. package/dist/routes/homeRouteHandler.js +0 -12
  37. package/dist/routes/linksToAllModulesRouteHandler.js +0 -10
  38. package/dist/routes/linksToAllPartialsRouteHandler.js +0 -10
  39. package/dist/routes/module.js +0 -41
  40. package/dist/routes/partial.js +0 -30
  41. package/dist/routes/proxyPageResourceRedirect.js +0 -22
  42. package/dist/routes/proxyPageRouteHandler.js +0 -40
  43. package/dist/routes/proxyPathPageResourceRedirect.js +0 -36
  44. package/dist/routes/proxyPathPageRouteHandler.js +0 -43
  45. package/dist/shadowDevServer/createShadowDevServerRoutes.js +0 -63
  46. package/dist/shadowDevServer/startShadowDevServer.js +0 -31
  47. package/dist/storybook/getFieldsArgTypes.js +0 -54
  48. package/dist/storybook/getFieldsArgTypes.test.js +0 -91
  49. package/dist/storybook/getNestedFieldObjectForArgs.js +0 -22
  50. package/dist/storybook/getNestedFieldObjectForArgs.test.js +0 -40
  51. package/dist/storybook/moduleStory.js +0 -61
  52. package/dist/storybook/preview.js +0 -9
  53. package/dist/storybook/types.js +0 -1
package/dist/index.js CHANGED
@@ -4,16 +4,6 @@ import { default as react } from "@vitejs/plugin-react";
4
4
 
5
5
  // ../cms-js-internal/dist/index.js
6
6
  import path, { basename } from "path";
7
- import { createRequire } from "module";
8
- import * as jsxRuntime from "react/jsx-runtime";
9
- import stream from "stream";
10
- import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
11
- import { createServerRenderContextV2, ServerRenderContext } from "@hubspot/cms-components";
12
- import { createHash } from "crypto";
13
- import { existsSync, readdirSync, lstatSync } from "fs";
14
- import { join } from "path/posix";
15
- import { cloneElement } from "react";
16
- var require2 = createRequire(import.meta.url);
17
7
  function isUngatedFor(gates, gate) {
18
8
  return gates.includes(gate);
19
9
  }
@@ -56,7 +46,7 @@ function resolveIslandPlugin(gates) {
56
46
  }
57
47
  };
58
48
  }
59
- var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: `island-${renderableIsland.index}-`,\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
49
+ var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {\n ClientRenderContextProvider,\n buildIslandIdentifierPrefix,\n} from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
60
50
  var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
61
51
  function clientIslandEntryPlugin() {
62
52
  return {
@@ -120,6 +110,7 @@ async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [
120
110
  noExternal: "@hubspot/cms-components"
121
111
  },
122
112
  resolve: {
113
+ conditions: ["server"],
123
114
  dedupe: ["react", "react-dom", "@hubspot/cms-components"]
124
115
  },
125
116
  optimizeDeps: {
@@ -1,12 +1,11 @@
1
1
  // ../cms-js-internal/dist/index.js
2
2
  import path, { basename } from "path";
3
- import { createRequire } from "module";
3
+ import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
4
4
  import * as jsxRuntime from "react/jsx-runtime";
5
5
  import stream from "stream";
6
6
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
7
7
  import { createServerRenderContextV2, ServerRenderContext } from "@hubspot/cms-components";
8
8
  import { createHash } from "crypto";
9
- import { existsSync, readdirSync, lstatSync } from "fs";
10
9
  import { join } from "path/posix";
11
10
  import { cloneElement } from "react";
12
11
  var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
@@ -152,12 +151,12 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
152
151
  indent
153
152
  )}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
154
153
  };
155
- var require2 = createRequire(import.meta.url);
156
154
  var GATES = [
157
155
  "CMS:JSRenderer:SharedDeps",
158
156
  "CMS:JSRenderer:GetServerSideProps",
159
157
  "CMS:JSRenderer:LocalProxySchemaVersion1",
160
- "CMS:JSRenderer:GraphQLQueryBuild"
158
+ "CMS:JSRenderer:GraphQLQueryBuild",
159
+ "CMS:JSRenderer:SeparateIslandRenderOption"
161
160
  ];
162
161
  var ENABLED_FEATURES_GATE_MAP = {
163
162
  "cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
@@ -172,10 +171,9 @@ var BUILD_INFO_PATH = "/build-info.json";
172
171
  function ungatedAtBuildTimeFor(buildDir, gate) {
173
172
  try {
174
173
  console.log("loading path", path.join(buildDir, BUILD_INFO_PATH));
175
- const buildInfo = require2(path.join(
176
- buildDir,
177
- BUILD_INFO_PATH
178
- ));
174
+ const buildInfo = JSON.parse(
175
+ readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
176
+ );
179
177
  return isUngatedFor(buildInfo.gates, gate);
180
178
  } catch (e) {
181
179
  console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
@@ -221,7 +219,7 @@ function resolveIslandPlugin(gates) {
221
219
  }
222
220
  };
223
221
  }
224
- var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: `island-${renderableIsland.index}-`,\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
222
+ var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {\n ClientRenderContextProvider,\n buildIslandIdentifierPrefix,\n} from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
225
223
  var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
226
224
  function clientIslandEntryPlugin() {
227
225
  return {
@@ -273,21 +271,21 @@ var promiseForNewWritableStream = () => {
273
271
  });
274
272
  return { streamDonePromise, writableStream };
275
273
  };
276
- var renderStreamToPromise = async (reactElements, renderOptions = {}) => {
274
+ var renderStreamToPromise = async (reactElements, options) => {
277
275
  const { streamDonePromise, writableStream } = promiseForNewWritableStream();
278
276
  const {
279
277
  pipe
280
278
  /* abort */
281
279
  } = renderToPipeableStream(reactElements, {
282
- ...renderOptions,
280
+ ...options || {},
283
281
  onShellReady() {
284
282
  },
285
283
  onAllReady() {
286
284
  pipe(writableStream);
285
+ if (options == null ? void 0 : options.onAllReady) {
286
+ options.onAllReady();
287
+ }
287
288
  }
288
- // We will log the error sent to the writable, any need to do something in these callbacks?
289
- // onShellError(error) {},
290
- // onError(error) {},
291
289
  });
292
290
  return streamDonePromise;
293
291
  };
package/dist/run.js CHANGED
@@ -40,6 +40,7 @@ import http3 from "http";
40
40
  import bodyParser from "body-parser";
41
41
  import { spawn } from "child_process";
42
42
  import { normalizePath as normalizePath4 } from "vite";
43
+ import { Transform } from "stream";
43
44
 
44
45
  // src/routes/createDevServerRoutes.ts
45
46
  import { Router } from "express";
@@ -56,13 +57,12 @@ function fullOriginalUrlFromRequest(request2) {
56
57
 
57
58
  // ../cms-js-internal/dist/index.js
58
59
  import path, { basename } from "path";
59
- import { createRequire } from "module";
60
+ import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
60
61
  import * as jsxRuntime from "react/jsx-runtime";
61
62
  import stream from "stream";
62
63
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
63
64
  import { createServerRenderContextV2, ServerRenderContext } from "@hubspot/cms-components";
64
65
  import { createHash } from "crypto";
65
- import { existsSync, readdirSync, lstatSync } from "fs";
66
66
  import { join } from "path/posix";
67
67
  import { cloneElement } from "react";
68
68
  var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
@@ -147,7 +147,6 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
147
147
  indent
148
148
  )}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
149
149
  };
150
- var require2 = createRequire(import.meta.url);
151
150
  var ENABLED_FEATURES_GATE_MAP = {
152
151
  "cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
153
152
  "cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
@@ -196,7 +195,7 @@ function resolveIslandPlugin(gates) {
196
195
  }
197
196
  };
198
197
  }
199
- var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: `island-${renderableIsland.index}-`,\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
198
+ var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {\n ClientRenderContextProvider,\n buildIslandIdentifierPrefix,\n} from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
200
199
  var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
201
200
  function clientIslandEntryPlugin() {
202
201
  return {
@@ -248,21 +247,21 @@ var promiseForNewWritableStream = () => {
248
247
  });
249
248
  return { streamDonePromise, writableStream };
250
249
  };
251
- var renderStreamToPromise = async (reactElements, renderOptions = {}) => {
250
+ var renderStreamToPromise = async (reactElements, options) => {
252
251
  const { streamDonePromise, writableStream } = promiseForNewWritableStream();
253
252
  const {
254
253
  pipe
255
254
  /* abort */
256
255
  } = renderToPipeableStream(reactElements, {
257
- ...renderOptions,
256
+ ...options || {},
258
257
  onShellReady() {
259
258
  },
260
259
  onAllReady() {
261
260
  pipe(writableStream);
261
+ if (options == null ? void 0 : options.onAllReady) {
262
+ options.onAllReady();
263
+ }
262
264
  }
263
- // We will log the error sent to the writable, any need to do something in these callbacks?
264
- // onShellError(error) {},
265
- // onError(error) {},
266
265
  });
267
266
  return streamDonePromise;
268
267
  };
@@ -709,7 +708,7 @@ var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerReque
709
708
  };
710
709
 
711
710
  // src/routes/partial.ts
712
- import { buildStaticEnvConfig } from "@hubspot/cms-components/config";
711
+ import { buildStaticEnvConfig } from "@hubspot/cms-components";
713
712
  var partialRouteHandler = async (request2, response) => {
714
713
  const {
715
714
  authedPortalId,
@@ -856,7 +855,7 @@ var linksToAllModuleRouteHandler = async (request2, response) => {
856
855
  var linksToAllModulesRouteHandler_default = linksToAllModuleRouteHandler;
857
856
 
858
857
  // src/routes/module.ts
859
- import { buildStaticEnvConfig as buildStaticEnvConfig2 } from "@hubspot/cms-components/config";
858
+ import { buildStaticEnvConfig as buildStaticEnvConfig2 } from "@hubspot/cms-components";
860
859
  import path4 from "path";
861
860
  import { normalizePath as normalizePath3 } from "vite";
862
861
 
@@ -1301,9 +1300,7 @@ ${error.error.message}`);
1301
1300
 
1302
1301
  // src/proxyPage/proxyPage.ts
1303
1302
  import {
1304
- buildStaticEnvConfig as buildStaticEnvConfig3
1305
- } from "@hubspot/cms-components/config";
1306
- import {
1303
+ buildStaticEnvConfig as buildStaticEnvConfig3,
1307
1304
  mergeServerRequestData_internal
1308
1305
  } from "@hubspot/cms-components";
1309
1306
  var getEntryPointBasePathFromProxyRequest = (request2) => {
@@ -1967,6 +1964,7 @@ async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy =
1967
1964
  noExternal: "@hubspot/cms-components"
1968
1965
  },
1969
1966
  resolve: {
1967
+ conditions: ["server"],
1970
1968
  dedupe: ["react", "react-dom", "@hubspot/cms-components"]
1971
1969
  },
1972
1970
  optimizeDeps: {
@@ -2116,6 +2114,23 @@ async function fetchWebsiteDomainNames(portalId) {
2116
2114
  return domainNames;
2117
2115
  }
2118
2116
 
2117
+ // src/lib/logColors.ts
2118
+ var CONTROL_CHARACTER = "\x1B";
2119
+ var DEFAULT_SCHEME = "[0m";
2120
+ var ForeGroudANSIColorMap = {
2121
+ black: 30,
2122
+ red: 31,
2123
+ green: 32,
2124
+ yellow: 33,
2125
+ blue: 34,
2126
+ megenta: 35,
2127
+ cyan: 36,
2128
+ white: 37
2129
+ };
2130
+ function wrapMessageInColor(color, message) {
2131
+ return `${CONTROL_CHARACTER}[${ForeGroudANSIColorMap[color]}m${message}${CONTROL_CHARACTER}${DEFAULT_SCHEME}`;
2132
+ }
2133
+
2119
2134
  // src/createDevServer.ts
2120
2135
  var BASE_PATH = "/";
2121
2136
  var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
@@ -2128,6 +2143,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
2128
2143
  let authedPortalId = null;
2129
2144
  let authedEnv = null;
2130
2145
  let jsRenderingGates = [];
2146
+ let personalAccessKey = null;
2131
2147
  if (hubspotCliConfigPathOption2 && hubspotCliAccountNameOption2) {
2132
2148
  console.log(
2133
2149
  `Loading HS auth (account = ${hubspotCliAccountNameOption2}) configuration at: ${hubspotCliConfigPathOption2}`
@@ -2145,12 +2161,26 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
2145
2161
  if (validateConfig()) {
2146
2162
  authedPortalId = getAccountId3(hubspotCliAccountNameOption2);
2147
2163
  authedEnv = getEnv2(hubspotCliAccountNameOption2);
2164
+ personalAccessKey = getAccountConfig(authedPortalId) && getAccountConfig(authedPortalId).personalAccessKey;
2148
2165
  if (!authedPortalId && hubspotCliAccountNameOption2) {
2149
2166
  console.error(
2150
2167
  `Couldn't find ${hubspotCliAccountNameOption2} in your hubspot.config.yaml`
2151
2168
  );
2152
2169
  process.exit(1);
2153
2170
  }
2171
+ if (personalAccessKey) {
2172
+ try {
2173
+ jsRenderingGates = await getJsRenderingGates(
2174
+ authedPortalId,
2175
+ authedEnv,
2176
+ personalAccessKey
2177
+ );
2178
+ } catch (e) {
2179
+ console.warn(
2180
+ `Unable to get gating information. gated features will not be availalbe in the local dev server`
2181
+ );
2182
+ }
2183
+ }
2154
2184
  } else {
2155
2185
  console.warn(
2156
2186
  `Couldn't find an account to use, make sure there is hubspot.config.yaml in this folder (or a parent).
@@ -2159,17 +2189,6 @@ If needed you can refer to another config file with --config.
2159
2189
  Local proxy functionality will not work without setting up authentication.`
2160
2190
  );
2161
2191
  }
2162
- try {
2163
- const { personalAccessKey } = getAccountConfig(authedPortalId);
2164
- jsRenderingGates = await getJsRenderingGates(
2165
- authedPortalId,
2166
- authedEnv,
2167
- personalAccessKey
2168
- );
2169
- } catch (e) {
2170
- console.error(e);
2171
- console.warn("Unable to fetch gating information");
2172
- }
2173
2192
  let domainsToProxy = [];
2174
2193
  if (sslEnabledOption2 && authedPortalId) {
2175
2194
  try {
@@ -2256,7 +2275,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
2256
2275
  );
2257
2276
  if (storybook2) {
2258
2277
  const packageRoot = path6.dirname(url2.fileURLToPath(import.meta.url));
2259
- const configPath = path6.resolve(packageRoot, "./storybook");
2278
+ const configPath = path6.resolve(packageRoot, "./storybook-main");
2260
2279
  const storybookProcess = spawn(
2261
2280
  "npx",
2262
2281
  [
@@ -2273,15 +2292,33 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
2273
2292
  cwd: process.cwd(),
2274
2293
  env: {
2275
2294
  ...process.env,
2295
+ portalId: authedPortalId.toString(),
2296
+ hsEnv: authedEnv,
2297
+ hublet: authedHublet,
2276
2298
  WEB_ROOT: path6.join(webRoot2, "components")
2277
2299
  }
2278
2300
  }
2279
2301
  );
2280
- console.log(`Starting storybook server on port ${STORYBOOK_PORT}`);
2281
- if (debug.enabled) {
2282
- storybookProcess.stdout.pipe(process.stdout);
2283
- }
2284
- storybookProcess.stderr.pipe(process.stderr);
2302
+ console.log(
2303
+ wrapMessageInColor(
2304
+ "yellow",
2305
+ `Starting storybook server on port ${STORYBOOK_PORT}`
2306
+ )
2307
+ );
2308
+ storybookProcess.stdout.pipe(
2309
+ new Transform({
2310
+ transform(chunk, _encoding, callback) {
2311
+ callback(null, wrapMessageInColor("yellow", chunk.toString()));
2312
+ }
2313
+ })
2314
+ ).pipe(process.stdout);
2315
+ storybookProcess.stderr.pipe(
2316
+ new Transform({
2317
+ transform(chunk, _encoding, callback) {
2318
+ callback(null, wrapMessageInColor("red", chunk.toString()));
2319
+ }
2320
+ })
2321
+ ).pipe(process.stderr);
2285
2322
  }
2286
2323
  return {
2287
2324
  close: () => {
@@ -3,17 +3,8 @@ import React, { useEffect } from "react";
3
3
  import { renderToStaticMarkup as renderToStaticMarkup2 } from "react-dom/server";
4
4
 
5
5
  // ../cms-js-internal/dist/index.js
6
- import path, { basename } from "path";
7
- import { createRequire } from "module";
8
- import * as jsxRuntime from "react/jsx-runtime";
9
- import stream from "stream";
10
6
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
11
- import { createServerRenderContextV2, ServerRenderContext } from "@hubspot/cms-components";
12
- import { createHash } from "crypto";
13
- import { existsSync, readdirSync, lstatSync } from "fs";
14
- import { join } from "path/posix";
15
7
  import { cloneElement } from "react";
16
- var require2 = createRequire(import.meta.url);
17
8
  function renderFieldsToJson(fields) {
18
9
  let moduleJson;
19
10
  const outputCallback = (callbackJson) => {
@@ -103,7 +94,7 @@ function getNestedFieldObjectForArgs(_args) {
103
94
  }
104
95
 
105
96
  // src/storybook/moduleStory.tsx
106
- import { jsx as jsx2 } from "react/jsx-runtime";
97
+ import { jsx } from "react/jsx-runtime";
107
98
  function moduleFieldsToJson(fields) {
108
99
  let moduleJson;
109
100
  const outputCallback = (callbackJson) => {
@@ -119,50 +110,74 @@ function moduleFieldsToJson(fields) {
119
110
  }
120
111
  return moduleJson;
121
112
  }
122
- function moduleStory(ModuleComponent, fields) {
113
+ function moduleArgs(argTypes) {
114
+ const args = {};
115
+ for (const argKey in argTypes) {
116
+ if (Object.hasOwnProperty.call(argTypes, argKey)) {
117
+ args[argKey] = argTypes[argKey].defaultValue;
118
+ }
119
+ }
120
+ return args;
121
+ }
122
+ function moduleStory(ModuleComponent, fields, storyArgs) {
123
123
  const moduleJson = renderFieldsToJson(fields);
124
124
  const argTypes = getFieldsArgTypes(moduleJson);
125
- const story = (_args) => /* @__PURE__ */ jsx2(ModuleComponent, { ..._args });
126
- const storyWithArgs = story.bind({});
127
- storyWithArgs.argTypes = argTypes;
128
- storyWithArgs.args = {};
129
- return storyWithArgs;
125
+ const args = { ...moduleArgs(argTypes), ...storyArgs };
126
+ return {
127
+ render: (_args) => {
128
+ const fieldValues = getNestedFieldObjectForArgs(_args);
129
+ return /* @__PURE__ */ jsx(ModuleComponent, { ...fieldValues });
130
+ },
131
+ argTypes,
132
+ args
133
+ };
130
134
  }
131
- function moduleStoryWithIsland(moduleName, fields) {
135
+ function moduleStoryWithIsland(fields, moduleName, storyArgs) {
136
+ if (typeof moduleName !== "string") {
137
+ throw new Error(
138
+ "moduleStoryWithIsland takes Fields JSX as the first argument, and the moduleName that matches the file or folder name for the module as a string for the second parameter"
139
+ );
140
+ }
141
+ if (!moduleName) {
142
+ throw new Error(
143
+ "moduleStoryWithIsland requires a second moduleName parameter that matches the file or folder name for the module"
144
+ );
145
+ }
132
146
  const moduleJson = moduleFieldsToJson(fields);
133
147
  const argTypes = getFieldsArgTypes(moduleJson);
134
- const story = (_args) => {
135
- const fieldValues = getNestedFieldObjectForArgs(_args);
136
- const fieldValuesString = JSON.stringify(fieldValues);
137
- const domain = `${window.location.protocol}//${window.location.hostname.replace("storybook.", "")}:3000`;
138
- const fieldValuesJson = encodeURIComponent(fieldValuesString);
139
- const iframeSrc = `${domain}/module/${moduleName}?fields=${fieldValuesJson}`;
140
- useEffect(() => {
141
- const existingElement = document.querySelector("#hs-module-iframe");
142
- if (existingElement) {
143
- existingElement.setAttribute("src", iframeSrc);
148
+ const args = { ...moduleArgs(argTypes), ...storyArgs };
149
+ return {
150
+ argTypes,
151
+ args,
152
+ render: (_args) => {
153
+ const fieldValues = getNestedFieldObjectForArgs(_args);
154
+ const fieldValuesString = JSON.stringify(fieldValues);
155
+ const domain = `${window.location.protocol}//${window.location.hostname.replace("storybook.", "")}:3000`;
156
+ const fieldValuesJson = encodeURIComponent(fieldValuesString);
157
+ const iframeSrc = `${domain}/module/${moduleName}?fields=${fieldValuesJson}`;
158
+ useEffect(() => {
159
+ const existingElement = document.querySelector("#hs-module-iframe");
160
+ if (existingElement) {
161
+ existingElement.setAttribute("src", iframeSrc);
162
+ return () => {
163
+ existingElement.remove();
164
+ };
165
+ }
166
+ const iframeElement = document.createElement("iframe");
167
+ iframeElement.setAttribute("src", iframeSrc);
168
+ iframeElement.setAttribute("id", "hs-module-iframe");
169
+ iframeElement.setAttribute(
170
+ "style",
171
+ `border: none;width: 100%;height: 100%;overflow: auto;`
172
+ );
173
+ document.querySelector("#storybook-root").appendChild(iframeElement);
144
174
  return () => {
145
- existingElement.remove();
175
+ iframeElement.remove();
146
176
  };
147
- }
148
- const iframeElement = document.createElement("iframe");
149
- iframeElement.setAttribute("src", iframeSrc);
150
- iframeElement.setAttribute("id", "hs-module-iframe");
151
- iframeElement.setAttribute(
152
- "style",
153
- `border: none;width: 100%;height: 100%;overflow: auto;`
154
- );
155
- document.body.appendChild(iframeElement);
156
- return () => {
157
- iframeElement.remove();
158
- };
159
- }, [iframeSrc]);
160
- return /* @__PURE__ */ jsx2("div", {});
177
+ }, [iframeSrc]);
178
+ return /* @__PURE__ */ jsx("div", {});
179
+ }
161
180
  };
162
- const storyWithArgs = story.bind({});
163
- storyWithArgs.argTypes = argTypes;
164
- storyWithArgs.args = {};
165
- return storyWithArgs;
166
181
  }
167
182
  export {
168
183
  moduleFieldsToJson,
@@ -48,13 +48,12 @@ __export(dist_exports, {
48
48
  virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
49
49
  });
50
50
  import path, { basename } from "path";
51
- import { createRequire } from "module";
51
+ import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
52
52
  import * as jsxRuntime from "react/jsx-runtime";
53
53
  import stream from "stream";
54
54
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
55
55
  import { createServerRenderContextV2, ServerRenderContext } from "@hubspot/cms-components";
56
56
  import { createHash } from "crypto";
57
- import { existsSync, readdirSync, lstatSync } from "fs";
58
57
  import { join } from "path/posix";
59
58
  import { cloneElement } from "react";
60
59
  function createPreloadLink(assetPath, basePath = "") {
@@ -100,10 +99,9 @@ function isUngatedFor(gates, gate) {
100
99
  function ungatedAtBuildTimeFor(buildDir, gate) {
101
100
  try {
102
101
  console.log("loading path", path.join(buildDir, BUILD_INFO_PATH));
103
- const buildInfo = require2(path.join(
104
- buildDir,
105
- BUILD_INFO_PATH
106
- ));
102
+ const buildInfo = JSON.parse(
103
+ readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
104
+ );
107
105
  return isUngatedFor(buildInfo.gates, gate);
108
106
  } catch (e) {
109
107
  console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
@@ -295,7 +293,7 @@ function renderFieldsToJson(fields) {
295
293
  );
296
294
  return moduleJson;
297
295
  }
298
- var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, require2, GATES, ENABLED_FEATURES_GATE_MAP, BUILD_INFO_PATH, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, findAllComponentsIn;
296
+ var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, GATES, ENABLED_FEATURES_GATE_MAP, BUILD_INFO_PATH, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, findAllComponentsIn;
299
297
  var init_dist = __esm({
300
298
  "../cms-js-internal/dist/index.js"() {
301
299
  COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
@@ -404,12 +402,12 @@ ${indentString}`);
404
402
  indent
405
403
  )}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
406
404
  };
407
- require2 = createRequire(import.meta.url);
408
405
  GATES = [
409
406
  "CMS:JSRenderer:SharedDeps",
410
407
  "CMS:JSRenderer:GetServerSideProps",
411
408
  "CMS:JSRenderer:LocalProxySchemaVersion1",
412
- "CMS:JSRenderer:GraphQLQueryBuild"
409
+ "CMS:JSRenderer:GraphQLQueryBuild",
410
+ "CMS:JSRenderer:SeparateIslandRenderOption"
413
411
  ];
414
412
  ENABLED_FEATURES_GATE_MAP = {
415
413
  "cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
@@ -418,7 +416,7 @@ ${indentString}`);
418
416
  "cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild"
419
417
  };
420
418
  BUILD_INFO_PATH = "/build-info.json";
421
- clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: `island-${renderableIsland.index}-`,\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
419
+ clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {\n ClientRenderContextProvider,\n buildIslandIdentifierPrefix,\n} from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
422
420
  virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
423
421
  jsx2 = jsxRuntime.jsx;
424
422
  promiseForNewWritableStream = () => {
@@ -439,21 +437,21 @@ ${indentString}`);
439
437
  });
440
438
  return { streamDonePromise, writableStream };
441
439
  };
442
- renderStreamToPromise = async (reactElements, renderOptions = {}) => {
440
+ renderStreamToPromise = async (reactElements, options) => {
443
441
  const { streamDonePromise, writableStream } = promiseForNewWritableStream();
444
442
  const {
445
443
  pipe
446
444
  /* abort */
447
445
  } = renderToPipeableStream(reactElements, {
448
- ...renderOptions,
446
+ ...options || {},
449
447
  onShellReady() {
450
448
  },
451
449
  onAllReady() {
452
450
  pipe(writableStream);
451
+ if (options == null ? void 0 : options.onAllReady) {
452
+ options.onAllReady();
453
+ }
453
454
  }
454
- // We will log the error sent to the writable, any need to do something in these callbacks?
455
- // onShellError(error) {},
456
- // onError(error) {},
457
455
  });
458
456
  return streamDonePromise;
459
457
  };
@@ -540,7 +538,7 @@ ${groupEnd}</script>
540
538
  }
541
539
  });
542
540
 
543
- // src/storybook/main.ts
541
+ // src/storybook-main/main.ts
544
542
  import path2 from "path";
545
543
  import { mergeConfig } from "vite";
546
544
  var webRoot = process.env.WEB_ROOT;
@@ -550,6 +548,24 @@ var main_default = {
550
548
  addons: ["@storybook/addon-essentials"],
551
549
  framework: "@storybook/react-vite",
552
550
  stories: [storyPath],
551
+ previewHead: (head) => {
552
+ return `
553
+ ${head}
554
+
555
+ <script type="module">
556
+ import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
557
+
558
+ initConfigSingletonFromJSON(${JSON.stringify({
559
+ portalId: process.env.portalId,
560
+ hublet: process.env.hublet,
561
+ hsEnv: process.env.hsEnv,
562
+ hsDeployed: false,
563
+ hsJSRGates: jsRenderingGates
564
+ })})
565
+ </script>
566
+
567
+ `;
568
+ },
553
569
  viteFinal: async (config) => {
554
570
  const { resolveIslandPlugin: resolveIslandPlugin2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
555
571
  const viteConfig = {
@@ -0,0 +1,20 @@
1
+ // src/storybook-main/preview.jsx
2
+ import {
3
+ ServerRenderContext,
4
+ createServerRenderContextV2,
5
+ ClientRenderContextProvider
6
+ } from "@hubspot/cms-components";
7
+ import { jsx } from "react/jsx-runtime";
8
+ var parameters = {
9
+ actions: { argTypesRegex: "^on[A-Z].*" }
10
+ };
11
+ var contextValue = createServerRenderContextV2("http://testUrl.com", {
12
+ environmentConfig: null
13
+ });
14
+ var decorators = [
15
+ (Story) => /* @__PURE__ */ jsx(ClientRenderContextProvider, { pageUrl: "http://test.com", islands: [], children: /* @__PURE__ */ jsx(ServerRenderContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(Story, {}) }) })
16
+ ];
17
+ export {
18
+ decorators,
19
+ parameters
20
+ };