@hubspot/cms-dev-server 0.6.4 → 0.6.5
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/index2.js +178 -0
- package/dist/internalSsr.js +28 -1
- package/dist/island-runtime.js +171 -0
- package/dist/main.js +52 -0
- package/dist/preview.js +18 -0
- package/dist/run.js +84 -4
- package/dist/storybook/index.js +2 -1
- package/dist/storybook-main/main.js +28 -1
- package/package.json +5 -4
- package/types/island-runtime.d.ts +2 -0
- package/dist/fsevents-72LCIACT.node +0 -0
package/dist/run.js
CHANGED
|
@@ -141,12 +141,39 @@ function getIslandUrls(roots, viteDevServer) {
|
|
|
141
141
|
return tweakedIsland;
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
+
function getPerServerRequestUrls(perServerRequestData, viteDevServer) {
|
|
145
|
+
if (!perServerRequestData.has("sharedStateIDs")) {
|
|
146
|
+
return new Map(perServerRequestData);
|
|
147
|
+
}
|
|
148
|
+
const perServerRequestDataWithUrls = new Map(
|
|
149
|
+
perServerRequestData
|
|
150
|
+
);
|
|
151
|
+
perServerRequestData.get("sharedStateIDs").forEach((id) => {
|
|
152
|
+
const reducer = perServerRequestData.get(id);
|
|
153
|
+
const reducerWithUrl = {
|
|
154
|
+
...reducer,
|
|
155
|
+
reducerFuncModuleUrl: viteDevServer.moduleGraph.getModuleById(
|
|
156
|
+
reducer.reducerFuncModuleId
|
|
157
|
+
).url
|
|
158
|
+
};
|
|
159
|
+
perServerRequestDataWithUrls.set(id, reducerWithUrl);
|
|
160
|
+
});
|
|
161
|
+
return perServerRequestDataWithUrls;
|
|
162
|
+
}
|
|
144
163
|
var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent) => {
|
|
145
164
|
const islands = getIslandUrls(roots, viteDevServer);
|
|
165
|
+
const perServerRequestDataWithUrls = getPerServerRequestUrls(
|
|
166
|
+
perServerRequestData,
|
|
167
|
+
viteDevServer
|
|
168
|
+
);
|
|
146
169
|
return `window.__islands = ${serializeIslandDataToJSON(
|
|
147
170
|
islands,
|
|
148
171
|
indent
|
|
149
|
-
)}${writeSharedStateToJsGlobal(
|
|
172
|
+
)}${writeSharedStateToJsGlobal(
|
|
173
|
+
islands,
|
|
174
|
+
perServerRequestDataWithUrls,
|
|
175
|
+
indent
|
|
176
|
+
)}`;
|
|
150
177
|
};
|
|
151
178
|
var ENABLED_FEATURES_GATE_MAP = {
|
|
152
179
|
"cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
|
|
@@ -614,7 +641,10 @@ var generateIslandSetupScriptBlock = (gates) => {
|
|
|
614
641
|
initConfigSingletonFromJSON(window.__hsEnvConfig);
|
|
615
642
|
</script>
|
|
616
643
|
<script type="module">
|
|
617
|
-
import { setupIslandHydration } from '
|
|
644
|
+
import { setupIslandHydration } from '${packagePath(
|
|
645
|
+
import.meta.url,
|
|
646
|
+
"island-runtime"
|
|
647
|
+
)}';
|
|
618
648
|
setupIslandHydration();
|
|
619
649
|
</script>
|
|
620
650
|
`;
|
|
@@ -864,6 +894,34 @@ import { normalizePath as normalizePath3 } from "vite";
|
|
|
864
894
|
// src/lib/renderModule.ts
|
|
865
895
|
import { join as joinPosix } from "path/posix";
|
|
866
896
|
import { traverseFieldsJSON } from "@hubspot/cms-components/fields";
|
|
897
|
+
|
|
898
|
+
// src/lib/fetchModuleGraphQLData.ts
|
|
899
|
+
import cliHttp from "@hubspot/cli-lib/http.js";
|
|
900
|
+
var graphQLCache = /* @__PURE__ */ new Map();
|
|
901
|
+
async function fetchModuleGraphQLData(accountId, query, requestedModulePath, pageUrl) {
|
|
902
|
+
const { searchParams } = new URL(pageUrl);
|
|
903
|
+
const hsLocalQueryKey = searchParams.get("hsLocalQueryKey");
|
|
904
|
+
const compositeQueryKey = `${hsLocalQueryKey}:${query}`;
|
|
905
|
+
let dataQueryResult;
|
|
906
|
+
if (graphQLCache.has(compositeQueryKey)) {
|
|
907
|
+
console.log(`Using cached GraphQL Query for ${requestedModulePath}`);
|
|
908
|
+
return Promise.resolve(graphQLCache.get(compositeQueryKey));
|
|
909
|
+
}
|
|
910
|
+
try {
|
|
911
|
+
dataQueryResult = await cliHttp.post(accountId, {
|
|
912
|
+
uri: "/collector/v3/graphql",
|
|
913
|
+
body: {
|
|
914
|
+
query
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
} catch (e) {
|
|
918
|
+
throw new Error(e);
|
|
919
|
+
}
|
|
920
|
+
graphQLCache.set(compositeQueryKey, dataQueryResult);
|
|
921
|
+
return dataQueryResult;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// src/lib/renderModule.ts
|
|
867
925
|
var lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
868
926
|
let componentModule;
|
|
869
927
|
const insideFolderPath = joinPosix(modulePath, "index");
|
|
@@ -884,6 +942,7 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
884
942
|
);
|
|
885
943
|
let serverSideProps;
|
|
886
944
|
let componentModule;
|
|
945
|
+
let dataQueryResult;
|
|
887
946
|
let foundPath;
|
|
888
947
|
if (!hasComponentExtension(requestedModulePath)) {
|
|
889
948
|
[componentModule, foundPath] = await lookForModuleInFolder(
|
|
@@ -923,11 +982,32 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
923
982
|
console.error(e);
|
|
924
983
|
}
|
|
925
984
|
}
|
|
985
|
+
if (componentModule.query && typeof componentModule.query === "string") {
|
|
986
|
+
try {
|
|
987
|
+
dataQueryResult = await fetchModuleGraphQLData(
|
|
988
|
+
environmentConfig.getHubID(),
|
|
989
|
+
componentModule.query,
|
|
990
|
+
requestedModulePath,
|
|
991
|
+
pageUrl
|
|
992
|
+
);
|
|
993
|
+
if (dataQueryResult.errors && dataQueryResult.errors.length) {
|
|
994
|
+
dataQueryResult.errors.forEach((graphQLError) => {
|
|
995
|
+
console.error(graphQLError);
|
|
996
|
+
});
|
|
997
|
+
console.error("Your GraphQL query resulted in the above errors");
|
|
998
|
+
}
|
|
999
|
+
} catch (error) {
|
|
1000
|
+
console.error(error.message);
|
|
1001
|
+
console.error(
|
|
1002
|
+
`Failed to execute query for ${requestedModulePath}. Check the above error message for more information.`
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
926
1006
|
return renderComponentWithCSS_default(
|
|
927
1007
|
viteServer,
|
|
928
1008
|
foundPath,
|
|
929
1009
|
Component,
|
|
930
|
-
{ ...props, ...serverSideProps },
|
|
1010
|
+
{ ...props, ...serverSideProps, dataQueryResult },
|
|
931
1011
|
pageUrl,
|
|
932
1012
|
basePath,
|
|
933
1013
|
environmentConfig,
|
|
@@ -2144,7 +2224,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
|
|
|
2144
2224
|
);
|
|
2145
2225
|
let authedPortalId = null;
|
|
2146
2226
|
let authedEnv = null;
|
|
2147
|
-
let jsRenderingGates = [];
|
|
2227
|
+
let jsRenderingGates = ["CMS:JSRenderer:SharedDeps"];
|
|
2148
2228
|
let personalAccessKey = null;
|
|
2149
2229
|
if (hubspotCliConfigPathOption2 && hubspotCliAccountNameOption2) {
|
|
2150
2230
|
console.log(
|
package/dist/storybook/index.js
CHANGED
|
@@ -60,10 +60,11 @@ function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
|
60
60
|
break;
|
|
61
61
|
}
|
|
62
62
|
case "choice": {
|
|
63
|
+
const options = field.choices ? field.choices.map((choice) => choice[1]) : [];
|
|
63
64
|
resultArgTypes[fullFieldName] = {
|
|
64
65
|
control: "select",
|
|
65
66
|
defaultValue: field.default,
|
|
66
|
-
options
|
|
67
|
+
options
|
|
67
68
|
};
|
|
68
69
|
break;
|
|
69
70
|
}
|
|
@@ -94,6 +94,25 @@ function getIslandUrls(roots, viteDevServer) {
|
|
|
94
94
|
return tweakedIsland;
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
+
function getPerServerRequestUrls(perServerRequestData, viteDevServer) {
|
|
98
|
+
if (!perServerRequestData.has("sharedStateIDs")) {
|
|
99
|
+
return new Map(perServerRequestData);
|
|
100
|
+
}
|
|
101
|
+
const perServerRequestDataWithUrls = new Map(
|
|
102
|
+
perServerRequestData
|
|
103
|
+
);
|
|
104
|
+
perServerRequestData.get("sharedStateIDs").forEach((id) => {
|
|
105
|
+
const reducer = perServerRequestData.get(id);
|
|
106
|
+
const reducerWithUrl = {
|
|
107
|
+
...reducer,
|
|
108
|
+
reducerFuncModuleUrl: viteDevServer.moduleGraph.getModuleById(
|
|
109
|
+
reducer.reducerFuncModuleId
|
|
110
|
+
).url
|
|
111
|
+
};
|
|
112
|
+
perServerRequestDataWithUrls.set(id, reducerWithUrl);
|
|
113
|
+
});
|
|
114
|
+
return perServerRequestDataWithUrls;
|
|
115
|
+
}
|
|
97
116
|
function isUngatedFor(gates, gate) {
|
|
98
117
|
return gates.includes(gate);
|
|
99
118
|
}
|
|
@@ -398,10 +417,18 @@ ${indentString}`);
|
|
|
398
417
|
};
|
|
399
418
|
createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent) => {
|
|
400
419
|
const islands = getIslandUrls(roots, viteDevServer);
|
|
420
|
+
const perServerRequestDataWithUrls = getPerServerRequestUrls(
|
|
421
|
+
perServerRequestData,
|
|
422
|
+
viteDevServer
|
|
423
|
+
);
|
|
401
424
|
return `window.__islands = ${serializeIslandDataToJSON(
|
|
402
425
|
islands,
|
|
403
426
|
indent
|
|
404
|
-
)}${writeSharedStateToJsGlobal(
|
|
427
|
+
)}${writeSharedStateToJsGlobal(
|
|
428
|
+
islands,
|
|
429
|
+
perServerRequestDataWithUrls,
|
|
430
|
+
indent
|
|
431
|
+
)}`;
|
|
405
432
|
};
|
|
406
433
|
GATES = [
|
|
407
434
|
"CMS:JSRenderer:SharedDeps",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -20,11 +20,12 @@
|
|
|
20
20
|
"runBuild": "node dist/run.js",
|
|
21
21
|
"start": "ts-node-esm --transpileOnly runWhenDeveloping.ts",
|
|
22
22
|
"start-inspect": "node --loader ts-node/esm --inspect runWhenDeveloping.ts",
|
|
23
|
-
"test": "NODE_ENV=test vitest run"
|
|
23
|
+
"test": "NODE_ENV=test vitest run",
|
|
24
|
+
"test:watch": "NODE_ENV=test vitest watch"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@hubspot/cli-lib": "^3.0.12",
|
|
27
|
-
"@hubspot/cms-components": "^0.6.
|
|
28
|
+
"@hubspot/cms-components": "^0.6.5",
|
|
28
29
|
"@storybook/addon-actions": "7.0.7",
|
|
29
30
|
"@storybook/addon-essentials": "7.0.7",
|
|
30
31
|
"@storybook/addon-interactions": "7.0.7",
|
|
@@ -96,5 +97,5 @@
|
|
|
96
97
|
"publishConfig": {
|
|
97
98
|
"access": "public"
|
|
98
99
|
},
|
|
99
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "08f0ed34d2c4f3c7ddf6cec03b6e07d83ff46922"
|
|
100
101
|
}
|
|
Binary file
|