@vercel/microfrontends 0.9.0 → 0.10.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 +2 -2
- package/dist/bin/cli.cjs +1483 -186
- package/dist/config/edge.cjs +47 -47
- package/dist/config/edge.cjs.map +1 -1
- package/dist/config/edge.d.ts +6 -6
- package/dist/config/edge.js +46 -46
- package/dist/config/edge.js.map +1 -1
- package/dist/config.cjs +66 -60
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.js +65 -59
- package/dist/config.js.map +1 -1
- package/dist/{index-eff254d8.d.ts → index-05742bef.d.ts} +11 -22
- package/dist/{micro-frontend-config-42886104.d.ts → microfrontend-config-2425db74.d.ts} +12 -12
- package/dist/next/config.cjs +83 -77
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +3 -3
- package/dist/next/config.js +82 -76
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +55 -55
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +11 -11
- package/dist/next/middleware.js +53 -53
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +79 -73
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +9 -9
- package/dist/next/testing.js +79 -73
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.cjs +9 -9
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.d.ts +1 -1
- package/dist/overrides.js +9 -9
- package/dist/overrides.js.map +1 -1
- package/dist/types-13f3e535.d.ts +15 -0
- package/dist/v2/config.cjs +39 -39
- package/dist/v2/config.cjs.map +1 -1
- package/dist/v2/config.d.ts +2 -1
- package/dist/v2/config.js +38 -38
- package/dist/v2/config.js.map +1 -1
- package/dist/v2/microfrontends/server.cjs +102 -65
- package/dist/v2/microfrontends/server.cjs.map +1 -1
- package/dist/v2/microfrontends/server.d.ts +6 -1
- package/dist/v2/microfrontends/server.js +102 -65
- package/dist/v2/microfrontends/server.js.map +1 -1
- package/dist/v2/microfrontends.cjs +44 -44
- package/dist/v2/microfrontends.cjs.map +1 -1
- package/dist/v2/microfrontends.d.ts +5 -4
- package/dist/v2/microfrontends.js +44 -44
- package/dist/v2/microfrontends.js.map +1 -1
- package/dist/v2/next/client.cjs +1 -1
- package/dist/v2/next/client.cjs.map +1 -1
- package/dist/v2/next/client.js +1 -1
- package/dist/v2/next/client.js.map +1 -1
- package/dist/v2/next/config.cjs +120 -83
- package/dist/v2/next/config.cjs.map +1 -1
- package/dist/v2/next/config.d.ts +4 -4
- package/dist/v2/next/config.js +119 -82
- package/dist/v2/next/config.js.map +1 -1
- package/dist/v2/next/endpoints.cjs +5 -5
- package/dist/v2/next/endpoints.cjs.map +1 -1
- package/dist/v2/next/endpoints.js +5 -5
- package/dist/v2/next/endpoints.js.map +1 -1
- package/dist/v2/next/middleware.cjs +54 -54
- package/dist/v2/next/middleware.cjs.map +1 -1
- package/dist/v2/next/middleware.d.ts +8 -8
- package/dist/v2/next/middleware.js +52 -52
- package/dist/v2/next/middleware.js.map +1 -1
- package/dist/v2/overrides.cjs +75 -0
- package/dist/v2/overrides.cjs.map +1 -0
- package/dist/v2/overrides.d.ts +24 -0
- package/dist/v2/overrides.js +45 -0
- package/dist/v2/overrides.js.map +1 -0
- package/dist/validation.cjs +20 -20
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.js +20 -20
- package/dist/validation.js.map +1 -1
- package/package.json +10 -3
|
@@ -6,14 +6,14 @@ import { pathToRegexp as pathToRegexp3 } from "path-to-regexp";
|
|
|
6
6
|
import { parse } from "jsonc-parser";
|
|
7
7
|
|
|
8
8
|
// src/config-v2/errors.ts
|
|
9
|
-
var
|
|
9
|
+
var MicrofrontendError = class extends Error {
|
|
10
10
|
constructor(message, opts) {
|
|
11
11
|
super(message);
|
|
12
|
-
this.name = "
|
|
13
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
12
|
+
this.name = "MicrofrontendsError";
|
|
13
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
14
14
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
15
15
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
16
|
-
Error.captureStackTrace(this,
|
|
16
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
17
17
|
}
|
|
18
18
|
isKnown() {
|
|
19
19
|
return this.type !== "unknown";
|
|
@@ -22,13 +22,13 @@ var MicroFrontendError = class extends Error {
|
|
|
22
22
|
return !this.isKnown();
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Converts an error to a
|
|
25
|
+
* Converts an error to a MicrofrontendsError.
|
|
26
26
|
* @param original - The original error to convert.
|
|
27
|
-
* @returns The converted
|
|
27
|
+
* @returns The converted MicrofrontendsError.
|
|
28
28
|
*/
|
|
29
29
|
static convert(original, opts) {
|
|
30
30
|
if (opts == null ? void 0 : opts.fileName) {
|
|
31
|
-
const err =
|
|
31
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
32
32
|
if (err) {
|
|
33
33
|
return err;
|
|
34
34
|
}
|
|
@@ -36,25 +36,25 @@ var MicroFrontendError = class extends Error {
|
|
|
36
36
|
if (original.message.includes(
|
|
37
37
|
"Code generation from strings disallowed for this context"
|
|
38
38
|
)) {
|
|
39
|
-
return new
|
|
39
|
+
return new MicrofrontendError(original.message, {
|
|
40
40
|
type: "config",
|
|
41
41
|
subtype: "unsupported_validation_env",
|
|
42
42
|
source: "ajv"
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
return new
|
|
45
|
+
return new MicrofrontendError(original.message);
|
|
46
46
|
}
|
|
47
47
|
static convertFSError(original, fileName) {
|
|
48
48
|
if (original instanceof Error && "code" in original) {
|
|
49
49
|
if (original.code === "ENOENT") {
|
|
50
|
-
return new
|
|
50
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
51
51
|
type: "config",
|
|
52
52
|
subtype: "unable_to_read_file",
|
|
53
53
|
source: "fs"
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
if (original.code === "EACCES") {
|
|
57
|
-
return new
|
|
57
|
+
return new MicrofrontendError(
|
|
58
58
|
`Permission denied while accessing "${fileName}"`,
|
|
59
59
|
{
|
|
60
60
|
type: "config",
|
|
@@ -65,7 +65,7 @@ var MicroFrontendError = class extends Error {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
if (original instanceof SyntaxError) {
|
|
68
|
-
return new
|
|
68
|
+
return new MicrofrontendError(
|
|
69
69
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
70
70
|
{
|
|
71
71
|
type: "config",
|
|
@@ -77,23 +77,23 @@ var MicroFrontendError = class extends Error {
|
|
|
77
77
|
return null;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Handles an unknown error and returns a
|
|
80
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
81
81
|
* @param err - The error to handle.
|
|
82
|
-
* @returns A
|
|
82
|
+
* @returns A MicrofrontendsError instance.
|
|
83
83
|
*/
|
|
84
84
|
static handle(err, opts) {
|
|
85
|
-
if (err instanceof
|
|
85
|
+
if (err instanceof MicrofrontendError) {
|
|
86
86
|
return err;
|
|
87
87
|
}
|
|
88
88
|
if (err instanceof Error) {
|
|
89
|
-
return
|
|
89
|
+
return MicrofrontendError.convert(err, opts);
|
|
90
90
|
}
|
|
91
91
|
if (typeof err === "object" && err !== null) {
|
|
92
92
|
if ("message" in err && typeof err.message === "string") {
|
|
93
|
-
return
|
|
93
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
return new
|
|
96
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
|
|
@@ -101,7 +101,7 @@ var MicroFrontendError = class extends Error {
|
|
|
101
101
|
function getConfigStringFromEnv() {
|
|
102
102
|
const config = process.env.MFE_CONFIG;
|
|
103
103
|
if (!config) {
|
|
104
|
-
throw new
|
|
104
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
105
105
|
type: "config",
|
|
106
106
|
subtype: "not_found_in_env"
|
|
107
107
|
});
|
|
@@ -121,7 +121,7 @@ function isDefaultApp(a) {
|
|
|
121
121
|
|
|
122
122
|
// src/config-v2/microfrontends-config/client/index.ts
|
|
123
123
|
import { pathToRegexp } from "path-to-regexp";
|
|
124
|
-
var
|
|
124
|
+
var MicrofrontendConfigClient = class {
|
|
125
125
|
constructor(config, opts) {
|
|
126
126
|
this.pathCache = {};
|
|
127
127
|
this.serialized = config;
|
|
@@ -135,14 +135,14 @@ var MicroFrontendConfigClient = class {
|
|
|
135
135
|
this.applications = config.applications;
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
|
-
* Create a new `
|
|
138
|
+
* Create a new `MicrofrontendConfigClient` from a JSON string.
|
|
139
139
|
* Config must be passed in to remain framework agnostic
|
|
140
140
|
*/
|
|
141
141
|
static fromEnv(config, opts) {
|
|
142
142
|
if (!config) {
|
|
143
|
-
throw new Error("No
|
|
143
|
+
throw new Error("No microfrontends configuration found");
|
|
144
144
|
}
|
|
145
|
-
return new
|
|
145
|
+
return new MicrofrontendConfigClient(
|
|
146
146
|
JSON.parse(config),
|
|
147
147
|
opts
|
|
148
148
|
);
|
|
@@ -224,7 +224,7 @@ import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to
|
|
|
224
224
|
var SUPPORTED_VERSIONS = ["2"];
|
|
225
225
|
var validateConfigVersion = (version) => {
|
|
226
226
|
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
227
|
-
throw new
|
|
227
|
+
throw new MicrofrontendError(
|
|
228
228
|
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
229
229
|
", "
|
|
230
230
|
)}`,
|
|
@@ -294,7 +294,7 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
294
294
|
);
|
|
295
295
|
});
|
|
296
296
|
if (errors.length) {
|
|
297
|
-
throw new
|
|
297
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
298
298
|
type: "config",
|
|
299
299
|
subtype: "conflicting_paths"
|
|
300
300
|
});
|
|
@@ -307,13 +307,13 @@ var validateAppPaths = (name, app) => {
|
|
|
307
307
|
continue;
|
|
308
308
|
}
|
|
309
309
|
if (p.endsWith("/")) {
|
|
310
|
-
throw new
|
|
310
|
+
throw new MicrofrontendError(
|
|
311
311
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
312
312
|
{ type: "application", subtype: "invalid_path" }
|
|
313
313
|
);
|
|
314
314
|
}
|
|
315
315
|
if (!p.startsWith("/")) {
|
|
316
|
-
throw new
|
|
316
|
+
throw new MicrofrontendError(
|
|
317
317
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
318
318
|
{ type: "application", subtype: "invalid_path" }
|
|
319
319
|
);
|
|
@@ -335,13 +335,13 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
335
335
|
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
336
336
|
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
337
337
|
if (numApplicationsWithoutRouting === 0) {
|
|
338
|
-
throw new
|
|
338
|
+
throw new MicrofrontendError(
|
|
339
339
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
340
340
|
{ type: "config", subtype: "no_default_application" }
|
|
341
341
|
);
|
|
342
342
|
}
|
|
343
343
|
if (numApplicationsWithoutRouting > 1) {
|
|
344
|
-
throw new
|
|
344
|
+
throw new MicrofrontendError(
|
|
345
345
|
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
346
346
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
347
347
|
);
|
|
@@ -353,7 +353,7 @@ var validateConfigOptions = (options) => {
|
|
|
353
353
|
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
354
354
|
options.vercel.previewDeploymentSuffix
|
|
355
355
|
)) {
|
|
356
|
-
throw new
|
|
356
|
+
throw new MicrofrontendError(
|
|
357
357
|
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
358
358
|
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
359
359
|
);
|
|
@@ -512,7 +512,7 @@ var ChildApplication = class extends Application {
|
|
|
512
512
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
513
513
|
|
|
514
514
|
// src/config-v2/microfrontends-config/isomorphic/index.ts
|
|
515
|
-
var
|
|
515
|
+
var MicrofrontendConfigIsomorphic = class {
|
|
516
516
|
constructor({
|
|
517
517
|
config,
|
|
518
518
|
overrides,
|
|
@@ -520,7 +520,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
520
520
|
}) {
|
|
521
521
|
this.childApplications = {};
|
|
522
522
|
var _a, _b, _c, _d;
|
|
523
|
-
|
|
523
|
+
MicrofrontendConfigIsomorphic.validate(config);
|
|
524
524
|
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
525
525
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
526
526
|
this.isMainConfig = isMainConfig(config);
|
|
@@ -552,7 +552,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
552
552
|
);
|
|
553
553
|
}
|
|
554
554
|
if (isMainConfig(config) && !this.defaultApplication) {
|
|
555
|
-
throw new
|
|
555
|
+
throw new MicrofrontendError(
|
|
556
556
|
`Could not find default application in microfrontends configuration`,
|
|
557
557
|
{
|
|
558
558
|
type: "application",
|
|
@@ -582,7 +582,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
582
582
|
meta,
|
|
583
583
|
cookies
|
|
584
584
|
}) {
|
|
585
|
-
return new
|
|
585
|
+
return new MicrofrontendConfigIsomorphic({
|
|
586
586
|
config: parse(getConfigStringFromEnv()),
|
|
587
587
|
overrides: parseOverrides(cookies ?? []),
|
|
588
588
|
meta
|
|
@@ -617,7 +617,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
617
617
|
}
|
|
618
618
|
const app = this.childApplications[name];
|
|
619
619
|
if (!app) {
|
|
620
|
-
throw new
|
|
620
|
+
throw new MicrofrontendError(
|
|
621
621
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
622
622
|
{
|
|
623
623
|
type: "application",
|
|
@@ -645,7 +645,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
645
645
|
*/
|
|
646
646
|
getDefaultApplication() {
|
|
647
647
|
if (!this.defaultApplication) {
|
|
648
|
-
throw new
|
|
648
|
+
throw new MicrofrontendError(
|
|
649
649
|
`Could not find default application in microfrontends configuration`,
|
|
650
650
|
{
|
|
651
651
|
type: "application",
|
|
@@ -685,7 +685,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
685
685
|
default: true
|
|
686
686
|
};
|
|
687
687
|
}
|
|
688
|
-
return new
|
|
688
|
+
return new MicrofrontendConfigClient({
|
|
689
689
|
applications
|
|
690
690
|
});
|
|
691
691
|
}
|
|
@@ -695,7 +695,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
695
695
|
};
|
|
696
696
|
|
|
697
697
|
// src/config-v2/microfrontends-config/isomorphic/child.ts
|
|
698
|
-
var
|
|
698
|
+
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
699
699
|
constructor({
|
|
700
700
|
config,
|
|
701
701
|
overrides,
|
|
@@ -708,7 +708,7 @@ var MicroFrontendChildConfig = class extends MicroFrontendConfigIsomorphic {
|
|
|
708
708
|
};
|
|
709
709
|
|
|
710
710
|
// src/config-v2/microfrontends-config/isomorphic/main.ts
|
|
711
|
-
var
|
|
711
|
+
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
712
712
|
constructor({
|
|
713
713
|
config,
|
|
714
714
|
overrides,
|
|
@@ -735,7 +735,7 @@ var MicroFrontendMainConfig = class extends MicroFrontendConfigIsomorphic {
|
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
737
|
if (!defaultApplication) {
|
|
738
|
-
throw new
|
|
738
|
+
throw new MicrofrontendError(
|
|
739
739
|
`Could not find default application in microfrontends configuration`,
|
|
740
740
|
{
|
|
741
741
|
type: "application",
|
|
@@ -755,19 +755,19 @@ var Microfrontends = class {
|
|
|
755
755
|
meta
|
|
756
756
|
}) {
|
|
757
757
|
if (isMainConfig(config)) {
|
|
758
|
-
this.config = new
|
|
758
|
+
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
759
759
|
} else {
|
|
760
|
-
this.config = new
|
|
760
|
+
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
761
761
|
}
|
|
762
762
|
}
|
|
763
763
|
isChildConfig() {
|
|
764
|
-
return this.config instanceof
|
|
764
|
+
return this.config instanceof MicrofrontendChildConfig;
|
|
765
765
|
}
|
|
766
766
|
static fromEnv({
|
|
767
767
|
cookies,
|
|
768
768
|
meta
|
|
769
769
|
}) {
|
|
770
|
-
const config =
|
|
770
|
+
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
771
771
|
cookies,
|
|
772
772
|
meta
|
|
773
773
|
});
|
|
@@ -874,7 +874,7 @@ async function verifyPreviewDomain(req, rewriteDomain) {
|
|
|
874
874
|
const vercelError = previewResponse.headers.get("x-vercel-error");
|
|
875
875
|
return !(previewResponse.status === 404 && (vercelError === "DEPLOYMENT_NOT_FOUND" || vercelError === "NOT_FOUND"));
|
|
876
876
|
}
|
|
877
|
-
function
|
|
877
|
+
function microfrontendInternalRoutingHandler({
|
|
878
878
|
config,
|
|
879
879
|
production
|
|
880
880
|
}) {
|
|
@@ -994,7 +994,7 @@ function getHandler({
|
|
|
994
994
|
}
|
|
995
995
|
};
|
|
996
996
|
}
|
|
997
|
-
function
|
|
997
|
+
function getMicrofrontendsMiddleware({
|
|
998
998
|
request,
|
|
999
999
|
flagValues
|
|
1000
1000
|
}) {
|
|
@@ -1005,14 +1005,14 @@ function getMicroFrontendsMiddleware({
|
|
|
1005
1005
|
}
|
|
1006
1006
|
});
|
|
1007
1007
|
const middlewares = [];
|
|
1008
|
-
if (microfrontends.config instanceof
|
|
1008
|
+
if (microfrontends.config instanceof MicrofrontendChildConfig) {
|
|
1009
1009
|
return middlewares;
|
|
1010
1010
|
}
|
|
1011
1011
|
const config = microfrontends.config;
|
|
1012
1012
|
const production = config.defaultApplication.production;
|
|
1013
1013
|
middlewares.push({
|
|
1014
1014
|
src: "/.well-known/vercel/microfrontend-routing",
|
|
1015
|
-
fn:
|
|
1015
|
+
fn: microfrontendInternalRoutingHandler({ config, production })
|
|
1016
1016
|
});
|
|
1017
1017
|
for (const application of config.getChildApplications()) {
|
|
1018
1018
|
if (application.name === process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {
|
|
@@ -1060,9 +1060,9 @@ function getMicroFrontendsMiddleware({
|
|
|
1060
1060
|
}
|
|
1061
1061
|
return middlewares;
|
|
1062
1062
|
}
|
|
1063
|
-
async function
|
|
1063
|
+
async function runMicrofrontendsMiddleware(request, flagValues) {
|
|
1064
1064
|
const pathname = request.nextUrl.pathname;
|
|
1065
|
-
const middlewares =
|
|
1065
|
+
const middlewares = getMicrofrontendsMiddleware({
|
|
1066
1066
|
request,
|
|
1067
1067
|
flagValues
|
|
1068
1068
|
});
|
|
@@ -1076,7 +1076,7 @@ async function runMicroFrontendsMiddleware(request, flagValues) {
|
|
|
1076
1076
|
}
|
|
1077
1077
|
}
|
|
1078
1078
|
export {
|
|
1079
|
-
|
|
1080
|
-
|
|
1079
|
+
getMicrofrontendsMiddleware,
|
|
1080
|
+
runMicrofrontendsMiddleware
|
|
1081
1081
|
};
|
|
1082
1082
|
//# sourceMappingURL=middleware.js.map
|