@vercel/microfrontends 1.0.1-canary.1 → 1.0.1-canary.3

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 (45) hide show
  1. package/dist/bin/cli.cjs +43 -33
  2. package/dist/config.cjs +41 -32
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +1 -1
  5. package/dist/config.js +41 -32
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +41 -32
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +41 -32
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +88 -46
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.d.ts +1 -1
  14. package/dist/experimental/vite.js +88 -48
  15. package/dist/experimental/vite.js.map +1 -1
  16. package/dist/{index-d5994ac5.d.ts → index-2b59c627.d.ts} +1 -1
  17. package/dist/microfrontends/server.cjs +41 -32
  18. package/dist/microfrontends/server.cjs.map +1 -1
  19. package/dist/microfrontends/server.d.ts +1 -1
  20. package/dist/microfrontends/server.js +41 -32
  21. package/dist/microfrontends/server.js.map +1 -1
  22. package/dist/microfrontends.cjs +41 -32
  23. package/dist/microfrontends.cjs.map +1 -1
  24. package/dist/microfrontends.d.ts +1 -1
  25. package/dist/microfrontends.js +41 -32
  26. package/dist/microfrontends.js.map +1 -1
  27. package/dist/next/config.cjs +205 -131
  28. package/dist/next/config.cjs.map +1 -1
  29. package/dist/next/config.d.ts +7 -1
  30. package/dist/next/config.js +205 -131
  31. package/dist/next/config.js.map +1 -1
  32. package/dist/next/middleware.cjs +41 -32
  33. package/dist/next/middleware.cjs.map +1 -1
  34. package/dist/next/middleware.js +41 -32
  35. package/dist/next/middleware.js.map +1 -1
  36. package/dist/next/testing.cjs +41 -32
  37. package/dist/next/testing.cjs.map +1 -1
  38. package/dist/next/testing.d.ts +2 -2
  39. package/dist/next/testing.js +42 -33
  40. package/dist/next/testing.js.map +1 -1
  41. package/dist/utils/mfe-port.cjs +41 -32
  42. package/dist/utils/mfe-port.cjs.map +1 -1
  43. package/dist/utils/mfe-port.js +41 -32
  44. package/dist/utils/mfe-port.js.map +1 -1
  45. package/package.json +2 -1
@@ -1,8 +1,3 @@
1
- // src/vite/index.ts
2
- import { existsSync } from "node:fs";
3
- import { join as join3 } from "node:path";
4
- import { cwd } from "node:process";
5
-
6
1
  // src/config/microfrontends/server/index.ts
7
2
  import fs5 from "node:fs";
8
3
  import { dirname as dirname3, join as join2 } from "node:path";
@@ -241,16 +236,17 @@ var validateConfigPaths = (applicationConfigsById) => {
241
236
  const maybeError = validatePathExpression(path5);
242
237
  if (maybeError) {
243
238
  errors.push(maybeError);
244
- }
245
- const existing = pathsByApplicationId.get(path5);
246
- if (existing) {
247
- existing.applications.push(id);
248
239
  } else {
249
- pathsByApplicationId.set(path5, {
250
- applications: [id],
251
- matcher: pathToRegexp2(path5),
252
- applicationId: id
253
- });
240
+ const existing = pathsByApplicationId.get(path5);
241
+ if (existing) {
242
+ existing.applications.push(id);
243
+ } else {
244
+ pathsByApplicationId.set(path5, {
245
+ applications: [id],
246
+ matcher: pathToRegexp2(path5),
247
+ applicationId: id
248
+ });
249
+ }
254
250
  }
255
251
  }
256
252
  }
@@ -290,26 +286,38 @@ var validateConfigPaths = (applicationConfigsById) => {
290
286
  };
