@hubspot/cms-dev-server 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createViteDevServer-5624911d.js +69 -0
- package/dist/index-de34229d.js +525 -0
- package/dist/index-e4860c0f.js +150 -0
- package/dist/index.js +5 -2
- package/dist/index2.js +178 -0
- package/dist/internalSsr.js +12 -11
- package/dist/main.js +52 -0
- package/dist/preview.js +18 -0
- package/dist/run.js +45 -18
- package/dist/storybook-main/main.js +12 -11
- package/package.json +3 -3
- package/types/island-runtime.d.ts +2 -0
- package/dist/fsevents-72LCIACT.node +0 -0
- package/types/generateBpmAliases.d.ts +0 -2
- package/types/noNodeBuiltinsPlugin.d.ts +0 -3
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createContext, useRef, useLayoutEffect } from "react";
|
|
2
|
+
import * as jsxRuntime from "react/jsx-runtime";
|
|
3
|
+
import "stream";
|
|
4
|
+
import "react-dom/server";
|
|
5
|
+
const Fragment = jsxRuntime.Fragment;
|
|
6
|
+
const jsx = jsxRuntime.jsx;
|
|
7
|
+
const jsxs = jsxRuntime.jsxs;
|
|
8
|
+
var define_import_meta_env_default = { DEV: false, PROD: true, SSR: true };
|
|
9
|
+
var renderSequenceNum = 1;
|
|
10
|
+
var createNewServerRequestMap = (renderId) => {
|
|
11
|
+
if (import.meta && define_import_meta_env_default && define_import_meta_env_default.DEBUG) {
|
|
12
|
+
return /* @__PURE__ */ new Map([["__tempRenderId", renderId]]);
|
|
13
|
+
}
|
|
14
|
+
return /* @__PURE__ */ new Map();
|
|
15
|
+
};
|
|
16
|
+
var createServerRenderContext = (pageUrl, environmentConfig, sharedServerRequestData) => {
|
|
17
|
+
const renderId = (renderSequenceNum++).toString(16);
|
|
18
|
+
const perServerRequestData = sharedServerRequestData ?? createNewServerRequestMap(renderId);
|
|
19
|
+
return {
|
|
20
|
+
pageUrl,
|
|
21
|
+
environmentConfig,
|
|
22
|
+
islands: [],
|
|
23
|
+
renderId,
|
|
24
|
+
perServerRequestData,
|
|
25
|
+
messagesForBrowser: [],
|
|
26
|
+
// Satisfies ServerRenderContextValueType
|
|
27
|
+
entryPointBasePath: null
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var createServerRenderContextV2 = (pageUrl, {
|
|
31
|
+
environmentConfig,
|
|
32
|
+
entryPointBasePath,
|
|
33
|
+
sharedServerRequestData
|
|
34
|
+
}) => {
|
|
35
|
+
const renderId = (renderSequenceNum++).toString(16);
|
|
36
|
+
const perServerRequestData = sharedServerRequestData ?? createNewServerRequestMap(renderId);
|
|
37
|
+
return {
|
|
38
|
+
pageUrl,
|
|
39
|
+
environmentConfig,
|
|
40
|
+
islands: [],
|
|
41
|
+
renderId,
|
|
42
|
+
perServerRequestData,
|
|
43
|
+
messagesForBrowser: [],
|
|
44
|
+
entryPointBasePath
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var createEmptyServerRenderContext = () => createServerRenderContextV2(null, { environmentConfig: null });
|
|
48
|
+
var ServerRenderContext = createContext(
|
|
49
|
+
createEmptyServerRenderContext()
|
|
50
|
+
);
|
|
51
|
+
var createClientRenderContext = (hsServerPageUrl, hsBasePath, islands = []) => {
|
|
52
|
+
return {
|
|
53
|
+
pageUrl: hsServerPageUrl,
|
|
54
|
+
islands,
|
|
55
|
+
island: null,
|
|
56
|
+
hydrationFinished: { current: false },
|
|
57
|
+
entryPointBasePath: hsBasePath
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
var ClientRenderContext = createContext(
|
|
61
|
+
createClientRenderContext(null, null)
|
|
62
|
+
);
|
|
63
|
+
var ClientRenderContextProvider = ({
|
|
64
|
+
children,
|
|
65
|
+
islands,
|
|
66
|
+
island,
|
|
67
|
+
pageUrl,
|
|
68
|
+
basePath,
|
|
69
|
+
onTopLevelHydrationFinish
|
|
70
|
+
}) => {
|
|
71
|
+
const hydrationFinished = useRef(false);
|
|
72
|
+
const contextValue = {
|
|
73
|
+
pageUrl,
|
|
74
|
+
islands,
|
|
75
|
+
hydrationFinished,
|
|
76
|
+
island,
|
|
77
|
+
entryPointBasePath: basePath
|
|
78
|
+
};
|
|
79
|
+
useLayoutEffect(() => {
|
|
80
|
+
if (hydrationFinished.current) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
hydrationFinished.current = true;
|
|
84
|
+
if (onTopLevelHydrationFinish) {
|
|
85
|
+
onTopLevelHydrationFinish();
|
|
86
|
+
}
|
|
87
|
+
}, [onTopLevelHydrationFinish]);
|
|
88
|
+
return /* @__PURE__ */ jsx(ClientRenderContext.Provider, { value: contextValue, children });
|
|
89
|
+
};
|
|
90
|
+
var mergeServerRequestData_internal = (dataA, dataB) => {
|
|
91
|
+
const toMerge = [...dataA, ...dataB];
|
|
92
|
+
if (dataA.has("sharedStateIDs") && dataB.has("sharedStateIDs")) {
|
|
93
|
+
const mergedSet = /* @__PURE__ */ new Set([
|
|
94
|
+
...dataA.get("sharedStateIDs"),
|
|
95
|
+
...dataB.get("sharedStateIDs")
|
|
96
|
+
]);
|
|
97
|
+
toMerge.push(["sharedStateIDs", mergedSet]);
|
|
98
|
+
}
|
|
99
|
+
return new Map(toMerge);
|
|
100
|
+
};
|
|
101
|
+
var UNSET_SHARED_STATE_ID = "hs-basic-shared-state-unset-id";
|
|
102
|
+
var ExistingIslandContext = createContext(null);
|
|
103
|
+
ExistingIslandContext.Provider;
|
|
104
|
+
createContext({
|
|
105
|
+
id: UNSET_SHARED_STATE_ID,
|
|
106
|
+
state: null
|
|
107
|
+
});
|
|
108
|
+
function buildStaticEnvConfig(portalID, hublet, hsEnv, hsDeployed, hsJSRGates) {
|
|
109
|
+
const getPortalID2 = () => portalID;
|
|
110
|
+
const getHubID = getPortalID2;
|
|
111
|
+
const getHublet2 = () => hublet;
|
|
112
|
+
const getInternalHSEnv = () => hsEnv;
|
|
113
|
+
const getIsDeployed2 = () => hsDeployed;
|
|
114
|
+
const getGates = () => hsJSRGates;
|
|
115
|
+
const toJSON = () => ({
|
|
116
|
+
portalID,
|
|
117
|
+
hublet,
|
|
118
|
+
hsEnv,
|
|
119
|
+
hsDeployed,
|
|
120
|
+
hsJSRGates
|
|
121
|
+
});
|
|
122
|
+
const equals = (envConfig) => {
|
|
123
|
+
return portalID === envConfig.getPortalID() && hsEnv === envConfig.getInternalHSEnv() && hublet === envConfig.getHublet() && hsDeployed === envConfig.getIsDeployed();
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
getPortalID: getPortalID2,
|
|
127
|
+
getHubID,
|
|
128
|
+
getHublet: getHublet2,
|
|
129
|
+
getInternalHSEnv,
|
|
130
|
+
getIsDeployed: getIsDeployed2,
|
|
131
|
+
equals,
|
|
132
|
+
getGates,
|
|
133
|
+
toJSON
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (import.meta && define_import_meta_env_default && !define_import_meta_env_default.SSR) {
|
|
137
|
+
new URL(window.location.href);
|
|
138
|
+
}
|
|
139
|
+
export {
|
|
140
|
+
ClientRenderContextProvider as C,
|
|
141
|
+
Fragment as F,
|
|
142
|
+
ServerRenderContext as S,
|
|
143
|
+
jsxs as a,
|
|
144
|
+
buildStaticEnvConfig as b,
|
|
145
|
+
createEmptyServerRenderContext as c,
|
|
146
|
+
createServerRenderContextV2 as d,
|
|
147
|
+
createServerRenderContext as e,
|
|
148
|
+
jsx as j,
|
|
149
|
+
mergeServerRequestData_internal as m
|
|
150
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,10 @@ import { createServer as createViteServer } from "vite";
|
|
|
3
3
|
import { default as react } from "@vitejs/plugin-react";
|
|
4
4
|
|
|
5
5
|
// ../cms-js-internal/dist/index.js
|
|
6
|
-
import path
|
|
6
|
+
import path from "path";
|
|
7
7
|
var viteRoot;
|
|
8
8
|
var viteCommand;
|
|
9
|
-
function resolveIslandPlugin() {
|
|
9
|
+
function resolveIslandPlugin(islandsSet) {
|
|
10
10
|
return {
|
|
11
11
|
enforce: "pre",
|
|
12
12
|
name: "resolve-islands",
|
|
@@ -25,6 +25,9 @@ function resolveIslandPlugin() {
|
|
|
25
25
|
);
|
|
26
26
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
27
27
|
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
28
|
+
if (islandsSet) {
|
|
29
|
+
islandsSet.add(moduleId);
|
|
30
|
+
}
|
|
28
31
|
return `
|
|
29
32
|
const moduleId = '${moduleId}';
|
|
30
33
|
|
package/dist/index2.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { j as jsx } from "./index-e4860c0f.js";
|
|
2
|
+
import React, { useEffect } from "react";
|
|
3
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
4
|
+
import { renderFieldsToJson } from "./index-de34229d.js";
|
|
5
|
+
import "react/jsx-runtime";
|
|
6
|
+
import "stream";
|
|
7
|
+
import "path";
|
|
8
|
+
import "fs";
|
|
9
|
+
import "crypto";
|
|
10
|
+
import "path/posix";
|
|
11
|
+
function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
12
|
+
let resultArgTypes = {};
|
|
13
|
+
for (const field of fieldsJson) {
|
|
14
|
+
const fullFieldName = [...currentPathSegments, field.name].join(".");
|
|
15
|
+
switch (field.type) {
|
|
16
|
+
case "group": {
|
|
17
|
+
if (!field.children) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const groupResult = getFieldsArgTypes(field.children, [
|
|
21
|
+
...currentPathSegments,
|
|
22
|
+
field.name
|
|
23
|
+
]);
|
|
24
|
+
resultArgTypes = {
|
|
25
|
+
...resultArgTypes,
|
|
26
|
+
...groupResult
|
|
27
|
+
};
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case "boolean": {
|
|
31
|
+
resultArgTypes[fullFieldName] = {
|
|
32
|
+
control: "boolean",
|
|
33
|
+
defaultValue: field.default
|
|
34
|
+
};
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "text": {
|
|
38
|
+
resultArgTypes[fullFieldName] = {
|
|
39
|
+
control: "text",
|
|
40
|
+
defaultValue: field.default
|
|
41
|
+
};
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "number": {
|
|
45
|
+
resultArgTypes[fullFieldName] = {
|
|
46
|
+
control: "number",
|
|
47
|
+
defaultValue: field.default
|
|
48
|
+
};
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "choice": {
|
|
52
|
+
resultArgTypes[fullFieldName] = {
|
|
53
|
+
control: "select",
|
|
54
|
+
defaultValue: field.default,
|
|
55
|
+
options: field.choices || []
|
|
56
|
+
};
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
default: {
|
|
60
|
+
resultArgTypes[fullFieldName] = {
|
|
61
|
+
control: "object",
|
|
62
|
+
defaultValue: field.default
|
|
63
|
+
};
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return resultArgTypes;
|
|
69
|
+
}
|
|
70
|
+
function getNestedFieldObjectForArgs(_args) {
|
|
71
|
+
const result = {};
|
|
72
|
+
for (const argPath in _args) {
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(_args, argPath)) {
|
|
74
|
+
const argPathSegments = argPath.split(".");
|
|
75
|
+
const nestedSegments = argPathSegments.slice(0, -1);
|
|
76
|
+
const fieldName = argPathSegments[argPathSegments.length - 1];
|
|
77
|
+
const fieldValue = _args[argPath];
|
|
78
|
+
let currentNest = result;
|
|
79
|
+
for (const segment of nestedSegments) {
|
|
80
|
+
if (!Object.prototype.hasOwnProperty.call(currentNest, segment)) {
|
|
81
|
+
currentNest[segment] = {};
|
|
82
|
+
}
|
|
83
|
+
currentNest = currentNest[segment];
|
|
84
|
+
}
|
|
85
|
+
currentNest[fieldName] = fieldValue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
function moduleFieldsToJson(fields) {
|
|
91
|
+
let moduleJson;
|
|
92
|
+
const outputCallback = (callbackJson) => {
|
|
93
|
+
moduleJson = callbackJson;
|
|
94
|
+
};
|
|
95
|
+
renderToStaticMarkup(
|
|
96
|
+
React.cloneElement(fields, {
|
|
97
|
+
outputCallback
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
if (!moduleJson) {
|
|
101
|
+
throw new Error("couldn't render module fields definition to fields.json");
|
|
102
|
+
}
|
|
103
|
+
return moduleJson;
|
|
104
|
+
}
|
|
105
|
+
function moduleArgs(argTypes) {
|
|
106
|
+
const args = {};
|
|
107
|
+
for (const argKey in argTypes) {
|
|
108
|
+
if (Object.hasOwnProperty.call(argTypes, argKey)) {
|
|
109
|
+
args[argKey] = argTypes[argKey].defaultValue;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return args;
|
|
113
|
+
}
|
|
114
|
+
function moduleStory(ModuleComponent, fields, storyArgs) {
|
|
115
|
+
const moduleJson = renderFieldsToJson(fields);
|
|
116
|
+
const argTypes = getFieldsArgTypes(moduleJson);
|
|
117
|
+
const args = { ...moduleArgs(argTypes), ...storyArgs };
|
|
118
|
+
return {
|
|
119
|
+
render: (_args) => {
|
|
120
|
+
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
121
|
+
return /* @__PURE__ */ jsx(ModuleComponent, { ...fieldValues });
|
|
122
|
+
},
|
|
123
|
+
argTypes,
|
|
124
|
+
args
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function moduleStoryWithIsland(fields, moduleName, storyArgs) {
|
|
128
|
+
if (typeof moduleName !== "string") {
|
|
129
|
+
throw new Error(
|
|
130
|
+
"moduleStoryWithIsland takes Fields JSX as the first argument, and the moduleName that matches the file or folder name for the module as a string for the second parameter"
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (!moduleName) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
"moduleStoryWithIsland requires a second moduleName parameter that matches the file or folder name for the module"
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const moduleJson = moduleFieldsToJson(fields);
|
|
139
|
+
const argTypes = getFieldsArgTypes(moduleJson);
|
|
140
|
+
const args = { ...moduleArgs(argTypes), ...storyArgs };
|
|
141
|
+
return {
|
|
142
|
+
argTypes,
|
|
143
|
+
args,
|
|
144
|
+
render: (_args) => {
|
|
145
|
+
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
146
|
+
const fieldValuesString = JSON.stringify(fieldValues);
|
|
147
|
+
const domain = `${window.location.protocol}//${window.location.hostname.replace("storybook.", "")}:3000`;
|
|
148
|
+
const fieldValuesJson = encodeURIComponent(fieldValuesString);
|
|
149
|
+
const iframeSrc = `${domain}/module/${moduleName}?fields=${fieldValuesJson}`;
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
const existingElement = document.querySelector("#hs-module-iframe");
|
|
152
|
+
if (existingElement) {
|
|
153
|
+
existingElement.setAttribute("src", iframeSrc);
|
|
154
|
+
return () => {
|
|
155
|
+
existingElement.remove();
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const iframeElement = document.createElement("iframe");
|
|
159
|
+
iframeElement.setAttribute("src", iframeSrc);
|
|
160
|
+
iframeElement.setAttribute("id", "hs-module-iframe");
|
|
161
|
+
iframeElement.setAttribute(
|
|
162
|
+
"style",
|
|
163
|
+
`border: none;width: 100%;height: 100%;overflow: auto;`
|
|
164
|
+
);
|
|
165
|
+
document.querySelector("#storybook-root").appendChild(iframeElement);
|
|
166
|
+
return () => {
|
|
167
|
+
iframeElement.remove();
|
|
168
|
+
};
|
|
169
|
+
}, [iframeSrc]);
|
|
170
|
+
return /* @__PURE__ */ jsx("div", {});
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export {
|
|
175
|
+
moduleFieldsToJson,
|
|
176
|
+
moduleStory,
|
|
177
|
+
moduleStoryWithIsland
|
|
178
|
+
};
|
package/dist/internalSsr.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// ../cms-js-internal/dist/index.js
|
|
2
|
-
import path
|
|
2
|
+
import path from "path";
|
|
3
3
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
4
4
|
import stream from "stream";
|
|
5
5
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
@@ -198,7 +198,7 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
198
198
|
};
|
|
199
199
|
var viteRoot;
|
|
200
200
|
var viteCommand;
|
|
201
|
-
function resolveIslandPlugin() {
|
|
201
|
+
function resolveIslandPlugin(islandsSet) {
|
|
202
202
|
return {
|
|
203
203
|
enforce: "pre",
|
|
204
204
|
name: "resolve-islands",
|
|
@@ -217,6 +217,9 @@ function resolveIslandPlugin() {
|
|
|
217
217
|
);
|
|
218
218
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
219
219
|
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
220
|
+
if (islandsSet) {
|
|
221
|
+
islandsSet.add(moduleId);
|
|
222
|
+
}
|
|
220
223
|
return `
|
|
221
224
|
const moduleId = '${moduleId}';
|
|
222
225
|
|
|
@@ -423,7 +426,7 @@ function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
|
423
426
|
return false;
|
|
424
427
|
}
|
|
425
428
|
}
|
|
426
|
-
var findAllComponentsIn = (webRoot, componentsFolder
|
|
429
|
+
var findAllComponentsIn = (webRoot, componentsFolder) => {
|
|
427
430
|
const fullComponentsFolderPath = join(webRoot, componentsFolder);
|
|
428
431
|
const componentsByName = {};
|
|
429
432
|
if (!existsSync(fullComponentsFolderPath)) {
|
|
@@ -436,7 +439,7 @@ var findAllComponentsIn = (webRoot, componentsFolder, includeSubdirIndexJS) => {
|
|
|
436
439
|
if (!isDirectory && hasComponentExtension(fileOrFolderName) && !isStorybookStory(fileOrFolderName)) {
|
|
437
440
|
const subdirPathNoExtension = removeComponentExtension(subdirPath);
|
|
438
441
|
componentsByName[subdirPathNoExtension] = subdirPath;
|
|
439
|
-
} else if (isDirectory
|
|
442
|
+
} else if (isDirectory) {
|
|
440
443
|
for (const potentialExtension of COMPONENT_EXTENSIONS) {
|
|
441
444
|
const potentialIndexModule = join(
|
|
442
445
|
subdirPath,
|
|
@@ -459,8 +462,7 @@ var findAllComponentsIn = (webRoot, componentsFolder, includeSubdirIndexJS) => {
|
|
|
459
462
|
function findAllModulesInRoot(webRoot) {
|
|
460
463
|
const allModuleComponents = findAllComponentsIn(
|
|
461
464
|
webRoot,
|
|
462
|
-
"./components/modules"
|
|
463
|
-
true
|
|
465
|
+
"./components/modules"
|
|
464
466
|
);
|
|
465
467
|
const moduleNames = Object.keys(allModuleComponents).map(
|
|
466
468
|
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
@@ -471,13 +473,12 @@ function findAllModulesInRoot(webRoot) {
|
|
|
471
473
|
function findAllPartialsInRoot(webRoot) {
|
|
472
474
|
const allPartialComponents = findAllComponentsIn(
|
|
473
475
|
webRoot,
|
|
474
|
-
"./components/partials"
|
|
475
|
-
false
|
|
476
|
+
"./components/partials"
|
|
476
477
|
);
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
(partialSubpath) => basename(partialSubpath)
|
|
478
|
+
const partialNames = Object.keys(allPartialComponents).map(
|
|
479
|
+
(partialSubpath) => partialSubpath.replace("components/partials/", "").replace("/index", "")
|
|
480
480
|
);
|
|
481
|
+
const partialSubpaths = Object.keys(allPartialComponents);
|
|
481
482
|
return { partialNames, partialSubpaths };
|
|
482
483
|
}
|
|
483
484
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath) {
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { mergeConfig } from "vite";
|
|
3
|
+
const webRoot = process.env.WEB_ROOT;
|
|
4
|
+
const storyPath = path.resolve(process.cwd(), webRoot, "**/*.stories.*");
|
|
5
|
+
const jsRenderingGates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
6
|
+
const main = {
|
|
7
|
+
addons: ["@storybook/addon-essentials"],
|
|
8
|
+
framework: "@storybook/react-vite",
|
|
9
|
+
stories: [storyPath],
|
|
10
|
+
previewHead: (head) => {
|
|
11
|
+
return `
|
|
12
|
+
${head}
|
|
13
|
+
|
|
14
|
+
<script type="module">
|
|
15
|
+
import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
|
|
16
|
+
|
|
17
|
+
initConfigSingletonFromJSON(${JSON.stringify({
|
|
18
|
+
portalId: process.env.portalId,
|
|
19
|
+
hublet: process.env.hublet,
|
|
20
|
+
hsEnv: process.env.hsEnv,
|
|
21
|
+
hsDeployed: false,
|
|
22
|
+
hsJSRGates: jsRenderingGates
|
|
23
|
+
})})
|
|
24
|
+
<\/script>
|
|
25
|
+
|
|
26
|
+
`;
|
|
27
|
+
},
|
|
28
|
+
viteFinal: async (config) => {
|
|
29
|
+
const { resolveIslandPlugin } = await import("./index-de34229d.js");
|
|
30
|
+
const viteConfig = {
|
|
31
|
+
resolve: {
|
|
32
|
+
dedupe: [
|
|
33
|
+
"react",
|
|
34
|
+
"react-dom",
|
|
35
|
+
"@hubspot/cms-components",
|
|
36
|
+
"@hubspot/cms-dev-server"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
optimizeDeps: {
|
|
40
|
+
include: ["react", "react-dom", "react-dom/client"]
|
|
41
|
+
},
|
|
42
|
+
css: {
|
|
43
|
+
postcss: webRoot
|
|
44
|
+
},
|
|
45
|
+
plugins: [resolveIslandPlugin(jsRenderingGates)]
|
|
46
|
+
};
|
|
47
|
+
return mergeConfig(config, viteConfig);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
main as default
|
|
52
|
+
};
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { d as createServerRenderContextV2, j as jsx, C as ClientRenderContextProvider, S as ServerRenderContext } from "./index-e4860c0f.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import "react/jsx-runtime";
|
|
4
|
+
import "stream";
|
|
5
|
+
import "react-dom/server";
|
|
6
|
+
const parameters = {
|
|
7
|
+
actions: { argTypesRegex: "^on[A-Z].*" }
|
|
8
|
+
};
|
|
9
|
+
const contextValue = createServerRenderContextV2("http://testUrl.com", {
|
|
10
|
+
environmentConfig: null
|
|
11
|
+
});
|
|
12
|
+
const decorators = [
|
|
13
|
+
(Story) => /* @__PURE__ */ jsx(ClientRenderContextProvider, { pageUrl: "http://test.com", islands: [], children: /* @__PURE__ */ jsx(ServerRenderContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(Story, {}) }) })
|
|
14
|
+
];
|
|
15
|
+
export {
|
|
16
|
+
decorators,
|
|
17
|
+
parameters
|
|
18
|
+
};
|
package/dist/run.js
CHANGED
|
@@ -55,6 +55,9 @@ function fullOriginalUrlFromRequest(request2) {
|
|
|
55
55
|
return `${request2.protocol}://${request2.get("host")}${request2.originalUrl}`;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// src/lib/renderPartial.ts
|
|
59
|
+
import { join as joinPosix } from "path/posix";
|
|
60
|
+
|
|
58
61
|
// src/lib/renderComponentWithCSS.ts
|
|
59
62
|
import {
|
|
60
63
|
renderToStaticMarkup as renderToStaticMarkup2
|
|
@@ -80,7 +83,7 @@ function packagePath(metaUrl, projectPath) {
|
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
// ../cms-js-internal/dist/index.js
|
|
83
|
-
import path2
|
|
86
|
+
import path2 from "path";
|
|
84
87
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
85
88
|
import stream from "stream";
|
|
86
89
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
@@ -218,7 +221,7 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
218
221
|
};
|
|
219
222
|
var viteRoot;
|
|
220
223
|
var viteCommand;
|
|
221
|
-
function resolveIslandPlugin() {
|
|
224
|
+
function resolveIslandPlugin(islandsSet) {
|
|
222
225
|
return {
|
|
223
226
|
enforce: "pre",
|
|
224
227
|
name: "resolve-islands",
|
|
@@ -237,6 +240,9 @@ function resolveIslandPlugin() {
|
|
|
237
240
|
);
|
|
238
241
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
239
242
|
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
243
|
+
if (islandsSet) {
|
|
244
|
+
islandsSet.add(moduleId);
|
|
245
|
+
}
|
|
240
246
|
return `
|
|
241
247
|
const moduleId = '${moduleId}';
|
|
242
248
|
|
|
@@ -403,7 +409,7 @@ var ENABLED_FEATURES_GATE_MAP = {
|
|
|
403
409
|
function isUngatedFor(gates, gate) {
|
|
404
410
|
return gates.includes(gate);
|
|
405
411
|
}
|
|
406
|
-
var findAllComponentsIn = (webRoot2, componentsFolder
|
|
412
|
+
var findAllComponentsIn = (webRoot2, componentsFolder) => {
|
|
407
413
|
const fullComponentsFolderPath = join(webRoot2, componentsFolder);
|
|
408
414
|
const componentsByName = {};
|
|
409
415
|
if (!existsSync(fullComponentsFolderPath)) {
|
|
@@ -416,7 +422,7 @@ var findAllComponentsIn = (webRoot2, componentsFolder, includeSubdirIndexJS) =>
|
|
|
416
422
|
if (!isDirectory && hasComponentExtension(fileOrFolderName) && !isStorybookStory(fileOrFolderName)) {
|
|
417
423
|
const subdirPathNoExtension = removeComponentExtension(subdirPath);
|
|
418
424
|
componentsByName[subdirPathNoExtension] = subdirPath;
|
|
419
|
-
} else if (isDirectory
|
|
425
|
+
} else if (isDirectory) {
|
|
420
426
|
for (const potentialExtension of COMPONENT_EXTENSIONS) {
|
|
421
427
|
const potentialIndexModule = join(
|
|
422
428
|
subdirPath,
|
|
@@ -439,8 +445,7 @@ var findAllComponentsIn = (webRoot2, componentsFolder, includeSubdirIndexJS) =>
|
|
|
439
445
|
function findAllModulesInRoot(webRoot2) {
|
|
440
446
|
const allModuleComponents = findAllComponentsIn(
|
|
441
447
|
webRoot2,
|
|
442
|
-
"./components/modules"
|
|
443
|
-
true
|
|
448
|
+
"./components/modules"
|
|
444
449
|
);
|
|
445
450
|
const moduleNames = Object.keys(allModuleComponents).map(
|
|
446
451
|
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
@@ -451,13 +456,12 @@ function findAllModulesInRoot(webRoot2) {
|
|
|
451
456
|
function findAllPartialsInRoot(webRoot2) {
|
|
452
457
|
const allPartialComponents = findAllComponentsIn(
|
|
453
458
|
webRoot2,
|
|
454
|
-
"./components/partials"
|
|
455
|
-
false
|
|
459
|
+
"./components/partials"
|
|
456
460
|
);
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
(partialSubpath) => basename(partialSubpath)
|
|
461
|
+
const partialNames = Object.keys(allPartialComponents).map(
|
|
462
|
+
(partialSubpath) => partialSubpath.replace("components/partials/", "").replace("/index", "")
|
|
460
463
|
);
|
|
464
|
+
const partialSubpaths = Object.keys(allPartialComponents);
|
|
461
465
|
return { partialNames, partialSubpaths };
|
|
462
466
|
}
|
|
463
467
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath) {
|
|
@@ -651,6 +655,18 @@ var logPartialInfo = (partialPath, props) => {
|
|
|
651
655
|
};
|
|
652
656
|
|
|
653
657
|
// src/lib/renderPartial.ts
|
|
658
|
+
var lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
659
|
+
let componentModule;
|
|
660
|
+
const insideFolderPath = joinPosix(modulePath, "index");
|
|
661
|
+
try {
|
|
662
|
+
componentModule = await viteServer.ssrLoadModule(insideFolderPath);
|
|
663
|
+
} catch (e) {
|
|
664
|
+
if (!e.message.includes("Failed to load url")) {
|
|
665
|
+
throw e;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return [componentModule, insideFolderPath];
|
|
669
|
+
};
|
|
654
670
|
async function renderPartial(viteServer, partialPath, props, pageUrl, basePath, environmentConfig, renderOptions) {
|
|
655
671
|
try {
|
|
656
672
|
logPartialInfo(partialPath, props);
|
|
@@ -658,17 +674,28 @@ async function renderPartial(viteServer, partialPath, props, pageUrl, basePath,
|
|
|
658
674
|
console.log("unable to log partial prop info");
|
|
659
675
|
console.error(e);
|
|
660
676
|
}
|
|
661
|
-
|
|
677
|
+
let componentModule;
|
|
678
|
+
let resolvedPath;
|
|
679
|
+
if (!hasComponentExtension(partialPath)) {
|
|
680
|
+
[componentModule, resolvedPath] = await lookForModuleInFolder(
|
|
681
|
+
partialPath,
|
|
682
|
+
viteServer
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
if (!componentModule) {
|
|
686
|
+
componentModule = await viteServer.ssrLoadModule(partialPath);
|
|
687
|
+
resolvedPath = componentModule ? partialPath : void 0;
|
|
688
|
+
}
|
|
662
689
|
if (!componentModule) {
|
|
663
690
|
throw new Error(`Couldn't find partial: ${partialPath}`);
|
|
664
691
|
}
|
|
665
692
|
const Component = componentModule.default;
|
|
666
693
|
if (!Component) {
|
|
667
|
-
throw new Error(`Couldn't find default export on partial: ${
|
|
694
|
+
throw new Error(`Couldn't find default export on partial: ${resolvedPath}`);
|
|
668
695
|
}
|
|
669
696
|
return renderComponentWithCSS_default(
|
|
670
697
|
viteServer,
|
|
671
|
-
|
|
698
|
+
resolvedPath,
|
|
672
699
|
Component,
|
|
673
700
|
props,
|
|
674
701
|
pageUrl,
|
|
@@ -934,7 +961,7 @@ import path4 from "path";
|
|
|
934
961
|
import { normalizePath as normalizePath3 } from "vite";
|
|
935
962
|
|
|
936
963
|
// src/lib/renderModule.ts
|
|
937
|
-
import { join as
|
|
964
|
+
import { join as joinPosix2 } from "path/posix";
|
|
938
965
|
import { traverseFieldsJSON } from "@hubspot/cms-components/fields";
|
|
939
966
|
|
|
940
967
|
// src/lib/fetchModuleGraphQLData.ts
|
|
@@ -964,9 +991,9 @@ async function fetchModuleGraphQLData(accountId, query, requestedModulePath, pag
|
|
|
964
991
|
}
|
|
965
992
|
|
|
966
993
|
// src/lib/renderModule.ts
|
|
967
|
-
var
|
|
994
|
+
var lookForModuleInFolder2 = async (modulePath, viteServer) => {
|
|
968
995
|
let componentModule;
|
|
969
|
-
const insideFolderPath =
|
|
996
|
+
const insideFolderPath = joinPosix2(modulePath, "index");
|
|
970
997
|
try {
|
|
971
998
|
componentModule = await viteServer.ssrLoadModule(insideFolderPath);
|
|
972
999
|
} catch (e) {
|
|
@@ -988,7 +1015,7 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
|
|
|
988
1015
|
let dataQueryResult;
|
|
989
1016
|
let foundPath;
|
|
990
1017
|
if (!hasComponentExtension(requestedModulePath)) {
|
|
991
|
-
[componentModule, foundPath] = await
|
|
1018
|
+
[componentModule, foundPath] = await lookForModuleInFolder2(
|
|
992
1019
|
requestedModulePath,
|
|
993
1020
|
viteServer
|
|
994
1021
|
);
|