@hubspot/cms-dev-server 0.14.3 → 0.14.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/index.js +26 -1
- package/dist/internalSsr.js +28 -3
- package/dist/run.js +122 -16
- package/dist/storybook/index.js +2 -0
- package/dist/storybook-main/main.js +29 -4
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3,7 +3,9 @@ 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 * as dotProp from "dot-prop";
|
|
6
7
|
import path from "path";
|
|
8
|
+
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
7
9
|
var viteRoot;
|
|
8
10
|
var viteCommand;
|
|
9
11
|
function resolveIslandPlugin(islandsSet) {
|
|
@@ -42,6 +44,28 @@ function resolveIslandPlugin(islandsSet) {
|
|
|
42
44
|
}
|
|
43
45
|
};
|
|
44
46
|
}
|
|
47
|
+
function noncePlaceholderPlugin() {
|
|
48
|
+
const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
|
|
49
|
+
return {
|
|
50
|
+
name: "hs-nonce-placeholder",
|
|
51
|
+
enforce: "post",
|
|
52
|
+
apply() {
|
|
53
|
+
return HS_DEPLOYED;
|
|
54
|
+
},
|
|
55
|
+
transformIndexHtml(html) {
|
|
56
|
+
const regex = /<(style|script|link) (.*)>/gi;
|
|
57
|
+
const replacer = (_, p1, p2) => {
|
|
58
|
+
if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
|
|
59
|
+
p1 === "link" && p2.includes('rel="stylesheet"')) {
|
|
60
|
+
const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
|
|
61
|
+
p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
|
|
62
|
+
}
|
|
63
|
+
return `<${p1} ${p2}>`;
|
|
64
|
+
};
|
|
65
|
+
return html.replace(regex, replacer);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
45
69
|
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: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\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 let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\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 {innerComponent}\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";
|
|
46
70
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
47
71
|
function clientIslandEntryPlugin() {
|
|
@@ -152,7 +176,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
152
176
|
clientIslandEntryPlugin(),
|
|
153
177
|
resolveIslandPlugin(),
|
|
154
178
|
jsRenderingGates.includes("CMS:JSRenderer:RemoveCjsPlugin") ? null : viteCommonjs(),
|
|
155
|
-
devSecretsPlugin(secretNames)
|
|
179
|
+
devSecretsPlugin(secretNames),
|
|
180
|
+
noncePlaceholderPlugin()
|
|
156
181
|
],
|
|
157
182
|
css: {
|
|
158
183
|
postcss: webRoot
|
package/dist/internalSsr.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// ../cms-js-internal/dist/index.js
|
|
2
|
-
import
|
|
2
|
+
import * as dotProp from "dot-prop";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
5
5
|
import stream from "stream";
|
|
@@ -97,6 +97,7 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
|
|
|
97
97
|
${indentString}`
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
|
+
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
100
101
|
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
101
102
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
102
103
|
({
|
|
@@ -292,6 +293,28 @@ function resolveIslandPlugin(islandsSet) {
|
|
|
292
293
|
}
|
|
293
294
|
};
|
|
294
295
|
}
|
|
296
|
+
function noncePlaceholderPlugin() {
|
|
297
|
+
const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
|
|
298
|
+
return {
|
|
299
|
+
name: "hs-nonce-placeholder",
|
|
300
|
+
enforce: "post",
|
|
301
|
+
apply() {
|
|
302
|
+
return HS_DEPLOYED;
|
|
303
|
+
},
|
|
304
|
+
transformIndexHtml(html) {
|
|
305
|
+
const regex = /<(style|script|link) (.*)>/gi;
|
|
306
|
+
const replacer = (_, p1, p2) => {
|
|
307
|
+
if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
|
|
308
|
+
p1 === "link" && p2.includes('rel="stylesheet"')) {
|
|
309
|
+
const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
|
|
310
|
+
p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
|
|
311
|
+
}
|
|
312
|
+
return `<${p1} ${p2}>`;
|
|
313
|
+
};
|
|
314
|
+
return html.replace(regex, replacer);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
295
318
|
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: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\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 let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\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 {innerComponent}\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";
|
|
296
319
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
297
320
|
function clientIslandEntryPlugin() {
|
|
@@ -548,7 +571,7 @@ function findAllPartialsInRoot(webRoot) {
|
|
|
548
571
|
const partialSubpaths = Object.keys(allPartialComponents);
|
|
549
572
|
return { partialNames, partialSubpaths };
|
|
550
573
|
}
|
|
551
|
-
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors) {
|
|
574
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
552
575
|
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
553
576
|
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
554
577
|
}
|
|
@@ -583,8 +606,9 @@ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath
|
|
|
583
606
|
})
|
|
584
607
|
`);
|
|
585
608
|
}
|
|
609
|
+
const nonceAttr = includeNonces && cmsComponents.STYLE_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.STYLE_NONCE_PLACEHOLDER}"` : "";
|
|
586
610
|
return `
|
|
587
|
-
<script type="text/javascript">
|
|
611
|
+
<script type="text/javascript"${nonceAttr}>
|
|
588
612
|
${globals.join("\n ")}
|
|
589
613
|
</script>
|
|
590
614
|
`;
|
|
@@ -705,6 +729,7 @@ export {
|
|
|
705
729
|
isUngatedFor,
|
|
706
730
|
jsonStringifyAndEscapeForInlineJS,
|
|
707
731
|
namespaceModulePropsShape,
|
|
732
|
+
noncePlaceholderPlugin,
|
|
708
733
|
removeComponentExtension,
|
|
709
734
|
renderComponentOnServer,
|
|
710
735
|
renderFieldsToJson,
|
package/dist/run.js
CHANGED
|
@@ -77,7 +77,7 @@ function getDevServerCommandLineOptions(argv) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// src/createDevServer.ts
|
|
80
|
-
import
|
|
80
|
+
import path9 from "path";
|
|
81
81
|
import url2 from "url";
|
|
82
82
|
import express2 from "express";
|
|
83
83
|
import http3 from "http";
|
|
@@ -127,7 +127,7 @@ function packagePath(metaUrl, projectPath) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// ../cms-js-internal/dist/index.js
|
|
130
|
-
import
|
|
130
|
+
import * as dotProp from "dot-prop";
|
|
131
131
|
import path2 from "path";
|
|
132
132
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
133
133
|
import stream from "stream";
|
|
@@ -163,6 +163,7 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
|
|
|
163
163
|
${indentString}`
|
|
164
164
|
);
|
|
165
165
|
}
|
|
166
|
+
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
166
167
|
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
167
168
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
168
169
|
({
|
|
@@ -358,6 +359,28 @@ function resolveIslandPlugin(islandsSet) {
|
|
|
358
359
|
}
|
|
359
360
|
};
|
|
360
361
|
}
|
|
362
|
+
function noncePlaceholderPlugin() {
|
|
363
|
+
const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
|
|
364
|
+
return {
|
|
365
|
+
name: "hs-nonce-placeholder",
|
|
366
|
+
enforce: "post",
|
|
367
|
+
apply() {
|
|
368
|
+
return HS_DEPLOYED;
|
|
369
|
+
},
|
|
370
|
+
transformIndexHtml(html) {
|
|
371
|
+
const regex = /<(style|script|link) (.*)>/gi;
|
|
372
|
+
const replacer = (_, p1, p2) => {
|
|
373
|
+
if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
|
|
374
|
+
p1 === "link" && p2.includes('rel="stylesheet"')) {
|
|
375
|
+
const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
|
|
376
|
+
p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
|
|
377
|
+
}
|
|
378
|
+
return `<${p1} ${p2}>`;
|
|
379
|
+
};
|
|
380
|
+
return html.replace(regex, replacer);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
361
384
|
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: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\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 let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\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 {innerComponent}\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";
|
|
362
385
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
363
386
|
function clientIslandEntryPlugin() {
|
|
@@ -567,7 +590,7 @@ function findAllPartialsInRoot(webRoot2) {
|
|
|
567
590
|
const partialSubpaths = Object.keys(allPartialComponents);
|
|
568
591
|
return { partialNames, partialSubpaths };
|
|
569
592
|
}
|
|
570
|
-
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors) {
|
|
593
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
571
594
|
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
572
595
|
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
573
596
|
}
|
|
@@ -602,8 +625,9 @@ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath
|
|
|
602
625
|
})
|
|
603
626
|
`);
|
|
604
627
|
}
|
|
628
|
+
const nonceAttr = includeNonces && cmsComponents.STYLE_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.STYLE_NONCE_PLACEHOLDER}"` : "";
|
|
605
629
|
return `
|
|
606
|
-
<script type="text/javascript">
|
|
630
|
+
<script type="text/javascript"${nonceAttr}>
|
|
607
631
|
${globals.join("\n ")}
|
|
608
632
|
</script>
|
|
609
633
|
`;
|
|
@@ -999,7 +1023,7 @@ function trackUsage(action) {
|
|
|
999
1023
|
eventName: EVENT_NAME,
|
|
1000
1024
|
action,
|
|
1001
1025
|
nodeVersion: getNodeVersionData(),
|
|
1002
|
-
version: "0.14.
|
|
1026
|
+
version: "0.14.5",
|
|
1003
1027
|
os: getPlatform()
|
|
1004
1028
|
};
|
|
1005
1029
|
const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -1623,12 +1647,12 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1623
1647
|
);
|
|
1624
1648
|
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
1625
1649
|
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
1626
|
-
const
|
|
1650
|
+
const path10 = body.substring(
|
|
1627
1651
|
startOffset + localJsRenderStartString.length,
|
|
1628
1652
|
pathEndOffset
|
|
1629
1653
|
);
|
|
1630
1654
|
offsetSoFar = pathEndOffset + 1;
|
|
1631
|
-
if (startOffset >= 0 &&
|
|
1655
|
+
if (startOffset >= 0 && path10) {
|
|
1632
1656
|
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
1633
1657
|
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
1634
1658
|
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
@@ -1648,7 +1672,7 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1648
1672
|
result.push({
|
|
1649
1673
|
startOffset,
|
|
1650
1674
|
endOffset: endOffset + localJsRenderEndString.length,
|
|
1651
|
-
path:
|
|
1675
|
+
path: path10,
|
|
1652
1676
|
json
|
|
1653
1677
|
});
|
|
1654
1678
|
}
|
|
@@ -1757,9 +1781,9 @@ var customColors = [
|
|
|
1757
1781
|
];
|
|
1758
1782
|
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
1759
1783
|
var darkErrorStyles = `background-color: #222; color: #ccc; padding: 0.5em; font-family: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace;`;
|
|
1760
|
-
var renderLocalError_default = (
|
|
1784
|
+
var renderLocalError_default = (path10, error) => {
|
|
1761
1785
|
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
1762
|
-
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${
|
|
1786
|
+
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path10}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
|
|
1763
1787
|
};
|
|
1764
1788
|
|
|
1765
1789
|
// src/proxyPage/fetchPreviewInfo.ts
|
|
@@ -2776,7 +2800,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
2776
2800
|
clientIslandEntryPlugin(),
|
|
2777
2801
|
resolveIslandPlugin(),
|
|
2778
2802
|
jsRenderingGates.includes("CMS:JSRenderer:RemoveCjsPlugin") ? null : viteCommonjs(),
|
|
2779
|
-
devSecretsPlugin(secretNames)
|
|
2803
|
+
devSecretsPlugin(secretNames),
|
|
2804
|
+
noncePlaceholderPlugin()
|
|
2780
2805
|
],
|
|
2781
2806
|
css: {
|
|
2782
2807
|
postcss: webRoot2
|
|
@@ -2927,6 +2952,84 @@ function getCMSAssetConfig(webRoot2) {
|
|
|
2927
2952
|
return JSON.parse(fs2.readFileSync(cmsAssetsPath).toString());
|
|
2928
2953
|
}
|
|
2929
2954
|
|
|
2955
|
+
// src/lib/validateHSPlatform.ts
|
|
2956
|
+
import path8 from "path";
|
|
2957
|
+
import fs3 from "fs";
|
|
2958
|
+
import select from "@inquirer/select";
|
|
2959
|
+
import { get as hsGet6 } from "@hubspot/cli-lib/http.js";
|
|
2960
|
+
var HSPROJECT_JSON = "hsproject.json";
|
|
2961
|
+
function checkFileExists(filePath) {
|
|
2962
|
+
return fs3.existsSync(filePath) && fs3.statSync(filePath).isFile();
|
|
2963
|
+
}
|
|
2964
|
+
function findHSProjectJson(startPath) {
|
|
2965
|
+
let currentDir = startPath;
|
|
2966
|
+
let dirLevel = 0;
|
|
2967
|
+
const maxDirLevel = 4;
|
|
2968
|
+
while (path8.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
|
|
2969
|
+
const filePath = path8.join(currentDir, HSPROJECT_JSON);
|
|
2970
|
+
if (checkFileExists(filePath)) {
|
|
2971
|
+
return filePath;
|
|
2972
|
+
}
|
|
2973
|
+
currentDir = path8.dirname(currentDir);
|
|
2974
|
+
dirLevel++;
|
|
2975
|
+
}
|
|
2976
|
+
console.log(
|
|
2977
|
+
`'${HSPROJECT_JSON}' not found in any parent of dev server target`
|
|
2978
|
+
);
|
|
2979
|
+
return null;
|
|
2980
|
+
}
|
|
2981
|
+
async function validateHSPlatform(webroot, portalId) {
|
|
2982
|
+
const foundHSProjectJsonPath = findHSProjectJson(webroot);
|
|
2983
|
+
if (foundHSProjectJsonPath === null) {
|
|
2984
|
+
console.log(
|
|
2985
|
+
`Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
|
|
2986
|
+
);
|
|
2987
|
+
return false;
|
|
2988
|
+
}
|
|
2989
|
+
const hsProjectJSONContents = fs3.readFileSync(foundHSProjectJsonPath, "utf8");
|
|
2990
|
+
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
2991
|
+
const { platformVersion } = hsProjectJSONData;
|
|
2992
|
+
let platformVersionResult;
|
|
2993
|
+
try {
|
|
2994
|
+
platformVersionResult = await hsGet6(portalId, {
|
|
2995
|
+
uri: `developer/projects/v1/platformVersion`,
|
|
2996
|
+
json: true
|
|
2997
|
+
});
|
|
2998
|
+
} catch (e) {
|
|
2999
|
+
console.error(e.message);
|
|
3000
|
+
console.log(
|
|
3001
|
+
"Unable to find active platform versions, skipping platform version validation."
|
|
3002
|
+
);
|
|
3003
|
+
return false;
|
|
3004
|
+
}
|
|
3005
|
+
if (platformVersion === void 0 || !platformVersionResult.activePlatformVersions.includes(platformVersion)) {
|
|
3006
|
+
const answer = await select({
|
|
3007
|
+
message: 'Your local "hsproject.json" does not have a valid platform version, please select a valid platform version. You can read more about Platform Versioning here https://developers.hubspot.com/docs/platform/platform-versioning',
|
|
3008
|
+
choices: platformVersionResult.activePlatformVersions.map(
|
|
3009
|
+
(versionNumber) => ({
|
|
3010
|
+
name: versionNumber,
|
|
3011
|
+
value: versionNumber
|
|
3012
|
+
})
|
|
3013
|
+
)
|
|
3014
|
+
});
|
|
3015
|
+
hsProjectJSONData.platformVersion = answer;
|
|
3016
|
+
try {
|
|
3017
|
+
fs3.writeFileSync(
|
|
3018
|
+
foundHSProjectJsonPath,
|
|
3019
|
+
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
3020
|
+
"utf8"
|
|
3021
|
+
);
|
|
3022
|
+
return true;
|
|
3023
|
+
} catch (e) {
|
|
3024
|
+
console.error(
|
|
3025
|
+
`unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
|
|
3026
|
+
);
|
|
3027
|
+
return false;
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
return true;
|
|
3031
|
+
}
|
|
3032
|
+
|
|
2930
3033
|
// src/createDevServer.ts
|
|
2931
3034
|
var BASE_PATH = "/";
|
|
2932
3035
|
var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
|
|
@@ -3031,8 +3134,11 @@ Local proxy functionality will not work without setting up authentication.`
|
|
|
3031
3134
|
}
|
|
3032
3135
|
}
|
|
3033
3136
|
const authedHublet = "na1";
|
|
3034
|
-
const absoluteWebRoot = normalizePath6(
|
|
3137
|
+
const absoluteWebRoot = normalizePath6(path9.resolve(process.cwd(), webRoot2));
|
|
3035
3138
|
const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, "").split("/").slice(-2);
|
|
3139
|
+
if (authedPortalId) {
|
|
3140
|
+
await validateHSPlatform(absoluteWebRoot, authedPortalId);
|
|
3141
|
+
}
|
|
3036
3142
|
const viteServer = await createViteDevServer_default(
|
|
3037
3143
|
absoluteWebRoot,
|
|
3038
3144
|
PORT,
|
|
@@ -3045,7 +3151,7 @@ Local proxy functionality will not work without setting up authentication.`
|
|
|
3045
3151
|
const httpsKey = viteHTTPSConfig ? viteHTTPSConfig.key : null;
|
|
3046
3152
|
const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
|
|
3047
3153
|
const projectName = getProjectNameFromHSConfig(
|
|
3048
|
-
|
|
3154
|
+
path9.join(webRoot2, "../hsproject.json")
|
|
3049
3155
|
);
|
|
3050
3156
|
const httpServers = [];
|
|
3051
3157
|
const expressServer = express2();
|
|
@@ -3102,8 +3208,8 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
3102
3208
|
`
|
|
3103
3209
|
);
|
|
3104
3210
|
if (storybook2) {
|
|
3105
|
-
const packageRoot =
|
|
3106
|
-
const configPath =
|
|
3211
|
+
const packageRoot = path9.dirname(url2.fileURLToPath(import.meta.url));
|
|
3212
|
+
const configPath = path9.resolve(packageRoot, "./storybook-main");
|
|
3107
3213
|
sendTrackingRequest("start-storybook");
|
|
3108
3214
|
const storybookProcess = spawn(
|
|
3109
3215
|
"sb",
|
|
@@ -3123,7 +3229,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
3123
3229
|
portalId: authedPortalId.toString(),
|
|
3124
3230
|
hsEnv: authedEnv,
|
|
3125
3231
|
hublet: authedHublet,
|
|
3126
|
-
WEB_ROOT:
|
|
3232
|
+
WEB_ROOT: path9.join(webRoot2, "components")
|
|
3127
3233
|
}
|
|
3128
3234
|
}
|
|
3129
3235
|
);
|
package/dist/storybook/index.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
|
|
4
4
|
// ../cms-js-internal/dist/index.js
|
|
5
|
+
import * as dotProp from "dot-prop";
|
|
5
6
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
6
7
|
import { isValidElement, cloneElement } from "react";
|
|
8
|
+
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
7
9
|
function namespaceModulePropsShape(props) {
|
|
8
10
|
const {
|
|
9
11
|
dataQueryResult,
|
|
@@ -41,6 +41,7 @@ __export(dist_exports, {
|
|
|
41
41
|
isUngatedFor: () => isUngatedFor,
|
|
42
42
|
jsonStringifyAndEscapeForInlineJS: () => jsonStringifyAndEscapeForInlineJS,
|
|
43
43
|
namespaceModulePropsShape: () => namespaceModulePropsShape,
|
|
44
|
+
noncePlaceholderPlugin: () => noncePlaceholderPlugin,
|
|
44
45
|
removeComponentExtension: () => removeComponentExtension,
|
|
45
46
|
renderComponentOnServer: () => renderComponentOnServer,
|
|
46
47
|
renderFieldsToJson: () => renderFieldsToJson,
|
|
@@ -53,7 +54,7 @@ __export(dist_exports, {
|
|
|
53
54
|
ungatedAtBuildTimeFor: () => ungatedAtBuildTimeFor,
|
|
54
55
|
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
|
|
55
56
|
});
|
|
56
|
-
import
|
|
57
|
+
import * as dotProp from "dot-prop";
|
|
57
58
|
import path from "path";
|
|
58
59
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
59
60
|
import stream from "stream";
|
|
@@ -199,6 +200,28 @@ function resolveIslandPlugin(islandsSet) {
|
|
|
199
200
|
}
|
|
200
201
|
};
|
|
201
202
|
}
|
|
203
|
+
function noncePlaceholderPlugin() {
|
|
204
|
+
const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
|
|
205
|
+
return {
|
|
206
|
+
name: "hs-nonce-placeholder",
|
|
207
|
+
enforce: "post",
|
|
208
|
+
apply() {
|
|
209
|
+
return HS_DEPLOYED;
|
|
210
|
+
},
|
|
211
|
+
transformIndexHtml(html) {
|
|
212
|
+
const regex = /<(style|script|link) (.*)>/gi;
|
|
213
|
+
const replacer = (_, p1, p2) => {
|
|
214
|
+
if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
|
|
215
|
+
p1 === "link" && p2.includes('rel="stylesheet"')) {
|
|
216
|
+
const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
|
|
217
|
+
p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
|
|
218
|
+
}
|
|
219
|
+
return `<${p1} ${p2}>`;
|
|
220
|
+
};
|
|
221
|
+
return html.replace(regex, replacer);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
202
225
|
function clientIslandEntryPlugin() {
|
|
203
226
|
return {
|
|
204
227
|
enforce: "pre",
|
|
@@ -319,7 +342,7 @@ function findAllPartialsInRoot(webRoot2) {
|
|
|
319
342
|
const partialSubpaths = Object.keys(allPartialComponents);
|
|
320
343
|
return { partialNames, partialSubpaths };
|
|
321
344
|
}
|
|
322
|
-
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors) {
|
|
345
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
323
346
|
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
324
347
|
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
325
348
|
}
|
|
@@ -354,8 +377,9 @@ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath
|
|
|
354
377
|
})
|
|
355
378
|
`);
|
|
356
379
|
}
|
|
380
|
+
const nonceAttr = includeNonces && cmsComponents.STYLE_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.STYLE_NONCE_PLACEHOLDER}"` : "";
|
|
357
381
|
return `
|
|
358
|
-
<script type="text/javascript">
|
|
382
|
+
<script type="text/javascript"${nonceAttr}>
|
|
359
383
|
${globals.join("\n ")}
|
|
360
384
|
</script>
|
|
361
385
|
`;
|
|
@@ -445,7 +469,7 @@ function renderFieldsToJson(fields, moduleName) {
|
|
|
445
469
|
function isStylesheetAsset(staticAsset) {
|
|
446
470
|
return staticAsset.type === "stylesheet";
|
|
447
471
|
}
|
|
448
|
-
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, badInlineJsChars, inlineJsEscapeChars, serializeIslandDataForInlineScript, 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;
|
|
472
|
+
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, badInlineJsChars, inlineJsEscapeChars, setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, 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;
|
|
449
473
|
var init_dist = __esm({
|
|
450
474
|
"../cms-js-internal/dist/index.js"() {
|
|
451
475
|
COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
@@ -498,6 +522,7 @@ var init_dist = __esm({
|
|
|
498
522
|
">": "\\u003E",
|
|
499
523
|
"/": "\\u002F"
|
|
500
524
|
};
|
|
525
|
+
({ setProperty, getProperty, hasProperty } = dotProp);
|
|
501
526
|
serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
502
527
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
503
528
|
({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.5",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@hubspot/cli-lib": "^3.0.12",
|
|
29
|
-
"@hubspot/cms-components": "^0.14.
|
|
29
|
+
"@hubspot/cms-components": "^0.14.5",
|
|
30
30
|
"@inquirer/select": "^2.0.0",
|
|
31
31
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
32
32
|
"@storybook/addon-actions": "7.0.7",
|
|
@@ -107,5 +107,5 @@
|
|
|
107
107
|
"publishConfig": {
|
|
108
108
|
"access": "public"
|
|
109
109
|
},
|
|
110
|
-
"gitHead": "
|
|
110
|
+
"gitHead": "606c5899215b3f31d248043e748bd37bcea948f7"
|
|
111
111
|
}
|