@vercel/microfrontends 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +3 -3
  2. package/dist/bin/cli.cjs +85 -60
  3. package/dist/config/client.d.ts +1 -1
  4. package/dist/config.cjs.map +1 -1
  5. package/dist/config.d.ts +1 -1
  6. package/dist/config.js.map +1 -1
  7. package/dist/{index-83133f2d.d.ts → index-bf67a461.d.ts} +3 -10
  8. package/dist/next/client.cjs +1 -1
  9. package/dist/next/client.cjs.map +1 -1
  10. package/dist/next/client.js +1 -1
  11. package/dist/next/client.js.map +1 -1
  12. package/dist/next/endpoints.cjs.map +1 -1
  13. package/dist/next/endpoints.d.ts +1 -1
  14. package/dist/next/endpoints.js.map +1 -1
  15. package/dist/next/middleware.cjs +0 -29
  16. package/dist/next/middleware.cjs.map +1 -1
  17. package/dist/next/middleware.js +0 -29
  18. package/dist/next/middleware.js.map +1 -1
  19. package/dist/{types-a995174e.d.ts → types-a29d224a.d.ts} +1 -7
  20. package/dist/{types-15b7f215.d.ts → types-cfe3308b.d.ts} +1 -1
  21. package/dist/types-fc30696d.d.ts +11 -0
  22. package/dist/utils/mfe-port.cjs +70 -56
  23. package/dist/utils/mfe-port.cjs.map +1 -1
  24. package/dist/utils/mfe-port.js +67 -53
  25. package/dist/utils/mfe-port.js.map +1 -1
  26. package/dist/v2/config.cjs +0 -14
  27. package/dist/v2/config.cjs.map +1 -1
  28. package/dist/v2/config.d.ts +4 -3
  29. package/dist/v2/config.js +0 -14
  30. package/dist/v2/config.js.map +1 -1
  31. package/dist/v2/microfrontends/server.cjs +68 -54
  32. package/dist/v2/microfrontends/server.cjs.map +1 -1
  33. package/dist/v2/microfrontends/server.d.ts +6 -5
  34. package/dist/v2/microfrontends/server.js +65 -51
  35. package/dist/v2/microfrontends/server.js.map +1 -1
  36. package/dist/v2/microfrontends.cjs +0 -14
  37. package/dist/v2/microfrontends.cjs.map +1 -1
  38. package/dist/v2/microfrontends.d.ts +4 -3
  39. package/dist/v2/microfrontends.js +0 -14
  40. package/dist/v2/microfrontends.js.map +1 -1
  41. package/dist/v2/next/client.cjs +1 -1
  42. package/dist/v2/next/client.cjs.map +1 -1
  43. package/dist/v2/next/client.js +1 -1
  44. package/dist/v2/next/client.js.map +1 -1
  45. package/dist/v2/next/config.cjs +106 -60
  46. package/dist/v2/next/config.cjs.map +1 -1
  47. package/dist/v2/next/config.js +103 -57
  48. package/dist/v2/next/config.js.map +1 -1
  49. package/dist/v2/next/endpoints.cjs.map +1 -1
  50. package/dist/v2/next/endpoints.d.ts +13 -2
  51. package/dist/v2/next/endpoints.js.map +1 -1
  52. package/dist/v2/next/middleware.cjs +10 -54
  53. package/dist/v2/next/middleware.cjs.map +1 -1
  54. package/dist/v2/next/middleware.d.ts +7 -2
  55. package/dist/v2/next/middleware.js +10 -54
  56. package/dist/v2/next/middleware.js.map +1 -1
  57. package/dist/v2/next/testing.cjs +992 -0
  58. package/dist/v2/next/testing.cjs.map +1 -0
  59. package/dist/v2/next/testing.d.ts +55 -0
  60. package/dist/v2/next/testing.js +961 -0
  61. package/dist/v2/next/testing.js.map +1 -0
  62. package/dist/v2/overrides.d.ts +3 -3
  63. package/dist/v2/routing.cjs +19 -0
  64. package/dist/v2/routing.cjs.map +1 -0
  65. package/dist/v2/routing.d.ts +26 -0
  66. package/dist/v2/routing.js +1 -0
  67. package/dist/v2/routing.js.map +1 -0
  68. package/dist/v2/schema.cjs.map +1 -1
  69. package/dist/v2/schema.d.ts +1 -1
  70. package/dist/validation.cjs +0 -4
  71. package/dist/validation.cjs.map +1 -1
  72. package/dist/validation.d.ts +0 -6
  73. package/dist/validation.js +0 -4
  74. package/dist/validation.js.map +1 -1
  75. package/package.json +20 -5
  76. package/schema/schema-v2.json +0 -4
