@hubspot/cms-dev-server 0.7.1 → 0.7.7
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/index.js +7 -18
- package/dist/internalSsr.js +29 -37
- package/dist/island-runtime.js +24 -28
- package/dist/run.js +85 -112
- package/dist/storybook-main/main.js +31 -39
- package/package.json +3 -3
- package/types/createViteDevServer.d.ts +1 -1
- package/dist/fsevents-72LCIACT.node +0 -0
package/dist/index.js
CHANGED
|
@@ -4,13 +4,9 @@ import { default as react } from "@vitejs/plugin-react";
|
|
|
4
4
|
|
|
5
5
|
// ../cms-js-internal/dist/index.js
|
|
6
6
|
import path, { basename } from "path";
|
|
7
|
-
function isUngatedFor(gates, gate) {
|
|
8
|
-
return gates.includes(gate);
|
|
9
|
-
}
|
|
10
7
|
var viteRoot;
|
|
11
8
|
var viteCommand;
|
|
12
|
-
function resolveIslandPlugin(
|
|
13
|
-
const sharedDepsEnabled = isUngatedFor(gates, "CMS:JSRenderer:SharedDeps");
|
|
9
|
+
function resolveIslandPlugin() {
|
|
14
10
|
return {
|
|
15
11
|
enforce: "pre",
|
|
16
12
|
name: "resolve-islands",
|
|
@@ -21,17 +17,14 @@ function resolveIslandPlugin(gates) {
|
|
|
21
17
|
load(id) {
|
|
22
18
|
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
23
19
|
const [idWithNoParam] = id.split("?");
|
|
24
|
-
const islandModuleImportPath =
|
|
20
|
+
const islandModuleImportPath = `${idWithNoParam}?client-entry`;
|
|
25
21
|
const componentExtension = path.extname(idWithNoParam);
|
|
26
22
|
const componentFilenameWithNoExtension = path.basename(
|
|
27
23
|
idWithNoParam,
|
|
28
24
|
componentExtension
|
|
29
25
|
);
|
|
30
26
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
31
|
-
|
|
32
|
-
if (sharedDepsEnabled) {
|
|
33
|
-
moduleId = moduleId.concat("?client-entry");
|
|
34
|
-
}
|
|
27
|
+
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
35
28
|
return `
|
|
36
29
|
const moduleId = '${moduleId}';
|
|
37
30
|
|
|
@@ -46,7 +39,7 @@ function resolveIslandPlugin(gates) {
|
|
|
46
39
|
}
|
|
47
40
|
};
|
|
48
41
|
}
|
|
49
|
-
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {
|
|
42
|
+
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: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
50
43
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
51
44
|
function clientIslandEntryPlugin() {
|
|
52
45
|
return {
|
|
@@ -82,11 +75,7 @@ function clientIslandEntryPlugin() {
|
|
|
82
75
|
|
|
83
76
|
// src/createViteDevServer.ts
|
|
84
77
|
import mkcert from "vite-plugin-mkcert";
|
|
85
|
-
async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [],
|
|
86
|
-
const sharedDepsEnabled = isUngatedFor(
|
|
87
|
-
jsRenderingGates,
|
|
88
|
-
"CMS:JSRenderer:SharedDeps"
|
|
89
|
-
);
|
|
78
|
+
async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], __jsRenderingGates) {
|
|
90
79
|
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
91
80
|
`${proxyDomain}.localhost`,
|
|
92
81
|
`${proxyDomain}.hslocal.net`
|
|
@@ -123,8 +112,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
123
112
|
plugins: [
|
|
124
113
|
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
125
114
|
react(),
|
|
126
|
-
|
|
127
|
-
resolveIslandPlugin(
|
|
115
|
+
clientIslandEntryPlugin(),
|
|
116
|
+
resolveIslandPlugin()
|
|
128
117
|
],
|
|
129
118
|
css: {
|
|
130
119
|
postcss: webRoot
|
package/dist/internalSsr.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// ../cms-js-internal/dist/index.js
|
|
2
2
|
import path, { basename } from "path";
|
|
3
|
-
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
4
3
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
5
4
|
import stream from "stream";
|
|
6
5
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
7
6
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
8
7
|
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
9
8
|
import { createHash } from "crypto";
|
|
9
|
+
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
10
10
|
import { join } from "path/posix";
|
|
11
11
|
import { cloneElement } from "react";
|
|
12
12
|
var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
@@ -181,38 +181,9 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
181
181
|
indent
|
|
182
182
|
)}`;
|
|
183
183
|
};
|
|
184
|
-
var GATES = [
|
|
185
|
-
"CMS:JSRenderer:SharedDeps",
|
|
186
|
-
"CMS:JSRenderer:GetServerSideProps",
|
|
187
|
-
"CMS:JSRenderer:GraphQLQueryBuild",
|
|
188
|
-
"CMS:JSRenderer:SeparateIslandRenderOption"
|
|
189
|
-
];
|
|
190
|
-
var ENABLED_FEATURES_GATE_MAP = {
|
|
191
|
-
"cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
|
|
192
|
-
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
193
|
-
"cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild",
|
|
194
|
-
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
195
|
-
};
|
|
196
|
-
function isUngatedFor(gates, gate) {
|
|
197
|
-
return gates.includes(gate);
|
|
198
|
-
}
|
|
199
|
-
var BUILD_INFO_PATH = "/build-info.json";
|
|
200
|
-
function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
201
|
-
try {
|
|
202
|
-
console.log("loading path", path.join(buildDir, BUILD_INFO_PATH));
|
|
203
|
-
const buildInfo = JSON.parse(
|
|
204
|
-
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
205
|
-
);
|
|
206
|
-
return isUngatedFor(buildInfo.gates, gate);
|
|
207
|
-
} catch (e) {
|
|
208
|
-
console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
184
|
var viteRoot;
|
|
213
185
|
var viteCommand;
|
|
214
|
-
function resolveIslandPlugin(
|
|
215
|
-
const sharedDepsEnabled = isUngatedFor(gates, "CMS:JSRenderer:SharedDeps");
|
|
186
|
+
function resolveIslandPlugin() {
|
|
216
187
|
return {
|
|
217
188
|
enforce: "pre",
|
|
218
189
|
name: "resolve-islands",
|
|
@@ -223,17 +194,14 @@ function resolveIslandPlugin(gates) {
|
|
|
223
194
|
load(id) {
|
|
224
195
|
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
225
196
|
const [idWithNoParam] = id.split("?");
|
|
226
|
-
const islandModuleImportPath =
|
|
197
|
+
const islandModuleImportPath = `${idWithNoParam}?client-entry`;
|
|
227
198
|
const componentExtension = path.extname(idWithNoParam);
|
|
228
199
|
const componentFilenameWithNoExtension = path.basename(
|
|
229
200
|
idWithNoParam,
|
|
230
201
|
componentExtension
|
|
231
202
|
);
|
|
232
203
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
233
|
-
|
|
234
|
-
if (sharedDepsEnabled) {
|
|
235
|
-
moduleId = moduleId.concat("?client-entry");
|
|
236
|
-
}
|
|
204
|
+
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
237
205
|
return `
|
|
238
206
|
const moduleId = '${moduleId}';
|
|
239
207
|
|
|
@@ -248,7 +216,7 @@ function resolveIslandPlugin(gates) {
|
|
|
248
216
|
}
|
|
249
217
|
};
|
|
250
218
|
}
|
|
251
|
-
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {
|
|
219
|
+
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: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
252
220
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
253
221
|
function clientIslandEntryPlugin() {
|
|
254
222
|
return {
|
|
@@ -416,6 +384,30 @@ function getIslandRuntimeConfigUrl() {
|
|
|
416
384
|
const fileVersion = hsEnv === "prod" ? `island-runtime.mjs` : "island-runtime-qa.mjs";
|
|
417
385
|
return `${ISLAND_RUNTIME_CONFIG_BASE_PATH}/${fileVersion}`;
|
|
418
386
|
}
|
|
387
|
+
var GATES = [
|
|
388
|
+
"CMS:JSRenderer:GetServerSideProps",
|
|
389
|
+
"CMS:JSRenderer:SeparateIslandRenderOption"
|
|
390
|
+
];
|
|
391
|
+
var ENABLED_FEATURES_GATE_MAP = {
|
|
392
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
393
|
+
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
394
|
+
};
|
|
395
|
+
function isUngatedFor(gates, gate) {
|
|
396
|
+
return gates.includes(gate);
|
|
397
|
+
}
|
|
398
|
+
var BUILD_INFO_PATH = "/build-info.json";
|
|
399
|
+
function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
400
|
+
try {
|
|
401
|
+
console.log("loading path", path.join(buildDir, BUILD_INFO_PATH));
|
|
402
|
+
const buildInfo = JSON.parse(
|
|
403
|
+
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
404
|
+
);
|
|
405
|
+
return isUngatedFor(buildInfo.gates, gate);
|
|
406
|
+
} catch (e) {
|
|
407
|
+
console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
419
411
|
var findAllComponentsIn = (webRoot, componentsFolder, includeSubdirIndexJS) => {
|
|
420
412
|
const fullComponentsFolderPath = join(webRoot, componentsFolder);
|
|
421
413
|
const componentsByName = {};
|
package/dist/island-runtime.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
// ../cms-js-internal/dist/island-runtime/island-runtime.js
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var onVisible = (islandEl, callback) => {
|
|
3
|
+
const observer = new IntersectionObserver((entries) => {
|
|
4
|
+
if (entries.some((entry) => entry.isIntersecting)) {
|
|
5
|
+
observer.disconnect();
|
|
6
|
+
callback();
|
|
7
|
+
}
|
|
8
|
+
return;
|
|
9
|
+
});
|
|
10
|
+
for (let i = 0; i < islandEl.children.length; i++) {
|
|
11
|
+
const child = islandEl.children[i];
|
|
12
|
+
observer.observe(child);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
6
15
|
var rootsToProcess;
|
|
7
16
|
var hydrationQueue = [];
|
|
8
17
|
var hydrationTypesToAccept = /* @__PURE__ */ new Set(["load", "visible"]);
|
|
@@ -14,8 +23,8 @@ var typedWindow = window;
|
|
|
14
23
|
var startHydratingIdleRoots = () => {
|
|
15
24
|
hydrationTypesToAccept.add("idle");
|
|
16
25
|
for (const root of rootsToProcess) {
|
|
17
|
-
if (root.hydrationStatus === HYDRATION_WAITING && hydrationTypesToAccept.has(root.hydrateOn)) {
|
|
18
|
-
root.hydrationStatus = HYDRATION_PREPARING;
|
|
26
|
+
if (root.hydrationStatus === "HYDRATION_WAITING" && hydrationTypesToAccept.has(root.hydrateOn)) {
|
|
27
|
+
root.hydrationStatus = "HYDRATION_PREPARING";
|
|
19
28
|
waitThenLoadAndHydrateIfNeeded(root, getLoadableModuleFor(root));
|
|
20
29
|
}
|
|
21
30
|
}
|
|
@@ -35,7 +44,7 @@ function setupIdleCallbackIfNeeded() {
|
|
|
35
44
|
}
|
|
36
45
|
}
|
|
37
46
|
function finishHydratingRootAndScheduleNext(rootAndExtraInfo) {
|
|
38
|
-
rootAndExtraInfo.root.hydrationStatus = HYDRATED;
|
|
47
|
+
rootAndExtraInfo.root.hydrationStatus = "HYDRATED";
|
|
39
48
|
hydrationQueue = hydrationQueue.filter(
|
|
40
49
|
(x) => x.root.id !== rootAndExtraInfo.root.id
|
|
41
50
|
);
|
|
@@ -62,10 +71,10 @@ function hydrateRoot(rootAndExtraInfo) {
|
|
|
62
71
|
index: rootAndExtraInfo.islandScheduledIndex
|
|
63
72
|
};
|
|
64
73
|
const reactRoot = IslandModule.render(renderableIsland);
|
|
65
|
-
rootsById
|
|
74
|
+
rootsById.set(root.id, reactRoot);
|
|
66
75
|
}
|
|
67
76
|
function pushToHydrationQueue(rootAndExtraInfo) {
|
|
68
|
-
rootAndExtraInfo.root.hydrationStatus = HYDRATION_QUEUED;
|
|
77
|
+
rootAndExtraInfo.root.hydrationStatus = "HYDRATION_QUEUED";
|
|
69
78
|
hydrationQueue.push(rootAndExtraInfo);
|
|
70
79
|
if (hydrationQueue.length === 1) {
|
|
71
80
|
hydrateRoot(rootAndExtraInfo);
|
|
@@ -97,7 +106,7 @@ function waitThenLoadAndHydrateIfNeeded(root, LoadableIslandModule) {
|
|
|
97
106
|
}
|
|
98
107
|
}
|
|
99
108
|
function getLoadableModuleFor(root) {
|
|
100
|
-
let url = `${window.location.origin}${root.url}`;
|
|
109
|
+
let url = root.url.startsWith("https://") || root.url.startsWith("http://") || root.url.startsWith("//") ? root.url : `${window.location.origin}${root.url}`;
|
|
101
110
|
if (shouldForceSeparateJsForAllIslands) {
|
|
102
111
|
url = `${root.url}?cacheBust=${Date.now()}-${root.id}`;
|
|
103
112
|
}
|
|
@@ -121,10 +130,10 @@ function hydrateIslandRoots() {
|
|
|
121
130
|
let encounteredAnyNonIdleIslands = false;
|
|
122
131
|
for (const root of rootsToProcess) {
|
|
123
132
|
if (!root.hydrationStatus) {
|
|
124
|
-
root.hydrationStatus = root.hydrationStatus || HYDRATION_WAITING;
|
|
133
|
+
root.hydrationStatus = root.hydrationStatus || "HYDRATION_WAITING";
|
|
125
134
|
if (hydrationTypesToAccept.has(root.hydrateOn)) {
|
|
126
135
|
encounteredAnyNonIdleIslands = true;
|
|
127
|
-
root.hydrationStatus = HYDRATION_PREPARING;
|
|
136
|
+
root.hydrationStatus = "HYDRATION_PREPARING";
|
|
128
137
|
waitThenLoadAndHydrateIfNeeded(root, getLoadableModuleFor(root));
|
|
129
138
|
}
|
|
130
139
|
}
|
|
@@ -142,29 +151,16 @@ function setupIslandHydration() {
|
|
|
142
151
|
}
|
|
143
152
|
function unmountIsland(islandId) {
|
|
144
153
|
const islandToUnmount = rootsToProcess.find((island) => island.id === islandId);
|
|
145
|
-
if (!islandToUnmount || !rootsById
|
|
154
|
+
if (!islandToUnmount || !rootsById.get(islandId)) {
|
|
146
155
|
throw new Error(`No known island: ${islandId}`);
|
|
147
156
|
}
|
|
148
157
|
const islandIndex = rootsToProcess.indexOf(islandToUnmount);
|
|
149
|
-
const reactRoot = rootsById
|
|
158
|
+
const reactRoot = rootsById.get(islandId);
|
|
150
159
|
rootsToProcess.splice(islandIndex, 1);
|
|
151
|
-
delete
|
|
160
|
+
rootsById.delete(islandId);
|
|
152
161
|
console.log("Unmounting island:", islandId);
|
|
153
162
|
reactRoot.unmount();
|
|
154
163
|
}
|
|
155
|
-
var onVisible = (islandEl, callback) => {
|
|
156
|
-
const observer = new IntersectionObserver((entries) => {
|
|
157
|
-
if (entries.some((entry) => entry.isIntersecting)) {
|
|
158
|
-
observer.disconnect();
|
|
159
|
-
callback();
|
|
160
|
-
}
|
|
161
|
-
return;
|
|
162
|
-
});
|
|
163
|
-
for (let i = 0; i < islandEl.children.length; i++) {
|
|
164
|
-
const child = islandEl.children[i];
|
|
165
|
-
observer.observe(child);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
164
|
export {
|
|
169
165
|
setupIslandHydration,
|
|
170
166
|
unmountIsland
|
package/dist/run.js
CHANGED
|
@@ -39,7 +39,7 @@ import express2 from "express";
|
|
|
39
39
|
import http3 from "http";
|
|
40
40
|
import bodyParser from "body-parser";
|
|
41
41
|
import { spawn } from "child_process";
|
|
42
|
-
import { normalizePath as
|
|
42
|
+
import { normalizePath as normalizePath5 } from "vite";
|
|
43
43
|
import { Transform } from "stream";
|
|
44
44
|
|
|
45
45
|
// src/routes/createDevServerRoutes.ts
|
|
@@ -55,15 +55,34 @@ function fullOriginalUrlFromRequest(request2) {
|
|
|
55
55
|
return `${request2.protocol}://${request2.get("host")}${request2.originalUrl}`;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// src/lib/packagePath.ts
|
|
59
|
+
import path from "path";
|
|
60
|
+
import url from "url";
|
|
61
|
+
import { normalizePath } from "vite";
|
|
62
|
+
function packagePath(metaUrl, projectPath) {
|
|
63
|
+
if (true) {
|
|
64
|
+
return normalizePath(
|
|
65
|
+
path.resolve(path.dirname(url.fileURLToPath(metaUrl)), projectPath)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const parentDirPath = normalizePath(path.dirname(url.fileURLToPath(metaUrl)));
|
|
69
|
+
const subPath = parentDirPath.replace(/^.+cms-dev-server\/src\//, "");
|
|
70
|
+
const subPathParentDirs = subPath.split("/").map(() => "..");
|
|
71
|
+
return path.resolve(
|
|
72
|
+
path.dirname(url.fileURLToPath(metaUrl)),
|
|
73
|
+
path.join(...subPathParentDirs, projectPath)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
58
77
|
// ../cms-js-internal/dist/index.js
|
|
59
|
-
import
|
|
60
|
-
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
78
|
+
import path2, { basename } from "path";
|
|
61
79
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
62
80
|
import stream from "stream";
|
|
63
81
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
64
82
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
65
83
|
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
66
84
|
import { createHash } from "crypto";
|
|
85
|
+
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
67
86
|
import { join } from "path/posix";
|
|
68
87
|
import { cloneElement } from "react";
|
|
69
88
|
var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
@@ -177,19 +196,9 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
177
196
|
indent
|
|
178
197
|
)}`;
|
|
179
198
|
};
|
|
180
|
-
var ENABLED_FEATURES_GATE_MAP = {
|
|
181
|
-
"cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
|
|
182
|
-
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
183
|
-
"cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild",
|
|
184
|
-
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
185
|
-
};
|
|
186
|
-
function isUngatedFor(gates, gate) {
|
|
187
|
-
return gates.includes(gate);
|
|
188
|
-
}
|
|
189
199
|
var viteRoot;
|
|
190
200
|
var viteCommand;
|
|
191
|
-
function resolveIslandPlugin(
|
|
192
|
-
const sharedDepsEnabled = isUngatedFor(gates, "CMS:JSRenderer:SharedDeps");
|
|
201
|
+
function resolveIslandPlugin() {
|
|
193
202
|
return {
|
|
194
203
|
enforce: "pre",
|
|
195
204
|
name: "resolve-islands",
|
|
@@ -200,17 +209,14 @@ function resolveIslandPlugin(gates) {
|
|
|
200
209
|
load(id) {
|
|
201
210
|
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
202
211
|
const [idWithNoParam] = id.split("?");
|
|
203
|
-
const islandModuleImportPath =
|
|
204
|
-
const componentExtension =
|
|
205
|
-
const componentFilenameWithNoExtension =
|
|
212
|
+
const islandModuleImportPath = `${idWithNoParam}?client-entry`;
|
|
213
|
+
const componentExtension = path2.extname(idWithNoParam);
|
|
214
|
+
const componentFilenameWithNoExtension = path2.basename(
|
|
206
215
|
idWithNoParam,
|
|
207
216
|
componentExtension
|
|
208
217
|
);
|
|
209
218
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
210
|
-
|
|
211
|
-
if (sharedDepsEnabled) {
|
|
212
|
-
moduleId = moduleId.concat("?client-entry");
|
|
213
|
-
}
|
|
219
|
+
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
214
220
|
return `
|
|
215
221
|
const moduleId = '${moduleId}';
|
|
216
222
|
|
|
@@ -225,7 +231,7 @@ function resolveIslandPlugin(gates) {
|
|
|
225
231
|
}
|
|
226
232
|
};
|
|
227
233
|
}
|
|
228
|
-
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {
|
|
234
|
+
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: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
229
235
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
230
236
|
function clientIslandEntryPlugin() {
|
|
231
237
|
return {
|
|
@@ -354,7 +360,7 @@ var hasComponentExtension = (componentPath) => {
|
|
|
354
360
|
return !!getComponentExtension(componentPath);
|
|
355
361
|
};
|
|
356
362
|
var isStorybookStory = (componentPath) => {
|
|
357
|
-
return !!
|
|
363
|
+
return !!path2.basename(componentPath, path2.extname(componentPath)).endsWith(".stories");
|
|
358
364
|
};
|
|
359
365
|
var removeComponentExtension = (componentPath) => {
|
|
360
366
|
const ext = getComponentExtension(componentPath);
|
|
@@ -370,6 +376,13 @@ function getEntryPointHashWithIndexSuffix(entryPoint, index) {
|
|
|
370
376
|
const renderIndexSuffix = index != null ? `i${index}` : "";
|
|
371
377
|
return `${getEntryPointHash(entryPoint)}${renderIndexSuffix}`;
|
|
372
378
|
}
|
|
379
|
+
var ENABLED_FEATURES_GATE_MAP = {
|
|
380
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
381
|
+
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
382
|
+
};
|
|
383
|
+
function isUngatedFor(gates, gate) {
|
|
384
|
+
return gates.includes(gate);
|
|
385
|
+
}
|
|
373
386
|
var findAllComponentsIn = (webRoot2, componentsFolder, includeSubdirIndexJS) => {
|
|
374
387
|
const fullComponentsFolderPath = join(webRoot2, componentsFolder);
|
|
375
388
|
const componentsByName = {};
|
|
@@ -497,25 +510,6 @@ function renderFieldsToJson(fields) {
|
|
|
497
510
|
return moduleJson;
|
|
498
511
|
}
|
|
499
512
|
|
|
500
|
-
// src/lib/packagePath.ts
|
|
501
|
-
import path2 from "path";
|
|
502
|
-
import url from "url";
|
|
503
|
-
import { normalizePath } from "vite";
|
|
504
|
-
function packagePath(metaUrl, projectPath) {
|
|
505
|
-
if (true) {
|
|
506
|
-
return normalizePath(
|
|
507
|
-
path2.resolve(path2.dirname(url.fileURLToPath(metaUrl)), projectPath)
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
const parentDirPath = normalizePath(path2.dirname(url.fileURLToPath(metaUrl)));
|
|
511
|
-
const subPath = parentDirPath.replace(/^.+cms-dev-server\/src\//, "");
|
|
512
|
-
const subPathParentDirs = subPath.split("/").map(() => "..");
|
|
513
|
-
return path2.resolve(
|
|
514
|
-
path2.dirname(url.fileURLToPath(metaUrl)),
|
|
515
|
-
path2.join(...subPathParentDirs, projectPath)
|
|
516
|
-
);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
513
|
// src/lib/moduleGraph.ts
|
|
520
514
|
var findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
|
|
521
515
|
for (const extension of COMPONENT_EXTENSIONS) {
|
|
@@ -623,13 +617,13 @@ var logPartialInfo = (partialPath, props) => {
|
|
|
623
617
|
|
|
624
618
|
// src/lib/renderPartial.ts
|
|
625
619
|
async function renderPartial(viteServer, partialPath, props, pageUrl, basePath, environmentConfig, renderOptions) {
|
|
626
|
-
|
|
627
|
-
|
|
620
|
+
try {
|
|
621
|
+
logPartialInfo(partialPath, props);
|
|
622
|
+
} catch (e) {
|
|
623
|
+
console.log("unable to log partial prop info");
|
|
624
|
+
console.error(e);
|
|
625
|
+
}
|
|
628
626
|
const componentModule = await viteServer.ssrLoadModule(partialPath);
|
|
629
|
-
const ungatedForServerSideProps = isUngatedFor(
|
|
630
|
-
environmentConfig.getGates(),
|
|
631
|
-
"CMS:JSRenderer:GetServerSideProps"
|
|
632
|
-
);
|
|
633
627
|
if (!componentModule) {
|
|
634
628
|
throw new Error(`Couldn't find partial: ${partialPath}`);
|
|
635
629
|
}
|
|
@@ -637,22 +631,11 @@ async function renderPartial(viteServer, partialPath, props, pageUrl, basePath,
|
|
|
637
631
|
if (!Component) {
|
|
638
632
|
throw new Error(`Couldn't find default export on partial: ${partialPath}`);
|
|
639
633
|
}
|
|
640
|
-
if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
|
|
641
|
-
try {
|
|
642
|
-
serverSideProps = await componentModule.getServerSidePropsUnstable(props);
|
|
643
|
-
if (serverSideProps.constructor !== {}.constructor) {
|
|
644
|
-
throw new Error("getServerSidePropsUnstable must return an object");
|
|
645
|
-
}
|
|
646
|
-
} catch (e) {
|
|
647
|
-
console.log("Error resolving server side props");
|
|
648
|
-
console.error(e);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
634
|
return renderComponentWithCSS_default(
|
|
652
635
|
viteServer,
|
|
653
636
|
partialPath,
|
|
654
637
|
Component,
|
|
655
|
-
|
|
638
|
+
props,
|
|
656
639
|
pageUrl,
|
|
657
640
|
basePath,
|
|
658
641
|
environmentConfig,
|
|
@@ -664,30 +647,19 @@ var renderPartial_default = renderPartial;
|
|
|
664
647
|
// src/lib/templates.ts
|
|
665
648
|
import { promises as fsPromises } from "fs";
|
|
666
649
|
var { readFile } = fsPromises;
|
|
667
|
-
var generateIslandSetupScriptBlock = (
|
|
668
|
-
|
|
669
|
-
return `<script type="module">
|
|
650
|
+
var generateIslandSetupScriptBlock = () => {
|
|
651
|
+
return `<script type="module">
|
|
670
652
|
import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
|
|
671
653
|
initConfigSingletonFromJSON(window.__hsEnvConfig);
|
|
672
654
|
</script>
|
|
673
655
|
<script type="module">
|
|
674
656
|
import { setupIslandHydration } from '${packagePath(
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
657
|
+
import.meta.url,
|
|
658
|
+
"island-runtime"
|
|
659
|
+
)}';
|
|
678
660
|
setupIslandHydration();
|
|
679
661
|
</script>
|
|
680
662
|
`;
|
|
681
|
-
}
|
|
682
|
-
return `<script type="module">
|
|
683
|
-
import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
|
|
684
|
-
initConfigSingletonFromJSON(window.__hsEnvConfig);
|
|
685
|
-
</script>
|
|
686
|
-
<script type="module">
|
|
687
|
-
import { setupIslandHydration } from '@hubspot/cms-components/island-runtime';
|
|
688
|
-
setupIslandHydration();
|
|
689
|
-
</script>
|
|
690
|
-
`;
|
|
691
663
|
};
|
|
692
664
|
var createdPlainHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock) => {
|
|
693
665
|
const htmlTemplateBase = await readFile(baseTemplatePath, "utf-8");
|
|
@@ -698,7 +670,7 @@ var createdPlainHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
|
|
|
698
670
|
<!--bodyend-->`
|
|
699
671
|
);
|
|
700
672
|
};
|
|
701
|
-
var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
|
|
673
|
+
var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock) => {
|
|
702
674
|
let htmlTemplate = await createdPlainHtmlTemplate(
|
|
703
675
|
baseTemplatePath,
|
|
704
676
|
title,
|
|
@@ -707,14 +679,14 @@ var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
|
|
|
707
679
|
htmlTemplate = htmlTemplate.replace(
|
|
708
680
|
"<!--bodyend-->",
|
|
709
681
|
`
|
|
710
|
-
${generateIslandSetupScriptBlock(
|
|
682
|
+
${generateIslandSetupScriptBlock()}
|
|
711
683
|
<!-- ISLAND_RUNTIME_AND_SETUP_SCRIPT_BLOCK -->
|
|
712
684
|
<!--islandsglobal-->
|
|
713
685
|
`
|
|
714
686
|
);
|
|
715
687
|
return htmlTemplate;
|
|
716
688
|
};
|
|
717
|
-
var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, title, renderContext, viteServer,
|
|
689
|
+
var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, title, renderContext, viteServer, __jsRenderingGates) => {
|
|
718
690
|
let htmlTemplate;
|
|
719
691
|
if (renderContext.islands.length) {
|
|
720
692
|
const globalScriptBlock = getServerGlobalsToInject(
|
|
@@ -725,8 +697,7 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
|
|
|
725
697
|
htmlTemplate = await createIslandHtmlTemplate(
|
|
726
698
|
baseTemplatePath,
|
|
727
699
|
title,
|
|
728
|
-
globalScriptBlock
|
|
729
|
-
jsRenderingGates
|
|
700
|
+
globalScriptBlock
|
|
730
701
|
);
|
|
731
702
|
htmlTemplate = htmlTemplate.replace(
|
|
732
703
|
"<!--islandsglobal-->",
|
|
@@ -752,12 +723,12 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
|
|
|
752
723
|
}
|
|
753
724
|
return viteServer.transformIndexHtml(url3, htmlTemplate);
|
|
754
725
|
};
|
|
755
|
-
var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerRequestData, viteServer,
|
|
726
|
+
var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerRequestData, viteServer, __gates) => {
|
|
756
727
|
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
757
728
|
const { createIslandsGlobalJsForClientInDev: createIslandsGlobalJsForClientInDev2 } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
758
729
|
const islandRuntimeScript = await viteServer.transformIndexHtml(
|
|
759
730
|
"/",
|
|
760
|
-
generateIslandSetupScriptBlock(
|
|
731
|
+
generateIslandSetupScriptBlock()
|
|
761
732
|
);
|
|
762
733
|
return `${islandRuntimeScript}
|
|
763
734
|
<script>${createIslandsGlobalJsForClientInDev2(
|
|
@@ -964,8 +935,9 @@ var lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
|
964
935
|
}
|
|
965
936
|
return [componentModule, insideFolderPath];
|
|
966
937
|
};
|
|
967
|
-
async function renderModule(viteServer, requestedModulePath,
|
|
938
|
+
async function renderModule(viteServer, requestedModulePath, moduleProps, pageUrl, basePath, environmentConfig, renderOptions) {
|
|
968
939
|
console.log("Rendering module", requestedModulePath);
|
|
940
|
+
const { fieldValues: fieldOverrides = {}, hublParameters } = moduleProps;
|
|
969
941
|
const ungatedForServerSideProps = isUngatedFor(
|
|
970
942
|
environmentConfig.getGates(),
|
|
971
943
|
"CMS:JSRenderer:GetServerSideProps"
|
|
@@ -1000,18 +972,7 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
1000
972
|
throw new Error(`Module does not have a named meta export: ${foundPath}`);
|
|
1001
973
|
}
|
|
1002
974
|
const fieldsJSON = renderFieldsToJson(fields);
|
|
1003
|
-
const
|
|
1004
|
-
if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
|
|
1005
|
-
try {
|
|
1006
|
-
serverSideProps = await componentModule.getServerSidePropsUnstable(props);
|
|
1007
|
-
if (serverSideProps.constructor !== {}.constructor) {
|
|
1008
|
-
throw new Error("getServerSidePropsUnstable must return an object");
|
|
1009
|
-
}
|
|
1010
|
-
} catch (e) {
|
|
1011
|
-
console.log("Error resolving server side props");
|
|
1012
|
-
console.error(e);
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
975
|
+
const fieldValues = getFieldValuesForModule(fieldsJSON, fieldOverrides);
|
|
1015
976
|
if (componentModule.query && typeof componentModule.query === "string") {
|
|
1016
977
|
try {
|
|
1017
978
|
dataQueryResult = await fetchModuleGraphQLData(
|
|
@@ -1034,9 +995,23 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
1034
995
|
}
|
|
1035
996
|
}
|
|
1036
997
|
const namespacedModuleProps = namespaceModulePropsShape({
|
|
1037
|
-
|
|
998
|
+
fieldValues,
|
|
999
|
+
hublParameters,
|
|
1038
1000
|
dataQueryResult
|
|
1039
1001
|
});
|
|
1002
|
+
if (ungatedForServerSideProps && componentModule.getServerSideProps) {
|
|
1003
|
+
try {
|
|
1004
|
+
serverSideProps = await componentModule.getServerSideProps(
|
|
1005
|
+
namespacedModuleProps
|
|
1006
|
+
);
|
|
1007
|
+
if (serverSideProps.constructor !== {}.constructor) {
|
|
1008
|
+
throw new Error("getServerSideProps must return an object");
|
|
1009
|
+
}
|
|
1010
|
+
} catch (e) {
|
|
1011
|
+
console.log("Error resolving server side props");
|
|
1012
|
+
console.error(e);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1040
1015
|
return renderComponentWithCSS_default(
|
|
1041
1016
|
viteServer,
|
|
1042
1017
|
foundPath,
|
|
@@ -1048,7 +1023,7 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
1048
1023
|
renderOptions
|
|
1049
1024
|
);
|
|
1050
1025
|
}
|
|
1051
|
-
function
|
|
1026
|
+
function getFieldValuesForModule(fieldsJSON, fieldOverrides = {}) {
|
|
1052
1027
|
const props = {};
|
|
1053
1028
|
traverseFieldsJSON(fieldsJSON, fieldOverrides, (fieldPathArray, value) => {
|
|
1054
1029
|
setIn(props, fieldPathArray, value);
|
|
@@ -1114,7 +1089,7 @@ var moduleRouteHandler = async (request2, response) => {
|
|
|
1114
1089
|
} = await renderModule_default(
|
|
1115
1090
|
viteServer,
|
|
1116
1091
|
modulePath,
|
|
1117
|
-
fieldOverrides,
|
|
1092
|
+
{ fieldValues: fieldOverrides },
|
|
1118
1093
|
fullOriginalUrlFromRequest(request2),
|
|
1119
1094
|
basePath,
|
|
1120
1095
|
environmentConfig,
|
|
@@ -1245,6 +1220,7 @@ async function fetchContentMetadata(url3, portalId) {
|
|
|
1245
1220
|
|
|
1246
1221
|
// src/proxyPage/proxyPage.ts
|
|
1247
1222
|
import path5 from "path";
|
|
1223
|
+
import { normalizePath as normalizePath4 } from "vite";
|
|
1248
1224
|
import { getAccountId as getAccountId2, getEnv } from "@hubspot/cli-lib/lib/config.js";
|
|
1249
1225
|
import { get as hsGet3 } from "@hubspot/cli-lib/http.js";
|
|
1250
1226
|
|
|
@@ -1477,7 +1453,6 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
|
|
|
1477
1453
|
proxiedQueryParams = {
|
|
1478
1454
|
...proxiedQueryParams,
|
|
1479
1455
|
hs_preview: `${previewKey}-${contentId}`,
|
|
1480
|
-
hsLocalProxy: true,
|
|
1481
1456
|
hsLocalProxyProject: `@projects/${projectName}`,
|
|
1482
1457
|
localProxySchemaVersion: 1
|
|
1483
1458
|
};
|
|
@@ -1517,7 +1492,9 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
|
|
|
1517
1492
|
`The specified component folder "${projectComponentFolder}" does not match the webroot project component folder "${webRootProjectComponent}/${projectComponentFolder}" specified to the cms-dev-server. Components must be located within the webroot project folder. Check that the specified path is correct: ${placeholderPath}.`
|
|
1518
1493
|
);
|
|
1519
1494
|
}
|
|
1520
|
-
const resolvedPath =
|
|
1495
|
+
const resolvedPath = normalizePath4(
|
|
1496
|
+
path5.resolve(webRoot2, partialPath, componentFileName)
|
|
1497
|
+
);
|
|
1521
1498
|
const entryPointPath = [
|
|
1522
1499
|
"@projects",
|
|
1523
1500
|
webRootProjectComponent,
|
|
@@ -1546,7 +1523,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
|
|
|
1546
1523
|
return renderModule_default(
|
|
1547
1524
|
viteServer,
|
|
1548
1525
|
resolvedPath,
|
|
1549
|
-
localRenderPlaceholderProps
|
|
1526
|
+
localRenderPlaceholderProps,
|
|
1550
1527
|
pageUrl,
|
|
1551
1528
|
basePath,
|
|
1552
1529
|
environmentConfig,
|
|
@@ -1883,7 +1860,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
|
|
|
1883
1860
|
try {
|
|
1884
1861
|
const { portalId, contentId, hublet } = await fetchContentMetadata(
|
|
1885
1862
|
proxyPageUrl.href,
|
|
1886
|
-
request2.app.locals.
|
|
1863
|
+
request2.app.locals.authedPortalId
|
|
1887
1864
|
);
|
|
1888
1865
|
await proxySpecificPage(
|
|
1889
1866
|
response,
|
|
@@ -2103,11 +2080,7 @@ async function startShadowDevServer(devServerPort, shadowPort, projectName, jsRe
|
|
|
2103
2080
|
import { createServer as createViteServer } from "vite";
|
|
2104
2081
|
import { default as react } from "@vitejs/plugin-react";
|
|
2105
2082
|
import mkcert from "vite-plugin-mkcert";
|
|
2106
|
-
async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [],
|
|
2107
|
-
const sharedDepsEnabled = isUngatedFor(
|
|
2108
|
-
jsRenderingGates,
|
|
2109
|
-
"CMS:JSRenderer:SharedDeps"
|
|
2110
|
-
);
|
|
2083
|
+
async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [], __jsRenderingGates) {
|
|
2111
2084
|
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
2112
2085
|
`${proxyDomain}.localhost`,
|
|
2113
2086
|
`${proxyDomain}.hslocal.net`
|
|
@@ -2144,8 +2117,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
2144
2117
|
plugins: [
|
|
2145
2118
|
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
2146
2119
|
react(),
|
|
2147
|
-
|
|
2148
|
-
resolveIslandPlugin(
|
|
2120
|
+
clientIslandEntryPlugin(),
|
|
2121
|
+
resolveIslandPlugin()
|
|
2149
2122
|
],
|
|
2150
2123
|
css: {
|
|
2151
2124
|
postcss: webRoot2
|
|
@@ -2313,7 +2286,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
|
|
|
2313
2286
|
);
|
|
2314
2287
|
let authedPortalId = null;
|
|
2315
2288
|
let authedEnv = null;
|
|
2316
|
-
let jsRenderingGates = [
|
|
2289
|
+
let jsRenderingGates = [];
|
|
2317
2290
|
let personalAccessKey = null;
|
|
2318
2291
|
if (hubspotCliConfigPathOption2 && hubspotCliAccountNameOption2) {
|
|
2319
2292
|
console.log(
|
|
@@ -2377,7 +2350,7 @@ Local proxy functionality will not work without setting up authentication.`
|
|
|
2377
2350
|
}
|
|
2378
2351
|
}
|
|
2379
2352
|
const authedHublet = "na1";
|
|
2380
|
-
const absoluteWebRoot =
|
|
2353
|
+
const absoluteWebRoot = normalizePath5(path6.resolve(process.cwd(), webRoot2));
|
|
2381
2354
|
const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, "").split("/").slice(-2);
|
|
2382
2355
|
const viteServer = await createViteDevServer_default(
|
|
2383
2356
|
absoluteWebRoot,
|
|
@@ -50,13 +50,13 @@ __export(dist_exports, {
|
|
|
50
50
|
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
|
|
51
51
|
});
|
|
52
52
|
import path, { basename } from "path";
|
|
53
|
-
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
54
53
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
55
54
|
import stream from "stream";
|
|
56
55
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
57
56
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
58
57
|
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
59
58
|
import { createHash } from "crypto";
|
|
59
|
+
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
60
60
|
import { join } from "path/posix";
|
|
61
61
|
import { cloneElement } from "react";
|
|
62
62
|
function createPreloadLink(assetPath, basePath = "") {
|
|
@@ -117,23 +117,7 @@ function getPerServerRequestUrls(perServerRequestData, viteDevServer) {
|
|
|
117
117
|
});
|
|
118
118
|
return perServerRequestDataWithUrls;
|
|
119
119
|
}
|
|
120
|
-
function
|
|
121
|
-
return gates.includes(gate);
|
|
122
|
-
}
|
|
123
|
-
function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
124
|
-
try {
|
|
125
|
-
console.log("loading path", path.join(buildDir, BUILD_INFO_PATH));
|
|
126
|
-
const buildInfo = JSON.parse(
|
|
127
|
-
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
128
|
-
);
|
|
129
|
-
return isUngatedFor(buildInfo.gates, gate);
|
|
130
|
-
} catch (e) {
|
|
131
|
-
console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
function resolveIslandPlugin(gates) {
|
|
136
|
-
const sharedDepsEnabled = isUngatedFor(gates, "CMS:JSRenderer:SharedDeps");
|
|
120
|
+
function resolveIslandPlugin() {
|
|
137
121
|
return {
|
|
138
122
|
enforce: "pre",
|
|
139
123
|
name: "resolve-islands",
|
|
@@ -144,17 +128,14 @@ function resolveIslandPlugin(gates) {
|
|
|
144
128
|
load(id) {
|
|
145
129
|
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
146
130
|
const [idWithNoParam] = id.split("?");
|
|
147
|
-
const islandModuleImportPath =
|
|
131
|
+
const islandModuleImportPath = `${idWithNoParam}?client-entry`;
|
|
148
132
|
const componentExtension = path.extname(idWithNoParam);
|
|
149
133
|
const componentFilenameWithNoExtension = path.basename(
|
|
150
134
|
idWithNoParam,
|
|
151
135
|
componentExtension
|
|
152
136
|
);
|
|
153
137
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
154
|
-
|
|
155
|
-
if (sharedDepsEnabled) {
|
|
156
|
-
moduleId = moduleId.concat("?client-entry");
|
|
157
|
-
}
|
|
138
|
+
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
158
139
|
return `
|
|
159
140
|
const moduleId = '${moduleId}';
|
|
160
141
|
|
|
@@ -245,6 +226,21 @@ function getIslandRuntimeConfigUrl() {
|
|
|
245
226
|
const fileVersion = hsEnv === "prod" ? `island-runtime.mjs` : "island-runtime-qa.mjs";
|
|
246
227
|
return `${ISLAND_RUNTIME_CONFIG_BASE_PATH}/${fileVersion}`;
|
|
247
228
|
}
|
|
229
|
+
function isUngatedFor(gates, gate) {
|
|
230
|
+
return gates.includes(gate);
|
|
231
|
+
}
|
|
232
|
+
function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
233
|
+
try {
|
|
234
|
+
console.log("loading path", path.join(buildDir, BUILD_INFO_PATH));
|
|
235
|
+
const buildInfo = JSON.parse(
|
|
236
|
+
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
237
|
+
);
|
|
238
|
+
return isUngatedFor(buildInfo.gates, gate);
|
|
239
|
+
} catch (e) {
|
|
240
|
+
console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
248
244
|
function findAllModulesInRoot(webRoot2) {
|
|
249
245
|
const allModuleComponents = findAllComponentsIn(
|
|
250
246
|
webRoot2,
|
|
@@ -338,7 +334,7 @@ function renderFieldsToJson(fields) {
|
|
|
338
334
|
);
|
|
339
335
|
return moduleJson;
|
|
340
336
|
}
|
|
341
|
-
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev,
|
|
337
|
+
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, GATES, ENABLED_FEATURES_GATE_MAP, BUILD_INFO_PATH, findAllComponentsIn;
|
|
342
338
|
var init_dist = __esm({
|
|
343
339
|
"../cms-js-internal/dist/index.js"() {
|
|
344
340
|
COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
@@ -455,20 +451,7 @@ ${indentString}`);
|
|
|
455
451
|
indent
|
|
456
452
|
)}`;
|
|
457
453
|
};
|
|
458
|
-
|
|
459
|
-
"CMS:JSRenderer:SharedDeps",
|
|
460
|
-
"CMS:JSRenderer:GetServerSideProps",
|
|
461
|
-
"CMS:JSRenderer:GraphQLQueryBuild",
|
|
462
|
-
"CMS:JSRenderer:SeparateIslandRenderOption"
|
|
463
|
-
];
|
|
464
|
-
ENABLED_FEATURES_GATE_MAP = {
|
|
465
|
-
"cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
|
|
466
|
-
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
467
|
-
"cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild",
|
|
468
|
-
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
469
|
-
};
|
|
470
|
-
BUILD_INFO_PATH = "/build-info.json";
|
|
471
|
-
clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {\n ClientRenderContextProvider,\n buildIslandIdentifierPrefix,\n} from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
454
|
+
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: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
472
455
|
virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
473
456
|
jsx2 = jsxRuntime.jsx;
|
|
474
457
|
promiseForNewWritableStream = () => {
|
|
@@ -560,6 +543,15 @@ ${groupEnd}</script>
|
|
|
560
543
|
};
|
|
561
544
|
COMBINED_REACT_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/react/v18";
|
|
562
545
|
ISLAND_RUNTIME_CONFIG_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/island-runtime/v1";
|
|
546
|
+
GATES = [
|
|
547
|
+
"CMS:JSRenderer:GetServerSideProps",
|
|
548
|
+
"CMS:JSRenderer:SeparateIslandRenderOption"
|
|
549
|
+
];
|
|
550
|
+
ENABLED_FEATURES_GATE_MAP = {
|
|
551
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
552
|
+
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
553
|
+
};
|
|
554
|
+
BUILD_INFO_PATH = "/build-info.json";
|
|
563
555
|
findAllComponentsIn = (webRoot2, componentsFolder, includeSubdirIndexJS) => {
|
|
564
556
|
const fullComponentsFolderPath = join(webRoot2, componentsFolder);
|
|
565
557
|
const componentsByName = {};
|
|
@@ -641,7 +633,7 @@ var main_default = {
|
|
|
641
633
|
css: {
|
|
642
634
|
postcss: webRoot
|
|
643
635
|
},
|
|
644
|
-
plugins: [resolveIslandPlugin2(
|
|
636
|
+
plugins: [resolveIslandPlugin2()]
|
|
645
637
|
};
|
|
646
638
|
return mergeConfig(config, viteConfig);
|
|
647
639
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@hubspot/cli-lib": "^3.0.12",
|
|
28
|
-
"@hubspot/cms-components": "^0.7.
|
|
28
|
+
"@hubspot/cms-components": "^0.7.7",
|
|
29
29
|
"@storybook/addon-actions": "7.0.7",
|
|
30
30
|
"@storybook/addon-essentials": "7.0.7",
|
|
31
31
|
"@storybook/addon-interactions": "7.0.7",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"publishConfig": {
|
|
98
98
|
"access": "public"
|
|
99
99
|
},
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "0a5d996b75302f9c7c600a937c42626728b98d48"
|
|
101
101
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function createViteDevServer(webRoot: string, port: any, sslEnabled: boolean, domainsToProxy: any[],
|
|
1
|
+
declare function createViteDevServer(webRoot: string, port: any, sslEnabled: boolean, domainsToProxy: any[], __jsRenderingGates: string[]): Promise<import("vite").ViteDevServer>;
|
|
2
2
|
export default createViteDevServer;
|
|
Binary file
|