@vercel/microfrontends 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/bin/cli.cjs +377 -1626
  2. package/dist/config.cjs +460 -1004
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +4 -25
  5. package/dist/config.js +456 -983
  6. package/dist/config.js.map +1 -1
  7. package/dist/{v2/microfrontends → microfrontends}/server.cjs +63 -143
  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 +63 -143
  11. package/dist/microfrontends/server.js.map +1 -0
  12. package/dist/{v2/microfrontends.cjs → microfrontends.cjs} +21 -21
  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} +20 -20
  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 +1323 -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 +1327 -1028
  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 +745 -396
  32. package/dist/next/middleware.cjs.map +1 -1
  33. package/dist/next/middleware.d.ts +10 -5
  34. package/dist/next/middleware.js +745 -396
  35. package/dist/next/middleware.js.map +1 -1
  36. package/dist/next/testing.cjs +595 -1032
  37. package/dist/next/testing.cjs.map +1 -1
  38. package/dist/next/testing.d.ts +14 -12
  39. package/dist/next/testing.js +589 -1016
  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 +211 -1333
  52. package/dist/utils/mfe-port.cjs.map +1 -1
  53. package/dist/utils/mfe-port.js +204 -1326
  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,299 @@ 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 tokens = (0, import_path_to_regexp2.parse)(path);
285
+ for (const token of tokens.slice(0, -1)) {
286
+ if (typeof token !== "string") {
287
+ errors.push(
288
+ `Path ${path} may only have a :wildcard in the last path component`
289
+ );
290
+ }
291
+ }
292
+ const existing = pathsByApplicationId.get(path);
293
+ if (existing) {
294
+ existing.applications.push(id);
295
+ } else {
296
+ pathsByApplicationId.set(path, {
297
+ applications: [id],
298
+ matcher: (0, import_path_to_regexp2.pathToRegexp)(path),
299
+ applicationId: id
300
+ });
301
+ }
302
+ }
303
+ }
240
304
  }
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
- };
305
+ const entries = Array.from(pathsByApplicationId.entries());
306
+ entries.forEach(([path, { applications: ids, matcher, applicationId }]) => {
307
+ if (ids.length > 1) {
308
+ errors.push(
309
+ `Duplicate path "${path}" for applications "${ids.join(", ")}"`
310
+ );
311
+ }
312
+ entries.forEach(
313
+ ([
314
+ matchPath,
315
+ { applications: matchIds, applicationId: matchApplicationId }
316
+ ]) => {
317
+ if (path === matchPath) {
318
+ return;
319
+ }
320
+ if (applicationId === matchApplicationId) {
321
+ return;
322
+ }
323
+ if (matcher.test(matchPath)) {
324
+ const source = `"${path}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
325
+ const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
326
+ errors.push(
327
+ `Overlapping path detected between ${source} and ${destination}`
328
+ );
329
+ }
330
+ }
331
+ );
332
+ });
333
+ if (errors.length) {
334
+ throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
335
+ type: "config",
336
+ subtype: "conflicting_paths"
250
337
  });
251
- return overridesConfig;
252
338
  }
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];
258
- }
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];
339
+ };
340
+ var validateAppPaths = (name, app) => {
341
+ for (const group of app.routing) {
342
+ for (const p of group.paths) {
343
+ if (p === "/") {
344
+ continue;
345
+ }
346
+ if (p.endsWith("/")) {
347
+ throw new MicrofrontendError(
348
+ `Invalid path for application "${name}". ${p} must not end with a slash.`,
349
+ { type: "application", subtype: "invalid_path" }
350
+ );
351
+ }
352
+ if (!p.startsWith("/")) {
353
+ throw new MicrofrontendError(
354
+ `Invalid path for application "${name}". ${p} must start with a slash.`,
355
+ { type: "application", subtype: "invalid_path" }
356
+ );
357
+ }
264
358
  }
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
359
  }
271
- static validateOverrideDomain(microfrontendConfig, zone, domain) {
272
- return new RegExp(
273
- `^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
274
- "|"
275
- )}$`
276
- ).test(domain);
360
+ };
361
+ var validateConfigDefaultApplication = (applicationConfigsById) => {
362
+ if (!applicationConfigsById) {
363
+ return;
277
364
  }
278
- serialize() {
279
- return this.config;
365
+ const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
366
+ ([, app]) => !isDefaultApp(app)
367
+ );
368
+ const applicationsWithRoutingNames = applicationsWithRouting.map(
369
+ ([key]) => key
370
+ );
371
+ const numApplications = Object.keys(applicationConfigsById).length;
372
+ const numApplicationsWithRouting = applicationsWithRoutingNames.length;
373
+ const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
374
+ if (numApplicationsWithoutRouting === 0) {
375
+ throw new MicrofrontendError(
376
+ `No default application found. At least one application needs to be the default by omitting routing.`,
377
+ { type: "config", subtype: "no_default_application" }
378
+ );
379
+ }
380
+ if (numApplicationsWithoutRouting > 1) {
381
+ throw new MicrofrontendError(
382
+ `Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
383
+ { type: "config", subtype: "multiple_default_applications" }
384
+ );
280
385
  }
281
386
  };
