@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
@@ -33,14 +33,14 @@ __export(config_exports, {
33
33
  withMicrofrontends: () => withMicrofrontends
34
34
  });
35
35
  module.exports = __toCommonJS(config_exports);
36
- var import_node_fs2 = __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_fs = __toESM(require("fs"), 1);
40
- var import_node_path2 = 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(path2) {
225
- if (!path2.startsWith("/")) {
224
+ getApplicationNameForPath(path5) {
225
+ if (!path5.startsWith("/")) {
226
226
  throw new Error(`Path must start with a /`);
227
227
  }
228
- if (this.pathCache[path2]) {
229
- return this.pathCache[path2];
228
+ if (this.pathCache[path5]) {
229
+ return this.pathCache[path5];
230
230
  }
231
- const pathname = new URL(path2, "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[path2] = 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[path2] = 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 path2 of pathMatch.paths) {
284
- const tokens = (0, import_path_to_regexp2.parse)(path2);
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 ${path2} 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(path2);
292
+ const existing = pathsByApplicationId.get(path5);
293
293
  if (existing) {
294
294
  existing.applications.push(id);
295
295
  } else {
296
- pathsByApplicationId.set(path2, {
296
+ pathsByApplicationId.set(path5, {
297
297
  applications: [id],
298
- matcher: (0, import_path_to_regexp2.pathToRegexp)(path2),
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(([path2, { 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 "${path2}" 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 (path2 === 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 = `"${path2}" 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}`
@@ -812,8 +812,189 @@ var Microfrontends = class {
812
812
  }
813
813
  };
814
814
 
815
- // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
815
+ // src/config-v2/microfrontends/utils/find-repository-root.ts
816
+ var import_node_fs = __toESM(require("fs"), 1);
816
817
  var import_node_path = __toESM(require("path"), 1);
818
+ var GIT_DIRECTORY = ".git";
819
+ function findRepositoryRoot(startDir) {
820
+ let currentDir = startDir || process.cwd();
821
+ while (currentDir !== import_node_path.default.parse(currentDir).root) {
822
+ const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
823
+ if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
824
+ return currentDir;
825
+ }
826
+ currentDir = import_node_path.default.dirname(currentDir);
827
+ }
828
+ throw new Error(
829
+ "Repository root not found. Specify the root of the repository with the `repository.root` option."
830
+ );
831
+ }
832
+
833
+ // src/config-v2/microfrontends/utils/find-package-path.ts
834
+ var import_node_path2 = require("path");
835
+ var import_node_fs2 = require("fs");
836
+ var import_fast_glob = __toESM(require("fast-glob"), 1);
837
+ var configCache = {};
838
+ function findPackagePathWithGlob({
839
+ repositoryRoot,
840
+ name
841
+ }) {
842
+ try {
843
+ const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
844
+ cwd: repositoryRoot,
845
+ absolute: true,
846
+ onlyFiles: true,
847
+ followSymbolicLinks: false,
848
+ ignore: ["**/node_modules/**", "**/.git/**"]
849
+ });
850
+ const matchingPaths = [];
851
+ for (const packageJsonPath2 of packageJsonPaths) {
852
+ const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
853
+ const packageJson = JSON.parse(packageJsonContent);
854
+ if (packageJson.name === name) {
855
+ matchingPaths.push(packageJsonPath2);
856
+ }
857
+ }
858
+ if (matchingPaths.length > 1) {
859
+ throw new Error(
860
+ `Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
861
+ );
862
+ }
863
+ if (matchingPaths.length === 0) {
864
+ throw new Error(
865
+ `Could not find package with the name "${name}" in the repository`
866
+ );
867
+ }
868
+ const [packageJsonPath] = matchingPaths;
869
+ return (0, import_node_path2.dirname)(packageJsonPath);
870
+ } catch (error) {
871
+ return null;
872
+ }
873
+ }
874
+ function findPackagePath(opts) {
875
+ const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
876
+ if (configCache[cacheKey]) {
877
+ return configCache[cacheKey];
878
+ }
879
+ const result = findPackagePathWithGlob(opts);
880
+ if (!result) {
881
+ throw new Error(
882
+ `Could not find package with the name "${opts.name}" in the repository`
883
+ );
884
+ }
885
+ configCache[cacheKey] = result;
886
+ return result;
887
+ }
888
+
889
+ // src/config-v2/microfrontends/utils/find-default-package.ts
890
+ var import_node_path3 = require("path");
891
+ var import_node_fs3 = require("fs");
892
+ var import_fast_glob2 = __toESM(require("fast-glob"), 1);
893
+ var configCache2 = {};
894
+ function findDefaultMicrofrontendsPackages({
895
+ repositoryRoot,
896
+ applicationName
897
+ }) {
898
+ try {
899
+ const microfrontendsJsonPaths = import_fast_glob2.default.globSync("**/microfrontends.json", {
900
+ cwd: repositoryRoot,
901
+ absolute: true,
902
+ onlyFiles: true,
903
+ followSymbolicLinks: false,
904
+ ignore: ["**/node_modules/**", "**/.git/**"]
905
+ });
906
+ const matchingPaths = [];
907
+ for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
908
+ const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
909
+ microfrontendsJsonPath,
910
+ "utf-8"
911
+ );
912
+ const microfrontendsJson = JSON.parse(
913
+ microfrontendsJsonContent
914
+ );
915
+ if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
916
+ matchingPaths.push(microfrontendsJsonPath);
917
+ }
918
+ }
919
+ if (matchingPaths.length > 1) {
920
+ throw new Error(
921
+ `Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
922
+ ${matchingPaths.join("\n \u2022 ")}`
923
+ );
924
+ }
925
+ if (matchingPaths.length === 0) {
926
+ throw new Error(
927
+ `Could not find default application with "applications.${applicationName}"`
928
+ );
929
+ }
930
+ const [packageJsonPath] = matchingPaths;
931
+ return (0, import_node_path3.dirname)(packageJsonPath);
932
+ } catch (error) {
933
+ return null;
934
+ }
935
+ }
936
+ function findDefaultMicrofrontendsPackage(opts) {
937
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
938
+ if (configCache2[cacheKey]) {
939
+ return configCache2[cacheKey];
940
+ }
941
+ const result = findDefaultMicrofrontendsPackages(opts);
942
+ if (!result) {
943
+ throw new Error(
944
+ `Error trying to resolve the main microfrontends.json configuration`
945
+ );
946
+ }
947
+ configCache2[cacheKey] = result;
948
+ return result;
949
+ }
950
+
951
+ // src/config-v2/microfrontends/utils/is-monorepo.ts
952
+ var import_node_fs4 = __toESM(require("fs"), 1);
953
+ var import_node_path4 = __toESM(require("path"), 1);
954
+ function isMonorepo({
955
+ repositoryRoot
956
+ }) {
957
+ try {
958
+ if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
959
+ return true;
960
+ }
961
+ if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
962
+ return true;
963
+ }
964
+ const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
965
+ if (!import_node_fs4.default.existsSync(packageJsonPath)) {
966
+ return false;
967
+ }
968
+ const packageJson = JSON.parse(
969
+ import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
970
+ );
971
+ return packageJson.workspaces !== void 0;
972
+ } catch (error) {
973
+ console.error("Error determining if repository is a monorepo", error);
974
+ return false;
975
+ }
976
+ }
977
+
978
+ // src/config-v2/microfrontends/utils/find-package-root.ts
979
+ var import_node_fs5 = __toESM(require("fs"), 1);
980
+ var import_node_path5 = __toESM(require("path"), 1);
981
+ var PACKAGE_JSON = "package.json";
982
+ function findPackageRoot(startDir) {
983
+ let currentDir = startDir || process.cwd();
984
+ while (currentDir !== import_node_path5.default.parse(currentDir).root) {
985
+ const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
986
+ if (import_node_fs5.default.existsSync(pkgJsonPath)) {
987
+ return currentDir;
988
+ }
989
+ currentDir = import_node_path5.default.dirname(currentDir);
990
+ }
991
+ throw new Error(
992
+ "Package root not found. Specify the root of the package with the `package.root` option."
993
+ );
994
+ }
995
+
996
+ // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
997
+ var import_node_path6 = __toESM(require("path"), 1);
817
998
 
818
999
  // src/config-v2/microfrontends/server/constants.ts
819
1000
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -827,13 +1008,13 @@ function isVercel() {
827
1008
  // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
828
1009
  function getOutputFilePath() {
829
1010
  if (isVercel()) {
830
- return import_node_path.default.join(
1011
+ return import_node_path6.default.join(
831
1012
  ".vercel",
832
1013
  MFE_CONFIG_DEFAULT_FILE_PATH,
833
1014
  MFE_CONFIG_DEFAULT_FILE_NAME
834
1015
  );
835
1016
  }
836
- return import_node_path.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1017
+ return import_node_path6.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
837
1018
  }
838
1019
 
839
1020
  // src/config-v2/microfrontends/server/validation.ts
@@ -1047,9 +1228,6 @@ var schema_v2_default = {
1047
1228
  projectId: {
1048
1229
  type: "string",
1049
1230
  description: "Vercel project ID"
1050
- },
1051
- routeSpeedInsightsToDefaultZone: {
1052
- type: "boolean"
1053
1231
  }
1054
1232
  },
1055
1233
  required: ["projectId"]
@@ -1143,10 +1321,6 @@ var schema_v2_default = {
1143
1321
  type: "string",
1144
1322
  description: "flag name that can be used to enable/disable all paths in the group"
1145
1323
  },
1146
- routeToDefaultApplication: {
1147
- type: "boolean",
1148
- 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."
1149
- },
1150
1324
  paths: {
1151
1325
  type: "array",
1152
1326
  items: {
@@ -1223,8 +1397,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1223
1397
  pretty: true
1224
1398
  }) {
1225
1399
  const outputPath = getOutputFilePath();
1226
- import_node_fs.default.mkdirSync((0, import_node_path2.dirname)(outputPath), { recursive: true });
1227
- import_node_fs.default.writeFileSync(
1400
+ import_node_fs6.default.mkdirSync((0, import_node_path7.dirname)(outputPath), { recursive: true });
1401
+ import_node_fs6.default.writeFileSync(
1228
1402
  outputPath,
1229
1403
  JSON.stringify(
1230
1404
  this.config.toSchemaJson(),
@@ -1286,18 +1460,104 @@ var MicrofrontendsServer = class extends Microfrontends {
1286
1460
  }
1287
1461
  return config;
1288
1462
  }
1463
+ /**
1464
+ * Looks up the configuration by inferring the package root and looking for a microfrontends.json file. If a file is not found,
1465
+ * it will look for a package in the repository with a microfrontends.json file that contains the current application
1466
+ * and use that configuration.
1467
+ *
1468
+ * This can return either a Child or Main configuration.
1469
+ */
1470
+ static infer({
1471
+ directory,
1472
+ filePath,
1473
+ meta,
1474
+ cookies,
1475
+ options
1476
+ } = {}) {
1477
+ if (filePath && meta) {
1478
+ return MicrofrontendsServer.fromFile({
1479
+ filePath,
1480
+ cookies,
1481
+ meta,
1482
+ options
1483
+ });
1484
+ }
1485
+ try {
1486
+ const packageRoot = findPackageRoot(directory);
1487
+ const packageJsonPath = (0, import_node_path7.join)(packageRoot, "package.json");
1488
+ const packageJson = JSON.parse(
1489
+ import_node_fs6.default.readFileSync(packageJsonPath, "utf-8")
1490
+ );
1491
+ if (!packageJson.name) {
1492
+ throw new Error(`No name found in package.json at ${packageJsonPath}`);
1493
+ }
1494
+ const configMeta = meta ?? { fromApp: packageJson.name };
1495
+ const maybeConfig = (0, import_node_path7.join)(packageRoot, "microfrontends.json");
1496
+ if (import_node_fs6.default.existsSync(maybeConfig)) {
1497
+ return MicrofrontendsServer.fromFile({
1498
+ filePath: maybeConfig,
1499
+ cookies,
1500
+ meta: configMeta,
1501
+ options
1502
+ });
1503
+ }
1504
+ const repositoryRoot = findRepositoryRoot();
1505
+ const isMonorepo2 = isMonorepo({ repositoryRoot });
1506
+ if (isMonorepo2) {
1507
+ const defaultPackage = findDefaultMicrofrontendsPackage({
1508
+ repositoryRoot,
1509
+ applicationName: packageJson.name
1510
+ });
1511
+ return MicrofrontendsServer.fromFile({
1512
+ filePath: (0, import_node_path7.join)(defaultPackage, "microfrontends.json"),
1513
+ cookies,
1514
+ meta: configMeta,
1515
+ options
1516
+ });
1517
+ }
1518
+ throw new Error("Unable to infer");
1519
+ } catch (e) {
1520
+ throw new MicrofrontendError(
1521
+ "Unable to infer microfrontends configuration",
1522
+ { type: "config", subtype: "inference_failed" }
1523
+ );
1524
+ }
1525
+ }
1289
1526
  /*
1290
1527
  * Generates a MicrofrontendsServer instance from a file.
1291
1528
  */
1292
1529
  static fromFile({
1293
1530
  filePath,
1294
1531
  cookies,
1295
- meta
1532
+ meta,
1533
+ options
1296
1534
  }) {
1297
1535
  try {
1298
- const config = import_node_fs.default.readFileSync(filePath, "utf-8");
1536
+ const configJson = import_node_fs6.default.readFileSync(filePath, "utf-8");
1537
+ const config = MicrofrontendsServer.validate(configJson);
1538
+ if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
1539
+ const repositoryRoot = findRepositoryRoot();
1540
+ const isMonorepo2 = isMonorepo({ repositoryRoot });
1541
+ if (isMonorepo2) {
1542
+ const packagePath = findPackagePath({
1543
+ repositoryRoot,
1544
+ name: config.partOf
1545
+ });
1546
+ if (!packagePath) {
1547
+ throw new MicrofrontendError(
1548
+ `Could not find default application "${config.partOf}" in the repository`,
1549
+ { type: "config", subtype: "not_found" }
1550
+ );
1551
+ }
1552
+ const mainConfigPath = (0, import_node_path7.join)(packagePath, "microfrontends.json");
1553
+ return MicrofrontendsServer.fromMainConfigFile({
1554
+ filePath: mainConfigPath,
1555
+ overrides: cookies ? parseOverrides(cookies) : void 0
1556
+ });
1557
+ }
1558
+ }
1299
1559
  return new MicrofrontendsServer({
1300
- config: MicrofrontendsServer.validate(config),
1560
+ config,
1301
1561
  overrides: cookies ? parseOverrides(cookies) : void 0,
1302
1562
  meta
1303
1563
  });
@@ -1315,7 +1575,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1315
1575
  overrides
1316
1576
  }) {
1317
1577
  try {
1318
- const config = import_node_fs.default.readFileSync(filePath, "utf-8");
1578
+ const config = import_node_fs6.default.readFileSync(filePath, "utf-8");
1319
1579
  const validatedConfig = MicrofrontendsServer.validate(config);
1320
1580
  if (!isMainConfig(validatedConfig)) {
1321
1581
  throw new MicrofrontendError(
@@ -1453,24 +1713,26 @@ function getDomainFromEnvironment({
1453
1713
  app,
1454
1714
  target
1455
1715
  }) {
1456
- const projects = JSON.parse(
1457
- process.env.VERCEL_RELATED_PROJECTS ?? "[]"
1716
+ var _a, _b;
1717
+ const mfeProjects = JSON.parse(
1718
+ process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "{}"
1458
1719
  );
1459
- if (projects.length === 0) {
1460
- throw new Error("Missing related vercel project information");
1720
+ if (Object.keys(mfeProjects).length === 0) {
1721
+ throw new Error("Missing related microfrontends project information");
1461
1722
  }
1462
- const vercelProject = projects.find(
1463
- (project) => {
1464
- var _a;
1465
- return project.projectId === ((_a = app.vercel) == null ? void 0 : _a.projectId) || project.appName === app.name;
1466
- }
1467
- );
1723
+ if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
1724
+ throw new Error(`Missing applications[${app.name}].vercel.projectId`);
1725
+ }
1726
+ const vercelProject = (_b = mfeProjects.applications) == null ? void 0 : _b[app.vercel.projectId];
1468
1727
  if (!vercelProject) {
1469
1728
  throw new Error(
1470
- `Missing related vercel project information for application "${app.name}"`
1729
+ `Missing related microfrontends project information for application "${app.name}"`
1471
1730
  );
1472
1731
  }
1473
- return vercelProject.aliases[target];
1732
+ if (target === "preview" && vercelProject.deploymentAlias) {
1733
+ return vercelProject.deploymentAlias;
1734
+ }
1735
+ return vercelProject.productionHost;
1474
1736
  }
1475
1737
 
1476
1738
  // src/routing-v2/get-domain-for-current-environment.ts
@@ -1509,12 +1771,12 @@ function getDomainForCurrentEnvironment(config, appName) {
1509
1771
  const productionHost = config.getDefaultApplication().production.toString();
1510
1772
  switch (group) {
1511
1773
  case "development": {
1512
- const domain = process.env.NODE_ENV === "test" ? app.development.local.toString() : productionHost;
1774
+ const domain = ["test", "development"].includes(process.env.NODE_ENV) ? app.development.local.toString() : productionHost;
1513
1775
  debugDomains(appName, "development", domain);
1514
1776
  return domain;
1515
1777
  }
1516
1778
  case "preview": {
1517
- return getDomainFromEnvironment({ app, target: "branch" });
1779
+ return getDomainFromEnvironment({ app, target: "preview" });
1518
1780
  }
1519
1781
  case "production": {
1520
1782
  return getDomainFromEnvironment({ app, target: "production" });
@@ -1546,11 +1808,11 @@ ${table}
1546
1808
  `);
1547
1809
  }
1548
1810
  }
1549
- function pathToRewrites(path2) {
1811
+ function pathToRewrites(path5) {
1550
1812
  var _a;
1551
1813
  const regex = /(?<base>^.+)\/:.+\*$/;
1552
- const match = regex.exec(path2);
1553
- const paths = [path2];
1814
+ const match = regex.exec(path5);
1815
+ const paths = [path5];
1554
1816
  if ((_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.base) {
1555
1817
  paths.unshift(match.groups.base);
1556
1818
  }
@@ -1564,7 +1826,16 @@ function rewritesMapToArr(rewrites) {
1564
1826
  return [
1565
1827
  {
1566
1828
  source,
1567
- destination
1829
+ destination,
1830
+ missing: [
1831
+ // if this header is present, the proxy has performed the rewrite.
1832
+ // once the proxy routing is fully rolled out, this package should
1833
+ // be updated to not perform any rewrites when deployed.
1834
+ {
1835
+ type: "header",
1836
+ key: "x-vercel-mfe-host"
1837
+ }
1838
+ ]
1568
1839
  }
1569
1840
  ];
1570
1841
  });
@@ -1572,15 +1843,9 @@ function rewritesMapToArr(rewrites) {
1572
1843
  function transform4(args) {
1573
1844
  const { next, microfrontend, app } = args;
1574
1845
  const buildBeforeFiles = () => {
1575
- var _a;
1576
1846
  const rewrites = /* @__PURE__ */ new Map();
1577
1847
  if (!app.isDefault()) {
1578
- rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
1579
- destination: {
1580
- pathname: `/_next/:path+`
1581
- }
1582
- });
1583
- if (!((_a = app.vercel) == null ? void 0 : _a.routeSpeedInsightsToDefaultZone)) {
1848
+ if (process.env.VERCEL_MICROFRONTENDS_CONSOLIDATE_SPEED_INSIGHTS === "1") {
1584
1849
  rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
1585
1850
  destination: { pathname: "/_vercel/:path*" }
1586
1851
  });
@@ -1598,9 +1863,7 @@ function transform4(args) {
1598
1863
  }
1599
1864
  });
1600
1865
  for (const group of routing) {
1601
- if (group.routeToDefaultApplication) {
1602
- continue;
1603
- } else if (group.flag) {
1866
+ if (group.flag) {
1604
1867
  continue;
1605
1868
  } else {
1606
1869
  for (const source of group.paths) {
@@ -1800,7 +2063,7 @@ function getApplicationContext(opts) {
1800
2063
  return { name: opts.appName };
1801
2064
  }
1802
2065
  try {
1803
- const packageJsonString = import_node_fs2.default.readFileSync("./package.json", "utf-8");
2066
+ const packageJsonString = import_node_fs7.default.readFileSync("./package.json", "utf-8");
1804
2067
  const packageJson = JSON.parse(packageJsonString);
1805
2068
  if (!packageJson.name) {
1806
2069
  throw new MicrofrontendError(
@@ -1825,8 +2088,8 @@ function withMicrofrontends(nextConfig, opts) {
1825
2088
  process.env.MFE_DEBUG = "true";
1826
2089
  }
1827
2090
  const { name: fromApp } = getApplicationContext(opts);
1828
- const microfrontends = MicrofrontendsServer.fromFile({
1829
- filePath: (opts == null ? void 0 : opts.configPath) ?? "./microfrontends.json",
2091
+ const microfrontends = MicrofrontendsServer.infer({
2092
+ filePath: opts == null ? void 0 : opts.configPath,
1830
2093
  meta: {
1831
2094
  fromApp
1832
2095
  }