@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/v2/next/config.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/next-v2/config/index.ts
|
|
2
|
-
import
|
|
2
|
+
import fs5 from "node:fs";
|
|
3
3
|
|
|
4
4
|
// src/config-v2/microfrontends/server/index.ts
|
|
5
|
-
import
|
|
6
|
-
import { dirname as
|
|
5
|
+
import fs4 from "node:fs";
|
|
6
|
+
import { dirname as dirname3, join } from "node:path";
|
|
7
7
|
|
|
8
8
|
// src/config-v2/overrides/constants.ts
|
|
9
|
-
var OVERRIDES_COOKIE_PREFIX = "vercel-
|
|
9
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
10
10
|
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
11
11
|
|
|
12
12
|
// src/config-v2/overrides/is-override-cookie.ts
|
|
@@ -187,21 +187,21 @@ var MicrofrontendConfigClient = class {
|
|
|
187
187
|
isEqual(other) {
|
|
188
188
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
189
189
|
}
|
|
190
|
-
getApplicationNameForPath(
|
|
191
|
-
if (!
|
|
190
|
+
getApplicationNameForPath(path5) {
|
|
191
|
+
if (!path5.startsWith("/")) {
|
|
192
192
|
throw new Error(`Path must start with a /`);
|
|
193
193
|
}
|
|
194
|
-
if (this.pathCache[
|
|
195
|
-
return this.pathCache[
|
|
194
|
+
if (this.pathCache[path5]) {
|
|
195
|
+
return this.pathCache[path5];
|
|
196
196
|
}
|
|
197
|
-
const pathname = new URL(
|
|
197
|
+
const pathname = new URL(path5, "https://example.com").pathname;
|
|
198
198
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
199
199
|
if (application.routing) {
|
|
200
200
|
for (const group of application.routing) {
|
|
201
201
|
for (const childPath of group.paths) {
|
|
202
202
|
const regexp = pathToRegexp(childPath);
|
|
203
203
|
if (regexp.test(pathname)) {
|
|
204
|
-
this.pathCache[
|
|
204
|
+
this.pathCache[path5] = name;
|
|
205
205
|
return name;
|
|
206
206
|
}
|
|
207
207
|
}
|
|
@@ -214,7 +214,7 @@ var MicrofrontendConfigClient = class {
|
|
|
214
214
|
if (!defaultApplication) {
|
|
215
215
|
return null;
|
|
216
216
|
}
|
|
217
|
-
this.pathCache[
|
|
217
|
+
this.pathCache[path5] = defaultApplication[0];
|
|
218
218
|
return defaultApplication[0];
|
|
219
219
|
}
|
|
220
220
|
serialize() {
|
|
@@ -246,22 +246,22 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
246
246
|
continue;
|
|
247
247
|
}
|
|
248
248
|
for (const pathMatch of app.routing) {
|
|
249
|
-
for (const
|
|
250
|
-
const tokens = parsePathRegexp(
|
|
249
|
+
for (const path5 of pathMatch.paths) {
|
|
250
|
+
const tokens = parsePathRegexp(path5);
|
|
251
251
|
for (const token of tokens.slice(0, -1)) {
|
|
252
252
|
if (typeof token !== "string") {
|
|
253
253
|
errors.push(
|
|
254
|
-
`Path ${
|
|
254
|
+
`Path ${path5} may only have a :wildcard in the last path component`
|
|
255
255
|
);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
-
const existing = pathsByApplicationId.get(
|
|
258
|
+
const existing = pathsByApplicationId.get(path5);
|
|
259
259
|
if (existing) {
|
|
260
260
|
existing.applications.push(id);
|
|
261
261
|
} else {
|
|
262
|
-
pathsByApplicationId.set(
|
|
262
|
+
pathsByApplicationId.set(path5, {
|
|
263
263
|
applications: [id],
|
|
264
|
-
matcher: pathToRegexp2(
|
|
264
|
+
matcher: pathToRegexp2(path5),
|
|
265
265
|
applicationId: id
|
|
266
266
|
});
|
|
267
267
|
}
|
|
@@ -269,10 +269,10 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
272
|
-
entries.forEach(([
|
|
272
|
+
entries.forEach(([path5, { applications: ids, matcher, applicationId }]) => {
|
|
273
273
|
if (ids.length > 1) {
|
|
274
274
|
errors.push(
|
|
275
|
-
`Duplicate path "${
|
|
275
|
+
`Duplicate path "${path5}" for applications "${ids.join(", ")}"`
|
|
276
276
|
);
|
|
277
277
|
}
|
|
278
278
|
entries.forEach(
|
|
@@ -280,14 +280,14 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
280
280
|
matchPath,
|
|
281
281
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
282
282
|
]) => {
|
|
283
|
-
if (
|
|
283
|
+
if (path5 === matchPath) {
|
|
284
284
|
return;
|
|
285
285
|
}
|
|
286
286
|
if (applicationId === matchApplicationId) {
|
|
287
287
|
return;
|
|
288
288
|
}
|
|
289
289
|
if (matcher.test(matchPath)) {
|
|
290
|
-
const source = `"${
|
|
290
|
+
const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
291
291
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
292
292
|
errors.push(
|
|
293
293
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -852,8 +852,115 @@ function findPackagePath(opts) {
|
|
|
852
852
|
return result;
|
|
853
853
|
}
|
|
854
854
|
|
|
855
|
-
// src/config-v2/microfrontends/
|
|
855
|
+
// src/config-v2/microfrontends/utils/find-default-package.ts
|
|
856
|
+
import { dirname as dirname2 } from "node:path";
|
|
857
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
858
|
+
import fg2 from "fast-glob";
|
|
859
|
+
var configCache2 = {};
|
|
860
|
+
function findDefaultMicrofrontendsPackages({
|
|
861
|
+
repositoryRoot,
|
|
862
|
+
applicationName
|
|
863
|
+
}) {
|
|
864
|
+
try {
|
|
865
|
+
const microfrontendsJsonPaths = fg2.globSync("**/microfrontends.json", {
|
|
866
|
+
cwd: repositoryRoot,
|
|
867
|
+
absolute: true,
|
|
868
|
+
onlyFiles: true,
|
|
869
|
+
followSymbolicLinks: false,
|
|
870
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
871
|
+
});
|
|
872
|
+
const matchingPaths = [];
|
|
873
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
874
|
+
const microfrontendsJsonContent = readFileSync2(
|
|
875
|
+
microfrontendsJsonPath,
|
|
876
|
+
"utf-8"
|
|
877
|
+
);
|
|
878
|
+
const microfrontendsJson = JSON.parse(
|
|
879
|
+
microfrontendsJsonContent
|
|
880
|
+
);
|
|
881
|
+
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
882
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (matchingPaths.length > 1) {
|
|
886
|
+
throw new Error(
|
|
887
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
|
|
888
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
if (matchingPaths.length === 0) {
|
|
892
|
+
throw new Error(
|
|
893
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
const [packageJsonPath] = matchingPaths;
|
|
897
|
+
return dirname2(packageJsonPath);
|
|
898
|
+
} catch (error) {
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
903
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
904
|
+
if (configCache2[cacheKey]) {
|
|
905
|
+
return configCache2[cacheKey];
|
|
906
|
+
}
|
|
907
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
908
|
+
if (!result) {
|
|
909
|
+
throw new Error(
|
|
910
|
+
`Error trying to resolve the main microfrontends.json configuration`
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
configCache2[cacheKey] = result;
|
|
914
|
+
return result;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// src/config-v2/microfrontends/utils/is-monorepo.ts
|
|
918
|
+
import fs2 from "node:fs";
|
|
856
919
|
import path2 from "node:path";
|
|
920
|
+
function isMonorepo({
|
|
921
|
+
repositoryRoot
|
|
922
|
+
}) {
|
|
923
|
+
try {
|
|
924
|
+
if (fs2.existsSync(path2.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
925
|
+
return true;
|
|
926
|
+
}
|
|
927
|
+
if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
930
|
+
const packageJsonPath = path2.join(repositoryRoot, "package.json");
|
|
931
|
+
if (!fs2.existsSync(packageJsonPath)) {
|
|
932
|
+
return false;
|
|
933
|
+
}
|
|
934
|
+
const packageJson = JSON.parse(
|
|
935
|
+
fs2.readFileSync(packageJsonPath, "utf-8")
|
|
936
|
+
);
|
|
937
|
+
return packageJson.workspaces !== void 0;
|
|
938
|
+
} catch (error) {
|
|
939
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
940
|
+
return false;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// src/config-v2/microfrontends/utils/find-package-root.ts
|
|
945
|
+
import fs3 from "node:fs";
|
|
946
|
+
import path3 from "node:path";
|
|
947
|
+
var PACKAGE_JSON = "package.json";
|
|
948
|
+
function findPackageRoot(startDir) {
|
|
949
|
+
let currentDir = startDir || process.cwd();
|
|
950
|
+
while (currentDir !== path3.parse(currentDir).root) {
|
|
951
|
+
const pkgJsonPath = path3.join(currentDir, PACKAGE_JSON);
|
|
952
|
+
if (fs3.existsSync(pkgJsonPath)) {
|
|
953
|
+
return currentDir;
|
|
954
|
+
}
|
|
955
|
+
currentDir = path3.dirname(currentDir);
|
|
956
|
+
}
|
|
957
|
+
throw new Error(
|
|
958
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
959
|
+
);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
963
|
+
import path4 from "node:path";
|
|
857
964
|
|
|
858
965
|
// src/config-v2/microfrontends/server/constants.ts
|
|
859
966
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -867,13 +974,13 @@ function isVercel() {
|
|
|
867
974
|
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
868
975
|
function getOutputFilePath() {
|
|
869
976
|
if (isVercel()) {
|
|
870
|
-
return
|
|
977
|
+
return path4.join(
|
|
871
978
|
".vercel",
|
|
872
979
|
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
873
980
|
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
874
981
|
);
|
|
875
982
|
}
|
|
876
|
-
return
|
|
983
|
+
return path4.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
877
984
|
}
|
|
878
985
|
|
|
879
986
|
// src/config-v2/microfrontends/server/validation.ts
|
|
@@ -1087,9 +1194,6 @@ var schema_v2_default = {
|
|
|
1087
1194
|
projectId: {
|
|
1088
1195
|
type: "string",
|
|
1089
1196
|
description: "Vercel project ID"
|
|
1090
|
-
},
|
|
1091
|
-
routeSpeedInsightsToDefaultZone: {
|
|
1092
|
-
type: "boolean"
|
|
1093
1197
|
}
|
|
1094
1198
|
},
|
|
1095
1199
|
required: ["projectId"]
|
|
@@ -1259,8 +1363,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1259
1363
|
pretty: true
|
|
1260
1364
|
}) {
|
|
1261
1365
|
const outputPath = getOutputFilePath();
|
|
1262
|
-
|
|
1263
|
-
|
|
1366
|
+
fs4.mkdirSync(dirname3(outputPath), { recursive: true });
|
|
1367
|
+
fs4.writeFileSync(
|
|
1264
1368
|
outputPath,
|
|
1265
1369
|
JSON.stringify(
|
|
1266
1370
|
this.config.toSchemaJson(),
|
|
@@ -1322,6 +1426,69 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1322
1426
|
}
|
|
1323
1427
|
return config;
|
|
1324
1428
|
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Looks up the configuration by inferring the package root and looking for a microfrontends.json file. If a file is not found,
|
|
1431
|
+
* it will look for a package in the repository with a microfrontends.json file that contains the current application
|
|
1432
|
+
* and use that configuration.
|
|
1433
|
+
*
|
|
1434
|
+
* This can return either a Child or Main configuration.
|
|
1435
|
+
*/
|
|
1436
|
+
static infer({
|
|
1437
|
+
directory,
|
|
1438
|
+
filePath,
|
|
1439
|
+
meta,
|
|
1440
|
+
cookies,
|
|
1441
|
+
options
|
|
1442
|
+
} = {}) {
|
|
1443
|
+
if (filePath && meta) {
|
|
1444
|
+
return MicrofrontendsServer.fromFile({
|
|
1445
|
+
filePath,
|
|
1446
|
+
cookies,
|
|
1447
|
+
meta,
|
|
1448
|
+
options
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
try {
|
|
1452
|
+
const packageRoot = findPackageRoot(directory);
|
|
1453
|
+
const packageJsonPath = join(packageRoot, "package.json");
|
|
1454
|
+
const packageJson = JSON.parse(
|
|
1455
|
+
fs4.readFileSync(packageJsonPath, "utf-8")
|
|
1456
|
+
);
|
|
1457
|
+
if (!packageJson.name) {
|
|
1458
|
+
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1459
|
+
}
|
|
1460
|
+
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1461
|
+
const maybeConfig = join(packageRoot, "microfrontends.json");
|
|
1462
|
+
if (fs4.existsSync(maybeConfig)) {
|
|
1463
|
+
return MicrofrontendsServer.fromFile({
|
|
1464
|
+
filePath: maybeConfig,
|
|
1465
|
+
cookies,
|
|
1466
|
+
meta: configMeta,
|
|
1467
|
+
options
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
const repositoryRoot = findRepositoryRoot();
|
|
1471
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1472
|
+
if (isMonorepo2) {
|
|
1473
|
+
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1474
|
+
repositoryRoot,
|
|
1475
|
+
applicationName: packageJson.name
|
|
1476
|
+
});
|
|
1477
|
+
return MicrofrontendsServer.fromFile({
|
|
1478
|
+
filePath: join(defaultPackage, "microfrontends.json"),
|
|
1479
|
+
cookies,
|
|
1480
|
+
meta: configMeta,
|
|
1481
|
+
options
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
throw new Error("Unable to infer");
|
|
1485
|
+
} catch (e) {
|
|
1486
|
+
throw new MicrofrontendError(
|
|
1487
|
+
"Unable to infer microfrontends configuration",
|
|
1488
|
+
{ type: "config", subtype: "inference_failed" }
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1325
1492
|
/*
|
|
1326
1493
|
* Generates a MicrofrontendsServer instance from a file.
|
|
1327
1494
|
*/
|
|
@@ -1332,25 +1499,28 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1332
1499
|
options
|
|
1333
1500
|
}) {
|
|
1334
1501
|
try {
|
|
1335
|
-
const configJson =
|
|
1502
|
+
const configJson = fs4.readFileSync(filePath, "utf-8");
|
|
1336
1503
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1337
1504
|
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
1338
1505
|
const repositoryRoot = findRepositoryRoot();
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1506
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1507
|
+
if (isMonorepo2) {
|
|
1508
|
+
const packagePath = findPackagePath({
|
|
1509
|
+
repositoryRoot,
|
|
1510
|
+
name: config.partOf
|
|
1511
|
+
});
|
|
1512
|
+
if (!packagePath) {
|
|
1513
|
+
throw new MicrofrontendError(
|
|
1514
|
+
`Could not find default application "${config.partOf}" in the repository`,
|
|
1515
|
+
{ type: "config", subtype: "not_found" }
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1518
|
+
const mainConfigPath = join(packagePath, "microfrontends.json");
|
|
1519
|
+
return MicrofrontendsServer.fromMainConfigFile({
|
|
1520
|
+
filePath: mainConfigPath,
|
|
1521
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1522
|
+
});
|
|
1348
1523
|
}
|
|
1349
|
-
const mainConfigPath = join(packagePath, "microfrontends.json");
|
|
1350
|
-
return MicrofrontendsServer.fromMainConfigFile({
|
|
1351
|
-
filePath: mainConfigPath,
|
|
1352
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1353
|
-
});
|
|
1354
1524
|
}
|
|
1355
1525
|
return new MicrofrontendsServer({
|
|
1356
1526
|
config,
|
|
@@ -1371,7 +1541,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1371
1541
|
overrides
|
|
1372
1542
|
}) {
|
|
1373
1543
|
try {
|
|
1374
|
-
const config =
|
|
1544
|
+
const config = fs4.readFileSync(filePath, "utf-8");
|
|
1375
1545
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1376
1546
|
if (!isMainConfig(validatedConfig)) {
|
|
1377
1547
|
throw new MicrofrontendError(
|
|
@@ -1509,24 +1679,26 @@ function getDomainFromEnvironment({
|
|
|
1509
1679
|
app,
|
|
1510
1680
|
target
|
|
1511
1681
|
}) {
|
|
1512
|
-
|
|
1513
|
-
|
|
1682
|
+
var _a, _b;
|
|
1683
|
+
const mfeProjects = JSON.parse(
|
|
1684
|
+
process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "{}"
|
|
1514
1685
|
);
|
|
1515
|
-
if (
|
|
1516
|
-
throw new Error("Missing related
|
|
1686
|
+
if (Object.keys(mfeProjects).length === 0) {
|
|
1687
|
+
throw new Error("Missing related microfrontends project information");
|
|
1517
1688
|
}
|
|
1518
|
-
|
|
1519
|
-
(
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
}
|
|
1523
|
-
);
|
|
1689
|
+
if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
|
|
1690
|
+
throw new Error(`Missing applications[${app.name}].vercel.projectId`);
|
|
1691
|
+
}
|
|
1692
|
+
const vercelProject = (_b = mfeProjects.applications) == null ? void 0 : _b[app.vercel.projectId];
|
|
1524
1693
|
if (!vercelProject) {
|
|
1525
1694
|
throw new Error(
|
|
1526
|
-
`Missing related
|
|
1695
|
+
`Missing related microfrontends project information for application "${app.name}"`
|
|
1527
1696
|
);
|
|
1528
1697
|
}
|
|
1529
|
-
|
|
1698
|
+
if (target === "preview" && vercelProject.deploymentAlias) {
|
|
1699
|
+
return vercelProject.deploymentAlias;
|
|
1700
|
+
}
|
|
1701
|
+
return vercelProject.productionHost;
|
|
1530
1702
|
}
|
|
1531
1703
|
|
|
1532
1704
|
// src/routing-v2/get-domain-for-current-environment.ts
|
|
@@ -1565,12 +1737,12 @@ function getDomainForCurrentEnvironment(config, appName) {
|
|
|
1565
1737
|
const productionHost = config.getDefaultApplication().production.toString();
|
|
1566
1738
|
switch (group) {
|
|
1567
1739
|
case "development": {
|
|
1568
|
-
const domain = process.env.NODE_ENV
|
|
1740
|
+
const domain = ["test", "development"].includes(process.env.NODE_ENV) ? app.development.local.toString() : productionHost;
|
|
1569
1741
|
debugDomains(appName, "development", domain);
|
|
1570
1742
|
return domain;
|
|
1571
1743
|
}
|
|
1572
1744
|
case "preview": {
|
|
1573
|
-
return getDomainFromEnvironment({ app, target: "
|
|
1745
|
+
return getDomainFromEnvironment({ app, target: "preview" });
|
|
1574
1746
|
}
|
|
1575
1747
|
case "production": {
|
|
1576
1748
|
return getDomainFromEnvironment({ app, target: "production" });
|
|
@@ -1602,11 +1774,11 @@ ${table}
|
|
|
1602
1774
|
`);
|
|
1603
1775
|
}
|
|
1604
1776
|
}
|
|
1605
|
-
function pathToRewrites(
|
|
1777
|
+
function pathToRewrites(path5) {
|
|
1606
1778
|
var _a;
|
|
1607
1779
|
const regex = /(?<base>^.+)\/:.+\*$/;
|
|
1608
|
-
const match = regex.exec(
|
|
1609
|
-
const paths = [
|
|
1780
|
+
const match = regex.exec(path5);
|
|
1781
|
+
const paths = [path5];
|
|
1610
1782
|
if ((_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.base) {
|
|
1611
1783
|
paths.unshift(match.groups.base);
|
|
1612
1784
|
}
|
|
@@ -1620,7 +1792,16 @@ function rewritesMapToArr(rewrites) {
|
|
|
1620
1792
|
return [
|
|
1621
1793
|
{
|
|
1622
1794
|
source,
|
|
1623
|
-
destination
|
|
1795
|
+
destination,
|
|
1796
|
+
missing: [
|
|
1797
|
+
// if this header is present, the proxy has performed the rewrite.
|
|
1798
|
+
// once the proxy routing is fully rolled out, this package should
|
|
1799
|
+
// be updated to not perform any rewrites when deployed.
|
|
1800
|
+
{
|
|
1801
|
+
type: "header",
|
|
1802
|
+
key: "x-vercel-mfe-host"
|
|
1803
|
+
}
|
|
1804
|
+
]
|
|
1624
1805
|
}
|
|
1625
1806
|
];
|
|
1626
1807
|
});
|
|
@@ -1628,15 +1809,9 @@ function rewritesMapToArr(rewrites) {
|
|
|
1628
1809
|
function transform4(args) {
|
|
1629
1810
|
const { next, microfrontend, app } = args;
|
|
1630
1811
|
const buildBeforeFiles = () => {
|
|
1631
|
-
var _a;
|
|
1632
1812
|
const rewrites = /* @__PURE__ */ new Map();
|
|
1633
1813
|
if (!app.isDefault()) {
|
|
1634
|
-
|
|
1635
|
-
destination: {
|
|
1636
|
-
pathname: `/_next/:path+`
|
|
1637
|
-
}
|
|
1638
|
-
});
|
|
1639
|
-
if (!((_a = app.vercel) == null ? void 0 : _a.routeSpeedInsightsToDefaultZone)) {
|
|
1814
|
+
if (process.env.VERCEL_MICROFRONTENDS_CONSOLIDATE_SPEED_INSIGHTS === "1") {
|
|
1640
1815
|
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1641
1816
|
destination: { pathname: "/_vercel/:path*" }
|
|
1642
1817
|
});
|
|
@@ -1854,7 +2029,7 @@ function getApplicationContext(opts) {
|
|
|
1854
2029
|
return { name: opts.appName };
|
|
1855
2030
|
}
|
|
1856
2031
|
try {
|
|
1857
|
-
const packageJsonString =
|
|
2032
|
+
const packageJsonString = fs5.readFileSync("./package.json", "utf-8");
|
|
1858
2033
|
const packageJson = JSON.parse(packageJsonString);
|
|
1859
2034
|
if (!packageJson.name) {
|
|
1860
2035
|
throw new MicrofrontendError(
|
|
@@ -1879,8 +2054,8 @@ function withMicrofrontends(nextConfig, opts) {
|
|
|
1879
2054
|
process.env.MFE_DEBUG = "true";
|
|
1880
2055
|
}
|
|
1881
2056
|
const { name: fromApp } = getApplicationContext(opts);
|
|
1882
|
-
const microfrontends = MicrofrontendsServer.
|
|
1883
|
-
filePath:
|
|
2057
|
+
const microfrontends = MicrofrontendsServer.infer({
|
|
2058
|
+
filePath: opts == null ? void 0 : opts.configPath,
|
|
1884
2059
|
meta: {
|
|
1885
2060
|
fromApp
|
|
1886
2061
|
}
|