282
- var Overrides = _Overrides;
283
- Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
284
387
 
285
- // src/config/common/host.ts
388
+ // src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
389
+ var PREFIX = "vc-ap";
390
+ function generateAssetPrefixFromName({
391
+ name
392
+ }) {
393
+ if (!name) {
394
+ throw new Error("Name is required to generate an asset prefix");
395
+ }
396
+ return `${PREFIX}-${name}`;
397
+ }
398
+
399
+ // src/config/microfrontends-config/isomorphic/utils/generate-port.ts
400
+ function generatePortFromName({
401
+ name,
402
+ minPort = 3e3,
403
+ maxPort = 8e3
404
+ }) {
405
+ if (!name) {
406
+ throw new Error("Name is required to generate a port");
407
+ }
408
+ let hash = 0;
409
+ for (let i = 0; i < name.length; i++) {
410
+ hash = (hash << 5) - hash + name.charCodeAt(i);
411
+ hash |= 0;
412
+ }
413
+ hash = Math.abs(hash);
414
+ const range = maxPort - minPort;
415
+ const port = minPort + hash % range;
416
+ return port;
417
+ }
418
+
419
+ // src/config/microfrontends-config/isomorphic/host.ts
286
420
  var Host = class {
287
- constructor({ protocol, host, port }) {
288
- this.protocol = protocol || "https";
421
+ constructor(hostConfig, options) {
422
+ const { protocol = "https", host, port } = hostConfig;
423
+ this.protocol = protocol;
289
424
  this.host = host;
290
425
  this.port = Host.getPort({ port, protocol: this.protocol });
291
- this.serialized = {
292
- protocol,
293
- host,
294
- ...port ? { port } : void 0
295
- };
426
+ this.local = options == null ? void 0 : options.isLocal;
296
427
  }
297
428
  isLocal() {
298
- return this.host === "localhost" || this.host === "127.0.0.1";
429
+ return this.local || this.host === "localhost" || this.host === "127.0.0.1";
299
430
  }
300
431
  static getPort({
301
432
  protocol,
@@ -321,176 +452,234 @@ var Host = class {
321
452
  const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
322
453
  return new URL(url);
323
454
  }
324
- serialize() {
325
- return this.serialized;
455
+ };
456
+ var LocalHost = class extends Host {
457
+ constructor({
458
+ appName,
459
+ ...hostConfig
460
+ }) {
461
+ const host = hostConfig.host ?? "localhost";
462
+ const port = hostConfig.port ?? generatePortFromName({ name: appName });
463
+ const protocol = hostConfig.protocol ?? "http";
464
+ super({ protocol, host, port });
326
465
  }
327
466
  };
328
467
 
329
- // src/config/common/application.ts
468
+ // src/config/microfrontends-config/isomorphic/application.ts
330
469
  var Application = class {
331
470
  constructor(name, {
332
471
  app,
333
- overrides
472
+ overrides,
473
+ isDefault
334
474
  }) {
335
- Application.validate(name, app);
475
+ var _a, _b;
336
476
  this.name = name;
337
- this.default = app.default;
338
- this.routing = app.routing;
339
477
  this.development = {
340
- local: new Host(app.development.local),
341
- fallback: app.development.fallback ? new Host(app.development.fallback) : void 0
478
+ local: new LocalHost({
479
+ appName: name,
480
+ ...(_a = app.development) == null ? void 0 : _a.local
481
+ }),
482
+ fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
342
483
  };
343
- this.production = new Host(app.production);
484
+ this.production = app.production ? new Host(app.production) : void 0;
344
485
  this.vercel = app.vercel;
345
486
  this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
346
487
  environment: new Host(overrides.environment)
347
488
  } : void 0;
489
+ this.default = isDefault ?? false;
490
+ this.serialized = app;
348
491
  }
349
492
  isDefault() {
350
493
  return this.default;
351
494
  }
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
- }
495
+ getAssetPrefix() {
496
+ return generateAssetPrefixFromName({ name: this.name });
379
497
  }
380
498
  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
- };
499
+ return this.serialized;
500
+ }
501
+ };
502
+ var DefaultApplication = class extends Application {
503
+ constructor(name, {
504
+ app,
505
+ overrides
506
+ }) {
507
+ super(name, {
508
+ app,
509
+ overrides,
510
+ isDefault: true
511
+ });
512
+ this.default = true;
513
+ this.production = new Host(app.production);
514
+ }
515
+ getAssetPrefix() {
516
+ return "";
517
+ }
518
+ };
519
+ var ChildApplication = class extends Application {
520
+ constructor(name, {
521
+ app,
522
+ overrides
523
+ }) {
524
+ ChildApplication.validate(name, app);
525
+ super(name, {
526
+ app,
527
+ overrides,
528
+ isDefault: false
529
+ });
530
+ this.default = false;
531
+ this.routing = app.routing;
532
+ }
533
+ static validate(name, app) {
534
+ validateAppPaths(name, app);
403
535
  }
404
536
  };
