@vercel/microfrontends 0.10.1 → 0.12.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 (61) hide show
  1. package/dist/bin/cli.cjs +263 -102
  2. package/dist/config.cjs +0 -2
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.js +0 -2
  5. package/dist/config.js.map +1 -1
  6. package/dist/{index-acb44057.d.ts → index-35038aec.d.ts} +2 -2
  7. package/dist/next/config.cjs +10 -3
  8. package/dist/next/config.cjs.map +1 -1
  9. package/dist/next/config.js +10 -3
  10. package/dist/next/config.js.map +1 -1
  11. package/dist/next/middleware.cjs +17 -1
  12. package/dist/next/middleware.cjs.map +1 -1
  13. package/dist/next/middleware.js +17 -1
  14. package/dist/next/middleware.js.map +1 -1
  15. package/dist/next/testing.cjs +0 -2
  16. package/dist/next/testing.cjs.map +1 -1
  17. package/dist/next/testing.js +0 -2
  18. package/dist/next/testing.js.map +1 -1
  19. package/dist/{types-c3d15d04.d.ts → types-15b7f215.d.ts} +1 -1
  20. package/dist/{types-7b1cd9f7.d.ts → types-a995174e.d.ts} +1 -4
  21. package/dist/v2/config.cjs +1 -1
  22. package/dist/v2/config.cjs.map +1 -1
  23. package/dist/v2/config.d.ts +3 -3
  24. package/dist/v2/config.js +1 -1
  25. package/dist/v2/config.js.map +1 -1
  26. package/dist/v2/microfrontends/server.cjs +215 -53
  27. package/dist/v2/microfrontends/server.cjs.map +1 -1
  28. package/dist/v2/microfrontends/server.d.ts +22 -3
  29. package/dist/v2/microfrontends/server.js +215 -53
  30. package/dist/v2/microfrontends/server.js.map +1 -1
  31. package/dist/v2/microfrontends.cjs +1 -2
  32. package/dist/v2/microfrontends.cjs.map +1 -1
  33. package/dist/v2/microfrontends.d.ts +3 -4
  34. package/dist/v2/microfrontends.js +1 -2
  35. package/dist/v2/microfrontends.js.map +1 -1
  36. package/dist/v2/next/config.cjs +249 -82
  37. package/dist/v2/next/config.cjs.map +1 -1
  38. package/dist/v2/next/config.js +249 -82
  39. package/dist/v2/next/config.js.map +1 -1
  40. package/dist/v2/next/endpoints.cjs +5 -2
  41. package/dist/v2/next/endpoints.cjs.map +1 -1
  42. package/dist/v2/next/endpoints.d.ts +1 -1
  43. package/dist/v2/next/endpoints.js +5 -2
  44. package/dist/v2/next/endpoints.js.map +1 -1
  45. package/dist/v2/next/middleware.cjs +107 -88
  46. package/dist/v2/next/middleware.cjs.map +1 -1
  47. package/dist/v2/next/middleware.js +107 -88
  48. package/dist/v2/next/middleware.js.map +1 -1
  49. package/dist/v2/overrides.cjs +1 -1
  50. package/dist/v2/overrides.cjs.map +1 -1
  51. package/dist/v2/overrides.d.ts +3 -3
  52. package/dist/v2/overrides.js +1 -1
  53. package/dist/v2/overrides.js.map +1 -1
  54. package/dist/v2/schema.d.ts +1 -1
  55. package/dist/validation.cjs +1 -11
  56. package/dist/validation.cjs.map +1 -1
  57. package/dist/validation.d.ts +0 -3
  58. package/dist/validation.js +1 -11
  59. package/dist/validation.js.map +1 -1
  60. package/package.json +8 -7
  61. package/schema/schema-v2.json +0 -14
@@ -33,14 +33,14 @@ __export(config_exports, {
33
33
  withMicrofrontends: () => withMicrofrontends
34
34
  });
35
35
  module.exports = __toCommonJS(config_exports);
