@vercel/microfrontends 2.3.0 → 2.3.2

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 (50) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/bin/cli.cjs +275 -268
  3. package/dist/config.cjs +22 -21
  4. package/dist/config.cjs.map +1 -1
  5. package/dist/config.d.ts +3 -2
  6. package/dist/config.js +22 -21
  7. package/dist/config.js.map +1 -1
  8. package/dist/experimental/sveltekit.cjs +259 -258
  9. package/dist/experimental/sveltekit.cjs.map +1 -1
  10. package/dist/experimental/sveltekit.js +239 -238
  11. package/dist/experimental/sveltekit.js.map +1 -1
  12. package/dist/experimental/vite.cjs +259 -258
  13. package/dist/experimental/vite.cjs.map +1 -1
  14. package/dist/experimental/vite.js +239 -238
  15. package/dist/experimental/vite.js.map +1 -1
  16. package/dist/microfrontends/server.cjs +259 -258
  17. package/dist/microfrontends/server.cjs.map +1 -1
  18. package/dist/microfrontends/server.d.ts +2 -2
  19. package/dist/microfrontends/server.js +239 -238
  20. package/dist/microfrontends/server.js.map +1 -1
  21. package/dist/microfrontends/utils.cjs +22 -0
  22. package/dist/microfrontends/utils.cjs.map +1 -1
  23. package/dist/microfrontends/utils.d.ts +5 -1
  24. package/dist/microfrontends/utils.js +21 -0
  25. package/dist/microfrontends/utils.js.map +1 -1
  26. package/dist/next/client.cjs.map +1 -1
  27. package/dist/next/client.js.map +1 -1
  28. package/dist/next/config.cjs +259 -258
  29. package/dist/next/config.cjs.map +1 -1
  30. package/dist/next/config.js +239 -238
  31. package/dist/next/config.js.map +1 -1
  32. package/dist/next/middleware.cjs +22 -21
  33. package/dist/next/middleware.cjs.map +1 -1
  34. package/dist/next/middleware.js +22 -21
  35. package/dist/next/middleware.js.map +1 -1
  36. package/dist/next/testing.cjs +22 -21
  37. package/dist/next/testing.cjs.map +1 -1
  38. package/dist/next/testing.d.ts +2 -2
  39. package/dist/next/testing.js +22 -21
  40. package/dist/next/testing.js.map +1 -1
  41. package/dist/overrides.d.ts +3 -3
  42. package/dist/schema.d.ts +2 -2
  43. package/dist/{types-b9ea41b2.d.ts → types-279c294f.d.ts} +1 -1
  44. package/dist/{types-dcd8b17a.d.ts → types-f331c2a8.d.ts} +0 -4
  45. package/dist/utils/mfe-port.cjs +259 -258
  46. package/dist/utils/mfe-port.cjs.map +1 -1
  47. package/dist/utils/mfe-port.js +239 -238
  48. package/dist/utils/mfe-port.js.map +1 -1
  49. package/dist/validation.d.ts +1 -1
  50. package/package.json +1 -1
@@ -156,7 +156,16 @@ var MicrofrontendError = class extends Error {
156
156
  };
157
157
 
158
158
  // src/config/microfrontends-config/isomorphic/index.ts
159
- var import_jsonc_parser = require("jsonc-parser");
159
+ var import_jsonc_parser2 = require("jsonc-parser");
160
+
161
+ // src/config/microfrontends/utils/hash-application-name.ts
162
+ var import_md5 = __toESM(require("md5"), 1);
163
+ function hashApplicationName(name) {
164
+ if (!name) {
165
+ throw new Error("Application name is required to generate hash");
166
+ }
167
+ return (0, import_md5.default)(name).substring(0, 6).padStart(6, "0");
168
+ }
160
169
 
161
170
  // src/config/overrides/constants.ts
162
171
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
@@ -306,6 +315,231 @@ function getConfigStringFromEnv() {
306
315
  return config;
307
316
  }
308
317
 
