@vercel/microfrontends 1.3.0 → 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.
@@ -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;
@@ -1639,6 +1647,11 @@ function transform5(args) {
1639
1647
  };
1640
1648
  }
1641
1649
 
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
+
1642
1655
  // src/next/config/plugins/sort-chunks.ts
1643
1656
  var SortChunksPlugin = class {
1644
1657
  apply(compiler) {
@@ -1662,17 +1675,31 @@ var SortChunksPlugin = class {
1662
1675
  };
1663
1676
 
1664
1677
  // src/next/config/transforms/webpack.ts
1678
+ var cjsRequire = typeof __require === "function" ? __require : createRequire(import.meta.url);
1679
+ var nextVersion = getNextJsVersion();
1665
1680
  function transform6(args) {
1681
+ const useDefineServer = args.opts?.preferWebpackEnvironmentPlugin ? false : semver.gte(nextVersion, "15.4.0-canary.41");
1666
1682
  const { next, microfrontend, opts } = args;
1667
1683
  const configWithWebpack = {
1668
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
+ } : {},
1669
1696
  webpack(cfg, context) {
1670
1697
  const config = typeof next.webpack === "function" ? next.webpack(cfg, context) : cfg;
1671
1698
  const { isServer, nextRuntime, webpack: wpFromNext } = context;
1672
- if (isServer || nextRuntime === "edge") {
1699
+ if (!useDefineServer && (isServer || nextRuntime === "edge")) {
1673
1700
  config.plugins.push(
1674
1701
  new wpFromNext.EnvironmentPlugin({
1675
- MFE_CONFIG: JSON.stringify(microfrontend.serialize())
1702
+ MFE_CONFIG: JSON.stringify(microfrontend.serialize().config)
1676
1703
  })
1677
1704
  );
1678
1705
  }
@@ -1706,6 +1733,20 @@ function transform6(args) {
1706
1733
  next: configWithWebpack
1707
1734
  };
1708
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
+ }
1709
1750
 
1710
1751
  // src/next/config/transforms/index.ts
1711
1752
  var transforms = {