@vercel/microfrontends 1.4.0-canary.3 → 1.4.0-canary.5

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 (39) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/bin/cli.cjs +43 -11
  3. package/dist/config.cjs +12 -2
  4. package/dist/config.cjs.map +1 -1
  5. package/dist/config.js +12 -2
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +42 -10
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +43 -11
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +42 -10
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.js +46 -14
  14. package/dist/experimental/vite.js.map +1 -1
  15. package/dist/microfrontends/server.cjs +42 -10
  16. package/dist/microfrontends/server.cjs.map +1 -1
  17. package/dist/microfrontends/server.js +43 -11
  18. package/dist/microfrontends/server.js.map +1 -1
  19. package/dist/next/client.cjs +1 -1
  20. package/dist/next/client.cjs.map +1 -1
  21. package/dist/next/client.js +1 -1
  22. package/dist/next/client.js.map +1 -1
  23. package/dist/next/config.cjs +42 -10
  24. package/dist/next/config.cjs.map +1 -1
  25. package/dist/next/config.js +43 -11
  26. package/dist/next/config.js.map +1 -1
  27. package/dist/next/middleware.cjs +12 -2
  28. package/dist/next/middleware.cjs.map +1 -1
  29. package/dist/next/middleware.js +12 -2
  30. package/dist/next/middleware.js.map +1 -1
  31. package/dist/next/testing.cjs +12 -2
  32. package/dist/next/testing.cjs.map +1 -1
  33. package/dist/next/testing.js +12 -2
  34. package/dist/next/testing.js.map +1 -1
  35. package/dist/utils/mfe-port.cjs +42 -10
  36. package/dist/utils/mfe-port.cjs.map +1 -1
  37. package/dist/utils/mfe-port.js +43 -11
  38. package/dist/utils/mfe-port.js.map +1 -1
  39. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  // src/config/microfrontends/server/index.ts
2
2
  import fs6 from "node:fs";
3
- import { dirname as dirname2 } from "node:path";
3
+ import { dirname as dirname2, join as join2, resolve } from "node:path";
4
4
 
5
5
  // src/config/overrides/constants.ts
6
6
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
@@ -323,6 +323,16 @@ import { parse as parse2 } from "jsonc-parser";
323
323
 
324
324
  // src/config/microfrontends-config/client/index.ts
325
325
  import { pathToRegexp } from "path-to-regexp";
326
+ var regexpCache = /* @__PURE__ */ new Map();
327
+ var getRegexp = (path6) => {
328
+ const existing = regexpCache.get(path6);
329
+ if (existing) {
330
+ return existing;
331
+ }
332
+ const regexp = pathToRegexp(path6);
333
+ regexpCache.set(path6, regexp);
334
+ return regexp;
335
+ };
326
336
  var MicrofrontendConfigClient = class {
327
337
  constructor(config, opts) {
328
338
  this.pathCache = {};
@@ -352,7 +362,7 @@ var MicrofrontendConfigClient = class {
352
362
  );
353
363
  }
354
364
  isEqual(other) {
355
- return JSON.stringify(this.applications) === JSON.stringify(other.applications);
365
+ return this === other || JSON.stringify(this.applications) === JSON.stringify(other.applications);
356
366
  }
357
367
  getApplicationNameForPath(path6) {
358
368
  if (!path6.startsWith("/")) {
@@ -366,7 +376,7 @@ var MicrofrontendConfigClient = class {
366
376
  if (application.routing) {
367
377
  for (const group of application.routing) {
368
378
  for (const childPath of group.paths) {
369
- const regexp = pathToRegexp(childPath);
379
+ const regexp = getRegexp(childPath);
370
380
  if (regexp.test(pathname)) {
371
381
  this.pathCache[path6] = name;
372
382
  return name;
@@ -1368,21 +1378,43 @@ var MicrofrontendsServer = class {
1368
1378
  }
1369
1379
  const repositoryRoot = findRepositoryRoot();
1370
1380
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1371
- if (isMonorepo2) {
1372
- const defaultPackage = inferMicrofrontendsLocation({
1373
- repositoryRoot,
1374
- applicationName: appName
1381
+ if (typeof process.env.VC_MICROFRONTENDS_CONFIG === "string") {
1382
+ const maybeConfigFromEnv = resolve(
1383
+ packageRoot,
1384
+ process.env.VC_MICROFRONTENDS_CONFIG
1385
+ );
1386
+ if (maybeConfigFromEnv) {
1387
+ return MicrofrontendsServer.fromFile({
1388
+ filePath: maybeConfigFromEnv,
1389
+ cookies
1390
+ });
1391
+ }
1392
+ } else {
1393
+ const maybeConfigFromVercel = findConfig({
1394
+ dir: join2(packageRoot, ".vercel")
1375
1395
  });
1376
- const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1377
- if (maybeConfigFromDefault) {
1396
+ if (maybeConfigFromVercel) {
1378
1397
  return MicrofrontendsServer.fromFile({
1379
- filePath: maybeConfigFromDefault,
1398
+ filePath: maybeConfigFromVercel,
1380
1399
  cookies
1381
1400
  });
1382
1401
  }
1402
+ if (isMonorepo2) {
1403
+ const defaultPackage = inferMicrofrontendsLocation({
1404
+ repositoryRoot,
1405
+ applicationName: appName
1406
+ });
1407
+ const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1408
+ if (maybeConfigFromDefault) {
1409
+ return MicrofrontendsServer.fromFile({
1410
+ filePath: maybeConfigFromDefault,
1411
+ cookies
1412
+ });
1413
+ }
1414
+ }
1383
1415
  }
1384
1416
  throw new MicrofrontendError(
1385
- "Unable to automatically infer the location of the `microfrontends.json` file. Microfrontends defined in separate repositories are not supported yet. If you suspect this is thrown in error, please reach out to the Vercel team.",
1417
+ 'Unable to automatically infer the location of the `microfrontends.json` file. 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. If you suspect this is thrown in error, please reach out to the Vercel team.',
1386
1418
  { type: "config", subtype: "inference_failed" }
1387
1419
  );
1388
1420
  } catch (e) {
@@ -1447,13 +1479,13 @@ var MicrofrontendsServer = class {
1447
1479
 
1448
1480
  // src/vite/detect-framework.ts
1449
1481
  import { existsSync } from "node:fs";
1450
- import { join as join2 } from "node:path";
1482
+ import { join as join3 } from "node:path";
1451
1483
  import { cwd } from "node:process";
1452
1484
  function detectFramework() {
1453
- if (existsSync(join2(cwd(), "svelte.config.js"))) {
1485
+ if (existsSync(join3(cwd(), "svelte.config.js"))) {
1454
1486
  return "sveltekit";
1455
1487
  }
1456
- if (existsSync(join2(cwd(), "react-router.config.js")) || existsSync(join2(cwd(), "react-router.config.ts"))) {
1488
+ if (existsSync(join3(cwd(), "react-router.config.js")) || existsSync(join3(cwd(), "react-router.config.ts"))) {
1457
1489
  return "react-router";
1458
1490
  }
1459
1491
  return "unknown";