@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
package/dist/v2/next/config.js
CHANGED
|
@@ -40,14 +40,14 @@ function parseOverrides(cookies) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// src/config-v2/errors.ts
|
|
43
|
-
var
|
|
43
|
+
var MicrofrontendError = class extends Error {
|
|
44
44
|
constructor(message, opts) {
|
|
45
45
|
super(message);
|
|
46
|
-
this.name = "
|
|
47
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
46
|
+
this.name = "MicrofrontendsError";
|
|
47
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
48
48
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
49
49
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
50
|
-
Error.captureStackTrace(this,
|
|
50
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
51
51
|
}
|
|
52
52
|
isKnown() {
|
|
53
53
|
return this.type !== "unknown";
|
|
@@ -56,13 +56,13 @@ var MicroFrontendError = class extends Error {
|
|
|
56
56
|
return !this.isKnown();
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* Converts an error to a
|
|
59
|
+
* Converts an error to a MicrofrontendsError.
|
|
60
60
|
* @param original - The original error to convert.
|
|
61
|
-
* @returns The converted
|
|
61
|
+
* @returns The converted MicrofrontendsError.
|
|
62
62
|
*/
|
|
63
63
|
static convert(original, opts) {
|
|
64
64
|
if (opts == null ? void 0 : opts.fileName) {
|
|
65
|
-
const err =
|
|
65
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
66
66
|
if (err) {
|
|
67
67
|
return err;
|
|
68
68
|
}
|
|
@@ -70,25 +70,25 @@ var MicroFrontendError = class extends Error {
|
|
|
70
70
|
if (original.message.includes(
|
|
71
71
|
"Code generation from strings disallowed for this context"
|
|
72
72
|
)) {
|
|
73
|
-
return new
|
|
73
|
+
return new MicrofrontendError(original.message, {
|
|
74
74
|
type: "config",
|
|
75
75
|
subtype: "unsupported_validation_env",
|
|
76
76
|
source: "ajv"
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
return new
|
|
79
|
+
return new MicrofrontendError(original.message);
|
|
80
80
|
}
|
|
81
81
|
static convertFSError(original, fileName) {
|
|
82
82
|
if (original instanceof Error && "code" in original) {
|
|
83
83
|
if (original.code === "ENOENT") {
|
|
84
|
-
return new
|
|
84
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
85
85
|
type: "config",
|
|
86
86
|
subtype: "unable_to_read_file",
|
|
87
87
|
source: "fs"
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
if (original.code === "EACCES") {
|
|
91
|
-
return new
|
|
91
|
+
return new MicrofrontendError(
|
|
92
92
|
`Permission denied while accessing "${fileName}"`,
|
|
93
93
|
{
|
|
94
94
|
type: "config",
|
|
@@ -99,7 +99,7 @@ var MicroFrontendError = class extends Error {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
if (original instanceof SyntaxError) {
|
|
102
|
-
return new
|
|
102
|
+
return new MicrofrontendError(
|
|
103
103
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
104
104
|
{
|
|
105
105
|
type: "config",
|
|
@@ -111,23 +111,23 @@ var MicroFrontendError = class extends Error {
|
|
|
111
111
|
return null;
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
* Handles an unknown error and returns a
|
|
114
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
115
115
|
* @param err - The error to handle.
|
|
116
|
-
* @returns A
|
|
116
|
+
* @returns A MicrofrontendsError instance.
|
|
117
117
|
*/
|
|
118
118
|
static handle(err, opts) {
|
|
119
|
-
if (err instanceof
|
|
119
|
+
if (err instanceof MicrofrontendError) {
|
|
120
120
|
return err;
|
|
121
121
|
}
|
|
122
122
|
if (err instanceof Error) {
|
|
123
|
-
return
|
|
123
|
+
return MicrofrontendError.convert(err, opts);
|
|
124
124
|
}
|
|
125
125
|
if (typeof err === "object" && err !== null) {
|
|
126
126
|
if ("message" in err && typeof err.message === "string") {
|
|
127
|
-
return
|
|
127
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
return new
|
|
130
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
133
|
|
|
@@ -135,7 +135,7 @@ var MicroFrontendError = class extends Error {
|
|
|
135
135
|
function getConfigStringFromEnv() {
|
|
136
136
|
const config = process.env.MFE_CONFIG;
|
|
137
137
|
if (!config) {
|
|
138
|
-
throw new
|
|
138
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
139
139
|
type: "config",
|
|
140
140
|
subtype: "not_found_in_env"
|
|
141
141
|
});
|
|
@@ -158,7 +158,7 @@ function isDefaultApp(a) {
|
|
|
158
158
|
|
|
159
159
|
// src/config-v2/microfrontends-config/client/index.ts
|
|
160
160
|
import { pathToRegexp } from "path-to-regexp";
|
|
161
|
-
var
|
|
161
|
+
var MicrofrontendConfigClient = class {
|
|
162
162
|
constructor(config, opts) {
|
|
163
163
|
this.pathCache = {};
|
|
164
164
|
this.serialized = config;
|
|
@@ -172,14 +172,14 @@ var MicroFrontendConfigClient = class {
|
|
|
172
172
|
this.applications = config.applications;
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
|
-
* Create a new `
|
|
175
|
+
* Create a new `MicrofrontendConfigClient` from a JSON string.
|
|
176
176
|
* Config must be passed in to remain framework agnostic
|
|
177
177
|
*/
|
|
178
178
|
static fromEnv(config, opts) {
|
|
179
179
|
if (!config) {
|
|
180
|
-
throw new Error("No
|
|
180
|
+
throw new Error("No microfrontends configuration found");
|
|
181
181
|
}
|
|
182
|
-
return new
|
|
182
|
+
return new MicrofrontendConfigClient(
|
|
183
183
|
JSON.parse(config),
|
|
184
184
|
opts
|
|
185
185
|
);
|
|
@@ -227,7 +227,7 @@ import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to
|
|
|
227
227
|
var SUPPORTED_VERSIONS = ["2"];
|
|
228
228
|
var validateConfigVersion = (version) => {
|
|
229
229
|
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
230
|
-
throw new
|
|
230
|
+
throw new MicrofrontendError(
|
|
231
231
|
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
232
232
|
", "
|
|
233
233
|
)}`,
|
|
@@ -297,7 +297,7 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
297
297
|
);
|
|
298
298
|
});
|
|
299
299
|
if (errors.length) {
|
|
300
|
-
throw new
|
|
300
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
301
301
|
type: "config",
|
|
302
302
|
subtype: "conflicting_paths"
|
|
303
303
|
});
|
|
@@ -310,13 +310,13 @@ var validateAppPaths = (name, app) => {
|
|
|
310
310
|
continue;
|
|
311
311
|
}
|
|
312
312
|
if (p.endsWith("/")) {
|
|
313
|
-
throw new
|
|
313
|
+
throw new MicrofrontendError(
|
|
314
314
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
315
315
|
{ type: "application", subtype: "invalid_path" }
|
|
316
316
|
);
|
|
317
317
|
}
|
|
318
318
|
if (!p.startsWith("/")) {
|
|
319
|
-
throw new
|
|
319
|
+
throw new MicrofrontendError(
|
|
320
320
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
321
321
|
{ type: "application", subtype: "invalid_path" }
|
|
322
322
|
);
|
|
@@ -338,13 +338,13 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
338
338
|
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
339
339
|
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
340
340
|
if (numApplicationsWithoutRouting === 0) {
|
|
341
|
-
throw new
|
|
341
|
+
throw new MicrofrontendError(
|
|
342
342
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
343
343
|
{ type: "config", subtype: "no_default_application" }
|
|
344
344
|
);
|
|
345
345
|
}
|
|
346
346
|
if (numApplicationsWithoutRouting > 1) {
|
|
347
|
-
throw new
|
|
347
|
+
throw new MicrofrontendError(
|
|
348
348
|
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
349
349
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
350
350
|
);
|
|
@@ -356,7 +356,7 @@ var validateConfigOptions = (options) => {
|
|
|
356
356
|
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
357
357
|
options.vercel.previewDeploymentSuffix
|
|
358
358
|
)) {
|
|
359
|
-
throw new
|
|
359
|
+
throw new MicrofrontendError(
|
|
360
360
|
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
361
361
|
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
362
362
|
);
|
|
@@ -515,7 +515,7 @@ var ChildApplication = class extends Application {
|
|
|
515
515
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
516
516
|
|
|
517
517
|
// src/config-v2/microfrontends-config/isomorphic/index.ts
|
|
518
|
-
var
|
|
518
|
+
var MicrofrontendConfigIsomorphic = class {
|
|
519
519
|
constructor({
|
|
520
520
|
config,
|
|
521
521
|
overrides,
|
|
@@ -523,7 +523,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
523
523
|
}) {
|
|
524
524
|
this.childApplications = {};
|
|
525
525
|
var _a, _b, _c, _d;
|
|
526
|
-
|
|
526
|
+
MicrofrontendConfigIsomorphic.validate(config);
|
|
527
527
|
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
528
528
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
529
529
|
this.isMainConfig = isMainConfig(config);
|
|
@@ -555,7 +555,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
555
555
|
);
|
|
556
556
|
}
|
|
557
557
|
if (isMainConfig(config) && !this.defaultApplication) {
|
|
558
|
-
throw new
|
|
558
|
+
throw new MicrofrontendError(
|
|
559
559
|
`Could not find default application in microfrontends configuration`,
|
|
560
560
|
{
|
|
561
561
|
type: "application",
|
|
@@ -585,7 +585,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
585
585
|
meta,
|
|
586
586
|
cookies
|
|
587
587
|
}) {
|
|
588
|
-
return new
|
|
588
|
+
return new MicrofrontendConfigIsomorphic({
|
|
589
589
|
config: parse(getConfigStringFromEnv()),
|
|
590
590
|
overrides: parseOverrides(cookies ?? []),
|
|
591
591
|
meta
|
|
@@ -620,7 +620,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
620
620
|
}
|
|
621
621
|
const app = this.childApplications[name];
|
|
622
622
|
if (!app) {
|
|
623
|
-
throw new
|
|
623
|
+
throw new MicrofrontendError(
|
|
624
624
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
625
625
|
{
|
|
626
626
|
type: "application",
|
|
@@ -648,7 +648,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
648
648
|
*/
|
|
649
649
|
getDefaultApplication() {
|
|
650
650
|
if (!this.defaultApplication) {
|
|
651
|
-
throw new
|
|
651
|
+
throw new MicrofrontendError(
|
|
652
652
|
`Could not find default application in microfrontends configuration`,
|
|
653
653
|
{
|
|
654
654
|
type: "application",
|
|
@@ -688,7 +688,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
688
688
|
default: true
|
|
689
689
|
};
|
|
690
690
|
}
|
|
691
|
-
return new
|
|
691
|
+
return new MicrofrontendConfigClient({
|
|
692
692
|
applications
|
|
693
693
|
});
|
|
694
694
|
}
|
|
@@ -698,7 +698,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
698
698
|
};
|
|
699
699
|
|
|
700
700
|
// src/config-v2/microfrontends-config/isomorphic/child.ts
|
|
701
|
-
var
|
|
701
|
+
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
702
702
|
constructor({
|
|
703
703
|
config,
|
|
704
704
|
overrides,
|
|
@@ -711,7 +711,7 @@ var MicroFrontendChildConfig = class extends MicroFrontendConfigIsomorphic {
|
|
|
711
711
|
};
|
|
712
712
|
|
|
713
713
|
// src/config-v2/microfrontends-config/isomorphic/main.ts
|
|
714
|
-
var
|
|
714
|
+
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
715
715
|
constructor({
|
|
716
716
|
config,
|
|
717
717
|
overrides,
|
|
@@ -738,7 +738,7 @@ var MicroFrontendMainConfig = class extends MicroFrontendConfigIsomorphic {
|
|
|
738
738
|
}
|
|
739
739
|
}
|
|
740
740
|
if (!defaultApplication) {
|
|
741
|
-
throw new
|
|
741
|
+
throw new MicrofrontendError(
|
|
742
742
|
`Could not find default application in microfrontends configuration`,
|
|
743
743
|
{
|
|
744
744
|
type: "application",
|
|
@@ -758,19 +758,19 @@ var Microfrontends = class {
|
|
|
758
758
|
meta
|
|
759
759
|
}) {
|
|
760
760
|
if (isMainConfig(config)) {
|
|
761
|
-
this.config = new
|
|
761
|
+
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
762
762
|
} else {
|
|
763
|
-
this.config = new
|
|
763
|
+
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
764
764
|
}
|
|
765
765
|
}
|
|
766
766
|
isChildConfig() {
|
|
767
|
-
return this.config instanceof
|
|
767
|
+
return this.config instanceof MicrofrontendChildConfig;
|
|
768
768
|
}
|
|
769
769
|
static fromEnv({
|
|
770
770
|
cookies,
|
|
771
771
|
meta
|
|
772
772
|
}) {
|
|
773
|
-
const config =
|
|
773
|
+
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
774
774
|
cookies,
|
|
775
775
|
meta
|
|
776
776
|
});
|
|
@@ -807,14 +807,14 @@ import { parse as parse2 } from "jsonc-parser";
|
|
|
807
807
|
import { Ajv } from "ajv";
|
|
808
808
|
|
|
809
809
|
// src/config/errors.ts
|
|
810
|
-
var
|
|
810
|
+
var MicrofrontendError2 = class extends Error {
|
|
811
811
|
constructor(message, opts) {
|
|
812
812
|
super(message);
|
|
813
|
-
this.name = "
|
|
814
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
813
|
+
this.name = "MicrofrontendsError";
|
|
814
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
815
815
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
816
816
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
817
|
-
Error.captureStackTrace(this,
|
|
817
|
+
Error.captureStackTrace(this, MicrofrontendError2);
|
|
818
818
|
}
|
|
819
819
|
isKnown() {
|
|
820
820
|
return this.type !== "unknown";
|
|
@@ -823,13 +823,13 @@ var MicroFrontendError2 = class extends Error {
|
|
|
823
823
|
return !this.isKnown();
|
|
824
824
|
}
|
|
825
825
|
/**
|
|
826
|
-
* Converts an error to a
|
|
826
|
+
* Converts an error to a MicrofrontendsError.
|
|
827
827
|
* @param original - The original error to convert.
|
|
828
|
-
* @returns The converted
|
|
828
|
+
* @returns The converted MicrofrontendsError.
|
|
829
829
|
*/
|
|
830
830
|
static convert(original, opts) {
|
|
831
831
|
if (opts == null ? void 0 : opts.fileName) {
|
|
832
|
-
const err =
|
|
832
|
+
const err = MicrofrontendError2.convertFSError(original, opts.fileName);
|
|
833
833
|
if (err) {
|
|
834
834
|
return err;
|
|
835
835
|
}
|
|
@@ -837,25 +837,25 @@ var MicroFrontendError2 = class extends Error {
|
|
|
837
837
|
if (original.message.includes(
|
|
838
838
|
"Code generation from strings disallowed for this context"
|
|
839
839
|
)) {
|
|
840
|
-
return new
|
|
840
|
+
return new MicrofrontendError2(original.message, {
|
|
841
841
|
type: "config",
|
|
842
842
|
subtype: "unsupported_validation_env",
|
|
843
843
|
source: "ajv"
|
|
844
844
|
});
|
|
845
845
|
}
|
|
846
|
-
return new
|
|
846
|
+
return new MicrofrontendError2(original.message);
|
|
847
847
|
}
|
|
848
848
|
static convertFSError(original, fileName) {
|
|
849
849
|
if (original instanceof Error && "code" in original) {
|
|
850
850
|
if (original.code === "ENOENT") {
|
|
851
|
-
return new
|
|
851
|
+
return new MicrofrontendError2(`Could not find "${fileName}"`, {
|
|
852
852
|
type: "config",
|
|
853
853
|
subtype: "unable_to_read_file",
|
|
854
854
|
source: "fs"
|
|
855
855
|
});
|
|
856
856
|
}
|
|
857
857
|
if (original.code === "EACCES") {
|
|
858
|
-
return new
|
|
858
|
+
return new MicrofrontendError2(
|
|
859
859
|
`Permission denied while accessing "${fileName}"`,
|
|
860
860
|
{
|
|
861
861
|
type: "config",
|
|
@@ -866,7 +866,7 @@ var MicroFrontendError2 = class extends Error {
|
|
|
866
866
|
}
|
|
867
867
|
}
|
|
868
868
|
if (original instanceof SyntaxError) {
|
|
869
|
-
return new
|
|
869
|
+
return new MicrofrontendError2(
|
|
870
870
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
871
871
|
{
|
|
872
872
|
type: "config",
|
|
@@ -878,23 +878,23 @@ var MicroFrontendError2 = class extends Error {
|
|
|
878
878
|
return null;
|
|
879
879
|
}
|
|
880
880
|
/**
|
|
881
|
-
* Handles an unknown error and returns a
|
|
881
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
882
882
|
* @param err - The error to handle.
|
|
883
|
-
* @returns A
|
|
883
|
+
* @returns A MicrofrontendsError instance.
|
|
884
884
|
*/
|
|
885
885
|
static handle(err, opts) {
|
|
886
|
-
if (err instanceof
|
|
886
|
+
if (err instanceof MicrofrontendError2) {
|
|
887
887
|
return err;
|
|
888
888
|
}
|
|
889
889
|
if (err instanceof Error) {
|
|
890
|
-
return
|
|
890
|
+
return MicrofrontendError2.convert(err, opts);
|
|
891
891
|
}
|
|
892
892
|
if (typeof err === "object" && err !== null) {
|
|
893
893
|
if ("message" in err && typeof err.message === "string") {
|
|
894
|
-
return
|
|
894
|
+
return MicrofrontendError2.convert(new Error(err.message), opts);
|
|
895
895
|
}
|
|
896
896
|
}
|
|
897
|
-
return new
|
|
897
|
+
return new MicrofrontendError2("An unknown error occurred");
|
|
898
898
|
}
|
|
899
899
|
};
|
|
900
900
|
|
|
@@ -1172,7 +1172,7 @@ function validateSchema(configString) {
|
|
|
1172
1172
|
const validate = ajv.compile(SCHEMA);
|
|
1173
1173
|
const isValid = validate(parsedConfig);
|
|
1174
1174
|
if (!isValid) {
|
|
1175
|
-
throw new
|
|
1175
|
+
throw new MicrofrontendError2(
|
|
1176
1176
|
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
1177
1177
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
1178
1178
|
);
|
|
@@ -1223,7 +1223,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1223
1223
|
meta
|
|
1224
1224
|
});
|
|
1225
1225
|
}
|
|
1226
|
-
throw new
|
|
1226
|
+
throw new MicrofrontendError(
|
|
1227
1227
|
"Invalid config: must be a string or an object",
|
|
1228
1228
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
1229
1229
|
);
|
|
@@ -1268,7 +1268,44 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1268
1268
|
meta
|
|
1269
1269
|
});
|
|
1270
1270
|
} catch (e) {
|
|
1271
|
-
throw
|
|
1271
|
+
throw MicrofrontendError.handle(e, {
|
|
1272
|
+
fileName: filePath
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
/*
|
|
1277
|
+
* Generates a MicrofrontendMainConfig instance from a file.
|
|
1278
|
+
*/
|
|
1279
|
+
static fromMainConfigFile({
|
|
1280
|
+
filePath,
|
|
1281
|
+
overrides
|
|
1282
|
+
}) {
|
|
1283
|
+
try {
|
|
1284
|
+
const config = fs.readFileSync(filePath, "utf-8");
|
|
1285
|
+
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1286
|
+
if (!isMainConfig(validatedConfig)) {
|
|
1287
|
+
throw new MicrofrontendError(
|
|
1288
|
+
`${filePath} is not a main microfrontend config`,
|
|
1289
|
+
{
|
|
1290
|
+
type: "config",
|
|
1291
|
+
subtype: "invalid_main_path"
|
|
1292
|
+
}
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1296
|
+
if (!defaultApplication) {
|
|
1297
|
+
throw new MicrofrontendError(
|
|
1298
|
+
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
1299
|
+
{ type: "config", subtype: "no_default_application" }
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
return new MicrofrontendsServer({
|
|
1303
|
+
config: validatedConfig,
|
|
1304
|
+
overrides,
|
|
1305
|
+
meta: { fromApp: defaultApplication }
|
|
1306
|
+
});
|
|
1307
|
+
} catch (e) {
|
|
1308
|
+
throw MicrofrontendError.handle(e, {
|
|
1272
1309
|
fileName: filePath
|
|
1273
1310
|
});
|
|
1274
1311
|
}
|
|
@@ -1499,7 +1536,7 @@ function rewritesMapToArr(rewrites) {
|
|
|
1499
1536
|
});
|
|
1500
1537
|
}
|
|
1501
1538
|
function transform4(args) {
|
|
1502
|
-
const { next,
|
|
1539
|
+
const { next, microfrontend, app } = args;
|
|
1503
1540
|
const buildBeforeFiles = () => {
|
|
1504
1541
|
var _a;
|
|
1505
1542
|
const rewrites = /* @__PURE__ */ new Map();
|
|
@@ -1514,12 +1551,12 @@ function transform4(args) {
|
|
|
1514
1551
|
destination: { pathname: "/_vercel/:path*" }
|
|
1515
1552
|
});
|
|
1516
1553
|
}
|
|
1517
|
-
} else if (
|
|
1554
|
+
} else if (microfrontend instanceof MicrofrontendMainConfig) {
|
|
1518
1555
|
for (const [_, a] of Object.entries(
|
|
1519
|
-
|
|
1556
|
+
microfrontend.getChildApplications()
|
|
1520
1557
|
)) {
|
|
1521
1558
|
const { routing } = a;
|
|
1522
|
-
const domain = getDomainForCurrentEnvironment(
|
|
1559
|
+
const domain = getDomainForCurrentEnvironment(microfrontend, a.name);
|
|
1523
1560
|
rewrites.set(`/${a.getAssetPrefix()}/:path+`, {
|
|
1524
1561
|
destination: {
|
|
1525
1562
|
domain,
|
|
@@ -1582,8 +1619,8 @@ function transform4(args) {
|
|
|
1582
1619
|
var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
|
|
1583
1620
|
function transform5(args) {
|
|
1584
1621
|
var _a;
|
|
1585
|
-
const { next, app,
|
|
1586
|
-
if (
|
|
1622
|
+
const { next, app, microfrontend } = args;
|
|
1623
|
+
if (microfrontend instanceof MicrofrontendChildConfig) {
|
|
1587
1624
|
console.warn(
|
|
1588
1625
|
"server actions transform requires the full config - skipping"
|
|
1589
1626
|
);
|
|
@@ -1591,12 +1628,12 @@ function transform5(args) {
|
|
|
1591
1628
|
next
|
|
1592
1629
|
};
|
|
1593
1630
|
}
|
|
1594
|
-
const defaultApplication =
|
|
1631
|
+
const defaultApplication = microfrontend.getDefaultApplication();
|
|
1595
1632
|
const appsToAllow = [
|
|
1596
1633
|
// this zone - this is included by default unless allowedOrigins is overridden (which we are)
|
|
1597
1634
|
// so we re-add it here.
|
|
1598
1635
|
app,
|
|
1599
|
-
// this is the default zone for the
|
|
1636
|
+
// this is the default zone for the microfrontend. Allow child zones to call server actions
|
|
1600
1637
|
// that are in the default zone.
|
|
1601
1638
|
defaultApplication
|
|
1602
1639
|
];
|
|
@@ -1613,7 +1650,7 @@ function transform5(args) {
|
|
|
1613
1650
|
defaultApplication.production.toString()
|
|
1614
1651
|
),
|
|
1615
1652
|
formatDomainForServerAction(
|
|
1616
|
-
getDomainForCurrentEnvironment(
|
|
1653
|
+
getDomainForCurrentEnvironment(microfrontend, a.name)
|
|
1617
1654
|
)
|
|
1618
1655
|
])
|
|
1619
1656
|
])
|
|
@@ -1627,7 +1664,7 @@ function transform5(args) {
|
|
|
1627
1664
|
|
|
1628
1665
|
// src/next-v2/config/transforms/webpack.ts
|
|
1629
1666
|
function transform6(args) {
|
|
1630
|
-
const { next,
|
|
1667
|
+
const { next, microfrontend } = args;
|
|
1631
1668
|
const configWithWebpack = {
|
|
1632
1669
|
...next,
|
|
1633
1670
|
webpack(cfg, context) {
|
|
@@ -1636,7 +1673,7 @@ function transform6(args) {
|
|
|
1636
1673
|
if (isServer || nextRuntime === "edge") {
|
|
1637
1674
|
config.plugins.push(
|
|
1638
1675
|
new wpFromNext.EnvironmentPlugin({
|
|
1639
|
-
MFE_CONFIG: JSON.stringify(
|
|
1676
|
+
MFE_CONFIG: JSON.stringify(microfrontend.serialize())
|
|
1640
1677
|
})
|
|
1641
1678
|
);
|
|
1642
1679
|
}
|
|
@@ -1732,23 +1769,23 @@ function getApplicationContext(opts) {
|
|
|
1732
1769
|
const packageJsonString = fs2.readFileSync("./package.json", "utf-8");
|
|
1733
1770
|
const packageJson = JSON.parse(packageJsonString);
|
|
1734
1771
|
if (!packageJson.name) {
|
|
1735
|
-
throw new
|
|
1772
|
+
throw new MicrofrontendError(
|
|
1736
1773
|
`package.json file missing required field "name"`,
|
|
1737
1774
|
{
|
|
1738
1775
|
type: "packageJson",
|
|
1739
1776
|
subtype: "missing_field_name",
|
|
1740
|
-
source: "@vercel/
|
|
1777
|
+
source: "@vercel/microfrontends/next"
|
|
1741
1778
|
}
|
|
1742
1779
|
);
|
|
1743
1780
|
}
|
|
1744
1781
|
return { name: packageJson.name };
|
|
1745
1782
|
} catch (err) {
|
|
1746
|
-
throw
|
|
1783
|
+
throw MicrofrontendError.handle(err, {
|
|
1747
1784
|
fileName: "package.json"
|
|
1748
1785
|
});
|
|
1749
1786
|
}
|
|
1750
1787
|
}
|
|
1751
|
-
function
|
|
1788
|
+
function withMicrofrontends(nextConfig, opts) {
|
|
1752
1789
|
var _a;
|
|
1753
1790
|
if (opts == null ? void 0 : opts.debug) {
|
|
1754
1791
|
process.env.MFE_DEBUG = "true";
|
|
@@ -1772,7 +1809,7 @@ function withMicroFrontends(nextConfig, opts) {
|
|
|
1772
1809
|
const transformedConfig = transform7({
|
|
1773
1810
|
app,
|
|
1774
1811
|
next,
|
|
1775
|
-
|
|
1812
|
+
microfrontend: microfrontends.config,
|
|
1776
1813
|
opts: {
|
|
1777
1814
|
isProduction: isProduction(opts)
|
|
1778
1815
|
}
|
|
@@ -1789,6 +1826,6 @@ function withMicroFrontends(nextConfig, opts) {
|
|
|
1789
1826
|
return next;
|
|
1790
1827
|
}
|
|
1791
1828
|
export {
|
|
1792
|
-
|
|
1829
|
+
withMicrofrontends
|
|
1793
1830
|
};
|
|
1794
1831
|
//# sourceMappingURL=config.js.map
|