405
537
 
406
- // src/config/common/microfrontend-config.ts
407
- var SUPPORTED_VERSIONS = ["1"];
538
+ // src/config/microfrontends-config/isomorphic/constants.ts
408
539
  var DEFAULT_LOCAL_PROXY_PORT = 3024;
409
- var MicrofrontendConfigCommon = class {
540
+
541
+ // src/config/microfrontends-config/isomorphic/index.ts
542
+ var MicrofrontendConfigIsomorphic = class {
410
543
  constructor({
411
544
  config,
412
- overrides
545
+ overrides,
546
+ meta
413
547
  }) {
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" }
548
+ this.childApplications = {};
549
+ var _a, _b, _c, _d;
550
+ MicrofrontendConfigIsomorphic.validate(config);
551
+ const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
552
+ this.overrides = overrides && !disableOverrides ? overrides : void 0;
553
+ this.isMainConfig = isMainConfig(config);
554
+ if (isMainConfig(config)) {
555
+ for (const [appId, appConfig] of Object.entries(config.applications)) {
556
+ const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
557
+ if (isDefaultApp(appConfig)) {
558
+ this.defaultApplication = new DefaultApplication(appId, {
559
+ app: appConfig,
560
+ overrides: appOverrides
561
+ });
562
+ } else {
563
+ this.childApplications[appId] = new ChildApplication(appId, {
564
+ app: appConfig,
565
+ overrides: appOverrides
566
+ });
567
+ }
568
+ }
569
+ } else {
570
+ this.partOf = config.partOf;
571
+ const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
572
+ this.childApplications[meta.fromApp] = new ChildApplication(
573
+ meta.fromApp,
574
+ {
575
+ // we don't know routing because we're not in the main config
576
+ app: { routing: [] },
577
+ overrides: appOverrides
578
+ }
422
579
  );
423
580
  }
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
- });
581
+ if (isMainConfig(config) && !this.defaultApplication) {
582
+ throw new MicrofrontendError(
583
+ `Could not find default application in microfrontends configuration`,
584
+ {
585
+ type: "application",
586
+ subtype: "not_found"
587
+ }
588
+ );
431
589
  }
432
590
  this.config = config;
433
- this.name = config.name;
434
- this.version = config.version;
435
591
  this.options = config.options;
436
- this.$schema = config.$schema;
592
+ this.serialized = {
593
+ config,
594
+ overrides,
595
+ meta
596
+ };
597
+ }
598
+ static validate(config) {
599
+ const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
600
+ if (isMainConfig(c)) {
601
+ validateConfigVersion(c.version);
602
+ validateConfigPaths(c.applications);
603
+ validateConfigDefaultApplication(c.applications);
604
+ }
605
+ return c;
606
+ }
607
+ static fromEnv({
608
+ meta,
609
+ cookies
610
+ }) {
611
+ return new MicrofrontendConfigIsomorphic({
612
+ config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
613
+ overrides: parseOverrides(cookies ?? []),
614
+ meta
615
+ });
437
616
  }
