@vercel/microfrontends 0.9.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 +202 -0
- package/cli/index.cjs +21 -0
- package/dist/bin/cli.cjs +1604 -0
- package/dist/config/client.cjs +54 -0
- package/dist/config/client.cjs.map +1 -0
- package/dist/config/client.d.ts +23 -0
- package/dist/config/client.js +28 -0
- package/dist/config/client.js.map +1 -0
- package/dist/config/edge.cjs +508 -0
- package/dist/config/edge.cjs.map +1 -0
- package/dist/config/edge.d.ts +20 -0
- package/dist/config/edge.js +481 -0
- package/dist/config/edge.js.map +1 -0
- package/dist/config.cjs +1254 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.js +1212 -0
- package/dist/config.js.map +1 -0
- package/dist/index-eff254d8.d.ts +175 -0
- package/dist/micro-frontend-config-42886104.d.ts +154 -0
- package/dist/next/client.cjs +3 -0
- package/dist/next/client.cjs.map +1 -0
- package/dist/next/client.d.ts +45 -0
- package/dist/next/client.js +3 -0
- package/dist/next/client.js.map +1 -0
- package/dist/next/config.cjs +1793 -0
- package/dist/next/config.cjs.map +1 -0
- package/dist/next/config.d.ts +22 -0
- package/dist/next/config.js +1758 -0
- package/dist/next/config.js.map +1 -0
- package/dist/next/endpoints.cjs +82 -0
- package/dist/next/endpoints.cjs.map +1 -0
- package/dist/next/endpoints.d.ts +15 -0
- package/dist/next/endpoints.js +57 -0
- package/dist/next/endpoints.js.map +1 -0
- package/dist/next/middleware.cjs +763 -0
- package/dist/next/middleware.cjs.map +1 -0
- package/dist/next/middleware.d.ts +29 -0
- package/dist/next/middleware.js +735 -0
- package/dist/next/middleware.js.map +1 -0
- package/dist/next/testing.cjs +1430 -0
- package/dist/next/testing.cjs.map +1 -0
- package/dist/next/testing.d.ts +53 -0
- package/dist/next/testing.js +1389 -0
- package/dist/next/testing.js.map +1 -0
- package/dist/overrides.cjs +143 -0
- package/dist/overrides.cjs.map +1 -0
- package/dist/overrides.d.ts +2 -0
- package/dist/overrides.js +115 -0
- package/dist/overrides.js.map +1 -0
- package/dist/schema-83a75e61.d.ts +188 -0
- package/dist/types-4fd1c7c6.d.ts +157 -0
- package/dist/v2/config.cjs +720 -0
- package/dist/v2/config.cjs.map +1 -0
- package/dist/v2/config.d.ts +2 -0
- package/dist/v2/config.js +695 -0
- package/dist/v2/config.js.map +1 -0
- package/dist/v2/microfrontends/server.cjs +1312 -0
- package/dist/v2/microfrontends/server.cjs.map +1 -0
- package/dist/v2/microfrontends/server.d.ts +48 -0
- package/dist/v2/microfrontends/server.js +1277 -0
- package/dist/v2/microfrontends/server.js.map +1 -0
- package/dist/v2/microfrontends.cjs +803 -0
- package/dist/v2/microfrontends.cjs.map +1 -0
- package/dist/v2/microfrontends.d.ts +44 -0
- package/dist/v2/microfrontends.js +776 -0
- package/dist/v2/microfrontends.js.map +1 -0
- package/dist/v2/next/client.cjs +3 -0
- package/dist/v2/next/client.cjs.map +1 -0
- package/dist/v2/next/client.d.ts +45 -0
- package/dist/v2/next/client.js +3 -0
- package/dist/v2/next/client.js.map +1 -0
- package/dist/v2/next/config.cjs +1829 -0
- package/dist/v2/next/config.cjs.map +1 -0
- package/dist/v2/next/config.d.ts +22 -0
- package/dist/v2/next/config.js +1794 -0
- package/dist/v2/next/config.js.map +1 -0
- package/dist/v2/next/endpoints.cjs +138 -0
- package/dist/v2/next/endpoints.cjs.map +1 -0
- package/dist/v2/next/endpoints.d.ts +15 -0
- package/dist/v2/next/endpoints.js +113 -0
- package/dist/v2/next/endpoints.js.map +1 -0
- package/dist/v2/next/middleware.cjs +1110 -0
- package/dist/v2/next/middleware.cjs.map +1 -0
- package/dist/v2/next/middleware.d.ts +29 -0
- package/dist/v2/next/middleware.js +1082 -0
- package/dist/v2/next/middleware.js.map +1 -0
- package/dist/v2/schema.cjs +19 -0
- package/dist/v2/schema.cjs.map +1 -0
- package/dist/v2/schema.d.ts +1 -0
- package/dist/v2/schema.js +1 -0
- package/dist/v2/schema.js.map +1 -0
- package/dist/validation.cjs +754 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.ts +163 -0
- package/dist/validation.js +726 -0
- package/dist/validation.js.map +1 -0
- package/package.json +204 -0
- package/schema/schema-v2.json +288 -0
- package/schema/schema.json +352 -0
|
@@ -0,0 +1,1793 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/next/config/index.ts
|
|
31
|
+
var config_exports = {};
|
|
32
|
+
__export(config_exports, {
|
|
33
|
+
withMicroFrontends: () => withMicroFrontends
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(config_exports);
|
|
36
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
37
|
+
|
|
38
|
+
// src/config/micro-frontend-config.ts
|
|
39
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
40
|
+
|
|
41
|
+
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
42
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
43
|
+
|
|
44
|
+
// src/config-v2/microfrontends/server/constants.ts
|
|
45
|
+
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
46
|
+
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
47
|
+
|
|
48
|
+
// src/utils/is-vercel.ts
|
|
49
|
+
function isVercel() {
|
|
50
|
+
return process.env.VERCEL === "1";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
54
|
+
function getOutputFilePath() {
|
|
55
|
+
if (isVercel()) {
|
|
56
|
+
return import_node_path.default.join(
|
|
57
|
+
".vercel",
|
|
58
|
+
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
59
|
+
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return import_node_path.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/config/errors.ts
|
|
66
|
+
var MicroFrontendError = class extends Error {
|
|
67
|
+
constructor(message, opts) {
|
|
68
|
+
super(message);
|
|
69
|
+
this.name = "MicroFrontendsError";
|
|
70
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
|
|
71
|
+
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
72
|
+
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
73
|
+
Error.captureStackTrace(this, MicroFrontendError);
|
|
74
|
+
}
|
|
75
|
+
isKnown() {
|
|
76
|
+
return this.type !== "unknown";
|
|
77
|
+
}
|
|
78
|
+
isUnknown() {
|
|
79
|
+
return !this.isKnown();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Converts an error to a MicroFrontendsError.
|
|
83
|
+
* @param original - The original error to convert.
|
|
84
|
+
* @returns The converted MicroFrontendsError.
|
|
85
|
+
*/
|
|
86
|
+
static convert(original, opts) {
|
|
87
|
+
if (opts == null ? void 0 : opts.fileName) {
|
|
88
|
+
const err = MicroFrontendError.convertFSError(original, opts.fileName);
|
|
89
|
+
if (err) {
|
|
90
|
+
return err;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (original.message.includes(
|
|
94
|
+
"Code generation from strings disallowed for this context"
|
|
95
|
+
)) {
|
|
96
|
+
return new MicroFrontendError(original.message, {
|
|
97
|
+
type: "config",
|
|
98
|
+
subtype: "unsupported_validation_env",
|
|
99
|
+
source: "ajv"
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return new MicroFrontendError(original.message);
|
|
103
|
+
}
|
|
104
|
+
static convertFSError(original, fileName) {
|
|
105
|
+
if (original instanceof Error && "code" in original) {
|
|
106
|
+
if (original.code === "ENOENT") {
|
|
107
|
+
return new MicroFrontendError(`Could not find "${fileName}"`, {
|
|
108
|
+
type: "config",
|
|
109
|
+
subtype: "unable_to_read_file",
|
|
110
|
+
source: "fs"
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (original.code === "EACCES") {
|
|
114
|
+
return new MicroFrontendError(
|
|
115
|
+
`Permission denied while accessing "${fileName}"`,
|
|
116
|
+
{
|
|
117
|
+
type: "config",
|
|
118
|
+
subtype: "invalid_permissions",
|
|
119
|
+
source: "fs"
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (original instanceof SyntaxError) {
|
|
125
|
+
return new MicroFrontendError(
|
|
126
|
+
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
127
|
+
{
|
|
128
|
+
type: "config",
|
|
129
|
+
subtype: "invalid_syntax",
|
|
130
|
+
source: "fs"
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Handles an unknown error and returns a MicroFrontendsError instance.
|
|
138
|
+
* @param err - The error to handle.
|
|
139
|
+
* @returns A MicroFrontendsError instance.
|
|
140
|
+
*/
|
|
141
|
+
static handle(err, opts) {
|
|
142
|
+
if (err instanceof MicroFrontendError) {
|
|
143
|
+
return err;
|
|
144
|
+
}
|
|
145
|
+
if (err instanceof Error) {
|
|
146
|
+
return MicroFrontendError.convert(err, opts);
|
|
147
|
+
}
|
|
148
|
+
if (typeof err === "object" && err !== null) {
|
|
149
|
+
if ("message" in err && typeof err.message === "string") {
|
|
150
|
+
return MicroFrontendError.convert(new Error(err.message), opts);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return new MicroFrontendError("An unknown error occurred");
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/routing/url.ts
|
|
158
|
+
function buildUrlSafeString(givenOpts = {}) {
|
|
159
|
+
const options = {
|
|
160
|
+
joinString: "-",
|
|
161
|
+
lowercaseOnly: true,
|
|
162
|
+
maxLen: 100,
|
|
163
|
+
regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,
|
|
164
|
+
trimWhitespace: true,
|
|
165
|
+
...givenOpts
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
generate: (...args) => {
|
|
169
|
+
const reJoinString = new RegExp(`${options.joinString}+`, "g");
|
|
170
|
+
let tag;
|
|
171
|
+
if (args.length === 0) {
|
|
172
|
+
throw new Error("generate method must be passed at least one argument");
|
|
173
|
+
}
|
|
174
|
+
for (let i = 0; i < args.length; i++) {
|
|
175
|
+
const arg = args[i];
|
|
176
|
+
if (typeof arg !== "string")
|
|
177
|
+
throw new Error("all supplied arguments must be Strings");
|
|
178
|
+
if (options.trimWhitespace) {
|
|
179
|
+
args[i] = arg.trim();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
tag = args.join(options.joinString);
|
|
183
|
+
tag = tag.replace(/\s/g, options.joinString);
|
|
184
|
+
if (options.lowercaseOnly)
|
|
185
|
+
tag = tag.toLowerCase();
|
|
186
|
+
tag = tag.replace(options.regexRemovePattern, (match) => {
|
|
187
|
+
if (match === options.joinString)
|
|
188
|
+
return match;
|
|
189
|
+
return "";
|
|
190
|
+
});
|
|
191
|
+
if (tag.length > options.maxLen)
|
|
192
|
+
tag = tag.substring(0, options.maxLen);
|
|
193
|
+
tag = tag.replace(reJoinString, options.joinString);
|
|
194
|
+
return tag;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
var urlSafeString = buildUrlSafeString().generate;
|
|
199
|
+
function makeUrlSafe(name) {
|
|
200
|
+
return urlSafeString(name.replace(/\//g, "-")).replace(/^-*/g, "").replace(/-*$/g, "");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/config/overrides/config.ts
|
|
204
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
205
|
+
var _Overrides = class {
|
|
206
|
+
constructor(config) {
|
|
207
|
+
this.config = config;
|
|
208
|
+
}
|
|
209
|
+
static getAppEnvOverrideCookieName(zone) {
|
|
210
|
+
return `${_Overrides.overrideEnvCookiePrefix}${zone}`;
|
|
211
|
+
}
|
|
212
|
+
static isOverrideCookie(cookie) {
|
|
213
|
+
var _a;
|
|
214
|
+
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
215
|
+
}
|
|
216
|
+
static getOverrideFromCookie(cookie) {
|
|
217
|
+
if (!_Overrides.isOverrideCookie(cookie) || !cookie.value)
|
|
218
|
+
return;
|
|
219
|
+
return {
|
|
220
|
+
zone: cookie.name.replace(_Overrides.overrideEnvCookiePrefix, ""),
|
|
221
|
+
host: cookie.value
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
static parseOverrides(cookies) {
|
|
225
|
+
const overridesConfig = { applications: {} };
|
|
226
|
+
cookies.forEach((cookie) => {
|
|
227
|
+
const override = _Overrides.getOverrideFromCookie(cookie);
|
|
228
|
+
if (!override)
|
|
229
|
+
return;
|
|
230
|
+
overridesConfig.applications[override.zone] = {
|
|
231
|
+
environment: { host: override.host }
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
return overridesConfig;
|
|
235
|
+
}
|
|
236
|
+
static validOverrideDomainsForZone(microFrontendConfig, zone) {
|
|
237
|
+
var _a, _b, _c, _d, _e;
|
|
238
|
+
const projectName = (_a = microFrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
239
|
+
if (!projectName) {
|
|
240
|
+
return [microFrontendConfig.getZone(zone).production.host];
|
|
241
|
+
}
|
|
242
|
+
const parsedProjectName = makeUrlSafe(projectName);
|
|
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
|
+
if (!teamSlug && !previewDeploymentSuffix) {
|
|
246
|
+
return [microFrontendConfig.getZone(zone).production.host];
|
|
247
|
+
}
|
|
248
|
+
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
249
|
+
return [
|
|
250
|
+
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
251
|
+
microFrontendConfig.getZone(zone).production.host
|
|
252
|
+
];
|
|
253
|
+
}
|
|
254
|
+
static validateOverrideDomain(microFrontendConfig, zone, domain) {
|
|
255
|
+
return new RegExp(
|
|
256
|
+
`^${_Overrides.validOverrideDomainsForZone(microFrontendConfig, zone).join(
|
|
257
|
+
"|"
|
|
258
|
+
)}$`
|
|
259
|
+
).test(domain);
|
|
260
|
+
}
|
|
261
|
+
serialize() {
|
|
262
|
+
return this.config;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var Overrides = _Overrides;
|
|
266
|
+
Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
267
|
+
|
|
268
|
+
// src/config/common/host.ts
|
|
269
|
+
var Host = class {
|
|
270
|
+
constructor({ protocol, host, port }) {
|
|
271
|
+
this.protocol = protocol || "https";
|
|
272
|
+
this.host = host;
|
|
273
|
+
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
274
|
+
this.serialized = {
|
|
275
|
+
protocol,
|
|
276
|
+
host,
|
|
277
|
+
...port ? { port } : void 0
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
isLocal() {
|
|
281
|
+
return this.host === "localhost" || this.host === "127.0.0.1";
|
|
282
|
+
}
|
|
283
|
+
static getPort({
|
|
284
|
+
protocol,
|
|
285
|
+
port
|
|
286
|
+
}) {
|
|
287
|
+
if (!port) {
|
|
288
|
+
if (protocol === "http") {
|
|
289
|
+
return 80;
|
|
290
|
+
}
|
|
291
|
+
return 443;
|
|
292
|
+
}
|
|
293
|
+
return port;
|
|
294
|
+
}
|
|
295
|
+
isDefaultPort() {
|
|
296
|
+
return this.port === Host.getPort({ protocol: this.protocol });
|
|
297
|
+
}
|
|
298
|
+
toString(opts = {}) {
|
|
299
|
+
const url = this.toUrl(opts);
|
|
300
|
+
return url.toString().replace(/\/$/, "");
|
|
301
|
+
}
|
|
302
|
+
toUrl(opts = {}) {
|
|
303
|
+
const { includeDefaultPort } = opts;
|
|
304
|
+
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
305
|
+
return new URL(url);
|
|
306
|
+
}
|
|
307
|
+
serialize() {
|
|
308
|
+
return this.serialized;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// src/config/common/application.ts
|
|
313
|
+
var Application = class {
|
|
314
|
+
constructor(name, {
|
|
315
|
+
app,
|
|
316
|
+
overrides
|
|
317
|
+
}) {
|
|
318
|
+
Application.validate(name, app);
|
|
319
|
+
this.name = name;
|
|
320
|
+
this.default = app.default;
|
|
321
|
+
this.routing = app.routing;
|
|
322
|
+
this.development = {
|
|
323
|
+
local: new Host(app.development.local),
|
|
324
|
+
fallback: app.development.fallback ? new Host(app.development.fallback) : void 0
|
|
325
|
+
};
|
|
326
|
+
this.production = new Host(app.production);
|
|
327
|
+
this.vercel = app.vercel;
|
|
328
|
+
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
329
|
+
environment: new Host(overrides.environment)
|
|
330
|
+
} : void 0;
|
|
331
|
+
}
|
|
332
|
+
isDefault() {
|
|
333
|
+
return this.default;
|
|
334
|
+
}
|
|
335
|
+
static validate(name, app) {
|
|
336
|
+
var _a, _b, _c, _d, _e;
|
|
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 MicroFrontendError(
|
|
339
|
+
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
340
|
+
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
for (const group of ((_e = app.routing) == null ? void 0 : _e.matches) ?? []) {
|
|
344
|
+
for (const p of group.paths) {
|
|
345
|
+
if (p === "/") {
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (p.endsWith("/")) {
|
|
349
|
+
throw new MicroFrontendError(
|
|
350
|
+
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
351
|
+
{ type: "zone", subtype: "invalid_path" }
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
if (!p.startsWith("/")) {
|
|
355
|
+
throw new MicroFrontendError(
|
|
356
|
+
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
357
|
+
{ type: "zone", subtype: "invalid_path" }
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
serialize() {
|
|
364
|
+
var _a, _b;
|
|
365
|
+
if (this.routing === void 0 || this.default) {
|
|
366
|
+
return {
|
|
367
|
+
default: true,
|
|
368
|
+
development: {
|
|
369
|
+
local: this.development.local.serialize(),
|
|
370
|
+
fallback: (_a = this.development.fallback) == null ? void 0 : _a.serialize()
|
|
371
|
+
},
|
|
372
|
+
production: this.production.serialize(),
|
|
373
|
+
vercel: this.vercel
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
default: false,
|
|
378
|
+
routing: this.routing,
|
|
379
|
+
development: {
|
|
380
|
+
local: this.development.local.serialize(),
|
|
381
|
+
fallback: (_b = this.development.fallback) == null ? void 0 : _b.serialize()
|
|
382
|
+
},
|
|
383
|
+
production: this.production.serialize(),
|
|
384
|
+
vercel: this.vercel
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// src/config/common/micro-frontend-config.ts
|
|
390
|
+
var SUPPORTED_VERSIONS = ["1"];
|
|
391
|
+
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
392
|
+
var MicroFrontendConfigCommon = class {
|
|
393
|
+
constructor({
|
|
394
|
+
config,
|
|
395
|
+
overrides
|
|
396
|
+
}) {
|
|
397
|
+
this.zones = {};
|
|
398
|
+
var _a, _b, _c;
|
|
399
|
+
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
400
|
+
throw new MicroFrontendError(
|
|
401
|
+
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
402
|
+
", "
|
|
403
|
+
)}`,
|
|
404
|
+
{ type: "config", subtype: "unsupported_version" }
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
408
|
+
this.overrides = overrides && !disableOverrides ? new Overrides(overrides) : void 0;
|
|
409
|
+
for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {
|
|
410
|
+
this.zones[zoneName] = new Application(zoneName, {
|
|
411
|
+
app: zoneConfig,
|
|
412
|
+
overrides: !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.config.applications[zoneName] : void 0
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
this.config = config;
|
|
416
|
+
this.name = config.name;
|
|
417
|
+
this.version = config.version;
|
|
418
|
+
this.options = config.options;
|
|
419
|
+
this.$schema = config.$schema;
|
|
420
|
+
}
|
|
421
|
+
isOverridesDisabled() {
|
|
422
|
+
var _a, _b;
|
|
423
|
+
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
424
|
+
}
|
|
425
|
+
static getConfigFromEnv() {
|
|
426
|
+
const config = process.env.MFE_CONFIG;
|
|
427
|
+
if (!config) {
|
|
428
|
+
throw new MicroFrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
429
|
+
type: "config",
|
|
430
|
+
subtype: "not_found_in_env"
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
return config;
|
|
434
|
+
}
|
|
435
|
+
static fromEnv(_) {
|
|
436
|
+
throw new Error("Not implemented");
|
|
437
|
+
}
|
|
438
|
+
getConfig() {
|
|
439
|
+
return this.config;
|
|
440
|
+
}
|
|
441
|
+
getAllApplications() {
|
|
442
|
+
return Object.values(this.zones);
|
|
443
|
+
}
|
|
444
|
+
getZone(name) {
|
|
445
|
+
const zone = this.zones[name];
|
|
446
|
+
if (!zone) {
|
|
447
|
+
throw new MicroFrontendError(
|
|
448
|
+
`Could not find micro-frontends configuration for application "${name}"`,
|
|
449
|
+
{
|
|
450
|
+
type: "zone",
|
|
451
|
+
subtype: "not_found"
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
return zone;
|
|
456
|
+
}
|
|
457
|
+
getApplicationByProjectId(projectId) {
|
|
458
|
+
return Object.values(this.zones).find(
|
|
459
|
+
(zone) => {
|
|
460
|
+
var _a;
|
|
461
|
+
return ((_a = zone.vercel) == null ? void 0 : _a.projectId) === projectId;
|
|
462
|
+
}
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
getDefaultZone() {
|
|
466
|
+
const zone = Object.values(this.zones).find((z) => z.default);
|
|
467
|
+
if (!zone) {
|
|
468
|
+
throw new MicroFrontendError(
|
|
469
|
+
`Could not find default zone in micro-frontends configuration`,
|
|
470
|
+
{
|
|
471
|
+
type: "zone",
|
|
472
|
+
subtype: "not_found"
|
|
473
|
+
}
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
return zone;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Returns the configured port for the local proxy
|
|
480
|
+
*/
|
|
481
|
+
getLocalProxyPort() {
|
|
482
|
+
var _a, _b;
|
|
483
|
+
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Serializes the class back to the Schema type.
|
|
487
|
+
*
|
|
488
|
+
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
489
|
+
*/
|
|
490
|
+
toSchemaJson() {
|
|
491
|
+
const applications = {};
|
|
492
|
+
for (const [name, zone] of Object.entries(this.zones)) {
|
|
493
|
+
applications[name] = zone.serialize();
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
$schema: this.$schema,
|
|
497
|
+
name: this.name,
|
|
498
|
+
version: this.version,
|
|
499
|
+
options: this.options,
|
|
500
|
+
applications
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
serialize() {
|
|
504
|
+
var _a;
|
|
505
|
+
const applications = {};
|
|
506
|
+
for (const [name, zone] of Object.entries(this.zones)) {
|
|
507
|
+
applications[name] = zone.serialize();
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
config: {
|
|
511
|
+
name: this.name,
|
|
512
|
+
version: this.version,
|
|
513
|
+
applications,
|
|
514
|
+
options: this.options,
|
|
515
|
+
$schema: this.$schema
|
|
516
|
+
},
|
|
517
|
+
overrides: (_a = this.overrides) == null ? void 0 : _a.serialize()
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
write(_) {
|
|
521
|
+
throw new MicroFrontendError(
|
|
522
|
+
`Writing to file to disk requires using an instance of "MicroFrontendConfig".`,
|
|
523
|
+
{ type: "config", subtype: "unsupported_operation" }
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// src/config/utils/get-output-file-path.ts
|
|
529
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
530
|
+
|
|
531
|
+
// src/config/constants.ts
|
|
532
|
+
var MFE_CONFIG_DEFAULT_FILE_PATH2 = "micro-frontends";
|
|
533
|
+
var MFE_CONFIG_DEFAULT_FILE_NAME2 = "micro-frontends.config.json";
|
|
534
|
+
|
|
535
|
+
// src/config/utils/get-output-file-path.ts
|
|
536
|
+
function getOutputFilePath2() {
|
|
537
|
+
if (isVercel()) {
|
|
538
|
+
return import_node_path2.default.join(
|
|
539
|
+
".vercel",
|
|
540
|
+
MFE_CONFIG_DEFAULT_FILE_PATH2,
|
|
541
|
+
MFE_CONFIG_DEFAULT_FILE_NAME2
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
return import_node_path2.default.join(MFE_CONFIG_DEFAULT_FILE_PATH2, MFE_CONFIG_DEFAULT_FILE_NAME2);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/config/validation.ts
|
|
548
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
549
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
550
|
+
var import_ajv = require("ajv");
|
|
551
|
+
|
|
552
|
+
// src/config/types.ts
|
|
553
|
+
var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
|
|
554
|
+
|
|
555
|
+
// schema/schema.json
|
|
556
|
+
var schema_default = {
|
|
557
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
558
|
+
$ref: "#/definitions/Config",
|
|
559
|
+
definitions: {
|
|
560
|
+
Config: {
|
|
561
|
+
type: "object",
|
|
562
|
+
properties: {
|
|
563
|
+
version: {
|
|
564
|
+
type: "string"
|
|
565
|
+
},
|
|
566
|
+
$schema: {
|
|
567
|
+
type: "string"
|
|
568
|
+
},
|
|
569
|
+
name: {
|
|
570
|
+
type: "string",
|
|
571
|
+
description: 'Name for the micro-frontend site (eg. "vercel.com", "vercel-site" etc.).'
|
|
572
|
+
},
|
|
573
|
+
applications: {
|
|
574
|
+
$ref: "#/definitions/ApplicationConfigsById"
|
|
575
|
+
},
|
|
576
|
+
options: {
|
|
577
|
+
$ref: "#/definitions/Options",
|
|
578
|
+
description: "Optional configuration for the entire micro-frontends setup."
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
required: ["version", "applications"],
|
|
582
|
+
description: "Configuration for micro-frontend applications\n\nTODO: Add proxy configuration"
|
|
583
|
+
},
|
|
584
|
+
ApplicationConfigsById: {
|
|
585
|
+
type: "object",
|
|
586
|
+
additionalProperties: {
|
|
587
|
+
$ref: "#/definitions/ApplicationConfig"
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
ApplicationConfig: {
|
|
591
|
+
anyOf: [
|
|
592
|
+
{
|
|
593
|
+
$ref: "#/definitions/DefaultApplicationConfig"
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
$ref: "#/definitions/CommonApplicationConfig"
|
|
597
|
+
}
|
|
598
|
+
],
|
|
599
|
+
description: "A Micro-Frontend Deployment Target"
|
|
600
|
+
},
|
|
601
|
+
DefaultApplicationConfig: {
|
|
602
|
+
type: "object",
|
|
603
|
+
properties: {
|
|
604
|
+
default: {
|
|
605
|
+
type: "boolean",
|
|
606
|
+
const: true,
|
|
607
|
+
description: "The default application is used no other application is matched via the routing config"
|
|
608
|
+
},
|
|
609
|
+
routing: {
|
|
610
|
+
$ref: "#/definitions/Routing"
|
|
611
|
+
},
|
|
612
|
+
development: {
|
|
613
|
+
type: "object",
|
|
614
|
+
properties: {
|
|
615
|
+
local: {
|
|
616
|
+
$ref: "#/definitions/HostConfig"
|
|
617
|
+
},
|
|
618
|
+
fallback: {
|
|
619
|
+
$ref: "#/definitions/HostConfig",
|
|
620
|
+
description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error."
|
|
621
|
+
},
|
|
622
|
+
task: {
|
|
623
|
+
type: "string",
|
|
624
|
+
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
625
|
+
}
|
|
626
|
+
},
|
|
627
|
+
required: ["local"]
|
|
628
|
+
},
|
|
629
|
+
production: {
|
|
630
|
+
$ref: "#/definitions/HostConfig"
|
|
631
|
+
},
|
|
632
|
+
metadata: {
|
|
633
|
+
type: "object",
|
|
634
|
+
additionalProperties: {
|
|
635
|
+
type: "string"
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
federation: {
|
|
639
|
+
type: "object",
|
|
640
|
+
properties: {
|
|
641
|
+
exposes: {
|
|
642
|
+
type: "array",
|
|
643
|
+
items: {
|
|
644
|
+
type: "object",
|
|
645
|
+
properties: {
|
|
646
|
+
name: {
|
|
647
|
+
type: "string",
|
|
648
|
+
description: "The name of the module - should be used when importing the module from another application"
|
|
649
|
+
},
|
|
650
|
+
path: {
|
|
651
|
+
type: "string",
|
|
652
|
+
description: "Relative path to the module within its `application`"
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
required: ["name", "path"]
|
|
656
|
+
},
|
|
657
|
+
description: "Modules that are exposed by this application"
|
|
658
|
+
},
|
|
659
|
+
uses: {
|
|
660
|
+
type: "array",
|
|
661
|
+
items: {
|
|
662
|
+
type: "string"
|
|
663
|
+
},
|
|
664
|
+
description: "Modules that are used by this application. Only the name of the module is required."
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
vercel: {
|
|
669
|
+
$ref: "#/definitions/Vercel"
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
required: ["default", "development", "production"]
|
|
673
|
+
},
|
|
674
|
+
Routing: {
|
|
675
|
+
type: "object",
|
|
676
|
+
properties: {
|
|
677
|
+
assetPrefix: {
|
|
678
|
+
type: "string",
|
|
679
|
+
description: "[assetPrefix] for the application"
|
|
680
|
+
},
|
|
681
|
+
matches: {
|
|
682
|
+
type: "array",
|
|
683
|
+
items: {
|
|
684
|
+
$ref: "#/definitions/PathGroup"
|
|
685
|
+
},
|
|
686
|
+
description: "Path expressions that are routed to this application."
|
|
687
|
+
}
|
|
688
|
+
},
|
|
689
|
+
required: ["matches"]
|
|
690
|
+
},
|
|
691
|
+
PathGroup: {
|
|
692
|
+
type: "object",
|
|
693
|
+
properties: {
|
|
694
|
+
group: {
|
|
695
|
+
type: "string",
|
|
696
|
+
description: "Optional group name for the paths"
|
|
697
|
+
},
|
|
698
|
+
options: {
|
|
699
|
+
type: "object",
|
|
700
|
+
properties: {
|
|
701
|
+
flag: {
|
|
702
|
+
type: "string",
|
|
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
|
+
}
|
|
709
|
+
}
|
|
710
|
+
},
|
|
711
|
+
paths: {
|
|
712
|
+
type: "array",
|
|
713
|
+
items: {
|
|
714
|
+
type: "string"
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
},
|
|
718
|
+
required: ["paths"]
|
|
719
|
+
},
|
|
720
|
+
HostConfig: {
|
|
721
|
+
type: "object",
|
|
722
|
+
properties: {
|
|
723
|
+
protocol: {
|
|
724
|
+
type: "string",
|
|
725
|
+
enum: ["http", "https"],
|
|
726
|
+
description: 'The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n* @defaultValue "https"'
|
|
727
|
+
},
|
|
728
|
+
host: {
|
|
729
|
+
type: "string",
|
|
730
|
+
description: "The hostname or IP address of the server. This can be a domain name (e.g., `example.com`) or an IP address (e.g., `192.168.1.1`)."
|
|
731
|
+
},
|
|
732
|
+
port: {
|
|
733
|
+
type: "number",
|
|
734
|
+
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS.\n\nThis field is optional and can be omitted if the default ports for the specified protocol are used"
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
required: ["host"]
|
|
738
|
+
},
|
|
739
|
+
Vercel: {
|
|
740
|
+
type: "object",
|
|
741
|
+
properties: {
|
|
742
|
+
projectId: {
|
|
743
|
+
type: "string",
|
|
744
|
+
description: "Vercel project ID"
|
|
745
|
+
},
|
|
746
|
+
projectName: {
|
|
747
|
+
type: "string",
|
|
748
|
+
description: "Vercel project name (temporary until we can use project ID)"
|
|
749
|
+
},
|
|
750
|
+
defaultRoute: {
|
|
751
|
+
type: "string",
|
|
752
|
+
description: "The default route for the application. Used to render screenshots, favicons, and provide direct zone links"
|
|
753
|
+
},
|
|
754
|
+
routeSpeedInsightsToDefaultZone: {
|
|
755
|
+
type: "boolean",
|
|
756
|
+
description: "Whether to route Speed Insights to the default zone or each individual microfrontend."
|
|
757
|
+
}
|
|
758
|
+
},
|
|
759
|
+
required: ["projectId"]
|
|
760
|
+
},
|
|
761
|
+
CommonApplicationConfig: {
|
|
762
|
+
type: "object",
|
|
763
|
+
properties: {
|
|
764
|
+
default: {
|
|
765
|
+
type: "boolean",
|
|
766
|
+
const: false,
|
|
767
|
+
description: "The default application is used no other application is matched via the routing config"
|
|
768
|
+
},
|
|
769
|
+
routing: {
|
|
770
|
+
$ref: "#/definitions/Routing"
|
|
771
|
+
},
|
|
772
|
+
development: {
|
|
773
|
+
type: "object",
|
|
774
|
+
properties: {
|
|
775
|
+
local: {
|
|
776
|
+
$ref: "#/definitions/HostConfig"
|
|
777
|
+
},
|
|
778
|
+
fallback: {
|
|
779
|
+
$ref: "#/definitions/HostConfig",
|
|
780
|
+
description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error."
|
|
781
|
+
},
|
|
782
|
+
task: {
|
|
783
|
+
type: "string",
|
|
784
|
+
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
required: ["local"]
|
|
788
|
+
},
|
|
789
|
+
production: {
|
|
790
|
+
$ref: "#/definitions/HostConfig"
|
|
791
|
+
},
|
|
792
|
+
metadata: {
|
|
793
|
+
type: "object",
|
|
794
|
+
additionalProperties: {
|
|
795
|
+
type: "string"
|
|
796
|
+
}
|
|
797
|
+
},
|
|
798
|
+
federation: {
|
|
799
|
+
type: "object",
|
|
800
|
+
properties: {
|
|
801
|
+
exposes: {
|
|
802
|
+
type: "array",
|
|
803
|
+
items: {
|
|
804
|
+
type: "object",
|
|
805
|
+
properties: {
|
|
806
|
+
name: {
|
|
807
|
+
type: "string",
|
|
808
|
+
description: "The name of the module - should be used when importing the module from another application"
|
|
809
|
+
},
|
|
810
|
+
path: {
|
|
811
|
+
type: "string",
|
|
812
|
+
description: "Relative path to the module within its `application`"
|
|
813
|
+
}
|
|
814
|
+
},
|
|
815
|
+
required: ["name", "path"]
|
|
816
|
+
},
|
|
817
|
+
description: "Modules that are exposed by this application"
|
|
818
|
+
},
|
|
819
|
+
uses: {
|
|
820
|
+
type: "array",
|
|
821
|
+
items: {
|
|
822
|
+
type: "string"
|
|
823
|
+
},
|
|
824
|
+
description: "Modules that are used by this application. Only the name of the module is required."
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
},
|
|
828
|
+
vercel: {
|
|
829
|
+
$ref: "#/definitions/Vercel"
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
required: ["default", "development", "production", "routing"]
|
|
833
|
+
},
|
|
834
|
+
Options: {
|
|
835
|
+
type: "object",
|
|
836
|
+
properties: {
|
|
837
|
+
vercel: {
|
|
838
|
+
$ref: "#/definitions/VercelOptions",
|
|
839
|
+
description: "Micro-Frontends wide options for Vercel."
|
|
840
|
+
},
|
|
841
|
+
localProxy: {
|
|
842
|
+
$ref: "#/definitions/LocalProxyOptions",
|
|
843
|
+
description: "Options for local proxy."
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
VercelOptions: {
|
|
848
|
+
type: "object",
|
|
849
|
+
properties: {
|
|
850
|
+
previewDeploymentSuffix: {
|
|
851
|
+
type: "string",
|
|
852
|
+
description: "If your team uses a custom Preview Deployment Suffix, please specify it here. See https://vercel.com/docs/deployments/preview-deployment-suffix. The default is `vercel.app`."
|
|
853
|
+
},
|
|
854
|
+
teamSlug: {
|
|
855
|
+
type: "string",
|
|
856
|
+
description: "Team slug for the Vercel team"
|
|
857
|
+
},
|
|
858
|
+
disableOverrides: {
|
|
859
|
+
type: "boolean",
|
|
860
|
+
description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
},
|
|
864
|
+
LocalProxyOptions: {
|
|
865
|
+
type: "object",
|
|
866
|
+
properties: {
|
|
867
|
+
port: {
|
|
868
|
+
type: "number",
|
|
869
|
+
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
// src/config/utils/load-schema.ts
|
|
877
|
+
var SCHEMA = schema_default;
|
|
878
|
+
|
|
879
|
+
// src/config/validation.ts
|
|
880
|
+
var validateSchema = (configString) => {
|
|
881
|
+
const parsedConfig = (0, import_jsonc_parser.parse)(configString);
|
|
882
|
+
const ajv = new import_ajv.Ajv();
|
|
883
|
+
const validate = ajv.compile(SCHEMA);
|
|
884
|
+
const isValid = validate(parsedConfig);
|
|
885
|
+
if (!isValid) {
|
|
886
|
+
throw new MicroFrontendError(
|
|
887
|
+
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
888
|
+
{ type: "config", subtype: "does_not_match_schema" }
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
return parsedConfig;
|
|
892
|
+
};
|
|
893
|
+
var SUPPORTED_VERSIONS2 = ["1"];
|
|
894
|
+
var validateVersion = (version) => {
|
|
895
|
+
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
896
|
+
throw new MicroFrontendError(
|
|
897
|
+
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
898
|
+
", "
|
|
899
|
+
)}`,
|
|
900
|
+
{ type: "config", subtype: "unsupported_version" }
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
function validateMainPath(applicationConfigsById) {
|
|
905
|
+
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
906
|
+
const { defaultRoute } = app.vercel ?? {};
|
|
907
|
+
if (!defaultRoute) {
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
if (isDefaultApplicationConfig(app)) {
|
|
911
|
+
const pathsWithApp = [];
|
|
912
|
+
for (const [otherId, otherApp] of Object.entries(
|
|
913
|
+
applicationConfigsById
|
|
914
|
+
)) {
|
|
915
|
+
if (isDefaultApplicationConfig(otherApp)) {
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
pathsWithApp.push({
|
|
919
|
+
id: otherId,
|
|
920
|
+
paths: otherApp.routing.matches.flatMap((match) => match.paths)
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
for (const { id: otherId, paths } of pathsWithApp) {
|
|
924
|
+
const isValid = paths.every((path3) => {
|
|
925
|
+
const matcher = (0, import_path_to_regexp.pathToRegexp)(path3);
|
|
926
|
+
return !matcher.test(defaultRoute);
|
|
927
|
+
});
|
|
928
|
+
if (!isValid) {
|
|
929
|
+
throw new MicroFrontendError(
|
|
930
|
+
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
931
|
+
{ type: "config", subtype: "invalid_main_path" }
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
} else {
|
|
936
|
+
const allPaths = app.routing.matches.flatMap((match) => match.paths);
|
|
937
|
+
const isValid = allPaths.some((path3) => {
|
|
938
|
+
const matcher = (0, import_path_to_regexp.pathToRegexp)(path3);
|
|
939
|
+
return matcher.test(defaultRoute);
|
|
940
|
+
});
|
|
941
|
+
if (!isValid) {
|
|
942
|
+
throw new MicroFrontendError(
|
|
943
|
+
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
944
|
+
{ type: "config", subtype: "invalid_main_path" }
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
var validatePaths = (applicationConfigsById) => {
|
|
951
|
+
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
952
|
+
const errors = [];
|
|
953
|
+
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
954
|
+
if (isDefaultApplicationConfig(app)) {
|
|
955
|
+
continue;
|
|
956
|
+
}
|
|
957
|
+
for (const pathMatch of app.routing.matches) {
|
|
958
|
+
for (const path3 of pathMatch.paths) {
|
|
959
|
+
const maybeError = validatePathExpression(path3);
|
|
960
|
+
if (maybeError) {
|
|
961
|
+
errors.push(maybeError);
|
|
962
|
+
}
|
|
963
|
+
const existing = pathsByApplicationId.get(path3);
|
|
964
|
+
if (existing) {
|
|
965
|
+
existing.applications.push(id);
|
|
966
|
+
} else {
|
|
967
|
+
pathsByApplicationId.set(path3, {
|
|
968
|
+
applications: [id],
|
|
969
|
+
matcher: (0, import_path_to_regexp.pathToRegexp)(path3),
|
|
970
|
+
applicationId: id
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
const entries = Array.from(pathsByApplicationId.entries());
|
|
977
|
+
entries.forEach(([path3, { applications: ids, matcher, applicationId }]) => {
|
|
978
|
+
if (ids.length > 1) {
|
|
979
|
+
errors.push(
|
|
980
|
+
`Duplicate path "${path3}" for applications "${ids.join(", ")}"`
|
|
981
|
+
);
|
|
982
|
+
}
|
|
983
|
+
entries.forEach(
|
|
984
|
+
([
|
|
985
|
+
matchPath,
|
|
986
|
+
{ applications: matchIds, applicationId: matchApplicationId }
|
|
987
|
+
]) => {
|
|
988
|
+
if (path3 === matchPath) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
if (applicationId === matchApplicationId) {
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
if (matcher.test(matchPath)) {
|
|
995
|
+
const source = `"${path3}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
996
|
+
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
997
|
+
errors.push(
|
|
998
|
+
`Overlapping path detected between ${source} and ${destination}`
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
);
|
|
1003
|
+
});
|
|
1004
|
+
if (errors.length) {
|
|
1005
|
+
throw new MicroFrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1006
|
+
type: "config",
|
|
1007
|
+
subtype: "conflicting_paths"
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
1012
|
+
function validatePathExpression(path3) {
|
|
1013
|
+
const tokens = (0, import_path_to_regexp.parse)(path3);
|
|
1014
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
1015
|
+
const token = tokens[i];
|
|
1016
|
+
if (token === void 0) {
|
|
1017
|
+
return `token ${i} in ${path3} is undefined, this shouldn't happen`;
|
|
1018
|
+
}
|
|
1019
|
+
if (typeof token !== "string") {
|
|
1020
|
+
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
1021
|
+
return `Path ${path3} cannot use a regular expression wildcard`;
|
|
1022
|
+
}
|
|
1023
|
+
if (token.prefix !== "/") {
|
|
1024
|
+
return `Wildcard :${token.name} must be immediately after a / in ${path3}`;
|
|
1025
|
+
}
|
|
1026
|
+
if (token.suffix) {
|
|
1027
|
+
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
1028
|
+
}
|
|
1029
|
+
if (token.modifier && i !== tokens.length - 1) {
|
|
1030
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path3}. Modifiers are only allowed in the last path component`;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
return void 0;
|
|
1035
|
+
}
|
|
1036
|
+
var validateDefaults = (applicationConfigsById) => {
|
|
1037
|
+
const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
|
|
1038
|
+
if (defaultApplicationIds.length === 0) {
|
|
1039
|
+
throw new MicroFrontendError(
|
|
1040
|
+
`No default application found. At least one application must be marked as default.`,
|
|
1041
|
+
{ type: "config", subtype: "no_default_application" }
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
if (defaultApplicationIds.length > 1) {
|
|
1045
|
+
throw new MicroFrontendError(
|
|
1046
|
+
`Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
|
|
1047
|
+
{ type: "config", subtype: "multiple_default_applications" }
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
var validateOptions = (options) => {
|
|
1052
|
+
var _a;
|
|
1053
|
+
if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
|
|
1054
|
+
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1055
|
+
options.vercel.previewDeploymentSuffix
|
|
1056
|
+
)) {
|
|
1057
|
+
throw new MicroFrontendError(
|
|
1058
|
+
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1059
|
+
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
// src/config/utils/convert.ts
|
|
1066
|
+
function convertV1RoutingToV2Routing(routing) {
|
|
1067
|
+
return routing.matches.map((group) => {
|
|
1068
|
+
var _a, _b;
|
|
1069
|
+
return {
|
|
1070
|
+
group: group.group,
|
|
1071
|
+
flag: (_a = group.options) == null ? void 0 : _a.flag,
|
|
1072
|
+
routeToDefaultApplication: (_b = group.options) == null ? void 0 : _b.routeToDefaultApplication,
|
|
1073
|
+
paths: group.paths
|
|
1074
|
+
};
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
function convertV1ApplicationToV2Application(application) {
|
|
1078
|
+
const common = {
|
|
1079
|
+
production: application.production,
|
|
1080
|
+
development: application.development,
|
|
1081
|
+
vercel: application.vercel
|
|
1082
|
+
};
|
|
1083
|
+
if (application.default) {
|
|
1084
|
+
return common;
|
|
1085
|
+
}
|
|
1086
|
+
return {
|
|
1087
|
+
...common,
|
|
1088
|
+
routing: convertV1RoutingToV2Routing(application.routing)
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
function convertV1ConfigToV2Config(config, fromApp) {
|
|
1092
|
+
if (!config.applications[fromApp]) {
|
|
1093
|
+
throw new Error(`Application "${fromApp}" not found in the config`);
|
|
1094
|
+
}
|
|
1095
|
+
const common = {
|
|
1096
|
+
version: "2",
|
|
1097
|
+
options: config.options
|
|
1098
|
+
};
|
|
1099
|
+
if (config.applications[fromApp].default) {
|
|
1100
|
+
return {
|
|
1101
|
+
...common,
|
|
1102
|
+
// this is assumed for now, and by the time this is released we won't need this conversion
|
|
1103
|
+
provider: "vercel",
|
|
1104
|
+
applications: Object.fromEntries(
|
|
1105
|
+
Object.entries(config.applications).map(([id, application]) => [
|
|
1106
|
+
id,
|
|
1107
|
+
convertV1ApplicationToV2Application(application)
|
|
1108
|
+
])
|
|
1109
|
+
)
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
return {
|
|
1113
|
+
...common,
|
|
1114
|
+
partOf: fromApp
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// src/config/utils/write-file.ts
|
|
1119
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
1120
|
+
var import_node_path3 = require("path");
|
|
1121
|
+
function writeFile(outputPath, config, prettify) {
|
|
1122
|
+
import_node_fs.default.mkdirSync((0, import_node_path3.dirname)(outputPath), { recursive: true });
|
|
1123
|
+
import_node_fs.default.writeFileSync(
|
|
1124
|
+
outputPath,
|
|
1125
|
+
JSON.stringify(config, null, prettify ? 2 : void 0)
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// src/config/micro-frontend-config.ts
|
|
1130
|
+
var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
|
|
1131
|
+
static validate(configString) {
|
|
1132
|
+
const config = validateSchema(configString);
|
|
1133
|
+
validateVersion(config.version);
|
|
1134
|
+
validatePaths(config.applications);
|
|
1135
|
+
validateMainPath(config.applications);
|
|
1136
|
+
validateDefaults(config.applications);
|
|
1137
|
+
validateOptions(config.options);
|
|
1138
|
+
return config;
|
|
1139
|
+
}
|
|
1140
|
+
static fromEnv({
|
|
1141
|
+
cookies
|
|
1142
|
+
}) {
|
|
1143
|
+
return new MicroFrontendConfigCommon({
|
|
1144
|
+
config: MicroFrontendConfig.validate(
|
|
1145
|
+
MicroFrontendConfigCommon.getConfigFromEnv()
|
|
1146
|
+
),
|
|
1147
|
+
overrides: Overrides.parseOverrides(cookies)
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
static fromFile({
|
|
1151
|
+
filePath
|
|
1152
|
+
}) {
|
|
1153
|
+
try {
|
|
1154
|
+
const config = import_node_fs2.default.readFileSync(filePath, "utf-8");
|
|
1155
|
+
return new MicroFrontendConfig({
|
|
1156
|
+
config: MicroFrontendConfig.validate(config)
|
|
1157
|
+
});
|
|
1158
|
+
} catch (e) {
|
|
1159
|
+
throw MicroFrontendError.handle(e, {
|
|
1160
|
+
fileName: filePath
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Writes the configuration to a file.
|
|
1166
|
+
*/
|
|
1167
|
+
write(fromApp, opts = {}) {
|
|
1168
|
+
const { pretty = true, versions = ["v1", "v2"] } = opts;
|
|
1169
|
+
const config = this.toSchemaJson();
|
|
1170
|
+
if (versions.includes("v1")) {
|
|
1171
|
+
const outputPath = getOutputFilePath2();
|
|
1172
|
+
writeFile(outputPath, config, pretty);
|
|
1173
|
+
}
|
|
1174
|
+
if (versions.includes("v2")) {
|
|
1175
|
+
const outputPath = getOutputFilePath();
|
|
1176
|
+
const v2Config = convertV1ConfigToV2Config(config, fromApp);
|
|
1177
|
+
writeFile(outputPath, v2Config, pretty);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
|
|
1182
|
+
// src/next/utils/check-proxy.ts
|
|
1183
|
+
function displayLocalProxyInfo(port) {
|
|
1184
|
+
const { MFE_PROXY_MESSAGE_PRINTED, TURBO_TASK_HAS_MFE_PROXY } = process.env;
|
|
1185
|
+
if (TURBO_TASK_HAS_MFE_PROXY === "true" && MFE_PROXY_MESSAGE_PRINTED !== "true") {
|
|
1186
|
+
process.env.MFE_PROXY_MESSAGE_PRINTED = "true";
|
|
1187
|
+
console.log(`Microfrontends Proxy running on http://localhost:${port}`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// src/next/config/transforms/asset-prefix.ts
|
|
1192
|
+
function transform(args) {
|
|
1193
|
+
var _a;
|
|
1194
|
+
const { next, zone } = args;
|
|
1195
|
+
if (!((_a = zone.routing) == null ? void 0 : _a.assetPrefix)) {
|
|
1196
|
+
return {
|
|
1197
|
+
next
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
if (next.assetPrefix !== void 0 && next.assetPrefix !== zone.routing.assetPrefix) {
|
|
1201
|
+
throw new Error(
|
|
1202
|
+
`"assetPrefix" already set. Overwriting with "${zone.name}"`
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
next.assetPrefix = `/${zone.routing.assetPrefix}`;
|
|
1206
|
+
return {
|
|
1207
|
+
next
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// src/next/config/transforms/draft-mode.ts
|
|
1212
|
+
function transform2(args) {
|
|
1213
|
+
var _a;
|
|
1214
|
+
const { next } = args;
|
|
1215
|
+
if (((_a = next.experimental) == null ? void 0 : _a.multiZoneDraftMode) !== void 0) {
|
|
1216
|
+
return {
|
|
1217
|
+
next
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
next.experimental = next.experimental || {};
|
|
1221
|
+
next.experimental.multiZoneDraftMode = true;
|
|
1222
|
+
return {
|
|
1223
|
+
next
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// src/next/config/transforms/headers.ts
|
|
1228
|
+
function transform3(args) {
|
|
1229
|
+
const { next, zone } = args;
|
|
1230
|
+
if (zone.isDefault()) {
|
|
1231
|
+
return {
|
|
1232
|
+
next
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
const headersToAdd = [
|
|
1236
|
+
{
|
|
1237
|
+
source: "/:path*",
|
|
1238
|
+
headers: [
|
|
1239
|
+
{
|
|
1240
|
+
key: "X-Vercel-Zone",
|
|
1241
|
+
value: zone.name
|
|
1242
|
+
}
|
|
1243
|
+
]
|
|
1244
|
+
},
|
|
1245
|
+
{
|
|
1246
|
+
source: "/:path*",
|
|
1247
|
+
has: [
|
|
1248
|
+
{
|
|
1249
|
+
type: "host",
|
|
1250
|
+
value: "(?<host>.*)"
|
|
1251
|
+
}
|
|
1252
|
+
],
|
|
1253
|
+
headers: [
|
|
1254
|
+
{
|
|
1255
|
+
// TODO: we may want to revisit before launch whether we want to expose this
|
|
1256
|
+
// value on all responses publicly since users may not want to reveal this host
|
|
1257
|
+
// (maybe just in preview? or when the user is logged in to the toolbar?)
|
|
1258
|
+
key: "X-Vercel-Host",
|
|
1259
|
+
value: ":host"
|
|
1260
|
+
}
|
|
1261
|
+
]
|
|
1262
|
+
}
|
|
1263
|
+
];
|
|
1264
|
+
if (next.headers && typeof next.headers === "function") {
|
|
1265
|
+
const originalHeadersFn = next.headers;
|
|
1266
|
+
next.headers = async () => {
|
|
1267
|
+
const originalHeaders = await originalHeadersFn();
|
|
1268
|
+
return [...originalHeaders, ...headersToAdd];
|
|
1269
|
+
};
|
|
1270
|
+
} else {
|
|
1271
|
+
next.headers = () => {
|
|
1272
|
+
return Promise.resolve(headersToAdd);
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
return {
|
|
1276
|
+
next
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
// src/routing/get-preview-domain.ts
|
|
1281
|
+
var import_node_crypto = require("crypto");
|
|
1282
|
+
var DOMAIN_SIZE = 253;
|
|
1283
|
+
var DOMAIN_LABEL_SIZE = 63;
|
|
1284
|
+
function getMaxLabelLength(domain) {
|
|
1285
|
+
return Math.min(DOMAIN_SIZE - domain.length - 1, DOMAIN_LABEL_SIZE);
|
|
1286
|
+
}
|
|
1287
|
+
function parseBranchUrl(branchUrl) {
|
|
1288
|
+
const branchUrlParts = branchUrl.split(".");
|
|
1289
|
+
if (branchUrlParts.length < 3) {
|
|
1290
|
+
throw new Error(`Could not parse Vercel branch URL "${branchUrl}"`);
|
|
1291
|
+
}
|
|
1292
|
+
const domain = [branchUrlParts[1], branchUrlParts[2]].join(".");
|
|
1293
|
+
return {
|
|
1294
|
+
// biome-ignore lint/style/noNonNullAssertion: Ignored using `--suppress`
|
|
1295
|
+
label: branchUrlParts[0],
|
|
1296
|
+
domain
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
function getDomainSuffix(branchUrl, vercelUrl) {
|
|
1300
|
+
const branchLabelParts = parseBranchUrl(branchUrl).label.split("-");
|
|
1301
|
+
const vercelUrlLabelParts = parseBranchUrl(vercelUrl).label.split("-");
|
|
1302
|
+
const suffixParts = [];
|
|
1303
|
+
for (let i = 1; i < branchLabelParts.length; i++) {
|
|
1304
|
+
if (branchLabelParts.at(-1 * i) === vercelUrlLabelParts.at(-1 * i)) {
|
|
1305
|
+
suffixParts.push(branchLabelParts.at(-1 * i) ?? "");
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
return suffixParts.reverse().filter(Boolean).join("-");
|
|
1309
|
+
}
|
|
1310
|
+
function getPreviewDomain(zone) {
|
|
1311
|
+
var _a;
|
|
1312
|
+
const targetVercelProjectName = (_a = zone.vercel) == null ? void 0 : _a.projectName;
|
|
1313
|
+
if (!targetVercelProjectName) {
|
|
1314
|
+
throw new Error(
|
|
1315
|
+
`Missing Vercel project configuration for application "${zone.name}"`
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
const { VERCEL_GIT_COMMIT_REF, VERCEL_BRANCH_URL, VERCEL_URL } = process.env;
|
|
1319
|
+
if (VERCEL_GIT_COMMIT_REF && VERCEL_BRANCH_URL && VERCEL_URL) {
|
|
1320
|
+
const branchUrlParts = parseBranchUrl(VERCEL_BRANCH_URL);
|
|
1321
|
+
const { domain } = branchUrlParts;
|
|
1322
|
+
const stagingSuffix = domain !== "vercel.sh" ? getDomainSuffix(VERCEL_BRANCH_URL, VERCEL_URL) : "";
|
|
1323
|
+
const gitBranch = `git-${VERCEL_GIT_COMMIT_REF.toLocaleLowerCase()}`;
|
|
1324
|
+
const gitBranchForHash = `git-${VERCEL_GIT_COMMIT_REF}`;
|
|
1325
|
+
const urlSafeBranch = makeUrlSafe(gitBranch);
|
|
1326
|
+
const urlSafeProjectName = makeUrlSafe(targetVercelProjectName);
|
|
1327
|
+
const maxLabelLength = getMaxLabelLength(domain);
|
|
1328
|
+
const label = [urlSafeProjectName, urlSafeBranch, stagingSuffix].filter(Boolean).join("-");
|
|
1329
|
+
if (label.length > maxLabelLength) {
|
|
1330
|
+
let newLabel = makeUrlSafe(stagingSuffix).slice(0, maxLabelLength);
|
|
1331
|
+
const hash = (0, import_node_crypto.createHash)("sha256").update(`${gitBranchForHash}${targetVercelProjectName}`).digest("hex").slice(0, 6);
|
|
1332
|
+
newLabel = [hash, newLabel].filter(Boolean).join("-");
|
|
1333
|
+
const projectNamePart = makeUrlSafe(
|
|
1334
|
+
urlSafeProjectName.slice(0, maxLabelLength - newLabel.length - 1 - 4)
|
|
1335
|
+
);
|
|
1336
|
+
const branchPart = makeUrlSafe(
|
|
1337
|
+
urlSafeBranch.slice(
|
|
1338
|
+
0,
|
|
1339
|
+
Math.max(
|
|
1340
|
+
0,
|
|
1341
|
+
maxLabelLength - (newLabel.length + projectNamePart.length) - 2
|
|
1342
|
+
)
|
|
1343
|
+
)
|
|
1344
|
+
);
|
|
1345
|
+
if (branchPart.length >= 3) {
|
|
1346
|
+
newLabel = [branchPart, newLabel].filter(Boolean).join("-");
|
|
1347
|
+
}
|
|
1348
|
+
if (projectNamePart) {
|
|
1349
|
+
newLabel = [projectNamePart, newLabel].filter(Boolean).join("-");
|
|
1350
|
+
}
|
|
1351
|
+
return `https://${newLabel}.${domain}`;
|
|
1352
|
+
}
|
|
1353
|
+
return `https://${label}.${domain}`;
|
|
1354
|
+
}
|
|
1355
|
+
return zone.production.toString();
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
// src/routing/get-domain-for-current-environment.ts
|
|
1359
|
+
function debugDomains(zone, env, domain) {
|
|
1360
|
+
if (process.env.MFE_DEBUG === "true") {
|
|
1361
|
+
const indent = " ".repeat(4);
|
|
1362
|
+
const header = "domains (zone (env) -> domain)";
|
|
1363
|
+
const separator = "\u23AF".repeat(header.length);
|
|
1364
|
+
const line = `${indent} 1. ${zone} (${env}) -> ${domain}`;
|
|
1365
|
+
console.log(`${indent}${header}
|
|
1366
|
+
${indent}${separator}
|
|
1367
|
+
${line}
|
|
1368
|
+
`);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
function getDomainForCurrentEnvironment(zone) {
|
|
1372
|
+
var _a;
|
|
1373
|
+
if ((_a = zone.overrides) == null ? void 0 : _a.environment) {
|
|
1374
|
+
return zone.overrides.environment.toString();
|
|
1375
|
+
}
|
|
1376
|
+
const zoneName = zone.name;
|
|
1377
|
+
if (!process.env.VERCEL_ENV || process.env.VERCEL_ENV === "development") {
|
|
1378
|
+
const domain = process.env.NODE_ENV === "test" ? zone.development.local.toString() : zone.production.toString();
|
|
1379
|
+
debugDomains(zoneName, "development", domain);
|
|
1380
|
+
return domain;
|
|
1381
|
+
} else if (process.env.VERCEL_ENV === "production") {
|
|
1382
|
+
const domain = zone.production.toString();
|
|
1383
|
+
debugDomains(zoneName, "production", domain);
|
|
1384
|
+
return domain;
|
|
1385
|
+
} else if (process.env.VERCEL_ENV === "preview") {
|
|
1386
|
+
const MFE_PREVIEW_DOMAINS = JSON.parse(
|
|
1387
|
+
process.env.MFE_PREVIEW_DOMAINS ?? "{}"
|
|
1388
|
+
);
|
|
1389
|
+
if (MFE_PREVIEW_DOMAINS[zoneName]) {
|
|
1390
|
+
debugDomains(zoneName, "preview", MFE_PREVIEW_DOMAINS[zoneName]);
|
|
1391
|
+
return MFE_PREVIEW_DOMAINS[zoneName];
|
|
1392
|
+
}
|
|
1393
|
+
throw new Error(
|
|
1394
|
+
`Could not find preview domain for application "${zoneName}"`
|
|
1395
|
+
);
|
|
1396
|
+
}
|
|
1397
|
+
debugDomains(zoneName, process.env.VERCEL_ENV, zone.production.toString());
|
|
1398
|
+
return zone.production.toString();
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
// src/next/config/transforms/rewrites.ts
|
|
1402
|
+
function debugRewrites(rewrites) {
|
|
1403
|
+
if (process.env.MFE_DEBUG === "true") {
|
|
1404
|
+
const indent = " ".repeat(4);
|
|
1405
|
+
const header = "rewrites (source \u2192 destination)";
|
|
1406
|
+
const separator = "\u23AF".repeat(header.length);
|
|
1407
|
+
const maxSourceLength = Math.max(
|
|
1408
|
+
...rewrites.map((key) => key.source.length)
|
|
1409
|
+
);
|
|
1410
|
+
const table = rewrites.map((route, idx) => {
|
|
1411
|
+
const paddedSource = route.source.padEnd(maxSourceLength);
|
|
1412
|
+
return `${indent} ${idx + 1}. ${paddedSource} \u2192 ${route.destination}`;
|
|
1413
|
+
}).join("\n");
|
|
1414
|
+
console.log(`${indent}${header}
|
|
1415
|
+
${indent}${separator}
|
|
1416
|
+
${table}
|
|
1417
|
+
`);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
function pathToRewrites(path3) {
|
|
1421
|
+
var _a;
|
|
1422
|
+
const regex = /(?<base>^.+)\/:.+\*$/;
|
|
1423
|
+
const match = regex.exec(path3);
|
|
1424
|
+
const paths = [path3];
|
|
1425
|
+
if ((_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.base) {
|
|
1426
|
+
paths.unshift(match.groups.base);
|
|
1427
|
+
}
|
|
1428
|
+
return paths;
|
|
1429
|
+
}
|
|
1430
|
+
function rewritesMapToArr(rewrites) {
|
|
1431
|
+
return Array.from(rewrites.entries()).flatMap(([source, rewrite]) => {
|
|
1432
|
+
const destination = `${rewrite.destination.domain || ""}${rewrite.destination.pathname}`;
|
|
1433
|
+
if (source === destination)
|
|
1434
|
+
return [];
|
|
1435
|
+
return [
|
|
1436
|
+
{
|
|
1437
|
+
source,
|
|
1438
|
+
destination
|
|
1439
|
+
}
|
|
1440
|
+
];
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
function transform4(args) {
|
|
1444
|
+
const { next, microFrontend, zone } = args;
|
|
1445
|
+
const buildBeforeFiles = () => {
|
|
1446
|
+
var _a, _b, _c, _d, _e;
|
|
1447
|
+
const rewrites = /* @__PURE__ */ new Map();
|
|
1448
|
+
if ((_a = zone.routing) == null ? void 0 : _a.assetPrefix) {
|
|
1449
|
+
rewrites.set(`/${zone.routing.assetPrefix}/_next/:path+`, {
|
|
1450
|
+
destination: {
|
|
1451
|
+
pathname: `/_next/:path+`
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
if (!((_b = zone.vercel) == null ? void 0 : _b.routeSpeedInsightsToDefaultZone)) {
|
|
1455
|
+
rewrites.set(`/${zone.routing.assetPrefix}/_vercel/:path*`, {
|
|
1456
|
+
destination: { pathname: "/_vercel/:path*" }
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
if (zone.isDefault()) {
|
|
1461
|
+
for (const [_, z] of Object.entries(microFrontend.zones)) {
|
|
1462
|
+
if (zone.name === z.name) {
|
|
1463
|
+
continue;
|
|
1464
|
+
}
|
|
1465
|
+
const { routing } = z;
|
|
1466
|
+
if (!routing) {
|
|
1467
|
+
continue;
|
|
1468
|
+
}
|
|
1469
|
+
const domain = process.env.VERCEL_ENV === "preview" ? getPreviewDomain(z) : getDomainForCurrentEnvironment(z);
|
|
1470
|
+
if ((_c = z.routing) == null ? void 0 : _c.assetPrefix) {
|
|
1471
|
+
rewrites.set(`/${z.routing.assetPrefix}/:path+`, {
|
|
1472
|
+
destination: {
|
|
1473
|
+
domain,
|
|
1474
|
+
pathname: `/${z.routing.assetPrefix}/:path+`
|
|
1475
|
+
}
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
for (const group of routing.matches) {
|
|
1479
|
+
if ((_d = group.options) == null ? void 0 : _d.routeToDefaultApplication) {
|
|
1480
|
+
continue;
|
|
1481
|
+
} else if ((_e = group.options) == null ? void 0 : _e.flag) {
|
|
1482
|
+
continue;
|
|
1483
|
+
} else {
|
|
1484
|
+
for (const source of group.paths) {
|
|
1485
|
+
const paths = pathToRewrites(source);
|
|
1486
|
+
for (const p of paths) {
|
|
1487
|
+
rewrites.set(p, {
|
|
1488
|
+
destination: { domain, pathname: p }
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
} else {
|
|
1496
|
+
}
|
|
1497
|
+
return rewritesMapToArr(rewrites);
|
|
1498
|
+
};
|
|
1499
|
+
const newBeforeFiles = buildBeforeFiles();
|
|
1500
|
+
if (next.rewrites && typeof next.rewrites === "function") {
|
|
1501
|
+
const originalRewritesFn = next.rewrites;
|
|
1502
|
+
next.rewrites = async () => {
|
|
1503
|
+
const originalRewrites = await originalRewritesFn();
|
|
1504
|
+
if (typeof originalRewrites === "object" && !Array.isArray(originalRewrites)) {
|
|
1505
|
+
const { beforeFiles = [] } = originalRewrites;
|
|
1506
|
+
return {
|
|
1507
|
+
beforeFiles: [...newBeforeFiles, ...beforeFiles],
|
|
1508
|
+
afterFiles: originalRewrites.afterFiles,
|
|
1509
|
+
fallback: originalRewrites.fallback
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1512
|
+
return {
|
|
1513
|
+
beforeFiles: newBeforeFiles,
|
|
1514
|
+
afterFiles: originalRewrites,
|
|
1515
|
+
fallback: []
|
|
1516
|
+
};
|
|
1517
|
+
};
|
|
1518
|
+
} else {
|
|
1519
|
+
next.rewrites = async () => ({
|
|
1520
|
+
beforeFiles: newBeforeFiles,
|
|
1521
|
+
afterFiles: [],
|
|
1522
|
+
fallback: []
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
debugRewrites(newBeforeFiles);
|
|
1526
|
+
return {
|
|
1527
|
+
next
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
// src/next/config/transforms/server-actions.ts
|
|
1532
|
+
var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
|
|
1533
|
+
function transform5(args) {
|
|
1534
|
+
var _a;
|
|
1535
|
+
const { next, zone, microFrontend } = args;
|
|
1536
|
+
const zonesToAllow = [
|
|
1537
|
+
// this zone - this is included by default unless allowedOrigins is overridden (which we are)
|
|
1538
|
+
// so we re-add it here.
|
|
1539
|
+
zone,
|
|
1540
|
+
// this is the default zone for the micro-frontend. Allow child zones to call server actions
|
|
1541
|
+
// that are in the default zone.
|
|
1542
|
+
microFrontend.getDefaultZone()
|
|
1543
|
+
];
|
|
1544
|
+
const existingServerActionConfig = (_a = next.experimental) == null ? void 0 : _a.serverActions;
|
|
1545
|
+
next.experimental = {
|
|
1546
|
+
...next.experimental,
|
|
1547
|
+
serverActions: {
|
|
1548
|
+
...existingServerActionConfig,
|
|
1549
|
+
allowedOrigins: Array.from(
|
|
1550
|
+
/* @__PURE__ */ new Set([
|
|
1551
|
+
...(existingServerActionConfig == null ? void 0 : existingServerActionConfig.allowedOrigins) ?? [],
|
|
1552
|
+
...zonesToAllow.flatMap((z) => [
|
|
1553
|
+
formatDomainForServerAction(z.production.toString()),
|
|
1554
|
+
formatDomainForServerAction(getDomainForCurrentEnvironment(z))
|
|
1555
|
+
])
|
|
1556
|
+
])
|
|
1557
|
+
)
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
return {
|
|
1561
|
+
next
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// src/next/config/transforms/webpack.ts
|
|
1566
|
+
function transform6(args) {
|
|
1567
|
+
const { next, microFrontend } = args;
|
|
1568
|
+
const previewDomains = process.env.VERCEL_ENV === "preview" ? microFrontend.getAllApplications().reduce(
|
|
1569
|
+
(obj, app) => {
|
|
1570
|
+
obj[app.name] = getPreviewDomain(app);
|
|
1571
|
+
return obj;
|
|
1572
|
+
},
|
|
1573
|
+
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter -- needed to satisfy TSC
|
|
1574
|
+
{}
|
|
1575
|
+
) : {};
|
|
1576
|
+
const configWithWebpack = {
|
|
1577
|
+
...next,
|
|
1578
|
+
webpack(cfg, context) {
|
|
1579
|
+
const config = typeof next.webpack === "function" ? next.webpack(cfg, context) : cfg;
|
|
1580
|
+
const { isServer, nextRuntime, webpack: wpFromNext } = context;
|
|
1581
|
+
if (isServer || nextRuntime === "edge") {
|
|
1582
|
+
config.plugins.push(
|
|
1583
|
+
new wpFromNext.EnvironmentPlugin({
|
|
1584
|
+
MFE_CONFIG: JSON.stringify(microFrontend.serialize()),
|
|
1585
|
+
MFE_PREVIEW_DOMAINS: JSON.stringify(previewDomains)
|
|
1586
|
+
})
|
|
1587
|
+
);
|
|
1588
|
+
}
|
|
1589
|
+
config.plugins.push(
|
|
1590
|
+
// Remove node: from import specifiers, because Next.js does not yet support node: scheme
|
|
1591
|
+
// https://github.com/vercel/next.js/issues/28774
|
|
1592
|
+
new wpFromNext.NormalModuleReplacementPlugin(
|
|
1593
|
+
/^node:/,
|
|
1594
|
+
(resource) => {
|
|
1595
|
+
resource.request = resource.request.replace(/^node:/, "");
|
|
1596
|
+
}
|
|
1597
|
+
)
|
|
1598
|
+
);
|
|
1599
|
+
if (!isServer) {
|
|
1600
|
+
config.resolve.fallback = {
|
|
1601
|
+
fs: false,
|
|
1602
|
+
path: false,
|
|
1603
|
+
crypto: false,
|
|
1604
|
+
...config.resolve.fallback
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
return config;
|
|
1608
|
+
}
|
|
1609
|
+
};
|
|
1610
|
+
return {
|
|
1611
|
+
next: configWithWebpack
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// src/next/config/transforms/index.ts
|
|
1616
|
+
var transforms = {
|
|
1617
|
+
assetPrefix: transform,
|
|
1618
|
+
draftMode: transform2,
|
|
1619
|
+
headers: transform3,
|
|
1620
|
+
rewrites: transform4,
|
|
1621
|
+
serverActions: transform5,
|
|
1622
|
+
webpack: transform6
|
|
1623
|
+
};
|
|
1624
|
+
|
|
1625
|
+
// src/config/client/client-config.ts
|
|
1626
|
+
function getConfigForClient(config) {
|
|
1627
|
+
return {
|
|
1628
|
+
applications: Object.fromEntries(
|
|
1629
|
+
Object.entries(config.applications).map(([name, application]) => [
|
|
1630
|
+
name,
|
|
1631
|
+
{
|
|
1632
|
+
default: application.default,
|
|
1633
|
+
routing: application.routing
|
|
1634
|
+
}
|
|
1635
|
+
])
|
|
1636
|
+
)
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
// src/next/config/env.ts
|
|
1641
|
+
function debugEnv(env) {
|
|
1642
|
+
if (process.env.MFE_DEBUG === "true") {
|
|
1643
|
+
const indent = " ".repeat(4);
|
|
1644
|
+
const header = "env (key \u2192 val)";
|
|
1645
|
+
const separator = "\u23AF".repeat(header.length);
|
|
1646
|
+
const maxKeyLength = Math.max(...Object.keys(env).map((key) => key.length));
|
|
1647
|
+
const table = Object.keys(env).map((key, idx) => {
|
|
1648
|
+
const paddedKey = key.padEnd(maxKeyLength);
|
|
1649
|
+
return `${indent} ${idx + 1}. ${paddedKey} = ${env[key]}`;
|
|
1650
|
+
}).join("\n");
|
|
1651
|
+
console.log(`${indent}${header}
|
|
1652
|
+
${indent}${separator}
|
|
1653
|
+
${table}
|
|
1654
|
+
`);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
function setEnvironment({
|
|
1658
|
+
zone,
|
|
1659
|
+
config
|
|
1660
|
+
}) {
|
|
1661
|
+
var _a, _b, _c, _d;
|
|
1662
|
+
const previewDomains = process.env.VERCEL_ENV === "preview" ? config.getAllApplications().reduce(
|
|
1663
|
+
(obj, app) => {
|
|
1664
|
+
obj[app.name] = getPreviewDomain(app);
|
|
1665
|
+
return obj;
|
|
1666
|
+
},
|
|
1667
|
+
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter -- needed to satisfy TSC
|
|
1668
|
+
{}
|
|
1669
|
+
) : {};
|
|
1670
|
+
const clientEnvs = {
|
|
1671
|
+
NEXT_PUBLIC_MFE_CURRENT_APPLICATION: zone.name,
|
|
1672
|
+
NEXT_PUBLIC_MFE_CLIENT_CONFIG: JSON.stringify(
|
|
1673
|
+
getConfigForClient(config.getConfig())
|
|
1674
|
+
),
|
|
1675
|
+
...((_a = zone.vercel) == null ? void 0 : _a.routeSpeedInsightsToDefaultZone) && ((_b = zone.routing) == null ? void 0 : _b.assetPrefix) ? {} : {
|
|
1676
|
+
NEXT_PUBLIC_SPEED_INSIGHTS_BASEPATH: (_c = zone.routing) == null ? void 0 : _c.assetPrefix,
|
|
1677
|
+
NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH: (_d = zone.routing) == null ? void 0 : _d.assetPrefix
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
const serverEnvs = {
|
|
1681
|
+
MFE_CURRENT_APPLICATION: zone.name,
|
|
1682
|
+
MFE_PREVIEW_DOMAINS: JSON.stringify(previewDomains),
|
|
1683
|
+
MFE_CONFIG: JSON.stringify(config.getConfig())
|
|
1684
|
+
};
|
|
1685
|
+
const allEnvs = { ...clientEnvs, ...serverEnvs };
|
|
1686
|
+
for (const [key, value] of Object.entries(allEnvs)) {
|
|
1687
|
+
process.env[key] = value;
|
|
1688
|
+
}
|
|
1689
|
+
debugEnv(allEnvs);
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
// src/next/config/index.ts
|
|
1693
|
+
function typedEntries(obj) {
|
|
1694
|
+
return Object.entries(obj);
|
|
1695
|
+
}
|
|
1696
|
+
function isProduction(opts) {
|
|
1697
|
+
if (opts == null ? void 0 : opts.isProduction) {
|
|
1698
|
+
return opts.isProduction();
|
|
1699
|
+
}
|
|
1700
|
+
return process.env.VERCEL_ENV === "production";
|
|
1701
|
+
}
|
|
1702
|
+
function getConfigPath(opts) {
|
|
1703
|
+
var _a;
|
|
1704
|
+
if (opts == null ? void 0 : opts.configPath) {
|
|
1705
|
+
return { configPath: opts.configPath };
|
|
1706
|
+
}
|
|
1707
|
+
try {
|
|
1708
|
+
const vercelJsonString = import_node_fs3.default.readFileSync("./vercel.json", "utf-8");
|
|
1709
|
+
const vercelJson = JSON.parse(vercelJsonString);
|
|
1710
|
+
if (!((_a = vercelJson.microFrontends) == null ? void 0 : _a.config)) {
|
|
1711
|
+
throw new MicroFrontendError(
|
|
1712
|
+
`vercel.json file missing required field "microFrontends.config"`,
|
|
1713
|
+
{
|
|
1714
|
+
type: "vercelJson",
|
|
1715
|
+
subtype: "missing_field_microFrontend_config_path",
|
|
1716
|
+
source: "@vercel/micro-frontends/next"
|
|
1717
|
+
}
|
|
1718
|
+
);
|
|
1719
|
+
}
|
|
1720
|
+
return { configPath: vercelJson.microFrontends.config };
|
|
1721
|
+
} catch (err) {
|
|
1722
|
+
throw MicroFrontendError.handle(err, {
|
|
1723
|
+
fileName: "vercel.json"
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
function getApplicationContext(opts) {
|
|
1728
|
+
if (opts == null ? void 0 : opts.appName) {
|
|
1729
|
+
return { name: opts.appName };
|
|
1730
|
+
}
|
|
1731
|
+
try {
|
|
1732
|
+
const packageJsonString = import_node_fs3.default.readFileSync("./package.json", "utf-8");
|
|
1733
|
+
const packageJson = JSON.parse(packageJsonString);
|
|
1734
|
+
if (!packageJson.name) {
|
|
1735
|
+
throw new MicroFrontendError(
|
|
1736
|
+
`package.json file missing required field "name"`,
|
|
1737
|
+
{
|
|
1738
|
+
type: "packageJson",
|
|
1739
|
+
subtype: "missing_field_name",
|
|
1740
|
+
source: "@vercel/micro-frontends/next"
|
|
1741
|
+
}
|
|
1742
|
+
);
|
|
1743
|
+
}
|
|
1744
|
+
return { name: packageJson.name };
|
|
1745
|
+
} catch (err) {
|
|
1746
|
+
throw MicroFrontendError.handle(err, {
|
|
1747
|
+
fileName: "package.json"
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
function withMicroFrontends(nextConfig, opts) {
|
|
1752
|
+
var _a;
|
|
1753
|
+
if (opts == null ? void 0 : opts.debug) {
|
|
1754
|
+
process.env.MFE_DEBUG = "true";
|
|
1755
|
+
}
|
|
1756
|
+
const { name } = getApplicationContext(opts);
|
|
1757
|
+
const { configPath } = getConfigPath(opts);
|
|
1758
|
+
const mfConfig = MicroFrontendConfig.fromFile({
|
|
1759
|
+
filePath: configPath
|
|
1760
|
+
});
|
|
1761
|
+
const zone = mfConfig.getZone(name);
|
|
1762
|
+
setEnvironment({ zone, config: mfConfig });
|
|
1763
|
+
let next = { ...nextConfig };
|
|
1764
|
+
for (const [key, transform7] of typedEntries(transforms)) {
|
|
1765
|
+
if ((_a = opts == null ? void 0 : opts.skipTransforms) == null ? void 0 : _a.includes(key)) {
|
|
1766
|
+
console.log(`Skipping ${key} transform`);
|
|
1767
|
+
continue;
|
|
1768
|
+
}
|
|
1769
|
+
try {
|
|
1770
|
+
const transformedConfig = transform7({
|
|
1771
|
+
zone,
|
|
1772
|
+
next,
|
|
1773
|
+
microFrontend: mfConfig,
|
|
1774
|
+
opts: {
|
|
1775
|
+
isProduction: isProduction(opts)
|
|
1776
|
+
}
|
|
1777
|
+
});
|
|
1778
|
+
next = transformedConfig.next;
|
|
1779
|
+
} catch (e) {
|
|
1780
|
+
console.error("Error transforming next config", e);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
displayLocalProxyInfo(mfConfig.getLocalProxyPort());
|
|
1784
|
+
if (isVercel()) {
|
|
1785
|
+
mfConfig.write(zone.name, { versions: ["v1", "v2"] });
|
|
1786
|
+
}
|
|
1787
|
+
return next;
|
|
1788
|
+
}
|
|
1789
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1790
|
+
0 && (module.exports = {
|
|
1791
|
+
withMicroFrontends
|
|
1792
|
+
});
|
|
1793
|
+
//# sourceMappingURL=config.cjs.map
|