@hubspot/cms-dev-server 1.1.0-prerelease.9 → 1.2.0
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/app/assets/LexendDeca-Bold-B8uERmr8.woff2 +0 -0
- package/dist/app/assets/LexendDeca-Light-BtcvwT5C.woff2 +0 -0
- package/dist/app/assets/LexendDeca-Medium-CxVPR2j6.woff2 +0 -0
- package/dist/app/assets/LexendDeca-SemiBold-BhzS3XUP.woff2 +0 -0
- package/dist/app/assets/index-PcyCbkys.css +1 -0
- package/dist/app/assets/index-tvg7JxpD.js +164 -0
- package/dist/app/index.html +15 -0
- package/dist/app/server/assets/RenderTreeSeparately-T6CL43QJ-D50VfKo0.js +111 -0
- package/dist/app/server/serverEntry.js +3641 -0
- package/dist/generateJsonFromJsx.js +744 -0
- package/dist/html/baseTemplate.html +1 -0
- package/dist/index.js +5800 -0
- package/dist/internalSsr.js +1312 -0
- package/dist/island-runtime.js +267 -0
- package/dist/run.js +6495 -4
- package/dist/storybook/index.js +241 -0
- package/dist/storybook-main/main.js +1457 -0
- package/dist/storybook-main/preview.js +21 -0
- package/package.json +93 -24
- package/types/api/designmanager.d.ts +44 -0
- package/types/api/project.d.ts +5 -0
- package/types/api/session.d.ts +2 -0
- package/types/components/HubLModulesList.d.ts +4 -0
- package/types/components/HubLTemplatesList.d.ts +5 -0
- package/types/components/ModulesList.d.ts +5 -0
- package/types/components/PartialsList.d.ts +4 -0
- package/types/createAppServer.d.ts +3 -0
- package/types/createDevServer.d.ts +5 -0
- package/types/createViteDevServer.d.ts +6 -0
- package/types/fileManager.d.ts +4 -0
- package/types/index.d.ts +2 -0
- package/types/lib/cliUtils.d.ts +15 -0
- package/types/lib/configHelpers.d.ts +2 -0
- package/types/lib/criticalDevErrorsToServerMessages.d.ts +4 -0
- package/types/lib/debug.d.ts +1 -0
- package/types/lib/errors.d.ts +6 -0
- package/types/lib/fetchModuleGraphQLData.d.ts +24 -0
- package/types/lib/fullOriginalUrlFromRequest.d.ts +2 -0
- package/types/lib/gates.d.ts +2 -0
- package/types/lib/getDevServerUIData.d.ts +60 -0
- package/types/lib/getFieldValuesForModule.d.ts +2 -0
- package/types/lib/getJSRenderingGates.d.ts +8 -0
- package/types/lib/httpsRedirectingServer.d.ts +11 -0
- package/types/lib/logColors.d.ts +6 -0
- package/types/lib/moduleGraph.d.ts +1 -0
- package/types/lib/packagePath.d.ts +1 -0
- package/types/lib/pathHelpers.d.ts +3 -0
- package/types/lib/previewUtils.d.ts +22 -0
- package/types/lib/proxyHelpers.d.ts +29 -0
- package/types/lib/renderComponentWithCSS.d.ts +14 -0
- package/types/lib/renderHelpers.d.ts +1 -0
- package/types/lib/renderModule.d.ts +11 -0
- package/types/lib/renderModuleFieldsJson.d.ts +4 -0
- package/types/lib/renderModulePreview.d.ts +6 -0
- package/types/lib/renderPartial.d.ts +5 -0
- package/types/lib/templates.d.ts +4 -0
- package/types/lib/trackUsage.d.ts +3 -0
- package/types/lib/validateHSPlatform.d.ts +3 -0
- package/types/lib/watchFieldsUpdates.d.ts +22 -0
- package/types/plugins/cmsComponentsShimPlugin.d.ts +11 -0
- package/types/plugins/devSecretsPlugin.d.ts +2 -0
- package/types/plugins/hsStaticAssetPlugin.d.ts +2 -0
- package/types/proxyPage/constants.d.ts +1 -0
- package/types/proxyPage/fetchContentMetadata.d.ts +7 -0
- package/types/proxyPage/fetchDomains.d.ts +9 -0
- package/types/proxyPage/fetchPreviewInfo.d.ts +7 -0
- package/types/proxyPage/proxyPage.d.ts +11 -0
- package/types/proxyPage/renderLocalError.d.ts +2 -0
- package/types/proxyPage/utils.d.ts +4 -0
- package/types/routes/appServerRouteHandler.d.ts +3 -0
- package/types/routes/createAppServerAPIRoutes.d.ts +5 -0
- package/types/routes/createDevServerRoutes.d.ts +4 -0
- package/types/routes/hublModuleRouteHandler.d.ts +2 -0
- package/types/routes/hublTemplateRouteHandler.d.ts +2 -0
- package/types/routes/legacyRouteHandler.d.ts +3 -0
- package/types/routes/linksToAllModulesRouteHandler.d.ts +2 -0
- package/types/routes/linksToAllPartialsRouteHandler.d.ts +2 -0
- package/types/routes/module.d.ts +3 -0
- package/types/routes/moduleFieldsJson.d.ts +3 -0
- package/types/routes/modulePreviewRouteHandler.d.ts +3 -0
- package/types/routes/partial.d.ts +2 -0
- package/types/routes/proxyPageResourceRedirect.d.ts +2 -0
- package/types/routes/proxyPageRouteHandler.d.ts +2 -0
- package/types/routes/proxyPathPageResourceRedirect.d.ts +2 -0
- package/types/routes/proxyPathPageRouteHandler.d.ts +2 -0
- package/types/routes/proxyServerlessHandler.d.ts +2 -0
- package/types/routes/remoteFsDirtyHandler.d.ts +2 -0
- package/types/shadowDevServer/createShadowDevServerRoutes.d.ts +1 -0
- package/types/shadowDevServer/startShadowDevServer.d.ts +1 -0
- package/types/storybook/getFieldsArgTypes.d.ts +3 -0
- package/types/storybook/getNestedFieldObjectForArgs.d.ts +6 -0
- package/types/storybook/index.d.ts +1 -0
- package/types/storybook/moduleStory.d.ts +5 -0
- package/types/storybook/types.d.ts +15 -0
- package/dist/components/ModulesList.js +0 -14
- package/dist/components/PartialsList.js +0 -13
- package/dist/createDevServer.js +0 -26
- package/dist/createViteDevServer.js +0 -26
- package/dist/lib/createIslandsGlobalJsForClientInDev.js +0 -32
- package/dist/lib/fullOriginalUrlFromRequest.js +0 -3
- package/dist/lib/htmlHelpers.js +0 -10
- package/dist/lib/moduleGraph.js +0 -11
- package/dist/lib/proxyHelpers.js +0 -69
- package/dist/lib/proxyHelpers.test.js +0 -136
- package/dist/lib/renderComponentWithCSS.js +0 -26
- package/dist/lib/renderHelpers.js +0 -45
- package/dist/lib/renderModule.js +0 -88
- package/dist/lib/renderPartial.js +0 -12
- package/dist/lib/templates.js +0 -48
- package/dist/lib/traverseFieldsJson.js +0 -78
- package/dist/proxyPage/constants.js +0 -4
- package/dist/proxyPage/fetchContentMetadata.js +0 -51
- package/dist/proxyPage/fetchPreviewInfo.js +0 -37
- package/dist/proxyPage/proxyPage.js +0 -167
- package/dist/proxyPage/renderLocalError.js +0 -27
- package/dist/proxyPage/utils.js +0 -38
- package/dist/render/renderOnServer.js +0 -40
- package/dist/render/renderOnServer.test.js +0 -24
- package/dist/render/renderStreamToPromise.js +0 -35
- package/dist/resolveSharedDeps.js +0 -28
- package/dist/routes/createDevServerRoutes.js +0 -21
- package/dist/routes/homeRouteHandler.js +0 -12
- package/dist/routes/linksToAllModulesRouteHandler.js +0 -10
- package/dist/routes/linksToAllPartialsRouteHandler.js +0 -10
- package/dist/routes/module.js +0 -27
- package/dist/routes/partial.js +0 -27
- package/dist/routes/proxyPageResourceRedirect.js +0 -12
- package/dist/routes/proxyPageRouteHandler.js +0 -40
|
@@ -0,0 +1,1312 @@
|
|
|
1
|
+
// ../cms-js-internal/dist/types-ohevhxjF.js
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { createHash } from "crypto";
|
|
4
|
+
import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
5
|
+
import { join } from "path/posix";
|
|
6
|
+
var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
7
|
+
var ENTRY_POINTS_PATH = "components/partials/";
|
|
8
|
+
var MODULE_FOLDER_PATH = "components/modules/";
|
|
9
|
+
var TEMPLATE_FOLDER_PATH = "components/templates/";
|
|
10
|
+
var VIRTUAL_ISLAND_RUNTIME = "virtual:island-runtime";
|
|
11
|
+
var VIRTUAL_CONFIG_SETUP = "virtual:config-setup";
|
|
12
|
+
var CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
13
|
+
var collectCssModules = (modulePathToStartWith, viteServer, cssModulesImported = /* @__PURE__ */ new Set()) => {
|
|
14
|
+
const appModulesForPath = viteServer.moduleGraph.fileToModulesMap.get(
|
|
15
|
+
modulePathToStartWith
|
|
16
|
+
);
|
|
17
|
+
if (!appModulesForPath || appModulesForPath.size === 0) {
|
|
18
|
+
throw new Error(`No modules at: ${modulePathToStartWith}`);
|
|
19
|
+
} else if (appModulesForPath.size > 1) {
|
|
20
|
+
throw new Error(`More than one module at: ${modulePathToStartWith}`);
|
|
21
|
+
}
|
|
22
|
+
const appModule = Array.from(appModulesForPath.values())[0];
|
|
23
|
+
const allServerSideModulesImported = /* @__PURE__ */ new Set();
|
|
24
|
+
const newCssModules = [];
|
|
25
|
+
const moduleQueue = Array.from(appModule.importedModules);
|
|
26
|
+
for (const importedModule of moduleQueue) {
|
|
27
|
+
if (allServerSideModulesImported.has(importedModule.id)) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
allServerSideModulesImported.add(importedModule.id);
|
|
31
|
+
const isCss = CSS_LANGS_RE.test(importedModule.file);
|
|
32
|
+
const moduleModulesToQueue = Array.from(importedModule.importedModules);
|
|
33
|
+
if (isCss && !cssModulesImported.has(importedModule)) {
|
|
34
|
+
cssModulesImported.add(importedModule);
|
|
35
|
+
newCssModules.push(importedModule);
|
|
36
|
+
}
|
|
37
|
+
moduleQueue.push(...moduleModulesToQueue);
|
|
38
|
+
}
|
|
39
|
+
return newCssModules;
|
|
40
|
+
};
|
|
41
|
+
function createPreloadLink(assetPath, basePath = "") {
|
|
42
|
+
if (assetPath && assetPath[0] !== "/") {
|
|
43
|
+
assetPath = `/${assetPath}`;
|
|
44
|
+
}
|
|
45
|
+
if (assetPath.endsWith(".js")) {
|
|
46
|
+
return `<link rel="modulepreload" crossorigin href="${basePath}${assetPath}">`;
|
|
47
|
+
} else if (CSS_LANGS_RE.test(assetPath)) {
|
|
48
|
+
return `<link rel="stylesheet" href="${basePath}${assetPath}?css">`;
|
|
49
|
+
} else if (assetPath.endsWith(".woff")) {
|
|
50
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="font" type="font/woff" crossorigin>`;
|
|
51
|
+
} else if (assetPath.endsWith(".woff2")) {
|
|
52
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="font" type="font/woff2" crossorigin>`;
|
|
53
|
+
} else if (assetPath.endsWith(".gif")) {
|
|
54
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="image" type="image/gif">`;
|
|
55
|
+
} else if (assetPath.endsWith(".jpg") || assetPath.endsWith(".jpeg")) {
|
|
56
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="image" type="image/jpeg">`;
|
|
57
|
+
} else if (assetPath.endsWith(".png")) {
|
|
58
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="image" type="image/png">`;
|
|
59
|
+
} else {
|
|
60
|
+
throw new Error(`Unknown preload type for ${assetPath}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
var collectCssInDev = (modulePathToStartWith, viteServer, cssModulesImported = /* @__PURE__ */ new Set()) => {
|
|
64
|
+
return `${collectCssModules(
|
|
65
|
+
modulePathToStartWith,
|
|
66
|
+
viteServer,
|
|
67
|
+
cssModulesImported
|
|
68
|
+
).map((cssModule) => createPreloadLink(cssModule.url)).join("\n")}
|
|
69
|
+
`;
|
|
70
|
+
};
|
|
71
|
+
function sortKeys(input, options = {}) {
|
|
72
|
+
const { deep, compare } = options;
|
|
73
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
74
|
+
function deepSortArray(array) {
|
|
75
|
+
const resultFromCache = cache.get(array);
|
|
76
|
+
if (resultFromCache !== void 0) {
|
|
77
|
+
return resultFromCache;
|
|
78
|
+
}
|
|
79
|
+
const result = [];
|
|
80
|
+
cache.set(array, result);
|
|
81
|
+
result.push(
|
|
82
|
+
...array.map((item) => {
|
|
83
|
+
if (Array.isArray(item)) {
|
|
84
|
+
return deepSortArray(item);
|
|
85
|
+
}
|
|
86
|
+
if (isPlainObject(item)) {
|
|
87
|
+
return _sortKeys(item);
|
|
88
|
+
}
|
|
89
|
+
return item;
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
function _sortKeys(object) {
|
|
95
|
+
const resultFromCache = cache.get(object);
|
|
96
|
+
if (resultFromCache !== void 0) {
|
|
97
|
+
return resultFromCache;
|
|
98
|
+
}
|
|
99
|
+
const result = {};
|
|
100
|
+
const keys = Object.keys(object).sort(compare);
|
|
101
|
+
cache.set(object, result);
|
|
102
|
+
for (const key of keys) {
|
|
103
|
+
const value = object[key];
|
|
104
|
+
let newValue;
|
|
105
|
+
if (deep && Array.isArray(value)) {
|
|
106
|
+
newValue = deepSortArray(value);
|
|
107
|
+
} else {
|
|
108
|
+
newValue = deep && isPlainObject(value) ? _sortKeys(value) : value;
|
|
109
|
+
}
|
|
110
|
+
Object.defineProperty(result, key, {
|
|
111
|
+
...Object.getOwnPropertyDescriptor(object, key),
|
|
112
|
+
value: newValue
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(input)) {
|
|
118
|
+
return deep ? deepSortArray(input) : [...input];
|
|
119
|
+
}
|
|
120
|
+
return _sortKeys(input);
|
|
121
|
+
}
|
|
122
|
+
function isPlainObject(value) {
|
|
123
|
+
if (typeof value !== "object" || value === null) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const prototype = Object.getPrototypeOf(value);
|
|
127
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
128
|
+
}
|
|
129
|
+
var badInlineJsChars = /[\u2028\u2029<>/]/g;
|
|
130
|
+
var inlineJsEscapeChars = {
|
|
131
|
+
"\u2028": "\\u2028",
|
|
132
|
+
"\u2029": "\\u2029",
|
|
133
|
+
"<": "\\u003C",
|
|
134
|
+
">": "\\u003E",
|
|
135
|
+
"/": "\\u002F"
|
|
136
|
+
};
|
|
137
|
+
function escapeChar(unsafeChar) {
|
|
138
|
+
return inlineJsEscapeChars[unsafeChar];
|
|
139
|
+
}
|
|
140
|
+
function escapeForInlineJS(input) {
|
|
141
|
+
return input.replace(badInlineJsChars, escapeChar);
|
|
142
|
+
}
|
|
143
|
+
function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent = 2, prettyPrint = true } = {}) {
|
|
144
|
+
const indentString = " ".repeat(baseIndent);
|
|
145
|
+
jsonIndent = prettyPrint ? jsonIndent : void 0;
|
|
146
|
+
let sorted;
|
|
147
|
+
try {
|
|
148
|
+
if (isPlainObject(input) || Array.isArray(input)) {
|
|
149
|
+
sorted = sortKeys(input, { deep: true });
|
|
150
|
+
}
|
|
151
|
+
} catch (e) {
|
|
152
|
+
console.error("Error sorting Island keys", e);
|
|
153
|
+
}
|
|
154
|
+
return escapeForInlineJS(
|
|
155
|
+
JSON.stringify(sorted ?? input, null, jsonIndent)
|
|
156
|
+
).replace(/\n/gm, `
|
|
157
|
+
${indentString}`);
|
|
158
|
+
}
|
|
159
|
+
var viteRoot;
|
|
160
|
+
var viteCommand;
|
|
161
|
+
function resolveIslandPlugin(islandsSet) {
|
|
162
|
+
return {
|
|
163
|
+
enforce: "pre",
|
|
164
|
+
name: "resolve-islands",
|
|
165
|
+
configResolved(config) {
|
|
166
|
+
viteRoot = config.root;
|
|
167
|
+
viteCommand = config.command;
|
|
168
|
+
},
|
|
169
|
+
load(id) {
|
|
170
|
+
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
171
|
+
const [idWithNoParam] = id.split("?");
|
|
172
|
+
const islandModuleImportPath = `${idWithNoParam}?client-entry`;
|
|
173
|
+
const componentExtension = path.extname(idWithNoParam);
|
|
174
|
+
const componentFilenameWithNoExtension = path.basename(
|
|
175
|
+
idWithNoParam,
|
|
176
|
+
componentExtension
|
|
177
|
+
);
|
|
178
|
+
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
179
|
+
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
180
|
+
if (islandsSet) {
|
|
181
|
+
islandsSet.add(moduleId);
|
|
182
|
+
}
|
|
183
|
+
return `
|
|
184
|
+
const moduleId = '${moduleId}';
|
|
185
|
+
|
|
186
|
+
const lazyComponent = () => import('${islandModuleImportPath}');
|
|
187
|
+
lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
|
|
188
|
+
lazyComponent.moduleId = moduleId;
|
|
189
|
+
|
|
190
|
+
export default lazyComponent;
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function resolveIslandToPlainModulePlugin(enabled = true) {
|
|
198
|
+
return {
|
|
199
|
+
enforce: "pre",
|
|
200
|
+
name: "resolve-islands-to-plain",
|
|
201
|
+
configResolved(config) {
|
|
202
|
+
viteRoot = config.root;
|
|
203
|
+
viteCommand = config.command;
|
|
204
|
+
},
|
|
205
|
+
async resolveId(id, importer, options) {
|
|
206
|
+
if (enabled && (id.endsWith("?island") || id.endsWith("?client"))) {
|
|
207
|
+
const newId = id.replace("?island", "").replace("?client", "");
|
|
208
|
+
const resolution = await this.resolve(newId, importer, {
|
|
209
|
+
skipSelf: true,
|
|
210
|
+
...options
|
|
211
|
+
});
|
|
212
|
+
if (resolution) {
|
|
213
|
+
return resolution;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function resolveIslandToPlainModuleNoopPlugin() {
|
|
221
|
+
return resolveIslandToPlainModulePlugin(false);
|
|
222
|
+
}
|
|
223
|
+
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";
|
|
224
|
+
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
225
|
+
function clientIslandEntryPlugin() {
|
|
226
|
+
return {
|
|
227
|
+
enforce: "pre",
|
|
228
|
+
name: "client-island-entry-plugin",
|
|
229
|
+
resolveId(id) {
|
|
230
|
+
if (id === virtualClientRenderIslandModuleId) {
|
|
231
|
+
return virtualClientRenderIslandModuleId;
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
},
|
|
235
|
+
load(id) {
|
|
236
|
+
if (id.endsWith("?client-entry")) {
|
|
237
|
+
const [idWithNoParam] = id.split("?");
|
|
238
|
+
return `
|
|
239
|
+
import { clientRenderIsland } from '${virtualClientRenderIslandModuleId}';
|
|
240
|
+
import Component from '${idWithNoParam}';
|
|
241
|
+
|
|
242
|
+
export function render(island) {
|
|
243
|
+
return clientRenderIsland(island, Component)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export default Component;
|
|
247
|
+
`;
|
|
248
|
+
}
|
|
249
|
+
if (id === virtualClientRenderIslandModuleId) {
|
|
250
|
+
return clientRenderIsland;
|
|
251
|
+
}
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel, nonceAttribute) => {
|
|
257
|
+
if (!messagesForBrowser) {
|
|
258
|
+
return "";
|
|
259
|
+
}
|
|
260
|
+
const consoleLines = [];
|
|
261
|
+
for (const message of messagesForBrowser) {
|
|
262
|
+
let funcString = "console.log";
|
|
263
|
+
if (message.level === "error") {
|
|
264
|
+
funcString = "console.error";
|
|
265
|
+
}
|
|
266
|
+
if (message.level === "warn") {
|
|
267
|
+
funcString = "console.warn";
|
|
268
|
+
}
|
|
269
|
+
const argString = message.parameters.map((arg) => JSON.stringify(arg)).join(", ");
|
|
270
|
+
consoleLines.push(` ${funcString}(${argString});`);
|
|
271
|
+
}
|
|
272
|
+
let groupStart = "";
|
|
273
|
+
let groupEnd = "";
|
|
274
|
+
if (groupLabel !== void 0 && groupLabel !== null) {
|
|
275
|
+
groupStart = `
|
|
276
|
+
console.group(${JSON.stringify(groupLabel)});`;
|
|
277
|
+
groupEnd = ` console.groupEnd()
|
|
278
|
+
`;
|
|
279
|
+
}
|
|
280
|
+
return `<script ${nonceAttribute}>${groupStart}
|
|
281
|
+
${consoleLines.join("\n")}
|
|
282
|
+
${groupEnd}</script>
|
|
283
|
+
`;
|
|
284
|
+
};
|
|
285
|
+
var getComponentExtension = (componentPath) => {
|
|
286
|
+
const filteredExtensions = COMPONENT_EXTENSIONS.filter(
|
|
287
|
+
(ext) => componentPath.endsWith(ext)
|
|
288
|
+
);
|
|
289
|
+
if (filteredExtensions.length === 1) {
|
|
290
|
+
return filteredExtensions[0];
|
|
291
|
+
}
|
|
292
|
+
return void 0;
|
|
293
|
+
};
|
|
294
|
+
var hasComponentExtension = (componentPath) => {
|
|
295
|
+
return !!getComponentExtension(componentPath);
|
|
296
|
+
};
|
|
297
|
+
var isStorybookStory = (componentPath) => {
|
|
298
|
+
return !!path.basename(componentPath, path.extname(componentPath)).endsWith(".stories");
|
|
299
|
+
};
|
|
300
|
+
var removeComponentExtension = (componentPath) => {
|
|
301
|
+
const ext = getComponentExtension(componentPath);
|
|
302
|
+
if (ext == null) {
|
|
303
|
+
return componentPath;
|
|
304
|
+
}
|
|
305
|
+
return componentPath.slice(0, -1 * ext.length);
|
|
306
|
+
};
|
|
307
|
+
function getEntryPointHash(entryPoint) {
|
|
308
|
+
return createHash("md5").update(entryPoint).digest("hex").slice(0, 6);
|
|
309
|
+
}
|
|
310
|
+
function getEntryPointHashWithIndexSuffix(entryPoint, index) {
|
|
311
|
+
const renderIndexSuffix = index != null ? `i${index}` : "";
|
|
312
|
+
return `${getEntryPointHash(entryPoint)}${renderIndexSuffix}`;
|
|
313
|
+
}
|
|
314
|
+
var COMBINED_REACT_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/react/v18";
|
|
315
|
+
var ISLAND_RUNTIME_CONFIG_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/island-runtime/v1";
|
|
316
|
+
function getCombinedReactUrl() {
|
|
317
|
+
const hsEnv = process.env.HS_ENV;
|
|
318
|
+
const fileVersion = hsEnv === "prod" ? `react-combined.mjs` : "react-combined-qa.mjs";
|
|
319
|
+
return `${COMBINED_REACT_BASE_PATH}/${fileVersion}`;
|
|
320
|
+
}
|
|
321
|
+
function getIslandRuntimeConfigUrl() {
|
|
322
|
+
const hsEnv = process.env.HS_ENV;
|
|
323
|
+
const fileVersion = hsEnv === "prod" ? `island-runtime.mjs` : "island-runtime-qa.mjs";
|
|
324
|
+
return `${ISLAND_RUNTIME_CONFIG_BASE_PATH}/${fileVersion}`;
|
|
325
|
+
}
|
|
326
|
+
function includesHublDataReference(templateSource) {
|
|
327
|
+
const hublDataPattern = /\{%\s+set\s+(experimentalHublData|hublData)\s*=/;
|
|
328
|
+
return !!templateSource.match(hublDataPattern);
|
|
329
|
+
}
|
|
330
|
+
var removeIndexFromPath = (id) => {
|
|
331
|
+
return id.replace(/\/index\.[jt]sx?$/, "");
|
|
332
|
+
};
|
|
333
|
+
var removeIndexOrTrailingJsFromPath = (id) => {
|
|
334
|
+
return removeIndexFromPath(id).replace(/\.[jt]sx?$/, "");
|
|
335
|
+
};
|
|
336
|
+
var HEALTHCHECKS_ENABLED_DEFAULT = true;
|
|
337
|
+
var HEALTHCHECKS_STRICT_DEFAULT = false;
|
|
338
|
+
function getCMSAssetConfig(webRoot) {
|
|
339
|
+
const cmsAssetsPath = path.join(webRoot, "cms-assets.json");
|
|
340
|
+
const cmsThemePath = path.join(webRoot, "theme.json");
|
|
341
|
+
const configPathToUse = fs.existsSync(cmsAssetsPath) ? cmsAssetsPath : cmsThemePath;
|
|
342
|
+
const parsedConfig = JSON.parse(
|
|
343
|
+
fs.readFileSync(configPathToUse).toString()
|
|
344
|
+
);
|
|
345
|
+
return parsedConfig;
|
|
346
|
+
}
|
|
347
|
+
function getCMSAssetConfigIfExists(webRoot) {
|
|
348
|
+
try {
|
|
349
|
+
return getCMSAssetConfig(webRoot);
|
|
350
|
+
} catch (e) {
|
|
351
|
+
console.error(
|
|
352
|
+
`Error finding or parsing cms-assets.json in ${webRoot}, but ignoring for now`
|
|
353
|
+
);
|
|
354
|
+
return {};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function areBuildHealthChecksEnabled(config) {
|
|
358
|
+
var _a, _b;
|
|
359
|
+
return ((_b = (_a = config.buildConfig) == null ? void 0 : _a.healthchecks) == null ? void 0 : _b.enabled) ?? HEALTHCHECKS_ENABLED_DEFAULT;
|
|
360
|
+
}
|
|
361
|
+
function doHealthChecksFailTheBuild(config) {
|
|
362
|
+
var _a, _b;
|
|
363
|
+
return ((_b = (_a = config.buildConfig) == null ? void 0 : _a.healthchecks) == null ? void 0 : _b.strict) ?? HEALTHCHECKS_STRICT_DEFAULT;
|
|
364
|
+
}
|
|
365
|
+
function getServerIncludePrebundleDepPatterns(config) {
|
|
366
|
+
var _a, _b;
|
|
367
|
+
return ((_b = (_a = config.buildConfig) == null ? void 0 : _a.serverPrebundling) == null ? void 0 : _b.include) ?? [];
|
|
368
|
+
}
|
|
369
|
+
var BUILD_INFO_PATH = "/build-info.json";
|
|
370
|
+
function getBuildInfo(buildDir) {
|
|
371
|
+
try {
|
|
372
|
+
const buildInfo = JSON.parse(
|
|
373
|
+
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
374
|
+
);
|
|
375
|
+
return buildInfo;
|
|
376
|
+
} catch (e) {
|
|
377
|
+
throw new Error(`Error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function getBaseAssetUrlFromBuild(buildDir) {
|
|
381
|
+
return getBuildInfo(buildDir).baseAssetUrl;
|
|
382
|
+
}
|
|
383
|
+
var GATES = [
|
|
384
|
+
"CMS:JSRenderer:GetServerSideProps",
|
|
385
|
+
"CMS:JSRenderer:ModuleHubl",
|
|
386
|
+
"CMS:JSRenderer:RemoveCjsPlugin",
|
|
387
|
+
"CMS:JSRenderer:RemoveMockClientEntryPlugin",
|
|
388
|
+
"CMS:JSRenderer:AnalyzeCmsModules"
|
|
389
|
+
];
|
|
390
|
+
var ENABLED_FEATURES_GATE_MAP = {
|
|
391
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
392
|
+
"cms:jsr:RemoveCjsPlugin": "CMS:JSRenderer:RemoveCjsPlugin",
|
|
393
|
+
"cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
|
|
394
|
+
};
|
|
395
|
+
function isUngatedFor(gates, gate) {
|
|
396
|
+
return gates.includes(gate);
|
|
397
|
+
}
|
|
398
|
+
function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
399
|
+
try {
|
|
400
|
+
const buildInfo = getBuildInfo(buildDir);
|
|
401
|
+
return isUngatedFor(buildInfo.gates, gate);
|
|
402
|
+
} catch (e) {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
var findAllComponentsIn = (webRoot, componentsFolder) => {
|
|
407
|
+
const fullComponentsFolderPath = join(webRoot, componentsFolder);
|
|
408
|
+
const componentsByName = {};
|
|
409
|
+
if (!existsSync(fullComponentsFolderPath)) {
|
|
410
|
+
return componentsByName;
|
|
411
|
+
}
|
|
412
|
+
readdirSync(fullComponentsFolderPath).forEach((fileOrFolderName) => {
|
|
413
|
+
const fullPath = join(fullComponentsFolderPath, fileOrFolderName);
|
|
414
|
+
const subdirPath = join(componentsFolder, fileOrFolderName);
|
|
415
|
+
const isDirectory = lstatSync(fullPath).isDirectory();
|
|
416
|
+
if (!isDirectory && hasComponentExtension(fileOrFolderName) && !isStorybookStory(fileOrFolderName)) {
|
|
417
|
+
const subdirPathNoExtension = removeComponentExtension(subdirPath);
|
|
418
|
+
componentsByName[subdirPathNoExtension] = subdirPath;
|
|
419
|
+
} else if (isDirectory) {
|
|
420
|
+
for (const potentialExtension of COMPONENT_EXTENSIONS) {
|
|
421
|
+
const potentialIndexModule = join(
|
|
422
|
+
subdirPath,
|
|
423
|
+
`index${potentialExtension}`
|
|
424
|
+
);
|
|
425
|
+
const fullPotentialPath = join(
|
|
426
|
+
fullPath,
|
|
427
|
+
`index${potentialExtension}`
|
|
428
|
+
);
|
|
429
|
+
if (existsSync(fullPotentialPath)) {
|
|
430
|
+
const moduleIndexPathNoExtension = removeComponentExtension(potentialIndexModule);
|
|
431
|
+
componentsByName[moduleIndexPathNoExtension] = potentialIndexModule;
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
return componentsByName;
|
|
438
|
+
};
|
|
439
|
+
function findAllModulesInRoot(webRoot) {
|
|
440
|
+
const allModuleComponents = findAllComponentsIn(
|
|
441
|
+
webRoot,
|
|
442
|
+
"./components/modules"
|
|
443
|
+
);
|
|
444
|
+
const moduleNames = Object.keys(allModuleComponents).map(
|
|
445
|
+
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
446
|
+
);
|
|
447
|
+
const moduleSubpaths = Object.keys(allModuleComponents);
|
|
448
|
+
const moduleExtensions = Object.values(allModuleComponents).map((path2) => {
|
|
449
|
+
if (!path2)
|
|
450
|
+
return "";
|
|
451
|
+
const extension = path2.split(".").pop() || "";
|
|
452
|
+
return extension;
|
|
453
|
+
});
|
|
454
|
+
const moduleNamesWithExtension = Object.values(allModuleComponents).map(
|
|
455
|
+
(path2) => {
|
|
456
|
+
if (!path2)
|
|
457
|
+
return "";
|
|
458
|
+
const file = path2.replace("components/modules/", "");
|
|
459
|
+
return file.includes("/index.") ? file.split("/index.")[0] : file;
|
|
460
|
+
}
|
|
461
|
+
);
|
|
462
|
+
return {
|
|
463
|
+
moduleNames,
|
|
464
|
+
moduleSubpaths,
|
|
465
|
+
moduleNamesWithExtension,
|
|
466
|
+
moduleExtensions
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function findAllPartialsInRoot(webRoot) {
|
|
470
|
+
const allPartialComponents = findAllComponentsIn(
|
|
471
|
+
webRoot,
|
|
472
|
+
"./components/partials"
|
|
473
|
+
);
|
|
474
|
+
const partialNames = Object.keys(allPartialComponents).map(
|
|
475
|
+
(partialSubpath) => partialSubpath.replace("components/partials/", "").replace("/index", "")
|
|
476
|
+
);
|
|
477
|
+
const partialSubpaths = Object.keys(allPartialComponents);
|
|
478
|
+
return { partialNames, partialSubpaths };
|
|
479
|
+
}
|
|
480
|
+
function namespaceModulePropsShape(props) {
|
|
481
|
+
const {
|
|
482
|
+
dataQueryResult,
|
|
483
|
+
hublParameters,
|
|
484
|
+
fieldValues: passedFieldValues,
|
|
485
|
+
hublData,
|
|
486
|
+
experimentalHublData,
|
|
487
|
+
moduleName,
|
|
488
|
+
supplementalFieldValues
|
|
489
|
+
} = props;
|
|
490
|
+
const oldPropsShape = { ...props };
|
|
491
|
+
if (oldPropsShape.dataQueryResult) {
|
|
492
|
+
delete oldPropsShape.dataQueryResult;
|
|
493
|
+
}
|
|
494
|
+
if (oldPropsShape.hublParameters) {
|
|
495
|
+
delete oldPropsShape.hublParameters;
|
|
496
|
+
}
|
|
497
|
+
const fieldValues = passedFieldValues || oldPropsShape;
|
|
498
|
+
return {
|
|
499
|
+
...fieldValues,
|
|
500
|
+
dataQueryResult,
|
|
501
|
+
fieldValues,
|
|
502
|
+
hublParameters,
|
|
503
|
+
hublData,
|
|
504
|
+
experimentalHublData,
|
|
505
|
+
moduleName,
|
|
506
|
+
supplementalFieldValues
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
function setIn(object, nestedKeysArray, value) {
|
|
510
|
+
let curr = object;
|
|
511
|
+
const finalKey = nestedKeysArray.pop();
|
|
512
|
+
for (let index = 0; index < nestedKeysArray.length; index++) {
|
|
513
|
+
const currentKey = nestedKeysArray[index];
|
|
514
|
+
const nextKey = nestedKeysArray[index + 1];
|
|
515
|
+
if (Number.isInteger(nextKey) || !nextKey && Number.isInteger(finalKey)) {
|
|
516
|
+
if (curr[currentKey] === void 0) {
|
|
517
|
+
curr[currentKey] = [];
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (curr[currentKey] === void 0) {
|
|
521
|
+
curr[currentKey] = {};
|
|
522
|
+
}
|
|
523
|
+
curr = curr[currentKey];
|
|
524
|
+
}
|
|
525
|
+
if (value !== void 0) {
|
|
526
|
+
curr[finalKey] = value;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
function isStylesheetAsset(staticAsset) {
|
|
530
|
+
return staticAsset.type === "stylesheet";
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// ../cms-js-internal/dist/index.js
|
|
534
|
+
import * as dotProp from "dot-prop";
|
|
535
|
+
import * as parser from "@babel/parser";
|
|
536
|
+
import _traverse from "@babel/traverse";
|
|
537
|
+
import * as t from "@babel/types";
|
|
538
|
+
import { jsx } from "react/jsx-runtime";
|
|
539
|
+
import stream from "stream";
|
|
540
|
+
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
541
|
+
import * as cmsComponents from "@hubspot/cms-components";
|
|
542
|
+
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
543
|
+
import { isValidElement, cloneElement } from "react";
|
|
544
|
+
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
545
|
+
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
546
|
+
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
547
|
+
({
|
|
548
|
+
id,
|
|
549
|
+
moduleName,
|
|
550
|
+
moduleId,
|
|
551
|
+
props,
|
|
552
|
+
hydrateOn,
|
|
553
|
+
clientOnly,
|
|
554
|
+
priority,
|
|
555
|
+
url,
|
|
556
|
+
sharedStateID,
|
|
557
|
+
supplementalFieldValues,
|
|
558
|
+
wrapperModuleId,
|
|
559
|
+
wrapperUrl,
|
|
560
|
+
resolvedDataDependencies
|
|
561
|
+
}) => {
|
|
562
|
+
const output = {
|
|
563
|
+
id,
|
|
564
|
+
moduleName,
|
|
565
|
+
moduleId,
|
|
566
|
+
hydrateOn,
|
|
567
|
+
clientOnly,
|
|
568
|
+
priority,
|
|
569
|
+
props,
|
|
570
|
+
url
|
|
571
|
+
};
|
|
572
|
+
if (resolvedDataDependencies) {
|
|
573
|
+
output.resolvedDataDependencies = resolvedDataDependencies;
|
|
574
|
+
}
|
|
575
|
+
if (sharedStateID) {
|
|
576
|
+
output.sharedStateID = sharedStateID;
|
|
577
|
+
}
|
|
578
|
+
if (wrapperModuleId) {
|
|
579
|
+
output.wrapperModuleId = wrapperModuleId;
|
|
580
|
+
}
|
|
581
|
+
if (wrapperUrl) {
|
|
582
|
+
output.wrapperUrl = wrapperUrl;
|
|
583
|
+
}
|
|
584
|
+
const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
|
|
585
|
+
supplementalFieldValues,
|
|
586
|
+
perServerRequestData.get("supplementalFieldValuesRead")
|
|
587
|
+
);
|
|
588
|
+
if (filteredSupplementalFieldValues) {
|
|
589
|
+
output.supplementalFieldValues = filteredSupplementalFieldValues;
|
|
590
|
+
}
|
|
591
|
+
if (output.clientOnly) {
|
|
592
|
+
output.supplementalFieldValues = supplementalFieldValues;
|
|
593
|
+
}
|
|
594
|
+
return output;
|
|
595
|
+
}
|
|
596
|
+
);
|
|
597
|
+
return jsonStringifyAndEscapeForInlineJS(islandsArrayToSerialize, {
|
|
598
|
+
baseIndent,
|
|
599
|
+
jsonIndent: 2,
|
|
600
|
+
prettyPrint
|
|
601
|
+
});
|
|
602
|
+
};
|
|
603
|
+
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
604
|
+
if (!supplementalFieldValues) {
|
|
605
|
+
return supplementalFieldValues;
|
|
606
|
+
}
|
|
607
|
+
if (!supplementalFieldValuesRead) {
|
|
608
|
+
return supplementalFieldValues;
|
|
609
|
+
}
|
|
610
|
+
const result = {};
|
|
611
|
+
Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
|
|
612
|
+
if (hasProperty(supplementalFieldValues, fieldPath)) {
|
|
613
|
+
setProperty(
|
|
614
|
+
result,
|
|
615
|
+
fieldPath,
|
|
616
|
+
getProperty(supplementalFieldValues, fieldPath)
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
return result;
|
|
621
|
+
}
|
|
622
|
+
var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
|
|
623
|
+
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x2) => !!x2);
|
|
624
|
+
if (sharedStateIDs.length > 0) {
|
|
625
|
+
const indentString = " ".repeat(indent);
|
|
626
|
+
const stateByID = {};
|
|
627
|
+
sharedStateIDs.forEach(
|
|
628
|
+
(id) => stateByID[id] = perServerRequestData.get(id)
|
|
629
|
+
);
|
|
630
|
+
const stringifiedState = jsonStringifyAndEscapeForInlineJS(stateByID, {
|
|
631
|
+
prettyPrint,
|
|
632
|
+
jsonIndent: 2
|
|
633
|
+
});
|
|
634
|
+
return `
|
|
635
|
+
|
|
636
|
+
var newState = ${stringifiedState};
|
|
637
|
+
if(window.__hsSSInit) {
|
|
638
|
+
window.__hsSSInit = Object.assign(window.__hsSSInit, newState);
|
|
639
|
+
} else {
|
|
640
|
+
window.__hsSSInit = newState;
|
|
641
|
+
}`.replace(/\n/gm, `
|
|
642
|
+
${indentString}`);
|
|
643
|
+
}
|
|
644
|
+
return "";
|
|
645
|
+
};
|
|
646
|
+
function getIslandUrls(roots, viteDevServer) {
|
|
647
|
+
return roots.map((island) => {
|
|
648
|
+
const islandModule = viteDevServer.moduleGraph.getModuleById(
|
|
649
|
+
island.moduleId
|
|
650
|
+
);
|
|
651
|
+
if (!islandModule) {
|
|
652
|
+
throw new Error(`Unknown island moduleId: ${island.moduleId}`);
|
|
653
|
+
}
|
|
654
|
+
let wrapperModule;
|
|
655
|
+
if (island.wrapperModuleId) {
|
|
656
|
+
wrapperModule = viteDevServer.moduleGraph.getModuleById(
|
|
657
|
+
island.wrapperModuleId
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
const tweakedIsland = {
|
|
661
|
+
...island,
|
|
662
|
+
url: islandModule.url,
|
|
663
|
+
wrapperUrl: wrapperModule ? wrapperModule.url : void 0
|
|
664
|
+
};
|
|
665
|
+
return tweakedIsland;
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
function getPerServerRequestUrls(perServerRequestData, viteDevServer) {
|
|
669
|
+
if (!perServerRequestData.has("sharedStateIDs")) {
|
|
670
|
+
return new Map(perServerRequestData);
|
|
671
|
+
}
|
|
672
|
+
const perServerRequestDataWithUrls = new Map(
|
|
673
|
+
perServerRequestData
|
|
674
|
+
);
|
|
675
|
+
perServerRequestData.get("sharedStateIDs").forEach((id) => {
|
|
676
|
+
const reducer = perServerRequestData.get(id);
|
|
677
|
+
if (reducer.reducerFuncModuleId) {
|
|
678
|
+
const reducerWithUrl = {
|
|
679
|
+
...reducer,
|
|
680
|
+
reducerFuncModuleUrl: viteDevServer.moduleGraph.getModuleById(
|
|
681
|
+
reducer.reducerFuncModuleId
|
|
682
|
+
).url
|
|
683
|
+
};
|
|
684
|
+
perServerRequestDataWithUrls.set(id, reducerWithUrl);
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
return perServerRequestDataWithUrls;
|
|
688
|
+
}
|
|
689
|
+
var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent, prettyPrint) => {
|
|
690
|
+
const islands = getIslandUrls(roots, viteDevServer);
|
|
691
|
+
const perServerRequestDataWithUrls = getPerServerRequestUrls(
|
|
692
|
+
perServerRequestData,
|
|
693
|
+
viteDevServer
|
|
694
|
+
);
|
|
695
|
+
return `${" ".repeat(
|
|
696
|
+
indent
|
|
697
|
+
)}window.__islands = ${serializeIslandDataForInlineScript(
|
|
698
|
+
islands,
|
|
699
|
+
perServerRequestData,
|
|
700
|
+
indent,
|
|
701
|
+
prettyPrint
|
|
702
|
+
)}${writeSharedStateToJsGlobal(
|
|
703
|
+
islands,
|
|
704
|
+
perServerRequestDataWithUrls,
|
|
705
|
+
indent,
|
|
706
|
+
prettyPrint
|
|
707
|
+
)}`;
|
|
708
|
+
};
|
|
709
|
+
function noncePlaceholderPlugin() {
|
|
710
|
+
const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
|
|
711
|
+
return {
|
|
712
|
+
name: "hs-nonce-placeholder",
|
|
713
|
+
enforce: "post",
|
|
714
|
+
apply() {
|
|
715
|
+
return HS_DEPLOYED;
|
|
716
|
+
},
|
|
717
|
+
transformIndexHtml(html) {
|
|
718
|
+
const regex = /<(style|script|link) (.*)>/gi;
|
|
719
|
+
const replacer = (_, p1, p2) => {
|
|
720
|
+
if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
|
|
721
|
+
p1 === "link" && p2.includes('rel="stylesheet"')) {
|
|
722
|
+
const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
|
|
723
|
+
p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
|
|
724
|
+
}
|
|
725
|
+
return `<${p1} ${p2}>`;
|
|
726
|
+
};
|
|
727
|
+
return html.replace(regex, replacer);
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
var traverse = _traverse.default;
|
|
732
|
+
var CMS_MODULE_COMPONENT_NAME = "Module";
|
|
733
|
+
var DND_AREA_COMPONENT_NAME = "DndArea";
|
|
734
|
+
var PLUGIN_NAME = "findCmsModules";
|
|
735
|
+
function findCmsModules(buildContentDescriptors = {}) {
|
|
736
|
+
let config;
|
|
737
|
+
return {
|
|
738
|
+
enforce: "pre",
|
|
739
|
+
name: "findCmsModules",
|
|
740
|
+
configResolved(resolvedConfig) {
|
|
741
|
+
config = resolvedConfig;
|
|
742
|
+
},
|
|
743
|
+
transform(code, id) {
|
|
744
|
+
const moduleInfo = this.getModuleInfo(id);
|
|
745
|
+
if (!shouldAnalyzeModule(config, moduleInfo, code))
|
|
746
|
+
return null;
|
|
747
|
+
const contentDescriptors = analyzeSourceCodeUsages(
|
|
748
|
+
this,
|
|
749
|
+
moduleInfo,
|
|
750
|
+
config,
|
|
751
|
+
code
|
|
752
|
+
);
|
|
753
|
+
if (Object.keys(contentDescriptors.dndAreas).length > 0 || Object.keys(contentDescriptors.modules).length > 0) {
|
|
754
|
+
return {
|
|
755
|
+
meta: {
|
|
756
|
+
findCmsModules: contentDescriptors
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
},
|
|
761
|
+
buildEnd(error) {
|
|
762
|
+
if (error)
|
|
763
|
+
throw error;
|
|
764
|
+
const entryPoints = getEntryPoints(this, config);
|
|
765
|
+
const entryPointCmsModuleMap = buildEntryPointsCmsModuleMap(
|
|
766
|
+
this,
|
|
767
|
+
entryPoints
|
|
768
|
+
);
|
|
769
|
+
const relativeEntryPointCmsModuleMap = convertEntryPointPathsToRelative(
|
|
770
|
+
config,
|
|
771
|
+
entryPointCmsModuleMap
|
|
772
|
+
);
|
|
773
|
+
const entryPointIslandCmsModuleMap = buildEntryPointIslandsCmsModuleMap(
|
|
774
|
+
this,
|
|
775
|
+
entryPoints
|
|
776
|
+
);
|
|
777
|
+
const relativeEntryPointIslandCmsModuleMap = convertEntryPointIslandPathsToRelative(
|
|
778
|
+
config,
|
|
779
|
+
entryPointIslandCmsModuleMap
|
|
780
|
+
);
|
|
781
|
+
if (Object.keys(relativeEntryPointIslandCmsModuleMap).length > 0) {
|
|
782
|
+
this.error(`
|
|
783
|
+
Error: <Module /> cannot be used within <Island />
|
|
784
|
+
Found invalid usages:
|
|
785
|
+
${JSON.stringify(relativeEntryPointIslandCmsModuleMap, null, 2)}
|
|
786
|
+
`);
|
|
787
|
+
}
|
|
788
|
+
const modulesWithinModules = filterEntryPointsToModules(
|
|
789
|
+
relativeEntryPointCmsModuleMap
|
|
790
|
+
);
|
|
791
|
+
if (Object.keys(modulesWithinModules).length > 0) {
|
|
792
|
+
this.error(`
|
|
793
|
+
Error: <Module /> can only be used in React Partials
|
|
794
|
+
Found invalid usages:
|
|
795
|
+
${JSON.stringify(modulesWithinModules, null, 2)}
|
|
796
|
+
`);
|
|
797
|
+
}
|
|
798
|
+
Object.assign(buildContentDescriptors, relativeEntryPointCmsModuleMap);
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
function convertEntryPointPathsToRelative(config, entryPointsCmsModuleMap) {
|
|
803
|
+
const relativeEntries = Object.entries(entryPointsCmsModuleMap).map(
|
|
804
|
+
([entryPointPath, cmsModules]) => {
|
|
805
|
+
return [toRelativePath(config, entryPointPath), cmsModules];
|
|
806
|
+
}
|
|
807
|
+
);
|
|
808
|
+
return Object.fromEntries(relativeEntries);
|
|
809
|
+
}
|
|
810
|
+
function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap) {
|
|
811
|
+
const relativeEntries = Object.entries(entryPointsCmsModuleMap).map(
|
|
812
|
+
([entryPointPath, islandContentDescriptors]) => {
|
|
813
|
+
const islandCmsModuleUsage = Object.fromEntries(
|
|
814
|
+
Object.entries(islandContentDescriptors).map(
|
|
815
|
+
([islandPath, contentDescriptors]) => {
|
|
816
|
+
return [
|
|
817
|
+
toRelativePath(config, islandPath).replace("?client-entry", ""),
|
|
818
|
+
contentDescriptors
|
|
819
|
+
];
|
|
820
|
+
}
|
|
821
|
+
)
|
|
822
|
+
);
|
|
823
|
+
return [toRelativePath(config, entryPointPath), islandCmsModuleUsage];
|
|
824
|
+
}
|
|
825
|
+
);
|
|
826
|
+
return Object.fromEntries(relativeEntries);
|
|
827
|
+
}
|
|
828
|
+
function toRelativePath(config, path2) {
|
|
829
|
+
return path2.replace(`${config.root}/`, "");
|
|
830
|
+
}
|
|
831
|
+
function shouldAnalyzeModule(config, moduleInfo, code) {
|
|
832
|
+
const [fileId, __] = moduleInfo.id.split("?");
|
|
833
|
+
const isExternal = config.command !== "serve" && moduleInfo.isExternal;
|
|
834
|
+
return (
|
|
835
|
+
// analyze customer code only
|
|
836
|
+
!isExternal && moduleInfo.id.startsWith(config.root) && // jsx files that contain "Module" / "DndArea"
|
|
837
|
+
(fileId.endsWith(".tsx") || fileId.endsWith(".jsx")) && (code.includes(CMS_MODULE_COMPONENT_NAME) || code.includes(DND_AREA_COMPONENT_NAME))
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
function getEntryPoints(ctx, config) {
|
|
841
|
+
return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
|
|
842
|
+
}
|
|
843
|
+
function buildEntryPointsCmsModuleMap(ctx, entryPoints) {
|
|
844
|
+
const entryPointCmsModuleUsage = {};
|
|
845
|
+
for (const entryPoint of entryPoints) {
|
|
846
|
+
const result = findCmsModuleUsages(ctx, entryPoint.id);
|
|
847
|
+
if (result) {
|
|
848
|
+
entryPointCmsModuleUsage[entryPoint.id] = result;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return entryPointCmsModuleUsage;
|
|
852
|
+
}
|
|
853
|
+
function buildEntryPointIslandsCmsModuleMap(ctx, entryPoints) {
|
|
854
|
+
const entryPointIslandsCmsModuleMap = {};
|
|
855
|
+
for (const entryPoint of entryPoints) {
|
|
856
|
+
const result = findIslandCmsModuleUsage(ctx, entryPoint.id);
|
|
857
|
+
if (result) {
|
|
858
|
+
entryPointIslandsCmsModuleMap[entryPoint.id] = result;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return entryPointIslandsCmsModuleMap;
|
|
862
|
+
}
|
|
863
|
+
function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
864
|
+
const sourceAst = parser.parse(code, {
|
|
865
|
+
sourceType: "module",
|
|
866
|
+
plugins: ["jsx", "typescript"]
|
|
867
|
+
});
|
|
868
|
+
const contentDescriptors = { modules: {}, dndAreas: {} };
|
|
869
|
+
let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
|
|
870
|
+
let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
|
|
871
|
+
traverse(sourceAst, {
|
|
872
|
+
ImportDeclaration(path2) {
|
|
873
|
+
if (t.isStringLiteral(path2.node.source, {
|
|
874
|
+
value: "@hubspot/cms-components"
|
|
875
|
+
})) {
|
|
876
|
+
for (const specifier of path2.node.specifiers) {
|
|
877
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
878
|
+
name: CMS_MODULE_COMPONENT_NAME
|
|
879
|
+
})) {
|
|
880
|
+
moduleComponentLocalImportName = specifier.local.name;
|
|
881
|
+
}
|
|
882
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
883
|
+
name: DND_AREA_COMPONENT_NAME
|
|
884
|
+
})) {
|
|
885
|
+
dndAreaComponentLocalImportName = specifier.local.name;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
},
|
|
890
|
+
JSXOpeningElement(path2) {
|
|
891
|
+
if (t.isJSXIdentifier(path2.node.name, {
|
|
892
|
+
name: moduleComponentLocalImportName
|
|
893
|
+
})) {
|
|
894
|
+
let cmsModuleName;
|
|
895
|
+
let cmsModulePath;
|
|
896
|
+
let cmsModuleLabel;
|
|
897
|
+
for (const prop of path2.node.attributes) {
|
|
898
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
899
|
+
cmsModuleName = prop.value.value;
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
|
|
903
|
+
cmsModulePath = prop.value.value;
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
|
|
907
|
+
cmsModuleLabel = prop.value.value;
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
ctx.error(
|
|
911
|
+
new Error(
|
|
912
|
+
`Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
913
|
+
)
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
const cmsModuleProps = {
|
|
917
|
+
name: cmsModuleName,
|
|
918
|
+
path: cmsModulePath
|
|
919
|
+
};
|
|
920
|
+
if (cmsModuleLabel) {
|
|
921
|
+
cmsModuleProps.label = cmsModuleLabel;
|
|
922
|
+
}
|
|
923
|
+
if (Object.hasOwn(contentDescriptors.modules, cmsModuleProps.name)) {
|
|
924
|
+
ctx.error(
|
|
925
|
+
new Error(
|
|
926
|
+
`Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
|
|
927
|
+
)
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
|
|
931
|
+
}
|
|
932
|
+
if (t.isJSXIdentifier(path2.node.name, {
|
|
933
|
+
name: dndAreaComponentLocalImportName
|
|
934
|
+
})) {
|
|
935
|
+
let dndAreaName;
|
|
936
|
+
for (const prop of path2.node.attributes) {
|
|
937
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
938
|
+
dndAreaName = prop.value.value;
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
ctx.error(
|
|
942
|
+
new Error(
|
|
943
|
+
`Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" must a primitive string`
|
|
944
|
+
)
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
const dndArea = {
|
|
948
|
+
name: dndAreaName
|
|
949
|
+
};
|
|
950
|
+
if (Object.hasOwn(contentDescriptors.dndAreas, dndArea.name)) {
|
|
951
|
+
ctx.error(
|
|
952
|
+
new Error(
|
|
953
|
+
`Error: multiple <${DND_AREA_COMPONENT_NAME} /> with duplicate name: ${dndArea.name}`
|
|
954
|
+
)
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
contentDescriptors.dndAreas[dndArea.name] = dndArea;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
return contentDescriptors;
|
|
962
|
+
}
|
|
963
|
+
function findCmsModuleUsages(ctx, moduleId, processed = /* @__PURE__ */ new Set(), result = {}) {
|
|
964
|
+
if (Object.hasOwn(result, moduleId)) {
|
|
965
|
+
return result[moduleId];
|
|
966
|
+
}
|
|
967
|
+
const moduleInfo = ctx.getModuleInfo(moduleId);
|
|
968
|
+
let entryPointContentDescriptors = null;
|
|
969
|
+
if (Object.hasOwn(moduleInfo.meta, PLUGIN_NAME)) {
|
|
970
|
+
entryPointContentDescriptors = {
|
|
971
|
+
...entryPointContentDescriptors,
|
|
972
|
+
...moduleInfo.meta[PLUGIN_NAME]
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
for (const importedId of [
|
|
976
|
+
...moduleInfo.importedIds,
|
|
977
|
+
...moduleInfo.dynamicallyImportedIds
|
|
978
|
+
]) {
|
|
979
|
+
if (processed.has(importedId)) {
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
982
|
+
const importedResult = findCmsModuleUsages(
|
|
983
|
+
ctx,
|
|
984
|
+
importedId,
|
|
985
|
+
processed,
|
|
986
|
+
result
|
|
987
|
+
);
|
|
988
|
+
if (importedResult) {
|
|
989
|
+
entryPointContentDescriptors = {
|
|
990
|
+
...entryPointContentDescriptors,
|
|
991
|
+
...importedResult
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
if (entryPointContentDescriptors) {
|
|
996
|
+
result[moduleId] = entryPointContentDescriptors;
|
|
997
|
+
}
|
|
998
|
+
processed.add(moduleId);
|
|
999
|
+
return entryPointContentDescriptors;
|
|
1000
|
+
}
|
|
1001
|
+
function findIslandCmsModuleUsage(ctx, moduleId, processedIslands = /* @__PURE__ */ new Set(), islandModuleResults = {}, processed = /* @__PURE__ */ new Set(), results = {}) {
|
|
1002
|
+
processedIslands.add(moduleId);
|
|
1003
|
+
if (Object.hasOwn(islandModuleResults, moduleId)) {
|
|
1004
|
+
return islandModuleResults[moduleId];
|
|
1005
|
+
}
|
|
1006
|
+
const moduleInfo = ctx.getModuleInfo(moduleId);
|
|
1007
|
+
let resultForModuleId = {};
|
|
1008
|
+
if (moduleInfo.id.endsWith("?client-entry")) {
|
|
1009
|
+
const mergedDataDependencies = findCmsModuleUsages(
|
|
1010
|
+
ctx,
|
|
1011
|
+
moduleInfo.id,
|
|
1012
|
+
processed,
|
|
1013
|
+
results
|
|
1014
|
+
);
|
|
1015
|
+
if (mergedDataDependencies) {
|
|
1016
|
+
resultForModuleId[moduleInfo.id] = mergedDataDependencies;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
for (const importedId of [
|
|
1020
|
+
...moduleInfo.importedIds,
|
|
1021
|
+
...moduleInfo.dynamicallyImportedIds
|
|
1022
|
+
]) {
|
|
1023
|
+
if (processedIslands.has(importedId)) {
|
|
1024
|
+
continue;
|
|
1025
|
+
}
|
|
1026
|
+
const importerCmsModuleUsageResult = findIslandCmsModuleUsage(
|
|
1027
|
+
ctx,
|
|
1028
|
+
importedId,
|
|
1029
|
+
processedIslands,
|
|
1030
|
+
islandModuleResults,
|
|
1031
|
+
processed,
|
|
1032
|
+
results
|
|
1033
|
+
);
|
|
1034
|
+
if (importerCmsModuleUsageResult) {
|
|
1035
|
+
resultForModuleId = {
|
|
1036
|
+
...resultForModuleId,
|
|
1037
|
+
...importerCmsModuleUsageResult
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
if (Object.keys(resultForModuleId).length > 0) {
|
|
1042
|
+
islandModuleResults[moduleId] = resultForModuleId;
|
|
1043
|
+
return resultForModuleId;
|
|
1044
|
+
}
|
|
1045
|
+
return null;
|
|
1046
|
+
}
|
|
1047
|
+
function filterEntryPointsToModules(entryPointCmsModuleMap) {
|
|
1048
|
+
return Object.fromEntries(
|
|
1049
|
+
Object.entries(entryPointCmsModuleMap).filter(
|
|
1050
|
+
([entryPoint]) => entryPoint.startsWith("components/modules/")
|
|
1051
|
+
)
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
var promiseForNewWritableStream = () => {
|
|
1055
|
+
const chunks = [];
|
|
1056
|
+
const writableStream = new stream.Writable();
|
|
1057
|
+
writableStream._write = (chunk, encoding, done) => {
|
|
1058
|
+
chunks.push(Buffer.from(chunk));
|
|
1059
|
+
done();
|
|
1060
|
+
};
|
|
1061
|
+
const streamDonePromise = new Promise((resolve, reject) => {
|
|
1062
|
+
writableStream.on("error", (error) => {
|
|
1063
|
+
reject(error);
|
|
1064
|
+
});
|
|
1065
|
+
writableStream._final = (done) => {
|
|
1066
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
1067
|
+
done();
|
|
1068
|
+
};
|
|
1069
|
+
});
|
|
1070
|
+
return { streamDonePromise, writableStream };
|
|
1071
|
+
};
|
|
1072
|
+
var renderStreamToPromise = async (reactElements, options) => {
|
|
1073
|
+
const { streamDonePromise, writableStream } = promiseForNewWritableStream();
|
|
1074
|
+
const {
|
|
1075
|
+
pipe
|
|
1076
|
+
/* abort */
|
|
1077
|
+
} = renderToPipeableStream(reactElements, {
|
|
1078
|
+
...options || {},
|
|
1079
|
+
onShellReady() {
|
|
1080
|
+
},
|
|
1081
|
+
onAllReady() {
|
|
1082
|
+
pipe(writableStream);
|
|
1083
|
+
if (options == null ? void 0 : options.onAllReady) {
|
|
1084
|
+
options.onAllReady();
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
return streamDonePromise;
|
|
1089
|
+
};
|
|
1090
|
+
var {
|
|
1091
|
+
createServerRenderContextV2: createServerRenderContextV22,
|
|
1092
|
+
createServerRenderContext: createServerRenderContext2,
|
|
1093
|
+
renderServerSidePropsWithAsyncLocalStoreContext
|
|
1094
|
+
} = cmsComponents;
|
|
1095
|
+
var bootStrapRenderContext = () => {
|
|
1096
|
+
const renderContext = createServerRenderContextV22 ? createServerRenderContextV22(null, {
|
|
1097
|
+
environmentConfig: null,
|
|
1098
|
+
entryPointBasePath: "",
|
|
1099
|
+
supplementalFieldValues: {},
|
|
1100
|
+
messagesForBrowser: []
|
|
1101
|
+
}) : createServerRenderContext2("", null);
|
|
1102
|
+
return renderContext;
|
|
1103
|
+
};
|
|
1104
|
+
async function renderComponentOnServer(Component, propsAndDeps, pageUrl, environmentConfig, entryPointBasePath, contextOptions, renderOptions, getServerSideProps) {
|
|
1105
|
+
const { props } = propsAndDeps;
|
|
1106
|
+
const componentDebugName = Component.displayName || Component.name;
|
|
1107
|
+
const supplementalFieldValues = contextOptions == null ? void 0 : contextOptions.supplementalFieldValues;
|
|
1108
|
+
const messagesForBrowser = contextOptions == null ? void 0 : contextOptions.messagesForBrowser;
|
|
1109
|
+
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
1110
|
+
environmentConfig,
|
|
1111
|
+
entryPointBasePath,
|
|
1112
|
+
supplementalFieldValues,
|
|
1113
|
+
messagesForBrowser
|
|
1114
|
+
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
1115
|
+
if (getServerSideProps !== void 0 && typeof getServerSideProps === "function") {
|
|
1116
|
+
const gSSPResult = await renderServerSidePropsWithAsyncLocalStoreContext(
|
|
1117
|
+
getServerSideProps,
|
|
1118
|
+
propsAndDeps,
|
|
1119
|
+
renderContext
|
|
1120
|
+
);
|
|
1121
|
+
if (gSSPResult) {
|
|
1122
|
+
props.serverSideProps = gSSPResult.serverSideProps;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
return renderOnServer(
|
|
1126
|
+
/* @__PURE__ */ jsx(Component, { ...props }),
|
|
1127
|
+
renderContext,
|
|
1128
|
+
componentDebugName,
|
|
1129
|
+
renderOptions
|
|
1130
|
+
);
|
|
1131
|
+
}
|
|
1132
|
+
async function renderOnServer(elements, renderContext = bootStrapRenderContext(), debugName, renderOptions) {
|
|
1133
|
+
let html = await renderStreamToPromise(
|
|
1134
|
+
/* @__PURE__ */ jsx(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
1135
|
+
renderOptions
|
|
1136
|
+
);
|
|
1137
|
+
if (renderContext.messagesForBrowser.length > 0) {
|
|
1138
|
+
html = `${html}${scriptTagToLogServerMessages(
|
|
1139
|
+
renderContext.messagesForBrowser,
|
|
1140
|
+
`Server messages rendering: ${debugName}`
|
|
1141
|
+
)}`;
|
|
1142
|
+
}
|
|
1143
|
+
return { html, renderContext };
|
|
1144
|
+
}
|
|
1145
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
1146
|
+
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
1147
|
+
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
1148
|
+
}
|
|
1149
|
+
const serializedJson = jsonStringifyAndEscapeForInlineJS(
|
|
1150
|
+
environmentConfig.toJSON(),
|
|
1151
|
+
{ baseIndent: 6, prettyPrint }
|
|
1152
|
+
);
|
|
1153
|
+
const globals = [`window.__hsEnvConfig = ${serializedJson};`];
|
|
1154
|
+
if (hsServerPageUrl) {
|
|
1155
|
+
globals.push(
|
|
1156
|
+
`window.__hsServerPageUrl = ${jsonStringifyAndEscapeForInlineJS(
|
|
1157
|
+
hsServerPageUrl
|
|
1158
|
+
)};`
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
if (hsBasePath) {
|
|
1162
|
+
globals.push(
|
|
1163
|
+
`window.__hsBasePath = ${jsonStringifyAndEscapeForInlineJS(hsBasePath)};`
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
if (!environmentConfig.getIsDeployed() && (criticalDevErrors == null ? void 0 : criticalDevErrors.length)) {
|
|
1167
|
+
const firstCriticalDevError = criticalDevErrors[0];
|
|
1168
|
+
globals.push(`
|
|
1169
|
+
customElements.whenDefined('vite-error-overlay').then(() => {
|
|
1170
|
+
const ErrorOverlay = customElements.get('vite-error-overlay');
|
|
1171
|
+
const error = new Error(${jsonStringifyAndEscapeForInlineJS(
|
|
1172
|
+
firstCriticalDevError.message
|
|
1173
|
+
)});
|
|
1174
|
+
const overlay = new ErrorOverlay(error);
|
|
1175
|
+
|
|
1176
|
+
document.body.appendChild(overlay);
|
|
1177
|
+
})
|
|
1178
|
+
`);
|
|
1179
|
+
}
|
|
1180
|
+
const nonceAttr = includeNonces && cmsComponents.SCRIPT_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.SCRIPT_NONCE_PLACEHOLDER}"` : "";
|
|
1181
|
+
return `
|
|
1182
|
+
<script type="text/javascript"${nonceAttr}>
|
|
1183
|
+
${globals.join("\n ")}
|
|
1184
|
+
</script>
|
|
1185
|
+
`;
|
|
1186
|
+
}
|
|
1187
|
+
function renderFieldsJSX(fieldsJSX) {
|
|
1188
|
+
let moduleJson;
|
|
1189
|
+
const outputCallback = (callbackJson) => {
|
|
1190
|
+
moduleJson = callbackJson;
|
|
1191
|
+
};
|
|
1192
|
+
renderToStaticMarkup(
|
|
1193
|
+
cloneElement(fieldsJSX, {
|
|
1194
|
+
outputCallback
|
|
1195
|
+
})
|
|
1196
|
+
);
|
|
1197
|
+
if (!moduleJson) {
|
|
1198
|
+
throw new Error("couldn't render module fields definition to fields.json");
|
|
1199
|
+
}
|
|
1200
|
+
return moduleJson;
|
|
1201
|
+
}
|
|
1202
|
+
function renderFieldsToJson(fields, moduleName) {
|
|
1203
|
+
let fieldsJSON;
|
|
1204
|
+
try {
|
|
1205
|
+
if (isValidElement(fields)) {
|
|
1206
|
+
fieldsJSON = renderFieldsJSX(fields);
|
|
1207
|
+
} else if (Array.isArray(fields)) {
|
|
1208
|
+
fieldsJSON = fields;
|
|
1209
|
+
} else {
|
|
1210
|
+
throw new Error(
|
|
1211
|
+
`Couldn't recognize \`fields\` value for module ${moduleName}`
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
return fieldsJSON;
|
|
1215
|
+
} catch (e2) {
|
|
1216
|
+
e2.message = `Error when rendering fields for ${moduleName}: ${e2.message}`;
|
|
1217
|
+
throw e2;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
function DndAreaSlot(props) {
|
|
1221
|
+
return /* @__PURE__ */ jsx(
|
|
1222
|
+
"div",
|
|
1223
|
+
{
|
|
1224
|
+
suppressHydrationWarning: true,
|
|
1225
|
+
dangerouslySetInnerHTML: {
|
|
1226
|
+
__html: `<!-- hs-dnd-area-placeholder-${props.name} -->`
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
function ModuleSlot(props) {
|
|
1232
|
+
return /* @__PURE__ */ jsx(
|
|
1233
|
+
"div",
|
|
1234
|
+
{
|
|
1235
|
+
suppressHydrationWarning: true,
|
|
1236
|
+
dangerouslySetInnerHTML: {
|
|
1237
|
+
__html: `<!-- hs-module-placeholder-${props.name} -->`
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
function GlobalPartialSlot(props) {
|
|
1243
|
+
return /* @__PURE__ */ jsx(
|
|
1244
|
+
"div",
|
|
1245
|
+
{
|
|
1246
|
+
suppressHydrationWarning: true,
|
|
1247
|
+
dangerouslySetInnerHTML: {
|
|
1248
|
+
__html: `<!-- hs-global-partial-placeholder-${props.name} -->`
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1253
|
+
export {
|
|
1254
|
+
COMPONENT_EXTENSIONS,
|
|
1255
|
+
CSS_LANGS_RE,
|
|
1256
|
+
DndAreaSlot,
|
|
1257
|
+
ENABLED_FEATURES_GATE_MAP,
|
|
1258
|
+
ENTRY_POINTS_PATH,
|
|
1259
|
+
GATES,
|
|
1260
|
+
GlobalPartialSlot,
|
|
1261
|
+
MODULE_FOLDER_PATH,
|
|
1262
|
+
ModuleSlot,
|
|
1263
|
+
TEMPLATE_FOLDER_PATH,
|
|
1264
|
+
VIRTUAL_CONFIG_SETUP,
|
|
1265
|
+
VIRTUAL_ISLAND_RUNTIME,
|
|
1266
|
+
areBuildHealthChecksEnabled,
|
|
1267
|
+
clientIslandEntryPlugin,
|
|
1268
|
+
collectCssInDev,
|
|
1269
|
+
collectCssModules,
|
|
1270
|
+
createIslandsGlobalJsForClientInDev,
|
|
1271
|
+
doHealthChecksFailTheBuild,
|
|
1272
|
+
escapeForInlineJS,
|
|
1273
|
+
findAllComponentsIn,
|
|
1274
|
+
findAllModulesInRoot,
|
|
1275
|
+
findAllPartialsInRoot,
|
|
1276
|
+
findCmsModules,
|
|
1277
|
+
getBaseAssetUrlFromBuild,
|
|
1278
|
+
getBuildInfo,
|
|
1279
|
+
getCMSAssetConfig,
|
|
1280
|
+
getCMSAssetConfigIfExists,
|
|
1281
|
+
getCombinedReactUrl,
|
|
1282
|
+
getComponentExtension,
|
|
1283
|
+
getEntryPointHash,
|
|
1284
|
+
getEntryPointHashWithIndexSuffix,
|
|
1285
|
+
getIslandRuntimeConfigUrl,
|
|
1286
|
+
getIslandUrls,
|
|
1287
|
+
getServerGlobalsToInject,
|
|
1288
|
+
getServerIncludePrebundleDepPatterns,
|
|
1289
|
+
hasComponentExtension,
|
|
1290
|
+
includesHublDataReference,
|
|
1291
|
+
isStorybookStory,
|
|
1292
|
+
isStylesheetAsset,
|
|
1293
|
+
isUngatedFor,
|
|
1294
|
+
jsonStringifyAndEscapeForInlineJS,
|
|
1295
|
+
namespaceModulePropsShape,
|
|
1296
|
+
noncePlaceholderPlugin,
|
|
1297
|
+
removeComponentExtension,
|
|
1298
|
+
removeIndexFromPath,
|
|
1299
|
+
removeIndexOrTrailingJsFromPath,
|
|
1300
|
+
renderComponentOnServer,
|
|
1301
|
+
renderFieldsToJson,
|
|
1302
|
+
renderOnServer,
|
|
1303
|
+
renderStreamToPromise,
|
|
1304
|
+
resolveIslandPlugin,
|
|
1305
|
+
resolveIslandToPlainModuleNoopPlugin,
|
|
1306
|
+
resolveIslandToPlainModulePlugin,
|
|
1307
|
+
scriptTagToLogServerMessages,
|
|
1308
|
+
serializeIslandDataForInlineScript,
|
|
1309
|
+
setIn,
|
|
1310
|
+
ungatedAtBuildTimeFor,
|
|
1311
|
+
virtualClientRenderIslandModuleId
|
|
1312
|
+
};
|