@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.cjs
CHANGED
|
@@ -33,14 +33,14 @@ __export(config_exports, {
|
|
|
33
33
|
withMicrofrontends: () => withMicrofrontends
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(config_exports);
|
|
36
|
-
var
|
|
36
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
37
37
|
|
|
38
38
|
// src/config-v2/microfrontends/server/index.ts
|
|
39
|
-
var
|
|
40
|
-
var
|
|
39
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
40
|
+
var import_node_path7 = require("path");
|
|
41
41
|
|
|
42
42
|
// src/config-v2/overrides/constants.ts
|
|
43
|
-
var OVERRIDES_COOKIE_PREFIX = "vercel-
|
|
43
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
44
44
|
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
45
45
|
|
|
46
46
|
// src/config-v2/overrides/is-override-cookie.ts
|
|
@@ -221,21 +221,21 @@ var MicrofrontendConfigClient = class {
|
|
|
221
221
|
isEqual(other) {
|
|
222
222
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
223
223
|
}
|
|
224
|
-
getApplicationNameForPath(
|
|
225
|
-
if (!
|
|
224
|
+
getApplicationNameForPath(path5) {
|
|
225
|
+
if (!path5.startsWith("/")) {
|
|
226
226
|
throw new Error(`Path must start with a /`);
|
|
227
227
|
}
|
|
228
|
-
if (this.pathCache[
|
|
229
|
-
return this.pathCache[
|
|
228
|
+
if (this.pathCache[path5]) {
|
|
229
|
+
return this.pathCache[path5];
|
|
230
230
|
}
|
|
231
|
-
const pathname = new URL(
|
|
231
|
+
const pathname = new URL(path5, "https://example.com").pathname;
|
|
232
232
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
233
233
|
if (application.routing) {
|
|
234
234
|
for (const group of application.routing) {
|
|
235
235
|
for (const childPath of group.paths) {
|
|
236
236
|
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
237
237
|
if (regexp.test(pathname)) {
|
|
238
|
-
this.pathCache[
|
|
238
|
+
this.pathCache[path5] = name;
|
|
239
239
|
return name;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
@@ -248,7 +248,7 @@ var MicrofrontendConfigClient = class {
|
|
|
248
248
|
if (!defaultApplication) {
|
|
249
249
|
return null;
|
|
250
250
|
}
|
|
251
|
-
this.pathCache[
|
|
251
|
+
this.pathCache[path5] = defaultApplication[0];
|
|
252
252
|
return defaultApplication[0];
|
|
253
253
|
}
|
|
254
254
|
serialize() {
|
|
@@ -280,22 +280,22 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
280
280
|
continue;
|
|
281
281
|
}
|
|
282
282
|
for (const pathMatch of app.routing) {
|
|
283
|
-
for (const
|
|
284
|
-
const tokens = (0, import_path_to_regexp2.parse)(
|
|
283
|
+
for (const path5 of pathMatch.paths) {
|
|
284
|
+
const tokens = (0, import_path_to_regexp2.parse)(path5);
|
|
285
285
|
for (const token of tokens.slice(0, -1)) {
|
|
286
286
|
if (typeof token !== "string") {
|
|
287
287
|
errors.push(
|
|
288
|
-
`Path ${
|
|
288
|
+
`Path ${path5} may only have a :wildcard in the last path component`
|
|
289
289
|
);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
|
-
const existing = pathsByApplicationId.get(
|
|
292
|
+
const existing = pathsByApplicationId.get(path5);
|
|
293
293
|
if (existing) {
|
|
294
294
|
existing.applications.push(id);
|
|
295
295
|
} else {
|
|
296
|
-
pathsByApplicationId.set(
|
|
296
|
+
pathsByApplicationId.set(path5, {
|
|
297
297
|
applications: [id],
|
|
298
|
-
matcher: (0, import_path_to_regexp2.pathToRegexp)(
|
|
298
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
|
|
299
299
|
applicationId: id
|
|
300
300
|
});
|
|
301
301
|
}
|
|
@@ -303,10 +303,10 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
306
|
-
entries.forEach(([
|
|
306
|
+
entries.forEach(([path5, { applications: ids, matcher, applicationId }]) => {
|
|
307
307
|
if (ids.length > 1) {
|
|
308
308
|
errors.push(
|
|
309
|
-
`Duplicate path "${
|
|
309
|
+
`Duplicate path "${path5}" for applications "${ids.join(", ")}"`
|
|
310
310
|
);
|
|
311
311
|
}
|
|
312
312
|
entries.forEach(
|
|
@@ -314,14 +314,14 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
314
314
|
matchPath,
|
|
315
315
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
316
316
|
]) => {
|
|
317
|
-
if (
|
|
317
|
+
if (path5 === matchPath) {
|
|
318
318
|
return;
|
|
319
319
|
}
|
|
320
320
|
if (applicationId === matchApplicationId) {
|
|
321
321
|
return;
|
|
322
322
|
}
|
|
323
323
|
if (matcher.test(matchPath)) {
|
|
324
|
-
const source = `"${
|
|
324
|
+
const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
325
325
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
326
326
|
errors.push(
|
|
327
327
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -886,8 +886,115 @@ function findPackagePath(opts) {
|
|
|
886
886
|
return result;
|
|
887
887
|
}
|
|
888
888
|
|
|
889
|
+
// src/config-v2/microfrontends/utils/find-default-package.ts
|
|
890
|
+
var import_node_path3 = require("path");
|
|
891
|
+
var import_node_fs3 = require("fs");
|
|
892
|
+
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
893
|
+
var configCache2 = {};
|
|
894
|
+
function findDefaultMicrofrontendsPackages({
|
|
895
|
+
repositoryRoot,
|
|
896
|
+
applicationName
|
|
897
|
+
}) {
|
|
898
|
+
try {
|
|
899
|
+
const microfrontendsJsonPaths = import_fast_glob2.default.globSync("**/microfrontends.json", {
|
|
900
|
+
cwd: repositoryRoot,
|
|
901
|
+
absolute: true,
|
|
902
|
+
onlyFiles: true,
|
|
903
|
+
followSymbolicLinks: false,
|
|
904
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
905
|
+
});
|
|
906
|
+
const matchingPaths = [];
|
|
907
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
908
|
+
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
909
|
+
microfrontendsJsonPath,
|
|
910
|
+
"utf-8"
|
|
911
|
+
);
|
|
912
|
+
const microfrontendsJson = JSON.parse(
|
|
913
|
+
microfrontendsJsonContent
|
|
914
|
+
);
|
|
915
|
+
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
916
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
if (matchingPaths.length > 1) {
|
|
920
|
+
throw new Error(
|
|
921
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
|
|
922
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
if (matchingPaths.length === 0) {
|
|
926
|
+
throw new Error(
|
|
927
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
const [packageJsonPath] = matchingPaths;
|
|
931
|
+
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
932
|
+
} catch (error) {
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
937
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
938
|
+
if (configCache2[cacheKey]) {
|
|
939
|
+
return configCache2[cacheKey];
|
|
940
|
+
}
|
|
941
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
942
|
+
if (!result) {
|
|
943
|
+
throw new Error(
|
|
944
|
+
`Error trying to resolve the main microfrontends.json configuration`
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
configCache2[cacheKey] = result;
|
|
948
|
+
return result;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// src/config-v2/microfrontends/utils/is-monorepo.ts
|
|
952
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
953
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
954
|
+
function isMonorepo({
|
|
955
|
+
repositoryRoot
|
|
956
|
+
}) {
|
|
957
|
+
try {
|
|
958
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
959
|
+
return true;
|
|
960
|
+
}
|
|
961
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
962
|
+
return true;
|
|
963
|
+
}
|
|
964
|
+
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
965
|
+
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
966
|
+
return false;
|
|
967
|
+
}
|
|
968
|
+
const packageJson = JSON.parse(
|
|
969
|
+
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
970
|
+
);
|
|
971
|
+
return packageJson.workspaces !== void 0;
|
|
972
|
+
} catch (error) {
|
|
973
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// src/config-v2/microfrontends/utils/find-package-root.ts
|
|
979
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
980
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
981
|
+
var PACKAGE_JSON = "package.json";
|
|
982
|
+
function findPackageRoot(startDir) {
|
|
983
|
+
let currentDir = startDir || process.cwd();
|
|
984
|
+
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
985
|
+
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
986
|
+
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
987
|
+
return currentDir;
|
|
988
|
+
}
|
|
989
|
+
currentDir = import_node_path5.default.dirname(currentDir);
|
|
990
|
+
}
|
|
991
|
+
throw new Error(
|
|
992
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
|
|
889
996
|
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
890
|
-
var
|
|
997
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
891
998
|
|
|
892
999
|
// src/config-v2/microfrontends/server/constants.ts
|
|
893
1000
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -901,13 +1008,13 @@ function isVercel() {
|
|
|
901
1008
|
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
902
1009
|
function getOutputFilePath() {
|
|
903
1010
|
if (isVercel()) {
|
|
904
|
-
return
|
|
1011
|
+
return import_node_path6.default.join(
|
|
905
1012
|
".vercel",
|
|
906
1013
|
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
907
1014
|
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
908
1015
|
);
|
|
909
1016
|
}
|
|
910
|
-
return
|
|
1017
|
+
return import_node_path6.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
911
1018
|
}
|
|
912
1019
|
|
|
913
1020
|
// src/config-v2/microfrontends/server/validation.ts
|
|
@@ -1121,9 +1228,6 @@ var schema_v2_default = {
|
|
|
1121
1228
|
projectId: {
|
|
1122
1229
|
type: "string",
|
|
1123
1230
|
description: "Vercel project ID"
|
|
1124
|
-
},
|
|
1125
|
-
routeSpeedInsightsToDefaultZone: {
|
|
1126
|
-
type: "boolean"
|
|
1127
1231
|
}
|
|
1128
1232
|
},
|
|
1129
1233
|
required: ["projectId"]
|
|
@@ -1293,8 +1397,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1293
1397
|
pretty: true
|
|
1294
1398
|
}) {
|
|
1295
1399
|
const outputPath = getOutputFilePath();
|
|
1296
|
-
|
|
1297
|
-
|
|
1400
|
+
import_node_fs6.default.mkdirSync((0, import_node_path7.dirname)(outputPath), { recursive: true });
|
|
1401
|
+
import_node_fs6.default.writeFileSync(
|
|
1298
1402
|
outputPath,
|
|
1299
1403
|
JSON.stringify(
|
|
1300
1404
|
this.config.toSchemaJson(),
|
|
@@ -1356,6 +1460,69 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1356
1460
|
}
|
|
1357
1461
|
return config;
|
|
1358
1462
|
}
|
|
1463
|
+
/**
|
|
1464
|
+
* Looks up the configuration by inferring the package root and looking for a microfrontends.json file. If a file is not found,
|
|
1465
|
+
* it will look for a package in the repository with a microfrontends.json file that contains the current application
|
|
1466
|
+
* and use that configuration.
|
|
1467
|
+
*
|
|
1468
|
+
* This can return either a Child or Main configuration.
|
|
1469
|
+
*/
|
|
1470
|
+
static infer({
|
|
1471
|
+
directory,
|
|
1472
|
+
filePath,
|
|
1473
|
+
meta,
|
|
1474
|
+
cookies,
|
|
1475
|
+
options
|
|
1476
|
+
} = {}) {
|
|
1477
|
+
if (filePath && meta) {
|
|
1478
|
+
return MicrofrontendsServer.fromFile({
|
|
1479
|
+
filePath,
|
|
1480
|
+
cookies,
|
|
1481
|
+
meta,
|
|
1482
|
+
options
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
try {
|
|
1486
|
+
const packageRoot = findPackageRoot(directory);
|
|
1487
|
+
const packageJsonPath = (0, import_node_path7.join)(packageRoot, "package.json");
|
|
1488
|
+
const packageJson = JSON.parse(
|
|
1489
|
+
import_node_fs6.default.readFileSync(packageJsonPath, "utf-8")
|
|
1490
|
+
);
|
|
1491
|
+
if (!packageJson.name) {
|
|
1492
|
+
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1493
|
+
}
|
|
1494
|
+
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1495
|
+
const maybeConfig = (0, import_node_path7.join)(packageRoot, "microfrontends.json");
|
|
1496
|
+
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
1497
|
+
return MicrofrontendsServer.fromFile({
|
|
1498
|
+
filePath: maybeConfig,
|
|
1499
|
+
cookies,
|
|
1500
|
+
meta: configMeta,
|
|
1501
|
+
options
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
const repositoryRoot = findRepositoryRoot();
|
|
1505
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1506
|
+
if (isMonorepo2) {
|
|
1507
|
+
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1508
|
+
repositoryRoot,
|
|
1509
|
+
applicationName: packageJson.name
|
|
1510
|
+
});
|
|
1511
|
+
return MicrofrontendsServer.fromFile({
|
|
1512
|
+
filePath: (0, import_node_path7.join)(defaultPackage, "microfrontends.json"),
|
|
1513
|
+
cookies,
|
|
1514
|
+
meta: configMeta,
|
|
1515
|
+
options
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
throw new Error("Unable to infer");
|
|
1519
|
+
} catch (e) {
|
|
1520
|
+
throw new MicrofrontendError(
|
|
1521
|
+
"Unable to infer microfrontends configuration",
|
|
1522
|
+
{ type: "config", subtype: "inference_failed" }
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1359
1526
|
/*
|
|
1360
1527
|
* Generates a MicrofrontendsServer instance from a file.
|
|
1361
1528
|
*/
|
|
@@ -1366,25 +1533,28 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1366
1533
|
options
|
|
1367
1534
|
}) {
|
|
1368
1535
|
try {
|
|
1369
|
-
const configJson =
|
|
1536
|
+
const configJson = import_node_fs6.default.readFileSync(filePath, "utf-8");
|
|
1370
1537
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1371
1538
|
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
1372
1539
|
const repositoryRoot = findRepositoryRoot();
|
|
1373
|
-
const
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1540
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1541
|
+
if (isMonorepo2) {
|
|
1542
|
+
const packagePath = findPackagePath({
|
|
1543
|
+
repositoryRoot,
|
|
1544
|
+
name: config.partOf
|
|
1545
|
+
});
|
|
1546
|
+
if (!packagePath) {
|
|
1547
|
+
throw new MicrofrontendError(
|
|
1548
|
+
`Could not find default application "${config.partOf}" in the repository`,
|
|
1549
|
+
{ type: "config", subtype: "not_found" }
|
|
1550
|
+
);
|
|
1551
|
+
}
|
|
1552
|
+
const mainConfigPath = (0, import_node_path7.join)(packagePath, "microfrontends.json");
|
|
1553
|
+
return MicrofrontendsServer.fromMainConfigFile({
|
|
1554
|
+
filePath: mainConfigPath,
|
|
1555
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1556
|
+
});
|
|
1382
1557
|
}
|
|
1383
|
-
const mainConfigPath = (0, import_node_path4.join)(packagePath, "microfrontends.json");
|
|
1384
|
-
return MicrofrontendsServer.fromMainConfigFile({
|
|
1385
|
-
filePath: mainConfigPath,
|
|
1386
|
-
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1387
|
-
});
|
|
1388
1558
|
}
|
|
1389
1559
|
return new MicrofrontendsServer({
|
|
1390
1560
|
config,
|
|
@@ -1405,7 +1575,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1405
1575
|
overrides
|
|
1406
1576
|
}) {
|
|
1407
1577
|
try {
|
|
1408
|
-
const config =
|
|
1578
|
+
const config = import_node_fs6.default.readFileSync(filePath, "utf-8");
|
|
1409
1579
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1410
1580
|
if (!isMainConfig(validatedConfig)) {
|
|
1411
1581
|
throw new MicrofrontendError(
|
|
@@ -1543,24 +1713,26 @@ function getDomainFromEnvironment({
|
|
|
1543
1713
|
app,
|
|
1544
1714
|
target
|
|
1545
1715
|
}) {
|
|
1546
|
-
|
|
1547
|
-
|
|
1716
|
+
var _a, _b;
|
|
1717
|
+
const mfeProjects = JSON.parse(
|
|
1718
|
+
process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "{}"
|
|
1548
1719
|
);
|
|
1549
|
-
if (
|
|
1550
|
-
throw new Error("Missing related
|
|
1720
|
+
if (Object.keys(mfeProjects).length === 0) {
|
|
1721
|
+
throw new Error("Missing related microfrontends project information");
|
|
1551
1722
|
}
|
|
1552
|
-
|
|
1553
|
-
(
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
}
|
|
1557
|
-
);
|
|
1723
|
+
if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
|
|
1724
|
+
throw new Error(`Missing applications[${app.name}].vercel.projectId`);
|
|
1725
|
+
}
|
|
1726
|
+
const vercelProject = (_b = mfeProjects.applications) == null ? void 0 : _b[app.vercel.projectId];
|
|
1558
1727
|
if (!vercelProject) {
|
|
1559
1728
|
throw new Error(
|
|
1560
|
-
`Missing related
|
|
1729
|
+
`Missing related microfrontends project information for application "${app.name}"`
|
|
1561
1730
|
);
|
|
1562
1731
|
}
|
|
1563
|
-
|
|
1732
|
+
if (target === "preview" && vercelProject.deploymentAlias) {
|
|
1733
|
+
return vercelProject.deploymentAlias;
|
|
1734
|
+
}
|
|
1735
|
+
return vercelProject.productionHost;
|
|
1564
1736
|
}
|
|
1565
1737
|
|
|
1566
1738
|
// src/routing-v2/get-domain-for-current-environment.ts
|
|
@@ -1599,12 +1771,12 @@ function getDomainForCurrentEnvironment(config, appName) {
|
|
|
1599
1771
|
const productionHost = config.getDefaultApplication().production.toString();
|
|
1600
1772
|
switch (group) {
|
|
1601
1773
|
case "development": {
|
|
1602
|
-
const domain = process.env.NODE_ENV
|
|
1774
|
+
const domain = ["test", "development"].includes(process.env.NODE_ENV) ? app.development.local.toString() : productionHost;
|
|
1603
1775
|
debugDomains(appName, "development", domain);
|
|
1604
1776
|
return domain;
|
|
1605
1777
|
}
|
|
1606
1778
|
case "preview": {
|
|
1607
|
-
return getDomainFromEnvironment({ app, target: "
|
|
1779
|
+
return getDomainFromEnvironment({ app, target: "preview" });
|
|
1608
1780
|
}
|
|
1609
1781
|
case "production": {
|
|
1610
1782
|
return getDomainFromEnvironment({ app, target: "production" });
|
|
@@ -1636,11 +1808,11 @@ ${table}
|
|
|
1636
1808
|
`);
|
|
1637
1809
|
}
|
|
1638
1810
|
}
|
|
1639
|
-
function pathToRewrites(
|
|
1811
|
+
function pathToRewrites(path5) {
|
|
1640
1812
|
var _a;
|
|
1641
1813
|
const regex = /(?<base>^.+)\/:.+\*$/;
|
|
1642
|
-
const match = regex.exec(
|
|
1643
|
-
const paths = [
|
|
1814
|
+
const match = regex.exec(path5);
|
|
1815
|
+
const paths = [path5];
|
|
1644
1816
|
if ((_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.base) {
|
|
1645
1817
|
paths.unshift(match.groups.base);
|
|
1646
1818
|
}
|
|
@@ -1654,7 +1826,16 @@ function rewritesMapToArr(rewrites) {
|
|
|
1654
1826
|
return [
|
|
1655
1827
|
{
|
|
1656
1828
|
source,
|
|
1657
|
-
destination
|
|
1829
|
+
destination,
|
|
1830
|
+
missing: [
|
|
1831
|
+
// if this header is present, the proxy has performed the rewrite.
|
|
1832
|
+
// once the proxy routing is fully rolled out, this package should
|
|
1833
|
+
// be updated to not perform any rewrites when deployed.
|
|
1834
|
+
{
|
|
1835
|
+
type: "header",
|
|
1836
|
+
key: "x-vercel-mfe-host"
|
|
1837
|
+
}
|
|
1838
|
+
]
|
|
1658
1839
|
}
|
|
1659
1840
|
];
|
|
1660
1841
|
});
|
|
@@ -1662,15 +1843,9 @@ function rewritesMapToArr(rewrites) {
|
|
|
1662
1843
|
function transform4(args) {
|
|
1663
1844
|
const { next, microfrontend, app } = args;
|
|
1664
1845
|
const buildBeforeFiles = () => {
|
|
1665
|
-
var _a;
|
|
1666
1846
|
const rewrites = /* @__PURE__ */ new Map();
|
|
1667
1847
|
if (!app.isDefault()) {
|
|
1668
|
-
|
|
1669
|
-
destination: {
|
|
1670
|
-
pathname: `/_next/:path+`
|
|
1671
|
-
}
|
|
1672
|
-
});
|
|
1673
|
-
if (!((_a = app.vercel) == null ? void 0 : _a.routeSpeedInsightsToDefaultZone)) {
|
|
1848
|
+
if (process.env.VERCEL_MICROFRONTENDS_CONSOLIDATE_SPEED_INSIGHTS === "1") {
|
|
1674
1849
|
rewrites.set(`/${app.getAssetPrefix()}/_vercel/:path*`, {
|
|
1675
1850
|
destination: { pathname: "/_vercel/:path*" }
|
|
1676
1851
|
});
|
|
@@ -1888,7 +2063,7 @@ function getApplicationContext(opts) {
|
|
|
1888
2063
|
return { name: opts.appName };
|
|
1889
2064
|
}
|
|
1890
2065
|
try {
|
|
1891
|
-
const packageJsonString =
|
|
2066
|
+
const packageJsonString = import_node_fs7.default.readFileSync("./package.json", "utf-8");
|
|
1892
2067
|
const packageJson = JSON.parse(packageJsonString);
|
|
1893
2068
|
if (!packageJson.name) {
|
|
1894
2069
|
throw new MicrofrontendError(
|
|
@@ -1913,8 +2088,8 @@ function withMicrofrontends(nextConfig, opts) {
|
|
|
1913
2088
|
process.env.MFE_DEBUG = "true";
|
|
1914
2089
|
}
|
|
1915
2090
|
const { name: fromApp } = getApplicationContext(opts);
|
|
1916
|
-
const microfrontends = MicrofrontendsServer.
|
|
1917
|
-
filePath:
|
|
2091
|
+
const microfrontends = MicrofrontendsServer.infer({
|
|
2092
|
+
filePath: opts == null ? void 0 : opts.configPath,
|
|
1918
2093
|
meta: {
|
|
1919
2094
|
fromApp
|
|
1920
2095
|
}
|