@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.cjs
CHANGED
|
@@ -52,7 +52,7 @@ var import_web = require("next/dist/server/base-http/web");
|
|
|
52
52
|
// src/config/types.ts
|
|
53
53
|
var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
|
|
54
54
|
|
|
55
|
-
// src/config/
|
|
55
|
+
// src/config/microfrontend-config.ts
|
|
56
56
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
57
57
|
|
|
58
58
|
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
@@ -80,14 +80,14 @@ function getOutputFilePath() {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// src/config/errors.ts
|
|
83
|
-
var
|
|
83
|
+
var MicrofrontendError = class extends Error {
|
|
84
84
|
constructor(message, opts) {
|
|
85
85
|
super(message);
|
|
86
|
-
this.name = "
|
|
87
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
86
|
+
this.name = "MicrofrontendsError";
|
|
87
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
88
88
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
89
89
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
90
|
-
Error.captureStackTrace(this,
|
|
90
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
91
91
|
}
|
|
92
92
|
isKnown() {
|
|
93
93
|
return this.type !== "unknown";
|
|
@@ -96,13 +96,13 @@ var MicroFrontendError = class extends Error {
|
|
|
96
96
|
return !this.isKnown();
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
|
-
* Converts an error to a
|
|
99
|
+
* Converts an error to a MicrofrontendsError.
|
|
100
100
|
* @param original - The original error to convert.
|
|
101
|
-
* @returns The converted
|
|
101
|
+
* @returns The converted MicrofrontendsError.
|
|
102
102
|
*/
|
|
103
103
|
static convert(original, opts) {
|
|
104
104
|
if (opts == null ? void 0 : opts.fileName) {
|
|
105
|
-
const err =
|
|
105
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
106
106
|
if (err) {
|
|
107
107
|
return err;
|
|
108
108
|
}
|
|
@@ -110,25 +110,25 @@ var MicroFrontendError = class extends Error {
|
|
|
110
110
|
if (original.message.includes(
|
|
111
111
|
"Code generation from strings disallowed for this context"
|
|
112
112
|
)) {
|
|
113
|
-
return new
|
|
113
|
+
return new MicrofrontendError(original.message, {
|
|
114
114
|
type: "config",
|
|
115
115
|
subtype: "unsupported_validation_env",
|
|
116
116
|
source: "ajv"
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
-
return new
|
|
119
|
+
return new MicrofrontendError(original.message);
|
|
120
120
|
}
|
|
121
121
|
static convertFSError(original, fileName) {
|
|
122
122
|
if (original instanceof Error && "code" in original) {
|
|
123
123
|
if (original.code === "ENOENT") {
|
|
124
|
-
return new
|
|
124
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
125
125
|
type: "config",
|
|
126
126
|
subtype: "unable_to_read_file",
|
|
127
127
|
source: "fs"
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
if (original.code === "EACCES") {
|
|
131
|
-
return new
|
|
131
|
+
return new MicrofrontendError(
|
|
132
132
|
`Permission denied while accessing "${fileName}"`,
|
|
133
133
|
{
|
|
134
134
|
type: "config",
|
|
@@ -139,7 +139,7 @@ var MicroFrontendError = class extends Error {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
if (original instanceof SyntaxError) {
|
|
142
|
-
return new
|
|
142
|
+
return new MicrofrontendError(
|
|
143
143
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
144
144
|
{
|
|
145
145
|
type: "config",
|
|
@@ -151,23 +151,23 @@ var MicroFrontendError = class extends Error {
|
|
|
151
151
|
return null;
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
|
-
* Handles an unknown error and returns a
|
|
154
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
155
155
|
* @param err - The error to handle.
|
|
156
|
-
* @returns A
|
|
156
|
+
* @returns A MicrofrontendsError instance.
|
|
157
157
|
*/
|
|
158
158
|
static handle(err, opts) {
|
|
159
|
-
if (err instanceof
|
|
159
|
+
if (err instanceof MicrofrontendError) {
|
|
160
160
|
return err;
|
|
161
161
|
}
|
|
162
162
|
if (err instanceof Error) {
|
|
163
|
-
return
|
|
163
|
+
return MicrofrontendError.convert(err, opts);
|
|
164
164
|
}
|
|
165
165
|
if (typeof err === "object" && err !== null) {
|
|
166
166
|
if ("message" in err && typeof err.message === "string") {
|
|
167
|
-
return
|
|
167
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
-
return new
|
|
170
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
171
171
|
}
|
|
172
172
|
};
|
|
173
173
|
|
|
@@ -250,27 +250,27 @@ var _Overrides = class {
|
|
|
250
250
|
});
|
|
251
251
|
return overridesConfig;
|
|
252
252
|
}
|
|
253
|
-
static validOverrideDomainsForZone(
|
|
253
|
+
static validOverrideDomainsForZone(microfrontendConfig, zone) {
|
|
254
254
|
var _a, _b, _c, _d, _e;
|
|
255
|
-
const projectName = (_a =
|
|
255
|
+
const projectName = (_a = microfrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
256
256
|
if (!projectName) {
|
|
257
|
-
return [
|
|
257
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
258
258
|
}
|
|
259
259
|
const parsedProjectName = makeUrlSafe(projectName);
|
|
260
|
-
const previewDeploymentSuffix = (_c = (_b =
|
|
261
|
-
const teamSlug = (_e = (_d =
|
|
260
|
+
const previewDeploymentSuffix = (_c = (_b = microfrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
|
|
261
|
+
const teamSlug = (_e = (_d = microfrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
|
|
262
262
|
if (!teamSlug && !previewDeploymentSuffix) {
|
|
263
|
-
return [
|
|
263
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
264
264
|
}
|
|
265
265
|
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
266
266
|
return [
|
|
267
267
|
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
268
|
-
|
|
268
|
+
microfrontendConfig.getZone(zone).production.host
|
|
269
269
|
];
|
|
270
270
|
}
|
|
271
|
-
static validateOverrideDomain(
|
|
271
|
+
static validateOverrideDomain(microfrontendConfig, zone, domain) {
|
|
272
272
|
return new RegExp(
|
|
273
|
-
`^${_Overrides.validOverrideDomainsForZone(
|
|
273
|
+
`^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
|
|
274
274
|
"|"
|
|
275
275
|
)}$`
|
|
276
276
|
).test(domain);
|
|
@@ -352,7 +352,7 @@ var Application = class {
|
|
|
352
352
|
static validate(name, app) {
|
|
353
353
|
var _a, _b, _c, _d, _e;
|
|
354
354
|
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("/"))) {
|
|
355
|
-
throw new
|
|
355
|
+
throw new MicrofrontendError(
|
|
356
356
|
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
357
357
|
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
358
358
|
);
|
|
@@ -363,13 +363,13 @@ var Application = class {
|
|
|
363
363
|
continue;
|
|
364
364
|
}
|
|
365
365
|
if (p.endsWith("/")) {
|
|
366
|
-
throw new
|
|
366
|
+
throw new MicrofrontendError(
|
|
367
367
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
368
368
|
{ type: "zone", subtype: "invalid_path" }
|
|
369
369
|
);
|
|
370
370
|
}
|
|
371
371
|
if (!p.startsWith("/")) {
|
|
372
|
-
throw new
|
|
372
|
+
throw new MicrofrontendError(
|
|
373
373
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
374
374
|
{ type: "zone", subtype: "invalid_path" }
|
|
375
375
|
);
|
|
@@ -403,10 +403,10 @@ var Application = class {
|
|
|
403
403
|
}
|
|
404
404
|
};
|
|
405
405
|
|
|
406
|
-
// src/config/common/
|
|
406
|
+
// src/config/common/microfrontend-config.ts
|
|
407
407
|
var SUPPORTED_VERSIONS = ["1"];
|
|
408
408
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
409
|
-
var
|
|
409
|
+
var MicrofrontendConfigCommon = class {
|
|
410
410
|
constructor({
|
|
411
411
|
config,
|
|
412
412
|
overrides
|
|
@@ -414,7 +414,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
414
414
|
this.zones = {};
|
|
415
415
|
var _a, _b, _c;
|
|
416
416
|
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
417
|
-
throw new
|
|
417
|
+
throw new MicrofrontendError(
|
|
418
418
|
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
419
419
|
", "
|
|
420
420
|
)}`,
|
|
@@ -442,7 +442,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
442
442
|
static getConfigFromEnv() {
|
|
443
443
|
const config = process.env.MFE_CONFIG;
|
|
444
444
|
if (!config) {
|
|
445
|
-
throw new
|
|
445
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
446
446
|
type: "config",
|
|
447
447
|
subtype: "not_found_in_env"
|
|
448
448
|
});
|
|
@@ -461,8 +461,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
461
461
|
getZone(name) {
|
|
462
462
|
const zone = this.zones[name];
|
|
463
463
|
if (!zone) {
|
|
464
|
-
throw new
|
|
465
|
-
`Could not find
|
|
464
|
+
throw new MicrofrontendError(
|
|
465
|
+
`Could not find microfrontends configuration for application "${name}"`,
|
|
466
466
|
{
|
|
467
467
|
type: "zone",
|
|
468
468
|
subtype: "not_found"
|
|
@@ -482,8 +482,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
482
482
|
getDefaultZone() {
|
|
483
483
|
const zone = Object.values(this.zones).find((z) => z.default);
|
|
484
484
|
if (!zone) {
|
|
485
|
-
throw new
|
|
486
|
-
`Could not find default zone in
|
|
485
|
+
throw new MicrofrontendError(
|
|
486
|
+
`Could not find default zone in microfrontends configuration`,
|
|
487
487
|
{
|
|
488
488
|
type: "zone",
|
|
489
489
|
subtype: "not_found"
|
|
@@ -535,8 +535,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
535
535
|
};
|
|
536
536
|
}
|
|
537
537
|
write(_) {
|
|
538
|
-
throw new
|
|
539
|
-
`Writing to file to disk requires using an instance of "
|
|
538
|
+
throw new MicrofrontendError(
|
|
539
|
+
`Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
|
|
540
540
|
{ type: "config", subtype: "unsupported_operation" }
|
|
541
541
|
);
|
|
542
542
|
}
|
|
@@ -897,7 +897,7 @@ var validateSchema = (configString) => {
|
|
|
897
897
|
const validate = ajv.compile(SCHEMA);
|
|
898
898
|
const isValid = validate(parsedConfig);
|
|
899
899
|
if (!isValid) {
|
|
900
|
-
throw new
|
|
900
|
+
throw new MicrofrontendError(
|
|
901
901
|
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
902
902
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
903
903
|
);
|
|
@@ -907,7 +907,7 @@ var validateSchema = (configString) => {
|
|
|
907
907
|
var SUPPORTED_VERSIONS2 = ["1"];
|
|
908
908
|
var validateVersion = (version) => {
|
|
909
909
|
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
910
|
-
throw new
|
|
910
|
+
throw new MicrofrontendError(
|
|
911
911
|
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
912
912
|
", "
|
|
913
913
|
)}`,
|
|
@@ -940,7 +940,7 @@ function validateMainPath(applicationConfigsById) {
|
|
|
940
940
|
return !matcher.test(defaultRoute);
|
|
941
941
|
});
|
|
942
942
|
if (!isValid) {
|
|
943
|
-
throw new
|
|
943
|
+
throw new MicrofrontendError(
|
|
944
944
|
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
945
945
|
{ type: "config", subtype: "invalid_main_path" }
|
|
946
946
|
);
|
|
@@ -953,7 +953,7 @@ function validateMainPath(applicationConfigsById) {
|
|
|
953
953
|
return matcher.test(defaultRoute);
|
|
954
954
|
});
|
|
955
955
|
if (!isValid) {
|
|
956
|
-
throw new
|
|
956
|
+
throw new MicrofrontendError(
|
|
957
957
|
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
958
958
|
{ type: "config", subtype: "invalid_main_path" }
|
|
959
959
|
);
|
|
@@ -1016,7 +1016,7 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1016
1016
|
);
|
|
1017
1017
|
});
|
|
1018
1018
|
if (errors.length) {
|
|
1019
|
-
throw new
|
|
1019
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1020
1020
|
type: "config",
|
|
1021
1021
|
subtype: "conflicting_paths"
|
|
1022
1022
|
});
|
|
@@ -1050,13 +1050,13 @@ function validatePathExpression(path3) {
|
|
|
1050
1050
|
var validateDefaults = (applicationConfigsById) => {
|
|
1051
1051
|
const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
|
|
1052
1052
|
if (defaultApplicationIds.length === 0) {
|
|
1053
|
-
throw new
|
|
1053
|
+
throw new MicrofrontendError(
|
|
1054
1054
|
`No default application found. At least one application must be marked as default.`,
|
|
1055
1055
|
{ type: "config", subtype: "no_default_application" }
|
|
1056
1056
|
);
|
|
1057
1057
|
}
|
|
1058
1058
|
if (defaultApplicationIds.length > 1) {
|
|
1059
|
-
throw new
|
|
1059
|
+
throw new MicrofrontendError(
|
|
1060
1060
|
`Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
|
|
1061
1061
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
1062
1062
|
);
|
|
@@ -1068,7 +1068,7 @@ var validateOptions = (options) => {
|
|
|
1068
1068
|
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1069
1069
|
options.vercel.previewDeploymentSuffix
|
|
1070
1070
|
)) {
|
|
1071
|
-
throw new
|
|
1071
|
+
throw new MicrofrontendError(
|
|
1072
1072
|
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1073
1073
|
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1074
1074
|
);
|
|
@@ -1123,9 +1123,15 @@ function convertV1ConfigToV2Config(config, fromApp) {
|
|
|
1123
1123
|
)
|
|
1124
1124
|
};
|
|
1125
1125
|
}
|
|
1126
|
+
const defaultApplication = Object.entries(config.applications).find(
|
|
1127
|
+
([, application]) => application.default
|
|
1128
|
+
);
|
|
1129
|
+
if (!defaultApplication) {
|
|
1130
|
+
throw new Error("No default application found in the config");
|
|
1131
|
+
}
|
|
1126
1132
|
return {
|
|
1127
1133
|
...common,
|
|
1128
|
-
partOf:
|
|
1134
|
+
partOf: defaultApplication[0]
|
|
1129
1135
|
};
|
|
1130
1136
|
}
|
|
1131
1137
|
|
|
@@ -1140,8 +1146,8 @@ function writeFile(outputPath, config, prettify) {
|
|
|
1140
1146
|
);
|
|
1141
1147
|
}
|
|
1142
1148
|
|
|
1143
|
-
// src/config/
|
|
1144
|
-
var
|
|
1149
|
+
// src/config/microfrontend-config.ts
|
|
1150
|
+
var MicrofrontendConfig = class extends MicrofrontendConfigCommon {
|
|
1145
1151
|
static validate(configString) {
|
|
1146
1152
|
const config = validateSchema(configString);
|
|
1147
1153
|
validateVersion(config.version);
|
|
@@ -1154,9 +1160,9 @@ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
|
|
|
1154
1160
|
static fromEnv({
|
|
1155
1161
|
cookies
|
|
1156
1162
|
}) {
|
|
1157
|
-
return new
|
|
1158
|
-
config:
|
|
1159
|
-
|
|
1163
|
+
return new MicrofrontendConfigCommon({
|
|
1164
|
+
config: MicrofrontendConfig.validate(
|
|
1165
|
+
MicrofrontendConfigCommon.getConfigFromEnv()
|
|
1160
1166
|
),
|
|
1161
1167
|
overrides: Overrides.parseOverrides(cookies)
|
|
1162
1168
|
});
|
|
@@ -1166,11 +1172,11 @@ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
|
|
|
1166
1172
|
}) {
|
|
1167
1173
|
try {
|
|
1168
1174
|
const config = import_node_fs2.default.readFileSync(filePath, "utf-8");
|
|
1169
|
-
return new
|
|
1170
|
-
config:
|
|
1175
|
+
return new MicrofrontendConfig({
|
|
1176
|
+
config: MicrofrontendConfig.validate(config)
|
|
1171
1177
|
});
|
|
1172
1178
|
} catch (e) {
|
|
1173
|
-
throw
|
|
1179
|
+
throw MicrofrontendError.handle(e, {
|
|
1174
1180
|
fileName: filePath
|
|
1175
1181
|
});
|
|
1176
1182
|
}
|
|
@@ -1215,7 +1221,7 @@ function expandWildcards(path3) {
|
|
|
1215
1221
|
}
|
|
1216
1222
|
function loadMicrofrontendConfigForEdge(path3) {
|
|
1217
1223
|
const rawMfConfig = (0, import_jsonc_parser2.parse)((0, import_node_fs3.readFileSync)(path3, "utf-8"));
|
|
1218
|
-
return new
|
|
1224
|
+
return new MicrofrontendConfig({ config: rawMfConfig });
|
|
1219
1225
|
}
|
|
1220
1226
|
function getAllZoneNames(mfConfig) {
|
|
1221
1227
|
return mfConfig.getAllApplications().filter((app) => !app.default).map((app) => app.name);
|
|
@@ -1277,12 +1283,12 @@ function urlMatches(middlewareConfig, path3, host) {
|
|
|
1277
1283
|
}
|
|
1278
1284
|
return false;
|
|
1279
1285
|
}
|
|
1280
|
-
function validateMiddlewareConfig(middlewareConfig,
|
|
1286
|
+
function validateMiddlewareConfig(middlewareConfig, microfrontendConfigOrPath, extraProductionMatches) {
|
|
1281
1287
|
var _a, _b;
|
|
1282
|
-
const
|
|
1288
|
+
const microfrontendConfig = typeof microfrontendConfigOrPath === "string" ? loadMicrofrontendConfigForEdge(microfrontendConfigOrPath) : microfrontendConfigOrPath;
|
|
1283
1289
|
const errors = [];
|
|
1284
1290
|
const usedExtraProductionMatches = /* @__PURE__ */ new Set();
|
|
1285
|
-
for (const application of
|
|
1291
|
+
for (const application of microfrontendConfig.getAllApplications()) {
|
|
1286
1292
|
if ((_a = application.routing) == null ? void 0 : _a.matches) {
|
|
1287
1293
|
const matches = [...application.routing.matches];
|
|
1288
1294
|
if (application.routing.assetPrefix) {
|
|
@@ -1299,14 +1305,14 @@ function validateMiddlewareConfig(middlewareConfig, microFrontendConfigOrPath, e
|
|
|
1299
1305
|
if (!urlMatches(middlewareConfig, testPath, "test.nonproduction.host")) {
|
|
1300
1306
|
errors.push(
|
|
1301
1307
|
`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:
|
|
1302
|
-
${getSampleMatcher(path3,
|
|
1308
|
+
${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}`
|
|
1303
1309
|
);
|
|
1304
1310
|
break;
|
|
1305
1311
|
}
|
|
1306
1312
|
const productionUrlMatches = urlMatches(
|
|
1307
1313
|
middlewareConfig,
|
|
1308
1314
|
testPath,
|
|
1309
|
-
|
|
1315
|
+
microfrontendConfig.getDefaultZone().production.host
|
|
1310
1316
|
);
|
|
1311
1317
|
if (isFlagged) {
|
|
1312
1318
|
if (!productionUrlMatches) {
|
|
@@ -1321,7 +1327,7 @@ ${getSampleMatcher(path3, microFrontendConfig.getDefaultZone().production.host)}
|
|
|
1321
1327
|
} else {
|
|
1322
1328
|
errors.push(
|
|
1323
1329
|
`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:
|
|
1324
|
-
${getSampleMatcher(path3,
|
|
1330
|
+
${getSampleMatcher(path3, microfrontendConfig.getDefaultZone().production.host)}`
|
|
1325
1331
|
);
|
|
1326
1332
|
}
|
|
1327
1333
|
break;
|
|
@@ -1340,7 +1346,7 @@ ${getSampleMatcher(path3, microFrontendConfig.getDefaultZone().production.host)}
|
|
|
1340
1346
|
);
|
|
1341
1347
|
}
|
|
1342
1348
|
if (errors.length > 0) {
|
|
1343
|
-
const message = `Found the following inconsistencies between your microfrontend config ${typeof
|
|
1349
|
+
const message = `Found the following inconsistencies between your microfrontend config ${typeof microfrontendConfigOrPath === "string" ? `(at ${microfrontendConfigOrPath}) ` : ""}and middleware config:
|
|
1344
1350
|
|
|
1345
1351
|
- `;
|
|
1346
1352
|
throw new Error(message + errors.join("\n\n- "));
|
|
@@ -1356,26 +1362,26 @@ function getSampleMatcher(path3, host) {
|
|
|
1356
1362
|
],
|
|
1357
1363
|
}`;
|
|
1358
1364
|
}
|
|
1359
|
-
async function validateMiddlewareOnFlaggedPaths(
|
|
1365
|
+
async function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath, middleware) {
|
|
1360
1366
|
const initialEnv = process.env.VERCEL_ENV;
|
|
1361
1367
|
const initialMfePreviewDomains = process.env.MFE_PREVIEW_DOMAINS;
|
|
1362
1368
|
try {
|
|
1363
|
-
const
|
|
1364
|
-
const fakePreviewDomains = createFakePreviewDomains(
|
|
1369
|
+
const microfrontendConfig = typeof microfrontendConfigOrPath === "string" ? loadMicrofrontendConfigForEdge(microfrontendConfigOrPath) : microfrontendConfigOrPath;
|
|
1370
|
+
const fakePreviewDomains = createFakePreviewDomains(microfrontendConfig);
|
|
1365
1371
|
process.env.MFE_PREVIEW_DOMAINS = JSON.stringify(fakePreviewDomains);
|
|
1366
|
-
const allZoneNames = getAllZoneNames(
|
|
1372
|
+
const allZoneNames = getAllZoneNames(microfrontendConfig);
|
|
1367
1373
|
const errors = [];
|
|
1368
1374
|
for (const zoneName of allZoneNames) {
|
|
1369
1375
|
const flaggedPaths = getFlaggedPathsForZone(
|
|
1370
|
-
|
|
1376
|
+
microfrontendConfig,
|
|
1371
1377
|
zoneName
|
|
1372
1378
|
);
|
|
1373
1379
|
if (flaggedPaths.length) {
|
|
1374
1380
|
for (const env of ["preview", "production"]) {
|
|
1375
1381
|
process.env.VERCEL_ENV = env;
|
|
1376
1382
|
for (const path3 of flaggedPaths) {
|
|
1377
|
-
const expectedHost = env === "preview" ? fakePreviewDomains[zoneName] : getExpectedDomainForZone(
|
|
1378
|
-
const requestPath = `https://${
|
|
1383
|
+
const expectedHost = env === "preview" ? fakePreviewDomains[zoneName] : getExpectedDomainForZone(microfrontendConfig, zoneName, env);
|
|
1384
|
+
const requestPath = `https://${microfrontendConfig.getDefaultZone().production.host}${path3}`;
|
|
1379
1385
|
const request = new import_server.NextRequest(requestPath, {
|
|
1380
1386
|
headers: { "x-vercel-skip-deployment-existence-check": "1" }
|
|
1381
1387
|
});
|