318
+ // src/config/microfrontends/utils/find-config.ts
319
+ var import_node_fs = __toESM(require("fs"), 1);
320
+ var import_node_path = require("path");
321
+
322
+ // src/config/microfrontends/utils/get-config-file-name.ts
323
+ var DEFAULT_CONFIGURATION_FILENAMES = [
324
+ "microfrontends.json",
325
+ "microfrontends.jsonc"
326
+ ];
327
+ function getPossibleConfigurationFilenames({
328
+ customConfigFilename
329
+ }) {
330
+ if (customConfigFilename) {
331
+ if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
332
+ throw new Error(
333
+ `Found VC_MICROFRONTENDS_CONFIG_FILE_NAME but the name is invalid. Received: ${customConfigFilename}. The file name must end with '.json' or '.jsonc'. It's also possible for the env var to include the path, eg microfrontends-dev.json or /path/to/microfrontends-dev.json.`
334
+ );
335
+ }
336
+ return Array.from(
337
+ /* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
338
+ );
339
+ }
340
+ return DEFAULT_CONFIGURATION_FILENAMES;
341
+ }
342
+
343
+ // src/config/microfrontends/utils/find-config.ts
344
+ function findConfig({
345
+ dir,
346
+ customConfigFilename
347
+ }) {
348
+ for (const filename of getPossibleConfigurationFilenames({
349
+ customConfigFilename
350
+ })) {
351
+ const maybeConfig = (0, import_node_path.join)(dir, filename);
352
+ if (import_node_fs.default.existsSync(maybeConfig)) {
353
+ return maybeConfig;
354
+ }
355
+ }
356
+ return null;
357
+ }
358
+
359
+ // src/config/microfrontends/utils/generate-default-asset-prefix.ts
360
+ var PREFIX = "vc-ap";
361
+ function generateDefaultAssetPrefixFromName({
362
+ name
363
+ }) {
364
+ if (!name) {
365
+ throw new Error("Name is required to generate an asset prefix");
366
+ }
367
+ return `${PREFIX}-${hashApplicationName(name)}`;
368
+ }
369
+
370
+ // src/config/microfrontends/utils/infer-microfrontends-location.ts
371
+ var import_node_fs2 = require("fs");
372
+ var import_node_path2 = require("path");
373
+ var import_fast_glob = __toESM(require("fast-glob"), 1);
374
+ var import_jsonc_parser = require("jsonc-parser");
375
+ var configCache = {};
376
+ function findPackageWithMicrofrontendsConfig({
377
+ repositoryRoot,
378
+ applicationContext,
379
+ customConfigFilename
380
+ }) {
381
+ const applicationName = applicationContext.name;
382
+ logger.debug(
383
+ "[MFE Config] Searching repository for configs containing application:",
384
+ applicationName
385
+ );
386
+ try {
387
+ const microfrontendsJsonPaths = import_fast_glob.default.globSync(
388
+ `**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
389
+ {
390
+ cwd: repositoryRoot,
391
+ absolute: true,
392
+ onlyFiles: true,
393
+ followSymbolicLinks: false,
394
+ ignore: ["**/node_modules/**", "**/.git/**"]
395
+ }
396
+ );
397
+ logger.debug(
398
+ "[MFE Config] Found",
399
+ microfrontendsJsonPaths.length,
400
+ "config file(s) in repository"
401
+ );
402
+ const matchingPaths = [];
403
+ for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
404
+ if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
405
+ matchingPaths.push(microfrontendsJsonPath);
406
+ }
407
+ }
408
+ logger.debug(
409
+ "[MFE Config] Total matching config files:",
410
+ matchingPaths.length
411
+ );
412
+ if (matchingPaths.length > 1) {
413
+ throw new MicrofrontendError(
414
+ `Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
415
+ ${matchingPaths.join("\n \u2022 ")}`,
416
+ { type: "config", subtype: "inference_failed" }
417
+ );
418
+ }
419
+ if (matchingPaths.length === 0) {
420
+ if (repositoryRoot && doesMisplacedConfigExist(
421
+ repositoryRoot,
422
+ applicationName,
423
+ customConfigFilename
424
+ )) {
425
+ logger.debug(
426
+ "[MFE Config] Found misplaced config in wrong .vercel directory in repository"
427
+ );
428
+ const misplacedConfigPath = (0, import_node_path2.join)(
429
+ repositoryRoot,
430
+ ".vercel",
431
+ customConfigFilename || "microfrontends.json"
432
+ );
433
+ throw new MicrofrontendError(
434
+ `Unable to automatically infer the location of the \`microfrontends.json\` file.
435
+
436
+ A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
437
+ However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
438
+
439
+ To fix this:
440
+ 1. If using \`vercel link\`, run it with \`vercel link --repo\` to handle monorepos, or run \`vercel microfrontends pull --cwd=<application-directory>\` to make sure it pulls the \`microfrontends.json\` file to the correct location
441
+ 2. If manually defined, move the config file to the \`.vercel\` directory in your application
442
+ 3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
443
+
444
+ For more information, see: https://vercel.com/docs/cli/project-linking`,
445
+ { type: "config", subtype: "inference_failed" }
446
+ );
447
+ }
448
+ let additionalErrorMessage = "";
449
+ if (microfrontendsJsonPaths.length > 0) {
450
+ if (!applicationContext.projectName) {
451
+ additionalErrorMessage = `
452
+
453
+ If the name in package.json (${applicationContext.packageJsonName}) differs from your Vercel Project name, set the \`packageName\` field for the application in \`microfrontends.json\` to ensure that the configuration can be found locally.`;
454
+ } else {
455
+ additionalErrorMessage = `
456
+
457
+ Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
458
+ }
459
+ }
460
+ throw new MicrofrontendError(
461
+ `Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
462
+
463
+ If your Vercel Microfrontends configuration is not in this repository, you can use the Vercel CLI to pull the Vercel Microfrontends configuration using the "vercel microfrontends pull" command, or you can specify the path manually using the VC_MICROFRONTENDS_CONFIG environment variable.
464
+
465
+ If your Vercel Microfrontends configuration has a custom name, ensure the VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable is set, you can pull the vercel project environment variables using the "vercel env pull" command.
466
+
467
+ If you suspect this is thrown in error, please reach out to the Vercel team.`,
468
+ { type: "config", subtype: "inference_failed" }
469
+ );
470
+ }
471
+ const [packageJsonPath] = matchingPaths;
472
+ return (0, import_node_path2.dirname)(packageJsonPath);
473
+ } catch (error2) {
474
+ if (error2 instanceof MicrofrontendError) {
475
+ throw error2;
476
+ }
477
+ return null;
478
+ }
479
+ }
480
+ function inferMicrofrontendsLocation(opts) {
481
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
482
+ if (configCache[cacheKey]) {
483
+ return configCache[cacheKey];
484
+ }
485
+ const result = findPackageWithMicrofrontendsConfig(opts);
486
+ if (!result) {
487
+ throw new MicrofrontendError(
488
+ `Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
489
+ { type: "config", subtype: "inference_failed" }
490
+ );
491
+ }
492
+ configCache[cacheKey] = result;
493
+ return result;
494
+ }
495
+ function existsSync(path7) {
496
+ try {
497
+ (0, import_node_fs2.statSync)(path7);
498
+ return true;
499
+ } catch (_) {
500
+ return false;
501
+ }
502
+ }
503
+ function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
504
+ logger.debug(
505
+ "[MFE Config] Looking for misplaced config in wrong .vercel directory"
506
+ );
507
+ const misplacedConfigPath = (0, import_node_path2.join)(
508
+ repositoryRoot,
509
+ ".vercel",
510
+ customConfigFilename || "microfrontends.json"
511
+ );
512
+ return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
513
+ }
514
+ function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
515
+ try {
516
+ const microfrontendsJsonContent = (0, import_node_fs2.readFileSync)(
517
+ microfrontendsJsonPath,
518
+ "utf-8"
519
+ );
520
+ const microfrontendsJson = (0, import_jsonc_parser.parse)(microfrontendsJsonContent);
521
+ if (microfrontendsJson.applications[applicationName]) {
522
+ logger.debug(
523
+ "[MFE Config] Found application in config:",
524
+ microfrontendsJsonPath
525
+ );
526
+ return true;
527
+ }
528
+ for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
529
+ if (app.packageName === applicationName) {
530
+ logger.debug(
531
+ "[MFE Config] Found application via packageName in config:",
532
+ microfrontendsJsonPath
533
+ );
534
+ return true;
535
+ }
536
+ }
537
+ } catch (error2) {
538
+ logger.debug("[MFE Config] Error checking application in config:", error2);
539
+ }
540
+ return false;
541
+ }
542
+
309
543
  // src/config/microfrontends-config/isomorphic/constants.ts
310
544
  var DEFAULT_LOCAL_PROXY_PORT = 3024;
311
545
  var MFE_APP_PORT_ENV = "MFE_APP_PORT";
@@ -444,26 +678,6 @@ var LocalHost = class extends Host {
444
678
  }
445
679
  };
446
680
 
447
- // src/config/microfrontends-config/isomorphic/utils/hash-application-name.ts
448
- var import_md5 = __toESM(require("md5"), 1);
449
- function hashApplicationName(name) {
450
- if (!name) {
451
- throw new Error("Application name is required to generate hash");
452
- }
453
- return (0, import_md5.default)(name).substring(0, 6).padStart(6, "0");
454
- }
455
-
456
- // src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
457
- var PREFIX = "vc-ap";
458
- function generateAssetPrefixFromName({
459
- name
460
- }) {
461
- if (!name) {
462
- throw new Error("Name is required to generate an asset prefix");
463
- }
464
- return `${PREFIX}-${hashApplicationName(name)}`;
465
- }
466
-
467
681
  // src/config/microfrontends-config/isomorphic/utils/generate-automation-bypass-env-var-name.ts
468
682
  function generateAutomationBypassEnvVarName({
469
683
  name
@@ -681,7 +895,7 @@ var Application = class {
681
895
  return this.default;
682
896
  }
683
897
  getAssetPrefix() {
684
- const generatedAssetPrefix = generateAssetPrefixFromName({
898
+ const generatedAssetPrefix = generateDefaultAssetPrefixFromName({
685
899
  name: this.name
686
900
  });
687
901
  if ("assetPrefix" in this.serialized) {
@@ -689,6 +903,7 @@ var Application = class {
689
903
  }
690
904
  return generatedAssetPrefix;
691
905
  }
906
+ /** @deprecated Prefer `VERCEL_AUTOMATION_BYPASS_SECRET`. Use this only if each project needs its own distinct bypass secret. */
692
907
  getAutomationBypassEnvVarName() {
693
908
  return generateAutomationBypassEnvVarName({ name: this.name });
694
909
  }
@@ -775,7 +990,7 @@ var MicrofrontendConfigIsomorphic = class {
775
990
  };
776
991
  }
777
992
  static validate(config) {
778
- const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
993
+ const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
779
994
  validateConfigPaths(c.applications);
780
995
  validateConfigDefaultApplication(c.applications);
781
996
  return c;
@@ -784,7 +999,7 @@ var MicrofrontendConfigIsomorphic = class {
784
999
  cookies
785
1000
  }) {
786
1001
  return new MicrofrontendConfigIsomorphic({
787
- config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
1002
+ config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
788
1003
  overrides: parseOverrides(cookies ?? [])
789
1004
  });
790
1005
  }
@@ -898,59 +1113,18 @@ var MicrofrontendConfigIsomorphic = class {
898
1113
  }
899
1114
  };
