@vercel/microfrontends 1.2.4 → 1.4.0-canary.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 (41) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +5 -1
  3. package/dist/bin/cli.cjs +8 -12
  4. package/dist/config.d.ts +10 -3
  5. package/dist/experimental/sveltekit.cjs.map +1 -1
  6. package/dist/experimental/sveltekit.js.map +1 -1
  7. package/dist/experimental/vite.cjs.map +1 -1
  8. package/dist/experimental/vite.js.map +1 -1
  9. package/dist/microfrontends/server.cjs +4 -2
  10. package/dist/microfrontends/server.cjs.map +1 -1
  11. package/dist/microfrontends/server.d.ts +13 -4
  12. package/dist/microfrontends/server.js +2 -1
  13. package/dist/microfrontends/server.js.map +1 -1
  14. package/dist/next/config.cjs +59 -30
  15. package/dist/next/config.cjs.map +1 -1
  16. package/dist/next/config.js +66 -30
  17. package/dist/next/config.js.map +1 -1
  18. package/dist/next/middleware.cjs +117 -69
  19. package/dist/next/middleware.cjs.map +1 -1
  20. package/dist/next/middleware.d.ts +4 -2
  21. package/dist/next/middleware.js +117 -69
  22. package/dist/next/middleware.js.map +1 -1
  23. package/dist/next/testing.cjs +6 -0
  24. package/dist/next/testing.cjs.map +1 -1
  25. package/dist/next/testing.d.ts +2 -3
  26. package/dist/next/testing.js +6 -0
  27. package/dist/next/testing.js.map +1 -1
  28. package/dist/overrides.d.ts +3 -3
  29. package/dist/schema.d.ts +2 -2
  30. package/dist/{types-c9f15465.d.ts → types-ab31c948.d.ts} +1 -1
  31. package/dist/{types-bee19651.d.ts → types-d3cb74a6.d.ts} +1 -1
  32. package/dist/utils/mfe-port.cjs.map +1 -1
  33. package/dist/utils/mfe-port.js.map +1 -1
  34. package/dist/validation.d.ts +1 -1
  35. package/package.json +8 -12
  36. package/dist/next/endpoints.cjs +0 -154
  37. package/dist/next/endpoints.cjs.map +0 -1
  38. package/dist/next/endpoints.d.ts +0 -68
  39. package/dist/next/endpoints.js +0 -127
  40. package/dist/next/endpoints.js.map +0 -1
  41. package/dist/types-b970b583.d.ts +0 -11
@@ -1,3 +1,11 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw new Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
1
9
  // src/bin/check-proxy.ts
