@vercel/microfrontends 2.3.0 → 2.3.1

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 (42) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/bin/cli.cjs +260 -260
  3. package/dist/config.cjs +21 -21
  4. package/dist/config.cjs.map +1 -1
  5. package/dist/config.js +21 -21
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +258 -258
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +238 -238
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +258 -258
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.js +238 -238
  14. package/dist/experimental/vite.js.map +1 -1
  15. package/dist/microfrontends/server.cjs +258 -258
  16. package/dist/microfrontends/server.cjs.map +1 -1
  17. package/dist/microfrontends/server.js +238 -238
  18. package/dist/microfrontends/server.js.map +1 -1
  19. package/dist/microfrontends/utils.cjs +22 -0
  20. package/dist/microfrontends/utils.cjs.map +1 -1
  21. package/dist/microfrontends/utils.d.ts +5 -1
  22. package/dist/microfrontends/utils.js +21 -0
  23. package/dist/microfrontends/utils.js.map +1 -1
  24. package/dist/next/client.cjs.map +1 -1
  25. package/dist/next/client.js.map +1 -1
  26. package/dist/next/config.cjs +258 -258
  27. package/dist/next/config.cjs.map +1 -1
  28. package/dist/next/config.js +238 -238
  29. package/dist/next/config.js.map +1 -1
  30. package/dist/next/middleware.cjs +21 -21
  31. package/dist/next/middleware.cjs.map +1 -1
  32. package/dist/next/middleware.js +21 -21
  33. package/dist/next/middleware.js.map +1 -1
  34. package/dist/next/testing.cjs +21 -21
  35. package/dist/next/testing.cjs.map +1 -1
  36. package/dist/next/testing.js +21 -21
  37. package/dist/next/testing.js.map +1 -1
  38. package/dist/utils/mfe-port.cjs +258 -258
  39. package/dist/utils/mfe-port.cjs.map +1 -1
  40. package/dist/utils/mfe-port.js +238 -238
  41. package/dist/utils/mfe-port.js.map +1 -1
  42. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vercel/microfrontends
2
2
 
3
+ ## 2.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 382fe66: Expose generateDefaultAssetPrefixFromName
8
+
3
9
  ## 2.3.0
4
10
 
5
11
  ### Minor Changes
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.1",
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) {
@@ -993,7 +1207,7 @@ var MicrofrontendConfigIsomorphic = class {
993
1207
  };
994
1208
  }
995
1209
  static validate(config) {
996
- const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
1210
+ const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
997
1211
  validateConfigPaths(c.applications);
998
1212
  validateConfigDefaultApplication(c.applications);
999
1213
  return c;
@@ -1002,7 +1216,7 @@ var MicrofrontendConfigIsomorphic = class {
1002
1216
  cookies
1003
1217
  }) {
1004
1218
  return new MicrofrontendConfigIsomorphic({
1005
- config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
1219
+ config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
1006
1220
  overrides: parseOverrides(cookies ?? [])
1007
1221
  });
1008
1222
  }
@@ -1116,59 +1330,18 @@ var MicrofrontendConfigIsomorphic = class {
1116
1330
  }
1117
1331
  };
1118
1332
 
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
1333
  // 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);
1334
+ var import_node_fs3 = __toESM(require("fs"), 1);
1335
+ var import_node_path3 = __toESM(require("path"), 1);
1163
1336
  var PACKAGE_JSON = "package.json";
1164
1337
  function findPackageRoot(startDir) {
1165
1338
  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)) {
1339
+ while (currentDir !== import_node_path3.default.parse(currentDir).root) {
1340
+ const pkgJsonPath = import_node_path3.default.join(currentDir, PACKAGE_JSON);
1341
+ if (import_node_fs3.default.existsSync(pkgJsonPath)) {
1169
1342
  return currentDir;
1170
1343
  }
1171
- currentDir = import_node_path2.default.dirname(currentDir);
1344
+ currentDir = import_node_path3.default.dirname(currentDir);
1172
1345
  }
1173
1346
  throw new Error(
1174
1347
  `The root of the package that contains the \`package.json\` file for the \`${startDir}\` directory could not be found.`
@@ -1176,18 +1349,18 @@ function findPackageRoot(startDir) {
1176
1349
  }
1177
1350
 
1178
1351
  // 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);
1352
+ var import_node_fs4 = __toESM(require("fs"), 1);
1353
+ var import_node_path4 = __toESM(require("path"), 1);
1181
1354
  var GIT_DIRECTORY = ".git";
1182
1355
  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();
1356
+ const gitPath = import_node_path4.default.join(dir, GIT_DIRECTORY);
1357
+ return import_node_fs4.default.existsSync(gitPath) && import_node_fs4.default.statSync(gitPath).isDirectory();
1185
1358
  }
1186
1359
  function hasPnpmWorkspaces(dir) {
1187
- return import_node_fs3.default.existsSync(import_node_path3.default.join(dir, "pnpm-workspace.yaml"));
1360
+ return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "pnpm-workspace.yaml"));
1188
1361
  }
