@vercel/microfrontends 0.19.5 → 0.20.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.
- package/dist/bin/cli.cjs +1 -1
- package/dist/next/config.cjs +103 -201
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +1 -1
- package/dist/next/config.js +103 -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/bin/cli.cjs
CHANGED
|
@@ -29,7 +29,7 @@ var import_commander = require("commander");
|
|
|
29
29
|
// package.json
|
|
30
30
|
var package_default = {
|
|
31
31
|
name: "@vercel/microfrontends",
|
|
32
|
-
version: "0.
|
|
32
|
+
version: "0.20.0",
|
|
33
33
|
private: false,
|
|
34
34
|
description: "Defines configuration and utilities for microfrontends development",
|
|
35
35
|
keywords: [
|
package/dist/next/config.cjs
CHANGED
|
@@ -1649,65 +1649,8 @@ function transform2(args) {
|
|
|
1649
1649
|
};
|
|
1650
1650
|
}
|
|
1651
1651
|
|
|
1652
|
-
// src/next/config/transforms/headers.ts
|
|
1653
|
-
function transform3(args) {
|
|
1654
|
-
const { next, app } = args;
|
|
1655
|
-
if (app.isDefault()) {
|
|
1656
|
-
return {
|
|
1657
|
-
next
|
|
1658
|
-
};
|
|
1659
|
-
}
|
|
1660
|
-
const headersToAdd = [
|
|
1661
|
-
{
|
|
1662
|
-
source: "/:path*",
|
|
1663
|
-
headers: [
|
|
1664
|
-
{
|
|
1665
|
-
key: "X-Vercel-Zone",
|
|
1666
|
-
value: app.name
|
|
1667
|
-
},
|
|
1668
|
-
{
|
|
1669
|
-
key: "X-Vercel-MFE-App",
|
|
1670
|
-
value: app.name
|
|
1671
|
-
}
|
|
1672
|
-
]
|
|
1673
|
-
},
|
|
1674
|
-
{
|
|
1675
|
-
source: "/:path*",
|
|
1676
|
-
has: [
|
|
1677
|
-
{
|
|
1678
|
-
type: "host",
|
|
1679
|
-
value: "(?<host>.*)"
|
|
1680
|
-
}
|
|
1681
|
-
],
|
|
1682
|
-
headers: [
|
|
1683
|
-
{
|
|
1684
|
-
// TODO: we may want to revisit before launch whether we want to expose this
|
|
1685
|
-
// value on all responses publicly since users may not want to reveal this host
|
|
1686
|
-
// (maybe just in preview? or when the user is logged in to the toolbar?)
|
|
1687
|
-
key: "X-Vercel-Host",
|
|
1688
|
-
value: ":host"
|
|
1689
|
-
}
|
|
1690
|
-
]
|
|
1691
|
-
}
|
|
1692
|
-
];
|
|
1693
|
-
if (next.headers && typeof next.headers === "function") {
|
|
1694
|
-
const originalHeadersFn = next.headers;
|
|
1695
|
-
next.headers = async () => {
|
|
1696
|
-
const originalHeaders = await originalHeadersFn();
|
|
1697
|
-
return [...originalHeaders, ...headersToAdd];
|
|
1698
|
-
};
|
|
1699
|
-
} else {
|
|
1700
|
-
next.headers = () => {
|
|
1701
|
-
return Promise.resolve(headersToAdd);
|
|
1702
|
-
};
|
|
1703
|
-
}
|
|
1704
|
-
return {
|
|
1705
|
-
next
|
|
1706
|
-
};
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
1652
|
// src/next/config/transforms/redirects.ts
|
|
1710
|
-
function
|
|
1653
|
+
function transform3(args) {
|
|
1711
1654
|
const { next, microfrontend, opts } = args;
|
|
1712
1655
|
const isProduction2 = opts?.isProduction ?? false;
|
|
1713
1656
|
const isDevEnv = (process.env.VERCEL_ENV ?? "development") === "development";
|
|
@@ -1732,6 +1675,98 @@ function transform4(args) {
|
|
|
1732
1675
|
return { next };
|
|
1733
1676
|
}
|
|
1734
1677
|
|
|
1678
|
+
// src/next/config/transforms/rewrites.ts
|
|
1679
|
+
function debugRewrites(rewrites) {
|
|
1680
|
+
if (process.env.MFE_DEBUG === "true") {
|
|
1681
|
+
const indent = " ".repeat(4);
|
|
1682
|
+
const header = "rewrites (source \u2192 destination)";
|
|
1683
|
+
const separator = "\u23AF".repeat(header.length);
|
|
1684
|
+
const maxSourceLength = Math.max(
|
|
1685
|
+
...rewrites.map((key) => key.source.length)
|
|
1686
|
+
);
|
|
1687
|
+
const table = rewrites.map((route, idx) => {
|
|
1688
|
+
const paddedSource = route.source.padEnd(maxSourceLength);
|
|
1689
|
+
return `${indent} ${idx + 1}. ${paddedSource} \u2192 ${route.destination}`;
|
|
1690
|
+
}).join("\n");
|
|
1691
|
+
console.log(`${indent}${header}
|
|
1692
|
+
${indent}${separator}
|
|
1693
|
+
${table}
|
|
1694
|
+
`);
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
function rewritesMapToArr(rewrites) {
|
|
1698
|
+
return Array.from(rewrites.entries()).flatMap(([source, rewrite]) => {
|
|
1699
|
+
const destination = `${rewrite.destination.domain || ""}${rewrite.destination.pathname}`;
|
|
1700
|
+
if (source === destination)
|
|
1701
|
+
return [];
|
|
1702
|
+
return [
|
|
1703
|
+
{
|
|
1704
|
+
source,
|
|
1705
|
+
destination
|
|
1706
|
+
}
|
|
1707
|
+
];
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
function transform4(args) {
|
|
1711
|
+
const { next, app } = args;
|
|
1712
|
+
if (process.env.VERCEL_ENV && process.env.VERCEL_ENV !== "development") {
|
|
1713
|
+
return {
|
|
1714
|
+
next
|
|
1715
|
+
};
|
|
1716
|
+
}
|
|
1717
|
+
const buildBeforeFiles = () => {
|
|
1718
|
+
const rewrites = /* @__PURE__ */ new Map();
|
|
1719
|
+
if (!app.isDefault()) {
|
|
1720
|
+
rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
|
|
1721
|
+
destination: {
|
|
1722
|
+
pathname: "/_next/:path+"
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
rewrites.set(`/${app.getAssetPrefix()}/.well-known/vercel/flags`, {
|
|
1726
|
+
destination: {
|
|
1727
|
+
pathname: "/.well-known/vercel/flags"
|
|
1728
|
+
}
|
|
1729
|
+
});
|
|
1730
|
+
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1731
|
+
destination: {
|
|
1732
|
+
pathname: "/_vercel/:path*"
|
|
1733
|
+
}
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
return rewritesMapToArr(rewrites);
|
|
1737
|
+
};
|
|
1738
|
+
const newBeforeFiles = buildBeforeFiles();
|
|
1739
|
+
if (next.rewrites && typeof next.rewrites === "function") {
|
|
1740
|
+
const originalRewritesFn = next.rewrites;
|
|
1741
|
+
next.rewrites = async () => {
|
|
1742
|
+
const originalRewrites = await originalRewritesFn();
|
|
1743
|
+
if (typeof originalRewrites === "object" && !Array.isArray(originalRewrites)) {
|
|
1744
|
+
const { beforeFiles = [] } = originalRewrites;
|
|
1745
|
+
return {
|
|
1746
|
+
beforeFiles: [...newBeforeFiles, ...beforeFiles],
|
|
1747
|
+
afterFiles: originalRewrites.afterFiles,
|
|
1748
|
+
fallback: originalRewrites.fallback
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
return {
|
|
1752
|
+
beforeFiles: newBeforeFiles,
|
|
1753
|
+
afterFiles: originalRewrites,
|
|
1754
|
+
fallback: []
|
|
1755
|
+
};
|
|
1756
|
+
};
|
|
1757
|
+
} else {
|
|
1758
|
+
next.rewrites = async () => ({
|
|
1759
|
+
beforeFiles: newBeforeFiles,
|
|
1760
|
+
afterFiles: [],
|
|
1761
|
+
fallback: []
|
|
1762
|
+
});
|
|
1763
|
+
}
|
|
1764
|
+
debugRewrites(newBeforeFiles);
|
|
1765
|
+
return {
|
|
1766
|
+
next
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1735
1770
|
// src/routing/get-domain-from-environment.ts
|
|
1736
1771
|
function getDomainFromEnvironment({
|
|
1737
1772
|
app,
|
|
@@ -1815,138 +1850,6 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
|
1815
1850
|
}
|
|
1816
1851
|
}
|
|
1817
1852
|
|
|
1818
|
-
// src/next/config/transforms/rewrites.ts
|
|
1819
|
-
function debugRewrites(rewrites) {
|
|
1820
|
-
if (process.env.MFE_DEBUG === "true") {
|
|
1821
|
-
const indent = " ".repeat(4);
|
|
1822
|
-
const header = "rewrites (source \u2192 destination)";
|
|
1823
|
-
const separator = "\u23AF".repeat(header.length);
|
|
1824
|
-
const maxSourceLength = Math.max(
|
|
1825
|
-
...rewrites.map((key) => key.source.length)
|
|
1826
|
-
);
|
|
1827
|
-
const table = rewrites.map((route, idx) => {
|
|
1828
|
-
const paddedSource = route.source.padEnd(maxSourceLength);
|
|
1829
|
-
return `${indent} ${idx + 1}. ${paddedSource} \u2192 ${route.destination}`;
|
|
1830
|
-
}).join("\n");
|
|
1831
|
-
console.log(`${indent}${header}
|
|
1832
|
-
${indent}${separator}
|
|
1833
|
-
${table}
|
|
1834
|
-
`);
|
|
1835
|
-
}
|
|
1836
|
-
}
|
|
1837
|
-
function pathToRewrites(path5) {
|
|
1838
|
-
const regex = /(?<base>^.+)\/:.+\*$/;
|
|
1839
|
-
const match = regex.exec(path5);
|
|
1840
|
-
const paths = [path5];
|
|
1841
|
-
if (match?.groups?.base) {
|
|
1842
|
-
paths.unshift(match.groups.base);
|
|
1843
|
-
}
|
|
1844
|
-
return paths;
|
|
1845
|
-
}
|
|
1846
|
-
function rewritesMapToArr(rewrites) {
|
|
1847
|
-
return Array.from(rewrites.entries()).flatMap(([source, rewrite]) => {
|
|
1848
|
-
const destination = `${rewrite.destination.domain || ""}${rewrite.destination.pathname}`;
|
|
1849
|
-
if (source === destination)
|
|
1850
|
-
return [];
|
|
1851
|
-
return [
|
|
1852
|
-
{
|
|
1853
|
-
source,
|
|
1854
|
-
destination,
|
|
1855
|
-
missing: [
|
|
1856
|
-
// if this header is present, the proxy has performed the rewrite.
|
|
1857
|
-
// once the proxy routing is fully rolled out, this package should
|
|
1858
|
-
// be updated to not perform any rewrites when deployed.
|
|
1859
|
-
{
|
|
1860
|
-
type: "header",
|
|
1861
|
-
key: "x-vercel-mfe-host"
|
|
1862
|
-
}
|
|
1863
|
-
]
|
|
1864
|
-
}
|
|
1865
|
-
];
|
|
1866
|
-
});
|
|
1867
|
-
}
|
|
1868
|
-
function transform5(args) {
|
|
1869
|
-
const { next, microfrontend, app } = args;
|
|
1870
|
-
const buildBeforeFiles = () => {
|
|
1871
|
-
const rewrites = /* @__PURE__ */ new Map();
|
|
1872
|
-
if (!app.isDefault()) {
|
|
1873
|
-
rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
|
|
1874
|
-
destination: {
|
|
1875
|
-
pathname: `/_next/:path+`
|
|
1876
|
-
}
|
|
1877
|
-
});
|
|
1878
|
-
rewrites.set(`/${app.getAssetPrefix()}/.well-known/vercel/flags`, {
|
|
1879
|
-
destination: {
|
|
1880
|
-
pathname: `/.well-known/vercel/flags`
|
|
1881
|
-
}
|
|
1882
|
-
});
|
|
1883
|
-
if (process.env.VERCEL_MICROFRONTENDS_CONSOLIDATE_SPEED_INSIGHTS === "1") {
|
|
1884
|
-
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1885
|
-
destination: { pathname: "/_vercel/:path*" }
|
|
1886
|
-
});
|
|
1887
|
-
}
|
|
1888
|
-
} else if (microfrontend instanceof MicrofrontendMainConfig) {
|
|
1889
|
-
for (const [_, a] of Object.entries(
|
|
1890
|
-
microfrontend.getChildApplications()
|
|
1891
|
-
)) {
|
|
1892
|
-
const { routing } = a;
|
|
1893
|
-
const domain = getDomainForCurrentEnvironment(microfrontend, a.name);
|
|
1894
|
-
rewrites.set(`/${a.getAssetPrefix()}/:path+`, {
|
|
1895
|
-
destination: {
|
|
1896
|
-
domain,
|
|
1897
|
-
pathname: `/${a.getAssetPrefix()}/:path+`
|
|
1898
|
-
}
|
|
1899
|
-
});
|
|
1900
|
-
for (const group of routing) {
|
|
1901
|
-
if (group.flag) {
|
|
1902
|
-
continue;
|
|
1903
|
-
} else {
|
|
1904
|
-
for (const source of group.paths) {
|
|
1905
|
-
const paths = pathToRewrites(source);
|
|
1906
|
-
for (const p of paths) {
|
|
1907
|
-
rewrites.set(p, {
|
|
1908
|
-
destination: { domain, pathname: p }
|
|
1909
|
-
});
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
return rewritesMapToArr(rewrites);
|
|
1917
|
-
};
|
|
1918
|
-
const newBeforeFiles = buildBeforeFiles();
|
|
1919
|
-
if (next.rewrites && typeof next.rewrites === "function") {
|
|
1920
|
-
const originalRewritesFn = next.rewrites;
|
|
1921
|
-
next.rewrites = async () => {
|
|
1922
|
-
const originalRewrites = await originalRewritesFn();
|
|
1923
|
-
if (typeof originalRewrites === "object" && !Array.isArray(originalRewrites)) {
|
|
1924
|
-
const { beforeFiles = [] } = originalRewrites;
|
|
1925
|
-
return {
|
|
1926
|
-
beforeFiles: [...newBeforeFiles, ...beforeFiles],
|
|
1927
|
-
afterFiles: originalRewrites.afterFiles,
|
|
1928
|
-
fallback: originalRewrites.fallback
|
|
1929
|
-
};
|
|
1930
|
-
}
|
|
1931
|
-
return {
|
|
1932
|
-
beforeFiles: newBeforeFiles,
|
|
1933
|
-
afterFiles: originalRewrites,
|
|
1934
|
-
fallback: []
|
|
1935
|
-
};
|
|
1936
|
-
};
|
|
1937
|
-
} else {
|
|
1938
|
-
next.rewrites = async () => ({
|
|
1939
|
-
beforeFiles: newBeforeFiles,
|
|
1940
|
-
afterFiles: [],
|
|
1941
|
-
fallback: []
|
|
1942
|
-
});
|
|
1943
|
-
}
|
|
1944
|
-
debugRewrites(newBeforeFiles);
|
|
1945
|
-
return {
|
|
1946
|
-
next
|
|
1947
|
-
};
|
|
1948
|
-
}
|
|
1949
|
-
|
|
1950
1853
|
// src/next/config/transforms/server-actions.ts
|
|
1951
1854
|
function debugRewrites2(allowedOrigins) {
|
|
1952
1855
|
if (process.env.MFE_DEBUG === "true" && allowedOrigins) {
|
|
@@ -1967,7 +1870,7 @@ ${table}
|
|
|
1967
1870
|
}
|
|
1968
1871
|
}
|
|
1969
1872
|
var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
|
|
1970
|
-
function
|
|
1873
|
+
function transform5(args) {
|
|
1971
1874
|
const { next, app, microfrontend } = args;
|
|
1972
1875
|
if (microfrontend instanceof MicrofrontendChildConfig) {
|
|
1973
1876
|
console.warn(
|
|
@@ -2024,7 +1927,7 @@ function transform6(args) {
|
|
|
2024
1927
|
}
|
|
2025
1928
|
|
|
2026
1929
|
// src/next/config/transforms/webpack.ts
|
|
2027
|
-
function
|
|
1930
|
+
function transform6(args) {
|
|
2028
1931
|
const { next, microfrontend } = args;
|
|
2029
1932
|
const configWithWebpack = {
|
|
2030
1933
|
...next,
|
|
@@ -2068,11 +1971,10 @@ function transform7(args) {
|
|
|
2068
1971
|
var transforms = {
|
|
2069
1972
|
assetPrefix: transform,
|
|
2070
1973
|
draftMode: transform2,
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
webpack: transform7
|
|
1974
|
+
redirects: transform3,
|
|
1975
|
+
rewrites: transform4,
|
|
1976
|
+
serverActions: transform5,
|
|
1977
|
+
webpack: transform6
|
|
2076
1978
|
};
|
|
2077
1979
|
|
|
2078
1980
|
// src/next/config/env.ts
|
|
@@ -2101,9 +2003,9 @@ function setEnvironment({
|
|
|
2101
2003
|
NEXT_PUBLIC_MFE_CLIENT_CONFIG: JSON.stringify(
|
|
2102
2004
|
microfrontends.config.toClientConfig().serialize()
|
|
2103
2005
|
),
|
|
2104
|
-
...process.env.
|
|
2006
|
+
...process.env.ROUTE_OBSERVABILITY_TO_THIS_PROJECT && app.getAssetPrefix() ? {
|
|
2105
2007
|
NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH: `/${app.getAssetPrefix()}/_vercel`
|
|
2106
|
-
}
|
|
2008
|
+
} : {}
|
|
2107
2009
|
};
|
|
2108
2010
|
const serverEnvs = {
|
|
2109
2011
|
MFE_CURRENT_APPLICATION: app.name,
|
|
@@ -2164,13 +2066,13 @@ function withMicrofrontends(nextConfig, opts) {
|
|
|
2164
2066
|
const app = microfrontends.config.getApplication(fromApp);
|
|
2165
2067
|
setEnvironment({ app, microfrontends });
|
|
2166
2068
|
let next = { ...nextConfig };
|
|
2167
|
-
for (const [key,
|
|
2069
|
+
for (const [key, transform7] of typedEntries(transforms)) {
|
|
2168
2070
|
if (opts?.skipTransforms?.includes(key)) {
|
|
2169
2071
|
console.log(`Skipping ${key} transform`);
|
|
2170
2072
|
continue;
|
|
2171
2073
|
}
|
|
2172
2074
|
try {
|
|
2173
|
-
const transformedConfig =
|
|
2075
|
+
const transformedConfig = transform7({
|
|
2174
2076
|
app,
|
|
2175
2077
|
next,
|
|
2176
2078
|
microfrontend: microfrontends.config,
|