@vercel/microfrontends 0.10.1 → 0.11.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 +261 -91
- package/dist/{index-acb44057.d.ts → index-a99d5459.d.ts} +2 -2
- package/dist/next/config.cjs +10 -1
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +10 -1
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +17 -1
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +17 -1
- package/dist/next/middleware.js.map +1 -1
- package/dist/{types-7b1cd9f7.d.ts → types-0030abae.d.ts} +0 -1
- package/dist/{types-c3d15d04.d.ts → types-c777c2f5.d.ts} +1 -1
- package/dist/v2/config.cjs +1 -1
- package/dist/v2/config.cjs.map +1 -1
- package/dist/v2/config.d.ts +3 -3
- package/dist/v2/config.js +1 -1
- package/dist/v2/config.js.map +1 -1
- package/dist/v2/microfrontends/server.cjs +214 -44
- package/dist/v2/microfrontends/server.cjs.map +1 -1
- package/dist/v2/microfrontends/server.d.ts +22 -3
- package/dist/v2/microfrontends/server.js +214 -44
- package/dist/v2/microfrontends/server.js.map +1 -1
- package/dist/v2/microfrontends.cjs +1 -1
- package/dist/v2/microfrontends.cjs.map +1 -1
- package/dist/v2/microfrontends.d.ts +3 -3
- package/dist/v2/microfrontends.js +1 -1
- package/dist/v2/microfrontends.js.map +1 -1
- package/dist/v2/next/config.cjs +248 -73
- package/dist/v2/next/config.cjs.map +1 -1
- package/dist/v2/next/config.js +248 -73
- package/dist/v2/next/config.js.map +1 -1
- package/dist/v2/next/endpoints.cjs +5 -2
- package/dist/v2/next/endpoints.cjs.map +1 -1
- package/dist/v2/next/endpoints.d.ts +1 -1
- package/dist/v2/next/endpoints.js +5 -2
- package/dist/v2/next/endpoints.js.map +1 -1
- package/dist/v2/next/middleware.cjs +107 -87
- package/dist/v2/next/middleware.cjs.map +1 -1
- package/dist/v2/next/middleware.js +107 -87
- package/dist/v2/next/middleware.js.map +1 -1
- package/dist/v2/overrides.cjs +1 -1
- package/dist/v2/overrides.cjs.map +1 -1
- package/dist/v2/overrides.d.ts +3 -3
- package/dist/v2/overrides.js +1 -1
- package/dist/v2/overrides.js.map +1 -1
- package/dist/v2/schema.d.ts +1 -1
- package/dist/validation.cjs +0 -3
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +0 -1
- package/dist/validation.js +0 -3
- package/dist/validation.js.map +1 -1
- package/package.json +7 -7
- package/schema/schema-v2.json +0 -3
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.11.0",
|
|
33
33
|
private: false,
|
|
34
34
|
description: "Defines configuration and utilities for micro-frontend development",
|
|
35
35
|
repository: {
|
|
@@ -181,9 +181,9 @@ var package_default = {
|
|
|
181
181
|
"@vercel-private/conformance": "^1.12.2-canary.0",
|
|
182
182
|
jest: "^29.7.0",
|
|
183
183
|
"jest-environment-jsdom": "29.2.2",
|
|
184
|
-
next: "15.0.4-canary.
|
|
185
|
-
react: "19.0.0
|
|
186
|
-
"react-dom": "19.0.0
|
|
184
|
+
next: "15.0.4-canary.47",
|
|
185
|
+
react: "19.0.0",
|
|
186
|
+
"react-dom": "19.0.0",
|
|
187
187
|
"ts-json-schema-generator": "^1.1.2",
|
|
188
188
|
tsup: "^6.6.2",
|
|
189
189
|
tsx: "^4.6.2",
|
|
@@ -191,9 +191,9 @@ var package_default = {
|
|
|
191
191
|
webpack: "5"
|
|
192
192
|
},
|
|
193
193
|
peerDependencies: {
|
|
194
|
-
next: "15.0.4-canary.
|
|
195
|
-
react: "19.0.0
|
|
196
|
-
"react-dom": "19.0.0
|
|
194
|
+
next: "15.0.4-canary.47",
|
|
195
|
+
react: "19.0.0",
|
|
196
|
+
"react-dom": "19.0.0"
|
|
197
197
|
},
|
|
198
198
|
publishConfig: {
|
|
199
199
|
access: "restricted"
|
|
@@ -1090,8 +1090,8 @@ function validateMainPath(applicationConfigsById) {
|
|
|
1090
1090
|
});
|
|
1091
1091
|
}
|
|
1092
1092
|
for (const { id: otherId, paths } of pathsWithApp) {
|
|
1093
|
-
const isValid = paths.every((
|
|
1094
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(
|
|
1093
|
+
const isValid = paths.every((path6) => {
|
|
1094
|
+
const matcher = (0, import_path_to_regexp.pathToRegexp)(path6);
|
|
1095
1095
|
return !matcher.test(defaultRoute);
|
|
1096
1096
|
});
|
|
1097
1097
|
if (!isValid) {
|
|
@@ -1103,8 +1103,8 @@ function validateMainPath(applicationConfigsById) {
|
|
|
1103
1103
|
}
|
|
1104
1104
|
} else {
|
|
1105
1105
|
const allPaths = app.routing.matches.flatMap((match) => match.paths);
|
|
1106
|
-
const isValid = allPaths.some((
|
|
1107
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(
|
|
1106
|
+
const isValid = allPaths.some((path6) => {
|
|
1107
|
+
const matcher = (0, import_path_to_regexp.pathToRegexp)(path6);
|
|
1108
1108
|
return matcher.test(defaultRoute);
|
|
1109
1109
|
});
|
|
1110
1110
|
if (!isValid) {
|
|
@@ -1124,18 +1124,18 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1124
1124
|
continue;
|
|
1125
1125
|
}
|
|
1126
1126
|
for (const pathMatch of app.routing.matches) {
|
|
1127
|
-
for (const
|
|
1128
|
-
const maybeError = validatePathExpression(
|
|
1127
|
+
for (const path6 of pathMatch.paths) {
|
|
1128
|
+
const maybeError = validatePathExpression(path6);
|
|
1129
1129
|
if (maybeError) {
|
|
1130
1130
|
errors.push(maybeError);
|
|
1131
1131
|
}
|
|
1132
|
-
const existing = pathsByApplicationId.get(
|
|
1132
|
+
const existing = pathsByApplicationId.get(path6);
|
|
1133
1133
|
if (existing) {
|
|
1134
1134
|
existing.applications.push(id);
|
|
1135
1135
|
} else {
|
|
1136
|
-
pathsByApplicationId.set(
|
|
1136
|
+
pathsByApplicationId.set(path6, {
|
|
1137
1137
|
applications: [id],
|
|
1138
|
-
matcher: (0, import_path_to_regexp.pathToRegexp)(
|
|
1138
|
+
matcher: (0, import_path_to_regexp.pathToRegexp)(path6),
|
|
1139
1139
|
applicationId: id
|
|
1140
1140
|
});
|
|
1141
1141
|
}
|
|
@@ -1143,10 +1143,10 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1143
1143
|
}
|
|
1144
1144
|
}
|
|
1145
1145
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
1146
|
-
entries.forEach(([
|
|
1146
|
+
entries.forEach(([path6, { applications: ids, matcher, applicationId }]) => {
|
|
1147
1147
|
if (ids.length > 1) {
|
|
1148
1148
|
errors.push(
|
|
1149
|
-
`Duplicate path "${
|
|
1149
|
+
`Duplicate path "${path6}" for applications "${ids.join(", ")}"`
|
|
1150
1150
|
);
|
|
1151
1151
|
}
|
|
1152
1152
|
entries.forEach(
|
|
@@ -1154,14 +1154,14 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1154
1154
|
matchPath,
|
|
1155
1155
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
1156
1156
|
]) => {
|
|
1157
|
-
if (
|
|
1157
|
+
if (path6 === matchPath) {
|
|
1158
1158
|
return;
|
|
1159
1159
|
}
|
|
1160
1160
|
if (applicationId === matchApplicationId) {
|
|
1161
1161
|
return;
|
|
1162
1162
|
}
|
|
1163
1163
|
if (matcher.test(matchPath)) {
|
|
1164
|
-
const source = `"${
|
|
1164
|
+
const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
1165
1165
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
1166
1166
|
errors.push(
|
|
1167
1167
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -1178,25 +1178,25 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1178
1178
|
}
|
|
1179
1179
|
};
|
|
1180
1180
|
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
1181
|
-
function validatePathExpression(
|
|
1182
|
-
const tokens = (0, import_path_to_regexp.parse)(
|
|
1181
|
+
function validatePathExpression(path6) {
|
|
1182
|
+
const tokens = (0, import_path_to_regexp.parse)(path6);
|
|
1183
1183
|
for (let i = 0; i < tokens.length; i++) {
|
|
1184
1184
|
const token = tokens[i];
|
|
1185
1185
|
if (token === void 0) {
|
|
1186
|
-
return `token ${i} in ${
|
|
1186
|
+
return `token ${i} in ${path6} is undefined, this shouldn't happen`;
|
|
1187
1187
|
}
|
|
1188
1188
|
if (typeof token !== "string") {
|
|
1189
1189
|
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
1190
|
-
return `Path ${
|
|
1190
|
+
return `Path ${path6} cannot use a regular expression wildcard`;
|
|
1191
1191
|
}
|
|
1192
1192
|
if (token.prefix !== "/") {
|
|
1193
|
-
return `Wildcard :${token.name} must be immediately after a / in ${
|
|
1193
|
+
return `Wildcard :${token.name} must be immediately after a / in ${path6}`;
|
|
1194
1194
|
}
|
|
1195
1195
|
if (token.suffix) {
|
|
1196
1196
|
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
1197
1197
|
}
|
|
1198
1198
|
if (token.modifier && i !== tokens.length - 1) {
|
|
1199
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${
|
|
1199
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
|
|
1200
1200
|
}
|
|
1201
1201
|
}
|
|
1202
1202
|
}
|
|
@@ -1474,22 +1474,22 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1474
1474
|
continue;
|
|
1475
1475
|
}
|
|
1476
1476
|
for (const pathMatch of app.routing) {
|
|
1477
|
-
for (const
|
|
1478
|
-
const tokens = (0, import_path_to_regexp2.parse)(
|
|
1477
|
+
for (const path6 of pathMatch.paths) {
|
|
1478
|
+
const tokens = (0, import_path_to_regexp2.parse)(path6);
|
|
1479
1479
|
for (const token of tokens.slice(0, -1)) {
|
|
1480
1480
|
if (typeof token !== "string") {
|
|
1481
1481
|
errors.push(
|
|
1482
|
-
`Path ${
|
|
1482
|
+
`Path ${path6} may only have a :wildcard in the last path component`
|
|
1483
1483
|
);
|
|
1484
1484
|
}
|
|
1485
1485
|
}
|
|
1486
|
-
const existing = pathsByApplicationId.get(
|
|
1486
|
+
const existing = pathsByApplicationId.get(path6);
|
|
1487
1487
|
if (existing) {
|
|
1488
1488
|
existing.applications.push(id);
|
|
1489
1489
|
} else {
|
|
1490
|
-
pathsByApplicationId.set(
|
|
1490
|
+
pathsByApplicationId.set(path6, {
|
|
1491
1491
|
applications: [id],
|
|
1492
|
-
matcher: (0, import_path_to_regexp2.pathToRegexp)(
|
|
1492
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path6),
|
|
1493
1493
|
applicationId: id
|
|
1494
1494
|
});
|
|
1495
1495
|
}
|
|
@@ -1497,10 +1497,10 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1497
1497
|
}
|
|
1498
1498
|
}
|
|
1499
1499
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
1500
|
-
entries.forEach(([
|
|
1500
|
+
entries.forEach(([path6, { applications: ids, matcher, applicationId }]) => {
|
|
1501
1501
|
if (ids.length > 1) {
|
|
1502
1502
|
errors.push(
|
|
1503
|
-
`Duplicate path "${
|
|
1503
|
+
`Duplicate path "${path6}" for applications "${ids.join(", ")}"`
|
|
1504
1504
|
);
|
|
1505
1505
|
}
|
|
1506
1506
|
entries.forEach(
|
|
@@ -1508,14 +1508,14 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1508
1508
|
matchPath,
|
|
1509
1509
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
1510
1510
|
]) => {
|
|
1511
|
-
if (
|
|
1511
|
+
if (path6 === matchPath) {
|
|
1512
1512
|
return;
|
|
1513
1513
|
}
|
|
1514
1514
|
if (applicationId === matchApplicationId) {
|
|
1515
1515
|
return;
|
|
1516
1516
|
}
|
|
1517
1517
|
if (matcher.test(matchPath)) {
|
|
1518
|
-
const source = `"${
|
|
1518
|
+
const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
1519
1519
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
1520
1520
|
errors.push(
|
|
1521
1521
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -1790,21 +1790,21 @@ var MicrofrontendConfigClient = class {
|
|
|
1790
1790
|
isEqual(other) {
|
|
1791
1791
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
1792
1792
|
}
|
|
1793
|
-
getApplicationNameForPath(
|
|
1794
|
-
if (!
|
|
1793
|
+
getApplicationNameForPath(path6) {
|
|
1794
|
+
if (!path6.startsWith("/")) {
|
|
1795
1795
|
throw new Error(`Path must start with a /`);
|
|
1796
1796
|
}
|
|
1797
|
-
if (this.pathCache[
|
|
1798
|
-
return this.pathCache[
|
|
1797
|
+
if (this.pathCache[path6]) {
|
|
1798
|
+
return this.pathCache[path6];
|
|
1799
1799
|
}
|
|
1800
|
-
const pathname = new URL(
|
|
1800
|
+
const pathname = new URL(path6, "https://example.com").pathname;
|
|
1801
1801
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
1802
1802
|
if (application.routing) {
|
|
1803
1803
|
for (const group of application.routing) {
|
|
1804
1804
|
for (const childPath of group.paths) {
|
|
1805
1805
|
const regexp = (0, import_path_to_regexp3.pathToRegexp)(childPath);
|
|
1806
1806
|
if (regexp.test(pathname)) {
|
|
1807
|
-
this.pathCache[
|
|
1807
|
+
this.pathCache[path6] = name;
|
|
1808
1808
|
return name;
|
|
1809
1809
|
}
|
|
1810
1810
|
}
|
|
@@ -1817,7 +1817,7 @@ var MicrofrontendConfigClient = class {
|
|
|
1817
1817
|
if (!defaultApplication) {
|
|
1818
1818
|
return null;
|
|
1819
1819
|
}
|
|
1820
|
-
this.pathCache[
|
|
1820
|
+
this.pathCache[path6] = defaultApplication[0];
|
|
1821
1821
|
return defaultApplication[0];
|
|
1822
1822
|
}
|
|
1823
1823
|
serialize() {
|
|
@@ -1826,7 +1826,7 @@ var MicrofrontendConfigClient = class {
|
|
|
1826
1826
|
};
|
|
1827
1827
|
|
|
1828
1828
|
// src/config-v2/overrides/constants.ts
|
|
1829
|
-
var OVERRIDES_COOKIE_PREFIX2 = "vercel-
|
|
1829
|
+
var OVERRIDES_COOKIE_PREFIX2 = "vercel-micro-frontends-override";
|
|
1830
1830
|
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX2}:env:`;
|
|
1831
1831
|
|
|
1832
1832
|
// src/config-v2/overrides/is-override-cookie.ts
|
|
@@ -2091,8 +2091,8 @@ function isMainConfig2(c) {
|
|
|
2091
2091
|
}
|
|
2092
2092
|
|
|
2093
2093
|
// src/config-v2/microfrontends/server/index.ts
|
|
2094
|
-
var
|
|
2095
|
-
var
|
|
2094
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
2095
|
+
var import_node_path9 = require("path");
|
|
2096
2096
|
|
|
2097
2097
|
// src/config-v2/microfrontends-config/isomorphic/child.ts
|
|
2098
2098
|
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
@@ -2209,6 +2209,113 @@ function findPackagePath(opts) {
|
|
|
2209
2209
|
return result;
|
|
2210
2210
|
}
|
|
2211
2211
|
|
|
2212
|
+
// src/config-v2/microfrontends/utils/find-default-package.ts
|
|
2213
|
+
var import_node_path6 = require("path");
|
|
2214
|
+
var import_node_fs5 = require("fs");
|
|
2215
|
+
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
2216
|
+
var configCache2 = {};
|
|
2217
|
+
function findDefaultMicrofrontendsPackages({
|
|
2218
|
+
repositoryRoot,
|
|
2219
|
+
applicationName
|
|
2220
|
+
}) {
|
|
2221
|
+
try {
|
|
2222
|
+
const microfrontendsJsonPaths = import_fast_glob2.default.globSync("**/microfrontends.json", {
|
|
2223
|
+
cwd: repositoryRoot,
|
|
2224
|
+
absolute: true,
|
|
2225
|
+
onlyFiles: true,
|
|
2226
|
+
followSymbolicLinks: false,
|
|
2227
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
2228
|
+
});
|
|
2229
|
+
const matchingPaths = [];
|
|
2230
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
2231
|
+
const microfrontendsJsonContent = (0, import_node_fs5.readFileSync)(
|
|
2232
|
+
microfrontendsJsonPath,
|
|
2233
|
+
"utf-8"
|
|
2234
|
+
);
|
|
2235
|
+
const microfrontendsJson = JSON.parse(
|
|
2236
|
+
microfrontendsJsonContent
|
|
2237
|
+
);
|
|
2238
|
+
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
2239
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
if (matchingPaths.length > 1) {
|
|
2243
|
+
throw new Error(
|
|
2244
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
|
|
2245
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
2246
|
+
);
|
|
2247
|
+
}
|
|
2248
|
+
if (matchingPaths.length === 0) {
|
|
2249
|
+
throw new Error(
|
|
2250
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
const [packageJsonPath] = matchingPaths;
|
|
2254
|
+
return (0, import_node_path6.dirname)(packageJsonPath);
|
|
2255
|
+
} catch (error) {
|
|
2256
|
+
return null;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
2260
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
2261
|
+
if (configCache2[cacheKey]) {
|
|
2262
|
+
return configCache2[cacheKey];
|
|
2263
|
+
}
|
|
2264
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
2265
|
+
if (!result) {
|
|
2266
|
+
throw new Error(
|
|
2267
|
+
`Error trying to resolve the main microfrontends.json configuration`
|
|
2268
|
+
);
|
|
2269
|
+
}
|
|
2270
|
+
configCache2[cacheKey] = result;
|
|
2271
|
+
return result;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
// src/config-v2/microfrontends/utils/is-monorepo.ts
|
|
2275
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
2276
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
2277
|
+
function isMonorepo({
|
|
2278
|
+
repositoryRoot
|
|
2279
|
+
}) {
|
|
2280
|
+
try {
|
|
2281
|
+
if (import_node_fs6.default.existsSync(import_node_path7.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
2282
|
+
return true;
|
|
2283
|
+
}
|
|
2284
|
+
if (import_node_fs6.default.existsSync(import_node_path7.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
2285
|
+
return true;
|
|
2286
|
+
}
|
|
2287
|
+
const packageJsonPath = import_node_path7.default.join(repositoryRoot, "package.json");
|
|
2288
|
+
if (!import_node_fs6.default.existsSync(packageJsonPath)) {
|
|
2289
|
+
return false;
|
|
2290
|
+
}
|
|
2291
|
+
const packageJson = JSON.parse(
|
|
2292
|
+
import_node_fs6.default.readFileSync(packageJsonPath, "utf-8")
|
|
2293
|
+
);
|
|
2294
|
+
return packageJson.workspaces !== void 0;
|
|
2295
|
+
} catch (error) {
|
|
2296
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
2297
|
+
return false;
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
// src/config-v2/microfrontends/utils/find-package-root.ts
|
|
2302
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
2303
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
2304
|
+
var PACKAGE_JSON = "package.json";
|
|
2305
|
+
function findPackageRoot(startDir) {
|
|
2306
|
+
let currentDir = startDir || process.cwd();
|
|
2307
|
+
while (currentDir !== import_node_path8.default.parse(currentDir).root) {
|
|
2308
|
+
const pkgJsonPath = import_node_path8.default.join(currentDir, PACKAGE_JSON);
|
|
2309
|
+
if (import_node_fs7.default.existsSync(pkgJsonPath)) {
|
|
2310
|
+
return currentDir;
|
|
2311
|
+
}
|
|
2312
|
+
currentDir = import_node_path8.default.dirname(currentDir);
|
|
2313
|
+
}
|
|
2314
|
+
throw new Error(
|
|
2315
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
2316
|
+
);
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2212
2319
|
// src/config-v2/microfrontends/server/validation.ts
|
|
2213
2320
|
var import_jsonc_parser3 = require("jsonc-parser");
|
|
2214
2321
|
var import_ajv2 = require("ajv");
|
|
@@ -2328,9 +2435,6 @@ var schema_v2_default = {
|
|
|
2328
2435
|
projectId: {
|
|
2329
2436
|
type: "string",
|
|
2330
2437
|
description: "Vercel project ID"
|
|
2331
|
-
},
|
|
2332
|
-
routeSpeedInsightsToDefaultZone: {
|
|
2333
|
-
type: "boolean"
|
|
2334
2438
|
}
|
|
2335
2439
|
},
|
|
2336
2440
|
required: ["projectId"]
|
|
@@ -2500,8 +2604,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2500
2604
|
pretty: true
|
|
2501
2605
|
}) {
|
|
2502
2606
|
const outputPath = getOutputFilePath();
|
|
2503
|
-
|
|
2504
|
-
|
|
2607
|
+
import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
|
|
2608
|
+
import_node_fs8.default.writeFileSync(
|
|
2505
2609
|
outputPath,
|
|
2506
2610
|
JSON.stringify(
|
|
2507
2611
|
this.config.toSchemaJson(),
|
|
@@ -2563,6 +2667,69 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2563
2667
|
}
|
|
2564
2668
|
return config;
|
|
2565
2669
|
}
|
|
2670
|
+
/**
|
|
2671
|
+
* Looks up the configuration by inferring the package root and looking for a microfrontends.json file. If a file is not found,
|
|
2672
|
+
* it will look for a package in the repository with a microfrontends.json file that contains the current application
|
|
2673
|
+
* and use that configuration.
|
|
2674
|
+
*
|
|
2675
|
+
* This can return either a Child or Main configuration.
|
|
2676
|
+
*/
|
|
2677
|
+
static infer({
|
|
2678
|
+
directory,
|
|
2679
|
+
filePath,
|
|
2680
|
+
meta,
|
|
2681
|
+
cookies,
|
|
2682
|
+
options
|
|
2683
|
+
} = {}) {
|
|
2684
|
+
if (filePath && meta) {
|
|
2685
|
+
return MicrofrontendsServer.fromFile({
|
|
2686
|
+
filePath,
|
|
2687
|
+
cookies,
|
|
2688
|
+
meta,
|
|
2689
|
+
options
|
|
2690
|
+
});
|
|
2691
|
+
}
|
|
2692
|
+
try {
|
|
2693
|
+
const packageRoot = findPackageRoot(directory);
|
|
2694
|
+
const packageJsonPath = (0, import_node_path9.join)(packageRoot, "package.json");
|
|
2695
|
+
const packageJson = JSON.parse(
|
|
2696
|
+
import_node_fs8.default.readFileSync(packageJsonPath, "utf-8")
|
|
2697
|
+
);
|
|
2698
|
+
if (!packageJson.name) {
|
|
2699
|
+
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
2700
|
+
}
|
|
2701
|
+
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
2702
|
+
const maybeConfig = (0, import_node_path9.join)(packageRoot, "microfrontends.json");
|
|
2703
|
+
if (import_node_fs8.default.existsSync(maybeConfig)) {
|
|
2704
|
+
return MicrofrontendsServer.fromFile({
|
|
2705
|
+
filePath: maybeConfig,
|
|
2706
|
+
cookies,
|
|
2707
|
+
meta: configMeta,
|
|
2708
|
+
options
|
|
2709
|
+
});
|
|
2710
|
+
}
|
|
2711
|
+
const repositoryRoot = findRepositoryRoot();
|
|
2712
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
2713
|
+
if (isMonorepo2) {
|
|
2714
|
+
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
2715
|
+
repositoryRoot,
|
|
2716
|
+
applicationName: packageJson.name
|
|
2717
|
+
});
|
|
2718
|
+
return MicrofrontendsServer.fromFile({
|
|
2719
|
+
filePath: (0, import_node_path9.join)(defaultPackage, "microfrontends.json"),
|
|
2720
|
+
cookies,
|
|
2721
|
+
meta: configMeta,
|
|
2722
|
+
options
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
throw new Error("Unable to infer");
|
|
2726
|
+
} catch (e) {
|
|
2727
|
+
throw new MicrofrontendError2(
|
|
2728
|
+
"Unable to infer microfrontends configuration",
|
|
2729
|
+
{ type: "config", subtype: "inference_failed" }
|
|
2730
|
+
);
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2566
2733
|
/*
|
|
2567
2734
|
* Generates a MicrofrontendsServer instance from a file.
|
|
2568
2735
|
*/
|
|
@@ -2573,25 +2740,28 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2573
2740
|
options
|
|
2574
2741
|
}) {
|
|
2575
2742
|
try {
|
|
2576
|
-
const configJson =
|
|
2743
|
+
const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
2577
2744
|
const config = MicrofrontendsServer.validate(configJson);
|
|
2578
2745
|
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
2579
2746
|
const repositoryRoot = findRepositoryRoot();
|
|
2580
|
-
const
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2747
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
2748
|
+
if (isMonorepo2) {
|
|
2749
|
+
const packagePath = findPackagePath({
|
|
2750
|
+
repositoryRoot,
|
|
2751
|
+
name: config.partOf
|
|
2752
|
+
});
|
|
2753
|
+
if (!packagePath) {
|
|
2754
|
+
throw new MicrofrontendError2(
|
|
2755
|
+
`Could not find default application "${config.partOf}" in the repository`,
|
|
2756
|
+
{ type: "config", subtype: "not_found" }
|
|
2757
|
+
);
|
|
2758
|
+
}
|
|
2759
|
+
const mainConfigPath = (0, import_node_path9.join)(packagePath, "microfrontends.json");
|
|
2760
|
+
return MicrofrontendsServer.fromMainConfigFile({
|
|
2761
|
+
filePath: mainConfigPath,
|
|
2762
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
2763
|
+
});
|
|
2589
2764
|
}
|
|
2590
|
-
const mainConfigPath = (0, import_node_path6.join)(packagePath, "microfrontends.json");
|
|
2591
|
-
return MicrofrontendsServer.fromMainConfigFile({
|
|
2592
|
-
filePath: mainConfigPath,
|
|
2593
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
2594
|
-
});
|
|
2595
2765
|
}
|
|
2596
2766
|
return new MicrofrontendsServer({
|
|
2597
2767
|
config,
|
|
@@ -2612,7 +2782,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2612
2782
|
overrides
|
|
2613
2783
|
}) {
|
|
2614
2784
|
try {
|
|
2615
|
-
const config =
|
|
2785
|
+
const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
2616
2786
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
2617
2787
|
if (!isMainConfig(validatedConfig)) {
|
|
2618
2788
|
throw new MicrofrontendError2(
|
|
@@ -2746,7 +2916,7 @@ var LocalProxy = class {
|
|
|
2746
2916
|
const isJWTRedirect = url.searchParams.has("_vercel_jwt");
|
|
2747
2917
|
const defaultHost = this.getDefaultHost(config);
|
|
2748
2918
|
let hostname = null;
|
|
2749
|
-
let
|
|
2919
|
+
let path6 = request2.url;
|
|
2750
2920
|
if (isAuthRedirect) {
|
|
2751
2921
|
hostname = url.searchParams.get("_host_override");
|
|
2752
2922
|
}
|
|
@@ -2756,12 +2926,12 @@ var LocalProxy = class {
|
|
|
2756
2926
|
if (isJWTRedirect) {
|
|
2757
2927
|
hostname = url.searchParams.get("_host_override");
|
|
2758
2928
|
url.searchParams.delete("_host_override");
|
|
2759
|
-
|
|
2929
|
+
path6 = `${url.pathname}${url.search}`;
|
|
2760
2930
|
}
|
|
2761
2931
|
if (!hostname) {
|
|
2762
2932
|
return void 0;
|
|
2763
2933
|
}
|
|
2764
|
-
return { ...defaultHost, path:
|
|
2934
|
+
return { ...defaultHost, path: path6, hostname, protocol: "https", port: 443 };
|
|
2765
2935
|
}
|
|
2766
2936
|
getConfigWithOverrides(cookies) {
|
|
2767
2937
|
if (isV2Config(this.config)) {
|
|
@@ -2792,19 +2962,19 @@ var LocalProxy = class {
|
|
|
2792
2962
|
getTarget(request2) {
|
|
2793
2963
|
const cookies = (0, import_cookie.parse)(request2.headers.cookie || "");
|
|
2794
2964
|
const config = this.getConfigWithOverrides(cookies);
|
|
2795
|
-
const
|
|
2796
|
-
if (!
|
|
2965
|
+
const path6 = request2.url;
|
|
2966
|
+
if (!path6) {
|
|
2797
2967
|
return this.getDefaultHost(config);
|
|
2798
2968
|
}
|
|
2799
2969
|
const authTarget = this.getAuthTarget(request2, config);
|
|
2800
2970
|
if (authTarget) {
|
|
2801
2971
|
return authTarget;
|
|
2802
2972
|
}
|
|
2803
|
-
const url = new URL(`http://example.com${
|
|
2973
|
+
const url = new URL(`http://example.com${path6}`);
|
|
2804
2974
|
const pathname = url.pathname;
|
|
2805
2975
|
if (isV2Config(config)) {
|
|
2806
2976
|
const target = this.findMatchingApplicationV2(
|
|
2807
|
-
|
|
2977
|
+
path6,
|
|
2808
2978
|
pathname,
|
|
2809
2979
|
config.getChildApplications()
|
|
2810
2980
|
);
|
|
@@ -2812,7 +2982,7 @@ var LocalProxy = class {
|
|
|
2812
2982
|
return target;
|
|
2813
2983
|
} else {
|
|
2814
2984
|
const target = this.findMatchingApplicationV1(
|
|
2815
|
-
|
|
2985
|
+
path6,
|
|
2816
2986
|
pathname,
|
|
2817
2987
|
config.getAllApplications()
|
|
2818
2988
|
);
|
|
@@ -2821,11 +2991,11 @@ var LocalProxy = class {
|
|
|
2821
2991
|
}
|
|
2822
2992
|
const defaultHost = this.getDefaultHost(config);
|
|
2823
2993
|
mfeDebug(
|
|
2824
|
-
`no matching routes, routing ${
|
|
2994
|
+
`no matching routes, routing ${path6} to default application: ${JSON.stringify(defaultHost)}`
|
|
2825
2995
|
);
|
|
2826
|
-
return { path:
|
|
2996
|
+
return { path: path6, ...defaultHost };
|
|
2827
2997
|
}
|
|
2828
|
-
findMatchingApplicationV1(
|
|
2998
|
+
findMatchingApplicationV1(path6, pathname, applications) {
|
|
2829
2999
|
for (const application of Object.values(applications)) {
|
|
2830
3000
|
if (application.routing) {
|
|
2831
3001
|
for (const group of application.routing.matches) {
|
|
@@ -2834,9 +3004,9 @@ var LocalProxy = class {
|
|
|
2834
3004
|
if (regexp.test(pathname)) {
|
|
2835
3005
|
const target = this.getApplicationTarget(application);
|
|
2836
3006
|
mfeDebug(
|
|
2837
|
-
`routing ${
|
|
3007
|
+
`routing ${path6} to '${target.application}' at ${target.hostname}`
|
|
2838
3008
|
);
|
|
2839
|
-
return { path:
|
|
3009
|
+
return { path: path6, ...target };
|
|
2840
3010
|
}
|
|
2841
3011
|
}
|
|
2842
3012
|
if (application.routing.assetPrefix) {
|
|
@@ -2846,9 +3016,9 @@ var LocalProxy = class {
|
|
|
2846
3016
|
if (pattern.test(pathname)) {
|
|
2847
3017
|
const target = this.getApplicationTarget(application);
|
|
2848
3018
|
mfeDebug(
|
|
2849
|
-
`routing ${
|
|
3019
|
+
`routing ${path6} to '${target.application}' at ${target.hostname}`
|
|
2850
3020
|
);
|
|
2851
|
-
return { path:
|
|
3021
|
+
return { path: path6, ...target };
|
|
2852
3022
|
}
|
|
2853
3023
|
}
|
|
2854
3024
|
}
|
|
@@ -2856,7 +3026,7 @@ var LocalProxy = class {
|
|
|
2856
3026
|
}
|
|
2857
3027
|
return null;
|
|
2858
3028
|
}
|
|
2859
|
-
findMatchingApplicationV2(
|
|
3029
|
+
findMatchingApplicationV2(path6, pathname, applications) {
|
|
2860
3030
|
for (const application of Object.values(applications)) {
|
|
2861
3031
|
for (const group of application.routing) {
|
|
2862
3032
|
for (const childPath of group.paths) {
|
|
@@ -2864,9 +3034,9 @@ var LocalProxy = class {
|
|
|
2864
3034
|
if (regexp.test(pathname)) {
|
|
2865
3035
|
const target = this.getApplicationTarget(application);
|
|
2866
3036
|
mfeDebug(
|
|
2867
|
-
`routing ${
|
|
3037
|
+
`routing ${path6} to '${target.application}' at ${target.hostname}`
|
|
2868
3038
|
);
|
|
2869
|
-
return { path:
|
|
3039
|
+
return { path: path6, ...target };
|
|
2870
3040
|
}
|
|
2871
3041
|
}
|
|
2872
3042
|
}
|
|
@@ -2875,11 +3045,11 @@ var LocalProxy = class {
|
|
|
2875
3045
|
}
|
|
2876
3046
|
// Handles requests that return data from the local proxy itself.
|
|
2877
3047
|
// Returns true if the request was handled, false otherwise.
|
|
2878
|
-
handleProxyInfoRequest(
|
|
2879
|
-
if (!
|
|
3048
|
+
handleProxyInfoRequest(path6, res) {
|
|
3049
|
+
if (!path6) {
|
|
2880
3050
|
return false;
|
|
2881
3051
|
}
|
|
2882
|
-
const url = new URL(`http://example.comf${
|
|
3052
|
+
const url = new URL(`http://example.comf${path6}`);
|
|
2883
3053
|
const pathname = url.pathname;
|
|
2884
3054
|
switch (pathname) {
|
|
2885
3055
|
case "/.well-known/vercel/microfrontend-routing": {
|
|
@@ -2907,10 +3077,10 @@ var LocalProxy = class {
|
|
|
2907
3077
|
}
|
|
2908
3078
|
const target = this.getTarget(req);
|
|
2909
3079
|
if (target.protocol === "https") {
|
|
2910
|
-
const { hostname, port, path:
|
|
3080
|
+
const { hostname, port, path: path6 } = target;
|
|
2911
3081
|
const requestOptions = {
|
|
2912
3082
|
hostname,
|
|
2913
|
-
path:
|
|
3083
|
+
path: path6,
|
|
2914
3084
|
method: req.method,
|
|
2915
3085
|
headers: {
|
|
2916
3086
|
...req.headers,
|
|
@@ -2938,7 +3108,7 @@ var LocalProxy = class {
|
|
|
2938
3108
|
console.error("Proxy request error: ", err);
|
|
2939
3109
|
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
2940
3110
|
res.end(
|
|
2941
|
-
`Error proxying request for ${target.application} to ${hostname}:${port}${
|
|
3111
|
+
`Error proxying request for ${target.application} to ${hostname}:${port}${path6}`
|
|
2942
3112
|
);
|
|
2943
3113
|
});
|
|
2944
3114
|
} else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as ApplicationId, b as PathGroup, H as HostConfig, L as LocalHostConfig, D as DefaultApplication$1, c as ChildApplication$1, V as Vercel, d as Application$1, C as Config } from './types-
|
|
2
|
-
import { A as ApplicationOverrideConfig, O as OverridesConfig } from './types-
|
|
1
|
+
import { A as ApplicationId, b as PathGroup, H as HostConfig, L as LocalHostConfig, D as DefaultApplication$1, c as ChildApplication$1, V as Vercel, d as Application$1, C as Config } from './types-0030abae.js';
|
|
2
|
+
import { A as ApplicationOverrideConfig, O as OverridesConfig } from './types-c777c2f5.js';
|
|
3
3
|
|
|
4
4
|
interface ClientApplication {
|
|
5
5
|
routing?: PathGroup[];
|