@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
|
@@ -37,14 +37,14 @@ function parseOverrides(cookies) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// src/config-v2/errors.ts
|
|
40
|
-
var
|
|
40
|
+
var MicrofrontendError = class extends Error {
|
|
41
41
|
constructor(message, opts) {
|
|
42
42
|
super(message);
|
|
43
|
-
this.name = "
|
|
44
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
43
|
+
this.name = "MicrofrontendsError";
|
|
44
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
45
45
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
46
46
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
47
|
-
Error.captureStackTrace(this,
|
|
47
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
48
48
|
}
|
|
49
49
|
isKnown() {
|
|
50
50
|
return this.type !== "unknown";
|
|
@@ -53,13 +53,13 @@ var MicroFrontendError = class extends Error {
|
|
|
53
53
|
return !this.isKnown();
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
* Converts an error to a
|
|
56
|
+
* Converts an error to a MicrofrontendsError.
|
|
57
57
|
* @param original - The original error to convert.
|
|
58
|
-
* @returns The converted
|
|
58
|
+
* @returns The converted MicrofrontendsError.
|
|
59
59
|
*/
|
|
60
60
|
static convert(original, opts) {
|
|
61
61
|
if (opts == null ? void 0 : opts.fileName) {
|
|
62
|
-
const err =
|
|
62
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
63
63
|
if (err) {
|
|
64
64
|
return err;
|
|
65
65
|
}
|
|
@@ -67,25 +67,25 @@ var MicroFrontendError = class extends Error {
|
|
|
67
67
|
if (original.message.includes(
|
|
68
68
|
"Code generation from strings disallowed for this context"
|
|
69
69
|
)) {
|
|
70
|
-
return new
|
|
70
|
+
return new MicrofrontendError(original.message, {
|
|
71
71
|
type: "config",
|
|
72
72
|
subtype: "unsupported_validation_env",
|
|
73
73
|
source: "ajv"
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
return new
|
|
76
|
+
return new MicrofrontendError(original.message);
|
|
77
77
|
}
|
|
78
78
|
static convertFSError(original, fileName) {
|
|
79
79
|
if (original instanceof Error && "code" in original) {
|
|
80
80
|
if (original.code === "ENOENT") {
|
|
81
|
-
return new
|
|
81
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
82
82
|
type: "config",
|
|
83
83
|
subtype: "unable_to_read_file",
|
|
84
84
|
source: "fs"
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
if (original.code === "EACCES") {
|
|
88
|
-
return new
|
|
88
|
+
return new MicrofrontendError(
|
|
89
89
|
`Permission denied while accessing "${fileName}"`,
|
|
90
90
|
{
|
|
91
91
|
type: "config",
|
|
@@ -96,7 +96,7 @@ var MicroFrontendError = class extends Error {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
if (original instanceof SyntaxError) {
|
|
99
|
-
return new
|
|
99
|
+
return new MicrofrontendError(
|
|
100
100
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
101
101
|
{
|
|
102
102
|
type: "config",
|
|
@@ -108,23 +108,23 @@ var MicroFrontendError = class extends Error {
|
|
|
108
108
|
return null;
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
|
-
* Handles an unknown error and returns a
|
|
111
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
112
112
|
* @param err - The error to handle.
|
|
113
|
-
* @returns A
|
|
113
|
+
* @returns A MicrofrontendsError instance.
|
|
114
114
|
*/
|
|
115
115
|
static handle(err, opts) {
|
|
116
|
-
if (err instanceof
|
|
116
|
+
if (err instanceof MicrofrontendError) {
|
|
117
117
|
return err;
|
|
118
118
|
}
|
|
119
119
|
if (err instanceof Error) {
|
|
120
|
-
return
|
|
120
|
+
return MicrofrontendError.convert(err, opts);
|
|
121
121
|
}
|
|
122
122
|
if (typeof err === "object" && err !== null) {
|
|
123
123
|
if ("message" in err && typeof err.message === "string") {
|
|
124
|
-
return
|
|
124
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
return new
|
|
127
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
|
|
@@ -132,7 +132,7 @@ var MicroFrontendError = class extends Error {
|
|
|
132
132
|
function getConfigStringFromEnv() {
|
|
133
133
|
const config = process.env.MFE_CONFIG;
|
|
134
134
|
if (!config) {
|
|
135
|
-
throw new
|
|
135
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
136
136
|
type: "config",
|
|
137
137
|
subtype: "not_found_in_env"
|
|
138
138
|
});
|
|
@@ -155,7 +155,7 @@ function isDefaultApp(a) {
|
|
|
155
155
|
|
|
156
156
|
// src/config-v2/microfrontends-config/client/index.ts
|
|
157
157
|
import { pathToRegexp } from "path-to-regexp";
|
|
158
|
-
var
|
|
158
|
+
var MicrofrontendConfigClient = class {
|
|
159
159
|
constructor(config, opts) {
|
|
160
160
|
this.pathCache = {};
|
|
161
161
|
this.serialized = config;
|
|
@@ -169,14 +169,14 @@ var MicroFrontendConfigClient = class {
|
|
|
169
169
|
this.applications = config.applications;
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
|
-
* Create a new `
|
|
172
|
+
* Create a new `MicrofrontendConfigClient` from a JSON string.
|
|
173
173
|
* Config must be passed in to remain framework agnostic
|
|
174
174
|
*/
|
|
175
175
|
static fromEnv(config, opts) {
|
|
176
176
|
if (!config) {
|
|
177
|
-
throw new Error("No
|
|
177
|
+
throw new Error("No microfrontends configuration found");
|
|
178
178
|
}
|
|
179
|
-
return new
|
|
179
|
+
return new MicrofrontendConfigClient(
|
|
180
180
|
JSON.parse(config),
|
|
181
181
|
opts
|
|
182
182
|
);
|
|
@@ -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
|
});
|
|
@@ -804,14 +804,14 @@ import { parse as parse2 } from "jsonc-parser";
|
|
|
804
804
|
import { Ajv } from "ajv";
|
|
805
805
|
|
|
806
806
|
// src/config/errors.ts
|
|
807
|
-
var
|
|
807
|
+
var MicrofrontendError2 = class extends Error {
|
|
808
808
|
constructor(message, opts) {
|
|
809
809
|
super(message);
|
|
810
|
-
this.name = "
|
|
811
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
810
|
+
this.name = "MicrofrontendsError";
|
|
811
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
812
812
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
813
813
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
814
|
-
Error.captureStackTrace(this,
|
|
814
|
+
Error.captureStackTrace(this, MicrofrontendError2);
|
|
815
815
|
}
|
|
816
816
|
isKnown() {
|
|
817
817
|
return this.type !== "unknown";
|
|
@@ -820,13 +820,13 @@ var MicroFrontendError2 = class extends Error {
|
|
|
820
820
|
return !this.isKnown();
|
|
821
821
|
}
|
|
822
822
|
/**
|
|
823
|
-
* Converts an error to a
|
|
823
|
+
* Converts an error to a MicrofrontendsError.
|
|
824
824
|
* @param original - The original error to convert.
|
|
825
|
-
* @returns The converted
|
|
825
|
+
* @returns The converted MicrofrontendsError.
|
|
826
826
|
*/
|
|
827
827
|
static convert(original, opts) {
|
|
828
828
|
if (opts == null ? void 0 : opts.fileName) {
|
|
829
|
-
const err =
|
|
829
|
+
const err = MicrofrontendError2.convertFSError(original, opts.fileName);
|
|
830
830
|
if (err) {
|
|
831
831
|
return err;
|
|
832
832
|
}
|
|
@@ -834,25 +834,25 @@ var MicroFrontendError2 = class extends Error {
|
|
|
834
834
|
if (original.message.includes(
|
|
835
835
|
"Code generation from strings disallowed for this context"
|
|
836
836
|
)) {
|
|
837
|
-
return new
|
|
837
|
+
return new MicrofrontendError2(original.message, {
|
|
838
838
|
type: "config",
|
|
839
839
|
subtype: "unsupported_validation_env",
|
|
840
840
|
source: "ajv"
|
|
841
841
|
});
|
|
842
842
|
}
|
|
843
|
-
return new
|
|
843
|
+
return new MicrofrontendError2(original.message);
|
|
844
844
|
}
|
|
845
845
|
static convertFSError(original, fileName) {
|
|
846
846
|
if (original instanceof Error && "code" in original) {
|
|
847
847
|
if (original.code === "ENOENT") {
|
|
848
|
-
return new
|
|
848
|
+
return new MicrofrontendError2(`Could not find "${fileName}"`, {
|
|
849
849
|
type: "config",
|
|
850
850
|
subtype: "unable_to_read_file",
|
|
851
851
|
source: "fs"
|
|
852
852
|
});
|
|
853
853
|
}
|
|
854
854
|
if (original.code === "EACCES") {
|
|
855
|
-
return new
|
|
855
|
+
return new MicrofrontendError2(
|
|
856
856
|
`Permission denied while accessing "${fileName}"`,
|
|
857
857
|
{
|
|
858
858
|
type: "config",
|
|
@@ -863,7 +863,7 @@ var MicroFrontendError2 = class extends Error {
|
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
865
|
if (original instanceof SyntaxError) {
|
|
866
|
-
return new
|
|
866
|
+
return new MicrofrontendError2(
|
|
867
867
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
868
868
|
{
|
|
869
869
|
type: "config",
|
|
@@ -875,23 +875,23 @@ var MicroFrontendError2 = class extends Error {
|
|
|
875
875
|
return null;
|
|
876
876
|
}
|
|
877
877
|
/**
|
|
878
|
-
* Handles an unknown error and returns a
|
|
878
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
879
879
|
* @param err - The error to handle.
|
|
880
|
-
* @returns A
|
|
880
|
+
* @returns A MicrofrontendsError instance.
|
|
881
881
|
*/
|
|
882
882
|
static handle(err, opts) {
|
|
883
|
-
if (err instanceof
|
|
883
|
+
if (err instanceof MicrofrontendError2) {
|
|
884
884
|
return err;
|
|
885
885
|
}
|
|
886
886
|
if (err instanceof Error) {
|
|
887
|
-
return
|
|
887
|
+
return MicrofrontendError2.convert(err, opts);
|
|
888
888
|
}
|
|
889
889
|
if (typeof err === "object" && err !== null) {
|
|
890
890
|
if ("message" in err && typeof err.message === "string") {
|
|
891
|
-
return
|
|
891
|
+
return MicrofrontendError2.convert(new Error(err.message), opts);
|
|
892
892
|
}
|
|
893
893
|
}
|
|
894
|
-
return new
|
|
894
|
+
return new MicrofrontendError2("An unknown error occurred");
|
|
895
895
|
}
|
|
896
896
|
};
|
|
897
897
|
|
|
@@ -1169,7 +1169,7 @@ function validateSchema(configString) {
|
|
|
1169
1169
|
const validate = ajv.compile(SCHEMA);
|
|
1170
1170
|
const isValid = validate(parsedConfig);
|
|
1171
1171
|
if (!isValid) {
|
|
1172
|
-
throw new
|
|
1172
|
+
throw new MicrofrontendError2(
|
|
1173
1173
|
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
1174
1174
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
1175
1175
|
);
|
|
@@ -1220,7 +1220,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1220
1220
|
meta
|
|
1221
1221
|
});
|
|
1222
1222
|
}
|
|
1223
|
-
throw new
|
|
1223
|
+
throw new MicrofrontendError(
|
|
1224
1224
|
"Invalid config: must be a string or an object",
|
|
1225
1225
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
1226
1226
|
);
|
|
@@ -1265,7 +1265,44 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1265
1265
|
meta
|
|
1266
1266
|
});
|
|
1267
1267
|
} catch (e) {
|
|
1268
|
-
throw
|
|
1268
|
+
throw MicrofrontendError.handle(e, {
|
|
1269
|
+
fileName: filePath
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
/*
|
|
1274
|
+
* Generates a MicrofrontendMainConfig instance from a file.
|
|
1275
|
+
*/
|
|
1276
|
+
static fromMainConfigFile({
|
|
1277
|
+
filePath,
|
|
1278
|
+
overrides
|
|
1279
|
+
}) {
|
|
1280
|
+
try {
|
|
1281
|
+
const config = fs.readFileSync(filePath, "utf-8");
|
|
1282
|
+
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1283
|
+
if (!isMainConfig(validatedConfig)) {
|
|
1284
|
+
throw new MicrofrontendError(
|
|
1285
|
+
`${filePath} is not a main microfrontend config`,
|
|
1286
|
+
{
|
|
1287
|
+
type: "config",
|
|
1288
|
+
subtype: "invalid_main_path"
|
|
1289
|
+
}
|
|
1290
|
+
);
|
|
1291
|
+
}
|
|
1292
|
+
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1293
|
+
if (!defaultApplication) {
|
|
1294
|
+
throw new MicrofrontendError(
|
|
1295
|
+
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
1296
|
+
{ type: "config", subtype: "no_default_application" }
|
|
1297
|
+
);
|
|
1298
|
+
}
|
|
1299
|
+
return new MicrofrontendsServer({
|
|
1300
|
+
config: validatedConfig,
|
|
1301
|
+
overrides,
|
|
1302
|
+
meta: { fromApp: defaultApplication }
|
|
1303
|
+
});
|
|
1304
|
+
} catch (e) {
|
|
1305
|
+
throw MicrofrontendError.handle(e, {
|
|
1269
1306
|
fileName: filePath
|
|
1270
1307
|
});
|
|
1271
1308
|
}
|