1189
1362
  function hasPackageJson(dir) {
1190
- return import_node_fs3.default.existsSync(import_node_path3.default.join(dir, "package.json"));
1363
+ return import_node_fs4.default.existsSync(import_node_path4.default.join(dir, "package.json"));
1191
1364
  }
1192
1365
  function findRepositoryRoot(startDir) {
1193
1366
  if (process.env.NX_WORKSPACE_ROOT) {
@@ -1195,14 +1368,14 @@ function findRepositoryRoot(startDir) {
1195
1368
  }
1196
1369
  let currentDir = startDir || process.cwd();
1197
1370
  let lastPackageJsonDir = null;
1198
- while (currentDir !== import_node_path3.default.parse(currentDir).root) {
1371
+ while (currentDir !== import_node_path4.default.parse(currentDir).root) {
1199
1372
  if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
1200
1373
  return currentDir;
1201
1374
  }
1202
1375
  if (hasPackageJson(currentDir)) {
1203
1376
  lastPackageJsonDir = currentDir;
1204
1377
  }
1205
- currentDir = import_node_path3.default.dirname(currentDir);
1378
+ currentDir = import_node_path4.default.dirname(currentDir);
1206
1379
  }
1207
1380
  if (lastPackageJsonDir) {
1208
1381
  return lastPackageJsonDir;
@@ -1213,8 +1386,8 @@ function findRepositoryRoot(startDir) {
1213
1386
  }
1214
1387
 
1215
1388
  // 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);
1389
+ var import_node_fs5 = __toESM(require("fs"), 1);
1390
+ var import_node_path5 = __toESM(require("path"), 1);
1218
1391
  function getApplicationContext(opts) {
1219
1392
  if (opts?.appName) {
1220
1393
  logger.debug(
@@ -1244,8 +1417,8 @@ function getApplicationContext(opts) {
1244
1417
  };
1245
1418
  }
1246
1419
  try {
1247
- const vercelProjectJsonPath = import_node_fs4.default.readFileSync(
1248
- import_node_path4.default.join(opts?.packageRoot || ".", ".vercel", "project.json"),
1420
+ const vercelProjectJsonPath = import_node_fs5.default.readFileSync(
1421
+ import_node_path5.default.join(opts?.packageRoot || ".", ".vercel", "project.json"),
1249
1422
  "utf-8"
1250
1423
  );
1251
1424
  const projectJson = JSON.parse(vercelProjectJsonPath);
@@ -1262,8 +1435,8 @@ function getApplicationContext(opts) {
1262
1435
  } catch (_) {
1263
1436
  }
1264
1437
  try {
1265
- const packageJsonString = import_node_fs4.default.readFileSync(
1266
- import_node_path4.default.join(opts?.packageRoot || ".", "package.json"),
1438
+ const packageJsonString = import_node_fs5.default.readFileSync(
1439
+ import_node_path5.default.join(opts?.packageRoot || ".", "package.json"),
1267
1440
  "utf-8"
1268
1441
  );
1269
1442
  const packageJson = JSON.parse(packageJsonString);
@@ -1289,179 +1462,6 @@ function getApplicationContext(opts) {
1289
1462
  }
1290
1463
  }
1291
1464
 
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
1465
  // src/config/microfrontends/utils/is-monorepo.ts
1466
1466
  var import_node_fs6 = __toESM(require("fs"), 1);
1467
1467
  var import_node_path6 = __toESM(require("path"), 1);
@@ -3082,7 +3082,7 @@ function main() {
3082
3082
  []
3083
3083
  ).addOption(new import_commander.Option("--names <names...>").hideHelp()).option("--port <port>", "Port proxy will use", (value) => {
3084
3084
  const parsedValue = Number.parseInt(value, 10);
3085
- if (isNaN(parsedValue) || parsedValue <= 0) {
3085
+ if (Number.isNaN(parsedValue) || parsedValue <= 0) {
3086
3086
  throw new Error(
3087
3087
  "The value passed in to --port must be a positive number."
3088
3088
  );