@vercel/microfrontends 0.19.5 → 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 +1 -1
- package/dist/next/config.cjs +98 -201
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +1 -1
- package/dist/next/config.js +98 -201
- package/dist/next/config.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
|
@@ -1615,65 +1615,8 @@ function transform2(args) {
|
|
|
1615
1615
|
};
|
|
1616
1616
|
}
|
|
1617
1617
|
|
|
1618
|
-
// src/next/config/transforms/headers.ts
|
|
1619
|
-
function transform3(args) {
|
|
1620
|
-
const { next, app } = args;
|
|
1621
|
-
if (app.isDefault()) {
|
|
1622
|
-
return {
|
|
1623
|
-
next
|
|
1624
|
-
};
|
|
1625
|
-
}
|
|
1626
|
-
const headersToAdd = [
|
|
1627
|
-
{
|
|
1628
|
-
source: "/:path*",
|
|
1629
|
-
headers: [
|
|
1630
|
-
{
|
|
1631
|
-
key: "X-Vercel-Zone",
|
|
1632
|
-
value: app.name
|
|
1633
|
-
},
|
|
1634
|
-
{
|
|
1635
|
-
key: "X-Vercel-MFE-App",
|
|
1636
|
-
value: app.name
|
|
1637
|
-
}
|
|
1638
|
-
]
|
|
1639
|
-
},
|
|
1640
|
-
{
|
|
1641
|
-
source: "/:path*",
|
|
1642
|
-
has: [
|
|
1643
|
-
{
|
|
1644
|
-
type: "host",
|
|
1645
|
-
value: "(?<host>.*)"
|
|
1646
|
-
}
|
|
1647
|
-
],
|
|
1648
|
-
headers: [
|
|
1649
|
-
{
|
|
1650
|
-
// TODO: we may want to revisit before launch whether we want to expose this
|
|
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"
|
|
1655
|
-
}
|
|
1656
|
-
]
|
|
1657
|
-
}
|
|
1658
|
-
];
|
|
1659
|
-
if (next.headers && typeof next.headers === "function") {
|
|
1660
|
-
const originalHeadersFn = next.headers;
|
|
1661
|
-
next.headers = async () => {
|
|
1662
|
-
const originalHeaders = await originalHeadersFn();
|
|
1663
|
-
return [...originalHeaders, ...headersToAdd];
|
|
1664
|
-
};
|
|
1665
|
-
} else {
|
|
1666
|
-
next.headers = () => {
|
|
1667
|
-
return Promise.resolve(headersToAdd);
|
|
1668
|
-
};
|
|
1669
|
-
}
|
|
1670
|
-
return {
|
|
1671
|
-
next
|
|
1672
|
-
};
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
1618
|
// src/next/config/transforms/redirects.ts
|
|
1676
|
-
function
|
|
1619
|
+
function transform3(args) {
|
|
1677
1620
|
const { next, microfrontend, opts } = args;
|
|
1678
1621
|
const isProduction2 = opts?.isProduction ?? false;
|
|
1679
1622
|
const isDevEnv = (process.env.VERCEL_ENV ?? "development") === "development";
|
|
@@ -1698,6 +1641,93 @@ function transform4(args) {
|
|
|
1698
1641
|
return { next };
|
|
1699
1642
|
}
|
|
1700
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+`
|
|
1684
|
+
}
|
|
1685
|
+
});
|
|
1686
|
+
rewrites.set(`/${app.getAssetPrefix()}/.well-known/vercel/flags`, {
|
|
1687
|
+
destination: {
|
|
1688
|
+
pathname: `/.well-known/vercel/flags`
|
|
1689
|
+
}
|
|
1690
|
+
});
|
|
1691
|
+
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1692
|
+
destination: {
|
|
1693
|
+
pathname: `/_vercel/:path*`
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
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
|
+
};
|
|
1717
|
+
};
|
|
1718
|
+
} else {
|
|
1719
|
+
next.rewrites = async () => ({
|
|
1720
|
+
beforeFiles: newBeforeFiles,
|
|
1721
|
+
afterFiles: [],
|
|
1722
|
+
fallback: []
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
debugRewrites(newBeforeFiles);
|
|
1726
|
+
return {
|
|
1727
|
+
next
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1701
1731
|
// src/routing/get-domain-from-environment.ts
|
|
1702
1732
|
function getDomainFromEnvironment({
|
|
1703
1733
|
app,
|
|
@@ -1781,138 +1811,6 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
|
1781
1811
|
}
|
|
1782
1812
|
}
|
|
1783
1813
|
|
|
1784
|
-
// src/next/config/transforms/rewrites.ts
|
|
1785
|
-
function debugRewrites(rewrites) {
|
|
1786
|
-
if (process.env.MFE_DEBUG === "true") {
|
|
1787
|
-
const indent = " ".repeat(4);
|
|
1788
|
-
const header = "rewrites (source \u2192 destination)";
|
|
1789
|
-
const separator = "\u23AF".repeat(header.length);
|
|
1790
|
-
const maxSourceLength = Math.max(
|
|
1791
|
-
...rewrites.map((key) => key.source.length)
|
|
1792
|
-
);
|
|
1793
|
-
const table = rewrites.map((route, idx) => {
|
|
1794
|
-
const paddedSource = route.source.padEnd(maxSourceLength);
|
|
1795
|
-
return `${indent} ${idx + 1}. ${paddedSource} \u2192 ${route.destination}`;
|
|
1796
|
-
}).join("\n");
|
|
1797
|
-
console.log(`${indent}${header}
|
|
1798
|
-
${indent}${separator}
|
|
1799
|
-
${table}
|
|
1800
|
-
`);
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
function pathToRewrites(path5) {
|
|
1804
|
-
const regex = /(?<base>^.+)\/:.+\*$/;
|
|
1805
|
-
const match = regex.exec(path5);
|
|
1806
|
-
const paths = [path5];
|
|
1807
|
-
if (match?.groups?.base) {
|
|
1808
|
-
paths.unshift(match.groups.base);
|
|
1809
|
-
}
|
|
1810
|
-
return paths;
|
|
1811
|
-
}
|
|
1812
|
-
function rewritesMapToArr(rewrites) {
|
|
1813
|
-
return Array.from(rewrites.entries()).flatMap(([source, rewrite]) => {
|
|
1814
|
-
const destination = `${rewrite.destination.domain || ""}${rewrite.destination.pathname}`;
|
|
1815
|
-
if (source === destination)
|
|
1816
|
-
return [];
|
|
1817
|
-
return [
|
|
1818
|
-
{
|
|
1819
|
-
source,
|
|
1820
|
-
destination,
|
|
1821
|
-
missing: [
|
|
1822
|
-
// if this header is present, the proxy has performed the rewrite.
|
|
1823
|
-
// once the proxy routing is fully rolled out, this package should
|
|
1824
|
-
// be updated to not perform any rewrites when deployed.
|
|
1825
|
-
{
|
|
1826
|
-
type: "header",
|
|
1827
|
-
key: "x-vercel-mfe-host"
|
|
1828
|
-
}
|
|
1829
|
-
]
|
|
1830
|
-
}
|
|
1831
|
-
];
|
|
1832
|
-
});
|
|
1833
|
-
}
|
|
1834
|
-
function transform5(args) {
|
|
1835
|
-
const { next, microfrontend, app } = args;
|
|
1836
|
-
const buildBeforeFiles = () => {
|
|
1837
|
-
const rewrites = /* @__PURE__ */ new Map();
|
|
1838
|
-
if (!app.isDefault()) {
|
|
1839
|
-
rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
|
|
1840
|
-
destination: {
|
|
1841
|
-
pathname: `/_next/:path+`
|
|
1842
|
-
}
|
|
1843
|
-
});
|
|
1844
|
-
rewrites.set(`/${app.getAssetPrefix()}/.well-known/vercel/flags`, {
|
|
1845
|
-
destination: {
|
|
1846
|
-
pathname: `/.well-known/vercel/flags`
|
|
1847
|
-
}
|
|
1848
|
-
});
|
|
1849
|
-
if (process.env.VERCEL_MICROFRONTENDS_CONSOLIDATE_SPEED_INSIGHTS === "1") {
|
|
1850
|
-
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1851
|
-
destination: { pathname: "/_vercel/:path*" }
|
|
1852
|
-
});
|
|
1853
|
-
}
|
|
1854
|
-
} else if (microfrontend instanceof MicrofrontendMainConfig) {
|
|
1855
|
-
for (const [_, a] of Object.entries(
|
|
1856
|
-
microfrontend.getChildApplications()
|
|
1857
|
-
)) {
|
|
1858
|
-
const { routing } = a;
|
|
1859
|
-
const domain = getDomainForCurrentEnvironment(microfrontend, a.name);
|
|
1860
|
-
rewrites.set(`/${a.getAssetPrefix()}/:path+`, {
|
|
1861
|
-
destination: {
|
|
1862
|
-
domain,
|
|
1863
|
-
pathname: `/${a.getAssetPrefix()}/:path+`
|
|
1864
|
-
}
|
|
1865
|
-
});
|
|
1866
|
-
for (const group of routing) {
|
|
1867
|
-
if (group.flag) {
|
|
1868
|
-
continue;
|
|
1869
|
-
} else {
|
|
1870
|
-
for (const source of group.paths) {
|
|
1871
|
-
const paths = pathToRewrites(source);
|
|
1872
|
-
for (const p of paths) {
|
|
1873
|
-
rewrites.set(p, {
|
|
1874
|
-
destination: { domain, pathname: p }
|
|
1875
|
-
});
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
return rewritesMapToArr(rewrites);
|
|
1883
|
-
};
|
|
1884
|
-
const newBeforeFiles = buildBeforeFiles();
|
|
1885
|
-
if (next.rewrites && typeof next.rewrites === "function") {
|
|
1886
|
-
const originalRewritesFn = next.rewrites;
|
|
1887
|
-
next.rewrites = async () => {
|
|
1888
|
-
const originalRewrites = await originalRewritesFn();
|
|
1889
|
-
if (typeof originalRewrites === "object" && !Array.isArray(originalRewrites)) {
|
|
1890
|
-
const { beforeFiles = [] } = originalRewrites;
|
|
1891
|
-
return {
|
|
1892
|
-
beforeFiles: [...newBeforeFiles, ...beforeFiles],
|
|
1893
|
-
afterFiles: originalRewrites.afterFiles,
|
|
1894
|
-
fallback: originalRewrites.fallback
|
|
1895
|
-
};
|
|
1896
|
-
}
|
|
1897
|
-
return {
|
|
1898
|
-
beforeFiles: newBeforeFiles,
|
|
1899
|
-
afterFiles: originalRewrites,
|
|
1900
|
-
fallback: []
|
|
1901
|
-
};
|
|
1902
|
-
};
|
|
1903
|
-
} else {
|
|
1904
|
-
next.rewrites = async () => ({
|
|
1905
|
-
beforeFiles: newBeforeFiles,
|
|
1906
|
-
afterFiles: [],
|
|
1907
|
-
fallback: []
|
|
1908
|
-
});
|
|
1909
|
-
}
|
|
1910
|
-
debugRewrites(newBeforeFiles);
|
|
1911
|
-
return {
|
|
1912
|
-
next
|
|
1913
|
-
};
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
1814
|
// src/next/config/transforms/server-actions.ts
|
|
1917
1815
|
function debugRewrites2(allowedOrigins) {
|
|
1918
1816
|
if (process.env.MFE_DEBUG === "true" && allowedOrigins) {
|
|
@@ -1933,7 +1831,7 @@ ${table}
|
|
|
1933
1831
|
}
|
|
1934
1832
|
}
|
|
1935
1833
|
var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
|
|
1936
|
-
function
|
|
1834
|
+
function transform5(args) {
|
|
1937
1835
|
const { next, app, microfrontend } = args;
|
|
1938
1836
|
if (microfrontend instanceof MicrofrontendChildConfig) {
|
|
1939
1837
|
console.warn(
|
|
@@ -1990,7 +1888,7 @@ function transform6(args) {
|
|
|
1990
1888
|
}
|
|
1991
1889
|
|
|
1992
1890
|
// src/next/config/transforms/webpack.ts
|
|
1993
|
-
function
|
|
1891
|
+
function transform6(args) {
|
|
1994
1892
|
const { next, microfrontend } = args;
|
|
1995
1893
|
const configWithWebpack = {
|
|
1996
1894
|
...next,
|
|
@@ -2034,11 +1932,10 @@ function transform7(args) {
|
|
|
2034
1932
|
var transforms = {
|
|
2035
1933
|
assetPrefix: transform,
|
|
2036
1934
|
draftMode: transform2,
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
webpack: transform7
|
|
1935
|
+
redirects: transform3,
|
|
1936
|
+
rewrites: transform4,
|
|
1937
|
+
serverActions: transform5,
|
|
1938
|
+
webpack: transform6
|
|
2042
1939
|
};
|
|
2043
1940
|
|
|
2044
1941
|
// src/next/config/env.ts
|
|
@@ -2067,9 +1964,9 @@ function setEnvironment({
|
|
|
2067
1964
|
NEXT_PUBLIC_MFE_CLIENT_CONFIG: JSON.stringify(
|
|
2068
1965
|
microfrontends.config.toClientConfig().serialize()
|
|
2069
1966
|
),
|
|
2070
|
-
...process.env.
|
|
1967
|
+
...process.env.ROUTE_OBSERVABILITY_TO_THIS_PROJECT && app.getAssetPrefix() ? {
|
|
2071
1968
|
NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH: `/${app.getAssetPrefix()}/_vercel`
|
|
2072
|
-
}
|
|
1969
|
+
} : {}
|
|
2073
1970
|
};
|
|
2074
1971
|
const serverEnvs = {
|
|
2075
1972
|
MFE_CURRENT_APPLICATION: app.name,
|
|
@@ -2130,13 +2027,13 @@ function withMicrofrontends(nextConfig, opts) {
|
|
|
2130
2027
|
const app = microfrontends.config.getApplication(fromApp);
|
|
2131
2028
|
setEnvironment({ app, microfrontends });
|
|
2132
2029
|
let next = { ...nextConfig };
|
|
2133
|
-
for (const [key,
|
|
2030
|
+
for (const [key, transform7] of typedEntries(transforms)) {
|
|
2134
2031
|
if (opts?.skipTransforms?.includes(key)) {
|
|
2135
2032
|
console.log(`Skipping ${key} transform`);
|
|
2136
2033
|
continue;
|
|
2137
2034
|
}
|
|
2138
2035
|
try {
|
|
2139
|
-
const transformedConfig =
|
|
2036
|
+
const transformedConfig = transform7({
|
|
2140
2037
|
app,
|
|
2141
2038
|
next,
|
|
2142
2039
|
microfrontend: microfrontends.config,
|