@vercel/microfrontends 0.10.0 → 0.11.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 (79) hide show
  1. package/README.md +5 -5
  2. package/dist/bin/cli.cjs +346 -90
  3. package/dist/config/client.d.ts +1 -1
  4. package/dist/config/edge.d.ts +2 -2
  5. package/dist/config.cjs +1 -6
  6. package/dist/config.cjs.map +1 -1
  7. package/dist/config.d.ts +3 -3
  8. package/dist/config.js +1 -6
  9. package/dist/config.js.map +1 -1
  10. package/dist/{index-05742bef.d.ts → index-a99d5459.d.ts} +2 -2
  11. package/dist/{microfrontend-config-2425db74.d.ts → microfrontend-config-983a5139.d.ts} +1 -1
  12. package/dist/next/client.cjs +1 -1
  13. package/dist/next/client.cjs.map +1 -1
  14. package/dist/next/client.js +1 -1
  15. package/dist/next/client.js.map +1 -1
  16. package/dist/next/config.cjs +13 -11
  17. package/dist/next/config.cjs.map +1 -1
  18. package/dist/next/config.js +13 -11
  19. package/dist/next/config.js.map +1 -1
  20. package/dist/next/middleware.cjs +22 -8
  21. package/dist/next/middleware.cjs.map +1 -1
  22. package/dist/next/middleware.js +22 -8
  23. package/dist/next/middleware.js.map +1 -1
  24. package/dist/next/testing.cjs +1 -6
  25. package/dist/next/testing.cjs.map +1 -1
  26. package/dist/next/testing.d.ts +2 -2
  27. package/dist/next/testing.js +1 -6
  28. package/dist/next/testing.js.map +1 -1
  29. package/dist/overrides.d.ts +2 -2
  30. package/dist/{schema-83a75e61.d.ts → schema-2922d49e.d.ts} +1 -7
  31. package/dist/{types-4fd1c7c6.d.ts → types-0030abae.d.ts} +1 -8
  32. package/dist/{types-13f3e535.d.ts → types-c777c2f5.d.ts} +1 -1
  33. package/dist/v2/config.cjs +1 -1
  34. package/dist/v2/config.cjs.map +1 -1
  35. package/dist/v2/config.d.ts +3 -3
  36. package/dist/v2/config.js +1 -1
  37. package/dist/v2/config.js.map +1 -1
  38. package/dist/v2/microfrontends/server.cjs +296 -36
  39. package/dist/v2/microfrontends/server.cjs.map +1 -1
  40. package/dist/v2/microfrontends/server.d.ts +26 -4
  41. package/dist/v2/microfrontends/server.js +296 -36
  42. package/dist/v2/microfrontends/server.js.map +1 -1
  43. package/dist/v2/microfrontends.cjs +1 -1
  44. package/dist/v2/microfrontends.cjs.map +1 -1
  45. package/dist/v2/microfrontends.d.ts +3 -3
  46. package/dist/v2/microfrontends.js +1 -1
  47. package/dist/v2/microfrontends.js.map +1 -1
  48. package/dist/v2/next/client.cjs +1 -1
  49. package/dist/v2/next/client.cjs.map +1 -1
  50. package/dist/v2/next/client.js +1 -1
  51. package/dist/v2/next/client.js.map +1 -1
  52. package/dist/v2/next/config.cjs +331 -68
  53. package/dist/v2/next/config.cjs.map +1 -1
  54. package/dist/v2/next/config.js +331 -68
  55. package/dist/v2/next/config.js.map +1 -1
  56. package/dist/v2/next/endpoints.cjs +5 -2
  57. package/dist/v2/next/endpoints.cjs.map +1 -1
  58. package/dist/v2/next/endpoints.d.ts +1 -1
  59. package/dist/v2/next/endpoints.js +5 -2
  60. package/dist/v2/next/endpoints.js.map +1 -1
  61. package/dist/v2/next/middleware.cjs +108 -88
  62. package/dist/v2/next/middleware.cjs.map +1 -1
  63. package/dist/v2/next/middleware.js +108 -88
  64. package/dist/v2/next/middleware.js.map +1 -1
  65. package/dist/v2/overrides.cjs +1 -1
  66. package/dist/v2/overrides.cjs.map +1 -1
  67. package/dist/v2/overrides.d.ts +3 -3
  68. package/dist/v2/overrides.js +1 -1
  69. package/dist/v2/overrides.js.map +1 -1
  70. package/dist/v2/schema.cjs.map +1 -1
  71. package/dist/v2/schema.d.ts +1 -1
  72. package/dist/validation.cjs +0 -11
  73. package/dist/validation.cjs.map +1 -1
  74. package/dist/validation.d.ts +2 -9
  75. package/dist/validation.js +0 -11
  76. package/dist/validation.js.map +1 -1
  77. package/package.json +8 -7
  78. package/schema/schema-v2.json +0 -7
  79. package/schema/schema.json +0 -4
