@vercel/microfrontends 2.0.0 → 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.
Files changed (46) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -5
  3. package/dist/bin/cli.cjs +226 -79
  4. package/dist/config.cjs +5 -4
  5. package/dist/config.cjs.map +1 -1
  6. package/dist/config.js +5 -4
  7. package/dist/config.js.map +1 -1
  8. package/dist/experimental/sveltekit.cjs +51 -20
  9. package/dist/experimental/sveltekit.cjs.map +1 -1
  10. package/dist/experimental/sveltekit.js +51 -20
  11. package/dist/experimental/sveltekit.js.map +1 -1
  12. package/dist/experimental/vite.cjs +51 -20
  13. package/dist/experimental/vite.cjs.map +1 -1
  14. package/dist/experimental/vite.js +51 -20
  15. package/dist/experimental/vite.js.map +1 -1
  16. package/dist/microfrontends/server.cjs +51 -20
  17. package/dist/microfrontends/server.cjs.map +1 -1
  18. package/dist/microfrontends/server.js +51 -20
  19. package/dist/microfrontends/server.js.map +1 -1
  20. package/dist/microfrontends/utils.cjs +32 -7
  21. package/dist/microfrontends/utils.cjs.map +1 -1
  22. package/dist/microfrontends/utils.d.ts +8 -2
  23. package/dist/microfrontends/utils.js +31 -7
  24. package/dist/microfrontends/utils.js.map +1 -1
  25. package/dist/next/client.cjs +1 -1
  26. package/dist/next/client.cjs.map +1 -1
  27. package/dist/next/client.d.ts +15 -1
  28. package/dist/next/client.js +1 -1
  29. package/dist/next/client.js.map +1 -1
  30. package/dist/next/config.cjs +62 -20
  31. package/dist/next/config.cjs.map +1 -1
  32. package/dist/next/config.js +62 -20
  33. package/dist/next/config.js.map +1 -1
  34. package/dist/next/middleware.cjs +5 -4
  35. package/dist/next/middleware.cjs.map +1 -1
  36. package/dist/next/middleware.js +5 -4
  37. package/dist/next/middleware.js.map +1 -1
  38. package/dist/next/testing.cjs +5 -4
  39. package/dist/next/testing.cjs.map +1 -1
  40. package/dist/next/testing.js +5 -4
  41. package/dist/next/testing.js.map +1 -1
  42. package/dist/utils/mfe-port.cjs +66 -40
  43. package/dist/utils/mfe-port.cjs.map +1 -1
  44. package/dist/utils/mfe-port.js +66 -40
  45. package/dist/utils/mfe-port.js.map +1 -1
  46. package/package.json +4 -4
@@ -223,22 +223,38 @@ var import_node_fs2 = require("fs");
223
223
  var import_jsonc_parser = require("jsonc-parser");
224
224
  var import_fast_glob = __toESM(require("fast-glob"), 1);
225
225
 