@@ -1,6 +1,6 @@
1
1
  // src/utils/mfe-port.ts
2
2
  import path6 from "node:path";
3
- import fs7 from "node:fs";
3
+ import fs8 from "node:fs";
4
4
 
5
5
  // src/config/types.ts
6
6
  var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
@@ -1146,8 +1146,8 @@ var MicrofrontendConfig = class extends MicrofrontendConfigCommon {
1146
1146
  };
1147
1147
 
1148
1148
  // src/config-v2/microfrontends/server/index.ts
1149
- import fs6 from "node:fs";
1150
- import { dirname as dirname4, join } from "node:path";
1149
+ import fs7 from "node:fs";
1150
+ import { dirname as dirname4, join as join2 } from "node:path";
1151
1151
 
1152
1152
  // src/config-v2/overrides/constants.ts
1153
1153
  var OVERRIDES_COOKIE_PREFIX2 = "vercel-micro-frontends-override";
@@ -1494,19 +1494,6 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
1494
1494
  );
1495
1495
  }
1496
1496
  };
1497
- var validateConfigOptions = (options) => {
1498
- var _a;
1499
- if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
1500
- if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
1501
- options.vercel.previewDeploymentSuffix
1502
- )) {
1503
- throw new MicrofrontendError2(
1504
- `Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
1505
- { type: "config", subtype: "invalid_preview_deployment_suffix" }
1506
- );
1507
- }
1508
- }
1509
- };
1510
1497
 
1511
1498
  // src/config-v2/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
1512
1499
  var PREFIX = "vc-ap";
@@ -1725,7 +1712,6 @@ var MicrofrontendConfigIsomorphic = class {
1725
1712
  validateConfigPaths(c.applications);
1726
1713
  validateConfigDefaultApplication(c.applications);
1727
1714
  }
1728
- validateConfigOptions(c.options);
1729
1715
  return c;
1730
1716
  }
1731
1717
  static fromEnv({
@@ -2001,29 +1987,39 @@ function findPackagePath(opts) {
2001
1987
  // src/config-v2/microfrontends/utils/find-default-package.ts
2002
1988
  import { dirname as dirname3 } from "node:path";
2003
1989
  import { readFileSync as readFileSync2 } from "node:fs";
1990
+ import { parse as parse3 } from "jsonc-parser";
2004
1991
  import fg2 from "fast-glob";
1992
+
1993
+ // src/config-v2/constants.ts
1994
+ var CONFIGURATION_FILENAMES = [
1995
+ "microfrontends.jsonc",
1996
+ "microfrontends.json"
1997
+ ];
1998
+
1999
+ // src/config-v2/microfrontends/utils/find-default-package.ts
2005
2000
  var configCache2 = {};
2006
2001
  function findDefaultMicrofrontendsPackages({
2007
2002
  repositoryRoot,
2008
2003
  applicationName
2009
2004
  }) {
2010
2005
  try {
2011
- const microfrontendsJsonPaths = fg2.globSync("**/microfrontends.json", {
2012
- cwd: repositoryRoot,
2013
- absolute: true,
2014
- onlyFiles: true,
2015
- followSymbolicLinks: false,
2016
- ignore: ["**/node_modules/**", "**/.git/**"]
2017
- });
2006
+ const microfrontendsJsonPaths = fg2.globSync(
2007
+ `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
2008
+ {
2009
+ cwd: repositoryRoot,
2010
+ absolute: true,
2011
+ onlyFiles: true,
2012
+ followSymbolicLinks: false,
2013
+ ignore: ["**/node_modules/**", "**/.git/**"]
2014
+ }
2015
+ );
2018
2016
  const matchingPaths = [];
2019
2017
  for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
2020
2018
  const microfrontendsJsonContent = readFileSync2(
2021
2019
  microfrontendsJsonPath,
2022
2020
  "utf-8"
2023
2021
  );
2024
- const microfrontendsJson = JSON.parse(
2025
- microfrontendsJsonContent
2026
- );
2022
+ const microfrontendsJson = parse3(microfrontendsJsonContent);
2027
2023
  if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
2028
2024
  matchingPaths.push(microfrontendsJsonPath);
2029
2025
  }
