@hubspot/cms-dev-server 0.4.2 → 0.4.4
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 +36 -6
- package/dist/internalSsr.js +87 -12
- package/dist/run.js +174 -45
- package/package.json +4 -4
- package/types/createViteDevServer.d.ts +1 -1
- package/dist/components/ModulesList.js +0 -14
- package/dist/components/PartialsList.js +0 -13
- package/dist/createDevServer.js +0 -164
- package/dist/createDevServerConfiguration.js +0 -155
- package/dist/createViteDevServer.js +0 -52
- package/dist/lib/cli.js +0 -27
- package/dist/lib/debug.js +0 -2
- package/dist/lib/errors.js +0 -22
- package/dist/lib/fullOriginalUrlFromRequest.js +0 -3
- package/dist/lib/getDevServerConfiguration.js +0 -63
- package/dist/lib/httpsRedirectingServer.js +0 -48
- package/dist/lib/moduleGraph.js +0 -11
- package/dist/lib/proxyHelpers.js +0 -70
- 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 -56
- package/dist/lib/renderPartial.js +0 -15
- package/dist/lib/templates.js +0 -66
- package/dist/proxyPage/constants.js +0 -1
- package/dist/proxyPage/fetchContentMetadata.js +0 -59
- package/dist/proxyPage/fetchDomains.js +0 -29
- package/dist/proxyPage/fetchPreviewInfo.js +0 -37
- package/dist/proxyPage/proxyPage.js +0 -174
- package/dist/proxyPage/renderLocalError.js +0 -27
- package/dist/proxyPage/utils.js +0 -38
- package/dist/routes/createDevServerRoutes.js +0 -43
- 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 -41
- package/dist/routes/partial.js +0 -30
- package/dist/routes/proxyPageResourceRedirect.js +0 -22
- package/dist/routes/proxyPageRouteHandler.js +0 -40
- package/dist/routes/proxyPathPageResourceRedirect.js +0 -36
- package/dist/routes/proxyPathPageRouteHandler.js +0 -43
- package/dist/shadowDevServer/createShadowDevServerRoutes.js +0 -63
- package/dist/shadowDevServer/startShadowDevServer.js +0 -31
- package/dist/storybook/getFieldsArgTypes.js +0 -54
- package/dist/storybook/getFieldsArgTypes.test.js +0 -91
- package/dist/storybook/getNestedFieldObjectForArgs.js +0 -22
- package/dist/storybook/getNestedFieldObjectForArgs.test.js +0 -40
- package/dist/storybook/main.js +0 -31
- package/dist/storybook/moduleStory.js +0 -61
- package/dist/storybook/preview.js +0 -9
- package/dist/storybook/types.js +0 -1
package/dist/index.js
CHANGED
|
@@ -19,7 +19,9 @@ import { cloneElement } from "react";
|
|
|
19
19
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
20
20
|
var viteRoot;
|
|
21
21
|
var viteCommand;
|
|
22
|
-
function resolveIslandPlugin(
|
|
22
|
+
function resolveIslandPlugin({
|
|
23
|
+
sharedDepsEnabled
|
|
24
|
+
}) {
|
|
23
25
|
return {
|
|
24
26
|
enforce: "pre",
|
|
25
27
|
name: "resolve-islands",
|
|
@@ -28,18 +30,23 @@ function resolveIslandPlugin() {
|
|
|
28
30
|
viteCommand = config.command;
|
|
29
31
|
},
|
|
30
32
|
load(id) {
|
|
31
|
-
if (id.endsWith("?island")) {
|
|
33
|
+
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
32
34
|
const [idWithNoParam] = id.split("?");
|
|
35
|
+
const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
|
|
33
36
|
const componentExtension = path.extname(idWithNoParam);
|
|
34
37
|
const componentFilenameWithNoExtension = path.basename(
|
|
35
38
|
idWithNoParam,
|
|
36
39
|
componentExtension
|
|
37
40
|
);
|
|
38
41
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
42
|
+
let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
|
|
43
|
+
if (sharedDepsEnabled) {
|
|
44
|
+
moduleId = moduleId.concat("?client-entry");
|
|
45
|
+
}
|
|
39
46
|
return `
|
|
40
|
-
const moduleId = '${
|
|
47
|
+
const moduleId = '${moduleId}';
|
|
41
48
|
|
|
42
|
-
const lazyComponent = () => import('${
|
|
49
|
+
const lazyComponent = () => import('${islandModuleImportPath}');
|
|
43
50
|
lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
|
|
44
51
|
lazyComponent.moduleId = moduleId;
|
|
45
52
|
|
|
@@ -50,10 +57,32 @@ function resolveIslandPlugin() {
|
|
|
50
57
|
}
|
|
51
58
|
};
|
|
52
59
|
}
|
|
60
|
+
function clientIslandEntryPlugin() {
|
|
61
|
+
return {
|
|
62
|
+
enforce: "pre",
|
|
63
|
+
name: "client-island-entry-plugin",
|
|
64
|
+
load(id) {
|
|
65
|
+
if (id.endsWith("?client-entry")) {
|
|
66
|
+
const [idWithNoParam] = id.split("?");
|
|
67
|
+
return `
|
|
68
|
+
import { clientRenderIsland } from '@hubspot/cms-components';
|
|
69
|
+
import Component from '${idWithNoParam}';
|
|
70
|
+
|
|
71
|
+
export function render(island) {
|
|
72
|
+
return clientRenderIsland(island, Component)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default Component;
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
53
82
|
|
|
54
83
|
// src/createViteDevServer.ts
|
|
55
84
|
import mkcert from "vite-plugin-mkcert";
|
|
56
|
-
async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = []) {
|
|
85
|
+
async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], sharedDepsEnabled) {
|
|
57
86
|
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
58
87
|
`${proxyDomain}.localhost`,
|
|
59
88
|
`${proxyDomain}.hslocal.net`
|
|
@@ -85,7 +114,8 @@ async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [
|
|
|
85
114
|
plugins: [
|
|
86
115
|
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
87
116
|
react(),
|
|
88
|
-
|
|
117
|
+
sharedDepsEnabled && clientIslandEntryPlugin(),
|
|
118
|
+
resolveIslandPlugin({ sharedDepsEnabled })
|
|
89
119
|
],
|
|
90
120
|
css: {
|
|
91
121
|
postcss: webRoot
|
package/dist/internalSsr.js
CHANGED
|
@@ -71,9 +71,9 @@ var collectCssInDev = (modulePathToStartWith, viteServer, cssModulesImported = /
|
|
|
71
71
|
).map((cssModule) => createPreloadLink(cssModule.url)).join("\n")}
|
|
72
72
|
`;
|
|
73
73
|
};
|
|
74
|
-
var
|
|
74
|
+
var serializeIslandDataToJSON = (tweakedIslandsArray, indent = 0) => {
|
|
75
75
|
const indentString = new Array(indent).fill(" ").join("");
|
|
76
|
-
return
|
|
76
|
+
return `${JSON.stringify(
|
|
77
77
|
tweakedIslandsArray.map(
|
|
78
78
|
({
|
|
79
79
|
id,
|
|
@@ -83,24 +83,50 @@ var writeIslandDataToJsGlobal = (tweakedIslandsArray, indent = 0) => {
|
|
|
83
83
|
hydrateOn,
|
|
84
84
|
clientOnly,
|
|
85
85
|
priority,
|
|
86
|
-
url
|
|
86
|
+
url,
|
|
87
|
+
sharedStateID
|
|
87
88
|
}) => {
|
|
88
|
-
|
|
89
|
+
const output = {
|
|
89
90
|
id,
|
|
90
91
|
moduleName,
|
|
91
92
|
moduleId,
|
|
92
|
-
props,
|
|
93
93
|
hydrateOn,
|
|
94
94
|
clientOnly,
|
|
95
95
|
priority,
|
|
96
|
+
props,
|
|
96
97
|
url
|
|
97
98
|
};
|
|
99
|
+
if (sharedStateID) {
|
|
100
|
+
output.sharedStateID = sharedStateID;
|
|
101
|
+
}
|
|
102
|
+
return output;
|
|
98
103
|
}
|
|
99
104
|
),
|
|
100
105
|
null,
|
|
101
106
|
2
|
|
102
107
|
).replace(/\n/gm, `
|
|
103
|
-
${indentString}`)}
|
|
108
|
+
${indentString}`)}`;
|
|
109
|
+
};
|
|
110
|
+
var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0) => {
|
|
111
|
+
const indentString = new Array(indent).fill(" ").join("");
|
|
112
|
+
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
|
|
113
|
+
if (sharedStateIDs.length > 0) {
|
|
114
|
+
const stateByID = {};
|
|
115
|
+
sharedStateIDs.forEach(
|
|
116
|
+
(id) => stateByID[id] = perServerRequestData.get(id)
|
|
117
|
+
);
|
|
118
|
+
const stringifiedState = JSON.stringify(stateByID, null, 2);
|
|
119
|
+
return `
|
|
120
|
+
|
|
121
|
+
var newState = ${stringifiedState};
|
|
122
|
+
if(window.__hsSSInit) {
|
|
123
|
+
window.__hsSSInit = Object.assign(window.__hsSSInit, newState);
|
|
124
|
+
} else {
|
|
125
|
+
window.__hsSSInit = newState;
|
|
126
|
+
}`.replace(/\n/gm, `
|
|
127
|
+
${indentString}`);
|
|
128
|
+
}
|
|
129
|
+
return "";
|
|
104
130
|
};
|
|
105
131
|
function getIslandUrls(roots, viteDevServer) {
|
|
106
132
|
return roots.map((island) => {
|
|
@@ -117,12 +143,18 @@ function getIslandUrls(roots, viteDevServer) {
|
|
|
117
143
|
return tweakedIsland;
|
|
118
144
|
});
|
|
119
145
|
}
|
|
120
|
-
var createIslandsGlobalJsForClientInDev = (roots, viteDevServer, indent) => {
|
|
121
|
-
|
|
146
|
+
var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent) => {
|
|
147
|
+
const islands = getIslandUrls(roots, viteDevServer);
|
|
148
|
+
return `window.__islands = ${serializeIslandDataToJSON(
|
|
149
|
+
islands,
|
|
150
|
+
indent
|
|
151
|
+
)}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
|
|
122
152
|
};
|
|
123
153
|
var viteRoot;
|
|
124
154
|
var viteCommand;
|
|
125
|
-
function resolveIslandPlugin(
|
|
155
|
+
function resolveIslandPlugin({
|
|
156
|
+
sharedDepsEnabled
|
|
157
|
+
}) {
|
|
126
158
|
return {
|
|
127
159
|
enforce: "pre",
|
|
128
160
|
name: "resolve-islands",
|
|
@@ -131,18 +163,23 @@ function resolveIslandPlugin() {
|
|
|
131
163
|
viteCommand = config.command;
|
|
132
164
|
},
|
|
133
165
|
load(id) {
|
|
134
|
-
if (id.endsWith("?island")) {
|
|
166
|
+
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
135
167
|
const [idWithNoParam] = id.split("?");
|
|
168
|
+
const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
|
|
136
169
|
const componentExtension = path.extname(idWithNoParam);
|
|
137
170
|
const componentFilenameWithNoExtension = path.basename(
|
|
138
171
|
idWithNoParam,
|
|
139
172
|
componentExtension
|
|
140
173
|
);
|
|
141
174
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
175
|
+
let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
|
|
176
|
+
if (sharedDepsEnabled) {
|
|
177
|
+
moduleId = moduleId.concat("?client-entry");
|
|
178
|
+
}
|
|
142
179
|
return `
|
|
143
|
-
const moduleId = '${
|
|
180
|
+
const moduleId = '${moduleId}';
|
|
144
181
|
|
|
145
|
-
const lazyComponent = () => import('${
|
|
182
|
+
const lazyComponent = () => import('${islandModuleImportPath}');
|
|
146
183
|
lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
|
|
147
184
|
lazyComponent.moduleId = moduleId;
|
|
148
185
|
|
|
@@ -153,6 +190,28 @@ function resolveIslandPlugin() {
|
|
|
153
190
|
}
|
|
154
191
|
};
|
|
155
192
|
}
|
|
193
|
+
function clientIslandEntryPlugin() {
|
|
194
|
+
return {
|
|
195
|
+
enforce: "pre",
|
|
196
|
+
name: "client-island-entry-plugin",
|
|
197
|
+
load(id) {
|
|
198
|
+
if (id.endsWith("?client-entry")) {
|
|
199
|
+
const [idWithNoParam] = id.split("?");
|
|
200
|
+
return `
|
|
201
|
+
import { clientRenderIsland } from '@hubspot/cms-components';
|
|
202
|
+
import Component from '${idWithNoParam}';
|
|
203
|
+
|
|
204
|
+
export function render(island) {
|
|
205
|
+
return clientRenderIsland(island, Component)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export default Component;
|
|
209
|
+
`;
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
156
215
|
var promiseForNewWritableStream = () => {
|
|
157
216
|
const chunks = [];
|
|
158
217
|
const writableStream = new stream.Writable();
|
|
@@ -260,6 +319,18 @@ var removeComponentExtension = (componentPath) => {
|
|
|
260
319
|
}
|
|
261
320
|
return componentPath.slice(0, -1 * ext.length);
|
|
262
321
|
};
|
|
322
|
+
var COMBINED_REACT_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/react/v18";
|
|
323
|
+
var ISLAND_RUNTIME_CONFIG_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/island-runtime/v1";
|
|
324
|
+
function getCombinedReactUrl() {
|
|
325
|
+
const hsEnv = process.env.HS_ENV;
|
|
326
|
+
const fileVersion = hsEnv === "prod" ? `react-combined.mjs` : "react-combined-qa.mjs";
|
|
327
|
+
return `${COMBINED_REACT_BASE_PATH}/${fileVersion}`;
|
|
328
|
+
}
|
|
329
|
+
function getIslandRuntimeConfigUrl() {
|
|
330
|
+
const hsEnv = process.env.HS_ENV;
|
|
331
|
+
const fileVersion = hsEnv === "prod" ? `island-runtime.mjs` : "island-runtime-qa.mjs";
|
|
332
|
+
return `${ISLAND_RUNTIME_CONFIG_BASE_PATH}/${fileVersion}`;
|
|
333
|
+
}
|
|
263
334
|
var findAllComponentsIn = (webRoot, componentsFolder, includeSubdirIndexJS) => {
|
|
264
335
|
const fullComponentsFolderPath = joinPosix(webRoot, componentsFolder);
|
|
265
336
|
const componentsByName = {};
|
|
@@ -369,13 +440,16 @@ export {
|
|
|
369
440
|
MODULE_FOLDER_PATH,
|
|
370
441
|
VIRTUAL_CONFIG_SETUP,
|
|
371
442
|
VIRTUAL_ISLAND_RUNTIME,
|
|
443
|
+
clientIslandEntryPlugin,
|
|
372
444
|
collectCssInDev,
|
|
373
445
|
collectCssModules,
|
|
374
446
|
createIslandsGlobalJsForClientInDev,
|
|
375
447
|
findAllComponentsIn_default as findAllComponentsIn,
|
|
376
448
|
findAllModulesInRoot,
|
|
377
449
|
findAllPartialsInRoot,
|
|
450
|
+
getCombinedReactUrl,
|
|
378
451
|
getComponentExtension,
|
|
452
|
+
getIslandRuntimeConfigUrl,
|
|
379
453
|
getIslandUrls,
|
|
380
454
|
getServerGlobalsToInject,
|
|
381
455
|
hasComponentExtension,
|
|
@@ -386,5 +460,6 @@ export {
|
|
|
386
460
|
renderOnServer,
|
|
387
461
|
renderStreamToPromise,
|
|
388
462
|
resolveIslandPlugin,
|
|
463
|
+
serializeIslandDataToJSON,
|
|
389
464
|
setIn
|
|
390
465
|
};
|