@vercel/microfrontends 0.12.1 → 0.13.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 +164 -124
- package/dist/utils/mfe-port.cjs +2690 -0
- package/dist/utils/mfe-port.cjs.map +1 -0
- package/dist/utils/mfe-port.d.ts +8 -0
- package/dist/utils/mfe-port.js +2655 -0
- package/dist/utils/mfe-port.js.map +1 -0
- package/dist/v2/next/config.cjs +10 -5
- package/dist/v2/next/config.cjs.map +1 -1
- package/dist/v2/next/config.js +10 -5
- package/dist/v2/next/config.js.map +1 -1
- package/dist/v2/next/middleware.cjs +10 -5
- package/dist/v2/next/middleware.cjs.map +1 -1
- package/dist/v2/next/middleware.js +10 -5
- package/dist/v2/next/middleware.js.map +1 -1
- package/package.json +12 -5
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.13.0",
|
|
33
33
|
private: false,
|
|
34
34
|
description: "Defines configuration and utilities for micro-frontend development",
|
|
35
35
|
repository: {
|
|
@@ -119,73 +119,37 @@ var package_default = {
|
|
|
119
119
|
"./v2/next/client": {
|
|
120
120
|
import: "./dist/v2/next/client.js",
|
|
121
121
|
require: "./dist/v2/next/client.cjs"
|
|
122
|
+
},
|
|
123
|
+
"./utils/mfe-port": {
|
|
124
|
+
import: "./dist/utils/mfe-port.js",
|
|
125
|
+
require: "./dist/utils/mfe-port.cjs"
|
|
122
126
|
}
|
|
123
127
|
},
|
|
124
128
|
typesVersions: {
|
|
125
129
|
"*": {
|
|
126
|
-
validation: [
|
|
127
|
-
|
|
128
|
-
],
|
|
129
|
-
config: [
|
|
130
|
-
|
|
131
|
-
],
|
|
132
|
-
"
|
|
133
|
-
|
|
134
|
-
],
|
|
135
|
-
"config
|
|
136
|
-
|
|
137
|
-
],
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
],
|
|
141
|
-
"next/
|
|
142
|
-
|
|
143
|
-
],
|
|
144
|
-
"next/
|
|
145
|
-
|
|
146
|
-
],
|
|
147
|
-
"next/endpoints": [
|
|
148
|
-
"./dist/next/endpoints.d.ts"
|
|
149
|
-
],
|
|
150
|
-
"next/testing": [
|
|
151
|
-
"./dist/next/testing.d.ts"
|
|
152
|
-
],
|
|
153
|
-
"v2/config": [
|
|
154
|
-
"./dist/v2/config.d.ts"
|
|
155
|
-
],
|
|
156
|
-
"v2/microfrontends": [
|
|
157
|
-
"./dist/v2/microfrontends.d.ts"
|
|
158
|
-
],
|
|
159
|
-
"v2/overrides": [
|
|
160
|
-
"./dist/v2/overrides.d.ts"
|
|
161
|
-
],
|
|
162
|
-
"v2/microfrontends/server": [
|
|
163
|
-
"./dist/v2/microfrontends/server.d.ts"
|
|
164
|
-
],
|
|
165
|
-
"v2/schema": [
|
|
166
|
-
"./dist/v2/schema.d.ts"
|
|
167
|
-
],
|
|
168
|
-
"v2/next/config": [
|
|
169
|
-
"./dist/v2/next/config.d.ts"
|
|
170
|
-
],
|
|
171
|
-
"v2/next/middleware": [
|
|
172
|
-
"./dist/v2/next/middleware.d.ts"
|
|
173
|
-
],
|
|
174
|
-
"v2/next/endpoints": [
|
|
175
|
-
"./dist/v2/next/endpoints.d.ts"
|
|
176
|
-
],
|
|
177
|
-
"next/client": [
|
|
178
|
-
"./dist/next/client.d.ts"
|
|
179
|
-
],
|
|
180
|
-
"v2/next/client": [
|
|
181
|
-
"./dist/v2/next/client.d.ts"
|
|
182
|
-
]
|
|
130
|
+
validation: ["./dist/validation.d.ts"],
|
|
131
|
+
config: ["./dist/config.d.ts"],
|
|
132
|
+
"config/client": ["./dist/config/client.d.ts"],
|
|
133
|
+
"config/edge": ["./dist/config/edge.d.ts"],
|
|
134
|
+
overrides: ["./dist/overrides.d.ts"],
|
|
135
|
+
"next/config": ["./dist/next/config.d.ts"],
|
|
136
|
+
"next/middleware": ["./dist/next/middleware.d.ts"],
|
|
137
|
+
"next/endpoints": ["./dist/next/endpoints.d.ts"],
|
|
138
|
+
"next/testing": ["./dist/next/testing.d.ts"],
|
|
139
|
+
"v2/config": ["./dist/v2/config.d.ts"],
|
|
140
|
+
"v2/microfrontends": ["./dist/v2/microfrontends.d.ts"],
|
|
141
|
+
"v2/overrides": ["./dist/v2/overrides.d.ts"],
|
|
142
|
+
"v2/microfrontends/server": ["./dist/v2/microfrontends/server.d.ts"],
|
|
143
|
+
"v2/schema": ["./dist/v2/schema.d.ts"],
|
|
144
|
+
"v2/next/config": ["./dist/v2/next/config.d.ts"],
|
|
145
|
+
"v2/next/middleware": ["./dist/v2/next/middleware.d.ts"],
|
|
146
|
+
"v2/next/endpoints": ["./dist/v2/next/endpoints.d.ts"],
|
|
147
|
+
"next/client": ["./dist/next/client.d.ts"],
|
|
148
|
+
"v2/next/client": ["./dist/v2/next/client.d.ts"],
|
|
149
|
+
"utils/mfe-port": ["./dist/utils/mfe-port.d.ts"]
|
|
183
150
|
}
|
|
184
151
|
},
|
|
185
|
-
files: [
|
|
186
|
-
"dist",
|
|
187
|
-
"schema"
|
|
188
|
-
],
|
|
152
|
+
files: ["dist", "schema"],
|
|
189
153
|
scripts: {
|
|
190
154
|
build: "tsup",
|
|
191
155
|
postbuild: "pnpm generate:exports",
|
|
@@ -223,7 +187,7 @@ var package_default = {
|
|
|
223
187
|
"@vercel-private/conformance": "^1.12.2-canary.0",
|
|
224
188
|
jest: "^29.7.0",
|
|
225
189
|
"jest-environment-jsdom": "29.2.2",
|
|
226
|
-
next: "15.1.1-canary.
|
|
190
|
+
next: "15.1.1-canary.12",
|
|
227
191
|
react: "19.0.0",
|
|
228
192
|
"react-dom": "19.0.0",
|
|
229
193
|
"ts-json-schema-generator": "^1.1.2",
|
|
@@ -233,7 +197,7 @@ var package_default = {
|
|
|
233
197
|
webpack: "5"
|
|
234
198
|
},
|
|
235
199
|
peerDependencies: {
|
|
236
|
-
next: "15.1.1-canary.
|
|
200
|
+
next: "15.1.1-canary.12",
|
|
237
201
|
react: "19.0.0",
|
|
238
202
|
"react-dom": "19.0.0"
|
|
239
203
|
},
|
|
@@ -1132,8 +1096,8 @@ function validateMainPath(applicationConfigsById) {
|
|
|
1132
1096
|
});
|
|
1133
1097
|
}
|
|
1134
1098
|
for (const { id: otherId, paths } of pathsWithApp) {
|
|
1135
|
-
const isValid = paths.every((
|
|
1136
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(
|
|
1099
|
+
const isValid = paths.every((path7) => {
|
|
1100
|
+
const matcher = (0, import_path_to_regexp.pathToRegexp)(path7);
|
|
1137
1101
|
return !matcher.test(defaultRoute);
|
|
1138
1102
|
});
|
|
1139
1103
|
if (!isValid) {
|
|
@@ -1145,8 +1109,8 @@ function validateMainPath(applicationConfigsById) {
|
|
|
1145
1109
|
}
|
|
1146
1110
|
} else {
|
|
1147
1111
|
const allPaths = app.routing.matches.flatMap((match) => match.paths);
|
|
1148
|
-
const isValid = allPaths.some((
|
|
1149
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(
|
|
1112
|
+
const isValid = allPaths.some((path7) => {
|
|
1113
|
+
const matcher = (0, import_path_to_regexp.pathToRegexp)(path7);
|
|
1150
1114
|
return matcher.test(defaultRoute);
|
|
1151
1115
|
});
|
|
1152
1116
|
if (!isValid) {
|
|
@@ -1166,18 +1130,18 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1166
1130
|
continue;
|
|
1167
1131
|
}
|
|
1168
1132
|
for (const pathMatch of app.routing.matches) {
|
|
1169
|
-
for (const
|
|
1170
|
-
const maybeError = validatePathExpression(
|
|
1133
|
+
for (const path7 of pathMatch.paths) {
|
|
1134
|
+
const maybeError = validatePathExpression(path7);
|
|
1171
1135
|
if (maybeError) {
|
|
1172
1136
|
errors.push(maybeError);
|
|
1173
1137
|
}
|
|
1174
|
-
const existing = pathsByApplicationId.get(
|
|
1138
|
+
const existing = pathsByApplicationId.get(path7);
|
|
1175
1139
|
if (existing) {
|
|
1176
1140
|
existing.applications.push(id);
|
|
1177
1141
|
} else {
|
|
1178
|
-
pathsByApplicationId.set(
|
|
1142
|
+
pathsByApplicationId.set(path7, {
|
|
1179
1143
|
applications: [id],
|
|
1180
|
-
matcher: (0, import_path_to_regexp.pathToRegexp)(
|
|
1144
|
+
matcher: (0, import_path_to_regexp.pathToRegexp)(path7),
|
|
1181
1145
|
applicationId: id
|
|
1182
1146
|
});
|
|
1183
1147
|
}
|
|
@@ -1185,10 +1149,10 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1185
1149
|
}
|
|
1186
1150
|
}
|
|
1187
1151
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
1188
|
-
entries.forEach(([
|
|
1152
|
+
entries.forEach(([path7, { applications: ids, matcher, applicationId }]) => {
|
|
1189
1153
|
if (ids.length > 1) {
|
|
1190
1154
|
errors.push(
|
|
1191
|
-
`Duplicate path "${
|
|
1155
|
+
`Duplicate path "${path7}" for applications "${ids.join(", ")}"`
|
|
1192
1156
|
);
|
|
1193
1157
|
}
|
|
1194
1158
|
entries.forEach(
|
|
@@ -1196,14 +1160,14 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1196
1160
|
matchPath,
|
|
1197
1161
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
1198
1162
|
]) => {
|
|
1199
|
-
if (
|
|
1163
|
+
if (path7 === matchPath) {
|
|
1200
1164
|
return;
|
|
1201
1165
|
}
|
|
1202
1166
|
if (applicationId === matchApplicationId) {
|
|
1203
1167
|
return;
|
|
1204
1168
|
}
|
|
1205
1169
|
if (matcher.test(matchPath)) {
|
|
1206
|
-
const source = `"${
|
|
1170
|
+
const source = `"${path7}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
1207
1171
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
1208
1172
|
errors.push(
|
|
1209
1173
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -1220,25 +1184,25 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1220
1184
|
}
|
|
1221
1185
|
};
|
|
1222
1186
|
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
1223
|
-
function validatePathExpression(
|
|
1224
|
-
const tokens = (0, import_path_to_regexp.parse)(
|
|
1187
|
+
function validatePathExpression(path7) {
|
|
1188
|
+
const tokens = (0, import_path_to_regexp.parse)(path7);
|
|
1225
1189
|
for (let i = 0; i < tokens.length; i++) {
|
|
1226
1190
|
const token = tokens[i];
|
|
1227
1191
|
if (token === void 0) {
|
|
1228
|
-
return `token ${i} in ${
|
|
1192
|
+
return `token ${i} in ${path7} is undefined, this shouldn't happen`;
|
|
1229
1193
|
}
|
|
1230
1194
|
if (typeof token !== "string") {
|
|
1231
1195
|
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
1232
|
-
return `Path ${
|
|
1196
|
+
return `Path ${path7} cannot use a regular expression wildcard`;
|
|
1233
1197
|
}
|
|
1234
1198
|
if (token.prefix !== "/") {
|
|
1235
|
-
return `Wildcard :${token.name} must be immediately after a / in ${
|
|
1199
|
+
return `Wildcard :${token.name} must be immediately after a / in ${path7}`;
|
|
1236
1200
|
}
|
|
1237
1201
|
if (token.suffix) {
|
|
1238
1202
|
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
1239
1203
|
}
|
|
1240
1204
|
if (token.modifier && i !== tokens.length - 1) {
|
|
1241
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${
|
|
1205
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path7}. Modifiers are only allowed in the last path component`;
|
|
1242
1206
|
}
|
|
1243
1207
|
}
|
|
1244
1208
|
}
|
|
@@ -1514,22 +1478,22 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1514
1478
|
continue;
|
|
1515
1479
|
}
|
|
1516
1480
|
for (const pathMatch of app.routing) {
|
|
1517
|
-
for (const
|
|
1518
|
-
const tokens = (0, import_path_to_regexp2.parse)(
|
|
1481
|
+
for (const path7 of pathMatch.paths) {
|
|
1482
|
+
const tokens = (0, import_path_to_regexp2.parse)(path7);
|
|
1519
1483
|
for (const token of tokens.slice(0, -1)) {
|
|
1520
1484
|
if (typeof token !== "string") {
|
|
1521
1485
|
errors.push(
|
|
1522
|
-
`Path ${
|
|
1486
|
+
`Path ${path7} may only have a :wildcard in the last path component`
|
|
1523
1487
|
);
|
|
1524
1488
|
}
|
|
1525
1489
|
}
|
|
1526
|
-
const existing = pathsByApplicationId.get(
|
|
1490
|
+
const existing = pathsByApplicationId.get(path7);
|
|
1527
1491
|
if (existing) {
|
|
1528
1492
|
existing.applications.push(id);
|
|
1529
1493
|
} else {
|
|
1530
|
-
pathsByApplicationId.set(
|
|
1494
|
+
pathsByApplicationId.set(path7, {
|
|
1531
1495
|
applications: [id],
|
|
1532
|
-
matcher: (0, import_path_to_regexp2.pathToRegexp)(
|
|
1496
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path7),
|
|
1533
1497
|
applicationId: id
|
|
1534
1498
|
});
|
|
1535
1499
|
}
|
|
@@ -1537,10 +1501,10 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1537
1501
|
}
|
|
1538
1502
|
}
|
|
1539
1503
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
1540
|
-
entries.forEach(([
|
|
1504
|
+
entries.forEach(([path7, { applications: ids, matcher, applicationId }]) => {
|
|
1541
1505
|
if (ids.length > 1) {
|
|
1542
1506
|
errors.push(
|
|
1543
|
-
`Duplicate path "${
|
|
1507
|
+
`Duplicate path "${path7}" for applications "${ids.join(", ")}"`
|
|
1544
1508
|
);
|
|
1545
1509
|
}
|
|
1546
1510
|
entries.forEach(
|
|
@@ -1548,14 +1512,14 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1548
1512
|
matchPath,
|
|
1549
1513
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
1550
1514
|
]) => {
|
|
1551
|
-
if (
|
|
1515
|
+
if (path7 === matchPath) {
|
|
1552
1516
|
return;
|
|
1553
1517
|
}
|
|
1554
1518
|
if (applicationId === matchApplicationId) {
|
|
1555
1519
|
return;
|
|
1556
1520
|
}
|
|
1557
1521
|
if (matcher.test(matchPath)) {
|
|
1558
|
-
const source = `"${
|
|
1522
|
+
const source = `"${path7}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
1559
1523
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
1560
1524
|
errors.push(
|
|
1561
1525
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -1833,21 +1797,21 @@ var MicrofrontendConfigClient = class {
|
|
|
1833
1797
|
isEqual(other) {
|
|
1834
1798
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
1835
1799
|
}
|
|
1836
|
-
getApplicationNameForPath(
|
|
1837
|
-
if (!
|
|
1800
|
+
getApplicationNameForPath(path7) {
|
|
1801
|
+
if (!path7.startsWith("/")) {
|
|
1838
1802
|
throw new Error(`Path must start with a /`);
|
|
1839
1803
|
}
|
|
1840
|
-
if (this.pathCache[
|
|
1841
|
-
return this.pathCache[
|
|
1804
|
+
if (this.pathCache[path7]) {
|
|
1805
|
+
return this.pathCache[path7];
|
|
1842
1806
|
}
|
|
1843
|
-
const pathname = new URL(
|
|
1807
|
+
const pathname = new URL(path7, "https://example.com").pathname;
|
|
1844
1808
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
1845
1809
|
if (application.routing) {
|
|
1846
1810
|
for (const group of application.routing) {
|
|
1847
1811
|
for (const childPath of group.paths) {
|
|
1848
1812
|
const regexp = (0, import_path_to_regexp3.pathToRegexp)(childPath);
|
|
1849
1813
|
if (regexp.test(pathname)) {
|
|
1850
|
-
this.pathCache[
|
|
1814
|
+
this.pathCache[path7] = name;
|
|
1851
1815
|
return name;
|
|
1852
1816
|
}
|
|
1853
1817
|
}
|
|
@@ -1860,7 +1824,7 @@ var MicrofrontendConfigClient = class {
|
|
|
1860
1824
|
if (!defaultApplication) {
|
|
1861
1825
|
return null;
|
|
1862
1826
|
}
|
|
1863
|
-
this.pathCache[
|
|
1827
|
+
this.pathCache[path7] = defaultApplication[0];
|
|
1864
1828
|
return defaultApplication[0];
|
|
1865
1829
|
}
|
|
1866
1830
|
serialize() {
|
|
@@ -2959,7 +2923,7 @@ var LocalProxy = class {
|
|
|
2959
2923
|
const isJWTRedirect = url.searchParams.has("_vercel_jwt");
|
|
2960
2924
|
const defaultHost = this.getDefaultHost(config);
|
|
2961
2925
|
let hostname = null;
|
|
2962
|
-
let
|
|
2926
|
+
let path7 = request2.url;
|
|
2963
2927
|
if (isAuthRedirect) {
|
|
2964
2928
|
hostname = url.searchParams.get("_host_override");
|
|
2965
2929
|
}
|
|
@@ -2969,12 +2933,12 @@ var LocalProxy = class {
|
|
|
2969
2933
|
if (isJWTRedirect) {
|
|
2970
2934
|
hostname = url.searchParams.get("_host_override");
|
|
2971
2935
|
url.searchParams.delete("_host_override");
|
|
2972
|
-
|
|
2936
|
+
path7 = `${url.pathname}${url.search}`;
|
|
2973
2937
|
}
|
|
2974
2938
|
if (!hostname) {
|
|
2975
2939
|
return void 0;
|
|
2976
2940
|
}
|
|
2977
|
-
return { ...defaultHost, path:
|
|
2941
|
+
return { ...defaultHost, path: path7, hostname, protocol: "https", port: 443 };
|
|
2978
2942
|
}
|
|
2979
2943
|
getConfigWithOverrides(cookies) {
|
|
2980
2944
|
if (isV2Config(this.config)) {
|
|
@@ -3005,19 +2969,19 @@ var LocalProxy = class {
|
|
|
3005
2969
|
getTarget(request2) {
|
|
3006
2970
|
const cookies = (0, import_cookie.parse)(request2.headers.cookie || "");
|
|
3007
2971
|
const config = this.getConfigWithOverrides(cookies);
|
|
3008
|
-
const
|
|
3009
|
-
if (!
|
|
2972
|
+
const path7 = request2.url;
|
|
2973
|
+
if (!path7) {
|
|
3010
2974
|
return this.getDefaultHost(config);
|
|
3011
2975
|
}
|
|
3012
2976
|
const authTarget = this.getAuthTarget(request2, config);
|
|
3013
2977
|
if (authTarget) {
|
|
3014
2978
|
return authTarget;
|
|
3015
2979
|
}
|
|
3016
|
-
const url = new URL(`http://example.com${
|
|
2980
|
+
const url = new URL(`http://example.com${path7}`);
|
|
3017
2981
|
const pathname = url.pathname;
|
|
3018
2982
|
if (isV2Config(config)) {
|
|
3019
2983
|
const target = this.findMatchingApplicationV2(
|
|
3020
|
-
|
|
2984
|
+
path7,
|
|
3021
2985
|
pathname,
|
|
3022
2986
|
config.getChildApplications()
|
|
3023
2987
|
);
|
|
@@ -3025,7 +2989,7 @@ var LocalProxy = class {
|
|
|
3025
2989
|
return target;
|
|
3026
2990
|
} else {
|
|
3027
2991
|
const target = this.findMatchingApplicationV1(
|
|
3028
|
-
|
|
2992
|
+
path7,
|
|
3029
2993
|
pathname,
|
|
3030
2994
|
config.getAllApplications()
|
|
3031
2995
|
);
|
|
@@ -3034,11 +2998,11 @@ var LocalProxy = class {
|
|
|
3034
2998
|
}
|
|
3035
2999
|
const defaultHost = this.getDefaultHost(config);
|
|
3036
3000
|
mfeDebug(
|
|
3037
|
-
`no matching routes, routing ${
|
|
3001
|
+
`no matching routes, routing ${path7} to default application: ${JSON.stringify(defaultHost)}`
|
|
3038
3002
|
);
|
|
3039
|
-
return { path:
|
|
3003
|
+
return { path: path7, ...defaultHost };
|
|
3040
3004
|
}
|
|
3041
|
-
findMatchingApplicationV1(
|
|
3005
|
+
findMatchingApplicationV1(path7, pathname, applications) {
|
|
3042
3006
|
for (const application of Object.values(applications)) {
|
|
3043
3007
|
if (application.routing) {
|
|
3044
3008
|
for (const group of application.routing.matches) {
|
|
@@ -3047,9 +3011,9 @@ var LocalProxy = class {
|
|
|
3047
3011
|
if (regexp.test(pathname)) {
|
|
3048
3012
|
const target = this.getApplicationTarget(application);
|
|
3049
3013
|
mfeDebug(
|
|
3050
|
-
`routing ${
|
|
3014
|
+
`routing ${path7} to '${target.application}' at ${target.hostname}`
|
|
3051
3015
|
);
|
|
3052
|
-
return { path:
|
|
3016
|
+
return { path: path7, ...target };
|
|
3053
3017
|
}
|
|
3054
3018
|
}
|
|
3055
3019
|
if (application.routing.assetPrefix) {
|
|
@@ -3059,9 +3023,9 @@ var LocalProxy = class {
|
|
|
3059
3023
|
if (pattern.test(pathname)) {
|
|
3060
3024
|
const target = this.getApplicationTarget(application);
|
|
3061
3025
|
mfeDebug(
|
|
3062
|
-
`routing ${
|
|
3026
|
+
`routing ${path7} to '${target.application}' at ${target.hostname}`
|
|
3063
3027
|
);
|
|
3064
|
-
return { path:
|
|
3028
|
+
return { path: path7, ...target };
|
|
3065
3029
|
}
|
|
3066
3030
|
}
|
|
3067
3031
|
}
|
|
@@ -3069,7 +3033,7 @@ var LocalProxy = class {
|
|
|
3069
3033
|
}
|
|
3070
3034
|
return null;
|
|
3071
3035
|
}
|
|
3072
|
-
findMatchingApplicationV2(
|
|
3036
|
+
findMatchingApplicationV2(path7, pathname, applications) {
|
|
3073
3037
|
for (const application of Object.values(applications)) {
|
|
3074
3038
|
for (const group of application.routing) {
|
|
3075
3039
|
for (const childPath of group.paths) {
|
|
@@ -3077,9 +3041,9 @@ var LocalProxy = class {
|
|
|
3077
3041
|
if (regexp.test(pathname)) {
|
|
3078
3042
|
const target = this.getApplicationTarget(application);
|
|
3079
3043
|
mfeDebug(
|
|
3080
|
-
`routing ${
|
|
3044
|
+
`routing ${path7} to '${target.application}' at ${target.hostname}`
|
|
3081
3045
|
);
|
|
3082
|
-
return { path:
|
|
3046
|
+
return { path: path7, ...target };
|
|
3083
3047
|
}
|
|
3084
3048
|
}
|
|
3085
3049
|
}
|
|
@@ -3088,11 +3052,11 @@ var LocalProxy = class {
|
|
|
3088
3052
|
}
|
|
3089
3053
|
// Handles requests that return data from the local proxy itself.
|
|
3090
3054
|
// Returns true if the request was handled, false otherwise.
|
|
3091
|
-
handleProxyInfoRequest(
|
|
3092
|
-
if (!
|
|
3055
|
+
handleProxyInfoRequest(path7, res) {
|
|
3056
|
+
if (!path7) {
|
|
3093
3057
|
return false;
|
|
3094
3058
|
}
|
|
3095
|
-
const url = new URL(`http://example.comf${
|
|
3059
|
+
const url = new URL(`http://example.comf${path7}`);
|
|
3096
3060
|
const pathname = url.pathname;
|
|
3097
3061
|
switch (pathname) {
|
|
3098
3062
|
case "/.well-known/vercel/microfrontend-routing": {
|
|
@@ -3120,10 +3084,10 @@ var LocalProxy = class {
|
|
|
3120
3084
|
}
|
|
3121
3085
|
const target = this.getTarget(req);
|
|
3122
3086
|
if (target.protocol === "https") {
|
|
3123
|
-
const { hostname, port, path:
|
|
3087
|
+
const { hostname, port, path: path7 } = target;
|
|
3124
3088
|
const requestOptions = {
|
|
3125
3089
|
hostname,
|
|
3126
|
-
path:
|
|
3090
|
+
path: path7,
|
|
3127
3091
|
method: req.method,
|
|
3128
3092
|
headers: {
|
|
3129
3093
|
...req.headers,
|
|
@@ -3151,7 +3115,7 @@ var LocalProxy = class {
|
|
|
3151
3115
|
console.error("Proxy request error: ", err);
|
|
3152
3116
|
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
3153
3117
|
res.end(
|
|
3154
|
-
`Error proxying request for ${target.application} to ${hostname}:${port}${
|
|
3118
|
+
`Error proxying request for ${target.application} to ${hostname}:${port}${path7}`
|
|
3155
3119
|
);
|
|
3156
3120
|
});
|
|
3157
3121
|
} else {
|
|
@@ -3178,6 +3142,79 @@ var LocalProxy = class {
|
|
|
3178
3142
|
}
|
|
3179
3143
|
};
|
|
3180
3144
|
|
|
3145
|
+
// src/bin/port.ts
|
|
3146
|
+
var import_node_process = require("process");
|
|
3147
|
+
|
|
3148
|
+
// src/utils/mfe-port.ts
|
|
3149
|
+
var import_node_path10 = __toESM(require("path"), 1);
|
|
3150
|
+
var import_node_fs9 = __toESM(require("fs"), 1);
|
|
3151
|
+
function mfePort(packageDir) {
|
|
3152
|
+
const { name: appName, version } = getPackageJson(packageDir);
|
|
3153
|
+
const result = loadV2({ packageDir, appName }) || loadV1({ packageDir, appName });
|
|
3154
|
+
if (!result) {
|
|
3155
|
+
throw new MicrofrontendError2(
|
|
3156
|
+
`Unable to determine configured port for ${appName}`,
|
|
3157
|
+
{ type: "config", subtype: "not_found" }
|
|
3158
|
+
);
|
|
3159
|
+
}
|
|
3160
|
+
const { port } = result;
|
|
3161
|
+
return {
|
|
3162
|
+
name: appName,
|
|
3163
|
+
version,
|
|
3164
|
+
port
|
|
3165
|
+
};
|
|
3166
|
+
}
|
|
3167
|
+
function getPackageJson(packageDir) {
|
|
3168
|
+
const filePath = import_node_path10.default.join(packageDir, "package.json");
|
|
3169
|
+
return JSON.parse(import_node_fs9.default.readFileSync(filePath, "utf-8"));
|
|
3170
|
+
}
|
|
3171
|
+
function loadV2({
|
|
3172
|
+
packageDir,
|
|
3173
|
+
appName
|
|
3174
|
+
}) {
|
|
3175
|
+
let config;
|
|
3176
|
+
try {
|
|
3177
|
+
config = MicrofrontendsServer.infer({
|
|
3178
|
+
directory: packageDir,
|
|
3179
|
+
meta: { fromApp: appName },
|
|
3180
|
+
options: { resolveMainConfig: true }
|
|
3181
|
+
});
|
|
3182
|
+
} catch (e) {
|
|
3183
|
+
return void 0;
|
|
3184
|
+
}
|
|
3185
|
+
const app = config.config.getApplication(appName);
|
|
3186
|
+
const port = app.development.local.port;
|
|
3187
|
+
return { port };
|
|
3188
|
+
}
|
|
3189
|
+
function loadV1({
|
|
3190
|
+
packageDir,
|
|
3191
|
+
appName
|
|
3192
|
+
}) {
|
|
3193
|
+
const filePath = import_node_path10.default.join(packageDir, "micro-frontends.jsonc");
|
|
3194
|
+
let config;
|
|
3195
|
+
try {
|
|
3196
|
+
config = MicrofrontendConfig.fromFile({ filePath });
|
|
3197
|
+
} catch (e) {
|
|
3198
|
+
return void 0;
|
|
3199
|
+
}
|
|
3200
|
+
const zone = config.getZone(appName);
|
|
3201
|
+
const port = zone.development.local.port;
|
|
3202
|
+
return { port };
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3205
|
+
// src/bin/port.ts
|
|
3206
|
+
function displayPort() {
|
|
3207
|
+
const portInfo = mfePort((0, import_node_process.cwd)());
|
|
3208
|
+
header(portInfo);
|
|
3209
|
+
console.log(portInfo.port);
|
|
3210
|
+
}
|
|
3211
|
+
function header({ name, version, port }) {
|
|
3212
|
+
console.error(`
|
|
3213
|
+
\u25B2 ${name}@${version}
|
|
3214
|
+
\xB7 setting port to ${port}
|
|
3215
|
+
`);
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3181
3218
|
// src/bin/index.ts
|
|
3182
3219
|
function main() {
|
|
3183
3220
|
const program = new import_commander.Command();
|
|
@@ -3195,6 +3232,9 @@ function main() {
|
|
|
3195
3232
|
});
|
|
3196
3233
|
localProxy.startServer();
|
|
3197
3234
|
});
|
|
3235
|
+
program.command("port").description("Prints development port").action(() => {
|
|
3236
|
+
displayPort();
|
|
3237
|
+
});
|
|
3198
3238
|
program.parse(process.argv);
|
|
3199
3239
|
}
|
|
3200
3240
|
main();
|