@hubspot/cms-dev-server 1.2.33 → 1.2.34
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/app/index.html +2 -2
- package/dist/generateJsonFromJsx.js +3 -3
- package/dist/index.js +226 -130
- package/dist/internalSsr.js +6 -6
- package/dist/island-runtime.js +38 -23
- package/dist/run.js +315 -219
- package/dist/storybook/index.js +1 -1
- package/dist/storybook-main/main.js +10 -10
- package/package.json +5 -5
- package/types/lib/hsmetaUtils.d.ts +3 -0
- package/types/lib/renderModulePreview.d.ts +4 -1
- /package/dist/app/assets/{index-tvg7JxpD.js → index-BhmkOPU4.js} +0 -0
- /package/dist/app/assets/{index-PcyCbkys.css → index-CbQ-tZoN.css} +0 -0
package/dist/run.js
CHANGED
|
@@ -38,8 +38,8 @@ import cliProgress from "cli-progress";
|
|
|
38
38
|
import { FILE_UPLOAD_RESULT_TYPES } from "@hubspot/local-dev-lib/constants/files";
|
|
39
39
|
|
|
40
40
|
// src/lib/cliUtils.ts
|
|
41
|
-
import
|
|
42
|
-
import
|
|
41
|
+
import fs2 from "fs";
|
|
42
|
+
import path2 from "path";
|
|
43
43
|
import { walk } from "@hubspot/local-dev-lib/fs";
|
|
44
44
|
import { createIgnoreFilter } from "@hubspot/local-dev-lib/ignoreRules";
|
|
45
45
|
import { isAllowedExtension } from "@hubspot/local-dev-lib/path";
|
|
@@ -50,6 +50,49 @@ import { getThemeJSONPath } from "@hubspot/local-dev-lib/cms/themes";
|
|
|
50
50
|
import findup from "findup-sync";
|
|
51
51
|
import { getAbsoluteFilePath } from "@hubspot/local-dev-lib/path";
|
|
52
52
|
import { logger } from "@hubspot/local-dev-lib/logger";
|
|
53
|
+
|
|
54
|
+
// src/lib/hsmetaUtils.ts
|
|
55
|
+
import path from "path";
|
|
56
|
+
import fs from "fs";
|
|
57
|
+
var HSMETA_FILENAMES = [
|
|
58
|
+
"theme-hsmeta.json",
|
|
59
|
+
"cms-assets-hsmeta.json"
|
|
60
|
+
];
|
|
61
|
+
function getSubdirectories(dirPath) {
|
|
62
|
+
try {
|
|
63
|
+
return fs.readdirSync(dirPath, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
64
|
+
} catch {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function hsmetaCandidatePaths(srcPath) {
|
|
69
|
+
const subdirs = getSubdirectories(srcPath);
|
|
70
|
+
return subdirs.flatMap(
|
|
71
|
+
(subdir) => HSMETA_FILENAMES.map((filename) => path.join(srcPath, subdir, filename))
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function tryParseUid(hsmetaPath) {
|
|
75
|
+
try {
|
|
76
|
+
const hsmeta = JSON.parse(fs.readFileSync(hsmetaPath, "utf8"));
|
|
77
|
+
return hsmeta.uid ?? null;
|
|
78
|
+
} catch (parseErr) {
|
|
79
|
+
console.warn(`Could not parse ${hsmetaPath}:`, parseErr.message);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function findHsmetaUid(projectDir, srcDir) {
|
|
84
|
+
const srcPath = path.join(projectDir, srcDir);
|
|
85
|
+
for (const candidatePath of hsmetaCandidatePaths(srcPath)) {
|
|
86
|
+
if (!fs.existsSync(candidatePath))
|
|
87
|
+
continue;
|
|
88
|
+
const uid = tryParseUid(candidatePath);
|
|
89
|
+
if (uid)
|
|
90
|
+
return uid;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/lib/cliUtils.ts
|
|
53
96
|
import {
|
|
54
97
|
isHubSpotHttpError,
|
|
55
98
|
isSystemError,
|
|
@@ -88,7 +131,7 @@ function previewProjectPrompt(themeComponents) {
|
|
|
88
131
|
message: "[--theme] Select which theme to preview.",
|
|
89
132
|
type: "list",
|
|
90
133
|
choices: themeComponents.map((t2) => {
|
|
91
|
-
const themeName =
|
|
134
|
+
const themeName = path2.basename(t2.path);
|
|
92
135
|
return {
|
|
93
136
|
name: themeName,
|
|
94
137
|
value: t2.path
|
|
@@ -105,7 +148,7 @@ var getProjectConfig = async (_dir, isUsingLocalWorkspace = false) => {
|
|
|
105
148
|
}
|
|
106
149
|
const PROJECT_CONFIG_FILE = "hsproject.json";
|
|
107
150
|
return findup(PROJECT_CONFIG_FILE, {
|
|
108
|
-
cwd:
|
|
151
|
+
cwd: path2.resolve(__dir),
|
|
109
152
|
nocase: true
|
|
110
153
|
});
|
|
111
154
|
};
|
|
@@ -114,10 +157,10 @@ var getProjectConfig = async (_dir, isUsingLocalWorkspace = false) => {
|
|
|
114
157
|
return { projectConfig: null, projectDir: null };
|
|
115
158
|
}
|
|
116
159
|
try {
|
|
117
|
-
const config =
|
|
160
|
+
const config = fs2.readFileSync(configPath, "utf8");
|
|
118
161
|
const projectConfig = JSON.parse(config);
|
|
119
162
|
return {
|
|
120
|
-
projectDir:
|
|
163
|
+
projectDir: path2.dirname(configPath),
|
|
121
164
|
projectConfig
|
|
122
165
|
};
|
|
123
166
|
} catch (e) {
|
|
@@ -127,7 +170,7 @@ var getProjectConfig = async (_dir, isUsingLocalWorkspace = false) => {
|
|
|
127
170
|
function loadConfigFile(configPath) {
|
|
128
171
|
if (configPath) {
|
|
129
172
|
try {
|
|
130
|
-
const source =
|
|
173
|
+
const source = fs2.readFileSync(configPath);
|
|
131
174
|
const parsedConfig = JSON.parse(source);
|
|
132
175
|
return parsedConfig;
|
|
133
176
|
} catch (e) {
|
|
@@ -153,7 +196,7 @@ async function findProjectComponents(projectSourceDir) {
|
|
|
153
196
|
console.error(e);
|
|
154
197
|
}
|
|
155
198
|
projectFiles.forEach((projectFile) => {
|
|
156
|
-
const { base, dir } =
|
|
199
|
+
const { base, dir } = path2.parse(projectFile);
|
|
157
200
|
if (Object.values(CONFIG_FILES).includes(base)) {
|
|
158
201
|
const parsedAppConfig = loadConfigFile(projectFile);
|
|
159
202
|
if (parsedAppConfig) {
|
|
@@ -179,7 +222,7 @@ function getAppCardConfigs(appConfig, appPath) {
|
|
|
179
222
|
if (cards) {
|
|
180
223
|
cards.forEach(({ file }) => {
|
|
181
224
|
if (typeof file === "string") {
|
|
182
|
-
const cardConfigPath =
|
|
225
|
+
const cardConfigPath = path2.join(appPath, file);
|
|
183
226
|
const cardConfig = loadConfigFile(cardConfigPath);
|
|
184
227
|
if (cardConfig) {
|
|
185
228
|
cardConfigs.push(cardConfig);
|
|
@@ -206,36 +249,34 @@ function getIsLegacyApp(appConfig, appPath) {
|
|
|
206
249
|
function hasNewDirectoryStructure(platformVersion) {
|
|
207
250
|
return parseFloat(platformVersion) >= 2025.2;
|
|
208
251
|
}
|
|
209
|
-
function
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
"theme-hsmeta.json"
|
|
215
|
-
);
|
|
216
|
-
if (!fs.existsSync(hsmetaPath)) {
|
|
252
|
+
function findAndReadHsmeta(projectDir, srcDir = "src") {
|
|
253
|
+
const srcPath = path2.join(projectDir, srcDir);
|
|
254
|
+
const candidates = hsmetaCandidatePaths(srcPath);
|
|
255
|
+
const hsmetaPath = candidates.find((p) => fs2.existsSync(p));
|
|
256
|
+
if (!hsmetaPath) {
|
|
217
257
|
console.error(
|
|
218
|
-
`Error: theme-hsmeta.json
|
|
258
|
+
`Error: No hsmeta file (theme-hsmeta.json or cms-assets-hsmeta.json) found in any subdirectory of ${srcPath}. For platformVersion 2025.2 and higher, the project structure requires an hsmeta file.`
|
|
219
259
|
);
|
|
220
260
|
process2.exit(1);
|
|
221
261
|
}
|
|
262
|
+
const hsmetaFilename = path2.basename(hsmetaPath);
|
|
263
|
+
let hsmeta;
|
|
222
264
|
try {
|
|
223
|
-
|
|
224
|
-
const hsmeta = JSON.parse(hsmetaContent);
|
|
225
|
-
if (!hsmeta.uid) {
|
|
226
|
-
console.error(
|
|
227
|
-
`Error: theme-hsmeta.json at ${hsmetaPath} is missing required 'uid' field.`
|
|
228
|
-
);
|
|
229
|
-
process2.exit(1);
|
|
230
|
-
}
|
|
231
|
-
return hsmeta;
|
|
265
|
+
hsmeta = JSON.parse(fs2.readFileSync(hsmetaPath, "utf8"));
|
|
232
266
|
} catch (e) {
|
|
233
267
|
console.error(
|
|
234
|
-
`Error: Failed to read or parse
|
|
268
|
+
`Error: Failed to read or parse ${hsmetaFilename} at ${hsmetaPath}`
|
|
235
269
|
);
|
|
236
270
|
console.error(e.message);
|
|
237
271
|
process2.exit(1);
|
|
238
272
|
}
|
|
273
|
+
if (!hsmeta.uid) {
|
|
274
|
+
console.error(
|
|
275
|
+
`Error: ${hsmetaFilename} at ${hsmetaPath} is missing required 'uid' field.`
|
|
276
|
+
);
|
|
277
|
+
process2.exit(1);
|
|
278
|
+
}
|
|
279
|
+
return hsmeta;
|
|
239
280
|
}
|
|
240
281
|
async function determineSrcAndDest(webRoot2, isUsingLocalWorkspace = false) {
|
|
241
282
|
let absoluteSrc;
|
|
@@ -260,14 +301,14 @@ async function determineSrcAndDest(webRoot2, isUsingLocalWorkspace = false) {
|
|
|
260
301
|
const answer = await previewProjectPrompt(themeComponents);
|
|
261
302
|
themeJsonPath = `${answer.themeComponentPath}/theme.json`;
|
|
262
303
|
}
|
|
263
|
-
const { dir: themeDir } =
|
|
304
|
+
const { dir: themeDir } = path2.parse(themeJsonPath);
|
|
264
305
|
absoluteSrc = themeDir;
|
|
265
|
-
const { base: themeName } =
|
|
306
|
+
const { base: themeName } = path2.parse(themeDir);
|
|
266
307
|
const platformVersion = projectConfig.platformVersion || "2025.1";
|
|
267
308
|
const isNewStructure = hasNewDirectoryStructure(platformVersion);
|
|
268
309
|
if (isNewStructure) {
|
|
269
310
|
const srcDir = projectConfig.srcDir || "src";
|
|
270
|
-
const hsmeta =
|
|
311
|
+
const hsmeta = findAndReadHsmeta(projectDir, srcDir);
|
|
271
312
|
const uid = hsmeta.uid;
|
|
272
313
|
dest = `@projects/${projectConfig.name}/${uid}`;
|
|
273
314
|
} else {
|
|
@@ -298,7 +339,7 @@ async function getUploadableFileList(src, convertFields) {
|
|
|
298
339
|
const uploadableFiles = [];
|
|
299
340
|
let skipFiles = [];
|
|
300
341
|
for (const filePath of allowedFiles) {
|
|
301
|
-
const fileName =
|
|
342
|
+
const fileName = path2.basename(filePath);
|
|
302
343
|
if (skipFiles.includes(filePath))
|
|
303
344
|
continue;
|
|
304
345
|
const isConvertable = isConvertableFieldJs(src, filePath, convertFields);
|
|
@@ -322,15 +363,15 @@ function promptUser(promptConfig) {
|
|
|
322
363
|
}
|
|
323
364
|
async function fieldsJsPrompt(filePath, projectDir, skipFiles = []) {
|
|
324
365
|
const FIELDS_FILES = ["fields.json", "fields.js", "fields.cjs", "fields.mjs"];
|
|
325
|
-
const dirName =
|
|
326
|
-
const fileChoices =
|
|
366
|
+
const dirName = path2.dirname(filePath);
|
|
367
|
+
const fileChoices = fs2.readdirSync(dirName).filter((file) => FIELDS_FILES.includes(file)).map((file) => path2.resolve(dirName, file)).filter((file) => !skipFiles.includes(file));
|
|
327
368
|
if (!fileChoices.length)
|
|
328
369
|
return [filePath, []];
|
|
329
370
|
if (fileChoices.length === 1)
|
|
330
371
|
return [fileChoices[0], []];
|
|
331
372
|
projectDir = projectDir.substring(0, projectDir.lastIndexOf("/"));
|
|
332
373
|
const projectDirRegex = new RegExp(`^${escapeRegExp(projectDir)}`);
|
|
333
|
-
const fileDir =
|
|
374
|
+
const fileDir = path2.dirname(fileChoices[0]).replace(projectDirRegex, "");
|
|
334
375
|
const selection = [];
|
|
335
376
|
fileChoices.forEach((fileChoice) => {
|
|
336
377
|
selection.push({
|
|
@@ -801,8 +842,8 @@ async function buildThemePreviewOptions(webRoot2, isUsingLocalWorkspace = false)
|
|
|
801
842
|
}
|
|
802
843
|
|
|
803
844
|
// src/createDevServer.ts
|
|
804
|
-
import
|
|
805
|
-
import
|
|
845
|
+
import path18 from "path";
|
|
846
|
+
import fs9 from "fs";
|
|
806
847
|
import url2 from "url";
|
|
807
848
|
import express2 from "express";
|
|
808
849
|
import http3 from "http";
|
|
@@ -819,7 +860,7 @@ import {
|
|
|
819
860
|
import { createProxyMiddleware as createProxyMiddleware2 } from "http-proxy-middleware";
|
|
820
861
|
|
|
821
862
|
// src/routes/partial.ts
|
|
822
|
-
import
|
|
863
|
+
import path9 from "path";
|
|
823
864
|
import { normalizePath as normalizePath5 } from "vite";
|
|
824
865
|
|
|
825
866
|
// src/lib/fullOriginalUrlFromRequest.ts
|
|
@@ -836,28 +877,28 @@ import {
|
|
|
836
877
|
} from "react-dom/server";
|
|
837
878
|
|
|
838
879
|
// src/lib/packagePath.ts
|
|
839
|
-
import
|
|
880
|
+
import path3 from "path";
|
|
840
881
|
import url from "url";
|
|
841
882
|
import { normalizePath } from "vite";
|
|
842
883
|
function packagePath(metaUrl, projectPath) {
|
|
843
884
|
if (true) {
|
|
844
885
|
return normalizePath(
|
|
845
|
-
|
|
886
|
+
path3.resolve(path3.dirname(url.fileURLToPath(metaUrl)), projectPath)
|
|
846
887
|
);
|
|
847
888
|
}
|
|
848
|
-
const parentDirPath = normalizePath(
|
|
889
|
+
const parentDirPath = normalizePath(path3.dirname(url.fileURLToPath(metaUrl)));
|
|
849
890
|
const subPath = parentDirPath.replace(/^.+cms-dev-server\/src\//, "");
|
|
850
891
|
const subPathParentDirs = subPath.split("/").map(() => "..");
|
|
851
|
-
return
|
|
852
|
-
|
|
853
|
-
|
|
892
|
+
return path3.resolve(
|
|
893
|
+
path3.dirname(url.fileURLToPath(metaUrl)),
|
|
894
|
+
path3.join(...subPathParentDirs, projectPath)
|
|
854
895
|
);
|
|
855
896
|
}
|
|
856
897
|
|
|
857
|
-
// ../cms-js-internal/dist/types-
|
|
858
|
-
import
|
|
898
|
+
// ../cms-js-internal/dist/types-BEz622C8.js
|
|
899
|
+
import path4 from "path";
|
|
859
900
|
import { createHash } from "crypto";
|
|
860
|
-
import
|
|
901
|
+
import fs3, { readFileSync, existsSync as existsSync2, readdirSync, lstatSync } from "fs";
|
|
861
902
|
import { join as join2 } from "path/posix";
|
|
862
903
|
var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
863
904
|
var ENTRY_POINTS_PATH = "components/partials/";
|
|
@@ -964,12 +1005,12 @@ function resolveIslandPlugin(islandsSet) {
|
|
|
964
1005
|
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
965
1006
|
const [idWithNoParam] = id.split("?");
|
|
966
1007
|
const islandModuleImportPath = `${idWithNoParam}?client-entry`;
|
|
967
|
-
const componentExtension =
|
|
968
|
-
const componentFilenameWithNoExtension =
|
|
1008
|
+
const componentExtension = path4.extname(idWithNoParam);
|
|
1009
|
+
const componentFilenameWithNoExtension = path4.basename(
|
|
969
1010
|
idWithNoParam,
|
|
970
1011
|
componentExtension
|
|
971
1012
|
);
|
|
972
|
-
const modulePath =
|
|
1013
|
+
const modulePath = path4.relative(viteRoot, idWithNoParam);
|
|
973
1014
|
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
974
1015
|
if (islandsSet) {
|
|
975
1016
|
islandsSet.add(moduleId);
|
|
@@ -1063,7 +1104,7 @@ var hasComponentExtension = (componentPath) => {
|
|
|
1063
1104
|
return !!getComponentExtension(componentPath);
|
|
1064
1105
|
};
|
|
1065
1106
|
var isStorybookStory = (componentPath) => {
|
|
1066
|
-
return !!
|
|
1107
|
+
return !!path4.basename(componentPath, path4.extname(componentPath)).endsWith(".stories");
|
|
1067
1108
|
};
|
|
1068
1109
|
var removeComponentExtension = (componentPath) => {
|
|
1069
1110
|
const ext = getComponentExtension(componentPath);
|
|
@@ -1080,18 +1121,28 @@ function getEntryPointHashWithIndexSuffix(entryPoint, index) {
|
|
|
1080
1121
|
return `${getEntryPointHash(entryPoint)}${renderIndexSuffix}`;
|
|
1081
1122
|
}
|
|
1082
1123
|
function getCMSAssetConfig(webRoot2) {
|
|
1083
|
-
const cmsAssetsPath =
|
|
1084
|
-
const cmsThemePath =
|
|
1085
|
-
const configPathToUse =
|
|
1124
|
+
const cmsAssetsPath = path4.join(webRoot2, "cms-assets.json");
|
|
1125
|
+
const cmsThemePath = path4.join(webRoot2, "theme.json");
|
|
1126
|
+
const configPathToUse = fs3.existsSync(cmsAssetsPath) ? cmsAssetsPath : cmsThemePath;
|
|
1086
1127
|
const parsedConfig = JSON.parse(
|
|
1087
|
-
|
|
1128
|
+
fs3.readFileSync(configPathToUse).toString()
|
|
1088
1129
|
);
|
|
1089
1130
|
return parsedConfig;
|
|
1090
1131
|
}
|
|
1132
|
+
function getCMSAssetConfigIfExists(webRoot2) {
|
|
1133
|
+
try {
|
|
1134
|
+
return getCMSAssetConfig(webRoot2);
|
|
1135
|
+
} catch (e) {
|
|
1136
|
+
console.error(
|
|
1137
|
+
`Error finding or parsing cms-assets.json in ${webRoot2}, but ignoring for now`
|
|
1138
|
+
);
|
|
1139
|
+
return {};
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1091
1142
|
var ENABLED_FEATURES_GATE_MAP = {
|
|
1092
1143
|
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
1093
|
-
"cms:jsr:
|
|
1094
|
-
"
|
|
1144
|
+
"cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules",
|
|
1145
|
+
"PortalsAccessIdentity:DesignManager:UrlSigning": "PortalsAccessIdentity:DesignManager:UrlSigning"
|
|
1095
1146
|
};
|
|
1096
1147
|
function isUngatedFor(gates, gate) {
|
|
1097
1148
|
return gates.includes(gate);
|
|
@@ -1514,8 +1565,8 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
|
|
|
1514
1565
|
);
|
|
1515
1566
|
return Object.fromEntries(relativeEntries);
|
|
1516
1567
|
}
|
|
1517
|
-
function toRelativePath(config,
|
|
1518
|
-
return
|
|
1568
|
+
function toRelativePath(config, path19) {
|
|
1569
|
+
return path19.replace(`${config.root}/`, "");
|
|
1519
1570
|
}
|
|
1520
1571
|
function shouldAnalyzeModule(config, moduleInfo, code) {
|
|
1521
1572
|
const [fileId, __] = moduleInfo.id.split("?");
|
|
@@ -1558,11 +1609,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
1558
1609
|
let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
|
|
1559
1610
|
let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
|
|
1560
1611
|
traverse(sourceAst, {
|
|
1561
|
-
ImportDeclaration(
|
|
1562
|
-
if (t.isStringLiteral(
|
|
1612
|
+
ImportDeclaration(path19) {
|
|
1613
|
+
if (t.isStringLiteral(path19.node.source, {
|
|
1563
1614
|
value: "@hubspot/cms-components"
|
|
1564
1615
|
})) {
|
|
1565
|
-
for (const specifier of
|
|
1616
|
+
for (const specifier of path19.node.specifiers) {
|
|
1566
1617
|
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
1567
1618
|
name: CMS_MODULE_COMPONENT_NAME
|
|
1568
1619
|
})) {
|
|
@@ -1576,14 +1627,14 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
1576
1627
|
}
|
|
1577
1628
|
}
|
|
1578
1629
|
},
|
|
1579
|
-
JSXOpeningElement(
|
|
1580
|
-
if (t.isJSXIdentifier(
|
|
1630
|
+
JSXOpeningElement(path19) {
|
|
1631
|
+
if (t.isJSXIdentifier(path19.node.name, {
|
|
1581
1632
|
name: moduleComponentLocalImportName
|
|
1582
1633
|
})) {
|
|
1583
1634
|
let cmsModuleName;
|
|
1584
1635
|
let cmsModulePath;
|
|
1585
1636
|
let cmsModuleLabel;
|
|
1586
|
-
for (const prop of
|
|
1637
|
+
for (const prop of path19.node.attributes) {
|
|
1587
1638
|
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
1588
1639
|
cmsModuleName = prop.value.value;
|
|
1589
1640
|
continue;
|
|
@@ -1618,11 +1669,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
1618
1669
|
}
|
|
1619
1670
|
contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
|
|
1620
1671
|
}
|
|
1621
|
-
if (t.isJSXIdentifier(
|
|
1672
|
+
if (t.isJSXIdentifier(path19.node.name, {
|
|
1622
1673
|
name: dndAreaComponentLocalImportName
|
|
1623
1674
|
})) {
|
|
1624
1675
|
let dndAreaName;
|
|
1625
|
-
for (const prop of
|
|
1676
|
+
for (const prop of path19.node.attributes) {
|
|
1626
1677
|
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
1627
1678
|
dndAreaName = prop.value.value;
|
|
1628
1679
|
continue;
|
|
@@ -2197,7 +2248,7 @@ function trackUsage(action) {
|
|
|
2197
2248
|
eventName: EVENT_NAME,
|
|
2198
2249
|
action,
|
|
2199
2250
|
nodeVersion: getNodeVersionData(),
|
|
2200
|
-
version: "1.2.
|
|
2251
|
+
version: "1.2.34",
|
|
2201
2252
|
os: getPlatform()
|
|
2202
2253
|
};
|
|
2203
2254
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -2237,11 +2288,11 @@ function sendTrackingRequest(action) {
|
|
|
2237
2288
|
|
|
2238
2289
|
// src/lib/renderModulePreview.ts
|
|
2239
2290
|
import { buildStaticEnvConfig as buildStaticEnvConfig2 } from "@hubspot/cms-components";
|
|
2240
|
-
import
|
|
2291
|
+
import path8 from "path";
|
|
2241
2292
|
import { normalizePath as normalizePath4 } from "vite";
|
|
2242
2293
|
|
|
2243
2294
|
// src/lib/proxyHelpers.ts
|
|
2244
|
-
import
|
|
2295
|
+
import fs4 from "fs";
|
|
2245
2296
|
import { resolve as resolve2 } from "path";
|
|
2246
2297
|
import { unescape } from "html-escaper";
|
|
2247
2298
|
var localJsRenderStartString = '<!-- proxy local render of "';
|
|
@@ -2270,12 +2321,12 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
2270
2321
|
);
|
|
2271
2322
|
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
2272
2323
|
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
2273
|
-
const
|
|
2324
|
+
const path19 = body.substring(
|
|
2274
2325
|
startOffset + localJsRenderStartString.length,
|
|
2275
2326
|
pathEndOffset
|
|
2276
2327
|
);
|
|
2277
2328
|
offsetSoFar = pathEndOffset + 1;
|
|
2278
|
-
if (startOffset >= 0 &&
|
|
2329
|
+
if (startOffset >= 0 && path19) {
|
|
2279
2330
|
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
2280
2331
|
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
2281
2332
|
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
@@ -2300,7 +2351,7 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
2300
2351
|
result.push({
|
|
2301
2352
|
startOffset,
|
|
2302
2353
|
endOffset: endOffset + localJsRenderEndString.length,
|
|
2303
|
-
path:
|
|
2354
|
+
path: path19,
|
|
2304
2355
|
json
|
|
2305
2356
|
});
|
|
2306
2357
|
}
|
|
@@ -2320,7 +2371,7 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
2320
2371
|
};
|
|
2321
2372
|
var getHSProjectConfig = (hsProjectConfigPath) => {
|
|
2322
2373
|
try {
|
|
2323
|
-
return JSON.parse(
|
|
2374
|
+
return JSON.parse(fs4.readFileSync(hsProjectConfigPath, "utf8"));
|
|
2324
2375
|
} catch (e) {
|
|
2325
2376
|
console.warn(
|
|
2326
2377
|
`Missing hsproject.json file (${resolve2(hsProjectConfigPath)}): `,
|
|
@@ -2338,7 +2389,7 @@ var getProjectNameFromHSConfig = (hsProjectConfigPath) => {
|
|
|
2338
2389
|
};
|
|
2339
2390
|
|
|
2340
2391
|
// src/proxyPage/proxyPage.ts
|
|
2341
|
-
import
|
|
2392
|
+
import path7 from "path";
|
|
2342
2393
|
import { normalizePath as normalizePath3 } from "vite";
|
|
2343
2394
|
import { getConfigAccountIfExists as getConfigAccountIfExists3 } from "@hubspot/local-dev-lib/config";
|
|
2344
2395
|
import { http as hsCliHttp6 } from "@hubspot/local-dev-lib/http";
|
|
@@ -2679,9 +2730,9 @@ var customColors = [
|
|
|
2679
2730
|
];
|
|
2680
2731
|
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
2681
2732
|
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;`;
|
|
2682
|
-
var renderLocalError_default = (
|
|
2733
|
+
var renderLocalError_default = (path19, error) => {
|
|
2683
2734
|
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
2684
|
-
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${
|
|
2735
|
+
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path19}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
|
|
2685
2736
|
};
|
|
2686
2737
|
|
|
2687
2738
|
// src/proxyPage/fetchPreviewInfo.ts
|
|
@@ -2770,7 +2821,7 @@ function diffDeveloperFileHashes(accountId, token, fileHashes) {
|
|
|
2770
2821
|
// src/fileManager.ts
|
|
2771
2822
|
import { uploadFolder } from "@hubspot/local-dev-lib/cms/uploadFolder";
|
|
2772
2823
|
import chokidar from "chokidar";
|
|
2773
|
-
import
|
|
2824
|
+
import path5 from "path";
|
|
2774
2825
|
import { shouldIgnoreFile } from "@hubspot/local-dev-lib/ignoreRules";
|
|
2775
2826
|
import {
|
|
2776
2827
|
convertToUnixPath,
|
|
@@ -2802,7 +2853,7 @@ async function initialPreviewBufferUpload(accountId, src, dest, filePaths, uploa
|
|
|
2802
2853
|
{},
|
|
2803
2854
|
rest,
|
|
2804
2855
|
filePaths.map(
|
|
2805
|
-
(filePath) => filePath.replaceAll(
|
|
2856
|
+
(filePath) => filePath.replaceAll(path5.sep, path5.posix.sep)
|
|
2806
2857
|
)
|
|
2807
2858
|
);
|
|
2808
2859
|
onFinishCallback(results);
|
|
@@ -2867,7 +2918,7 @@ function buildUploadFileToPreviewBufferCallback(accountId, src, dest) {
|
|
|
2867
2918
|
console.debug(`Skipping ${filePath} due to an ignore rule`);
|
|
2868
2919
|
return;
|
|
2869
2920
|
}
|
|
2870
|
-
if (
|
|
2921
|
+
if (path5.dirname(filePath) === src && ["theme.json", "fields.json"].includes(path5.basename(filePath))) {
|
|
2871
2922
|
console.warn(`Editing of theme fields or meta is not yet supported.`);
|
|
2872
2923
|
return;
|
|
2873
2924
|
}
|
|
@@ -2883,7 +2934,7 @@ function buildDeleteFileFromPreviewBufferCallback(accountId, src, dest, type) {
|
|
|
2883
2934
|
}
|
|
2884
2935
|
if (type === "file") {
|
|
2885
2936
|
const moduleChild = isModuleFolderChild(filePath);
|
|
2886
|
-
const filename =
|
|
2937
|
+
const filename = path5.basename(filePath);
|
|
2887
2938
|
if (moduleChild && filename === "meta.json") {
|
|
2888
2939
|
return;
|
|
2889
2940
|
}
|
|
@@ -2897,7 +2948,7 @@ function getDesignManagerPath(src, dest, file) {
|
|
|
2897
2948
|
const normalizedFile = normalizePath2(file);
|
|
2898
2949
|
const regex = new RegExp(`^${escapeRegExp2(normalizedSrc)}`);
|
|
2899
2950
|
const relativePath = normalizedFile.replace(regex, "");
|
|
2900
|
-
return convertToUnixPath(
|
|
2951
|
+
return convertToUnixPath(path5.join(dest, relativePath));
|
|
2901
2952
|
}
|
|
2902
2953
|
async function uploadFile(accountId, src, dest) {
|
|
2903
2954
|
console.debug(`Attempting to upload file "${src}" to "${dest}"`);
|
|
@@ -2938,11 +2989,11 @@ function isModuleFolderChild(filePath) {
|
|
|
2938
2989
|
const pathParts = splitLocalPath(filePath);
|
|
2939
2990
|
if (pathParts.length <= 1)
|
|
2940
2991
|
return false;
|
|
2941
|
-
return pathParts.slice(0, pathParts.length - 1).some((part) => getExt(
|
|
2992
|
+
return pathParts.slice(0, pathParts.length - 1).some((part) => getExt(path5.normalize(part)) === MODULE_EXTENSION);
|
|
2942
2993
|
}
|
|
2943
2994
|
|
|
2944
2995
|
// src/lib/previewUtils.ts
|
|
2945
|
-
import
|
|
2996
|
+
import path6 from "path";
|
|
2946
2997
|
var removePreviewPrefix = (t2) => t2.split("/").slice(2).join("/");
|
|
2947
2998
|
var getPreviewUrl = (request, queryParams) => {
|
|
2948
2999
|
const { authedPortalId, authedEnv, authedHublet, sslEnabled } = request.app.locals;
|
|
@@ -3004,8 +3055,8 @@ function buildDevFileHashTable(src, dest, filePaths) {
|
|
|
3004
3055
|
return filePaths.reduce((acc, filePath) => {
|
|
3005
3056
|
const relativePath = relative(src, filePath);
|
|
3006
3057
|
const destPath = join3(dest, relativePath).replaceAll(
|
|
3007
|
-
|
|
3008
|
-
|
|
3058
|
+
path6.sep,
|
|
3059
|
+
path6.posix.sep
|
|
3009
3060
|
);
|
|
3010
3061
|
acc[`/${destPath}`] = getMd5Hash(filePath);
|
|
3011
3062
|
return acc;
|
|
@@ -3030,7 +3081,7 @@ async function initiatePreviewSession(authedPortalId, absoluteWebRoot, themePrev
|
|
|
3030
3081
|
const { dest, filePaths, startProgressBar } = themePreviewOptions2;
|
|
3031
3082
|
const absoluteDest = `@preview/${token}/${dest}`;
|
|
3032
3083
|
const nonJSRFilePaths = filePaths.filter(
|
|
3033
|
-
(filePath) => !filePath.startsWith(
|
|
3084
|
+
(filePath) => !filePath.startsWith(path6.join(absoluteWebRoot, "components"))
|
|
3034
3085
|
);
|
|
3035
3086
|
if (tokenStatus === "NEW") {
|
|
3036
3087
|
console.log("Uploading for a new session...");
|
|
@@ -3064,8 +3115,8 @@ async function initiatePreviewSession(authedPortalId, absoluteWebRoot, themePrev
|
|
|
3064
3115
|
/*, deletedFiles */
|
|
3065
3116
|
} = diffRes;
|
|
3066
3117
|
const filesToUpload = [...changedFiles, ...addedFiles].map((filePath) => {
|
|
3067
|
-
const relPath =
|
|
3068
|
-
return
|
|
3118
|
+
const relPath = path6.relative(absoluteDest, filePath.substring(1));
|
|
3119
|
+
return path6.join(absoluteWebRoot, relPath);
|
|
3069
3120
|
});
|
|
3070
3121
|
if (filesToUpload.length) {
|
|
3071
3122
|
const uploadOptions = startProgressBar(filesToUpload.length);
|
|
@@ -3203,7 +3254,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
|
|
|
3203
3254
|
);
|
|
3204
3255
|
}
|
|
3205
3256
|
const resolvedPath = normalizePath3(
|
|
3206
|
-
|
|
3257
|
+
path7.resolve(webRoot2, partialPath, componentFileName)
|
|
3207
3258
|
);
|
|
3208
3259
|
const entryPointPath = [
|
|
3209
3260
|
"@projects",
|
|
@@ -3478,8 +3529,51 @@ import { http as hsCliHttp7 } from "@hubspot/local-dev-lib/http";
|
|
|
3478
3529
|
import { getConfigAccountIfExists as getConfigAccountIfExists4 } from "@hubspot/local-dev-lib/config";
|
|
3479
3530
|
import { accessTokenForPersonalAccessKey } from "@hubspot/local-dev-lib/personalAccessKey";
|
|
3480
3531
|
import jsdom from "jsdom";
|
|
3532
|
+
var URL_SIGNING_GATE = "PortalsAccessIdentity:DesignManager:UrlSigning";
|
|
3533
|
+
async function signGetUrl(authedPortalId, unsignedUrl) {
|
|
3534
|
+
const urlWithPortalId = new URL(unsignedUrl);
|
|
3535
|
+
urlWithPortalId.searchParams.set("portalId", `${authedPortalId}`);
|
|
3536
|
+
const response = await hsCliHttp7.post(authedPortalId, {
|
|
3537
|
+
url: "/url-signer-rest/v1/signing",
|
|
3538
|
+
headers: {
|
|
3539
|
+
"Content-Type": "application/json",
|
|
3540
|
+
Accept: "application/json"
|
|
3541
|
+
},
|
|
3542
|
+
data: JSON.stringify({
|
|
3543
|
+
unsignedUrl: urlWithPortalId.toString(),
|
|
3544
|
+
httpMethod: "GET"
|
|
3545
|
+
})
|
|
3546
|
+
});
|
|
3547
|
+
return response.data.signedUrl;
|
|
3548
|
+
}
|
|
3549
|
+
async function signedGet(authedPortalId, unsignedUrl, headers, gates) {
|
|
3550
|
+
if (!isUngatedFor(gates, URL_SIGNING_GATE)) {
|
|
3551
|
+
const { data } = await hsCliHttp7.get(authedPortalId, {
|
|
3552
|
+
url: unsignedUrl,
|
|
3553
|
+
headers
|
|
3554
|
+
});
|
|
3555
|
+
return data;
|
|
3556
|
+
}
|
|
3557
|
+
const signedUrl = await signGetUrl(authedPortalId, unsignedUrl);
|
|
3558
|
+
const authHeaders = {};
|
|
3559
|
+
const accountConfig = getConfigAccountIfExists4(authedPortalId);
|
|
3560
|
+
if (accountConfig && accountConfig.authType === "personalaccesskey") {
|
|
3561
|
+
const accessToken = await accessTokenForPersonalAccessKey(authedPortalId);
|
|
3562
|
+
authHeaders["Authorization"] = `Bearer ${accessToken}`;
|
|
3563
|
+
}
|
|
3564
|
+
const response = await fetch(signedUrl, {
|
|
3565
|
+
method: "GET",
|
|
3566
|
+
headers: { ...headers, ...authHeaders }
|
|
3567
|
+
});
|
|
3568
|
+
if (!response.ok) {
|
|
3569
|
+
throw new Error(
|
|
3570
|
+
`Preview GET failed: ${response.status} ${response.statusText}`
|
|
3571
|
+
);
|
|
3572
|
+
}
|
|
3573
|
+
return await response.text();
|
|
3574
|
+
}
|
|
3481
3575
|
var { JSDOM } = jsdom;
|
|
3482
|
-
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue) {
|
|
3576
|
+
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue, gates) {
|
|
3483
3577
|
const moduleInfoQueryParams = new URLSearchParams({
|
|
3484
3578
|
portalId: `${authedPortalId}`
|
|
3485
3579
|
});
|
|
@@ -3494,8 +3588,6 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
|
|
|
3494
3588
|
"User-Agent": "HubSpot CMS Dev Server"
|
|
3495
3589
|
}
|
|
3496
3590
|
})).data;
|
|
3497
|
-
const currentHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
3498
|
-
process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot`;
|
|
3499
3591
|
const queryParams = new URLSearchParams({
|
|
3500
3592
|
portalId: `${authedPortalId}`,
|
|
3501
3593
|
hsLocalProxy: `${true}`,
|
|
@@ -3503,20 +3595,34 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
|
|
|
3503
3595
|
hsLoginVerifyDisabled: `${true}`,
|
|
3504
3596
|
module_id: moduleInfo.moduleId
|
|
3505
3597
|
});
|
|
3506
|
-
const
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3598
|
+
const cosRenderingUrl = `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}.com/api/cos-rendering/v1/public/_hcms/preview/template/multi?${queryParams}`;
|
|
3599
|
+
const previousHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
3600
|
+
const needsDomainOverride = !isUngatedFor(gates, URL_SIGNING_GATE);
|
|
3601
|
+
if (needsDomainOverride) {
|
|
3602
|
+
process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot`;
|
|
3603
|
+
}
|
|
3604
|
+
let modulePreviewHtml;
|
|
3605
|
+
try {
|
|
3606
|
+
modulePreviewHtml = await signedGet(
|
|
3607
|
+
authedPortalId,
|
|
3608
|
+
cosRenderingUrl,
|
|
3609
|
+
{
|
|
3610
|
+
["content-type"]: "application/x-www-form-urlencoded",
|
|
3611
|
+
["Accept"]: "text/html",
|
|
3612
|
+
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
3613
|
+
cookie: cookieValue,
|
|
3614
|
+
"User-Agent": "HubSpot CMS Dev Server"
|
|
3615
|
+
},
|
|
3616
|
+
gates
|
|
3617
|
+
);
|
|
3618
|
+
} finally {
|
|
3619
|
+
if (needsDomainOverride) {
|
|
3620
|
+
if (previousHubApiDomainOverride) {
|
|
3621
|
+
process.env.HUBAPI_DOMAIN_OVERRIDE = previousHubApiDomainOverride;
|
|
3622
|
+
} else {
|
|
3623
|
+
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
3624
|
+
}
|
|
3514
3625
|
}
|
|
3515
|
-
})).data;
|
|
3516
|
-
if (currentHubApiDomainOverride) {
|
|
3517
|
-
process.env.HUBAPI_DOMAIN_OVERRIDE = currentHubApiDomainOverride;
|
|
3518
|
-
} else {
|
|
3519
|
-
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
3520
3626
|
}
|
|
3521
3627
|
const dom = new JSDOM(modulePreviewHtml);
|
|
3522
3628
|
const modulePreviewContent = dom.window.document.querySelector(
|
|
@@ -3551,7 +3657,7 @@ async function signUrl(authedPortalId, unsignedUrl, requestBody) {
|
|
|
3551
3657
|
}
|
|
3552
3658
|
async function renderLocalProjectModulePreview(moduleName, authedPortalId, authedEnv, authedHublet, webRoot2, viteServer, jsRenderingGates, projectName, projectComponentPath, fullOriginalUrl, cookieValue, fieldOverrides = {}) {
|
|
3553
3659
|
const modulePath = normalizePath4(
|
|
3554
|
-
|
|
3660
|
+
path8.resolve(webRoot2, "components/modules/", moduleName)
|
|
3555
3661
|
);
|
|
3556
3662
|
const basePath = `preview/${getEntryPointBasePath(modulePath)}`;
|
|
3557
3663
|
const environmentConfig = buildStaticEnvConfig2(
|
|
@@ -3688,7 +3794,7 @@ var partialRouteHandler = async (request, response) => {
|
|
|
3688
3794
|
"html/baseTemplate.html"
|
|
3689
3795
|
);
|
|
3690
3796
|
const partialPath = normalizePath5(
|
|
3691
|
-
|
|
3797
|
+
path9.resolve(webRoot2, "components/partials/", partialName)
|
|
3692
3798
|
);
|
|
3693
3799
|
const entrypointPath = normalizePath5(
|
|
3694
3800
|
[
|
|
@@ -3759,7 +3865,8 @@ var partialRouteHandler = async (request, response) => {
|
|
|
3759
3865
|
remoteModule.path,
|
|
3760
3866
|
authedPortalId,
|
|
3761
3867
|
authedEnv,
|
|
3762
|
-
request.get("COOKIE")
|
|
3868
|
+
request.get("COOKIE"),
|
|
3869
|
+
jsRenderingGates
|
|
3763
3870
|
).then((result) => ({
|
|
3764
3871
|
remoteModule,
|
|
3765
3872
|
result
|
|
@@ -3774,7 +3881,7 @@ var partialRouteHandler = async (request, response) => {
|
|
|
3774
3881
|
continue;
|
|
3775
3882
|
localProjectModulePreviewPromises.push(
|
|
3776
3883
|
renderLocalProjectModulePreview(
|
|
3777
|
-
|
|
3884
|
+
path9.basename(localProjectModule.path),
|
|
3778
3885
|
authedPortalId,
|
|
3779
3886
|
authedEnv,
|
|
3780
3887
|
authedHublet,
|
|
@@ -3912,7 +4019,7 @@ var linksToAllModulesRouteHandler_default = linksToAllModuleRouteHandler;
|
|
|
3912
4019
|
|
|
3913
4020
|
// src/routes/module.ts
|
|
3914
4021
|
import { buildStaticEnvConfig as buildStaticEnvConfig4 } from "@hubspot/cms-components";
|
|
3915
|
-
import
|
|
4022
|
+
import path10 from "path";
|
|
3916
4023
|
import { normalizePath as normalizePath6 } from "vite";
|
|
3917
4024
|
var moduleRouteHandler = async (request, response) => {
|
|
3918
4025
|
sendTrackingRequest("view-module-route");
|
|
@@ -3932,7 +4039,7 @@ var moduleRouteHandler = async (request, response) => {
|
|
|
3932
4039
|
"html/baseTemplate.html"
|
|
3933
4040
|
);
|
|
3934
4041
|
const modulePath = normalizePath6(
|
|
3935
|
-
|
|
4042
|
+
path10.resolve(webRoot2, "components/modules/", moduleName)
|
|
3936
4043
|
);
|
|
3937
4044
|
const entrypointPath = normalizePath6(
|
|
3938
4045
|
[
|
|
@@ -4013,7 +4120,7 @@ ${e.stack}`);
|
|
|
4013
4120
|
var module_default = moduleRouteHandler;
|
|
4014
4121
|
|
|
4015
4122
|
// src/routes/moduleFieldsJson.ts
|
|
4016
|
-
import
|
|
4123
|
+
import path11 from "path";
|
|
4017
4124
|
import { normalizePath as normalizePath7 } from "vite";
|
|
4018
4125
|
|
|
4019
4126
|
// src/lib/renderModuleFieldsJson.ts
|
|
@@ -4067,7 +4174,7 @@ var moduleFieldsJsonRouteHandler = async (request, response) => {
|
|
|
4067
4174
|
const { webRoot: webRoot2, viteServer } = request.app.locals;
|
|
4068
4175
|
const { moduleName } = request.params;
|
|
4069
4176
|
const modulePath = normalizePath7(
|
|
4070
|
-
|
|
4177
|
+
path11.resolve(webRoot2, "components/modules/", moduleName)
|
|
4071
4178
|
);
|
|
4072
4179
|
const fieldsJson = await renderModuleFieldsJson_default(viteServer, modulePath);
|
|
4073
4180
|
return response.status(200).set({ "Content-Type": "application/json" }).json(fieldsJson);
|
|
@@ -4293,18 +4400,18 @@ async function fetchPreviewTemplates(accountId, previewToken, limit = 250) {
|
|
|
4293
4400
|
url: `${DESIGN_MANAGER_API_PATH}/templates/local-preview?previewToken=${previewToken}&limit=${limit}`
|
|
4294
4401
|
})).data;
|
|
4295
4402
|
}
|
|
4296
|
-
async function fetchModuleByPath(accountId,
|
|
4403
|
+
async function fetchModuleByPath(accountId, path19) {
|
|
4297
4404
|
return (await hsCliHttp8.get(accountId, {
|
|
4298
|
-
url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${
|
|
4405
|
+
url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${path19}?portalId=${accountId}`
|
|
4299
4406
|
})).data;
|
|
4300
4407
|
}
|
|
4301
|
-
async function fetchTemplateByPath(accountId,
|
|
4408
|
+
async function fetchTemplateByPath(accountId, path19) {
|
|
4302
4409
|
return (await hsCliHttp8.get(accountId, {
|
|
4303
|
-
url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${
|
|
4410
|
+
url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${path19}?portalId=${accountId}`
|
|
4304
4411
|
})).data;
|
|
4305
4412
|
}
|
|
4306
|
-
async function fetchModulePageDependencies(accountId,
|
|
4307
|
-
const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${
|
|
4413
|
+
async function fetchModulePageDependencies(accountId, path19) {
|
|
4414
|
+
const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${path19}`;
|
|
4308
4415
|
return (await hsCliHttp8.get(accountId, { url: url3 })).data;
|
|
4309
4416
|
}
|
|
4310
4417
|
|
|
@@ -4540,7 +4647,7 @@ function proxyServerlessRequest(req, res, next) {
|
|
|
4540
4647
|
}
|
|
4541
4648
|
|
|
4542
4649
|
// src/routes/modulePreviewRouteHandler.ts
|
|
4543
|
-
import
|
|
4650
|
+
import path12 from "path";
|
|
4544
4651
|
import { normalizePath as normalizePath8 } from "vite";
|
|
4545
4652
|
async function modulePreviewRouteHandler(request, response) {
|
|
4546
4653
|
sendTrackingRequest("view-module-preview-route");
|
|
@@ -4556,7 +4663,7 @@ async function modulePreviewRouteHandler(request, response) {
|
|
|
4556
4663
|
} = request.app.locals;
|
|
4557
4664
|
const moduleName = request.params.moduleName;
|
|
4558
4665
|
const modulePath = normalizePath8(
|
|
4559
|
-
|
|
4666
|
+
path12.resolve(webRoot2, "components/modules/", moduleName)
|
|
4560
4667
|
);
|
|
4561
4668
|
const PREVIEWER_APP_PARAM = "hsPreviewerApp";
|
|
4562
4669
|
let fieldOverrides = {};
|
|
@@ -4646,21 +4753,27 @@ ${e.stack}`);
|
|
|
4646
4753
|
var modulePreviewRouteHandler_default = modulePreviewRouteHandler;
|
|
4647
4754
|
|
|
4648
4755
|
// src/routes/hublModuleRouteHandler.ts
|
|
4649
|
-
import { http as hsCliHttp9 } from "@hubspot/local-dev-lib/http";
|
|
4650
4756
|
var hublModuleRouteHandler = async (request, response) => {
|
|
4651
4757
|
sendTrackingRequest("view-hubl-module-route");
|
|
4652
|
-
const { authedPortalId, localPreviewToken } = request.app.locals;
|
|
4758
|
+
const { authedPortalId, localPreviewToken, projectName, jsRenderingGates } = request.app.locals;
|
|
4653
4759
|
const { modulePath } = request.params;
|
|
4654
4760
|
if (!modulePath) {
|
|
4655
4761
|
response.status(200).set({ "Content-Type": "text/html" }).end(buildModuleIndex());
|
|
4656
4762
|
return;
|
|
4657
4763
|
}
|
|
4658
|
-
const
|
|
4764
|
+
const projectPrefix = projectName ? "@projects/" : "";
|
|
4765
|
+
const calculatedPath = `@preview/${localPreviewToken}/${projectPrefix}${modulePath}.module`;
|
|
4659
4766
|
let customWidgetInfo;
|
|
4660
4767
|
try {
|
|
4661
4768
|
customWidgetInfo = await fetchModuleByPath(authedPortalId, calculatedPath);
|
|
4662
4769
|
} catch (err) {
|
|
4663
|
-
console.
|
|
4770
|
+
console.error(`Failed to fetch module data for ${calculatedPath}: ${err}`);
|
|
4771
|
+
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex(err));
|
|
4772
|
+
return;
|
|
4773
|
+
}
|
|
4774
|
+
if (!customWidgetInfo || !("moduleId" in customWidgetInfo)) {
|
|
4775
|
+
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex(null));
|
|
4776
|
+
return;
|
|
4664
4777
|
}
|
|
4665
4778
|
const params = {
|
|
4666
4779
|
module_id: customWidgetInfo.moduleId,
|
|
@@ -4668,13 +4781,9 @@ var hublModuleRouteHandler = async (request, response) => {
|
|
|
4668
4781
|
updated: Date.now(),
|
|
4669
4782
|
...request.query
|
|
4670
4783
|
};
|
|
4671
|
-
const previewUrl =
|
|
4784
|
+
const previewUrl = getPreviewUrl(request, params);
|
|
4672
4785
|
try {
|
|
4673
|
-
const result =
|
|
4674
|
-
baseURL: previewUrl.origin,
|
|
4675
|
-
url: previewUrl.pathname,
|
|
4676
|
-
params
|
|
4677
|
-
})).data;
|
|
4786
|
+
const result = await signedGet(authedPortalId, previewUrl, {}, jsRenderingGates);
|
|
4678
4787
|
const html = addRefreshScript(result);
|
|
4679
4788
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
4680
4789
|
} catch (err) {
|
|
@@ -4696,7 +4805,6 @@ var buildModuleIndex = () => buildHTMLResponse(`
|
|
|
4696
4805
|
`);
|
|
4697
4806
|
|
|
4698
4807
|
// src/routes/hublTemplateRouteHandler.ts
|
|
4699
|
-
import { http as hsCliHttp10 } from "@hubspot/local-dev-lib/http";
|
|
4700
4808
|
import { buildStaticEnvConfig as buildStaticEnvConfig5 } from "@hubspot/cms-components";
|
|
4701
4809
|
import { getConfigAccountEnvironment } from "@hubspot/local-dev-lib/config";
|
|
4702
4810
|
var HUBSPOT_PREVIEW_BASE_TAG_REGEX = /<base\s+[^>]*href=["'][^"']*(?:hubspotpreview(?:qa)?)[^"']*["'][^>]*>/i;
|
|
@@ -4747,14 +4855,15 @@ var templateRouteHandler = async (request, response) => {
|
|
|
4747
4855
|
hsCacheBuster: Date.now().toString(),
|
|
4748
4856
|
...request.query
|
|
4749
4857
|
};
|
|
4750
|
-
const previewUrl =
|
|
4858
|
+
const previewUrl = getPreviewUrl(request, params);
|
|
4751
4859
|
const fullOriginalUrl = `${request.protocol}://${request.get("host")}${request.originalUrl}`;
|
|
4752
4860
|
try {
|
|
4753
|
-
const result =
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4861
|
+
const result = await signedGet(
|
|
4862
|
+
authedPortalId,
|
|
4863
|
+
previewUrl,
|
|
4864
|
+
{},
|
|
4865
|
+
jsRenderingGates
|
|
4866
|
+
);
|
|
4758
4867
|
const pageHtml = addRefreshScript(result);
|
|
4759
4868
|
const finalHtml = pageHtml.replace(
|
|
4760
4869
|
HUBSPOT_PREVIEW_BASE_TAG_REGEX,
|
|
@@ -4773,6 +4882,7 @@ var templateRouteHandler = async (request, response) => {
|
|
|
4773
4882
|
false
|
|
4774
4883
|
);
|
|
4775
4884
|
} catch (err) {
|
|
4885
|
+
console.error("Template route error:", err);
|
|
4776
4886
|
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex2());
|
|
4777
4887
|
}
|
|
4778
4888
|
};
|
|
@@ -4807,15 +4917,15 @@ function getOpenCommand() {
|
|
|
4807
4917
|
}
|
|
4808
4918
|
}
|
|
4809
4919
|
async function handleGetModulePages(req, res, next) {
|
|
4810
|
-
const { path:
|
|
4811
|
-
if (!
|
|
4920
|
+
const { path: path19, portalId } = req.query;
|
|
4921
|
+
if (!path19 || !portalId) {
|
|
4812
4922
|
return res.status(400).json({ error: "Missing required parameters" });
|
|
4813
4923
|
}
|
|
4814
4924
|
try {
|
|
4815
4925
|
sendTrackingRequest("handle-module-dependencies");
|
|
4816
4926
|
const data = await fetchModulePageDependencies(
|
|
4817
4927
|
Number(portalId),
|
|
4818
|
-
|
|
4928
|
+
path19
|
|
4819
4929
|
);
|
|
4820
4930
|
res.json(data);
|
|
4821
4931
|
} catch (err) {
|
|
@@ -4823,14 +4933,14 @@ async function handleGetModulePages(req, res, next) {
|
|
|
4823
4933
|
}
|
|
4824
4934
|
}
|
|
4825
4935
|
function handleOpenFile(req, res, next) {
|
|
4826
|
-
const { path:
|
|
4827
|
-
if (!
|
|
4936
|
+
const { path: path19 } = req.query;
|
|
4937
|
+
if (!path19) {
|
|
4828
4938
|
return res.status(400).json({ error: "Missing required parameters" });
|
|
4829
4939
|
}
|
|
4830
4940
|
try {
|
|
4831
4941
|
sendTrackingRequest("handle-open-file");
|
|
4832
4942
|
const command = getOpenCommand();
|
|
4833
|
-
spawn(command, [
|
|
4943
|
+
spawn(command, [path19], { detached: true }).unref();
|
|
4834
4944
|
res.sendStatus(200);
|
|
4835
4945
|
} catch (err) {
|
|
4836
4946
|
next(err);
|
|
@@ -4845,19 +4955,19 @@ function createAppServerAPIRoutes() {
|
|
|
4845
4955
|
var createAppServerAPIRoutes_default = createAppServerAPIRoutes;
|
|
4846
4956
|
|
|
4847
4957
|
// src/routes/appServerRouteHandler.ts
|
|
4848
|
-
import
|
|
4849
|
-
import
|
|
4958
|
+
import fs6 from "node:fs/promises";
|
|
4959
|
+
import path14 from "path";
|
|
4850
4960
|
import { pathToFileURL } from "url";
|
|
4851
4961
|
|
|
4852
4962
|
// src/lib/getDevServerUIData.ts
|
|
4853
|
-
import
|
|
4963
|
+
import path13 from "path";
|
|
4854
4964
|
import { normalizePath as normalizePath9 } from "vite";
|
|
4855
4965
|
|
|
4856
4966
|
// src/api/project.ts
|
|
4857
|
-
import { http as
|
|
4967
|
+
import { http as hsCliHttp9 } from "@hubspot/local-dev-lib/http";
|
|
4858
4968
|
var DEVELOPER_PROJECTS_API_PATH = "/developer/projects/v1";
|
|
4859
4969
|
async function fetchProjectByName(accountId, projectName) {
|
|
4860
|
-
return (await
|
|
4970
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4861
4971
|
url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${projectName}`
|
|
4862
4972
|
})).data;
|
|
4863
4973
|
}
|
|
@@ -5043,7 +5153,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
5043
5153
|
}),
|
|
5044
5154
|
clientIslandEntryPlugin(),
|
|
5045
5155
|
resolveIslandPlugin(),
|
|
5046
|
-
|
|
5156
|
+
viteCommonjs(),
|
|
5047
5157
|
devSecretsPlugin(secretNames),
|
|
5048
5158
|
noncePlaceholderPlugin()
|
|
5049
5159
|
] : [];
|
|
@@ -5080,7 +5190,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
5080
5190
|
var createViteDevServer_default = createViteDevServer;
|
|
5081
5191
|
|
|
5082
5192
|
// src/lib/getDevServerUIData.ts
|
|
5083
|
-
import
|
|
5193
|
+
import fs5 from "node:fs";
|
|
5084
5194
|
var templateTypeMap = {
|
|
5085
5195
|
// Standard templates
|
|
5086
5196
|
4: "Page",
|
|
@@ -5106,7 +5216,7 @@ function mapReactModules(modules, themeWebRoot, appViteServer) {
|
|
|
5106
5216
|
return Promise.all(
|
|
5107
5217
|
modules.moduleNames.map(async (name, index) => {
|
|
5108
5218
|
const modulePath = normalizePath9(
|
|
5109
|
-
|
|
5219
|
+
path13.resolve(themeWebRoot, "components/modules/", name)
|
|
5110
5220
|
);
|
|
5111
5221
|
const fieldsJson = await renderModuleFieldsJson_default(
|
|
5112
5222
|
appViteServer,
|
|
@@ -5152,9 +5262,9 @@ function normalizeTemplatesData(templates, projectName) {
|
|
|
5152
5262
|
});
|
|
5153
5263
|
}
|
|
5154
5264
|
function detectPackageManager(projectRoot) {
|
|
5155
|
-
if (
|
|
5265
|
+
if (fs5.existsSync(path13.join(projectRoot, "yarn.lock")))
|
|
5156
5266
|
return "yarn";
|
|
5157
|
-
if (
|
|
5267
|
+
if (fs5.existsSync(path13.join(projectRoot, "pnpm-lock.yaml")))
|
|
5158
5268
|
return "pnpm";
|
|
5159
5269
|
return "npm";
|
|
5160
5270
|
}
|
|
@@ -5238,10 +5348,10 @@ var appServerRouteHandler = async (req, res, __next) => {
|
|
|
5238
5348
|
const { appWebRoot, appViteServer } = appLocals;
|
|
5239
5349
|
const initialProps = await getDevServerUIData(appLocals);
|
|
5240
5350
|
const url3 = req.originalUrl.replace("/", "");
|
|
5241
|
-
const templatePath =
|
|
5242
|
-
const serverEntryPath = isProd ?
|
|
5351
|
+
const templatePath = path14.join(appWebRoot, "index.html");
|
|
5352
|
+
const serverEntryPath = isProd ? path14.join(appWebRoot, "server/serverEntry.js") : path14.join(appWebRoot, "serverEntry.tsx");
|
|
5243
5353
|
let render;
|
|
5244
|
-
let template = await
|
|
5354
|
+
let template = await fs6.readFile(path14.join(templatePath), "utf-8");
|
|
5245
5355
|
if (isProd) {
|
|
5246
5356
|
const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
|
|
5247
5357
|
render = ssrRender;
|
|
@@ -5267,7 +5377,7 @@ var appServerRouteHandler = async (req, res, __next) => {
|
|
|
5267
5377
|
var appServerRouteHandler_default = appServerRouteHandler;
|
|
5268
5378
|
|
|
5269
5379
|
// src/routes/createDevServerRoutes.ts
|
|
5270
|
-
import
|
|
5380
|
+
import path15 from "path";
|
|
5271
5381
|
var isProd2 = true;
|
|
5272
5382
|
var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
|
|
5273
5383
|
(domain2) => `storybook.${domain2}`
|
|
@@ -5293,7 +5403,7 @@ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
|
|
|
5293
5403
|
}
|
|
5294
5404
|
devServerApp.use(urlencoded());
|
|
5295
5405
|
if (isProd2) {
|
|
5296
|
-
const distAssetsPath =
|
|
5406
|
+
const distAssetsPath = path15.join(appWebRoot, "assets");
|
|
5297
5407
|
devServerApp.use("/assets", expressStatic(distAssetsPath));
|
|
5298
5408
|
} else {
|
|
5299
5409
|
devServerApp.use("/local", appViteServer.middlewares);
|
|
@@ -5578,7 +5688,7 @@ import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
|
|
|
5578
5688
|
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from "@hubspot/local-dev-lib/constants/auth";
|
|
5579
5689
|
|
|
5580
5690
|
// src/proxyPage/fetchDomains.ts
|
|
5581
|
-
import { http as
|
|
5691
|
+
import { http as hsCliHttp10 } from "@hubspot/local-dev-lib/http";
|
|
5582
5692
|
|
|
5583
5693
|
// src/lib/errors.ts
|
|
5584
5694
|
var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
|
|
@@ -5636,7 +5746,7 @@ function handleSecretsError(error) {
|
|
|
5636
5746
|
// src/proxyPage/fetchDomains.ts
|
|
5637
5747
|
async function fetchDomains(portalId) {
|
|
5638
5748
|
try {
|
|
5639
|
-
const result = (await
|
|
5749
|
+
const result = (await hsCliHttp10.get(portalId, {
|
|
5640
5750
|
url: `/cms/v3/domains`,
|
|
5641
5751
|
params: { portalId },
|
|
5642
5752
|
responseType: "json"
|
|
@@ -5659,24 +5769,24 @@ async function fetchWebsiteDomainNames(portalId) {
|
|
|
5659
5769
|
}
|
|
5660
5770
|
|
|
5661
5771
|
// src/lib/validateHSPlatform.ts
|
|
5662
|
-
import
|
|
5663
|
-
import
|
|
5772
|
+
import path16 from "path";
|
|
5773
|
+
import fs7 from "fs";
|
|
5664
5774
|
import select from "@inquirer/select";
|
|
5665
|
-
import { http as
|
|
5775
|
+
import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
|
|
5666
5776
|
var HSPROJECT_JSON = "hsproject.json";
|
|
5667
5777
|
function checkFileExists(filePath) {
|
|
5668
|
-
return
|
|
5778
|
+
return fs7.existsSync(filePath) && fs7.statSync(filePath).isFile();
|
|
5669
5779
|
}
|
|
5670
5780
|
function findHSProjectJson(startPath) {
|
|
5671
5781
|
let currentDir = startPath;
|
|
5672
5782
|
let dirLevel = 0;
|
|
5673
5783
|
const maxDirLevel = 4;
|
|
5674
|
-
while (
|
|
5675
|
-
const filePath =
|
|
5784
|
+
while (path16.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
|
|
5785
|
+
const filePath = path16.join(currentDir, HSPROJECT_JSON);
|
|
5676
5786
|
if (checkFileExists(filePath)) {
|
|
5677
5787
|
return filePath;
|
|
5678
5788
|
}
|
|
5679
|
-
currentDir =
|
|
5789
|
+
currentDir = path16.dirname(currentDir);
|
|
5680
5790
|
dirLevel++;
|
|
5681
5791
|
}
|
|
5682
5792
|
console.log(
|
|
@@ -5691,12 +5801,12 @@ async function validateHSPlatform(projectConfigPath, portalId) {
|
|
|
5691
5801
|
);
|
|
5692
5802
|
return false;
|
|
5693
5803
|
}
|
|
5694
|
-
const hsProjectJSONContents =
|
|
5804
|
+
const hsProjectJSONContents = fs7.readFileSync(projectConfigPath, "utf8");
|
|
5695
5805
|
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
5696
5806
|
const { platformVersion } = hsProjectJSONData;
|
|
5697
5807
|
let platformVersionResult;
|
|
5698
5808
|
try {
|
|
5699
|
-
platformVersionResult = (await
|
|
5809
|
+
platformVersionResult = (await hsCliHttp11.get(portalId, {
|
|
5700
5810
|
url: `developer/projects/v1/platformVersion`,
|
|
5701
5811
|
responseType: "json"
|
|
5702
5812
|
})).data;
|
|
@@ -5719,7 +5829,7 @@ async function validateHSPlatform(projectConfigPath, portalId) {
|
|
|
5719
5829
|
});
|
|
5720
5830
|
hsProjectJSONData.platformVersion = answer;
|
|
5721
5831
|
try {
|
|
5722
|
-
|
|
5832
|
+
fs7.writeFileSync(
|
|
5723
5833
|
projectConfigPath,
|
|
5724
5834
|
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
5725
5835
|
"utf8"
|
|
@@ -5736,7 +5846,7 @@ async function validateHSPlatform(projectConfigPath, portalId) {
|
|
|
5736
5846
|
}
|
|
5737
5847
|
|
|
5738
5848
|
// src/createDevServer.ts
|
|
5739
|
-
import { http as
|
|
5849
|
+
import { http as hsCliHttp12 } from "@hubspot/local-dev-lib/http";
|
|
5740
5850
|
|
|
5741
5851
|
// ../cms-js-internal/dist/buildFieldsTypes.js
|
|
5742
5852
|
import { writeFileSync } from "fs";
|
|
@@ -5981,8 +6091,8 @@ function writeFieldsType(fields, fileName, typeName) {
|
|
|
5981
6091
|
}
|
|
5982
6092
|
|
|
5983
6093
|
// src/lib/watchFieldsUpdates.ts
|
|
5984
|
-
import
|
|
5985
|
-
import
|
|
6094
|
+
import fs8 from "fs";
|
|
6095
|
+
import path17 from "path";
|
|
5986
6096
|
import readline from "readline";
|
|
5987
6097
|
var lastSerializedFieldsCache = {};
|
|
5988
6098
|
var formatAsTypeName = (str) => {
|
|
@@ -5992,20 +6102,20 @@ var formatAsTypeName = (str) => {
|
|
|
5992
6102
|
};
|
|
5993
6103
|
var isInModulesFolder = (filePath, projectRoot) => {
|
|
5994
6104
|
const getEntryPathFromId = (id) => {
|
|
5995
|
-
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}${
|
|
6105
|
+
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}${path17.sep}`, "") : "";
|
|
5996
6106
|
};
|
|
5997
|
-
const currentModuleId =
|
|
6107
|
+
const currentModuleId = path17.normalize(filePath);
|
|
5998
6108
|
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
5999
|
-
const subFolderTokens = moduleEntryPath.split(
|
|
6109
|
+
const subFolderTokens = moduleEntryPath.split(path17.sep);
|
|
6000
6110
|
return {
|
|
6001
6111
|
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
6002
6112
|
isRootModuleFile: subFolderTokens.length === 3
|
|
6003
6113
|
};
|
|
6004
6114
|
};
|
|
6005
6115
|
var fileContainsAutoGenComment = async (filePath) => {
|
|
6006
|
-
if (!
|
|
6116
|
+
if (!fs8.existsSync(filePath))
|
|
6007
6117
|
return true;
|
|
6008
|
-
const stream2 =
|
|
6118
|
+
const stream2 = fs8.createReadStream(filePath);
|
|
6009
6119
|
const reader = readline.createInterface({ input: stream2 });
|
|
6010
6120
|
const firstLine = await new Promise(
|
|
6011
6121
|
(resolve3) => reader.once("line", (line) => resolve3(line.trim()))
|
|
@@ -6023,10 +6133,10 @@ var getIndexFile = (filePath, projectRoot) => {
|
|
|
6023
6133
|
return void 0;
|
|
6024
6134
|
if (isRootModuleFile)
|
|
6025
6135
|
return { indexFilePath: filePath, isRootModuleFile };
|
|
6026
|
-
const dir =
|
|
6027
|
-
const files =
|
|
6136
|
+
const dir = path17.dirname(filePath);
|
|
6137
|
+
const files = fs8.readdirSync(dir);
|
|
6028
6138
|
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
6029
|
-
return indexFileName ? { indexFilePath:
|
|
6139
|
+
return indexFileName ? { indexFilePath: path17.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
6030
6140
|
};
|
|
6031
6141
|
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
6032
6142
|
let indexFile;
|
|
@@ -6050,7 +6160,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
6050
6160
|
if (!indexInfo)
|
|
6051
6161
|
return;
|
|
6052
6162
|
const { indexFilePath, isRootModuleFile } = indexInfo;
|
|
6053
|
-
const indexFileName =
|
|
6163
|
+
const indexFileName = path17.parse(indexFilePath).name;
|
|
6054
6164
|
const isTypeFile = filePath.endsWith(".types.ts");
|
|
6055
6165
|
if (isTypeFile)
|
|
6056
6166
|
return;
|
|
@@ -6061,7 +6171,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
6061
6171
|
);
|
|
6062
6172
|
if (fields) {
|
|
6063
6173
|
const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
|
|
6064
|
-
const typeFilePath =
|
|
6174
|
+
const typeFilePath = path17.join(path17.dirname(filePath), typeFileName);
|
|
6065
6175
|
const lastSerializedFields = lastSerializedFieldsCache[typeFilePath];
|
|
6066
6176
|
const serializedFields = JSON.stringify(fields);
|
|
6067
6177
|
if (lastSerializedFields === serializedFields)
|
|
@@ -6069,7 +6179,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
6069
6179
|
const hasAutoGenComment = await fileContainsAutoGenComment(typeFilePath);
|
|
6070
6180
|
if (!hasAutoGenComment)
|
|
6071
6181
|
return;
|
|
6072
|
-
const moduleFolderName =
|
|
6182
|
+
const moduleFolderName = path17.basename(path17.dirname(filePath));
|
|
6073
6183
|
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
6074
6184
|
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
6075
6185
|
if (didSucceed) {
|
|
@@ -6085,7 +6195,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
6085
6195
|
var startFieldsTypeGenWatcher = (viteServer, projectRoot) => {
|
|
6086
6196
|
const { moduleSubpaths } = findAllModulesInRoot(projectRoot);
|
|
6087
6197
|
moduleSubpaths.forEach((modulePath) => {
|
|
6088
|
-
const resolvedPath =
|
|
6198
|
+
const resolvedPath = path17.resolve(projectRoot, modulePath);
|
|
6089
6199
|
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
6090
6200
|
});
|
|
6091
6201
|
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
@@ -6116,27 +6226,13 @@ function getWebRootProjectComponentFolder(absoluteWebRoot, projectConfigPath) {
|
|
|
6116
6226
|
return themeFolderName;
|
|
6117
6227
|
}
|
|
6118
6228
|
try {
|
|
6119
|
-
const projectDir =
|
|
6120
|
-
const configContent =
|
|
6229
|
+
const projectDir = path18.dirname(projectConfigPath);
|
|
6230
|
+
const configContent = fs9.readFileSync(projectConfigPath, "utf8");
|
|
6121
6231
|
const projectConfig = JSON.parse(configContent);
|
|
6122
|
-
|
|
6123
|
-
projectConfig.platformVersion
|
|
6124
|
-
);
|
|
6125
|
-
if (isNewStructure) {
|
|
6232
|
+
if (hasNewDirectoryStructure(projectConfig.platformVersion)) {
|
|
6126
6233
|
const srcDir = projectConfig.srcDir || "src";
|
|
6127
|
-
const
|
|
6128
|
-
|
|
6129
|
-
srcDir,
|
|
6130
|
-
"theme",
|
|
6131
|
-
"theme-hsmeta.json"
|
|
6132
|
-
);
|
|
6133
|
-
if (fs8.existsSync(hsmetaPath)) {
|
|
6134
|
-
const hsmetaContent = fs8.readFileSync(hsmetaPath, "utf8");
|
|
6135
|
-
const hsmeta = JSON.parse(hsmetaContent);
|
|
6136
|
-
if (hsmeta.uid) {
|
|
6137
|
-
return hsmeta.uid;
|
|
6138
|
-
}
|
|
6139
|
-
}
|
|
6234
|
+
const uid = findHsmetaUid(projectDir, srcDir);
|
|
6235
|
+
return uid ?? projectConfig.name;
|
|
6140
6236
|
}
|
|
6141
6237
|
} catch (e) {
|
|
6142
6238
|
console.warn(
|
|
@@ -6169,7 +6265,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
|
|
|
6169
6265
|
`Loading HS auth (account = ${hubspotCliAccountNameOption2}) configuration.`
|
|
6170
6266
|
);
|
|
6171
6267
|
}
|
|
6172
|
-
const cmsAssetConfig =
|
|
6268
|
+
const cmsAssetConfig = getCMSAssetConfigIfExists(webRoot2);
|
|
6173
6269
|
secretNamesFromConfig = getSecretNamesFromConfig(cmsAssetConfig);
|
|
6174
6270
|
const { isValid } = validateConfig();
|
|
6175
6271
|
if (isValid) {
|
|
@@ -6257,14 +6353,14 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6257
6353
|
}
|
|
6258
6354
|
let authedHublet;
|
|
6259
6355
|
try {
|
|
6260
|
-
const accountInformation = (await
|
|
6356
|
+
const accountInformation = (await hsCliHttp12.get(authedPortalId, {
|
|
6261
6357
|
url: "/account-info/v3/details"
|
|
6262
6358
|
})).data;
|
|
6263
6359
|
authedHublet = accountInformation.dataHostingLocation;
|
|
6264
6360
|
} catch (e) {
|
|
6265
6361
|
authedHublet = "na1";
|
|
6266
6362
|
}
|
|
6267
|
-
const absoluteWebRoot = normalizePath10(
|
|
6363
|
+
const absoluteWebRoot = normalizePath10(path18.resolve(process.cwd(), webRoot2));
|
|
6268
6364
|
const projectConfigPath = findHSProjectJson(absoluteWebRoot);
|
|
6269
6365
|
const webRootProjectComponentFolder = getWebRootProjectComponentFolder(
|
|
6270
6366
|
absoluteWebRoot,
|
|
@@ -6293,7 +6389,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6293
6389
|
secretNames
|
|
6294
6390
|
);
|
|
6295
6391
|
if (fieldGenEnabledOption2) {
|
|
6296
|
-
const normalizedAbsoluteWebRoot =
|
|
6392
|
+
const normalizedAbsoluteWebRoot = path18.normalize(absoluteWebRoot);
|
|
6297
6393
|
startFieldsTypeGenWatcher(viteServer, normalizedAbsoluteWebRoot);
|
|
6298
6394
|
}
|
|
6299
6395
|
const viteHTTPSConfig = viteServer.config.server.https;
|
|
@@ -6318,10 +6414,10 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6318
6414
|
expressServer.locals.localPreviewToken = _localPreviewToken;
|
|
6319
6415
|
expressServer.locals.sslEnabled = sslEnabledOption2;
|
|
6320
6416
|
expressServer.use(bodyParser.json());
|
|
6321
|
-
const __dirname =
|
|
6322
|
-
let appWebRoot = normalizePath10(
|
|
6417
|
+
const __dirname = path18.dirname(url2.fileURLToPath(new URL(import.meta.url)));
|
|
6418
|
+
let appWebRoot = normalizePath10(path18.resolve(__dirname, "../app"));
|
|
6323
6419
|
if (true) {
|
|
6324
|
-
appWebRoot =
|
|
6420
|
+
appWebRoot = path18.join(__dirname, "app");
|
|
6325
6421
|
}
|
|
6326
6422
|
const appViteServer = await createAppServer_default(
|
|
6327
6423
|
appWebRoot,
|
|
@@ -6391,17 +6487,17 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6391
6487
|
`;
|
|
6392
6488
|
console.log(startMessage);
|
|
6393
6489
|
if (storybook2) {
|
|
6394
|
-
const packageRoot =
|
|
6395
|
-
const configPath =
|
|
6490
|
+
const packageRoot = path18.dirname(url2.fileURLToPath(import.meta.url));
|
|
6491
|
+
const configPath = path18.resolve(packageRoot, "./storybook-main");
|
|
6396
6492
|
sendTrackingRequest("start-storybook");
|
|
6397
6493
|
let storybookBin;
|
|
6398
6494
|
try {
|
|
6399
6495
|
const sbPackagePath = await import.meta.resolve("storybook/package.json");
|
|
6400
|
-
const sbPackageDir =
|
|
6496
|
+
const sbPackageDir = path18.dirname(url2.fileURLToPath(sbPackagePath));
|
|
6401
6497
|
const packageJson = JSON.parse(
|
|
6402
|
-
|
|
6498
|
+
fs9.readFileSync(path18.join(sbPackageDir, "package.json"), "utf-8")
|
|
6403
6499
|
);
|
|
6404
|
-
storybookBin =
|
|
6500
|
+
storybookBin = path18.join(
|
|
6405
6501
|
sbPackageDir,
|
|
6406
6502
|
packageJson.bin.storybook || packageJson.bin
|
|
6407
6503
|
);
|
|
@@ -6438,7 +6534,7 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6438
6534
|
portalId: authedPortalId.toString(),
|
|
6439
6535
|
hsEnv: authedEnv,
|
|
6440
6536
|
hublet: authedHublet,
|
|
6441
|
-
WEB_ROOT:
|
|
6537
|
+
WEB_ROOT: path18.join(webRoot2, "components")
|
|
6442
6538
|
},
|
|
6443
6539
|
stdio: "inherit"
|
|
6444
6540
|
}
|