@@ -1,12 +1,12 @@
1
1
  // src/next-v2/config/index.ts
2
- import fs2 from "node:fs";
2
+ import fs5 from "node:fs";
3
3
 
4
4
  // src/config-v2/microfrontends/server/index.ts
5
- import fs from "node:fs";
6
- import { dirname } from "node:path";
5
+ import fs4 from "node:fs";
6
+ import { dirname as dirname3, join } from "node:path";
7
7
 
8
8
  // src/config-v2/overrides/constants.ts
9
- var OVERRIDES_COOKIE_PREFIX = "vercel-microfrontends-override";
9
+ var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
10
10
  var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
11
11
 
12
12
  // src/config-v2/overrides/is-override-cookie.ts
@@ -187,21 +187,21 @@ var MicrofrontendConfigClient = class {
187
187
  isEqual(other) {
188
188
  return JSON.stringify(this.applications) === JSON.stringify(other.applications);
189
189
  }
190
- getApplicationNameForPath(path2) {
191
- if (!path2.startsWith("/")) {
190
+ getApplicationNameForPath(path5) {
191
+ if (!path5.startsWith("/")) {
192
192
  throw new Error(`Path must start with a /`);
193
193
  }
194
- if (this.pathCache[path2]) {
195
- return this.pathCache[path2];
194
+ if (this.pathCache[path5]) {
195
+ return this.pathCache[path5];
196
196
  }
197
- const pathname = new URL(path2, "https://example.com").pathname;
197
+ const pathname = new URL(path5, "https://example.com").pathname;
198
198
  for (const [name, application] of Object.entries(this.applications)) {
199
199
  if (application.routing) {
200
200
  for (const group of application.routing) {
201
201
  for (const childPath of group.paths) {
202
202
  const regexp = pathToRegexp(childPath);
203
203
  if (regexp.test(pathname)) {
204
- this.pathCache[path2] = name;
204
+ this.pathCache[path5] = name;
205
205
  return name;
206
206
  }
207
207
  }
@@ -214,7 +214,7 @@ var MicrofrontendConfigClient = class {
214
214
  if (!defaultApplication) {
215
215
  return null;
216
216
  }
217
- this.pathCache[path2] = defaultApplication[0];
217
+ this.pathCache[path5] = defaultApplication[0];
218
218
  return defaultApplication[0];
219
219
  }
220
220
  serialize() {
@@ -246,22 +246,22 @@ var validateConfigPaths = (applicationConfigsById) => {
246
246
  continue;
247
247
  }
248
248
  for (const pathMatch of app.routing) {
249
- for (const path2 of pathMatch.paths) {
250
- const tokens = parsePathRegexp(path2);
249
+ for (const path5 of pathMatch.paths) {
250
+ const tokens = parsePathRegexp(path5);
251
251
  for (const token of tokens.slice(0, -1)) {
252
252
  if (typeof token !== "string") {
253
253
  errors.push(
254
- `Path ${path2} may only have a :wildcard in the last path component`
254
+ `Path ${path5} may only have a :wildcard in the last path component`
255
255
  );
256
256
  }
257
257
  }
258
- const existing = pathsByApplicationId.get(path2);
258
+ const existing = pathsByApplicationId.get(path5);
259
259
  if (existing) {
260
260
  existing.applications.push(id);
261
261
  } else {
262
- pathsByApplicationId.set(path2, {
262
+ pathsByApplicationId.set(path5, {
263
263
  applications: [id],
264
- matcher: pathToRegexp2(path2),
264
+ matcher: pathToRegexp2(path5),
265
265
  applicationId: id
266
266
  });
267
267
  }
@@ -269,10 +269,10 @@ var validateConfigPaths = (applicationConfigsById) => {
269
269
  }
270
270
  }
271
271
  const entries = Array.from(pathsByApplicationId.entries());
272
- entries.forEach(([path2, { applications: ids, matcher, applicationId }]) => {
272
+ entries.forEach(([path5, { applications: ids, matcher, applicationId }]) => {
273
273
  if (ids.length > 1) {
274
274
  errors.push(
275
- `Duplicate path "${path2}" for applications "${ids.join(", ")}"`
275
+ `Duplicate path "${path5}" for applications "${ids.join(", ")}"`
276
276
  );
277
277
  }
278
278
  entries.forEach(
@@ -280,14 +280,14 @@ var validateConfigPaths = (applicationConfigsById) => {
280
280
  matchPath,
281
281
  { applications: matchIds, applicationId: matchApplicationId }
282
282
  ]) => {
283
- if (path2 === matchPath) {
283
+ if (path5 === matchPath) {
284
284
  return;
285
285
  }
286
286
  if (applicationId === matchApplicationId) {
287
287
  return;
288
288
  }
289
289
  if (matcher.test(matchPath)) {
290
- const source = `"${path2}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
290
+ const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
291
291
  const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
292
292
  errors.push(
293
293
  `Overlapping path detected between ${source} and ${destination}`
@@ -778,8 +778,189 @@ var Microfrontends = class {
778
778
  }
779
779
  };
780
780
 
781
- // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
781
+ // src/config-v2/microfrontends/utils/find-repository-root.ts
782
+ import fs from "node:fs";
782
783
  import path from "node:path";
784
+ var GIT_DIRECTORY = ".git";
785
+ function findRepositoryRoot(startDir) {
786
+ let currentDir = startDir || process.cwd();
787
+ while (currentDir !== path.parse(currentDir).root) {
788
+ const gitPath = path.join(currentDir, GIT_DIRECTORY);
789
+ if (fs.existsSync(gitPath) && fs.statSync(gitPath).isDirectory()) {
790
+ return currentDir;
791
+ }
792
+ currentDir = path.dirname(currentDir);
793
+ }
794
+ throw new Error(
795
+ "Repository root not found. Specify the root of the repository with the `repository.root` option."
796
+ );
797
+ }
798
+
799
+ // src/config-v2/microfrontends/utils/find-package-path.ts
800
+ import { dirname } from "node:path";
801
+ import { readFileSync } from "node:fs";
802
+ import fg from "fast-glob";
803
+ var configCache = {};
804
+ function findPackagePathWithGlob({
805
+ repositoryRoot,
806
+ name
807
+ }) {
808
+ try {
809
+ const packageJsonPaths = fg.globSync("**/package.json", {
810
+ cwd: repositoryRoot,
811
+ absolute: true,
812
+ onlyFiles: true,
813
+ followSymbolicLinks: false,
814
+ ignore: ["**/node_modules/**", "**/.git/**"]
815
+ });
816
+ const matchingPaths = [];
817
+ for (const packageJsonPath2 of packageJsonPaths) {
818
+ const packageJsonContent = readFileSync(packageJsonPath2, "utf-8");
819
+ const packageJson = JSON.parse(packageJsonContent);
820
+ if (packageJson.name === name) {
821
+ matchingPaths.push(packageJsonPath2);
822
+ }
823
+ }
824
+ if (matchingPaths.length > 1) {
825
+ throw new Error(
826
+ `Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
827
+ );
828
+ }
829
+ if (matchingPaths.length === 0) {
830
+ throw new Error(
831
+ `Could not find package with the name "${name}" in the repository`
832
+ );
833
+ }
834
+ const [packageJsonPath] = matchingPaths;
835
+ return dirname(packageJsonPath);
836
+ } catch (error) {
837
+ return null;
838
+ }
839
+ }
840
+ function findPackagePath(opts) {
841
+ const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
842
+ if (configCache[cacheKey]) {
843
+ return configCache[cacheKey];
844
+ }
845
+ const result = findPackagePathWithGlob(opts);
846
+ if (!result) {
847
+ throw new Error(
848
+ `Could not find package with the name "${opts.name}" in the repository`
849
+ );
850
+ }
851
+ configCache[cacheKey] = result;
852
+ return result;
853
+ }
854
+
855
+ // src/config-v2/microfrontends/utils/find-default-package.ts
856
+ import { dirname as dirname2 } from "node:path";
857
+ import { readFileSync as readFileSync2 } from "node:fs";
858
+ import fg2 from "fast-glob";
859
+ var configCache2 = {};
860
+ function findDefaultMicrofrontendsPackages({
861
+ repositoryRoot,
862
+ applicationName
863
+ }) {
864
+ try {
865
+ const microfrontendsJsonPaths = fg2.globSync("**/microfrontends.json", {
866
+ cwd: repositoryRoot,
867
+ absolute: true,
868
+ onlyFiles: true,
869
+ followSymbolicLinks: false,
870
+ ignore: ["**/node_modules/**", "**/.git/**"]
871
+ });
872
+ const matchingPaths = [];
873
+ for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
874
+ const microfrontendsJsonContent = readFileSync2(
875
+ microfrontendsJsonPath,
876
+ "utf-8"
877
+ );
878
+ const microfrontendsJson = JSON.parse(
879
+ microfrontendsJsonContent
880
+ );
881
+ if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
882
+ matchingPaths.push(microfrontendsJsonPath);
883
+ }
884
+ }
885
+ if (matchingPaths.length > 1) {
886
+ throw new Error(
887
+ `Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
888
+ ${matchingPaths.join("\n \u2022 ")}`
889
+ );
890
+ }
891
+ if (matchingPaths.length === 0) {
892
+ throw new Error(
893
+ `Could not find default application with "applications.${applicationName}"`
894
+ );
895
+ }
896
+ const [packageJsonPath] = matchingPaths;
897
+ return dirname2(packageJsonPath);
898
+ } catch (error) {
899
+ return null;
900
+ }
901
+ }
902
+ function findDefaultMicrofrontendsPackage(opts) {
903
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
904
+ if (configCache2[cacheKey]) {
905
+ return configCache2[cacheKey];
906
+ }
907
+ const result = findDefaultMicrofrontendsPackages(opts);
908
+ if (!result) {
909
+ throw new Error(
910
+ `Error trying to resolve the main microfrontends.json configuration`
911
+ );
912
+ }
913
+ configCache2[cacheKey] = result;
914
+ return result;
915
+ }
916
+
917
+ // src/config-v2/microfrontends/utils/is-monorepo.ts
918
+ import fs2 from "node:fs";
919
+ import path2 from "node:path";
920
+ function isMonorepo({
921
+ repositoryRoot
922
+ }) {
923
+ try {
924
+ if (fs2.existsSync(path2.join(repositoryRoot, "pnpm-workspace.yaml"))) {
925
+ return true;
926
+ }
927
+ if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
928
+ return true;
929
+ }
930
+ const packageJsonPath = path2.join(repositoryRoot, "package.json");
931
+ if (!fs2.existsSync(packageJsonPath)) {
932
+ return false;
933
+ }
934
+ const packageJson = JSON.parse(
935
+ fs2.readFileSync(packageJsonPath, "utf-8")
936
+ );
937
+ return packageJson.workspaces !== void 0;
938
+ } catch (error) {
939
+ console.error("Error determining if repository is a monorepo", error);
940
+ return false;
941
+ }
942
+ }
943
+
944
+ // src/config-v2/microfrontends/utils/find-package-root.ts
945
+ import fs3 from "node:fs";
946
+ import path3 from "node:path";
947
+ var PACKAGE_JSON = "package.json";
948
+ function findPackageRoot(startDir) {
949
+ let currentDir = startDir || process.cwd();
950
+ while (currentDir !== path3.parse(currentDir).root) {
951
+ const pkgJsonPath = path3.join(currentDir, PACKAGE_JSON);
952
+ if (fs3.existsSync(pkgJsonPath)) {
953
+ return currentDir;
954
+ }
955
+ currentDir = path3.dirname(currentDir);
956
+ }
957
+ throw new Error(
958
+ "Package root not found. Specify the root of the package with the `package.root` option."
959
+ );
960
+ }
961
+
962
+ // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
963
+ import path4 from "node:path";
783
964
 
784
965
  // src/config-v2/microfrontends/server/constants.ts
785
966
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -793,13 +974,13 @@ function isVercel() {
793
974
  // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
794
975
  function getOutputFilePath() {
795
976
  if (isVercel()) {
796
- return path.join(
977
+ return path4.join(
797
978
  ".vercel",
798
979
  MFE_CONFIG_DEFAULT_FILE_PATH,
799
980
  MFE_CONFIG_DEFAULT_FILE_NAME
800
981
  );
801
982
  }
802
- return path.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
983
+ return path4.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
803
984
  }
804
985
 
805
986
  // src/config-v2/microfrontends/server/validation.ts
@@ -1013,9 +1194,6 @@ var schema_v2_default = {
1013
1194
  projectId: {
1014
1195
  type: "string",
1015
1196
  description: "Vercel project ID"
1016
- },
1017
- routeSpeedInsightsToDefaultZone: {
1018
- type: "boolean"
1019
1197
  }
1020
1198
  },
1021
1199
  required: ["projectId"]
@@ -1109,10 +1287,6 @@ var schema_v2_default = {
1109
1287
  type: "string",
1110
1288
  description: "flag name that can be used to enable/disable all paths in the group"
1111
1289
  },
1112
- routeToDefaultApplication: {
1113
- type: "boolean",
1114
- description: "True to route the request to the default application for this micro-frontends set-up. This must be `true` when using `flag` or when you want to use custom logic to make the routing decision for this group of paths."
1115
- },
1116
1290
  paths: {
1117
1291
  type: "array",
1118
1292
  items: {
@@ -1189,8 +1363,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1189
1363
  pretty: true
1190
1364
  }) {
1191
1365
  const outputPath = getOutputFilePath();
1192
- fs.mkdirSync(dirname(outputPath), { recursive: true });
1193
- fs.writeFileSync(
1366
+ fs4.mkdirSync(dirname3(outputPath), { recursive: true });
1367
+ fs4.writeFileSync(
1194
1368
  outputPath,
1195
1369
  JSON.stringify(
1196
1370
  this.config.toSchemaJson(),
@@ -1252,18 +1426,104 @@ var MicrofrontendsServer = class extends Microfrontends {
1252
1426
  }
1253
1427
  return config;
1254
1428
  }
1429
+ /**
1430
+ * Looks up the configuration by inferring the package root and looking for a microfrontends.json file. If a file is not found,
1431
+ * it will look for a package in the repository with a microfrontends.json file that contains the current application
1432
+ * and use that configuration.
1433
+ *
1434
+ * This can return either a Child or Main configuration.
1435
+ */
1436
+ static infer({
1437
+ directory,
1438
+ filePath,
1439
+ meta,
1440
+ cookies,
1441
+ options
1442
+ } = {}) {
1443
+ if (filePath && meta) {
1444
+ return MicrofrontendsServer.fromFile({
1445
+ filePath,
1446
+ cookies,
1447
+ meta,
1448
+ options
1449
+ });
1450
+ }
1451
+ try {
1452
+ const packageRoot = findPackageRoot(directory);
1453
+ const packageJsonPath = join(packageRoot, "package.json");
1454
+ const packageJson = JSON.parse(
1455
+ fs4.readFileSync(packageJsonPath, "utf-8")
1456
+ );
1457
+ if (!packageJson.name) {
1458
+ throw new Error(`No name found in package.json at ${packageJsonPath}`);
1459
+ }
1460
+ const configMeta = meta ?? { fromApp: packageJson.name };
1461
+ const maybeConfig = join(packageRoot, "microfrontends.json");
1462
+ if (fs4.existsSync(maybeConfig)) {
1463
+ return MicrofrontendsServer.fromFile({
1464
+ filePath: maybeConfig,
1465
+ cookies,
1466
+ meta: configMeta,
1467
+ options
1468
+ });
1469
+ }
1470
+ const repositoryRoot = findRepositoryRoot();
1471
+ const isMonorepo2 = isMonorepo({ repositoryRoot });
1472
+ if (isMonorepo2) {
1473
+ const defaultPackage = findDefaultMicrofrontendsPackage({
1474
+ repositoryRoot,
1475
+ applicationName: packageJson.name
1476
+ });
1477
+ return MicrofrontendsServer.fromFile({
1478
+ filePath: join(defaultPackage, "microfrontends.json"),
1479
+ cookies,
1480
+ meta: configMeta,
1481
+ options
1482
+ });
1483
+ }
1484
+ throw new Error("Unable to infer");
1485
+ } catch (e) {
1486
+ throw new MicrofrontendError(
1487
+ "Unable to infer microfrontends configuration",
1488
+ { type: "config", subtype: "inference_failed" }
1489
+ );
1490
+ }
1491
+ }
1255
1492
  /*
1256
1493
  * Generates a MicrofrontendsServer instance from a file.
1257
1494
  */
1258
1495
  static fromFile({
1259
1496
  filePath,
1260
1497
  cookies,
1261
- meta
1498
+ meta,
1499
+ options
1262
1500
  }) {
1263
1501
  try {
1264
- const config = fs.readFileSync(filePath, "utf-8");
1502
+ const configJson = fs4.readFileSync(filePath, "utf-8");
1503
+ const config = MicrofrontendsServer.validate(configJson);
1504
+ if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
1505
+ const repositoryRoot = findRepositoryRoot();
1506
+ const isMonorepo2 = isMonorepo({ repositoryRoot });
1507
+ if (isMonorepo2) {
1508
+ const packagePath = findPackagePath({
1509
+ repositoryRoot,
1510
+ name: config.partOf
1511
+ });
1512
+ if (!packagePath) {
1513
+ throw new MicrofrontendError(
1514
+ `Could not find default application "${config.partOf}" in the repository`,
1515
+ { type: "config", subtype: "not_found" }
1516
+ );
1517
+ }
1518
+ const mainConfigPath = join(packagePath, "microfrontends.json");
1519
+ return MicrofrontendsServer.fromMainConfigFile({
1520
+ filePath: mainConfigPath,
1521
+ overrides: cookies ? parseOverrides(cookies) : void 0
1522
+ });
1523
+ }
1524
+ }
1265
1525
  return new MicrofrontendsServer({
1266
- config: MicrofrontendsServer.validate(config),
1526
+ config,
1267
1527
  overrides: cookies ? parseOverrides(cookies) : void 0,
1268
1528
  meta
1269
1529
  });
@@ -1281,7 +1541,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1281
1541
  overrides
1282
1542
  }) {
1283
1543
  try {
1284
- const config = fs.readFileSync(filePath, "utf-8");
1544
+ const config = fs4.readFileSync(filePath, "utf-8");
1285
1545
  const validatedConfig = MicrofrontendsServer.validate(config);
1286
1546
  if (!isMainConfig(validatedConfig)) {
1287
1547
  throw new MicrofrontendError(
@@ -1419,24 +1679,26 @@ function getDomainFromEnvironment({
1419
1679
  app,
1420
1680
  target
1421
1681
  }) {
1422
- const projects = JSON.parse(
1423
- process.env.VERCEL_RELATED_PROJECTS ?? "[]"
1682
+ var _a, _b;
1683
+ const mfeProjects = JSON.parse(
1684
+ process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "{}"
1424
1685
  );
1425
- if (projects.length === 0) {
1426
- throw new Error("Missing related vercel project information");
1686
+ if (Object.keys(mfeProjects).length === 0) {
1687
+ throw new Error("Missing related microfrontends project information");
1427
1688
  }
1428
- const vercelProject = projects.find(
1429
- (project) => {
1430
- var _a;
1431
- return project.projectId === ((_a = app.vercel) == null ? void 0 : _a.projectId) || project.appName === app.name;
1432
- }
1433
- );
1689
+ if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
1690
+ throw new Error(`Missing applications[${app.name}].vercel.projectId`);
1691
+ }
1692
+ const vercelProject = (_b = mfeProjects.applications) == null ? void 0 : _b[app.vercel.projectId];
1434
1693
  if (!vercelProject) {
1435
1694
  throw new Error(
1436
- `Missing related vercel project information for application "${app.name}"`
1695
+ `Missing related microfrontends project information for application "${app.name}"`
1437
1696
  );
1438
1697
  }
1439
- return vercelProject.aliases[target];
1698
+ if (target === "preview" && vercelProject.deploymentAlias) {
1699
+ return vercelProject.deploymentAlias;
1700
+ }
1701
+ return vercelProject.productionHost;
1440
1702
  }
1441
1703
 
1442
1704
  // src/routing-v2/get-domain-for-current-environment.ts
@@ -1475,12 +1737,12 @@ function getDomainForCurrentEnvironment(config, appName) {
1475
1737
  const productionHost = config.getDefaultApplication().production.toString();
1476
1738
  switch (group) {
1477
1739
  case "development": {
1478
- const domain = process.env.NODE_ENV === "test" ? app.development.local.toString() : productionHost;
1740
+ const domain = ["test", "development"].includes(process.env.NODE_ENV) ? app.development.local.toString() : productionHost;
1479
1741
  debugDomains(appName, "development", domain);
1480
1742
  return domain;
1481
1743
  }
1482
1744
  case "preview": {
1483
- return getDomainFromEnvironment({ app, target: "branch" });
1745
+ return getDomainFromEnvironment({ app, target: "preview" });
1484
1746
  }
1485
1747
  case "production": {
1486
1748
  return getDomainFromEnvironment({ app, target: "production" });
@@ -1512,11 +1774,11 @@ ${table}
1512
1774
  `);
1513
1775
  }
1514
1776
  }
1515
- function pathToRewrites(path2) {
1777
+ function pathToRewrites(path5) {
1516
1778
  var _a;
1517
1779
  const regex = /(?<base>^.+)\/:.+\*$/;
1518
- const match = regex.exec(path2);
1519
- const paths = [path2];
1780
+ const match = regex.exec(path5);
1781
+ const paths = [path5];
1520
1782
  if ((_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.base) {
1521
1783
  paths.unshift(match.groups.base);
1522
1784
  }
@@ -1530,7 +1792,16 @@ function rewritesMapToArr(rewrites) {
1530
1792
  return [
1531
1793
  {
1532
1794
  source,
1533
- destination
1795
+ destination,
1796
+ missing: [
1797
+ // if this header is present, the proxy has performed the rewrite.
1798
+ // once the proxy routing is fully rolled out, this package should
1799
+ // be updated to not perform any rewrites when deployed.
1800
+ {
1801
+ type: "header",
1802
+ key: "x-vercel-mfe-host"
1803
+ }
1804
+ ]
1534
1805
  }
1535
1806
  ];
1536
1807
  });
@@ -1538,15 +1809,9 @@ function rewritesMapToArr(rewrites) {
1538
1809
  function transform4(args) {
1539
1810
  const { next, microfrontend, app } = args;
1540
1811
  const buildBeforeFiles = () => {
1541
- var _a;
1542
1812
  const rewrites = /* @__PURE__ */ new Map();
1543
1813
  if (!app.isDefault()) {
1544
- rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
1545
- destination: {
1546
- pathname: `/_next/:path+`
1547
- }
1548
- });
1549
- if (!((_a = app.vercel) == null ? void 0 : _a.routeSpeedInsightsToDefaultZone)) {
1814
+ if (process.env.VERCEL_MICROFRONTENDS_CONSOLIDATE_SPEED_INSIGHTS === "1") {
1550
1815
  rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
1551
1816
  destination: { pathname: "/_vercel/:path*" }
1552
1817
  });
@@ -1564,9 +1829,7 @@ function transform4(args) {
1564
1829
  }
1565
1830
  });
1566
1831
  for (const group of routing) {
1567
- if (group.routeToDefaultApplication) {
1568
- continue;
1569
- } else if (group.flag) {
1832
+ if (group.flag) {
1570
1833
  continue;
1571
1834
  } else {
1572
1835
  for (const source of group.paths) {
@@ -1766,7 +2029,7 @@ function getApplicationContext(opts) {
1766
2029
  return { name: opts.appName };
1767
2030
  }
1768
2031
  try {
1769
- const packageJsonString = fs2.readFileSync("./package.json", "utf-8");
2032
+ const packageJsonString = fs5.readFileSync("./package.json", "utf-8");
1770
2033
  const packageJson = JSON.parse(packageJsonString);
1771
2034
  if (!packageJson.name) {
1772
2035
  throw new MicrofrontendError(
@@ -1791,8 +2054,8 @@ function withMicrofrontends(nextConfig, opts) {
1791
2054
  process.env.MFE_DEBUG = "true";
1792
2055
  }
1793
2056
  const { name: fromApp } = getApplicationContext(opts);
1794
- const microfrontends = MicrofrontendsServer.fromFile({
1795
- filePath: (opts == null ? void 0 : opts.configPath) ?? "./microfrontends.json",
2057
+ const microfrontends = MicrofrontendsServer.infer({
2058
+ filePath: opts == null ? void 0 : opts.configPath,
1796
2059
  meta: {
1797
2060
  fromApp
1798
2061
  }