@vercel/microfrontends 0.19.4 → 0.19.6
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.
- package/dist/bin/cli.cjs +13 -6
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.ts +9 -2
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +106 -182
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +1 -1
- package/dist/next/config.js +106 -182
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +31 -223
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +31 -223
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +11 -46
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +3 -22
- package/dist/next/testing.js +10 -45
- package/dist/next/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/next/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextConfig } from 'next';
|
|
2
2
|
|
|
3
|
-
type TransformKeys = 'assetPrefix' | 'draftMode' | '
|
|
3
|
+
type TransformKeys = 'assetPrefix' | 'draftMode' | 'redirects' | 'rewrites' | 'serverActions' | 'webpack';
|
|
4
4
|
|
|
5
5
|
interface WithMicrofrontendsOptions {
|
|
6
6
|
/**
|
package/dist/next/config.js
CHANGED
|
@@ -1588,13 +1588,13 @@ function transform(args) {
|
|
|
1588
1588
|
next
|
|
1589
1589
|
};
|
|
1590
1590
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1591
|
+
const assetPrefix = `/${app.getAssetPrefix()}`;
|
|
1592
|
+
if (next.assetPrefix !== void 0 && next.assetPrefix !== assetPrefix) {
|
|
1593
|
+
throw new Error(
|
|
1594
|
+
`"assetPrefix" already set and does not equal "${assetPrefix}". Either omit the assetPrefix in your next config, or set it to "${assetPrefix}".`
|
|
1594
1595
|
);
|
|
1595
|
-
} else {
|
|
1596
|
-
next.assetPrefix = `/${app.getAssetPrefix()}`;
|
|
1597
1596
|
}
|
|
1597
|
+
next.assetPrefix = assetPrefix;
|
|
1598
1598
|
return {
|
|
1599
1599
|
next
|
|
1600
1600
|
};
|
|
@@ -1615,58 +1615,114 @@ function transform2(args) {
|
|
|
1615
1615
|
};
|
|
1616
1616
|
}
|
|
1617
1617
|
|
|
1618
|
-
// src/next/config/transforms/
|
|
1618
|
+
// src/next/config/transforms/redirects.ts
|
|
1619
1619
|
function transform3(args) {
|
|
1620
|
-
const { next,
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1620
|
+
const { next, microfrontend, opts } = args;
|
|
1621
|
+
const isProduction2 = opts?.isProduction ?? false;
|
|
1622
|
+
const isDevEnv = (process.env.VERCEL_ENV ?? "development") === "development";
|
|
1623
|
+
const requireLocalProxyHeader = !isProduction2 && isDevEnv && Boolean(process.env.TURBO_TASK_HAS_MFE_PROXY) && !process.env.MFE_DISABLE_LOCAL_PROXY_REWRITE;
|
|
1624
|
+
if (requireLocalProxyHeader) {
|
|
1625
|
+
const proxyRedirect = {
|
|
1626
|
+
source: "/:path*",
|
|
1627
|
+
destination: `http://localhost:${microfrontend.getLocalProxyPort()}/:path*`,
|
|
1628
|
+
permanent: false,
|
|
1629
|
+
missing: [{ type: "header", key: "x-vercel-mfe-local-proxy-origin" }]
|
|
1624
1630
|
};
|
|
1631
|
+
if (next.redirects && typeof next.redirects === "function") {
|
|
1632
|
+
const originalRedirectsFn = next.redirects;
|
|
1633
|
+
next.redirects = async () => {
|
|
1634
|
+
const originalRedirects = await originalRedirectsFn();
|
|
1635
|
+
return [proxyRedirect, ...originalRedirects];
|
|
1636
|
+
};
|
|
1637
|
+
} else {
|
|
1638
|
+
next.redirects = async () => [proxyRedirect];
|
|
1639
|
+
}
|
|
1625
1640
|
}
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1641
|
+
return { next };
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
// src/next/config/transforms/rewrites.ts
|
|
1645
|
+
function debugRewrites(rewrites) {
|
|
1646
|
+
if (process.env.MFE_DEBUG === "true") {
|
|
1647
|
+
const indent = " ".repeat(4);
|
|
1648
|
+
const header = "rewrites (source \u2192 destination)";
|
|
1649
|
+
const separator = "\u23AF".repeat(header.length);
|
|
1650
|
+
const maxSourceLength = Math.max(
|
|
1651
|
+
...rewrites.map((key) => key.source.length)
|
|
1652
|
+
);
|
|
1653
|
+
const table = rewrites.map((route, idx) => {
|
|
1654
|
+
const paddedSource = route.source.padEnd(maxSourceLength);
|
|
1655
|
+
return `${indent} ${idx + 1}. ${paddedSource} \u2192 ${route.destination}`;
|
|
1656
|
+
}).join("\n");
|
|
1657
|
+
console.log(`${indent}${header}
|
|
1658
|
+
${indent}${separator}
|
|
1659
|
+
${table}
|
|
1660
|
+
`);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
function rewritesMapToArr(rewrites) {
|
|
1664
|
+
return Array.from(rewrites.entries()).flatMap(([source, rewrite]) => {
|
|
1665
|
+
const destination = `${rewrite.destination.domain || ""}${rewrite.destination.pathname}`;
|
|
1666
|
+
if (source === destination)
|
|
1667
|
+
return [];
|
|
1668
|
+
return [
|
|
1669
|
+
{
|
|
1670
|
+
source,
|
|
1671
|
+
destination
|
|
1672
|
+
}
|
|
1673
|
+
];
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
function transform4(args) {
|
|
1677
|
+
const { next, app } = args;
|
|
1678
|
+
const buildBeforeFiles = () => {
|
|
1679
|
+
const rewrites = /* @__PURE__ */ new Map();
|
|
1680
|
+
if (!app.isDefault()) {
|
|
1681
|
+
rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
|
|
1682
|
+
destination: {
|
|
1683
|
+
pathname: `/_next/:path+`
|
|
1637
1684
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
has: [
|
|
1643
|
-
{
|
|
1644
|
-
type: "host",
|
|
1645
|
-
value: "(?<host>.*)"
|
|
1685
|
+
});
|
|
1686
|
+
rewrites.set(`/${app.getAssetPrefix()}/.well-known/vercel/flags`, {
|
|
1687
|
+
destination: {
|
|
1688
|
+
pathname: `/.well-known/vercel/flags`
|
|
1646
1689
|
}
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
{
|
|
1650
|
-
|
|
1651
|
-
// value on all responses publicly since users may not want to reveal this host
|
|
1652
|
-
// (maybe just in preview? or when the user is logged in to the toolbar?)
|
|
1653
|
-
key: "X-Vercel-Host",
|
|
1654
|
-
value: ":host"
|
|
1690
|
+
});
|
|
1691
|
+
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1692
|
+
destination: {
|
|
1693
|
+
pathname: `/_vercel/:path*`
|
|
1655
1694
|
}
|
|
1656
|
-
|
|
1695
|
+
});
|
|
1657
1696
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1697
|
+
return rewritesMapToArr(rewrites);
|
|
1698
|
+
};
|
|
1699
|
+
const newBeforeFiles = buildBeforeFiles();
|
|
1700
|
+
if (next.rewrites && typeof next.rewrites === "function") {
|
|
1701
|
+
const originalRewritesFn = next.rewrites;
|
|
1702
|
+
next.rewrites = async () => {
|
|
1703
|
+
const originalRewrites = await originalRewritesFn();
|
|
1704
|
+
if (typeof originalRewrites === "object" && !Array.isArray(originalRewrites)) {
|
|
1705
|
+
const { beforeFiles = [] } = originalRewrites;
|
|
1706
|
+
return {
|
|
1707
|
+
beforeFiles: [...newBeforeFiles, ...beforeFiles],
|
|
1708
|
+
afterFiles: originalRewrites.afterFiles,
|
|
1709
|
+
fallback: originalRewrites.fallback
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
return {
|
|
1713
|
+
beforeFiles: newBeforeFiles,
|
|
1714
|
+
afterFiles: originalRewrites,
|
|
1715
|
+
fallback: []
|
|
1716
|
+
};
|
|
1664
1717
|
};
|
|
1665
1718
|
} else {
|
|
1666
|
-
next.
|
|
1667
|
-
|
|
1668
|
-
|
|
1719
|
+
next.rewrites = async () => ({
|
|
1720
|
+
beforeFiles: newBeforeFiles,
|
|
1721
|
+
afterFiles: [],
|
|
1722
|
+
fallback: []
|
|
1723
|
+
});
|
|
1669
1724
|
}
|
|
1725
|
+
debugRewrites(newBeforeFiles);
|
|
1670
1726
|
return {
|
|
1671
1727
|
next
|
|
1672
1728
|
};
|
|
@@ -1755,138 +1811,6 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
|
1755
1811
|
}
|
|
1756
1812
|
}
|
|
1757
1813
|
|
|
1758
|
-
// src/next/config/transforms/rewrites.ts
|
|
1759
|
-
function debugRewrites(rewrites) {
|
|
1760
|
-
if (process.env.MFE_DEBUG === "true") {
|
|
1761
|
-
const indent = " ".repeat(4);
|
|
1762
|
-
const header = "rewrites (source \u2192 destination)";
|
|
1763
|
-
const separator = "\u23AF".repeat(header.length);
|
|
1764
|
-
const maxSourceLength = Math.max(
|
|
1765
|
-
...rewrites.map((key) => key.source.length)
|
|
1766
|
-
);
|
|
1767
|
-
const table = rewrites.map((route, idx) => {
|
|
1768
|
-
const paddedSource = route.source.padEnd(maxSourceLength);
|
|
1769
|
-
return `${indent} ${idx + 1}. ${paddedSource} \u2192 ${route.destination}`;
|
|
1770
|
-
}).join("\n");
|
|
1771
|
-
console.log(`${indent}${header}
|
|
1772
|
-
${indent}${separator}
|
|
1773
|
-
${table}
|
|
1774
|
-
`);
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
function pathToRewrites(path5) {
|
|
1778
|
-
const regex = /(?<base>^.+)\/:.+\*$/;
|
|
1779
|
-
const match = regex.exec(path5);
|
|
1780
|
-
const paths = [path5];
|
|
1781
|
-
if (match?.groups?.base) {
|
|
1782
|
-
paths.unshift(match.groups.base);
|
|
1783
|
-
}
|
|
1784
|
-
return paths;
|
|
1785
|
-
}
|
|
1786
|
-
function rewritesMapToArr(rewrites) {
|
|
1787
|
-
return Array.from(rewrites.entries()).flatMap(([source, rewrite]) => {
|
|
1788
|
-
const destination = `${rewrite.destination.domain || ""}${rewrite.destination.pathname}`;
|
|
1789
|
-
if (source === destination)
|
|
1790
|
-
return [];
|
|
1791
|
-
return [
|
|
1792
|
-
{
|
|
1793
|
-
source,
|
|
1794
|
-
destination,
|
|
1795
|
-
missing: [
|
|
1796
|
-
// if this header is present, the proxy has performed the rewrite.
|
|
1797
|
-
// once the proxy routing is fully rolled out, this package should
|
|
1798
|
-
// be updated to not perform any rewrites when deployed.
|
|
1799
|
-
{
|
|
1800
|
-
type: "header",
|
|
1801
|
-
key: "x-vercel-mfe-host"
|
|
1802
|
-
}
|
|
1803
|
-
]
|
|
1804
|
-
}
|
|
1805
|
-
];
|
|
1806
|
-
});
|
|
1807
|
-
}
|
|
1808
|
-
function transform4(args) {
|
|
1809
|
-
const { next, microfrontend, app } = args;
|
|
1810
|
-
const buildBeforeFiles = () => {
|
|
1811
|
-
const rewrites = /* @__PURE__ */ new Map();
|
|
1812
|
-
if (!app.isDefault()) {
|
|
1813
|
-
rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
|
|
1814
|
-
destination: {
|
|
1815
|
-
pathname: `/_next/:path+`
|
|
1816
|
-
}
|
|
1817
|
-
});
|
|
1818
|
-
rewrites.set(`/${app.getAssetPrefix()}/.well-known/vercel/flags`, {
|
|
1819
|
-
destination: {
|
|
1820
|
-
pathname: `/.well-known/vercel/flags`
|
|
1821
|
-
}
|
|
1822
|
-
});
|
|
1823
|
-
if (process.env.VERCEL_MICROFRONTENDS_CONSOLIDATE_SPEED_INSIGHTS === "1") {
|
|
1824
|
-
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1825
|
-
destination: { pathname: "/_vercel/:path*" }
|
|
1826
|
-
});
|
|
1827
|
-
}
|
|
1828
|
-
} else if (microfrontend instanceof MicrofrontendMainConfig) {
|
|
1829
|
-
for (const [_, a] of Object.entries(
|
|
1830
|
-
microfrontend.getChildApplications()
|
|
1831
|
-
)) {
|
|
1832
|
-
const { routing } = a;
|
|
1833
|
-
const domain = getDomainForCurrentEnvironment(microfrontend, a.name);
|
|
1834
|
-
rewrites.set(`/${a.getAssetPrefix()}/:path+`, {
|
|
1835
|
-
destination: {
|
|
1836
|
-
domain,
|
|
1837
|
-
pathname: `/${a.getAssetPrefix()}/:path+`
|
|
1838
|
-
}
|
|
1839
|
-
});
|
|
1840
|
-
for (const group of routing) {
|
|
1841
|
-
if (group.flag) {
|
|
1842
|
-
continue;
|
|
1843
|
-
} else {
|
|
1844
|
-
for (const source of group.paths) {
|
|
1845
|
-
const paths = pathToRewrites(source);
|
|
1846
|
-
for (const p of paths) {
|
|
1847
|
-
rewrites.set(p, {
|
|
1848
|
-
destination: { domain, pathname: p }
|
|
1849
|
-
});
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
return rewritesMapToArr(rewrites);
|
|
1857
|
-
};
|
|
1858
|
-
const newBeforeFiles = buildBeforeFiles();
|
|
1859
|
-
if (next.rewrites && typeof next.rewrites === "function") {
|
|
1860
|
-
const originalRewritesFn = next.rewrites;
|
|
1861
|
-
next.rewrites = async () => {
|
|
1862
|
-
const originalRewrites = await originalRewritesFn();
|
|
1863
|
-
if (typeof originalRewrites === "object" && !Array.isArray(originalRewrites)) {
|
|
1864
|
-
const { beforeFiles = [] } = originalRewrites;
|
|
1865
|
-
return {
|
|
1866
|
-
beforeFiles: [...newBeforeFiles, ...beforeFiles],
|
|
1867
|
-
afterFiles: originalRewrites.afterFiles,
|
|
1868
|
-
fallback: originalRewrites.fallback
|
|
1869
|
-
};
|
|
1870
|
-
}
|
|
1871
|
-
return {
|
|
1872
|
-
beforeFiles: newBeforeFiles,
|
|
1873
|
-
afterFiles: originalRewrites,
|
|
1874
|
-
fallback: []
|
|
1875
|
-
};
|
|
1876
|
-
};
|
|
1877
|
-
} else {
|
|
1878
|
-
next.rewrites = async () => ({
|
|
1879
|
-
beforeFiles: newBeforeFiles,
|
|
1880
|
-
afterFiles: [],
|
|
1881
|
-
fallback: []
|
|
1882
|
-
});
|
|
1883
|
-
}
|
|
1884
|
-
debugRewrites(newBeforeFiles);
|
|
1885
|
-
return {
|
|
1886
|
-
next
|
|
1887
|
-
};
|
|
1888
|
-
}
|
|
1889
|
-
|
|
1890
1814
|
// src/next/config/transforms/server-actions.ts
|
|
1891
1815
|
function debugRewrites2(allowedOrigins) {
|
|
1892
1816
|
if (process.env.MFE_DEBUG === "true" && allowedOrigins) {
|
|
@@ -2008,7 +1932,7 @@ function transform6(args) {
|
|
|
2008
1932
|
var transforms = {
|
|
2009
1933
|
assetPrefix: transform,
|
|
2010
1934
|
draftMode: transform2,
|
|
2011
|
-
|
|
1935
|
+
redirects: transform3,
|
|
2012
1936
|
rewrites: transform4,
|
|
2013
1937
|
serverActions: transform5,
|
|
2014
1938
|
webpack: transform6
|
|
@@ -2040,9 +1964,9 @@ function setEnvironment({
|
|
|
2040
1964
|
NEXT_PUBLIC_MFE_CLIENT_CONFIG: JSON.stringify(
|
|
2041
1965
|
microfrontends.config.toClientConfig().serialize()
|
|
2042
1966
|
),
|
|
2043
|
-
...process.env.
|
|
1967
|
+
...process.env.ROUTE_OBSERVABILITY_TO_THIS_PROJECT && app.getAssetPrefix() ? {
|
|
2044
1968
|
NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH: `/${app.getAssetPrefix()}/_vercel`
|
|
2045
|
-
}
|
|
1969
|
+
} : {}
|
|
2046
1970
|
};
|
|
2047
1971
|
const serverEnvs = {
|
|
2048
1972
|
MFE_CURRENT_APPLICATION: app.name,
|