@hubspot/cms-dev-server 0.13.6 → 0.13.8

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.
@@ -516,7 +516,7 @@ function findAllPartialsInRoot(webRoot) {
516
516
  const partialSubpaths = Object.keys(allPartialComponents);
517
517
  return { partialNames, partialSubpaths };
518
518
  }
519
- function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint) {
519
+ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors) {
520
520
  if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
521
521
  prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
522
522
  }
@@ -531,6 +531,18 @@ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath
531
531
  if (hsBasePath) {
532
532
  globals.push(`window.__hsBasePath = '${hsBasePath}';`);
533
533
  }
534
+ if (!environmentConfig.getIsDeployed() && (criticalDevErrors == null ? void 0 : criticalDevErrors.length)) {
535
+ const firstCriticalDevError = criticalDevErrors[0];
536
+ globals.push(`
537
+ customElements.whenDefined('vite-error-overlay').then(() => {
538
+ const ErrorOverlay = customElements.get('vite-error-overlay');
539
+ const error = new Error("${firstCriticalDevError.message}");
540
+ const overlay = new ErrorOverlay(error);
541
+
542
+ document.body.appendChild(overlay);
543
+ })
544
+ `);
545
+ }
534
546
  return `
535
547
  <script type="text/javascript">
536
548
  ${globals.join("\n ")}
package/dist/run.js CHANGED
@@ -537,7 +537,7 @@ function findAllPartialsInRoot(webRoot2) {
537
537
  const partialSubpaths = Object.keys(allPartialComponents);
538
538
  return { partialNames, partialSubpaths };
539
539
  }
540
- function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint) {
540
+ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors) {
541
541
  if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
542
542
  prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
543
543
  }
@@ -552,6 +552,18 @@ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath
552
552
  if (hsBasePath) {
553
553
  globals.push(`window.__hsBasePath = '${hsBasePath}';`);
554
554
  }
555
+ if (!environmentConfig.getIsDeployed() && (criticalDevErrors == null ? void 0 : criticalDevErrors.length)) {
556
+ const firstCriticalDevError = criticalDevErrors[0];
557
+ globals.push(`
558
+ customElements.whenDefined('vite-error-overlay').then(() => {
559
+ const ErrorOverlay = customElements.get('vite-error-overlay');
560
+ const error = new Error("${firstCriticalDevError.message}");
561
+ const overlay = new ErrorOverlay(error);
562
+
563
+ document.body.appendChild(overlay);
564
+ })
565
+ `);
566
+ }
555
567
  return `
556
568
  <script type="text/javascript">
557
569
  ${globals.join("\n ")}
@@ -778,6 +790,22 @@ import { promises as fsPromises } from "fs";
778
790
  import {
779
791
  isDebugUrlString as isDebugUrlString2
780
792
  } from "@hubspot/cms-components";
793
+
794
+ // src/lib/criticalDevErrorsToServerMessages.ts
795
+ var criticalDevErrorsToServerMessages = (criticalDevErrors) => {
796
+ const logMessages = criticalDevErrors.map(
797
+ (criticalDevError) => {
798
+ return {
799
+ level: criticalDevError.level,
800
+ parameters: [criticalDevError.message]
801
+ };
802
+ }
803
+ );
804
+ return logMessages;
805
+ };
806
+ var criticalDevErrorsToServerMessages_default = criticalDevErrorsToServerMessages;
807
+
808
+ // src/lib/templates.ts
781
809
  var { readFile } = fsPromises;
