@vercel/microfrontends 2.0.1 → 2.1.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.
@@ -204,22 +204,38 @@ import { readFileSync } from "node:fs";
204
204
  import { parse } from "jsonc-parser";
205
205
  import fg from "fast-glob";
206
206
 
207
- // src/config/constants.ts
208
- var CONFIGURATION_FILENAMES = [
207
+ // src/config/microfrontends/utils/get-config-file-name.ts
208
+ var DEFAULT_CONFIGURATION_FILENAMES = [
209
209
  "microfrontends.jsonc",
210
210
  "microfrontends.json"
211
211
  ];
212
+ function getPossibleConfigurationFilenames({
213
+ customConfigFilename
214
+ }) {
215
+ if (customConfigFilename) {
216
+ if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
217
+ throw new Error(
218
+ `The VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable must end with '.json' or '.jsonc'. Received: ${customConfigFilename}`
219
+ );
220
+ }
221
+ return Array.from(
222
+ /* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
223
+ );
224
+ }
225
+ return DEFAULT_CONFIGURATION_FILENAMES;
226
+ }
212
227
 
213
228
  // src/config/microfrontends/utils/infer-microfrontends-location.ts
214
229
  var configCache = {};
215
230
  function findPackageWithMicrofrontendsConfig({
216
231
  repositoryRoot,
217
- applicationContext
232
+ applicationContext,
233
+ customConfigFilename
218
234
  }) {
219
235
  const applicationName = applicationContext.name;
220
236
  try {
221
237
  const microfrontendsJsonPaths = fg.globSync(
222
- `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
238
+ `**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
223
239
  {
224
240
  cwd: repositoryRoot,
225
241
  absolute: true,
@@ -275,6 +291,8 @@ Names of applications in \`microfrontends.json\` must match the Vercel Project n
275
291
 
276
292
  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.
277
293
 
294
+ 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.
295
+
278
296
  If you suspect this is thrown in error, please reach out to the Vercel team.`,
279
297
  { type: "config", subtype: "inference_failed" }
280
298
  );
@@ -289,7 +307,7 @@ If you suspect this is thrown in error, please reach out to the Vercel team.`,
289
307
  }
290
308
  }
291
309
  function inferMicrofrontendsLocation(opts) {
292
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}`;
310
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
293
311
  if (configCache[cacheKey]) {
294
312
  return configCache[cacheKey];
295
313
  }
@@ -355,8 +373,13 @@ function findPackageRoot(startDir) {
355
373
  // src/config/microfrontends/utils/find-config.ts
356
374
  import fs4 from "node:fs";
357
375
  import { join } from "node:path";
358
- function findConfig({ dir }) {
359
- for (const filename of CONFIGURATION_FILENAMES) {
376
+ function findConfig({
377
+ dir,
378
+ customConfigFilename
379
+ }) {
380
+ for (const filename of getPossibleConfigurationFilenames({
381
+ customConfigFilename
382
+ })) {
360
383
  const maybeConfig = join(dir, filename);
361
384
  if (fs4.existsSync(maybeConfig)) {
362
385
  return maybeConfig;
@@ -1459,7 +1482,11 @@ var MicrofrontendsServer = class {
1459
1482
  appName,
1460
1483
  packageRoot
1461
1484
  });
1462
- const maybeConfig = findConfig({ dir: packageRoot });
1485
+ const customConfigFilename = process.env.VC_MICROFRONTENDS_CONFIG_FILE_NAME;
1486
+ const maybeConfig = findConfig({
1487
+ dir: packageRoot,
1488
+ customConfigFilename
1489
+ });
1463
1490
  if (maybeConfig) {
1464
1491
  return MicrofrontendsServer.fromFile({
1465
1492
  filePath: maybeConfig,
@@ -1468,11 +1495,9 @@ var MicrofrontendsServer = class {
1468
1495
  }
1469
1496
  const repositoryRoot = findRepositoryRoot();
1470
1497
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1471
- if (typeof process.env.VC_MICROFRONTENDS_CONFIG === "string") {
1472
- const maybeConfigFromEnv = resolve(
1473
- packageRoot,
1474
- process.env.VC_MICROFRONTENDS_CONFIG
1475
- );
1498
+ const configFromEnv = process.env.VC_MICROFRONTENDS_CONFIG;
1499
+ if (typeof configFromEnv === "string") {
1500
+ const maybeConfigFromEnv = resolve(packageRoot, configFromEnv);
1476
1501
  if (maybeConfigFromEnv) {
1477
1502
  return MicrofrontendsServer.fromFile({
1478
1503
  filePath: maybeConfigFromEnv,
@@ -1481,7 +1506,8 @@ var MicrofrontendsServer = class {
1481
1506
  }
1482
1507
  } else {
1483
1508
  const maybeConfigFromVercel = findConfig({
1484
- dir: join2(packageRoot, ".vercel")
1509
+ dir: join2(packageRoot, ".vercel"),
1510
+ customConfigFilename
1485
1511
  });
1486
1512
  if (maybeConfigFromVercel) {
1487
1513
  return MicrofrontendsServer.fromFile({
@@ -1492,9 +1518,13 @@ var MicrofrontendsServer = class {
1492
1518
  if (isMonorepo2) {
1493
1519
  const defaultPackage = inferMicrofrontendsLocation({
1494
1520
  repositoryRoot,
1495
- applicationContext
1521
+ applicationContext,
1522
+ customConfigFilename
1523
+ });
1524
+ const maybeConfigFromDefault = findConfig({
1525
+ dir: defaultPackage,
1526
+ customConfigFilename
1496
1527
  });
1497
- const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1498
1528
  if (maybeConfigFromDefault) {
1499
1529
  return MicrofrontendsServer.fromFile({
1500
1530
  filePath: maybeConfigFromDefault,
@@ -1733,6 +1763,14 @@ function transform6(args) {
1733
1763
  pathname: "/.well-known/vercel/flags"
1734
1764
  }
1735
1765
  });
1766
+ rewrites.set(
1767
+ `/${app.getAssetPrefix()}/.well-known/vercel/rate-limit-api/:path*`,
1768
+ {
1769
+ destination: {
1770
+ pathname: "/.well-known/vercel/rate-limit-api/:path*"
1771
+ }
1772
+ }
1773
+ );
1736
1774
  rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
1737
1775
  destination: {
1738
1776
  pathname: "/_vercel/:path*"
@@ -1920,6 +1958,9 @@ function setEnvironment({
1920
1958
  removeFlaggedPaths: true
1921
1959
  }).serialize()
1922
1960
  ),
1961
+ ...app.getAssetPrefix() ? {
1962
+ NEXT_PUBLIC_VERCEL_FIREWALL_PATH_PREFIX: `/${app.getAssetPrefix()}`
1963
+ } : {},
1923
1964
  ...process.env.ROUTE_OBSERVABILITY_TO_THIS_PROJECT && app.getAssetPrefix() ? {
1924
1965
  NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH: `/${app.getAssetPrefix()}/_vercel`
1925
1966
  } : {}