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