@hubspot/cms-dev-server 0.18.3 → 0.18.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.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createServer as createViteServer } from "vite";
3
3
  import { default as react } from "@vitejs/plugin-react";
4
4
 
5
- // ../cms-js-internal/dist/basicUtils.js
5
+ // ../cms-js-internal/dist/types-BXr0V0Zd.js
6
6
  import path from "path";
7
7
  import { createHash } from "crypto";
8
8
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
@@ -371,7 +371,7 @@ function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplem
371
371
  return result;
372
372
  }
373
373
  var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
374
- const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
374
+ const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x2) => !!x2);
375
375
  if (sharedStateIDs.length > 0) {
376
376
  const indentString = " ".repeat(indent);
377
377
  const stateByID = {};
@@ -482,8 +482,9 @@ function noncePlaceholderPlugin() {
482
482
  }
483
483
  var traverse = _traverse.default;
484
484
  var CMS_MODULE_COMPONENT_NAME = "Module";
485
+ var DND_AREA_COMPONENT_NAME = "DndArea";
485
486
  var PLUGIN_NAME = "findCmsModules";
486
- function findCmsModules(cmsModules = {}) {
487
+ function findCmsModules(buildContentDescriptors = {}) {
487
488
  let config;
488
489
  return {
489
490
  enforce: "pre",
@@ -495,20 +496,20 @@ function findCmsModules(cmsModules = {}) {
495
496
  const moduleInfo = this.getModuleInfo(id);
496
497
  if (shouldSkipModule(config, moduleInfo, code))
497
498
  return null;
498
- const { localCmsModules, moduleUsed } = analyzeSourceCodeUsages(
499
+ const contentDescriptors = analyzeSourceCodeUsages(
499
500
  this,
500
501
  moduleInfo,
501
502
  config,
502
503
  code
503
504
  );
504
- if (!moduleUsed) {
505
- return null;
505
+ if (Object.keys(contentDescriptors.dndAreas).length > 0 || Object.keys(contentDescriptors.modules).length > 0) {
506
+ return {
507
+ meta: {
508
+ findCmsModules: contentDescriptors
509
+ }
510
+ };
506
511
  }
507
- return {
508
- meta: {
509
- findCmsModules: localCmsModules
510
- }
511
- };
512
+ return null;
512
513
  },
513
514
  buildEnd(error) {
514
515
  if (error)
@@ -547,7 +548,7 @@ function findCmsModules(cmsModules = {}) {
547
548
  ${JSON.stringify(modulesWithinModules, null, 2)}
548
549
  `);
549
550
  }
550
- Object.assign(cmsModules, relativeEntryPointCmsModuleMap);
551
+ Object.assign(buildContentDescriptors, relativeEntryPointCmsModuleMap);
551
552
  }
552
553
  };
553
554
  }
@@ -561,14 +562,16 @@ function convertEntryPointPathsToRelative(config, entryPointsCmsModuleMap) {
561
562
  }
562
563
  function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap) {
563
564
  const relativeEntries = Object.entries(entryPointsCmsModuleMap).map(
564
- ([entryPointPath, islandCmsModules]) => {
565
+ ([entryPointPath, islandContentDescriptors]) => {
565
566
  const islandCmsModuleUsage = Object.fromEntries(
566
- Object.entries(islandCmsModules).map(([islandPath, cmsModule]) => {
567
- return [
568
- toRelativePath(config, islandPath).replace("?client-entry", ""),
569
- cmsModule
570
- ];
571
- })
567
+ Object.entries(islandContentDescriptors).map(
568
+ ([islandPath, contentDescriptors]) => {
569
+ return [
570
+ toRelativePath(config, islandPath).replace("?client-entry", ""),
571
+ contentDescriptors
572
+ ];
573
+ }
574
+ )
572
575
  );
573
576
  return [toRelativePath(config, entryPointPath), islandCmsModuleUsage];
574
577
  }
@@ -580,7 +583,7 @@ function toRelativePath(config, path14) {
580
583
  }
581
584
  function shouldSkipModule(config, moduleInfo, code) {
582
585
  const isExternal = config.command !== "serve" && moduleInfo.isExternal;
583
- return isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME);
586
+ return isExternal || !moduleInfo.id.startsWith(config.root) || !(code.includes(CMS_MODULE_COMPONENT_NAME) || code.includes(DND_AREA_COMPONENT_NAME));
584
587
  }
585
588
  function getEntryPoints(ctx, config) {
586
589
  return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
@@ -610,9 +613,9 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
610
613
  sourceType: "module",
611
614
  plugins: ["jsx", "typescript"]
612
615
  });
613
- const localCmsModules = {};
614
- let moduleUsed = false;
616
+ const contentDescriptors = { modules: {}, dndAreas: {} };
615
617
  let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
618
+ let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
616
619
  traverse(sourceAst, {
617
620
  ImportDeclaration(path14) {
618
621
  if (t.isStringLiteral(path14.node.source, {
@@ -624,69 +627,96 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
624
627
  })) {
625
628
  moduleComponentLocalImportName = specifier.local.name;
626
629
  }
630
+ if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
631
+ name: DND_AREA_COMPONENT_NAME
632
+ })) {
633
+ dndAreaComponentLocalImportName = specifier.local.name;
634
+ }
627
635
  }
628
636
  }
629
637
  },
630
638
  JSXOpeningElement(path14) {
631
- if (!t.isJSXIdentifier(path14.node.name, {
639
+ if (t.isJSXIdentifier(path14.node.name, {
632
640
  name: moduleComponentLocalImportName
633
641
  })) {
634
- return null;
635
- }
636
- moduleUsed = true;
637
- let cmsModuleName;
638
- let cmsModulePath;
639
- let cmsModuleLabel;
640
- for (const prop of path14.node.attributes) {
641
- if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
642
- cmsModuleName = prop.value.value;
643
- continue;
642
+ let cmsModuleName;
643
+ let cmsModulePath;
644
+ let cmsModuleLabel;
645
+ for (const prop of path14.node.attributes) {
646
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
647
+ cmsModuleName = prop.value.value;
648
+ continue;
649
+ }
650
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
651
+ cmsModulePath = prop.value.value;
652
+ continue;
653
+ }
654
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
655
+ cmsModuleLabel = prop.value.value;
656
+ continue;
657
+ }
658
+ ctx.error(
659
+ new Error(
660
+ `Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
661
+ )
662
+ );
644
663
  }
645
- if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
646
- cmsModulePath = prop.value.value;
647
- continue;
664
+ const cmsModuleProps = {
665
+ name: cmsModuleName,
666
+ path: cmsModulePath
667
+ };
668
+ if (cmsModuleLabel) {
669
+ cmsModuleProps.label = cmsModuleLabel;
648
670
  }
649
- if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
650
- cmsModuleLabel = prop.value.value;
651
- continue;
671
+ if (Object.hasOwn(contentDescriptors.modules, cmsModuleProps.name)) {
672
+ ctx.error(
673
+ new Error(
674
+ `Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
675
+ )
676
+ );
652
677
  }
653
- ctx.error(
654
- new Error(
655
- `Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
656
- )
657
- );
678
+ contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
658
679
  }
659
- const cmsModuleProps = {
660
- name: cmsModuleName,
661
- path: cmsModulePath
662
- };
663
- if (cmsModuleLabel) {
664
- cmsModuleProps.label = cmsModuleLabel;
665
- }
666
- if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
667
- ctx.error(
668
- new Error(
669
- `Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
670
- )
671
- );
680
+ if (t.isJSXIdentifier(path14.node.name, {
681
+ name: dndAreaComponentLocalImportName
682
+ })) {
683
+ let dndAreaName;
684
+ for (const prop of path14.node.attributes) {
685
+ if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
686
+ dndAreaName = prop.value.value;
687
+ continue;
688
+ }
689
+ ctx.error(
690
+ new Error(
691
+ `Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" must a primitive string`
692
+ )
693
+ );
694
+ }
695
+ const dndArea = {
696
+ name: dndAreaName
697
+ };
698
+ if (Object.hasOwn(contentDescriptors.dndAreas, dndArea.name)) {
699
+ ctx.error(
700
+ new Error(
701
+ `Error: multiple <${DND_AREA_COMPONENT_NAME} /> with duplicate name: ${dndArea.name}`
702
+ )
703
+ );
704
+ }
705
+ contentDescriptors.dndAreas[dndArea.name] = dndArea;
672
706
  }
673
- localCmsModules[cmsModuleProps.name] = cmsModuleProps;
674
707
  }
675
708
  });
