@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
@@ -33,9 +33,6 @@ __export(vite_exports, {
33
33
  microfrontends: () => microfrontends
34
34
  });
35
35
  module.exports = __toCommonJS(vite_exports);
36
- var import_node_fs9 = require("fs");
37
- var import_node_path9 = require("path");
38
- var import_node_process = require("process");
39
36
 
40
37
  // src/config/microfrontends/server/index.ts
41
38
  var import_node_fs7 = __toESM(require("fs"), 1);
@@ -275,16 +272,17 @@ var validateConfigPaths = (applicationConfigsById) => {
275
272
  const maybeError = validatePathExpression(path5);
276
273
  if (maybeError) {
277
274
  errors.push(maybeError);
278
- }
279
- const existing = pathsByApplicationId.get(path5);
280
- if (existing) {
281
- existing.applications.push(id);
282
275
  } else {
283
- pathsByApplicationId.set(path5, {
284
- applications: [id],
285
- matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
286
- applicationId: id
287
- });
276
+ const existing = pathsByApplicationId.get(path5);
277
+ if (existing) {
278
+ existing.applications.push(id);
279
+ } else {
280
+ pathsByApplicationId.set(path5, {
281
+ applications: [id],
282
+ matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
283
+ applicationId: id
284
+ });
285
+ }
288
286
  }
289
287
  }
290
288
  }
@@ -324,26 +322,38 @@ var validateConfigPaths = (applicationConfigsById) => {
324
322
  };
325
323
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
326
324
  function validatePathExpression(path5) {
327
- const tokens = (0, import_path_to_regexp2.parse)(path5);
328
- for (let i = 0; i < tokens.length; i++) {
329
- const token = tokens[i];
330
- if (token === void 0) {
331
- return `token ${i} in ${path5} is undefined, this shouldn't happen`;
332
- }
333
- if (typeof token !== "string") {
334
- if (token.pattern !== PATH_DEFAULT_PATTERN) {
335
- return `Path ${path5} cannot use a regular expression wildcard`;
336
- }
337
- if (token.prefix !== "/") {
338
- return `Wildcard :${token.name} must be immediately after a / in ${path5}`;
339
- }
340
- if (token.suffix) {
341
- return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
325
+ try {
326
+ const tokens = (0, import_path_to_regexp2.parse)(path5);
327
+ if (/(?<!\\)\{/.test(path5)) {
328
+ return `Optional paths are not supported: ${path5}`;
329
+ }
330
+ if (/(?<!\\|\()\?/.test(path5)) {
331
+ return `Optional paths are not supported: ${path5}`;
332
+ }
333
+ if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path5)) {
334
+ return `Only one wildcard is allowed per path segment: ${path5}`;
335
+ }
336
+ for (let i = 0; i < tokens.length; i++) {
337
+ const token = tokens[i];
338
+ if (token === void 0) {
339
+ return `token ${i} in ${path5} is undefined, this shouldn't happen`;
342
340
  }
343
- if (token.modifier && i !== tokens.length - 1) {
344
- return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path5}. Modifiers are only allowed in the last path component`;
341
+ if (typeof token !== "string") {
342
+ if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
343
+ // Only limited regex is supported for now, due to performance considerations
344
+ !/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
345
+ token.pattern
346
+ )) {
347
+ return `Path ${path5} cannot use unsupported regular expression wildcard`;
348
+ }
349
+ if (token.modifier && i !== tokens.length - 1) {
350
+ return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path5}. Modifiers are only allowed in the last path component`;
351
+ }
345
352
  }
346
353
  }
354
+ } catch (e) {
355
+ const message = e instanceof Error ? e.message : String(e);
356
+ return `Path ${path5} could not be parsed into regexp: ${message}`;
347
357
  }
348
358
  return void 0;
349
359
  }
@@ -697,12 +707,8 @@ var MicrofrontendConfigIsomorphic = class {
697
707
  const skipValidation = opts?.skipValidation ?? [];
698
708
  const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
699
709
  if (isMainConfig(c)) {
700
- if (!skipValidation.includes("paths")) {
701
- validateConfigPaths(c.applications);
702
- }
703
- if (!skipValidation.includes("defaultApplication")) {
704
- validateConfigDefaultApplication(c.applications);
705
- }
710
+ validateConfigPaths(c.applications);
711
+ validateConfigDefaultApplication(c.applications);
706
712
  if (!skipValidation.includes("deprecatedFields")) {
707
713
  validateDeprecatedFields(c);
708
714
  }
@@ -1697,6 +1703,20 @@ function getApplicationContext(opts) {
1697
1703
  }
1698
1704
  }
1699
1705
 
1706
+ // src/vite/detect-framework.ts
1707
+ var import_node_fs9 = require("fs");
1708
+ var import_node_path9 = require("path");
1709
+ var import_node_process = require("process");
1710
+ function detectFramework() {
1711
+ if ((0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "svelte.config.js"))) {
1712
+ return "sveltekit";
1713
+ }
1714
+ if ((0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "react-router.config.js")) || (0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "react-router.config.ts"))) {
1715
+ return "react-router";
1716
+ }
1717
+ return "unknown";
1718
+ }
1719
+
1700
1720
  // src/vite/index.ts
