@vercel/microfrontends 0.14.0 → 0.15.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/bin/cli.cjs +377 -1626
- package/dist/config.cjs +460 -1004
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -25
- package/dist/config.js +456 -983
- package/dist/config.js.map +1 -1
- package/dist/{v2/microfrontends → microfrontends}/server.cjs +63 -143
- package/dist/microfrontends/server.cjs.map +1 -0
- package/dist/{v2/microfrontends → microfrontends}/server.d.ts +4 -4
- package/dist/{v2/microfrontends → microfrontends}/server.js +63 -143
- package/dist/microfrontends/server.js.map +1 -0
- package/dist/{v2/microfrontends.cjs → microfrontends.cjs} +21 -21
- package/dist/microfrontends.cjs.map +1 -0
- package/dist/{v2/microfrontends.d.ts → microfrontends.d.ts} +4 -4
- package/dist/{v2/microfrontends.js → microfrontends.js} +20 -20
- package/dist/microfrontends.js.map +1 -0
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +1323 -1024
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +1 -1
- package/dist/next/config.js +1327 -1028
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.cjs +77 -18
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.d.ts +13 -2
- package/dist/next/endpoints.js +77 -18
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +745 -396
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +10 -5
- package/dist/next/middleware.js +745 -396
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +595 -1032
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +14 -12
- package/dist/next/testing.js +589 -1016
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.cjs +40 -108
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.d.ts +24 -2
- package/dist/overrides.js +36 -106
- package/dist/overrides.js.map +1 -1
- package/dist/{v2/routing.cjs → routing.cjs} +3 -3
- package/dist/routing.cjs.map +1 -0
- package/dist/{v2/schema.cjs → schema.cjs} +1 -1
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.ts +1 -0
- package/dist/utils/mfe-port.cjs +211 -1333
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +204 -1326
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +31 -361
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +3 -146
- package/dist/validation.js +30 -359
- package/dist/validation.js.map +1 -1
- package/package.json +29 -92
- package/schema/schema.json +174 -244
- package/dist/config/client.cjs +0 -54
- package/dist/config/client.cjs.map +0 -1
- package/dist/config/client.d.ts +0 -23
- package/dist/config/client.js +0 -28
- package/dist/config/client.js.map +0 -1
- package/dist/config/edge.cjs +0 -508
- package/dist/config/edge.cjs.map +0 -1
- package/dist/config/edge.d.ts +0 -20
- package/dist/config/edge.js +0 -481
- package/dist/config/edge.js.map +0 -1
- package/dist/microfrontend-config-983a5139.d.ts +0 -154
- package/dist/schema-2922d49e.d.ts +0 -182
- package/dist/v2/config.cjs +0 -709
- package/dist/v2/config.cjs.map +0 -1
- package/dist/v2/config.d.ts +0 -4
- package/dist/v2/config.js +0 -684
- package/dist/v2/config.js.map +0 -1
- package/dist/v2/microfrontends/server.cjs.map +0 -1
- package/dist/v2/microfrontends/server.js.map +0 -1
- package/dist/v2/microfrontends.cjs.map +0 -1
- package/dist/v2/microfrontends.js.map +0 -1
- package/dist/v2/next/client.cjs +0 -3
- package/dist/v2/next/client.cjs.map +0 -1
- package/dist/v2/next/client.d.ts +0 -45
- package/dist/v2/next/client.js +0 -3
- package/dist/v2/next/client.js.map +0 -1
- package/dist/v2/next/config.cjs +0 -2178
- package/dist/v2/next/config.cjs.map +0 -1
- package/dist/v2/next/config.d.ts +0 -22
- package/dist/v2/next/config.js +0 -2143
- package/dist/v2/next/config.js.map +0 -1
- package/dist/v2/next/endpoints.cjs +0 -141
- package/dist/v2/next/endpoints.cjs.map +0 -1
- package/dist/v2/next/endpoints.d.ts +0 -26
- package/dist/v2/next/endpoints.js +0 -116
- package/dist/v2/next/endpoints.js.map +0 -1
- package/dist/v2/next/middleware.cjs +0 -1099
- package/dist/v2/next/middleware.cjs.map +0 -1
- package/dist/v2/next/middleware.d.ts +0 -34
- package/dist/v2/next/middleware.js +0 -1071
- package/dist/v2/next/middleware.js.map +0 -1
- package/dist/v2/next/testing.cjs +0 -992
- package/dist/v2/next/testing.cjs.map +0 -1
- package/dist/v2/next/testing.d.ts +0 -55
- package/dist/v2/next/testing.js +0 -961
- package/dist/v2/next/testing.js.map +0 -1
- package/dist/v2/overrides.cjs +0 -75
- package/dist/v2/overrides.cjs.map +0 -1
- package/dist/v2/overrides.d.ts +0 -24
- package/dist/v2/overrides.js +0 -45
- package/dist/v2/overrides.js.map +0 -1
- package/dist/v2/routing.cjs.map +0 -1
- package/dist/v2/schema.cjs.map +0 -1
- package/dist/v2/schema.d.ts +0 -1
- package/schema/schema-v2.json +0 -266
- /package/dist/{v2/routing.d.ts → routing.d.ts} +0 -0
- /package/dist/{v2/routing.js → routing.js} +0 -0
- /package/dist/{v2/routing.js.map → routing.js.map} +0 -0
- /package/dist/{v2/schema.js → schema.js} +0 -0
- /package/dist/{v2/schema.js.map → schema.js.map} +0 -0
package/dist/next/config.cjs
CHANGED
|
@@ -33,33 +33,44 @@ __export(config_exports, {
|
|
|
33
33
|
withMicrofrontends: () => withMicrofrontends
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(config_exports);
|
|
36
|
-
var
|
|
36
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
37
37
|
|
|
38
|
-
// src/config/
|
|
39
|
-
var
|
|
38
|
+
// src/config/microfrontends/server/index.ts
|
|
39
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
40
|
+
var import_node_path8 = require("path");
|
|
40
41
|
|
|
41
|
-
// src/config
|
|
42
|
-
var
|
|
42
|
+
// src/config/overrides/constants.ts
|
|
43
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
44
|
+
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
43
45
|
|
|
44
|
-
// src/config
|
|
45
|
-
|
|
46
|
-
var
|
|
46
|
+
// src/config/overrides/is-override-cookie.ts
|
|
47
|
+
function isOverrideCookie(cookie) {
|
|
48
|
+
var _a;
|
|
49
|
+
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
50
|
+
}
|
|
47
51
|
|
|
48
|
-
// src/
|
|
49
|
-
function
|
|
50
|
-
|
|
52
|
+
// src/config/overrides/get-override-from-cookie.ts
|
|
53
|
+
function getOverrideFromCookie(cookie) {
|
|
54
|
+
if (!isOverrideCookie(cookie) || !cookie.value)
|
|
55
|
+
return;
|
|
56
|
+
return {
|
|
57
|
+
application: cookie.name.replace(OVERRIDES_ENV_COOKIE_PREFIX, ""),
|
|
58
|
+
host: cookie.value
|
|
59
|
+
};
|
|
51
60
|
}
|
|
52
61
|
|
|
53
|
-
// src/config
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
// src/config/overrides/parse-overrides.ts
|
|
63
|
+
function parseOverrides(cookies) {
|
|
64
|
+
const overridesConfig = { applications: {} };
|
|
65
|
+
cookies.forEach((cookie) => {
|
|
66
|
+
const override = getOverrideFromCookie(cookie);
|
|
67
|
+
if (!override)
|
|
68
|
+
return;
|
|
69
|
+
overridesConfig.applications[override.application] = {
|
|
70
|
+
environment: { host: override.host }
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
return overridesConfig;
|
|
63
74
|
}
|
|
64
75
|
|
|
65
76
|
// src/config/errors.ts
|
|
@@ -154,131 +165,268 @@ var MicrofrontendError = class extends Error {
|
|
|
154
165
|
}
|
|
155
166
|
};
|
|
156
167
|
|
|
157
|
-
// src/
|
|
158
|
-
function
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
// src/config/microfrontends-config/utils/get-config-from-env.ts
|
|
169
|
+
function getConfigStringFromEnv() {
|
|
170
|
+
const config = process.env.MFE_CONFIG;
|
|
171
|
+
if (!config) {
|
|
172
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
173
|
+
type: "config",
|
|
174
|
+
subtype: "not_found_in_env"
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return config;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
181
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
182
|
+
|
|
183
|
+
// src/config/schema/utils/is-main-config.ts
|
|
184
|
+
function isMainConfig(c) {
|
|
185
|
+
return !("partOf" in c);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/config/schema/utils/is-default-app.ts
|
|
189
|
+
function isDefaultApp(a) {
|
|
190
|
+
return !("routing" in a);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/config/microfrontends-config/client/index.ts
|
|
194
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
195
|
+
var MicrofrontendConfigClient = class {
|
|
196
|
+
constructor(config, opts) {
|
|
197
|
+
this.pathCache = {};
|
|
198
|
+
this.serialized = config;
|
|
199
|
+
if (opts == null ? void 0 : opts.removeFlaggedPaths) {
|
|
200
|
+
for (const app of Object.values(config.applications)) {
|
|
201
|
+
if (app.routing) {
|
|
202
|
+
app.routing = app.routing.filter((match) => !match.flag);
|
|
203
|
+
}
|
|
173
204
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
205
|
+
}
|
|
206
|
+
this.applications = config.applications;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create a new `MicrofrontendConfigClient` from a JSON string.
|
|
210
|
+
* Config must be passed in to remain framework agnostic
|
|
211
|
+
*/
|
|
212
|
+
static fromEnv(config, opts) {
|
|
213
|
+
if (!config) {
|
|
214
|
+
throw new Error("No microfrontends configuration found");
|
|
215
|
+
}
|
|
216
|
+
return new MicrofrontendConfigClient(
|
|
217
|
+
JSON.parse(config),
|
|
218
|
+
opts
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
isEqual(other) {
|
|
222
|
+
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
223
|
+
}
|
|
224
|
+
getApplicationNameForPath(path5) {
|
|
225
|
+
if (!path5.startsWith("/")) {
|
|
226
|
+
throw new Error(`Path must start with a /`);
|
|
227
|
+
}
|
|
228
|
+
if (this.pathCache[path5]) {
|
|
229
|
+
return this.pathCache[path5];
|
|
230
|
+
}
|
|
231
|
+
const pathname = new URL(path5, "https://example.com").pathname;
|
|
232
|
+
for (const [name, application] of Object.entries(this.applications)) {
|
|
233
|
+
if (application.routing) {
|
|
234
|
+
for (const group of application.routing) {
|
|
235
|
+
for (const childPath of group.paths) {
|
|
236
|
+
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
237
|
+
if (regexp.test(pathname)) {
|
|
238
|
+
this.pathCache[path5] = name;
|
|
239
|
+
return name;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
180
242
|
}
|
|
181
243
|
}
|
|
182
|
-
tag = args.join(options.joinString);
|
|
183
|
-
tag = tag.replace(/\s/g, options.joinString);
|
|
184
|
-
if (options.lowercaseOnly)
|
|
185
|
-
tag = tag.toLowerCase();
|
|
186
|
-
tag = tag.replace(options.regexRemovePattern, (match) => {
|
|
187
|
-
if (match === options.joinString)
|
|
188
|
-
return match;
|
|
189
|
-
return "";
|
|
190
|
-
});
|
|
191
|
-
if (tag.length > options.maxLen)
|
|
192
|
-
tag = tag.substring(0, options.maxLen);
|
|
193
|
-
tag = tag.replace(reJoinString, options.joinString);
|
|
194
|
-
return tag;
|
|
195
244
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
205
|
-
var _Overrides = class {
|
|
206
|
-
constructor(config) {
|
|
207
|
-
this.config = config;
|
|
245
|
+
const defaultApplication = Object.entries(this.applications).find(
|
|
246
|
+
([, application]) => application.default
|
|
247
|
+
);
|
|
248
|
+
if (!defaultApplication) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
this.pathCache[path5] = defaultApplication[0];
|
|
252
|
+
return defaultApplication[0];
|
|
208
253
|
}
|
|
209
|
-
|
|
210
|
-
return
|
|
254
|
+
serialize() {
|
|
255
|
+
return this.serialized;
|
|
211
256
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
260
|
+
var import_path_to_regexp2 = require("path-to-regexp");
|
|
261
|
+
var SUPPORTED_VERSIONS = ["2"];
|
|
262
|
+
var validateConfigVersion = (version) => {
|
|
263
|
+
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
264
|
+
throw new MicrofrontendError(
|
|
265
|
+
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
266
|
+
", "
|
|
267
|
+
)}`,
|
|
268
|
+
{ type: "config", subtype: "unsupported_version" }
|
|
269
|
+
);
|
|
215
270
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return
|
|
220
|
-
zone: cookie.name.replace(_Overrides.overrideEnvCookiePrefix, ""),
|
|
221
|
-
host: cookie.value
|
|
222
|
-
};
|
|
271
|
+
};
|
|
272
|
+
var validateConfigPaths = (applicationConfigsById) => {
|
|
273
|
+
if (!applicationConfigsById) {
|
|
274
|
+
return;
|
|
223
275
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
276
|
+
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
277
|
+
const errors = [];
|
|
278
|
+
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
279
|
+
if (isDefaultApp(app)) {
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
for (const pathMatch of app.routing) {
|
|
283
|
+
for (const path5 of pathMatch.paths) {
|
|
284
|
+
const tokens = (0, import_path_to_regexp2.parse)(path5);
|
|
285
|
+
for (const token of tokens.slice(0, -1)) {
|
|
286
|
+
if (typeof token !== "string") {
|
|
287
|
+
errors.push(
|
|
288
|
+
`Path ${path5} may only have a :wildcard in the last path component`
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const existing = pathsByApplicationId.get(path5);
|
|
293
|
+
if (existing) {
|
|
294
|
+
existing.applications.push(id);
|
|
295
|
+
} else {
|
|
296
|
+
pathsByApplicationId.set(path5, {
|
|
297
|
+
applications: [id],
|
|
298
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
|
|
299
|
+
applicationId: id
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
235
304
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
305
|
+
const entries = Array.from(pathsByApplicationId.entries());
|
|
306
|
+
entries.forEach(([path5, { applications: ids, matcher, applicationId }]) => {
|
|
307
|
+
if (ids.length > 1) {
|
|
308
|
+
errors.push(
|
|
309
|
+
`Duplicate path "${path5}" for applications "${ids.join(", ")}"`
|
|
310
|
+
);
|
|
241
311
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
312
|
+
entries.forEach(
|
|
313
|
+
([
|
|
314
|
+
matchPath,
|
|
315
|
+
{ applications: matchIds, applicationId: matchApplicationId }
|
|
316
|
+
]) => {
|
|
317
|
+
if (path5 === matchPath) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (applicationId === matchApplicationId) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (matcher.test(matchPath)) {
|
|
324
|
+
const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
325
|
+
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
326
|
+
errors.push(
|
|
327
|
+
`Overlapping path detected between ${source} and ${destination}`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
});
|
|
333
|
+
if (errors.length) {
|
|
334
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
335
|
+
type: "config",
|
|
336
|
+
subtype: "conflicting_paths"
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
var validateAppPaths = (name, app) => {
|
|
341
|
+
for (const group of app.routing) {
|
|
342
|
+
for (const p of group.paths) {
|
|
343
|
+
if (p === "/") {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (p.endsWith("/")) {
|
|
347
|
+
throw new MicrofrontendError(
|
|
348
|
+
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
349
|
+
{ type: "application", subtype: "invalid_path" }
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
if (!p.startsWith("/")) {
|
|
353
|
+
throw new MicrofrontendError(
|
|
354
|
+
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
355
|
+
{ type: "application", subtype: "invalid_path" }
|
|
356
|
+
);
|
|
357
|
+
}
|
|
247
358
|
}
|
|
248
|
-
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
249
|
-
return [
|
|
250
|
-
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
251
|
-
microfrontendConfig.getZone(zone).production.host
|
|
252
|
-
];
|
|
253
359
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
)}$`
|
|
259
|
-
).test(domain);
|
|
360
|
+
};
|
|
361
|
+
var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
362
|
+
if (!applicationConfigsById) {
|
|
363
|
+
return;
|
|
260
364
|
}
|
|
261
|
-
|
|
262
|
-
|
|
365
|
+
const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
|
|
366
|
+
([, app]) => !isDefaultApp(app)
|
|
367
|
+
);
|
|
368
|
+
const applicationsWithRoutingNames = applicationsWithRouting.map(
|
|
369
|
+
([key]) => key
|
|
370
|
+
);
|
|
371
|
+
const numApplications = Object.keys(applicationConfigsById).length;
|
|
372
|
+
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
373
|
+
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
374
|
+
if (numApplicationsWithoutRouting === 0) {
|
|
375
|
+
throw new MicrofrontendError(
|
|
376
|
+
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
377
|
+
{ type: "config", subtype: "no_default_application" }
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
if (numApplicationsWithoutRouting > 1) {
|
|
381
|
+
throw new MicrofrontendError(
|
|
382
|
+
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
383
|
+
{ type: "config", subtype: "multiple_default_applications" }
|
|
384
|
+
);
|
|
263
385
|
}
|
|
264
386
|
};
|
|
265
|
-
var Overrides = _Overrides;
|
|
266
|
-
Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
267
387
|
|
|
268
|
-
// src/config/
|
|
388
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
389
|
+
var PREFIX = "vc-ap";
|
|
390
|
+
function generateAssetPrefixFromName({
|
|
391
|
+
name
|
|
392
|
+
}) {
|
|
393
|
+
if (!name) {
|
|
394
|
+
throw new Error("Name is required to generate an asset prefix");
|
|
395
|
+
}
|
|
396
|
+
return `${PREFIX}-${name}`;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-port.ts
|
|
400
|
+
function generatePortFromName({
|
|
401
|
+
name,
|
|
402
|
+
minPort = 3e3,
|
|
403
|
+
maxPort = 8e3
|
|
404
|
+
}) {
|
|
405
|
+
if (!name) {
|
|
406
|
+
throw new Error("Name is required to generate a port");
|
|
407
|
+
}
|
|
408
|
+
let hash = 0;
|
|
409
|
+
for (let i = 0; i < name.length; i++) {
|
|
410
|
+
hash = (hash << 5) - hash + name.charCodeAt(i);
|
|
411
|
+
hash |= 0;
|
|
412
|
+
}
|
|
413
|
+
hash = Math.abs(hash);
|
|
414
|
+
const range = maxPort - minPort;
|
|
415
|
+
const port = minPort + hash % range;
|
|
416
|
+
return port;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/config/microfrontends-config/isomorphic/host.ts
|
|
269
420
|
var Host = class {
|
|
270
|
-
constructor(
|
|
271
|
-
|
|
421
|
+
constructor(hostConfig, options) {
|
|
422
|
+
const { protocol = "https", host, port } = hostConfig;
|
|
423
|
+
this.protocol = protocol;
|
|
272
424
|
this.host = host;
|
|
273
425
|
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
274
|
-
this.
|
|
275
|
-
protocol,
|
|
276
|
-
host,
|
|
277
|
-
...port ? { port } : void 0
|
|
278
|
-
};
|
|
426
|
+
this.local = options == null ? void 0 : options.isLocal;
|
|
279
427
|
}
|
|
280
428
|
isLocal() {
|
|
281
|
-
return this.host === "localhost" || this.host === "127.0.0.1";
|
|
429
|
+
return this.local || this.host === "localhost" || this.host === "127.0.0.1";
|
|
282
430
|
}
|
|
283
431
|
static getPort({
|
|
284
432
|
protocol,
|
|
@@ -304,176 +452,234 @@ var Host = class {
|
|
|
304
452
|
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
305
453
|
return new URL(url);
|
|
306
454
|
}
|
|
307
|
-
|
|
308
|
-
|
|
455
|
+
};
|
|
456
|
+
var LocalHost = class extends Host {
|
|
457
|
+
constructor({
|
|
458
|
+
appName,
|
|
459
|
+
...hostConfig
|
|
460
|
+
}) {
|
|
461
|
+
const host = hostConfig.host ?? "localhost";
|
|
462
|
+
const port = hostConfig.port ?? generatePortFromName({ name: appName });
|
|
463
|
+
const protocol = hostConfig.protocol ?? "http";
|
|
464
|
+
super({ protocol, host, port });
|
|
309
465
|
}
|
|
310
466
|
};
|
|
311
467
|
|
|
312
|
-
// src/config/
|
|
468
|
+
// src/config/microfrontends-config/isomorphic/application.ts
|
|
313
469
|
var Application = class {
|
|
314
470
|
constructor(name, {
|
|
315
471
|
app,
|
|
316
|
-
overrides
|
|
472
|
+
overrides,
|
|
473
|
+
isDefault
|
|
317
474
|
}) {
|
|
318
|
-
|
|
475
|
+
var _a, _b;
|
|
319
476
|
this.name = name;
|
|
320
|
-
this.default = app.default;
|
|
321
|
-
this.routing = app.routing;
|
|
322
477
|
this.development = {
|
|
323
|
-
local: new
|
|
324
|
-
|
|
478
|
+
local: new LocalHost({
|
|
479
|
+
appName: name,
|
|
480
|
+
...(_a = app.development) == null ? void 0 : _a.local
|
|
481
|
+
}),
|
|
482
|
+
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
|
|
325
483
|
};
|
|
326
|
-
this.production = new Host(app.production);
|
|
484
|
+
this.production = app.production ? new Host(app.production) : void 0;
|
|
327
485
|
this.vercel = app.vercel;
|
|
328
486
|
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
329
487
|
environment: new Host(overrides.environment)
|
|
330
488
|
} : void 0;
|
|
489
|
+
this.default = isDefault ?? false;
|
|
490
|
+
this.serialized = app;
|
|
331
491
|
}
|
|
332
492
|
isDefault() {
|
|
333
493
|
return this.default;
|
|
334
494
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (((_b = (_a = app.routing) == null ? void 0 : _a.assetPrefix) == null ? void 0 : _b.startsWith("/")) || ((_d = (_c = app.routing) == null ? void 0 : _c.assetPrefix) == null ? void 0 : _d.endsWith("/"))) {
|
|
338
|
-
throw new MicrofrontendError(
|
|
339
|
-
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
340
|
-
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
341
|
-
);
|
|
342
|
-
}
|
|
343
|
-
for (const group of ((_e = app.routing) == null ? void 0 : _e.matches) ?? []) {
|
|
344
|
-
for (const p of group.paths) {
|
|
345
|
-
if (p === "/") {
|
|
346
|
-
continue;
|
|
347
|
-
}
|
|
348
|
-
if (p.endsWith("/")) {
|
|
349
|
-
throw new MicrofrontendError(
|
|
350
|
-
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
351
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
if (!p.startsWith("/")) {
|
|
355
|
-
throw new MicrofrontendError(
|
|
356
|
-
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
357
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
495
|
+
getAssetPrefix() {
|
|
496
|
+
return generateAssetPrefixFromName({ name: this.name });
|
|
362
497
|
}
|
|
363
498
|
serialize() {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
499
|
+
return this.serialized;
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
var DefaultApplication = class extends Application {
|
|
503
|
+
constructor(name, {
|
|
504
|
+
app,
|
|
505
|
+
overrides
|
|
506
|
+
}) {
|
|
507
|
+
super(name, {
|
|
508
|
+
app,
|
|
509
|
+
overrides,
|
|
510
|
+
isDefault: true
|
|
511
|
+
});
|
|
512
|
+
this.default = true;
|
|
513
|
+
this.production = new Host(app.production);
|
|
514
|
+
}
|
|
515
|
+
getAssetPrefix() {
|
|
516
|
+
return "";
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
var ChildApplication = class extends Application {
|
|
520
|
+
constructor(name, {
|
|
521
|
+
app,
|
|
522
|
+
overrides
|
|
523
|
+
}) {
|
|
524
|
+
ChildApplication.validate(name, app);
|
|
525
|
+
super(name, {
|
|
526
|
+
app,
|
|
527
|
+
overrides,
|
|
528
|
+
isDefault: false
|
|
529
|
+
});
|
|
530
|
+
this.default = false;
|
|
531
|
+
this.routing = app.routing;
|
|
532
|
+
}
|
|
533
|
+
static validate(name, app) {
|
|
534
|
+
validateAppPaths(name, app);
|
|
386
535
|
}
|
|
387
536
|
};
|
|
388
537
|
|
|
389
|
-
// src/config/
|
|
390
|
-
var SUPPORTED_VERSIONS = ["1"];
|
|
538
|
+
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
391
539
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
392
|
-
|
|
540
|
+
|
|
541
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
542
|
+
var MicrofrontendConfigIsomorphic = class {
|
|
393
543
|
constructor({
|
|
394
544
|
config,
|
|
395
|
-
overrides
|
|
545
|
+
overrides,
|
|
546
|
+
meta
|
|
396
547
|
}) {
|
|
397
|
-
this.
|
|
398
|
-
var _a, _b, _c;
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
548
|
+
this.childApplications = {};
|
|
549
|
+
var _a, _b, _c, _d;
|
|
550
|
+
MicrofrontendConfigIsomorphic.validate(config);
|
|
551
|
+
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
552
|
+
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
553
|
+
this.isMainConfig = isMainConfig(config);
|
|
554
|
+
if (isMainConfig(config)) {
|
|
555
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
556
|
+
const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
|
|
557
|
+
if (isDefaultApp(appConfig)) {
|
|
558
|
+
this.defaultApplication = new DefaultApplication(appId, {
|
|
559
|
+
app: appConfig,
|
|
560
|
+
overrides: appOverrides
|
|
561
|
+
});
|
|
562
|
+
} else {
|
|
563
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
564
|
+
app: appConfig,
|
|
565
|
+
overrides: appOverrides
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
} else {
|
|
570
|
+
this.partOf = config.partOf;
|
|
571
|
+
const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
|
|
572
|
+
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
573
|
+
meta.fromApp,
|
|
574
|
+
{
|
|
575
|
+
// we don't know routing because we're not in the main config
|
|
576
|
+
app: { routing: [] },
|
|
577
|
+
overrides: appOverrides
|
|
578
|
+
}
|
|
405
579
|
);
|
|
406
580
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
581
|
+
if (isMainConfig(config) && !this.defaultApplication) {
|
|
582
|
+
throw new MicrofrontendError(
|
|
583
|
+
`Could not find default application in microfrontends configuration`,
|
|
584
|
+
{
|
|
585
|
+
type: "application",
|
|
586
|
+
subtype: "not_found"
|
|
587
|
+
}
|
|
588
|
+
);
|
|
414
589
|
}
|
|
415
590
|
this.config = config;
|
|
416
|
-
this.name = config.name;
|
|
417
|
-
this.version = config.version;
|
|
418
591
|
this.options = config.options;
|
|
419
|
-
this
|
|
592
|
+
this.serialized = {
|
|
593
|
+
config,
|
|
594
|
+
overrides,
|
|
595
|
+
meta
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
static validate(config) {
|
|
599
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
600
|
+
if (isMainConfig(c)) {
|
|
601
|
+
validateConfigVersion(c.version);
|
|
602
|
+
validateConfigPaths(c.applications);
|
|
603
|
+
validateConfigDefaultApplication(c.applications);
|
|
604
|
+
}
|
|
605
|
+
return c;
|
|
606
|
+
}
|
|
607
|
+
static fromEnv({
|
|
608
|
+
meta,
|
|
609
|
+
cookies
|
|
610
|
+
}) {
|
|
611
|
+
return new MicrofrontendConfigIsomorphic({
|
|
612
|
+
config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
|
|
613
|
+
overrides: parseOverrides(cookies ?? []),
|
|
614
|
+
meta
|
|
615
|
+
});
|
|
420
616
|
}
|
|
421
617
|
isOverridesDisabled() {
|
|
422
618
|
var _a, _b;
|
|
423
619
|
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
424
620
|
}
|
|
425
|
-
static getConfigFromEnv() {
|
|
426
|
-
const config = process.env.MFE_CONFIG;
|
|
427
|
-
if (!config) {
|
|
428
|
-
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
429
|
-
type: "config",
|
|
430
|
-
subtype: "not_found_in_env"
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
return config;
|
|
434
|
-
}
|
|
435
|
-
static fromEnv(_) {
|
|
436
|
-
throw new Error("Not implemented");
|
|
437
|
-
}
|
|
438
621
|
getConfig() {
|
|
439
622
|
return this.config;
|
|
440
623
|
}
|
|
624
|
+
getApplicationsByType() {
|
|
625
|
+
return {
|
|
626
|
+
defaultApplication: this.defaultApplication,
|
|
627
|
+
applications: Object.values(this.childApplications)
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
getChildApplications() {
|
|
631
|
+
return Object.values(this.childApplications);
|
|
632
|
+
}
|
|
441
633
|
getAllApplications() {
|
|
442
|
-
return
|
|
634
|
+
return [
|
|
635
|
+
this.defaultApplication,
|
|
636
|
+
...Object.values(this.childApplications)
|
|
637
|
+
].filter(Boolean);
|
|
443
638
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
if (
|
|
639
|
+
getApplication(name) {
|
|
640
|
+
var _a;
|
|
641
|
+
if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
|
|
642
|
+
return this.defaultApplication;
|
|
643
|
+
}
|
|
644
|
+
const app = this.childApplications[name];
|
|
645
|
+
if (!app) {
|
|
447
646
|
throw new MicrofrontendError(
|
|
448
647
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
449
648
|
{
|
|
450
|
-
type: "
|
|
649
|
+
type: "application",
|
|
451
650
|
subtype: "not_found"
|
|
452
651
|
}
|
|
453
652
|
);
|
|
454
653
|
}
|
|
455
|
-
return
|
|
654
|
+
return app;
|
|
456
655
|
}
|
|
457
656
|
getApplicationByProjectId(projectId) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
657
|
+
var _a, _b;
|
|
658
|
+
if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
|
|
659
|
+
return this.defaultApplication;
|
|
660
|
+
}
|
|
661
|
+
return Object.values(this.childApplications).find(
|
|
662
|
+
(app) => {
|
|
663
|
+
var _a2;
|
|
664
|
+
return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
|
|
462
665
|
}
|
|
463
666
|
);
|
|
464
667
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
668
|
+
/**
|
|
669
|
+
* Returns the default application. This can throw if the default application
|
|
670
|
+
* is undefined ( )
|
|
671
|
+
*/
|
|
672
|
+
getDefaultApplication() {
|
|
673
|
+
if (!this.defaultApplication) {
|
|
468
674
|
throw new MicrofrontendError(
|
|
469
|
-
`Could not find default
|
|
675
|
+
`Could not find default application in microfrontends configuration`,
|
|
470
676
|
{
|
|
471
|
-
type: "
|
|
677
|
+
type: "application",
|
|
472
678
|
subtype: "not_found"
|
|
473
679
|
}
|
|
474
680
|
);
|
|
475
681
|
}
|
|
476
|
-
return
|
|
682
|
+
return this.defaultApplication;
|
|
477
683
|
}
|
|
478
684
|
/**
|
|
479
685
|
* Returns the configured port for the local proxy
|
|
@@ -488,671 +694,801 @@ var MicrofrontendConfigCommon = class {
|
|
|
488
694
|
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
489
695
|
*/
|
|
490
696
|
toSchemaJson() {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
697
|
+
return this.serialized.config;
|
|
698
|
+
}
|
|
699
|
+
toClientConfig() {
|
|
700
|
+
const applications = Object.fromEntries(
|
|
701
|
+
Object.entries(this.childApplications).map(([name, application]) => [
|
|
702
|
+
name,
|
|
703
|
+
{
|
|
704
|
+
default: false,
|
|
705
|
+
routing: application.routing
|
|
706
|
+
}
|
|
707
|
+
])
|
|
708
|
+
);
|
|
709
|
+
if (this.defaultApplication) {
|
|
710
|
+
applications[this.defaultApplication.name] = {
|
|
711
|
+
default: true
|
|
712
|
+
};
|
|
494
713
|
}
|
|
495
|
-
return {
|
|
496
|
-
$schema: this.$schema,
|
|
497
|
-
name: this.name,
|
|
498
|
-
version: this.version,
|
|
499
|
-
options: this.options,
|
|
714
|
+
return new MicrofrontendConfigClient({
|
|
500
715
|
applications
|
|
501
|
-
};
|
|
716
|
+
});
|
|
502
717
|
}
|
|
503
718
|
serialize() {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
719
|
+
return this.serialized;
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
// src/config/microfrontends-config/isomorphic/child.ts
|
|
724
|
+
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
725
|
+
constructor({
|
|
726
|
+
config,
|
|
727
|
+
overrides,
|
|
728
|
+
meta
|
|
729
|
+
}) {
|
|
730
|
+
super({ config, overrides, meta });
|
|
731
|
+
this.isMainConfig = false;
|
|
732
|
+
this.partOf = config.partOf;
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
// src/config/microfrontends-config/isomorphic/main.ts
|
|
737
|
+
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
738
|
+
constructor({
|
|
739
|
+
config,
|
|
740
|
+
overrides,
|
|
741
|
+
meta
|
|
742
|
+
}) {
|
|
743
|
+
var _a, _b, _c;
|
|
744
|
+
super({ config, overrides, meta });
|
|
745
|
+
this.isMainConfig = true;
|
|
746
|
+
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
747
|
+
let defaultApplication;
|
|
748
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
749
|
+
const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
|
|
750
|
+
if (isDefaultApp(appConfig)) {
|
|
751
|
+
defaultApplication = new DefaultApplication(appId, {
|
|
752
|
+
app: appConfig,
|
|
753
|
+
overrides: appOverrides
|
|
754
|
+
});
|
|
755
|
+
} else {
|
|
756
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
757
|
+
app: appConfig,
|
|
758
|
+
overrides: appOverrides
|
|
759
|
+
});
|
|
760
|
+
}
|
|
508
761
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
762
|
+
if (!defaultApplication) {
|
|
763
|
+
throw new MicrofrontendError(
|
|
764
|
+
`Could not find default application in microfrontends configuration`,
|
|
765
|
+
{
|
|
766
|
+
type: "application",
|
|
767
|
+
subtype: "not_found"
|
|
768
|
+
}
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
this.defaultApplication = defaultApplication;
|
|
519
772
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
// src/config/microfrontends/isomorphic/index.ts
|
|
776
|
+
var Microfrontends = class {
|
|
777
|
+
constructor({
|
|
778
|
+
config,
|
|
779
|
+
overrides,
|
|
780
|
+
meta
|
|
781
|
+
}) {
|
|
782
|
+
if (isMainConfig(config)) {
|
|
783
|
+
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
784
|
+
} else {
|
|
785
|
+
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
isChildConfig() {
|
|
789
|
+
return this.config instanceof MicrofrontendChildConfig;
|
|
790
|
+
}
|
|
791
|
+
static fromEnv({
|
|
792
|
+
cookies,
|
|
793
|
+
meta
|
|
794
|
+
}) {
|
|
795
|
+
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
796
|
+
cookies,
|
|
797
|
+
meta
|
|
798
|
+
});
|
|
799
|
+
return new Microfrontends(config.serialize());
|
|
525
800
|
}
|
|
526
801
|
};
|
|
527
802
|
|
|
528
|
-
// src/config/utils/
|
|
529
|
-
var
|
|
803
|
+
// src/config/microfrontends/utils/find-repository-root.ts
|
|
804
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
805
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
806
|
+
var GIT_DIRECTORY = ".git";
|
|
807
|
+
function findRepositoryRoot(startDir) {
|
|
808
|
+
let currentDir = startDir || process.cwd();
|
|
809
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
810
|
+
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
811
|
+
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
812
|
+
return currentDir;
|
|
813
|
+
}
|
|
814
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
815
|
+
}
|
|
816
|
+
throw new Error(
|
|
817
|
+
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// src/config/microfrontends/utils/find-package-path.ts
|
|
822
|
+
var import_node_path2 = require("path");
|
|
823
|
+
var import_node_fs2 = require("fs");
|
|
824
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
825
|
+
var configCache = {};
|
|
826
|
+
function findPackagePathWithGlob({
|
|
827
|
+
repositoryRoot,
|
|
828
|
+
name
|
|
829
|
+
}) {
|
|
830
|
+
try {
|
|
831
|
+
const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
|
|
832
|
+
cwd: repositoryRoot,
|
|
833
|
+
absolute: true,
|
|
834
|
+
onlyFiles: true,
|
|
835
|
+
followSymbolicLinks: false,
|
|
836
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
837
|
+
});
|
|
838
|
+
const matchingPaths = [];
|
|
839
|
+
for (const packageJsonPath2 of packageJsonPaths) {
|
|
840
|
+
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
841
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
842
|
+
if (packageJson.name === name) {
|
|
843
|
+
matchingPaths.push(packageJsonPath2);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (matchingPaths.length > 1) {
|
|
847
|
+
throw new Error(
|
|
848
|
+
`Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
if (matchingPaths.length === 0) {
|
|
852
|
+
throw new Error(
|
|
853
|
+
`Could not find package with the name "${name}" in the repository`
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
const [packageJsonPath] = matchingPaths;
|
|
857
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
858
|
+
} catch (error) {
|
|
859
|
+
return null;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function findPackagePath(opts) {
|
|
863
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
|
|
864
|
+
if (configCache[cacheKey]) {
|
|
865
|
+
return configCache[cacheKey];
|
|
866
|
+
}
|
|
867
|
+
const result = findPackagePathWithGlob(opts);
|
|
868
|
+
if (!result) {
|
|
869
|
+
throw new Error(
|
|
870
|
+
`Could not find package with the name "${opts.name}" in the repository`
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
configCache[cacheKey] = result;
|
|
874
|
+
return result;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
878
|
+
var import_node_path3 = require("path");
|
|
879
|
+
var import_node_fs3 = require("fs");
|
|
880
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
881
|
+
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
530
882
|
|
|
531
883
|
// src/config/constants.ts
|
|
532
|
-
var
|
|
533
|
-
|
|
884
|
+
var CONFIGURATION_FILENAMES = [
|
|
885
|
+
"microfrontends.jsonc",
|
|
886
|
+
"microfrontends.json"
|
|
887
|
+
];
|
|
888
|
+
|
|
889
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
890
|
+
var configCache2 = {};
|
|
891
|
+
function findDefaultMicrofrontendsPackages({
|
|
892
|
+
repositoryRoot,
|
|
893
|
+
applicationName
|
|
894
|
+
}) {
|
|
895
|
+
try {
|
|
896
|
+
const microfrontendsJsonPaths = import_fast_glob2.default.globSync(
|
|
897
|
+
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
898
|
+
{
|
|
899
|
+
cwd: repositoryRoot,
|
|
900
|
+
absolute: true,
|
|
901
|
+
onlyFiles: true,
|
|
902
|
+
followSymbolicLinks: false,
|
|
903
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
904
|
+
}
|
|
905
|
+
);
|
|
906
|
+
const matchingPaths = [];
|
|
907
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
908
|
+
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
909
|
+
microfrontendsJsonPath,
|
|
910
|
+
"utf-8"
|
|
911
|
+
);
|
|
912
|
+
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
913
|
+
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
914
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (matchingPaths.length > 1) {
|
|
918
|
+
throw new Error(
|
|
919
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
|
|
920
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
if (matchingPaths.length === 0) {
|
|
924
|
+
throw new Error(
|
|
925
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
const [packageJsonPath] = matchingPaths;
|
|
929
|
+
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
930
|
+
} catch (error) {
|
|
931
|
+
return null;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
935
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
936
|
+
if (configCache2[cacheKey]) {
|
|
937
|
+
return configCache2[cacheKey];
|
|
938
|
+
}
|
|
939
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
940
|
+
if (!result) {
|
|
941
|
+
throw new Error(
|
|
942
|
+
`Error trying to resolve the main microfrontends configuration`
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
configCache2[cacheKey] = result;
|
|
946
|
+
return result;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// src/config/microfrontends/utils/is-monorepo.ts
|
|
950
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
951
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
952
|
+
function isMonorepo({
|
|
953
|
+
repositoryRoot
|
|
954
|
+
}) {
|
|
955
|
+
try {
|
|
956
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
957
|
+
return true;
|
|
958
|
+
}
|
|
959
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
960
|
+
return true;
|
|
961
|
+
}
|
|
962
|
+
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
963
|
+
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
964
|
+
return false;
|
|
965
|
+
}
|
|
966
|
+
const packageJson = JSON.parse(
|
|
967
|
+
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
968
|
+
);
|
|
969
|
+
return packageJson.workspaces !== void 0;
|
|
970
|
+
} catch (error) {
|
|
971
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
534
975
|
|
|
535
|
-
// src/config/utils/
|
|
536
|
-
|
|
976
|
+
// src/config/microfrontends/utils/find-package-root.ts
|
|
977
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
978
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
979
|
+
var PACKAGE_JSON = "package.json";
|
|
980
|
+
function findPackageRoot(startDir) {
|
|
981
|
+
let currentDir = startDir || process.cwd();
|
|
982
|
+
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
983
|
+
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
984
|
+
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
985
|
+
return currentDir;
|
|
986
|
+
}
|
|
987
|
+
currentDir = import_node_path5.default.dirname(currentDir);
|
|
988
|
+
}
|
|
989
|
+
throw new Error(
|
|
990
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
995
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
996
|
+
var import_node_path6 = require("path");
|
|
997
|
+
function findConfig({ dir }) {
|
|
998
|
+
for (const filename of CONFIGURATION_FILENAMES) {
|
|
999
|
+
const maybeConfig = (0, import_node_path6.join)(dir, filename);
|
|
1000
|
+
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
1001
|
+
return maybeConfig;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return null;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1008
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1009
|
+
|
|
1010
|
+
// src/config/microfrontends/server/constants.ts
|
|
1011
|
+
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
1012
|
+
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
1013
|
+
|
|
1014
|
+
// src/utils/is-vercel.ts
|
|
1015
|
+
function isVercel() {
|
|
1016
|
+
return process.env.VERCEL === "1";
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1020
|
+
function getOutputFilePath() {
|
|
537
1021
|
if (isVercel()) {
|
|
538
|
-
return
|
|
1022
|
+
return import_node_path7.default.join(
|
|
539
1023
|
".vercel",
|
|
540
|
-
|
|
541
|
-
|
|
1024
|
+
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
1025
|
+
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
542
1026
|
);
|
|
543
1027
|
}
|
|
544
|
-
return
|
|
1028
|
+
return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
545
1029
|
}
|
|
546
1030
|
|
|
547
|
-
// src/config/validation.ts
|
|
548
|
-
var
|
|
549
|
-
var import_path_to_regexp = require("path-to-regexp");
|
|
1031
|
+
// src/config/microfrontends/server/validation.ts
|
|
1032
|
+
var import_jsonc_parser3 = require("jsonc-parser");
|
|
550
1033
|
var import_ajv = require("ajv");
|
|
551
1034
|
|
|
552
|
-
// src/config/types.ts
|
|
553
|
-
var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
|
|
554
|
-
|
|
555
1035
|
// schema/schema.json
|
|
556
1036
|
var schema_default = {
|
|
557
1037
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
558
1038
|
$ref: "#/definitions/Config",
|
|
559
1039
|
definitions: {
|
|
560
1040
|
Config: {
|
|
1041
|
+
anyOf: [
|
|
1042
|
+
{
|
|
1043
|
+
$ref: "#/definitions/MainConfig"
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
$ref: "#/definitions/ChildConfig"
|
|
1047
|
+
}
|
|
1048
|
+
]
|
|
1049
|
+
},
|
|
1050
|
+
MainConfig: {
|
|
561
1051
|
type: "object",
|
|
562
1052
|
properties: {
|
|
563
|
-
version: {
|
|
564
|
-
type: "string"
|
|
565
|
-
},
|
|
566
1053
|
$schema: {
|
|
567
1054
|
type: "string"
|
|
568
1055
|
},
|
|
569
|
-
|
|
1056
|
+
version: {
|
|
570
1057
|
type: "string",
|
|
571
|
-
|
|
1058
|
+
const: "2"
|
|
1059
|
+
},
|
|
1060
|
+
options: {
|
|
1061
|
+
$ref: "#/definitions/Options"
|
|
1062
|
+
},
|
|
1063
|
+
remotes: {
|
|
1064
|
+
type: "object",
|
|
1065
|
+
additionalProperties: {
|
|
1066
|
+
$ref: "#/definitions/Application"
|
|
1067
|
+
},
|
|
1068
|
+
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
572
1069
|
},
|
|
573
1070
|
applications: {
|
|
574
|
-
$ref: "#/definitions/
|
|
1071
|
+
$ref: "#/definitions/ApplicationRouting",
|
|
1072
|
+
description: "Mapping of application names to the routes that they host. Only needs to be defined in the application that owns the primary microfrontend domain"
|
|
1073
|
+
}
|
|
1074
|
+
},
|
|
1075
|
+
required: ["applications", "version"],
|
|
1076
|
+
additionalProperties: false
|
|
1077
|
+
},
|
|
1078
|
+
Options: {
|
|
1079
|
+
type: "object",
|
|
1080
|
+
properties: {
|
|
1081
|
+
vercel: {
|
|
1082
|
+
$ref: "#/definitions/VercelOptions",
|
|
1083
|
+
description: "Micro-Frontends wide options for Vercel."
|
|
575
1084
|
},
|
|
576
|
-
|
|
577
|
-
$ref: "#/definitions/
|
|
578
|
-
description: "
|
|
1085
|
+
localProxy: {
|
|
1086
|
+
$ref: "#/definitions/LocalProxyOptions",
|
|
1087
|
+
description: "Options for local proxy."
|
|
579
1088
|
}
|
|
580
1089
|
},
|
|
581
|
-
|
|
582
|
-
description: "Configuration for micro-frontend applications\n\nTODO: Add proxy configuration"
|
|
1090
|
+
additionalProperties: false
|
|
583
1091
|
},
|
|
584
|
-
|
|
1092
|
+
VercelOptions: {
|
|
585
1093
|
type: "object",
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
1094
|
+
properties: {
|
|
1095
|
+
teamSlug: {
|
|
1096
|
+
type: "string",
|
|
1097
|
+
description: "Team slug for the Vercel team"
|
|
1098
|
+
},
|
|
1099
|
+
disableOverrides: {
|
|
1100
|
+
type: "boolean",
|
|
1101
|
+
description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
|
|
1102
|
+
}
|
|
1103
|
+
},
|
|
1104
|
+
additionalProperties: false
|
|
589
1105
|
},
|
|
590
|
-
|
|
1106
|
+
LocalProxyOptions: {
|
|
1107
|
+
type: "object",
|
|
1108
|
+
properties: {
|
|
1109
|
+
port: {
|
|
1110
|
+
type: "number",
|
|
1111
|
+
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
1112
|
+
}
|
|
1113
|
+
},
|
|
1114
|
+
additionalProperties: false
|
|
1115
|
+
},
|
|
1116
|
+
Application: {
|
|
591
1117
|
anyOf: [
|
|
592
1118
|
{
|
|
593
|
-
$ref: "#/definitions/
|
|
1119
|
+
$ref: "#/definitions/DefaultApplication"
|
|
594
1120
|
},
|
|
595
1121
|
{
|
|
596
|
-
$ref: "#/definitions/
|
|
1122
|
+
$ref: "#/definitions/ChildApplication"
|
|
597
1123
|
}
|
|
598
|
-
]
|
|
599
|
-
description: "A Micro-Frontend Deployment Target"
|
|
1124
|
+
]
|
|
600
1125
|
},
|
|
601
|
-
|
|
1126
|
+
DefaultApplication: {
|
|
602
1127
|
type: "object",
|
|
603
1128
|
properties: {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const: true,
|
|
607
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
608
|
-
},
|
|
609
|
-
routing: {
|
|
610
|
-
$ref: "#/definitions/Routing"
|
|
1129
|
+
vercel: {
|
|
1130
|
+
$ref: "#/definitions/Vercel"
|
|
611
1131
|
},
|
|
612
1132
|
development: {
|
|
613
|
-
|
|
614
|
-
properties: {
|
|
615
|
-
local: {
|
|
616
|
-
$ref: "#/definitions/HostConfig"
|
|
617
|
-
},
|
|
618
|
-
fallback: {
|
|
619
|
-
$ref: "#/definitions/HostConfig",
|
|
620
|
-
description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error."
|
|
621
|
-
},
|
|
622
|
-
task: {
|
|
623
|
-
type: "string",
|
|
624
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
625
|
-
}
|
|
626
|
-
},
|
|
627
|
-
required: ["local"]
|
|
1133
|
+
$ref: "#/definitions/Development"
|
|
628
1134
|
},
|
|
629
1135
|
production: {
|
|
630
1136
|
$ref: "#/definitions/HostConfig"
|
|
631
|
-
},
|
|
632
|
-
metadata: {
|
|
633
|
-
type: "object",
|
|
634
|
-
additionalProperties: {
|
|
635
|
-
type: "string"
|
|
636
|
-
}
|
|
637
|
-
},
|
|
638
|
-
federation: {
|
|
639
|
-
type: "object",
|
|
640
|
-
properties: {
|
|
641
|
-
exposes: {
|
|
642
|
-
type: "array",
|
|
643
|
-
items: {
|
|
644
|
-
type: "object",
|
|
645
|
-
properties: {
|
|
646
|
-
name: {
|
|
647
|
-
type: "string",
|
|
648
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
649
|
-
},
|
|
650
|
-
path: {
|
|
651
|
-
type: "string",
|
|
652
|
-
description: "Relative path to the module within its `application`"
|
|
653
|
-
}
|
|
654
|
-
},
|
|
655
|
-
required: ["name", "path"]
|
|
656
|
-
},
|
|
657
|
-
description: "Modules that are exposed by this application"
|
|
658
|
-
},
|
|
659
|
-
uses: {
|
|
660
|
-
type: "array",
|
|
661
|
-
items: {
|
|
662
|
-
type: "string"
|
|
663
|
-
},
|
|
664
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
},
|
|
668
|
-
vercel: {
|
|
669
|
-
$ref: "#/definitions/Vercel"
|
|
670
1137
|
}
|
|
671
1138
|
},
|
|
672
|
-
required: ["
|
|
1139
|
+
required: ["production"],
|
|
1140
|
+
additionalProperties: false
|
|
673
1141
|
},
|
|
674
|
-
|
|
1142
|
+
Vercel: {
|
|
675
1143
|
type: "object",
|
|
676
1144
|
properties: {
|
|
677
|
-
|
|
1145
|
+
projectId: {
|
|
678
1146
|
type: "string",
|
|
679
|
-
description: "
|
|
680
|
-
},
|
|
681
|
-
matches: {
|
|
682
|
-
type: "array",
|
|
683
|
-
items: {
|
|
684
|
-
$ref: "#/definitions/PathGroup"
|
|
685
|
-
},
|
|
686
|
-
description: "Path expressions that are routed to this application."
|
|
1147
|
+
description: "Vercel project ID"
|
|
687
1148
|
}
|
|
688
1149
|
},
|
|
689
|
-
required: ["
|
|
1150
|
+
required: ["projectId"],
|
|
1151
|
+
additionalProperties: false
|
|
690
1152
|
},
|
|
691
|
-
|
|
1153
|
+
Development: {
|
|
692
1154
|
type: "object",
|
|
693
1155
|
properties: {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
description: "Optional group name for the paths"
|
|
1156
|
+
local: {
|
|
1157
|
+
$ref: "#/definitions/LocalHostConfig"
|
|
697
1158
|
},
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
flag: {
|
|
702
|
-
type: "string",
|
|
703
|
-
description: "flag name that can be used to enable/disable all paths in the group"
|
|
704
|
-
}
|
|
705
|
-
}
|
|
1159
|
+
fallback: {
|
|
1160
|
+
$ref: "#/definitions/HostConfig",
|
|
1161
|
+
description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error."
|
|
706
1162
|
},
|
|
707
|
-
|
|
708
|
-
type: "
|
|
709
|
-
|
|
710
|
-
type: "string"
|
|
711
|
-
}
|
|
1163
|
+
task: {
|
|
1164
|
+
type: "string",
|
|
1165
|
+
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
712
1166
|
}
|
|
713
1167
|
},
|
|
714
|
-
|
|
1168
|
+
additionalProperties: false
|
|
715
1169
|
},
|
|
716
|
-
|
|
1170
|
+
LocalHostConfig: {
|
|
717
1171
|
type: "object",
|
|
1172
|
+
additionalProperties: false,
|
|
718
1173
|
properties: {
|
|
719
|
-
protocol: {
|
|
720
|
-
type: "string",
|
|
721
|
-
enum: ["http", "https"],
|
|
722
|
-
description: 'The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n* @defaultValue "https"'
|
|
723
|
-
},
|
|
724
1174
|
host: {
|
|
725
1175
|
type: "string",
|
|
726
1176
|
description: "The hostname or IP address of the server. This can be a domain name (e.g., `example.com`) or an IP address (e.g., `192.168.1.1`)."
|
|
727
1177
|
},
|
|
1178
|
+
protocol: {
|
|
1179
|
+
type: "string",
|
|
1180
|
+
enum: ["http", "https"],
|
|
1181
|
+
description: 'The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n* @defaultValue "http" for local development, "https" for otherwise'
|
|
1182
|
+
},
|
|
728
1183
|
port: {
|
|
729
1184
|
type: "number",
|
|
730
|
-
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS
|
|
1185
|
+
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
731
1186
|
}
|
|
732
|
-
}
|
|
733
|
-
required: ["host"]
|
|
1187
|
+
}
|
|
734
1188
|
},
|
|
735
|
-
|
|
1189
|
+
HostConfig: {
|
|
736
1190
|
type: "object",
|
|
737
1191
|
properties: {
|
|
738
|
-
|
|
739
|
-
type: "string",
|
|
740
|
-
description: "Vercel project ID"
|
|
741
|
-
},
|
|
742
|
-
projectName: {
|
|
1192
|
+
protocol: {
|
|
743
1193
|
type: "string",
|
|
744
|
-
|
|
1194
|
+
enum: ["http", "https"],
|
|
1195
|
+
description: 'The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n* @defaultValue "http" for local development, "https" for otherwise'
|
|
745
1196
|
},
|
|
746
|
-
|
|
1197
|
+
host: {
|
|
747
1198
|
type: "string",
|
|
748
|
-
description: "The
|
|
1199
|
+
description: "The hostname or IP address of the server. This can be a domain name (e.g., `example.com`) or an IP address (e.g., `192.168.1.1`)."
|
|
749
1200
|
},
|
|
750
|
-
|
|
751
|
-
type: "
|
|
752
|
-
description: "
|
|
1201
|
+
port: {
|
|
1202
|
+
type: "number",
|
|
1203
|
+
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
753
1204
|
}
|
|
754
1205
|
},
|
|
755
|
-
required: ["
|
|
1206
|
+
required: ["host"],
|
|
1207
|
+
additionalProperties: false
|
|
756
1208
|
},
|
|
757
|
-
|
|
1209
|
+
ChildApplication: {
|
|
758
1210
|
type: "object",
|
|
759
1211
|
properties: {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
const: false,
|
|
763
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
764
|
-
},
|
|
765
|
-
routing: {
|
|
766
|
-
$ref: "#/definitions/Routing"
|
|
1212
|
+
vercel: {
|
|
1213
|
+
$ref: "#/definitions/Vercel"
|
|
767
1214
|
},
|
|
768
1215
|
development: {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
fallback: {
|
|
775
|
-
$ref: "#/definitions/HostConfig",
|
|
776
|
-
description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error."
|
|
777
|
-
},
|
|
778
|
-
task: {
|
|
779
|
-
type: "string",
|
|
780
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
781
|
-
}
|
|
782
|
-
},
|
|
783
|
-
required: ["local"]
|
|
1216
|
+
$ref: "#/definitions/Development"
|
|
1217
|
+
},
|
|
1218
|
+
routing: {
|
|
1219
|
+
$ref: "#/definitions/Routing",
|
|
1220
|
+
description: "Groups of path expressions that are routed to this application."
|
|
784
1221
|
},
|
|
785
1222
|
production: {
|
|
786
1223
|
$ref: "#/definitions/HostConfig"
|
|
787
|
-
},
|
|
788
|
-
metadata: {
|
|
789
|
-
type: "object",
|
|
790
|
-
additionalProperties: {
|
|
791
|
-
type: "string"
|
|
792
|
-
}
|
|
793
|
-
},
|
|
794
|
-
federation: {
|
|
795
|
-
type: "object",
|
|
796
|
-
properties: {
|
|
797
|
-
exposes: {
|
|
798
|
-
type: "array",
|
|
799
|
-
items: {
|
|
800
|
-
type: "object",
|
|
801
|
-
properties: {
|
|
802
|
-
name: {
|
|
803
|
-
type: "string",
|
|
804
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
805
|
-
},
|
|
806
|
-
path: {
|
|
807
|
-
type: "string",
|
|
808
|
-
description: "Relative path to the module within its `application`"
|
|
809
|
-
}
|
|
810
|
-
},
|
|
811
|
-
required: ["name", "path"]
|
|
812
|
-
},
|
|
813
|
-
description: "Modules that are exposed by this application"
|
|
814
|
-
},
|
|
815
|
-
uses: {
|
|
816
|
-
type: "array",
|
|
817
|
-
items: {
|
|
818
|
-
type: "string"
|
|
819
|
-
},
|
|
820
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
},
|
|
824
|
-
vercel: {
|
|
825
|
-
$ref: "#/definitions/Vercel"
|
|
826
1224
|
}
|
|
827
1225
|
},
|
|
828
|
-
required: ["
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
description: "Micro-Frontends wide options for Vercel."
|
|
836
|
-
},
|
|
837
|
-
localProxy: {
|
|
838
|
-
$ref: "#/definitions/LocalProxyOptions",
|
|
839
|
-
description: "Options for local proxy."
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
},
|
|
843
|
-
VercelOptions: {
|
|
844
|
-
type: "object",
|
|
845
|
-
properties: {
|
|
846
|
-
previewDeploymentSuffix: {
|
|
847
|
-
type: "string",
|
|
848
|
-
description: "If your team uses a custom Preview Deployment Suffix, please specify it here. See https://vercel.com/docs/deployments/preview-deployment-suffix. The default is `vercel.app`."
|
|
849
|
-
},
|
|
850
|
-
teamSlug: {
|
|
851
|
-
type: "string",
|
|
852
|
-
description: "Team slug for the Vercel team"
|
|
853
|
-
},
|
|
854
|
-
disableOverrides: {
|
|
855
|
-
type: "boolean",
|
|
856
|
-
description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
},
|
|
860
|
-
LocalProxyOptions: {
|
|
861
|
-
type: "object",
|
|
862
|
-
properties: {
|
|
863
|
-
port: {
|
|
864
|
-
type: "number",
|
|
865
|
-
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
// src/config/utils/load-schema.ts
|
|
873
|
-
var SCHEMA = schema_default;
|
|
874
|
-
|
|
875
|
-
// src/config/validation.ts
|
|
876
|
-
var validateSchema = (configString) => {
|
|
877
|
-
const parsedConfig = (0, import_jsonc_parser.parse)(configString);
|
|
878
|
-
const ajv = new import_ajv.Ajv();
|
|
879
|
-
const validate = ajv.compile(SCHEMA);
|
|
880
|
-
const isValid = validate(parsedConfig);
|
|
881
|
-
if (!isValid) {
|
|
882
|
-
throw new MicrofrontendError(
|
|
883
|
-
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
884
|
-
{ type: "config", subtype: "does_not_match_schema" }
|
|
885
|
-
);
|
|
886
|
-
}
|
|
887
|
-
return parsedConfig;
|
|
888
|
-
};
|
|
889
|
-
var SUPPORTED_VERSIONS2 = ["1"];
|
|
890
|
-
var validateVersion = (version) => {
|
|
891
|
-
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
892
|
-
throw new MicrofrontendError(
|
|
893
|
-
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
894
|
-
", "
|
|
895
|
-
)}`,
|
|
896
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
897
|
-
);
|
|
898
|
-
}
|
|
899
|
-
};
|
|
900
|
-
function validateMainPath(applicationConfigsById) {
|
|
901
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
902
|
-
const { defaultRoute } = app.vercel ?? {};
|
|
903
|
-
if (!defaultRoute) {
|
|
904
|
-
continue;
|
|
905
|
-
}
|
|
906
|
-
if (isDefaultApplicationConfig(app)) {
|
|
907
|
-
const pathsWithApp = [];
|
|
908
|
-
for (const [otherId, otherApp] of Object.entries(
|
|
909
|
-
applicationConfigsById
|
|
910
|
-
)) {
|
|
911
|
-
if (isDefaultApplicationConfig(otherApp)) {
|
|
912
|
-
continue;
|
|
913
|
-
}
|
|
914
|
-
pathsWithApp.push({
|
|
915
|
-
id: otherId,
|
|
916
|
-
paths: otherApp.routing.matches.flatMap((match) => match.paths)
|
|
917
|
-
});
|
|
918
|
-
}
|
|
919
|
-
for (const { id: otherId, paths } of pathsWithApp) {
|
|
920
|
-
const isValid = paths.every((path3) => {
|
|
921
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(path3);
|
|
922
|
-
return !matcher.test(defaultRoute);
|
|
923
|
-
});
|
|
924
|
-
if (!isValid) {
|
|
925
|
-
throw new MicrofrontendError(
|
|
926
|
-
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
927
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
} else {
|
|
932
|
-
const allPaths = app.routing.matches.flatMap((match) => match.paths);
|
|
933
|
-
const isValid = allPaths.some((path3) => {
|
|
934
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(path3);
|
|
935
|
-
return matcher.test(defaultRoute);
|
|
936
|
-
});
|
|
937
|
-
if (!isValid) {
|
|
938
|
-
throw new MicrofrontendError(
|
|
939
|
-
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
940
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
941
|
-
);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
var validatePaths = (applicationConfigsById) => {
|
|
947
|
-
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
948
|
-
const errors = [];
|
|
949
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
950
|
-
if (isDefaultApplicationConfig(app)) {
|
|
951
|
-
continue;
|
|
952
|
-
}
|
|
953
|
-
for (const pathMatch of app.routing.matches) {
|
|
954
|
-
for (const path3 of pathMatch.paths) {
|
|
955
|
-
const maybeError = validatePathExpression(path3);
|
|
956
|
-
if (maybeError) {
|
|
957
|
-
errors.push(maybeError);
|
|
958
|
-
}
|
|
959
|
-
const existing = pathsByApplicationId.get(path3);
|
|
960
|
-
if (existing) {
|
|
961
|
-
existing.applications.push(id);
|
|
962
|
-
} else {
|
|
963
|
-
pathsByApplicationId.set(path3, {
|
|
964
|
-
applications: [id],
|
|
965
|
-
matcher: (0, import_path_to_regexp.pathToRegexp)(path3),
|
|
966
|
-
applicationId: id
|
|
967
|
-
});
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
const entries = Array.from(pathsByApplicationId.entries());
|
|
973
|
-
entries.forEach(([path3, { applications: ids, matcher, applicationId }]) => {
|
|
974
|
-
if (ids.length > 1) {
|
|
975
|
-
errors.push(
|
|
976
|
-
`Duplicate path "${path3}" for applications "${ids.join(", ")}"`
|
|
977
|
-
);
|
|
978
|
-
}
|
|
979
|
-
entries.forEach(
|
|
980
|
-
([
|
|
981
|
-
matchPath,
|
|
982
|
-
{ applications: matchIds, applicationId: matchApplicationId }
|
|
983
|
-
]) => {
|
|
984
|
-
if (path3 === matchPath) {
|
|
985
|
-
return;
|
|
986
|
-
}
|
|
987
|
-
if (applicationId === matchApplicationId) {
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
if (matcher.test(matchPath)) {
|
|
991
|
-
const source = `"${path3}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
992
|
-
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
993
|
-
errors.push(
|
|
994
|
-
`Overlapping path detected between ${source} and ${destination}`
|
|
995
|
-
);
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
);
|
|
999
|
-
});
|
|
1000
|
-
if (errors.length) {
|
|
1001
|
-
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1002
|
-
type: "config",
|
|
1003
|
-
subtype: "conflicting_paths"
|
|
1004
|
-
});
|
|
1005
|
-
}
|
|
1006
|
-
};
|
|
1007
|
-
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
1008
|
-
function validatePathExpression(path3) {
|
|
1009
|
-
const tokens = (0, import_path_to_regexp.parse)(path3);
|
|
1010
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
1011
|
-
const token = tokens[i];
|
|
1012
|
-
if (token === void 0) {
|
|
1013
|
-
return `token ${i} in ${path3} is undefined, this shouldn't happen`;
|
|
1014
|
-
}
|
|
1015
|
-
if (typeof token !== "string") {
|
|
1016
|
-
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
1017
|
-
return `Path ${path3} cannot use a regular expression wildcard`;
|
|
1018
|
-
}
|
|
1019
|
-
if (token.prefix !== "/") {
|
|
1020
|
-
return `Wildcard :${token.name} must be immediately after a / in ${path3}`;
|
|
1021
|
-
}
|
|
1022
|
-
if (token.suffix) {
|
|
1023
|
-
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
1226
|
+
required: ["routing"],
|
|
1227
|
+
additionalProperties: false
|
|
1228
|
+
},
|
|
1229
|
+
Routing: {
|
|
1230
|
+
type: "array",
|
|
1231
|
+
items: {
|
|
1232
|
+
$ref: "#/definitions/PathGroup"
|
|
1024
1233
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1234
|
+
},
|
|
1235
|
+
PathGroup: {
|
|
1236
|
+
type: "object",
|
|
1237
|
+
properties: {
|
|
1238
|
+
group: {
|
|
1239
|
+
type: "string",
|
|
1240
|
+
description: "Optional group name for the paths"
|
|
1241
|
+
},
|
|
1242
|
+
flag: {
|
|
1243
|
+
type: "string",
|
|
1244
|
+
description: "flag name that can be used to enable/disable all paths in the group"
|
|
1245
|
+
},
|
|
1246
|
+
paths: {
|
|
1247
|
+
type: "array",
|
|
1248
|
+
items: {
|
|
1249
|
+
type: "string"
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
},
|
|
1253
|
+
required: ["paths"],
|
|
1254
|
+
additionalProperties: false
|
|
1255
|
+
},
|
|
1256
|
+
ApplicationRouting: {
|
|
1257
|
+
type: "object",
|
|
1258
|
+
additionalProperties: {
|
|
1259
|
+
$ref: "#/definitions/Application"
|
|
1027
1260
|
}
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
);
|
|
1261
|
+
},
|
|
1262
|
+
ChildConfig: {
|
|
1263
|
+
type: "object",
|
|
1264
|
+
properties: {
|
|
1265
|
+
$schema: {
|
|
1266
|
+
type: "string"
|
|
1267
|
+
},
|
|
1268
|
+
version: {
|
|
1269
|
+
type: "string",
|
|
1270
|
+
const: "2"
|
|
1271
|
+
},
|
|
1272
|
+
options: {
|
|
1273
|
+
$ref: "#/definitions/Options"
|
|
1274
|
+
},
|
|
1275
|
+
remotes: {
|
|
1276
|
+
type: "object",
|
|
1277
|
+
additionalProperties: {
|
|
1278
|
+
$ref: "#/definitions/Application"
|
|
1279
|
+
},
|
|
1280
|
+
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
1281
|
+
},
|
|
1282
|
+
partOf: {
|
|
1283
|
+
type: "string",
|
|
1284
|
+
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1287
|
+
required: ["partOf", "version"],
|
|
1288
|
+
additionalProperties: false
|
|
1057
1289
|
}
|
|
1058
1290
|
}
|
|
1059
1291
|
};
|
|
1060
1292
|
|
|
1061
|
-
// src/config/utils/
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
development: application.development,
|
|
1076
|
-
vercel: application.vercel
|
|
1077
|
-
};
|
|
1078
|
-
if (application.default) {
|
|
1079
|
-
return common;
|
|
1293
|
+
// src/config/schema/utils/load.ts
|
|
1294
|
+
var SCHEMA = schema_default;
|
|
1295
|
+
|
|
1296
|
+
// src/config/microfrontends/server/validation.ts
|
|
1297
|
+
function validateSchema(configString) {
|
|
1298
|
+
const parsedConfig = (0, import_jsonc_parser3.parse)(configString);
|
|
1299
|
+
const ajv = new import_ajv.Ajv();
|
|
1300
|
+
const validate = ajv.compile(SCHEMA);
|
|
1301
|
+
const isValid = validate(parsedConfig);
|
|
1302
|
+
if (!isValid) {
|
|
1303
|
+
throw new MicrofrontendError(
|
|
1304
|
+
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
1305
|
+
{ type: "config", subtype: "does_not_match_schema" }
|
|
1306
|
+
);
|
|
1080
1307
|
}
|
|
1081
|
-
return
|
|
1082
|
-
...common,
|
|
1083
|
-
routing: convertV1RoutingToV2Routing(application.routing)
|
|
1084
|
-
};
|
|
1308
|
+
return parsedConfig;
|
|
1085
1309
|
}
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1310
|
+
|
|
1311
|
+
// src/config/microfrontends/server/index.ts
|
|
1312
|
+
var MicrofrontendsServer = class extends Microfrontends {
|
|
1313
|
+
/**
|
|
1314
|
+
* Writes the configuration to a file.
|
|
1315
|
+
*/
|
|
1316
|
+
writeConfig(opts = {
|
|
1317
|
+
pretty: true
|
|
1318
|
+
}) {
|
|
1319
|
+
const outputPath = getOutputFilePath();
|
|
1320
|
+
import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
|
|
1321
|
+
import_node_fs7.default.writeFileSync(
|
|
1322
|
+
outputPath,
|
|
1323
|
+
JSON.stringify(
|
|
1324
|
+
this.config.toSchemaJson(),
|
|
1325
|
+
null,
|
|
1326
|
+
opts.pretty ?? true ? 2 : void 0
|
|
1102
1327
|
)
|
|
1103
|
-
|
|
1104
|
-
}
|
|
1105
|
-
const defaultApplication = Object.entries(config.applications).find(
|
|
1106
|
-
([, application]) => application.default
|
|
1107
|
-
);
|
|
1108
|
-
if (!defaultApplication) {
|
|
1109
|
-
throw new Error("No default application found in the config");
|
|
1328
|
+
);
|
|
1110
1329
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1330
|
+
// --------- Static Methods ---------
|
|
1331
|
+
/**
|
|
1332
|
+
* Generates a MicrofrontendsServer instance from an unknown object.
|
|
1333
|
+
*/
|
|
1334
|
+
static fromUnknown({
|
|
1335
|
+
config,
|
|
1336
|
+
cookies,
|
|
1337
|
+
meta
|
|
1338
|
+
}) {
|
|
1339
|
+
const overrides = cookies ? parseOverrides(cookies) : void 0;
|
|
1340
|
+
if (typeof config === "string") {
|
|
1341
|
+
return new MicrofrontendsServer({
|
|
1342
|
+
config: MicrofrontendsServer.validate(config),
|
|
1343
|
+
overrides,
|
|
1344
|
+
meta
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
if (typeof config === "object") {
|
|
1348
|
+
return new MicrofrontendsServer({
|
|
1349
|
+
config,
|
|
1350
|
+
overrides,
|
|
1351
|
+
meta
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
throw new MicrofrontendError(
|
|
1355
|
+
"Invalid config: must be a string or an object",
|
|
1356
|
+
{ type: "config", subtype: "does_not_match_schema" }
|
|
1357
|
+
);
|
|
1138
1358
|
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Generates a MicrofrontendsServer instance from the environment.
|
|
1361
|
+
* Uses additional validation that is only available when in a node runtime
|
|
1362
|
+
*/
|
|
1139
1363
|
static fromEnv({
|
|
1140
|
-
cookies
|
|
1364
|
+
cookies,
|
|
1365
|
+
meta
|
|
1141
1366
|
}) {
|
|
1142
|
-
return new
|
|
1143
|
-
config:
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
overrides: Overrides.parseOverrides(cookies)
|
|
1367
|
+
return new MicrofrontendsServer({
|
|
1368
|
+
config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
|
|
1369
|
+
overrides: parseOverrides(cookies),
|
|
1370
|
+
meta
|
|
1147
1371
|
});
|
|
1148
1372
|
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Validates the configuration against the JSON schema
|
|
1375
|
+
*/
|
|
1376
|
+
static validate(config) {
|
|
1377
|
+
if (typeof config === "string") {
|
|
1378
|
+
const c = validateSchema(config);
|
|
1379
|
+
return c;
|
|
1380
|
+
}
|
|
1381
|
+
return config;
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Looks up the configuration by inferring the package root and looking for a microfrontends config file. If a file is not found,
|
|
1385
|
+
* it will look for a package in the repository with a microfrontends file that contains the current application
|
|
1386
|
+
* and use that configuration.
|
|
1387
|
+
*
|
|
1388
|
+
* This can return either a Child or Main configuration.
|
|
1389
|
+
*/
|
|
1390
|
+
static infer({
|
|
1391
|
+
directory,
|
|
1392
|
+
filePath,
|
|
1393
|
+
meta,
|
|
1394
|
+
cookies,
|
|
1395
|
+
options
|
|
1396
|
+
} = {}) {
|
|
1397
|
+
if (filePath && meta) {
|
|
1398
|
+
return MicrofrontendsServer.fromFile({
|
|
1399
|
+
filePath,
|
|
1400
|
+
cookies,
|
|
1401
|
+
meta,
|
|
1402
|
+
options
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
try {
|
|
1406
|
+
const packageRoot = findPackageRoot(directory);
|
|
1407
|
+
const packageJsonPath = (0, import_node_path8.join)(packageRoot, "package.json");
|
|
1408
|
+
const packageJson = JSON.parse(
|
|
1409
|
+
import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
|
|
1410
|
+
);
|
|
1411
|
+
if (!packageJson.name) {
|
|
1412
|
+
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1413
|
+
}
|
|
1414
|
+
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1415
|
+
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1416
|
+
if (maybeConfig) {
|
|
1417
|
+
return MicrofrontendsServer.fromFile({
|
|
1418
|
+
filePath: maybeConfig,
|
|
1419
|
+
cookies,
|
|
1420
|
+
meta: configMeta,
|
|
1421
|
+
options
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
const repositoryRoot = findRepositoryRoot();
|
|
1425
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1426
|
+
if (isMonorepo2) {
|
|
1427
|
+
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1428
|
+
repositoryRoot,
|
|
1429
|
+
applicationName: packageJson.name
|
|
1430
|
+
});
|
|
1431
|
+
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1432
|
+
if (maybeConfigFromDefault) {
|
|
1433
|
+
return MicrofrontendsServer.fromFile({
|
|
1434
|
+
filePath: maybeConfigFromDefault,
|
|
1435
|
+
cookies,
|
|
1436
|
+
meta: configMeta,
|
|
1437
|
+
options
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
throw new Error("Unable to infer");
|
|
1442
|
+
} catch (e) {
|
|
1443
|
+
throw new MicrofrontendError(
|
|
1444
|
+
"Unable to infer microfrontends configuration",
|
|
1445
|
+
{ type: "config", subtype: "inference_failed" }
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
/*
|
|
1450
|
+
* Generates a MicrofrontendsServer instance from a file.
|
|
1451
|
+
*/
|
|
1149
1452
|
static fromFile({
|
|
1150
|
-
filePath
|
|
1453
|
+
filePath,
|
|
1454
|
+
cookies,
|
|
1455
|
+
meta,
|
|
1456
|
+
options
|
|
1151
1457
|
}) {
|
|
1152
1458
|
try {
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1155
|
-
|
|
1459
|
+
const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1460
|
+
const config = MicrofrontendsServer.validate(configJson);
|
|
1461
|
+
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
1462
|
+
const repositoryRoot = findRepositoryRoot();
|
|
1463
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1464
|
+
if (isMonorepo2) {
|
|
1465
|
+
const packagePath = findPackagePath({
|
|
1466
|
+
repositoryRoot,
|
|
1467
|
+
name: config.partOf
|
|
1468
|
+
});
|
|
1469
|
+
if (!packagePath) {
|
|
1470
|
+
throw new MicrofrontendError(
|
|
1471
|
+
`Could not find default application "${config.partOf}" in the repository`,
|
|
1472
|
+
{ type: "config", subtype: "not_found" }
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
const maybeConfig = findConfig({ dir: packagePath });
|
|
1476
|
+
if (!maybeConfig) {
|
|
1477
|
+
throw new MicrofrontendError(
|
|
1478
|
+
`Could not find microfrontends configuration in ${packagePath}`,
|
|
1479
|
+
{ type: "config", subtype: "not_found" }
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
return MicrofrontendsServer.fromMainConfigFile({
|
|
1483
|
+
filePath: maybeConfig,
|
|
1484
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
return new MicrofrontendsServer({
|
|
1489
|
+
config,
|
|
1490
|
+
overrides: cookies ? parseOverrides(cookies) : void 0,
|
|
1491
|
+
meta
|
|
1156
1492
|
});
|
|
1157
1493
|
} catch (e) {
|
|
1158
1494
|
throw MicrofrontendError.handle(e, {
|
|
@@ -1160,20 +1496,41 @@ var MicrofrontendConfig = class extends MicrofrontendConfigCommon {
|
|
|
1160
1496
|
});
|
|
1161
1497
|
}
|
|
1162
1498
|
}
|
|
1163
|
-
|
|
1164
|
-
*
|
|
1499
|
+
/*
|
|
1500
|
+
* Generates a MicrofrontendMainConfig instance from a file.
|
|
1165
1501
|
*/
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1502
|
+
static fromMainConfigFile({
|
|
1503
|
+
filePath,
|
|
1504
|
+
overrides
|
|
1505
|
+
}) {
|
|
1506
|
+
try {
|
|
1507
|
+
const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1508
|
+
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1509
|
+
if (!isMainConfig(validatedConfig)) {
|
|
1510
|
+
throw new MicrofrontendError(
|
|
1511
|
+
`${filePath} is not a main microfrontend config`,
|
|
1512
|
+
{
|
|
1513
|
+
type: "config",
|
|
1514
|
+
subtype: "invalid_main_path"
|
|
1515
|
+
}
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1518
|
+
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1519
|
+
if (!defaultApplication) {
|
|
1520
|
+
throw new MicrofrontendError(
|
|
1521
|
+
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
1522
|
+
{ type: "config", subtype: "no_default_application" }
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1525
|
+
return new MicrofrontendsServer({
|
|
1526
|
+
config: validatedConfig,
|
|
1527
|
+
overrides,
|
|
1528
|
+
meta: { fromApp: defaultApplication }
|
|
1529
|
+
});
|
|
1530
|
+
} catch (e) {
|
|
1531
|
+
throw MicrofrontendError.handle(e, {
|
|
1532
|
+
fileName: filePath
|
|
1533
|
+
});
|
|
1177
1534
|
}
|
|
1178
1535
|
}
|
|
1179
1536
|
};
|
|
@@ -1189,19 +1546,19 @@ function displayLocalProxyInfo(port) {
|
|
|
1189
1546
|
|
|
1190
1547
|
// src/next/config/transforms/asset-prefix.ts
|
|
1191
1548
|
function transform(args) {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
if (!((_a = zone.routing) == null ? void 0 : _a.assetPrefix)) {
|
|
1549
|
+
const { next, app } = args;
|
|
1550
|
+
if (app.isDefault()) {
|
|
1195
1551
|
return {
|
|
1196
1552
|
next
|
|
1197
1553
|
};
|
|
1198
1554
|
}
|
|
1199
|
-
if (next.assetPrefix !== void 0 && next.assetPrefix !==
|
|
1200
|
-
|
|
1201
|
-
`"assetPrefix" already set.
|
|
1555
|
+
if (next.assetPrefix !== void 0 && next.assetPrefix !== app.getAssetPrefix()) {
|
|
1556
|
+
console.log(
|
|
1557
|
+
`"assetPrefix" already set. This route must be manually configured in your microfrontend.json file.`
|
|
1202
1558
|
);
|
|
1559
|
+
} else {
|
|
1560
|
+
next.assetPrefix = `/${app.getAssetPrefix()}`;
|
|
1203
1561
|
}
|
|
1204
|
-
next.assetPrefix = `/${zone.routing.assetPrefix}`;
|
|
1205
1562
|
return {
|
|
1206
1563
|
next
|
|
1207
1564
|
};
|
|
@@ -1225,8 +1582,8 @@ function transform2(args) {
|
|
|
1225
1582
|
|
|
1226
1583
|
// src/next/config/transforms/headers.ts
|
|
1227
1584
|
function transform3(args) {
|
|
1228
|
-
const { next,
|
|
1229
|
-
if (
|
|
1585
|
+
const { next, app } = args;
|
|
1586
|
+
if (app.isDefault()) {
|
|
1230
1587
|
return {
|
|
1231
1588
|
next
|
|
1232
1589
|
};
|
|
@@ -1237,7 +1594,11 @@ function transform3(args) {
|
|
|
1237
1594
|
headers: [
|
|
1238
1595
|
{
|
|
1239
1596
|
key: "X-Vercel-Zone",
|
|
1240
|
-
value:
|
|
1597
|
+
value: app.name
|
|
1598
|
+
},
|
|
1599
|
+
{
|
|
1600
|
+
key: "X-Vercel-MFE-App",
|
|
1601
|
+
value: app.name
|
|
1241
1602
|
}
|
|
1242
1603
|
]
|
|
1243
1604
|
},
|
|
@@ -1276,82 +1637,39 @@ function transform3(args) {
|
|
|
1276
1637
|
};
|
|
1277
1638
|
}
|
|
1278
1639
|
|
|
1279
|
-
// src/routing/get-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
if (
|
|
1289
|
-
throw new Error(
|
|
1640
|
+
// src/routing/get-domain-from-environment.ts
|
|
1641
|
+
function getDomainFromEnvironment({
|
|
1642
|
+
app,
|
|
1643
|
+
target
|
|
1644
|
+
}) {
|
|
1645
|
+
var _a;
|
|
1646
|
+
const mfeProjects = JSON.parse(
|
|
1647
|
+
process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "[]"
|
|
1648
|
+
);
|
|
1649
|
+
if (mfeProjects.length === 0) {
|
|
1650
|
+
throw new Error("Missing related microfrontends project information");
|
|
1290
1651
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
// biome-ignore lint/style/noNonNullAssertion: Ignored using `--suppress`
|
|
1294
|
-
label: branchUrlParts[0],
|
|
1295
|
-
domain
|
|
1296
|
-
};
|
|
1297
|
-
}
|
|
1298
|
-
function getDomainSuffix(branchUrl, vercelUrl) {
|
|
1299
|
-
const branchLabelParts = parseBranchUrl(branchUrl).label.split("-");
|
|
1300
|
-
const vercelUrlLabelParts = parseBranchUrl(vercelUrl).label.split("-");
|
|
1301
|
-
const suffixParts = [];
|
|
1302
|
-
for (let i = 1; i < branchLabelParts.length; i++) {
|
|
1303
|
-
if (branchLabelParts.at(-1 * i) === vercelUrlLabelParts.at(-1 * i)) {
|
|
1304
|
-
suffixParts.push(branchLabelParts.at(-1 * i) ?? "");
|
|
1305
|
-
}
|
|
1652
|
+
if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
|
|
1653
|
+
throw new Error(`Missing applications[${app.name}].vercel.projectId`);
|
|
1306
1654
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1655
|
+
const vercelProject = mfeProjects.find(
|
|
1656
|
+
(p) => {
|
|
1657
|
+
var _a2;
|
|
1658
|
+
return p.project.id === ((_a2 = app.vercel) == null ? void 0 : _a2.projectId);
|
|
1659
|
+
}
|
|
1660
|
+
);
|
|
1661
|
+
if (!vercelProject) {
|
|
1313
1662
|
throw new Error(
|
|
1314
|
-
`Missing
|
|
1663
|
+
`Missing related microfrontends project information for application "${app.name}"`
|
|
1315
1664
|
);
|
|
1316
1665
|
}
|
|
1317
|
-
const
|
|
1318
|
-
if (
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
const gitBranch = `git-${VERCEL_GIT_COMMIT_REF.toLocaleLowerCase()}`;
|
|
1323
|
-
const gitBranchForHash = `git-${VERCEL_GIT_COMMIT_REF}`;
|
|
1324
|
-
const urlSafeBranch = makeUrlSafe(gitBranch);
|
|
1325
|
-
const urlSafeProjectName = makeUrlSafe(targetVercelProjectName);
|
|
1326
|
-
const maxLabelLength = getMaxLabelLength(domain);
|
|
1327
|
-
const label = [urlSafeProjectName, urlSafeBranch, stagingSuffix].filter(Boolean).join("-");
|
|
1328
|
-
if (label.length > maxLabelLength) {
|
|
1329
|
-
let newLabel = makeUrlSafe(stagingSuffix).slice(0, maxLabelLength);
|
|
1330
|
-
const hash = (0, import_node_crypto.createHash)("sha256").update(`${gitBranchForHash}${targetVercelProjectName}`).digest("hex").slice(0, 6);
|
|
1331
|
-
newLabel = [hash, newLabel].filter(Boolean).join("-");
|
|
1332
|
-
const projectNamePart = makeUrlSafe(
|
|
1333
|
-
urlSafeProjectName.slice(0, maxLabelLength - newLabel.length - 1 - 4)
|
|
1334
|
-
);
|
|
1335
|
-
const branchPart = makeUrlSafe(
|
|
1336
|
-
urlSafeBranch.slice(
|
|
1337
|
-
0,
|
|
1338
|
-
Math.max(
|
|
1339
|
-
0,
|
|
1340
|
-
maxLabelLength - (newLabel.length + projectNamePart.length) - 2
|
|
1341
|
-
)
|
|
1342
|
-
)
|
|
1343
|
-
);
|
|
1344
|
-
if (branchPart.length >= 3) {
|
|
1345
|
-
newLabel = [branchPart, newLabel].filter(Boolean).join("-");
|
|
1346
|
-
}
|
|
1347
|
-
if (projectNamePart) {
|
|
1348
|
-
newLabel = [projectNamePart, newLabel].filter(Boolean).join("-");
|
|
1349
|
-
}
|
|
1350
|
-
return `https://${newLabel}.${domain}`;
|
|
1351
|
-
}
|
|
1352
|
-
return `https://${label}.${domain}`;
|
|
1666
|
+
const domain = target === "preview" && vercelProject.preview.branch ? vercelProject.preview.branch : vercelProject.production.alias ?? vercelProject.production.url;
|
|
1667
|
+
if (!domain) {
|
|
1668
|
+
throw new Error(
|
|
1669
|
+
`Missing domain for target "${target}" in application "${app.name}"`
|
|
1670
|
+
);
|
|
1353
1671
|
}
|
|
1354
|
-
return
|
|
1672
|
+
return domain.startsWith("https://") ? domain : `https://${domain}`;
|
|
1355
1673
|
}
|
|
1356
1674
|
|
|
1357
1675
|
// src/routing/get-domain-for-current-environment.ts
|
|
@@ -1367,34 +1685,45 @@ ${line}
|
|
|
1367
1685
|
`);
|
|
1368
1686
|
}
|
|
1369
1687
|
}
|
|
1370
|
-
function
|
|
1688
|
+
function getCurrentEnvironment() {
|
|
1689
|
+
const isDevelopment = !process.env.VERCEL_ENV || process.env.VERCEL_ENV === "development";
|
|
1690
|
+
const isPreview = process.env.VERCEL_ENV === "preview";
|
|
1691
|
+
const isProduction2 = process.env.VERCEL_ENV === "production";
|
|
1692
|
+
if (isDevelopment) {
|
|
1693
|
+
return { group: "development" };
|
|
1694
|
+
} else if (isProduction2) {
|
|
1695
|
+
return { group: "production" };
|
|
1696
|
+
} else if (isPreview) {
|
|
1697
|
+
return { group: "preview" };
|
|
1698
|
+
}
|
|
1699
|
+
return { group: "custom", name: process.env.VERCEL_ENV };
|
|
1700
|
+
}
|
|
1701
|
+
function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
1371
1702
|
var _a;
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
return domain;
|
|
1384
|
-
} else if (process.env.VERCEL_ENV === "preview") {
|
|
1385
|
-
const MFE_PREVIEW_DOMAINS = JSON.parse(
|
|
1386
|
-
process.env.MFE_PREVIEW_DOMAINS ?? "{}"
|
|
1387
|
-
);
|
|
1388
|
-
if (MFE_PREVIEW_DOMAINS[zoneName]) {
|
|
1389
|
-
debugDomains(zoneName, "preview", MFE_PREVIEW_DOMAINS[zoneName]);
|
|
1390
|
-
return MFE_PREVIEW_DOMAINS[zoneName];
|
|
1703
|
+
const app = config.getApplication(appName);
|
|
1704
|
+
if (!opts.ignoreOverride && ((_a = app.overrides) == null ? void 0 : _a.environment)) {
|
|
1705
|
+
return app.overrides.environment.toString();
|
|
1706
|
+
}
|
|
1707
|
+
const { group } = getCurrentEnvironment();
|
|
1708
|
+
const productionHost = config.getDefaultApplication().production.toString();
|
|
1709
|
+
switch (group) {
|
|
1710
|
+
case "development": {
|
|
1711
|
+
const domain = ["test", "development"].includes(process.env.NODE_ENV) ? app.development.local.toString() : productionHost;
|
|
1712
|
+
debugDomains(appName, "development", domain);
|
|
1713
|
+
return domain;
|
|
1391
1714
|
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1715
|
+
case "preview": {
|
|
1716
|
+
return getDomainFromEnvironment({ app, target: "preview" });
|
|
1717
|
+
}
|
|
1718
|
+
case "production": {
|
|
1719
|
+
return getDomainFromEnvironment({ app, target: "production" });
|
|
1720
|
+
}
|
|
1721
|
+
case "custom":
|
|
1722
|
+
console.warn(
|
|
1723
|
+
`Custom environments are not supported in getDomainForCurrentEnvironment`
|
|
1724
|
+
);
|
|
1725
|
+
return productionHost;
|
|
1395
1726
|
}
|
|
1396
|
-
debugDomains(zoneName, process.env.VERCEL_ENV, zone.production.toString());
|
|
1397
|
-
return zone.production.toString();
|
|
1398
1727
|
}
|
|
1399
1728
|
|
|
1400
1729
|
// src/next/config/transforms/rewrites.ts
|
|
@@ -1416,11 +1745,11 @@ ${table}
|
|
|
1416
1745
|
`);
|
|
1417
1746
|
}
|
|
1418
1747
|
}
|
|
1419
|
-
function pathToRewrites(
|
|
1748
|
+
function pathToRewrites(path5) {
|
|
1420
1749
|
var _a;
|
|
1421
1750
|
const regex = /(?<base>^.+)\/:.+\*$/;
|
|
1422
|
-
const match = regex.exec(
|
|
1423
|
-
const paths = [
|
|
1751
|
+
const match = regex.exec(path5);
|
|
1752
|
+
const paths = [path5];
|
|
1424
1753
|
if ((_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.base) {
|
|
1425
1754
|
paths.unshift(match.groups.base);
|
|
1426
1755
|
}
|
|
@@ -1449,42 +1778,39 @@ function rewritesMapToArr(rewrites) {
|
|
|
1449
1778
|
});
|
|
1450
1779
|
}
|
|
1451
1780
|
function transform4(args) {
|
|
1452
|
-
const { next, microfrontend,
|
|
1781
|
+
const { next, microfrontend, app } = args;
|
|
1453
1782
|
const buildBeforeFiles = () => {
|
|
1454
|
-
var _a, _b, _c, _d;
|
|
1455
1783
|
const rewrites = /* @__PURE__ */ new Map();
|
|
1456
|
-
if ((
|
|
1457
|
-
rewrites.set(`/${
|
|
1784
|
+
if (!app.isDefault()) {
|
|
1785
|
+
rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
|
|
1458
1786
|
destination: {
|
|
1459
1787
|
pathname: `/_next/:path+`
|
|
1460
1788
|
}
|
|
1461
1789
|
});
|
|
1462
|
-
|
|
1463
|
-
|
|
1790
|
+
rewrites.set(`/${app.getAssetPrefix()}/.well-known/vercel/flags`, {
|
|
1791
|
+
destination: {
|
|
1792
|
+
pathname: `/.well-known/vercel/flags`
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
1795
|
+
if (process.env.VERCEL_MICROFRONTENDS_CONSOLIDATE_SPEED_INSIGHTS === "1") {
|
|
1796
|
+
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1464
1797
|
destination: { pathname: "/_vercel/:path*" }
|
|
1465
1798
|
});
|
|
1466
1799
|
}
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
domain,
|
|
1482
|
-
pathname: `/${z.routing.assetPrefix}/:path+`
|
|
1483
|
-
}
|
|
1484
|
-
});
|
|
1485
|
-
}
|
|
1486
|
-
for (const group of routing.matches) {
|
|
1487
|
-
if ((_d = group.options) == null ? void 0 : _d.flag) {
|
|
1800
|
+
} else if (microfrontend instanceof MicrofrontendMainConfig) {
|
|
1801
|
+
for (const [_, a] of Object.entries(
|
|
1802
|
+
microfrontend.getChildApplications()
|
|
1803
|
+
)) {
|
|
1804
|
+
const { routing } = a;
|
|
1805
|
+
const domain = getDomainForCurrentEnvironment(microfrontend, a.name);
|
|
1806
|
+
rewrites.set(`/${a.getAssetPrefix()}/:path+`, {
|
|
1807
|
+
destination: {
|
|
1808
|
+
domain,
|
|
1809
|
+
pathname: `/${a.getAssetPrefix()}/:path+`
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
for (const group of routing) {
|
|
1813
|
+
if (group.flag) {
|
|
1488
1814
|
continue;
|
|
1489
1815
|
} else {
|
|
1490
1816
|
for (const source of group.paths) {
|
|
@@ -1498,7 +1824,6 @@ function transform4(args) {
|
|
|
1498
1824
|
}
|
|
1499
1825
|
}
|
|
1500
1826
|
}
|
|
1501
|
-
} else {
|
|
1502
1827
|
}
|
|
1503
1828
|
return rewritesMapToArr(rewrites);
|
|
1504
1829
|
};
|
|
@@ -1535,17 +1860,44 @@ function transform4(args) {
|
|
|
1535
1860
|
}
|
|
1536
1861
|
|
|
1537
1862
|
// src/next/config/transforms/server-actions.ts
|
|
1863
|
+
function debugRewrites2(allowedOrigins) {
|
|
1864
|
+
if (process.env.MFE_DEBUG === "true" && allowedOrigins) {
|
|
1865
|
+
const indent = " ".repeat(4);
|
|
1866
|
+
const header = "server actions allowed origins";
|
|
1867
|
+
const separator = "\u23AF".repeat(header.length);
|
|
1868
|
+
const maxSourceLength = Math.max(
|
|
1869
|
+
...allowedOrigins.map((key) => key.length)
|
|
1870
|
+
);
|
|
1871
|
+
const table = allowedOrigins.map((origin, idx) => {
|
|
1872
|
+
const paddedSource = origin.padEnd(maxSourceLength);
|
|
1873
|
+
return `${indent} ${idx + 1}. ${paddedSource}`;
|
|
1874
|
+
}).join("\n");
|
|
1875
|
+
console.log(`${indent}${header}
|
|
1876
|
+
${indent}${separator}
|
|
1877
|
+
${table}
|
|
1878
|
+
`);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1538
1881
|
var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
|
|
1539
1882
|
function transform5(args) {
|
|
1540
|
-
var _a;
|
|
1541
|
-
const { next,
|
|
1542
|
-
|
|
1883
|
+
var _a, _b;
|
|
1884
|
+
const { next, app, microfrontend } = args;
|
|
1885
|
+
if (microfrontend instanceof MicrofrontendChildConfig) {
|
|
1886
|
+
console.warn(
|
|
1887
|
+
"server actions transform requires the full config - skipping"
|
|
1888
|
+
);
|
|
1889
|
+
return {
|
|
1890
|
+
next
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
const defaultApplication = microfrontend.getDefaultApplication();
|
|
1894
|
+
const appsToAllow = [
|
|
1543
1895
|
// this zone - this is included by default unless allowedOrigins is overridden (which we are)
|
|
1544
1896
|
// so we re-add it here.
|
|
1545
|
-
|
|
1897
|
+
app,
|
|
1546
1898
|
// this is the default zone for the microfrontend. Allow child zones to call server actions
|
|
1547
1899
|
// that are in the default zone.
|
|
1548
|
-
|
|
1900
|
+
defaultApplication
|
|
1549
1901
|
];
|
|
1550
1902
|
const existingServerActionConfig = (_a = next.experimental) == null ? void 0 : _a.serverActions;
|
|
1551
1903
|
next.experimental = {
|
|
@@ -1554,15 +1906,23 @@ function transform5(args) {
|
|
|
1554
1906
|
...existingServerActionConfig,
|
|
1555
1907
|
allowedOrigins: Array.from(
|
|
1556
1908
|
/* @__PURE__ */ new Set([
|
|
1909
|
+
// existing
|
|
1557
1910
|
...(existingServerActionConfig == null ? void 0 : existingServerActionConfig.allowedOrigins) ?? [],
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1911
|
+
// this deployments host
|
|
1912
|
+
...process.env.VERCEL_URL ? [formatDomainForServerAction(process.env.VERCEL_URL)] : [],
|
|
1913
|
+
// default application host
|
|
1914
|
+
formatDomainForServerAction(defaultApplication.production.toString()),
|
|
1915
|
+
// environment specific microfrontend hosts
|
|
1916
|
+
...appsToAllow.flatMap((a) => [
|
|
1917
|
+
formatDomainForServerAction(
|
|
1918
|
+
getDomainForCurrentEnvironment(microfrontend, a.name)
|
|
1919
|
+
)
|
|
1561
1920
|
])
|
|
1562
1921
|
])
|
|
1563
1922
|
)
|
|
1564
1923
|
}
|
|
1565
1924
|
};
|
|
1925
|
+
debugRewrites2((_b = next.experimental.serverActions) == null ? void 0 : _b.allowedOrigins);
|
|
1566
1926
|
return {
|
|
1567
1927
|
next
|
|
1568
1928
|
};
|
|
@@ -1571,14 +1931,6 @@ function transform5(args) {
|
|
|
1571
1931
|
// src/next/config/transforms/webpack.ts
|
|
1572
1932
|
function transform6(args) {
|
|
1573
1933
|
const { next, microfrontend } = args;
|
|
1574
|
-
const previewDomains = process.env.VERCEL_ENV === "preview" ? microfrontend.getAllApplications().reduce(
|
|
1575
|
-
(obj, app) => {
|
|
1576
|
-
obj[app.name] = getPreviewDomain(app);
|
|
1577
|
-
return obj;
|
|
1578
|
-
},
|
|
1579
|
-
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter -- needed to satisfy TSC
|
|
1580
|
-
{}
|
|
1581
|
-
) : {};
|
|
1582
1934
|
const configWithWebpack = {
|
|
1583
1935
|
...next,
|
|
1584
1936
|
webpack(cfg, context) {
|
|
@@ -1587,8 +1939,7 @@ function transform6(args) {
|
|
|
1587
1939
|
if (isServer || nextRuntime === "edge") {
|
|
1588
1940
|
config.plugins.push(
|
|
1589
1941
|
new wpFromNext.EnvironmentPlugin({
|
|
1590
|
-
MFE_CONFIG: JSON.stringify(microfrontend.serialize())
|
|
1591
|
-
MFE_PREVIEW_DOMAINS: JSON.stringify(previewDomains)
|
|
1942
|
+
MFE_CONFIG: JSON.stringify(microfrontend.serialize())
|
|
1592
1943
|
})
|
|
1593
1944
|
);
|
|
1594
1945
|
}
|
|
@@ -1628,21 +1979,6 @@ var transforms = {
|
|
|
1628
1979
|
webpack: transform6
|
|
1629
1980
|
};
|
|
1630
1981
|
|
|
1631
|
-
// src/config/client/client-config.ts
|
|
1632
|
-
function getConfigForClient(config) {
|
|
1633
|
-
return {
|
|
1634
|
-
applications: Object.fromEntries(
|
|
1635
|
-
Object.entries(config.applications).map(([name, application]) => [
|
|
1636
|
-
name,
|
|
1637
|
-
{
|
|
1638
|
-
default: application.default,
|
|
1639
|
-
routing: application.routing
|
|
1640
|
-
}
|
|
1641
|
-
])
|
|
1642
|
-
)
|
|
1643
|
-
};
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
1982
|
// src/next/config/env.ts
|
|
1647
1983
|
function debugEnv(env) {
|
|
1648
1984
|
if (process.env.MFE_DEBUG === "true") {
|
|
@@ -1661,32 +1997,18 @@ ${table}
|
|
|
1661
1997
|
}
|
|
1662
1998
|
}
|
|
1663
1999
|
function setEnvironment({
|
|
1664
|
-
|
|
1665
|
-
|
|
2000
|
+
app,
|
|
2001
|
+
microfrontends
|
|
1666
2002
|
}) {
|
|
1667
|
-
var _a, _b, _c, _d;
|
|
1668
|
-
const previewDomains = process.env.VERCEL_ENV === "preview" ? config.getAllApplications().reduce(
|
|
1669
|
-
(obj, app) => {
|
|
1670
|
-
obj[app.name] = getPreviewDomain(app);
|
|
1671
|
-
return obj;
|
|
1672
|
-
},
|
|
1673
|
-
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter -- needed to satisfy TSC
|
|
1674
|
-
{}
|
|
1675
|
-
) : {};
|
|
1676
2003
|
const clientEnvs = {
|
|
1677
|
-
NEXT_PUBLIC_MFE_CURRENT_APPLICATION:
|
|
2004
|
+
NEXT_PUBLIC_MFE_CURRENT_APPLICATION: app.name,
|
|
1678
2005
|
NEXT_PUBLIC_MFE_CLIENT_CONFIG: JSON.stringify(
|
|
1679
|
-
|
|
1680
|
-
)
|
|
1681
|
-
...((_a = zone.vercel) == null ? void 0 : _a.routeSpeedInsightsToDefaultZone) && ((_b = zone.routing) == null ? void 0 : _b.assetPrefix) ? {} : {
|
|
1682
|
-
NEXT_PUBLIC_SPEED_INSIGHTS_BASEPATH: (_c = zone.routing) == null ? void 0 : _c.assetPrefix,
|
|
1683
|
-
NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH: (_d = zone.routing) == null ? void 0 : _d.assetPrefix
|
|
1684
|
-
}
|
|
2006
|
+
microfrontends.config.toClientConfig().serialize()
|
|
2007
|
+
)
|
|
1685
2008
|
};
|
|
1686
2009
|
const serverEnvs = {
|
|
1687
|
-
MFE_CURRENT_APPLICATION:
|
|
1688
|
-
|
|
1689
|
-
MFE_CONFIG: JSON.stringify(config.getConfig())
|
|
2010
|
+
MFE_CURRENT_APPLICATION: app.name,
|
|
2011
|
+
MFE_CONFIG: JSON.stringify(microfrontends.config.getConfig())
|
|
1690
2012
|
};
|
|
1691
2013
|
const allEnvs = { ...clientEnvs, ...serverEnvs };
|
|
1692
2014
|
for (const [key, value] of Object.entries(allEnvs)) {
|
|
@@ -1705,37 +2027,12 @@ function isProduction(opts) {
|
|
|
1705
2027
|
}
|
|
1706
2028
|
return process.env.VERCEL_ENV === "production";
|
|
1707
2029
|
}
|
|
1708
|
-
function getConfigPath(opts) {
|
|
1709
|
-
var _a;
|
|
1710
|
-
if (opts == null ? void 0 : opts.configPath) {
|
|
1711
|
-
return { configPath: opts.configPath };
|
|
1712
|
-
}
|
|
1713
|
-
try {
|
|
1714
|
-
const vercelJsonString = import_node_fs3.default.readFileSync("./vercel.json", "utf-8");
|
|
1715
|
-
const vercelJson = JSON.parse(vercelJsonString);
|
|
1716
|
-
if (!((_a = vercelJson.microFrontends) == null ? void 0 : _a.config)) {
|
|
1717
|
-
throw new MicrofrontendError(
|
|
1718
|
-
`vercel.json file missing required field "microFrontends.config"`,
|
|
1719
|
-
{
|
|
1720
|
-
type: "vercelJson",
|
|
1721
|
-
subtype: "missing_field_microFrontend_config_path",
|
|
1722
|
-
source: "@vercel/microfrontends/next"
|
|
1723
|
-
}
|
|
1724
|
-
);
|
|
1725
|
-
}
|
|
1726
|
-
return { configPath: vercelJson.microFrontends.config };
|
|
1727
|
-
} catch (err) {
|
|
1728
|
-
throw MicrofrontendError.handle(err, {
|
|
1729
|
-
fileName: "vercel.json"
|
|
1730
|
-
});
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
2030
|
function getApplicationContext(opts) {
|
|
1734
2031
|
if (opts == null ? void 0 : opts.appName) {
|
|
1735
2032
|
return { name: opts.appName };
|
|
1736
2033
|
}
|
|
1737
2034
|
try {
|
|
1738
|
-
const packageJsonString =
|
|
2035
|
+
const packageJsonString = import_node_fs8.default.readFileSync("./package.json", "utf-8");
|
|
1739
2036
|
const packageJson = JSON.parse(packageJsonString);
|
|
1740
2037
|
if (!packageJson.name) {
|
|
1741
2038
|
throw new MicrofrontendError(
|
|
@@ -1759,13 +2056,15 @@ function withMicrofrontends(nextConfig, opts) {
|
|
|
1759
2056
|
if (opts == null ? void 0 : opts.debug) {
|
|
1760
2057
|
process.env.MFE_DEBUG = "true";
|
|
1761
2058
|
}
|
|
1762
|
-
const { name } = getApplicationContext(opts);
|
|
1763
|
-
const
|
|
1764
|
-
|
|
1765
|
-
|
|
2059
|
+
const { name: fromApp } = getApplicationContext(opts);
|
|
2060
|
+
const microfrontends = MicrofrontendsServer.infer({
|
|
2061
|
+
filePath: opts == null ? void 0 : opts.configPath,
|
|
2062
|
+
meta: {
|
|
2063
|
+
fromApp
|
|
2064
|
+
}
|
|
1766
2065
|
});
|
|
1767
|
-
const
|
|
1768
|
-
setEnvironment({
|
|
2066
|
+
const app = microfrontends.config.getApplication(fromApp);
|
|
2067
|
+
setEnvironment({ app, microfrontends });
|
|
1769
2068
|
let next = { ...nextConfig };
|
|
1770
2069
|
for (const [key, transform7] of typedEntries(transforms)) {
|
|
1771
2070
|
if ((_a = opts == null ? void 0 : opts.skipTransforms) == null ? void 0 : _a.includes(key)) {
|
|
@@ -1774,9 +2073,9 @@ function withMicrofrontends(nextConfig, opts) {
|
|
|
1774
2073
|
}
|
|
1775
2074
|
try {
|
|
1776
2075
|
const transformedConfig = transform7({
|
|
1777
|
-
|
|
2076
|
+
app,
|
|
1778
2077
|
next,
|
|
1779
|
-
microfrontend:
|
|
2078
|
+
microfrontend: microfrontends.config,
|
|
1780
2079
|
opts: {
|
|
1781
2080
|
isProduction: isProduction(opts)
|
|
1782
2081
|
}
|
|
@@ -1786,9 +2085,9 @@ function withMicrofrontends(nextConfig, opts) {
|
|
|
1786
2085
|
console.error("Error transforming next config", e);
|
|
1787
2086
|
}
|
|
1788
2087
|
}
|
|
1789
|
-
displayLocalProxyInfo(
|
|
2088
|
+
displayLocalProxyInfo(microfrontends.config.getLocalProxyPort());
|
|
1790
2089
|
if (isVercel()) {
|
|
1791
|
-
|
|
2090
|
+
microfrontends.writeConfig();
|
|
1792
2091
|
}
|
|
1793
2092
|
return next;
|
|
1794
2093
|
}
|