@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/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.19.
|
|
32
|
+
version: "0.19.6",
|
|
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,93 @@ 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
|
+
const buildBeforeFiles = () => {
|
|
1713
|
+
const rewrites = /* @__PURE__ */ new Map();
|
|
1714
|
+
if (!app.isDefault()) {
|
|
1715
|
+
rewrites.set(`/${app.getAssetPrefix()}/_next/:path+`, {
|
|
1716
|
+
destination: {
|
|
1717
|
+
pathname: `/_next/:path+`
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
rewrites.set(`/${app.getAssetPrefix()}/.well-known/vercel/flags`, {
|
|
1721
|
+
destination: {
|
|
1722
|
+
pathname: `/.well-known/vercel/flags`
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1726
|
+
destination: {
|
|
1727
|
+
pathname: `/_vercel/:path*`
|
|
1728
|
+
}
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
return rewritesMapToArr(rewrites);
|
|
1732
|
+
};
|
|
1733
|
+
const newBeforeFiles = buildBeforeFiles();
|
|
1734
|
+
if (next.rewrites && typeof next.rewrites === "function") {
|
|
1735
|
+
const originalRewritesFn = next.rewrites;
|
|
1736
|
+
next.rewrites = async () => {
|
|
1737
|
+
const originalRewrites = await originalRewritesFn();
|
|
1738
|
+
if (typeof originalRewrites === "object" && !Array.isArray(originalRewrites)) {
|
|
1739
|
+
const { beforeFiles = [] } = originalRewrites;
|
|
1740
|
+
return {
|
|
1741
|
+
beforeFiles: [...newBeforeFiles, ...beforeFiles],
|
|
1742
|
+
afterFiles: originalRewrites.afterFiles,
|
|
1743
|
+
fallback: originalRewrites.fallback
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
return {
|
|
1747
|
+
beforeFiles: newBeforeFiles,
|
|
1748
|
+
afterFiles: originalRewrites,
|
|
1749
|
+
fallback: []
|
|
1750
|
+
};
|
|
1751
|
+
};
|
|
1752
|
+
} else {
|
|
1753
|
+
next.rewrites = async () => ({
|
|
1754
|
+
beforeFiles: newBeforeFiles,
|
|
1755
|
+
afterFiles: [],
|
|
1756
|
+
fallback: []
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
debugRewrites(newBeforeFiles);
|
|
1760
|
+
return {
|
|
1761
|
+
next
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1735
1765
|
// src/routing/get-domain-from-environment.ts
|
|
1736
1766
|
function getDomainFromEnvironment({
|
|
1737
1767
|
app,
|
|
@@ -1815,138 +1845,6 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
|
1815
1845
|
}
|
|
1816
1846
|
}
|
|
1817
1847
|
|
|
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
1848
|
// src/next/config/transforms/server-actions.ts
|
|
1951
1849
|
function debugRewrites2(allowedOrigins) {
|
|
1952
1850
|
if (process.env.MFE_DEBUG === "true" && allowedOrigins) {
|
|
@@ -1967,7 +1865,7 @@ ${table}
|
|
|
1967
1865
|
}
|
|
1968
1866
|
}
|
|
1969
1867
|
var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
|
|
1970
|
-
function
|
|
1868
|
+
function transform5(args) {
|
|
1971
1869
|
const { next, app, microfrontend } = args;
|
|
1972
1870
|
if (microfrontend instanceof MicrofrontendChildConfig) {
|
|
1973
1871
|
console.warn(
|
|
@@ -2024,7 +1922,7 @@ function transform6(args) {
|
|
|
2024
1922
|
}
|
|
2025
1923
|
|
|
2026
1924
|
// src/next/config/transforms/webpack.ts
|
|
2027
|
-
function
|
|
1925
|
+
function transform6(args) {
|
|
2028
1926
|
const { next, microfrontend } = args;
|
|
2029
1927
|
const configWithWebpack = {
|
|
2030
1928
|
...next,
|
|
@@ -2068,11 +1966,10 @@ function transform7(args) {
|
|
|
2068
1966
|
var transforms = {
|
|
2069
1967
|
assetPrefix: transform,
|
|
2070
1968
|
draftMode: transform2,
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
webpack: transform7
|
|
1969
|
+
redirects: transform3,
|
|
1970
|
+
rewrites: transform4,
|
|
1971
|
+
serverActions: transform5,
|
|
1972
|
+
webpack: transform6
|
|
2076
1973
|
};
|
|
2077
1974
|
|
|
2078
1975
|
// src/next/config/env.ts
|
|
@@ -2101,9 +1998,9 @@ function setEnvironment({
|
|
|
2101
1998
|
NEXT_PUBLIC_MFE_CLIENT_CONFIG: JSON.stringify(
|
|
2102
1999
|
microfrontends.config.toClientConfig().serialize()
|
|
2103
2000
|
),
|
|
2104
|
-
...process.env.
|
|
2001
|
+
...process.env.ROUTE_OBSERVABILITY_TO_THIS_PROJECT && app.getAssetPrefix() ? {
|
|
2105
2002
|
NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH: `/${app.getAssetPrefix()}/_vercel`
|
|
2106
|
-
}
|
|
2003
|
+
} : {}
|
|
2107
2004
|
};
|
|
2108
2005
|
const serverEnvs = {
|
|
2109
2006
|
MFE_CURRENT_APPLICATION: app.name,
|
|
@@ -2164,13 +2061,13 @@ function withMicrofrontends(nextConfig, opts) {
|
|
|
2164
2061
|
const app = microfrontends.config.getApplication(fromApp);
|
|
2165
2062
|
setEnvironment({ app, microfrontends });
|
|
2166
2063
|
let next = { ...nextConfig };
|
|
2167
|
-
for (const [key,
|
|
2064
|
+
for (const [key, transform7] of typedEntries(transforms)) {
|
|
2168
2065
|
if (opts?.skipTransforms?.includes(key)) {
|
|
2169
2066
|
console.log(`Skipping ${key} transform`);
|
|
2170
2067
|
continue;
|
|
2171
2068
|
}
|
|
2172
2069
|
try {
|
|
2173
|
-
const transformedConfig =
|
|
2070
|
+
const transformedConfig = transform7({
|
|
2174
2071
|
app,
|
|
2175
2072
|
next,
|
|
2176
2073
|
microfrontend: microfrontends.config,
|