@hubspot/cms-dev-server 0.7.2 → 0.7.7

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.
@@ -106,7 +106,7 @@ function waitThenLoadAndHydrateIfNeeded(root, LoadableIslandModule) {
106
106
  }
107
107
  }
108
108
  function getLoadableModuleFor(root) {
109
- let url = `${window.location.origin}${root.url}`;
109
+ let url = root.url.startsWith("https://") || root.url.startsWith("http://") || root.url.startsWith("//") ? root.url : `${window.location.origin}${root.url}`;
110
110
  if (shouldForceSeparateJsForAllIslands) {
111
111
  url = `${root.url}?cacheBust=${Date.now()}-${root.id}`;
112
112
  }
package/dist/run.js CHANGED
@@ -55,8 +55,27 @@ function fullOriginalUrlFromRequest(request2) {
55
55
  return `${request2.protocol}://${request2.get("host")}${request2.originalUrl}`;
56
56
  }
57
57
 
58
+ // src/lib/packagePath.ts
59
+ import path from "path";
60
+ import url from "url";
61
+ import { normalizePath } from "vite";
62
+ function packagePath(metaUrl, projectPath) {
63
+ if (true) {
64
+ return normalizePath(
65
+ path.resolve(path.dirname(url.fileURLToPath(metaUrl)), projectPath)
66
+ );
67
+ }
68
+ const parentDirPath = normalizePath(path.dirname(url.fileURLToPath(metaUrl)));
69
+ const subPath = parentDirPath.replace(/^.+cms-dev-server\/src\//, "");
70
+ const subPathParentDirs = subPath.split("/").map(() => "..");
71
+ return path.resolve(
72
+ path.dirname(url.fileURLToPath(metaUrl)),
73
+ path.join(...subPathParentDirs, projectPath)
74
+ );
75
+ }
76
+
58
77
  // ../cms-js-internal/dist/index.js
59
- import path, { basename } from "path";
78
+ import path2, { basename } from "path";
60
79
  import * as jsxRuntime from "react/jsx-runtime";
61
80
  import stream from "stream";
62
81
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
@@ -191,8 +210,8 @@ function resolveIslandPlugin() {
191
210
  if (id.endsWith("?island") || id.endsWith("?client")) {
192
211
  const [idWithNoParam] = id.split("?");
193
212
  const islandModuleImportPath = `${idWithNoParam}?client-entry`;
194
- const componentExtension = path.extname(idWithNoParam);
195
- const componentFilenameWithNoExtension = path.basename(
213
+ const componentExtension = path2.extname(idWithNoParam);
214
+ const componentFilenameWithNoExtension = path2.basename(
196
215
  idWithNoParam,
197
216
  componentExtension
198
217
  );
@@ -341,7 +360,7 @@ var hasComponentExtension = (componentPath) => {
341
360
  return !!getComponentExtension(componentPath);
342
361
  };
343
362
  var isStorybookStory = (componentPath) => {
344
- return !!path.basename(componentPath, path.extname(componentPath)).endsWith(".stories");
363
+ return !!path2.basename(componentPath, path2.extname(componentPath)).endsWith(".stories");
345
364
  };
346
365
  var removeComponentExtension = (componentPath) => {
347
366
  const ext = getComponentExtension(componentPath);
@@ -491,25 +510,6 @@ function renderFieldsToJson(fields) {
491
510
  return moduleJson;
492
511
  }
493
512
 
494
- // src/lib/packagePath.ts
495
- import path2 from "path";
496
- import url from "url";
497
- import { normalizePath } from "vite";
498
- function packagePath(metaUrl, projectPath) {
499
- if (true) {
500
- return normalizePath(
501
- path2.resolve(path2.dirname(url.fileURLToPath(metaUrl)), projectPath)
502
- );
503
- }
504
- const parentDirPath = normalizePath(path2.dirname(url.fileURLToPath(metaUrl)));
505
- const subPath = parentDirPath.replace(/^.+cms-dev-server\/src\//, "");
506
- const subPathParentDirs = subPath.split("/").map(() => "..");
507
- return path2.resolve(
508
- path2.dirname(url.fileURLToPath(metaUrl)),
509
- path2.join(...subPathParentDirs, projectPath)
510
- );
511
- }
512
-
513
513
  // src/lib/moduleGraph.ts
514
514
  var findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
515
515
  for (const extension of COMPONENT_EXTENSIONS) {
@@ -617,13 +617,13 @@ var logPartialInfo = (partialPath, props) => {
617
617
 
618
618
  // src/lib/renderPartial.ts
619
619
  async function renderPartial(viteServer, partialPath, props, pageUrl, basePath, environmentConfig, renderOptions) {
620
- logPartialInfo(partialPath, props);
621
- let serverSideProps;
620
+ try {
621
+ logPartialInfo(partialPath, props);
622
+ } catch (e) {
623
+ console.log("unable to log partial prop info");
624
+ console.error(e);
625
+ }
622
626
  const componentModule = await viteServer.ssrLoadModule(partialPath);
623
- const ungatedForServerSideProps = isUngatedFor(
624
- environmentConfig.getGates(),
625
- "CMS:JSRenderer:GetServerSideProps"
626
- );
627
627
  if (!componentModule) {
628
628
  throw new Error(`Couldn't find partial: ${partialPath}`);
629
629
  }
@@ -631,22 +631,11 @@ async function renderPartial(viteServer, partialPath, props, pageUrl, basePath,
631
631
  if (!Component) {
632
632
  throw new Error(`Couldn't find default export on partial: ${partialPath}`);
633
633
  }
634
- if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
635
- try {
636
- serverSideProps = await componentModule.getServerSidePropsUnstable(props);
637
- if (serverSideProps.constructor !== {}.constructor) {
638
- throw new Error("getServerSidePropsUnstable must return an object");
639
- }
640
- } catch (e) {
641
- console.log("Error resolving server side props");
642
- console.error(e);
643
- }
644
- }
645
634
  return renderComponentWithCSS_default(
646
635
  viteServer,
647
636
  partialPath,
648
637
  Component,
649
- { ...props, ...serverSideProps },
638
+ props,
650
639
  pageUrl,
651
640
  basePath,
652
641
  environmentConfig,
@@ -946,8 +935,9 @@ var lookForModuleInFolder = async (modulePath, viteServer) => {
946
935
  }
947
936
  return [componentModule, insideFolderPath];
948
937
  };
949
- async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}, pageUrl, basePath, environmentConfig, renderOptions) {
938
+ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUrl, basePath, environmentConfig, renderOptions) {
950
939
  console.log("Rendering module", requestedModulePath);
940
+ const { fieldValues: fieldOverrides = {}, hublParameters } = moduleProps;
951
941
  const ungatedForServerSideProps = isUngatedFor(
952
942
  environmentConfig.getGates(),
953
943
  "CMS:JSRenderer:GetServerSideProps"
@@ -982,18 +972,7 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
982
972
  throw new Error(`Module does not have a named meta export: ${foundPath}`);
983
973
  }
984
974
  const fieldsJSON = renderFieldsToJson(fields);
985
- const props = getPropsForModule(fieldsJSON, fieldOverrides);
986
- if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
987
- try {
988
- serverSideProps = await componentModule.getServerSidePropsUnstable(props);
989
- if (serverSideProps.constructor !== {}.constructor) {
990
- throw new Error("getServerSidePropsUnstable must return an object");
991
- }
992
- } catch (e) {
993
- console.log("Error resolving server side props");
994
- console.error(e);
995
- }
996
- }
975
+ const fieldValues = getFieldValuesForModule(fieldsJSON, fieldOverrides);
997
976
  if (componentModule.query && typeof componentModule.query === "string") {
998
977
  try {
999
978
  dataQueryResult = await fetchModuleGraphQLData(
@@ -1016,9 +995,23 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
1016
995
  }
1017
996
  }
1018
997
  const namespacedModuleProps = namespaceModulePropsShape({
1019
- ...props,
998
+ fieldValues,
999
+ hublParameters,
1020
1000
  dataQueryResult
1021
1001
  });
1002
+ if (ungatedForServerSideProps && componentModule.getServerSideProps) {
1003
+ try {
1004
+ serverSideProps = await componentModule.getServerSideProps(
1005
+ namespacedModuleProps
1006
+ );
1007
+ if (serverSideProps.constructor !== {}.constructor) {
1008
+ throw new Error("getServerSideProps must return an object");
1009
+ }
1010
+ } catch (e) {
1011
+ console.log("Error resolving server side props");
1012
+ console.error(e);
1013
+ }
1014
+ }
1022
1015
  return renderComponentWithCSS_default(
1023
1016
  viteServer,
1024
1017
  foundPath,
@@ -1030,7 +1023,7 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
1030
1023
  renderOptions
1031
1024
  );
1032
1025
  }
1033
- function getPropsForModule(fieldsJSON, fieldOverrides = {}) {
1026
+ function getFieldValuesForModule(fieldsJSON, fieldOverrides = {}) {
1034
1027
  const props = {};
1035
1028
  traverseFieldsJSON(fieldsJSON, fieldOverrides, (fieldPathArray, value) => {
1036
1029
  setIn(props, fieldPathArray, value);
@@ -1096,7 +1089,7 @@ var moduleRouteHandler = async (request2, response) => {
1096
1089
  } = await renderModule_default(
1097
1090
  viteServer,
1098
1091
  modulePath,
1099
- fieldOverrides,
1092
+ { fieldValues: fieldOverrides },
1100
1093
  fullOriginalUrlFromRequest(request2),
1101
1094
  basePath,
1102
1095
  environmentConfig,
@@ -1460,7 +1453,6 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
1460
1453
  proxiedQueryParams = {
1461
1454
  ...proxiedQueryParams,
1462
1455
  hs_preview: `${previewKey}-${contentId}`,
1463
- hsLocalProxy: true,
1464
1456
  hsLocalProxyProject: `@projects/${projectName}`,
1465
1457
  localProxySchemaVersion: 1
1466
1458
  };
@@ -1531,7 +1523,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
1531
1523
  return renderModule_default(
1532
1524
  viteServer,
1533
1525
  resolvedPath,
1534
- localRenderPlaceholderProps.fieldValues,
1526
+ localRenderPlaceholderProps,
1535
1527
  pageUrl,
1536
1528
  basePath,
1537
1529
  environmentConfig,
@@ -1868,7 +1860,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
1868
1860
  try {
1869
1861
  const { portalId, contentId, hublet } = await fetchContentMetadata(
1870
1862
  proxyPageUrl.href,
1871
- request2.app.locals.portalId
1863
+ request2.app.locals.authedPortalId
1872
1864
  );
1873
1865
  await proxySpecificPage(
1874
1866
  response,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.7.2",
3
+ "version": "0.7.7",
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.7.2",
28
+ "@hubspot/cms-components": "^0.7.7",
29
29
  "@storybook/addon-actions": "7.0.7",
30
30
  "@storybook/addon-essentials": "7.0.7",
31
31
  "@storybook/addon-interactions": "7.0.7",
@@ -97,5 +97,5 @@
97
97
  "publishConfig": {
98
98
  "access": "public"
99
99
  },
100
- "gitHead": "c7d8d001f21316fb22f45a9466be0ff36d824756"
100
+ "gitHead": "0a5d996b75302f9c7c600a937c42626728b98d48"
101
101
  }
Binary file
@@ -1,3 +0,0 @@
1
- import { Plugin } from 'vite';
2
- declare const noNodeBuiltinsPlugin: () => Plugin;
3
- export default noNodeBuiltinsPlugin;