@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
|
@@ -71,14 +71,14 @@ function parseOverrides(cookies) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// src/config-v2/errors.ts
|
|
74
|
-
var
|
|
74
|
+
var MicrofrontendError = class extends Error {
|
|
75
75
|
constructor(message, opts) {
|
|
76
76
|
super(message);
|
|
77
|
-
this.name = "
|
|
78
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
77
|
+
this.name = "MicrofrontendsError";
|
|
78
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
79
79
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
80
80
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
81
|
-
Error.captureStackTrace(this,
|
|
81
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
82
82
|
}
|
|
83
83
|
isKnown() {
|
|
84
84
|
return this.type !== "unknown";
|
|
@@ -87,13 +87,13 @@ var MicroFrontendError = class extends Error {
|
|
|
87
87
|
return !this.isKnown();
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
|
-
* Converts an error to a
|
|
90
|
+
* Converts an error to a MicrofrontendsError.
|
|
91
91
|
* @param original - The original error to convert.
|
|
92
|
-
* @returns The converted
|
|
92
|
+
* @returns The converted MicrofrontendsError.
|
|
93
93
|
*/
|
|
94
94
|
static convert(original, opts) {
|
|
95
95
|
if (opts == null ? void 0 : opts.fileName) {
|
|
96
|
-
const err =
|
|
96
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
97
97
|
if (err) {
|
|
98
98
|
return err;
|
|
99
99
|
}
|
|
@@ -101,25 +101,25 @@ var MicroFrontendError = class extends Error {
|
|
|
101
101
|
if (original.message.includes(
|
|
102
102
|
"Code generation from strings disallowed for this context"
|
|
103
103
|
)) {
|
|
104
|
-
return new
|
|
104
|
+
return new MicrofrontendError(original.message, {
|
|
105
105
|
type: "config",
|
|
106
106
|
subtype: "unsupported_validation_env",
|
|
107
107
|
source: "ajv"
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
-
return new
|
|
110
|
+
return new MicrofrontendError(original.message);
|
|
111
111
|
}
|
|
112
112
|
static convertFSError(original, fileName) {
|
|
113
113
|
if (original instanceof Error && "code" in original) {
|
|
114
114
|
if (original.code === "ENOENT") {
|
|
115
|
-
return new
|
|
115
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
116
116
|
type: "config",
|
|
117
117
|
subtype: "unable_to_read_file",
|
|
118
118
|
source: "fs"
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
if (original.code === "EACCES") {
|
|
122
|
-
return new
|
|
122
|
+
return new MicrofrontendError(
|
|
123
123
|
`Permission denied while accessing "${fileName}"`,
|
|
124
124
|
{
|
|
125
125
|
type: "config",
|
|
@@ -130,7 +130,7 @@ var MicroFrontendError = class extends Error {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
if (original instanceof SyntaxError) {
|
|
133
|
-
return new
|
|
133
|
+
return new MicrofrontendError(
|
|
134
134
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
135
135
|
{
|
|
136
136
|
type: "config",
|
|
@@ -142,23 +142,23 @@ var MicroFrontendError = class extends Error {
|
|
|
142
142
|
return null;
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
|
-
* Handles an unknown error and returns a
|
|
145
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
146
146
|
* @param err - The error to handle.
|
|
147
|
-
* @returns A
|
|
147
|
+
* @returns A MicrofrontendsError instance.
|
|
148
148
|
*/
|
|
149
149
|
static handle(err, opts) {
|
|
150
|
-
if (err instanceof
|
|
150
|
+
if (err instanceof MicrofrontendError) {
|
|
151
151
|
return err;
|
|
152
152
|
}
|
|
153
153
|
if (err instanceof Error) {
|
|
154
|
-
return
|
|
154
|
+
return MicrofrontendError.convert(err, opts);
|
|
155
155
|
}
|
|
156
156
|
if (typeof err === "object" && err !== null) {
|
|
157
157
|
if ("message" in err && typeof err.message === "string") {
|
|
158
|
-
return
|
|
158
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
return new
|
|
161
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
164
|
|
|
@@ -166,7 +166,7 @@ var MicroFrontendError = class extends Error {
|
|
|
166
166
|
function getConfigStringFromEnv() {
|
|
167
167
|
const config = process.env.MFE_CONFIG;
|
|
168
168
|
if (!config) {
|
|
169
|
-
throw new
|
|
169
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
170
170
|
type: "config",
|
|
171
171
|
subtype: "not_found_in_env"
|
|
172
172
|
});
|
|
@@ -189,7 +189,7 @@ function isDefaultApp(a) {
|
|
|
189
189
|
|
|
190
190
|
// src/config-v2/microfrontends-config/client/index.ts
|
|
191
191
|
var import_path_to_regexp = require("path-to-regexp");
|
|
192
|
-
var
|
|
192
|
+
var MicrofrontendConfigClient = class {
|
|
193
193
|
constructor(config, opts) {
|
|
194
194
|
this.pathCache = {};
|
|
195
195
|
this.serialized = config;
|
|
@@ -203,14 +203,14 @@ var MicroFrontendConfigClient = class {
|
|
|
203
203
|
this.applications = config.applications;
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
|
-
* Create a new `
|
|
206
|
+
* Create a new `MicrofrontendConfigClient` from a JSON string.
|
|
207
207
|
* Config must be passed in to remain framework agnostic
|
|
208
208
|
*/
|
|
209
209
|
static fromEnv(config, opts) {
|
|
210
210
|
if (!config) {
|
|
211
|
-
throw new Error("No
|
|
211
|
+
throw new Error("No microfrontends configuration found");
|
|
212
212
|
}
|
|
213
|
-
return new
|
|
213
|
+
return new MicrofrontendConfigClient(
|
|
214
214
|
JSON.parse(config),
|
|
215
215
|
opts
|
|
216
216
|
);
|
|
@@ -258,7 +258,7 @@ var import_path_to_regexp2 = require("path-to-regexp");
|
|
|
258
258
|
var SUPPORTED_VERSIONS = ["2"];
|
|
259
259
|
var validateConfigVersion = (version) => {
|
|
260
260
|
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
261
|
-
throw new
|
|
261
|
+
throw new MicrofrontendError(
|
|
262
262
|
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
263
263
|
", "
|
|
264
264
|
)}`,
|
|
@@ -328,7 +328,7 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
328
328
|
);
|
|
329
329
|
});
|
|
330
330
|
if (errors.length) {
|
|
331
|
-
throw new
|
|
331
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
332
332
|
type: "config",
|
|
333
333
|
subtype: "conflicting_paths"
|
|
334
334
|
});
|
|
@@ -341,13 +341,13 @@ var validateAppPaths = (name, app) => {
|
|
|
341
341
|
continue;
|
|
342
342
|
}
|
|
343
343
|
if (p.endsWith("/")) {
|
|
344
|
-
throw new
|
|
344
|
+
throw new MicrofrontendError(
|
|
345
345
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
346
346
|
{ type: "application", subtype: "invalid_path" }
|
|
347
347
|
);
|
|
348
348
|
}
|
|
349
349
|
if (!p.startsWith("/")) {
|
|
350
|
-
throw new
|
|
350
|
+
throw new MicrofrontendError(
|
|
351
351
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
352
352
|
{ type: "application", subtype: "invalid_path" }
|
|
353
353
|
);
|
|
@@ -369,13 +369,13 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
369
369
|
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
370
370
|
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
371
371
|
if (numApplicationsWithoutRouting === 0) {
|
|
372
|
-
throw new
|
|
372
|
+
throw new MicrofrontendError(
|
|
373
373
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
374
374
|
{ type: "config", subtype: "no_default_application" }
|
|
375
375
|
);
|
|
376
376
|
}
|
|
377
377
|
if (numApplicationsWithoutRouting > 1) {
|
|
378
|
-
throw new
|
|
378
|
+
throw new MicrofrontendError(
|
|
379
379
|
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
380
380
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
381
381
|
);
|
|
@@ -387,7 +387,7 @@ var validateConfigOptions = (options) => {
|
|
|
387
387
|
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
388
388
|
options.vercel.previewDeploymentSuffix
|
|
389
389
|
)) {
|
|
390
|
-
throw new
|
|
390
|
+
throw new MicrofrontendError(
|
|
391
391
|
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
392
392
|
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
393
393
|
);
|
|
@@ -546,7 +546,7 @@ var ChildApplication = class extends Application {
|
|
|
546
546
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
547
547
|
|
|
548
548
|
// src/config-v2/microfrontends-config/isomorphic/index.ts
|
|
549
|
-
var
|
|
549
|
+
var MicrofrontendConfigIsomorphic = class {
|
|
550
550
|
constructor({
|
|
551
551
|
config,
|
|
552
552
|
overrides,
|
|
@@ -554,7 +554,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
554
554
|
}) {
|
|
555
555
|
this.childApplications = {};
|
|
556
556
|
var _a, _b, _c, _d;
|
|
557
|
-
|
|
557
|
+
MicrofrontendConfigIsomorphic.validate(config);
|
|
558
558
|
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
559
559
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
560
560
|
this.isMainConfig = isMainConfig(config);
|
|
@@ -586,7 +586,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
586
586
|
);
|
|
587
587
|
}
|
|
588
588
|
if (isMainConfig(config) && !this.defaultApplication) {
|
|
589
|
-
throw new
|
|
589
|
+
throw new MicrofrontendError(
|
|
590
590
|
`Could not find default application in microfrontends configuration`,
|
|
591
591
|
{
|
|
592
592
|
type: "application",
|
|
@@ -616,7 +616,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
616
616
|
meta,
|
|
617
617
|
cookies
|
|
618
618
|
}) {
|
|
619
|
-
return new
|
|
619
|
+
return new MicrofrontendConfigIsomorphic({
|
|
620
620
|
config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
|
|
621
621
|
overrides: parseOverrides(cookies ?? []),
|
|
622
622
|
meta
|
|
@@ -651,7 +651,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
651
651
|
}
|
|
652
652
|
const app = this.childApplications[name];
|
|
653
653
|
if (!app) {
|
|
654
|
-
throw new
|
|
654
|
+
throw new MicrofrontendError(
|
|
655
655
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
656
656
|
{
|
|
657
657
|
type: "application",
|
|
@@ -679,7 +679,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
679
679
|
*/
|
|
680
680
|
getDefaultApplication() {
|
|
681
681
|
if (!this.defaultApplication) {
|
|
682
|
-
throw new
|
|
682
|
+
throw new MicrofrontendError(
|
|
683
683
|
`Could not find default application in microfrontends configuration`,
|
|
684
684
|
{
|
|
685
685
|
type: "application",
|
|
@@ -719,7 +719,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
719
719
|
default: true
|
|
720
720
|
};
|
|
721
721
|
}
|
|
722
|
-
return new
|
|
722
|
+
return new MicrofrontendConfigClient({
|
|
723
723
|
applications
|
|
724
724
|
});
|
|
725
725
|
}
|
|
@@ -729,7 +729,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
729
729
|
};
|
|
730
730
|
|
|
731
731
|
// src/config-v2/microfrontends-config/isomorphic/child.ts
|
|
732
|
-
var
|
|
732
|
+
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
733
733
|
constructor({
|
|
734
734
|
config,
|
|
735
735
|
overrides,
|
|
@@ -742,7 +742,7 @@ var MicroFrontendChildConfig = class extends MicroFrontendConfigIsomorphic {
|
|
|
742
742
|
};
|
|
743
743
|
|
|
744
744
|
// src/config-v2/microfrontends-config/isomorphic/main.ts
|
|
745
|
-
var
|
|
745
|
+
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
746
746
|
constructor({
|
|
747
747
|
config,
|
|
748
748
|
overrides,
|
|
@@ -769,7 +769,7 @@ var MicroFrontendMainConfig = class extends MicroFrontendConfigIsomorphic {
|
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
771
|
if (!defaultApplication) {
|
|
772
|
-
throw new
|
|
772
|
+
throw new MicrofrontendError(
|
|
773
773
|
`Could not find default application in microfrontends configuration`,
|
|
774
774
|
{
|
|
775
775
|
type: "application",
|
|
@@ -789,19 +789,19 @@ var Microfrontends = class {
|
|
|
789
789
|
meta
|
|
790
790
|
}) {
|
|
791
791
|
if (isMainConfig(config)) {
|
|
792
|
-
this.config = new
|
|
792
|
+
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
793
793
|
} else {
|
|
794
|
-
this.config = new
|
|
794
|
+
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
795
795
|
}
|
|
796
796
|
}
|
|
797
797
|
isChildConfig() {
|
|
798
|
-
return this.config instanceof
|
|
798
|
+
return this.config instanceof MicrofrontendChildConfig;
|
|
799
799
|
}
|
|
800
800
|
static fromEnv({
|
|
801
801
|
cookies,
|
|
802
802
|
meta
|
|
803
803
|
}) {
|
|
804
|
-
const config =
|
|
804
|
+
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
805
805
|
cookies,
|
|
806
806
|
meta
|
|
807
807
|
});
|
|
@@ -838,14 +838,14 @@ var import_jsonc_parser2 = require("jsonc-parser");
|
|
|
838
838
|
var import_ajv = require("ajv");
|
|
839
839
|
|
|
840
840
|
// src/config/errors.ts
|
|
841
|
-
var
|
|
841
|
+
var MicrofrontendError2 = class extends Error {
|
|
842
842
|
constructor(message, opts) {
|
|
843
843
|
super(message);
|
|
844
|
-
this.name = "
|
|
845
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
844
|
+
this.name = "MicrofrontendsError";
|
|
845
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
846
846
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
847
847
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
848
|
-
Error.captureStackTrace(this,
|
|
848
|
+
Error.captureStackTrace(this, MicrofrontendError2);
|
|
849
849
|
}
|
|
850
850
|
isKnown() {
|
|
851
851
|
return this.type !== "unknown";
|
|
@@ -854,13 +854,13 @@ var MicroFrontendError2 = class extends Error {
|
|
|
854
854
|
return !this.isKnown();
|
|
855
855
|
}
|
|
856
856
|
/**
|
|
857
|
-
* Converts an error to a
|
|
857
|
+
* Converts an error to a MicrofrontendsError.
|
|
858
858
|
* @param original - The original error to convert.
|
|
859
|
-
* @returns The converted
|
|
859
|
+
* @returns The converted MicrofrontendsError.
|
|
860
860
|
*/
|
|
861
861
|
static convert(original, opts) {
|
|
862
862
|
if (opts == null ? void 0 : opts.fileName) {
|
|
863
|
-
const err =
|
|
863
|
+
const err = MicrofrontendError2.convertFSError(original, opts.fileName);
|
|
864
864
|
if (err) {
|
|
865
865
|
return err;
|
|
866
866
|
}
|
|
@@ -868,25 +868,25 @@ var MicroFrontendError2 = class extends Error {
|
|
|
868
868
|
if (original.message.includes(
|
|
869
869
|
"Code generation from strings disallowed for this context"
|
|
870
870
|
)) {
|
|
871
|
-
return new
|
|
871
|
+
return new MicrofrontendError2(original.message, {
|
|
872
872
|
type: "config",
|
|
873
873
|
subtype: "unsupported_validation_env",
|
|
874
874
|
source: "ajv"
|
|
875
875
|
});
|
|
876
876
|
}
|
|
877
|
-
return new
|
|
877
|
+
return new MicrofrontendError2(original.message);
|
|
878
878
|
}
|
|
879
879
|
static convertFSError(original, fileName) {
|
|
880
880
|
if (original instanceof Error && "code" in original) {
|
|
881
881
|
if (original.code === "ENOENT") {
|
|
882
|
-
return new
|
|
882
|
+
return new MicrofrontendError2(`Could not find "${fileName}"`, {
|
|
883
883
|
type: "config",
|
|
884
884
|
subtype: "unable_to_read_file",
|
|
885
885
|
source: "fs"
|
|
886
886
|
});
|
|
887
887
|
}
|
|
888
888
|
if (original.code === "EACCES") {
|
|
889
|
-
return new
|
|
889
|
+
return new MicrofrontendError2(
|
|
890
890
|
`Permission denied while accessing "${fileName}"`,
|
|
891
891
|
{
|
|
892
892
|
type: "config",
|
|
@@ -897,7 +897,7 @@ var MicroFrontendError2 = class extends Error {
|
|
|
897
897
|
}
|
|
898
898
|
}
|
|
899
899
|
if (original instanceof SyntaxError) {
|
|
900
|
-
return new
|
|
900
|
+
return new MicrofrontendError2(
|
|
901
901
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
902
902
|
{
|
|
903
903
|
type: "config",
|
|
@@ -909,23 +909,23 @@ var MicroFrontendError2 = class extends Error {
|
|
|
909
909
|
return null;
|
|
910
910
|
}
|
|
911
911
|
/**
|
|
912
|
-
* Handles an unknown error and returns a
|
|
912
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
913
913
|
* @param err - The error to handle.
|
|
914
|
-
* @returns A
|
|
914
|
+
* @returns A MicrofrontendsError instance.
|
|
915
915
|
*/
|
|
916
916
|
static handle(err, opts) {
|
|
917
|
-
if (err instanceof
|
|
917
|
+
if (err instanceof MicrofrontendError2) {
|
|
918
918
|
return err;
|
|
919
919
|
}
|
|
920
920
|
if (err instanceof Error) {
|
|
921
|
-
return
|
|
921
|
+
return MicrofrontendError2.convert(err, opts);
|
|
922
922
|
}
|
|
923
923
|
if (typeof err === "object" && err !== null) {
|
|
924
924
|
if ("message" in err && typeof err.message === "string") {
|
|
925
|
-
return
|
|
925
|
+
return MicrofrontendError2.convert(new Error(err.message), opts);
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
|
-
return new
|
|
928
|
+
return new MicrofrontendError2("An unknown error occurred");
|
|
929
929
|
}
|
|
930
930
|
};
|
|
931
931
|
|
|
@@ -1203,7 +1203,7 @@ function validateSchema(configString) {
|
|
|
1203
1203
|
const validate = ajv.compile(SCHEMA);
|
|
1204
1204
|
const isValid = validate(parsedConfig);
|
|
1205
1205
|
if (!isValid) {
|
|
1206
|
-
throw new
|
|
1206
|
+
throw new MicrofrontendError2(
|
|
1207
1207
|
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
1208
1208
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
1209
1209
|
);
|
|
@@ -1254,7 +1254,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1254
1254
|
meta
|
|
1255
1255
|
});
|
|
1256
1256
|
}
|
|
1257
|
-
throw new
|
|
1257
|
+
throw new MicrofrontendError(
|
|
1258
1258
|
"Invalid config: must be a string or an object",
|
|
1259
1259
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
1260
1260
|
);
|
|
@@ -1299,7 +1299,44 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1299
1299
|
meta
|
|
1300
1300
|
});
|
|
1301
1301
|
} catch (e) {
|
|
1302
|
-
throw
|
|
1302
|
+
throw MicrofrontendError.handle(e, {
|
|
1303
|
+
fileName: filePath
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
/*
|
|
1308
|
+
* Generates a MicrofrontendMainConfig instance from a file.
|
|
1309
|
+
*/
|
|
1310
|
+
static fromMainConfigFile({
|
|
1311
|
+
filePath,
|
|
1312
|
+
overrides
|
|
1313
|
+
}) {
|
|
1314
|
+
try {
|
|
1315
|
+
const config = import_node_fs.default.readFileSync(filePath, "utf-8");
|
|
1316
|
+
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1317
|
+
if (!isMainConfig(validatedConfig)) {
|
|
1318
|
+
throw new MicrofrontendError(
|
|
1319
|
+
`${filePath} is not a main microfrontend config`,
|
|
1320
|
+
{
|
|
1321
|
+
type: "config",
|
|
1322
|
+
subtype: "invalid_main_path"
|
|
1323
|
+
}
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1327
|
+
if (!defaultApplication) {
|
|
1328
|
+
throw new MicrofrontendError(
|
|
1329
|
+
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
1330
|
+
{ type: "config", subtype: "no_default_application" }
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1333
|
+
return new MicrofrontendsServer({
|
|
1334
|
+
config: validatedConfig,
|
|
1335
|
+
overrides,
|
|
1336
|
+
meta: { fromApp: defaultApplication }
|
|
1337
|
+
});
|
|
1338
|
+
} catch (e) {
|
|
1339
|
+
throw MicrofrontendError.handle(e, {
|
|
1303
1340
|
fileName: filePath
|
|
1304
1341
|
});
|
|
1305
1342
|
}
|