226
- // src/config/constants.ts
227
- var CONFIGURATION_FILENAMES = [
226
+ // src/config/microfrontends/utils/get-config-file-name.ts
227
+ var DEFAULT_CONFIGURATION_FILENAMES = [
228
228
  "microfrontends.jsonc",
229
229
  "microfrontends.json"
230
230
  ];
231
+ function getPossibleConfigurationFilenames({
232
+ customConfigFilename
233
+ }) {
234
+ if (customConfigFilename) {
235
+ if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
236
+ throw new Error(
237
+ `The VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable must end with '.json' or '.jsonc'. Received: ${customConfigFilename}`
238
+ );
239
+ }
240
+ return Array.from(
241
+ /* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
242
+ );
243
+ }
244
+ return DEFAULT_CONFIGURATION_FILENAMES;
245
+ }
231
246
 
232
247
  // src/config/microfrontends/utils/infer-microfrontends-location.ts
233
248
  var configCache = {};
234
249
  function findPackageWithMicrofrontendsConfig({
235
250
  repositoryRoot,
236
- applicationContext
251
+ applicationContext,
252
+ customConfigFilename
237
253
  }) {
238
254
  const applicationName = applicationContext.name;
239
255
  try {
240
256
  const microfrontendsJsonPaths = import_fast_glob.default.globSync(
241
- `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
257
+ `**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
242
258
  {
243
259
  cwd: repositoryRoot,
244
260
  absolute: true,
@@ -294,6 +310,8 @@ Names of applications in \`microfrontends.json\` must match the Vercel Project n
294
310
 
295
311
  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.
296
312
 
313
+ 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.
314
+
297
315
  If you suspect this is thrown in error, please reach out to the Vercel team.`,
298
316
  { type: "config", subtype: "inference_failed" }
299
317
  );
@@ -308,7 +326,7 @@ If you suspect this is thrown in error, please reach out to the Vercel team.`,
308
326
  }
309
327
  }
310
328
  function inferMicrofrontendsLocation(opts) {
311
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}`;
329
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
312
330
  if (configCache[cacheKey]) {
313
331
  return configCache[cacheKey];
314
332
  }
@@ -374,8 +392,13 @@ function findPackageRoot(startDir) {
374
392
  // src/config/microfrontends/utils/find-config.ts
375
393
  var import_node_fs5 = __toESM(require("fs"), 1);
376
394
  var import_node_path5 = require("path");
377
- function findConfig({ dir }) {
378
- for (const filename of CONFIGURATION_FILENAMES) {
395
+ function findConfig({
396
+ dir,
397
+ customConfigFilename
398
+ }) {
399
+ for (const filename of getPossibleConfigurationFilenames({
400
+ customConfigFilename
401
+ })) {
379
402
  const maybeConfig = (0, import_node_path5.join)(dir, filename);
380
403
  if (import_node_fs5.default.existsSync(maybeConfig)) {
381
404
  return maybeConfig;
@@ -442,7 +465,7 @@ var MicrofrontendConfigClient = class {
442
465
  static fromEnv(config) {
443
466
  if (!config) {
444
467
  throw new Error(
445
- "Could not construct MicrofrontendConfigClient: configuration is empty or undefined. Did you set up your application with `withMicrofrontends`?"
468
+ "Could not construct MicrofrontendConfigClient: configuration is empty or undefined. Did you set up your application with `withMicrofrontends`? Is the local proxy running and this application is being accessed via the proxy port? See https://vercel.com/docs/microfrontends/local-development#setting-up-microfrontends-proxy"
446
469
  );
447
470
  }
448
471
  return new MicrofrontendConfigClient(JSON.parse(config));
@@ -582,10 +605,11 @@ function validatePathExpression(path6) {
582
605
  }
583
606
  if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
584
607
  // Only limited regex is supported for now, due to performance considerations
585
- !/^(?<allowed>[\w]+(?:\|[^:|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^:|()]+)*)\)\.\*$/.test(
586
- token.pattern
608
+ // Allows all letters, numbers, and hyphens. Other characters must be escaped.
609
+ !/^(?<allowed>[\w-~]+(?:\|[^:|()]+)+)$|^\(\?!(?<disallowed>[\w-~]+(?:\|[^:|()]+)*)\)\.\*$/.test(
610
+ token.pattern.replace(/\\./g, "")
587
611
  )) {
588
- return `Path ${path6} cannot use unsupported regular expression wildcard`;
612
+ return `Path ${path6} cannot use unsupported regular expression wildcard. If the path includes special characters, they must be escaped with backslash (e.g. '\\(')`;
589
613
  }
590
614
  if (token.modifier && i !== tokens.length - 1) {
591
615
  return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
@@ -1477,7 +1501,11 @@ var MicrofrontendsServer = class {
1477
1501
  appName,
1478
1502
  packageRoot
1479
1503
  });
1480
- const maybeConfig = findConfig({ dir: packageRoot });
1504
+ const customConfigFilename = process.env.VC_MICROFRONTENDS_CONFIG_FILE_NAME;
1505
+ const maybeConfig = findConfig({
1506
+ dir: packageRoot,
1507
+ customConfigFilename
1508
+ });
1481
1509
  if (maybeConfig) {
1482
1510
  return MicrofrontendsServer.fromFile({
1483
1511
  filePath: maybeConfig,
@@ -1486,11 +1514,9 @@ var MicrofrontendsServer = class {
1486
1514
  }
1487
1515
  const repositoryRoot = findRepositoryRoot();
1488
1516
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1489
- if (typeof process.env.VC_MICROFRONTENDS_CONFIG === "string") {
1490
- const maybeConfigFromEnv = (0, import_node_path8.resolve)(
1491
- packageRoot,
1492
- process.env.VC_MICROFRONTENDS_CONFIG
1493
- );
1517
+ const configFromEnv = process.env.VC_MICROFRONTENDS_CONFIG;
1518
+ if (typeof configFromEnv === "string") {
1519
+ const maybeConfigFromEnv = (0, import_node_path8.resolve)(packageRoot, configFromEnv);
1494
1520
  if (maybeConfigFromEnv) {
1495
1521
  return MicrofrontendsServer.fromFile({
1496
1522
  filePath: maybeConfigFromEnv,
@@ -1499,7 +1525,8 @@ var MicrofrontendsServer = class {
1499
1525
  }
1500
1526
  } else {
1501
1527
  const maybeConfigFromVercel = findConfig({
1502
- dir: (0, import_node_path8.join)(packageRoot, ".vercel")
1528
+ dir: (0, import_node_path8.join)(packageRoot, ".vercel"),
1529
+ customConfigFilename
1503
1530
  });
1504
1531
  if (maybeConfigFromVercel) {
1505
1532
  return MicrofrontendsServer.fromFile({
@@ -1510,9 +1537,13 @@ var MicrofrontendsServer = class {
1510
1537
  if (isMonorepo2) {
1511
1538
  const defaultPackage = inferMicrofrontendsLocation({
1512
1539
  repositoryRoot,
1513
- applicationContext
1540
+ applicationContext,
1541
+ customConfigFilename
1542
+ });
1543
+ const maybeConfigFromDefault = findConfig({
1544
+ dir: defaultPackage,
1545
+ customConfigFilename
1514
1546
  });
1515
- const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1516
1547
  if (maybeConfigFromDefault) {
1517
1548
  return MicrofrontendsServer.fromFile({
1518
1549
  filePath: maybeConfigFromDefault,