438
617
  isOverridesDisabled() {
439
618
  var _a, _b;
440
619
  return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
441
620
  }
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
621
  getConfig() {
456
622
  return this.config;
457
623
  }
624
+ getApplicationsByType() {
625
+ return {
626
+ defaultApplication: this.defaultApplication,
627
+ applications: Object.values(this.childApplications)
628
+ };
629
+ }
630
+ getChildApplications() {
631
+ return Object.values(this.childApplications);
632
+ }
458
633
  getAllApplications() {
459
- return Object.values(this.zones);
634
+ return [
635
+ this.defaultApplication,
636
+ ...Object.values(this.childApplications)
637
+ ].filter(Boolean);
460
638
  }
461
- getZone(name) {
462
- const zone = this.zones[name];
463
- if (!zone) {
639
+ getApplication(name) {
640
+ var _a;
641
+ if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
642
+ return this.defaultApplication;
643
+ }
644
+ const app = this.childApplications[name];
645
+ if (!app) {
464
646
  throw new MicrofrontendError(
465
647
  `Could not find microfrontends configuration for application "${name}"`,
466
648
  {
467
- type: "zone",
649
+ type: "application",
468
650
  subtype: "not_found"
469
651
  }
470
652
  );
471
653
  }
472
- return zone;
654
+ return app;
473
655
  }
474
656
  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;
657
+ var _a, _b;
658
+ if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
659
+ return this.defaultApplication;
660
+ }
661
+ return Object.values(this.childApplications).find(
662
+ (app) => {
663
+ var _a2;
664
+ return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
479
665
  }
480
666
  );
481
667
  }
