@vercel/microfrontends 0.14.0 → 0.16.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 +392 -1620
- package/dist/config.cjs +478 -1001
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -25
- package/dist/config.js +474 -980
- package/dist/config.js.map +1 -1
- package/dist/{v2/microfrontends → microfrontends}/server.cjs +91 -150
- 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 +91 -150
- package/dist/microfrontends/server.js.map +1 -0
- package/dist/{v2/microfrontends.cjs → microfrontends.cjs} +49 -28
- 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} +48 -27
- 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 +1344 -1024
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +1 -1
- package/dist/next/config.js +1343 -1023
- 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 +765 -395
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +10 -5
- package/dist/next/middleware.js +765 -395
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +615 -1031
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +14 -12
- package/dist/next/testing.js +609 -1015
- 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 +237 -1338
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +230 -1331
- 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,320 @@ 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 maybeError = validatePathExpression(path);
|
|
255
|
+
if (maybeError) {
|
|
256
|
+
errors.push(maybeError);
|
|
257
|
+
}
|
|
258
|
+
const existing = pathsByApplicationId.get(path);
|
|
259
|
+
if (existing) {
|
|
260
|
+
existing.applications.push(id);
|
|
261
|
+
} else {
|
|
262
|
+
pathsByApplicationId.set(path, {
|
|
263
|
+
applications: [id],
|
|
264
|
+
matcher: pathToRegexp2(path),
|
|
265
|
+
applicationId: id
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
200
270
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
271
|
+
const entries = Array.from(pathsByApplicationId.entries());
|
|
272
|
+
entries.forEach(([path, { applications: ids, matcher, applicationId }]) => {
|
|
273
|
+
if (ids.length > 1) {
|
|
274
|
+
errors.push(
|
|
275
|
+
`Duplicate path "${path}" for applications "${ids.join(", ")}"`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
entries.forEach(
|
|
279
|
+
([
|
|
280
|
+
matchPath,
|
|
281
|
+
{ applications: matchIds, applicationId: matchApplicationId }
|
|
282
|
+
]) => {
|
|
283
|
+
if (path === matchPath) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (applicationId === matchApplicationId) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (matcher.test(matchPath)) {
|
|
290
|
+
const source = `"${path}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
291
|
+
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
292
|
+
errors.push(
|
|
293
|
+
`Overlapping path detected between ${source} and ${destination}`
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
);
|
|
298
|
+
});
|
|
299
|
+
if (errors.length) {
|
|
300
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
301
|
+
type: "config",
|
|
302
|
+
subtype: "conflicting_paths"
|
|
210
303
|
});
|
|
211
|
-
return overridesConfig;
|
|
212
304
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
305
|
+
};
|
|
306
|
+
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
307
|
+
function validatePathExpression(path) {
|
|
308
|
+
const tokens = parsePathRegexp(path);
|
|
309
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
310
|
+
const token = tokens[i];
|
|
311
|
+
if (token === void 0) {
|
|
312
|
+
return `token ${i} in ${path} is undefined, this shouldn't happen`;
|
|
313
|
+
}
|
|
314
|
+
if (typeof token !== "string") {
|
|
315
|
+
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
316
|
+
return `Path ${path} cannot use a regular expression wildcard`;
|
|
317
|
+
}
|
|
318
|
+
if (token.prefix !== "/") {
|
|
319
|
+
return `Wildcard :${token.name} must be immediately after a / in ${path}`;
|
|
320
|
+
}
|
|
321
|
+
if (token.suffix) {
|
|
322
|
+
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
323
|
+
}
|
|
324
|
+
if (token.modifier && i !== tokens.length - 1) {
|
|
325
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path}. Modifiers are only allowed in the last path component`;
|
|
326
|
+
}
|
|
218
327
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
328
|
+
}
|
|
329
|
+
return void 0;
|
|
330
|
+
}
|
|
331
|
+
var validateAppPaths = (name, app) => {
|
|
332
|
+
for (const group of app.routing) {
|
|
333
|
+
for (const p of group.paths) {
|
|
334
|
+
if (p === "/") {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (p.endsWith("/")) {
|
|
338
|
+
throw new MicrofrontendError(
|
|
339
|
+
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
340
|
+
{ type: "application", subtype: "invalid_path" }
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
if (!p.startsWith("/")) {
|
|
344
|
+
throw new MicrofrontendError(
|
|
345
|
+
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
346
|
+
{ type: "application", subtype: "invalid_path" }
|
|
347
|
+
);
|
|
348
|
+
}
|
|
224
349
|
}
|
|
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
350
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
)}$`
|
|
236
|
-
).test(domain);
|
|
351
|
+
};
|
|
352
|
+
var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
353
|
+
if (!applicationConfigsById) {
|
|
354
|
+
return;
|
|
237
355
|
}
|
|
238
|
-
|
|
239
|
-
|
|
356
|
+
const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
|
|
357
|
+
([, app]) => !isDefaultApp(app)
|
|
358
|
+
);
|
|
359
|
+
const applicationsWithRoutingNames = applicationsWithRouting.map(
|
|
360
|
+
([key]) => key
|
|
361
|
+
);
|
|
362
|
+
const numApplications = Object.keys(applicationConfigsById).length;
|
|
363
|
+
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
364
|
+
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
365
|
+
if (numApplicationsWithoutRouting === 0) {
|
|
366
|
+
throw new MicrofrontendError(
|
|
367
|
+
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
368
|
+
{ type: "config", subtype: "no_default_application" }
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
if (numApplicationsWithoutRouting > 1) {
|
|
372
|
+
throw new MicrofrontendError(
|
|
373
|
+
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
374
|
+
{ type: "config", subtype: "multiple_default_applications" }
|
|
375
|
+
);
|
|
240
376
|
}
|
|
241
377
|
};
|
|
242
|
-
var Overrides = _Overrides;
|
|
243
|
-
Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
244
378
|
|
|
245
|
-
// src/config/
|
|
379
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
380
|
+
var PREFIX = "vc-ap";
|
|
381
|
+
function generateAssetPrefixFromName({
|
|
382
|
+
name
|
|
383
|
+
}) {
|
|
384
|
+
if (!name) {
|
|
385
|
+
throw new Error("Name is required to generate an asset prefix");
|
|
386
|
+
}
|
|
387
|
+
return `${PREFIX}-${name}`;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-port.ts
|
|
391
|
+
function generatePortFromName({
|
|
392
|
+
name,
|
|
393
|
+
minPort = 3e3,
|
|
394
|
+
maxPort = 8e3
|
|
395
|
+
}) {
|
|
396
|
+
if (!name) {
|
|
397
|
+
throw new Error("Name is required to generate a port");
|
|
398
|
+
}
|
|
399
|
+
let hash = 0;
|
|
400
|
+
for (let i = 0; i < name.length; i++) {
|
|
401
|
+
hash = (hash << 5) - hash + name.charCodeAt(i);
|
|
402
|
+
hash |= 0;
|
|
403
|
+
}
|
|
404
|
+
hash = Math.abs(hash);
|
|
405
|
+
const range = maxPort - minPort;
|
|
406
|
+
const port = minPort + hash % range;
|
|
407
|
+
return port;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/config/microfrontends-config/isomorphic/host.ts
|
|
246
411
|
var Host = class {
|
|
247
|
-
constructor(
|
|
248
|
-
|
|
412
|
+
constructor(hostConfig, options) {
|
|
413
|
+
const { protocol = "https", host, port } = hostConfig;
|
|
414
|
+
this.protocol = protocol;
|
|
249
415
|
this.host = host;
|
|
250
416
|
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
251
|
-
this.
|
|
252
|
-
protocol,
|
|
253
|
-
host,
|
|
254
|
-
...port ? { port } : void 0
|
|
255
|
-
};
|
|
417
|
+
this.local = options == null ? void 0 : options.isLocal;
|
|
256
418
|
}
|
|
257
419
|
isLocal() {
|
|
258
|
-
return this.host === "localhost" || this.host === "127.0.0.1";
|
|
420
|
+
return this.local || this.host === "localhost" || this.host === "127.0.0.1";
|
|
259
421
|
}
|
|
260
422
|
static getPort({
|
|
261
423
|
protocol,
|
|
@@ -281,176 +443,234 @@ var Host = class {
|
|
|
281
443
|
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
282
444
|
return new URL(url);
|
|
283
445
|
}
|
|
284
|
-
|
|
285
|
-
|
|
446
|
+
};
|
|
447
|
+
var LocalHost = class extends Host {
|
|
448
|
+
constructor({
|
|
449
|
+
appName,
|
|
450
|
+
...hostConfig
|
|
451
|
+
}) {
|
|
452
|
+
const host = hostConfig.host ?? "localhost";
|
|
453
|
+
const port = hostConfig.port ?? generatePortFromName({ name: appName });
|
|
454
|
+
const protocol = hostConfig.protocol ?? "http";
|
|
455
|
+
super({ protocol, host, port });
|
|
286
456
|
}
|
|
287
457
|
};
|
|
288
458
|
|
|
289
|
-
// src/config/
|
|
459
|
+
// src/config/microfrontends-config/isomorphic/application.ts
|
|
290
460
|
var Application = class {
|
|
291
461
|
constructor(name, {
|
|
292
462
|
app,
|
|
293
|
-
overrides
|
|
463
|
+
overrides,
|
|
464
|
+
isDefault
|
|
294
465
|
}) {
|
|
295
|
-
|
|
466
|
+
var _a, _b;
|
|
296
467
|
this.name = name;
|
|
297
|
-
this.default = app.default;
|
|
298
|
-
this.routing = app.routing;
|
|
299
468
|
this.development = {
|
|
300
|
-
local: new
|
|
301
|
-
|
|
469
|
+
local: new LocalHost({
|
|
470
|
+
appName: name,
|
|
471
|
+
...(_a = app.development) == null ? void 0 : _a.local
|
|
472
|
+
}),
|
|
473
|
+
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
|
|
302
474
|
};
|
|
303
|
-
this.production = new Host(app.production);
|
|
475
|
+
this.production = app.production ? new Host(app.production) : void 0;
|
|
304
476
|
this.vercel = app.vercel;
|
|
305
477
|
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
306
478
|
environment: new Host(overrides.environment)
|
|
307
479
|
} : void 0;
|
|
480
|
+
this.default = isDefault ?? false;
|
|
481
|
+
this.serialized = app;
|
|
308
482
|
}
|
|
309
483
|
isDefault() {
|
|
310
484
|
return this.default;
|
|
311
485
|
}
|
|
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
|
-
}
|
|
486
|
+
getAssetPrefix() {
|
|
487
|
+
return generateAssetPrefixFromName({ name: this.name });
|
|
339
488
|
}
|
|
340
489
|
serialize() {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
490
|
+
return this.serialized;
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
var DefaultApplication = class extends Application {
|
|
494
|
+
constructor(name, {
|
|
495
|
+
app,
|
|
496
|
+
overrides
|
|
497
|
+
}) {
|
|
498
|
+
super(name, {
|
|
499
|
+
app,
|
|
500
|
+
overrides,
|
|
501
|
+
isDefault: true
|
|
502
|
+
});
|
|
503
|
+
this.default = true;
|
|
504
|
+
this.production = new Host(app.production);
|
|
505
|
+
}
|
|
506
|
+
getAssetPrefix() {
|
|
507
|
+
return "";
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
var ChildApplication = class extends Application {
|
|
511
|
+
constructor(name, {
|
|
512
|
+
app,
|
|
513
|
+
overrides
|
|
514
|
+
}) {
|
|
515
|
+
ChildApplication.validate(name, app);
|
|
516
|
+
super(name, {
|
|
517
|
+
app,
|
|
518
|
+
overrides,
|
|
519
|
+
isDefault: false
|
|
520
|
+
});
|
|
521
|
+
this.default = false;
|
|
522
|
+
this.routing = app.routing;
|
|
523
|
+
}
|
|
524
|
+
static validate(name, app) {
|
|
525
|
+
validateAppPaths(name, app);
|
|
363
526
|
}
|
|
364
527
|
};
|
|
365
528
|
|
|
366
|
-
// src/config/
|
|
367
|
-
var SUPPORTED_VERSIONS = ["1"];
|
|
529
|
+
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
368
530
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
369
|
-
|
|
531
|
+
|
|
532
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
533
|
+
var MicrofrontendConfigIsomorphic = class {
|
|
370
534
|
constructor({
|
|
371
535
|
config,
|
|
372
|
-
overrides
|
|
536
|
+
overrides,
|
|
537
|
+
meta
|
|
373
538
|
}) {
|
|
374
|
-
this.
|
|
375
|
-
var _a, _b, _c;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
539
|
+
this.childApplications = {};
|
|
540
|
+
var _a, _b, _c, _d;
|
|
541
|
+
MicrofrontendConfigIsomorphic.validate(config);
|
|
542
|
+
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
543
|
+
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
544
|
+
this.isMainConfig = isMainConfig(config);
|
|
545
|
+
if (isMainConfig(config)) {
|
|
546
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
547
|
+
const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
|
|
548
|
+
if (isDefaultApp(appConfig)) {
|
|
549
|
+
this.defaultApplication = new DefaultApplication(appId, {
|
|
550
|
+
app: appConfig,
|
|
551
|
+
overrides: appOverrides
|
|
552
|
+
});
|
|
553
|
+
} else {
|
|
554
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
555
|
+
app: appConfig,
|
|
556
|
+
overrides: appOverrides
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
} else {
|
|
561
|
+
this.partOf = config.partOf;
|
|
562
|
+
const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
|
|
563
|
+
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
564
|
+
meta.fromApp,
|
|
565
|
+
{
|
|
566
|
+
// we don't know routing because we're not in the main config
|
|
567
|
+
app: { routing: [] },
|
|
568
|
+
overrides: appOverrides
|
|
569
|
+
}
|
|
382
570
|
);
|
|
383
571
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
572
|
+
if (isMainConfig(config) && !this.defaultApplication) {
|
|
573
|
+
throw new MicrofrontendError(
|
|
574
|
+
`Could not find default application in microfrontends configuration`,
|
|
575
|
+
{
|
|
576
|
+
type: "application",
|
|
577
|
+
subtype: "not_found"
|
|
578
|
+
}
|
|
579
|
+
);
|
|
391
580
|
}
|
|
392
581
|
this.config = config;
|
|
393
|
-
this.name = config.name;
|
|
394
|
-
this.version = config.version;
|
|
395
582
|
this.options = config.options;
|
|
396
|
-
this
|
|
583
|
+
this.serialized = {
|
|
584
|
+
config,
|
|
585
|
+
overrides,
|
|
586
|
+
meta
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
static validate(config) {
|
|
590
|
+
const c = typeof config === "string" ? parse(config) : config;
|
|
591
|
+
if (isMainConfig(c)) {
|
|
592
|
+
validateConfigVersion(c.version);
|
|
593
|
+
validateConfigPaths(c.applications);
|
|
594
|
+
validateConfigDefaultApplication(c.applications);
|
|
595
|
+
}
|
|
596
|
+
return c;
|
|
597
|
+
}
|
|
598
|
+
static fromEnv({
|
|
599
|
+
meta,
|
|
600
|
+
cookies
|
|
601
|
+
}) {
|
|
602
|
+
return new MicrofrontendConfigIsomorphic({
|
|
603
|
+
config: parse(getConfigStringFromEnv()),
|
|
604
|
+
overrides: parseOverrides(cookies ?? []),
|
|
605
|
+
meta
|
|
606
|
+
});
|
|
397
607
|
}
|
|
398
608
|
isOverridesDisabled() {
|
|
399
609
|
var _a, _b;
|
|
400
610
|
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
401
611
|
}
|
|
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
612
|
getConfig() {
|
|
416
613
|
return this.config;
|
|
417
614
|
}
|
|
615
|
+
getApplicationsByType() {
|
|
616
|
+
return {
|
|
617
|
+
defaultApplication: this.defaultApplication,
|
|
618
|
+
applications: Object.values(this.childApplications)
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
getChildApplications() {
|
|
622
|
+
return Object.values(this.childApplications);
|
|
623
|
+
}
|
|
418
624
|
getAllApplications() {
|
|
419
|
-
return
|
|
625
|
+
return [
|
|
626
|
+
this.defaultApplication,
|
|
627
|
+
...Object.values(this.childApplications)
|
|
628
|
+
].filter(Boolean);
|
|
420
629
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (
|
|
630
|
+
getApplication(name) {
|
|
631
|
+
var _a;
|
|
632
|
+
if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
|
|
633
|
+
return this.defaultApplication;
|
|
634
|
+
}
|
|
635
|
+
const app = this.childApplications[name];
|
|
636
|
+
if (!app) {
|
|
424
637
|
throw new MicrofrontendError(
|
|
425
638
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
426
639
|
{
|
|
427
|
-
type: "
|
|
640
|
+
type: "application",
|
|
428
641
|
subtype: "not_found"
|
|
429
642
|
}
|
|
430
643
|
);
|
|
431
644
|
}
|
|
432
|
-
return
|
|
645
|
+
return app;
|
|
433
646
|
}
|
|
434
647
|
getApplicationByProjectId(projectId) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
648
|
+
var _a, _b;
|
|
649
|
+
if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
|
|
650
|
+
return this.defaultApplication;
|
|
651
|
+
}
|
|
652
|
+
return Object.values(this.childApplications).find(
|
|
653
|
+
(app) => {
|
|
654
|
+
var _a2;
|
|
655
|
+
return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
|
|
439
656
|
}
|
|
440
657
|
);
|
|
441
658
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
659
|
+
/**
|
|
660
|
+
* Returns the default application. This can throw if the default application
|
|
661
|
+
* is undefined ( )
|
|
662
|
+
*/
|
|
663
|
+
getDefaultApplication() {
|
|
664
|
+
if (!this.defaultApplication) {
|
|
445
665
|
throw new MicrofrontendError(
|
|
446
|
-
`Could not find default
|
|
666
|
+
`Could not find default application in microfrontends configuration`,
|
|
447
667
|
{
|
|
448
|
-
type: "
|
|
668
|
+
type: "application",
|
|
449
669
|
subtype: "not_found"
|
|
450
670
|
}
|
|
451
671
|
);
|
|
452
672
|
}
|
|
453
|
-
return
|
|
673
|
+
return this.defaultApplication;
|
|
454
674
|
}
|
|
455
675
|
/**
|
|
456
676
|
* Returns the configured port for the local proxy
|
|
@@ -465,764 +685,144 @@ var MicrofrontendConfigCommon = class {
|
|
|
465
685
|
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
466
686
|
*/
|
|
467
687
|
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
|
-
);
|
|
688
|
+
return this.serialized.config;
|
|
502
689
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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
|
-
);
|
|
520
|
-
}
|
|
521
|
-
return path2.join(MFE_CONFIG_DEFAULT_FILE_PATH2, MFE_CONFIG_DEFAULT_FILE_NAME2);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
// src/config/validation.ts
|
|
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
|
-
},
|
|
690
|
+
toClientConfig() {
|
|
691
|
+
const applications = Object.fromEntries(
|
|
692
|
+
Object.entries(this.childApplications).map(([name, application]) => [
|
|
693
|
+
name,
|
|
569
694
|
{
|
|
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
|
-
}
|
|
686
|
-
}
|
|
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"
|
|
695
|
+
default: false,
|
|
696
|
+
routing: application.routing
|
|
705
697
|
}
|
|
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" }
|
|
698
|
+
])
|
|
859
699
|
);
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
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" }
|
|
871
|
-
);
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
function validateMainPath(applicationConfigsById) {
|
|
875
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
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
|
-
);
|
|
700
|
+
if (this.defaultApplication) {
|
|
701
|
+
applications[this.defaultApplication.name] = {
|
|
702
|
+
default: true
|
|
703
|
+
};
|
|
952
704
|
}
|
|
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"
|
|
705
|
+
return new MicrofrontendConfigClient({
|
|
706
|
+
applications
|
|
978
707
|
});
|
|
979
708
|
}
|
|
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
|
-
}
|
|
709
|
+
serialize() {
|
|
710
|
+
return this.serialized;
|
|
1032
711
|
}
|
|
1033
712
|
};
|
|
1034
713
|
|
|
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)
|
|
714
|
+
// src/routing/get-domain-from-environment.ts
|
|
715
|
+
function getDomainFromEnvironment({
|
|
716
|
+
app,
|
|
717
|
+
target
|
|
718
|
+
}) {
|
|
719
|
+
var _a;
|
|
720
|
+
const mfeProjects = JSON.parse(
|
|
721
|
+
process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "[]"
|
|
1099
722
|
);
|
|
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;
|
|
723
|
+
if (mfeProjects.length === 0) {
|
|
724
|
+
throw new Error("Missing related microfrontends project information");
|
|
1112
725
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
}) {
|
|
1116
|
-
return new MicrofrontendConfigCommon({
|
|
1117
|
-
config: MicrofrontendConfig.validate(
|
|
1118
|
-
MicrofrontendConfigCommon.getConfigFromEnv()
|
|
1119
|
-
),
|
|
1120
|
-
overrides: Overrides.parseOverrides(cookies)
|
|
1121
|
-
});
|
|
726
|
+
if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
|
|
727
|
+
throw new Error(`Missing applications[${app.name}].vercel.projectId`);
|
|
1122
728
|
}
|
|
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
|
-
});
|
|
729
|
+
const vercelProject = mfeProjects.find(
|
|
730
|
+
(p) => {
|
|
731
|
+
var _a2;
|
|
732
|
+
return p.project.id === ((_a2 = app.vercel) == null ? void 0 : _a2.projectId);
|
|
1135
733
|
}
|
|
734
|
+
);
|
|
735
|
+
if (!vercelProject) {
|
|
736
|
+
throw new Error(
|
|
737
|
+
`Missing related microfrontends project information for application "${app.name}"`
|
|
738
|
+
);
|
|
1136
739
|
}
|
|
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
|
-
}
|
|
740
|
+
const domain = target === "preview" && vercelProject.preview.branch ? vercelProject.preview.branch : vercelProject.production.alias ?? vercelProject.production.url;
|
|
741
|
+
if (!domain) {
|
|
742
|
+
throw new Error(
|
|
743
|
+
`Missing domain for target "${target}" in application "${app.name}"`
|
|
744
|
+
);
|
|
1152
745
|
}
|
|
1153
|
-
}
|
|
746
|
+
return domain.startsWith("https://") ? domain : `https://${domain}`;
|
|
747
|
+
}
|
|
1154
748
|
|
|
1155
749
|
// src/next/testing/index.ts
|
|
1156
|
-
function expandWildcards(
|
|
1157
|
-
if (
|
|
750
|
+
function expandWildcards(path) {
|
|
751
|
+
if (path.includes("/:path*") || path.includes("/:slug*")) {
|
|
1158
752
|
return [
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
753
|
+
path === "/:path*" || path === "/:slug*" ? "/" : path.replace("/:path*", "").replace("/:slug*", ""),
|
|
754
|
+
path.replace("/:path*", "/foo").replace("/:slug*", "/foo"),
|
|
755
|
+
path.replace("/:path*", "/foo/bar").replace("/:slug*", "/foo/bar")
|
|
1162
756
|
];
|
|
1163
757
|
}
|
|
1164
|
-
if (
|
|
758
|
+
if (path.includes("/:path+") || path.includes("/:slug+")) {
|
|
1165
759
|
return [
|
|
1166
|
-
|
|
1167
|
-
|
|
760
|
+
path.replace("/:path+", "/foo").replace("/:slug+", "/foo"),
|
|
761
|
+
path.replace("/:path+", "/foo/bar").replace("/:slug+", "/foo/bar")
|
|
1168
762
|
];
|
|
1169
763
|
}
|
|
1170
|
-
if (
|
|
1171
|
-
return [
|
|
764
|
+
if (path.includes("/:path") || path.includes("/:slug")) {
|
|
765
|
+
return [path.replace("/:path", "/foo").replace("/:slug", "/foo")];
|
|
1172
766
|
}
|
|
1173
|
-
return [
|
|
767
|
+
return [path];
|
|
1174
768
|
}
|
|
1175
|
-
function loadMicrofrontendConfigForEdge(
|
|
1176
|
-
const rawMfConfig = parse2(readFileSync(
|
|
1177
|
-
return new
|
|
769
|
+
function loadMicrofrontendConfigForEdge(path) {
|
|
770
|
+
const rawMfConfig = parse2(readFileSync(path, "utf-8"));
|
|
771
|
+
return new MicrofrontendConfigIsomorphic({
|
|
772
|
+
config: rawMfConfig,
|
|
773
|
+
meta: { fromApp: "test" }
|
|
774
|
+
});
|
|
1178
775
|
}
|
|
1179
|
-
function
|
|
1180
|
-
return mfConfig.
|
|
776
|
+
function getAllChildApplicationNames(mfConfig) {
|
|
777
|
+
return mfConfig.getChildApplications().map((app) => app.name);
|
|
1181
778
|
}
|
|
1182
|
-
function
|
|
1183
|
-
|
|
1184
|
-
|
|
779
|
+
function getLaunchedPathsForApp(mfConfig, appName) {
|
|
780
|
+
const app = mfConfig.getApplication(appName);
|
|
781
|
+
if (app instanceof DefaultApplication) {
|
|
782
|
+
return [];
|
|
783
|
+
}
|
|
1185
784
|
return [
|
|
1186
|
-
|
|
1187
|
-
...((
|
|
1188
|
-
var _a2;
|
|
1189
|
-
return !((_a2 = group.options) == null ? void 0 : _a2.flag);
|
|
1190
|
-
}).flatMap((group) => group.paths.flatMap(expandWildcards))) ?? []
|
|
785
|
+
`/${app.getAssetPrefix()}/_next/static`,
|
|
786
|
+
...app.routing.filter((group) => !group.flag).flatMap((group) => group.paths.flatMap(expandWildcards))
|
|
1191
787
|
];
|
|
1192
788
|
}
|
|
1193
|
-
function
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
}).flatMap((group) => group.paths.flatMap(expandWildcards))) ?? [];
|
|
789
|
+
function getFlaggedPathsForApp(mfConfig, appName) {
|
|
790
|
+
const app = mfConfig.getApplication(appName);
|
|
791
|
+
if (app instanceof DefaultApplication) {
|
|
792
|
+
return [];
|
|
793
|
+
}
|
|
794
|
+
return app.routing.filter((group) => Boolean(group.flag)).flatMap((group) => group.paths.flatMap(expandWildcards));
|
|
1200
795
|
}
|
|
1201
|
-
function
|
|
1202
|
-
const
|
|
1203
|
-
|
|
796
|
+
function getExpectedDomainForApp(mfConfig, appName, env) {
|
|
797
|
+
const app = mfConfig.getApplication(appName);
|
|
798
|
+
const defaultApp = mfConfig.getDefaultApplication();
|
|
799
|
+
if (env === "development") {
|
|
800
|
+
return app.development.local.toString();
|
|
801
|
+
}
|
|
802
|
+
if (["preview", "production"].includes(env)) {
|
|
803
|
+
const target = env;
|
|
804
|
+
return getDomainFromEnvironment({ app, target });
|
|
805
|
+
}
|
|
806
|
+
return defaultApp.production.toString();
|
|
1204
807
|
}
|
|
1205
808
|
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
|
-
)) ?? [];
|
|
809
|
+
return mfConfig.getChildApplications().flatMap((app) => {
|
|
810
|
+
return app.routing.flatMap((group) => group.paths.flatMap(expandWildcards));
|
|
1211
811
|
});
|
|
1212
812
|
}
|
|
1213
|
-
function urlMatches(middlewareConfig,
|
|
813
|
+
function urlMatches(middlewareConfig, path, host) {
|
|
1214
814
|
if (!middlewareConfig.matcher) {
|
|
1215
815
|
return false;
|
|
1216
816
|
}
|
|
1217
817
|
const matchers = Array.isArray(middlewareConfig.matcher) ? middlewareConfig.matcher : [middlewareConfig.matcher];
|
|
1218
818
|
for (let matcher of matchers) {
|
|
1219
819
|
matcher = typeof matcher === "string" ? { source: matcher } : matcher;
|
|
1220
|
-
if (match(matcher.source)(
|
|
820
|
+
if (match(matcher.source)(path)) {
|
|
1221
821
|
if (matchHas(
|
|
1222
822
|
new WebNextRequest(
|
|
1223
823
|
new NextRequestHint({
|
|
1224
824
|
init: { headers: { host } },
|
|
1225
|
-
input: `https://${host}${
|
|
825
|
+
input: `https://${host}${path}`,
|
|
1226
826
|
page: "unused_placeholder"
|
|
1227
827
|
})
|
|
1228
828
|
),
|
|
@@ -1237,54 +837,50 @@ function urlMatches(middlewareConfig, path3, host) {
|
|
|
1237
837
|
return false;
|
|
1238
838
|
}
|
|
1239
839
|
function validateMiddlewareConfig(middlewareConfig, microfrontendConfigOrPath, extraProductionMatches) {
|
|
1240
|
-
var _a, _b;
|
|
1241
840
|
const microfrontendConfig = typeof microfrontendConfigOrPath === "string" ? loadMicrofrontendConfigForEdge(microfrontendConfigOrPath) : microfrontendConfigOrPath;
|
|
1242
841
|
const errors = [];
|
|
1243
842
|
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
|
-
|
|
843
|
+
for (const application of microfrontendConfig.getChildApplications()) {
|
|
844
|
+
const matches = [...application.routing];
|
|
845
|
+
matches.push({
|
|
846
|
+
paths: [`/${application.getAssetPrefix()}/_next/:path+`]
|
|
847
|
+
});
|
|
848
|
+
for (const aMatch of matches) {
|
|
849
|
+
const isFlagged = Boolean(aMatch.flag);
|
|
850
|
+
for (const path of aMatch.paths) {
|
|
851
|
+
const pathsToTest = expandWildcards(path);
|
|
852
|
+
for (const testPath of pathsToTest) {
|
|
853
|
+
const productionHost = microfrontendConfig.getDefaultApplication().production.host;
|
|
854
|
+
const pathForDisplay = `${testPath}${path === testPath ? "" : ` (synthesized from ${path})`}`;
|
|
855
|
+
if (!urlMatches(middlewareConfig, testPath, "test.nonproduction.host")) {
|
|
856
|
+
errors.push(
|
|
857
|
+
`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:
|
|
858
|
+
${getSampleMatcher(path, productionHost)}`
|
|
859
|
+
);
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
const productionUrlMatches = urlMatches(
|
|
863
|
+
middlewareConfig,
|
|
864
|
+
testPath,
|
|
865
|
+
productionHost
|
|
866
|
+
);
|
|
867
|
+
if (isFlagged) {
|
|
868
|
+
if (!productionUrlMatches) {
|
|
1259
869
|
errors.push(
|
|
1260
|
-
`Matcher misconfigured for ${pathForDisplay}.
|
|
1261
|
-
${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}`
|
|
870
|
+
`Matcher misconfigured for ${pathForDisplay}. Middleware config matchers for flagged paths should ALWAYS match.`
|
|
1262
871
|
);
|
|
1263
872
|
break;
|
|
1264
873
|
}
|
|
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;
|
|
874
|
+
} else if (productionUrlMatches) {
|
|
875
|
+
if (extraProductionMatches == null ? void 0 : extraProductionMatches.includes(path)) {
|
|
876
|
+
usedExtraProductionMatches.add(path);
|
|
877
|
+
} else {
|
|
878
|
+
errors.push(
|
|
879
|
+
`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:
|
|
880
|
+
${getSampleMatcher(path, productionHost)}`
|
|
881
|
+
);
|
|
1287
882
|
}
|
|
883
|
+
break;
|
|
1288
884
|
}
|
|
1289
885
|
}
|
|
1290
886
|
}
|
|
@@ -1305,9 +901,9 @@ ${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}
|
|
|
1305
901
|
throw new Error(message + errors.join("\n\n- "));
|
|
1306
902
|
}
|
|
1307
903
|
}
|
|
1308
|
-
function getSampleMatcher(
|
|
904
|
+
function getSampleMatcher(path, host) {
|
|
1309
905
|
return ` {
|
|
1310
|
-
source: '${
|
|
906
|
+
source: '${path}', // This can also be a broader regular expression.
|
|
1311
907
|
missing: [
|
|
1312
908
|
type: 'header',
|
|
1313
909
|
key: 'host',
|
|
@@ -1320,21 +916,25 @@ async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middl
|
|
|
1320
916
|
const initialMfePreviewDomains = process.env.MFE_PREVIEW_DOMAINS;
|
|
1321
917
|
try {
|
|
1322
918
|
const microfrontendConfig = typeof microfrontendConfigOrPath === "string" ? loadMicrofrontendConfigForEdge(microfrontendConfigOrPath) : microfrontendConfigOrPath;
|
|
1323
|
-
const
|
|
1324
|
-
process.env.MFE_PREVIEW_DOMAINS = JSON.stringify(fakePreviewDomains);
|
|
1325
|
-
const allZoneNames = getAllZoneNames(microfrontendConfig);
|
|
919
|
+
const allAppNames = getAllChildApplicationNames(microfrontendConfig);
|
|
1326
920
|
const errors = [];
|
|
1327
|
-
for (const
|
|
1328
|
-
const flaggedPaths =
|
|
1329
|
-
microfrontendConfig,
|
|
1330
|
-
zoneName
|
|
1331
|
-
);
|
|
921
|
+
for (const appName of allAppNames) {
|
|
922
|
+
const flaggedPaths = getFlaggedPathsForApp(microfrontendConfig, appName);
|
|
1332
923
|
if (flaggedPaths.length) {
|
|
1333
924
|
for (const env of ["preview", "production"]) {
|
|
1334
925
|
process.env.VERCEL_ENV = env;
|
|
1335
|
-
for (const
|
|
1336
|
-
const expectedHost =
|
|
1337
|
-
|
|
926
|
+
for (const path of flaggedPaths) {
|
|
927
|
+
const expectedHost = getExpectedDomainForApp(
|
|
928
|
+
microfrontendConfig,
|
|
929
|
+
appName,
|
|
930
|
+
env
|
|
931
|
+
);
|
|
932
|
+
const expectedDefaultHost = getExpectedDomainForApp(
|
|
933
|
+
microfrontendConfig,
|
|
934
|
+
microfrontendConfig.getDefaultApplication().name,
|
|
935
|
+
env
|
|
936
|
+
);
|
|
937
|
+
const requestPath = `${expectedDefaultHost}${path}`;
|
|
1338
938
|
const request = new NextRequest(requestPath, {
|
|
1339
939
|
headers: { "x-vercel-skip-deployment-existence-check": "1" }
|
|
1340
940
|
});
|
|
@@ -1342,7 +942,7 @@ async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middl
|
|
|
1342
942
|
request,
|
|
1343
943
|
{}
|
|
1344
944
|
);
|
|
1345
|
-
const expectedUrl = `${expectedHost}${
|
|
945
|
+
const expectedUrl = `${expectedHost}${path}`;
|
|
1346
946
|
if (!response) {
|
|
1347
947
|
errors.push(
|
|
1348
948
|
`middleware did not action for ${requestPath} in ${env}. Expected a rewrite to ${expectedUrl}`
|
|
@@ -1368,19 +968,13 @@ async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middl
|
|
|
1368
968
|
process.env.MFE_PREVIEW_DOMAINS = initialMfePreviewDomains;
|
|
1369
969
|
}
|
|
1370
970
|
}
|
|
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
971
|
export {
|
|
1378
972
|
expandWildcards,
|
|
973
|
+
getAllChildApplicationNames,
|
|
1379
974
|
getAllMultiZonesPaths,
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
getLaunchedPathsForZone,
|
|
975
|
+
getExpectedDomainForApp,
|
|
976
|
+
getFlaggedPathsForApp,
|
|
977
|
+
getLaunchedPathsForApp,
|
|
1384
978
|
loadMicrofrontendConfigForEdge,
|
|
1385
979
|
validateMiddlewareConfig,
|
|
1386
980
|
validateMiddlewareOnFlaggedPaths
|