2
10
  function displayLocalProxyInfo(port) {
3
11
  const { MFE_PROXY_MESSAGE_PRINTED, TURBO_TASK_HAS_MFE_PROXY } = process.env;
@@ -1640,17 +1648,58 @@ function transform5(args) {
1640
1648
  }
1641
1649
 
1642
1650
  // src/next/config/transforms/webpack.ts
1651
+ import fs7 from "node:fs";
1652
+ import { createRequire } from "node:module";
1653
+ import * as semver from "semver";
1654
+
1655
+ // src/next/config/plugins/sort-chunks.ts
1656
+ var SortChunksPlugin = class {
1657
+ apply(compiler) {
1658
+ compiler.hooks.compilation.tap("SortChunksPlugin", (compilation) => {
1659
+ compilation.hooks.optimizeChunks.tap("SortChunksPlugin", (chunks) => {
1660
+ const sortedChunks = Array.from(chunks).sort((a, b) => {
1661
+ if (a.name && b.name) {
1662
+ return a.name.localeCompare(b.name);
1663
+ }
1664
+ return (String(a.id) || "").localeCompare(String(b.id) || "");
1665
+ });
1666
+ Array.from(chunks).forEach((chunk) => {
1667
+ compilation.chunks.delete(chunk);
1668
+ });
1669
+ sortedChunks.forEach((chunk) => {
1670
+ compilation.chunks.add(chunk);
1671
+ });
1672
+ });
1673
+ });
1674
+ }
1675
+ };
1676
+
1677
+ // src/next/config/transforms/webpack.ts
1678
+ var cjsRequire = typeof __require === "function" ? __require : createRequire(import.meta.url);
1679
+ var nextVersion = getNextJsVersion();
1643
1680
  function transform6(args) {
1681
+ const useDefineServer = args.opts?.preferWebpackEnvironmentPlugin ? false : semver.gte(nextVersion, "15.4.0-canary.41");
1644
1682
  const { next, microfrontend, opts } = args;
1645
1683
  const configWithWebpack = {
1646
1684
  ...next,
1685
+ ...useDefineServer ? {
1686
+ compiler: {
1687
+ ...next.compiler,
1688
+ defineServer: {
1689
+ ...next.compiler?.defineServer,
1690
+ "process.env.MFE_CONFIG": JSON.stringify(
1691
+ microfrontend.serialize().config
1692
+ )
1693
+ }
1694
+ }
1695
+ } : {},
1647
1696
  webpack(cfg, context) {
1648
1697
  const config = typeof next.webpack === "function" ? next.webpack(cfg, context) : cfg;
1649
1698
  const { isServer, nextRuntime, webpack: wpFromNext } = context;
1650
- if (isServer || nextRuntime === "edge") {
1699
+ if (!useDefineServer && (isServer || nextRuntime === "edge")) {
1651
1700
  config.plugins.push(
1652
1701
  new wpFromNext.EnvironmentPlugin({
1653
- MFE_CONFIG: JSON.stringify(microfrontend.serialize())
1702
+ MFE_CONFIG: JSON.stringify(microfrontend.serialize().config)
1654
1703
  })
1655
1704
  );
1656
1705
  }
@@ -1675,34 +1724,7 @@ function transform6(args) {
1675
1724
  if (opts?.supportPagesRouter) {
1676
1725
  config.optimization.moduleIds = "deterministic";
1677
1726
  config.optimization.chunkIds = "deterministic";
1678
- config.plugins.push({
1679
- apply: (compiler) => {
1680
- compiler.hooks.compilation.tap(
1681
- "SortChunksPlugin",
1682
- (compilation) => {
1683
- compilation.hooks.optimizeChunks.tap(
1684
- "SortChunksPlugin",
1685
- (chunks) => {
1686
- const sortedChunks = Array.from(chunks).sort((a, b) => {
1687
- if (a.name && b.name) {
1688
- return a.name.localeCompare(b.name);
1689
- }
1690
- return (String(a.id) || "").localeCompare(
1691
- String(b.id) || ""
1692
- );
1693
- });
1694
- Array.from(chunks).forEach((chunk) => {
1695
- compilation.chunks.delete(chunk);
1696
- });
1697
- sortedChunks.forEach((chunk) => {
1698
- compilation.chunks.add(chunk);
1699
- });
1700
- }
1701
- );
1702
- }
1703
- );
1704
- }
1705
- });
1727
+ config.plugins.push(new SortChunksPlugin());
1706
1728
  }
1707
1729
  return config;
1708
1730
  }
@@ -1711,6 +1733,20 @@ function transform6(args) {
1711
1733
  next: configWithWebpack
1712
1734
  };
1713
1735
  }
1736
+ function getNextJsVersion() {
1737
+ const parsedNextPackageJson = JSON.parse(
1738
+ // `import.meta.url` is not available in CJS or early Node.js versions
1739
+ fs7.readFileSync(cjsRequire.resolve("next/package.json"), "utf8")
1740
+ );
1741
+ if (typeof parsedNextPackageJson !== "object" || parsedNextPackageJson === null) {
1742
+ throw new Error("Could not read 'next/package.json'.");
1743
+ }
1744
+ const parsedNextVersion = "version" in parsedNextPackageJson && parsedNextPackageJson.version;
1745
+ if (typeof parsedNextVersion !== "string") {
1746
+ throw new Error("Could not read version from 'next/package.json'.");
1747
+ }
1748
+ return parsedNextVersion;
1749
+ }
1714
1750
 
1715
1751
  // src/next/config/transforms/index.ts
1716
1752
  var transforms = {