482
- getDefaultZone() {
483
- const zone = Object.values(this.zones).find((z) => z.default);
484
- if (!zone) {
668
+ /**
669
+ * Returns the default application. This can throw if the default application
670
+ * is undefined ( )
671
+ */
672
+ getDefaultApplication() {
673
+ if (!this.defaultApplication) {
485
674
  throw new MicrofrontendError(
486
- `Could not find default zone in microfrontends configuration`,
675
+ `Could not find default application in microfrontends configuration`,
487
676
  {
488
- type: "zone",
677
+ type: "application",
489
678
  subtype: "not_found"
490
679
  }
491
680
  );
492
681
  }
493
- return zone;
682
+ return this.defaultApplication;
494
683
  }
495
684
  /**
496
685
  * Returns the configured port for the local proxy
@@ -505,764 +694,144 @@ var MicrofrontendConfigCommon = class {
505
694
  * NOTE: This is used when writing the config to disk and must always match the input Schema
506
695
  */
507
696
  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
- };
536
- }
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
- );
697
+ return this.serialized.config;
560
698
  }
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
- },
699
+ toClientConfig() {
700
+ const applications = Object.fromEntries(
701
+ Object.entries(this.childApplications).map(([name, application]) => [
702
+ name,
609
703
  {
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"
840
- }
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`."
704
+ default: false,
705
+ routing: application.routing
880
706
  }
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" }
899
- );
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" }
707
+ ])
911
708
  );
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
- );
709
+ if (this.defaultApplication) {
710
+ applications[this.defaultApplication.name] = {
711
+ default: true
712
+ };
992
713
  }
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"
714
+ return new MicrofrontendConfigClient({
715
+ applications
1018
716
  });
1019
717
  }
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
- }
718
+ serialize() {
719
+ return this.serialized;
1072
720
  }
1073
721
  };
1074
722
 
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)
723
+ // src/routing/get-domain-from-environment.ts
724
+ function getDomainFromEnvironment({
725
+ app,
726
+ target
727
+ }) {
728
+ var _a;
729
+ const mfeProjects = JSON.parse(
730
+ process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "[]"
1139
731
  );
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;
732
+ if (mfeProjects.length === 0) {
733
+ throw new Error("Missing related microfrontends project information");
1152
734
  }
1153
- static fromEnv({
1154
- cookies
1155
- }) {
1156
- return new MicrofrontendConfigCommon({
1157
- config: MicrofrontendConfig.validate(
1158
- MicrofrontendConfigCommon.getConfigFromEnv()
1159
- ),
1160
- overrides: Overrides.parseOverrides(cookies)
1161
- });
735
+ if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
736
+ throw new Error(`Missing applications[${app.name}].vercel.projectId`);
1162
737
  }
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
- });
738
+ const vercelProject = mfeProjects.find(
739
+ (p) => {
740
+ var _a2;
741
+ return p.project.id === ((_a2 = app.vercel) == null ? void 0 : _a2.projectId);
1175
742
  }
743
+ );
744
+ if (!vercelProject) {
745
+ throw new Error(
746
+ `Missing related microfrontends project information for application "${app.name}"`
747
+ );
1176
748
  }
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
- }
749
+ const domain = target === "preview" && vercelProject.preview.branch ? vercelProject.preview.branch : vercelProject.production.alias ?? vercelProject.production.url;
750
+ if (!domain) {
751
+ throw new Error(
752
+ `Missing domain for target "${target}" in application "${app.name}"`
753
+ );
1192
754
  }
1193
- };
755
+ return domain.startsWith("https://") ? domain : `https://${domain}`;
756
+ }
1194
757
 
1195
758
  // src/next/testing/index.ts
1196
- function expandWildcards(path3) {
1197
- if (path3.includes("/:path*") || path3.includes("/:slug*")) {
759
+ function expandWildcards(path) {
760
+ if (path.includes("/:path*") || path.includes("/:slug*")) {
1198
761
  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")
762
+ path === "/:path*" || path === "/:slug*" ? "/" : path.replace("/:path*", "").replace("/:slug*", ""),
763
+ path.replace("/:path*", "/foo").replace("/:slug*", "/foo"),
764
+ path.replace("/:path*", "/foo/bar").replace("/:slug*", "/foo/bar")
1202
765
  ];
1203
766
  }
1204
- if (path3.includes("/:path+") || path3.includes("/:slug+")) {
767
+ if (path.includes("/:path+") || path.includes("/:slug+")) {
1205
768
  return [
1206
- path3.replace("/:path+", "/foo").replace("/:slug+", "/foo"),
1207
- path3.replace("/:path+", "/foo/bar").replace("/:slug+", "/foo/bar")
769
+ path.replace("/:path+", "/foo").replace("/:slug+", "/foo"),
770
+ path.replace("/:path+", "/foo/bar").replace("/:slug+", "/foo/bar")
1208
771
  ];
1209
772
  }
1210
- if (path3.includes("/:path") || path3.includes("/:slug")) {
1211
- return [path3.replace("/:path", "/foo").replace("/:slug", "/foo")];
773
+ if (path.includes("/:path") || path.includes("/:slug")) {
774
+ return [path.replace("/:path", "/foo").replace("/:slug", "/foo")];
1212
775
  }
1213
- return [path3];
776
+ return [path];
1214
777
  }
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 });
778
+ function loadMicrofrontendConfigForEdge(path) {
779
+ const rawMfConfig = (0, import_jsonc_parser2.parse)((0, import_node_fs.readFileSync)(path, "utf-8"));
780
+ return new MicrofrontendConfigIsomorphic({
781
+ config: rawMfConfig,
782
+ meta: { fromApp: "test" }
783
+ });
1218
784
  }
1219
- function getAllZoneNames(mfConfig) {
1220
- return mfConfig.getAllApplications().filter((app) => !app.default).map((app) => app.name);
785
+ function getAllChildApplicationNames(mfConfig) {
786
+ return mfConfig.getChildApplications().map((app) => app.name);
1221
787
  }
1222
- function getLaunchedPathsForZone(mfConfig, zoneName) {
1223
- var _a, _b;
1224
- const zone = mfConfig.getZone(zoneName);
788
+ function getLaunchedPathsForApp(mfConfig, appName) {
789
+ const app = mfConfig.getApplication(appName);
790
+ if (app instanceof DefaultApplication) {
791
+ return [];
792
+ }
1225
793
  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))) ?? []
794
+ `/${app.getAssetPrefix()}/_next/static`,
795
+ ...app.routing.filter((group) => !group.flag).flatMap((group) => group.paths.flatMap(expandWildcards))
1231
796
  ];
1232
797
  }
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))) ?? [];
798
+ function getFlaggedPathsForApp(mfConfig, appName) {
799
+ const app = mfConfig.getApplication(appName);
800
+ if (app instanceof DefaultApplication) {
801
+ return [];
802
+ }
803
+ return app.routing.filter((group) => Boolean(group.flag)).flatMap((group) => group.paths.flatMap(expandWildcards));
1240
804
  }