782
810
  var generateIslandSetupScriptBlock = () => {
783
811
  return `
@@ -822,21 +850,30 @@ var createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock
822
850
  var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, title, renderContext, viteServer, __jsRenderingGates) => {
823
851
  let htmlTemplate;
824
852
  const prettyPrint = isDebugUrlString2(url3);
853
+ const serverMessages = criticalDevErrorsToServerMessages_default(
854
+ renderContext.criticalDevErrors
855
+ );
856
+ const serverLogScript = serverMessages.length ? scriptTagToLogServerMessages(
857
+ serverMessages,
858
+ "@hubspot/cms-dev-server messages"
859
+ ) : "";
825
860
  if (renderContext.islands.length) {
826
861
  const globalScriptBlock = getServerGlobalsToInject(
827
862
  renderContext.environmentConfig,
828
863
  renderContext.pageUrl,
829
- renderContext.entryPointBasePath
864
+ renderContext.entryPointBasePath,
865
+ void 0,
866
+ renderContext.criticalDevErrors
830
867
  );
831
868
  htmlTemplate = await createIslandHtmlTemplate(
832
869
  baseTemplatePath,
833
870
  title,
834
- globalScriptBlock
871
+ `${globalScriptBlock}${serverLogScript}`
835
872
  );
836
873
  htmlTemplate = htmlTemplate.replace(
837
874
  "<!--islandsglobal-->",
838
875
  `<script>
839
- ${createIslandsGlobalJsForClientInDev(
876
+ ${createIslandsGlobalJsForClientInDev(
840
877
  renderContext.islands,
841
878
  renderContext.perServerRequestData,
842
879
  viteServer,
@@ -848,12 +885,16 @@ ${createIslandsGlobalJsForClientInDev(
848
885
  );
849
886
  } else {
850
887
  const globalScriptBlock = getServerGlobalsToInject(
851
- renderContext.environmentConfig
888
+ renderContext.environmentConfig,
889
+ void 0,
890
+ void 0,
891
+ void 0,
892
+ renderContext.criticalDevErrors
852
893
  );
853
894
  htmlTemplate = await createdPlainHtmlTemplate(
854
895
  baseTemplatePath,
855
896
  title,
856
- globalScriptBlock
897
+ `${globalScriptBlock}${serverLogScript}`
857
898
  );
858
899
  }
859
900
  return viteServer.transformIndexHtml(url3, htmlTemplate);
@@ -913,7 +954,7 @@ function trackUsage(action) {
913
954
  eventName: EVENT_NAME,
914
955
  action,
915
956
  nodeVersion: getNodeVersionData(),
916
- version: "0.13.6",
957
+ version: "0.13.8",
917
958
  os: getPlatform()
918
959
  };
919
960
  const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -1112,6 +1153,7 @@ import { normalizePath as normalizePath3 } from "vite";
1112
1153
  // src/lib/renderModule.ts
1113
1154
  import { join as joinPosix2 } from "path/posix";
1114
1155
  import { traverseFieldsJSON } from "@hubspot/cms-components/fields";
1156
+ import cliHttp3 from "@hubspot/cli-lib/http.js";
1115
1157
 
1116
1158
  // src/lib/fetchModuleGraphQLData.ts
1117
1159
  import cliHttp2 from "@hubspot/cli-lib/http.js";
@@ -1140,6 +1182,39 @@ async function fetchModuleGraphQLData(accountId, query, requestedModulePath, pag
1140
1182
  }
1141
1183
 
1142
1184
  // src/lib/renderModule.ts
1185
+ var getApplyFieldsValidationToRenderContext = (portalId, fieldsJSON, requestedModulePath) => {
1186
+ return async (renderResult) => {
1187
+ const { renderContext } = renderResult;
1188
+ const validationSeverityToLogLevel = {
1189
+ FATAL: "error",
1190
+ WARNING: "warn"
1191
+ };
1192
+ let validationRequest;
1193
+ let fieldValidationErrors = [];
1194
+ try {
1195
+ validationRequest = await cliHttp3.post(portalId, {
1196
+ uri: "/designmanager/v1/modules/validate-fields",
1197
+ body: fieldsJSON,
1198
+ resolveWithFullResponse: true
1199
+ });
1200
+ } catch {
1201
+ console.log("Failed to validate module fields for", requestedModulePath);
1202
+ }
1203
+ if (validationRequest) {
1204
+ fieldValidationErrors = validationRequest.body;
1205
+ }
1206
+ if (fieldValidationErrors.length) {
1207
+ fieldValidationErrors.forEach((fieldValidationError) => {
1208
+ renderContext.criticalDevErrors.push({
1209
+ message: `Field Validation Error in ${requestedModulePath}: ${fieldValidationError.message}`,
1210
+ error: new Error(fieldValidationError.message),
1211
+ level: validationSeverityToLogLevel[fieldValidationError.severity] || "info"
1212
+ });
1213
+ });
1214
+ }
1215
+ return renderResult;
1216
+ };
1217
+ };
1143
1218
  var lookForModuleInFolder2 = async (modulePath, viteServer) => {
1144
1219
  let componentModule;
1145
1220
  const insideFolderPath = joinPosix2(modulePath, "index");
@@ -1199,6 +1274,11 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
1199
1274
  );
1200
1275
  const fieldsJSON = renderFieldsToJson(fields, requestedModulePath);
1201
1276
  const fieldValues = getFieldValuesForModule(fieldsJSON, fieldOverrides);
1277
+ const applyFieldsValidationToRenderContext = getApplyFieldsValidationToRenderContext(
1278
+ environmentConfig.getPortalID(),
1279
+ fieldsJSON,
1280
+ requestedModulePath
1281
+ );
1202
1282
  if (componentModule.query && typeof componentModule.query === "string") {
1203
1283
  try {
1204
1284
  dataQueryResult = await fetchModuleGraphQLData(
@@ -1249,7 +1329,7 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
1249
1329
  basePath,
1250
1330
  environmentConfig,
1251
1331
  renderOptions
1252
- );
1332
+ ).then(applyFieldsValidationToRenderContext);
1253
1333
  }
1254
1334
  function getFieldValuesForModule(fieldsJSON, fieldOverrides = {}) {
1255
1335
  const props = {};
@@ -1745,6 +1825,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
1745
1825
  hsProjectJsonProjectName,
1746
1826
  webRootProjectComponent
1747
1827
  );
1828
+ const localRenderPlaceholderProps = localRenderPlaceholder.json.props;
1748
1829
  const [
1749
1830
  __projectIdentifier,
1750
1831
  projectFolder,
@@ -1779,7 +1860,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
1779
1860
  return renderComponentForPlaceholderPartial(
1780
1861
  viteServer,
1781
1862
  resolvedPath,
1782
- localRenderPlaceholder,
1863
+ localRenderPlaceholderProps,
1783
1864
  pageUrl,
1784
1865
  basePath,
1785
1866
  environmentConfig,
@@ -1891,6 +1972,7 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1891
1972
  let islands = [];
1892
1973
  let mergedPerRequestState = /* @__PURE__ */ new Map();
1893
1974
  let basePath;
1975
+ const criticalDevErrors = [];
1894
1976
  const renderPromisesByChunkIndex = new Array(
1895
1977
  numPlaceholders
1896
1978
  );
@@ -1920,10 +2002,14 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1920
2002
  projectComponentPath
1921
2003
  );
1922
2004
  renderPromisesByChunkIndex[indexForThisRender] = renderPromise.then((promiseResult) => {
2005
+ var _a;
1923
2006
  let { html, cssNeeded, inlineAssets, renderContext } = promiseResult;
1924
2007
  console.log(
1925
2008
  `Finished render of ${localRenderPlaceholder.path} (i = ${indexForThisRender})`
1926
2009
  );
2010
+ if ((_a = renderContext.criticalDevErrors) == null ? void 0 : _a.length) {
2011
+ criticalDevErrors.push(...renderContext.criticalDevErrors);
2012
+ }
1927
2013
  if (renderContext.islands.length > 0) {
1928
2014
  islands = islands.concat(renderContext.islands);
1929
2015
  }
@@ -1963,8 +2049,22 @@ ${result}`;
1963
2049
  response.write(foobar);
1964
2050
  }
1965
2051
  response.write(
1966
- getServerGlobalsToInject(environmentConfig, fullOriginalUrl, basePath)
2052
+ getServerGlobalsToInject(
2053
+ environmentConfig,
2054
+ fullOriginalUrl,
2055
+ basePath,
2056
+ void 0,
2057
+ criticalDevErrors
2058
+ )
1967
2059
  );
2060
+ if (criticalDevErrors.length) {
2061
+ response.write(
2062
+ scriptTagToLogServerMessages(
2063
+ criticalDevErrorsToServerMessages_default(criticalDevErrors),
2064
+ "@hubspot/cms-dev-server messages"
2065
+ )
2066
+ );
2067
+ }
1968
2068
  if (islands.length > 0) {
1969
2069
  const sortedIslandRoots = sortIslandRootsByPriority(islands);
1970
2070
  const islandRuntimeAndGlobalScriptHtml = await getIslandRuntimeAndGlobalToInject(
@@ -296,7 +296,7 @@ function findAllPartialsInRoot(webRoot2) {
296
296
  const partialSubpaths = Object.keys(allPartialComponents);
297
297
  return { partialNames, partialSubpaths };
298
298
  }
299
- function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint) {
299
+ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors) {
300
300
  if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
301
301
  prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
302
302
  }
@@ -311,6 +311,18 @@ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath
311
311
  if (hsBasePath) {
312
312
  globals.push(`window.__hsBasePath = '${hsBasePath}';`);
313
313
  }
314
+ if (!environmentConfig.getIsDeployed() && (criticalDevErrors == null ? void 0 : criticalDevErrors.length)) {
315
+ const firstCriticalDevError = criticalDevErrors[0];
316
+ globals.push(`
317
+ customElements.whenDefined('vite-error-overlay').then(() => {
318
+ const ErrorOverlay = customElements.get('vite-error-overlay');
319
+ const error = new Error("${firstCriticalDevError.message}");
320
+ const overlay = new ErrorOverlay(error);
321
+
322
+ document.body.appendChild(overlay);
323
+ })
324
+ `);
325
+ }
314
326
  return `
315
327
  <script type="text/javascript">
316
328
  ${globals.join("\n ")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.13.6",
3
+ "version": "0.13.8",
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.13.6",
28
+ "@hubspot/cms-components": "^0.13.8",
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",
@@ -101,5 +101,5 @@
101
101
  "publishConfig": {
102
102
  "access": "public"
103
103
  },
104
- "gitHead": "53a9873619c758aefca75e2a9462c1334e63627f"
104
+ "gitHead": "cfca2e8d8e549fe75fc74636982bb3b938f1b203"
105
105
  }