@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/v2/next/config.cjs
CHANGED
|
@@ -30,14 +30,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/next-v2/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
|
-
var
|
|
36
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
37
37
|
|
|
38
38
|
// src/config-v2/microfrontends/server/index.ts
|
|
39
|
-
var
|
|
40
|
-
var
|
|
39
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
40
|
+
var import_node_path4 = require("path");
|
|
41
41
|
|
|
42
42
|
// src/config-v2/overrides/constants.ts
|
|
43
43
|
var OVERRIDES_COOKIE_PREFIX = "vercel-microfrontends-override";
|
|
@@ -74,14 +74,14 @@ function parseOverrides(cookies) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// src/config-v2/errors.ts
|
|
77
|
-
var
|
|
77
|
+
var MicrofrontendError = class extends Error {
|
|
78
78
|
constructor(message, opts) {
|
|
79
79
|
super(message);
|
|
80
|
-
this.name = "
|
|
81
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
80
|
+
this.name = "MicrofrontendsError";
|
|
81
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
82
82
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
83
83
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
84
|
-
Error.captureStackTrace(this,
|
|
84
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
85
85
|
}
|
|
86
86
|
isKnown() {
|
|
87
87
|
return this.type !== "unknown";
|
|
@@ -90,13 +90,13 @@ var MicroFrontendError = class extends Error {
|
|
|
90
90
|
return !this.isKnown();
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
|
-
* Converts an error to a
|
|
93
|
+
* Converts an error to a MicrofrontendsError.
|
|
94
94
|
* @param original - The original error to convert.
|
|
95
|
-
* @returns The converted
|
|
95
|
+
* @returns The converted MicrofrontendsError.
|
|
96
96
|
*/
|
|
97
97
|
static convert(original, opts) {
|
|
98
98
|
if (opts == null ? void 0 : opts.fileName) {
|
|
99
|
-
const err =
|
|
99
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
100
100
|
if (err) {
|
|
101
101
|
return err;
|
|
102
102
|
}
|
|
@@ -104,25 +104,25 @@ var MicroFrontendError = class extends Error {
|
|
|
104
104
|
if (original.message.includes(
|
|
105
105
|
"Code generation from strings disallowed for this context"
|
|
106
106
|
)) {
|
|
107
|
-
return new
|
|
107
|
+
return new MicrofrontendError(original.message, {
|
|
108
108
|
type: "config",
|
|
109
109
|
subtype: "unsupported_validation_env",
|
|
110
110
|
source: "ajv"
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
return new
|
|
113
|
+
return new MicrofrontendError(original.message);
|
|
114
114
|
}
|
|
115
115
|
static convertFSError(original, fileName) {
|
|
116
116
|
if (original instanceof Error && "code" in original) {
|
|
117
117
|
if (original.code === "ENOENT") {
|
|
118
|
-
return new
|
|
118
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
119
119
|
type: "config",
|
|
120
120
|
subtype: "unable_to_read_file",
|
|
121
121
|
source: "fs"
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
if (original.code === "EACCES") {
|
|
125
|
-
return new
|
|
125
|
+
return new MicrofrontendError(
|
|
126
126
|
`Permission denied while accessing "${fileName}"`,
|
|
127
127
|
{
|
|
128
128
|
type: "config",
|
|
@@ -133,7 +133,7 @@ var MicroFrontendError = class extends Error {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
if (original instanceof SyntaxError) {
|
|
136
|
-
return new
|
|
136
|
+
return new MicrofrontendError(
|
|
137
137
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
138
138
|
{
|
|
139
139
|
type: "config",
|
|
@@ -145,23 +145,23 @@ var MicroFrontendError = class extends Error {
|
|
|
145
145
|
return null;
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
|
-
* Handles an unknown error and returns a
|
|
148
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
149
149
|
* @param err - The error to handle.
|
|
150
|
-
* @returns A
|
|
150
|
+
* @returns A MicrofrontendsError instance.
|
|
151
151
|
*/
|
|
152
152
|
static handle(err, opts) {
|
|
153
|
-
if (err instanceof
|
|
153
|
+
if (err instanceof MicrofrontendError) {
|
|
154
154
|
return err;
|
|
155
155
|
}
|
|
156
156
|
if (err instanceof Error) {
|
|
157
|
-
return
|
|
157
|
+
return MicrofrontendError.convert(err, opts);
|
|
158
158
|
}
|
|
159
159
|
if (typeof err === "object" && err !== null) {
|
|
160
160
|
if ("message" in err && typeof err.message === "string") {
|
|
161
|
-
return
|
|
161
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
return new
|
|
164
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
165
165
|
}
|
|
166
166
|
};
|
|
167
167
|
|
|
@@ -169,7 +169,7 @@ var MicroFrontendError = class extends Error {
|
|
|
169
169
|
function getConfigStringFromEnv() {
|
|
170
170
|
const config = process.env.MFE_CONFIG;
|
|
171
171
|
if (!config) {
|
|
172
|
-
throw new
|
|
172
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
173
173
|
type: "config",
|
|
174
174
|
subtype: "not_found_in_env"
|
|
175
175
|
});
|
|
@@ -192,7 +192,7 @@ function isDefaultApp(a) {
|
|
|
192
192
|
|
|
193
193
|
// src/config-v2/microfrontends-config/client/index.ts
|
|
194
194
|
var import_path_to_regexp = require("path-to-regexp");
|
|
195
|
-
var
|
|
195
|
+
var MicrofrontendConfigClient = class {
|
|
196
196
|
constructor(config, opts) {
|
|
197
197
|
this.pathCache = {};
|
|
198
198
|
this.serialized = config;
|
|
@@ -206,14 +206,14 @@ var MicroFrontendConfigClient = class {
|
|
|
206
206
|
this.applications = config.applications;
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
|
-
* Create a new `
|
|
209
|
+
* Create a new `MicrofrontendConfigClient` from a JSON string.
|
|
210
210
|
* Config must be passed in to remain framework agnostic
|
|
211
211
|
*/
|
|
212
212
|
static fromEnv(config, opts) {
|
|
213
213
|
if (!config) {
|
|
214
|
-
throw new Error("No
|
|
214
|
+
throw new Error("No microfrontends configuration found");
|
|
215
215
|
}
|
|
216
|
-
return new
|
|
216
|
+
return new MicrofrontendConfigClient(
|
|
217
217
|
JSON.parse(config),
|
|
218
218
|
opts
|
|
219
219
|
);
|
|
@@ -221,21 +221,21 @@ var MicroFrontendConfigClient = class {
|
|
|
221
221
|
isEqual(other) {
|
|
222
222
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
223
223
|
}
|
|
224
|
-
getApplicationNameForPath(
|
|
225
|
-
if (!
|
|
224
|
+
getApplicationNameForPath(path3) {
|
|
225
|
+
if (!path3.startsWith("/")) {
|
|
226
226
|
throw new Error(`Path must start with a /`);
|
|
227
227
|
}
|
|
228
|
-
if (this.pathCache[
|
|
229
|
-
return this.pathCache[
|
|
228
|
+
if (this.pathCache[path3]) {
|
|
229
|
+
return this.pathCache[path3];
|
|
230
230
|
}
|
|
231
|
-
const pathname = new URL(
|
|
231
|
+
const pathname = new URL(path3, "https://example.com").pathname;
|
|
232
232
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
233
233
|
if (application.routing) {
|
|
234
234
|
for (const group of application.routing) {
|
|
235
235
|
for (const childPath of group.paths) {
|
|
236
236
|
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
237
237
|
if (regexp.test(pathname)) {
|
|
238
|
-
this.pathCache[
|
|
238
|
+
this.pathCache[path3] = name;
|
|
239
239
|
return name;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
@@ -248,7 +248,7 @@ var MicroFrontendConfigClient = class {
|
|
|
248
248
|
if (!defaultApplication) {
|
|
249
249
|
return null;
|
|
250
250
|
}
|
|
251
|
-
this.pathCache[
|
|
251
|
+
this.pathCache[path3] = defaultApplication[0];
|
|
252
252
|
return defaultApplication[0];
|
|
253
253
|
}
|
|
254
254
|
serialize() {
|
|
@@ -261,7 +261,7 @@ var import_path_to_regexp2 = require("path-to-regexp");
|
|
|
261
261
|
var SUPPORTED_VERSIONS = ["2"];
|
|
262
262
|
var validateConfigVersion = (version) => {
|
|
263
263
|
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
264
|
-
throw new
|
|
264
|
+
throw new MicrofrontendError(
|
|
265
265
|
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
266
266
|
", "
|
|
267
267
|
)}`,
|
|
@@ -280,22 +280,22 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
280
280
|
continue;
|
|
281
281
|
}
|
|
282
282
|
for (const pathMatch of app.routing) {
|
|
283
|
-
for (const
|
|
284
|
-
const tokens = (0, import_path_to_regexp2.parse)(
|
|
283
|
+
for (const path3 of pathMatch.paths) {
|
|
284
|
+
const tokens = (0, import_path_to_regexp2.parse)(path3);
|
|
285
285
|
for (const token of tokens.slice(0, -1)) {
|
|
286
286
|
if (typeof token !== "string") {
|
|
287
287
|
errors.push(
|
|
288
|
-
`Path ${
|
|
288
|
+
`Path ${path3} may only have a :wildcard in the last path component`
|
|
289
289
|
);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
|
-
const existing = pathsByApplicationId.get(
|
|
292
|
+
const existing = pathsByApplicationId.get(path3);
|
|
293
293
|
if (existing) {
|
|
294
294
|
existing.applications.push(id);
|
|
295
295
|
} else {
|
|
296
|
-
pathsByApplicationId.set(
|
|
296
|
+
pathsByApplicationId.set(path3, {
|
|
297
297
|
applications: [id],
|
|
298
|
-
matcher: (0, import_path_to_regexp2.pathToRegexp)(
|
|
298
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path3),
|
|
299
299
|
applicationId: id
|
|
300
300
|
});
|
|
301
301
|
}
|
|
@@ -303,10 +303,10 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
306
|
-
entries.forEach(([
|
|
306
|
+
entries.forEach(([path3, { applications: ids, matcher, applicationId }]) => {
|
|
307
307
|
if (ids.length > 1) {
|
|
308
308
|
errors.push(
|
|
309
|
-
`Duplicate path "${
|
|
309
|
+
`Duplicate path "${path3}" for applications "${ids.join(", ")}"`
|
|
310
310
|
);
|
|
311
311
|
}
|
|
312
312
|
entries.forEach(
|
|
@@ -314,14 +314,14 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
314
314
|
matchPath,
|
|
315
315
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
316
316
|
]) => {
|
|
317
|
-
if (
|
|
317
|
+
if (path3 === matchPath) {
|
|
318
318
|
return;
|
|
319
319
|
}
|
|
320
320
|
if (applicationId === matchApplicationId) {
|
|
321
321
|
return;
|
|
322
322
|
}
|
|
323
323
|
if (matcher.test(matchPath)) {
|
|
324
|
-
const source = `"${
|
|
324
|
+
const source = `"${path3}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
325
325
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
326
326
|
errors.push(
|
|
327
327
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -331,7 +331,7 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
331
331
|
);
|
|
332
332
|
});
|
|
333
333
|
if (errors.length) {
|
|
334
|
-
throw new
|
|
334
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
335
335
|
type: "config",
|
|
336
336
|
subtype: "conflicting_paths"
|
|
337
337
|
});
|
|
@@ -344,13 +344,13 @@ var validateAppPaths = (name, app) => {
|
|
|
344
344
|
continue;
|
|
345
345
|
}
|
|
346
346
|
if (p.endsWith("/")) {
|
|
347
|
-
throw new
|
|
347
|
+
throw new MicrofrontendError(
|
|
348
348
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
349
349
|
{ type: "application", subtype: "invalid_path" }
|
|
350
350
|
);
|
|
351
351
|
}
|
|
352
352
|
if (!p.startsWith("/")) {
|
|
353
|
-
throw new
|
|
353
|
+
throw new MicrofrontendError(
|
|
354
354
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
355
355
|
{ type: "application", subtype: "invalid_path" }
|
|
356
356
|
);
|
|
@@ -372,13 +372,13 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
372
372
|
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
373
373
|
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
374
374
|
if (numApplicationsWithoutRouting === 0) {
|
|
375
|
-
throw new
|
|
375
|
+
throw new MicrofrontendError(
|
|
376
376
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
377
377
|
{ type: "config", subtype: "no_default_application" }
|
|
378
378
|
);
|
|
379
379
|
}
|
|
380
380
|
if (numApplicationsWithoutRouting > 1) {
|
|
381
|
-
throw new
|
|
381
|
+
throw new MicrofrontendError(
|
|
382
382
|
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
383
383
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
384
384
|
);
|
|
@@ -390,7 +390,7 @@ var validateConfigOptions = (options) => {
|
|
|
390
390
|
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
391
391
|
options.vercel.previewDeploymentSuffix
|
|
392
392
|
)) {
|
|
393
|
-
throw new
|
|
393
|
+
throw new MicrofrontendError(
|
|
394
394
|
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
395
395
|
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
396
396
|
);
|
|
@@ -549,7 +549,7 @@ var ChildApplication = class extends Application {
|
|
|
549
549
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
550
550
|
|
|
551
551
|
// src/config-v2/microfrontends-config/isomorphic/index.ts
|
|
552
|
-
var
|
|
552
|
+
var MicrofrontendConfigIsomorphic = class {
|
|
553
553
|
constructor({
|
|
554
554
|
config,
|
|
555
555
|
overrides,
|
|
@@ -557,7 +557,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
557
557
|
}) {
|
|
558
558
|
this.childApplications = {};
|
|
559
559
|
var _a, _b, _c, _d;
|
|
560
|
-
|
|
560
|
+
MicrofrontendConfigIsomorphic.validate(config);
|
|
561
561
|
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
562
562
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
563
563
|
this.isMainConfig = isMainConfig(config);
|
|
@@ -589,7 +589,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
589
589
|
);
|
|
590
590
|
}
|
|
591
591
|
if (isMainConfig(config) && !this.defaultApplication) {
|
|
592
|
-
throw new
|
|
592
|
+
throw new MicrofrontendError(
|
|
593
593
|
`Could not find default application in microfrontends configuration`,
|
|
594
594
|
{
|
|
595
595
|
type: "application",
|
|
@@ -619,7 +619,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
619
619
|
meta,
|
|
620
620
|
cookies
|
|
621
621
|
}) {
|
|
622
|
-
return new
|
|
622
|
+
return new MicrofrontendConfigIsomorphic({
|
|
623
623
|
config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
|
|
624
624
|
overrides: parseOverrides(cookies ?? []),
|
|
625
625
|
meta
|
|
@@ -654,7 +654,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
654
654
|
}
|
|
655
655
|
const app = this.childApplications[name];
|
|
656
656
|
if (!app) {
|
|
657
|
-
throw new
|
|
657
|
+
throw new MicrofrontendError(
|
|
658
658
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
659
659
|
{
|
|
660
660
|
type: "application",
|
|
@@ -682,7 +682,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
682
682
|
*/
|
|
683
683
|
getDefaultApplication() {
|
|
684
684
|
if (!this.defaultApplication) {
|
|
685
|
-
throw new
|
|
685
|
+
throw new MicrofrontendError(
|
|
686
686
|
`Could not find default application in microfrontends configuration`,
|
|
687
687
|
{
|
|
688
688
|
type: "application",
|
|
@@ -722,7 +722,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
722
722
|
default: true
|
|
723
723
|
};
|
|
724
724
|
}
|
|
725
|
-
return new
|
|
725
|
+
return new MicrofrontendConfigClient({
|
|
726
726
|
applications
|
|
727
727
|
});
|
|
728
728
|
}
|
|
@@ -732,7 +732,7 @@ var MicroFrontendConfigIsomorphic = class {
|
|
|
732
732
|
};
|
|
733
733
|
|
|
734
734
|
// src/config-v2/microfrontends-config/isomorphic/child.ts
|
|
735
|
-
var
|
|
735
|
+
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
736
736
|
constructor({
|
|
737
737
|
config,
|
|
738
738
|
overrides,
|
|
@@ -745,7 +745,7 @@ var MicroFrontendChildConfig = class extends MicroFrontendConfigIsomorphic {
|
|
|
745
745
|
};
|
|
746
746
|
|
|
747
747
|
// src/config-v2/microfrontends-config/isomorphic/main.ts
|
|
748
|
-
var
|
|
748
|
+
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
749
749
|
constructor({
|
|
750
750
|
config,
|
|
751
751
|
overrides,
|
|
@@ -772,7 +772,7 @@ var MicroFrontendMainConfig = class extends MicroFrontendConfigIsomorphic {
|
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
774
|
if (!defaultApplication) {
|
|
775
|
-
throw new
|
|
775
|
+
throw new MicrofrontendError(
|
|
776
776
|
`Could not find default application in microfrontends configuration`,
|
|
777
777
|
{
|
|
778
778
|
type: "application",
|
|
@@ -792,19 +792,19 @@ var Microfrontends = class {
|
|
|
792
792
|
meta
|
|
793
793
|
}) {
|
|
794
794
|
if (isMainConfig(config)) {
|
|
795
|
-
this.config = new
|
|
795
|
+
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
796
796
|
} else {
|
|
797
|
-
this.config = new
|
|
797
|
+
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
798
798
|
}
|
|
799
799
|
}
|
|
800
800
|
isChildConfig() {
|
|
801
|
-
return this.config instanceof
|
|
801
|
+
return this.config instanceof MicrofrontendChildConfig;
|
|
802
802
|
}
|
|
803
803
|
static fromEnv({
|
|
804
804
|
cookies,
|
|
805
805
|
meta
|
|
806
806
|
}) {
|
|
807
|
-
const config =
|
|
807
|
+
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
808
808
|
cookies,
|
|
809
809
|
meta
|
|
810
810
|
});
|
|
@@ -812,8 +812,82 @@ var Microfrontends = class {
|
|
|
812
812
|
}
|
|
813
813
|
};
|
|
814
814
|
|
|
815
|
-
// src/config-v2/microfrontends/
|
|
815
|
+
// src/config-v2/microfrontends/utils/find-repository-root.ts
|
|
816
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
816
817
|
var import_node_path = __toESM(require("path"), 1);
|
|
818
|
+
var GIT_DIRECTORY = ".git";
|
|
819
|
+
function findRepositoryRoot(startDir) {
|
|
820
|
+
let currentDir = startDir || process.cwd();
|
|
821
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
822
|
+
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
823
|
+
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
824
|
+
return currentDir;
|
|
825
|
+
}
|
|
826
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
827
|
+
}
|
|
828
|
+
throw new Error(
|
|
829
|
+
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// src/config-v2/microfrontends/utils/find-package-path.ts
|
|
834
|
+
var import_node_path2 = require("path");
|
|
835
|
+
var import_node_fs2 = require("fs");
|
|
836
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
837
|
+
var configCache = {};
|
|
838
|
+
function findPackagePathWithGlob({
|
|
839
|
+
repositoryRoot,
|
|
840
|
+
name
|
|
841
|
+
}) {
|
|
842
|
+
try {
|
|
843
|
+
const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
|
|
844
|
+
cwd: repositoryRoot,
|
|
845
|
+
absolute: true,
|
|
846
|
+
onlyFiles: true,
|
|
847
|
+
followSymbolicLinks: false,
|
|
848
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
849
|
+
});
|
|
850
|
+
const matchingPaths = [];
|
|
851
|
+
for (const packageJsonPath2 of packageJsonPaths) {
|
|
852
|
+
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
853
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
854
|
+
if (packageJson.name === name) {
|
|
855
|
+
matchingPaths.push(packageJsonPath2);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (matchingPaths.length > 1) {
|
|
859
|
+
throw new Error(
|
|
860
|
+
`Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
if (matchingPaths.length === 0) {
|
|
864
|
+
throw new Error(
|
|
865
|
+
`Could not find package with the name "${name}" in the repository`
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
const [packageJsonPath] = matchingPaths;
|
|
869
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
870
|
+
} catch (error) {
|
|
871
|
+
return null;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
function findPackagePath(opts) {
|
|
875
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
|
|
876
|
+
if (configCache[cacheKey]) {
|
|
877
|
+
return configCache[cacheKey];
|
|
878
|
+
}
|
|
879
|
+
const result = findPackagePathWithGlob(opts);
|
|
880
|
+
if (!result) {
|
|
881
|
+
throw new Error(
|
|
882
|
+
`Could not find package with the name "${opts.name}" in the repository`
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
configCache[cacheKey] = result;
|
|
886
|
+
return result;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
890
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
817
891
|
|
|
818
892
|
// src/config-v2/microfrontends/server/constants.ts
|
|
819
893
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -827,13 +901,13 @@ function isVercel() {
|
|
|
827
901
|
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
828
902
|
function getOutputFilePath() {
|
|
829
903
|
if (isVercel()) {
|
|
830
|
-
return
|
|
904
|
+
return import_node_path3.default.join(
|
|
831
905
|
".vercel",
|
|
832
906
|
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
833
907
|
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
834
908
|
);
|
|
835
909
|
}
|
|
836
|
-
return
|
|
910
|
+
return import_node_path3.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
837
911
|
}
|
|
838
912
|
|
|
839
913
|
// src/config-v2/microfrontends/server/validation.ts
|
|
@@ -841,14 +915,14 @@ var import_jsonc_parser2 = require("jsonc-parser");
|
|
|
841
915
|
var import_ajv = require("ajv");
|
|
842
916
|
|
|
843
917
|
// src/config/errors.ts
|
|
844
|
-
var
|
|
918
|
+
var MicrofrontendError2 = class extends Error {
|
|
845
919
|
constructor(message, opts) {
|
|
846
920
|
super(message);
|
|
847
|
-
this.name = "
|
|
848
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
921
|
+
this.name = "MicrofrontendsError";
|
|
922
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
849
923
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
850
924
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
851
|
-
Error.captureStackTrace(this,
|
|
925
|
+
Error.captureStackTrace(this, MicrofrontendError2);
|
|
852
926
|
}
|
|
853
927
|
isKnown() {
|
|
854
928
|
return this.type !== "unknown";
|
|
@@ -857,13 +931,13 @@ var MicroFrontendError2 = class extends Error {
|
|
|
857
931
|
return !this.isKnown();
|
|
858
932
|
}
|
|
859
933
|
/**
|
|
860
|
-
* Converts an error to a
|
|
934
|
+
* Converts an error to a MicrofrontendsError.
|
|
861
935
|
* @param original - The original error to convert.
|
|
862
|
-
* @returns The converted
|
|
936
|
+
* @returns The converted MicrofrontendsError.
|
|
863
937
|
*/
|
|
864
938
|
static convert(original, opts) {
|
|
865
939
|
if (opts == null ? void 0 : opts.fileName) {
|
|
866
|
-
const err =
|
|
940
|
+
const err = MicrofrontendError2.convertFSError(original, opts.fileName);
|
|
867
941
|
if (err) {
|
|
868
942
|
return err;
|
|
869
943
|
}
|
|
@@ -871,25 +945,25 @@ var MicroFrontendError2 = class extends Error {
|
|
|
871
945
|
if (original.message.includes(
|
|
872
946
|
"Code generation from strings disallowed for this context"
|
|
873
947
|
)) {
|
|
874
|
-
return new
|
|
948
|
+
return new MicrofrontendError2(original.message, {
|
|
875
949
|
type: "config",
|
|
876
950
|
subtype: "unsupported_validation_env",
|
|
877
951
|
source: "ajv"
|
|
878
952
|
});
|
|
879
953
|
}
|
|
880
|
-
return new
|
|
954
|
+
return new MicrofrontendError2(original.message);
|
|
881
955
|
}
|
|
882
956
|
static convertFSError(original, fileName) {
|
|
883
957
|
if (original instanceof Error && "code" in original) {
|
|
884
958
|
if (original.code === "ENOENT") {
|
|
885
|
-
return new
|
|
959
|
+
return new MicrofrontendError2(`Could not find "${fileName}"`, {
|
|
886
960
|
type: "config",
|
|
887
961
|
subtype: "unable_to_read_file",
|
|
888
962
|
source: "fs"
|
|
889
963
|
});
|
|
890
964
|
}
|
|
891
965
|
if (original.code === "EACCES") {
|
|
892
|
-
return new
|
|
966
|
+
return new MicrofrontendError2(
|
|
893
967
|
`Permission denied while accessing "${fileName}"`,
|
|
894
968
|
{
|
|
895
969
|
type: "config",
|
|
@@ -900,7 +974,7 @@ var MicroFrontendError2 = class extends Error {
|
|
|
900
974
|
}
|
|
901
975
|
}
|
|
902
976
|
if (original instanceof SyntaxError) {
|
|
903
|
-
return new
|
|
977
|
+
return new MicrofrontendError2(
|
|
904
978
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
905
979
|
{
|
|
906
980
|
type: "config",
|
|
@@ -912,23 +986,23 @@ var MicroFrontendError2 = class extends Error {
|
|
|
912
986
|
return null;
|
|
913
987
|
}
|
|
914
988
|
/**
|
|
915
|
-
* Handles an unknown error and returns a
|
|
989
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
916
990
|
* @param err - The error to handle.
|
|
917
|
-
* @returns A
|
|
991
|
+
* @returns A MicrofrontendsError instance.
|
|
918
992
|
*/
|
|
919
993
|
static handle(err, opts) {
|
|
920
|
-
if (err instanceof
|
|
994
|
+
if (err instanceof MicrofrontendError2) {
|
|
921
995
|
return err;
|
|
922
996
|
}
|
|
923
997
|
if (err instanceof Error) {
|
|
924
|
-
return
|
|
998
|
+
return MicrofrontendError2.convert(err, opts);
|
|
925
999
|
}
|
|
926
1000
|
if (typeof err === "object" && err !== null) {
|
|
927
1001
|
if ("message" in err && typeof err.message === "string") {
|
|
928
|
-
return
|
|
1002
|
+
return MicrofrontendError2.convert(new Error(err.message), opts);
|
|
929
1003
|
}
|
|
930
1004
|
}
|
|
931
|
-
return new
|
|
1005
|
+
return new MicrofrontendError2("An unknown error occurred");
|
|
932
1006
|
}
|
|
933
1007
|
};
|
|
934
1008
|
|
|
@@ -1143,10 +1217,6 @@ var schema_v2_default = {
|
|
|
1143
1217
|
type: "string",
|
|
1144
1218
|
description: "flag name that can be used to enable/disable all paths in the group"
|
|
1145
1219
|
},
|
|
1146
|
-
routeToDefaultApplication: {
|
|
1147
|
-
type: "boolean",
|
|
1148
|
-
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."
|
|
1149
|
-
},
|
|
1150
1220
|
paths: {
|
|
1151
1221
|
type: "array",
|
|
1152
1222
|
items: {
|
|
@@ -1206,7 +1276,7 @@ function validateSchema(configString) {
|
|
|
1206
1276
|
const validate = ajv.compile(SCHEMA);
|
|
1207
1277
|
const isValid = validate(parsedConfig);
|
|
1208
1278
|
if (!isValid) {
|
|
1209
|
-
throw new
|
|
1279
|
+
throw new MicrofrontendError2(
|
|
1210
1280
|
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
1211
1281
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
1212
1282
|
);
|
|
@@ -1223,8 +1293,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1223
1293
|
pretty: true
|
|
1224
1294
|
}) {
|
|
1225
1295
|
const outputPath = getOutputFilePath();
|
|
1226
|
-
|
|
1227
|
-
|
|
1296
|
+
import_node_fs3.default.mkdirSync((0, import_node_path4.dirname)(outputPath), { recursive: true });
|
|
1297
|
+
import_node_fs3.default.writeFileSync(
|
|
1228
1298
|
outputPath,
|
|
1229
1299
|
JSON.stringify(
|
|
1230
1300
|
this.config.toSchemaJson(),
|
|
@@ -1257,7 +1327,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1257
1327
|
meta
|
|
1258
1328
|
});
|
|
1259
1329
|
}
|
|
1260
|
-
throw new
|
|
1330
|
+
throw new MicrofrontendError(
|
|
1261
1331
|
"Invalid config: must be a string or an object",
|
|
1262
1332
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
1263
1333
|
);
|
|
@@ -1292,17 +1362,74 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1292
1362
|
static fromFile({
|
|
1293
1363
|
filePath,
|
|
1294
1364
|
cookies,
|
|
1295
|
-
meta
|
|
1365
|
+
meta,
|
|
1366
|
+
options
|
|
1296
1367
|
}) {
|
|
1297
1368
|
try {
|
|
1298
|
-
const
|
|
1369
|
+
const configJson = import_node_fs3.default.readFileSync(filePath, "utf-8");
|
|
1370
|
+
const config = MicrofrontendsServer.validate(configJson);
|
|
1371
|
+
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
1372
|
+
const repositoryRoot = findRepositoryRoot();
|
|
1373
|
+
const packagePath = findPackagePath({
|
|
1374
|
+
repositoryRoot,
|
|
1375
|
+
name: config.partOf
|
|
1376
|
+
});
|
|
1377
|
+
if (!packagePath) {
|
|
1378
|
+
throw new MicrofrontendError(
|
|
1379
|
+
`Could not find default application "${config.partOf}" in the repository`,
|
|
1380
|
+
{ type: "config", subtype: "not_found" }
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
const mainConfigPath = (0, import_node_path4.join)(packagePath, "microfrontends.json");
|
|
1384
|
+
return MicrofrontendsServer.fromMainConfigFile({
|
|
1385
|
+
filePath: mainConfigPath,
|
|
1386
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1299
1389
|
return new MicrofrontendsServer({
|
|
1300
|
-
config
|
|
1390
|
+
config,
|
|
1301
1391
|
overrides: cookies ? parseOverrides(cookies) : void 0,
|
|
1302
1392
|
meta
|
|
1303
1393
|
});
|
|
1304
1394
|
} catch (e) {
|
|
1305
|
-
throw
|
|
1395
|
+
throw MicrofrontendError.handle(e, {
|
|
1396
|
+
fileName: filePath
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
/*
|
|
1401
|
+
* Generates a MicrofrontendMainConfig instance from a file.
|
|
1402
|
+
*/
|
|
1403
|
+
static fromMainConfigFile({
|
|
1404
|
+
filePath,
|
|
1405
|
+
overrides
|
|
1406
|
+
}) {
|
|
1407
|
+
try {
|
|
1408
|
+
const config = import_node_fs3.default.readFileSync(filePath, "utf-8");
|
|
1409
|
+
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1410
|
+
if (!isMainConfig(validatedConfig)) {
|
|
1411
|
+
throw new MicrofrontendError(
|
|
1412
|
+
`${filePath} is not a main microfrontend config`,
|
|
1413
|
+
{
|
|
1414
|
+
type: "config",
|
|
1415
|
+
subtype: "invalid_main_path"
|
|
1416
|
+
}
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1420
|
+
if (!defaultApplication) {
|
|
1421
|
+
throw new MicrofrontendError(
|
|
1422
|
+
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
1423
|
+
{ type: "config", subtype: "no_default_application" }
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
return new MicrofrontendsServer({
|
|
1427
|
+
config: validatedConfig,
|
|
1428
|
+
overrides,
|
|
1429
|
+
meta: { fromApp: defaultApplication }
|
|
1430
|
+
});
|
|
1431
|
+
} catch (e) {
|
|
1432
|
+
throw MicrofrontendError.handle(e, {
|
|
1306
1433
|
fileName: filePath
|
|
1307
1434
|
});
|
|
1308
1435
|
}
|
|
@@ -1509,11 +1636,11 @@ ${table}
|
|
|
1509
1636
|
`);
|
|
1510
1637
|
}
|
|
1511
1638
|
}
|
|
1512
|
-
function pathToRewrites(
|
|
1639
|
+
function pathToRewrites(path3) {
|
|
1513
1640
|
var _a;
|
|
1514
1641
|
const regex = /(?<base>^.+)\/:.+\*$/;
|
|
1515
|
-
const match = regex.exec(
|
|
1516
|
-
const paths = [
|
|
1642
|
+
const match = regex.exec(path3);
|
|
1643
|
+
const paths = [path3];
|
|
1517
1644
|
if ((_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.base) {
|
|
1518
1645
|
paths.unshift(match.groups.base);
|
|
1519
1646
|
}
|
|
@@ -1533,7 +1660,7 @@ function rewritesMapToArr(rewrites) {
|
|
|
1533
1660
|
});
|
|
1534
1661
|
}
|
|
1535
1662
|
function transform4(args) {
|
|
1536
|
-
const { next,
|
|
1663
|
+
const { next, microfrontend, app } = args;
|
|
1537
1664
|
const buildBeforeFiles = () => {
|
|
1538
1665
|
var _a;
|
|
1539
1666
|
const rewrites = /* @__PURE__ */ new Map();
|
|
@@ -1548,12 +1675,12 @@ function transform4(args) {
|
|
|
1548
1675
|
destination: { pathname: "/_vercel/:path*" }
|
|
1549
1676
|
});
|
|
1550
1677
|
}
|
|
1551
|
-
} else if (
|
|
1678
|
+
} else if (microfrontend instanceof MicrofrontendMainConfig) {
|
|
1552
1679
|
for (const [_, a] of Object.entries(
|
|
1553
|
-
|
|
1680
|
+
microfrontend.getChildApplications()
|
|
1554
1681
|
)) {
|
|
1555
1682
|
const { routing } = a;
|
|
1556
|
-
const domain = getDomainForCurrentEnvironment(
|
|
1683
|
+
const domain = getDomainForCurrentEnvironment(microfrontend, a.name);
|
|
1557
1684
|
rewrites.set(`/${a.getAssetPrefix()}/:path+`, {
|
|
1558
1685
|
destination: {
|
|
1559
1686
|
domain,
|
|
@@ -1561,9 +1688,7 @@ function transform4(args) {
|
|
|
1561
1688
|
}
|
|
1562
1689
|
});
|
|
1563
1690
|
for (const group of routing) {
|
|
1564
|
-
if (group.
|
|
1565
|
-
continue;
|
|
1566
|
-
} else if (group.flag) {
|
|
1691
|
+
if (group.flag) {
|
|
1567
1692
|
continue;
|
|
1568
1693
|
} else {
|
|
1569
1694
|
for (const source of group.paths) {
|
|
@@ -1616,8 +1741,8 @@ function transform4(args) {
|
|
|
1616
1741
|
var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
|
|
1617
1742
|
function transform5(args) {
|
|
1618
1743
|
var _a;
|
|
1619
|
-
const { next, app,
|
|
1620
|
-
if (
|
|
1744
|
+
const { next, app, microfrontend } = args;
|
|
1745
|
+
if (microfrontend instanceof MicrofrontendChildConfig) {
|
|
1621
1746
|
console.warn(
|
|
1622
1747
|
"server actions transform requires the full config - skipping"
|
|
1623
1748
|
);
|
|
@@ -1625,12 +1750,12 @@ function transform5(args) {
|
|
|
1625
1750
|
next
|
|
1626
1751
|
};
|
|
1627
1752
|
}
|
|
1628
|
-
const defaultApplication =
|
|
1753
|
+
const defaultApplication = microfrontend.getDefaultApplication();
|
|
1629
1754
|
const appsToAllow = [
|
|
1630
1755
|
// this zone - this is included by default unless allowedOrigins is overridden (which we are)
|
|
1631
1756
|
// so we re-add it here.
|
|
1632
1757
|
app,
|
|
1633
|
-
// this is the default zone for the
|
|
1758
|
+
// this is the default zone for the microfrontend. Allow child zones to call server actions
|
|
1634
1759
|
// that are in the default zone.
|
|
1635
1760
|
defaultApplication
|
|
1636
1761
|
];
|
|
@@ -1647,7 +1772,7 @@ function transform5(args) {
|
|
|
1647
1772
|
defaultApplication.production.toString()
|
|
1648
1773
|
),
|
|
1649
1774
|
formatDomainForServerAction(
|
|
1650
|
-
getDomainForCurrentEnvironment(
|
|
1775
|
+
getDomainForCurrentEnvironment(microfrontend, a.name)
|
|
1651
1776
|
)
|
|
1652
1777
|
])
|
|
1653
1778
|
])
|
|
@@ -1661,7 +1786,7 @@ function transform5(args) {
|
|
|
1661
1786
|
|
|
1662
1787
|
// src/next-v2/config/transforms/webpack.ts
|
|
1663
1788
|
function transform6(args) {
|
|
1664
|
-
const { next,
|
|
1789
|
+
const { next, microfrontend } = args;
|
|
1665
1790
|
const configWithWebpack = {
|
|
1666
1791
|
...next,
|
|
1667
1792
|
webpack(cfg, context) {
|
|
@@ -1670,7 +1795,7 @@ function transform6(args) {
|
|
|
1670
1795
|
if (isServer || nextRuntime === "edge") {
|
|
1671
1796
|
config.plugins.push(
|
|
1672
1797
|
new wpFromNext.EnvironmentPlugin({
|
|
1673
|
-
MFE_CONFIG: JSON.stringify(
|
|
1798
|
+
MFE_CONFIG: JSON.stringify(microfrontend.serialize())
|
|
1674
1799
|
})
|
|
1675
1800
|
);
|
|
1676
1801
|
}
|
|
@@ -1763,26 +1888,26 @@ function getApplicationContext(opts) {
|
|
|
1763
1888
|
return { name: opts.appName };
|
|
1764
1889
|
}
|
|
1765
1890
|
try {
|
|
1766
|
-
const packageJsonString =
|
|
1891
|
+
const packageJsonString = import_node_fs4.default.readFileSync("./package.json", "utf-8");
|
|
1767
1892
|
const packageJson = JSON.parse(packageJsonString);
|
|
1768
1893
|
if (!packageJson.name) {
|
|
1769
|
-
throw new
|
|
1894
|
+
throw new MicrofrontendError(
|
|
1770
1895
|
`package.json file missing required field "name"`,
|
|
1771
1896
|
{
|
|
1772
1897
|
type: "packageJson",
|
|
1773
1898
|
subtype: "missing_field_name",
|
|
1774
|
-
source: "@vercel/
|
|
1899
|
+
source: "@vercel/microfrontends/next"
|
|
1775
1900
|
}
|
|
1776
1901
|
);
|
|
1777
1902
|
}
|
|
1778
1903
|
return { name: packageJson.name };
|
|
1779
1904
|
} catch (err) {
|
|
1780
|
-
throw
|
|
1905
|
+
throw MicrofrontendError.handle(err, {
|
|
1781
1906
|
fileName: "package.json"
|
|
1782
1907
|
});
|
|
1783
1908
|
}
|
|
1784
1909
|
}
|
|
1785
|
-
function
|
|
1910
|
+
function withMicrofrontends(nextConfig, opts) {
|
|
1786
1911
|
var _a;
|
|
1787
1912
|
if (opts == null ? void 0 : opts.debug) {
|
|
1788
1913
|
process.env.MFE_DEBUG = "true";
|
|
@@ -1806,7 +1931,7 @@ function withMicroFrontends(nextConfig, opts) {
|
|
|
1806
1931
|
const transformedConfig = transform7({
|
|
1807
1932
|
app,
|
|
1808
1933
|
next,
|
|
1809
|
-
|
|
1934
|
+
microfrontend: microfrontends.config,
|
|
1810
1935
|
opts: {
|
|
1811
1936
|
isProduction: isProduction(opts)
|
|
1812
1937
|
}
|
|
@@ -1824,6 +1949,6 @@ function withMicroFrontends(nextConfig, opts) {
|
|
|
1824
1949
|
}
|
|
1825
1950
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1826
1951
|
0 && (module.exports = {
|
|
1827
|
-
|
|
1952
|
+
withMicrofrontends
|
|
1828
1953
|
});
|
|
1829
1954
|
//# sourceMappingURL=config.cjs.map
|