1241
- function getExpectedDomainForZone(mfConfig, zoneName, env) {
1242
- const zone = mfConfig.getZone(zoneName);
1243
- return env === "development" ? zone.development.local.toString() : zone.production.toString();
805
+ function getExpectedDomainForApp(mfConfig, appName, env) {
806
+ const app = mfConfig.getApplication(appName);
807
+ const defaultApp = mfConfig.getDefaultApplication();
808
+ if (env === "development") {
809
+ return app.development.local.toString();
810
+ }
811
+ if (["preview", "production"].includes(env)) {
812
+ const target = env;
813
+ return getDomainFromEnvironment({ app, target });
814
+ }
815
+ return defaultApp.production.toString();
1244
816
  }
1245
817
  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
- )) ?? [];
818
+ return mfConfig.getChildApplications().flatMap((app) => {
819
+ return app.routing.flatMap((group) => group.paths.flatMap(expandWildcards));
1251
820
  });
1252
821
  }
1253
- function urlMatches(middlewareConfig, path3, host) {
822
+ function urlMatches(middlewareConfig, path, host) {
1254
823
  if (!middlewareConfig.matcher) {
1255
824
  return false;
1256
825
  }
1257
826
  const matchers = Array.isArray(middlewareConfig.matcher) ? middlewareConfig.matcher : [middlewareConfig.matcher];
1258
827
  for (let matcher of matchers) {
1259
828
  matcher = typeof matcher === "string" ? { source: matcher } : matcher;
1260
- if ((0, import_path_to_regexp2.match)(matcher.source)(path3)) {
829
+ if ((0, import_path_to_regexp3.match)(matcher.source)(path)) {
1261
830
  if ((0, import_prepare_destination.matchHas)(
1262
831
  new import_web.WebNextRequest(
1263
832
  new import_adapter.NextRequestHint({
1264
833
  init: { headers: { host } },
1265
- input: `https://${host}${path3}`,
834
+ input: `https://${host}${path}`,
1266
835
  page: "unused_placeholder"
1267
836
  })
1268
837
  ),
@@ -1277,54 +846,50 @@ function urlMatches(middlewareConfig, path3, host) {
1277
846
  return false;
1278
847
  }
1279
848
  function validateMiddlewareConfig(middlewareConfig, microfrontendConfigOrPath, extraProductionMatches) {
1280
- var _a, _b;
1281
849
  const microfrontendConfig = typeof microfrontendConfigOrPath === "string" ? loadMicrofrontendConfigForEdge(microfrontendConfigOrPath) : microfrontendConfigOrPath;
1282
850
  const errors = [];
1283
851
  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")) {
852
+ for (const application of microfrontendConfig.getChildApplications()) {
853
+ const matches = [...application.routing];
854
+ matches.push({
855
+ paths: [`/${application.getAssetPrefix()}/_next/:path+`]
856
+ });
857
+ for (const aMatch of matches) {
858
+ const isFlagged = Boolean(aMatch.flag);
859
+ for (const path of aMatch.paths) {
860
+ const pathsToTest = expandWildcards(path);
861
+ for (const testPath of pathsToTest) {
862
+ const productionHost = microfrontendConfig.getDefaultApplication().production.host;
863
+ const pathForDisplay = `${testPath}${path === testPath ? "" : ` (synthesized from ${path})`}`;
864
+ if (!urlMatches(middlewareConfig, testPath, "test.nonproduction.host")) {
865
+ errors.push(
866
+ `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:
867
+ ${getSampleMatcher(path, productionHost)}`
868
+ );
869
+ break;
870
+ }
871
+ const productionUrlMatches = urlMatches(
872
+ middlewareConfig,
873
+ testPath,
874
+ productionHost
875
+ );
876
+ if (isFlagged) {
877
+ if (!productionUrlMatches) {
1299
878
  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)}`
879
+ `Matcher misconfigured for ${pathForDisplay}. Middleware config matchers for flagged paths should ALWAYS match.`
1302
880
  );
1303
881
  break;
1304
882
  }
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;
883
+ } else if (productionUrlMatches) {
884
+ if (extraProductionMatches == null ? void 0 : extraProductionMatches.includes(path)) {
885
+ usedExtraProductionMatches.add(path);
886
+ } else {
887
+ errors.push(
888
+ `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:
889
+ ${getSampleMatcher(path, productionHost)}`
890
+ );
1327
891
  }
892
+ break;
1328
893
  }
1329
894
  }
1330
895
  }
@@ -1345,9 +910,9 @@ ${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}
1345
910
  throw new Error(message + errors.join("\n\n- "));
1346
911
  }
1347
912
  }
1348
- function getSampleMatcher(path3, host) {
913
+ function getSampleMatcher(path, host) {
1349
914
  return ` {
1350
- source: '${path3}', // This can also be a broader regular expression.
915
+ source: '${path}', // This can also be a broader regular expression.
1351
916
  missing: [
1352
917
  type: 'header',
1353
918
  key: 'host',
@@ -1360,21 +925,25 @@ async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middl
1360
925
  const initialMfePreviewDomains = process.env.MFE_PREVIEW_DOMAINS;
1361
926
  try {
1362
927
  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);
928
+ const allAppNames = getAllChildApplicationNames(microfrontendConfig);
1366
929
  const errors = [];
1367
- for (const zoneName of allZoneNames) {
1368
- const flaggedPaths = getFlaggedPathsForZone(
1369
- microfrontendConfig,
1370
- zoneName
1371
- );
930
+ for (const appName of allAppNames) {
931
+ const flaggedPaths = getFlaggedPathsForApp(microfrontendConfig, appName);
1372
932
  if (flaggedPaths.length) {
1373
933
  for (const env of ["preview", "production"]) {
1374
934
  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}`;
935
+ for (const path of flaggedPaths) {
936
+ const expectedHost = getExpectedDomainForApp(
937
+ microfrontendConfig,
938
+ appName,
939
+ env
940
+ );
941
+ const expectedDefaultHost = getExpectedDomainForApp(
942
+ microfrontendConfig,
943
+ microfrontendConfig.getDefaultApplication().name,
944
+ env
945
+ );
946
+ const requestPath = `${expectedDefaultHost}${path}`;
1378
947
  const request = new import_server.NextRequest(requestPath, {
1379
948
  headers: { "x-vercel-skip-deployment-existence-check": "1" }
1380
949
  });
@@ -1382,7 +951,7 @@ async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middl
1382
951
  request,
1383
952
  {}
1384
953
  );
1385
- const expectedUrl = `${expectedHost}${path3}`;
954
+ const expectedUrl = `${expectedHost}${path}`;
1386
955
  if (!response) {
1387
956
  errors.push(
1388
957
  `middleware did not action for ${requestPath} in ${env}. Expected a rewrite to ${expectedUrl}`
@@ -1408,20 +977,14 @@ async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middl
1408
977
  process.env.MFE_PREVIEW_DOMAINS = initialMfePreviewDomains;
1409
978
  }
1410
979
  }
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
980
  // Annotate the CommonJS export names for ESM import in node:
1418
981
  0 && (module.exports = {
1419
982
  expandWildcards,
983
+ getAllChildApplicationNames,
1420
984
  getAllMultiZonesPaths,
1421
- getAllZoneNames,
1422
- getExpectedDomainForZone,
1423
- getFlaggedPathsForZone,
1424
- getLaunchedPathsForZone,
985
+ getExpectedDomainForApp,
986
+ getFlaggedPathsForApp,
987
+ getLaunchedPathsForApp,
1425
988
  loadMicrofrontendConfigForEdge,
1426
989
  validateMiddlewareConfig,
1427
990
  validateMiddlewareOnFlaggedPaths