@hubspot/cms-dev-server 0.16.7 → 0.16.10
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 +178 -0
- package/dist/index.js +178 -0
- package/dist/internalSsr.js +180 -1
- package/dist/run.js +179 -1
- package/dist/storybook/index.js +2 -0
- package/dist/storybook-main/main.js +181 -2
- package/package.json +7 -3
- package/types/island-runtime.d.ts +0 -2
|
@@ -85,6 +85,9 @@ function clientIslandEntryPlugin() {
|
|
|
85
85
|
|
|
86
86
|
// ../cms-js-internal/dist/index.js
|
|
87
87
|
import * as dotProp from "dot-prop";
|
|
88
|
+
import * as parser from "@babel/parser";
|
|
89
|
+
import _traverse from "@babel/traverse";
|
|
90
|
+
import * as t from "@babel/types";
|
|
88
91
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
89
92
|
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
90
93
|
function noncePlaceholderPlugin() {
|
|
@@ -109,6 +112,180 @@ function noncePlaceholderPlugin() {
|
|
|
109
112
|
}
|
|
110
113
|
};
|
|
111
114
|
}
|
|
115
|
+
var traverse = _traverse.default;
|
|
116
|
+
var CMS_MODULE_COMPONENT_NAME = "UnstableModule";
|
|
117
|
+
function findCmsModules(cmsModules = {}) {
|
|
118
|
+
let config;
|
|
119
|
+
return {
|
|
120
|
+
enforce: "pre",
|
|
121
|
+
name: "findCmsModules",
|
|
122
|
+
configResolved(resolvedConfig) {
|
|
123
|
+
config = resolvedConfig;
|
|
124
|
+
},
|
|
125
|
+
transform(code, id) {
|
|
126
|
+
const moduleInfo = this.getModuleInfo(id);
|
|
127
|
+
const isExternal = config.command === "serve" ? false : moduleInfo.isExternal;
|
|
128
|
+
if (isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME)) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const localCmsModules = {};
|
|
132
|
+
const sourceAst = parser.parse(code, {
|
|
133
|
+
sourceType: "module",
|
|
134
|
+
plugins: ["jsx", "typescript"]
|
|
135
|
+
});
|
|
136
|
+
let unstableModuleLocalName = CMS_MODULE_COMPONENT_NAME;
|
|
137
|
+
const pluginError = this.error.bind(this);
|
|
138
|
+
traverse(sourceAst, {
|
|
139
|
+
ImportDeclaration(path4) {
|
|
140
|
+
if (!t.isStringLiteral(path4.node.source, {
|
|
141
|
+
value: "@hubspot/cms-components"
|
|
142
|
+
})) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
for (const specifier of path4.node.specifiers) {
|
|
146
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
147
|
+
name: CMS_MODULE_COMPONENT_NAME
|
|
148
|
+
})) {
|
|
149
|
+
unstableModuleLocalName = specifier.local.name;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
JSXOpeningElement(path4) {
|
|
154
|
+
if (!t.isJSXIdentifier(path4.node.name, {
|
|
155
|
+
name: unstableModuleLocalName
|
|
156
|
+
}) || path4.node.attributes.length !== 2) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
let cmsModuleName;
|
|
160
|
+
let cmsModulePath;
|
|
161
|
+
for (const prop of path4.node.attributes) {
|
|
162
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
163
|
+
cmsModuleName = prop.value.value;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
|
|
167
|
+
cmsModulePath = prop.value.value;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
pluginError(
|
|
171
|
+
new Error(
|
|
172
|
+
`Error: ${id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
173
|
+
)
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
const cmsModuleProps = {
|
|
177
|
+
name: cmsModuleName,
|
|
178
|
+
path: cmsModulePath
|
|
179
|
+
};
|
|
180
|
+
if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
|
|
181
|
+
pluginError(
|
|
182
|
+
new Error(
|
|
183
|
+
`Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
localCmsModules[cmsModuleProps.name] = cmsModuleProps;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
meta: {
|
|
192
|
+
findCmsModules: localCmsModules
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
buildEnd(error) {
|
|
197
|
+
if (error)
|
|
198
|
+
throw error;
|
|
199
|
+
const modulesWithCmsModuleUsage = Array.of(
|
|
200
|
+
...this.getModuleIds()
|
|
201
|
+
).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => this.getModuleInfo(moduleId)).filter(
|
|
202
|
+
(moduleInfo) => Object.hasOwn(moduleInfo.meta, "findCmsModules")
|
|
203
|
+
);
|
|
204
|
+
const moduleToEntryPoints = {};
|
|
205
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
206
|
+
moduleToEntryPoints[moduleWithCmsModuleUsage.id] = findEntryPoints(
|
|
207
|
+
this,
|
|
208
|
+
moduleWithCmsModuleUsage
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
212
|
+
const usageInModuleEntryPoint = moduleToEntryPoints[moduleWithCmsModuleUsage.id].find((entryPoint) => entryPoint.id.includes("/components/modules"));
|
|
213
|
+
if (usageInModuleEntryPoint) {
|
|
214
|
+
this.error(`
|
|
215
|
+
Error: <${CMS_MODULE_COMPONENT_NAME} /> can only be used in Partials.
|
|
216
|
+
Module: ${usageInModuleEntryPoint.id === moduleWithCmsModuleUsage.id ? usageInModuleEntryPoint.id.replace(config.root, "") : `imports: ${moduleWithCmsModuleUsage.id.replace(
|
|
217
|
+
config.root,
|
|
218
|
+
""
|
|
219
|
+
)}, which`} contains a <${CMS_MODULE_COMPONENT_NAME} />
|
|
220
|
+
`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const root = config.root;
|
|
224
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
225
|
+
const islandsContainingCmsModuleUsage = checkModuleTreeForIslands(
|
|
226
|
+
this,
|
|
227
|
+
moduleWithCmsModuleUsage
|
|
228
|
+
);
|
|
229
|
+
if (islandsContainingCmsModuleUsage.length > 0) {
|
|
230
|
+
throw new Error(`
|
|
231
|
+
<${CMS_MODULE_COMPONENT_NAME} /> cannot be used within islands.
|
|
232
|
+
${formatIslandImporter(
|
|
233
|
+
moduleWithCmsModuleUsage.id,
|
|
234
|
+
root
|
|
235
|
+
)} uses <${CMS_MODULE_COMPONENT_NAME} /> and is used by islands:
|
|
236
|
+
${islandsContainingCmsModuleUsage.map(
|
|
237
|
+
(islandModuleInfo) => formatIslandImporter(islandModuleInfo.id, root)
|
|
238
|
+
).join(", ")}
|
|
239
|
+
`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
243
|
+
const entryPoints = moduleToEntryPoints[moduleWithCmsModuleUsage.id];
|
|
244
|
+
for (const entryPoint of entryPoints) {
|
|
245
|
+
const relativeEntryPoint = entryPoint.id.replace(root, "");
|
|
246
|
+
if (!Object.hasOwn(cmsModules, relativeEntryPoint)) {
|
|
247
|
+
cmsModules[relativeEntryPoint] = {};
|
|
248
|
+
}
|
|
249
|
+
for (const [cmsModuleName, cmsModuleValue] of Object.entries(
|
|
250
|
+
moduleWithCmsModuleUsage.meta.findCmsModules
|
|
251
|
+
)) {
|
|
252
|
+
if (Object.hasOwn(cmsModules[relativeEntryPoint], cmsModuleName)) {
|
|
253
|
+
this.error(`Error: duplicate module name: ${cmsModuleName}`);
|
|
254
|
+
}
|
|
255
|
+
cmsModules[relativeEntryPoint][cmsModuleName] = cmsModuleValue;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function findEntryPoints(ctx, moduleInfo) {
|
|
263
|
+
if (moduleInfo.isEntry) {
|
|
264
|
+
return [moduleInfo];
|
|
265
|
+
}
|
|
266
|
+
const result = [];
|
|
267
|
+
for (const importer of moduleInfo.importers) {
|
|
268
|
+
const importerModuleInfo = ctx.getModuleInfo(importer);
|
|
269
|
+
const entryPoints = findEntryPoints(ctx, importerModuleInfo);
|
|
270
|
+
result.push(...entryPoints);
|
|
271
|
+
}
|
|
272
|
+
return result;
|
|
273
|
+
}
|
|
274
|
+
function checkModuleTreeForIslands(ctx, module) {
|
|
275
|
+
if (module.id.endsWith("?client-entry")) {
|
|
276
|
+
return [module];
|
|
277
|
+
}
|
|
278
|
+
const importerResults = [];
|
|
279
|
+
for (const importer of module.importers) {
|
|
280
|
+
const importerInfo = ctx.getModuleInfo(importer);
|
|
281
|
+
const importerResult = checkModuleTreeForIslands(ctx, importerInfo);
|
|
282
|
+
importerResults.push(importerResult);
|
|
283
|
+
}
|
|
284
|
+
return importerResults.flat();
|
|
285
|
+
}
|
|
286
|
+
function formatIslandImporter(id, root) {
|
|
287
|
+
return id.replace(root, "").replace("?client-entry", "");
|
|
288
|
+
}
|
|
112
289
|
var {
|
|
113
290
|
createServerRenderContextV2: createServerRenderContextV22,
|
|
114
291
|
createServerRenderContext: createServerRenderContext2,
|
|
@@ -181,6 +358,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
181
358
|
include: ["react", "react-dom", "react-dom/client"]
|
|
182
359
|
},
|
|
183
360
|
plugins: [
|
|
361
|
+
jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules") ? findCmsModules() : null,
|
|
184
362
|
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
185
363
|
react({
|
|
186
364
|
babel: {
|
package/dist/index.js
CHANGED
|
@@ -78,6 +78,9 @@ function clientIslandEntryPlugin() {
|
|
|
78
78
|
|
|
79
79
|
// ../cms-js-internal/dist/index.js
|
|
80
80
|
import * as dotProp from "dot-prop";
|
|
81
|
+
import * as parser from "@babel/parser";
|
|
82
|
+
import _traverse from "@babel/traverse";
|
|
83
|
+
import * as t from "@babel/types";
|
|
81
84
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
82
85
|
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
83
86
|
function noncePlaceholderPlugin() {
|
|
@@ -102,6 +105,180 @@ function noncePlaceholderPlugin() {
|
|
|
102
105
|
}
|
|
103
106
|
};
|
|
104
107
|
}
|
|
108
|
+
var traverse = _traverse.default;
|
|
109
|
+
var CMS_MODULE_COMPONENT_NAME = "UnstableModule";
|
|
110
|
+
function findCmsModules(cmsModules = {}) {
|
|
111
|
+
let config;
|
|
112
|
+
return {
|
|
113
|
+
enforce: "pre",
|
|
114
|
+
name: "findCmsModules",
|
|
115
|
+
configResolved(resolvedConfig) {
|
|
116
|
+
config = resolvedConfig;
|
|
117
|
+
},
|
|
118
|
+
transform(code, id) {
|
|
119
|
+
const moduleInfo = this.getModuleInfo(id);
|
|
120
|
+
const isExternal = config.command === "serve" ? false : moduleInfo.isExternal;
|
|
121
|
+
if (isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME)) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const localCmsModules = {};
|
|
125
|
+
const sourceAst = parser.parse(code, {
|
|
126
|
+
sourceType: "module",
|
|
127
|
+
plugins: ["jsx", "typescript"]
|
|
128
|
+
});
|
|
129
|
+
let unstableModuleLocalName = CMS_MODULE_COMPONENT_NAME;
|
|
130
|
+
const pluginError = this.error.bind(this);
|
|
131
|
+
traverse(sourceAst, {
|
|
132
|
+
ImportDeclaration(path2) {
|
|
133
|
+
if (!t.isStringLiteral(path2.node.source, {
|
|
134
|
+
value: "@hubspot/cms-components"
|
|
135
|
+
})) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
for (const specifier of path2.node.specifiers) {
|
|
139
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
140
|
+
name: CMS_MODULE_COMPONENT_NAME
|
|
141
|
+
})) {
|
|
142
|
+
unstableModuleLocalName = specifier.local.name;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
JSXOpeningElement(path2) {
|
|
147
|
+
if (!t.isJSXIdentifier(path2.node.name, {
|
|
148
|
+
name: unstableModuleLocalName
|
|
149
|
+
}) || path2.node.attributes.length !== 2) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
let cmsModuleName;
|
|
153
|
+
let cmsModulePath;
|
|
154
|
+
for (const prop of path2.node.attributes) {
|
|
155
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
156
|
+
cmsModuleName = prop.value.value;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
|
|
160
|
+
cmsModulePath = prop.value.value;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
pluginError(
|
|
164
|
+
new Error(
|
|
165
|
+
`Error: ${id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
const cmsModuleProps = {
|
|
170
|
+
name: cmsModuleName,
|
|
171
|
+
path: cmsModulePath
|
|
172
|
+
};
|
|
173
|
+
if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
|
|
174
|
+
pluginError(
|
|
175
|
+
new Error(
|
|
176
|
+
`Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
localCmsModules[cmsModuleProps.name] = cmsModuleProps;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
meta: {
|
|
185
|
+
findCmsModules: localCmsModules
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
buildEnd(error) {
|
|
190
|
+
if (error)
|
|
191
|
+
throw error;
|
|
192
|
+
const modulesWithCmsModuleUsage = Array.of(
|
|
193
|
+
...this.getModuleIds()
|
|
194
|
+
).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => this.getModuleInfo(moduleId)).filter(
|
|
195
|
+
(moduleInfo) => Object.hasOwn(moduleInfo.meta, "findCmsModules")
|
|
196
|
+
);
|
|
197
|
+
const moduleToEntryPoints = {};
|
|
198
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
199
|
+
moduleToEntryPoints[moduleWithCmsModuleUsage.id] = findEntryPoints(
|
|
200
|
+
this,
|
|
201
|
+
moduleWithCmsModuleUsage
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
205
|
+
const usageInModuleEntryPoint = moduleToEntryPoints[moduleWithCmsModuleUsage.id].find((entryPoint) => entryPoint.id.includes("/components/modules"));
|
|
206
|
+
if (usageInModuleEntryPoint) {
|
|
207
|
+
this.error(`
|
|
208
|
+
Error: <${CMS_MODULE_COMPONENT_NAME} /> can only be used in Partials.
|
|
209
|
+
Module: ${usageInModuleEntryPoint.id === moduleWithCmsModuleUsage.id ? usageInModuleEntryPoint.id.replace(config.root, "") : `imports: ${moduleWithCmsModuleUsage.id.replace(
|
|
210
|
+
config.root,
|
|
211
|
+
""
|
|
212
|
+
)}, which`} contains a <${CMS_MODULE_COMPONENT_NAME} />
|
|
213
|
+
`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const root = config.root;
|
|
217
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
218
|
+
const islandsContainingCmsModuleUsage = checkModuleTreeForIslands(
|
|
219
|
+
this,
|
|
220
|
+
moduleWithCmsModuleUsage
|
|
221
|
+
);
|
|
222
|
+
if (islandsContainingCmsModuleUsage.length > 0) {
|
|
223
|
+
throw new Error(`
|
|
224
|
+
<${CMS_MODULE_COMPONENT_NAME} /> cannot be used within islands.
|
|
225
|
+
${formatIslandImporter(
|
|
226
|
+
moduleWithCmsModuleUsage.id,
|
|
227
|
+
root
|
|
228
|
+
)} uses <${CMS_MODULE_COMPONENT_NAME} /> and is used by islands:
|
|
229
|
+
${islandsContainingCmsModuleUsage.map(
|
|
230
|
+
(islandModuleInfo) => formatIslandImporter(islandModuleInfo.id, root)
|
|
231
|
+
).join(", ")}
|
|
232
|
+
`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
236
|
+
const entryPoints = moduleToEntryPoints[moduleWithCmsModuleUsage.id];
|
|
237
|
+
for (const entryPoint of entryPoints) {
|
|
238
|
+
const relativeEntryPoint = entryPoint.id.replace(root, "");
|
|
239
|
+
if (!Object.hasOwn(cmsModules, relativeEntryPoint)) {
|
|
240
|
+
cmsModules[relativeEntryPoint] = {};
|
|
241
|
+
}
|
|
242
|
+
for (const [cmsModuleName, cmsModuleValue] of Object.entries(
|
|
243
|
+
moduleWithCmsModuleUsage.meta.findCmsModules
|
|
244
|
+
)) {
|
|
245
|
+
if (Object.hasOwn(cmsModules[relativeEntryPoint], cmsModuleName)) {
|
|
246
|
+
this.error(`Error: duplicate module name: ${cmsModuleName}`);
|
|
247
|
+
}
|
|
248
|
+
cmsModules[relativeEntryPoint][cmsModuleName] = cmsModuleValue;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function findEntryPoints(ctx, moduleInfo) {
|
|
256
|
+
if (moduleInfo.isEntry) {
|
|
257
|
+
return [moduleInfo];
|
|
258
|
+
}
|
|
259
|
+
const result = [];
|
|
260
|
+
for (const importer of moduleInfo.importers) {
|
|
261
|
+
const importerModuleInfo = ctx.getModuleInfo(importer);
|
|
262
|
+
const entryPoints = findEntryPoints(ctx, importerModuleInfo);
|
|
263
|
+
result.push(...entryPoints);
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
function checkModuleTreeForIslands(ctx, module) {
|
|
268
|
+
if (module.id.endsWith("?client-entry")) {
|
|
269
|
+
return [module];
|
|
270
|
+
}
|
|
271
|
+
const importerResults = [];
|
|
272
|
+
for (const importer of module.importers) {
|
|
273
|
+
const importerInfo = ctx.getModuleInfo(importer);
|
|
274
|
+
const importerResult = checkModuleTreeForIslands(ctx, importerInfo);
|
|
275
|
+
importerResults.push(importerResult);
|
|
276
|
+
}
|
|
277
|
+
return importerResults.flat();
|
|
278
|
+
}
|
|
279
|
+
function formatIslandImporter(id, root) {
|
|
280
|
+
return id.replace(root, "").replace("?client-entry", "");
|
|
281
|
+
}
|
|
105
282
|
var {
|
|
106
283
|
createServerRenderContextV2: createServerRenderContextV22,
|
|
107
284
|
createServerRenderContext: createServerRenderContext2,
|
|
@@ -174,6 +351,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
174
351
|
include: ["react", "react-dom", "react-dom/client"]
|
|
175
352
|
},
|
|
176
353
|
plugins: [
|
|
354
|
+
jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules") ? findCmsModules() : null,
|
|
177
355
|
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
178
356
|
react({
|
|
179
357
|
babel: {
|
package/dist/internalSsr.js
CHANGED
|
@@ -318,7 +318,8 @@ var GATES = [
|
|
|
318
318
|
"CMS:JSRenderer:GetServerSideProps",
|
|
319
319
|
"CMS:JSRenderer:ModuleHubl",
|
|
320
320
|
"CMS:JSRenderer:RemoveCjsPlugin",
|
|
321
|
-
"CMS:JSRenderer:RemoveMockClientEntryPlugin"
|
|
321
|
+
"CMS:JSRenderer:RemoveMockClientEntryPlugin",
|
|
322
|
+
"CMS:JSRenderer:AnalyzeCmsModules"
|
|
322
323
|
];
|
|
323
324
|
var ENABLED_FEATURES_GATE_MAP = {
|
|
324
325
|
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
@@ -445,6 +446,9 @@ function isStylesheetAsset(staticAsset) {
|
|
|
445
446
|
|
|
446
447
|
// ../cms-js-internal/dist/index.js
|
|
447
448
|
import * as dotProp from "dot-prop";
|
|
449
|
+
import * as parser from "@babel/parser";
|
|
450
|
+
import _traverse from "@babel/traverse";
|
|
451
|
+
import * as t from "@babel/types";
|
|
448
452
|
import { jsx } from "react/jsx-runtime";
|
|
449
453
|
import stream from "stream";
|
|
450
454
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
@@ -631,6 +635,180 @@ function noncePlaceholderPlugin() {
|
|
|
631
635
|
}
|
|
632
636
|
};
|
|
633
637
|
}
|
|
638
|
+
var traverse = _traverse.default;
|
|
639
|
+
var CMS_MODULE_COMPONENT_NAME = "UnstableModule";
|
|
640
|
+
function findCmsModules(cmsModules = {}) {
|
|
641
|
+
let config;
|
|
642
|
+
return {
|
|
643
|
+
enforce: "pre",
|
|
644
|
+
name: "findCmsModules",
|
|
645
|
+
configResolved(resolvedConfig) {
|
|
646
|
+
config = resolvedConfig;
|
|
647
|
+
},
|
|
648
|
+
transform(code, id) {
|
|
649
|
+
const moduleInfo = this.getModuleInfo(id);
|
|
650
|
+
const isExternal = config.command === "serve" ? false : moduleInfo.isExternal;
|
|
651
|
+
if (isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME)) {
|
|
652
|
+
return null;
|
|
653
|
+
}
|
|
654
|
+
const localCmsModules = {};
|
|
655
|
+
const sourceAst = parser.parse(code, {
|
|
656
|
+
sourceType: "module",
|
|
657
|
+
plugins: ["jsx", "typescript"]
|
|
658
|
+
});
|
|
659
|
+
let unstableModuleLocalName = CMS_MODULE_COMPONENT_NAME;
|
|
660
|
+
const pluginError = this.error.bind(this);
|
|
661
|
+
traverse(sourceAst, {
|
|
662
|
+
ImportDeclaration(path2) {
|
|
663
|
+
if (!t.isStringLiteral(path2.node.source, {
|
|
664
|
+
value: "@hubspot/cms-components"
|
|
665
|
+
})) {
|
|
666
|
+
return null;
|
|
667
|
+
}
|
|
668
|
+
for (const specifier of path2.node.specifiers) {
|
|
669
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
670
|
+
name: CMS_MODULE_COMPONENT_NAME
|
|
671
|
+
})) {
|
|
672
|
+
unstableModuleLocalName = specifier.local.name;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
JSXOpeningElement(path2) {
|
|
677
|
+
if (!t.isJSXIdentifier(path2.node.name, {
|
|
678
|
+
name: unstableModuleLocalName
|
|
679
|
+
}) || path2.node.attributes.length !== 2) {
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
682
|
+
let cmsModuleName;
|
|
683
|
+
let cmsModulePath;
|
|
684
|
+
for (const prop of path2.node.attributes) {
|
|
685
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
686
|
+
cmsModuleName = prop.value.value;
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
|
|
690
|
+
cmsModulePath = prop.value.value;
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
pluginError(
|
|
694
|
+
new Error(
|
|
695
|
+
`Error: ${id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
696
|
+
)
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
const cmsModuleProps = {
|
|
700
|
+
name: cmsModuleName,
|
|
701
|
+
path: cmsModulePath
|
|
702
|
+
};
|
|
703
|
+
if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
|
|
704
|
+
pluginError(
|
|
705
|
+
new Error(
|
|
706
|
+
`Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
|
|
707
|
+
)
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
localCmsModules[cmsModuleProps.name] = cmsModuleProps;
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
return {
|
|
714
|
+
meta: {
|
|
715
|
+
findCmsModules: localCmsModules
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
},
|
|
719
|
+
buildEnd(error) {
|
|
720
|
+
if (error)
|
|
721
|
+
throw error;
|
|
722
|
+
const modulesWithCmsModuleUsage = Array.of(
|
|
723
|
+
...this.getModuleIds()
|
|
724
|
+
).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => this.getModuleInfo(moduleId)).filter(
|
|
725
|
+
(moduleInfo) => Object.hasOwn(moduleInfo.meta, "findCmsModules")
|
|
726
|
+
);
|
|
727
|
+
const moduleToEntryPoints = {};
|
|
728
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
729
|
+
moduleToEntryPoints[moduleWithCmsModuleUsage.id] = findEntryPoints(
|
|
730
|
+
this,
|
|
731
|
+
moduleWithCmsModuleUsage
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
735
|
+
const usageInModuleEntryPoint = moduleToEntryPoints[moduleWithCmsModuleUsage.id].find((entryPoint) => entryPoint.id.includes("/components/modules"));
|
|
736
|
+
if (usageInModuleEntryPoint) {
|
|
737
|
+
this.error(`
|
|
738
|
+
Error: <${CMS_MODULE_COMPONENT_NAME} /> can only be used in Partials.
|
|
739
|
+
Module: ${usageInModuleEntryPoint.id === moduleWithCmsModuleUsage.id ? usageInModuleEntryPoint.id.replace(config.root, "") : `imports: ${moduleWithCmsModuleUsage.id.replace(
|
|
740
|
+
config.root,
|
|
741
|
+
""
|
|
742
|
+
)}, which`} contains a <${CMS_MODULE_COMPONENT_NAME} />
|
|
743
|
+
`);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
const root = config.root;
|
|
747
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
748
|
+
const islandsContainingCmsModuleUsage = checkModuleTreeForIslands(
|
|
749
|
+
this,
|
|
750
|
+
moduleWithCmsModuleUsage
|
|
751
|
+
);
|
|
752
|
+
if (islandsContainingCmsModuleUsage.length > 0) {
|
|
753
|
+
throw new Error(`
|
|
754
|
+
<${CMS_MODULE_COMPONENT_NAME} /> cannot be used within islands.
|
|
755
|
+
${formatIslandImporter(
|
|
756
|
+
moduleWithCmsModuleUsage.id,
|
|
757
|
+
root
|
|
758
|
+
)} uses <${CMS_MODULE_COMPONENT_NAME} /> and is used by islands:
|
|
759
|
+
${islandsContainingCmsModuleUsage.map(
|
|
760
|
+
(islandModuleInfo) => formatIslandImporter(islandModuleInfo.id, root)
|
|
761
|
+
).join(", ")}
|
|
762
|
+
`);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
766
|
+
const entryPoints = moduleToEntryPoints[moduleWithCmsModuleUsage.id];
|
|
767
|
+
for (const entryPoint of entryPoints) {
|
|
768
|
+
const relativeEntryPoint = entryPoint.id.replace(root, "");
|
|
769
|
+
if (!Object.hasOwn(cmsModules, relativeEntryPoint)) {
|
|
770
|
+
cmsModules[relativeEntryPoint] = {};
|
|
771
|
+
}
|
|
772
|
+
for (const [cmsModuleName, cmsModuleValue] of Object.entries(
|
|
773
|
+
moduleWithCmsModuleUsage.meta.findCmsModules
|
|
774
|
+
)) {
|
|
775
|
+
if (Object.hasOwn(cmsModules[relativeEntryPoint], cmsModuleName)) {
|
|
776
|
+
this.error(`Error: duplicate module name: ${cmsModuleName}`);
|
|
777
|
+
}
|
|
778
|
+
cmsModules[relativeEntryPoint][cmsModuleName] = cmsModuleValue;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
function findEntryPoints(ctx, moduleInfo) {
|
|
786
|
+
if (moduleInfo.isEntry) {
|
|
787
|
+
return [moduleInfo];
|
|
788
|
+
}
|
|
789
|
+
const result = [];
|
|
790
|
+
for (const importer of moduleInfo.importers) {
|
|
791
|
+
const importerModuleInfo = ctx.getModuleInfo(importer);
|
|
792
|
+
const entryPoints = findEntryPoints(ctx, importerModuleInfo);
|
|
793
|
+
result.push(...entryPoints);
|
|
794
|
+
}
|
|
795
|
+
return result;
|
|
796
|
+
}
|
|
797
|
+
function checkModuleTreeForIslands(ctx, module) {
|
|
798
|
+
if (module.id.endsWith("?client-entry")) {
|
|
799
|
+
return [module];
|
|
800
|
+
}
|
|
801
|
+
const importerResults = [];
|
|
802
|
+
for (const importer of module.importers) {
|
|
803
|
+
const importerInfo = ctx.getModuleInfo(importer);
|
|
804
|
+
const importerResult = checkModuleTreeForIslands(ctx, importerInfo);
|
|
805
|
+
importerResults.push(importerResult);
|
|
806
|
+
}
|
|
807
|
+
return importerResults.flat();
|
|
808
|
+
}
|
|
809
|
+
function formatIslandImporter(id, root) {
|
|
810
|
+
return id.replace(root, "").replace("?client-entry", "");
|
|
811
|
+
}
|
|
634
812
|
var promiseForNewWritableStream = () => {
|
|
635
813
|
const chunks = [];
|
|
636
814
|
const writableStream = new stream.Writable();
|
|
@@ -816,6 +994,7 @@ export {
|
|
|
816
994
|
findAllComponentsIn,
|
|
817
995
|
findAllModulesInRoot,
|
|
818
996
|
findAllPartialsInRoot,
|
|
997
|
+
findCmsModules,
|
|
819
998
|
getBaseAssetUrlFromBuild,
|
|
820
999
|
getBuildInfo,
|
|
821
1000
|
getCMSAssetConfig,
|
package/dist/run.js
CHANGED
|
@@ -412,6 +412,9 @@ function setIn(object, nestedKeysArray, value) {
|
|
|
412
412
|
|
|
413
413
|
// ../cms-js-internal/dist/index.js
|
|
414
414
|
import * as dotProp from "dot-prop";
|
|
415
|
+
import * as parser from "@babel/parser";
|
|
416
|
+
import _traverse from "@babel/traverse";
|
|
417
|
+
import * as t from "@babel/types";
|
|
415
418
|
import { jsx } from "react/jsx-runtime";
|
|
416
419
|
import stream from "stream";
|
|
417
420
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
@@ -597,6 +600,180 @@ function noncePlaceholderPlugin() {
|
|
|
597
600
|
}
|
|
598
601
|
};
|
|
599
602
|
}
|
|
603
|
+
var traverse = _traverse.default;
|
|
604
|
+
var CMS_MODULE_COMPONENT_NAME = "UnstableModule";
|
|
605
|
+
function findCmsModules(cmsModules = {}) {
|
|
606
|
+
let config;
|
|
607
|
+
return {
|
|
608
|
+
enforce: "pre",
|
|
609
|
+
name: "findCmsModules",
|
|
610
|
+
configResolved(resolvedConfig) {
|
|
611
|
+
config = resolvedConfig;
|
|
612
|
+
},
|
|
613
|
+
transform(code, id) {
|
|
614
|
+
const moduleInfo = this.getModuleInfo(id);
|
|
615
|
+
const isExternal = config.command === "serve" ? false : moduleInfo.isExternal;
|
|
616
|
+
if (isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME)) {
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
const localCmsModules = {};
|
|
620
|
+
const sourceAst = parser.parse(code, {
|
|
621
|
+
sourceType: "module",
|
|
622
|
+
plugins: ["jsx", "typescript"]
|
|
623
|
+
});
|
|
624
|
+
let unstableModuleLocalName = CMS_MODULE_COMPONENT_NAME;
|
|
625
|
+
const pluginError = this.error.bind(this);
|
|
626
|
+
traverse(sourceAst, {
|
|
627
|
+
ImportDeclaration(path10) {
|
|
628
|
+
if (!t.isStringLiteral(path10.node.source, {
|
|
629
|
+
value: "@hubspot/cms-components"
|
|
630
|
+
})) {
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
for (const specifier of path10.node.specifiers) {
|
|
634
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
635
|
+
name: CMS_MODULE_COMPONENT_NAME
|
|
636
|
+
})) {
|
|
637
|
+
unstableModuleLocalName = specifier.local.name;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
JSXOpeningElement(path10) {
|
|
642
|
+
if (!t.isJSXIdentifier(path10.node.name, {
|
|
643
|
+
name: unstableModuleLocalName
|
|
644
|
+
}) || path10.node.attributes.length !== 2) {
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
let cmsModuleName;
|
|
648
|
+
let cmsModulePath;
|
|
649
|
+
for (const prop of path10.node.attributes) {
|
|
650
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
651
|
+
cmsModuleName = prop.value.value;
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
|
|
655
|
+
cmsModulePath = prop.value.value;
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
pluginError(
|
|
659
|
+
new Error(
|
|
660
|
+
`Error: ${id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
661
|
+
)
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
const cmsModuleProps = {
|
|
665
|
+
name: cmsModuleName,
|
|
666
|
+
path: cmsModulePath
|
|
667
|
+
};
|
|
668
|
+
if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
|
|
669
|
+
pluginError(
|
|
670
|
+
new Error(
|
|
671
|
+
`Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
|
|
672
|
+
)
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
localCmsModules[cmsModuleProps.name] = cmsModuleProps;
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
return {
|
|
679
|
+
meta: {
|
|
680
|
+
findCmsModules: localCmsModules
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
},
|
|
684
|
+
buildEnd(error) {
|
|
685
|
+
if (error)
|
|
686
|
+
throw error;
|
|
687
|
+
const modulesWithCmsModuleUsage = Array.of(
|
|
688
|
+
...this.getModuleIds()
|
|
689
|
+
).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => this.getModuleInfo(moduleId)).filter(
|
|
690
|
+
(moduleInfo) => Object.hasOwn(moduleInfo.meta, "findCmsModules")
|
|
691
|
+
);
|
|
692
|
+
const moduleToEntryPoints = {};
|
|
693
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
694
|
+
moduleToEntryPoints[moduleWithCmsModuleUsage.id] = findEntryPoints(
|
|
695
|
+
this,
|
|
696
|
+
moduleWithCmsModuleUsage
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
700
|
+
const usageInModuleEntryPoint = moduleToEntryPoints[moduleWithCmsModuleUsage.id].find((entryPoint) => entryPoint.id.includes("/components/modules"));
|
|
701
|
+
if (usageInModuleEntryPoint) {
|
|
702
|
+
this.error(`
|
|
703
|
+
Error: <${CMS_MODULE_COMPONENT_NAME} /> can only be used in Partials.
|
|
704
|
+
Module: ${usageInModuleEntryPoint.id === moduleWithCmsModuleUsage.id ? usageInModuleEntryPoint.id.replace(config.root, "") : `imports: ${moduleWithCmsModuleUsage.id.replace(
|
|
705
|
+
config.root,
|
|
706
|
+
""
|
|
707
|
+
)}, which`} contains a <${CMS_MODULE_COMPONENT_NAME} />
|
|
708
|
+
`);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
const root = config.root;
|
|
712
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
713
|
+
const islandsContainingCmsModuleUsage = checkModuleTreeForIslands(
|
|
714
|
+
this,
|
|
715
|
+
moduleWithCmsModuleUsage
|
|
716
|
+
);
|
|
717
|
+
if (islandsContainingCmsModuleUsage.length > 0) {
|
|
718
|
+
throw new Error(`
|
|
719
|
+
<${CMS_MODULE_COMPONENT_NAME} /> cannot be used within islands.
|
|
720
|
+
${formatIslandImporter(
|
|
721
|
+
moduleWithCmsModuleUsage.id,
|
|
722
|
+
root
|
|
723
|
+
)} uses <${CMS_MODULE_COMPONENT_NAME} /> and is used by islands:
|
|
724
|
+
${islandsContainingCmsModuleUsage.map(
|
|
725
|
+
(islandModuleInfo) => formatIslandImporter(islandModuleInfo.id, root)
|
|
726
|
+
).join(", ")}
|
|
727
|
+
`);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
731
|
+
const entryPoints = moduleToEntryPoints[moduleWithCmsModuleUsage.id];
|
|
732
|
+
for (const entryPoint of entryPoints) {
|
|
733
|
+
const relativeEntryPoint = entryPoint.id.replace(root, "");
|
|
734
|
+
if (!Object.hasOwn(cmsModules, relativeEntryPoint)) {
|
|
735
|
+
cmsModules[relativeEntryPoint] = {};
|
|
736
|
+
}
|
|
737
|
+
for (const [cmsModuleName, cmsModuleValue] of Object.entries(
|
|
738
|
+
moduleWithCmsModuleUsage.meta.findCmsModules
|
|
739
|
+
)) {
|
|
740
|
+
if (Object.hasOwn(cmsModules[relativeEntryPoint], cmsModuleName)) {
|
|
741
|
+
this.error(`Error: duplicate module name: ${cmsModuleName}`);
|
|
742
|
+
}
|
|
743
|
+
cmsModules[relativeEntryPoint][cmsModuleName] = cmsModuleValue;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
function findEntryPoints(ctx, moduleInfo) {
|
|
751
|
+
if (moduleInfo.isEntry) {
|
|
752
|
+
return [moduleInfo];
|
|
753
|
+
}
|
|
754
|
+
const result = [];
|
|
755
|
+
for (const importer of moduleInfo.importers) {
|
|
756
|
+
const importerModuleInfo = ctx.getModuleInfo(importer);
|
|
757
|
+
const entryPoints = findEntryPoints(ctx, importerModuleInfo);
|
|
758
|
+
result.push(...entryPoints);
|
|
759
|
+
}
|
|
760
|
+
return result;
|
|
761
|
+
}
|
|
762
|
+
function checkModuleTreeForIslands(ctx, module) {
|
|
763
|
+
if (module.id.endsWith("?client-entry")) {
|
|
764
|
+
return [module];
|
|
765
|
+
}
|
|
766
|
+
const importerResults = [];
|
|
767
|
+
for (const importer of module.importers) {
|
|
768
|
+
const importerInfo = ctx.getModuleInfo(importer);
|
|
769
|
+
const importerResult = checkModuleTreeForIslands(ctx, importerInfo);
|
|
770
|
+
importerResults.push(importerResult);
|
|
771
|
+
}
|
|
772
|
+
return importerResults.flat();
|
|
773
|
+
}
|
|
774
|
+
function formatIslandImporter(id, root) {
|
|
775
|
+
return id.replace(root, "").replace("?client-entry", "");
|
|
776
|
+
}
|
|
600
777
|
var promiseForNewWritableStream = () => {
|
|
601
778
|
const chunks = [];
|
|
602
779
|
const writableStream = new stream.Writable();
|
|
@@ -1055,7 +1232,7 @@ function trackUsage(action) {
|
|
|
1055
1232
|
eventName: EVENT_NAME,
|
|
1056
1233
|
action,
|
|
1057
1234
|
nodeVersion: getNodeVersionData(),
|
|
1058
|
-
version: "0.16.
|
|
1235
|
+
version: "0.16.10",
|
|
1059
1236
|
os: getPlatform()
|
|
1060
1237
|
};
|
|
1061
1238
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -2955,6 +3132,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
2955
3132
|
include: ["react", "react-dom", "react-dom/client"]
|
|
2956
3133
|
},
|
|
2957
3134
|
plugins: [
|
|
3135
|
+
jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules") ? findCmsModules() : null,
|
|
2958
3136
|
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
2959
3137
|
react({
|
|
2960
3138
|
babel: {
|
package/dist/storybook/index.js
CHANGED
|
@@ -34,10 +34,12 @@ function namespaceModulePropsShape(props) {
|
|
|
34
34
|
|
|
35
35
|
// ../cms-js-internal/dist/index.js
|
|
36
36
|
import * as dotProp from "dot-prop";
|
|
37
|
+
import _traverse from "@babel/traverse";
|
|
37
38
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
38
39
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
39
40
|
import { isValidElement, cloneElement } from "react";
|
|
40
41
|
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
42
|
+
var traverse = _traverse.default;
|
|
41
43
|
var {
|
|
42
44
|
createServerRenderContextV2: createServerRenderContextV22,
|
|
43
45
|
createServerRenderContext: createServerRenderContext2,
|
|
@@ -414,7 +414,8 @@ ${groupEnd}</script>
|
|
|
414
414
|
"CMS:JSRenderer:GetServerSideProps",
|
|
415
415
|
"CMS:JSRenderer:ModuleHubl",
|
|
416
416
|
"CMS:JSRenderer:RemoveCjsPlugin",
|
|
417
|
-
"CMS:JSRenderer:RemoveMockClientEntryPlugin"
|
|
417
|
+
"CMS:JSRenderer:RemoveMockClientEntryPlugin",
|
|
418
|
+
"CMS:JSRenderer:AnalyzeCmsModules"
|
|
418
419
|
];
|
|
419
420
|
ENABLED_FEATURES_GATE_MAP = {
|
|
420
421
|
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
@@ -477,6 +478,7 @@ __export(dist_exports, {
|
|
|
477
478
|
findAllComponentsIn: () => findAllComponentsIn,
|
|
478
479
|
findAllModulesInRoot: () => findAllModulesInRoot,
|
|
479
480
|
findAllPartialsInRoot: () => findAllPartialsInRoot,
|
|
481
|
+
findCmsModules: () => findCmsModules,
|
|
480
482
|
getBaseAssetUrlFromBuild: () => getBaseAssetUrlFromBuild,
|
|
481
483
|
getBuildInfo: () => getBuildInfo,
|
|
482
484
|
getCMSAssetConfig: () => getCMSAssetConfig,
|
|
@@ -514,6 +516,9 @@ __export(dist_exports, {
|
|
|
514
516
|
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
|
|
515
517
|
});
|
|
516
518
|
import * as dotProp from "dot-prop";
|
|
519
|
+
import * as parser from "@babel/parser";
|
|
520
|
+
import _traverse from "@babel/traverse";
|
|
521
|
+
import * as t from "@babel/types";
|
|
517
522
|
import { jsx } from "react/jsx-runtime";
|
|
518
523
|
import stream from "stream";
|
|
519
524
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
@@ -604,6 +609,178 @@ function noncePlaceholderPlugin() {
|
|
|
604
609
|
}
|
|
605
610
|
};
|
|
606
611
|
}
|
|
612
|
+
function findCmsModules(cmsModules = {}) {
|
|
613
|
+
let config;
|
|
614
|
+
return {
|
|
615
|
+
enforce: "pre",
|
|
616
|
+
name: "findCmsModules",
|
|
617
|
+
configResolved(resolvedConfig) {
|
|
618
|
+
config = resolvedConfig;
|
|
619
|
+
},
|
|
620
|
+
transform(code, id) {
|
|
621
|
+
const moduleInfo = this.getModuleInfo(id);
|
|
622
|
+
const isExternal = config.command === "serve" ? false : moduleInfo.isExternal;
|
|
623
|
+
if (isExternal || !moduleInfo.id.startsWith(config.root) || !code.includes(CMS_MODULE_COMPONENT_NAME)) {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
const localCmsModules = {};
|
|
627
|
+
const sourceAst = parser.parse(code, {
|
|
628
|
+
sourceType: "module",
|
|
629
|
+
plugins: ["jsx", "typescript"]
|
|
630
|
+
});
|
|
631
|
+
let unstableModuleLocalName = CMS_MODULE_COMPONENT_NAME;
|
|
632
|
+
const pluginError = this.error.bind(this);
|
|
633
|
+
traverse(sourceAst, {
|
|
634
|
+
ImportDeclaration(path3) {
|
|
635
|
+
if (!t.isStringLiteral(path3.node.source, {
|
|
636
|
+
value: "@hubspot/cms-components"
|
|
637
|
+
})) {
|
|
638
|
+
return null;
|
|
639
|
+
}
|
|
640
|
+
for (const specifier of path3.node.specifiers) {
|
|
641
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
642
|
+
name: CMS_MODULE_COMPONENT_NAME
|
|
643
|
+
})) {
|
|
644
|
+
unstableModuleLocalName = specifier.local.name;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
JSXOpeningElement(path3) {
|
|
649
|
+
if (!t.isJSXIdentifier(path3.node.name, {
|
|
650
|
+
name: unstableModuleLocalName
|
|
651
|
+
}) || path3.node.attributes.length !== 2) {
|
|
652
|
+
return null;
|
|
653
|
+
}
|
|
654
|
+
let cmsModuleName;
|
|
655
|
+
let cmsModulePath;
|
|
656
|
+
for (const prop of path3.node.attributes) {
|
|
657
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
658
|
+
cmsModuleName = prop.value.value;
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "path" }) && t.isStringLiteral(prop.value)) {
|
|
662
|
+
cmsModulePath = prop.value.value;
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
pluginError(
|
|
666
|
+
new Error(
|
|
667
|
+
`Error: ${id.replace(config.root, "")}:${prop.loc.start.line} "name" and "path" must be primitive strings`
|
|
668
|
+
)
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
const cmsModuleProps = {
|
|
672
|
+
name: cmsModuleName,
|
|
673
|
+
path: cmsModulePath
|
|
674
|
+
};
|
|
675
|
+
if (Object.hasOwn(localCmsModules, cmsModuleProps.name)) {
|
|
676
|
+
pluginError(
|
|
677
|
+
new Error(
|
|
678
|
+
`Error: multiple <${CMS_MODULE_COMPONENT_NAME} /> with duplicate name: ${cmsModuleProps.name}`
|
|
679
|
+
)
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
localCmsModules[cmsModuleProps.name] = cmsModuleProps;
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
return {
|
|
686
|
+
meta: {
|
|
687
|
+
findCmsModules: localCmsModules
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
},
|
|
691
|
+
buildEnd(error) {
|
|
692
|
+
if (error)
|
|
693
|
+
throw error;
|
|
694
|
+
const modulesWithCmsModuleUsage = Array.of(
|
|
695
|
+
...this.getModuleIds()
|
|
696
|
+
).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => this.getModuleInfo(moduleId)).filter(
|
|
697
|
+
(moduleInfo) => Object.hasOwn(moduleInfo.meta, "findCmsModules")
|
|
698
|
+
);
|
|
699
|
+
const moduleToEntryPoints = {};
|
|
700
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
701
|
+
moduleToEntryPoints[moduleWithCmsModuleUsage.id] = findEntryPoints(
|
|
702
|
+
this,
|
|
703
|
+
moduleWithCmsModuleUsage
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
707
|
+
const usageInModuleEntryPoint = moduleToEntryPoints[moduleWithCmsModuleUsage.id].find((entryPoint) => entryPoint.id.includes("/components/modules"));
|
|
708
|
+
if (usageInModuleEntryPoint) {
|
|
709
|
+
this.error(`
|
|
710
|
+
Error: <${CMS_MODULE_COMPONENT_NAME} /> can only be used in Partials.
|
|
711
|
+
Module: ${usageInModuleEntryPoint.id === moduleWithCmsModuleUsage.id ? usageInModuleEntryPoint.id.replace(config.root, "") : `imports: ${moduleWithCmsModuleUsage.id.replace(
|
|
712
|
+
config.root,
|
|
713
|
+
""
|
|
714
|
+
)}, which`} contains a <${CMS_MODULE_COMPONENT_NAME} />
|
|
715
|
+
`);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
const root = config.root;
|
|
719
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
720
|
+
const islandsContainingCmsModuleUsage = checkModuleTreeForIslands(
|
|
721
|
+
this,
|
|
722
|
+
moduleWithCmsModuleUsage
|
|
723
|
+
);
|
|
724
|
+
if (islandsContainingCmsModuleUsage.length > 0) {
|
|
725
|
+
throw new Error(`
|
|
726
|
+
<${CMS_MODULE_COMPONENT_NAME} /> cannot be used within islands.
|
|
727
|
+
${formatIslandImporter(
|
|
728
|
+
moduleWithCmsModuleUsage.id,
|
|
729
|
+
root
|
|
730
|
+
)} uses <${CMS_MODULE_COMPONENT_NAME} /> and is used by islands:
|
|
731
|
+
${islandsContainingCmsModuleUsage.map(
|
|
732
|
+
(islandModuleInfo) => formatIslandImporter(islandModuleInfo.id, root)
|
|
733
|
+
).join(", ")}
|
|
734
|
+
`);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
for (const moduleWithCmsModuleUsage of modulesWithCmsModuleUsage) {
|
|
738
|
+
const entryPoints = moduleToEntryPoints[moduleWithCmsModuleUsage.id];
|
|
739
|
+
for (const entryPoint of entryPoints) {
|
|
740
|
+
const relativeEntryPoint = entryPoint.id.replace(root, "");
|
|
741
|
+
if (!Object.hasOwn(cmsModules, relativeEntryPoint)) {
|
|
742
|
+
cmsModules[relativeEntryPoint] = {};
|
|
743
|
+
}
|
|
744
|
+
for (const [cmsModuleName, cmsModuleValue] of Object.entries(
|
|
745
|
+
moduleWithCmsModuleUsage.meta.findCmsModules
|
|
746
|
+
)) {
|
|
747
|
+
if (Object.hasOwn(cmsModules[relativeEntryPoint], cmsModuleName)) {
|
|
748
|
+
this.error(`Error: duplicate module name: ${cmsModuleName}`);
|
|
749
|
+
}
|
|
750
|
+
cmsModules[relativeEntryPoint][cmsModuleName] = cmsModuleValue;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
function findEntryPoints(ctx, moduleInfo) {
|
|
758
|
+
if (moduleInfo.isEntry) {
|
|
759
|
+
return [moduleInfo];
|
|
760
|
+
}
|
|
761
|
+
const result = [];
|
|
762
|
+
for (const importer of moduleInfo.importers) {
|
|
763
|
+
const importerModuleInfo = ctx.getModuleInfo(importer);
|
|
764
|
+
const entryPoints = findEntryPoints(ctx, importerModuleInfo);
|
|
765
|
+
result.push(...entryPoints);
|
|
766
|
+
}
|
|
767
|
+
return result;
|
|
768
|
+
}
|
|
769
|
+
function checkModuleTreeForIslands(ctx, module) {
|
|
770
|
+
if (module.id.endsWith("?client-entry")) {
|
|
771
|
+
return [module];
|
|
772
|
+
}
|
|
773
|
+
const importerResults = [];
|
|
774
|
+
for (const importer of module.importers) {
|
|
775
|
+
const importerInfo = ctx.getModuleInfo(importer);
|
|
776
|
+
const importerResult = checkModuleTreeForIslands(ctx, importerInfo);
|
|
777
|
+
importerResults.push(importerResult);
|
|
778
|
+
}
|
|
779
|
+
return importerResults.flat();
|
|
780
|
+
}
|
|
781
|
+
function formatIslandImporter(id, root) {
|
|
782
|
+
return id.replace(root, "").replace("?client-entry", "");
|
|
783
|
+
}
|
|
607
784
|
async function renderComponentOnServer(Component, propsAndDeps, pageUrl, environmentConfig, entryPointBasePath, contextOptions, renderOptions, getServerSideProps) {
|
|
608
785
|
const { props } = propsAndDeps;
|
|
609
786
|
const componentDebugName = Component.displayName || Component.name;
|
|
@@ -720,7 +897,7 @@ function renderFieldsToJson(fields, moduleName) {
|
|
|
720
897
|
throw e;
|
|
721
898
|
}
|
|
722
899
|
}
|
|
723
|
-
var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext;
|
|
900
|
+
var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, traverse, CMS_MODULE_COMPONENT_NAME, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext;
|
|
724
901
|
var init_dist = __esm({
|
|
725
902
|
"../cms-js-internal/dist/index.js"() {
|
|
726
903
|
init_basicUtils();
|
|
@@ -821,6 +998,8 @@ ${indentString}`);
|
|
|
821
998
|
prettyPrint
|
|
822
999
|
)}`;
|
|
823
1000
|
};
|
|
1001
|
+
traverse = _traverse.default;
|
|
1002
|
+
CMS_MODULE_COMPONENT_NAME = "UnstableModule";
|
|
824
1003
|
promiseForNewWritableStream = () => {
|
|
825
1004
|
const chunks = [];
|
|
826
1005
|
const writableStream = new stream.Writable();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.10",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -25,7 +25,11 @@
|
|
|
25
25
|
"publint": "publint --level warning --prod"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@
|
|
28
|
+
"@babel/code-frame": "^7.24.7",
|
|
29
|
+
"@babel/parser": "^7.25.3",
|
|
30
|
+
"@babel/traverse": "^7.25.3",
|
|
31
|
+
"@babel/types": "^7.25.2",
|
|
32
|
+
"@hubspot/cms-components": "^0.16.10",
|
|
29
33
|
"@hubspot/local-dev-lib": "^1.9.0",
|
|
30
34
|
"@inquirer/select": "^2.0.0",
|
|
31
35
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
@@ -109,5 +113,5 @@
|
|
|
109
113
|
"publishConfig": {
|
|
110
114
|
"access": "public"
|
|
111
115
|
},
|
|
112
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "4bd57c6245ac08223477c0a8fe38e2e853d1d35d"
|
|
113
117
|
}
|