@@ -2053,7 +2049,7 @@ function findDefaultMicrofrontendsPackage(opts) {
2053
2049
  const result = findDefaultMicrofrontendsPackages(opts);
2054
2050
  if (!result) {
2055
2051
  throw new Error(
2056
- `Error trying to resolve the main microfrontends.json configuration`
2052
+ `Error trying to resolve the main microfrontends configuration`
2057
2053
  );
2058
2054
  }
2059
2055
  configCache2[cacheKey] = result;
@@ -2105,8 +2101,21 @@ function findPackageRoot(startDir) {
2105
2101
  );
2106
2102
  }
2107
2103
 
2104
+ // src/config-v2/microfrontends/utils/find-config.ts
2105
+ import fs6 from "node:fs";
2106
+ import { join } from "node:path";
2107
+ function findConfig({ dir }) {
2108
+ for (const filename of CONFIGURATION_FILENAMES) {
2109
+ const maybeConfig = join(dir, filename);
2110
+ if (fs6.existsSync(maybeConfig)) {
2111
+ return maybeConfig;
2112
+ }
2113
+ }
2114
+ return null;
2115
+ }
2116
+
2108
2117
  // src/config-v2/microfrontends/server/validation.ts
2109
- import { parse as parse3 } from "jsonc-parser";
2118
+ import { parse as parse4 } from "jsonc-parser";
2110
2119
  import { Ajv as Ajv2 } from "ajv";
2111
2120
 
2112
2121
  // schema/schema-v2.json
