@hubspot/cms-dev-server 0.16.18 → 0.18.0
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/generateJsonFromJsx.js +297 -172
- package/dist/index.js +4766 -176
- package/dist/internalSsr.js +260 -151
- package/dist/run.js +1989 -503
- package/dist/storybook-main/main.js +261 -152
- package/package.json +14 -10
- package/types/api/designmanager.d.ts +31 -0
- package/types/api/session.d.ts +2 -0
- package/types/components/HubLModulesList.d.ts +4 -0
- package/types/components/HubLTemplatesList.d.ts +4 -0
- package/types/components/ModulesList.d.ts +5 -0
- package/types/components/PartialsList.d.ts +4 -0
- package/types/createAppServer.d.ts +2 -0
- package/types/createDevServer.d.ts +5 -0
- package/types/createViteDevServer.d.ts +3 -0
- package/types/fileManager.d.ts +4 -0
- package/types/index.d.ts +1 -0
- package/types/lib/configHelpers.d.ts +2 -0
- package/types/lib/criticalDevErrorsToServerMessages.d.ts +4 -0
- package/types/lib/debug.d.ts +1 -0
- package/types/lib/errors.d.ts +6 -0
- package/types/lib/fetchModuleGraphQLData.d.ts +24 -0
- package/types/lib/fullOriginalUrlFromRequest.d.ts +2 -0
- package/types/lib/gates.d.ts +2 -0
- package/types/lib/getJSRenderingGates.d.ts +8 -0
- package/types/lib/httpsRedirectingServer.d.ts +11 -0
- package/types/lib/logColors.d.ts +6 -0
- package/types/lib/moduleGraph.d.ts +1 -0
- package/types/lib/packagePath.d.ts +1 -0
- package/types/lib/pathHelpers.d.ts +3 -0
- package/types/lib/previewUtils.d.ts +22 -0
- package/types/lib/proxyHelpers.d.ts +29 -0
- package/types/lib/renderComponentWithCSS.d.ts +14 -0
- package/types/lib/renderHelpers.d.ts +1 -0
- package/types/lib/renderModule.d.ts +11 -0
- package/types/lib/renderModulePreview.d.ts +5 -0
- package/types/lib/renderPartial.d.ts +5 -0
- package/types/lib/templates.d.ts +4 -0
- package/types/lib/trackUsage.d.ts +3 -0
- package/types/lib/validateHSPlatform.d.ts +3 -0
- package/types/lib/watchFieldsUpdates.d.ts +22 -0
- package/types/proxyPage/constants.d.ts +1 -0
- package/types/proxyPage/fetchContentMetadata.d.ts +7 -0
- package/types/proxyPage/fetchDomains.d.ts +9 -0
- package/types/proxyPage/fetchPreviewInfo.d.ts +6 -0
- package/types/proxyPage/proxyPage.d.ts +11 -0
- package/types/proxyPage/renderLocalError.d.ts +2 -0
- package/types/proxyPage/utils.d.ts +4 -0
- package/types/routes/createDevServerRoutes.d.ts +3 -0
- package/types/routes/homeRouteHandler.d.ts +3 -0
- package/types/routes/hublModuleRouteHandler.d.ts +2 -0
- package/types/routes/hublTemplateRouteHandler.d.ts +2 -0
- package/types/routes/linksToAllModulesRouteHandler.d.ts +2 -0
- package/types/routes/linksToAllPartialsRouteHandler.d.ts +2 -0
- package/types/routes/meta.d.ts +2 -0
- package/types/routes/module.d.ts +3 -0
- package/types/routes/modulePreviewRouteHandler.d.ts +3 -0
- package/types/routes/partial.d.ts +2 -0
- package/types/routes/proxyPageResourceRedirect.d.ts +2 -0
- package/types/routes/proxyPageRouteHandler.d.ts +2 -0
- package/types/routes/proxyPathPageResourceRedirect.d.ts +2 -0
- package/types/routes/proxyPathPageRouteHandler.d.ts +2 -0
- package/types/routes/proxyServerlessHandler.d.ts +2 -0
- package/types/routes/remoteFsDirtyHandler.d.ts +2 -0
- package/types/shadowDevServer/createShadowDevServerRoutes.d.ts +2 -0
- package/types/shadowDevServer/startShadowDevServer.d.ts +2 -0
- package/dist/generateJsonFromJsx.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/internalSsr.js.map +0 -7
- package/dist/island-runtime.js.map +0 -7
- package/dist/run.js.map +0 -7
- package/dist/storybook/index.js.map +0 -7
- package/dist/storybook-main/main.js.map +0 -7
- package/dist/storybook-main/preview.js.map +0 -7
- package/types/island-runtime.d.ts +0 -2
|
@@ -114,6 +114,7 @@ function noncePlaceholderPlugin() {
|
|
|
114
114
|
}
|
|
115
115
|
var traverse = _traverse.default;
|
|
116
116
|
var CMS_MODULE_COMPONENT_NAME = "Module";
|
|
117
|
+
var PLUGIN_NAME = "findCmsModules";
|
|
117
118
|
function findCmsModules(cmsModules = {}) {
|
|
118
119
|
let config;
|
|
119
120
|
return {
|
|
@@ -124,80 +125,14 @@ function findCmsModules(cmsModules = {}) {
|
|
|
124
125
|
},
|
|
125
126
|
transform(code, id) {
|
|
126
127
|
const moduleInfo = this.getModuleInfo(id);
|
|
127
|
-
|
|
128
|
-
if (isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME)) {
|
|
128
|
+
if (shouldSkipModule(config, moduleInfo, code))
|
|
129
129
|
return null;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
let moduleLocalImportName = CMS_MODULE_COMPONENT_NAME;
|
|
137
|
-
let moduleUsed = false;
|
|
138
|
-
const pluginError = this.error.bind(this);
|
|
139
|
-
traverse(sourceAst, {
|
|
140
|
-
ImportDeclaration(path4) {
|
|
141
|
-
if (!t.isStringLiteral(path4.node.source, {
|
|
142
|
-
value: "@hubspot/cms-components"
|
|
143
|
-
})) {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
for (const specifier of path4.node.specifiers) {
|
|
147
|
-
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
148
|
-
name: CMS_MODULE_COMPONENT_NAME
|
|
149
|
-
})) {
|
|
150
|
-
moduleLocalImportName = specifier.local.name;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
JSXOpeningElement(path4) {
|
|
155
|
-
if (!t.isJSXIdentifier(path4.node.name, {
|
|
156
|
-
name: moduleLocalImportName
|
|
157
|
-
})) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
moduleUsed = true;
|
|
161
|
-
let cmsModuleName;
|
|
162
|
-
let cmsModulePath;
|
|
163
|
-
let cmsModuleLabel;
|
|
164
|
-
for (const prop of path4.node.attributes) {
|
|
165
|
-
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
166
|
-
cmsModuleName = prop.value.value;
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
|
|
170
|
-
cmsModulePath = prop.value.value;
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
|
|
174
|
-
cmsModuleLabel = prop.value.value;
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
pluginError(
|
|
178
|
-
new Error(
|
|
179
|
-
`Error: ${id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
180
|
-
)
|
|
181
|
-
);
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
const cmsModuleProps = {
|
|
185
|
-
name: cmsModuleName,
|
|
186
|
-
path: cmsModulePath
|
|
187
|
-
};
|
|
188
|
-
if (cmsModuleLabel) {
|
|
189
|
-
cmsModuleProps.label = cmsModuleLabel;
|
|
190
|
-
}
|
|
191
|
-
if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
|
|
192
|
-
pluginError(
|
|
193
|
-
new Error(
|
|
194
|
-
`Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
|
|
195
|
-
)
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
localCmsModules[cmsModuleProps.name] = cmsModuleProps;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
130
|
+
const { localCmsModules, moduleUsed } = analyzeSourceCodeUsages(
|
|
131
|
+
this,
|
|
132
|
+
moduleInfo,
|
|
133
|
+
config,
|
|
134
|
+
code
|
|
135
|
+
);
|
|
201
136
|
if (!moduleUsed) {
|
|
202
137
|
return null;
|
|
203
138
|
}
|
|
@@ -210,95 +145,261 @@ function findCmsModules(cmsModules = {}) {
|
|
|
210
145
|
buildEnd(error) {
|
|
211
146
|
if (error)
|
|
212
147
|
throw error;
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
148
|
+
const entryPoints = getEntryPoints(this, config);
|
|
149
|
+
const entryPointCmsModuleMap = buildEntryPointsCmsModuleMap(
|
|
150
|
+
this,
|
|
151
|
+
entryPoints
|
|
217
152
|
);
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
153
|
+
const relativeEntryPointCmsModuleMap = convertEntryPointPathsToRelative(
|
|
154
|
+
config,
|
|
155
|
+
entryPointCmsModuleMap
|
|
156
|
+
);
|
|
157
|
+
const entryPointIslandCmsModuleMap = buildEntryPointIslandsCmsModuleMap(
|
|
158
|
+
this,
|
|
159
|
+
entryPoints
|
|
160
|
+
);
|
|
161
|
+
const relativeEntryPointIslandCmsModuleMap = convertEntryPointIslandPathsToRelative(
|
|
162
|
+
config,
|
|
163
|
+
entryPointIslandCmsModuleMap
|
|
164
|
+
);
|
|
165
|
+
if (Object.keys(relativeEntryPointIslandCmsModuleMap).length > 0) {
|
|
166
|
+
this.error(`
|
|
167
|
+
Error: <Module /> cannot be used within <Island />
|
|
168
|
+
Found invalid usages:
|
|
169
|
+
${JSON.stringify(relativeEntryPointIslandCmsModuleMap, null, 2)}
|
|
234
170
|
`);
|
|
235
|
-
}
|
|
236
171
|
}
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
${formatIslandImporter(
|
|
247
|
-
moduleWithCmsModuleUsage.id,
|
|
248
|
-
root
|
|
249
|
-
)} uses <${CMS_MODULE_COMPONENT_NAME} /> and is used by islands:
|
|
250
|
-
${islandsContainingCmsModuleUsage.map(
|
|
251
|
-
(islandModuleInfo) => formatIslandImporter(islandModuleInfo.id, root)
|
|
252
|
-
).join(", ")}
|
|
253
|
-
`);
|
|
254
|
-
}
|
|
172
|
+
const modulesWithinModules = filterEntryPointsToModules(
|
|
173
|
+
relativeEntryPointCmsModuleMap
|
|
174
|
+
);
|
|
175
|
+
if (Object.keys(modulesWithinModules).length > 0) {
|
|
176
|
+
this.error(`
|
|
177
|
+
Error: <Module /> can only be used in React Partials
|
|
178
|
+
Found invalid usages:
|
|
179
|
+
${JSON.stringify(modulesWithinModules, null, 2)}
|
|
180
|
+
`);
|
|
255
181
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
182
|
+
Object.assign(cmsModules, relativeEntryPointCmsModuleMap);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function convertEntryPointPathsToRelative(config, entryPointsCmsModuleMap) {
|
|
187
|
+
const relativeEntries = Object.entries(entryPointsCmsModuleMap).map(
|
|
188
|
+
([entryPointPath, cmsModules]) => {
|
|
189
|
+
return [toRelativePath(config, entryPointPath), cmsModules];
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
return Object.fromEntries(relativeEntries);
|
|
193
|
+
}
|
|
194
|
+
function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap) {
|
|
195
|
+
const relativeEntries = Object.entries(entryPointsCmsModuleMap).map(
|
|
196
|
+
([entryPointPath, islandCmsModules]) => {
|
|
197
|
+
const islandCmsModuleUsage = Object.fromEntries(
|
|
198
|
+
Object.entries(islandCmsModules).map(([islandPath, cmsModule]) => {
|
|
199
|
+
return [
|
|
200
|
+
toRelativePath(config, islandPath).replace("?client-entry", ""),
|
|
201
|
+
cmsModule
|
|
202
|
+
];
|
|
203
|
+
})
|
|
204
|
+
);
|
|
205
|
+
return [toRelativePath(config, entryPointPath), islandCmsModuleUsage];
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
return Object.fromEntries(relativeEntries);
|
|
209
|
+
}
|
|
210
|
+
function toRelativePath(config, path4) {
|
|
211
|
+
return path4.replace(config.root, "");
|
|
212
|
+
}
|
|
213
|
+
function shouldSkipModule(config, moduleInfo, code) {
|
|
214
|
+
const isExternal = config.command !== "serve" && moduleInfo.isExternal;
|
|
215
|
+
return isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME);
|
|
216
|
+
}
|
|
217
|
+
function getEntryPoints(ctx, config) {
|
|
218
|
+
return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
|
|
219
|
+
}
|
|
220
|
+
function buildEntryPointsCmsModuleMap(ctx, entryPoints) {
|
|
221
|
+
const entryPointCmsModuleUsage = {};
|
|
222
|
+
for (const entryPoint of entryPoints) {
|
|
223
|
+
const result = findCmsModuleUsages(ctx, entryPoint.id);
|
|
224
|
+
if (result) {
|
|
225
|
+
entryPointCmsModuleUsage[entryPoint.id] = result;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return entryPointCmsModuleUsage;
|
|
229
|
+
}
|
|
230
|
+
function buildEntryPointIslandsCmsModuleMap(ctx, entryPoints) {
|
|
231
|
+
const entryPointIslandsCmsModuleMap = {};
|
|
232
|
+
for (const entryPoint of entryPoints) {
|
|
233
|
+
const result = findIslandCmsModuleUsage(ctx, entryPoint.id);
|
|
234
|
+
if (result) {
|
|
235
|
+
entryPointIslandsCmsModuleMap[entryPoint.id] = result;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return entryPointIslandsCmsModuleMap;
|
|
239
|
+
}
|
|
240
|
+
function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
241
|
+
const sourceAst = parser.parse(code, {
|
|
242
|
+
sourceType: "module",
|
|
243
|
+
plugins: ["jsx", "typescript"]
|
|
244
|
+
});
|
|
245
|
+
const localCmsModules = {};
|
|
246
|
+
let moduleUsed = false;
|
|
247
|
+
let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
|
|
248
|
+
traverse(sourceAst, {
|
|
249
|
+
ImportDeclaration(path4) {
|
|
250
|
+
if (t.isStringLiteral(path4.node.source, {
|
|
251
|
+
value: "@hubspot/cms-components"
|
|
252
|
+
})) {
|
|
253
|
+
for (const specifier of path4.node.specifiers) {
|
|
254
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
255
|
+
name: CMS_MODULE_COMPONENT_NAME
|
|
256
|
+
})) {
|
|
257
|
+
moduleComponentLocalImportName = specifier.local.name;
|
|
270
258
|
}
|
|
271
259
|
}
|
|
272
260
|
}
|
|
261
|
+
},
|
|
262
|
+
JSXOpeningElement(path4) {
|
|
263
|
+
if (!t.isJSXIdentifier(path4.node.name, {
|
|
264
|
+
name: moduleComponentLocalImportName
|
|
265
|
+
})) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
moduleUsed = true;
|
|
269
|
+
let cmsModuleName;
|
|
270
|
+
let cmsModulePath;
|
|
271
|
+
let cmsModuleLabel;
|
|
272
|
+
for (const prop of path4.node.attributes) {
|
|
273
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
274
|
+
cmsModuleName = prop.value.value;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
|
|
278
|
+
cmsModulePath = prop.value.value;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
|
|
282
|
+
cmsModuleLabel = prop.value.value;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
ctx.error(
|
|
286
|
+
new Error(
|
|
287
|
+
`Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
288
|
+
)
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
const cmsModuleProps = {
|
|
292
|
+
name: cmsModuleName,
|
|
293
|
+
path: cmsModulePath
|
|
294
|
+
};
|
|
295
|
+
if (cmsModuleLabel) {
|
|
296
|
+
cmsModuleProps.label = cmsModuleLabel;
|
|
297
|
+
}
|
|
298
|
+
if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
|
|
299
|
+
ctx.error(
|
|
300
|
+
new Error(
|
|
301
|
+
`Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
|
|
302
|
+
)
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
localCmsModules[cmsModuleProps.name] = cmsModuleProps;
|
|
273
306
|
}
|
|
307
|
+
});
|
|
308
|
+
return {
|
|
309
|
+
moduleUsed,
|
|
310
|
+
localCmsModules
|
|
274
311
|
};
|
|
275
312
|
}
|
|
276
|
-
function
|
|
277
|
-
if (
|
|
278
|
-
return [
|
|
313
|
+
function findCmsModuleUsages(ctx, moduleId, processed = /* @__PURE__ */ new Set(), result = {}) {
|
|
314
|
+
if (Object.hasOwn(result, moduleId)) {
|
|
315
|
+
return result[moduleId];
|
|
316
|
+
}
|
|
317
|
+
const moduleInfo = ctx.getModuleInfo(moduleId);
|
|
318
|
+
let entryPointModules = null;
|
|
319
|
+
if (Object.hasOwn(moduleInfo.meta, PLUGIN_NAME)) {
|
|
320
|
+
entryPointModules = {
|
|
321
|
+
...entryPointModules,
|
|
322
|
+
...moduleInfo.meta[PLUGIN_NAME]
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
for (const importedId of [
|
|
326
|
+
...moduleInfo.importedIds,
|
|
327
|
+
...moduleInfo.dynamicallyImportedIds
|
|
328
|
+
]) {
|
|
329
|
+
if (processed.has(importedId)) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const importedResult = findCmsModuleUsages(
|
|
333
|
+
ctx,
|
|
334
|
+
importedId,
|
|
335
|
+
processed,
|
|
336
|
+
result
|
|
337
|
+
);
|
|
338
|
+
if (importedResult) {
|
|
339
|
+
entryPointModules = {
|
|
340
|
+
...entryPointModules,
|
|
341
|
+
...importedResult
|
|
342
|
+
};
|
|
343
|
+
}
|
|
279
344
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const importerModuleInfo = ctx.getModuleInfo(importer);
|
|
283
|
-
const entryPoints = findEntryPoints(ctx, importerModuleInfo);
|
|
284
|
-
result.push(...entryPoints);
|
|
345
|
+
if (entryPointModules) {
|
|
346
|
+
result[moduleId] = entryPointModules;
|
|
285
347
|
}
|
|
286
|
-
|
|
348
|
+
processed.add(moduleId);
|
|
349
|
+
return entryPointModules;
|
|
287
350
|
}
|
|
288
|
-
function
|
|
289
|
-
|
|
290
|
-
|
|
351
|
+
function findIslandCmsModuleUsage(ctx, moduleId, processedIslands = /* @__PURE__ */ new Set(), islandModuleResults = {}, processed = /* @__PURE__ */ new Set(), results = {}) {
|
|
352
|
+
processedIslands.add(moduleId);
|
|
353
|
+
if (Object.hasOwn(islandModuleResults, moduleId)) {
|
|
354
|
+
return islandModuleResults[moduleId];
|
|
291
355
|
}
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
356
|
+
const moduleInfo = ctx.getModuleInfo(moduleId);
|
|
357
|
+
let resultForModuleId = {};
|
|
358
|
+
if (moduleInfo.id.endsWith("?client-entry")) {
|
|
359
|
+
const mergedDataDependencies = findCmsModuleUsages(
|
|
360
|
+
ctx,
|
|
361
|
+
moduleInfo.id,
|
|
362
|
+
processed,
|
|
363
|
+
results
|
|
364
|
+
);
|
|
365
|
+
if (mergedDataDependencies) {
|
|
366
|
+
resultForModuleId[moduleInfo.id] = mergedDataDependencies;
|
|
367
|
+
}
|
|
297
368
|
}
|
|
298
|
-
|
|
369
|
+
for (const importedId of [
|
|
370
|
+
...moduleInfo.importedIds,
|
|
371
|
+
...moduleInfo.dynamicallyImportedIds
|
|
372
|
+
]) {
|
|
373
|
+
if (processedIslands.has(importedId)) {
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
const importerCmsModuleUsageResult = findIslandCmsModuleUsage(
|
|
377
|
+
ctx,
|
|
378
|
+
importedId,
|
|
379
|
+
processedIslands,
|
|
380
|
+
islandModuleResults,
|
|
381
|
+
processed,
|
|
382
|
+
results
|
|
383
|
+
);
|
|
384
|
+
if (importerCmsModuleUsageResult) {
|
|
385
|
+
resultForModuleId = {
|
|
386
|
+
...resultForModuleId,
|
|
387
|
+
...importerCmsModuleUsageResult
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (Object.keys(resultForModuleId).length > 0) {
|
|
392
|
+
islandModuleResults[moduleId] = resultForModuleId;
|
|
393
|
+
return resultForModuleId;
|
|
394
|
+
}
|
|
395
|
+
return null;
|
|
299
396
|
}
|
|
300
|
-
function
|
|
301
|
-
return
|
|
397
|
+
function filterEntryPointsToModules(entryPointCmsModuleMap) {
|
|
398
|
+
return Object.fromEntries(
|
|
399
|
+
Object.entries(entryPointCmsModuleMap).filter(
|
|
400
|
+
([entryPoint]) => entryPoint.startsWith("/components/modules/")
|
|
401
|
+
)
|
|
402
|
+
);
|
|
302
403
|
}
|
|
303
404
|
var {
|
|
304
405
|
createServerRenderContextV2: createServerRenderContextV22,
|
|
@@ -336,6 +437,23 @@ function devSecretsPlugin(secretNames) {
|
|
|
336
437
|
}
|
|
337
438
|
|
|
338
439
|
// src/createViteDevServer.ts
|
|
440
|
+
import { readFileSync } from "fs";
|
|
441
|
+
import { join } from "path";
|
|
442
|
+
function getPackageJson(packagePath2) {
|
|
443
|
+
return JSON.parse(readFileSync(join(packagePath2, "package.json")).toString());
|
|
444
|
+
}
|
|
445
|
+
function getDepsForPackage(packagePath2) {
|
|
446
|
+
const packageJson = getPackageJson(packagePath2);
|
|
447
|
+
return packageJson.dependencies ? Object.keys(packageJson.dependencies) : [];
|
|
448
|
+
}
|
|
449
|
+
function getDepsForPackageIfExists(packagePath2) {
|
|
450
|
+
try {
|
|
451
|
+
return getDepsForPackage(packagePath2);
|
|
452
|
+
} catch (e) {
|
|
453
|
+
console.log("No package.json at ", packagePath2);
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
}
|
|
339
457
|
async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], jsRenderingGates, secretNames) {
|
|
340
458
|
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
341
459
|
`${proxyDomain}.localhost`,
|
|
@@ -347,18 +465,9 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
347
465
|
`);
|
|
348
466
|
}
|
|
349
467
|
const origin = process.env.VITE_ORIGIN ?? (sslEnabled ? `https://hslocal.net:${port}` : `http://hslocal.net:${port}`);
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
middlewareMode: true,
|
|
354
|
-
host: "hslocal.net",
|
|
355
|
-
origin,
|
|
356
|
-
https: sslEnabled,
|
|
357
|
-
hmr: {
|
|
358
|
-
protocol: sslEnabled ? "wss" : void 0
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
root: webRoot,
|
|
468
|
+
const consumerDeps = getDepsForPackageIfExists(webRoot);
|
|
469
|
+
const isProjectWithReact = consumerDeps.includes("@hubspot/cms-components");
|
|
470
|
+
const ssrAndOptimizeDep = isProjectWithReact ? {
|
|
362
471
|
ssr: {
|
|
363
472
|
// TODO: might need more entries here to get things to resolve through
|
|
364
473
|
// resolveWebRootDepsPlugin
|
|
@@ -370,24 +479,40 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
370
479
|
},
|
|
371
480
|
optimizeDeps: {
|
|
372
481
|
include: ["react", "react-dom", "react-dom/client"]
|
|
482
|
+
}
|
|
483
|
+
} : {};
|
|
484
|
+
const reactAndIslandsPlugins = isProjectWithReact || process.env.VITEST ? [
|
|
485
|
+
react({
|
|
486
|
+
babel: {
|
|
487
|
+
plugins: [
|
|
488
|
+
"babel-plugin-styled-components",
|
|
489
|
+
"styled-jsx/babel",
|
|
490
|
+
"macros"
|
|
491
|
+
]
|
|
492
|
+
}
|
|
493
|
+
}),
|
|
494
|
+
clientIslandEntryPlugin(),
|
|
495
|
+
resolveIslandPlugin(),
|
|
496
|
+
jsRenderingGates.includes("CMS:JSRenderer:RemoveCjsPlugin") ? null : viteCommonjs(),
|
|
497
|
+
devSecretsPlugin(secretNames),
|
|
498
|
+
noncePlaceholderPlugin()
|
|
499
|
+
] : [];
|
|
500
|
+
const viteConfig = {
|
|
501
|
+
appType: "custom",
|
|
502
|
+
server: {
|
|
503
|
+
middlewareMode: true,
|
|
504
|
+
host: "hslocal.net",
|
|
505
|
+
origin,
|
|
506
|
+
hmr: {
|
|
507
|
+
protocol: sslEnabled ? "wss" : void 0
|
|
508
|
+
}
|
|
373
509
|
},
|
|
510
|
+
root: webRoot,
|
|
511
|
+
...ssrAndOptimizeDep,
|
|
374
512
|
plugins: [
|
|
375
513
|
jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules") ? findCmsModules() : null,
|
|
376
514
|
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
377
|
-
|
|
378
|
-
babel: {
|
|
379
|
-
plugins: [
|
|
380
|
-
"babel-plugin-styled-components",
|
|
381
|
-
"styled-jsx/babel",
|
|
382
|
-
"macros"
|
|
383
|
-
]
|
|
384
|
-
}
|
|
385
|
-
}),
|
|
386
|
-
clientIslandEntryPlugin(),
|
|
387
|
-
resolveIslandPlugin(),
|
|
388
|
-
jsRenderingGates.includes("CMS:JSRenderer:RemoveCjsPlugin") ? null : viteCommonjs(),
|
|
389
|
-
devSecretsPlugin(secretNames),
|
|
390
|
-
noncePlaceholderPlugin()
|
|
515
|
+
...reactAndIslandsPlugins
|
|
391
516
|
],
|
|
392
517
|
css: {
|
|
393
518
|
postcss: webRoot
|