291
287
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
292
288
  function validatePathExpression(path5) {
293
- const tokens = parsePathRegexp(path5);
294
- for (let i = 0; i < tokens.length; i++) {
295
- const token = tokens[i];
296
- if (token === void 0) {
297
- return `token ${i} in ${path5} is undefined, this shouldn't happen`;
298
- }
299
- if (typeof token !== "string") {
300
- if (token.pattern !== PATH_DEFAULT_PATTERN) {
301
- return `Path ${path5} cannot use a regular expression wildcard`;
302
- }
303
- if (token.prefix !== "/") {
304
- return `Wildcard :${token.name} must be immediately after a / in ${path5}`;
305
- }
306
- if (token.suffix) {
307
- return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
289
+ try {
290
+ const tokens = parsePathRegexp(path5);
291
+ if (/(?<!\\)\{/.test(path5)) {
292
+ return `Optional paths are not supported: ${path5}`;
293
+ }
294
+ if (/(?<!\\|\()\?/.test(path5)) {
295
+ return `Optional paths are not supported: ${path5}`;
296
+ }
297
+ if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path5)) {
298
+ return `Only one wildcard is allowed per path segment: ${path5}`;
299
+ }
300
+ for (let i = 0; i < tokens.length; i++) {
301
+ const token = tokens[i];
302
+ if (token === void 0) {
303
+ return `token ${i} in ${path5} is undefined, this shouldn't happen`;
308
304
  }
309
- if (token.modifier && i !== tokens.length - 1) {
310
- return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path5}. Modifiers are only allowed in the last path component`;
305
+ if (typeof token !== "string") {
306
+ if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
307
+ // Only limited regex is supported for now, due to performance considerations
308
+ !/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
309
+ token.pattern
310
+ )) {
311
+ return `Path ${path5} cannot use unsupported regular expression wildcard`;
312
+ }
313
+ if (token.modifier && i !== tokens.length - 1) {
314
+ return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path5}. Modifiers are only allowed in the last path component`;
315
+ }
311
316
  }
312
317
  }
318
+ } catch (e) {
319
+ const message = e instanceof Error ? e.message : String(e);
320
+ return `Path ${path5} could not be parsed into regexp: ${message}`;
313
321
  }
314
322
  return void 0;
315
323
  }
@@ -663,12 +671,8 @@ var MicrofrontendConfigIsomorphic = class {
663
671
  const skipValidation = opts?.skipValidation ?? [];
664
672
  const c = typeof config === "string" ? parse(config) : config;
665
673
  if (isMainConfig(c)) {
666
- if (!skipValidation.includes("paths")) {
667
- validateConfigPaths(c.applications);
668
- }
669
- if (!skipValidation.includes("defaultApplication")) {
670
- validateConfigDefaultApplication(c.applications);
671
- }
674
+ validateConfigPaths(c.applications);
675
+ validateConfigDefaultApplication(c.applications);
672
676
  if (!skipValidation.includes("deprecatedFields")) {
673
677
  validateDeprecatedFields(c);
674
678
  }
@@ -1663,6 +1667,20 @@ function getApplicationContext(opts) {
1663
1667
  }
1664
1668
  }
1665
1669
 
1670
+ // src/vite/detect-framework.ts
1671
+ import { existsSync } from "node:fs";
1672
+ import { join as join3 } from "node:path";
1673
+ import { cwd } from "node:process";
1674
+ function detectFramework() {
1675
+ if (existsSync(join3(cwd(), "svelte.config.js"))) {
1676
+ return "sveltekit";
1677
+ }
1678
+ if (existsSync(join3(cwd(), "react-router.config.js")) || existsSync(join3(cwd(), "react-router.config.ts"))) {
1679
+ return "react-router";
1680
+ }
1681
+ return "unknown";
1682
+ }
1683
+
1666
1684
  // src/vite/index.ts
1667
1685
  function microfrontends(opts) {
1668
1686
  const { name: fromApp } = getApplicationContext();
@@ -1672,23 +1690,45 @@ function microfrontends(opts) {
1672
1690
  }
1673
1691
  });
1674
1692
  const app = microfrontendsObj.config.getApplication(fromApp);
1693
+ if (app.isDefault() && opts?.basePath) {
1694
+ throw new Error(
1695
+ "`basePath` can not be set for the default microfrontends application."
1696
+ );
1697
+ }
1698
+ if (opts?.basePath && !opts.basePath.startsWith("/")) {
1699
+ throw new Error("`basePath` must start with a `/`");
1700
+ }
1675
1701
  const additionalConfigOptions = {};
1702
+ const framework = detectFramework();
1676
1703
  if (!app.isDefault()) {
1677
1704
  if (opts?.basePath) {
1678
- additionalConfigOptions.base = `/${opts.basePath}`;
1679
- } else {
1680
- const isSvelteKit = existsSync(join3(cwd(), "svelte.config.js"));
1681
- if (!isSvelteKit) {
1682
- additionalConfigOptions.experimental = {
1683
- renderBuiltUrl(filename, { type }) {
1684
- if (type === "asset") {
1685
- return `/${app.getAssetPrefix()}/${filename}`;
1686
- }
1687
- }
1688
- };
1705
+ if (framework !== "react-router" || !process.env.VERCEL_ENV) {
1706
+ let basePath = opts.basePath;
1707
+ if (process.env.NODE_ENV === "production" && !basePath.endsWith("/")) {
1708
+ basePath = `${basePath}/`;
1709
+ }
1710
+ additionalConfigOptions.base = basePath;
1689
1711
  }
1712
+ } else if (framework !== "sveltekit") {
1713
+ additionalConfigOptions.experimental = {
1714
+ renderBuiltUrl(filename, { type }) {
1715
+ if (type === "asset") {
1716
+ return `/${app.getAssetPrefix()}/${filename}`;
1717
+ }
1718
+ }
1719
+ };
1720
+ }
1721
+ if (framework === "react-router") {
1722
+ additionalConfigOptions.build = {
1723
+ assetsDir: `./${opts?.basePath ?? app.getAssetPrefix()}`
1724
+ };
1690
1725
  }
1691
1726
  }
1727
+ if (app.development.local.port) {
1728
+ additionalConfigOptions.server = {
1729
+ port: app.development.local.port
1730
+ };
1731
+ }
1692
1732
  return {
1693
1733
  name: "vite-plugin-vercel-microfrontends",
1694
1734
  config: () => {