@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/next/testing.js
CHANGED
|
@@ -12,7 +12,7 @@ import { WebNextRequest } from "next/dist/server/base-http/web";
|
|
|
12
12
|
// src/config/types.ts
|
|
13
13
|
var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
|
|
14
14
|
|
|
15
|
-
// src/config/
|
|
15
|
+
// src/config/microfrontend-config.ts
|
|
16
16
|
import fs2 from "node:fs";
|
|
17
17
|
|
|
18
18
|
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
@@ -40,14 +40,14 @@ function getOutputFilePath() {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// src/config/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
|
|
|
@@ -210,27 +210,27 @@ var _Overrides = class {
|
|
|
210
210
|
});
|
|
211
211
|
return overridesConfig;
|
|
212
212
|
}
|
|
213
|
-
static validOverrideDomainsForZone(
|
|
213
|
+
static validOverrideDomainsForZone(microfrontendConfig, zone) {
|
|
214
214
|
var _a, _b, _c, _d, _e;
|
|
215
|
-
const projectName = (_a =
|
|
215
|
+
const projectName = (_a = microfrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
216
216
|
if (!projectName) {
|
|
217
|
-
return [
|
|
217
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
218
218
|
}
|
|
219
219
|
const parsedProjectName = makeUrlSafe(projectName);
|
|
220
|
-
const previewDeploymentSuffix = (_c = (_b =
|
|
221
|
-
const teamSlug = (_e = (_d =
|
|
220
|
+
const previewDeploymentSuffix = (_c = (_b = microfrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
|
|
221
|
+
const teamSlug = (_e = (_d = microfrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
|
|
222
222
|
if (!teamSlug && !previewDeploymentSuffix) {
|
|
223
|
-
return [
|
|
223
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
224
224
|
}
|
|
225
225
|
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
226
226
|
return [
|
|
227
227
|
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
228
|
-
|
|
228
|
+
microfrontendConfig.getZone(zone).production.host
|
|
229
229
|
];
|
|
230
230
|
}
|
|
231
|
-
static validateOverrideDomain(
|
|
231
|
+
static validateOverrideDomain(microfrontendConfig, zone, domain) {
|
|
232
232
|
return new RegExp(
|
|
233
|
-
`^${_Overrides.validOverrideDomainsForZone(
|
|
233
|
+
`^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
|
|
234
234
|
"|"
|
|
235
235
|
)}$`
|
|
236
236
|
).test(domain);
|
|
@@ -312,7 +312,7 @@ var Application = class {
|
|
|
312
312
|
static validate(name, app) {
|
|
313
313
|
var _a, _b, _c, _d, _e;
|
|
314
314
|
if (((_b = (_a = app.routing) == null ? void 0 : _a.assetPrefix) == null ? void 0 : _b.startsWith("/")) || ((_d = (_c = app.routing) == null ? void 0 : _c.assetPrefix) == null ? void 0 : _d.endsWith("/"))) {
|
|
315
|
-
throw new
|
|
315
|
+
throw new MicrofrontendError(
|
|
316
316
|
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
317
317
|
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
318
318
|
);
|
|
@@ -323,13 +323,13 @@ var Application = class {
|
|
|
323
323
|
continue;
|
|
324
324
|
}
|
|
325
325
|
if (p.endsWith("/")) {
|
|
326
|
-
throw new
|
|
326
|
+
throw new MicrofrontendError(
|
|
327
327
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
328
328
|
{ type: "zone", subtype: "invalid_path" }
|
|
329
329
|
);
|
|
330
330
|
}
|
|
331
331
|
if (!p.startsWith("/")) {
|
|
332
|
-
throw new
|
|
332
|
+
throw new MicrofrontendError(
|
|
333
333
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
334
334
|
{ type: "zone", subtype: "invalid_path" }
|
|
335
335
|
);
|
|
@@ -363,10 +363,10 @@ var Application = class {
|
|
|
363
363
|
}
|
|
364
364
|
};
|
|
365
365
|
|
|
366
|
-
// src/config/common/
|
|
366
|
+
// src/config/common/microfrontend-config.ts
|
|
367
367
|
var SUPPORTED_VERSIONS = ["1"];
|
|
368
368
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
369
|
-
var
|
|
369
|
+
var MicrofrontendConfigCommon = class {
|
|
370
370
|
constructor({
|
|
371
371
|
config,
|
|
372
372
|
overrides
|
|
@@ -374,7 +374,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
374
374
|
this.zones = {};
|
|
375
375
|
var _a, _b, _c;
|
|
376
376
|
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
377
|
-
throw new
|
|
377
|
+
throw new MicrofrontendError(
|
|
378
378
|
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
379
379
|
", "
|
|
380
380
|
)}`,
|
|
@@ -402,7 +402,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
402
402
|
static getConfigFromEnv() {
|
|
403
403
|
const config = process.env.MFE_CONFIG;
|
|
404
404
|
if (!config) {
|
|
405
|
-
throw new
|
|
405
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
406
406
|
type: "config",
|
|
407
407
|
subtype: "not_found_in_env"
|
|
408
408
|
});
|
|
@@ -421,8 +421,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
421
421
|
getZone(name) {
|
|
422
422
|
const zone = this.zones[name];
|
|
423
423
|
if (!zone) {
|
|
424
|
-
throw new
|
|
425
|
-
`Could not find
|
|
424
|
+
throw new MicrofrontendError(
|
|
425
|
+
`Could not find microfrontends configuration for application "${name}"`,
|
|
426
426
|
{
|
|
427
427
|
type: "zone",
|
|
428
428
|
subtype: "not_found"
|
|
@@ -442,8 +442,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
442
442
|
getDefaultZone() {
|
|
443
443
|
const zone = Object.values(this.zones).find((z) => z.default);
|
|
444
444
|
if (!zone) {
|
|
445
|
-
throw new
|
|
446
|
-
`Could not find default zone in
|
|
445
|
+
throw new MicrofrontendError(
|
|
446
|
+
`Could not find default zone in microfrontends configuration`,
|
|
447
447
|
{
|
|
448
448
|
type: "zone",
|
|
449
449
|
subtype: "not_found"
|
|
@@ -495,8 +495,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
495
495
|
};
|
|
496
496
|
}
|
|
497
497
|
write(_) {
|
|
498
|
-
throw new
|
|
499
|
-
`Writing to file to disk requires using an instance of "
|
|
498
|
+
throw new MicrofrontendError(
|
|
499
|
+
`Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
|
|
500
500
|
{ type: "config", subtype: "unsupported_operation" }
|
|
501
501
|
);
|
|
502
502
|
}
|
|
@@ -857,7 +857,7 @@ var validateSchema = (configString) => {
|
|
|
857
857
|
const validate = ajv.compile(SCHEMA);
|
|
858
858
|
const isValid = validate(parsedConfig);
|
|
859
859
|
if (!isValid) {
|
|
860
|
-
throw new
|
|
860
|
+
throw new MicrofrontendError(
|
|
861
861
|
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
862
862
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
863
863
|
);
|
|
@@ -867,7 +867,7 @@ var validateSchema = (configString) => {
|
|
|
867
867
|
var SUPPORTED_VERSIONS2 = ["1"];
|
|
868
868
|
var validateVersion = (version) => {
|
|
869
869
|
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
870
|
-
throw new
|
|
870
|
+
throw new MicrofrontendError(
|
|
871
871
|
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
872
872
|
", "
|
|
873
873
|
)}`,
|
|
@@ -900,7 +900,7 @@ function validateMainPath(applicationConfigsById) {
|
|
|
900
900
|
return !matcher.test(defaultRoute);
|
|
901
901
|
});
|
|
902
902
|
if (!isValid) {
|
|
903
|
-
throw new
|
|
903
|
+
throw new MicrofrontendError(
|
|
904
904
|
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
905
905
|
{ type: "config", subtype: "invalid_main_path" }
|
|
906
906
|
);
|
|
@@ -913,7 +913,7 @@ function validateMainPath(applicationConfigsById) {
|
|
|
913
913
|
return matcher.test(defaultRoute);
|
|
914
914
|
});
|
|
915
915
|
if (!isValid) {
|
|
916
|
-
throw new
|
|
916
|
+
throw new MicrofrontendError(
|
|
917
917
|
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
918
918
|
{ type: "config", subtype: "invalid_main_path" }
|
|
919
919
|
);
|
|
@@ -976,7 +976,7 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
976
976
|
);
|
|
977
977
|
});
|
|
978
978
|
if (errors.length) {
|
|
979
|
-
throw new
|
|
979
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
980
980
|
type: "config",
|
|
981
981
|
subtype: "conflicting_paths"
|
|
982
982
|
});
|
|
@@ -1010,13 +1010,13 @@ function validatePathExpression(path3) {
|
|
|
1010
1010
|
var validateDefaults = (applicationConfigsById) => {
|
|
1011
1011
|
const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
|
|
1012
1012
|
if (defaultApplicationIds.length === 0) {
|
|
1013
|
-
throw new
|
|
1013
|
+
throw new MicrofrontendError(
|
|
1014
1014
|
`No default application found. At least one application must be marked as default.`,
|
|
1015
1015
|
{ type: "config", subtype: "no_default_application" }
|
|
1016
1016
|
);
|
|
1017
1017
|
}
|
|
1018
1018
|
if (defaultApplicationIds.length > 1) {
|
|
1019
|
-
throw new
|
|
1019
|
+
throw new MicrofrontendError(
|
|
1020
1020
|
`Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
|
|
1021
1021
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
1022
1022
|
);
|
|
@@ -1028,7 +1028,7 @@ var validateOptions = (options) => {
|
|
|
1028
1028
|
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1029
1029
|
options.vercel.previewDeploymentSuffix
|
|
1030
1030
|
)) {
|
|
1031
|
-
throw new
|
|
1031
|
+
throw new MicrofrontendError(
|
|
1032
1032
|
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1033
1033
|
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1034
1034
|
);
|
|
@@ -1083,9 +1083,15 @@ function convertV1ConfigToV2Config(config, fromApp) {
|
|
|
1083
1083
|
)
|
|
1084
1084
|
};
|
|
1085
1085
|
}
|
|
1086
|
+
const defaultApplication = Object.entries(config.applications).find(
|
|
1087
|
+
([, application]) => application.default
|
|
1088
|
+
);
|
|
1089
|
+
if (!defaultApplication) {
|
|
1090
|
+
throw new Error("No default application found in the config");
|
|
1091
|
+
}
|
|
1086
1092
|
return {
|
|
1087
1093
|
...common,
|
|
1088
|
-
partOf:
|
|
1094
|
+
partOf: defaultApplication[0]
|
|
1089
1095
|
};
|
|
1090
1096
|
}
|
|
1091
1097
|
|
|
@@ -1100,8 +1106,8 @@ function writeFile(outputPath, config, prettify) {
|
|
|
1100
1106
|
);
|
|
1101
1107
|
}
|
|
1102
1108
|
|
|
1103
|
-
// src/config/
|
|
1104
|
-
var
|
|
1109
|
+
// src/config/microfrontend-config.ts
|
|
1110
|
+
var MicrofrontendConfig = class extends MicrofrontendConfigCommon {
|
|
1105
1111
|
static validate(configString) {
|
|
1106
1112
|
const config = validateSchema(configString);
|
|
1107
1113
|
validateVersion(config.version);
|
|
@@ -1114,9 +1120,9 @@ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
|
|
|
1114
1120
|
static fromEnv({
|
|
1115
1121
|
cookies
|
|
1116
1122
|
}) {
|
|
1117
|
-
return new
|
|
1118
|
-
config:
|
|
1119
|
-
|
|
1123
|
+
return new MicrofrontendConfigCommon({
|
|
1124
|
+
config: MicrofrontendConfig.validate(
|
|
1125
|
+
MicrofrontendConfigCommon.getConfigFromEnv()
|
|
1120
1126
|
),
|
|
1121
1127
|
overrides: Overrides.parseOverrides(cookies)
|
|
1122
1128
|
});
|
|
@@ -1126,11 +1132,11 @@ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
|
|
|
1126
1132
|
}) {
|
|
1127
1133
|
try {
|
|
1128
1134
|
const config = fs2.readFileSync(filePath, "utf-8");
|
|
1129
|
-
return new
|
|
1130
|
-
config:
|
|
1135
|
+
return new MicrofrontendConfig({
|
|
1136
|
+
config: MicrofrontendConfig.validate(config)
|
|
1131
1137
|
});
|
|
1132
1138
|
} catch (e) {
|
|
1133
|
-
throw
|
|
1139
|
+
throw MicrofrontendError.handle(e, {
|
|
1134
1140
|
fileName: filePath
|
|
1135
1141
|
});
|
|
1136
1142
|
}
|
|
@@ -1175,7 +1181,7 @@ function expandWildcards(path3) {
|
|
|
1175
1181
|
}
|
|
1176
1182
|
function loadMicrofrontendConfigForEdge(path3) {
|
|
1177
1183
|
const rawMfConfig = parse2(readFileSync(path3, "utf-8"));
|
|
1178
|
-
return new
|
|
1184
|
+
return new MicrofrontendConfig({ config: rawMfConfig });
|
|
1179
1185
|
}
|
|
1180
1186
|
function getAllZoneNames(mfConfig) {
|
|
1181
1187
|
return mfConfig.getAllApplications().filter((app) => !app.default).map((app) => app.name);
|
|
@@ -1237,12 +1243,12 @@ function urlMatches(middlewareConfig, path3, host) {
|
|
|
1237
1243
|
}
|
|
1238
1244
|
return false;
|
|
1239
1245
|
}
|
|
1240
|
-
function validateMiddlewareConfig(middlewareConfig,
|
|
1246
|
+
function validateMiddlewareConfig(middlewareConfig, microfrontendConfigOrPath, extraProductionMatches) {
|
|
1241
1247
|
var _a, _b;
|
|
1242
|
-
const
|
|
1248
|
+
const microfrontendConfig = typeof microfrontendConfigOrPath === "string" ? loadMicrofrontendConfigForEdge(microfrontendConfigOrPath) : microfrontendConfigOrPath;
|
|
1243
1249
|
const errors = [];
|
|
1244
1250
|
const usedExtraProductionMatches = /* @__PURE__ */ new Set();
|
|
1245
|
-
for (const application of
|
|
1251
|
+
for (const application of microfrontendConfig.getAllApplications()) {
|
|
1246
1252
|
if ((_a = application.routing) == null ? void 0 : _a.matches) {
|
|
1247
1253
|
const matches = [...application.routing.matches];
|
|
1248
1254
|
if (application.routing.assetPrefix) {
|
|
@@ -1259,14 +1265,14 @@ function validateMiddlewareConfig(middlewareConfig, microFrontendConfigOrPath, e
|
|
|
1259
1265
|
if (!urlMatches(middlewareConfig, testPath, "test.nonproduction.host")) {
|
|
1260
1266
|
errors.push(
|
|
1261
1267
|
`Matcher misconfigured for ${pathForDisplay}. This path should have matched the middleware config on a non-production host, but did not. Microfrontends require a middleware config matcher that matches on this host everywhere but in production. That can be configured with a configuration like this:
|
|
1262
|
-
${getSampleMatcher(path3,
|
|
1268
|
+
${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}`
|
|
1263
1269
|
);
|
|
1264
1270
|
break;
|
|
1265
1271
|
}
|
|
1266
1272
|
const productionUrlMatches = urlMatches(
|
|
1267
1273
|
middlewareConfig,
|
|
1268
1274
|
testPath,
|
|
1269
|
-
|
|
1275
|
+
microfrontendConfig.getDefaultZone().production.host
|
|
1270
1276
|
);
|
|
1271
1277
|
if (isFlagged) {
|
|
1272
1278
|
if (!productionUrlMatches) {
|
|
@@ -1281,7 +1287,7 @@ ${getSampleMatcher(path3, microFrontendConfig.getDefaultZone().production.host)}
|
|
|
1281
1287
|
} else {
|
|
1282
1288
|
errors.push(
|
|
1283
1289
|
`Matcher misconfigured for ${pathForDisplay}. This path matched the middleware config on a production host, but should not have. Microfrontends require a middleware config matcher that matches on this host everywhere but in production. If this is desired, you can add the path the to extraProductionMatches parameter. Otherwise, you can set up a configuration like this:
|
|
1284
|
-
${getSampleMatcher(path3,
|
|
1290
|
+
${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}`
|
|
1285
1291
|
);
|
|
1286
1292
|
}
|
|
1287
1293
|
break;
|
|
@@ -1300,7 +1306,7 @@ ${getSampleMatcher(path3, microFrontendConfig.getDefaultZone().production.host)}
|
|
|
1300
1306
|
);
|
|
1301
1307
|
}
|
|
1302
1308
|
if (errors.length > 0) {
|
|
1303
|
-
const message = `Found the following inconsistencies between your microfrontend config ${typeof
|
|
1309
|
+
const message = `Found the following inconsistencies between your microfrontend config ${typeof microfrontendConfigOrPath === "string" ? `(at ${microfrontendConfigOrPath}) ` : ""}and middleware config:
|
|
1304
1310
|
|
|
1305
1311
|
- `;
|
|
1306
1312
|
throw new Error(message + errors.join("\n\n- "));
|
|
@@ -1316,26 +1322,26 @@ function getSampleMatcher(path3, host) {
|
|
|
1316
1322
|
],
|
|
1317
1323
|
}`;
|
|
1318
1324
|
}
|
|
1319
|
-
async function validateMiddlewareOnFlaggedPaths(
|
|
1325
|
+
async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middleware) {
|
|
1320
1326
|
const initialEnv = process.env.VERCEL_ENV;
|
|
1321
1327
|
const initialMfePreviewDomains = process.env.MFE_PREVIEW_DOMAINS;
|
|
1322
1328
|
try {
|
|
1323
|
-
const
|
|
1324
|
-
const fakePreviewDomains = createFakePreviewDomains(
|
|
1329
|
+
const microfrontendConfig = typeof microfrontendConfigOrPath === "string" ? loadMicrofrontendConfigForEdge(microfrontendConfigOrPath) : microfrontendConfigOrPath;
|
|
1330
|
+
const fakePreviewDomains = createFakePreviewDomains(microfrontendConfig);
|
|
1325
1331
|
process.env.MFE_PREVIEW_DOMAINS = JSON.stringify(fakePreviewDomains);
|
|
1326
|
-
const allZoneNames = getAllZoneNames(
|
|
1332
|
+
const allZoneNames = getAllZoneNames(microfrontendConfig);
|
|
1327
1333
|
const errors = [];
|
|
1328
1334
|
for (const zoneName of allZoneNames) {
|
|
1329
1335
|
const flaggedPaths = getFlaggedPathsForZone(
|
|
1330
|
-
|
|
1336
|
+
microfrontendConfig,
|
|
1331
1337
|
zoneName
|
|
1332
1338
|
);
|
|
1333
1339
|
if (flaggedPaths.length) {
|
|
1334
1340
|
for (const env of ["preview", "production"]) {
|
|
1335
1341
|
process.env.VERCEL_ENV = env;
|
|
1336
1342
|
for (const path3 of flaggedPaths) {
|
|
1337
|
-
const expectedHost = env === "preview" ? fakePreviewDomains[zoneName] : getExpectedDomainForZone(
|
|
1338
|
-
const requestPath = `https://${
|
|
1343
|
+
const expectedHost = env === "preview" ? fakePreviewDomains[zoneName] : getExpectedDomainForZone(microfrontendConfig, zoneName, env);
|
|
1344
|
+
const requestPath = `https://${microfrontendConfig.getDefaultZone().production.host}${path3}`;
|
|
1339
1345
|
const request = new NextRequest(requestPath, {
|
|
1340
1346
|
headers: { "x-vercel-skip-deployment-existence-check": "1" }
|
|
1341
1347
|
});
|