36
- var import_node_fs4 = __toESM(require("fs"), 1);
36
+ var import_node_fs7 = __toESM(require("fs"), 1);
37
37
 
38
38
  // src/config-v2/microfrontends/server/index.ts
39
- var import_node_fs3 = __toESM(require("fs"), 1);
40
- var import_node_path4 = require("path");
39
+ var import_node_fs6 = __toESM(require("fs"), 1);
40
+ var import_node_path7 = require("path");
41
41
 
42
42
  // src/config-v2/overrides/constants.ts
43
- var OVERRIDES_COOKIE_PREFIX = "vercel-microfrontends-override";
43
+ var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
44
44
  var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
45
45
 
46
46
  // src/config-v2/overrides/is-override-cookie.ts
@@ -221,21 +221,21 @@ var MicrofrontendConfigClient = class {
221
221
  isEqual(other) {
222
222
  return JSON.stringify(this.applications) === JSON.stringify(other.applications);
223
223
  }
224
- getApplicationNameForPath(path3) {
225
- if (!path3.startsWith("/")) {
224
+ getApplicationNameForPath(path5) {
225
+ if (!path5.startsWith("/")) {
226
226
  throw new Error(`Path must start with a /`);
227
227
  }
228
- if (this.pathCache[path3]) {
229
- return this.pathCache[path3];
228
+ if (this.pathCache[path5]) {
229
+ return this.pathCache[path5];
230
230
  }
231
- const pathname = new URL(path3, "https://example.com").pathname;
231
+ const pathname = new URL(path5, "https://example.com").pathname;
232
232
  for (const [name, application] of Object.entries(this.applications)) {
233
233
  if (application.routing) {
234
234
  for (const group of application.routing) {
235
235
  for (const childPath of group.paths) {
236
236
  const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
237
237
  if (regexp.test(pathname)) {
238
- this.pathCache[path3] = name;
238
+ this.pathCache[path5] = name;
239
239
  return name;
240
240
  }
241
241
  }
@@ -248,7 +248,7 @@ var MicrofrontendConfigClient = class {
248
248
  if (!defaultApplication) {
249
249
  return null;
250
250
  }
251
- this.pathCache[path3] = defaultApplication[0];
251
+ this.pathCache[path5] = defaultApplication[0];
252
252
  return defaultApplication[0];
253
253
  }
254
254
  serialize() {
@@ -280,22 +280,22 @@ var validateConfigPaths = (applicationConfigsById) => {
280
280
  continue;
281
281
  }
282
282
  for (const pathMatch of app.routing) {
283
- for (const path3 of pathMatch.paths) {
284
- const tokens = (0, import_path_to_regexp2.parse)(path3);
283
+ for (const path5 of pathMatch.paths) {
284
+ const tokens = (0, import_path_to_regexp2.parse)(path5);
285
285
  for (const token of tokens.slice(0, -1)) {
286
286
  if (typeof token !== "string") {
287
287
  errors.push(
288
- `Path ${path3} may only have a :wildcard in the last path component`
288
+ `Path ${path5} may only have a :wildcard in the last path component`
289
289
  );
290
290
  }
291
291
  }
292
- const existing = pathsByApplicationId.get(path3);
292
+ const existing = pathsByApplicationId.get(path5);
293
293
  if (existing) {
294
294
  existing.applications.push(id);
295
295
  } else {
296
- pathsByApplicationId.set(path3, {
296
+ pathsByApplicationId.set(path5, {
297
297
  applications: [id],
298
- matcher: (0, import_path_to_regexp2.pathToRegexp)(path3),
298
+ matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
299
299
  applicationId: id
300
300
  });
301
301
  }
@@ -303,10 +303,10 @@ var validateConfigPaths = (applicationConfigsById) => {
303
303
  }
304
304
  }
305
305
  const entries = Array.from(pathsByApplicationId.entries());
306
- entries.forEach(([path3, { applications: ids, matcher, applicationId }]) => {
306
+ entries.forEach(([path5, { applications: ids, matcher, applicationId }]) => {
307
307
  if (ids.length > 1) {
308
308
  errors.push(
309
- `Duplicate path "${path3}" for applications "${ids.join(", ")}"`
309
+ `Duplicate path "${path5}" for applications "${ids.join(", ")}"`
310
310
  );
311
311
  }
312
312
  entries.forEach(
@@ -314,14 +314,14 @@ var validateConfigPaths = (applicationConfigsById) => {
314
314
  matchPath,
315
315
  { applications: matchIds, applicationId: matchApplicationId }
316
316
  ]) => {
317
- if (path3 === matchPath) {
317
+ if (path5 === matchPath) {
318
318
  return;
319
319
  }
320
320
  if (applicationId === matchApplicationId) {
321
321
  return;
322
322
  }
323
323
  if (matcher.test(matchPath)) {
324
- const source = `"${path3}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
324
+ const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
325
325
  const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
326
326
  errors.push(
327
327
  `Overlapping path detected between ${source} and ${destination}`
@@ -754,7 +754,6 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
754
754
  var _a, _b, _c;
755
755
  super({ config, overrides, meta });
756
756
  this.isMainConfig = true;
757
- this.provider = config.provider;
758
757
  const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
759
758
  let defaultApplication;
760
759
  for (const [appId, appConfig] of Object.entries(config.applications)) {
@@ -886,8 +885,115 @@ function findPackagePath(opts) {
886
885
  return result;
887
886
  }
888
887
 
888
+ // src/config-v2/microfrontends/utils/find-default-package.ts
889
+ var import_node_path3 = require("path");
890
+ var import_node_fs3 = require("fs");
891
+ var import_fast_glob2 = __toESM(require("fast-glob"), 1);
892
+ var configCache2 = {};
893
+ function findDefaultMicrofrontendsPackages({
894
+ repositoryRoot,
895
+ applicationName
896
+ }) {
897
+ try {
898
+ const microfrontendsJsonPaths = import_fast_glob2.default.globSync("**/microfrontends.json", {
899
+ cwd: repositoryRoot,
900
+ absolute: true,
901
+ onlyFiles: true,
902
+ followSymbolicLinks: false,
903
+ ignore: ["**/node_modules/**", "**/.git/**"]
904
+ });
905
+ const matchingPaths = [];
906
+ for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
907
+ const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
908
+ microfrontendsJsonPath,
909
+ "utf-8"
910
+ );
911
+ const microfrontendsJson = JSON.parse(
912
+ microfrontendsJsonContent
913
+ );
914
+ if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
915
+ matchingPaths.push(microfrontendsJsonPath);
916
+ }
917
+ }
918
+ if (matchingPaths.length > 1) {
919
+ throw new Error(
920
+ `Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
921
+ ${matchingPaths.join("\n \u2022 ")}`
922
+ );
923
+ }
924
+ if (matchingPaths.length === 0) {
925
+ throw new Error(
926
+ `Could not find default application with "applications.${applicationName}"`
927
+ );
928
+ }
929
+ const [packageJsonPath] = matchingPaths;
930
+ return (0, import_node_path3.dirname)(packageJsonPath);
931
+ } catch (error) {
932
+ return null;
933
+ }
934
+ }
935
+ function findDefaultMicrofrontendsPackage(opts) {
936
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
937
+ if (configCache2[cacheKey]) {
938
+ return configCache2[cacheKey];
939
+ }
940
+ const result = findDefaultMicrofrontendsPackages(opts);
941
+ if (!result) {
942
+ throw new Error(
943
+ `Error trying to resolve the main microfrontends.json configuration`
944
+ );
945
+ }
946
+ configCache2[cacheKey] = result;
947
+ return result;
948
+ }
949
+
950
+ // src/config-v2/microfrontends/utils/is-monorepo.ts
951
+ var import_node_fs4 = __toESM(require("fs"), 1);
952
+ var import_node_path4 = __toESM(require("path"), 1);
953
+ function isMonorepo({
954
+ repositoryRoot
955
+ }) {
956
+ try {
957
+ if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
958
+ return true;
959
+ }
960
+ if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
961
+ return true;
962
+ }
963
+ const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
964
+ if (!import_node_fs4.default.existsSync(packageJsonPath)) {
965
+ return false;
966
+ }
967
+ const packageJson = JSON.parse(
968
+ import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
969
+ );
970
+ return packageJson.workspaces !== void 0;
971
+ } catch (error) {
972
+ console.error("Error determining if repository is a monorepo", error);
973
+ return false;
974
+ }
975
+ }
976
+
977
+ // src/config-v2/microfrontends/utils/find-package-root.ts
978
+ var import_node_fs5 = __toESM(require("fs"), 1);
979
+ var import_node_path5 = __toESM(require("path"), 1);
980
+ var PACKAGE_JSON = "package.json";
981
+ function findPackageRoot(startDir) {
982
+ let currentDir = startDir || process.cwd();
983
+ while (currentDir !== import_node_path5.default.parse(currentDir).root) {
984
+ const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
985
+ if (import_node_fs5.default.existsSync(pkgJsonPath)) {
986
+ return currentDir;
987
+ }
988
+ currentDir = import_node_path5.default.dirname(currentDir);
989
+ }
990
+ throw new Error(
991
+ "Package root not found. Specify the root of the package with the `package.root` option."
992
+ );
993
+ }
994
+
889
995
  // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
890
- var import_node_path3 = __toESM(require("path"), 1);
996
+ var import_node_path6 = __toESM(require("path"), 1);
891
997
 
892
998
  // src/config-v2/microfrontends/server/constants.ts
893
999
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -901,13 +1007,13 @@ function isVercel() {
901
1007
  // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
902
1008
  function getOutputFilePath() {
903
1009
  if (isVercel()) {
904
- return import_node_path3.default.join(
1010
+ return import_node_path6.default.join(
905
1011
  ".vercel",
906
1012
  MFE_CONFIG_DEFAULT_FILE_PATH,
907
1013
  MFE_CONFIG_DEFAULT_FILE_NAME
908
1014
  );
909
1015
  }
910
- return import_node_path3.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1016
+ return import_node_path6.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
911
1017
  }
912
1018
 
913
1019
  // src/config-v2/microfrontends/server/validation.ts
@@ -1041,15 +1147,12 @@ var schema_v2_default = {
1041
1147
  },
1042
1148
  description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
1043
1149
  },
1044
- provider: {
1045
- $ref: "#/definitions/Provider"
1046
- },
1047
1150
  applications: {
1048
1151
  $ref: "#/definitions/ApplicationRouting",
1049
1152
  description: "Mapping of application names to the routes that they host. Only needs to be defined in the application that owns the primary microfrontend domain"
1050
1153
  }
1051
1154
  },
1052
- required: ["applications", "provider", "version"]
1155
+ required: ["applications", "version"]
1053
1156
  },
1054
1157
  Options: {
1055
1158
  type: "object",
@@ -1121,9 +1224,6 @@ var schema_v2_default = {
1121
1224
  projectId: {
1122
1225
  type: "string",
1123
1226
  description: "Vercel project ID"
1124
- },
1125
- routeSpeedInsightsToDefaultZone: {
1126
- type: "boolean"
1127
1227
  }
1128
1228
  },
1129
1229
  required: ["projectId"]
@@ -1226,10 +1326,6 @@ var schema_v2_default = {
1226
1326
  },
1227
1327
  required: ["paths"]
1228
1328
  },
1229
- Provider: {
1230
- type: "string",
1231
- enum: ["vercel", "other"]
1232
- },
1233
1329
  ApplicationRouting: {
1234
1330
  type: "object",
1235
1331
  additionalProperties: {
@@ -1293,8 +1389,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1293
1389
  pretty: true
1294
1390
  }) {
1295
1391
  const outputPath = getOutputFilePath();
1296
- import_node_fs3.default.mkdirSync((0, import_node_path4.dirname)(outputPath), { recursive: true });
1297
- import_node_fs3.default.writeFileSync(
1392
+ import_node_fs6.default.mkdirSync((0, import_node_path7.dirname)(outputPath), { recursive: true });
1393
+ import_node_fs6.default.writeFileSync(
1298
1394
  outputPath,
1299
1395
  JSON.stringify(
1300
1396
  this.config.toSchemaJson(),
@@ -1356,6 +1452,69 @@ var MicrofrontendsServer = class extends Microfrontends {
1356
1452
  }
1357
1453
  return config;
1358
1454
  }
1455
+ /**
1456
+ * Looks up the configuration by inferring the package root and looking for a microfrontends.json file. If a file is not found,
1457
+ * it will look for a package in the repository with a microfrontends.json file that contains the current application
1458
+ * and use that configuration.
1459
+ *
1460
+ * This can return either a Child or Main configuration.
1461
+ */
1462
+ static infer({
1463
+ directory,
1464
+ filePath,
1465
+ meta,
1466
+ cookies,
1467
+ options
1468
+ } = {}) {
1469
+ if (filePath && meta) {
1470
+ return MicrofrontendsServer.fromFile({
1471
+ filePath,
1472
+ cookies,
1473
+ meta,
1474
+ options
1475
+ });
1476
+ }
1477
+ try {
1478
+ const packageRoot = findPackageRoot(directory);
1479
+ const packageJsonPath = (0, import_node_path7.join)(packageRoot, "package.json");
1480
+ const packageJson = JSON.parse(
1481
+ import_node_fs6.default.readFileSync(packageJsonPath, "utf-8")
1482
+ );
1483
+ if (!packageJson.name) {
1484
+ throw new Error(`No name found in package.json at ${packageJsonPath}`);
1485
+ }
1486
+ const configMeta = meta ?? { fromApp: packageJson.name };
1487
+ const maybeConfig = (0, import_node_path7.join)(packageRoot, "microfrontends.json");
1488
+ if (import_node_fs6.default.existsSync(maybeConfig)) {
1489
+ return MicrofrontendsServer.fromFile({
1490
+ filePath: maybeConfig,
1491
+ cookies,
1492
+ meta: configMeta,
1493
+ options
1494
+ });
1495
+ }
1496
+ const repositoryRoot = findRepositoryRoot();
1497
+ const isMonorepo2 = isMonorepo({ repositoryRoot });
1498
+ if (isMonorepo2) {
1499
+ const defaultPackage = findDefaultMicrofrontendsPackage({
1500
+ repositoryRoot,
1501
+ applicationName: packageJson.name
1502
+ });
1503
+ return MicrofrontendsServer.fromFile({
1504
+ filePath: (0, import_node_path7.join)(defaultPackage, "microfrontends.json"),
1505
+ cookies,
1506
+ meta: configMeta,
1507
+ options
1508
+ });
1509
+ }
1510
+ throw new Error("Unable to infer");
1511
+ } catch (e) {
1512
+ throw new MicrofrontendError(
1513
+ "Unable to infer microfrontends configuration",
1514
+ { type: "config", subtype: "inference_failed" }
1515
+ );
1516
+ }
1517
+ }
1359
1518
  /*
1360
1519
  * Generates a MicrofrontendsServer instance from a file.
1361
1520
  */
@@ -1366,25 +1525,28 @@ var MicrofrontendsServer = class extends Microfrontends {
1366
1525
  options
1367
1526
  }) {
1368
1527
  try {
1369
- const configJson = import_node_fs3.default.readFileSync(filePath, "utf-8");
1528
+ const configJson = import_node_fs6.default.readFileSync(filePath, "utf-8");
1370
1529
  const config = MicrofrontendsServer.validate(configJson);
1371
1530
  if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
1372
1531
  const repositoryRoot = findRepositoryRoot();
1373
- const packagePath = findPackagePath({
1374
- repositoryRoot,
1375
- name: config.partOf
1376
- });
1377
- if (!packagePath) {
1378
- throw new MicrofrontendError(
1379
- `Could not find default application "${config.partOf}" in the repository`,
1380
- { type: "config", subtype: "not_found" }
1381
- );
1532
+ const isMonorepo2 = isMonorepo({ repositoryRoot });
1533
+ if (isMonorepo2) {
1534
+ const packagePath = findPackagePath({
1535
+ repositoryRoot,
1536
+ name: config.partOf
1537
+ });
1538
+ if (!packagePath) {
1539
+ throw new MicrofrontendError(
1540
+ `Could not find default application "${config.partOf}" in the repository`,
1541
+ { type: "config", subtype: "not_found" }
1542
+ );
1543
+ }
1544
+ const mainConfigPath = (0, import_node_path7.join)(packagePath, "microfrontends.json");
1545
+ return MicrofrontendsServer.fromMainConfigFile({
1546
+ filePath: mainConfigPath,
1547
+ overrides: cookies ? parseOverrides(cookies) : void 0
1548
+ });
1382
1549
  }
1383
- const mainConfigPath = (0, import_node_path4.join)(packagePath, "microfrontends.json");
1384
- return MicrofrontendsServer.fromMainConfigFile({
1385
- filePath: mainConfigPath,
1386
- overrides: cookies ? parseOverrides(cookies) : void 0
1387
- });
1388
1550
  }
1389
1551
  return new MicrofrontendsServer({
1390
1552
  config,
@@ -1405,7 +1567,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1405
1567
  overrides
1406
1568
  }) {
1407
1569
  try {
1408
- const config = import_node_fs3.default.readFileSync(filePath, "utf-8");
1570
+ const config = import_node_fs6.default.readFileSync(filePath, "utf-8");
1409
1571
  const validatedConfig = MicrofrontendsServer.validate(config);
1410
1572
  if (!isMainConfig(validatedConfig)) {
1411
1573
  throw new MicrofrontendError(
@@ -1543,24 +1705,26 @@ function getDomainFromEnvironment({
1543
1705
  app,
1544
1706
  target
1545
1707
  }) {
1546
- const projects = JSON.parse(
1547
- process.env.VERCEL_RELATED_PROJECTS ?? "[]"
1708
+ var _a, _b;
1709
+ const mfeProjects = JSON.parse(
1710
+ process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "{}"
1548
1711
  );
1549
- if (projects.length === 0) {
1550
- throw new Error("Missing related vercel project information");
1712
+ if (Object.keys(mfeProjects).length === 0) {
1713
+ throw new Error("Missing related microfrontends project information");
1551
1714
  }
1552
- const vercelProject = projects.find(
1553
- (project) => {
1554
- var _a;
1555
- return project.projectId === ((_a = app.vercel) == null ? void 0 : _a.projectId) || project.appName === app.name;
1556
- }
1557
- );
1715
+ if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
1716
+ throw new Error(`Missing applications[${app.name}].vercel.projectId`);
1717
+ }
1718
+ const vercelProject = (_b = mfeProjects.applications) == null ? void 0 : _b[app.vercel.projectId];
1558
1719
  if (!vercelProject) {
1559
1720
  throw new Error(
1560
- `Missing related vercel project information for application "${app.name}"`
1721
+ `Missing related microfrontends project information for application "${app.name}"`
1561
1722
  );
1562
1723
  }
1563
- return vercelProject.aliases[target];
1724
+ if (target === "preview" && vercelProject.deploymentAlias) {
1725
+ return vercelProject.deploymentAlias;
1726
+ }
1727
+ return vercelProject.productionHost;
1564
1728
  }
1565
1729
 
1566
1730
  // src/routing-v2/get-domain-for-current-environment.ts
@@ -1599,12 +1763,12 @@ function getDomainForCurrentEnvironment(config, appName) {
1599
1763
  const productionHost = config.getDefaultApplication().production.toString();
1600
1764
  switch (group) {
1601
1765
  case "development": {
1602
- const domain = process.env.NODE_ENV === "test" ? app.development.local.toString() : productionHost;
1766
+ const domain = ["test", "development"].includes(process.env.NODE_ENV) ? app.development.local.toString() : productionHost;
1603
1767
  debugDomains(appName, "development", domain);
1604
1768
  return domain;
1605
1769
  }
1606
1770
  case "preview": {
1607
- return getDomainFromEnvironment({ app, target: "branch" });
1771
+ return getDomainFromEnvironment({ app, target: "preview" });
1608
1772
  }
1609
1773
  case "production": {
1610
1774
  return getDomainFromEnvironment({ app, target: "production" });
@@ -1636,11 +1800,11 @@ ${table}
1636
1800
  `);
1637
1801
  }
1638
1802
  }
1639
- function pathToRewrites(path3) {
1803
+ function pathToRewrites(path5) {
1640
1804
  var _a;
1641
1805
  const regex = /(?<base>^.+)\/:.+\*$/;
1642
- const match = regex.exec(path3);
1643
- const paths = [path3];
1806
+ const match = regex.exec(path5);
1807
+ const paths = [path5];
1644
1808
  if ((_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.base) {
1645
1809
  paths.unshift(match.groups.base);
1646
1810
  }
@@ -1654,7 +1818,16 @@ function rewritesMapToArr(rewrites) {
1654
1818
  return [
1655
1819
  {
1656
1820
  source,
1657
- destination
1821
+ destination,
1822
+ missing: [
1823
+ // if this header is present, the proxy has performed the rewrite.
1824
+ // once the proxy routing is fully rolled out, this package should
1825
+ // be updated to not perform any rewrites when deployed.
1826
+ {
1827
+ type: "header",
1828
+ key: "x-vercel-mfe-host"
1829
+ }
1830
+ ]
1658
1831
  }
1659
1832
  ];
1660
1833
  });
@@ -1662,15 +1835,9 @@ function rewritesMapToArr(rewrites) {
1662
1835
  function transform4(args) {
1663
1836
  const { next, microfrontend, app } = args;
1664
1837
  const buildBeforeFiles = () => {
1665
- var _a;
1666
1838
  const rewrites = /* @__PURE__ */ new Map();
1667
1839
  if (!app.isDefault()) {
1668
- rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
1669
- destination: {
1670
- pathname: `/_next/:path+`
1671
- }
1672
- });
1673
- if (!((_a = app.vercel) == null ? void 0 : _a.routeSpeedInsightsToDefaultZone)) {
1840
+ if (process.env.VERCEL_MICROFRONTENDS_CONSOLIDATE_SPEED_INSIGHTS === "1") {
1674
1841
  rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
1675
1842
  destination: { pathname: "/_vercel/:path*" }
1676
1843
  });
@@ -1888,7 +2055,7 @@ function getApplicationContext(opts) {
1888
2055
  return { name: opts.appName };
1889
2056
  }
1890
2057
  try {
1891
- const packageJsonString = import_node_fs4.default.readFileSync("./package.json", "utf-8");
2058
+ const packageJsonString = import_node_fs7.default.readFileSync("./package.json", "utf-8");
1892
2059
  const packageJson = JSON.parse(packageJsonString);
1893
2060
  if (!packageJson.name) {
1894
2061
  throw new MicrofrontendError(
@@ -1913,8 +2080,8 @@ function withMicrofrontends(nextConfig, opts) {
1913
2080
  process.env.MFE_DEBUG = "true";
1914
2081
  }
1915
2082
  const { name: fromApp } = getApplicationContext(opts);
1916
- const microfrontends = MicrofrontendsServer.fromFile({
1917
- filePath: (opts == null ? void 0 : opts.configPath) ?? "./microfrontends.json",
2083
+ const microfrontends = MicrofrontendsServer.infer({
2084
+ filePath: opts == null ? void 0 : opts.configPath,
1918
2085
  meta: {
1919
2086
  fromApp
1920
2087
  }