@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
package/dist/bin/cli.cjs CHANGED
@@ -30,7 +30,7 @@ var import_commander = require("commander");
30
30
  // package.json
31
31
  var package_default = {
32
32
  name: "@vercel/microfrontends",
33
- version: "2.3.0",
33
+ version: "2.3.2",
34
34
  private: false,
35
35
  description: "Defines configuration and utilities for microfrontends development",
36
36
  keywords: [
@@ -369,7 +369,16 @@ var MicrofrontendError = class extends Error {
369
369
  };
370
370
 
371
371
  // src/config/microfrontends-config/isomorphic/index.ts
372
- var import_jsonc_parser = require("jsonc-parser");
372
+ var import_jsonc_parser2 = require("jsonc-parser");
373
+
374
+ // src/config/microfrontends/utils/hash-application-name.ts
375
+ var import_md5 = __toESM(require("md5"), 1);
376
+ function hashApplicationName(name) {
377
+ if (!name) {
378
+ throw new Error("Application name is required to generate hash");
379
+ }
380
+ return (0, import_md5.default)(name).substring(0, 6).padStart(6, "0");
381
+ }
373
382
 
374
383
  // src/config/overrides/constants.ts
375
384
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
@@ -524,6 +533,231 @@ function getConfigStringFromEnv() {
524
533
  return config;
525
534
  }
526
535
 
536
+ // src/config/microfrontends/utils/find-config.ts
537
+ var import_node_fs = __toESM(require("fs"), 1);
538
+ var import_node_path = require("path");
539
+
540
+ // src/config/microfrontends/utils/get-config-file-name.ts
541
+ var DEFAULT_CONFIGURATION_FILENAMES = [
542
+ "microfrontends.json",
543
+ "microfrontends.jsonc"
544
+ ];
545
+ function getPossibleConfigurationFilenames({
546
+ customConfigFilename
547
+ }) {
548
+ if (customConfigFilename) {
549
+ if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
550
+ throw new Error(
551
+ `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.`
552
+ );
553
+ }
554
+ return Array.from(
555
+ /* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
556
+ );
557
+ }
558
+ return DEFAULT_CONFIGURATION_FILENAMES;
559
+ }
560
+
561
+ // src/config/microfrontends/utils/find-config.ts
562
+ function findConfig({
563
+ dir,
564
+ customConfigFilename
565
+ }) {
566
+ for (const filename of getPossibleConfigurationFilenames({
567
+ customConfigFilename
568
+ })) {
569
+ const maybeConfig = (0, import_node_path.join)(dir, filename);
570
+ if (import_node_fs.default.existsSync(maybeConfig)) {
571
+ return maybeConfig;
572
+ }
573
+ }
574
+ return null;
575
+ }
576
+
577
+ // src/config/microfrontends/utils/generate-default-asset-prefix.ts
578
+ var PREFIX = "vc-ap";
579
+ function generateDefaultAssetPrefixFromName({
580
+ name
581
+ }) {
582
+ if (!name) {
583
+ throw new Error("Name is required to generate an asset prefix");
584
+ }
585
+ return `${PREFIX}-${hashApplicationName(name)}`;
586
+ }
587
+
588
+ // src/config/microfrontends/utils/infer-microfrontends-location.ts
589
+ var import_node_fs2 = require("fs");
590
+ var import_node_path2 = require("path");
591
+ var import_fast_glob = __toESM(require("fast-glob"), 1);
592
+ var import_jsonc_parser = require("jsonc-parser");
593
+ var configCache = {};
594
+ function findPackageWithMicrofrontendsConfig({
595
+ repositoryRoot,
596
+ applicationContext,
597
+ customConfigFilename
598
+ }) {
599
+ const applicationName = applicationContext.name;
600
+ logger.debug(
601
+ "[MFE Config] Searching repository for configs containing application:",
602
+ applicationName
603
+ );
604
+ try {
605
+ const microfrontendsJsonPaths = import_fast_glob.default.globSync(
606
+ `**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
607
+ {
608
+ cwd: repositoryRoot,
609
+ absolute: true,
610
+ onlyFiles: true,
611
+ followSymbolicLinks: false,
612
+ ignore: ["**/node_modules/**", "**/.git/**"]
613
+ }
614
+ );
615
+ logger.debug(
616
+ "[MFE Config] Found",
617
+ microfrontendsJsonPaths.length,
618
+ "config file(s) in repository"
619
+ );
620
+ const matchingPaths = [];
621
+ for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
622
+ if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
623
+ matchingPaths.push(microfrontendsJsonPath);
624
+ }
625
+ }
626
+ logger.debug(
627
+ "[MFE Config] Total matching config files:",
628
+ matchingPaths.length
629
+ );
630
+ if (matchingPaths.length > 1) {
631
+ throw new MicrofrontendError(
632
+ `Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
633
+ ${matchingPaths.join("\n \u2022 ")}`,
634
+ { type: "config", subtype: "inference_failed" }
635
+ );
636
+ }
637
+ if (matchingPaths.length === 0) {
638
+ if (repositoryRoot && doesMisplacedConfigExist(
639
+ repositoryRoot,
640
+ applicationName,
641
+ customConfigFilename
642
+ )) {
643
+ logger.debug(
644
+ "[MFE Config] Found misplaced config in wrong .vercel directory in repository"
645
+ );
646
+ const misplacedConfigPath = (0, import_node_path2.join)(
647
+ repositoryRoot,
648
+ ".vercel",
649
+ customConfigFilename || "microfrontends.json"
650
+ );
651
+ throw new MicrofrontendError(
652
+ `Unable to automatically infer the location of the \`microfrontends.json\` file.
653
+
654
+ A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
655
+ However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
656
+
657
+ To fix this:
658
+ 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
659
+ 2. If manually defined, move the config file to the \`.vercel\` directory in your application
660
+ 3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
661
+
662
+ For more information, see: https://vercel.com/docs/cli/project-linking`,
663
+ { type: "config", subtype: "inference_failed" }
664
+ );
665
+ }
666
+ let additionalErrorMessage = "";
667
+ if (microfrontendsJsonPaths.length > 0) {
668
+ if (!applicationContext.projectName) {
669
+ additionalErrorMessage = `
670
+
671
+ 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.`;
672
+ } else {
673
+ additionalErrorMessage = `
674
+
675
+ Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
676
+ }
677
+ }
678
+ throw new MicrofrontendError(
679
+ `Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
680
+
681
+ 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.
682
+
683
+ 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.
684
+
685
+ If you suspect this is thrown in error, please reach out to the Vercel team.`,
686
+ { type: "config", subtype: "inference_failed" }
687
+ );
688
+ }
689
+ const [packageJsonPath] = matchingPaths;
690
+ return (0, import_node_path2.dirname)(packageJsonPath);
691
+ } catch (error2) {
692
+ if (error2 instanceof MicrofrontendError) {
693
+ throw error2;
694
+ }
695
+ return null;
696
+ }
697
+ }
698
+ function inferMicrofrontendsLocation(opts) {
699
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
700
+ if (configCache[cacheKey]) {
701
+ return configCache[cacheKey];
702
+ }
703
+ const result = findPackageWithMicrofrontendsConfig(opts);
704
+ if (!result) {
705
+ throw new MicrofrontendError(
706
+ `Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
707
+ { type: "config", subtype: "inference_failed" }
708
+ );
709
+ }
710
+ configCache[cacheKey] = result;
711
+ return result;
712
+ }
713
+ function existsSync(path7) {
714
+ try {
715
+ (0, import_node_fs2.statSync)(path7);
716
+ return true;
717
+ } catch (_) {
718
+ return false;
719
+ }
720
+ }
721
+ function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
722
+ logger.debug(
723
+ "[MFE Config] Looking for misplaced config in wrong .vercel directory"
724
+ );
725
+ const misplacedConfigPath = (0, import_node_path2.join)(
726
+ repositoryRoot,
727
+ ".vercel",
728
+ customConfigFilename || "microfrontends.json"
729
+ );
730
+ return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
731
+ }
732
+ function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
733
+ try {
734
+ const microfrontendsJsonContent = (0, import_node_fs2.readFileSync)(
735
+ microfrontendsJsonPath,
736
+ "utf-8"
737
+ );
738
+ const microfrontendsJson = (0, import_jsonc_parser.parse)(microfrontendsJsonContent);
739
+ if (microfrontendsJson.applications[applicationName]) {
740
+ logger.debug(
741
+ "[MFE Config] Found application in config:",
742
+ microfrontendsJsonPath
743
+ );
744
+ return true;
745
+ }
746
+ for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
747
+ if (app.packageName === applicationName) {
748
+ logger.debug(
749
+ "[MFE Config] Found application via packageName in config:",
750
+ microfrontendsJsonPath
751
+ );
752
+ return true;
753
+ }
754
+ }
755
+ } catch (error2) {
756
+ logger.debug("[MFE Config] Error checking application in config:", error2);
757
+ }
758
+ return false;
759
+ }
760
+
527
761
  // src/config/microfrontends-config/isomorphic/constants.ts
528
762
  var DEFAULT_LOCAL_PROXY_PORT = 3024;
529
763
  var MFE_APP_PORT_ENV = "MFE_APP_PORT";
@@ -662,26 +896,6 @@ var LocalHost = class extends Host {
662
896
  }
663
897
  };
664
898
 
665
- // src/config/microfrontends-config/isomorphic/utils/hash-application-name.ts
666
- var import_md5 = __toESM(require("md5"), 1);
667
- function hashApplicationName(name) {
668
- if (!name) {
669
- throw new Error("Application name is required to generate hash");
670
- }
671
- return (0, import_md5.default)(name).substring(0, 6).padStart(6, "0");
672
- }
673
-
674
- // src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
675
- var PREFIX = "vc-ap";
676
- function generateAssetPrefixFromName({
677
- name
678
- }) {
679
- if (!name) {
680
- throw new Error("Name is required to generate an asset prefix");
681
- }
682
- return `${PREFIX}-${hashApplicationName(name)}`;
683
- }
684
-
685
899
  // src/config/microfrontends-config/isomorphic/utils/generate-automation-bypass-env-var-name.ts
686
900
  function generateAutomationBypassEnvVarName({
687
901
  name
@@ -899,7 +1113,7 @@ var Application = class {
899
1113
  return this.default;
900
1114
  }
901
1115
  getAssetPrefix() {
902
- const generatedAssetPrefix = generateAssetPrefixFromName({
1116
+ const generatedAssetPrefix = generateDefaultAssetPrefixFromName({
903
1117
  name: this.name
904
1118
  });
905
1119
  if ("assetPrefix" in this.serialized) {
@@ -907,6 +1121,7 @@ var Application = class {
907
1121
  }
908
1122
  return generatedAssetPrefix;
909
1123
  }
1124
+ /** @deprecated Prefer `VERCEL_AUTOMATION_BYPASS_SECRET`. Use this only if each project needs its own distinct bypass secret. */
910
1125
  getAutomationBypassEnvVarName() {
911
1126
  return generateAutomationBypassEnvVarName({ name: this.name });
912
1127
  }
@@ -993,7 +1208,7 @@ var MicrofrontendConfigIsomorphic = class {
993
1208
  };
994
1209
  }
995
1210
  static validate(config) {
996
- const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
1211
+ const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
997
1212
  validateConfigPaths(c.applications);
998
1213
  validateConfigDefaultApplication(c.applications);
999
1214
  return c;
@@ -1002,7 +1217,7 @@ var MicrofrontendConfigIsomorphic = class {
1002
1217
  cookies
1003
1218
  }) {
1004
1219
  return new MicrofrontendConfigIsomorphic({
1005
- config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
1220
+ config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
1006
1221
  overrides: parseOverrides(cookies ?? [])
1007
1222
  });
1008
1223
  }
@@ -1116,59 +1331,18 @@ var MicrofrontendConfigIsomorphic = class {
1116
1331
  }
1117
1332
  };
1118
1333
 
1119
- // src/config/microfrontends/utils/find-config.ts
1120
- var import_node_fs = __toESM(require("fs"), 1);
1121
- var import_node_path = require("path");
1122
-
1123
- // src/config/microfrontends/utils/get-config-file-name.ts
1124
- var DEFAULT_CONFIGURATION_FILENAMES = [
1125
- "microfrontends.json",
1126
- "microfrontends.jsonc"
1127
- ];
1128
- function getPossibleConfigurationFilenames({
1129
- customConfigFilename
1130
- }) {
1131
- if (customConfigFilename) {
1132
- if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
1133
- throw new Error(
1134
- `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.`
1135
- );
1136
- }
1137
- return Array.from(
1138
- /* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
1139
- );
1140
- }
1141
- return DEFAULT_CONFIGURATION_FILENAMES;
1142
- }
1143
-
1144
- // src/config/microfrontends/utils/find-config.ts
1145
- function findConfig({
1146
- dir,
1147
- customConfigFilename
1148
- }) {
1149
- for (const filename of getPossibleConfigurationFilenames({
1150
- customConfigFilename
1151
- })) {
1152
- const maybeConfig = (0, import_node_path.join)(dir, filename);
1153
- if (import_node_fs.default.existsSync(maybeConfig)) {
1154
- return maybeConfig;
1155
- }
1156
- }
1157
- return null;
1158
- }
1159
-
1160
1334
  // src/config/microfrontends/utils/find-package-root.ts
1161
- var import_node_fs2 = __toESM(require("fs"), 1);
1162
- var import_node_path2 = __toESM(require("path"), 1);
1335
+ var import_node_fs3 = __toESM(require("fs"), 1);
1336
+ var import_node_path3 = __toESM(require("path"), 1);
1163
1337
  var PACKAGE_JSON = "package.json";
1164
1338
  function findPackageRoot(startDir) {
1165
1339
  let currentDir = startDir || process.cwd();
1166
- while (currentDir !== import_node_path2.default.parse(currentDir).root) {
1167
- const pkgJsonPath = import_node_path2.default.join(currentDir, PACKAGE_JSON);
1168
- if (import_node_fs2.default.existsSync(pkgJsonPath)) {
1340
+ while (currentDir !== import_node_path3.default.parse(currentDir).root) {
1341
+ const pkgJsonPath = import_node_path3.default.join(currentDir, PACKAGE_JSON);
1342
+ if (import_node_fs3.default.existsSync(pkgJsonPath)) {
1169
1343
  return currentDir;
1170
1344
  }
1171
- currentDir = import_node_path2.default.dirname(currentDir);
1345
+ currentDir = import_node_path3.default.dirname(currentDir);
1172
1346
  }
1173
1347
  throw new Error(
1174
1348
  `The root of the package that contains the \`package.json\` file for the \`${startDir}\` directory could not be found.`
@@ -1176,18 +1350,18 @@ function findPackageRoot(startDir) {
1176
1350
  }
1177
1351
 
1178
1352
  // src/config/microfrontends/utils/find-repository-root.ts
1179
- var import_node_fs3 = __toESM(require("fs"), 1);
1180
- var import_node_path3 = __toESM(require("path"), 1);
1353
+ var import_node_fs4 = __toESM(require("fs"), 1);
1354
+ var import_node_path4 = __toESM(require("path"), 1);
1181
1355
  var GIT_DIRECTORY = ".git";
1182
1356
  function hasGitDirectory(dir) {
1183
- const gitPath = import_node_path3.default.join(dir, GIT_DIRECTORY);
1184
- return import_node_fs3.default.existsSync(gitPath) && import_node_fs3.default.statSync(gitPath).isDirectory();
1357
+ const gitPath = import_node_path4.default.join(dir, GIT_DIRECTORY);
1358
+ return import_node_fs4.default.existsSync(gitPath) && import_node_fs4.default.statSync(gitPath).isDirectory();
1185
1359
  }
1186
1360
  function hasPnpmWorkspaces(dir) {
1187
- return import_node_fs3.default.existsSync(import_node_path3.default.join(dir, "pnpm-workspace.yaml"));
1361
+ return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "pnpm-workspace.yaml"));
1188
1362
  }
1189
1363
  function hasPackageJson(dir) {
1190
- return import_node_fs3.default.existsSync(import_node_path3.default.join(dir, "package.json"));
1364
+ return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "package.json"));
1191
1365
  }
1192
1366
  function findRepositoryRoot(startDir) {
1193
1367
  if (process.env.NX_WORKSPACE_ROOT) {
@@ -1195,14 +1369,14 @@ function findRepositoryRoot(startDir) {
1195
1369
  }
1196
1370
  let currentDir = startDir || process.cwd();
1197
1371
  let lastPackageJsonDir = null;
1198
- while (currentDir !== import_node_path3.default.parse(currentDir).root) {
1372
+ while (currentDir !== import_node_path4.default.parse(currentDir).root) {
1199
1373
  if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
1200
1374
  return currentDir;
1201
1375
  }
1202
1376
  if (hasPackageJson(currentDir)) {
1203
1377
  lastPackageJsonDir = currentDir;
1204
1378
  }
1205
- currentDir = import_node_path3.default.dirname(currentDir);
1379
+ currentDir = import_node_path4.default.dirname(currentDir);
1206
1380
  }
1207
1381
  if (lastPackageJsonDir) {
1208
1382
  return lastPackageJsonDir;
@@ -1213,8 +1387,8 @@ function findRepositoryRoot(startDir) {
1213
1387
  }
1214
1388
 
1215
1389
  // src/config/microfrontends/utils/get-application-context.ts
1216
- var import_node_fs4 = __toESM(require("fs"), 1);
1217
- var import_node_path4 = __toESM(require("path"), 1);
1390
+ var import_node_fs5 = __toESM(require("fs"), 1);
1391
+ var import_node_path5 = __toESM(require("path"), 1);
1218
1392
  function getApplicationContext(opts) {
1219
1393
  if (opts?.appName) {
1220
1394
  logger.debug(
@@ -1244,8 +1418,8 @@ function getApplicationContext(opts) {
1244
1418
  };
1245
1419
  }
1246
1420
  try {
1247
- const vercelProjectJsonPath = import_node_fs4.default.readFileSync(
1248
- import_node_path4.default.join(opts?.packageRoot || ".", ".vercel", "project.json"),
1421
+ const vercelProjectJsonPath = import_node_fs5.default.readFileSync(
1422
+ import_node_path5.default.join(opts?.packageRoot || ".", ".vercel", "project.json"),
1249
1423
  "utf-8"
1250
1424
  );
1251
1425
  const projectJson = JSON.parse(vercelProjectJsonPath);
@@ -1262,8 +1436,8 @@ function getApplicationContext(opts) {
1262
1436
  } catch (_) {
1263
1437
  }
1264
1438
  try {
1265
- const packageJsonString = import_node_fs4.default.readFileSync(
1266
- import_node_path4.default.join(opts?.packageRoot || ".", "package.json"),
1439
+ const packageJsonString = import_node_fs5.default.readFileSync(
1440
+ import_node_path5.default.join(opts?.packageRoot || ".", "package.json"),
1267
1441
  "utf-8"
1268
1442
  );
1269
1443
  const packageJson = JSON.parse(packageJsonString);
@@ -1289,179 +1463,6 @@ function getApplicationContext(opts) {
1289
1463
  }
1290
1464
  }
1291
1465
 
1292
- // src/config/microfrontends/utils/infer-microfrontends-location.ts
1293
- var import_node_fs5 = require("fs");
1294
- var import_node_path5 = require("path");
1295
- var import_fast_glob = __toESM(require("fast-glob"), 1);
1296
- var import_jsonc_parser2 = require("jsonc-parser");
1297
- var configCache = {};
1298
- function findPackageWithMicrofrontendsConfig({
1299
- repositoryRoot,
1300
- applicationContext,
1301
- customConfigFilename
1302
- }) {
1303
- const applicationName = applicationContext.name;
1304
- logger.debug(
1305
- "[MFE Config] Searching repository for configs containing application:",
1306
- applicationName
1307
- );
1308
- try {
1309
- const microfrontendsJsonPaths = import_fast_glob.default.globSync(
1310
- `**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
1311
- {
1312
- cwd: repositoryRoot,
1313
- absolute: true,
1314
- onlyFiles: true,
1315
- followSymbolicLinks: false,
1316
- ignore: ["**/node_modules/**", "**/.git/**"]
1317
- }
1318
- );
1319
- logger.debug(
1320
- "[MFE Config] Found",
1321
- microfrontendsJsonPaths.length,
1322
- "config file(s) in repository"
1323
- );
1324
- const matchingPaths = [];
1325
- for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
1326
- if (doesApplicationExistInConfig(microfrontendsJsonPath, applicationName)) {
1327
- matchingPaths.push(microfrontendsJsonPath);
1328
- }
1329
- }
1330
- logger.debug(
1331
- "[MFE Config] Total matching config files:",
1332
- matchingPaths.length
1333
- );
1334
- if (matchingPaths.length > 1) {
1335
- throw new MicrofrontendError(
1336
- `Found multiple \`microfrontends.json\` files in the repository referencing the application "${applicationName}", but only one is allowed.
1337
- ${matchingPaths.join("\n \u2022 ")}`,
1338
- { type: "config", subtype: "inference_failed" }
1339
- );
1340
- }
1341
- if (matchingPaths.length === 0) {
1342
- if (repositoryRoot && doesMisplacedConfigExist(
1343
- repositoryRoot,
1344
- applicationName,
1345
- customConfigFilename
1346
- )) {
1347
- logger.debug(
1348
- "[MFE Config] Found misplaced config in wrong .vercel directory in repository"
1349
- );
1350
- const misplacedConfigPath = (0, import_node_path5.join)(
1351
- repositoryRoot,
1352
- ".vercel",
1353
- customConfigFilename || "microfrontends.json"
1354
- );
1355
- throw new MicrofrontendError(
1356
- `Unable to automatically infer the location of the \`microfrontends.json\` file.
1357
-
1358
- A microfrontends config was found in the \`.vercel\` directory at the repository root: ${misplacedConfigPath}
1359
- However, in a monorepo, the config file should be placed in the \`.vercel\` directory in your application directory instead.
1360
-
1361
- To fix this:
1362
- 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
1363
- 2. If manually defined, move the config file to the \`.vercel\` directory in your application
1364
- 3. Alternatively, set the VC_MICROFRONTENDS_CONFIG environment variable to the correct path
1365
-
1366
- For more information, see: https://vercel.com/docs/cli/project-linking`,
1367
- { type: "config", subtype: "inference_failed" }
1368
- );
1369
- }
1370
- let additionalErrorMessage = "";
1371
- if (microfrontendsJsonPaths.length > 0) {
1372
- if (!applicationContext.projectName) {
1373
- additionalErrorMessage = `
1374
-
1375
- 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.`;
1376
- } else {
1377
- additionalErrorMessage = `
1378
-
1379
- Names of applications in \`microfrontends.json\` must match the Vercel Project name (${applicationContext.projectName}).`;
1380
- }
1381
- }
1382
- throw new MicrofrontendError(
1383
- `Could not find a \`microfrontends.json\` file in the repository that contains the "${applicationName}" application.${additionalErrorMessage}
1384
-
1385
- 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.
1386
-
1387
- 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.
1388
-
1389
- If you suspect this is thrown in error, please reach out to the Vercel team.`,
1390
- { type: "config", subtype: "inference_failed" }
1391
- );
1392
- }
1393
- const [packageJsonPath] = matchingPaths;
1394
- return (0, import_node_path5.dirname)(packageJsonPath);
1395
- } catch (error2) {
1396
- if (error2 instanceof MicrofrontendError) {
1397
- throw error2;
1398
- }
1399
- return null;
1400
- }
1401
- }
1402
- function inferMicrofrontendsLocation(opts) {
1403
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
1404
- if (configCache[cacheKey]) {
1405
- return configCache[cacheKey];
1406
- }
1407
- const result = findPackageWithMicrofrontendsConfig(opts);
1408
- if (!result) {
1409
- throw new MicrofrontendError(
1410
- `Could not infer the location of the \`microfrontends.json\` file for application "${opts.applicationContext.name}" starting in directory "${opts.repositoryRoot}".`,
1411
- { type: "config", subtype: "inference_failed" }
1412
- );
1413
- }
1414
- configCache[cacheKey] = result;
1415
- return result;
1416
- }
1417
- function existsSync(path7) {
1418
- try {
1419
- (0, import_node_fs5.statSync)(path7);
1420
- return true;
1421
- } catch (_) {
1422
- return false;
1423
- }
1424
- }
1425
- function doesMisplacedConfigExist(repositoryRoot, applicationName, customConfigFilename) {
1426
- logger.debug(
1427
- "[MFE Config] Looking for misplaced config in wrong .vercel directory"
1428
- );
1429
- const misplacedConfigPath = (0, import_node_path5.join)(
1430
- repositoryRoot,
1431
- ".vercel",
1432
- customConfigFilename || "microfrontends.json"
1433
- );
1434
- return existsSync(misplacedConfigPath) && doesApplicationExistInConfig(misplacedConfigPath, applicationName);
1435
- }
1436
- function doesApplicationExistInConfig(microfrontendsJsonPath, applicationName) {
1437
- try {
1438
- const microfrontendsJsonContent = (0, import_node_fs5.readFileSync)(
1439
- microfrontendsJsonPath,
1440
- "utf-8"
1441
- );
1442
- const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
1443
- if (microfrontendsJson.applications[applicationName]) {
1444
- logger.debug(
1445
- "[MFE Config] Found application in config:",
1446
- microfrontendsJsonPath
1447
- );
1448
- return true;
1449
- }
1450
- for (const [_, app] of Object.entries(microfrontendsJson.applications)) {
1451
- if (app.packageName === applicationName) {
1452
- logger.debug(
1453
- "[MFE Config] Found application via packageName in config:",
1454
- microfrontendsJsonPath
1455
- );
1456
- return true;
1457
- }
1458
- }
1459
- } catch (error2) {
1460
- logger.debug("[MFE Config] Error checking application in config:", error2);
1461
- }
1462
- return false;
1463
- }
1464
-
1465
1466
  // src/config/microfrontends/utils/is-monorepo.ts
1466
1467
  var import_node_fs6 = __toESM(require("fs"), 1);
1467
1468
  var import_node_path6 = __toESM(require("path"), 1);
@@ -2032,7 +2033,13 @@ var localAuthHtml = ({
2032
2033
  override
2033
2034
  }) => {
2034
2035
  const intro = override ? `<b><code>${app}</code></b> is overriding to a protected deployment <a target="_blank" href="https://${override}">${override}</a>.` : `<b><code>${app}</code></b> is falling back to a protected deployment <a target="_blank" href="https://${hostname}">${hostname}</a>.`;
2035
- const content = automationBypass ? `<b><code>${automationBypassEnvVarName}</code></b> is set with the value <b><code>${automationBypass}</code></b>, please verify this value equals the <a href="https://vercel.com/docs/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation">Protection Bypass for Automation</a> for the Vercel project hosting the deployment.` : `To access, set a local environment variable <b><code>${automationBypassEnvVarName}</code></b> with the value of the <a href="https://vercel.com/docs/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation">Protection Bypass for Automation</a> for the Vercel project hosting the deployment.`;
2036
+ const bypassDocsLink = `<a href="https://vercel.com/docs/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation">Protection Bypass for Automation</a>`;
2037
+ const content = automationBypass ? `<span><b><code>${automationBypassEnvVarName}</code></b> is set with the value <b><code>${automationBypass}</code></b>, please verify this value is also configured as a ${bypassDocsLink} secret in the <b><code>${app}</code></b> Vercel project.</span>` : `To access, follow these steps:
2038
+ <ol>
2039
+ <li>In the <b><code>${defaultApp}</code></b> Vercel project, go to Settings \u2192 Deployment Protection \u2192 ensure ${bypassDocsLink} is enabled and a secret exists (add one if not). Copy the secret.</li>
2040
+ <li>In the <b><code>${app}</code></b> Vercel project, go to Settings \u2192 Deployment Protection \u2192 add a new secret with the copied secret from <b><code>${defaultApp}</code></b>.</li>
2041
+ <li>Add <b><code>${automationBypassEnvVarName}=&lt;secret&gt;</code></b> to the <b><code>${defaultApp}</code></b> local environment file (e.g. <b><code>.env.local</code></b>).</li>
2042
+ </ol>`;
2036
2043
  const action = override ? `<buttton onClick="clearOverride()" class="button">Clear Override</button>` : "";
2037
2044
  return `<!DOCTYPE html>
2038
2045
  <html lang="en">
@@ -2344,13 +2351,11 @@ var localAuthHtml = ({
2344
2351
  <body>
2345
2352
  <div class="container">
2346
2353
  <main>
2347
- <p class="devinfo-container">
2354
+ <div class="devinfo-container">
2348
2355
  <span>${intro}</span>
2349
2356
  <br/>
2350
- <span>${content}</span>
2351
- <br/>
2352
- <span>The environment variable should be set in the default app <b><code>${defaultApp}</code></b>, where the local proxy is running.</span>
2353
- </p>
2357
+ <div>${content}</div>
2358
+ </div>
2354
2359
 
2355
2360
  <a href="https://vercel.com/docs/microfrontends/local-development#falling-back-to-protected-deployments"><div class="note">Click here to learn more about setting up the environment variable.</div></a>
2356
2361
 
@@ -2793,7 +2798,9 @@ var LocalProxy = class {
2793
2798
  if (target.protocol === "https") {
2794
2799
  const { hostname, port, path: path7 } = target;
2795
2800
  const app = this.router.config.getApplication(target.application);
2796
- const automationBypass = process.env[app.getAutomationBypassEnvVarName()];
2801
+ const perAppEnvVarName = app.getAutomationBypassEnvVarName();
2802
+ const automationBypass = process.env[perAppEnvVarName] ?? process.env.VERCEL_AUTOMATION_BYPASS_SECRET;
2803
+ const automationBypassEnvVarName = process.env[perAppEnvVarName] !== void 0 ? perAppEnvVarName : "VERCEL_AUTOMATION_BYPASS_SECRET";
2797
2804
  const cookies = (0, import_cookie.parse)(req.headers.cookie || "");
2798
2805
  const overrideCookieName = getAppEnvOverrideCookieName(
2799
2806
  target.application
@@ -2829,7 +2836,7 @@ var LocalProxy = class {
2829
2836
  app: target.application,
2830
2837
  hostname,
2831
2838
  defaultApp: defaultApp.packageName || defaultApp.name,
2832
- automationBypassEnvVarName: app.getAutomationBypassEnvVarName(),
2839
+ automationBypassEnvVarName,
2833
2840
  automationBypass,
2834
2841
  override: cookies[overrideCookieName]
2835
2842
  })
@@ -3082,7 +3089,7 @@ function main() {
3082
3089
  []
3083
3090
  ).addOption(new import_commander.Option("--names <names...>").hideHelp()).option("--port <port>", "Port proxy will use", (value) => {
3084
3091
  const parsedValue = Number.parseInt(value, 10);
3085
- if (isNaN(parsedValue) || parsedValue <= 0) {
3092
+ if (Number.isNaN(parsedValue) || parsedValue <= 0) {
3086
3093
  throw new Error(
3087
3094
  "The value passed in to --port must be a positive number."
3088
3095
  );