900
1115
 
901
- // src/config/microfrontends/utils/find-config.ts
902
- var import_node_fs = __toESM(require("fs"), 1);
903
- var import_node_path = require("path");
904
-
905
- // src/config/microfrontends/utils/get-config-file-name.ts
906
- var DEFAULT_CONFIGURATION_FILENAMES = [
907
- "microfrontends.json",
908
- "microfrontends.jsonc"
909
- ];
910
- function getPossibleConfigurationFilenames({
911
- customConfigFilename
912
- }) {
913
- if (customConfigFilename) {
914
- if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
915
- throw new Error(
916
- `Found VC_MICROFRONTENDS_CONFIG_FILE_NAME but the name is invalid. Received: ${customConfigFilename}. The file name must end with '.json' or '.jsonc'. It's also possible for the env var to include the path, eg microfrontends-dev.json or /path/to/microfrontends-dev.json.`
917
- );
918
- }
919
- return Array.from(
920
- /* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
921
- );
922
- }
923
- return DEFAULT_CONFIGURATION_FILENAMES;
924
- }
925
-
926
- // src/config/microfrontends/utils/find-config.ts
927
- function findConfig({
928
- dir,
929
- customConfigFilename
930
- }) {
931
- for (const filename of getPossibleConfigurationFilenames({
932
- customConfigFilename
933
- })) {
934
- const maybeConfig = (0, import_node_path.join)(dir, filename);
935
- if (import_node_fs.default.existsSync(maybeConfig)) {
936
- return maybeConfig;
937
- }
938
- }
939
- return null;
940
- }
941
-
942
1116
  // src/config/microfrontends/utils/find-package-root.ts
943
- var import_node_fs2 = __toESM(require("fs"), 1);
944
- var import_node_path2 = __toESM(require("path"), 1);
1117
+ var import_node_fs3 = __toESM(require("fs"), 1);
1118
+ var import_node_path3 = __toESM(require("path"), 1);
945
1119
  var PACKAGE_JSON = "package.json";
946
1120
  function findPackageRoot(startDir) {
947
1121
  let currentDir = startDir || process.cwd();
948
- while (currentDir !== import_node_path2.default.parse(currentDir).root) {
949
- const pkgJsonPath = import_node_path2.default.join(currentDir, PACKAGE_JSON);
950
- if (import_node_fs2.default.existsSync(pkgJsonPath)) {
1122
+ while (currentDir !== import_node_path3.default.parse(currentDir).root) {
1123
+ const pkgJsonPath = import_node_path3.default.join(currentDir, PACKAGE_JSON);
1124
+ if (import_node_fs3.default.existsSync(pkgJsonPath)) {
951
1125
  return currentDir;
952
1126
  }
953
- currentDir = import_node_path2.default.dirname(currentDir);
1127
+ currentDir = import_node_path3.default.dirname(currentDir);
954
1128
  }
955
1129
  throw new Error(
956
1130
  `The root of the package that contains the \`package.json\` file for the \`${startDir}\` directory could not be found.`
@@ -958,18 +1132,18 @@ function findPackageRoot(startDir) {
958
1132
  }
959
1133
 
960
1134
  // src/config/microfrontends/utils/find-repository-root.ts
961
- var import_node_fs3 = __toESM(require("fs"), 1);
962
- var import_node_path3 = __toESM(require("path"), 1);
1135
+ var import_node_fs4 = __toESM(require("fs"), 1);
1136
+ var import_node_path4 = __toESM(require("path"), 1);
963
1137
  var GIT_DIRECTORY = ".git";
964
1138
  function hasGitDirectory(dir) {
965
- const gitPath = import_node_path3.default.join(dir, GIT_DIRECTORY);
966
- return import_node_fs3.default.existsSync(gitPath) && import_node_fs3.default.statSync(gitPath).isDirectory();
1139
+ const gitPath = import_node_path4.default.join(dir, GIT_DIRECTORY);
1140
+ return import_node_fs4.default.existsSync(gitPath) && import_node_fs4.default.statSync(gitPath).isDirectory();
967
1141
  }
968
1142
  function hasPnpmWorkspaces(dir) {
969
- return import_node_fs3.default.existsSync(import_node_path3.default.join(dir, "pnpm-workspace.yaml"));
1143
+ return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "pnpm-workspace.yaml"));
970
1144
  }
971
1145
  function hasPackageJson(dir) {
972
- return import_node_fs3.default.existsSync(import_node_path3.default.join(dir, "package.json"));
1146
+ return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "package.json"));
973
1147
  }
974
1148
  function findRepositoryRoot(startDir) {
975
1149
  if (process.env.NX_WORKSPACE_ROOT) {
@@ -977,14 +1151,14 @@ function findRepositoryRoot(startDir) {
977
1151
  }
978
1152
  let currentDir = startDir || process.cwd();
979
1153
  let lastPackageJsonDir = null;
980
- while (currentDir !== import_node_path3.default.parse(currentDir).root) {
1154
+ while (currentDir !== import_node_path4.default.parse(currentDir).root) {
981
1155
  if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
982
1156
  return currentDir;
983
1157
  }
984
1158
  if (hasPackageJson(currentDir)) {
985
1159
  lastPackageJsonDir = currentDir;
986
1160
  }
987
- currentDir = import_node_path3.default.dirname(currentDir);
1161
+ currentDir = import_node_path4.default.dirname(currentDir);
988
1162
  }
989
1163
  if (lastPackageJsonDir) {
990
1164
  return lastPackageJsonDir;
@@ -995,8 +1169,8 @@ function findRepositoryRoot(startDir) {
995
1169
  }
996
1170
 
997
1171
  // src/config/microfrontends/utils/get-application-context.ts
998
- var import_node_fs4 = __toESM(require("fs"), 1);
999
- var import_node_path4 = __toESM(require("path"), 1);
1172
+ var import_node_fs5 = __toESM(require("fs"), 1);
1173
+ var import_node_path5 = __toESM(require("path"), 1);
1000
1174
  function getApplicationContext(opts) {
1001
1175
  if (opts?.appName) {
1002
1176
  logger.debug(
@@ -1026,8 +1200,8 @@ function getApplicationContext(opts) {
1026
1200
  };
1027
1201
  }
1028
1202
  try {
1029
- const vercelProjectJsonPath = import_node_fs4.default.readFileSync(
1030
- import_node_path4.default.join(opts?.packageRoot || ".", ".vercel", "project.json"),
1203
+ const vercelProjectJsonPath = import_node_fs5.default.readFileSync(
1204
+ import_node_path5.default.join(opts?.packageRoot || ".", ".vercel", "project.json"),
1031
1205
  "utf-8"
1032
1206
  );
1033
1207
  const projectJson = JSON.parse(vercelProjectJsonPath);
@@ -1044,8 +1218,8 @@ function getApplicationContext(opts) {
1044
1218
  } catch (_) {
1045
1219
  }
1046
1220
  try {
1047
- const packageJsonString = import_node_fs4.default.readFileSync(
1048
- import_node_path4.default.join(opts?.packageRoot || ".", "package.json"),
1221
+ const packageJsonString = import_node_fs5.default.readFileSync(
1222
+ import_node_path5.default.join(opts?.packageRoot || ".", "package.json"),
1049
1223
  "utf-8"
1050
1224
  );
1051
1225
  const packageJson = JSON.parse(packageJsonString);
@@ -1071,179 +1245,6 @@ function getApplicationContext(opts) {
1071
1245
  }
1072
1246
  }
1073
1247
 
1074
- // src/config/microfrontends/utils/infer-microfrontends-location.ts
1075
- var import_node_fs5 = require("fs");
1076
- var import_node_path5 = require("path");
1077
- var import_fast_glob = __toESM(require("fast-glob"), 1);
1078
- var import_jsonc_parser2 = require("jsonc-parser");
1079
- var configCache = {};
1080
- function findPackageWithMicrofrontendsConfig({
1081
- repositoryRoot,
1082
- applicationContext,
1083
- customConfigFilename
1084
- }) {
1085
- const applicationName = applicationContext.name;
1086
- logger.debug(
1087
- "[MFE Config] Searching repository for configs containing application:",
1088
- applicationName
1089
- );
1090
- try {
1091
- const microfrontendsJsonPaths = import_fast_glob.default.globSync(
1092
- `**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
1093
- {
1094
- cwd: repositoryRoot,
1095
- absolute: true,
1096
- onlyFiles: true,
1097
- followSymbolicLinks: false,
1098
- ignore: ["**/node_modules/**", "**/.git/**"]
1099
- }
1100
- );
1101
- logger.debug(
1102
- "[MFE Config] Found",
1103
- microfrontendsJsonPaths.length,
1104
- "config file(s) in repository"
1105
- );
1106
- const matchingPaths = [];
1107
- for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
1108
- if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
1109
- matchingPaths.push(microfrontendsJsonPath);
1110
- }
1111
- }
1112
- logger.debug(
1113
- "[MFE Config] Total matching config files:",
1114
- matchingPaths.length
1115
- );
1116
- if (matchingPaths.length > 1) {
1117
- throw new MicrofrontendError(
1118
- `Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
1119
- ${matchingPaths.join("\n \u2022 ")}`,
1120
- { type: "config", subtype: "inference_failed" }
1121
- );
1122
- }
1123
- if (matchingPaths.length === 0) {
1124
- if (repositoryRoot && doesMisplacedConfigExist(
1125
- repositoryRoot,
1126
- applicationName,
1127
- customConfigFilename
1128
- )) {
1129
- logger.debug(
1130
- "[MFE Config] Found misplaced config in wrong .vercel directory in repository"
1131
- );
1132
- const misplacedConfigPath = (0, import_node_path5.join)(
1133
- repositoryRoot,
1134
- ".vercel",
1135
- customConfigFilename || "microfrontends.json"
1136
- );
1137
- throw new MicrofrontendError(
1138
- `Unable to automatically infer the location of the \`microfrontends.json\` file.
1139
-
1140
- A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
1141
- However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
1142
-
1143
- To fix this:
1144
- 1. If using \`vercel link\`, run it with \`vercel link --repo\` to handle monorepos, or run \`vercel microfrontends pull --cwd=<application-directory>\` to make sure it pulls the \`microfrontends.json\` file to the correct location
1145
- 2. If manually defined, move the config file to the \`.vercel\` directory in your application
1146
- 3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
1147
-
1148
- For more information, see: https://vercel.com/docs/cli/project-linking`,
1149
- { type: "config", subtype: "inference_failed" }
1150
- );
1151
- }
1152
- let additionalErrorMessage = "";
1153
- if (microfrontendsJsonPaths.length > 0) {
1154
- if (!applicationContext.projectName) {
1155
- additionalErrorMessage = `
1156
-
1157
- If the name in package.json (${applicationContext.packageJsonName}) differs from your Vercel Project name, set the \`packageName\` field for the application in \`microfrontends.json\` to ensure that the configuration can be found locally.`;
1158
- } else {
1159
- additionalErrorMessage = `
1160
-
1161
- Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
1162
- }
1163
- }
1164
- throw new MicrofrontendError(
1165
- `Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
1166
-
1167
- If your Vercel Microfrontends configuration is not in this repository, you can use the Vercel CLI to pull the Vercel Microfrontends configuration using the "vercel microfrontends pull" command, or you can specify the path manually using the VC_MICROFRONTENDS_CONFIG environment variable.
1168
-
1169
- If your Vercel Microfrontends configuration has a custom name, ensure the VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable is set, you can pull the vercel project environment variables using the "vercel env pull" command.
1170
-
1171
- If you suspect this is thrown in error, please reach out to the Vercel team.`,
1172
- { type: "config", subtype: "inference_failed" }
1173
- );
1174
- }
1175
- const [packageJsonPath] = matchingPaths;
1176
- return (0, import_node_path5.dirname)(packageJsonPath);
1177
- } catch (error2) {
1178
- if (error2 instanceof MicrofrontendError) {
1179
- throw error2;
1180
- }
1181
- return null;
1182
- }
1183
- }
1184
- function inferMicrofrontendsLocation(opts) {
1185
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
1186
- if (configCache[cacheKey]) {
1187
- return configCache[cacheKey];
1188
- }
1189
- const result = findPackageWithMicrofrontendsConfig(opts);
1190
- if (!result) {
1191
- throw new MicrofrontendError(
1192
- `Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
1193
- { type: "config", subtype: "inference_failed" }
1194
- );
1195
- }
1196
- configCache[cacheKey] = result;
1197
- return result;
1198
- }
1199
- function existsSync(path7) {
1200
- try {
1201
- (0, import_node_fs5.statSync)(path7);
1202
- return true;
1203
- } catch (_) {
1204
- return false;
1205
- }
1206
- }
1207
- function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
1208
- logger.debug(
1209
- "[MFE Config] Looking for misplaced config in wrong .vercel directory"
1210
- );
1211
- const misplacedConfigPath = (0, import_node_path5.join)(
1212
- repositoryRoot,
1213
- ".vercel",
1214
- customConfigFilename || "microfrontends.json"
1215
- );
1216
- return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
1217
- }
1218
- function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
1219
- try {
1220
- const microfrontendsJsonContent = (0, import_node_fs5.readFileSync)(
1221
- microfrontendsJsonPath,
1222
- "utf-8"
1223
- );
1224
- const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
1225
- if (microfrontendsJson.applications[applicationName]) {
1226
- logger.debug(
1227
- "[MFE Config] Found application in config:",
1228
- microfrontendsJsonPath
1229
- );
1230
- return true;
1231
- }
1232
- for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
1233
- if (app.packageName === applicationName) {
1234
- logger.debug(
1235
- "[MFE Config] Found application via packageName in config:",
1236
- microfrontendsJsonPath
1237
- );
1238
- return true;
1239
- }
1240
- }
1241
- } catch (error2) {
1242
- logger.debug("[MFE Config] Error checking application in config:", error2);
1243
- }
1244
- return false;
1245
- }
1246
-
1247
1248
  // src/config/microfrontends/utils/is-monorepo.ts
1248
1249
  var import_node_fs6 = __toESM(require("fs"), 1);
1249
1250
  var import_node_path6 = __toESM(require("path"), 1);