@vercel/microfrontends 2.0.1 → 2.1.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.
@@ -187,22 +187,38 @@ import { readFileSync } from "node:fs";
187
187
  import { parse } from "jsonc-parser";
188
188
  import fg from "fast-glob";
189
189
 
190
- // src/config/constants.ts
191
- var CONFIGURATION_FILENAMES = [
190
+ // src/config/microfrontends/utils/get-config-file-name.ts
191
+ var DEFAULT_CONFIGURATION_FILENAMES = [
192
192
  "microfrontends.jsonc",
193
193
  "microfrontends.json"
194
194
  ];
195
+ function getPossibleConfigurationFilenames({
196
+ customConfigFilename
197
+ }) {
198
+ if (customConfigFilename) {
199
+ if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
200
+ throw new Error(
201
+ `The VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable must end with '.json' or '.jsonc'. Received: ${customConfigFilename}`
202
+ );
203
+ }
204
+ return Array.from(
205
+ /* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
206
+ );
207
+ }
208
+ return DEFAULT_CONFIGURATION_FILENAMES;
209
+ }
195
210
 
196
211
  // src/config/microfrontends/utils/infer-microfrontends-location.ts
197
212
  var configCache = {};
198
213
  function findPackageWithMicrofrontendsConfig({
199
214
  repositoryRoot,
200
- applicationContext
215
+ applicationContext,
216
+ customConfigFilename
201
217
  }) {
202
218
  const applicationName = applicationContext.name;
203
219
  try {
204
220
  const microfrontendsJsonPaths = fg.globSync(
205
- `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
221
+ `**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
206
222
  {
207
223
  cwd: repositoryRoot,
208
224
  absolute: true,
@@ -258,6 +274,8 @@ Names of applications in \`microfrontends.json\` must match the Vercel Project n
258
274
 
259
275
  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.
260
276
 
277
+ 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.
278
+
261
279
  If you suspect this is thrown in error, please reach out to the Vercel team.`,
262
280
  { type: "config", subtype: "inference_failed" }
263
281
  );
@@ -272,7 +290,7 @@ If you suspect this is thrown in error, please reach out to the Vercel team.`,
272
290
  }
273
291
  }
274
292
  function inferMicrofrontendsLocation(opts) {
275
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}`;
293
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
276
294
  if (configCache[cacheKey]) {
277
295
  return configCache[cacheKey];
278
296
  }
@@ -338,8 +356,13 @@ function findPackageRoot(startDir) {
338
356
  // src/config/microfrontends/utils/find-config.ts
339
357
  import fs4 from "node:fs";
340
358
  import { join } from "node:path";
341
- function findConfig({ dir }) {
342
- for (const filename of CONFIGURATION_FILENAMES) {
359
+ function findConfig({
360
+ dir,
361
+ customConfigFilename
362
+ }) {
363
+ for (const filename of getPossibleConfigurationFilenames({
364
+ customConfigFilename
365
+ })) {
343
366
  const maybeConfig = join(dir, filename);
344
367
  if (fs4.existsSync(maybeConfig)) {
345
368
  return maybeConfig;
@@ -1442,7 +1465,11 @@ var MicrofrontendsServer = class {
1442
1465
  appName,
1443
1466
  packageRoot
1444
1467
  });
1445
- const maybeConfig = findConfig({ dir: packageRoot });
1468
+ const customConfigFilename = process.env.VC_MICROFRONTENDS_CONFIG_FILE_NAME;
1469
+ const maybeConfig = findConfig({
1470
+ dir: packageRoot,
1471
+ customConfigFilename
1472
+ });
1446
1473
  if (maybeConfig) {
1447
1474
  return MicrofrontendsServer.fromFile({
1448
1475
  filePath: maybeConfig,
@@ -1451,11 +1478,9 @@ var MicrofrontendsServer = class {
1451
1478
  }
1452
1479
  const repositoryRoot = findRepositoryRoot();
1453
1480
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1454
- if (typeof process.env.VC_MICROFRONTENDS_CONFIG === "string") {
1455
- const maybeConfigFromEnv = resolve(
1456
- packageRoot,
1457
- process.env.VC_MICROFRONTENDS_CONFIG
1458
- );
1481
+ const configFromEnv = process.env.VC_MICROFRONTENDS_CONFIG;
1482
+ if (typeof configFromEnv === "string") {
1483
+ const maybeConfigFromEnv = resolve(packageRoot, configFromEnv);
1459
1484
  if (maybeConfigFromEnv) {
1460
1485
  return MicrofrontendsServer.fromFile({
1461
1486
  filePath: maybeConfigFromEnv,
@@ -1464,7 +1489,8 @@ var MicrofrontendsServer = class {
1464
1489
  }
1465
1490
  } else {
1466
1491
  const maybeConfigFromVercel = findConfig({
1467
- dir: join2(packageRoot, ".vercel")
1492
+ dir: join2(packageRoot, ".vercel"),
1493
+ customConfigFilename
1468
1494
  });
1469
1495
  if (maybeConfigFromVercel) {
1470
1496
  return MicrofrontendsServer.fromFile({
@@ -1475,9 +1501,13 @@ var MicrofrontendsServer = class {
1475
1501
  if (isMonorepo2) {
1476
1502
  const defaultPackage = inferMicrofrontendsLocation({
1477
1503
  repositoryRoot,
1478
- applicationContext
1504
+ applicationContext,
1505
+ customConfigFilename
1506
+ });
1507
+ const maybeConfigFromDefault = findConfig({
1508
+ dir: defaultPackage,
1509
+ customConfigFilename
1479
1510
  });
1480
- const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1481
1511
  if (maybeConfigFromDefault) {
1482
1512
  return MicrofrontendsServer.fromFile({
1483
1513
  filePath: maybeConfigFromDefault,