@vercel/microfrontends 0.17.2 → 0.17.3
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/LICENSE +21 -0
- package/README.md +48 -89
- package/dist/bin/cli.cjs +296 -198
- package/dist/config.cjs +19 -43
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.js +19 -43
- package/dist/config.js.map +1 -1
- package/dist/{types-a29d224a.d.ts → index-5fcf0863.d.ts} +2 -2
- package/dist/{index-09caaa28.d.ts → index-f094deb1.d.ts} +3 -3
- package/dist/microfrontends/server.cjs +65 -73
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +4 -4
- package/dist/microfrontends/server.js +65 -73
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends.cjs +21 -46
- package/dist/microfrontends.cjs.map +1 -1
- package/dist/microfrontends.d.ts +4 -4
- package/dist/microfrontends.js +21 -46
- 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.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +83 -99
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +83 -99
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.cjs +1 -1
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.d.ts +2 -2
- package/dist/next/endpoints.js +1 -1
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +29 -61
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +29 -61
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +24 -52
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +4 -4
- package/dist/next/testing.js +24 -52
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.cjs +1 -2
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.d.ts +3 -3
- package/dist/overrides.js +1 -2
- package/dist/overrides.js.map +1 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/{types-fc30696d.d.ts → types-5900be7c.d.ts} +1 -1
- package/dist/{types-cfe3308b.d.ts → types-ecd7b91b.d.ts} +1 -1
- package/dist/utils/mfe-port.cjs +65 -73
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +65 -73
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +46 -17
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.js +46 -17
- package/dist/validation.js.map +1 -1
- package/package.json +18 -22
- package/schema/schema.json +15 -8
package/dist/next/middleware.js
CHANGED
|
@@ -10,9 +10,9 @@ var MicrofrontendError = class extends Error {
|
|
|
10
10
|
constructor(message, opts) {
|
|
11
11
|
super(message);
|
|
12
12
|
this.name = "MicrofrontendsError";
|
|
13
|
-
this.source =
|
|
14
|
-
this.type =
|
|
15
|
-
this.subtype = opts
|
|
13
|
+
this.source = opts?.source ?? "@vercel/microfrontends";
|
|
14
|
+
this.type = opts?.type ?? "unknown";
|
|
15
|
+
this.subtype = opts?.subtype;
|
|
16
16
|
Error.captureStackTrace(this, MicrofrontendError);
|
|
17
17
|
}
|
|
18
18
|
isKnown() {
|
|
@@ -27,7 +27,7 @@ var MicrofrontendError = class extends Error {
|
|
|
27
27
|
* @returns The converted MicrofrontendsError.
|
|
28
28
|
*/
|
|
29
29
|
static convert(original, opts) {
|
|
30
|
-
if (opts
|
|
30
|
+
if (opts?.fileName) {
|
|
31
31
|
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
32
32
|
if (err) {
|
|
33
33
|
return err;
|
|
@@ -125,7 +125,7 @@ var MicrofrontendConfigClient = class {
|
|
|
125
125
|
constructor(config, opts) {
|
|
126
126
|
this.pathCache = {};
|
|
127
127
|
this.serialized = config;
|
|
128
|
-
if (opts
|
|
128
|
+
if (opts?.removeFlaggedPaths) {
|
|
129
129
|
for (const app of Object.values(config.applications)) {
|
|
130
130
|
if (app.routing) {
|
|
131
131
|
app.routing = app.routing.filter((match) => !match.flag);
|
|
@@ -191,8 +191,7 @@ var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
|
191
191
|
|
|
192
192
|
// src/config/overrides/is-override-cookie.ts
|
|
193
193
|
function isOverrideCookie(cookie) {
|
|
194
|
-
|
|
195
|
-
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
194
|
+
return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
196
195
|
}
|
|
197
196
|
|
|
198
197
|
// src/config/overrides/get-override-from-cookie.ts
|
|
@@ -221,17 +220,6 @@ function parseOverrides(cookies) {
|
|
|
221
220
|
|
|
222
221
|
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
223
222
|
import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to-regexp";
|
|
224
|
-
var SUPPORTED_VERSIONS = ["2"];
|
|
225
|
-
var validateConfigVersion = (version) => {
|
|
226
|
-
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
227
|
-
throw new MicrofrontendError(
|
|
228
|
-
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
229
|
-
", "
|
|
230
|
-
)}`,
|
|
231
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
223
|
var validateConfigPaths = (applicationConfigsById) => {
|
|
236
224
|
if (!applicationConfigsById) {
|
|
237
225
|
return;
|
|
@@ -407,7 +395,7 @@ var Host = class {
|
|
|
407
395
|
this.protocol = protocol;
|
|
408
396
|
this.host = host;
|
|
409
397
|
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
410
|
-
this.local = options
|
|
398
|
+
this.local = options?.isLocal;
|
|
411
399
|
}
|
|
412
400
|
isLocal() {
|
|
413
401
|
return this.local || this.host === "localhost" || this.host === "127.0.0.1";
|
|
@@ -456,18 +444,17 @@ var Application = class {
|
|
|
456
444
|
overrides,
|
|
457
445
|
isDefault
|
|
458
446
|
}) {
|
|
459
|
-
var _a, _b;
|
|
460
447
|
this.name = name;
|
|
461
448
|
this.development = {
|
|
462
449
|
local: new LocalHost({
|
|
463
450
|
appName: name,
|
|
464
|
-
...
|
|
451
|
+
...app.development?.local
|
|
465
452
|
}),
|
|
466
|
-
fallback:
|
|
453
|
+
fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
|
|
467
454
|
};
|
|
468
455
|
this.production = app.production ? new Host(app.production) : void 0;
|
|
469
456
|
this.vercel = app.vercel;
|
|
470
|
-
this.overrides =
|
|
457
|
+
this.overrides = overrides?.environment ? {
|
|
471
458
|
environment: new Host(overrides.environment)
|
|
472
459
|
} : void 0;
|
|
473
460
|
this.default = isDefault ?? false;
|
|
@@ -531,14 +518,13 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
531
518
|
opts
|
|
532
519
|
}) {
|
|
533
520
|
this.childApplications = {};
|
|
534
|
-
var _a, _b, _c, _d;
|
|
535
521
|
MicrofrontendConfigIsomorphic.validate(config, opts);
|
|
536
|
-
const disableOverrides =
|
|
522
|
+
const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
|
|
537
523
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
538
524
|
this.isMainConfig = isMainConfig(config);
|
|
539
525
|
if (isMainConfig(config)) {
|
|
540
526
|
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
541
|
-
const appOverrides = !disableOverrides ?
|
|
527
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
542
528
|
if (isDefaultApp(appConfig)) {
|
|
543
529
|
this.defaultApplication = new DefaultApplication(appId, {
|
|
544
530
|
app: appConfig,
|
|
@@ -553,7 +539,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
553
539
|
}
|
|
554
540
|
} else {
|
|
555
541
|
this.partOf = config.partOf;
|
|
556
|
-
const appOverrides = !disableOverrides ?
|
|
542
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
|
|
557
543
|
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
558
544
|
meta.fromApp,
|
|
559
545
|
{
|
|
@@ -581,12 +567,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
581
567
|
};
|
|
582
568
|
}
|
|
583
569
|
static validate(config, opts) {
|
|
584
|
-
const skipValidation =
|
|
570
|
+
const skipValidation = opts?.skipValidation ?? [];
|
|
585
571
|
const c = typeof config === "string" ? parse(config) : config;
|
|
586
572
|
if (isMainConfig(c)) {
|
|
587
|
-
if (!skipValidation.includes("version")) {
|
|
588
|
-
validateConfigVersion(c.version);
|
|
589
|
-
}
|
|
590
573
|
if (!skipValidation.includes("paths")) {
|
|
591
574
|
validateConfigPaths(c.applications);
|
|
592
575
|
}
|
|
@@ -607,8 +590,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
607
590
|
});
|
|
608
591
|
}
|
|
609
592
|
isOverridesDisabled() {
|
|
610
|
-
|
|
611
|
-
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
593
|
+
return this.options?.vercel?.disableOverrides ?? false;
|
|
612
594
|
}
|
|
613
595
|
getConfig() {
|
|
614
596
|
return this.config;
|
|
@@ -629,8 +611,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
629
611
|
].filter(Boolean);
|
|
630
612
|
}
|
|
631
613
|
getApplication(name) {
|
|
632
|
-
|
|
633
|
-
if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
|
|
614
|
+
if (this.defaultApplication?.name === name) {
|
|
634
615
|
return this.defaultApplication;
|
|
635
616
|
}
|
|
636
617
|
const app = this.childApplications[name];
|
|
@@ -646,15 +627,11 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
646
627
|
return app;
|
|
647
628
|
}
|
|
648
629
|
getApplicationByProjectId(projectId) {
|
|
649
|
-
|
|
650
|
-
if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
|
|
630
|
+
if (this.defaultApplication?.vercel?.projectId === projectId) {
|
|
651
631
|
return this.defaultApplication;
|
|
652
632
|
}
|
|
653
633
|
return Object.values(this.childApplications).find(
|
|
654
|
-
(app) =>
|
|
655
|
-
var _a2;
|
|
656
|
-
return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
|
|
657
|
-
}
|
|
634
|
+
(app) => app.vercel?.projectId === projectId
|
|
658
635
|
);
|
|
659
636
|
}
|
|
660
637
|
/**
|
|
@@ -677,8 +654,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
677
654
|
* Returns the configured port for the local proxy
|
|
678
655
|
*/
|
|
679
656
|
getLocalProxyPort() {
|
|
680
|
-
|
|
681
|
-
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
657
|
+
return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
682
658
|
}
|
|
683
659
|
/**
|
|
684
660
|
* Serializes the class back to the Schema type.
|
|
@@ -732,13 +708,12 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
732
708
|
overrides,
|
|
733
709
|
meta
|
|
734
710
|
}) {
|
|
735
|
-
var _a, _b, _c;
|
|
736
711
|
super({ config, overrides, meta });
|
|
737
712
|
this.isMainConfig = true;
|
|
738
|
-
const disableOverrides =
|
|
713
|
+
const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
|
|
739
714
|
let defaultApplication;
|
|
740
715
|
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
741
|
-
const appOverrides = !disableOverrides ?
|
|
716
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
742
717
|
if (isDefaultApp(appConfig)) {
|
|
743
718
|
defaultApplication = new DefaultApplication(appId, {
|
|
744
719
|
app: appConfig,
|
|
@@ -797,21 +772,17 @@ function getDomainFromEnvironment({
|
|
|
797
772
|
app,
|
|
798
773
|
target
|
|
799
774
|
}) {
|
|
800
|
-
var _a;
|
|
801
775
|
const mfeProjects = JSON.parse(
|
|
802
776
|
process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "[]"
|
|
803
777
|
);
|
|
804
778
|
if (mfeProjects.length === 0) {
|
|
805
779
|
throw new Error("Missing related microfrontends project information");
|
|
806
780
|
}
|
|
807
|
-
if (!
|
|
781
|
+
if (!app.vercel?.projectId) {
|
|
808
782
|
throw new Error(`Missing applications[${app.name}].vercel.projectId`);
|
|
809
783
|
}
|
|
810
784
|
const vercelProject = mfeProjects.find(
|
|
811
|
-
(p) =>
|
|
812
|
-
var _a2;
|
|
813
|
-
return p.project.id === ((_a2 = app.vercel) == null ? void 0 : _a2.projectId);
|
|
814
|
-
}
|
|
785
|
+
(p) => p.project.id === app.vercel?.projectId
|
|
815
786
|
);
|
|
816
787
|
if (!vercelProject) {
|
|
817
788
|
throw new Error(
|
|
@@ -854,9 +825,8 @@ function getCurrentEnvironment() {
|
|
|
854
825
|
return { group: "custom", name: process.env.VERCEL_ENV };
|
|
855
826
|
}
|
|
856
827
|
function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
857
|
-
var _a;
|
|
858
828
|
const app = config.getApplication(appName);
|
|
859
|
-
if (!opts.ignoreOverride &&
|
|
829
|
+
if (!opts.ignoreOverride && app.overrides?.environment) {
|
|
860
830
|
return app.overrides.environment.toString();
|
|
861
831
|
}
|
|
862
832
|
const { group } = getCurrentEnvironment();
|
|
@@ -883,8 +853,7 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
|
883
853
|
|
|
884
854
|
// src/next/middleware/middleware.ts
|
|
885
855
|
async function verifyPreviewDomain(req, rewriteDomain) {
|
|
886
|
-
|
|
887
|
-
const jwtCookie = (_a = req.cookies.get("_vercel_jwt")) == null ? void 0 : _a.value;
|
|
856
|
+
const jwtCookie = req.cookies.get("_vercel_jwt")?.value;
|
|
888
857
|
const deploymentProtectionBypassHeader = req.headers.get(
|
|
889
858
|
"x-vercel-protection-bypass"
|
|
890
859
|
);
|
|
@@ -909,7 +878,6 @@ function getHandler({
|
|
|
909
878
|
production
|
|
910
879
|
}) {
|
|
911
880
|
return async (req) => {
|
|
912
|
-
var _a, _b;
|
|
913
881
|
try {
|
|
914
882
|
const pathname = req.nextUrl.pathname;
|
|
915
883
|
const search = req.nextUrl.search;
|
|
@@ -926,7 +894,7 @@ function getHandler({
|
|
|
926
894
|
if (process.env.VERCEL_ENV === "preview" && rewriteDomain) {
|
|
927
895
|
const zoneFallbackCookieName = `__zone_${application.name}_production_fallback`;
|
|
928
896
|
const assetPrefix = application.getAssetPrefix();
|
|
929
|
-
if (assetPrefix && pathname.startsWith(`/${assetPrefix}`) &&
|
|
897
|
+
if (assetPrefix && pathname.startsWith(`/${assetPrefix}`) && req.cookies.get(zoneFallbackCookieName)?.value === "1") {
|
|
930
898
|
rewriteDomain = production.toString();
|
|
931
899
|
} else {
|
|
932
900
|
try {
|
|
@@ -949,7 +917,7 @@ function getHandler({
|
|
|
949
917
|
});
|
|
950
918
|
try {
|
|
951
919
|
const existingCookie = patchedHeaders.get("cookie");
|
|
952
|
-
if (!
|
|
920
|
+
if (!existingCookie?.includes("__vercel_toolbar")) {
|
|
953
921
|
patchedHeaders.set(
|
|
954
922
|
"cookie",
|
|
955
923
|
[`__vercel_toolbar=1`, existingCookie].join("; ")
|
|
@@ -965,7 +933,7 @@ function getHandler({
|
|
|
965
933
|
}
|
|
966
934
|
} catch (error) {
|
|
967
935
|
}
|
|
968
|
-
} else if (
|
|
936
|
+
} else if (req.cookies.get(zoneFallbackCookieName)?.value === "1") {
|
|
969
937
|
responseCallbacks.push((response) => {
|
|
970
938
|
response.cookies.set(zoneFallbackCookieName, "", {
|
|
971
939
|
httpOnly: true,
|
|
@@ -1048,7 +1016,7 @@ function getMicrofrontendsMiddleware({
|
|
|
1048
1016
|
const flagName = pathGroup.flag;
|
|
1049
1017
|
let flagFn;
|
|
1050
1018
|
if (flagName) {
|
|
1051
|
-
flagFn = flagValues
|
|
1019
|
+
flagFn = flagValues?.[flagName];
|
|
1052
1020
|
if (!flagFn) {
|
|
1053
1021
|
throw new Error(
|
|
1054
1022
|
`Flag "${flagName}" was specified to control routing for path group "${pathGroup.group}" in application ${application.name} but not found in provided flag values.`
|