1701
1721
  function microfrontends(opts) {
1702
1722
  const { name: fromApp } = getApplicationContext();
@@ -1706,22 +1726,44 @@ function microfrontends(opts) {
1706
1726
  }
1707
1727
  });
1708
1728
  const app = microfrontendsObj.config.getApplication(fromApp);
1729
+ if (app.isDefault() && opts?.basePath) {
1730
+ throw new Error(
1731
+ "`basePath` can not be set for the default microfrontends application."
1732
+ );
1733
+ }
1734
+ if (opts?.basePath && !opts.basePath.startsWith("/")) {
1735
+ throw new Error("`basePath` must start with a `/`");
1736
+ }
1709
1737
  const additionalConfigOptions = {};
1738
+ const framework = detectFramework();
1710
1739
  if (!app.isDefault()) {
1711
1740
  if (opts?.basePath) {
1712
- additionalConfigOptions.base = `/${opts.basePath}`;
1713
- } else {
1714
- const isSvelteKit = (0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "svelte.config.js"));
1715
- if (!isSvelteKit) {
1716
- additionalConfigOptions.experimental = {
1717
- renderBuiltUrl(filename, { type }) {
1718
- if (type === "asset") {
1719
- return `/${app.getAssetPrefix()}/${filename}`;
1720
- }
1721
- }
1722
- };
1741
+ if (framework !== "react-router" || !process.env.VERCEL_ENV) {
1742
+ let basePath = opts.basePath;
1743
+ if (process.env.NODE_ENV === "production" && !basePath.endsWith("/")) {
1744
+ basePath = `${basePath}/`;
1745
+ }
1746
+ additionalConfigOptions.base = basePath;
1723
1747
  }
1748
+ } else if (framework !== "sveltekit") {
1749
+ additionalConfigOptions.experimental = {
1750
+ renderBuiltUrl(filename, { type }) {
1751
+ if (type === "asset") {
1752
+ return `/${app.getAssetPrefix()}/${filename}`;
1753
+ }
1754
+ }
1755
+ };
1724
1756
  }
1757
+ if (framework === "react-router") {
1758
+ additionalConfigOptions.build = {
1759
+ assetsDir: `./${opts?.basePath ?? app.getAssetPrefix()}`
1760
+ };
1761
+ }
1762
+ }
1763
+ if (app.development.local.port) {
1764
+ additionalConfigOptions.server = {
1765
+ port: app.development.local.port
1766
+ };
1725
1767
  }
1726
1768
  return {
1727
1769
  name: "vite-plugin-vercel-microfrontends",