@vercel/microfrontends 0.9.0 → 0.10.1
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 +7 -7
- package/dist/bin/cli.cjs +1604 -221
- package/dist/config/client.d.ts +1 -1
- 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 +67 -66
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.js +66 -65
- package/dist/config.js.map +1 -1
- package/dist/{index-eff254d8.d.ts → index-acb44057.d.ts} +12 -23
- package/dist/{micro-frontend-config-42886104.d.ts → microfrontend-config-983a5139.d.ts} +13 -13
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +86 -87
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +3 -3
- package/dist/next/config.js +85 -86
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +60 -62
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +11 -11
- package/dist/next/middleware.js +58 -60
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +80 -79
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +10 -10
- package/dist/next/testing.js +80 -79
- 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 +2 -2
- package/dist/overrides.js +9 -9
- package/dist/overrides.js.map +1 -1
- package/dist/{schema-83a75e61.d.ts → schema-2922d49e.d.ts} +1 -7
- package/dist/{types-4fd1c7c6.d.ts → types-7b1cd9f7.d.ts} +1 -7
- package/dist/types-c3d15d04.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 +3 -2
- package/dist/v2/config.js +38 -38
- package/dist/v2/config.js.map +1 -1
- package/dist/v2/microfrontends/server.cjs +223 -96
- package/dist/v2/microfrontends/server.cjs.map +1 -1
- package/dist/v2/microfrontends/server.d.ts +11 -3
- package/dist/v2/microfrontends/server.js +223 -96
- 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 +6 -5
- 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 +247 -122
- package/dist/v2/next/config.cjs.map +1 -1
- package/dist/v2/next/config.d.ts +4 -4
- package/dist/v2/next/config.js +246 -121
- 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 +55 -55
- package/dist/v2/next/middleware.cjs.map +1 -1
- package/dist/v2/next/middleware.d.ts +8 -8
- package/dist/v2/next/middleware.js +53 -53
- 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/v2/schema.cjs.map +1 -1
- package/dist/v2/schema.d.ts +1 -1
- package/dist/validation.cjs +20 -28
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +2 -8
- package/dist/validation.js +20 -28
- package/dist/validation.js.map +1 -1
- package/package.json +15 -7
- package/schema/schema-v2.json +0 -4
- package/schema/schema.json +0 -4
package/dist/next/config.cjs
CHANGED
|
@@ -30,12 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/next/config/index.ts
|
|
31
31
|
var config_exports = {};
|
|
32
32
|
__export(config_exports, {
|
|
33
|
-
|
|
33
|
+
withMicrofrontends: () => withMicrofrontends
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(config_exports);
|
|
36
36
|
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
37
37
|
|
|
38
|
-
// src/config/
|
|
38
|
+
// src/config/microfrontend-config.ts
|
|
39
39
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
40
40
|
|
|
41
41
|
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
@@ -63,14 +63,14 @@ function getOutputFilePath() {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// src/config/errors.ts
|
|
66
|
-
var
|
|
66
|
+
var MicrofrontendError = class extends Error {
|
|
67
67
|
constructor(message, opts) {
|
|
68
68
|
super(message);
|
|
69
|
-
this.name = "
|
|
70
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
69
|
+
this.name = "MicrofrontendsError";
|
|
70
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
71
71
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
72
72
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
73
|
-
Error.captureStackTrace(this,
|
|
73
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
74
74
|
}
|
|
75
75
|
isKnown() {
|
|
76
76
|
return this.type !== "unknown";
|
|
@@ -79,13 +79,13 @@ var MicroFrontendError = class extends Error {
|
|
|
79
79
|
return !this.isKnown();
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
* Converts an error to a
|
|
82
|
+
* Converts an error to a MicrofrontendsError.
|
|
83
83
|
* @param original - The original error to convert.
|
|
84
|
-
* @returns The converted
|
|
84
|
+
* @returns The converted MicrofrontendsError.
|
|
85
85
|
*/
|
|
86
86
|
static convert(original, opts) {
|
|
87
87
|
if (opts == null ? void 0 : opts.fileName) {
|
|
88
|
-
const err =
|
|
88
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
89
89
|
if (err) {
|
|
90
90
|
return err;
|
|
91
91
|
}
|
|
@@ -93,25 +93,25 @@ var MicroFrontendError = class extends Error {
|
|
|
93
93
|
if (original.message.includes(
|
|
94
94
|
"Code generation from strings disallowed for this context"
|
|
95
95
|
)) {
|
|
96
|
-
return new
|
|
96
|
+
return new MicrofrontendError(original.message, {
|
|
97
97
|
type: "config",
|
|
98
98
|
subtype: "unsupported_validation_env",
|
|
99
99
|
source: "ajv"
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
return new
|
|
102
|
+
return new MicrofrontendError(original.message);
|
|
103
103
|
}
|
|
104
104
|
static convertFSError(original, fileName) {
|
|
105
105
|
if (original instanceof Error && "code" in original) {
|
|
106
106
|
if (original.code === "ENOENT") {
|
|
107
|
-
return new
|
|
107
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
108
108
|
type: "config",
|
|
109
109
|
subtype: "unable_to_read_file",
|
|
110
110
|
source: "fs"
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
if (original.code === "EACCES") {
|
|
114
|
-
return new
|
|
114
|
+
return new MicrofrontendError(
|
|
115
115
|
`Permission denied while accessing "${fileName}"`,
|
|
116
116
|
{
|
|
117
117
|
type: "config",
|
|
@@ -122,7 +122,7 @@ var MicroFrontendError = class extends Error {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
if (original instanceof SyntaxError) {
|
|
125
|
-
return new
|
|
125
|
+
return new MicrofrontendError(
|
|
126
126
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
127
127
|
{
|
|
128
128
|
type: "config",
|
|
@@ -134,23 +134,23 @@ var MicroFrontendError = class extends Error {
|
|
|
134
134
|
return null;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
|
-
* Handles an unknown error and returns a
|
|
137
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
138
138
|
* @param err - The error to handle.
|
|
139
|
-
* @returns A
|
|
139
|
+
* @returns A MicrofrontendsError instance.
|
|
140
140
|
*/
|
|
141
141
|
static handle(err, opts) {
|
|
142
|
-
if (err instanceof
|
|
142
|
+
if (err instanceof MicrofrontendError) {
|
|
143
143
|
return err;
|
|
144
144
|
}
|
|
145
145
|
if (err instanceof Error) {
|
|
146
|
-
return
|
|
146
|
+
return MicrofrontendError.convert(err, opts);
|
|
147
147
|
}
|
|
148
148
|
if (typeof err === "object" && err !== null) {
|
|
149
149
|
if ("message" in err && typeof err.message === "string") {
|
|
150
|
-
return
|
|
150
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
return new
|
|
153
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
|
|
@@ -233,27 +233,27 @@ var _Overrides = class {
|
|
|
233
233
|
});
|
|
234
234
|
return overridesConfig;
|
|
235
235
|
}
|
|
236
|
-
static validOverrideDomainsForZone(
|
|
236
|
+
static validOverrideDomainsForZone(microfrontendConfig, zone) {
|
|
237
237
|
var _a, _b, _c, _d, _e;
|
|
238
|
-
const projectName = (_a =
|
|
238
|
+
const projectName = (_a = microfrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
239
239
|
if (!projectName) {
|
|
240
|
-
return [
|
|
240
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
241
241
|
}
|
|
242
242
|
const parsedProjectName = makeUrlSafe(projectName);
|
|
243
|
-
const previewDeploymentSuffix = (_c = (_b =
|
|
244
|
-
const teamSlug = (_e = (_d =
|
|
243
|
+
const previewDeploymentSuffix = (_c = (_b = microfrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
|
|
244
|
+
const teamSlug = (_e = (_d = microfrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
|
|
245
245
|
if (!teamSlug && !previewDeploymentSuffix) {
|
|
246
|
-
return [
|
|
246
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
247
247
|
}
|
|
248
248
|
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
249
249
|
return [
|
|
250
250
|
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
251
|
-
|
|
251
|
+
microfrontendConfig.getZone(zone).production.host
|
|
252
252
|
];
|
|
253
253
|
}
|
|
254
|
-
static validateOverrideDomain(
|
|
254
|
+
static validateOverrideDomain(microfrontendConfig, zone, domain) {
|
|
255
255
|
return new RegExp(
|
|
256
|
-
`^${_Overrides.validOverrideDomainsForZone(
|
|
256
|
+
`^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
|
|
257
257
|
"|"
|
|
258
258
|
)}$`
|
|
259
259
|
).test(domain);
|
|
@@ -335,7 +335,7 @@ var Application = class {
|
|
|
335
335
|
static validate(name, app) {
|
|
336
336
|
var _a, _b, _c, _d, _e;
|
|
337
337
|
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("/"))) {
|
|
338
|
-
throw new
|
|
338
|
+
throw new MicrofrontendError(
|
|
339
339
|
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
340
340
|
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
341
341
|
);
|
|
@@ -346,13 +346,13 @@ var Application = class {
|
|
|
346
346
|
continue;
|
|
347
347
|
}
|
|
348
348
|
if (p.endsWith("/")) {
|
|
349
|
-
throw new
|
|
349
|
+
throw new MicrofrontendError(
|
|
350
350
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
351
351
|
{ type: "zone", subtype: "invalid_path" }
|
|
352
352
|
);
|
|
353
353
|
}
|
|
354
354
|
if (!p.startsWith("/")) {
|
|
355
|
-
throw new
|
|
355
|
+
throw new MicrofrontendError(
|
|
356
356
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
357
357
|
{ type: "zone", subtype: "invalid_path" }
|
|
358
358
|
);
|
|
@@ -386,10 +386,10 @@ var Application = class {
|
|
|
386
386
|
}
|
|
387
387
|
};
|
|
388
388
|
|
|
389
|
-
// src/config/common/
|
|
389
|
+
// src/config/common/microfrontend-config.ts
|
|
390
390
|
var SUPPORTED_VERSIONS = ["1"];
|
|
391
391
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
392
|
-
var
|
|
392
|
+
var MicrofrontendConfigCommon = class {
|
|
393
393
|
constructor({
|
|
394
394
|
config,
|
|
395
395
|
overrides
|
|
@@ -397,7 +397,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
397
397
|
this.zones = {};
|
|
398
398
|
var _a, _b, _c;
|
|
399
399
|
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
400
|
-
throw new
|
|
400
|
+
throw new MicrofrontendError(
|
|
401
401
|
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
402
402
|
", "
|
|
403
403
|
)}`,
|
|
@@ -425,7 +425,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
425
425
|
static getConfigFromEnv() {
|
|
426
426
|
const config = process.env.MFE_CONFIG;
|
|
427
427
|
if (!config) {
|
|
428
|
-
throw new
|
|
428
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
429
429
|
type: "config",
|
|
430
430
|
subtype: "not_found_in_env"
|
|
431
431
|
});
|
|
@@ -444,8 +444,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
444
444
|
getZone(name) {
|
|
445
445
|
const zone = this.zones[name];
|
|
446
446
|
if (!zone) {
|
|
447
|
-
throw new
|
|
448
|
-
`Could not find
|
|
447
|
+
throw new MicrofrontendError(
|
|
448
|
+
`Could not find microfrontends configuration for application "${name}"`,
|
|
449
449
|
{
|
|
450
450
|
type: "zone",
|
|
451
451
|
subtype: "not_found"
|
|
@@ -465,8 +465,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
465
465
|
getDefaultZone() {
|
|
466
466
|
const zone = Object.values(this.zones).find((z) => z.default);
|
|
467
467
|
if (!zone) {
|
|
468
|
-
throw new
|
|
469
|
-
`Could not find default zone in
|
|
468
|
+
throw new MicrofrontendError(
|
|
469
|
+
`Could not find default zone in microfrontends configuration`,
|
|
470
470
|
{
|
|
471
471
|
type: "zone",
|
|
472
472
|
subtype: "not_found"
|
|
@@ -518,8 +518,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
518
518
|
};
|
|
519
519
|
}
|
|
520
520
|
write(_) {
|
|
521
|
-
throw new
|
|
522
|
-
`Writing to file to disk requires using an instance of "
|
|
521
|
+
throw new MicrofrontendError(
|
|
522
|
+
`Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
|
|
523
523
|
{ type: "config", subtype: "unsupported_operation" }
|
|
524
524
|
);
|
|
525
525
|
}
|
|
@@ -701,10 +701,6 @@ var schema_default = {
|
|
|
701
701
|
flag: {
|
|
702
702
|
type: "string",
|
|
703
703
|
description: "flag name that can be used to enable/disable all paths in the group"
|
|
704
|
-
},
|
|
705
|
-
routeToDefaultApplication: {
|
|
706
|
-
type: "boolean",
|
|
707
|
-
description: "True to route the request to the default application for this micro-frontends set-up. This must be `true` when using `flag` or when you want to use custom logic to make the routing decision for this group of paths."
|
|
708
704
|
}
|
|
709
705
|
}
|
|
710
706
|
},
|
|
@@ -883,7 +879,7 @@ var validateSchema = (configString) => {
|
|
|
883
879
|
const validate = ajv.compile(SCHEMA);
|
|
884
880
|
const isValid = validate(parsedConfig);
|
|
885
881
|
if (!isValid) {
|
|
886
|
-
throw new
|
|
882
|
+
throw new MicrofrontendError(
|
|
887
883
|
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
888
884
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
889
885
|
);
|
|
@@ -893,7 +889,7 @@ var validateSchema = (configString) => {
|
|
|
893
889
|
var SUPPORTED_VERSIONS2 = ["1"];
|
|
894
890
|
var validateVersion = (version) => {
|
|
895
891
|
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
896
|
-
throw new
|
|
892
|
+
throw new MicrofrontendError(
|
|
897
893
|
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
898
894
|
", "
|
|
899
895
|
)}`,
|
|
@@ -926,7 +922,7 @@ function validateMainPath(applicationConfigsById) {
|
|
|
926
922
|
return !matcher.test(defaultRoute);
|
|
927
923
|
});
|
|
928
924
|
if (!isValid) {
|
|
929
|
-
throw new
|
|
925
|
+
throw new MicrofrontendError(
|
|
930
926
|
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
931
927
|
{ type: "config", subtype: "invalid_main_path" }
|
|
932
928
|
);
|
|
@@ -939,7 +935,7 @@ function validateMainPath(applicationConfigsById) {
|
|
|
939
935
|
return matcher.test(defaultRoute);
|
|
940
936
|
});
|
|
941
937
|
if (!isValid) {
|
|
942
|
-
throw new
|
|
938
|
+
throw new MicrofrontendError(
|
|
943
939
|
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
944
940
|
{ type: "config", subtype: "invalid_main_path" }
|
|
945
941
|
);
|
|
@@ -1002,7 +998,7 @@ var validatePaths = (applicationConfigsById) => {
|
|
|
1002
998
|
);
|
|
1003
999
|
});
|
|
1004
1000
|
if (errors.length) {
|
|
1005
|
-
throw new
|
|
1001
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1006
1002
|
type: "config",
|
|
1007
1003
|
subtype: "conflicting_paths"
|
|
1008
1004
|
});
|
|
@@ -1036,13 +1032,13 @@ function validatePathExpression(path3) {
|
|
|
1036
1032
|
var validateDefaults = (applicationConfigsById) => {
|
|
1037
1033
|
const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
|
|
1038
1034
|
if (defaultApplicationIds.length === 0) {
|
|
1039
|
-
throw new
|
|
1035
|
+
throw new MicrofrontendError(
|
|
1040
1036
|
`No default application found. At least one application must be marked as default.`,
|
|
1041
1037
|
{ type: "config", subtype: "no_default_application" }
|
|
1042
1038
|
);
|
|
1043
1039
|
}
|
|
1044
1040
|
if (defaultApplicationIds.length > 1) {
|
|
1045
|
-
throw new
|
|
1041
|
+
throw new MicrofrontendError(
|
|
1046
1042
|
`Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
|
|
1047
1043
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
1048
1044
|
);
|
|
@@ -1054,7 +1050,7 @@ var validateOptions = (options) => {
|
|
|
1054
1050
|
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1055
1051
|
options.vercel.previewDeploymentSuffix
|
|
1056
1052
|
)) {
|
|
1057
|
-
throw new
|
|
1053
|
+
throw new MicrofrontendError(
|
|
1058
1054
|
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1059
1055
|
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1060
1056
|
);
|
|
@@ -1065,11 +1061,10 @@ var validateOptions = (options) => {
|
|
|
1065
1061
|
// src/config/utils/convert.ts
|
|
1066
1062
|
function convertV1RoutingToV2Routing(routing) {
|
|
1067
1063
|
return routing.matches.map((group) => {
|
|
1068
|
-
var _a
|
|
1064
|
+
var _a;
|
|
1069
1065
|
return {
|
|
1070
1066
|
group: group.group,
|
|
1071
1067
|
flag: (_a = group.options) == null ? void 0 : _a.flag,
|
|
1072
|
-
routeToDefaultApplication: (_b = group.options) == null ? void 0 : _b.routeToDefaultApplication,
|
|
1073
1068
|
paths: group.paths
|
|
1074
1069
|
};
|
|
1075
1070
|
});
|
|
@@ -1109,9 +1104,15 @@ function convertV1ConfigToV2Config(config, fromApp) {
|
|
|
1109
1104
|
)
|
|
1110
1105
|
};
|
|
1111
1106
|
}
|
|
1107
|
+
const defaultApplication = Object.entries(config.applications).find(
|
|
1108
|
+
([, application]) => application.default
|
|
1109
|
+
);
|
|
1110
|
+
if (!defaultApplication) {
|
|
1111
|
+
throw new Error("No default application found in the config");
|
|
1112
|
+
}
|
|
1112
1113
|
return {
|
|
1113
1114
|
...common,
|
|
1114
|
-
partOf:
|
|
1115
|
+
partOf: defaultApplication[0]
|
|
1115
1116
|
};
|
|
1116
1117
|
}
|
|
1117
1118
|
|
|
@@ -1126,8 +1127,8 @@ function writeFile(outputPath, config, prettify) {
|
|
|
1126
1127
|
);
|
|
1127
1128
|
}
|
|
1128
1129
|
|
|
1129
|
-
// src/config/
|
|
1130
|
-
var
|
|
1130
|
+
// src/config/microfrontend-config.ts
|
|
1131
|
+
var MicrofrontendConfig = class extends MicrofrontendConfigCommon {
|
|
1131
1132
|
static validate(configString) {
|
|
1132
1133
|
const config = validateSchema(configString);
|
|
1133
1134
|
validateVersion(config.version);
|
|
@@ -1140,9 +1141,9 @@ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
|
|
|
1140
1141
|
static fromEnv({
|
|
1141
1142
|
cookies
|
|
1142
1143
|
}) {
|
|
1143
|
-
return new
|
|
1144
|
-
config:
|
|
1145
|
-
|
|
1144
|
+
return new MicrofrontendConfigCommon({
|
|
1145
|
+
config: MicrofrontendConfig.validate(
|
|
1146
|
+
MicrofrontendConfigCommon.getConfigFromEnv()
|
|
1146
1147
|
),
|
|
1147
1148
|
overrides: Overrides.parseOverrides(cookies)
|
|
1148
1149
|
});
|
|
@@ -1152,11 +1153,11 @@ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
|
|
|
1152
1153
|
}) {
|
|
1153
1154
|
try {
|
|
1154
1155
|
const config = import_node_fs2.default.readFileSync(filePath, "utf-8");
|
|
1155
|
-
return new
|
|
1156
|
-
config:
|
|
1156
|
+
return new MicrofrontendConfig({
|
|
1157
|
+
config: MicrofrontendConfig.validate(config)
|
|
1157
1158
|
});
|
|
1158
1159
|
} catch (e) {
|
|
1159
|
-
throw
|
|
1160
|
+
throw MicrofrontendError.handle(e, {
|
|
1160
1161
|
fileName: filePath
|
|
1161
1162
|
});
|
|
1162
1163
|
}
|
|
@@ -1441,9 +1442,9 @@ function rewritesMapToArr(rewrites) {
|
|
|
1441
1442
|
});
|
|
1442
1443
|
}
|
|
1443
1444
|
function transform4(args) {
|
|
1444
|
-
const { next,
|
|
1445
|
+
const { next, microfrontend, zone } = args;
|
|
1445
1446
|
const buildBeforeFiles = () => {
|
|
1446
|
-
var _a, _b, _c, _d
|
|
1447
|
+
var _a, _b, _c, _d;
|
|
1447
1448
|
const rewrites = /* @__PURE__ */ new Map();
|
|
1448
1449
|
if ((_a = zone.routing) == null ? void 0 : _a.assetPrefix) {
|
|
1449
1450
|
rewrites.set(`/${zone.routing.assetPrefix}/_next/:path+`, {
|
|
@@ -1458,7 +1459,7 @@ function transform4(args) {
|
|
|
1458
1459
|
}
|
|
1459
1460
|
}
|
|
1460
1461
|
if (zone.isDefault()) {
|
|
1461
|
-
for (const [_, z] of Object.entries(
|
|
1462
|
+
for (const [_, z] of Object.entries(microfrontend.zones)) {
|
|
1462
1463
|
if (zone.name === z.name) {
|
|
1463
1464
|
continue;
|
|
1464
1465
|
}
|
|
@@ -1476,9 +1477,7 @@ function transform4(args) {
|
|
|
1476
1477
|
});
|
|
1477
1478
|
}
|
|
1478
1479
|
for (const group of routing.matches) {
|
|
1479
|
-
if ((_d = group.options) == null ? void 0 : _d.
|
|
1480
|
-
continue;
|
|
1481
|
-
} else if ((_e = group.options) == null ? void 0 : _e.flag) {
|
|
1480
|
+
if ((_d = group.options) == null ? void 0 : _d.flag) {
|
|
1482
1481
|
continue;
|
|
1483
1482
|
} else {
|
|
1484
1483
|
for (const source of group.paths) {
|
|
@@ -1532,14 +1531,14 @@ function transform4(args) {
|
|
|
1532
1531
|
var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
|
|
1533
1532
|
function transform5(args) {
|
|
1534
1533
|
var _a;
|
|
1535
|
-
const { next, zone,
|
|
1534
|
+
const { next, zone, microfrontend } = args;
|
|
1536
1535
|
const zonesToAllow = [
|
|
1537
1536
|
// this zone - this is included by default unless allowedOrigins is overridden (which we are)
|
|
1538
1537
|
// so we re-add it here.
|
|
1539
1538
|
zone,
|
|
1540
|
-
// this is the default zone for the
|
|
1539
|
+
// this is the default zone for the microfrontend. Allow child zones to call server actions
|
|
1541
1540
|
// that are in the default zone.
|
|
1542
|
-
|
|
1541
|
+
microfrontend.getDefaultZone()
|
|
1543
1542
|
];
|
|
1544
1543
|
const existingServerActionConfig = (_a = next.experimental) == null ? void 0 : _a.serverActions;
|
|
1545
1544
|
next.experimental = {
|
|
@@ -1564,8 +1563,8 @@ function transform5(args) {
|
|
|
1564
1563
|
|
|
1565
1564
|
// src/next/config/transforms/webpack.ts
|
|
1566
1565
|
function transform6(args) {
|
|
1567
|
-
const { next,
|
|
1568
|
-
const previewDomains = process.env.VERCEL_ENV === "preview" ?
|
|
1566
|
+
const { next, microfrontend } = args;
|
|
1567
|
+
const previewDomains = process.env.VERCEL_ENV === "preview" ? microfrontend.getAllApplications().reduce(
|
|
1569
1568
|
(obj, app) => {
|
|
1570
1569
|
obj[app.name] = getPreviewDomain(app);
|
|
1571
1570
|
return obj;
|
|
@@ -1581,7 +1580,7 @@ function transform6(args) {
|
|
|
1581
1580
|
if (isServer || nextRuntime === "edge") {
|
|
1582
1581
|
config.plugins.push(
|
|
1583
1582
|
new wpFromNext.EnvironmentPlugin({
|
|
1584
|
-
MFE_CONFIG: JSON.stringify(
|
|
1583
|
+
MFE_CONFIG: JSON.stringify(microfrontend.serialize()),
|
|
1585
1584
|
MFE_PREVIEW_DOMAINS: JSON.stringify(previewDomains)
|
|
1586
1585
|
})
|
|
1587
1586
|
);
|
|
@@ -1708,18 +1707,18 @@ function getConfigPath(opts) {
|
|
|
1708
1707
|
const vercelJsonString = import_node_fs3.default.readFileSync("./vercel.json", "utf-8");
|
|
1709
1708
|
const vercelJson = JSON.parse(vercelJsonString);
|
|
1710
1709
|
if (!((_a = vercelJson.microFrontends) == null ? void 0 : _a.config)) {
|
|
1711
|
-
throw new
|
|
1710
|
+
throw new MicrofrontendError(
|
|
1712
1711
|
`vercel.json file missing required field "microFrontends.config"`,
|
|
1713
1712
|
{
|
|
1714
1713
|
type: "vercelJson",
|
|
1715
1714
|
subtype: "missing_field_microFrontend_config_path",
|
|
1716
|
-
source: "@vercel/
|
|
1715
|
+
source: "@vercel/microfrontends/next"
|
|
1717
1716
|
}
|
|
1718
1717
|
);
|
|
1719
1718
|
}
|
|
1720
1719
|
return { configPath: vercelJson.microFrontends.config };
|
|
1721
1720
|
} catch (err) {
|
|
1722
|
-
throw
|
|
1721
|
+
throw MicrofrontendError.handle(err, {
|
|
1723
1722
|
fileName: "vercel.json"
|
|
1724
1723
|
});
|
|
1725
1724
|
}
|
|
@@ -1732,30 +1731,30 @@ function getApplicationContext(opts) {
|
|
|
1732
1731
|
const packageJsonString = import_node_fs3.default.readFileSync("./package.json", "utf-8");
|
|
1733
1732
|
const packageJson = JSON.parse(packageJsonString);
|
|
1734
1733
|
if (!packageJson.name) {
|
|
1735
|
-
throw new
|
|
1734
|
+
throw new MicrofrontendError(
|
|
1736
1735
|
`package.json file missing required field "name"`,
|
|
1737
1736
|
{
|
|
1738
1737
|
type: "packageJson",
|
|
1739
1738
|
subtype: "missing_field_name",
|
|
1740
|
-
source: "@vercel/
|
|
1739
|
+
source: "@vercel/microfrontends/next"
|
|
1741
1740
|
}
|
|
1742
1741
|
);
|
|
1743
1742
|
}
|
|
1744
1743
|
return { name: packageJson.name };
|
|
1745
1744
|
} catch (err) {
|
|
1746
|
-
throw
|
|
1745
|
+
throw MicrofrontendError.handle(err, {
|
|
1747
1746
|
fileName: "package.json"
|
|
1748
1747
|
});
|
|
1749
1748
|
}
|
|
1750
1749
|
}
|
|
1751
|
-
function
|
|
1750
|
+
function withMicrofrontends(nextConfig, opts) {
|
|
1752
1751
|
var _a;
|
|
1753
1752
|
if (opts == null ? void 0 : opts.debug) {
|
|
1754
1753
|
process.env.MFE_DEBUG = "true";
|
|
1755
1754
|
}
|
|
1756
1755
|
const { name } = getApplicationContext(opts);
|
|
1757
1756
|
const { configPath } = getConfigPath(opts);
|
|
1758
|
-
const mfConfig =
|
|
1757
|
+
const mfConfig = MicrofrontendConfig.fromFile({
|
|
1759
1758
|
filePath: configPath
|
|
1760
1759
|
});
|
|
1761
1760
|
const zone = mfConfig.getZone(name);
|
|
@@ -1770,7 +1769,7 @@ function withMicroFrontends(nextConfig, opts) {
|
|
|
1770
1769
|
const transformedConfig = transform7({
|
|
1771
1770
|
zone,
|
|
1772
1771
|
next,
|
|
1773
|
-
|
|
1772
|
+
microfrontend: mfConfig,
|
|
1774
1773
|
opts: {
|
|
1775
1774
|
isProduction: isProduction(opts)
|
|
1776
1775
|
}
|
|
@@ -1788,6 +1787,6 @@ function withMicroFrontends(nextConfig, opts) {
|
|
|
1788
1787
|
}
|
|
1789
1788
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1790
1789
|
0 && (module.exports = {
|
|
1791
|
-
|
|
1790
|
+
withMicrofrontends
|
|
1792
1791
|
});
|
|
1793
1792
|
//# sourceMappingURL=config.cjs.map
|