@vercel/microfrontends 0.17.4 → 0.19.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/README.md +7 -159
- package/dist/bin/cli.cjs +202 -139
- package/dist/config.cjs +103 -57
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.js +103 -57
- package/dist/config.js.map +1 -1
- package/dist/{index-f094deb1.d.ts → index-09b1ddf9.d.ts} +16 -19
- package/dist/{index-5fcf0863.d.ts → index-2f78c0ca.d.ts} +44 -17
- package/dist/microfrontends/server.cjs +180 -133
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +4 -4
- package/dist/microfrontends/server.js +180 -133
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends.cjs +104 -58
- package/dist/microfrontends.cjs.map +1 -1
- package/dist/microfrontends.d.ts +4 -4
- package/dist/microfrontends.js +104 -58
- package/dist/microfrontends.js.map +1 -1
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.ts +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +197 -145
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +197 -145
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.d.ts +2 -2
- package/dist/next/middleware.cjs +121 -80
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +121 -80
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +110 -63
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +4 -4
- package/dist/next/testing.js +110 -63
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.d.ts +3 -3
- package/dist/schema.d.ts +1 -1
- package/dist/{types-5900be7c.d.ts → types-4ef2bddb.d.ts} +1 -1
- package/dist/{types-ecd7b91b.d.ts → types-b6d38aea.d.ts} +1 -1
- package/dist/utils/mfe-port.cjs +181 -134
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +181 -134
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +74 -73
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.js +74 -73
- package/dist/validation.js.map +1 -1
- package/package.json +19 -3
- package/schema/schema.json +80 -73
package/dist/next/config.js
CHANGED
|
@@ -41,7 +41,7 @@ function parseOverrides(cookies) {
|
|
|
41
41
|
// src/config/errors.ts
|
|
42
42
|
var MicrofrontendError = class extends Error {
|
|
43
43
|
constructor(message, opts) {
|
|
44
|
-
super(message);
|
|
44
|
+
super(message, { cause: opts?.cause });
|
|
45
45
|
this.name = "MicrofrontendsError";
|
|
46
46
|
this.source = opts?.source ?? "@vercel/microfrontends";
|
|
47
47
|
this.type = opts?.type ?? "unknown";
|
|
@@ -233,7 +233,8 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
233
233
|
if (isDefaultApp(app)) {
|
|
234
234
|
continue;
|
|
235
235
|
}
|
|
236
|
-
|
|
236
|
+
const childApp = app;
|
|
237
|
+
for (const pathMatch of childApp.routing) {
|
|
237
238
|
for (const path5 of pathMatch.paths) {
|
|
238
239
|
const maybeError = validatePathExpression(path5);
|
|
239
240
|
if (maybeError) {
|
|
@@ -253,33 +254,31 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
253
254
|
}
|
|
254
255
|
}
|
|
255
256
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
256
|
-
|
|
257
|
+
for (const [path5, { applications: ids, matcher, applicationId }] of entries) {
|
|
257
258
|
if (ids.length > 1) {
|
|
258
259
|
errors.push(
|
|
259
260
|
`Duplicate path "${path5}" for applications "${ids.join(", ")}"`
|
|
260
261
|
);
|
|
261
262
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
if (applicationId === matchApplicationId) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
if (matcher.test(matchPath)) {
|
|
274
|
-
const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
275
|
-
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
276
|
-
errors.push(
|
|
277
|
-
`Overlapping path detected between ${source} and ${destination}`
|
|
278
|
-
);
|
|
279
|
-
}
|
|
263
|
+
for (const [
|
|
264
|
+
matchPath,
|
|
265
|
+
{ applications: matchIds, applicationId: matchApplicationId }
|
|
266
|
+
] of entries) {
|
|
267
|
+
if (path5 === matchPath) {
|
|
268
|
+
continue;
|
|
280
269
|
}
|
|
281
|
-
|
|
282
|
-
|
|
270
|
+
if (applicationId === matchApplicationId) {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (matcher.test(matchPath)) {
|
|
274
|
+
const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
275
|
+
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
276
|
+
errors.push(
|
|
277
|
+
`Overlapping path detected between ${source} and ${destination}`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
283
282
|
if (errors.length) {
|
|
284
283
|
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
285
284
|
type: "config",
|
|
@@ -348,7 +347,7 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
348
347
|
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
349
348
|
if (numApplicationsWithoutRouting === 0) {
|
|
350
349
|
throw new MicrofrontendError(
|
|
351
|
-
|
|
350
|
+
"No default application found. At least one application needs to be the default by omitting routing.",
|
|
352
351
|
{ type: "config", subtype: "no_default_application" }
|
|
353
352
|
);
|
|
354
353
|
}
|
|
@@ -394,47 +393,80 @@ function generatePortFromName({
|
|
|
394
393
|
// src/config/microfrontends-config/isomorphic/host.ts
|
|
395
394
|
var Host = class {
|
|
396
395
|
constructor(hostConfig, options) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
396
|
+
if (typeof hostConfig === "string") {
|
|
397
|
+
({
|
|
398
|
+
protocol: this.protocol,
|
|
399
|
+
host: this.host,
|
|
400
|
+
port: this.port
|
|
401
|
+
} = Host.parseUrl(hostConfig));
|
|
402
|
+
} else {
|
|
403
|
+
const { protocol = "https", host, port } = hostConfig;
|
|
404
|
+
this.protocol = protocol;
|
|
405
|
+
this.host = host;
|
|
406
|
+
this.port = port;
|
|
407
|
+
}
|
|
401
408
|
this.local = options?.isLocal;
|
|
402
409
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
410
|
+
static parseUrl(url) {
|
|
411
|
+
let hostToParse = url;
|
|
412
|
+
if (!/^https?:\/\//.exec(hostToParse)) {
|
|
413
|
+
hostToParse = `https://${hostToParse}`;
|
|
414
|
+
}
|
|
415
|
+
const parsed = new URL(hostToParse);
|
|
416
|
+
if (!parsed.hostname) {
|
|
417
|
+
throw new Error(Host.getMicrofrontendsError(url, "requires a host"));
|
|
418
|
+
}
|
|
419
|
+
if (parsed.hash) {
|
|
420
|
+
throw new Error(
|
|
421
|
+
Host.getMicrofrontendsError(url, "cannot have a fragment")
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
if (parsed.username || parsed.password) {
|
|
425
|
+
throw new Error(
|
|
426
|
+
Host.getMicrofrontendsError(
|
|
427
|
+
url,
|
|
428
|
+
"cannot have authentication credentials (username and/or password)"
|
|
429
|
+
)
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
if (parsed.pathname !== "/") {
|
|
433
|
+
throw new Error(Host.getMicrofrontendsError(url, "cannot have a path"));
|
|
415
434
|
}
|
|
416
|
-
|
|
435
|
+
if (parsed.search) {
|
|
436
|
+
throw new Error(
|
|
437
|
+
Host.getMicrofrontendsError(url, "cannot have query parameters")
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
const protocol = parsed.protocol.slice(0, -1);
|
|
441
|
+
return {
|
|
442
|
+
protocol,
|
|
443
|
+
host: parsed.hostname,
|
|
444
|
+
port: parsed.port ? Number.parseInt(parsed.port) : void 0
|
|
445
|
+
};
|
|
417
446
|
}
|
|
418
|
-
|
|
419
|
-
return
|
|
447
|
+
static getMicrofrontendsError(url, message) {
|
|
448
|
+
return `Microfrontends configuration error: the URL ${url} in your microfrontends.json ${message}.`;
|
|
420
449
|
}
|
|
421
|
-
|
|
422
|
-
|
|
450
|
+
isLocal() {
|
|
451
|
+
return this.local || this.host === "localhost" || this.host === "127.0.0.1";
|
|
452
|
+
}
|
|
453
|
+
toString() {
|
|
454
|
+
const url = this.toUrl();
|
|
423
455
|
return url.toString().replace(/\/$/, "");
|
|
424
456
|
}
|
|
425
|
-
toUrl(
|
|
426
|
-
const {
|
|
427
|
-
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
457
|
+
toUrl() {
|
|
458
|
+
const url = `${this.protocol}://${this.host}${this.port ? `:${this.port}` : ""}`;
|
|
428
459
|
return new URL(url);
|
|
429
460
|
}
|
|
430
461
|
};
|
|
431
462
|
var LocalHost = class extends Host {
|
|
432
463
|
constructor({
|
|
433
464
|
appName,
|
|
465
|
+
localPort,
|
|
434
466
|
...hostConfig
|
|
435
467
|
}) {
|
|
436
468
|
const host = hostConfig.host ?? "localhost";
|
|
437
|
-
const port = hostConfig.port ?? generatePortFromName({ name: appName });
|
|
469
|
+
const port = localPort ?? hostConfig.port ?? generatePortFromName({ name: appName });
|
|
438
470
|
const protocol = hostConfig.protocol ?? "http";
|
|
439
471
|
super({ protocol, host, port });
|
|
440
472
|
}
|
|
@@ -451,12 +483,17 @@ var Application = class {
|
|
|
451
483
|
this.development = {
|
|
452
484
|
local: new LocalHost({
|
|
453
485
|
appName: name,
|
|
486
|
+
localPort: app.development?.localPort,
|
|
454
487
|
...app.development?.local
|
|
455
488
|
}),
|
|
456
489
|
fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
|
|
457
490
|
};
|
|
458
|
-
|
|
459
|
-
|
|
491
|
+
if (app.development?.fallback) {
|
|
492
|
+
this.fallback = new Host(app.development.fallback);
|
|
493
|
+
} else if (app.production) {
|
|
494
|
+
this.fallback = new Host(app.production);
|
|
495
|
+
}
|
|
496
|
+
this.projectId = app.projectId ?? app.vercel?.projectId;
|
|
460
497
|
this.overrides = overrides?.environment ? {
|
|
461
498
|
environment: new Host(overrides.environment)
|
|
462
499
|
} : void 0;
|
|
@@ -484,7 +521,16 @@ var DefaultApplication = class extends Application {
|
|
|
484
521
|
isDefault: true
|
|
485
522
|
});
|
|
486
523
|
this.default = true;
|
|
487
|
-
|
|
524
|
+
const fallbackHost = app.development?.fallback ?? app.production;
|
|
525
|
+
if (fallbackHost === void 0) {
|
|
526
|
+
throw new Error(
|
|
527
|
+
"`app.production` or `app.development.fallback` must be set in the default application in microfrontends.json."
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
this.fallback = new Host(fallbackHost);
|
|
531
|
+
if (app.production) {
|
|
532
|
+
this.production = new Host(app.production);
|
|
533
|
+
}
|
|
488
534
|
}
|
|
489
535
|
getAssetPrefix() {
|
|
490
536
|
return "";
|
|
@@ -554,7 +600,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
554
600
|
}
|
|
555
601
|
if (isMainConfig(config) && !this.defaultApplication) {
|
|
556
602
|
throw new MicrofrontendError(
|
|
557
|
-
|
|
603
|
+
"Could not find default application in microfrontends configuration",
|
|
558
604
|
{
|
|
559
605
|
type: "application",
|
|
560
606
|
subtype: "not_found"
|
|
@@ -630,11 +676,11 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
630
676
|
return app;
|
|
631
677
|
}
|
|
632
678
|
getApplicationByProjectId(projectId) {
|
|
633
|
-
if (this.defaultApplication?.
|
|
679
|
+
if (this.defaultApplication?.projectId === projectId) {
|
|
634
680
|
return this.defaultApplication;
|
|
635
681
|
}
|
|
636
682
|
return Object.values(this.childApplications).find(
|
|
637
|
-
(app) => app.
|
|
683
|
+
(app) => app.projectId === projectId
|
|
638
684
|
);
|
|
639
685
|
}
|
|
640
686
|
/**
|
|
@@ -644,7 +690,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
644
690
|
getDefaultApplication() {
|
|
645
691
|
if (!this.defaultApplication) {
|
|
646
692
|
throw new MicrofrontendError(
|
|
647
|
-
|
|
693
|
+
"Could not find default application in microfrontends configuration",
|
|
648
694
|
{
|
|
649
695
|
type: "application",
|
|
650
696
|
subtype: "not_found"
|
|
@@ -657,7 +703,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
657
703
|
* Returns the configured port for the local proxy
|
|
658
704
|
*/
|
|
659
705
|
getLocalProxyPort() {
|
|
660
|
-
return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
706
|
+
return this.config.options?.localProxyPort ?? this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
661
707
|
}
|
|
662
708
|
/**
|
|
663
709
|
* Serializes the class back to the Schema type.
|
|
@@ -731,7 +777,7 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
731
777
|
}
|
|
732
778
|
if (!defaultApplication) {
|
|
733
779
|
throw new MicrofrontendError(
|
|
734
|
-
|
|
780
|
+
"Could not find default application in microfrontends configuration",
|
|
735
781
|
{
|
|
736
782
|
type: "application",
|
|
737
783
|
subtype: "not_found"
|
|
@@ -1018,24 +1064,12 @@ var schema_default = {
|
|
|
1018
1064
|
options: {
|
|
1019
1065
|
$ref: "#/definitions/Options"
|
|
1020
1066
|
},
|
|
1021
|
-
remotes: {
|
|
1022
|
-
type: "object",
|
|
1023
|
-
additionalProperties: {
|
|
1024
|
-
$ref: "#/definitions/Application"
|
|
1025
|
-
},
|
|
1026
|
-
propertyNames: {
|
|
1027
|
-
description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
|
|
1028
|
-
},
|
|
1029
|
-
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
1030
|
-
},
|
|
1031
1067
|
applications: {
|
|
1032
1068
|
$ref: "#/definitions/ApplicationRouting",
|
|
1033
1069
|
description: "Mapping of application names to the routes that they host. Only needs to be defined in the application that owns the primary microfrontend domain"
|
|
1034
1070
|
}
|
|
1035
1071
|
},
|
|
1036
|
-
required: [
|
|
1037
|
-
"applications"
|
|
1038
|
-
],
|
|
1072
|
+
required: ["applications"],
|
|
1039
1073
|
additionalProperties: false
|
|
1040
1074
|
},
|
|
1041
1075
|
Options: {
|
|
@@ -1043,11 +1077,21 @@ var schema_default = {
|
|
|
1043
1077
|
properties: {
|
|
1044
1078
|
vercel: {
|
|
1045
1079
|
$ref: "#/definitions/VercelOptions",
|
|
1046
|
-
description: "
|
|
1080
|
+
description: "Microfrontends wide options for Vercel.",
|
|
1081
|
+
deprecated: "This is being replaced by the `disableOverrides` field below."
|
|
1082
|
+
},
|
|
1083
|
+
disableOverrides: {
|
|
1084
|
+
type: "boolean",
|
|
1085
|
+
description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
|
|
1047
1086
|
},
|
|
1048
1087
|
localProxy: {
|
|
1049
1088
|
$ref: "#/definitions/LocalProxyOptions",
|
|
1050
|
-
description: "Options for local proxy."
|
|
1089
|
+
description: "Options for local proxy.",
|
|
1090
|
+
deprecated: "This is being replaced by the `localProxyPort` field below."
|
|
1091
|
+
},
|
|
1092
|
+
localProxyPort: {
|
|
1093
|
+
type: "number",
|
|
1094
|
+
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
1051
1095
|
}
|
|
1052
1096
|
},
|
|
1053
1097
|
additionalProperties: false
|
|
@@ -1055,10 +1099,6 @@ var schema_default = {
|
|
|
1055
1099
|
VercelOptions: {
|
|
1056
1100
|
type: "object",
|
|
1057
1101
|
properties: {
|
|
1058
|
-
teamSlug: {
|
|
1059
|
-
type: "string",
|
|
1060
|
-
description: "Team slug for the Vercel team"
|
|
1061
|
-
},
|
|
1062
1102
|
disableOverrides: {
|
|
1063
1103
|
type: "boolean",
|
|
1064
1104
|
description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
|
|
@@ -1076,6 +1116,15 @@ var schema_default = {
|
|
|
1076
1116
|
},
|
|
1077
1117
|
additionalProperties: false
|
|
1078
1118
|
},
|
|
1119
|
+
ApplicationRouting: {
|
|
1120
|
+
type: "object",
|
|
1121
|
+
additionalProperties: {
|
|
1122
|
+
$ref: "#/definitions/Application"
|
|
1123
|
+
},
|
|
1124
|
+
propertyNames: {
|
|
1125
|
+
description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
|
|
1126
|
+
}
|
|
1127
|
+
},
|
|
1079
1128
|
Application: {
|
|
1080
1129
|
anyOf: [
|
|
1081
1130
|
{
|
|
@@ -1090,18 +1139,22 @@ var schema_default = {
|
|
|
1090
1139
|
type: "object",
|
|
1091
1140
|
properties: {
|
|
1092
1141
|
vercel: {
|
|
1093
|
-
$ref: "#/definitions/Vercel"
|
|
1142
|
+
$ref: "#/definitions/Vercel",
|
|
1143
|
+
deprecated: "This is being replaced by the `projectId` field below."
|
|
1144
|
+
},
|
|
1145
|
+
projectId: {
|
|
1146
|
+
type: "string",
|
|
1147
|
+
description: "Vercel project ID"
|
|
1094
1148
|
},
|
|
1095
1149
|
development: {
|
|
1096
1150
|
$ref: "#/definitions/Development"
|
|
1097
1151
|
},
|
|
1098
1152
|
production: {
|
|
1099
|
-
$ref: "#/definitions/HostConfig"
|
|
1153
|
+
$ref: "#/definitions/HostConfig",
|
|
1154
|
+
deprecated: "This is a duplicate of the `development.fallback` field and this will be removed soon."
|
|
1100
1155
|
}
|
|
1101
1156
|
},
|
|
1102
|
-
required: [
|
|
1103
|
-
"production"
|
|
1104
|
-
],
|
|
1157
|
+
required: ["production"],
|
|
1105
1158
|
additionalProperties: false
|
|
1106
1159
|
},
|
|
1107
1160
|
Vercel: {
|
|
@@ -1112,20 +1165,30 @@ var schema_default = {
|
|
|
1112
1165
|
description: "Vercel project ID"
|
|
1113
1166
|
}
|
|
1114
1167
|
},
|
|
1115
|
-
required: [
|
|
1116
|
-
"projectId"
|
|
1117
|
-
],
|
|
1168
|
+
required: ["projectId"],
|
|
1118
1169
|
additionalProperties: false
|
|
1119
1170
|
},
|
|
1120
1171
|
Development: {
|
|
1121
1172
|
type: "object",
|
|
1122
1173
|
properties: {
|
|
1123
1174
|
local: {
|
|
1124
|
-
$ref: "#/definitions/LocalHostConfig"
|
|
1175
|
+
$ref: "#/definitions/LocalHostConfig",
|
|
1176
|
+
deprecated: "This is being replaced by the `localPort` field below."
|
|
1177
|
+
},
|
|
1178
|
+
localPort: {
|
|
1179
|
+
type: "number",
|
|
1180
|
+
description: "The local port number that this application runs on when it is running locally. Common values include `80` for HTTP and `443` for HTTPS."
|
|
1125
1181
|
},
|
|
1126
1182
|
fallback: {
|
|
1127
|
-
|
|
1128
|
-
|
|
1183
|
+
anyOf: [
|
|
1184
|
+
{
|
|
1185
|
+
$ref: "#/definitions/HostConfig"
|
|
1186
|
+
},
|
|
1187
|
+
{
|
|
1188
|
+
type: "string"
|
|
1189
|
+
}
|
|
1190
|
+
],
|
|
1191
|
+
description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error.\n\nIf passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTPS. If omitted, the port defaults to `80` for HTTP and `443` for HTTPS."
|
|
1129
1192
|
},
|
|
1130
1193
|
task: {
|
|
1131
1194
|
type: "string",
|
|
@@ -1144,10 +1207,7 @@ var schema_default = {
|
|
|
1144
1207
|
},
|
|
1145
1208
|
protocol: {
|
|
1146
1209
|
type: "string",
|
|
1147
|
-
enum: [
|
|
1148
|
-
"http",
|
|
1149
|
-
"https"
|
|
1150
|
-
],
|
|
1210
|
+
enum: ["http", "https"],
|
|
1151
1211
|
description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
|
|
1152
1212
|
},
|
|
1153
1213
|
port: {
|
|
@@ -1161,10 +1221,7 @@ var schema_default = {
|
|
|
1161
1221
|
properties: {
|
|
1162
1222
|
protocol: {
|
|
1163
1223
|
type: "string",
|
|
1164
|
-
enum: [
|
|
1165
|
-
"http",
|
|
1166
|
-
"https"
|
|
1167
|
-
],
|
|
1224
|
+
enum: ["http", "https"],
|
|
1168
1225
|
description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
|
|
1169
1226
|
},
|
|
1170
1227
|
host: {
|
|
@@ -1176,16 +1233,19 @@ var schema_default = {
|
|
|
1176
1233
|
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
1177
1234
|
}
|
|
1178
1235
|
},
|
|
1179
|
-
required: [
|
|
1180
|
-
"host"
|
|
1181
|
-
],
|
|
1236
|
+
required: ["host"],
|
|
1182
1237
|
additionalProperties: false
|
|
1183
1238
|
},
|
|
1184
1239
|
ChildApplication: {
|
|
1185
1240
|
type: "object",
|
|
1186
1241
|
properties: {
|
|
1187
1242
|
vercel: {
|
|
1188
|
-
$ref: "#/definitions/Vercel"
|
|
1243
|
+
$ref: "#/definitions/Vercel",
|
|
1244
|
+
deprecated: "This is being replaced by the `projectId` field below."
|
|
1245
|
+
},
|
|
1246
|
+
projectId: {
|
|
1247
|
+
type: "string",
|
|
1248
|
+
description: "Vercel project ID"
|
|
1189
1249
|
},
|
|
1190
1250
|
development: {
|
|
1191
1251
|
$ref: "#/definitions/Development"
|
|
@@ -1195,12 +1255,11 @@ var schema_default = {
|
|
|
1195
1255
|
description: "Groups of path expressions that are routed to this application."
|
|
1196
1256
|
},
|
|
1197
1257
|
production: {
|
|
1198
|
-
$ref: "#/definitions/HostConfig"
|
|
1258
|
+
$ref: "#/definitions/HostConfig",
|
|
1259
|
+
deprecated: "This is a duplicate of the `development.fallback` field and this will be removed soon."
|
|
1199
1260
|
}
|
|
1200
1261
|
},
|
|
1201
|
-
required: [
|
|
1202
|
-
"routing"
|
|
1203
|
-
],
|
|
1262
|
+
required: ["routing"],
|
|
1204
1263
|
additionalProperties: false
|
|
1205
1264
|
},
|
|
1206
1265
|
Routing: {
|
|
@@ -1227,20 +1286,9 @@ var schema_default = {
|
|
|
1227
1286
|
}
|
|
1228
1287
|
}
|
|
1229
1288
|
},
|
|
1230
|
-
required: [
|
|
1231
|
-
"paths"
|
|
1232
|
-
],
|
|
1289
|
+
required: ["paths"],
|
|
1233
1290
|
additionalProperties: false
|
|
1234
1291
|
},
|
|
1235
|
-
ApplicationRouting: {
|
|
1236
|
-
type: "object",
|
|
1237
|
-
additionalProperties: {
|
|
1238
|
-
$ref: "#/definitions/Application"
|
|
1239
|
-
},
|
|
1240
|
-
propertyNames: {
|
|
1241
|
-
description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
|
|
1242
|
-
}
|
|
1243
|
-
},
|
|
1244
1292
|
ChildConfig: {
|
|
1245
1293
|
type: "object",
|
|
1246
1294
|
properties: {
|
|
@@ -1254,24 +1302,12 @@ var schema_default = {
|
|
|
1254
1302
|
options: {
|
|
1255
1303
|
$ref: "#/definitions/Options"
|
|
1256
1304
|
},
|
|
1257
|
-
remotes: {
|
|
1258
|
-
type: "object",
|
|
1259
|
-
additionalProperties: {
|
|
1260
|
-
$ref: "#/definitions/Application"
|
|
1261
|
-
},
|
|
1262
|
-
propertyNames: {
|
|
1263
|
-
description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
|
|
1264
|
-
},
|
|
1265
|
-
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
1266
|
-
},
|
|
1267
1305
|
partOf: {
|
|
1268
1306
|
type: "string",
|
|
1269
1307
|
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
1270
1308
|
}
|
|
1271
1309
|
},
|
|
1272
|
-
required: [
|
|
1273
|
-
"partOf"
|
|
1274
|
-
],
|
|
1310
|
+
required: ["partOf"],
|
|
1275
1311
|
additionalProperties: false
|
|
1276
1312
|
}
|
|
1277
1313
|
}
|
|
@@ -1281,6 +1317,14 @@ var schema_default = {
|
|
|
1281
1317
|
var SCHEMA = schema_default;
|
|
1282
1318
|
|
|
1283
1319
|
// src/config/microfrontends/server/validation.ts
|
|
1320
|
+
function filterAjvErrors(errors) {
|
|
1321
|
+
if (!errors) {
|
|
1322
|
+
return [];
|
|
1323
|
+
}
|
|
1324
|
+
return errors.filter((error) => {
|
|
1325
|
+
return error.keyword === "additionalProperties" || error.keyword === "required";
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1284
1328
|
function validateSchema(configString) {
|
|
1285
1329
|
const parsedConfig = parse3(configString);
|
|
1286
1330
|
const ajv = new Ajv();
|
|
@@ -1288,7 +1332,10 @@ function validateSchema(configString) {
|
|
|
1288
1332
|
const isValid = validate(parsedConfig);
|
|
1289
1333
|
if (!isValid) {
|
|
1290
1334
|
throw new MicrofrontendError(
|
|
1291
|
-
`Invalid config:
|
|
1335
|
+
`Invalid microfrontends config:
|
|
1336
|
+
- ${ajv.errorsText(filterAjvErrors(validate.errors), { separator: "\n - " })}
|
|
1337
|
+
|
|
1338
|
+
See https://openapi.vercel.sh/microfrontends.json for the schema.`,
|
|
1292
1339
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
1293
1340
|
);
|
|
1294
1341
|
}
|
|
@@ -1428,8 +1475,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1428
1475
|
throw new Error("Unable to infer");
|
|
1429
1476
|
} catch (e) {
|
|
1430
1477
|
throw new MicrofrontendError(
|
|
1431
|
-
"Unable to
|
|
1432
|
-
{ type: "config", subtype: "inference_failed" }
|
|
1478
|
+
"Unable to locate and parse microfrontends configuration",
|
|
1479
|
+
{ cause: e, type: "config", subtype: "inference_failed" }
|
|
1433
1480
|
);
|
|
1434
1481
|
}
|
|
1435
1482
|
}
|
|
@@ -1505,7 +1552,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1505
1552
|
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1506
1553
|
if (!defaultApplication) {
|
|
1507
1554
|
throw new MicrofrontendError(
|
|
1508
|
-
|
|
1555
|
+
"No default application found. At least one application needs to be the default by omitting routing.",
|
|
1509
1556
|
{ type: "config", subtype: "no_default_application" }
|
|
1510
1557
|
);
|
|
1511
1558
|
}
|
|
@@ -1634,12 +1681,10 @@ function getDomainFromEnvironment({
|
|
|
1634
1681
|
if (mfeProjects.length === 0) {
|
|
1635
1682
|
throw new Error("Missing related microfrontends project information");
|
|
1636
1683
|
}
|
|
1637
|
-
if (!app.
|
|
1684
|
+
if (!app.projectId) {
|
|
1638
1685
|
throw new Error(`Missing applications[${app.name}].vercel.projectId`);
|
|
1639
1686
|
}
|
|
1640
|
-
const vercelProject = mfeProjects.find(
|
|
1641
|
-
(p) => p.project.id === app.vercel?.projectId
|
|
1642
|
-
);
|
|
1687
|
+
const vercelProject = mfeProjects.find((p) => p.project.id === app.projectId);
|
|
1643
1688
|
if (!vercelProject) {
|
|
1644
1689
|
throw new Error(
|
|
1645
1690
|
`Missing related microfrontends project information for application "${app.name}"`
|
|
@@ -1673,9 +1718,11 @@ function getCurrentEnvironment() {
|
|
|
1673
1718
|
const isProduction2 = process.env.VERCEL_ENV === "production";
|
|
1674
1719
|
if (isDevelopment) {
|
|
1675
1720
|
return { group: "development" };
|
|
1676
|
-
}
|
|
1721
|
+
}
|
|
1722
|
+
if (isProduction2) {
|
|
1677
1723
|
return { group: "production" };
|
|
1678
|
-
}
|
|
1724
|
+
}
|
|
1725
|
+
if (isPreview) {
|
|
1679
1726
|
return { group: "preview" };
|
|
1680
1727
|
}
|
|
1681
1728
|
return { group: "custom", name: process.env.VERCEL_ENV };
|
|
@@ -1686,10 +1733,10 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
|
1686
1733
|
return app.overrides.environment.toString();
|
|
1687
1734
|
}
|
|
1688
1735
|
const { group } = getCurrentEnvironment();
|
|
1689
|
-
const
|
|
1736
|
+
const fallbackHost = config.getDefaultApplication().fallback.toString();
|
|
1690
1737
|
switch (group) {
|
|
1691
1738
|
case "development": {
|
|
1692
|
-
const domain = ["test", "development"].includes(process.env.NODE_ENV) ? app.development.local.toString() :
|
|
1739
|
+
const domain = ["test", "development"].includes(process.env.NODE_ENV) ? app.development.local.toString() : fallbackHost;
|
|
1693
1740
|
debugDomains(appName, "development", domain);
|
|
1694
1741
|
return domain;
|
|
1695
1742
|
}
|
|
@@ -1700,10 +1747,9 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
|
1700
1747
|
return getDomainFromEnvironment({ app, target: "production" });
|
|
1701
1748
|
}
|
|
1702
1749
|
case "custom":
|
|
1703
|
-
|
|
1704
|
-
|
|
1750
|
+
throw new Error(
|
|
1751
|
+
"Custom environments are not supported in getDomainForCurrentEnvironment"
|
|
1705
1752
|
);
|
|
1706
|
-
return productionHost;
|
|
1707
1753
|
}
|
|
1708
1754
|
}
|
|
1709
1755
|
|
|
@@ -1890,7 +1936,13 @@ function transform5(args) {
|
|
|
1890
1936
|
// this deployments host
|
|
1891
1937
|
...process.env.VERCEL_URL ? [formatDomainForServerAction(process.env.VERCEL_URL)] : [],
|
|
1892
1938
|
// default application host
|
|
1893
|
-
formatDomainForServerAction(
|
|
1939
|
+
formatDomainForServerAction(
|
|
1940
|
+
getDomainFromEnvironment({
|
|
1941
|
+
app: defaultApplication,
|
|
1942
|
+
target: "production"
|
|
1943
|
+
})
|
|
1944
|
+
),
|
|
1945
|
+
formatDomainForServerAction(defaultApplication.fallback.toString()),
|
|
1894
1946
|
// environment specific microfrontend hosts
|
|
1895
1947
|
...appsToAllow.flatMap((a) => [
|
|
1896
1948
|
formatDomainForServerAction(
|