@hubspot/cms-dev-server 0.8.1 → 0.8.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 +1 -1
- package/dist/internalSsr.js +31 -19
- package/dist/run.js +64 -23
- package/dist/storybook/index.js +25 -7
- package/dist/storybook-main/main.js +31 -19
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ 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
9
|
function resolveIslandPlugin(islandsSet) {
|
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";
|
|
@@ -8,7 +8,7 @@ import { ServerRenderContext } from "@hubspot/cms-components";
|
|
|
8
8
|
import { createHash } from "crypto";
|
|
9
9
|
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
10
10
|
import { join } from "path/posix";
|
|
11
|
-
import { cloneElement } from "react";
|
|
11
|
+
import { isValidElement, cloneElement } from "react";
|
|
12
12
|
var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
13
13
|
var ENTRY_POINTS_PATH = "components/partials/";
|
|
14
14
|
var MODULE_FOLDER_PATH = "components/modules/";
|
|
@@ -402,13 +402,9 @@ function getIslandRuntimeConfigUrl() {
|
|
|
402
402
|
const fileVersion = hsEnv === "prod" ? `island-runtime.mjs` : "island-runtime-qa.mjs";
|
|
403
403
|
return `${ISLAND_RUNTIME_CONFIG_BASE_PATH}/${fileVersion}`;
|
|
404
404
|
}
|
|
405
|
-
var GATES = [
|
|
406
|
-
"CMS:JSRenderer:GetServerSideProps",
|
|
407
|
-
"CMS:JSRenderer:SeparateIslandRenderOption"
|
|
408
|
-
];
|
|
405
|
+
var GATES = ["CMS:JSRenderer:GetServerSideProps"];
|
|
409
406
|
var ENABLED_FEATURES_GATE_MAP = {
|
|
410
|
-
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps"
|
|
411
|
-
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
407
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps"
|
|
412
408
|
};
|
|
413
409
|
function isUngatedFor(gates, gate) {
|
|
414
410
|
return gates.includes(gate);
|
|
@@ -426,7 +422,7 @@ function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
|
426
422
|
return false;
|
|
427
423
|
}
|
|
428
424
|
}
|
|
429
|
-
var findAllComponentsIn = (webRoot, componentsFolder
|
|
425
|
+
var findAllComponentsIn = (webRoot, componentsFolder) => {
|
|
430
426
|
const fullComponentsFolderPath = join(webRoot, componentsFolder);
|
|
431
427
|
const componentsByName = {};
|
|
432
428
|
if (!existsSync(fullComponentsFolderPath)) {
|
|
@@ -439,7 +435,7 @@ var findAllComponentsIn = (webRoot, componentsFolder, includeSubdirIndexJS) => {
|
|
|
439
435
|
if (!isDirectory && hasComponentExtension(fileOrFolderName) && !isStorybookStory(fileOrFolderName)) {
|
|
440
436
|
const subdirPathNoExtension = removeComponentExtension(subdirPath);
|
|
441
437
|
componentsByName[subdirPathNoExtension] = subdirPath;
|
|
442
|
-
} else if (isDirectory
|
|
438
|
+
} else if (isDirectory) {
|
|
443
439
|
for (const potentialExtension of COMPONENT_EXTENSIONS) {
|
|
444
440
|
const potentialIndexModule = join(
|
|
445
441
|
subdirPath,
|
|
@@ -462,8 +458,7 @@ var findAllComponentsIn = (webRoot, componentsFolder, includeSubdirIndexJS) => {
|
|
|
462
458
|
function findAllModulesInRoot(webRoot) {
|
|
463
459
|
const allModuleComponents = findAllComponentsIn(
|
|
464
460
|
webRoot,
|
|
465
|
-
"./components/modules"
|
|
466
|
-
true
|
|
461
|
+
"./components/modules"
|
|
467
462
|
);
|
|
468
463
|
const moduleNames = Object.keys(allModuleComponents).map(
|
|
469
464
|
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
@@ -474,13 +469,12 @@ function findAllModulesInRoot(webRoot) {
|
|
|
474
469
|
function findAllPartialsInRoot(webRoot) {
|
|
475
470
|
const allPartialComponents = findAllComponentsIn(
|
|
476
471
|
webRoot,
|
|
477
|
-
"./components/partials"
|
|
478
|
-
false
|
|
472
|
+
"./components/partials"
|
|
479
473
|
);
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
(partialSubpath) => basename(partialSubpath)
|
|
474
|
+
const partialNames = Object.keys(allPartialComponents).map(
|
|
475
|
+
(partialSubpath) => partialSubpath.replace("components/partials/", "").replace("/index", "")
|
|
483
476
|
);
|
|
477
|
+
const partialSubpaths = Object.keys(allPartialComponents);
|
|
484
478
|
return { partialNames, partialSubpaths };
|
|
485
479
|
}
|
|
486
480
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath) {
|
|
@@ -540,13 +534,13 @@ function setIn(object, nestedKeysArray, value) {
|
|
|
540
534
|
curr[finalKey] = value;
|
|
541
535
|
}
|
|
542
536
|
}
|
|
543
|
-
function
|
|
537
|
+
function renderFieldsJSX(fieldsJSX) {
|
|
544
538
|
let moduleJson;
|
|
545
539
|
const outputCallback = (callbackJson) => {
|
|
546
540
|
moduleJson = callbackJson;
|
|
547
541
|
};
|
|
548
542
|
renderToStaticMarkup(
|
|
549
|
-
cloneElement(
|
|
543
|
+
cloneElement(fieldsJSX, {
|
|
550
544
|
outputCallback
|
|
551
545
|
})
|
|
552
546
|
);
|
|
@@ -555,6 +549,24 @@ function renderFieldsToJson(fields) {
|
|
|
555
549
|
}
|
|
556
550
|
return moduleJson;
|
|
557
551
|
}
|
|
552
|
+
function renderFieldsToJson(fields, moduleName) {
|
|
553
|
+
let fieldsJSON;
|
|
554
|
+
try {
|
|
555
|
+
if (isValidElement(fields)) {
|
|
556
|
+
fieldsJSON = renderFieldsJSX(fields);
|
|
557
|
+
} else if (Array.isArray(fields)) {
|
|
558
|
+
fieldsJSON = fields;
|
|
559
|
+
} else {
|
|
560
|
+
throw new Error(
|
|
561
|
+
`Couldn't recognize \`fields\` value for module ${moduleName}`
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
return fieldsJSON;
|
|
565
|
+
} catch (e) {
|
|
566
|
+
e.message = `Error when rendering fields for ${moduleName}: ${e.message}`;
|
|
567
|
+
throw e;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
558
570
|
function isStylesheetAsset(staticAsset) {
|
|
559
571
|
return staticAsset.type === "stylesheet";
|
|
560
572
|
}
|
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";
|
|
@@ -89,7 +92,7 @@ import { ServerRenderContext } from "@hubspot/cms-components";
|
|
|
89
92
|
import { createHash } from "crypto";
|
|
90
93
|
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
91
94
|
import { join } from "path/posix";
|
|
92
|
-
import { cloneElement } from "react";
|
|
95
|
+
import { isValidElement, cloneElement } from "react";
|
|
93
96
|
var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
94
97
|
var ENTRY_POINTS_PATH = "components/partials/";
|
|
95
98
|
var MODULE_FOLDER_PATH = "components/modules/";
|
|
@@ -400,13 +403,12 @@ function getEntryPointHashWithIndexSuffix(entryPoint, index) {
|
|
|
400
403
|
return `${getEntryPointHash(entryPoint)}${renderIndexSuffix}`;
|
|
401
404
|
}
|
|
402
405
|
var ENABLED_FEATURES_GATE_MAP = {
|
|
403
|
-
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps"
|
|
404
|
-
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
406
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps"
|
|
405
407
|
};
|
|
406
408
|
function isUngatedFor(gates, gate) {
|
|
407
409
|
return gates.includes(gate);
|
|
408
410
|
}
|
|
409
|
-
var findAllComponentsIn = (webRoot2, componentsFolder
|
|
411
|
+
var findAllComponentsIn = (webRoot2, componentsFolder) => {
|
|
410
412
|
const fullComponentsFolderPath = join(webRoot2, componentsFolder);
|
|
411
413
|
const componentsByName = {};
|
|
412
414
|
if (!existsSync(fullComponentsFolderPath)) {
|
|
@@ -419,7 +421,7 @@ var findAllComponentsIn = (webRoot2, componentsFolder, includeSubdirIndexJS) =>
|
|
|
419
421
|
if (!isDirectory && hasComponentExtension(fileOrFolderName) && !isStorybookStory(fileOrFolderName)) {
|
|
420
422
|
const subdirPathNoExtension = removeComponentExtension(subdirPath);
|
|
421
423
|
componentsByName[subdirPathNoExtension] = subdirPath;
|
|
422
|
-
} else if (isDirectory
|
|
424
|
+
} else if (isDirectory) {
|
|
423
425
|
for (const potentialExtension of COMPONENT_EXTENSIONS) {
|
|
424
426
|
const potentialIndexModule = join(
|
|
425
427
|
subdirPath,
|
|
@@ -442,8 +444,7 @@ var findAllComponentsIn = (webRoot2, componentsFolder, includeSubdirIndexJS) =>
|
|
|
442
444
|
function findAllModulesInRoot(webRoot2) {
|
|
443
445
|
const allModuleComponents = findAllComponentsIn(
|
|
444
446
|
webRoot2,
|
|
445
|
-
"./components/modules"
|
|
446
|
-
true
|
|
447
|
+
"./components/modules"
|
|
447
448
|
);
|
|
448
449
|
const moduleNames = Object.keys(allModuleComponents).map(
|
|
449
450
|
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
@@ -454,13 +455,12 @@ function findAllModulesInRoot(webRoot2) {
|
|
|
454
455
|
function findAllPartialsInRoot(webRoot2) {
|
|
455
456
|
const allPartialComponents = findAllComponentsIn(
|
|
456
457
|
webRoot2,
|
|
457
|
-
"./components/partials"
|
|
458
|
-
false
|
|
458
|
+
"./components/partials"
|
|
459
459
|
);
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
(partialSubpath) => basename(partialSubpath)
|
|
460
|
+
const partialNames = Object.keys(allPartialComponents).map(
|
|
461
|
+
(partialSubpath) => partialSubpath.replace("components/partials/", "").replace("/index", "")
|
|
463
462
|
);
|
|
463
|
+
const partialSubpaths = Object.keys(allPartialComponents);
|
|
464
464
|
return { partialNames, partialSubpaths };
|
|
465
465
|
}
|
|
466
466
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath) {
|
|
@@ -520,13 +520,13 @@ function setIn(object, nestedKeysArray, value) {
|
|
|
520
520
|
curr[finalKey] = value;
|
|
521
521
|
}
|
|
522
522
|
}
|
|
523
|
-
function
|
|
523
|
+
function renderFieldsJSX(fieldsJSX) {
|
|
524
524
|
let moduleJson;
|
|
525
525
|
const outputCallback = (callbackJson) => {
|
|
526
526
|
moduleJson = callbackJson;
|
|
527
527
|
};
|
|
528
528
|
renderToStaticMarkup(
|
|
529
|
-
cloneElement(
|
|
529
|
+
cloneElement(fieldsJSX, {
|
|
530
530
|
outputCallback
|
|
531
531
|
})
|
|
532
532
|
);
|
|
@@ -535,6 +535,24 @@ function renderFieldsToJson(fields) {
|
|
|
535
535
|
}
|
|
536
536
|
return moduleJson;
|
|
537
537
|
}
|
|
538
|
+
function renderFieldsToJson(fields, moduleName) {
|
|
539
|
+
let fieldsJSON;
|
|
540
|
+
try {
|
|
541
|
+
if (isValidElement(fields)) {
|
|
542
|
+
fieldsJSON = renderFieldsJSX(fields);
|
|
543
|
+
} else if (Array.isArray(fields)) {
|
|
544
|
+
fieldsJSON = fields;
|
|
545
|
+
} else {
|
|
546
|
+
throw new Error(
|
|
547
|
+
`Couldn't recognize \`fields\` value for module ${moduleName}`
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
return fieldsJSON;
|
|
551
|
+
} catch (e) {
|
|
552
|
+
e.message = `Error when rendering fields for ${moduleName}: ${e.message}`;
|
|
553
|
+
throw e;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
538
556
|
|
|
539
557
|
// src/lib/moduleGraph.ts
|
|
540
558
|
var findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
|
|
@@ -654,6 +672,18 @@ var logPartialInfo = (partialPath, props) => {
|
|
|
654
672
|
};
|
|
655
673
|
|
|
656
674
|
// src/lib/renderPartial.ts
|
|
675
|
+
var lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
676
|
+
let componentModule;
|
|
677
|
+
const insideFolderPath = joinPosix(modulePath, "index");
|
|
678
|
+
try {
|
|
679
|
+
componentModule = await viteServer.ssrLoadModule(insideFolderPath);
|
|
680
|
+
} catch (e) {
|
|
681
|
+
if (!e.message.includes("Failed to load url")) {
|
|
682
|
+
throw e;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return [componentModule, insideFolderPath];
|
|
686
|
+
};
|
|
657
687
|
async function renderPartial(viteServer, partialPath, props, pageUrl, basePath, environmentConfig, renderOptions) {
|
|
658
688
|
try {
|
|
659
689
|
logPartialInfo(partialPath, props);
|
|
@@ -661,17 +691,28 @@ async function renderPartial(viteServer, partialPath, props, pageUrl, basePath,
|
|
|
661
691
|
console.log("unable to log partial prop info");
|
|
662
692
|
console.error(e);
|
|
663
693
|
}
|
|
664
|
-
|
|
694
|
+
let componentModule;
|
|
695
|
+
let resolvedPath;
|
|
696
|
+
if (!hasComponentExtension(partialPath)) {
|
|
697
|
+
[componentModule, resolvedPath] = await lookForModuleInFolder(
|
|
698
|
+
partialPath,
|
|
699
|
+
viteServer
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
if (!componentModule) {
|
|
703
|
+
componentModule = await viteServer.ssrLoadModule(partialPath);
|
|
704
|
+
resolvedPath = componentModule ? partialPath : void 0;
|
|
705
|
+
}
|
|
665
706
|
if (!componentModule) {
|
|
666
707
|
throw new Error(`Couldn't find partial: ${partialPath}`);
|
|
667
708
|
}
|
|
668
709
|
const Component = componentModule.default;
|
|
669
710
|
if (!Component) {
|
|
670
|
-
throw new Error(`Couldn't find default export on partial: ${
|
|
711
|
+
throw new Error(`Couldn't find default export on partial: ${resolvedPath}`);
|
|
671
712
|
}
|
|
672
713
|
return renderComponentWithCSS_default(
|
|
673
714
|
viteServer,
|
|
674
|
-
|
|
715
|
+
resolvedPath,
|
|
675
716
|
Component,
|
|
676
717
|
props,
|
|
677
718
|
pageUrl,
|
|
@@ -937,7 +978,7 @@ import path4 from "path";
|
|
|
937
978
|
import { normalizePath as normalizePath3 } from "vite";
|
|
938
979
|
|
|
939
980
|
// src/lib/renderModule.ts
|
|
940
|
-
import { join as
|
|
981
|
+
import { join as joinPosix2 } from "path/posix";
|
|
941
982
|
import { traverseFieldsJSON } from "@hubspot/cms-components/fields";
|
|
942
983
|
|
|
943
984
|
// src/lib/fetchModuleGraphQLData.ts
|
|
@@ -967,9 +1008,9 @@ async function fetchModuleGraphQLData(accountId, query, requestedModulePath, pag
|
|
|
967
1008
|
}
|
|
968
1009
|
|
|
969
1010
|
// src/lib/renderModule.ts
|
|
970
|
-
var
|
|
1011
|
+
var lookForModuleInFolder2 = async (modulePath, viteServer) => {
|
|
971
1012
|
let componentModule;
|
|
972
|
-
const insideFolderPath =
|
|
1013
|
+
const insideFolderPath = joinPosix2(modulePath, "index");
|
|
973
1014
|
try {
|
|
974
1015
|
componentModule = await viteServer.ssrLoadModule(insideFolderPath);
|
|
975
1016
|
} catch (e) {
|
|
@@ -991,7 +1032,7 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
|
|
|
991
1032
|
let dataQueryResult;
|
|
992
1033
|
let foundPath;
|
|
993
1034
|
if (!hasComponentExtension(requestedModulePath)) {
|
|
994
|
-
[componentModule, foundPath] = await
|
|
1035
|
+
[componentModule, foundPath] = await lookForModuleInFolder2(
|
|
995
1036
|
requestedModulePath,
|
|
996
1037
|
viteServer
|
|
997
1038
|
);
|
|
@@ -1015,7 +1056,7 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
|
|
|
1015
1056
|
} else if (!meta) {
|
|
1016
1057
|
throw new Error(`Module does not have a named meta export: ${foundPath}`);
|
|
1017
1058
|
}
|
|
1018
|
-
const fieldsJSON = renderFieldsToJson(fields);
|
|
1059
|
+
const fieldsJSON = renderFieldsToJson(fields, requestedModulePath);
|
|
1019
1060
|
const fieldValues = getFieldValuesForModule(fieldsJSON, fieldOverrides);
|
|
1020
1061
|
if (componentModule.query && typeof componentModule.query === "string") {
|
|
1021
1062
|
try {
|
package/dist/storybook/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useEffect } from "react";
|
|
|
3
3
|
|
|
4
4
|
// ../cms-js-internal/dist/index.js
|
|
5
5
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
6
|
-
import { cloneElement } from "react";
|
|
6
|
+
import { isValidElement, cloneElement } from "react";
|
|
7
7
|
function namespaceModulePropsShape(props) {
|
|
8
8
|
const {
|
|
9
9
|
dataQueryResult,
|
|
@@ -25,13 +25,13 @@ function namespaceModulePropsShape(props) {
|
|
|
25
25
|
hublParameters
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function renderFieldsJSX(fieldsJSX) {
|
|
29
29
|
let moduleJson;
|
|
30
30
|
const outputCallback = (callbackJson) => {
|
|
31
31
|
moduleJson = callbackJson;
|
|
32
32
|
};
|
|
33
33
|
renderToStaticMarkup(
|
|
34
|
-
cloneElement(
|
|
34
|
+
cloneElement(fieldsJSX, {
|
|
35
35
|
outputCallback
|
|
36
36
|
})
|
|
37
37
|
);
|
|
@@ -40,6 +40,24 @@ function renderFieldsToJson(fields) {
|
|
|
40
40
|
}
|
|
41
41
|
return moduleJson;
|
|
42
42
|
}
|
|
43
|
+
function renderFieldsToJson(fields, moduleName) {
|
|
44
|
+
let fieldsJSON;
|
|
45
|
+
try {
|
|
46
|
+
if (isValidElement(fields)) {
|
|
47
|
+
fieldsJSON = renderFieldsJSX(fields);
|
|
48
|
+
} else if (Array.isArray(fields)) {
|
|
49
|
+
fieldsJSON = fields;
|
|
50
|
+
} else {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Couldn't recognize \`fields\` value for module ${moduleName}`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return fieldsJSON;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
e.message = `Error when rendering fields for ${moduleName}: ${e.message}`;
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
43
61
|
|
|
44
62
|
// src/storybook/getFieldsArgTypes.ts
|
|
45
63
|
function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
@@ -137,8 +155,8 @@ function moduleArgs(argTypes) {
|
|
|
137
155
|
return args;
|
|
138
156
|
}
|
|
139
157
|
function moduleStory(ModuleComponent, fields, storyArgs) {
|
|
140
|
-
const
|
|
141
|
-
const argTypes = getFieldsArgTypes(
|
|
158
|
+
const fieldsJSON = renderFieldsToJson(fields, ModuleComponent.name);
|
|
159
|
+
const argTypes = getFieldsArgTypes(fieldsJSON);
|
|
142
160
|
const args = { ...moduleArgs(argTypes), ...storyArgs };
|
|
143
161
|
return {
|
|
144
162
|
render: (_args) => {
|
|
@@ -161,8 +179,8 @@ function moduleStoryWithIsland(moduleName, fields, storyArgs) {
|
|
|
161
179
|
"moduleStoryWithIsland requires a second parameter of the module's fields configuration"
|
|
162
180
|
);
|
|
163
181
|
}
|
|
164
|
-
const
|
|
165
|
-
const argTypes = getFieldsArgTypes(
|
|
182
|
+
const fieldsJSON = renderFieldsToJson(fields, moduleName);
|
|
183
|
+
const argTypes = getFieldsArgTypes(fieldsJSON);
|
|
166
184
|
const args = { ...moduleArgs(argTypes), ...storyArgs };
|
|
167
185
|
return {
|
|
168
186
|
argTypes,
|
|
@@ -50,7 +50,7 @@ __export(dist_exports, {
|
|
|
50
50
|
ungatedAtBuildTimeFor: () => ungatedAtBuildTimeFor,
|
|
51
51
|
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
|
|
52
52
|
});
|
|
53
|
-
import path
|
|
53
|
+
import path from "path";
|
|
54
54
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
55
55
|
import stream from "stream";
|
|
56
56
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
@@ -59,7 +59,7 @@ import { ServerRenderContext } from "@hubspot/cms-components";
|
|
|
59
59
|
import { createHash } from "crypto";
|
|
60
60
|
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
61
61
|
import { join } from "path/posix";
|
|
62
|
-
import { cloneElement } from "react";
|
|
62
|
+
import { isValidElement, cloneElement } from "react";
|
|
63
63
|
function createPreloadLink(assetPath, basePath = "") {
|
|
64
64
|
if (assetPath && assetPath[0] !== "/") {
|
|
65
65
|
assetPath = `/${assetPath}`;
|
|
@@ -255,8 +255,7 @@ function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
|
255
255
|
function findAllModulesInRoot(webRoot2) {
|
|
256
256
|
const allModuleComponents = findAllComponentsIn(
|
|
257
257
|
webRoot2,
|
|
258
|
-
"./components/modules"
|
|
259
|
-
true
|
|
258
|
+
"./components/modules"
|
|
260
259
|
);
|
|
261
260
|
const moduleNames = Object.keys(allModuleComponents).map(
|
|
262
261
|
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
@@ -267,13 +266,12 @@ function findAllModulesInRoot(webRoot2) {
|
|
|
267
266
|
function findAllPartialsInRoot(webRoot2) {
|
|
268
267
|
const allPartialComponents = findAllComponentsIn(
|
|
269
268
|
webRoot2,
|
|
270
|
-
"./components/partials"
|
|
271
|
-
false
|
|
269
|
+
"./components/partials"
|
|
272
270
|
);
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
(partialSubpath) => basename(partialSubpath)
|
|
271
|
+
const partialNames = Object.keys(allPartialComponents).map(
|
|
272
|
+
(partialSubpath) => partialSubpath.replace("components/partials/", "").replace("/index", "")
|
|
276
273
|
);
|
|
274
|
+
const partialSubpaths = Object.keys(allPartialComponents);
|
|
277
275
|
return { partialNames, partialSubpaths };
|
|
278
276
|
}
|
|
279
277
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath) {
|
|
@@ -333,13 +331,13 @@ function setIn(object, nestedKeysArray, value) {
|
|
|
333
331
|
curr[finalKey] = value;
|
|
334
332
|
}
|
|
335
333
|
}
|
|
336
|
-
function
|
|
334
|
+
function renderFieldsJSX(fieldsJSX) {
|
|
337
335
|
let moduleJson;
|
|
338
336
|
const outputCallback = (callbackJson) => {
|
|
339
337
|
moduleJson = callbackJson;
|
|
340
338
|
};
|
|
341
339
|
renderToStaticMarkup(
|
|
342
|
-
cloneElement(
|
|
340
|
+
cloneElement(fieldsJSX, {
|
|
343
341
|
outputCallback
|
|
344
342
|
})
|
|
345
343
|
);
|
|
@@ -348,6 +346,24 @@ function renderFieldsToJson(fields) {
|
|
|
348
346
|
}
|
|
349
347
|
return moduleJson;
|
|
350
348
|
}
|
|
349
|
+
function renderFieldsToJson(fields, moduleName) {
|
|
350
|
+
let fieldsJSON;
|
|
351
|
+
try {
|
|
352
|
+
if (isValidElement(fields)) {
|
|
353
|
+
fieldsJSON = renderFieldsJSX(fields);
|
|
354
|
+
} else if (Array.isArray(fields)) {
|
|
355
|
+
fieldsJSON = fields;
|
|
356
|
+
} else {
|
|
357
|
+
throw new Error(
|
|
358
|
+
`Couldn't recognize \`fields\` value for module ${moduleName}`
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
return fieldsJSON;
|
|
362
|
+
} catch (e) {
|
|
363
|
+
e.message = `Error when rendering fields for ${moduleName}: ${e.message}`;
|
|
364
|
+
throw e;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
351
367
|
function isStylesheetAsset(staticAsset) {
|
|
352
368
|
return staticAsset.type === "stylesheet";
|
|
353
369
|
}
|
|
@@ -568,16 +584,12 @@ ${groupEnd}</script>
|
|
|
568
584
|
};
|
|
569
585
|
COMBINED_REACT_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/react/v18";
|
|
570
586
|
ISLAND_RUNTIME_CONFIG_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/island-runtime/v1";
|
|
571
|
-
GATES = [
|
|
572
|
-
"CMS:JSRenderer:GetServerSideProps",
|
|
573
|
-
"CMS:JSRenderer:SeparateIslandRenderOption"
|
|
574
|
-
];
|
|
587
|
+
GATES = ["CMS:JSRenderer:GetServerSideProps"];
|
|
575
588
|
ENABLED_FEATURES_GATE_MAP = {
|
|
576
|
-
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps"
|
|
577
|
-
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
589
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps"
|
|
578
590
|
};
|
|
579
591
|
BUILD_INFO_PATH = "/build-info.json";
|
|
580
|
-
findAllComponentsIn = (webRoot2, componentsFolder
|
|
592
|
+
findAllComponentsIn = (webRoot2, componentsFolder) => {
|
|
581
593
|
const fullComponentsFolderPath = join(webRoot2, componentsFolder);
|
|
582
594
|
const componentsByName = {};
|
|
583
595
|
if (!existsSync(fullComponentsFolderPath)) {
|
|
@@ -590,7 +602,7 @@ ${groupEnd}</script>
|
|
|
590
602
|
if (!isDirectory && hasComponentExtension(fileOrFolderName) && !isStorybookStory(fileOrFolderName)) {
|
|
591
603
|
const subdirPathNoExtension = removeComponentExtension(subdirPath);
|
|
592
604
|
componentsByName[subdirPathNoExtension] = subdirPath;
|
|
593
|
-
} else if (isDirectory
|
|
605
|
+
} else if (isDirectory) {
|
|
594
606
|
for (const potentialExtension of COMPONENT_EXTENSIONS) {
|
|
595
607
|
const potentialIndexModule = join(
|
|
596
608
|
subdirPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
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.8.
|
|
28
|
+
"@hubspot/cms-components": "^0.8.4",
|
|
29
29
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
30
30
|
"@storybook/addon-actions": "7.0.7",
|
|
31
31
|
"@storybook/addon-essentials": "7.0.7",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"publishConfig": {
|
|
101
101
|
"access": "public"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "f75353eed1a5d59d1e1af013767f70f0910d7d88"
|
|
104
104
|
}
|