@hubspot/cms-dev-server 0.14.5 → 0.14.6
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.
- package/dist/createViteDevServer-5624911d.js +69 -0
- package/dist/index-de34229d.js +525 -0
- package/dist/index-e4860c0f.js +150 -0
- package/dist/index.js +27 -25
- package/dist/index2.js +178 -0
- package/dist/internalSsr.js +370 -299
- package/dist/main.js +52 -0
- package/dist/preview.js +18 -0
- package/dist/run.js +354 -326
- package/dist/storybook/index.js +7 -5
- package/dist/storybook-main/main.js +418 -340
- package/package.json +3 -3
- package/types/island-runtime.d.ts +2 -0
package/dist/internalSsr.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
// ../cms-js-internal/dist/
|
|
2
|
-
import * as dotProp from "dot-prop";
|
|
1
|
+
// ../cms-js-internal/dist/basicUtils.js
|
|
3
2
|
import path from "path";
|
|
4
|
-
import * as jsxRuntime from "react/jsx-runtime";
|
|
5
|
-
import stream from "stream";
|
|
6
|
-
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
7
|
-
import * as cmsComponents from "@hubspot/cms-components";
|
|
8
|
-
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
9
3
|
import { createHash } from "crypto";
|
|
10
|
-
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
4
|
+
import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
11
5
|
import { join } from "path/posix";
|
|
12
|
-
import { isValidElement, cloneElement } from "react";
|
|
13
6
|
var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
14
7
|
var ENTRY_POINTS_PATH = "components/partials/";
|
|
15
8
|
var MODULE_FOLDER_PATH = "components/modules/";
|
|
@@ -97,164 +90,6 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
|
|
|
97
90
|
${indentString}`
|
|
98
91
|
);
|
|
99
92
|
}
|
|
100
|
-
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
101
|
-
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
102
|
-
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
103
|
-
({
|
|
104
|
-
id,
|
|
105
|
-
moduleName,
|
|
106
|
-
moduleId,
|
|
107
|
-
props,
|
|
108
|
-
hydrateOn,
|
|
109
|
-
clientOnly,
|
|
110
|
-
priority,
|
|
111
|
-
url,
|
|
112
|
-
sharedStateID,
|
|
113
|
-
supplementalFieldValues,
|
|
114
|
-
wrapperModuleId,
|
|
115
|
-
wrapperUrl
|
|
116
|
-
}) => {
|
|
117
|
-
const output = {
|
|
118
|
-
id,
|
|
119
|
-
moduleName,
|
|
120
|
-
moduleId,
|
|
121
|
-
hydrateOn,
|
|
122
|
-
clientOnly,
|
|
123
|
-
priority,
|
|
124
|
-
props,
|
|
125
|
-
url
|
|
126
|
-
};
|
|
127
|
-
if (sharedStateID) {
|
|
128
|
-
output.sharedStateID = sharedStateID;
|
|
129
|
-
}
|
|
130
|
-
if (wrapperModuleId) {
|
|
131
|
-
output.wrapperModuleId = wrapperModuleId;
|
|
132
|
-
}
|
|
133
|
-
if (wrapperUrl) {
|
|
134
|
-
output.wrapperUrl = wrapperUrl;
|
|
135
|
-
}
|
|
136
|
-
const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
|
|
137
|
-
supplementalFieldValues,
|
|
138
|
-
perServerRequestData.get("supplementalFieldValuesRead")
|
|
139
|
-
);
|
|
140
|
-
if (filteredSupplementalFieldValues) {
|
|
141
|
-
output.supplementalFieldValues = filteredSupplementalFieldValues;
|
|
142
|
-
}
|
|
143
|
-
return output;
|
|
144
|
-
}
|
|
145
|
-
);
|
|
146
|
-
return jsonStringifyAndEscapeForInlineJS(islandsArrayToSerialize, {
|
|
147
|
-
baseIndent,
|
|
148
|
-
jsonIndent: 2,
|
|
149
|
-
prettyPrint
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
153
|
-
if (!supplementalFieldValues) {
|
|
154
|
-
return supplementalFieldValues;
|
|
155
|
-
}
|
|
156
|
-
if (!supplementalFieldValuesRead) {
|
|
157
|
-
return supplementalFieldValues;
|
|
158
|
-
}
|
|
159
|
-
const result = {};
|
|
160
|
-
Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
|
|
161
|
-
if (hasProperty(supplementalFieldValues, fieldPath)) {
|
|
162
|
-
setProperty(
|
|
163
|
-
result,
|
|
164
|
-
fieldPath,
|
|
165
|
-
getProperty(supplementalFieldValues, fieldPath)
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
return result;
|
|
170
|
-
}
|
|
171
|
-
var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
|
|
172
|
-
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
|
|
173
|
-
if (sharedStateIDs.length > 0) {
|
|
174
|
-
const indentString = " ".repeat(indent);
|
|
175
|
-
const stateByID = {};
|
|
176
|
-
sharedStateIDs.forEach(
|
|
177
|
-
(id) => stateByID[id] = perServerRequestData.get(id)
|
|
178
|
-
);
|
|
179
|
-
const stringifiedState = jsonStringifyAndEscapeForInlineJS(stateByID, {
|
|
180
|
-
prettyPrint,
|
|
181
|
-
jsonIndent: 2
|
|
182
|
-
});
|
|
183
|
-
return `
|
|
184
|
-
|
|
185
|
-
var newState = ${stringifiedState};
|
|
186
|
-
if(window.__hsSSInit) {
|
|
187
|
-
window.__hsSSInit = Object.assign(window.__hsSSInit, newState);
|
|
188
|
-
} else {
|
|
189
|
-
window.__hsSSInit = newState;
|
|
190
|
-
}`.replace(/\n/gm, `
|
|
191
|
-
${indentString}`);
|
|
192
|
-
}
|
|
193
|
-
return "";
|
|
194
|
-
};
|
|
195
|
-
function getIslandUrls(roots, viteDevServer) {
|
|
196
|
-
return roots.map((island) => {
|
|
197
|
-
const islandModule = viteDevServer.moduleGraph.getModuleById(
|
|
198
|
-
island.moduleId
|
|
199
|
-
);
|
|
200
|
-
if (!islandModule) {
|
|
201
|
-
throw new Error(`Unknown island moduleId: ${island.moduleId}`);
|
|
202
|
-
}
|
|
203
|
-
let wrapperModule;
|
|
204
|
-
if (island.wrapperModuleId) {
|
|
205
|
-
wrapperModule = viteDevServer.moduleGraph.getModuleById(
|
|
206
|
-
island.wrapperModuleId
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
const tweakedIsland = {
|
|
210
|
-
...island,
|
|
211
|
-
url: islandModule.url,
|
|
212
|
-
wrapperUrl: wrapperModule ? wrapperModule.url : void 0
|
|
213
|
-
};
|
|
214
|
-
return tweakedIsland;
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
function getPerServerRequestUrls(perServerRequestData, viteDevServer) {
|
|
218
|
-
if (!perServerRequestData.has("sharedStateIDs")) {
|
|
219
|
-
return new Map(perServerRequestData);
|
|
220
|
-
}
|
|
221
|
-
const perServerRequestDataWithUrls = new Map(
|
|
222
|
-
perServerRequestData
|
|
223
|
-
);
|
|
224
|
-
perServerRequestData.get("sharedStateIDs").forEach((id) => {
|
|
225
|
-
const reducer = perServerRequestData.get(id);
|
|
226
|
-
if (reducer.reducerFuncModuleId) {
|
|
227
|
-
const reducerWithUrl = {
|
|
228
|
-
...reducer,
|
|
229
|
-
reducerFuncModuleUrl: viteDevServer.moduleGraph.getModuleById(
|
|
230
|
-
reducer.reducerFuncModuleId
|
|
231
|
-
).url
|
|
232
|
-
};
|
|
233
|
-
perServerRequestDataWithUrls.set(id, reducerWithUrl);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
return perServerRequestDataWithUrls;
|
|
237
|
-
}
|
|
238
|
-
var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent, prettyPrint) => {
|
|
239
|
-
const islands = getIslandUrls(roots, viteDevServer);
|
|
240
|
-
const perServerRequestDataWithUrls = getPerServerRequestUrls(
|
|
241
|
-
perServerRequestData,
|
|
242
|
-
viteDevServer
|
|
243
|
-
);
|
|
244
|
-
return `${" ".repeat(
|
|
245
|
-
indent
|
|
246
|
-
)}window.__islands = ${serializeIslandDataForInlineScript(
|
|
247
|
-
islands,
|
|
248
|
-
perServerRequestData,
|
|
249
|
-
indent,
|
|
250
|
-
prettyPrint
|
|
251
|
-
)}${writeSharedStateToJsGlobal(
|
|
252
|
-
islands,
|
|
253
|
-
perServerRequestDataWithUrls,
|
|
254
|
-
indent,
|
|
255
|
-
prettyPrint
|
|
256
|
-
)}`;
|
|
257
|
-
};
|
|
258
93
|
var viteRoot;
|
|
259
94
|
var viteCommand;
|
|
260
95
|
function resolveIslandPlugin(islandsSet) {
|
|
@@ -293,28 +128,32 @@ function resolveIslandPlugin(islandsSet) {
|
|
|
293
128
|
}
|
|
294
129
|
};
|
|
295
130
|
}
|
|
296
|
-
function
|
|
297
|
-
const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
|
|
131
|
+
function resolveIslandToPlainModulePlugin(enabled = true) {
|
|
298
132
|
return {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
133
|
+
enforce: "pre",
|
|
134
|
+
name: "resolve-islands-to-plain",
|
|
135
|
+
configResolved(config) {
|
|
136
|
+
viteRoot = config.root;
|
|
137
|
+
viteCommand = config.command;
|
|
303
138
|
},
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
139
|
+
async resolveId(id, importer, options) {
|
|
140
|
+
if (enabled && (id.endsWith("?island") || id.endsWith("?client"))) {
|
|
141
|
+
const newId = id.replace("?island", "").replace("?client", "");
|
|
142
|
+
const resolution = await this.resolve(newId, importer, {
|
|
143
|
+
skipSelf: true,
|
|
144
|
+
...options
|
|
145
|
+
});
|
|
146
|
+
if (resolution) {
|
|
147
|
+
return resolution;
|
|
311
148
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
return html.replace(regex, replacer);
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
315
151
|
}
|
|
316
152
|
};
|
|
317
153
|
}
|
|
154
|
+
function resolveIslandToPlainModuleNoopPlugin() {
|
|
155
|
+
return resolveIslandToPlainModulePlugin(false);
|
|
156
|
+
}
|
|
318
157
|
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\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 let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\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 {innerComponent}\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";
|
|
319
158
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
320
159
|
function clientIslandEntryPlugin() {
|
|
@@ -348,43 +187,6 @@ function clientIslandEntryPlugin() {
|
|
|
348
187
|
}
|
|
349
188
|
};
|
|
350
189
|
}
|
|
351
|
-
var jsx2 = jsxRuntime.jsx;
|
|
352
|
-
var promiseForNewWritableStream = () => {
|
|
353
|
-
const chunks = [];
|
|
354
|
-
const writableStream = new stream.Writable();
|
|
355
|
-
writableStream._write = (chunk, encoding, done) => {
|
|
356
|
-
chunks.push(Buffer.from(chunk));
|
|
357
|
-
done();
|
|
358
|
-
};
|
|
359
|
-
const streamDonePromise = new Promise((resolve, reject) => {
|
|
360
|
-
writableStream.on("error", (error) => {
|
|
361
|
-
reject(error);
|
|
362
|
-
});
|
|
363
|
-
writableStream._final = (done) => {
|
|
364
|
-
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
365
|
-
done();
|
|
366
|
-
};
|
|
367
|
-
});
|
|
368
|
-
return { streamDonePromise, writableStream };
|
|
369
|
-
};
|
|
370
|
-
var renderStreamToPromise = async (reactElements, options) => {
|
|
371
|
-
const { streamDonePromise, writableStream } = promiseForNewWritableStream();
|
|
372
|
-
const {
|
|
373
|
-
pipe
|
|
374
|
-
/* abort */
|
|
375
|
-
} = renderToPipeableStream(reactElements, {
|
|
376
|
-
...options || {},
|
|
377
|
-
onShellReady() {
|
|
378
|
-
},
|
|
379
|
-
onAllReady() {
|
|
380
|
-
pipe(writableStream);
|
|
381
|
-
if (options == null ? void 0 : options.onAllReady) {
|
|
382
|
-
options.onAllReady();
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
return streamDonePromise;
|
|
387
|
-
};
|
|
388
190
|
var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
|
|
389
191
|
if (!messagesForBrowser) {
|
|
390
192
|
return "";
|
|
@@ -414,40 +216,9 @@ ${consoleLines.join("\n")}
|
|
|
414
216
|
${groupEnd}</script>
|
|
415
217
|
`;
|
|
416
218
|
};
|
|
417
|
-
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
/* @__PURE__ */ jsx2(Component, { ...props }),
|
|
421
|
-
pageUrl,
|
|
422
|
-
environmentConfig,
|
|
423
|
-
entryPointBasePath,
|
|
424
|
-
contextOptions,
|
|
425
|
-
componentDebugName,
|
|
426
|
-
renderOptions
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
|
|
430
|
-
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
431
|
-
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
432
|
-
environmentConfig,
|
|
433
|
-
entryPointBasePath,
|
|
434
|
-
supplementalFieldValues
|
|
435
|
-
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
436
|
-
let html = await renderStreamToPromise(
|
|
437
|
-
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
438
|
-
renderOptions
|
|
439
|
-
);
|
|
440
|
-
if (renderContext.messagesForBrowser.length > 0) {
|
|
441
|
-
html = `${html}${scriptTagToLogServerMessages(
|
|
442
|
-
renderContext.messagesForBrowser,
|
|
443
|
-
`Server messages rendering: ${debugName}`
|
|
444
|
-
)}`;
|
|
445
|
-
}
|
|
446
|
-
return { html, renderContext };
|
|
447
|
-
}
|
|
448
|
-
var getComponentExtension = (componentPath) => {
|
|
449
|
-
const filteredExtensions = COMPONENT_EXTENSIONS.filter(
|
|
450
|
-
(ext) => componentPath.endsWith(ext)
|
|
219
|
+
var getComponentExtension = (componentPath) => {
|
|
220
|
+
const filteredExtensions = COMPONENT_EXTENSIONS.filter(
|
|
221
|
+
(ext) => componentPath.endsWith(ext)
|
|
451
222
|
);
|
|
452
223
|
if (filteredExtensions.length === 1) {
|
|
453
224
|
return filteredExtensions[0];
|
|
@@ -490,6 +261,40 @@ function includesHublDataReference(templateSource) {
|
|
|
490
261
|
const hublDataPattern = /\{%\s+set\s+(experimentalHublData|hublData)\s*=/;
|
|
491
262
|
return !!templateSource.match(hublDataPattern);
|
|
492
263
|
}
|
|
264
|
+
var removeIndexFromPath = (id) => {
|
|
265
|
+
return id.replace(/\/index\.[jt]sx?$/, "");
|
|
266
|
+
};
|
|
267
|
+
var removeIndexOrTrailingJsFromPath = (id) => {
|
|
268
|
+
return removeIndexFromPath(id).replace(/\.[jt]sx?$/, "");
|
|
269
|
+
};
|
|
270
|
+
var HEALTHCHECKS_ENABLED_DEFAULT = true;
|
|
271
|
+
var HEALTHCHECKS_STRICT_DEFAULT = false;
|
|
272
|
+
function getCMSAssetConfig(webRoot) {
|
|
273
|
+
const cmsAssetsPath = path.join(webRoot, "cms-assets.json");
|
|
274
|
+
return JSON.parse(fs.readFileSync(cmsAssetsPath).toString());
|
|
275
|
+
}
|
|
276
|
+
function getCMSAssetConfigIfExists(webRoot) {
|
|
277
|
+
try {
|
|
278
|
+
return getCMSAssetConfig(webRoot);
|
|
279
|
+
} catch (e) {
|
|
280
|
+
console.error(
|
|
281
|
+
`Error finding or parsing cms-assets.json in ${webRoot}, but ignoring for now`
|
|
282
|
+
);
|
|
283
|
+
return {};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function areBuildHealthChecksEnabled(config) {
|
|
287
|
+
var _a, _b;
|
|
288
|
+
return ((_b = (_a = config.buildConfig) == null ? void 0 : _a.healthchecks) == null ? void 0 : _b.enabled) ?? HEALTHCHECKS_ENABLED_DEFAULT;
|
|
289
|
+
}
|
|
290
|
+
function doHealthChecksFailTheBuild(config) {
|
|
291
|
+
var _a, _b;
|
|
292
|
+
return ((_b = (_a = config.buildConfig) == null ? void 0 : _a.healthchecks) == null ? void 0 : _b.strict) ?? HEALTHCHECKS_STRICT_DEFAULT;
|
|
293
|
+
}
|
|
294
|
+
function getServerIncludePrebundleDepPatterns(config) {
|
|
295
|
+
var _a, _b;
|
|
296
|
+
return ((_b = (_a = config.buildConfig) == null ? void 0 : _a.serverPrebundling) == null ? void 0 : _b.include) ?? [];
|
|
297
|
+
}
|
|
493
298
|
var GATES = [
|
|
494
299
|
"CMS:JSRenderer:GetServerSideProps",
|
|
495
300
|
"CMS:JSRenderer:ModuleHubl",
|
|
@@ -571,48 +376,6 @@ function findAllPartialsInRoot(webRoot) {
|
|
|
571
376
|
const partialSubpaths = Object.keys(allPartialComponents);
|
|
572
377
|
return { partialNames, partialSubpaths };
|
|
573
378
|
}
|
|
574
|
-
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
575
|
-
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
576
|
-
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
577
|
-
}
|
|
578
|
-
const serializedJson = jsonStringifyAndEscapeForInlineJS(
|
|
579
|
-
environmentConfig.toJSON(),
|
|
580
|
-
{ baseIndent: 6, prettyPrint }
|
|
581
|
-
);
|
|
582
|
-
const globals = [`window.__hsEnvConfig = ${serializedJson};`];
|
|
583
|
-
if (hsServerPageUrl) {
|
|
584
|
-
globals.push(
|
|
585
|
-
`window.__hsServerPageUrl = ${jsonStringifyAndEscapeForInlineJS(
|
|
586
|
-
hsServerPageUrl
|
|
587
|
-
)};`
|
|
588
|
-
);
|
|
589
|
-
}
|
|
590
|
-
if (hsBasePath) {
|
|
591
|
-
globals.push(
|
|
592
|
-
`window.__hsBasePath = ${jsonStringifyAndEscapeForInlineJS(hsBasePath)};`
|
|
593
|
-
);
|
|
594
|
-
}
|
|
595
|
-
if (!environmentConfig.getIsDeployed() && (criticalDevErrors == null ? void 0 : criticalDevErrors.length)) {
|
|
596
|
-
const firstCriticalDevError = criticalDevErrors[0];
|
|
597
|
-
globals.push(`
|
|
598
|
-
customElements.whenDefined('vite-error-overlay').then(() => {
|
|
599
|
-
const ErrorOverlay = customElements.get('vite-error-overlay');
|
|
600
|
-
const error = new Error(${jsonStringifyAndEscapeForInlineJS(
|
|
601
|
-
firstCriticalDevError.message
|
|
602
|
-
)});
|
|
603
|
-
const overlay = new ErrorOverlay(error);
|
|
604
|
-
|
|
605
|
-
document.body.appendChild(overlay);
|
|
606
|
-
})
|
|
607
|
-
`);
|
|
608
|
-
}
|
|
609
|
-
const nonceAttr = includeNonces && cmsComponents.STYLE_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.STYLE_NONCE_PLACEHOLDER}"` : "";
|
|
610
|
-
return `
|
|
611
|
-
<script type="text/javascript"${nonceAttr}>
|
|
612
|
-
${globals.join("\n ")}
|
|
613
|
-
</script>
|
|
614
|
-
`;
|
|
615
|
-
}
|
|
616
379
|
function namespaceModulePropsShape(props) {
|
|
617
380
|
const {
|
|
618
381
|
dataQueryResult,
|
|
@@ -662,6 +425,308 @@ function setIn(object, nestedKeysArray, value) {
|
|
|
662
425
|
curr[finalKey] = value;
|
|
663
426
|
}
|
|
664
427
|
}
|
|
428
|
+
function isStylesheetAsset(staticAsset) {
|
|
429
|
+
return staticAsset.type === "stylesheet";
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// ../cms-js-internal/dist/index.js
|
|
433
|
+
import * as dotProp from "dot-prop";
|
|
434
|
+
import * as jsxRuntime from "react/jsx-runtime";
|
|
435
|
+
import stream from "stream";
|
|
436
|
+
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
437
|
+
import * as cmsComponents from "@hubspot/cms-components";
|
|
438
|
+
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
439
|
+
import { isValidElement, cloneElement } from "react";
|
|
440
|
+
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
441
|
+
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
442
|
+
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
443
|
+
({
|
|
444
|
+
id,
|
|
445
|
+
moduleName,
|
|
446
|
+
moduleId,
|
|
447
|
+
props,
|
|
448
|
+
hydrateOn,
|
|
449
|
+
clientOnly,
|
|
450
|
+
priority,
|
|
451
|
+
url,
|
|
452
|
+
sharedStateID,
|
|
453
|
+
supplementalFieldValues,
|
|
454
|
+
wrapperModuleId,
|
|
455
|
+
wrapperUrl
|
|
456
|
+
}) => {
|
|
457
|
+
const output = {
|
|
458
|
+
id,
|
|
459
|
+
moduleName,
|
|
460
|
+
moduleId,
|
|
461
|
+
hydrateOn,
|
|
462
|
+
clientOnly,
|
|
463
|
+
priority,
|
|
464
|
+
props,
|
|
465
|
+
url
|
|
466
|
+
};
|
|
467
|
+
if (sharedStateID) {
|
|
468
|
+
output.sharedStateID = sharedStateID;
|
|
469
|
+
}
|
|
470
|
+
if (wrapperModuleId) {
|
|
471
|
+
output.wrapperModuleId = wrapperModuleId;
|
|
472
|
+
}
|
|
473
|
+
if (wrapperUrl) {
|
|
474
|
+
output.wrapperUrl = wrapperUrl;
|
|
475
|
+
}
|
|
476
|
+
const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
|
|
477
|
+
supplementalFieldValues,
|
|
478
|
+
perServerRequestData.get("supplementalFieldValuesRead")
|
|
479
|
+
);
|
|
480
|
+
if (filteredSupplementalFieldValues) {
|
|
481
|
+
output.supplementalFieldValues = filteredSupplementalFieldValues;
|
|
482
|
+
}
|
|
483
|
+
return output;
|
|
484
|
+
}
|
|
485
|
+
);
|
|
486
|
+
return jsonStringifyAndEscapeForInlineJS(islandsArrayToSerialize, {
|
|
487
|
+
baseIndent,
|
|
488
|
+
jsonIndent: 2,
|
|
489
|
+
prettyPrint
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
493
|
+
if (!supplementalFieldValues) {
|
|
494
|
+
return supplementalFieldValues;
|
|
495
|
+
}
|
|
496
|
+
if (!supplementalFieldValuesRead) {
|
|
497
|
+
return supplementalFieldValues;
|
|
498
|
+
}
|
|
499
|
+
const result = {};
|
|
500
|
+
Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
|
|
501
|
+
if (hasProperty(supplementalFieldValues, fieldPath)) {
|
|
502
|
+
setProperty(
|
|
503
|
+
result,
|
|
504
|
+
fieldPath,
|
|
505
|
+
getProperty(supplementalFieldValues, fieldPath)
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
return result;
|
|
510
|
+
}
|
|
511
|
+
var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
|
|
512
|
+
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
|
|
513
|
+
if (sharedStateIDs.length > 0) {
|
|
514
|
+
const indentString = " ".repeat(indent);
|
|
515
|
+
const stateByID = {};
|
|
516
|
+
sharedStateIDs.forEach(
|
|
517
|
+
(id) => stateByID[id] = perServerRequestData.get(id)
|
|
518
|
+
);
|
|
519
|
+
const stringifiedState = jsonStringifyAndEscapeForInlineJS(stateByID, {
|
|
520
|
+
prettyPrint,
|
|
521
|
+
jsonIndent: 2
|
|
522
|
+
});
|
|
523
|
+
return `
|
|
524
|
+
|
|
525
|
+
var newState = ${stringifiedState};
|
|
526
|
+
if(window.__hsSSInit) {
|
|
527
|
+
window.__hsSSInit = Object.assign(window.__hsSSInit, newState);
|
|
528
|
+
} else {
|
|
529
|
+
window.__hsSSInit = newState;
|
|
530
|
+
}`.replace(/\n/gm, `
|
|
531
|
+
${indentString}`);
|
|
532
|
+
}
|
|
533
|
+
return "";
|
|
534
|
+
};
|
|
535
|
+
function getIslandUrls(roots, viteDevServer) {
|
|
536
|
+
return roots.map((island) => {
|
|
537
|
+
const islandModule = viteDevServer.moduleGraph.getModuleById(
|
|
538
|
+
island.moduleId
|
|
539
|
+
);
|
|
540
|
+
if (!islandModule) {
|
|
541
|
+
throw new Error(`Unknown island moduleId: ${island.moduleId}`);
|
|
542
|
+
}
|
|
543
|
+
let wrapperModule;
|
|
544
|
+
if (island.wrapperModuleId) {
|
|
545
|
+
wrapperModule = viteDevServer.moduleGraph.getModuleById(
|
|
546
|
+
island.wrapperModuleId
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
const tweakedIsland = {
|
|
550
|
+
...island,
|
|
551
|
+
url: islandModule.url,
|
|
552
|
+
wrapperUrl: wrapperModule ? wrapperModule.url : void 0
|
|
553
|
+
};
|
|
554
|
+
return tweakedIsland;
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
function getPerServerRequestUrls(perServerRequestData, viteDevServer) {
|
|
558
|
+
if (!perServerRequestData.has("sharedStateIDs")) {
|
|
559
|
+
return new Map(perServerRequestData);
|
|
560
|
+
}
|
|
561
|
+
const perServerRequestDataWithUrls = new Map(
|
|
562
|
+
perServerRequestData
|
|
563
|
+
);
|
|
564
|
+
perServerRequestData.get("sharedStateIDs").forEach((id) => {
|
|
565
|
+
const reducer = perServerRequestData.get(id);
|
|
566
|
+
if (reducer.reducerFuncModuleId) {
|
|
567
|
+
const reducerWithUrl = {
|
|
568
|
+
...reducer,
|
|
569
|
+
reducerFuncModuleUrl: viteDevServer.moduleGraph.getModuleById(
|
|
570
|
+
reducer.reducerFuncModuleId
|
|
571
|
+
).url
|
|
572
|
+
};
|
|
573
|
+
perServerRequestDataWithUrls.set(id, reducerWithUrl);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
return perServerRequestDataWithUrls;
|
|
577
|
+
}
|
|
578
|
+
var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent, prettyPrint) => {
|
|
579
|
+
const islands = getIslandUrls(roots, viteDevServer);
|
|
580
|
+
const perServerRequestDataWithUrls = getPerServerRequestUrls(
|
|
581
|
+
perServerRequestData,
|
|
582
|
+
viteDevServer
|
|
583
|
+
);
|
|
584
|
+
return `${" ".repeat(
|
|
585
|
+
indent
|
|
586
|
+
)}window.__islands = ${serializeIslandDataForInlineScript(
|
|
587
|
+
islands,
|
|
588
|
+
perServerRequestData,
|
|
589
|
+
indent,
|
|
590
|
+
prettyPrint
|
|
591
|
+
)}${writeSharedStateToJsGlobal(
|
|
592
|
+
islands,
|
|
593
|
+
perServerRequestDataWithUrls,
|
|
594
|
+
indent,
|
|
595
|
+
prettyPrint
|
|
596
|
+
)}`;
|
|
597
|
+
};
|
|
598
|
+
function noncePlaceholderPlugin() {
|
|
599
|
+
const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
|
|
600
|
+
return {
|
|
601
|
+
name: "hs-nonce-placeholder",
|
|
602
|
+
enforce: "post",
|
|
603
|
+
apply() {
|
|
604
|
+
return HS_DEPLOYED;
|
|
605
|
+
},
|
|
606
|
+
transformIndexHtml(html) {
|
|
607
|
+
const regex = /<(style|script|link) (.*)>/gi;
|
|
608
|
+
const replacer = (_, p1, p2) => {
|
|
609
|
+
if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
|
|
610
|
+
p1 === "link" && p2.includes('rel="stylesheet"')) {
|
|
611
|
+
const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
|
|
612
|
+
p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
|
|
613
|
+
}
|
|
614
|
+
return `<${p1} ${p2}>`;
|
|
615
|
+
};
|
|
616
|
+
return html.replace(regex, replacer);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
var jsx2 = jsxRuntime.jsx;
|
|
621
|
+
var promiseForNewWritableStream = () => {
|
|
622
|
+
const chunks = [];
|
|
623
|
+
const writableStream = new stream.Writable();
|
|
624
|
+
writableStream._write = (chunk, encoding, done) => {
|
|
625
|
+
chunks.push(Buffer.from(chunk));
|
|
626
|
+
done();
|
|
627
|
+
};
|
|
628
|
+
const streamDonePromise = new Promise((resolve, reject) => {
|
|
629
|
+
writableStream.on("error", (error) => {
|
|
630
|
+
reject(error);
|
|
631
|
+
});
|
|
632
|
+
writableStream._final = (done) => {
|
|
633
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
634
|
+
done();
|
|
635
|
+
};
|
|
636
|
+
});
|
|
637
|
+
return { streamDonePromise, writableStream };
|
|
638
|
+
};
|
|
639
|
+
var renderStreamToPromise = async (reactElements, options) => {
|
|
640
|
+
const { streamDonePromise, writableStream } = promiseForNewWritableStream();
|
|
641
|
+
const {
|
|
642
|
+
pipe
|
|
643
|
+
/* abort */
|
|
644
|
+
} = renderToPipeableStream(reactElements, {
|
|
645
|
+
...options || {},
|
|
646
|
+
onShellReady() {
|
|
647
|
+
},
|
|
648
|
+
onAllReady() {
|
|
649
|
+
pipe(writableStream);
|
|
650
|
+
if (options == null ? void 0 : options.onAllReady) {
|
|
651
|
+
options.onAllReady();
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
return streamDonePromise;
|
|
656
|
+
};
|
|
657
|
+
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, contextOptions, renderOptions) {
|
|
658
|
+
const componentDebugName = Component.displayName || Component.name;
|
|
659
|
+
return renderOnServer(
|
|
660
|
+
/* @__PURE__ */ jsx2(Component, { ...props }),
|
|
661
|
+
pageUrl,
|
|
662
|
+
environmentConfig,
|
|
663
|
+
entryPointBasePath,
|
|
664
|
+
contextOptions,
|
|
665
|
+
componentDebugName,
|
|
666
|
+
renderOptions
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
|
|
670
|
+
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
671
|
+
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
672
|
+
environmentConfig,
|
|
673
|
+
entryPointBasePath,
|
|
674
|
+
supplementalFieldValues
|
|
675
|
+
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
676
|
+
let html = await renderStreamToPromise(
|
|
677
|
+
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
678
|
+
renderOptions
|
|
679
|
+
);
|
|
680
|
+
if (renderContext.messagesForBrowser.length > 0) {
|
|
681
|
+
html = `${html}${scriptTagToLogServerMessages(
|
|
682
|
+
renderContext.messagesForBrowser,
|
|
683
|
+
`Server messages rendering: ${debugName}`
|
|
684
|
+
)}`;
|
|
685
|
+
}
|
|
686
|
+
return { html, renderContext };
|
|
687
|
+
}
|
|
688
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
689
|
+
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
690
|
+
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
691
|
+
}
|
|
692
|
+
const serializedJson = jsonStringifyAndEscapeForInlineJS(
|
|
693
|
+
environmentConfig.toJSON(),
|
|
694
|
+
{ baseIndent: 6, prettyPrint }
|
|
695
|
+
);
|
|
696
|
+
const globals = [`window.__hsEnvConfig = ${serializedJson};`];
|
|
697
|
+
if (hsServerPageUrl) {
|
|
698
|
+
globals.push(
|
|
699
|
+
`window.__hsServerPageUrl = ${jsonStringifyAndEscapeForInlineJS(
|
|
700
|
+
hsServerPageUrl
|
|
701
|
+
)};`
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
if (hsBasePath) {
|
|
705
|
+
globals.push(
|
|
706
|
+
`window.__hsBasePath = ${jsonStringifyAndEscapeForInlineJS(hsBasePath)};`
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
if (!environmentConfig.getIsDeployed() && (criticalDevErrors == null ? void 0 : criticalDevErrors.length)) {
|
|
710
|
+
const firstCriticalDevError = criticalDevErrors[0];
|
|
711
|
+
globals.push(`
|
|
712
|
+
customElements.whenDefined('vite-error-overlay').then(() => {
|
|
713
|
+
const ErrorOverlay = customElements.get('vite-error-overlay');
|
|
714
|
+
const error = new Error(${jsonStringifyAndEscapeForInlineJS(
|
|
715
|
+
firstCriticalDevError.message
|
|
716
|
+
)});
|
|
717
|
+
const overlay = new ErrorOverlay(error);
|
|
718
|
+
|
|
719
|
+
document.body.appendChild(overlay);
|
|
720
|
+
})
|
|
721
|
+
`);
|
|
722
|
+
}
|
|
723
|
+
const nonceAttr = includeNonces && cmsComponents.STYLE_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.STYLE_NONCE_PLACEHOLDER}"` : "";
|
|
724
|
+
return `
|
|
725
|
+
<script type="text/javascript"${nonceAttr}>
|
|
726
|
+
${globals.join("\n ")}
|
|
727
|
+
</script>
|
|
728
|
+
`;
|
|
729
|
+
}
|
|
665
730
|
function renderFieldsJSX(fieldsJSX) {
|
|
666
731
|
let moduleJson;
|
|
667
732
|
const outputCallback = (callbackJson) => {
|
|
@@ -695,9 +760,6 @@ function renderFieldsToJson(fields, moduleName) {
|
|
|
695
760
|
throw e;
|
|
696
761
|
}
|
|
697
762
|
}
|
|
698
|
-
function isStylesheetAsset(staticAsset) {
|
|
699
|
-
return staticAsset.type === "stylesheet";
|
|
700
|
-
}
|
|
701
763
|
export {
|
|
702
764
|
COMPONENT_EXTENSIONS,
|
|
703
765
|
CSS_LANGS_RE,
|
|
@@ -707,14 +769,18 @@ export {
|
|
|
707
769
|
MODULE_FOLDER_PATH,
|
|
708
770
|
VIRTUAL_CONFIG_SETUP,
|
|
709
771
|
VIRTUAL_ISLAND_RUNTIME,
|
|
772
|
+
areBuildHealthChecksEnabled,
|
|
710
773
|
clientIslandEntryPlugin,
|
|
711
774
|
collectCssInDev,
|
|
712
775
|
collectCssModules,
|
|
713
776
|
createIslandsGlobalJsForClientInDev,
|
|
777
|
+
doHealthChecksFailTheBuild,
|
|
714
778
|
escapeForInlineJS,
|
|
715
779
|
findAllComponentsIn,
|
|
716
780
|
findAllModulesInRoot,
|
|
717
781
|
findAllPartialsInRoot,
|
|
782
|
+
getCMSAssetConfig,
|
|
783
|
+
getCMSAssetConfigIfExists,
|
|
718
784
|
getCombinedReactUrl,
|
|
719
785
|
getComponentExtension,
|
|
720
786
|
getEntryPointHash,
|
|
@@ -722,6 +788,7 @@ export {
|
|
|
722
788
|
getIslandRuntimeConfigUrl,
|
|
723
789
|
getIslandUrls,
|
|
724
790
|
getServerGlobalsToInject,
|
|
791
|
+
getServerIncludePrebundleDepPatterns,
|
|
725
792
|
hasComponentExtension,
|
|
726
793
|
includesHublDataReference,
|
|
727
794
|
isStorybookStory,
|
|
@@ -731,11 +798,15 @@ export {
|
|
|
731
798
|
namespaceModulePropsShape,
|
|
732
799
|
noncePlaceholderPlugin,
|
|
733
800
|
removeComponentExtension,
|
|
801
|
+
removeIndexFromPath,
|
|
802
|
+
removeIndexOrTrailingJsFromPath,
|
|
734
803
|
renderComponentOnServer,
|
|
735
804
|
renderFieldsToJson,
|
|
736
805
|
renderOnServer,
|
|
737
806
|
renderStreamToPromise,
|
|
738
807
|
resolveIslandPlugin,
|
|
808
|
+
resolveIslandToPlainModuleNoopPlugin,
|
|
809
|
+
resolveIslandToPlainModulePlugin,
|
|
739
810
|
scriptTagToLogServerMessages,
|
|
740
811
|
serializeIslandDataForInlineScript,
|
|
741
812
|
setIn,
|