@hubspot/cms-dev-server 0.4.15 → 0.4.17
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/storybook/main.js +563 -0
- package/package.json +3 -3
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// ../cms-js-internal/dist/index.js
|
|
12
|
+
var dist_exports = {};
|
|
13
|
+
__export(dist_exports, {
|
|
14
|
+
COMPONENT_EXTENSIONS: () => COMPONENT_EXTENSIONS,
|
|
15
|
+
CSS_LANGS_RE: () => CSS_LANGS_RE,
|
|
16
|
+
ENTRY_POINTS_PATH: () => ENTRY_POINTS_PATH,
|
|
17
|
+
GATES: () => GATES,
|
|
18
|
+
MODULE_FOLDER_PATH: () => MODULE_FOLDER_PATH,
|
|
19
|
+
VIRTUAL_CONFIG_SETUP: () => VIRTUAL_CONFIG_SETUP,
|
|
20
|
+
VIRTUAL_ISLAND_RUNTIME: () => VIRTUAL_ISLAND_RUNTIME,
|
|
21
|
+
clientIslandEntryPlugin: () => clientIslandEntryPlugin,
|
|
22
|
+
collectCssInDev: () => collectCssInDev,
|
|
23
|
+
collectCssModules: () => collectCssModules,
|
|
24
|
+
createIslandsGlobalJsForClientInDev: () => createIslandsGlobalJsForClientInDev,
|
|
25
|
+
findAllComponentsIn: () => findAllComponentsIn,
|
|
26
|
+
findAllModulesInRoot: () => findAllModulesInRoot,
|
|
27
|
+
findAllPartialsInRoot: () => findAllPartialsInRoot,
|
|
28
|
+
getCombinedReactUrl: () => getCombinedReactUrl,
|
|
29
|
+
getComponentExtension: () => getComponentExtension,
|
|
30
|
+
getEntryPointHash: () => getEntryPointHash,
|
|
31
|
+
getEntryPointHashWithIndexSuffix: () => getEntryPointHashWithIndexSuffix,
|
|
32
|
+
getIslandRuntimeConfigUrl: () => getIslandRuntimeConfigUrl,
|
|
33
|
+
getIslandUrls: () => getIslandUrls,
|
|
34
|
+
getServerGlobalsToInject: () => getServerGlobalsToInject,
|
|
35
|
+
hasComponentExtension: () => hasComponentExtension,
|
|
36
|
+
isStorybookStory: () => isStorybookStory,
|
|
37
|
+
isUngatedFor: () => isUngatedFor,
|
|
38
|
+
removeComponentExtension: () => removeComponentExtension,
|
|
39
|
+
renderComponentOnServer: () => renderComponentOnServer,
|
|
40
|
+
renderFieldsToJson: () => renderFieldsToJson,
|
|
41
|
+
renderOnServer: () => renderOnServer,
|
|
42
|
+
renderStreamToPromise: () => renderStreamToPromise,
|
|
43
|
+
resolveIslandPlugin: () => resolveIslandPlugin,
|
|
44
|
+
serializeIslandDataToJSON: () => serializeIslandDataToJSON,
|
|
45
|
+
setIn: () => setIn,
|
|
46
|
+
ungatedAtBuildTimeFor: () => ungatedAtBuildTimeFor,
|
|
47
|
+
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
|
|
48
|
+
});
|
|
49
|
+
import path, { basename } from "path";
|
|
50
|
+
import { createRequire } from "module";
|
|
51
|
+
import * as jsxRuntime from "react/jsx-runtime";
|
|
52
|
+
import stream from "stream";
|
|
53
|
+
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
54
|
+
import { createServerRenderContext, ServerRenderContext } from "@hubspot/cms-components";
|
|
55
|
+
import { createHash } from "crypto";
|
|
56
|
+
import { existsSync, readdirSync, lstatSync } from "fs";
|
|
57
|
+
import { join } from "path/posix";
|
|
58
|
+
import { cloneElement } from "react";
|
|
59
|
+
function createPreloadLink(assetPath, basePath = "") {
|
|
60
|
+
if (assetPath && assetPath[0] !== "/") {
|
|
61
|
+
assetPath = `/${assetPath}`;
|
|
62
|
+
}
|
|
63
|
+
if (assetPath.endsWith(".js")) {
|
|
64
|
+
return `<link rel="modulepreload" crossorigin href="${basePath}${assetPath}">`;
|
|
65
|
+
} else if (CSS_LANGS_RE.test(assetPath)) {
|
|
66
|
+
return `<link rel="stylesheet" href="${basePath}${assetPath}?css">`;
|
|
67
|
+
} else if (assetPath.endsWith(".woff")) {
|
|
68
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="font" type="font/woff" crossorigin>`;
|
|
69
|
+
} else if (assetPath.endsWith(".woff2")) {
|
|
70
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="font" type="font/woff2" crossorigin>`;
|
|
71
|
+
} else if (assetPath.endsWith(".gif")) {
|
|
72
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="image" type="image/gif">`;
|
|
73
|
+
} else if (assetPath.endsWith(".jpg") || assetPath.endsWith(".jpeg")) {
|
|
74
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="image" type="image/jpeg">`;
|
|
75
|
+
} else if (assetPath.endsWith(".png")) {
|
|
76
|
+
return ` <link rel="preload" href="${basePath}${assetPath}" as="image" type="image/png">`;
|
|
77
|
+
} else {
|
|
78
|
+
throw new Error(`Unknown preload type for ${assetPath}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function getIslandUrls(roots, viteDevServer) {
|
|
82
|
+
return roots.map((island) => {
|
|
83
|
+
const islandModule = viteDevServer.moduleGraph.getModuleById(
|
|
84
|
+
island.moduleId
|
|
85
|
+
);
|
|
86
|
+
if (!islandModule) {
|
|
87
|
+
throw new Error(`Unknown island moduleId: ${island.moduleId}`);
|
|
88
|
+
}
|
|
89
|
+
const tweakedIsland = {
|
|
90
|
+
...island,
|
|
91
|
+
url: islandModule.url
|
|
92
|
+
};
|
|
93
|
+
return tweakedIsland;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function isUngatedFor(gates, gate) {
|
|
97
|
+
return gates.includes(gate);
|
|
98
|
+
}
|
|
99
|
+
function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
100
|
+
try {
|
|
101
|
+
console.log("loading path", path.join(buildDir, BUILD_INFO_PATH));
|
|
102
|
+
const buildInfo = require2(path.join(
|
|
103
|
+
buildDir,
|
|
104
|
+
BUILD_INFO_PATH
|
|
105
|
+
));
|
|
106
|
+
return isUngatedFor(buildInfo.gates, gate);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function resolveIslandPlugin(gates) {
|
|
113
|
+
const sharedDepsEnabled = isUngatedFor(gates, "CMS:JSRenderer:SharedDeps");
|
|
114
|
+
return {
|
|
115
|
+
enforce: "pre",
|
|
116
|
+
name: "resolve-islands",
|
|
117
|
+
configResolved(config) {
|
|
118
|
+
viteRoot = config.root;
|
|
119
|
+
viteCommand = config.command;
|
|
120
|
+
},
|
|
121
|
+
load(id) {
|
|
122
|
+
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
123
|
+
const [idWithNoParam] = id.split("?");
|
|
124
|
+
const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
|
|
125
|
+
const componentExtension = path.extname(idWithNoParam);
|
|
126
|
+
const componentFilenameWithNoExtension = path.basename(
|
|
127
|
+
idWithNoParam,
|
|
128
|
+
componentExtension
|
|
129
|
+
);
|
|
130
|
+
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
131
|
+
let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
|
|
132
|
+
if (sharedDepsEnabled) {
|
|
133
|
+
moduleId = moduleId.concat("?client-entry");
|
|
134
|
+
}
|
|
135
|
+
return `
|
|
136
|
+
const moduleId = '${moduleId}';
|
|
137
|
+
|
|
138
|
+
const lazyComponent = () => import('${islandModuleImportPath}');
|
|
139
|
+
lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
|
|
140
|
+
lazyComponent.moduleId = moduleId;
|
|
141
|
+
|
|
142
|
+
export default lazyComponent;
|
|
143
|
+
`;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function clientIslandEntryPlugin() {
|
|
150
|
+
return {
|
|
151
|
+
enforce: "pre",
|
|
152
|
+
name: "client-island-entry-plugin",
|
|
153
|
+
resolveId(id) {
|
|
154
|
+
if (id === virtualClientRenderIslandModuleId) {
|
|
155
|
+
return virtualClientRenderIslandModuleId;
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
},
|
|
159
|
+
load(id) {
|
|
160
|
+
if (id.endsWith("?client-entry")) {
|
|
161
|
+
const [idWithNoParam] = id.split("?");
|
|
162
|
+
return `
|
|
163
|
+
import { clientRenderIsland } from '${virtualClientRenderIslandModuleId}';
|
|
164
|
+
import Component from '${idWithNoParam}';
|
|
165
|
+
|
|
166
|
+
export function render(island) {
|
|
167
|
+
return clientRenderIsland(island, Component)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export default Component;
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
if (id === virtualClientRenderIslandModuleId) {
|
|
174
|
+
return clientRenderIsland;
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, renderOptions) {
|
|
181
|
+
const componentDebugName = Component.displayName || Component.name;
|
|
182
|
+
return renderOnServer(
|
|
183
|
+
/* @__PURE__ */ jsx2(Component, { ...props }),
|
|
184
|
+
pageUrl,
|
|
185
|
+
environmentConfig,
|
|
186
|
+
componentDebugName,
|
|
187
|
+
renderOptions
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, debugName, renderOptions) {
|
|
191
|
+
const renderContext = createServerRenderContext(pageUrl, environmentConfig);
|
|
192
|
+
let html = await renderStreamToPromise(
|
|
193
|
+
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
194
|
+
renderOptions
|
|
195
|
+
);
|
|
196
|
+
if (renderContext.messagesForBrowser.length > 0) {
|
|
197
|
+
html = `${html}${scriptTagToLogServerMessages(
|
|
198
|
+
renderContext.messagesForBrowser,
|
|
199
|
+
`Server messages rendering: ${debugName}`
|
|
200
|
+
)}`;
|
|
201
|
+
}
|
|
202
|
+
return { html, renderContext };
|
|
203
|
+
}
|
|
204
|
+
function getEntryPointHash(entryPoint) {
|
|
205
|
+
return createHash("md5").update(entryPoint).digest("hex").slice(0, 6);
|
|
206
|
+
}
|
|
207
|
+
function getEntryPointHashWithIndexSuffix(entryPoint, index) {
|
|
208
|
+
const renderIndexSuffix = index != null ? `i${index}` : "";
|
|
209
|
+
return `${getEntryPointHash(entryPoint)}${renderIndexSuffix}`;
|
|
210
|
+
}
|
|
211
|
+
function getCombinedReactUrl() {
|
|
212
|
+
const hsEnv = process.env.HS_ENV;
|
|
213
|
+
const fileVersion = hsEnv === "prod" ? `react-combined.mjs` : "react-combined-qa.mjs";
|
|
214
|
+
return `${COMBINED_REACT_BASE_PATH}/${fileVersion}`;
|
|
215
|
+
}
|
|
216
|
+
function getIslandRuntimeConfigUrl() {
|
|
217
|
+
const hsEnv = process.env.HS_ENV;
|
|
218
|
+
const fileVersion = hsEnv === "prod" ? `island-runtime.mjs` : "island-runtime-qa.mjs";
|
|
219
|
+
return `${ISLAND_RUNTIME_CONFIG_BASE_PATH}/${fileVersion}`;
|
|
220
|
+
}
|
|
221
|
+
function findAllModulesInRoot(webRoot2) {
|
|
222
|
+
const allModuleComponents = findAllComponentsIn(
|
|
223
|
+
webRoot2,
|
|
224
|
+
"./components/modules",
|
|
225
|
+
true
|
|
226
|
+
);
|
|
227
|
+
const moduleNames = Object.keys(allModuleComponents).map(
|
|
228
|
+
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
229
|
+
);
|
|
230
|
+
const moduleSubpaths = Object.keys(allModuleComponents);
|
|
231
|
+
return { moduleNames, moduleSubpaths };
|
|
232
|
+
}
|
|
233
|
+
function findAllPartialsInRoot(webRoot2) {
|
|
234
|
+
const allPartialComponents = findAllComponentsIn(
|
|
235
|
+
webRoot2,
|
|
236
|
+
"./components/partials",
|
|
237
|
+
false
|
|
238
|
+
);
|
|
239
|
+
const partialSubpaths = Object.keys(allPartialComponents);
|
|
240
|
+
const partialNames = partialSubpaths.map(
|
|
241
|
+
(partialSubpath) => basename(partialSubpath)
|
|
242
|
+
);
|
|
243
|
+
return { partialNames, partialSubpaths };
|
|
244
|
+
}
|
|
245
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl) {
|
|
246
|
+
const globals = [
|
|
247
|
+
`window.__hsEnvConfig = ${JSON.stringify(environmentConfig.toJSON())};`
|
|
248
|
+
];
|
|
249
|
+
if (hsServerPageUrl) {
|
|
250
|
+
globals.push(`window.__hsServerPageUrl = '${hsServerPageUrl}';`);
|
|
251
|
+
}
|
|
252
|
+
return `
|
|
253
|
+
<script type="text/javascript">
|
|
254
|
+
${globals.join("\n ")}
|
|
255
|
+
</script>
|
|
256
|
+
`;
|
|
257
|
+
}
|
|
258
|
+
function setIn(object, nestedKeysArray, value) {
|
|
259
|
+
let curr = object;
|
|
260
|
+
const finalKey = nestedKeysArray.pop();
|
|
261
|
+
for (let index = 0; index < nestedKeysArray.length; index++) {
|
|
262
|
+
const currentKey = nestedKeysArray[index];
|
|
263
|
+
const nextKey = nestedKeysArray[index + 1];
|
|
264
|
+
if (Number.isInteger(nextKey) || !nextKey && Number.isInteger(finalKey)) {
|
|
265
|
+
if (curr[currentKey] === void 0) {
|
|
266
|
+
curr[currentKey] = [];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (curr[currentKey] === void 0) {
|
|
270
|
+
curr[currentKey] = {};
|
|
271
|
+
}
|
|
272
|
+
curr = curr[currentKey];
|
|
273
|
+
}
|
|
274
|
+
if (value !== void 0) {
|
|
275
|
+
curr[finalKey] = value;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function renderFieldsToJson(fields) {
|
|
279
|
+
let moduleJson;
|
|
280
|
+
const outputCallback = (callbackJson) => {
|
|
281
|
+
moduleJson = callbackJson;
|
|
282
|
+
};
|
|
283
|
+
renderToStaticMarkup(
|
|
284
|
+
cloneElement(fields, {
|
|
285
|
+
outputCallback
|
|
286
|
+
})
|
|
287
|
+
);
|
|
288
|
+
return moduleJson;
|
|
289
|
+
}
|
|
290
|
+
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, require2, GATES, BUILD_INFO_PATH, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, findAllComponentsIn;
|
|
291
|
+
var init_dist = __esm({
|
|
292
|
+
"../cms-js-internal/dist/index.js"() {
|
|
293
|
+
COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
294
|
+
ENTRY_POINTS_PATH = "components/partials/";
|
|
295
|
+
MODULE_FOLDER_PATH = "components/modules/";
|
|
296
|
+
VIRTUAL_ISLAND_RUNTIME = "virtual:island-runtime";
|
|
297
|
+
VIRTUAL_CONFIG_SETUP = "virtual:config-setup";
|
|
298
|
+
CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
299
|
+
collectCssModules = (modulePathToStartWith, viteServer, cssModulesImported = /* @__PURE__ */ new Set()) => {
|
|
300
|
+
const appModulesForPath = viteServer.moduleGraph.fileToModulesMap.get(
|
|
301
|
+
modulePathToStartWith
|
|
302
|
+
);
|
|
303
|
+
if (!appModulesForPath || appModulesForPath.size === 0) {
|
|
304
|
+
throw new Error(`No modules at: ${modulePathToStartWith}`);
|
|
305
|
+
} else if (appModulesForPath.size > 1) {
|
|
306
|
+
throw new Error(`More than one module at: ${modulePathToStartWith}`);
|
|
307
|
+
}
|
|
308
|
+
const appModule = Array.from(appModulesForPath.values())[0];
|
|
309
|
+
const allServerSideModulesImported = /* @__PURE__ */ new Set();
|
|
310
|
+
const newCssModules = [];
|
|
311
|
+
const moduleQueue = Array.from(appModule.importedModules);
|
|
312
|
+
for (const importedModule of moduleQueue) {
|
|
313
|
+
if (allServerSideModulesImported.has(importedModule.id)) {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
allServerSideModulesImported.add(importedModule.id);
|
|
317
|
+
const isCss = CSS_LANGS_RE.test(importedModule.file);
|
|
318
|
+
const moduleModulesToQueue = Array.from(importedModule.importedModules);
|
|
319
|
+
if (isCss && !cssModulesImported.has(importedModule)) {
|
|
320
|
+
cssModulesImported.add(importedModule);
|
|
321
|
+
newCssModules.push(importedModule);
|
|
322
|
+
}
|
|
323
|
+
moduleQueue.push(...moduleModulesToQueue);
|
|
324
|
+
}
|
|
325
|
+
return newCssModules;
|
|
326
|
+
};
|
|
327
|
+
collectCssInDev = (modulePathToStartWith, viteServer, cssModulesImported = /* @__PURE__ */ new Set()) => {
|
|
328
|
+
return `${collectCssModules(
|
|
329
|
+
modulePathToStartWith,
|
|
330
|
+
viteServer,
|
|
331
|
+
cssModulesImported
|
|
332
|
+
).map((cssModule) => createPreloadLink(cssModule.url)).join("\n")}
|
|
333
|
+
`;
|
|
334
|
+
};
|
|
335
|
+
serializeIslandDataToJSON = (tweakedIslandsArray, indent = 0) => {
|
|
336
|
+
const indentString = new Array(indent).fill(" ").join("");
|
|
337
|
+
return `${JSON.stringify(
|
|
338
|
+
tweakedIslandsArray.map(
|
|
339
|
+
({
|
|
340
|
+
id,
|
|
341
|
+
moduleName,
|
|
342
|
+
moduleId,
|
|
343
|
+
props,
|
|
344
|
+
hydrateOn,
|
|
345
|
+
clientOnly,
|
|
346
|
+
priority,
|
|
347
|
+
url,
|
|
348
|
+
sharedStateID
|
|
349
|
+
}) => {
|
|
350
|
+
const output = {
|
|
351
|
+
id,
|
|
352
|
+
moduleName,
|
|
353
|
+
moduleId,
|
|
354
|
+
hydrateOn,
|
|
355
|
+
clientOnly,
|
|
356
|
+
priority,
|
|
357
|
+
props,
|
|
358
|
+
url
|
|
359
|
+
};
|
|
360
|
+
if (sharedStateID) {
|
|
361
|
+
output.sharedStateID = sharedStateID;
|
|
362
|
+
}
|
|
363
|
+
return output;
|
|
364
|
+
}
|
|
365
|
+
),
|
|
366
|
+
null,
|
|
367
|
+
2
|
|
368
|
+
).replace(/\n/gm, `
|
|
369
|
+
${indentString}`)}`;
|
|
370
|
+
};
|
|
371
|
+
writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0) => {
|
|
372
|
+
const indentString = new Array(indent).fill(" ").join("");
|
|
373
|
+
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
|
|
374
|
+
if (sharedStateIDs.length > 0) {
|
|
375
|
+
const stateByID = {};
|
|
376
|
+
sharedStateIDs.forEach(
|
|
377
|
+
(id) => stateByID[id] = perServerRequestData.get(id)
|
|
378
|
+
);
|
|
379
|
+
const stringifiedState = JSON.stringify(stateByID, null, 2);
|
|
380
|
+
return `
|
|
381
|
+
|
|
382
|
+
var newState = ${stringifiedState};
|
|
383
|
+
if(window.__hsSSInit) {
|
|
384
|
+
window.__hsSSInit = Object.assign(window.__hsSSInit, newState);
|
|
385
|
+
} else {
|
|
386
|
+
window.__hsSSInit = newState;
|
|
387
|
+
}`.replace(/\n/gm, `
|
|
388
|
+
${indentString}`);
|
|
389
|
+
}
|
|
390
|
+
return "";
|
|
391
|
+
};
|
|
392
|
+
createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent) => {
|
|
393
|
+
const islands = getIslandUrls(roots, viteDevServer);
|
|
394
|
+
return `window.__islands = ${serializeIslandDataToJSON(
|
|
395
|
+
islands,
|
|
396
|
+
indent
|
|
397
|
+
)}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
|
|
398
|
+
};
|
|
399
|
+
require2 = createRequire(import.meta.url);
|
|
400
|
+
GATES = [
|
|
401
|
+
"CMS:JSRenderer:SharedDeps",
|
|
402
|
+
"CMS:JSRenderer:GetServerSideProps",
|
|
403
|
+
"CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
404
|
+
"CMS:JSRenderer:GraphQLQueryBuild"
|
|
405
|
+
];
|
|
406
|
+
BUILD_INFO_PATH = "/build-info.json";
|
|
407
|
+
clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: `island-${renderableIsland.index}-`,\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
408
|
+
virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
409
|
+
jsx2 = jsxRuntime.jsx;
|
|
410
|
+
promiseForNewWritableStream = () => {
|
|
411
|
+
const chunks = [];
|
|
412
|
+
const writableStream = new stream.Writable();
|
|
413
|
+
writableStream._write = (chunk, encoding, done) => {
|
|
414
|
+
chunks.push(Buffer.from(chunk));
|
|
415
|
+
done();
|
|
416
|
+
};
|
|
417
|
+
const streamDonePromise = new Promise((resolve, reject) => {
|
|
418
|
+
writableStream.on("error", (error) => {
|
|
419
|
+
reject(error);
|
|
420
|
+
});
|
|
421
|
+
writableStream._final = (done) => {
|
|
422
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
423
|
+
done();
|
|
424
|
+
};
|
|
425
|
+
});
|
|
426
|
+
return { streamDonePromise, writableStream };
|
|
427
|
+
};
|
|
428
|
+
renderStreamToPromise = async (reactElements, renderOptions = {}) => {
|
|
429
|
+
const { streamDonePromise, writableStream } = promiseForNewWritableStream();
|
|
430
|
+
const {
|
|
431
|
+
pipe
|
|
432
|
+
/* abort */
|
|
433
|
+
} = renderToPipeableStream(reactElements, {
|
|
434
|
+
...renderOptions,
|
|
435
|
+
onShellReady() {
|
|
436
|
+
},
|
|
437
|
+
onAllReady() {
|
|
438
|
+
pipe(writableStream);
|
|
439
|
+
}
|
|
440
|
+
// We will log the error sent to the writable, any need to do something in these callbacks?
|
|
441
|
+
// onShellError(error) {},
|
|
442
|
+
// onError(error) {},
|
|
443
|
+
});
|
|
444
|
+
return streamDonePromise;
|
|
445
|
+
};
|
|
446
|
+
scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
|
|
447
|
+
if (!messagesForBrowser) {
|
|
448
|
+
return "";
|
|
449
|
+
}
|
|
450
|
+
const consoleLines = [];
|
|
451
|
+
for (const message of messagesForBrowser) {
|
|
452
|
+
const funcString = message.level === "error" ? "console.error" : "console.warn";
|
|
453
|
+
const argString = message.parameters.map((arg) => JSON.stringify(arg)).join(", ");
|
|
454
|
+
consoleLines.push(` ${funcString}(${argString});`);
|
|
455
|
+
}
|
|
456
|
+
let groupStart = "";
|
|
457
|
+
let groupEnd = "";
|
|
458
|
+
if (groupLabel !== null) {
|
|
459
|
+
groupStart = `
|
|
460
|
+
console.group(${JSON.stringify(groupLabel)});`;
|
|
461
|
+
groupEnd = ` console.groupEnd()
|
|
462
|
+
`;
|
|
463
|
+
}
|
|
464
|
+
return `<script>${groupStart}
|
|
465
|
+
${consoleLines.join("\n")}
|
|
466
|
+
${groupEnd}</script>
|
|
467
|
+
`;
|
|
468
|
+
};
|
|
469
|
+
getComponentExtension = (componentPath) => {
|
|
470
|
+
const filteredExtensions = COMPONENT_EXTENSIONS.filter(
|
|
471
|
+
(ext) => componentPath.endsWith(ext)
|
|
472
|
+
);
|
|
473
|
+
if (filteredExtensions.length === 1) {
|
|
474
|
+
return filteredExtensions[0];
|
|
475
|
+
}
|
|
476
|
+
return void 0;
|
|
477
|
+
};
|
|
478
|
+
hasComponentExtension = (componentPath) => {
|
|
479
|
+
return !!getComponentExtension(componentPath);
|
|
480
|
+
};
|
|
481
|
+
isStorybookStory = (componentPath) => {
|
|
482
|
+
return !!path.basename(componentPath, path.extname(componentPath)).endsWith(".stories");
|
|
483
|
+
};
|
|
484
|
+
removeComponentExtension = (componentPath) => {
|
|
485
|
+
const ext = getComponentExtension(componentPath);
|
|
486
|
+
if (ext == null) {
|
|
487
|
+
return componentPath;
|
|
488
|
+
}
|
|
489
|
+
return componentPath.slice(0, -1 * ext.length);
|
|
490
|
+
};
|
|
491
|
+
COMBINED_REACT_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/react/v18";
|
|
492
|
+
ISLAND_RUNTIME_CONFIG_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/island-runtime/v1";
|
|
493
|
+
findAllComponentsIn = (webRoot2, componentsFolder, includeSubdirIndexJS) => {
|
|
494
|
+
const fullComponentsFolderPath = join(webRoot2, componentsFolder);
|
|
495
|
+
const componentsByName = {};
|
|
496
|
+
if (!existsSync(fullComponentsFolderPath)) {
|
|
497
|
+
return componentsByName;
|
|
498
|
+
}
|
|
499
|
+
readdirSync(fullComponentsFolderPath).forEach((fileOrFolderName) => {
|
|
500
|
+
const fullPath = join(fullComponentsFolderPath, fileOrFolderName);
|
|
501
|
+
const subdirPath = join(componentsFolder, fileOrFolderName);
|
|
502
|
+
const isDirectory = lstatSync(fullPath).isDirectory();
|
|
503
|
+
if (!isDirectory && hasComponentExtension(fileOrFolderName) && !isStorybookStory(fileOrFolderName)) {
|
|
504
|
+
const subdirPathNoExtension = removeComponentExtension(subdirPath);
|
|
505
|
+
componentsByName[subdirPathNoExtension] = subdirPath;
|
|
506
|
+
} else if (isDirectory && includeSubdirIndexJS) {
|
|
507
|
+
for (const potentialExtension of COMPONENT_EXTENSIONS) {
|
|
508
|
+
const potentialIndexModule = join(
|
|
509
|
+
subdirPath,
|
|
510
|
+
`index${potentialExtension}`
|
|
511
|
+
);
|
|
512
|
+
const fullPotentialPath = join(
|
|
513
|
+
fullPath,
|
|
514
|
+
`index${potentialExtension}`
|
|
515
|
+
);
|
|
516
|
+
if (existsSync(fullPotentialPath)) {
|
|
517
|
+
const moduleIndexPathNoExtension = removeComponentExtension(potentialIndexModule);
|
|
518
|
+
componentsByName[moduleIndexPathNoExtension] = potentialIndexModule;
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
return componentsByName;
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
// src/storybook/main.ts
|
|
530
|
+
import path2 from "path";
|
|
531
|
+
import { mergeConfig } from "vite";
|
|
532
|
+
var webRoot = process.env.WEB_ROOT;
|
|
533
|
+
var storyPath = path2.resolve(process.cwd(), webRoot, "**/*.stories.*");
|
|
534
|
+
var jsRenderingGates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
535
|
+
var main_default = {
|
|
536
|
+
addons: ["@storybook/addon-essentials"],
|
|
537
|
+
framework: "@storybook/react-vite",
|
|
538
|
+
stories: [storyPath],
|
|
539
|
+
viteFinal: async (config) => {
|
|
540
|
+
const { resolveIslandPlugin: resolveIslandPlugin2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
|
|
541
|
+
const viteConfig = {
|
|
542
|
+
resolve: {
|
|
543
|
+
dedupe: [
|
|
544
|
+
"react",
|
|
545
|
+
"react-dom",
|
|
546
|
+
"@hubspot/cms-components",
|
|
547
|
+
"@hubspot/cms-dev-server"
|
|
548
|
+
]
|
|
549
|
+
},
|
|
550
|
+
optimizeDeps: {
|
|
551
|
+
include: ["react", "react-dom", "react-dom/client"]
|
|
552
|
+
},
|
|
553
|
+
css: {
|
|
554
|
+
postcss: webRoot
|
|
555
|
+
},
|
|
556
|
+
plugins: [resolveIslandPlugin2(jsRenderingGates)]
|
|
557
|
+
};
|
|
558
|
+
return mergeConfig(config, viteConfig);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
export {
|
|
562
|
+
main_default as default
|
|
563
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.17",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@hubspot/cli-lib": "^3.0.12",
|
|
27
|
-
"@hubspot/cms-components": "^0.4.
|
|
27
|
+
"@hubspot/cms-components": "^0.4.17",
|
|
28
28
|
"@storybook/addon-actions": "^7.0.0-beta.19",
|
|
29
29
|
"@storybook/addon-essentials": "^7.0.0-beta.19",
|
|
30
30
|
"@storybook/addon-interactions": "^7.0.0-beta.19",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"publishConfig": {
|
|
96
96
|
"access": "public"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "68c175a46f2237b7fb2827764c4ab5655969992c"
|
|
99
99
|
}
|