@@ -2167,10 +2176,6 @@ var schema_v2_default = {
2167
2176
  VercelOptions: {
2168
2177
  type: "object",
2169
2178
  properties: {
2170
- previewDeploymentSuffix: {
2171
- type: "string",
2172
- description: "If your team uses a custom Preview Deployment Suffix, please specify it here. See https://vercel.com/docs/deployments/preview-deployment-suffix. The default is `vercel.app`."
2173
- },
2174
2179
  teamSlug: {
2175
2180
  type: "string",
2176
2181
  description: "Team slug for the Vercel team"
@@ -2364,7 +2369,7 @@ var SCHEMA2 = schema_v2_default;
2364
2369
 
2365
2370
  // src/config-v2/microfrontends/server/validation.ts
2366
2371
  function validateSchema2(configString) {
2367
- const parsedConfig = parse3(configString);
2372
+ const parsedConfig = parse4(configString);
2368
2373
  const ajv = new Ajv2();
2369
2374
  const validate = ajv.compile(SCHEMA2);
2370
2375
  const isValid = validate(parsedConfig);
@@ -2386,8 +2391,8 @@ var MicrofrontendsServer = class extends Microfrontends {
2386
2391
  pretty: true
2387
2392
  }) {
2388
2393
  const outputPath = getOutputFilePath();
2389
- fs6.mkdirSync(dirname4(outputPath), { recursive: true });
2390
- fs6.writeFileSync(
2394
+ fs7.mkdirSync(dirname4(outputPath), { recursive: true });
2395
+ fs7.writeFileSync(
2391
2396
  outputPath,
2392
2397
  JSON.stringify(
2393
2398
  this.config.toSchemaJson(),
@@ -2450,8 +2455,8 @@ var MicrofrontendsServer = class extends Microfrontends {
2450
2455
  return config;
2451
2456
  }
2452
2457
  /**
2453
- * Looks up the configuration by inferring the package root and looking for a microfrontends.json file. If a file is not found,
2454
- * it will look for a package in the repository with a microfrontends.json file that contains the current application
2458
+ * Looks up the configuration by inferring the package root and looking for a microfrontends config file. If a file is not found,
2459
+ * it will look for a package in the repository with a microfrontends file that contains the current application
2455
2460
  * and use that configuration.
2456
2461
  *
2457
2462
  * This can return either a Child or Main configuration.
@@ -2473,16 +2478,16 @@ var MicrofrontendsServer = class extends Microfrontends {
2473
2478
  }
2474
2479
  try {
2475
2480
  const packageRoot = findPackageRoot(directory);
2476
- const packageJsonPath = join(packageRoot, "package.json");
2481
+ const packageJsonPath = join2(packageRoot, "package.json");
2477
2482
  const packageJson = JSON.parse(
2478
- fs6.readFileSync(packageJsonPath, "utf-8")
2483
+ fs7.readFileSync(packageJsonPath, "utf-8")
2479
2484
  );
2480
2485
  if (!packageJson.name) {
2481
2486
  throw new Error(`No name found in package.json at ${packageJsonPath}`);
2482
2487
  }
2483
2488
  const configMeta = meta ?? { fromApp: packageJson.name };
2484
- const maybeConfig = join(packageRoot, "microfrontends.json");
2485
- if (fs6.existsSync(maybeConfig)) {
2489
+ const maybeConfig = findConfig({ dir: packageRoot });
2490
+ if (maybeConfig) {
2486
2491
  return MicrofrontendsServer.fromFile({
2487
2492
  filePath: maybeConfig,
2488
2493
  cookies,
@@ -2497,12 +2502,15 @@ var MicrofrontendsServer = class extends Microfrontends {
2497
2502
  repositoryRoot,
2498
2503
  applicationName: packageJson.name
2499
2504
  });
2500
- return MicrofrontendsServer.fromFile({
2501
- filePath: join(defaultPackage, "microfrontends.json"),
2502
- cookies,
2503
- meta: configMeta,
2504
- options
2505
- });
2505
+ const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
2506
+ if (maybeConfigFromDefault) {
2507
+ return MicrofrontendsServer.fromFile({
2508
+ filePath: maybeConfigFromDefault,
2509
+ cookies,
2510
+ meta: configMeta,
2511
+ options
2512
+ });
2513
+ }
2506
2514
  }
2507
2515
  throw new Error("Unable to infer");
2508
2516
  } catch (e) {
@@ -2522,7 +2530,7 @@ var MicrofrontendsServer = class extends Microfrontends {
2522
2530
  options
2523
2531
  }) {
2524
2532
  try {
2525
- const configJson = fs6.readFileSync(filePath, "utf-8");
2533
+ const configJson = fs7.readFileSync(filePath, "utf-8");
2526
2534
  const config = MicrofrontendsServer.validate(configJson);
2527
2535
  if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
2528
2536
  const repositoryRoot = findRepositoryRoot();
@@ -2538,9 +2546,15 @@ var MicrofrontendsServer = class extends Microfrontends {
2538
2546
  { type: "config", subtype: "not_found" }
2539
2547
  );
2540
2548
  }
2541
- const mainConfigPath = join(packagePath, "microfrontends.json");
2549
+ const maybeConfig = findConfig({ dir: packagePath });
2550
+ if (!maybeConfig) {
2551
+ throw new MicrofrontendError2(
2552
+ `Could not find microfrontends configuration in ${packagePath}`,
2553
+ { type: "config", subtype: "not_found" }
2554
+ );
2555
+ }
2542
2556
  return MicrofrontendsServer.fromMainConfigFile({
2543
- filePath: mainConfigPath,
2557
+ filePath: maybeConfig,
2544
2558
  overrides: cookies ? parseOverrides(cookies) : void 0
2545
2559
  });
2546
2560
  }
@@ -2564,7 +2578,7 @@ var MicrofrontendsServer = class extends Microfrontends {
2564
2578
  overrides
2565
2579
  }) {
2566
2580
  try {
2567
- const config = fs6.readFileSync(filePath, "utf-8");
2581
+ const config = fs7.readFileSync(filePath, "utf-8");
2568
2582
  const validatedConfig = MicrofrontendsServer.validate(config);
2569
2583
  if (!isMainConfig(validatedConfig)) {
2570
2584
  throw new MicrofrontendError2(
@@ -2614,7 +2628,7 @@ function mfePort(packageDir) {
2614
2628
  }
2615
2629
  function getPackageJson(packageDir) {
2616
2630
  const filePath = path6.join(packageDir, "package.json");
2617
- return JSON.parse(fs7.readFileSync(filePath, "utf-8"));
2631
+ return JSON.parse(fs8.readFileSync(filePath, "utf-8"));
2618
2632
  }
2619
2633
  function loadV2({
2620
2634
  packageDir,