@hubspot/cms-dev-server 0.18.2 → 0.18.5
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 +99 -69
- package/dist/index.js +139 -84
- package/dist/internalSsr.js +103 -73
- package/dist/run.js +139 -84
- package/dist/storybook/index.js +4 -4
- package/dist/storybook-main/main.js +108 -78
- package/package.json +3 -3
- package/types/createAppServer.d.ts +1 -1
- package/types/transformJsxToJson.d.ts +4 -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
|
@@ -9,7 +9,7 @@ import { normalizePath as normalizePath2 } from "vite";
|
|
|
9
9
|
import { createServer as createViteServer } from "vite";
|
|
10
10
|
import { default as react } from "@vitejs/plugin-react";
|
|
11
11
|
|
|
12
|
-
// ../cms-js-internal/dist/
|
|
12
|
+
// ../cms-js-internal/dist/types-BXr0V0Zd.js
|
|
13
13
|
import path from "path";
|
|
14
14
|
var viteRoot;
|
|
15
15
|
var viteCommand;
|
|
@@ -114,8 +114,9 @@ function noncePlaceholderPlugin() {
|
|
|
114
114
|
}
|
|
115
115
|
var traverse = _traverse.default;
|
|
116
116
|
var CMS_MODULE_COMPONENT_NAME = "Module";
|
|
117
|
+
var DND_AREA_COMPONENT_NAME = "DndArea";
|
|
117
118
|
var PLUGIN_NAME = "findCmsModules";
|
|
118
|
-
function findCmsModules(
|
|
119
|
+
function findCmsModules(buildContentDescriptors = {}) {
|
|
119
120
|
let config;
|
|
120
121
|
return {
|
|
121
122
|
enforce: "pre",
|
|
@@ -127,20 +128,20 @@ function findCmsModules(cmsModules = {}) {
|
|
|
127
128
|
const moduleInfo = this.getModuleInfo(id);
|
|
128
129
|
if (shouldSkipModule(config, moduleInfo, code))
|
|
129
130
|
return null;
|
|
130
|
-
const
|
|
131
|
+
const contentDescriptors = analyzeSourceCodeUsages(
|
|
131
132
|
this,
|
|
132
133
|
moduleInfo,
|
|
133
134
|
config,
|
|
134
135
|
code
|
|
135
136
|
);
|
|
136
|
-
if (
|
|
137
|
-
return
|
|
137
|
+
if (Object.keys(contentDescriptors.dndAreas).length > 0 || Object.keys(contentDescriptors.modules).length > 0) {
|
|
138
|
+
return {
|
|
139
|
+
meta: {
|
|
140
|
+
findCmsModules: contentDescriptors
|
|
141
|
+
}
|
|
142
|
+
};
|
|
138
143
|
}
|
|
139
|
-
return
|
|
140
|
-
meta: {
|
|
141
|
-
findCmsModules: localCmsModules
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
+
return null;
|
|
144
145
|
},
|
|
145
146
|
buildEnd(error) {
|
|
146
147
|
if (error)
|
|
@@ -179,7 +180,7 @@ function findCmsModules(cmsModules = {}) {
|
|
|
179
180
|
${JSON.stringify(modulesWithinModules, null, 2)}
|
|
180
181
|
`);
|
|
181
182
|
}
|
|
182
|
-
Object.assign(
|
|
183
|
+
Object.assign(buildContentDescriptors, relativeEntryPointCmsModuleMap);
|
|
183
184
|
}
|
|
184
185
|
};
|
|
185
186
|
}
|
|
@@ -193,14 +194,16 @@ function convertEntryPointPathsToRelative(config, entryPointsCmsModuleMap) {
|
|
|
193
194
|
}
|
|
194
195
|
function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap) {
|
|
195
196
|
const relativeEntries = Object.entries(entryPointsCmsModuleMap).map(
|
|
196
|
-
([entryPointPath,
|
|
197
|
+
([entryPointPath, islandContentDescriptors]) => {
|
|
197
198
|
const islandCmsModuleUsage = Object.fromEntries(
|
|
198
|
-
Object.entries(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
Object.entries(islandContentDescriptors).map(
|
|
200
|
+
([islandPath, contentDescriptors]) => {
|
|
201
|
+
return [
|
|
202
|
+
toRelativePath(config, islandPath).replace("?client-entry", ""),
|
|
203
|
+
contentDescriptors
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
)
|
|
204
207
|
);
|
|
205
208
|
return [toRelativePath(config, entryPointPath), islandCmsModuleUsage];
|
|
206
209
|
}
|
|
@@ -212,7 +215,7 @@ function toRelativePath(config, path4) {
|
|
|
212
215
|
}
|
|
213
216
|
function shouldSkipModule(config, moduleInfo, code) {
|
|
214
217
|
const isExternal = config.command !== "serve" && moduleInfo.isExternal;
|
|
215
|
-
return isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME);
|
|
218
|
+
return isExternal || !moduleInfo.id.startsWith(config.root) || !(code.includes(CMS_MODULE_COMPONENT_NAME) || code.includes(DND_AREA_COMPONENT_NAME));
|
|
216
219
|
}
|
|
217
220
|
function getEntryPoints(ctx, config) {
|
|
218
221
|
return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
|
|
@@ -242,9 +245,9 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
242
245
|
sourceType: "module",
|
|
243
246
|
plugins: ["jsx", "typescript"]
|
|
244
247
|
});
|
|
245
|
-
const
|
|
246
|
-
let moduleUsed = false;
|
|
248
|
+
const contentDescriptors = { modules: {}, dndAreas: {} };
|
|
247
249
|
let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
|
|
250
|
+
let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
|
|
248
251
|
traverse(sourceAst, {
|
|
249
252
|
ImportDeclaration(path4) {
|
|
250
253
|
if (t.isStringLiteral(path4.node.source, {
|
|
@@ -256,69 +259,96 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
256
259
|
})) {
|
|
257
260
|
moduleComponentLocalImportName = specifier.local.name;
|
|
258
261
|
}
|
|
262
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
263
|
+
name: DND_AREA_COMPONENT_NAME
|
|
264
|
+
})) {
|
|
265
|
+
dndAreaComponentLocalImportName = specifier.local.name;
|
|
266
|
+
}
|
|
259
267
|
}
|
|
260
268
|
}
|
|
261
269
|
},
|
|
262
270
|
JSXOpeningElement(path4) {
|
|
263
|
-
if (
|
|
271
|
+
if (t.isJSXIdentifier(path4.node.name, {
|
|
264
272
|
name: moduleComponentLocalImportName
|
|
265
273
|
})) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
let cmsModuleName;
|
|
275
|
+
let cmsModulePath;
|
|
276
|
+
let cmsModuleLabel;
|
|
277
|
+
for (const prop of path4.node.attributes) {
|
|
278
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
279
|
+
cmsModuleName = prop.value.value;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
|
|
283
|
+
cmsModulePath = prop.value.value;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "label" }) && t.isStringLiteral(prop.value)) {
|
|
287
|
+
cmsModuleLabel = prop.value.value;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
ctx.error(
|
|
291
|
+
new Error(
|
|
292
|
+
`Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
293
|
+
)
|
|
294
|
+
);
|
|
276
295
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
296
|
+
const cmsModuleProps = {
|
|
297
|
+
name: cmsModuleName,
|
|
298
|
+
path: cmsModulePath
|
|
299
|
+
};
|
|
300
|
+
if (cmsModuleLabel) {
|
|
301
|
+
cmsModuleProps.label = cmsModuleLabel;
|
|
280
302
|
}
|
|
281
|
-
if (
|
|
282
|
-
|
|
283
|
-
|
|
303
|
+
if (Object.hasOwn(contentDescriptors.modules, cmsModuleProps.name)) {
|
|
304
|
+
ctx.error(
|
|
305
|
+
new Error(
|
|
306
|
+
`Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
|
|
307
|
+
)
|
|
308
|
+
);
|
|
284
309
|
}
|
|
285
|
-
|
|
286
|
-
new Error(
|
|
287
|
-
`Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
288
|
-
)
|
|
289
|
-
);
|
|
310
|
+
contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
|
|
290
311
|
}
|
|
291
|
-
|
|
292
|
-
name:
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
312
|
+
if (t.isJSXIdentifier(path4.node.name, {
|
|
313
|
+
name: dndAreaComponentLocalImportName
|
|
314
|
+
})) {
|
|
315
|
+
let dndAreaName;
|
|
316
|
+
for (const prop of path4.node.attributes) {
|
|
317
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
318
|
+
dndAreaName = prop.value.value;
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
ctx.error(
|
|
322
|
+
new Error(
|
|
323
|
+
`Error: ${moduleInfo.id.replace(config.root, "")}:${prop.loc.start.line} "name" must a primitive string`
|
|
324
|
+
)
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
const dndArea = {
|
|
328
|
+
name: dndAreaName
|
|
329
|
+
};
|
|
330
|
+
if (Object.hasOwn(contentDescriptors.dndAreas, dndArea.name)) {
|
|
331
|
+
ctx.error(
|
|
332
|
+
new Error(
|
|
333
|
+
`Error: multiple <${DND_AREA_COMPONENT_NAME} /> with duplicate name: ${dndArea.name}`
|
|
334
|
+
)
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
contentDescriptors.dndAreas[dndArea.name] = dndArea;
|
|
304
338
|
}
|
|
305
|
-
localCmsModules[cmsModuleProps.name] = cmsModuleProps;
|
|
306
339
|
}
|
|
307
340
|
});
|
|
308
|
-
return
|
|
309
|
-
moduleUsed,
|
|
310
|
-
localCmsModules
|
|
311
|
-
};
|
|
341
|
+
return contentDescriptors;
|
|
312
342
|
}
|
|
313
343
|
function findCmsModuleUsages(ctx, moduleId, processed = /* @__PURE__ */ new Set(), result = {}) {
|
|
314
344
|
if (Object.hasOwn(result, moduleId)) {
|
|
315
345
|
return result[moduleId];
|
|
316
346
|
}
|
|
317
347
|
const moduleInfo = ctx.getModuleInfo(moduleId);
|
|
318
|
-
let
|
|
348
|
+
let entryPointContentDescriptors = null;
|
|
319
349
|
if (Object.hasOwn(moduleInfo.meta, PLUGIN_NAME)) {
|
|
320
|
-
|
|
321
|
-
...
|
|
350
|
+
entryPointContentDescriptors = {
|
|
351
|
+
...entryPointContentDescriptors,
|
|
322
352
|
...moduleInfo.meta[PLUGIN_NAME]
|
|
323
353
|
};
|
|
324
354
|
}
|
|
@@ -336,17 +366,17 @@ function findCmsModuleUsages(ctx, moduleId, processed = /* @__PURE__ */ new Set(
|
|
|
336
366
|
result
|
|
337
367
|
);
|
|
338
368
|
if (importedResult) {
|
|
339
|
-
|
|
340
|
-
...
|
|
369
|
+
entryPointContentDescriptors = {
|
|
370
|
+
...entryPointContentDescriptors,
|
|
341
371
|
...importedResult
|
|
342
372
|
};
|
|
343
373
|
}
|
|
344
374
|
}
|
|
345
|
-
if (
|
|
346
|
-
result[moduleId] =
|
|
375
|
+
if (entryPointContentDescriptors) {
|
|
376
|
+
result[moduleId] = entryPointContentDescriptors;
|
|
347
377
|
}
|
|
348
378
|
processed.add(moduleId);
|
|
349
|
-
return
|
|
379
|
+
return entryPointContentDescriptors;
|
|
350
380
|
}
|
|
351
381
|
function findIslandCmsModuleUsage(ctx, moduleId, processedIslands = /* @__PURE__ */ new Set(), islandModuleResults = {}, processed = /* @__PURE__ */ new Set(), results = {}) {
|
|
352
382
|
processedIslands.add(moduleId);
|