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