@hubspot/cms-dev-server 1.2.53 → 1.2.60

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 CHANGED
@@ -1651,7 +1651,7 @@ function trackUsage(action) {
1651
1651
  eventName: EVENT_NAME,
1652
1652
  action,
1653
1653
  nodeVersion: getNodeVersionData(),
1654
- version: "1.2.53",
1654
+ version: "1.2.60",
1655
1655
  os: getPlatform()
1656
1656
  };
1657
1657
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -2399,9 +2399,8 @@ function isModuleFolderChild(filePath) {
2399
2399
  import path4 from "path";
2400
2400
  var removePreviewPrefix = (t2) => t2.split("/").slice(2).join("/");
2401
2401
  var getPreviewUrl = (request, queryParams) => {
2402
- const { authedPortalId, authedEnv, authedHublet, sslEnabled } = request.app.locals;
2403
- const protocol = sslEnabled ? "https" : "http";
2404
- return `${protocol}://${authedPortalId}.hubspotpreview${authedEnv === "qa" ? "qa" : ""}-${authedHublet}.com/_hcms/preview/template/multi?${stringify(queryParams)}`;
2402
+ const { authedPortalId, authedEnv, authedHublet } = request.app.locals;
2403
+ return `https://${authedPortalId}.hubspotpreview${authedEnv === "qa" ? "qa" : ""}-${authedHublet}.com/_hcms/preview/template/multi?${stringify(queryParams)}`;
2405
2404
  };
2406
2405
  var buildHTMLResponse = (content) => {
2407
2406
  return `
@@ -3027,6 +3026,50 @@ async function fetchSignedModulePreview(signedUrl, authedEnv, cookieValue, postB
3027
3026
  return response.text();
3028
3027
  }
3029
3028
 
3029
+ // src/lib/extractRelevantCss.ts
3030
+ import postcss from "postcss";
3031
+ function isRelevantSelector(selector) {
3032
+ return selector.split(",").some(
3033
+ (part) => part.trim() === ":root" || /\[data-\w+-variant=/.test(part)
3034
+ );
3035
+ }
3036
+ function filterNodes(container) {
3037
+ const kept = [];
3038
+ container.each((node) => {
3039
+ if (node.type === "rule" && isRelevantSelector(node.selector)) {
3040
+ kept.push(node.clone());
3041
+ } else if (node.type === "atrule") {
3042
+ const children = filterNodes(node);
3043
+ if (children.length > 0) {
3044
+ const cloned = node.clone({ nodes: [] });
3045
+ for (const child of children) {
3046
+ cloned.append(child);
3047
+ }
3048
+ kept.push(cloned);
3049
+ }
3050
+ }
3051
+ });
3052
+ return kept;
3053
+ }
3054
+ function extractRelevantCss(cssText) {
3055
+ if (!cssText.trim()) {
3056
+ return "";
3057
+ }
3058
+ let root;
3059
+ try {
3060
+ root = postcss.parse(cssText);
3061
+ } catch (e) {
3062
+ console.warn("Failed to parse CSS for filtering, using unfiltered CSS:", e);
3063
+ return cssText;
3064
+ }
3065
+ const result = postcss.root();
3066
+ for (const node of filterNodes(root)) {
3067
+ result.append(node);
3068
+ }
3069
+ const output = result.toString();
3070
+ return output;
3071
+ }
3072
+
3030
3073
  // src/lib/renderModulePreview.ts
3031
3074
  import jsdom from "jsdom";
3032
3075
  var URL_SIGNING_GATE = "PortalsAccessIdentity:DesignManager:UrlSigning";
@@ -3055,15 +3098,23 @@ async function signedGet(authedPortalId, unsignedUrl, headers, gates) {
3055
3098
  return data;
3056
3099
  }
3057
3100
  const signedUrl = await signGetUrl(authedPortalId, unsignedUrl);
3058
- const authHeaders = {};
3059
3101
  const accountConfig = getConfigAccountIfExists4(authedPortalId);
3102
+ const authHeaders = {};
3060
3103
  if (accountConfig && accountConfig.authType === "personalaccesskey") {
3061
3104
  const accessToken = await accessTokenForPersonalAccessKey2(authedPortalId);
3062
3105
  authHeaders["Authorization"] = `Bearer ${accessToken}`;
3063
3106
  }
3107
+ const env2 = accountConfig == null ? void 0 : accountConfig.env;
3108
+ const referer = `https://api.hubspot${env2 === "qa" ? "qa" : ""}.com`;
3064
3109
  const response = await fetch(signedUrl, {
3065
3110
  method: "GET",
3066
- headers: { ...headers, ...authHeaders }
3111
+ headers: {
3112
+ ["Accept"]: "text/html",
3113
+ "User-Agent": "HubSpot CMS Dev Server",
3114
+ referer,
3115
+ ...headers,
3116
+ ...authHeaders
3117
+ }
3067
3118
  });
3068
3119
  if (!response.ok) {
3069
3120
  throw new Error(
@@ -3128,7 +3179,11 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
3128
3179
  const modulePreviewContent = dom.window.document.querySelector(
3129
3180
  'div[data-hs-cos-type="module"]'
3130
3181
  ).outerHTML;
3131
- const cssNeeded = Array.from(dom.window.document.querySelectorAll("style")).map((element) => element.outerHTML).join("");
3182
+ const allStyleContent = Array.from(
3183
+ dom.window.document.querySelectorAll("style")
3184
+ ).map((element) => element.textContent || "").join("\n");
3185
+ const filteredCss = extractRelevantCss(allStyleContent);
3186
+ const cssNeeded = filteredCss ? `<style>${filteredCss}</style>` : "";
3132
3187
  return { html: modulePreviewContent, cssNeeded };
3133
3188
  }
3134
3189
  async function signUrl(authedPortalId, unsignedUrl, requestBody) {
@@ -3213,7 +3268,8 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3213
3268
  const queryParams = new URLSearchParams({
3214
3269
  hsLocalProxy: `${true}`,
3215
3270
  localProxySchemaVersion: "2",
3216
- portalId: `${authedPortalId}`
3271
+ portalId: `${authedPortalId}`,
3272
+ ...meta.editor_version === "2.0" ? { editor_version: "2.0" } : {}
3217
3273
  });
3218
3274
  const currentHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
3219
3275
  process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot`;
@@ -3249,7 +3305,13 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3249
3305
  );
3250
3306
  }
3251
3307
  localRenderPlaceholders[0].json.props.fieldValues = localFieldValues;
3252
- return await renderComponentForPlaceholder(
3308
+ const previewDom = new JSDOM(templatePreview);
3309
+ const allStyleContent = Array.from(
3310
+ previewDom.window.document.querySelectorAll("head style")
3311
+ ).map((element) => element.textContent || "").join("\n");
3312
+ const filteredCss = extractRelevantCss(allStyleContent);
3313
+ const globalStylesCss = filteredCss ? `<style>${filteredCss}</style>` : "";
3314
+ const renderResult = await renderComponentForPlaceholder(
3253
3315
  0,
3254
3316
  localRenderPlaceholders[0],
3255
3317
  webRoot,
@@ -3260,6 +3322,7 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3260
3322
  projectName,
3261
3323
  projectComponentPath
3262
3324
  );
3325
+ return { ...renderResult, globalStylesCss };
3263
3326
  }
3264
3327
 
3265
3328
  // src/routes/partial.ts
@@ -4199,7 +4262,8 @@ async function modulePreviewRouteHandler(request, response) {
4199
4262
  html: renderedHtml,
4200
4263
  cssNeeded,
4201
4264
  renderContext,
4202
- inlineAssets
4265
+ inlineAssets,
4266
+ globalStylesCss
4203
4267
  } = await renderLocalProjectModulePreview(
4204
4268
  moduleName,
4205
4269
  authedPortalId,
@@ -4231,6 +4295,7 @@ async function modulePreviewRouteHandler(request, response) {
4231
4295
  htmlShell.replace(
4232
4296
  "<!--headend-->",
4233
4297
  [
4298
+ globalStylesCss,
4234
4299
  fullHeightCss,
4235
4300
  cssNeeded,
4236
4301
  ...inlineAssets.map((inlineAsset) => inlineAsset.html)
package/dist/run.js CHANGED
@@ -2256,7 +2256,7 @@ function trackUsage(action) {
2256
2256
  eventName: EVENT_NAME,
2257
2257
  action,
2258
2258
  nodeVersion: getNodeVersionData(),
2259
- version: "1.2.53",
2259
+ version: "1.2.60",
2260
2260
  os: getPlatform()
2261
2261
  };
2262
2262
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -3004,9 +3004,8 @@ function isModuleFolderChild(filePath) {
3004
3004
  import path6 from "path";
3005
3005
  var removePreviewPrefix = (t2) => t2.split("/").slice(2).join("/");
3006
3006
  var getPreviewUrl = (request, queryParams) => {
3007
- const { authedPortalId, authedEnv, authedHublet, sslEnabled } = request.app.locals;
3008
- const protocol = sslEnabled ? "https" : "http";
3009
- return `${protocol}://${authedPortalId}.hubspotpreview${authedEnv === "qa" ? "qa" : ""}-${authedHublet}.com/_hcms/preview/template/multi?${stringify(queryParams)}`;
3007
+ const { authedPortalId, authedEnv, authedHublet } = request.app.locals;
3008
+ return `https://${authedPortalId}.hubspotpreview${authedEnv === "qa" ? "qa" : ""}-${authedHublet}.com/_hcms/preview/template/multi?${stringify(queryParams)}`;
3010
3009
  };
3011
3010
  var buildHTMLResponse = (content) => {
3012
3011
  return `
@@ -3632,6 +3631,50 @@ async function fetchSignedModulePreview(signedUrl, authedEnv, cookieValue, postB
3632
3631
  return response.text();
3633
3632
  }
3634
3633
 
3634
+ // src/lib/extractRelevantCss.ts
3635
+ import postcss from "postcss";
3636
+ function isRelevantSelector(selector) {
3637
+ return selector.split(",").some(
3638
+ (part) => part.trim() === ":root" || /\[data-\w+-variant=/.test(part)
3639
+ );
3640
+ }
3641
+ function filterNodes(container) {
3642
+ const kept = [];
3643
+ container.each((node) => {
3644
+ if (node.type === "rule" && isRelevantSelector(node.selector)) {
3645
+ kept.push(node.clone());
3646
+ } else if (node.type === "atrule") {
3647
+ const children = filterNodes(node);
3648
+ if (children.length > 0) {
3649
+ const cloned = node.clone({ nodes: [] });
3650
+ for (const child of children) {
3651
+ cloned.append(child);
3652
+ }
3653
+ kept.push(cloned);
3654
+ }
3655
+ }
3656
+ });
3657
+ return kept;
3658
+ }
3659
+ function extractRelevantCss(cssText) {
3660
+ if (!cssText.trim()) {
3661
+ return "";
3662
+ }
3663
+ let root;
3664
+ try {
3665
+ root = postcss.parse(cssText);
3666
+ } catch (e) {
3667
+ console.warn("Failed to parse CSS for filtering, using unfiltered CSS:", e);
3668
+ return cssText;
3669
+ }
3670
+ const result = postcss.root();
3671
+ for (const node of filterNodes(root)) {
3672
+ result.append(node);
3673
+ }
3674
+ const output = result.toString();
3675
+ return output;
3676
+ }
3677
+
3635
3678
  // src/lib/renderModulePreview.ts
3636
3679
  import jsdom from "jsdom";
3637
3680
  var URL_SIGNING_GATE = "PortalsAccessIdentity:DesignManager:UrlSigning";
@@ -3660,15 +3703,23 @@ async function signedGet(authedPortalId, unsignedUrl, headers, gates) {
3660
3703
  return data;
3661
3704
  }
3662
3705
  const signedUrl = await signGetUrl(authedPortalId, unsignedUrl);
3663
- const authHeaders = {};
3664
3706
  const accountConfig = getConfigAccountIfExists5(authedPortalId);
3707
+ const authHeaders = {};
3665
3708
  if (accountConfig && accountConfig.authType === "personalaccesskey") {
3666
3709
  const accessToken = await accessTokenForPersonalAccessKey2(authedPortalId);
3667
3710
  authHeaders["Authorization"] = `Bearer ${accessToken}`;
3668
3711
  }
3712
+ const env2 = accountConfig == null ? void 0 : accountConfig.env;
3713
+ const referer = `https://api.hubspot${env2 === "qa" ? "qa" : ""}.com`;
3669
3714
  const response = await fetch(signedUrl, {
3670
3715
  method: "GET",
3671
- headers: { ...headers, ...authHeaders }
3716
+ headers: {
3717
+ ["Accept"]: "text/html",
3718
+ "User-Agent": "HubSpot CMS Dev Server",
3719
+ referer,
3720
+ ...headers,
3721
+ ...authHeaders
3722
+ }
3672
3723
  });
3673
3724
  if (!response.ok) {
3674
3725
  throw new Error(
@@ -3733,7 +3784,11 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
3733
3784
  const modulePreviewContent = dom.window.document.querySelector(
3734
3785
  'div[data-hs-cos-type="module"]'
3735
3786
  ).outerHTML;
3736
- const cssNeeded = Array.from(dom.window.document.querySelectorAll("style")).map((element) => element.outerHTML).join("");
3787
+ const allStyleContent = Array.from(
3788
+ dom.window.document.querySelectorAll("style")
3789
+ ).map((element) => element.textContent || "").join("\n");
3790
+ const filteredCss = extractRelevantCss(allStyleContent);
3791
+ const cssNeeded = filteredCss ? `<style>${filteredCss}</style>` : "";
3737
3792
  return { html: modulePreviewContent, cssNeeded };
3738
3793
  }
3739
3794
  async function signUrl(authedPortalId, unsignedUrl, requestBody) {
@@ -3818,7 +3873,8 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3818
3873
  const queryParams = new URLSearchParams({
3819
3874
  hsLocalProxy: `${true}`,
3820
3875
  localProxySchemaVersion: "2",
3821
- portalId: `${authedPortalId}`
3876
+ portalId: `${authedPortalId}`,
3877
+ ...meta.editor_version === "2.0" ? { editor_version: "2.0" } : {}
3822
3878
  });
3823
3879
  const currentHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
3824
3880
  process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot`;
@@ -3854,7 +3910,13 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3854
3910
  );
3855
3911
  }
3856
3912
  localRenderPlaceholders[0].json.props.fieldValues = localFieldValues;
3857
- return await renderComponentForPlaceholder(
3913
+ const previewDom = new JSDOM(templatePreview);
3914
+ const allStyleContent = Array.from(
3915
+ previewDom.window.document.querySelectorAll("head style")
3916
+ ).map((element) => element.textContent || "").join("\n");
3917
+ const filteredCss = extractRelevantCss(allStyleContent);
3918
+ const globalStylesCss = filteredCss ? `<style>${filteredCss}</style>` : "";
3919
+ const renderResult = await renderComponentForPlaceholder(
3858
3920
  0,
3859
3921
  localRenderPlaceholders[0],
3860
3922
  webRoot2,
@@ -3865,6 +3927,7 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3865
3927
  projectName,
3866
3928
  projectComponentPath
3867
3929
  );
3930
+ return { ...renderResult, globalStylesCss };
3868
3931
  }
3869
3932
 
3870
3933
  // src/routes/partial.ts
@@ -4804,7 +4867,8 @@ async function modulePreviewRouteHandler(request, response) {
4804
4867
  html: renderedHtml,
4805
4868
  cssNeeded,
4806
4869
  renderContext,
4807
- inlineAssets
4870
+ inlineAssets,
4871
+ globalStylesCss
4808
4872
  } = await renderLocalProjectModulePreview(
4809
4873
  moduleName,
4810
4874
  authedPortalId,
@@ -4836,6 +4900,7 @@ async function modulePreviewRouteHandler(request, response) {
4836
4900
  htmlShell.replace(
4837
4901
  "<!--headend-->",
4838
4902
  [
4903
+ globalStylesCss,
4839
4904
  fullHeightCss,
4840
4905
  cssNeeded,
4841
4906
  ...inlineAssets.map((inlineAsset) => inlineAsset.html)
@@ -730,6 +730,7 @@ async function validateModuleFields(projectRoot, moduleName) {
730
730
  logLevel: "silent",
731
731
  appType: "custom",
732
732
  root: absoluteRoot,
733
+ cacheDir: path3.join(absoluteRoot, "node_modules/.vite-validate-fields"),
733
734
  server: { middlewareMode: true, hmr: false },
734
735
  optimizeDeps: { noDiscovery: true, include: [] },
735
736
  ssr: { noExternal: "@hubspot/cms-components" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "1.2.53",
3
+ "version": "1.2.60",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -29,7 +29,7 @@
29
29
  "@babel/parser": "^7.25.3",
30
30
  "@babel/traverse": "^7.25.3",
31
31
  "@babel/types": "^7.25.2",
32
- "@hubspot/cms-components": "^1.2.53",
32
+ "@hubspot/cms-components": "^1.2.60",
33
33
  "@hubspot/local-dev-lib": "5.8.2",
34
34
  "@inquirer/select": "^2.0.0",
35
35
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -135,5 +135,5 @@
135
135
  "publishConfig": {
136
136
  "access": "public"
137
137
  },
138
- "gitHead": "969ccc853c57cf798cc99cd581580145a196947a"
138
+ "gitHead": "3f0de1da7da87dedafe63b9f96e10324de5a9e1a"
139
139
  }
@@ -0,0 +1 @@
1
+ export declare function extractRelevantCss(cssText: string): string;
@@ -6,4 +6,10 @@ export declare function renderRemoteModulePreview(modulePath: string, authedPort
6
6
  cssNeeded: string;
7
7
  }>;
8
8
  export declare function signUrl(authedPortalId: number, unsignedUrl: string, requestBody: any): Promise<string>;
9
- export declare function renderLocalProjectModulePreview(moduleName: string, authedPortalId: any, authedEnv: any, authedHublet: any, webRoot: any, viteServer: any, jsRenderingGates: any, projectName: any, projectComponentPath: any, fullOriginalUrl: any, cookieValue: any, fieldOverrides?: {}): Promise<import("./renderComponentWithCSS.js").RenderResult>;
9
+ export declare function renderLocalProjectModulePreview(moduleName: string, authedPortalId: any, authedEnv: any, authedHublet: any, webRoot: any, viteServer: any, jsRenderingGates: any, projectName: any, projectComponentPath: any, fullOriginalUrl: any, cookieValue: any, fieldOverrides?: {}): Promise<{
10
+ globalStylesCss: string;
11
+ html: string;
12
+ inlineAssets?: import("@hubspot/cms-js-internal").InlineAsset[];
13
+ cssNeeded: string;
14
+ renderContext: import("@hubspot/cms-components").ServerRenderContextValue;
15
+ }>;