@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/testing.js
CHANGED
|
@@ -9,35 +9,8 @@ import { matchHas } from "next/dist/shared/lib/router/utils/prepare-destination"
|
|
|
9
9
|
import { NextRequestHint } from "next/dist/server/web/adapter";
|
|
10
10
|
import { WebNextRequest } from "next/dist/server/base-http/web";
|
|
11
11
|
|
|
12
|
-
// src/config/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// src/config/microfrontend-config.ts
|
|
16
|
-
import fs2 from "node:fs";
|
|
17
|
-
|
|
18
|
-
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
19
|
-
import path from "node:path";
|
|
20
|
-
|
|
21
|
-
// src/config-v2/microfrontends/server/constants.ts
|
|
22
|
-
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
23
|
-
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
24
|
-
|
|
25
|
-
// src/utils/is-vercel.ts
|
|
26
|
-
function isVercel() {
|
|
27
|
-
return process.env.VERCEL === "1";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
31
|
-
function getOutputFilePath() {
|
|
32
|
-
if (isVercel()) {
|
|
33
|
-
return path.join(
|
|
34
|
-
".vercel",
|
|
35
|
-
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
36
|
-
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return path.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
40
|
-
}
|
|
12
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
13
|
+
import { parse } from "jsonc-parser";
|
|
41
14
|
|
|
42
15
|
// src/config/errors.ts
|
|
43
16
|
var MicrofrontendError = class extends Error {
|
|
@@ -131,131 +104,299 @@ var MicrofrontendError = class extends Error {
|
|
|
131
104
|
}
|
|
132
105
|
};
|
|
133
106
|
|
|
134
|
-
// src/
|
|
135
|
-
function
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
107
|
+
// src/config/microfrontends-config/utils/get-config-from-env.ts
|
|
108
|
+
function getConfigStringFromEnv() {
|
|
109
|
+
const config = process.env.MFE_CONFIG;
|
|
110
|
+
if (!config) {
|
|
111
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
112
|
+
type: "config",
|
|
113
|
+
subtype: "not_found_in_env"
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return config;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/config/schema/utils/is-main-config.ts
|
|
120
|
+
function isMainConfig(c) {
|
|
121
|
+
return !("partOf" in c);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/config/schema/utils/is-default-app.ts
|
|
125
|
+
function isDefaultApp(a) {
|
|
126
|
+
return !("routing" in a);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/config/microfrontends-config/client/index.ts
|
|
130
|
+
import { pathToRegexp } from "path-to-regexp";
|
|
131
|
+
var MicrofrontendConfigClient = class {
|
|
132
|
+
constructor(config, opts) {
|
|
133
|
+
this.pathCache = {};
|
|
134
|
+
this.serialized = config;
|
|
135
|
+
if (opts == null ? void 0 : opts.removeFlaggedPaths) {
|
|
136
|
+
for (const app of Object.values(config.applications)) {
|
|
137
|
+
if (app.routing) {
|
|
138
|
+
app.routing = app.routing.filter((match2) => !match2.flag);
|
|
139
|
+
}
|
|
150
140
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
141
|
+
}
|
|
142
|
+
this.applications = config.applications;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Create a new `MicrofrontendConfigClient` from a JSON string.
|
|
146
|
+
* Config must be passed in to remain framework agnostic
|
|
147
|
+
*/
|
|
148
|
+
static fromEnv(config, opts) {
|
|
149
|
+
if (!config) {
|
|
150
|
+
throw new Error("No microfrontends configuration found");
|
|
151
|
+
}
|
|
152
|
+
return new MicrofrontendConfigClient(
|
|
153
|
+
JSON.parse(config),
|
|
154
|
+
opts
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
isEqual(other) {
|
|
158
|
+
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
159
|
+
}
|
|
160
|
+
getApplicationNameForPath(path) {
|
|
161
|
+
if (!path.startsWith("/")) {
|
|
162
|
+
throw new Error(`Path must start with a /`);
|
|
163
|
+
}
|
|
164
|
+
if (this.pathCache[path]) {
|
|
165
|
+
return this.pathCache[path];
|
|
166
|
+
}
|
|
167
|
+
const pathname = new URL(path, "https://example.com").pathname;
|
|
168
|
+
for (const [name, application] of Object.entries(this.applications)) {
|
|
169
|
+
if (application.routing) {
|
|
170
|
+
for (const group of application.routing) {
|
|
171
|
+
for (const childPath of group.paths) {
|
|
172
|
+
const regexp = pathToRegexp(childPath);
|
|
173
|
+
if (regexp.test(pathname)) {
|
|
174
|
+
this.pathCache[path] = name;
|
|
175
|
+
return name;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
157
178
|
}
|
|
158
179
|
}
|
|
159
|
-
tag = args.join(options.joinString);
|
|
160
|
-
tag = tag.replace(/\s/g, options.joinString);
|
|
161
|
-
if (options.lowercaseOnly)
|
|
162
|
-
tag = tag.toLowerCase();
|
|
163
|
-
tag = tag.replace(options.regexRemovePattern, (match2) => {
|
|
164
|
-
if (match2 === options.joinString)
|
|
165
|
-
return match2;
|
|
166
|
-
return "";
|
|
167
|
-
});
|
|
168
|
-
if (tag.length > options.maxLen)
|
|
169
|
-
tag = tag.substring(0, options.maxLen);
|
|
170
|
-
tag = tag.replace(reJoinString, options.joinString);
|
|
171
|
-
return tag;
|
|
172
180
|
}
|
|
181
|
+
const defaultApplication = Object.entries(this.applications).find(
|
|
182
|
+
([, application]) => application.default
|
|
183
|
+
);
|
|
184
|
+
if (!defaultApplication) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
this.pathCache[path] = defaultApplication[0];
|
|
188
|
+
return defaultApplication[0];
|
|
189
|
+
}
|
|
190
|
+
serialize() {
|
|
191
|
+
return this.serialized;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/config/overrides/constants.ts
|
|
196
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
197
|
+
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
198
|
+
|
|
199
|
+
// src/config/overrides/is-override-cookie.ts
|
|
200
|
+
function isOverrideCookie(cookie) {
|
|
201
|
+
var _a;
|
|
202
|
+
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// src/config/overrides/get-override-from-cookie.ts
|
|
206
|
+
function getOverrideFromCookie(cookie) {
|
|
207
|
+
if (!isOverrideCookie(cookie) || !cookie.value)
|
|
208
|
+
return;
|
|
209
|
+
return {
|
|
210
|
+
application: cookie.name.replace(OVERRIDES_ENV_COOKIE_PREFIX, ""),
|
|
211
|
+
host: cookie.value
|
|
173
212
|
};
|
|
174
213
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
214
|
+
|
|
215
|
+
// src/config/overrides/parse-overrides.ts
|
|
216
|
+
function parseOverrides(cookies) {
|
|
217
|
+
const overridesConfig = { applications: {} };
|
|
218
|
+
cookies.forEach((cookie) => {
|
|
219
|
+
const override = getOverrideFromCookie(cookie);
|
|
220
|
+
if (!override)
|
|
221
|
+
return;
|
|
222
|
+
overridesConfig.applications[override.application] = {
|
|
223
|
+
environment: { host: override.host }
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
return overridesConfig;
|
|
178
227
|
}
|
|
179
228
|
|
|
180
|
-
// src/config/
|
|
181
|
-
|
|
182
|
-
var
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
229
|
+
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
230
|
+
import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to-regexp";
|
|
231
|
+
var SUPPORTED_VERSIONS = ["2"];
|
|
232
|
+
var validateConfigVersion = (version) => {
|
|
233
|
+
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
234
|
+
throw new MicrofrontendError(
|
|
235
|
+
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
236
|
+
", "
|
|
237
|
+
)}`,
|
|
238
|
+
{ type: "config", subtype: "unsupported_version" }
|
|
239
|
+
);
|
|
188
240
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
241
|
+
};
|
|
242
|
+
var validateConfigPaths = (applicationConfigsById) => {
|
|
243
|
+
if (!applicationConfigsById) {
|
|
244
|
+
return;
|
|
192
245
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
246
|
+
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
247
|
+
const errors = [];
|
|
248
|
+
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
249
|
+
if (isDefaultApp(app)) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
for (const pathMatch of app.routing) {
|
|
253
|
+
for (const path of pathMatch.paths) {
|
|
254
|
+
const tokens = parsePathRegexp(path);
|
|
255
|
+
for (const token of tokens.slice(0, -1)) {
|
|
256
|
+
if (typeof token !== "string") {
|
|
257
|
+
errors.push(
|
|
258
|
+
`Path ${path} may only have a :wildcard in the last path component`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const existing = pathsByApplicationId.get(path);
|
|
263
|
+
if (existing) {
|
|
264
|
+
existing.applications.push(id);
|
|
265
|
+
} else {
|
|
266
|
+
pathsByApplicationId.set(path, {
|
|
267
|
+
applications: [id],
|
|
268
|
+
matcher: pathToRegexp2(path),
|
|
269
|
+
applicationId: id
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
200
274
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
275
|
+
const entries = Array.from(pathsByApplicationId.entries());
|
|
276
|
+
entries.forEach(([path, { applications: ids, matcher, applicationId }]) => {
|
|
277
|
+
if (ids.length > 1) {
|
|
278
|
+
errors.push(
|
|
279
|
+
`Duplicate path "${path}" for applications "${ids.join(", ")}"`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
entries.forEach(
|
|
283
|
+
([
|
|
284
|
+
matchPath,
|
|
285
|
+
{ applications: matchIds, applicationId: matchApplicationId }
|
|
286
|
+
]) => {
|
|
287
|
+
if (path === matchPath) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (applicationId === matchApplicationId) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (matcher.test(matchPath)) {
|
|
294
|
+
const source = `"${path}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
295
|
+
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
296
|
+
errors.push(
|
|
297
|
+
`Overlapping path detected between ${source} and ${destination}`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
});
|
|
303
|
+
if (errors.length) {
|
|
304
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
305
|
+
type: "config",
|
|
306
|
+
subtype: "conflicting_paths"
|
|
210
307
|
});
|
|
211
|
-
return overridesConfig;
|
|
212
308
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
309
|
+
};
|
|
310
|
+
var validateAppPaths = (name, app) => {
|
|
311
|
+
for (const group of app.routing) {
|
|
312
|
+
for (const p of group.paths) {
|
|
313
|
+
if (p === "/") {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (p.endsWith("/")) {
|
|
317
|
+
throw new MicrofrontendError(
|
|
318
|
+
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
319
|
+
{ type: "application", subtype: "invalid_path" }
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
if (!p.startsWith("/")) {
|
|
323
|
+
throw new MicrofrontendError(
|
|
324
|
+
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
325
|
+
{ type: "application", subtype: "invalid_path" }
|
|
326
|
+
);
|
|
327
|
+
}
|
|
224
328
|
}
|
|
225
|
-
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
226
|
-
return [
|
|
227
|
-
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
228
|
-
microfrontendConfig.getZone(zone).production.host
|
|
229
|
-
];
|
|
230
329
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
)}$`
|
|
236
|
-
).test(domain);
|
|
330
|
+
};
|
|
331
|
+
var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
332
|
+
if (!applicationConfigsById) {
|
|
333
|
+
return;
|
|
237
334
|
}
|
|
238
|
-
|
|
239
|
-
|
|
335
|
+
const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
|
|
336
|
+
([, app]) => !isDefaultApp(app)
|
|
337
|
+
);
|
|
338
|
+
const applicationsWithRoutingNames = applicationsWithRouting.map(
|
|
339
|
+
([key]) => key
|
|
340
|
+
);
|
|
341
|
+
const numApplications = Object.keys(applicationConfigsById).length;
|
|
342
|
+
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
343
|
+
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
344
|
+
if (numApplicationsWithoutRouting === 0) {
|
|
345
|
+
throw new MicrofrontendError(
|
|
346
|
+
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
347
|
+
{ type: "config", subtype: "no_default_application" }
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
if (numApplicationsWithoutRouting > 1) {
|
|
351
|
+
throw new MicrofrontendError(
|
|
352
|
+
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
353
|
+
{ type: "config", subtype: "multiple_default_applications" }
|
|
354
|
+
);
|
|
240
355
|
}
|
|
241
356
|
};
|
|
242
|
-
var Overrides = _Overrides;
|
|
243
|
-
Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
244
357
|
|
|
245
|
-
// src/config/
|
|
358
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
359
|
+
var PREFIX = "vc-ap";
|
|
360
|
+
function generateAssetPrefixFromName({
|
|
361
|
+
name
|
|
362
|
+
}) {
|
|
363
|
+
if (!name) {
|
|
364
|
+
throw new Error("Name is required to generate an asset prefix");
|
|
365
|
+
}
|
|
366
|
+
return `${PREFIX}-${name}`;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-port.ts
|
|
370
|
+
function generatePortFromName({
|
|
371
|
+
name,
|
|
372
|
+
minPort = 3e3,
|
|
373
|
+
maxPort = 8e3
|
|
374
|
+
}) {
|
|
375
|
+
if (!name) {
|
|
376
|
+
throw new Error("Name is required to generate a port");
|
|
377
|
+
}
|
|
378
|
+
let hash = 0;
|
|
379
|
+
for (let i = 0; i < name.length; i++) {
|
|
380
|
+
hash = (hash << 5) - hash + name.charCodeAt(i);
|
|
381
|
+
hash |= 0;
|
|
382
|
+
}
|
|
383
|
+
hash = Math.abs(hash);
|
|
384
|
+
const range = maxPort - minPort;
|
|
385
|
+
const port = minPort + hash % range;
|
|
386
|
+
return port;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// src/config/microfrontends-config/isomorphic/host.ts
|
|
246
390
|
var Host = class {
|
|
247
|
-
constructor(
|
|
248
|
-
|
|
391
|
+
constructor(hostConfig, options) {
|
|
392
|
+
const { protocol = "https", host, port } = hostConfig;
|
|
393
|
+
this.protocol = protocol;
|
|
249
394
|
this.host = host;
|
|
250
395
|
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
251
|
-
this.
|
|
252
|
-
protocol,
|
|
253
|
-
host,
|
|
254
|
-
...port ? { port } : void 0
|
|
255
|
-
};
|
|
396
|
+
this.local = options == null ? void 0 : options.isLocal;
|
|
256
397
|
}
|
|
257
398
|
isLocal() {
|
|
258
|
-
return this.host === "localhost" || this.host === "127.0.0.1";
|
|
399
|
+
return this.local || this.host === "localhost" || this.host === "127.0.0.1";
|
|
259
400
|
}
|
|
260
401
|
static getPort({
|
|
261
402
|
protocol,
|
|
@@ -281,176 +422,234 @@ var Host = class {
|
|
|
281
422
|
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
282
423
|
return new URL(url);
|
|
283
424
|
}
|
|
284
|
-
|
|
285
|
-
|
|
425
|
+
};
|
|
426
|
+
var LocalHost = class extends Host {
|
|
427
|
+
constructor({
|
|
428
|
+
appName,
|
|
429
|
+
...hostConfig
|
|
430
|
+
}) {
|
|
431
|
+
const host = hostConfig.host ?? "localhost";
|
|
432
|
+
const port = hostConfig.port ?? generatePortFromName({ name: appName });
|
|
433
|
+
const protocol = hostConfig.protocol ?? "http";
|
|
434
|
+
super({ protocol, host, port });
|
|
286
435
|
}
|
|
287
436
|
};
|
|
288
437
|
|
|
289
|
-
// src/config/
|
|
438
|
+
// src/config/microfrontends-config/isomorphic/application.ts
|
|
290
439
|
var Application = class {
|
|
291
440
|
constructor(name, {
|
|
292
441
|
app,
|
|
293
|
-
overrides
|
|
442
|
+
overrides,
|
|
443
|
+
isDefault
|
|
294
444
|
}) {
|
|
295
|
-
|
|
445
|
+
var _a, _b;
|
|
296
446
|
this.name = name;
|
|
297
|
-
this.default = app.default;
|
|
298
|
-
this.routing = app.routing;
|
|
299
447
|
this.development = {
|
|
300
|
-
local: new
|
|
301
|
-
|
|
448
|
+
local: new LocalHost({
|
|
449
|
+
appName: name,
|
|
450
|
+
...(_a = app.development) == null ? void 0 : _a.local
|
|
451
|
+
}),
|
|
452
|
+
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
|
|
302
453
|
};
|
|
303
|
-
this.production = new Host(app.production);
|
|
454
|
+
this.production = app.production ? new Host(app.production) : void 0;
|
|
304
455
|
this.vercel = app.vercel;
|
|
305
456
|
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
306
457
|
environment: new Host(overrides.environment)
|
|
307
458
|
} : void 0;
|
|
459
|
+
this.default = isDefault ?? false;
|
|
460
|
+
this.serialized = app;
|
|
308
461
|
}
|
|
309
462
|
isDefault() {
|
|
310
463
|
return this.default;
|
|
311
464
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
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("/"))) {
|
|
315
|
-
throw new MicrofrontendError(
|
|
316
|
-
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
317
|
-
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
for (const group of ((_e = app.routing) == null ? void 0 : _e.matches) ?? []) {
|
|
321
|
-
for (const p of group.paths) {
|
|
322
|
-
if (p === "/") {
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
if (p.endsWith("/")) {
|
|
326
|
-
throw new MicrofrontendError(
|
|
327
|
-
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
328
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
if (!p.startsWith("/")) {
|
|
332
|
-
throw new MicrofrontendError(
|
|
333
|
-
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
334
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
465
|
+
getAssetPrefix() {
|
|
466
|
+
return generateAssetPrefixFromName({ name: this.name });
|
|
339
467
|
}
|
|
340
468
|
serialize() {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
469
|
+
return this.serialized;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
var DefaultApplication = class extends Application {
|
|
473
|
+
constructor(name, {
|
|
474
|
+
app,
|
|
475
|
+
overrides
|
|
476
|
+
}) {
|
|
477
|
+
super(name, {
|
|
478
|
+
app,
|
|
479
|
+
overrides,
|
|
480
|
+
isDefault: true
|
|
481
|
+
});
|
|
482
|
+
this.default = true;
|
|
483
|
+
this.production = new Host(app.production);
|
|
484
|
+
}
|
|
485
|
+
getAssetPrefix() {
|
|
486
|
+
return "";
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
var ChildApplication = class extends Application {
|
|
490
|
+
constructor(name, {
|
|
491
|
+
app,
|
|
492
|
+
overrides
|
|
493
|
+
}) {
|
|
494
|
+
ChildApplication.validate(name, app);
|
|
495
|
+
super(name, {
|
|
496
|
+
app,
|
|
497
|
+
overrides,
|
|
498
|
+
isDefault: false
|
|
499
|
+
});
|
|
500
|
+
this.default = false;
|
|
501
|
+
this.routing = app.routing;
|
|
502
|
+
}
|
|
503
|
+
static validate(name, app) {
|
|
504
|
+
validateAppPaths(name, app);
|
|
363
505
|
}
|
|
364
506
|
};
|
|
365
507
|
|
|
366
|
-
// src/config/
|
|
367
|
-
var SUPPORTED_VERSIONS = ["1"];
|
|
508
|
+
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
368
509
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
369
|
-
|
|
510
|
+
|
|
511
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
512
|
+
var MicrofrontendConfigIsomorphic = class {
|
|
370
513
|
constructor({
|
|
371
514
|
config,
|
|
372
|
-
overrides
|
|
515
|
+
overrides,
|
|
516
|
+
meta
|
|
373
517
|
}) {
|
|
374
|
-
this.
|
|
375
|
-
var _a, _b, _c;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
518
|
+
this.childApplications = {};
|
|
519
|
+
var _a, _b, _c, _d;
|
|
520
|
+
MicrofrontendConfigIsomorphic.validate(config);
|
|
521
|
+
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
522
|
+
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
523
|
+
this.isMainConfig = isMainConfig(config);
|
|
524
|
+
if (isMainConfig(config)) {
|
|
525
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
526
|
+
const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
|
|
527
|
+
if (isDefaultApp(appConfig)) {
|
|
528
|
+
this.defaultApplication = new DefaultApplication(appId, {
|
|
529
|
+
app: appConfig,
|
|
530
|
+
overrides: appOverrides
|
|
531
|
+
});
|
|
532
|
+
} else {
|
|
533
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
534
|
+
app: appConfig,
|
|
535
|
+
overrides: appOverrides
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
} else {
|
|
540
|
+
this.partOf = config.partOf;
|
|
541
|
+
const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
|
|
542
|
+
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
543
|
+
meta.fromApp,
|
|
544
|
+
{
|
|
545
|
+
// we don't know routing because we're not in the main config
|
|
546
|
+
app: { routing: [] },
|
|
547
|
+
overrides: appOverrides
|
|
548
|
+
}
|
|
382
549
|
);
|
|
383
550
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
551
|
+
if (isMainConfig(config) && !this.defaultApplication) {
|
|
552
|
+
throw new MicrofrontendError(
|
|
553
|
+
`Could not find default application in microfrontends configuration`,
|
|
554
|
+
{
|
|
555
|
+
type: "application",
|
|
556
|
+
subtype: "not_found"
|
|
557
|
+
}
|
|
558
|
+
);
|
|
391
559
|
}
|
|
392
560
|
this.config = config;
|
|
393
|
-
this.name = config.name;
|
|
394
|
-
this.version = config.version;
|
|
395
561
|
this.options = config.options;
|
|
396
|
-
this
|
|
562
|
+
this.serialized = {
|
|
563
|
+
config,
|
|
564
|
+
overrides,
|
|
565
|
+
meta
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
static validate(config) {
|
|
569
|
+
const c = typeof config === "string" ? parse(config) : config;
|
|
570
|
+
if (isMainConfig(c)) {
|
|
571
|
+
validateConfigVersion(c.version);
|
|
572
|
+
validateConfigPaths(c.applications);
|
|
573
|
+
validateConfigDefaultApplication(c.applications);
|
|
574
|
+
}
|
|
575
|
+
return c;
|
|
576
|
+
}
|
|
577
|
+
static fromEnv({
|
|
578
|
+
meta,
|
|
579
|
+
cookies
|
|
580
|
+
}) {
|
|
581
|
+
return new MicrofrontendConfigIsomorphic({
|
|
582
|
+
config: parse(getConfigStringFromEnv()),
|
|
583
|
+
overrides: parseOverrides(cookies ?? []),
|
|
584
|
+
meta
|
|
585
|
+
});
|
|
397
586
|
}
|
|
398
587
|
isOverridesDisabled() {
|
|
399
588
|
var _a, _b;
|
|
400
589
|
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
401
590
|
}
|
|
402
|
-
static getConfigFromEnv() {
|
|
403
|
-
const config = process.env.MFE_CONFIG;
|
|
404
|
-
if (!config) {
|
|
405
|
-
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
406
|
-
type: "config",
|
|
407
|
-
subtype: "not_found_in_env"
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
return config;
|
|
411
|
-
}
|
|
412
|
-
static fromEnv(_) {
|
|
413
|
-
throw new Error("Not implemented");
|
|
414
|
-
}
|
|
415
591
|
getConfig() {
|
|
416
592
|
return this.config;
|
|
417
593
|
}
|
|
594
|
+
getApplicationsByType() {
|
|
595
|
+
return {
|
|
596
|
+
defaultApplication: this.defaultApplication,
|
|
597
|
+
applications: Object.values(this.childApplications)
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
getChildApplications() {
|
|
601
|
+
return Object.values(this.childApplications);
|
|
602
|
+
}
|
|
418
603
|
getAllApplications() {
|
|
419
|
-
return
|
|
604
|
+
return [
|
|
605
|
+
this.defaultApplication,
|
|
606
|
+
...Object.values(this.childApplications)
|
|
607
|
+
].filter(Boolean);
|
|
420
608
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (
|
|
609
|
+
getApplication(name) {
|
|
610
|
+
var _a;
|
|
611
|
+
if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
|
|
612
|
+
return this.defaultApplication;
|
|
613
|
+
}
|
|
614
|
+
const app = this.childApplications[name];
|
|
615
|
+
if (!app) {
|
|
424
616
|
throw new MicrofrontendError(
|
|
425
617
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
426
618
|
{
|
|
427
|
-
type: "
|
|
619
|
+
type: "application",
|
|
428
620
|
subtype: "not_found"
|
|
429
621
|
}
|
|
430
622
|
);
|
|
431
623
|
}
|
|
432
|
-
return
|
|
624
|
+
return app;
|
|
433
625
|
}
|
|
434
626
|
getApplicationByProjectId(projectId) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
627
|
+
var _a, _b;
|
|
628
|
+
if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
|
|
629
|
+
return this.defaultApplication;
|
|
630
|
+
}
|
|
631
|
+
return Object.values(this.childApplications).find(
|
|
632
|
+
(app) => {
|
|
633
|
+
var _a2;
|
|
634
|
+
return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
|
|
439
635
|
}
|
|
440
636
|
);
|
|
441
637
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
638
|
+
/**
|
|
639
|
+
* Returns the default application. This can throw if the default application
|
|
640
|
+
* is undefined ( )
|
|
641
|
+
*/
|
|
642
|
+
getDefaultApplication() {
|
|
643
|
+
if (!this.defaultApplication) {
|
|
445
644
|
throw new MicrofrontendError(
|
|
446
|
-
`Could not find default
|
|
645
|
+
`Could not find default application in microfrontends configuration`,
|
|
447
646
|
{
|
|
448
|
-
type: "
|
|
647
|
+
type: "application",
|
|
449
648
|
subtype: "not_found"
|
|
450
649
|
}
|
|
451
650
|
);
|
|
452
651
|
}
|
|
453
|
-
return
|
|
652
|
+
return this.defaultApplication;
|
|
454
653
|
}
|
|
455
654
|
/**
|
|
456
655
|
* Returns the configured port for the local proxy
|
|
@@ -465,764 +664,144 @@ var MicrofrontendConfigCommon = class {
|
|
|
465
664
|
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
466
665
|
*/
|
|
467
666
|
toSchemaJson() {
|
|
468
|
-
|
|
469
|
-
for (const [name, zone] of Object.entries(this.zones)) {
|
|
470
|
-
applications[name] = zone.serialize();
|
|
471
|
-
}
|
|
472
|
-
return {
|
|
473
|
-
$schema: this.$schema,
|
|
474
|
-
name: this.name,
|
|
475
|
-
version: this.version,
|
|
476
|
-
options: this.options,
|
|
477
|
-
applications
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
serialize() {
|
|
481
|
-
var _a;
|
|
482
|
-
const applications = {};
|
|
483
|
-
for (const [name, zone] of Object.entries(this.zones)) {
|
|
484
|
-
applications[name] = zone.serialize();
|
|
485
|
-
}
|
|
486
|
-
return {
|
|
487
|
-
config: {
|
|
488
|
-
name: this.name,
|
|
489
|
-
version: this.version,
|
|
490
|
-
applications,
|
|
491
|
-
options: this.options,
|
|
492
|
-
$schema: this.$schema
|
|
493
|
-
},
|
|
494
|
-
overrides: (_a = this.overrides) == null ? void 0 : _a.serialize()
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
write(_) {
|
|
498
|
-
throw new MicrofrontendError(
|
|
499
|
-
`Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
|
|
500
|
-
{ type: "config", subtype: "unsupported_operation" }
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
// src/config/utils/get-output-file-path.ts
|
|
506
|
-
import path2 from "node:path";
|
|
507
|
-
|
|
508
|
-
// src/config/constants.ts
|
|
509
|
-
var MFE_CONFIG_DEFAULT_FILE_PATH2 = "micro-frontends";
|
|
510
|
-
var MFE_CONFIG_DEFAULT_FILE_NAME2 = "micro-frontends.config.json";
|
|
511
|
-
|
|
512
|
-
// src/config/utils/get-output-file-path.ts
|
|
513
|
-
function getOutputFilePath2() {
|
|
514
|
-
if (isVercel()) {
|
|
515
|
-
return path2.join(
|
|
516
|
-
".vercel",
|
|
517
|
-
MFE_CONFIG_DEFAULT_FILE_PATH2,
|
|
518
|
-
MFE_CONFIG_DEFAULT_FILE_NAME2
|
|
519
|
-
);
|
|
667
|
+
return this.serialized.config;
|
|
520
668
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
import { parse } from "jsonc-parser";
|
|
526
|
-
import { pathToRegexp, parse as parsePathRegexp } from "path-to-regexp";
|
|
527
|
-
import { Ajv } from "ajv";
|
|
528
|
-
|
|
529
|
-
// schema/schema.json
|
|
530
|
-
var schema_default = {
|
|
531
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
532
|
-
$ref: "#/definitions/Config",
|
|
533
|
-
definitions: {
|
|
534
|
-
Config: {
|
|
535
|
-
type: "object",
|
|
536
|
-
properties: {
|
|
537
|
-
version: {
|
|
538
|
-
type: "string"
|
|
539
|
-
},
|
|
540
|
-
$schema: {
|
|
541
|
-
type: "string"
|
|
542
|
-
},
|
|
543
|
-
name: {
|
|
544
|
-
type: "string",
|
|
545
|
-
description: 'Name for the micro-frontend site (eg. "vercel.com", "vercel-site" etc.).'
|
|
546
|
-
},
|
|
547
|
-
applications: {
|
|
548
|
-
$ref: "#/definitions/ApplicationConfigsById"
|
|
549
|
-
},
|
|
550
|
-
options: {
|
|
551
|
-
$ref: "#/definitions/Options",
|
|
552
|
-
description: "Optional configuration for the entire micro-frontends setup."
|
|
553
|
-
}
|
|
554
|
-
},
|
|
555
|
-
required: ["version", "applications"],
|
|
556
|
-
description: "Configuration for micro-frontend applications\n\nTODO: Add proxy configuration"
|
|
557
|
-
},
|
|
558
|
-
ApplicationConfigsById: {
|
|
559
|
-
type: "object",
|
|
560
|
-
additionalProperties: {
|
|
561
|
-
$ref: "#/definitions/ApplicationConfig"
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
ApplicationConfig: {
|
|
565
|
-
anyOf: [
|
|
566
|
-
{
|
|
567
|
-
$ref: "#/definitions/DefaultApplicationConfig"
|
|
568
|
-
},
|
|
669
|
+
toClientConfig() {
|
|
670
|
+
const applications = Object.fromEntries(
|
|
671
|
+
Object.entries(this.childApplications).map(([name, application]) => [
|
|
672
|
+
name,
|
|
569
673
|
{
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
],
|
|
573
|
-
description: "A Micro-Frontend Deployment Target"
|
|
574
|
-
},
|
|
575
|
-
DefaultApplicationConfig: {
|
|
576
|
-
type: "object",
|
|
577
|
-
properties: {
|
|
578
|
-
default: {
|
|
579
|
-
type: "boolean",
|
|
580
|
-
const: true,
|
|
581
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
582
|
-
},
|
|
583
|
-
routing: {
|
|
584
|
-
$ref: "#/definitions/Routing"
|
|
585
|
-
},
|
|
586
|
-
development: {
|
|
587
|
-
type: "object",
|
|
588
|
-
properties: {
|
|
589
|
-
local: {
|
|
590
|
-
$ref: "#/definitions/HostConfig"
|
|
591
|
-
},
|
|
592
|
-
fallback: {
|
|
593
|
-
$ref: "#/definitions/HostConfig",
|
|
594
|
-
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."
|
|
595
|
-
},
|
|
596
|
-
task: {
|
|
597
|
-
type: "string",
|
|
598
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
599
|
-
}
|
|
600
|
-
},
|
|
601
|
-
required: ["local"]
|
|
602
|
-
},
|
|
603
|
-
production: {
|
|
604
|
-
$ref: "#/definitions/HostConfig"
|
|
605
|
-
},
|
|
606
|
-
metadata: {
|
|
607
|
-
type: "object",
|
|
608
|
-
additionalProperties: {
|
|
609
|
-
type: "string"
|
|
610
|
-
}
|
|
611
|
-
},
|
|
612
|
-
federation: {
|
|
613
|
-
type: "object",
|
|
614
|
-
properties: {
|
|
615
|
-
exposes: {
|
|
616
|
-
type: "array",
|
|
617
|
-
items: {
|
|
618
|
-
type: "object",
|
|
619
|
-
properties: {
|
|
620
|
-
name: {
|
|
621
|
-
type: "string",
|
|
622
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
623
|
-
},
|
|
624
|
-
path: {
|
|
625
|
-
type: "string",
|
|
626
|
-
description: "Relative path to the module within its `application`"
|
|
627
|
-
}
|
|
628
|
-
},
|
|
629
|
-
required: ["name", "path"]
|
|
630
|
-
},
|
|
631
|
-
description: "Modules that are exposed by this application"
|
|
632
|
-
},
|
|
633
|
-
uses: {
|
|
634
|
-
type: "array",
|
|
635
|
-
items: {
|
|
636
|
-
type: "string"
|
|
637
|
-
},
|
|
638
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
},
|
|
642
|
-
vercel: {
|
|
643
|
-
$ref: "#/definitions/Vercel"
|
|
644
|
-
}
|
|
645
|
-
},
|
|
646
|
-
required: ["default", "development", "production"]
|
|
647
|
-
},
|
|
648
|
-
Routing: {
|
|
649
|
-
type: "object",
|
|
650
|
-
properties: {
|
|
651
|
-
assetPrefix: {
|
|
652
|
-
type: "string",
|
|
653
|
-
description: "[assetPrefix] for the application"
|
|
654
|
-
},
|
|
655
|
-
matches: {
|
|
656
|
-
type: "array",
|
|
657
|
-
items: {
|
|
658
|
-
$ref: "#/definitions/PathGroup"
|
|
659
|
-
},
|
|
660
|
-
description: "Path expressions that are routed to this application."
|
|
661
|
-
}
|
|
662
|
-
},
|
|
663
|
-
required: ["matches"]
|
|
664
|
-
},
|
|
665
|
-
PathGroup: {
|
|
666
|
-
type: "object",
|
|
667
|
-
properties: {
|
|
668
|
-
group: {
|
|
669
|
-
type: "string",
|
|
670
|
-
description: "Optional group name for the paths"
|
|
671
|
-
},
|
|
672
|
-
options: {
|
|
673
|
-
type: "object",
|
|
674
|
-
properties: {
|
|
675
|
-
flag: {
|
|
676
|
-
type: "string",
|
|
677
|
-
description: "flag name that can be used to enable/disable all paths in the group"
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
},
|
|
681
|
-
paths: {
|
|
682
|
-
type: "array",
|
|
683
|
-
items: {
|
|
684
|
-
type: "string"
|
|
685
|
-
}
|
|
674
|
+
default: false,
|
|
675
|
+
routing: application.routing
|
|
686
676
|
}
|
|
687
|
-
|
|
688
|
-
required: ["paths"]
|
|
689
|
-
},
|
|
690
|
-
HostConfig: {
|
|
691
|
-
type: "object",
|
|
692
|
-
properties: {
|
|
693
|
-
protocol: {
|
|
694
|
-
type: "string",
|
|
695
|
-
enum: ["http", "https"],
|
|
696
|
-
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"'
|
|
697
|
-
},
|
|
698
|
-
host: {
|
|
699
|
-
type: "string",
|
|
700
|
-
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`)."
|
|
701
|
-
},
|
|
702
|
-
port: {
|
|
703
|
-
type: "number",
|
|
704
|
-
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS.\n\nThis field is optional and can be omitted if the default ports for the specified protocol are used"
|
|
705
|
-
}
|
|
706
|
-
},
|
|
707
|
-
required: ["host"]
|
|
708
|
-
},
|
|
709
|
-
Vercel: {
|
|
710
|
-
type: "object",
|
|
711
|
-
properties: {
|
|
712
|
-
projectId: {
|
|
713
|
-
type: "string",
|
|
714
|
-
description: "Vercel project ID"
|
|
715
|
-
},
|
|
716
|
-
projectName: {
|
|
717
|
-
type: "string",
|
|
718
|
-
description: "Vercel project name (temporary until we can use project ID)"
|
|
719
|
-
},
|
|
720
|
-
defaultRoute: {
|
|
721
|
-
type: "string",
|
|
722
|
-
description: "The default route for the application. Used to render screenshots, favicons, and provide direct zone links"
|
|
723
|
-
},
|
|
724
|
-
routeSpeedInsightsToDefaultZone: {
|
|
725
|
-
type: "boolean",
|
|
726
|
-
description: "Whether to route Speed Insights to the default zone or each individual microfrontend."
|
|
727
|
-
}
|
|
728
|
-
},
|
|
729
|
-
required: ["projectId"]
|
|
730
|
-
},
|
|
731
|
-
CommonApplicationConfig: {
|
|
732
|
-
type: "object",
|
|
733
|
-
properties: {
|
|
734
|
-
default: {
|
|
735
|
-
type: "boolean",
|
|
736
|
-
const: false,
|
|
737
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
738
|
-
},
|
|
739
|
-
routing: {
|
|
740
|
-
$ref: "#/definitions/Routing"
|
|
741
|
-
},
|
|
742
|
-
development: {
|
|
743
|
-
type: "object",
|
|
744
|
-
properties: {
|
|
745
|
-
local: {
|
|
746
|
-
$ref: "#/definitions/HostConfig"
|
|
747
|
-
},
|
|
748
|
-
fallback: {
|
|
749
|
-
$ref: "#/definitions/HostConfig",
|
|
750
|
-
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."
|
|
751
|
-
},
|
|
752
|
-
task: {
|
|
753
|
-
type: "string",
|
|
754
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
755
|
-
}
|
|
756
|
-
},
|
|
757
|
-
required: ["local"]
|
|
758
|
-
},
|
|
759
|
-
production: {
|
|
760
|
-
$ref: "#/definitions/HostConfig"
|
|
761
|
-
},
|
|
762
|
-
metadata: {
|
|
763
|
-
type: "object",
|
|
764
|
-
additionalProperties: {
|
|
765
|
-
type: "string"
|
|
766
|
-
}
|
|
767
|
-
},
|
|
768
|
-
federation: {
|
|
769
|
-
type: "object",
|
|
770
|
-
properties: {
|
|
771
|
-
exposes: {
|
|
772
|
-
type: "array",
|
|
773
|
-
items: {
|
|
774
|
-
type: "object",
|
|
775
|
-
properties: {
|
|
776
|
-
name: {
|
|
777
|
-
type: "string",
|
|
778
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
779
|
-
},
|
|
780
|
-
path: {
|
|
781
|
-
type: "string",
|
|
782
|
-
description: "Relative path to the module within its `application`"
|
|
783
|
-
}
|
|
784
|
-
},
|
|
785
|
-
required: ["name", "path"]
|
|
786
|
-
},
|
|
787
|
-
description: "Modules that are exposed by this application"
|
|
788
|
-
},
|
|
789
|
-
uses: {
|
|
790
|
-
type: "array",
|
|
791
|
-
items: {
|
|
792
|
-
type: "string"
|
|
793
|
-
},
|
|
794
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
},
|
|
798
|
-
vercel: {
|
|
799
|
-
$ref: "#/definitions/Vercel"
|
|
800
|
-
}
|
|
801
|
-
},
|
|
802
|
-
required: ["default", "development", "production", "routing"]
|
|
803
|
-
},
|
|
804
|
-
Options: {
|
|
805
|
-
type: "object",
|
|
806
|
-
properties: {
|
|
807
|
-
vercel: {
|
|
808
|
-
$ref: "#/definitions/VercelOptions",
|
|
809
|
-
description: "Micro-Frontends wide options for Vercel."
|
|
810
|
-
},
|
|
811
|
-
localProxy: {
|
|
812
|
-
$ref: "#/definitions/LocalProxyOptions",
|
|
813
|
-
description: "Options for local proxy."
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
},
|
|
817
|
-
VercelOptions: {
|
|
818
|
-
type: "object",
|
|
819
|
-
properties: {
|
|
820
|
-
previewDeploymentSuffix: {
|
|
821
|
-
type: "string",
|
|
822
|
-
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`."
|
|
823
|
-
},
|
|
824
|
-
teamSlug: {
|
|
825
|
-
type: "string",
|
|
826
|
-
description: "Team slug for the Vercel team"
|
|
827
|
-
},
|
|
828
|
-
disableOverrides: {
|
|
829
|
-
type: "boolean",
|
|
830
|
-
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."
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
},
|
|
834
|
-
LocalProxyOptions: {
|
|
835
|
-
type: "object",
|
|
836
|
-
properties: {
|
|
837
|
-
port: {
|
|
838
|
-
type: "number",
|
|
839
|
-
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
// src/config/utils/load-schema.ts
|
|
847
|
-
var SCHEMA = schema_default;
|
|
848
|
-
|
|
849
|
-
// src/config/validation.ts
|
|
850
|
-
var validateSchema = (configString) => {
|
|
851
|
-
const parsedConfig = parse(configString);
|
|
852
|
-
const ajv = new Ajv();
|
|
853
|
-
const validate = ajv.compile(SCHEMA);
|
|
854
|
-
const isValid = validate(parsedConfig);
|
|
855
|
-
if (!isValid) {
|
|
856
|
-
throw new MicrofrontendError(
|
|
857
|
-
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
858
|
-
{ type: "config", subtype: "does_not_match_schema" }
|
|
859
|
-
);
|
|
860
|
-
}
|
|
861
|
-
return parsedConfig;
|
|
862
|
-
};
|
|
863
|
-
var SUPPORTED_VERSIONS2 = ["1"];
|
|
864
|
-
var validateVersion = (version) => {
|
|
865
|
-
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
866
|
-
throw new MicrofrontendError(
|
|
867
|
-
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
868
|
-
", "
|
|
869
|
-
)}`,
|
|
870
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
677
|
+
])
|
|
871
678
|
);
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const { defaultRoute } = app.vercel ?? {};
|
|
877
|
-
if (!defaultRoute) {
|
|
878
|
-
continue;
|
|
879
|
-
}
|
|
880
|
-
if (isDefaultApplicationConfig(app)) {
|
|
881
|
-
const pathsWithApp = [];
|
|
882
|
-
for (const [otherId, otherApp] of Object.entries(
|
|
883
|
-
applicationConfigsById
|
|
884
|
-
)) {
|
|
885
|
-
if (isDefaultApplicationConfig(otherApp)) {
|
|
886
|
-
continue;
|
|
887
|
-
}
|
|
888
|
-
pathsWithApp.push({
|
|
889
|
-
id: otherId,
|
|
890
|
-
paths: otherApp.routing.matches.flatMap((match2) => match2.paths)
|
|
891
|
-
});
|
|
892
|
-
}
|
|
893
|
-
for (const { id: otherId, paths } of pathsWithApp) {
|
|
894
|
-
const isValid = paths.every((path3) => {
|
|
895
|
-
const matcher = pathToRegexp(path3);
|
|
896
|
-
return !matcher.test(defaultRoute);
|
|
897
|
-
});
|
|
898
|
-
if (!isValid) {
|
|
899
|
-
throw new MicrofrontendError(
|
|
900
|
-
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
901
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
902
|
-
);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
} else {
|
|
906
|
-
const allPaths = app.routing.matches.flatMap((match2) => match2.paths);
|
|
907
|
-
const isValid = allPaths.some((path3) => {
|
|
908
|
-
const matcher = pathToRegexp(path3);
|
|
909
|
-
return matcher.test(defaultRoute);
|
|
910
|
-
});
|
|
911
|
-
if (!isValid) {
|
|
912
|
-
throw new MicrofrontendError(
|
|
913
|
-
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
914
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
915
|
-
);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
var validatePaths = (applicationConfigsById) => {
|
|
921
|
-
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
922
|
-
const errors = [];
|
|
923
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
924
|
-
if (isDefaultApplicationConfig(app)) {
|
|
925
|
-
continue;
|
|
926
|
-
}
|
|
927
|
-
for (const pathMatch of app.routing.matches) {
|
|
928
|
-
for (const path3 of pathMatch.paths) {
|
|
929
|
-
const maybeError = validatePathExpression(path3);
|
|
930
|
-
if (maybeError) {
|
|
931
|
-
errors.push(maybeError);
|
|
932
|
-
}
|
|
933
|
-
const existing = pathsByApplicationId.get(path3);
|
|
934
|
-
if (existing) {
|
|
935
|
-
existing.applications.push(id);
|
|
936
|
-
} else {
|
|
937
|
-
pathsByApplicationId.set(path3, {
|
|
938
|
-
applications: [id],
|
|
939
|
-
matcher: pathToRegexp(path3),
|
|
940
|
-
applicationId: id
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
const entries = Array.from(pathsByApplicationId.entries());
|
|
947
|
-
entries.forEach(([path3, { applications: ids, matcher, applicationId }]) => {
|
|
948
|
-
if (ids.length > 1) {
|
|
949
|
-
errors.push(
|
|
950
|
-
`Duplicate path "${path3}" for applications "${ids.join(", ")}"`
|
|
951
|
-
);
|
|
679
|
+
if (this.defaultApplication) {
|
|
680
|
+
applications[this.defaultApplication.name] = {
|
|
681
|
+
default: true
|
|
682
|
+
};
|
|
952
683
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
matchPath,
|
|
956
|
-
{ applications: matchIds, applicationId: matchApplicationId }
|
|
957
|
-
]) => {
|
|
958
|
-
if (path3 === matchPath) {
|
|
959
|
-
return;
|
|
960
|
-
}
|
|
961
|
-
if (applicationId === matchApplicationId) {
|
|
962
|
-
return;
|
|
963
|
-
}
|
|
964
|
-
if (matcher.test(matchPath)) {
|
|
965
|
-
const source = `"${path3}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
966
|
-
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
967
|
-
errors.push(
|
|
968
|
-
`Overlapping path detected between ${source} and ${destination}`
|
|
969
|
-
);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
);
|
|
973
|
-
});
|
|
974
|
-
if (errors.length) {
|
|
975
|
-
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
976
|
-
type: "config",
|
|
977
|
-
subtype: "conflicting_paths"
|
|
684
|
+
return new MicrofrontendConfigClient({
|
|
685
|
+
applications
|
|
978
686
|
});
|
|
979
687
|
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
function validatePathExpression(path3) {
|
|
983
|
-
const tokens = parsePathRegexp(path3);
|
|
984
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
985
|
-
const token = tokens[i];
|
|
986
|
-
if (token === void 0) {
|
|
987
|
-
return `token ${i} in ${path3} is undefined, this shouldn't happen`;
|
|
988
|
-
}
|
|
989
|
-
if (typeof token !== "string") {
|
|
990
|
-
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
991
|
-
return `Path ${path3} cannot use a regular expression wildcard`;
|
|
992
|
-
}
|
|
993
|
-
if (token.prefix !== "/") {
|
|
994
|
-
return `Wildcard :${token.name} must be immediately after a / in ${path3}`;
|
|
995
|
-
}
|
|
996
|
-
if (token.suffix) {
|
|
997
|
-
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
998
|
-
}
|
|
999
|
-
if (token.modifier && i !== tokens.length - 1) {
|
|
1000
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path3}. Modifiers are only allowed in the last path component`;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
return void 0;
|
|
1005
|
-
}
|
|
1006
|
-
var validateDefaults = (applicationConfigsById) => {
|
|
1007
|
-
const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
|
|
1008
|
-
if (defaultApplicationIds.length === 0) {
|
|
1009
|
-
throw new MicrofrontendError(
|
|
1010
|
-
`No default application found. At least one application must be marked as default.`,
|
|
1011
|
-
{ type: "config", subtype: "no_default_application" }
|
|
1012
|
-
);
|
|
1013
|
-
}
|
|
1014
|
-
if (defaultApplicationIds.length > 1) {
|
|
1015
|
-
throw new MicrofrontendError(
|
|
1016
|
-
`Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
|
|
1017
|
-
{ type: "config", subtype: "multiple_default_applications" }
|
|
1018
|
-
);
|
|
1019
|
-
}
|
|
1020
|
-
};
|
|
1021
|
-
var validateOptions = (options) => {
|
|
1022
|
-
var _a;
|
|
1023
|
-
if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
|
|
1024
|
-
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1025
|
-
options.vercel.previewDeploymentSuffix
|
|
1026
|
-
)) {
|
|
1027
|
-
throw new MicrofrontendError(
|
|
1028
|
-
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1029
|
-
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1030
|
-
);
|
|
1031
|
-
}
|
|
688
|
+
serialize() {
|
|
689
|
+
return this.serialized;
|
|
1032
690
|
}
|
|
1033
691
|
};
|
|
1034
692
|
|
|
1035
|
-
// src/
|
|
1036
|
-
function
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
};
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
function convertV1ApplicationToV2Application(application) {
|
|
1047
|
-
const common = {
|
|
1048
|
-
production: application.production,
|
|
1049
|
-
development: application.development,
|
|
1050
|
-
vercel: application.vercel
|
|
1051
|
-
};
|
|
1052
|
-
if (application.default) {
|
|
1053
|
-
return common;
|
|
1054
|
-
}
|
|
1055
|
-
return {
|
|
1056
|
-
...common,
|
|
1057
|
-
routing: convertV1RoutingToV2Routing(application.routing)
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
function convertV1ConfigToV2Config(config, fromApp) {
|
|
1061
|
-
if (!config.applications[fromApp]) {
|
|
1062
|
-
throw new Error(`Application "${fromApp}" not found in the config`);
|
|
1063
|
-
}
|
|
1064
|
-
const common = {
|
|
1065
|
-
version: "2",
|
|
1066
|
-
options: config.options
|
|
1067
|
-
};
|
|
1068
|
-
if (config.applications[fromApp].default) {
|
|
1069
|
-
return {
|
|
1070
|
-
...common,
|
|
1071
|
-
applications: Object.fromEntries(
|
|
1072
|
-
Object.entries(config.applications).map(([id, application]) => [
|
|
1073
|
-
id,
|
|
1074
|
-
convertV1ApplicationToV2Application(application)
|
|
1075
|
-
])
|
|
1076
|
-
)
|
|
1077
|
-
};
|
|
1078
|
-
}
|
|
1079
|
-
const defaultApplication = Object.entries(config.applications).find(
|
|
1080
|
-
([, application]) => application.default
|
|
1081
|
-
);
|
|
1082
|
-
if (!defaultApplication) {
|
|
1083
|
-
throw new Error("No default application found in the config");
|
|
1084
|
-
}
|
|
1085
|
-
return {
|
|
1086
|
-
...common,
|
|
1087
|
-
partOf: defaultApplication[0]
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
// src/config/utils/write-file.ts
|
|
1092
|
-
import fs from "node:fs";
|
|
1093
|
-
import { dirname } from "node:path";
|
|
1094
|
-
function writeFile(outputPath, config, prettify) {
|
|
1095
|
-
fs.mkdirSync(dirname(outputPath), { recursive: true });
|
|
1096
|
-
fs.writeFileSync(
|
|
1097
|
-
outputPath,
|
|
1098
|
-
JSON.stringify(config, null, prettify ? 2 : void 0)
|
|
693
|
+
// src/routing/get-domain-from-environment.ts
|
|
694
|
+
function getDomainFromEnvironment({
|
|
695
|
+
app,
|
|
696
|
+
target
|
|
697
|
+
}) {
|
|
698
|
+
var _a;
|
|
699
|
+
const mfeProjects = JSON.parse(
|
|
700
|
+
process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "[]"
|
|
1099
701
|
);
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
// src/config/microfrontend-config.ts
|
|
1103
|
-
var MicrofrontendConfig = class extends MicrofrontendConfigCommon {
|
|
1104
|
-
static validate(configString) {
|
|
1105
|
-
const config = validateSchema(configString);
|
|
1106
|
-
validateVersion(config.version);
|
|
1107
|
-
validatePaths(config.applications);
|
|
1108
|
-
validateMainPath(config.applications);
|
|
1109
|
-
validateDefaults(config.applications);
|
|
1110
|
-
validateOptions(config.options);
|
|
1111
|
-
return config;
|
|
702
|
+
if (mfeProjects.length === 0) {
|
|
703
|
+
throw new Error("Missing related microfrontends project information");
|
|
1112
704
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
}) {
|
|
1116
|
-
return new MicrofrontendConfigCommon({
|
|
1117
|
-
config: MicrofrontendConfig.validate(
|
|
1118
|
-
MicrofrontendConfigCommon.getConfigFromEnv()
|
|
1119
|
-
),
|
|
1120
|
-
overrides: Overrides.parseOverrides(cookies)
|
|
1121
|
-
});
|
|
705
|
+
if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
|
|
706
|
+
throw new Error(`Missing applications[${app.name}].vercel.projectId`);
|
|
1122
707
|
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
const config = fs2.readFileSync(filePath, "utf-8");
|
|
1128
|
-
return new MicrofrontendConfig({
|
|
1129
|
-
config: MicrofrontendConfig.validate(config)
|
|
1130
|
-
});
|
|
1131
|
-
} catch (e) {
|
|
1132
|
-
throw MicrofrontendError.handle(e, {
|
|
1133
|
-
fileName: filePath
|
|
1134
|
-
});
|
|
708
|
+
const vercelProject = mfeProjects.find(
|
|
709
|
+
(p) => {
|
|
710
|
+
var _a2;
|
|
711
|
+
return p.project.id === ((_a2 = app.vercel) == null ? void 0 : _a2.projectId);
|
|
1135
712
|
}
|
|
713
|
+
);
|
|
714
|
+
if (!vercelProject) {
|
|
715
|
+
throw new Error(
|
|
716
|
+
`Missing related microfrontends project information for application "${app.name}"`
|
|
717
|
+
);
|
|
1136
718
|
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
const config = this.toSchemaJson();
|
|
1143
|
-
if (versions.includes("v1")) {
|
|
1144
|
-
const outputPath = getOutputFilePath2();
|
|
1145
|
-
writeFile(outputPath, config, pretty);
|
|
1146
|
-
}
|
|
1147
|
-
if (versions.includes("v2")) {
|
|
1148
|
-
const outputPath = getOutputFilePath();
|
|
1149
|
-
const v2Config = convertV1ConfigToV2Config(config, fromApp);
|
|
1150
|
-
writeFile(outputPath, v2Config, pretty);
|
|
1151
|
-
}
|
|
719
|
+
const domain = target === "preview" && vercelProject.preview.branch ? vercelProject.preview.branch : vercelProject.production.alias ?? vercelProject.production.url;
|
|
720
|
+
if (!domain) {
|
|
721
|
+
throw new Error(
|
|
722
|
+
`Missing domain for target "${target}" in application "${app.name}"`
|
|
723
|
+
);
|
|
1152
724
|
}
|
|
1153
|
-
}
|
|
725
|
+
return domain.startsWith("https://") ? domain : `https://${domain}`;
|
|
726
|
+
}
|
|
1154
727
|
|
|
1155
728
|
// src/next/testing/index.ts
|
|
1156
|
-
function expandWildcards(
|
|
1157
|
-
if (
|
|
729
|
+
function expandWildcards(path) {
|
|
730
|
+
if (path.includes("/:path*") || path.includes("/:slug*")) {
|
|
1158
731
|
return [
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
732
|
+
path === "/:path*" || path === "/:slug*" ? "/" : path.replace("/:path*", "").replace("/:slug*", ""),
|
|
733
|
+
path.replace("/:path*", "/foo").replace("/:slug*", "/foo"),
|
|
734
|
+
path.replace("/:path*", "/foo/bar").replace("/:slug*", "/foo/bar")
|
|
1162
735
|
];
|
|
1163
736
|
}
|
|
1164
|
-
if (
|
|
737
|
+
if (path.includes("/:path+") || path.includes("/:slug+")) {
|
|
1165
738
|
return [
|
|
1166
|
-
|
|
1167
|
-
|
|
739
|
+
path.replace("/:path+", "/foo").replace("/:slug+", "/foo"),
|
|
740
|
+
path.replace("/:path+", "/foo/bar").replace("/:slug+", "/foo/bar")
|
|
1168
741
|
];
|
|
1169
742
|
}
|
|
1170
|
-
if (
|
|
1171
|
-
return [
|
|
743
|
+
if (path.includes("/:path") || path.includes("/:slug")) {
|
|
744
|
+
return [path.replace("/:path", "/foo").replace("/:slug", "/foo")];
|
|
1172
745
|
}
|
|
1173
|
-
return [
|
|
746
|
+
return [path];
|
|
1174
747
|
}
|
|
1175
|
-
function loadMicrofrontendConfigForEdge(
|
|
1176
|
-
const rawMfConfig = parse2(readFileSync(
|
|
1177
|
-
return new
|
|
748
|
+
function loadMicrofrontendConfigForEdge(path) {
|
|
749
|
+
const rawMfConfig = parse2(readFileSync(path, "utf-8"));
|
|
750
|
+
return new MicrofrontendConfigIsomorphic({
|
|
751
|
+
config: rawMfConfig,
|
|
752
|
+
meta: { fromApp: "test" }
|
|
753
|
+
});
|
|
1178
754
|
}
|
|
1179
|
-
function
|
|
1180
|
-
return mfConfig.
|
|
755
|
+
function getAllChildApplicationNames(mfConfig) {
|
|
756
|
+
return mfConfig.getChildApplications().map((app) => app.name);
|
|
1181
757
|
}
|
|
1182
|
-
function
|
|
1183
|
-
|
|
1184
|
-
|
|
758
|
+
function getLaunchedPathsForApp(mfConfig, appName) {
|
|
759
|
+
const app = mfConfig.getApplication(appName);
|
|
760
|
+
if (app instanceof DefaultApplication) {
|
|
761
|
+
return [];
|
|
762
|
+
}
|
|
1185
763
|
return [
|
|
1186
|
-
|
|
1187
|
-
...((
|
|
1188
|
-
var _a2;
|
|
1189
|
-
return !((_a2 = group.options) == null ? void 0 : _a2.flag);
|
|
1190
|
-
}).flatMap((group) => group.paths.flatMap(expandWildcards))) ?? []
|
|
764
|
+
`/${app.getAssetPrefix()}/_next/static`,
|
|
765
|
+
...app.routing.filter((group) => !group.flag).flatMap((group) => group.paths.flatMap(expandWildcards))
|
|
1191
766
|
];
|
|
1192
767
|
}
|
|
1193
|
-
function
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
}).flatMap((group) => group.paths.flatMap(expandWildcards))) ?? [];
|
|
768
|
+
function getFlaggedPathsForApp(mfConfig, appName) {
|
|
769
|
+
const app = mfConfig.getApplication(appName);
|
|
770
|
+
if (app instanceof DefaultApplication) {
|
|
771
|
+
return [];
|
|
772
|
+
}
|
|
773
|
+
return app.routing.filter((group) => Boolean(group.flag)).flatMap((group) => group.paths.flatMap(expandWildcards));
|
|
1200
774
|
}
|
|
1201
|
-
function
|
|
1202
|
-
const
|
|
1203
|
-
|
|
775
|
+
function getExpectedDomainForApp(mfConfig, appName, env) {
|
|
776
|
+
const app = mfConfig.getApplication(appName);
|
|
777
|
+
const defaultApp = mfConfig.getDefaultApplication();
|
|
778
|
+
if (env === "development") {
|
|
779
|
+
return app.development.local.toString();
|
|
780
|
+
}
|
|
781
|
+
if (["preview", "production"].includes(env)) {
|
|
782
|
+
const target = env;
|
|
783
|
+
return getDomainFromEnvironment({ app, target });
|
|
784
|
+
}
|
|
785
|
+
return defaultApp.production.toString();
|
|
1204
786
|
}
|
|
1205
787
|
function getAllMultiZonesPaths(mfConfig) {
|
|
1206
|
-
return mfConfig.
|
|
1207
|
-
|
|
1208
|
-
return ((_a = app.routing) == null ? void 0 : _a.matches.flatMap(
|
|
1209
|
-
(group) => group.paths.flatMap(expandWildcards)
|
|
1210
|
-
)) ?? [];
|
|
788
|
+
return mfConfig.getChildApplications().flatMap((app) => {
|
|
789
|
+
return app.routing.flatMap((group) => group.paths.flatMap(expandWildcards));
|
|
1211
790
|
});
|
|
1212
791
|
}
|
|
1213
|
-
function urlMatches(middlewareConfig,
|
|
792
|
+
function urlMatches(middlewareConfig, path, host) {
|
|
1214
793
|
if (!middlewareConfig.matcher) {
|
|
1215
794
|
return false;
|
|
1216
795
|
}
|
|
1217
796
|
const matchers = Array.isArray(middlewareConfig.matcher) ? middlewareConfig.matcher : [middlewareConfig.matcher];
|
|
1218
797
|
for (let matcher of matchers) {
|
|
1219
798
|
matcher = typeof matcher === "string" ? { source: matcher } : matcher;
|
|
1220
|
-
if (match(matcher.source)(
|
|
799
|
+
if (match(matcher.source)(path)) {
|
|
1221
800
|
if (matchHas(
|
|
1222
801
|
new WebNextRequest(
|
|
1223
802
|
new NextRequestHint({
|
|
1224
803
|
init: { headers: { host } },
|
|
1225
|
-
input: `https://${host}${
|
|
804
|
+
input: `https://${host}${path}`,
|
|
1226
805
|
page: "unused_placeholder"
|
|
1227
806
|
})
|
|
1228
807
|
),
|
|
@@ -1237,54 +816,50 @@ function urlMatches(middlewareConfig, path3, host) {
|
|
|
1237
816
|
return false;
|
|
1238
817
|
}
|
|
1239
818
|
function validateMiddlewareConfig(middlewareConfig, microfrontendConfigOrPath, extraProductionMatches) {
|
|
1240
|
-
var _a, _b;
|
|
1241
819
|
const microfrontendConfig = typeof microfrontendConfigOrPath === "string" ? loadMicrofrontendConfigForEdge(microfrontendConfigOrPath) : microfrontendConfigOrPath;
|
|
1242
820
|
const errors = [];
|
|
1243
821
|
const usedExtraProductionMatches = /* @__PURE__ */ new Set();
|
|
1244
|
-
for (const application of microfrontendConfig.
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
const
|
|
1254
|
-
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
822
|
+
for (const application of microfrontendConfig.getChildApplications()) {
|
|
823
|
+
const matches = [...application.routing];
|
|
824
|
+
matches.push({
|
|
825
|
+
paths: [`/${application.getAssetPrefix()}/_next/:path+`]
|
|
826
|
+
});
|
|
827
|
+
for (const aMatch of matches) {
|
|
828
|
+
const isFlagged = Boolean(aMatch.flag);
|
|
829
|
+
for (const path of aMatch.paths) {
|
|
830
|
+
const pathsToTest = expandWildcards(path);
|
|
831
|
+
for (const testPath of pathsToTest) {
|
|
832
|
+
const productionHost = microfrontendConfig.getDefaultApplication().production.host;
|
|
833
|
+
const pathForDisplay = `${testPath}${path === testPath ? "" : ` (synthesized from ${path})`}`;
|
|
834
|
+
if (!urlMatches(middlewareConfig, testPath, "test.nonproduction.host")) {
|
|
835
|
+
errors.push(
|
|
836
|
+
`Matcher misconfigured for ${pathForDisplay}. This path should have matched the middleware config on a non-production host, but did not. Microfrontends require a middleware config matcher that matches on this host everywhere but in production. That can be configured with a configuration like this:
|
|
837
|
+
${getSampleMatcher(path, productionHost)}`
|
|
838
|
+
);
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
const productionUrlMatches = urlMatches(
|
|
842
|
+
middlewareConfig,
|
|
843
|
+
testPath,
|
|
844
|
+
productionHost
|
|
845
|
+
);
|
|
846
|
+
if (isFlagged) {
|
|
847
|
+
if (!productionUrlMatches) {
|
|
1259
848
|
errors.push(
|
|
1260
|
-
`Matcher misconfigured for ${pathForDisplay}.
|
|
1261
|
-
${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}`
|
|
849
|
+
`Matcher misconfigured for ${pathForDisplay}. Middleware config matchers for flagged paths should ALWAYS match.`
|
|
1262
850
|
);
|
|
1263
851
|
break;
|
|
1264
852
|
}
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
`Matcher misconfigured for ${pathForDisplay}. Middleware config matchers for flagged paths should ALWAYS match.`
|
|
1274
|
-
);
|
|
1275
|
-
break;
|
|
1276
|
-
}
|
|
1277
|
-
} else if (productionUrlMatches) {
|
|
1278
|
-
if (extraProductionMatches == null ? void 0 : extraProductionMatches.includes(path3)) {
|
|
1279
|
-
usedExtraProductionMatches.add(path3);
|
|
1280
|
-
} else {
|
|
1281
|
-
errors.push(
|
|
1282
|
-
`Matcher misconfigured for ${pathForDisplay}. This path matched the middleware config on a production host, but should not have. Microfrontends require a middleware config matcher that matches on this host everywhere but in production. If this is desired, you can add the path the to extraProductionMatches parameter. Otherwise, you can set up a configuration like this:
|
|
1283
|
-
${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}`
|
|
1284
|
-
);
|
|
1285
|
-
}
|
|
1286
|
-
break;
|
|
853
|
+
} else if (productionUrlMatches) {
|
|
854
|
+
if (extraProductionMatches == null ? void 0 : extraProductionMatches.includes(path)) {
|
|
855
|
+
usedExtraProductionMatches.add(path);
|
|
856
|
+
} else {
|
|
857
|
+
errors.push(
|
|
858
|
+
`Matcher misconfigured for ${pathForDisplay}. This path matched the middleware config on a production host, but should not have. Microfrontends require a middleware config matcher that matches on this host everywhere but in production. If this is desired, you can add the path the to extraProductionMatches parameter. Otherwise, you can set up a configuration like this:
|
|
859
|
+
${getSampleMatcher(path, productionHost)}`
|
|
860
|
+
);
|
|
1287
861
|
}
|
|
862
|
+
break;
|
|
1288
863
|
}
|
|
1289
864
|
}
|
|
1290
865
|
}
|
|
@@ -1305,9 +880,9 @@ ${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}
|
|
|
1305
880
|
throw new Error(message + errors.join("\n\n- "));
|
|
1306
881
|
}
|
|
1307
882
|
}
|
|
1308
|
-
function getSampleMatcher(
|
|
883
|
+
function getSampleMatcher(path, host) {
|
|
1309
884
|
return ` {
|
|
1310
|
-
source: '${
|
|
885
|
+
source: '${path}', // This can also be a broader regular expression.
|
|
1311
886
|
missing: [
|
|
1312
887
|
type: 'header',
|
|
1313
888
|
key: 'host',
|
|
@@ -1320,21 +895,25 @@ async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middl
|
|
|
1320
895
|
const initialMfePreviewDomains = process.env.MFE_PREVIEW_DOMAINS;
|
|
1321
896
|
try {
|
|
1322
897
|
const microfrontendConfig = typeof microfrontendConfigOrPath === "string" ? loadMicrofrontendConfigForEdge(microfrontendConfigOrPath) : microfrontendConfigOrPath;
|
|
1323
|
-
const
|
|
1324
|
-
process.env.MFE_PREVIEW_DOMAINS = JSON.stringify(fakePreviewDomains);
|
|
1325
|
-
const allZoneNames = getAllZoneNames(microfrontendConfig);
|
|
898
|
+
const allAppNames = getAllChildApplicationNames(microfrontendConfig);
|
|
1326
899
|
const errors = [];
|
|
1327
|
-
for (const
|
|
1328
|
-
const flaggedPaths =
|
|
1329
|
-
microfrontendConfig,
|
|
1330
|
-
zoneName
|
|
1331
|
-
);
|
|
900
|
+
for (const appName of allAppNames) {
|
|
901
|
+
const flaggedPaths = getFlaggedPathsForApp(microfrontendConfig, appName);
|
|
1332
902
|
if (flaggedPaths.length) {
|
|
1333
903
|
for (const env of ["preview", "production"]) {
|
|
1334
904
|
process.env.VERCEL_ENV = env;
|
|
1335
|
-
for (const
|
|
1336
|
-
const expectedHost =
|
|
1337
|
-
|
|
905
|
+
for (const path of flaggedPaths) {
|
|
906
|
+
const expectedHost = getExpectedDomainForApp(
|
|
907
|
+
microfrontendConfig,
|
|
908
|
+
appName,
|
|
909
|
+
env
|
|
910
|
+
);
|
|
911
|
+
const expectedDefaultHost = getExpectedDomainForApp(
|
|
912
|
+
microfrontendConfig,
|
|
913
|
+
microfrontendConfig.getDefaultApplication().name,
|
|
914
|
+
env
|
|
915
|
+
);
|
|
916
|
+
const requestPath = `${expectedDefaultHost}${path}`;
|
|
1338
917
|
const request = new NextRequest(requestPath, {
|
|
1339
918
|
headers: { "x-vercel-skip-deployment-existence-check": "1" }
|
|
1340
919
|
});
|
|
@@ -1342,7 +921,7 @@ async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middl
|
|
|
1342
921
|
request,
|
|
1343
922
|
{}
|
|
1344
923
|
);
|
|
1345
|
-
const expectedUrl = `${expectedHost}${
|
|
924
|
+
const expectedUrl = `${expectedHost}${path}`;
|
|
1346
925
|
if (!response) {
|
|
1347
926
|
errors.push(
|
|
1348
927
|
`middleware did not action for ${requestPath} in ${env}. Expected a rewrite to ${expectedUrl}`
|
|
@@ -1368,19 +947,13 @@ async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middl
|
|
|
1368
947
|
process.env.MFE_PREVIEW_DOMAINS = initialMfePreviewDomains;
|
|
1369
948
|
}
|
|
1370
949
|
}
|
|
1371
|
-
function createFakePreviewDomains(config) {
|
|
1372
|
-
return config.getAllApplications().reduce((result, application) => {
|
|
1373
|
-
result[application.name] = `https://preview-for-middleware-test-only.${application.production.host}`;
|
|
1374
|
-
return result;
|
|
1375
|
-
}, {});
|
|
1376
|
-
}
|
|
1377
950
|
export {
|
|
1378
951
|
expandWildcards,
|
|
952
|
+
getAllChildApplicationNames,
|
|
1379
953
|
getAllMultiZonesPaths,
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
getLaunchedPathsForZone,
|
|
954
|
+
getExpectedDomainForApp,
|
|
955
|
+
getFlaggedPathsForApp,
|
|
956
|
+
getLaunchedPathsForApp,
|
|
1384
957
|
loadMicrofrontendConfigForEdge,
|
|
1385
958
|
validateMiddlewareConfig,
|
|
1386
959
|
validateMiddlewareOnFlaggedPaths
|