@vercel/microfrontends 1.0.1-canary.2 → 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 (44) hide show
  1. package/dist/bin/cli.cjs +3 -7
  2. package/dist/config.cjs +2 -6
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +1 -1
  5. package/dist/config.js +2 -6
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +2 -6
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +2 -6
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +49 -20
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.d.ts +1 -1
  14. package/dist/experimental/vite.js +49 -22
  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 +2 -6
  18. package/dist/microfrontends/server.cjs.map +1 -1
  19. package/dist/microfrontends/server.d.ts +1 -1
  20. package/dist/microfrontends/server.js +2 -6
  21. package/dist/microfrontends/server.js.map +1 -1
  22. package/dist/microfrontends.cjs +2 -6
  23. package/dist/microfrontends.cjs.map +1 -1
  24. package/dist/microfrontends.d.ts +1 -1
  25. package/dist/microfrontends.js +2 -6
  26. package/dist/microfrontends.js.map +1 -1
  27. package/dist/next/config.cjs +2 -6
  28. package/dist/next/config.cjs.map +1 -1
  29. package/dist/next/config.js +2 -6
  30. package/dist/next/config.js.map +1 -1
  31. package/dist/next/middleware.cjs +2 -6
  32. package/dist/next/middleware.cjs.map +1 -1
  33. package/dist/next/middleware.js +2 -6
  34. package/dist/next/middleware.js.map +1 -1
  35. package/dist/next/testing.cjs +2 -6
  36. package/dist/next/testing.cjs.map +1 -1
  37. package/dist/next/testing.d.ts +1 -1
  38. package/dist/next/testing.js +2 -6
  39. package/dist/next/testing.js.map +1 -1
  40. package/dist/utils/mfe-port.cjs +2 -6
  41. package/dist/utils/mfe-port.cjs.map +1 -1
  42. package/dist/utils/mfe-port.js +2 -6
  43. package/dist/utils/mfe-port.js.map +1 -1
  44. package/package.json +1 -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);
@@ -710,12 +707,8 @@ var MicrofrontendConfigIsomorphic = class {
710
707
  const skipValidation = opts?.skipValidation ?? [];
711
708
  const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
712
709
  if (isMainConfig(c)) {
713
- if (!skipValidation.includes("paths")) {
714
- validateConfigPaths(c.applications);
715
- }
716
- if (!skipValidation.includes("defaultApplication")) {
717
- validateConfigDefaultApplication(c.applications);
718
- }
710
+ validateConfigPaths(c.applications);
711
+ validateConfigDefaultApplication(c.applications);
719
712
  if (!skipValidation.includes("deprecatedFields")) {
720
713
  validateDeprecatedFields(c);
721
714
  }
@@ -1710,6 +1703,20 @@ function getApplicationContext(opts) {
1710
1703
  }
1711
1704
  }
1712
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
+
1713
1720
  // src/vite/index.ts
1714
1721
  function microfrontends(opts) {
1715
1722
  const { name: fromApp } = getApplicationContext();
@@ -1719,23 +1726,45 @@ function microfrontends(opts) {
1719
1726
  }
1720
1727
  });
1721
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
+ }
1722
1737
  const additionalConfigOptions = {};
1738
+ const framework = detectFramework();
1723
1739
  if (!app.isDefault()) {
1724
1740
  if (opts?.basePath) {
1725
- additionalConfigOptions.base = `/${opts.basePath}`;
1726
- } else {
1727
- const isSvelteKit = (0, import_node_fs9.existsSync)((0, import_node_path9.join)((0, import_node_process.cwd)(), "svelte.config.js"));
1728
- if (!isSvelteKit) {
1729
- additionalConfigOptions.experimental = {
1730
- renderBuiltUrl(filename, { type }) {
1731
- if (type === "asset") {
1732
- return `/${app.getAssetPrefix()}/${filename}`;
1733
- }
1734
- }
1735
- };
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;
1736
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
+ };
1756
+ }
1757
+ if (framework === "react-router") {
1758
+ additionalConfigOptions.build = {
1759
+ assetsDir: `./${opts?.basePath ?? app.getAssetPrefix()}`
1760
+ };
1737
1761
  }
1738
1762
  }
1763
+ if (app.development.local.port) {
1764
+ additionalConfigOptions.server = {
1765
+ port: app.development.local.port
1766
+ };
1767
+ }
1739
1768
  return {
1740
1769
  name: "vite-plugin-vercel-microfrontends",
1741
1770
  config: () => {