676
- return {
677
- moduleUsed,
678
- localCmsModules
679
- };
709
+ return contentDescriptors;
680
710
  }
681
711
  function findCmsModuleUsages(ctx, moduleId, processed = /* @__PURE__ */ new Set(), result = {}) {
682
712
  if (Object.hasOwn(result, moduleId)) {
683
713
  return result[moduleId];
684
714
  }
685
715
  const moduleInfo = ctx.getModuleInfo(moduleId);
686
- let entryPointModules = null;
716
+ let entryPointContentDescriptors = null;
687
717
  if (Object.hasOwn(moduleInfo.meta, PLUGIN_NAME)) {
688
- entryPointModules = {
689
- ...entryPointModules,
718
+ entryPointContentDescriptors = {
719
+ ...entryPointContentDescriptors,
690
720
  ...moduleInfo.meta[PLUGIN_NAME]
691
721
  };
692
722
  }
@@ -704,17 +734,17 @@ function findCmsModuleUsages(ctx, moduleId, processed = /* @__PURE__ */ new Set(
704
734
  result
705
735
  );
706
736
  if (importedResult) {
707
- entryPointModules = {
708
- ...entryPointModules,
737
+ entryPointContentDescriptors = {
738
+ ...entryPointContentDescriptors,
709
739
  ...importedResult
710
740
  };
711
741
  }
712
742
  }
713
- if (entryPointModules) {
714
- result[moduleId] = entryPointModules;
743
+ if (entryPointContentDescriptors) {
744
+ result[moduleId] = entryPointContentDescriptors;
715
745
  }
716
746
  processed.add(moduleId);
717
- return entryPointModules;
747
+ return entryPointContentDescriptors;
718
748
  }
719
749
  function findIslandCmsModuleUsage(ctx, moduleId, processedIslands = /* @__PURE__ */ new Set(), islandModuleResults = {}, processed = /* @__PURE__ */ new Set(), results = {}) {
720
750
  processedIslands.add(moduleId);
@@ -995,7 +1025,7 @@ var createViteDevServer_default = createViteDevServer;
995
1025
  // src/createDevServer.ts
996
1026
  import path13 from "path";
997
1027
  import url3 from "url";
998
- import express2 from "express";
1028
+ import express3 from "express";
999
1029
  import http3 from "http";
1000
1030
  import bodyParser from "body-parser";
1001
1031
  import { spawn } from "child_process";
@@ -1419,7 +1449,7 @@ function trackUsage(action) {
1419
1449
  eventName: EVENT_NAME,
1420
1450
  action,
1421
1451
  nodeVersion: getNodeVersionData(),
1422
- version: "0.18.3",
1452
+ version: "0.18.7",
1423
1453
  os: getPlatform()
1424
1454
  };
1425
1455
  const url4 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -4052,16 +4082,20 @@ async function startShadowDevServer(devServerPort, shadowPort, projectName, jsRe
4052
4082
  }
4053
4083
 
4054
4084
  // src/createAppServer.ts
4085
+ import fs3 from "node:fs/promises";
4086
+ import express2 from "express";
4055
4087
  import { createServer as createViteServer2 } from "vite";
4056
4088
  import { default as react2 } from "@vitejs/plugin-react";
4057
4089
  async function createAppServer(webRoot, port) {
4090
+ const app = express2();
4058
4091
  const origin = `http://hslocal.net:${port}`;
4059
4092
  const viteConfig = {
4060
4093
  server: {
4061
- middlewareMode: false,
4094
+ middlewareMode: true,
4062
4095
  host: "hslocal.net",
4063
4096
  origin
4064
4097
  },
4098
+ appType: "custom",
4065
4099
  root: webRoot,
4066
4100
  ssr: {
4067
4101
  noExternal: "@hubspot/cms-components"
@@ -4095,7 +4129,29 @@ async function createAppServer(webRoot, port) {
4095
4129
  envDir: webRoot,
4096
4130
  envPrefix: "HS_"
4097
4131
  };
4098
- return createViteServer2(viteConfig);
4132
+ const viteServer = await createViteServer2(viteConfig);
4133
+ app.use(viteServer.middlewares);
4134
+ app.use("*", async (req, res) => {
4135
+ try {
4136
+ const url4 = req.originalUrl.replace("/", "");
4137
+ let template = await fs3.readFile("./app/index.html", "utf-8");
4138
+ template = await viteServer.transformIndexHtml(url4, template);
4139
+ const { render } = await viteServer.ssrLoadModule(
4140
+ "./app/serverEntry.tsx"
4141
+ );
4142
+ const rendered = await render(url4);
4143
+ const html = template.replace(`<!--app-head-->`, rendered.head ?? "").replace(`<!--app-html-->`, rendered.html ?? "");
4144
+ res.status(200).set({ "Content-Type": "text/html" }).send(html);
4145
+ } catch (e) {
4146
+ viteServer == null ? void 0 : viteServer.ssrFixStacktrace(e);
4147
+ console.log(e.stack);
4148
+ res.status(500).end(e.stack);
4149
+ }
4150
+ });
4151
+ app.listen(port, () => {
4152
+ console.log(`Server started at http://localhost:${port}`);
4153
+ });
4154
+ return app;
4099
4155
  }
4100
4156
  var createAppServer_default = createAppServer;
4101
4157
 
@@ -4259,12 +4315,12 @@ async function fetchWebsiteDomainNames(portalId) {
4259
4315
 
4260
4316
  // src/lib/validateHSPlatform.ts
4261
4317
  import path11 from "path";
4262
- import fs3 from "fs";
4318
+ import fs4 from "fs";
4263
4319
  import select from "@inquirer/select";
4264
4320
  import { http as hsCliHttp12 } from "@hubspot/local-dev-lib/http";
4265
4321
  var HSPROJECT_JSON = "hsproject.json";
4266
4322
  function checkFileExists(filePath) {
4267
- return fs3.existsSync(filePath) && fs3.statSync(filePath).isFile();
4323
+ return fs4.existsSync(filePath) && fs4.statSync(filePath).isFile();
4268
4324
  }
4269
4325
  function findHSProjectJson(startPath) {
4270
4326
  let currentDir = startPath;
@@ -4290,7 +4346,7 @@ async function validateHSPlatform(projectConfigPath, portalId) {
4290
4346
  );
4291
4347
  return false;
4292
4348
  }
4293
- const hsProjectJSONContents = fs3.readFileSync(projectConfigPath, "utf8");
4349
+ const hsProjectJSONContents = fs4.readFileSync(projectConfigPath, "utf8");
4294
4350
  const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
4295
4351
  const { platformVersion } = hsProjectJSONData;
4296
4352
  let platformVersionResult;
@@ -4318,7 +4374,7 @@ async function validateHSPlatform(projectConfigPath, portalId) {
4318
4374
  });
4319
4375
  hsProjectJSONData.platformVersion = answer;
4320
4376
  try {
4321
- fs3.writeFileSync(
4377
+ fs4.writeFileSync(
4322
4378
  projectConfigPath,
4323
4379
  JSON.stringify(hsProjectJSONData, void 0, 2),
4324
4380
  "utf8"
@@ -4580,7 +4636,7 @@ function writeFieldsType(fields, fileName, typeName) {
4580
4636
  }
4581
4637
 
4582
4638
  // src/lib/watchFieldsUpdates.ts
4583
- import fs4 from "fs";
4639
+ import fs5 from "fs";
4584
4640
  import path12 from "path";
4585
4641
  import readline from "readline";
4586
4642
  var lastSerializedFieldsCache = {};
@@ -4602,9 +4658,9 @@ var isInModulesFolder = (filePath, projectRoot) => {
4602
4658
  };
4603
4659
  };
4604
4660
  var fileContainsAutoGenComment = async (filePath) => {
4605
- if (!fs4.existsSync(filePath))
4661
+ if (!fs5.existsSync(filePath))
4606
4662
  return true;
4607
- const stream2 = fs4.createReadStream(filePath);
4663
+ const stream2 = fs5.createReadStream(filePath);
4608
4664
  const reader = readline.createInterface({ input: stream2 });
4609
4665
  const firstLine = await new Promise(
4610
4666
  (resolve2) => reader.once("line", (line) => resolve2(line.trim()))
@@ -4623,7 +4679,7 @@ var getIndexFile = (filePath, projectRoot) => {
4623
4679
  if (isRootModuleFile)
4624
4680
  return { indexFilePath: filePath, isRootModuleFile };
4625
4681
  const dir = path12.dirname(filePath);
4626
- const files = fs4.readdirSync(dir);
4682
+ const files = fs5.readdirSync(dir);
4627
4683
  const indexFileName = files.find((file) => file.startsWith("index."));
4628
4684
  return indexFileName ? { indexFilePath: path12.join(dir, indexFileName), isRootModuleFile } : void 0;
4629
4685
  };
@@ -4858,7 +4914,7 @@ Local proxy functionality and module preview routes will not work without settin
4858
4914
  const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
4859
4915
  const projectName = projectConfigPath ? getProjectNameFromHSConfig(projectConfigPath) : "";
4860
4916
  const httpServers = [];
4861
- const expressServer = express2();
4917
+ const expressServer = express3();
4862
4918
  expressServer.locals.devServerHost = "hslocal.net";
4863
4919
  expressServer.locals.devServerPort = PORT;
4864
4920
  expressServer.locals.webRoot = webRoot;
@@ -4919,7 +4975,6 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
4919
4975
  "../app"
4920
4976
  );
4921
4977
  const appServer = await createAppServer_default(appWebRoot, PORT + 1);
4922
- await appServer.listen(PORT + 1);
4923
4978
  httpServers.push(appServer);
4924
4979
  }
4925
4980
  if (storybook) {