@vercel/microfrontends 0.14.0 → 0.16.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/dist/bin/cli.cjs +392 -1620
- package/dist/config.cjs +478 -1001
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -25
- package/dist/config.js +474 -980
- package/dist/config.js.map +1 -1
- package/dist/{v2/microfrontends → microfrontends}/server.cjs +91 -150
- package/dist/microfrontends/server.cjs.map +1 -0
- package/dist/{v2/microfrontends → microfrontends}/server.d.ts +4 -4
- package/dist/{v2/microfrontends → microfrontends}/server.js +91 -150
- package/dist/microfrontends/server.js.map +1 -0
- package/dist/{v2/microfrontends.cjs → microfrontends.cjs} +49 -28
- package/dist/microfrontends.cjs.map +1 -0
- package/dist/{v2/microfrontends.d.ts → microfrontends.d.ts} +4 -4
- package/dist/{v2/microfrontends.js → microfrontends.js} +48 -27
- package/dist/microfrontends.js.map +1 -0
- 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 +1344 -1024
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +1 -1
- package/dist/next/config.js +1343 -1023
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.cjs +77 -18
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.d.ts +13 -2
- package/dist/next/endpoints.js +77 -18
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +765 -395
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +10 -5
- package/dist/next/middleware.js +765 -395
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +615 -1031
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +14 -12
- package/dist/next/testing.js +609 -1015
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.cjs +40 -108
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.d.ts +24 -2
- package/dist/overrides.js +36 -106
- package/dist/overrides.js.map +1 -1
- package/dist/{v2/routing.cjs → routing.cjs} +3 -3
- package/dist/routing.cjs.map +1 -0
- package/dist/{v2/schema.cjs → schema.cjs} +1 -1
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.ts +1 -0
- package/dist/utils/mfe-port.cjs +237 -1338
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +230 -1331
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +31 -361
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +3 -146
- package/dist/validation.js +30 -359
- package/dist/validation.js.map +1 -1
- package/package.json +29 -92
- package/schema/schema.json +174 -244
- package/dist/config/client.cjs +0 -54
- package/dist/config/client.cjs.map +0 -1
- package/dist/config/client.d.ts +0 -23
- package/dist/config/client.js +0 -28
- package/dist/config/client.js.map +0 -1
- package/dist/config/edge.cjs +0 -508
- package/dist/config/edge.cjs.map +0 -1
- package/dist/config/edge.d.ts +0 -20
- package/dist/config/edge.js +0 -481
- package/dist/config/edge.js.map +0 -1
- package/dist/microfrontend-config-983a5139.d.ts +0 -154
- package/dist/schema-2922d49e.d.ts +0 -182
- package/dist/v2/config.cjs +0 -709
- package/dist/v2/config.cjs.map +0 -1
- package/dist/v2/config.d.ts +0 -4
- package/dist/v2/config.js +0 -684
- package/dist/v2/config.js.map +0 -1
- package/dist/v2/microfrontends/server.cjs.map +0 -1
- package/dist/v2/microfrontends/server.js.map +0 -1
- package/dist/v2/microfrontends.cjs.map +0 -1
- package/dist/v2/microfrontends.js.map +0 -1
- package/dist/v2/next/client.cjs +0 -3
- package/dist/v2/next/client.cjs.map +0 -1
- package/dist/v2/next/client.d.ts +0 -45
- package/dist/v2/next/client.js +0 -3
- package/dist/v2/next/client.js.map +0 -1
- package/dist/v2/next/config.cjs +0 -2178
- package/dist/v2/next/config.cjs.map +0 -1
- package/dist/v2/next/config.d.ts +0 -22
- package/dist/v2/next/config.js +0 -2143
- package/dist/v2/next/config.js.map +0 -1
- package/dist/v2/next/endpoints.cjs +0 -141
- package/dist/v2/next/endpoints.cjs.map +0 -1
- package/dist/v2/next/endpoints.d.ts +0 -26
- package/dist/v2/next/endpoints.js +0 -116
- package/dist/v2/next/endpoints.js.map +0 -1
- package/dist/v2/next/middleware.cjs +0 -1099
- package/dist/v2/next/middleware.cjs.map +0 -1
- package/dist/v2/next/middleware.d.ts +0 -34
- package/dist/v2/next/middleware.js +0 -1071
- package/dist/v2/next/middleware.js.map +0 -1
- package/dist/v2/next/testing.cjs +0 -992
- package/dist/v2/next/testing.cjs.map +0 -1
- package/dist/v2/next/testing.d.ts +0 -55
- package/dist/v2/next/testing.js +0 -961
- package/dist/v2/next/testing.js.map +0 -1
- package/dist/v2/overrides.cjs +0 -75
- package/dist/v2/overrides.cjs.map +0 -1
- package/dist/v2/overrides.d.ts +0 -24
- package/dist/v2/overrides.js +0 -45
- package/dist/v2/overrides.js.map +0 -1
- package/dist/v2/routing.cjs.map +0 -1
- package/dist/v2/schema.cjs.map +0 -1
- package/dist/v2/schema.d.ts +0 -1
- package/schema/schema-v2.json +0 -266
- /package/dist/{v2/routing.d.ts → routing.d.ts} +0 -0
- /package/dist/{v2/routing.js → routing.js} +0 -0
- /package/dist/{v2/routing.js.map → routing.js.map} +0 -0
- /package/dist/{v2/schema.js → schema.js} +0 -0
- /package/dist/{v2/schema.js.map → schema.js.map} +0 -0
package/dist/utils/mfe-port.cjs
CHANGED
|
@@ -33,1167 +33,24 @@ __export(mfe_port_exports, {
|
|
|
33
33
|
mfePort: () => mfePort
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(mfe_port_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
// src/config/types.ts
|
|
40
|
-
var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
|
|
41
|
-
|
|
42
|
-
// src/config/microfrontend-config.ts
|
|
43
|
-
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
44
|
-
|
|
45
|
-
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
46
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
47
|
-
|
|
48
|
-
// src/config-v2/microfrontends/server/constants.ts
|
|
49
|
-
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
50
|
-
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
51
|
-
|
|
52
|
-
// src/utils/is-vercel.ts
|
|
53
|
-
function isVercel() {
|
|
54
|
-
return process.env.VERCEL === "1";
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
58
|
-
function getOutputFilePath() {
|
|
59
|
-
if (isVercel()) {
|
|
60
|
-
return import_node_path.default.join(
|
|
61
|
-
".vercel",
|
|
62
|
-
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
63
|
-
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
return import_node_path.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// src/config/errors.ts
|
|
70
|
-
var MicrofrontendError = class extends Error {
|
|
71
|
-
constructor(message, opts) {
|
|
72
|
-
super(message);
|
|
73
|
-
this.name = "MicrofrontendsError";
|
|
74
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
75
|
-
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
76
|
-
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
77
|
-
Error.captureStackTrace(this, MicrofrontendError);
|
|
78
|
-
}
|
|
79
|
-
isKnown() {
|
|
80
|
-
return this.type !== "unknown";
|
|
81
|
-
}
|
|
82
|
-
isUnknown() {
|
|
83
|
-
return !this.isKnown();
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Converts an error to a MicrofrontendsError.
|
|
87
|
-
* @param original - The original error to convert.
|
|
88
|
-
* @returns The converted MicrofrontendsError.
|
|
89
|
-
*/
|
|
90
|
-
static convert(original, opts) {
|
|
91
|
-
if (opts == null ? void 0 : opts.fileName) {
|
|
92
|
-
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
93
|
-
if (err) {
|
|
94
|
-
return err;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (original.message.includes(
|
|
98
|
-
"Code generation from strings disallowed for this context"
|
|
99
|
-
)) {
|
|
100
|
-
return new MicrofrontendError(original.message, {
|
|
101
|
-
type: "config",
|
|
102
|
-
subtype: "unsupported_validation_env",
|
|
103
|
-
source: "ajv"
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return new MicrofrontendError(original.message);
|
|
107
|
-
}
|
|
108
|
-
static convertFSError(original, fileName) {
|
|
109
|
-
if (original instanceof Error && "code" in original) {
|
|
110
|
-
if (original.code === "ENOENT") {
|
|
111
|
-
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
112
|
-
type: "config",
|
|
113
|
-
subtype: "unable_to_read_file",
|
|
114
|
-
source: "fs"
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (original.code === "EACCES") {
|
|
118
|
-
return new MicrofrontendError(
|
|
119
|
-
`Permission denied while accessing "${fileName}"`,
|
|
120
|
-
{
|
|
121
|
-
type: "config",
|
|
122
|
-
subtype: "invalid_permissions",
|
|
123
|
-
source: "fs"
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (original instanceof SyntaxError) {
|
|
129
|
-
return new MicrofrontendError(
|
|
130
|
-
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
131
|
-
{
|
|
132
|
-
type: "config",
|
|
133
|
-
subtype: "invalid_syntax",
|
|
134
|
-
source: "fs"
|
|
135
|
-
}
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
142
|
-
* @param err - The error to handle.
|
|
143
|
-
* @returns A MicrofrontendsError instance.
|
|
144
|
-
*/
|
|
145
|
-
static handle(err, opts) {
|
|
146
|
-
if (err instanceof MicrofrontendError) {
|
|
147
|
-
return err;
|
|
148
|
-
}
|
|
149
|
-
if (err instanceof Error) {
|
|
150
|
-
return MicrofrontendError.convert(err, opts);
|
|
151
|
-
}
|
|
152
|
-
if (typeof err === "object" && err !== null) {
|
|
153
|
-
if ("message" in err && typeof err.message === "string") {
|
|
154
|
-
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return new MicrofrontendError("An unknown error occurred");
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// src/routing/url.ts
|
|
162
|
-
function buildUrlSafeString(givenOpts = {}) {
|
|
163
|
-
const options = {
|
|
164
|
-
joinString: "-",
|
|
165
|
-
lowercaseOnly: true,
|
|
166
|
-
maxLen: 100,
|
|
167
|
-
regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,
|
|
168
|
-
trimWhitespace: true,
|
|
169
|
-
...givenOpts
|
|
170
|
-
};
|
|
171
|
-
return {
|
|
172
|
-
generate: (...args) => {
|
|
173
|
-
const reJoinString = new RegExp(`${options.joinString}+`, "g");
|
|
174
|
-
let tag;
|
|
175
|
-
if (args.length === 0) {
|
|
176
|
-
throw new Error("generate method must be passed at least one argument");
|
|
177
|
-
}
|
|
178
|
-
for (let i = 0; i < args.length; i++) {
|
|
179
|
-
const arg = args[i];
|
|
180
|
-
if (typeof arg !== "string")
|
|
181
|
-
throw new Error("all supplied arguments must be Strings");
|
|
182
|
-
if (options.trimWhitespace) {
|
|
183
|
-
args[i] = arg.trim();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
tag = args.join(options.joinString);
|
|
187
|
-
tag = tag.replace(/\s/g, options.joinString);
|
|
188
|
-
if (options.lowercaseOnly)
|
|
189
|
-
tag = tag.toLowerCase();
|
|
190
|
-
tag = tag.replace(options.regexRemovePattern, (match) => {
|
|
191
|
-
if (match === options.joinString)
|
|
192
|
-
return match;
|
|
193
|
-
return "";
|
|
194
|
-
});
|
|
195
|
-
if (tag.length > options.maxLen)
|
|
196
|
-
tag = tag.substring(0, options.maxLen);
|
|
197
|
-
tag = tag.replace(reJoinString, options.joinString);
|
|
198
|
-
return tag;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
var urlSafeString = buildUrlSafeString().generate;
|
|
203
|
-
function makeUrlSafe(name) {
|
|
204
|
-
return urlSafeString(name.replace(/\//g, "-")).replace(/^-*/g, "").replace(/-*$/g, "");
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// src/config/overrides/config.ts
|
|
208
|
-
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
209
|
-
var _Overrides = class {
|
|
210
|
-
constructor(config) {
|
|
211
|
-
this.config = config;
|
|
212
|
-
}
|
|
213
|
-
static getAppEnvOverrideCookieName(zone) {
|
|
214
|
-
return `${_Overrides.overrideEnvCookiePrefix}${zone}`;
|
|
215
|
-
}
|
|
216
|
-
static isOverrideCookie(cookie) {
|
|
217
|
-
var _a;
|
|
218
|
-
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
219
|
-
}
|
|
220
|
-
static getOverrideFromCookie(cookie) {
|
|
221
|
-
if (!_Overrides.isOverrideCookie(cookie) || !cookie.value)
|
|
222
|
-
return;
|
|
223
|
-
return {
|
|
224
|
-
zone: cookie.name.replace(_Overrides.overrideEnvCookiePrefix, ""),
|
|
225
|
-
host: cookie.value
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
static parseOverrides(cookies) {
|
|
229
|
-
const overridesConfig = { applications: {} };
|
|
230
|
-
cookies.forEach((cookie) => {
|
|
231
|
-
const override = _Overrides.getOverrideFromCookie(cookie);
|
|
232
|
-
if (!override)
|
|
233
|
-
return;
|
|
234
|
-
overridesConfig.applications[override.zone] = {
|
|
235
|
-
environment: { host: override.host }
|
|
236
|
-
};
|
|
237
|
-
});
|
|
238
|
-
return overridesConfig;
|
|
239
|
-
}
|
|
240
|
-
static validOverrideDomainsForZone(microfrontendConfig, zone) {
|
|
241
|
-
var _a, _b, _c, _d, _e;
|
|
242
|
-
const projectName = (_a = microfrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
243
|
-
if (!projectName) {
|
|
244
|
-
return [microfrontendConfig.getZone(zone).production.host];
|
|
245
|
-
}
|
|
246
|
-
const parsedProjectName = makeUrlSafe(projectName);
|
|
247
|
-
const previewDeploymentSuffix = (_c = (_b = microfrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
|
|
248
|
-
const teamSlug = (_e = (_d = microfrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
|
|
249
|
-
if (!teamSlug && !previewDeploymentSuffix) {
|
|
250
|
-
return [microfrontendConfig.getZone(zone).production.host];
|
|
251
|
-
}
|
|
252
|
-
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
253
|
-
return [
|
|
254
|
-
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
255
|
-
microfrontendConfig.getZone(zone).production.host
|
|
256
|
-
];
|
|
257
|
-
}
|
|
258
|
-
static validateOverrideDomain(microfrontendConfig, zone, domain) {
|
|
259
|
-
return new RegExp(
|
|
260
|
-
`^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
|
|
261
|
-
"|"
|
|
262
|
-
)}$`
|
|
263
|
-
).test(domain);
|
|
264
|
-
}
|
|
265
|
-
serialize() {
|
|
266
|
-
return this.config;
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
var Overrides = _Overrides;
|
|
270
|
-
Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
271
|
-
|
|
272
|
-
// src/config/common/host.ts
|
|
273
|
-
var Host = class {
|
|
274
|
-
constructor({ protocol, host, port }) {
|
|
275
|
-
this.protocol = protocol || "https";
|
|
276
|
-
this.host = host;
|
|
277
|
-
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
278
|
-
this.serialized = {
|
|
279
|
-
protocol,
|
|
280
|
-
host,
|
|
281
|
-
...port ? { port } : void 0
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
isLocal() {
|
|
285
|
-
return this.host === "localhost" || this.host === "127.0.0.1";
|
|
286
|
-
}
|
|
287
|
-
static getPort({
|
|
288
|
-
protocol,
|
|
289
|
-
port
|
|
290
|
-
}) {
|
|
291
|
-
if (!port) {
|
|
292
|
-
if (protocol === "http") {
|
|
293
|
-
return 80;
|
|
294
|
-
}
|
|
295
|
-
return 443;
|
|
296
|
-
}
|
|
297
|
-
return port;
|
|
298
|
-
}
|
|
299
|
-
isDefaultPort() {
|
|
300
|
-
return this.port === Host.getPort({ protocol: this.protocol });
|
|
301
|
-
}
|
|
302
|
-
toString(opts = {}) {
|
|
303
|
-
const url = this.toUrl(opts);
|
|
304
|
-
return url.toString().replace(/\/$/, "");
|
|
305
|
-
}
|
|
306
|
-
toUrl(opts = {}) {
|
|
307
|
-
const { includeDefaultPort } = opts;
|
|
308
|
-
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
309
|
-
return new URL(url);
|
|
310
|
-
}
|
|
311
|
-
serialize() {
|
|
312
|
-
return this.serialized;
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// src/config/common/application.ts
|
|
317
|
-
var Application = class {
|
|
318
|
-
constructor(name, {
|
|
319
|
-
app,
|
|
320
|
-
overrides
|
|
321
|
-
}) {
|
|
322
|
-
Application.validate(name, app);
|
|
323
|
-
this.name = name;
|
|
324
|
-
this.default = app.default;
|
|
325
|
-
this.routing = app.routing;
|
|
326
|
-
this.development = {
|
|
327
|
-
local: new Host(app.development.local),
|
|
328
|
-
fallback: app.development.fallback ? new Host(app.development.fallback) : void 0
|
|
329
|
-
};
|
|
330
|
-
this.production = new Host(app.production);
|
|
331
|
-
this.vercel = app.vercel;
|
|
332
|
-
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
333
|
-
environment: new Host(overrides.environment)
|
|
334
|
-
} : void 0;
|
|
335
|
-
}
|
|
336
|
-
isDefault() {
|
|
337
|
-
return this.default;
|
|
338
|
-
}
|
|
339
|
-
static validate(name, app) {
|
|
340
|
-
var _a, _b, _c, _d, _e;
|
|
341
|
-
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("/"))) {
|
|
342
|
-
throw new MicrofrontendError(
|
|
343
|
-
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
344
|
-
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
for (const group of ((_e = app.routing) == null ? void 0 : _e.matches) ?? []) {
|
|
348
|
-
for (const p of group.paths) {
|
|
349
|
-
if (p === "/") {
|
|
350
|
-
continue;
|
|
351
|
-
}
|
|
352
|
-
if (p.endsWith("/")) {
|
|
353
|
-
throw new MicrofrontendError(
|
|
354
|
-
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
355
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
if (!p.startsWith("/")) {
|
|
359
|
-
throw new MicrofrontendError(
|
|
360
|
-
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
361
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
serialize() {
|
|
368
|
-
var _a, _b;
|
|
369
|
-
if (this.routing === void 0 || this.default) {
|
|
370
|
-
return {
|
|
371
|
-
default: true,
|
|
372
|
-
development: {
|
|
373
|
-
local: this.development.local.serialize(),
|
|
374
|
-
fallback: (_a = this.development.fallback) == null ? void 0 : _a.serialize()
|
|
375
|
-
},
|
|
376
|
-
production: this.production.serialize(),
|
|
377
|
-
vercel: this.vercel
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
default: false,
|
|
382
|
-
routing: this.routing,
|
|
383
|
-
development: {
|
|
384
|
-
local: this.development.local.serialize(),
|
|
385
|
-
fallback: (_b = this.development.fallback) == null ? void 0 : _b.serialize()
|
|
386
|
-
},
|
|
387
|
-
production: this.production.serialize(),
|
|
388
|
-
vercel: this.vercel
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
// src/config/common/microfrontend-config.ts
|
|
394
|
-
var SUPPORTED_VERSIONS = ["1"];
|
|
395
|
-
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
396
|
-
var MicrofrontendConfigCommon = class {
|
|
397
|
-
constructor({
|
|
398
|
-
config,
|
|
399
|
-
overrides
|
|
400
|
-
}) {
|
|
401
|
-
this.zones = {};
|
|
402
|
-
var _a, _b, _c;
|
|
403
|
-
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
404
|
-
throw new MicrofrontendError(
|
|
405
|
-
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
406
|
-
", "
|
|
407
|
-
)}`,
|
|
408
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
412
|
-
this.overrides = overrides && !disableOverrides ? new Overrides(overrides) : void 0;
|
|
413
|
-
for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {
|
|
414
|
-
this.zones[zoneName] = new Application(zoneName, {
|
|
415
|
-
app: zoneConfig,
|
|
416
|
-
overrides: !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.config.applications[zoneName] : void 0
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
this.config = config;
|
|
420
|
-
this.name = config.name;
|
|
421
|
-
this.version = config.version;
|
|
422
|
-
this.options = config.options;
|
|
423
|
-
this.$schema = config.$schema;
|
|
424
|
-
}
|
|
425
|
-
isOverridesDisabled() {
|
|
426
|
-
var _a, _b;
|
|
427
|
-
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
428
|
-
}
|
|
429
|
-
static getConfigFromEnv() {
|
|
430
|
-
const config = process.env.MFE_CONFIG;
|
|
431
|
-
if (!config) {
|
|
432
|
-
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
433
|
-
type: "config",
|
|
434
|
-
subtype: "not_found_in_env"
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
return config;
|
|
438
|
-
}
|
|
439
|
-
static fromEnv(_) {
|
|
440
|
-
throw new Error("Not implemented");
|
|
441
|
-
}
|
|
442
|
-
getConfig() {
|
|
443
|
-
return this.config;
|
|
444
|
-
}
|
|
445
|
-
getAllApplications() {
|
|
446
|
-
return Object.values(this.zones);
|
|
447
|
-
}
|
|
448
|
-
getZone(name) {
|
|
449
|
-
const zone = this.zones[name];
|
|
450
|
-
if (!zone) {
|
|
451
|
-
throw new MicrofrontendError(
|
|
452
|
-
`Could not find microfrontends configuration for application "${name}"`,
|
|
453
|
-
{
|
|
454
|
-
type: "zone",
|
|
455
|
-
subtype: "not_found"
|
|
456
|
-
}
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
return zone;
|
|
460
|
-
}
|
|
461
|
-
getApplicationByProjectId(projectId) {
|
|
462
|
-
return Object.values(this.zones).find(
|
|
463
|
-
(zone) => {
|
|
464
|
-
var _a;
|
|
465
|
-
return ((_a = zone.vercel) == null ? void 0 : _a.projectId) === projectId;
|
|
466
|
-
}
|
|
467
|
-
);
|
|
468
|
-
}
|
|
469
|
-
getDefaultZone() {
|
|
470
|
-
const zone = Object.values(this.zones).find((z) => z.default);
|
|
471
|
-
if (!zone) {
|
|
472
|
-
throw new MicrofrontendError(
|
|
473
|
-
`Could not find default zone in microfrontends configuration`,
|
|
474
|
-
{
|
|
475
|
-
type: "zone",
|
|
476
|
-
subtype: "not_found"
|
|
477
|
-
}
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
return zone;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Returns the configured port for the local proxy
|
|
484
|
-
*/
|
|
485
|
-
getLocalProxyPort() {
|
|
486
|
-
var _a, _b;
|
|
487
|
-
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Serializes the class back to the Schema type.
|
|
491
|
-
*
|
|
492
|
-
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
493
|
-
*/
|
|
494
|
-
toSchemaJson() {
|
|
495
|
-
const applications = {};
|
|
496
|
-
for (const [name, zone] of Object.entries(this.zones)) {
|
|
497
|
-
applications[name] = zone.serialize();
|
|
498
|
-
}
|
|
499
|
-
return {
|
|
500
|
-
$schema: this.$schema,
|
|
501
|
-
name: this.name,
|
|
502
|
-
version: this.version,
|
|
503
|
-
options: this.options,
|
|
504
|
-
applications
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
serialize() {
|
|
508
|
-
var _a;
|
|
509
|
-
const applications = {};
|
|
510
|
-
for (const [name, zone] of Object.entries(this.zones)) {
|
|
511
|
-
applications[name] = zone.serialize();
|
|
512
|
-
}
|
|
513
|
-
return {
|
|
514
|
-
config: {
|
|
515
|
-
name: this.name,
|
|
516
|
-
version: this.version,
|
|
517
|
-
applications,
|
|
518
|
-
options: this.options,
|
|
519
|
-
$schema: this.$schema
|
|
520
|
-
},
|
|
521
|
-
overrides: (_a = this.overrides) == null ? void 0 : _a.serialize()
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
write(_) {
|
|
525
|
-
throw new MicrofrontendError(
|
|
526
|
-
`Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
|
|
527
|
-
{ type: "config", subtype: "unsupported_operation" }
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
// src/config/utils/get-output-file-path.ts
|
|
533
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
534
|
-
|
|
535
|
-
// src/config/constants.ts
|
|
536
|
-
var MFE_CONFIG_DEFAULT_FILE_PATH2 = "micro-frontends";
|
|
537
|
-
var MFE_CONFIG_DEFAULT_FILE_NAME2 = "micro-frontends.config.json";
|
|
538
|
-
|
|
539
|
-
// src/config/utils/get-output-file-path.ts
|
|
540
|
-
function getOutputFilePath2() {
|
|
541
|
-
if (isVercel()) {
|
|
542
|
-
return import_node_path2.default.join(
|
|
543
|
-
".vercel",
|
|
544
|
-
MFE_CONFIG_DEFAULT_FILE_PATH2,
|
|
545
|
-
MFE_CONFIG_DEFAULT_FILE_NAME2
|
|
546
|
-
);
|
|
547
|
-
}
|
|
548
|
-
return import_node_path2.default.join(MFE_CONFIG_DEFAULT_FILE_PATH2, MFE_CONFIG_DEFAULT_FILE_NAME2);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// src/config/validation.ts
|
|
552
|
-
var import_jsonc_parser = require("jsonc-parser");
|
|
553
|
-
var import_path_to_regexp = require("path-to-regexp");
|
|
554
|
-
var import_ajv = require("ajv");
|
|
555
|
-
|
|
556
|
-
// schema/schema.json
|
|
557
|
-
var schema_default = {
|
|
558
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
559
|
-
$ref: "#/definitions/Config",
|
|
560
|
-
definitions: {
|
|
561
|
-
Config: {
|
|
562
|
-
type: "object",
|
|
563
|
-
properties: {
|
|
564
|
-
version: {
|
|
565
|
-
type: "string"
|
|
566
|
-
},
|
|
567
|
-
$schema: {
|
|
568
|
-
type: "string"
|
|
569
|
-
},
|
|
570
|
-
name: {
|
|
571
|
-
type: "string",
|
|
572
|
-
description: 'Name for the micro-frontend site (eg. "vercel.com", "vercel-site" etc.).'
|
|
573
|
-
},
|
|
574
|
-
applications: {
|
|
575
|
-
$ref: "#/definitions/ApplicationConfigsById"
|
|
576
|
-
},
|
|
577
|
-
options: {
|
|
578
|
-
$ref: "#/definitions/Options",
|
|
579
|
-
description: "Optional configuration for the entire micro-frontends setup."
|
|
580
|
-
}
|
|
581
|
-
},
|
|
582
|
-
required: ["version", "applications"],
|
|
583
|
-
description: "Configuration for micro-frontend applications\n\nTODO: Add proxy configuration"
|
|
584
|
-
},
|
|
585
|
-
ApplicationConfigsById: {
|
|
586
|
-
type: "object",
|
|
587
|
-
additionalProperties: {
|
|
588
|
-
$ref: "#/definitions/ApplicationConfig"
|
|
589
|
-
}
|
|
590
|
-
},
|
|
591
|
-
ApplicationConfig: {
|
|
592
|
-
anyOf: [
|
|
593
|
-
{
|
|
594
|
-
$ref: "#/definitions/DefaultApplicationConfig"
|
|
595
|
-
},
|
|
596
|
-
{
|
|
597
|
-
$ref: "#/definitions/CommonApplicationConfig"
|
|
598
|
-
}
|
|
599
|
-
],
|
|
600
|
-
description: "A Micro-Frontend Deployment Target"
|
|
601
|
-
},
|
|
602
|
-
DefaultApplicationConfig: {
|
|
603
|
-
type: "object",
|
|
604
|
-
properties: {
|
|
605
|
-
default: {
|
|
606
|
-
type: "boolean",
|
|
607
|
-
const: true,
|
|
608
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
609
|
-
},
|
|
610
|
-
routing: {
|
|
611
|
-
$ref: "#/definitions/Routing"
|
|
612
|
-
},
|
|
613
|
-
development: {
|
|
614
|
-
type: "object",
|
|
615
|
-
properties: {
|
|
616
|
-
local: {
|
|
617
|
-
$ref: "#/definitions/HostConfig"
|
|
618
|
-
},
|
|
619
|
-
fallback: {
|
|
620
|
-
$ref: "#/definitions/HostConfig",
|
|
621
|
-
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."
|
|
622
|
-
},
|
|
623
|
-
task: {
|
|
624
|
-
type: "string",
|
|
625
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
626
|
-
}
|
|
627
|
-
},
|
|
628
|
-
required: ["local"]
|
|
629
|
-
},
|
|
630
|
-
production: {
|
|
631
|
-
$ref: "#/definitions/HostConfig"
|
|
632
|
-
},
|
|
633
|
-
metadata: {
|
|
634
|
-
type: "object",
|
|
635
|
-
additionalProperties: {
|
|
636
|
-
type: "string"
|
|
637
|
-
}
|
|
638
|
-
},
|
|
639
|
-
federation: {
|
|
640
|
-
type: "object",
|
|
641
|
-
properties: {
|
|
642
|
-
exposes: {
|
|
643
|
-
type: "array",
|
|
644
|
-
items: {
|
|
645
|
-
type: "object",
|
|
646
|
-
properties: {
|
|
647
|
-
name: {
|
|
648
|
-
type: "string",
|
|
649
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
650
|
-
},
|
|
651
|
-
path: {
|
|
652
|
-
type: "string",
|
|
653
|
-
description: "Relative path to the module within its `application`"
|
|
654
|
-
}
|
|
655
|
-
},
|
|
656
|
-
required: ["name", "path"]
|
|
657
|
-
},
|
|
658
|
-
description: "Modules that are exposed by this application"
|
|
659
|
-
},
|
|
660
|
-
uses: {
|
|
661
|
-
type: "array",
|
|
662
|
-
items: {
|
|
663
|
-
type: "string"
|
|
664
|
-
},
|
|
665
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
},
|
|
669
|
-
vercel: {
|
|
670
|
-
$ref: "#/definitions/Vercel"
|
|
671
|
-
}
|
|
672
|
-
},
|
|
673
|
-
required: ["default", "development", "production"]
|
|
674
|
-
},
|
|
675
|
-
Routing: {
|
|
676
|
-
type: "object",
|
|
677
|
-
properties: {
|
|
678
|
-
assetPrefix: {
|
|
679
|
-
type: "string",
|
|
680
|
-
description: "[assetPrefix] for the application"
|
|
681
|
-
},
|
|
682
|
-
matches: {
|
|
683
|
-
type: "array",
|
|
684
|
-
items: {
|
|
685
|
-
$ref: "#/definitions/PathGroup"
|
|
686
|
-
},
|
|
687
|
-
description: "Path expressions that are routed to this application."
|
|
688
|
-
}
|
|
689
|
-
},
|
|
690
|
-
required: ["matches"]
|
|
691
|
-
},
|
|
692
|
-
PathGroup: {
|
|
693
|
-
type: "object",
|
|
694
|
-
properties: {
|
|
695
|
-
group: {
|
|
696
|
-
type: "string",
|
|
697
|
-
description: "Optional group name for the paths"
|
|
698
|
-
},
|
|
699
|
-
options: {
|
|
700
|
-
type: "object",
|
|
701
|
-
properties: {
|
|
702
|
-
flag: {
|
|
703
|
-
type: "string",
|
|
704
|
-
description: "flag name that can be used to enable/disable all paths in the group"
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
},
|
|
708
|
-
paths: {
|
|
709
|
-
type: "array",
|
|
710
|
-
items: {
|
|
711
|
-
type: "string"
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
},
|
|
715
|
-
required: ["paths"]
|
|
716
|
-
},
|
|
717
|
-
HostConfig: {
|
|
718
|
-
type: "object",
|
|
719
|
-
properties: {
|
|
720
|
-
protocol: {
|
|
721
|
-
type: "string",
|
|
722
|
-
enum: ["http", "https"],
|
|
723
|
-
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"'
|
|
724
|
-
},
|
|
725
|
-
host: {
|
|
726
|
-
type: "string",
|
|
727
|
-
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`)."
|
|
728
|
-
},
|
|
729
|
-
port: {
|
|
730
|
-
type: "number",
|
|
731
|
-
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"
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
required: ["host"]
|
|
735
|
-
},
|
|
736
|
-
Vercel: {
|
|
737
|
-
type: "object",
|
|
738
|
-
properties: {
|
|
739
|
-
projectId: {
|
|
740
|
-
type: "string",
|
|
741
|
-
description: "Vercel project ID"
|
|
742
|
-
},
|
|
743
|
-
projectName: {
|
|
744
|
-
type: "string",
|
|
745
|
-
description: "Vercel project name (temporary until we can use project ID)"
|
|
746
|
-
},
|
|
747
|
-
defaultRoute: {
|
|
748
|
-
type: "string",
|
|
749
|
-
description: "The default route for the application. Used to render screenshots, favicons, and provide direct zone links"
|
|
750
|
-
},
|
|
751
|
-
routeSpeedInsightsToDefaultZone: {
|
|
752
|
-
type: "boolean",
|
|
753
|
-
description: "Whether to route Speed Insights to the default zone or each individual microfrontend."
|
|
754
|
-
}
|
|
755
|
-
},
|
|
756
|
-
required: ["projectId"]
|
|
757
|
-
},
|
|
758
|
-
CommonApplicationConfig: {
|
|
759
|
-
type: "object",
|
|
760
|
-
properties: {
|
|
761
|
-
default: {
|
|
762
|
-
type: "boolean",
|
|
763
|
-
const: false,
|
|
764
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
765
|
-
},
|
|
766
|
-
routing: {
|
|
767
|
-
$ref: "#/definitions/Routing"
|
|
768
|
-
},
|
|
769
|
-
development: {
|
|
770
|
-
type: "object",
|
|
771
|
-
properties: {
|
|
772
|
-
local: {
|
|
773
|
-
$ref: "#/definitions/HostConfig"
|
|
774
|
-
},
|
|
775
|
-
fallback: {
|
|
776
|
-
$ref: "#/definitions/HostConfig",
|
|
777
|
-
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."
|
|
778
|
-
},
|
|
779
|
-
task: {
|
|
780
|
-
type: "string",
|
|
781
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
782
|
-
}
|
|
783
|
-
},
|
|
784
|
-
required: ["local"]
|
|
785
|
-
},
|
|
786
|
-
production: {
|
|
787
|
-
$ref: "#/definitions/HostConfig"
|
|
788
|
-
},
|
|
789
|
-
metadata: {
|
|
790
|
-
type: "object",
|
|
791
|
-
additionalProperties: {
|
|
792
|
-
type: "string"
|
|
793
|
-
}
|
|
794
|
-
},
|
|
795
|
-
federation: {
|
|
796
|
-
type: "object",
|
|
797
|
-
properties: {
|
|
798
|
-
exposes: {
|
|
799
|
-
type: "array",
|
|
800
|
-
items: {
|
|
801
|
-
type: "object",
|
|
802
|
-
properties: {
|
|
803
|
-
name: {
|
|
804
|
-
type: "string",
|
|
805
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
806
|
-
},
|
|
807
|
-
path: {
|
|
808
|
-
type: "string",
|
|
809
|
-
description: "Relative path to the module within its `application`"
|
|
810
|
-
}
|
|
811
|
-
},
|
|
812
|
-
required: ["name", "path"]
|
|
813
|
-
},
|
|
814
|
-
description: "Modules that are exposed by this application"
|
|
815
|
-
},
|
|
816
|
-
uses: {
|
|
817
|
-
type: "array",
|
|
818
|
-
items: {
|
|
819
|
-
type: "string"
|
|
820
|
-
},
|
|
821
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
},
|
|
825
|
-
vercel: {
|
|
826
|
-
$ref: "#/definitions/Vercel"
|
|
827
|
-
}
|
|
828
|
-
},
|
|
829
|
-
required: ["default", "development", "production", "routing"]
|
|
830
|
-
},
|
|
831
|
-
Options: {
|
|
832
|
-
type: "object",
|
|
833
|
-
properties: {
|
|
834
|
-
vercel: {
|
|
835
|
-
$ref: "#/definitions/VercelOptions",
|
|
836
|
-
description: "Micro-Frontends wide options for Vercel."
|
|
837
|
-
},
|
|
838
|
-
localProxy: {
|
|
839
|
-
$ref: "#/definitions/LocalProxyOptions",
|
|
840
|
-
description: "Options for local proxy."
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
},
|
|
844
|
-
VercelOptions: {
|
|
845
|
-
type: "object",
|
|
846
|
-
properties: {
|
|
847
|
-
previewDeploymentSuffix: {
|
|
848
|
-
type: "string",
|
|
849
|
-
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`."
|
|
850
|
-
},
|
|
851
|
-
teamSlug: {
|
|
852
|
-
type: "string",
|
|
853
|
-
description: "Team slug for the Vercel team"
|
|
854
|
-
},
|
|
855
|
-
disableOverrides: {
|
|
856
|
-
type: "boolean",
|
|
857
|
-
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."
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
},
|
|
861
|
-
LocalProxyOptions: {
|
|
862
|
-
type: "object",
|
|
863
|
-
properties: {
|
|
864
|
-
port: {
|
|
865
|
-
type: "number",
|
|
866
|
-
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
|
|
873
|
-
// src/config/utils/load-schema.ts
|
|
874
|
-
var SCHEMA = schema_default;
|
|
875
|
-
|
|
876
|
-
// src/config/validation.ts
|
|
877
|
-
var validateSchema = (configString) => {
|
|
878
|
-
const parsedConfig = (0, import_jsonc_parser.parse)(configString);
|
|
879
|
-
const ajv = new import_ajv.Ajv();
|
|
880
|
-
const validate = ajv.compile(SCHEMA);
|
|
881
|
-
const isValid = validate(parsedConfig);
|
|
882
|
-
if (!isValid) {
|
|
883
|
-
throw new MicrofrontendError(
|
|
884
|
-
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
885
|
-
{ type: "config", subtype: "does_not_match_schema" }
|
|
886
|
-
);
|
|
887
|
-
}
|
|
888
|
-
return parsedConfig;
|
|
889
|
-
};
|
|
890
|
-
var SUPPORTED_VERSIONS2 = ["1"];
|
|
891
|
-
var validateVersion = (version) => {
|
|
892
|
-
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
893
|
-
throw new MicrofrontendError(
|
|
894
|
-
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
895
|
-
", "
|
|
896
|
-
)}`,
|
|
897
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
898
|
-
);
|
|
899
|
-
}
|
|
900
|
-
};
|
|
901
|
-
function validateMainPath(applicationConfigsById) {
|
|
902
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
903
|
-
const { defaultRoute } = app.vercel ?? {};
|
|
904
|
-
if (!defaultRoute) {
|
|
905
|
-
continue;
|
|
906
|
-
}
|
|
907
|
-
if (isDefaultApplicationConfig(app)) {
|
|
908
|
-
const pathsWithApp = [];
|
|
909
|
-
for (const [otherId, otherApp] of Object.entries(
|
|
910
|
-
applicationConfigsById
|
|
911
|
-
)) {
|
|
912
|
-
if (isDefaultApplicationConfig(otherApp)) {
|
|
913
|
-
continue;
|
|
914
|
-
}
|
|
915
|
-
pathsWithApp.push({
|
|
916
|
-
id: otherId,
|
|
917
|
-
paths: otherApp.routing.matches.flatMap((match) => match.paths)
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
for (const { id: otherId, paths } of pathsWithApp) {
|
|
921
|
-
const isValid = paths.every((path7) => {
|
|
922
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(path7);
|
|
923
|
-
return !matcher.test(defaultRoute);
|
|
924
|
-
});
|
|
925
|
-
if (!isValid) {
|
|
926
|
-
throw new MicrofrontendError(
|
|
927
|
-
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
928
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
929
|
-
);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
} else {
|
|
933
|
-
const allPaths = app.routing.matches.flatMap((match) => match.paths);
|
|
934
|
-
const isValid = allPaths.some((path7) => {
|
|
935
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(path7);
|
|
936
|
-
return matcher.test(defaultRoute);
|
|
937
|
-
});
|
|
938
|
-
if (!isValid) {
|
|
939
|
-
throw new MicrofrontendError(
|
|
940
|
-
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
941
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
942
|
-
);
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
var validatePaths = (applicationConfigsById) => {
|
|
948
|
-
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
949
|
-
const errors = [];
|
|
950
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
951
|
-
if (isDefaultApplicationConfig(app)) {
|
|
952
|
-
continue;
|
|
953
|
-
}
|
|
954
|
-
for (const pathMatch of app.routing.matches) {
|
|
955
|
-
for (const path7 of pathMatch.paths) {
|
|
956
|
-
const maybeError = validatePathExpression(path7);
|
|
957
|
-
if (maybeError) {
|
|
958
|
-
errors.push(maybeError);
|
|
959
|
-
}
|
|
960
|
-
const existing = pathsByApplicationId.get(path7);
|
|
961
|
-
if (existing) {
|
|
962
|
-
existing.applications.push(id);
|
|
963
|
-
} else {
|
|
964
|
-
pathsByApplicationId.set(path7, {
|
|
965
|
-
applications: [id],
|
|
966
|
-
matcher: (0, import_path_to_regexp.pathToRegexp)(path7),
|
|
967
|
-
applicationId: id
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
const entries = Array.from(pathsByApplicationId.entries());
|
|
974
|
-
entries.forEach(([path7, { applications: ids, matcher, applicationId }]) => {
|
|
975
|
-
if (ids.length > 1) {
|
|
976
|
-
errors.push(
|
|
977
|
-
`Duplicate path "${path7}" for applications "${ids.join(", ")}"`
|
|
978
|
-
);
|
|
979
|
-
}
|
|
980
|
-
entries.forEach(
|
|
981
|
-
([
|
|
982
|
-
matchPath,
|
|
983
|
-
{ applications: matchIds, applicationId: matchApplicationId }
|
|
984
|
-
]) => {
|
|
985
|
-
if (path7 === matchPath) {
|
|
986
|
-
return;
|
|
987
|
-
}
|
|
988
|
-
if (applicationId === matchApplicationId) {
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
if (matcher.test(matchPath)) {
|
|
992
|
-
const source = `"${path7}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
993
|
-
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
994
|
-
errors.push(
|
|
995
|
-
`Overlapping path detected between ${source} and ${destination}`
|
|
996
|
-
);
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
);
|
|
1000
|
-
});
|
|
1001
|
-
if (errors.length) {
|
|
1002
|
-
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1003
|
-
type: "config",
|
|
1004
|
-
subtype: "conflicting_paths"
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
};
|
|
1008
|
-
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
1009
|
-
function validatePathExpression(path7) {
|
|
1010
|
-
const tokens = (0, import_path_to_regexp.parse)(path7);
|
|
1011
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
1012
|
-
const token = tokens[i];
|
|
1013
|
-
if (token === void 0) {
|
|
1014
|
-
return `token ${i} in ${path7} is undefined, this shouldn't happen`;
|
|
1015
|
-
}
|
|
1016
|
-
if (typeof token !== "string") {
|
|
1017
|
-
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
1018
|
-
return `Path ${path7} cannot use a regular expression wildcard`;
|
|
1019
|
-
}
|
|
1020
|
-
if (token.prefix !== "/") {
|
|
1021
|
-
return `Wildcard :${token.name} must be immediately after a / in ${path7}`;
|
|
1022
|
-
}
|
|
1023
|
-
if (token.suffix) {
|
|
1024
|
-
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
1025
|
-
}
|
|
1026
|
-
if (token.modifier && i !== tokens.length - 1) {
|
|
1027
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path7}. Modifiers are only allowed in the last path component`;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
return void 0;
|
|
1032
|
-
}
|
|
1033
|
-
var validateDefaults = (applicationConfigsById) => {
|
|
1034
|
-
const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
|
|
1035
|
-
if (defaultApplicationIds.length === 0) {
|
|
1036
|
-
throw new MicrofrontendError(
|
|
1037
|
-
`No default application found. At least one application must be marked as default.`,
|
|
1038
|
-
{ type: "config", subtype: "no_default_application" }
|
|
1039
|
-
);
|
|
1040
|
-
}
|
|
1041
|
-
if (defaultApplicationIds.length > 1) {
|
|
1042
|
-
throw new MicrofrontendError(
|
|
1043
|
-
`Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
|
|
1044
|
-
{ type: "config", subtype: "multiple_default_applications" }
|
|
1045
|
-
);
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
var validateOptions = (options) => {
|
|
1049
|
-
var _a;
|
|
1050
|
-
if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
|
|
1051
|
-
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1052
|
-
options.vercel.previewDeploymentSuffix
|
|
1053
|
-
)) {
|
|
1054
|
-
throw new MicrofrontendError(
|
|
1055
|
-
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1056
|
-
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1057
|
-
);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
// src/config/utils/convert.ts
|
|
1063
|
-
function convertV1RoutingToV2Routing(routing) {
|
|
1064
|
-
return routing.matches.map((group) => {
|
|
1065
|
-
var _a;
|
|
1066
|
-
return {
|
|
1067
|
-
group: group.group,
|
|
1068
|
-
flag: (_a = group.options) == null ? void 0 : _a.flag,
|
|
1069
|
-
paths: group.paths
|
|
1070
|
-
};
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
function convertV1ApplicationToV2Application(application) {
|
|
1074
|
-
const common = {
|
|
1075
|
-
production: application.production,
|
|
1076
|
-
development: application.development,
|
|
1077
|
-
vercel: application.vercel
|
|
1078
|
-
};
|
|
1079
|
-
if (application.default) {
|
|
1080
|
-
return common;
|
|
1081
|
-
}
|
|
1082
|
-
return {
|
|
1083
|
-
...common,
|
|
1084
|
-
routing: convertV1RoutingToV2Routing(application.routing)
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
function convertV1ConfigToV2Config(config, fromApp) {
|
|
1088
|
-
if (!config.applications[fromApp]) {
|
|
1089
|
-
throw new Error(`Application "${fromApp}" not found in the config`);
|
|
1090
|
-
}
|
|
1091
|
-
const common = {
|
|
1092
|
-
version: "2",
|
|
1093
|
-
options: config.options
|
|
1094
|
-
};
|
|
1095
|
-
if (config.applications[fromApp].default) {
|
|
1096
|
-
return {
|
|
1097
|
-
...common,
|
|
1098
|
-
applications: Object.fromEntries(
|
|
1099
|
-
Object.entries(config.applications).map(([id, application]) => [
|
|
1100
|
-
id,
|
|
1101
|
-
convertV1ApplicationToV2Application(application)
|
|
1102
|
-
])
|
|
1103
|
-
)
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
const defaultApplication = Object.entries(config.applications).find(
|
|
1107
|
-
([, application]) => application.default
|
|
1108
|
-
);
|
|
1109
|
-
if (!defaultApplication) {
|
|
1110
|
-
throw new Error("No default application found in the config");
|
|
1111
|
-
}
|
|
1112
|
-
return {
|
|
1113
|
-
...common,
|
|
1114
|
-
partOf: defaultApplication[0]
|
|
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/microfrontend-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
|
-
};
|
|
36
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
37
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
1181
38
|
|
|
1182
|
-
// src/config
|
|
1183
|
-
var
|
|
1184
|
-
var
|
|
39
|
+
// src/config/microfrontends/server/index.ts
|
|
40
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
41
|
+
var import_node_path8 = require("path");
|
|
1185
42
|
|
|
1186
|
-
// src/config
|
|
1187
|
-
var
|
|
1188
|
-
var OVERRIDES_ENV_COOKIE_PREFIX = `${
|
|
43
|
+
// src/config/overrides/constants.ts
|
|
44
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
45
|
+
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
1189
46
|
|
|
1190
|
-
// src/config
|
|
47
|
+
// src/config/overrides/is-override-cookie.ts
|
|
1191
48
|
function isOverrideCookie(cookie) {
|
|
1192
49
|
var _a;
|
|
1193
|
-
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(
|
|
50
|
+
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
1194
51
|
}
|
|
1195
52
|
|
|
1196
|
-
// src/config
|
|
53
|
+
// src/config/overrides/get-override-from-cookie.ts
|
|
1197
54
|
function getOverrideFromCookie(cookie) {
|
|
1198
55
|
if (!isOverrideCookie(cookie) || !cookie.value)
|
|
1199
56
|
return;
|
|
@@ -1203,7 +60,7 @@ function getOverrideFromCookie(cookie) {
|
|
|
1203
60
|
};
|
|
1204
61
|
}
|
|
1205
62
|
|
|
1206
|
-
// src/config
|
|
63
|
+
// src/config/overrides/parse-overrides.ts
|
|
1207
64
|
function parseOverrides(cookies) {
|
|
1208
65
|
const overridesConfig = { applications: {} };
|
|
1209
66
|
cookies.forEach((cookie) => {
|
|
@@ -1217,15 +74,15 @@ function parseOverrides(cookies) {
|
|
|
1217
74
|
return overridesConfig;
|
|
1218
75
|
}
|
|
1219
76
|
|
|
1220
|
-
// src/config
|
|
1221
|
-
var
|
|
77
|
+
// src/config/errors.ts
|
|
78
|
+
var MicrofrontendError = class extends Error {
|
|
1222
79
|
constructor(message, opts) {
|
|
1223
80
|
super(message);
|
|
1224
81
|
this.name = "MicrofrontendsError";
|
|
1225
82
|
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
1226
83
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
1227
84
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
1228
|
-
Error.captureStackTrace(this,
|
|
85
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
1229
86
|
}
|
|
1230
87
|
isKnown() {
|
|
1231
88
|
return this.type !== "unknown";
|
|
@@ -1240,7 +97,7 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1240
97
|
*/
|
|
1241
98
|
static convert(original, opts) {
|
|
1242
99
|
if (opts == null ? void 0 : opts.fileName) {
|
|
1243
|
-
const err =
|
|
100
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
1244
101
|
if (err) {
|
|
1245
102
|
return err;
|
|
1246
103
|
}
|
|
@@ -1248,25 +105,25 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1248
105
|
if (original.message.includes(
|
|
1249
106
|
"Code generation from strings disallowed for this context"
|
|
1250
107
|
)) {
|
|
1251
|
-
return new
|
|
108
|
+
return new MicrofrontendError(original.message, {
|
|
1252
109
|
type: "config",
|
|
1253
110
|
subtype: "unsupported_validation_env",
|
|
1254
111
|
source: "ajv"
|
|
1255
112
|
});
|
|
1256
113
|
}
|
|
1257
|
-
return new
|
|
114
|
+
return new MicrofrontendError(original.message);
|
|
1258
115
|
}
|
|
1259
116
|
static convertFSError(original, fileName) {
|
|
1260
117
|
if (original instanceof Error && "code" in original) {
|
|
1261
118
|
if (original.code === "ENOENT") {
|
|
1262
|
-
return new
|
|
119
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
1263
120
|
type: "config",
|
|
1264
121
|
subtype: "unable_to_read_file",
|
|
1265
122
|
source: "fs"
|
|
1266
123
|
});
|
|
1267
124
|
}
|
|
1268
125
|
if (original.code === "EACCES") {
|
|
1269
|
-
return new
|
|
126
|
+
return new MicrofrontendError(
|
|
1270
127
|
`Permission denied while accessing "${fileName}"`,
|
|
1271
128
|
{
|
|
1272
129
|
type: "config",
|
|
@@ -1277,7 +134,7 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1277
134
|
}
|
|
1278
135
|
}
|
|
1279
136
|
if (original instanceof SyntaxError) {
|
|
1280
|
-
return new
|
|
137
|
+
return new MicrofrontendError(
|
|
1281
138
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
1282
139
|
{
|
|
1283
140
|
type: "config",
|
|
@@ -1294,26 +151,26 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1294
151
|
* @returns A MicrofrontendsError instance.
|
|
1295
152
|
*/
|
|
1296
153
|
static handle(err, opts) {
|
|
1297
|
-
if (err instanceof
|
|
154
|
+
if (err instanceof MicrofrontendError) {
|
|
1298
155
|
return err;
|
|
1299
156
|
}
|
|
1300
157
|
if (err instanceof Error) {
|
|
1301
|
-
return
|
|
158
|
+
return MicrofrontendError.convert(err, opts);
|
|
1302
159
|
}
|
|
1303
160
|
if (typeof err === "object" && err !== null) {
|
|
1304
161
|
if ("message" in err && typeof err.message === "string") {
|
|
1305
|
-
return
|
|
162
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
1306
163
|
}
|
|
1307
164
|
}
|
|
1308
|
-
return new
|
|
165
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
1309
166
|
}
|
|
1310
167
|
};
|
|
1311
168
|
|
|
1312
|
-
// src/config
|
|
169
|
+
// src/config/microfrontends-config/utils/get-config-from-env.ts
|
|
1313
170
|
function getConfigStringFromEnv() {
|
|
1314
171
|
const config = process.env.MFE_CONFIG;
|
|
1315
172
|
if (!config) {
|
|
1316
|
-
throw new
|
|
173
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
1317
174
|
type: "config",
|
|
1318
175
|
subtype: "not_found_in_env"
|
|
1319
176
|
});
|
|
@@ -1321,21 +178,21 @@ function getConfigStringFromEnv() {
|
|
|
1321
178
|
return config;
|
|
1322
179
|
}
|
|
1323
180
|
|
|
1324
|
-
// src/config
|
|
1325
|
-
var
|
|
181
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
182
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
1326
183
|
|
|
1327
|
-
// src/config
|
|
184
|
+
// src/config/schema/utils/is-main-config.ts
|
|
1328
185
|
function isMainConfig(c) {
|
|
1329
186
|
return !("partOf" in c);
|
|
1330
187
|
}
|
|
1331
188
|
|
|
1332
|
-
// src/config
|
|
189
|
+
// src/config/schema/utils/is-default-app.ts
|
|
1333
190
|
function isDefaultApp(a) {
|
|
1334
191
|
return !("routing" in a);
|
|
1335
192
|
}
|
|
1336
193
|
|
|
1337
|
-
// src/config
|
|
1338
|
-
var
|
|
194
|
+
// src/config/microfrontends-config/client/index.ts
|
|
195
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
1339
196
|
var MicrofrontendConfigClient = class {
|
|
1340
197
|
constructor(config, opts) {
|
|
1341
198
|
this.pathCache = {};
|
|
@@ -1365,21 +222,21 @@ var MicrofrontendConfigClient = class {
|
|
|
1365
222
|
isEqual(other) {
|
|
1366
223
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
1367
224
|
}
|
|
1368
|
-
getApplicationNameForPath(
|
|
1369
|
-
if (!
|
|
225
|
+
getApplicationNameForPath(path6) {
|
|
226
|
+
if (!path6.startsWith("/")) {
|
|
1370
227
|
throw new Error(`Path must start with a /`);
|
|
1371
228
|
}
|
|
1372
|
-
if (this.pathCache[
|
|
1373
|
-
return this.pathCache[
|
|
229
|
+
if (this.pathCache[path6]) {
|
|
230
|
+
return this.pathCache[path6];
|
|
1374
231
|
}
|
|
1375
|
-
const pathname = new URL(
|
|
232
|
+
const pathname = new URL(path6, "https://example.com").pathname;
|
|
1376
233
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
1377
234
|
if (application.routing) {
|
|
1378
235
|
for (const group of application.routing) {
|
|
1379
236
|
for (const childPath of group.paths) {
|
|
1380
|
-
const regexp = (0,
|
|
237
|
+
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
1381
238
|
if (regexp.test(pathname)) {
|
|
1382
|
-
this.pathCache[
|
|
239
|
+
this.pathCache[path6] = name;
|
|
1383
240
|
return name;
|
|
1384
241
|
}
|
|
1385
242
|
}
|
|
@@ -1392,7 +249,7 @@ var MicrofrontendConfigClient = class {
|
|
|
1392
249
|
if (!defaultApplication) {
|
|
1393
250
|
return null;
|
|
1394
251
|
}
|
|
1395
|
-
this.pathCache[
|
|
252
|
+
this.pathCache[path6] = defaultApplication[0];
|
|
1396
253
|
return defaultApplication[0];
|
|
1397
254
|
}
|
|
1398
255
|
serialize() {
|
|
@@ -1400,13 +257,13 @@ var MicrofrontendConfigClient = class {
|
|
|
1400
257
|
}
|
|
1401
258
|
};
|
|
1402
259
|
|
|
1403
|
-
// src/config
|
|
1404
|
-
var
|
|
1405
|
-
var
|
|
260
|
+
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
261
|
+
var import_path_to_regexp2 = require("path-to-regexp");
|
|
262
|
+
var SUPPORTED_VERSIONS = ["2"];
|
|
1406
263
|
var validateConfigVersion = (version) => {
|
|
1407
|
-
if (!
|
|
1408
|
-
throw new
|
|
1409
|
-
`Unsupported version: ${version}. Supported versions are: ${
|
|
264
|
+
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
265
|
+
throw new MicrofrontendError(
|
|
266
|
+
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
1410
267
|
", "
|
|
1411
268
|
)}`,
|
|
1412
269
|
{ type: "config", subtype: "unsupported_version" }
|
|
@@ -1424,22 +281,18 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1424
281
|
continue;
|
|
1425
282
|
}
|
|
1426
283
|
for (const pathMatch of app.routing) {
|
|
1427
|
-
for (const
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
errors.push(
|
|
1432
|
-
`Path ${path7} may only have a :wildcard in the last path component`
|
|
1433
|
-
);
|
|
1434
|
-
}
|
|
284
|
+
for (const path6 of pathMatch.paths) {
|
|
285
|
+
const maybeError = validatePathExpression(path6);
|
|
286
|
+
if (maybeError) {
|
|
287
|
+
errors.push(maybeError);
|
|
1435
288
|
}
|
|
1436
|
-
const existing = pathsByApplicationId.get(
|
|
289
|
+
const existing = pathsByApplicationId.get(path6);
|
|
1437
290
|
if (existing) {
|
|
1438
291
|
existing.applications.push(id);
|
|
1439
292
|
} else {
|
|
1440
|
-
pathsByApplicationId.set(
|
|
293
|
+
pathsByApplicationId.set(path6, {
|
|
1441
294
|
applications: [id],
|
|
1442
|
-
matcher: (0,
|
|
295
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path6),
|
|
1443
296
|
applicationId: id
|
|
1444
297
|
});
|
|
1445
298
|
}
|
|
@@ -1447,10 +300,10 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1447
300
|
}
|
|
1448
301
|
}
|
|
1449
302
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
1450
|
-
entries.forEach(([
|
|
303
|
+
entries.forEach(([path6, { applications: ids, matcher, applicationId }]) => {
|
|
1451
304
|
if (ids.length > 1) {
|
|
1452
305
|
errors.push(
|
|
1453
|
-
`Duplicate path "${
|
|
306
|
+
`Duplicate path "${path6}" for applications "${ids.join(", ")}"`
|
|
1454
307
|
);
|
|
1455
308
|
}
|
|
1456
309
|
entries.forEach(
|
|
@@ -1458,14 +311,14 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1458
311
|
matchPath,
|
|
1459
312
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
1460
313
|
]) => {
|
|
1461
|
-
if (
|
|
314
|
+
if (path6 === matchPath) {
|
|
1462
315
|
return;
|
|
1463
316
|
}
|
|
1464
317
|
if (applicationId === matchApplicationId) {
|
|
1465
318
|
return;
|
|
1466
319
|
}
|
|
1467
320
|
if (matcher.test(matchPath)) {
|
|
1468
|
-
const source = `"${
|
|
321
|
+
const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
1469
322
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
1470
323
|
errors.push(
|
|
1471
324
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -1475,12 +328,37 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1475
328
|
);
|
|
1476
329
|
});
|
|
1477
330
|
if (errors.length) {
|
|
1478
|
-
throw new
|
|
331
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1479
332
|
type: "config",
|
|
1480
333
|
subtype: "conflicting_paths"
|
|
1481
334
|
});
|
|
1482
335
|
}
|
|
1483
336
|
};
|
|
337
|
+
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
338
|
+
function validatePathExpression(path6) {
|
|
339
|
+
const tokens = (0, import_path_to_regexp2.parse)(path6);
|
|
340
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
341
|
+
const token = tokens[i];
|
|
342
|
+
if (token === void 0) {
|
|
343
|
+
return `token ${i} in ${path6} is undefined, this shouldn't happen`;
|
|
344
|
+
}
|
|
345
|
+
if (typeof token !== "string") {
|
|
346
|
+
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
347
|
+
return `Path ${path6} cannot use a regular expression wildcard`;
|
|
348
|
+
}
|
|
349
|
+
if (token.prefix !== "/") {
|
|
350
|
+
return `Wildcard :${token.name} must be immediately after a / in ${path6}`;
|
|
351
|
+
}
|
|
352
|
+
if (token.suffix) {
|
|
353
|
+
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
354
|
+
}
|
|
355
|
+
if (token.modifier && i !== tokens.length - 1) {
|
|
356
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return void 0;
|
|
361
|
+
}
|
|
1484
362
|
var validateAppPaths = (name, app) => {
|
|
1485
363
|
for (const group of app.routing) {
|
|
1486
364
|
for (const p of group.paths) {
|
|
@@ -1488,13 +366,13 @@ var validateAppPaths = (name, app) => {
|
|
|
1488
366
|
continue;
|
|
1489
367
|
}
|
|
1490
368
|
if (p.endsWith("/")) {
|
|
1491
|
-
throw new
|
|
369
|
+
throw new MicrofrontendError(
|
|
1492
370
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
1493
371
|
{ type: "application", subtype: "invalid_path" }
|
|
1494
372
|
);
|
|
1495
373
|
}
|
|
1496
374
|
if (!p.startsWith("/")) {
|
|
1497
|
-
throw new
|
|
375
|
+
throw new MicrofrontendError(
|
|
1498
376
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
1499
377
|
{ type: "application", subtype: "invalid_path" }
|
|
1500
378
|
);
|
|
@@ -1516,20 +394,20 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
1516
394
|
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
1517
395
|
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
1518
396
|
if (numApplicationsWithoutRouting === 0) {
|
|
1519
|
-
throw new
|
|
397
|
+
throw new MicrofrontendError(
|
|
1520
398
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
1521
399
|
{ type: "config", subtype: "no_default_application" }
|
|
1522
400
|
);
|
|
1523
401
|
}
|
|
1524
402
|
if (numApplicationsWithoutRouting > 1) {
|
|
1525
|
-
throw new
|
|
403
|
+
throw new MicrofrontendError(
|
|
1526
404
|
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
1527
405
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
1528
406
|
);
|
|
1529
407
|
}
|
|
1530
408
|
};
|
|
1531
409
|
|
|
1532
|
-
// src/config
|
|
410
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
1533
411
|
var PREFIX = "vc-ap";
|
|
1534
412
|
function generateAssetPrefixFromName({
|
|
1535
413
|
name
|
|
@@ -1540,7 +418,7 @@ function generateAssetPrefixFromName({
|
|
|
1540
418
|
return `${PREFIX}-${name}`;
|
|
1541
419
|
}
|
|
1542
420
|
|
|
1543
|
-
// src/config
|
|
421
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-port.ts
|
|
1544
422
|
function generatePortFromName({
|
|
1545
423
|
name,
|
|
1546
424
|
minPort = 3e3,
|
|
@@ -1560,13 +438,13 @@ function generatePortFromName({
|
|
|
1560
438
|
return port;
|
|
1561
439
|
}
|
|
1562
440
|
|
|
1563
|
-
// src/config
|
|
1564
|
-
var
|
|
441
|
+
// src/config/microfrontends-config/isomorphic/host.ts
|
|
442
|
+
var Host = class {
|
|
1565
443
|
constructor(hostConfig, options) {
|
|
1566
444
|
const { protocol = "https", host, port } = hostConfig;
|
|
1567
445
|
this.protocol = protocol;
|
|
1568
446
|
this.host = host;
|
|
1569
|
-
this.port =
|
|
447
|
+
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
1570
448
|
this.local = options == null ? void 0 : options.isLocal;
|
|
1571
449
|
}
|
|
1572
450
|
isLocal() {
|
|
@@ -1585,7 +463,7 @@ var Host2 = class {
|
|
|
1585
463
|
return port;
|
|
1586
464
|
}
|
|
1587
465
|
isDefaultPort() {
|
|
1588
|
-
return this.port ===
|
|
466
|
+
return this.port === Host.getPort({ protocol: this.protocol });
|
|
1589
467
|
}
|
|
1590
468
|
toString(opts = {}) {
|
|
1591
469
|
const url = this.toUrl(opts);
|
|
@@ -1597,7 +475,7 @@ var Host2 = class {
|
|
|
1597
475
|
return new URL(url);
|
|
1598
476
|
}
|
|
1599
477
|
};
|
|
1600
|
-
var LocalHost = class extends
|
|
478
|
+
var LocalHost = class extends Host {
|
|
1601
479
|
constructor({
|
|
1602
480
|
appName,
|
|
1603
481
|
...hostConfig
|
|
@@ -1609,8 +487,8 @@ var LocalHost = class extends Host2 {
|
|
|
1609
487
|
}
|
|
1610
488
|
};
|
|
1611
489
|
|
|
1612
|
-
// src/config
|
|
1613
|
-
var
|
|
490
|
+
// src/config/microfrontends-config/isomorphic/application.ts
|
|
491
|
+
var Application = class {
|
|
1614
492
|
constructor(name, {
|
|
1615
493
|
app,
|
|
1616
494
|
overrides,
|
|
@@ -1623,12 +501,12 @@ var Application2 = class {
|
|
|
1623
501
|
appName: name,
|
|
1624
502
|
...(_a = app.development) == null ? void 0 : _a.local
|
|
1625
503
|
}),
|
|
1626
|
-
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new
|
|
504
|
+
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
|
|
1627
505
|
};
|
|
1628
|
-
this.production = app.production ? new
|
|
506
|
+
this.production = app.production ? new Host(app.production) : void 0;
|
|
1629
507
|
this.vercel = app.vercel;
|
|
1630
508
|
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
1631
|
-
environment: new
|
|
509
|
+
environment: new Host(overrides.environment)
|
|
1632
510
|
} : void 0;
|
|
1633
511
|
this.default = isDefault ?? false;
|
|
1634
512
|
this.serialized = app;
|
|
@@ -1643,7 +521,7 @@ var Application2 = class {
|
|
|
1643
521
|
return this.serialized;
|
|
1644
522
|
}
|
|
1645
523
|
};
|
|
1646
|
-
var DefaultApplication = class extends
|
|
524
|
+
var DefaultApplication = class extends Application {
|
|
1647
525
|
constructor(name, {
|
|
1648
526
|
app,
|
|
1649
527
|
overrides
|
|
@@ -1654,13 +532,13 @@ var DefaultApplication = class extends Application2 {
|
|
|
1654
532
|
isDefault: true
|
|
1655
533
|
});
|
|
1656
534
|
this.default = true;
|
|
1657
|
-
this.production = new
|
|
535
|
+
this.production = new Host(app.production);
|
|
1658
536
|
}
|
|
1659
537
|
getAssetPrefix() {
|
|
1660
538
|
return "";
|
|
1661
539
|
}
|
|
1662
540
|
};
|
|
1663
|
-
var ChildApplication = class extends
|
|
541
|
+
var ChildApplication = class extends Application {
|
|
1664
542
|
constructor(name, {
|
|
1665
543
|
app,
|
|
1666
544
|
overrides
|
|
@@ -1679,10 +557,10 @@ var ChildApplication = class extends Application2 {
|
|
|
1679
557
|
}
|
|
1680
558
|
};
|
|
1681
559
|
|
|
1682
|
-
// src/config
|
|
1683
|
-
var
|
|
560
|
+
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
561
|
+
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
1684
562
|
|
|
1685
|
-
// src/config
|
|
563
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
1686
564
|
var MicrofrontendConfigIsomorphic = class {
|
|
1687
565
|
constructor({
|
|
1688
566
|
config,
|
|
@@ -1723,7 +601,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1723
601
|
);
|
|
1724
602
|
}
|
|
1725
603
|
if (isMainConfig(config) && !this.defaultApplication) {
|
|
1726
|
-
throw new
|
|
604
|
+
throw new MicrofrontendError(
|
|
1727
605
|
`Could not find default application in microfrontends configuration`,
|
|
1728
606
|
{
|
|
1729
607
|
type: "application",
|
|
@@ -1740,7 +618,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1740
618
|
};
|
|
1741
619
|
}
|
|
1742
620
|
static validate(config) {
|
|
1743
|
-
const c = typeof config === "string" ? (0,
|
|
621
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
1744
622
|
if (isMainConfig(c)) {
|
|
1745
623
|
validateConfigVersion(c.version);
|
|
1746
624
|
validateConfigPaths(c.applications);
|
|
@@ -1753,7 +631,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1753
631
|
cookies
|
|
1754
632
|
}) {
|
|
1755
633
|
return new MicrofrontendConfigIsomorphic({
|
|
1756
|
-
config: (0,
|
|
634
|
+
config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
|
|
1757
635
|
overrides: parseOverrides(cookies ?? []),
|
|
1758
636
|
meta
|
|
1759
637
|
});
|
|
@@ -1787,7 +665,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1787
665
|
}
|
|
1788
666
|
const app = this.childApplications[name];
|
|
1789
667
|
if (!app) {
|
|
1790
|
-
throw new
|
|
668
|
+
throw new MicrofrontendError(
|
|
1791
669
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
1792
670
|
{
|
|
1793
671
|
type: "application",
|
|
@@ -1815,7 +693,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1815
693
|
*/
|
|
1816
694
|
getDefaultApplication() {
|
|
1817
695
|
if (!this.defaultApplication) {
|
|
1818
|
-
throw new
|
|
696
|
+
throw new MicrofrontendError(
|
|
1819
697
|
`Could not find default application in microfrontends configuration`,
|
|
1820
698
|
{
|
|
1821
699
|
type: "application",
|
|
@@ -1830,7 +708,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1830
708
|
*/
|
|
1831
709
|
getLocalProxyPort() {
|
|
1832
710
|
var _a, _b;
|
|
1833
|
-
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ??
|
|
711
|
+
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
1834
712
|
}
|
|
1835
713
|
/**
|
|
1836
714
|
* Serializes the class back to the Schema type.
|
|
@@ -1864,7 +742,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1864
742
|
}
|
|
1865
743
|
};
|
|
1866
744
|
|
|
1867
|
-
// src/config
|
|
745
|
+
// src/config/microfrontends-config/isomorphic/child.ts
|
|
1868
746
|
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
1869
747
|
constructor({
|
|
1870
748
|
config,
|
|
@@ -1877,7 +755,7 @@ var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
1877
755
|
}
|
|
1878
756
|
};
|
|
1879
757
|
|
|
1880
|
-
// src/config
|
|
758
|
+
// src/config/microfrontends-config/isomorphic/main.ts
|
|
1881
759
|
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
1882
760
|
constructor({
|
|
1883
761
|
config,
|
|
@@ -1904,7 +782,7 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
1904
782
|
}
|
|
1905
783
|
}
|
|
1906
784
|
if (!defaultApplication) {
|
|
1907
|
-
throw new
|
|
785
|
+
throw new MicrofrontendError(
|
|
1908
786
|
`Could not find default application in microfrontends configuration`,
|
|
1909
787
|
{
|
|
1910
788
|
type: "application",
|
|
@@ -1916,7 +794,7 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
1916
794
|
}
|
|
1917
795
|
};
|
|
1918
796
|
|
|
1919
|
-
// src/config
|
|
797
|
+
// src/config/microfrontends/isomorphic/index.ts
|
|
1920
798
|
var Microfrontends = class {
|
|
1921
799
|
constructor({
|
|
1922
800
|
config,
|
|
@@ -1944,27 +822,27 @@ var Microfrontends = class {
|
|
|
1944
822
|
}
|
|
1945
823
|
};
|
|
1946
824
|
|
|
1947
|
-
// src/config
|
|
1948
|
-
var
|
|
1949
|
-
var
|
|
825
|
+
// src/config/microfrontends/utils/find-repository-root.ts
|
|
826
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
827
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
1950
828
|
var GIT_DIRECTORY = ".git";
|
|
1951
829
|
function findRepositoryRoot(startDir) {
|
|
1952
830
|
let currentDir = startDir || process.cwd();
|
|
1953
|
-
while (currentDir !==
|
|
1954
|
-
const gitPath =
|
|
1955
|
-
if (
|
|
831
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
832
|
+
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
833
|
+
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
1956
834
|
return currentDir;
|
|
1957
835
|
}
|
|
1958
|
-
currentDir =
|
|
836
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
1959
837
|
}
|
|
1960
838
|
throw new Error(
|
|
1961
839
|
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
1962
840
|
);
|
|
1963
841
|
}
|
|
1964
842
|
|
|
1965
|
-
// src/config
|
|
1966
|
-
var
|
|
1967
|
-
var
|
|
843
|
+
// src/config/microfrontends/utils/find-package-path.ts
|
|
844
|
+
var import_node_path2 = require("path");
|
|
845
|
+
var import_node_fs2 = require("fs");
|
|
1968
846
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
1969
847
|
var configCache = {};
|
|
1970
848
|
function findPackagePathWithGlob({
|
|
@@ -1981,7 +859,7 @@ function findPackagePathWithGlob({
|
|
|
1981
859
|
});
|
|
1982
860
|
const matchingPaths = [];
|
|
1983
861
|
for (const packageJsonPath2 of packageJsonPaths) {
|
|
1984
|
-
const packageJsonContent = (0,
|
|
862
|
+
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
1985
863
|
const packageJson = JSON.parse(packageJsonContent);
|
|
1986
864
|
if (packageJson.name === name) {
|
|
1987
865
|
matchingPaths.push(packageJsonPath2);
|
|
@@ -1998,7 +876,7 @@ function findPackagePathWithGlob({
|
|
|
1998
876
|
);
|
|
1999
877
|
}
|
|
2000
878
|
const [packageJsonPath] = matchingPaths;
|
|
2001
|
-
return (0,
|
|
879
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
2002
880
|
} catch (error) {
|
|
2003
881
|
return null;
|
|
2004
882
|
}
|
|
@@ -2018,19 +896,19 @@ function findPackagePath(opts) {
|
|
|
2018
896
|
return result;
|
|
2019
897
|
}
|
|
2020
898
|
|
|
2021
|
-
// src/config
|
|
2022
|
-
var
|
|
2023
|
-
var
|
|
2024
|
-
var
|
|
899
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
900
|
+
var import_node_path3 = require("path");
|
|
901
|
+
var import_node_fs3 = require("fs");
|
|
902
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
2025
903
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
2026
904
|
|
|
2027
|
-
// src/config
|
|
905
|
+
// src/config/constants.ts
|
|
2028
906
|
var CONFIGURATION_FILENAMES = [
|
|
2029
907
|
"microfrontends.jsonc",
|
|
2030
908
|
"microfrontends.json"
|
|
2031
909
|
];
|
|
2032
910
|
|
|
2033
|
-
// src/config
|
|
911
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
2034
912
|
var configCache2 = {};
|
|
2035
913
|
function findDefaultMicrofrontendsPackages({
|
|
2036
914
|
repositoryRoot,
|
|
@@ -2049,11 +927,11 @@ function findDefaultMicrofrontendsPackages({
|
|
|
2049
927
|
);
|
|
2050
928
|
const matchingPaths = [];
|
|
2051
929
|
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
2052
|
-
const microfrontendsJsonContent = (0,
|
|
930
|
+
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
2053
931
|
microfrontendsJsonPath,
|
|
2054
932
|
"utf-8"
|
|
2055
933
|
);
|
|
2056
|
-
const microfrontendsJson = (0,
|
|
934
|
+
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
2057
935
|
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
2058
936
|
matchingPaths.push(microfrontendsJsonPath);
|
|
2059
937
|
}
|
|
@@ -2070,7 +948,7 @@ ${matchingPaths.join("\n \u2022 ")}`
|
|
|
2070
948
|
);
|
|
2071
949
|
}
|
|
2072
950
|
const [packageJsonPath] = matchingPaths;
|
|
2073
|
-
return (0,
|
|
951
|
+
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
2074
952
|
} catch (error) {
|
|
2075
953
|
return null;
|
|
2076
954
|
}
|
|
@@ -2090,25 +968,25 @@ function findDefaultMicrofrontendsPackage(opts) {
|
|
|
2090
968
|
return result;
|
|
2091
969
|
}
|
|
2092
970
|
|
|
2093
|
-
// src/config
|
|
2094
|
-
var
|
|
2095
|
-
var
|
|
971
|
+
// src/config/microfrontends/utils/is-monorepo.ts
|
|
972
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
973
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
2096
974
|
function isMonorepo({
|
|
2097
975
|
repositoryRoot
|
|
2098
976
|
}) {
|
|
2099
977
|
try {
|
|
2100
|
-
if (
|
|
978
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
2101
979
|
return true;
|
|
2102
980
|
}
|
|
2103
|
-
if (
|
|
981
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
2104
982
|
return true;
|
|
2105
983
|
}
|
|
2106
|
-
const packageJsonPath =
|
|
2107
|
-
if (!
|
|
984
|
+
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
985
|
+
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
2108
986
|
return false;
|
|
2109
987
|
}
|
|
2110
988
|
const packageJson = JSON.parse(
|
|
2111
|
-
|
|
989
|
+
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
2112
990
|
);
|
|
2113
991
|
return packageJson.workspaces !== void 0;
|
|
2114
992
|
} catch (error) {
|
|
@@ -2117,43 +995,67 @@ function isMonorepo({
|
|
|
2117
995
|
}
|
|
2118
996
|
}
|
|
2119
997
|
|
|
2120
|
-
// src/config
|
|
2121
|
-
var
|
|
2122
|
-
var
|
|
998
|
+
// src/config/microfrontends/utils/find-package-root.ts
|
|
999
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1000
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
2123
1001
|
var PACKAGE_JSON = "package.json";
|
|
2124
1002
|
function findPackageRoot(startDir) {
|
|
2125
1003
|
let currentDir = startDir || process.cwd();
|
|
2126
|
-
while (currentDir !==
|
|
2127
|
-
const pkgJsonPath =
|
|
2128
|
-
if (
|
|
1004
|
+
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
1005
|
+
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
1006
|
+
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
2129
1007
|
return currentDir;
|
|
2130
1008
|
}
|
|
2131
|
-
currentDir =
|
|
1009
|
+
currentDir = import_node_path5.default.dirname(currentDir);
|
|
2132
1010
|
}
|
|
2133
1011
|
throw new Error(
|
|
2134
1012
|
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
2135
1013
|
);
|
|
2136
1014
|
}
|
|
2137
1015
|
|
|
2138
|
-
// src/config
|
|
2139
|
-
var
|
|
2140
|
-
var
|
|
1016
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
1017
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1018
|
+
var import_node_path6 = require("path");
|
|
2141
1019
|
function findConfig({ dir }) {
|
|
2142
1020
|
for (const filename of CONFIGURATION_FILENAMES) {
|
|
2143
|
-
const maybeConfig = (0,
|
|
2144
|
-
if (
|
|
1021
|
+
const maybeConfig = (0, import_node_path6.join)(dir, filename);
|
|
1022
|
+
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
2145
1023
|
return maybeConfig;
|
|
2146
1024
|
}
|
|
2147
1025
|
}
|
|
2148
1026
|
return null;
|
|
2149
1027
|
}
|
|
2150
1028
|
|
|
2151
|
-
// src/config
|
|
2152
|
-
var
|
|
2153
|
-
|
|
1029
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1030
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1031
|
+
|
|
1032
|
+
// src/config/microfrontends/server/constants.ts
|
|
1033
|
+
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
1034
|
+
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
1035
|
+
|
|
1036
|
+
// src/utils/is-vercel.ts
|
|
1037
|
+
function isVercel() {
|
|
1038
|
+
return process.env.VERCEL === "1";
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1042
|
+
function getOutputFilePath() {
|
|
1043
|
+
if (isVercel()) {
|
|
1044
|
+
return import_node_path7.default.join(
|
|
1045
|
+
".vercel",
|
|
1046
|
+
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
1047
|
+
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// src/config/microfrontends/server/validation.ts
|
|
1054
|
+
var import_jsonc_parser3 = require("jsonc-parser");
|
|
1055
|
+
var import_ajv = require("ajv");
|
|
2154
1056
|
|
|
2155
|
-
// schema/schema
|
|
2156
|
-
var
|
|
1057
|
+
// schema/schema.json
|
|
1058
|
+
var schema_default = {
|
|
2157
1059
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
2158
1060
|
$ref: "#/definitions/Config",
|
|
2159
1061
|
definitions: {
|
|
@@ -2192,7 +1094,8 @@ var schema_v2_default = {
|
|
|
2192
1094
|
description: "Mapping of application names to the routes that they host. Only needs to be defined in the application that owns the primary microfrontend domain"
|
|
2193
1095
|
}
|
|
2194
1096
|
},
|
|
2195
|
-
required: ["applications", "version"]
|
|
1097
|
+
required: ["applications", "version"],
|
|
1098
|
+
additionalProperties: false
|
|
2196
1099
|
},
|
|
2197
1100
|
Options: {
|
|
2198
1101
|
type: "object",
|
|
@@ -2205,7 +1108,8 @@ var schema_v2_default = {
|
|
|
2205
1108
|
$ref: "#/definitions/LocalProxyOptions",
|
|
2206
1109
|
description: "Options for local proxy."
|
|
2207
1110
|
}
|
|
2208
|
-
}
|
|
1111
|
+
},
|
|
1112
|
+
additionalProperties: false
|
|
2209
1113
|
},
|
|
2210
1114
|
VercelOptions: {
|
|
2211
1115
|
type: "object",
|
|
@@ -2218,7 +1122,8 @@ var schema_v2_default = {
|
|
|
2218
1122
|
type: "boolean",
|
|
2219
1123
|
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."
|
|
2220
1124
|
}
|
|
2221
|
-
}
|
|
1125
|
+
},
|
|
1126
|
+
additionalProperties: false
|
|
2222
1127
|
},
|
|
2223
1128
|
LocalProxyOptions: {
|
|
2224
1129
|
type: "object",
|
|
@@ -2227,7 +1132,8 @@ var schema_v2_default = {
|
|
|
2227
1132
|
type: "number",
|
|
2228
1133
|
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
2229
1134
|
}
|
|
2230
|
-
}
|
|
1135
|
+
},
|
|
1136
|
+
additionalProperties: false
|
|
2231
1137
|
},
|
|
2232
1138
|
Application: {
|
|
2233
1139
|
anyOf: [
|
|
@@ -2252,7 +1158,8 @@ var schema_v2_default = {
|
|
|
2252
1158
|
$ref: "#/definitions/HostConfig"
|
|
2253
1159
|
}
|
|
2254
1160
|
},
|
|
2255
|
-
required: ["production"]
|
|
1161
|
+
required: ["production"],
|
|
1162
|
+
additionalProperties: false
|
|
2256
1163
|
},
|
|
2257
1164
|
Vercel: {
|
|
2258
1165
|
type: "object",
|
|
@@ -2262,7 +1169,8 @@ var schema_v2_default = {
|
|
|
2262
1169
|
description: "Vercel project ID"
|
|
2263
1170
|
}
|
|
2264
1171
|
},
|
|
2265
|
-
required: ["projectId"]
|
|
1172
|
+
required: ["projectId"],
|
|
1173
|
+
additionalProperties: false
|
|
2266
1174
|
},
|
|
2267
1175
|
Development: {
|
|
2268
1176
|
type: "object",
|
|
@@ -2278,10 +1186,12 @@ var schema_v2_default = {
|
|
|
2278
1186
|
type: "string",
|
|
2279
1187
|
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
2280
1188
|
}
|
|
2281
|
-
}
|
|
1189
|
+
},
|
|
1190
|
+
additionalProperties: false
|
|
2282
1191
|
},
|
|
2283
1192
|
LocalHostConfig: {
|
|
2284
1193
|
type: "object",
|
|
1194
|
+
additionalProperties: false,
|
|
2285
1195
|
properties: {
|
|
2286
1196
|
host: {
|
|
2287
1197
|
type: "string",
|
|
@@ -2315,7 +1225,8 @@ var schema_v2_default = {
|
|
|
2315
1225
|
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
2316
1226
|
}
|
|
2317
1227
|
},
|
|
2318
|
-
required: ["host"]
|
|
1228
|
+
required: ["host"],
|
|
1229
|
+
additionalProperties: false
|
|
2319
1230
|
},
|
|
2320
1231
|
ChildApplication: {
|
|
2321
1232
|
type: "object",
|
|
@@ -2334,7 +1245,8 @@ var schema_v2_default = {
|
|
|
2334
1245
|
$ref: "#/definitions/HostConfig"
|
|
2335
1246
|
}
|
|
2336
1247
|
},
|
|
2337
|
-
required: ["routing"]
|
|
1248
|
+
required: ["routing"],
|
|
1249
|
+
additionalProperties: false
|
|
2338
1250
|
},
|
|
2339
1251
|
Routing: {
|
|
2340
1252
|
type: "array",
|
|
@@ -2360,7 +1272,8 @@ var schema_v2_default = {
|
|
|
2360
1272
|
}
|
|
2361
1273
|
}
|
|
2362
1274
|
},
|
|
2363
|
-
required: ["paths"]
|
|
1275
|
+
required: ["paths"],
|
|
1276
|
+
additionalProperties: false
|
|
2364
1277
|
},
|
|
2365
1278
|
ApplicationRouting: {
|
|
2366
1279
|
type: "object",
|
|
@@ -2393,19 +1306,20 @@ var schema_v2_default = {
|
|
|
2393
1306
|
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
2394
1307
|
}
|
|
2395
1308
|
},
|
|
2396
|
-
required: ["partOf", "version"]
|
|
1309
|
+
required: ["partOf", "version"],
|
|
1310
|
+
additionalProperties: false
|
|
2397
1311
|
}
|
|
2398
1312
|
}
|
|
2399
1313
|
};
|
|
2400
1314
|
|
|
2401
|
-
// src/config
|
|
2402
|
-
var
|
|
1315
|
+
// src/config/schema/utils/load.ts
|
|
1316
|
+
var SCHEMA = schema_default;
|
|
2403
1317
|
|
|
2404
|
-
// src/config
|
|
2405
|
-
function
|
|
2406
|
-
const parsedConfig = (0,
|
|
2407
|
-
const ajv = new
|
|
2408
|
-
const validate = ajv.compile(
|
|
1318
|
+
// src/config/microfrontends/server/validation.ts
|
|
1319
|
+
function validateSchema(configString) {
|
|
1320
|
+
const parsedConfig = (0, import_jsonc_parser3.parse)(configString);
|
|
1321
|
+
const ajv = new import_ajv.Ajv();
|
|
1322
|
+
const validate = ajv.compile(SCHEMA);
|
|
2409
1323
|
const isValid = validate(parsedConfig);
|
|
2410
1324
|
if (!isValid) {
|
|
2411
1325
|
throw new MicrofrontendError(
|
|
@@ -2416,7 +1330,7 @@ function validateSchema2(configString) {
|
|
|
2416
1330
|
return parsedConfig;
|
|
2417
1331
|
}
|
|
2418
1332
|
|
|
2419
|
-
// src/config
|
|
1333
|
+
// src/config/microfrontends/server/index.ts
|
|
2420
1334
|
var MicrofrontendsServer = class extends Microfrontends {
|
|
2421
1335
|
/**
|
|
2422
1336
|
* Writes the configuration to a file.
|
|
@@ -2425,8 +1339,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2425
1339
|
pretty: true
|
|
2426
1340
|
}) {
|
|
2427
1341
|
const outputPath = getOutputFilePath();
|
|
2428
|
-
|
|
2429
|
-
|
|
1342
|
+
import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
|
|
1343
|
+
import_node_fs7.default.writeFileSync(
|
|
2430
1344
|
outputPath,
|
|
2431
1345
|
JSON.stringify(
|
|
2432
1346
|
this.config.toSchemaJson(),
|
|
@@ -2459,7 +1373,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2459
1373
|
meta
|
|
2460
1374
|
});
|
|
2461
1375
|
}
|
|
2462
|
-
throw new
|
|
1376
|
+
throw new MicrofrontendError(
|
|
2463
1377
|
"Invalid config: must be a string or an object",
|
|
2464
1378
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
2465
1379
|
);
|
|
@@ -2483,7 +1397,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2483
1397
|
*/
|
|
2484
1398
|
static validate(config) {
|
|
2485
1399
|
if (typeof config === "string") {
|
|
2486
|
-
const c =
|
|
1400
|
+
const c = validateSchema(config);
|
|
2487
1401
|
return c;
|
|
2488
1402
|
}
|
|
2489
1403
|
return config;
|
|
@@ -2512,9 +1426,9 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2512
1426
|
}
|
|
2513
1427
|
try {
|
|
2514
1428
|
const packageRoot = findPackageRoot(directory);
|
|
2515
|
-
const packageJsonPath = (0,
|
|
1429
|
+
const packageJsonPath = (0, import_node_path8.join)(packageRoot, "package.json");
|
|
2516
1430
|
const packageJson = JSON.parse(
|
|
2517
|
-
|
|
1431
|
+
import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
|
|
2518
1432
|
);
|
|
2519
1433
|
if (!packageJson.name) {
|
|
2520
1434
|
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
@@ -2548,7 +1462,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2548
1462
|
}
|
|
2549
1463
|
throw new Error("Unable to infer");
|
|
2550
1464
|
} catch (e) {
|
|
2551
|
-
throw new
|
|
1465
|
+
throw new MicrofrontendError(
|
|
2552
1466
|
"Unable to infer microfrontends configuration",
|
|
2553
1467
|
{ type: "config", subtype: "inference_failed" }
|
|
2554
1468
|
);
|
|
@@ -2564,7 +1478,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2564
1478
|
options
|
|
2565
1479
|
}) {
|
|
2566
1480
|
try {
|
|
2567
|
-
const configJson =
|
|
1481
|
+
const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
2568
1482
|
const config = MicrofrontendsServer.validate(configJson);
|
|
2569
1483
|
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
2570
1484
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -2575,14 +1489,14 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2575
1489
|
name: config.partOf
|
|
2576
1490
|
});
|
|
2577
1491
|
if (!packagePath) {
|
|
2578
|
-
throw new
|
|
1492
|
+
throw new MicrofrontendError(
|
|
2579
1493
|
`Could not find default application "${config.partOf}" in the repository`,
|
|
2580
1494
|
{ type: "config", subtype: "not_found" }
|
|
2581
1495
|
);
|
|
2582
1496
|
}
|
|
2583
1497
|
const maybeConfig = findConfig({ dir: packagePath });
|
|
2584
1498
|
if (!maybeConfig) {
|
|
2585
|
-
throw new
|
|
1499
|
+
throw new MicrofrontendError(
|
|
2586
1500
|
`Could not find microfrontends configuration in ${packagePath}`,
|
|
2587
1501
|
{ type: "config", subtype: "not_found" }
|
|
2588
1502
|
);
|
|
@@ -2599,7 +1513,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2599
1513
|
meta
|
|
2600
1514
|
});
|
|
2601
1515
|
} catch (e) {
|
|
2602
|
-
throw
|
|
1516
|
+
throw MicrofrontendError.handle(e, {
|
|
2603
1517
|
fileName: filePath
|
|
2604
1518
|
});
|
|
2605
1519
|
}
|
|
@@ -2612,10 +1526,10 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2612
1526
|
overrides
|
|
2613
1527
|
}) {
|
|
2614
1528
|
try {
|
|
2615
|
-
const config =
|
|
1529
|
+
const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
2616
1530
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
2617
1531
|
if (!isMainConfig(validatedConfig)) {
|
|
2618
|
-
throw new
|
|
1532
|
+
throw new MicrofrontendError(
|
|
2619
1533
|
`${filePath} is not a main microfrontend config`,
|
|
2620
1534
|
{
|
|
2621
1535
|
type: "config",
|
|
@@ -2625,7 +1539,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2625
1539
|
}
|
|
2626
1540
|
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
2627
1541
|
if (!defaultApplication) {
|
|
2628
|
-
throw new
|
|
1542
|
+
throw new MicrofrontendError(
|
|
2629
1543
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
2630
1544
|
{ type: "config", subtype: "no_default_application" }
|
|
2631
1545
|
);
|
|
@@ -2636,7 +1550,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2636
1550
|
meta: { fromApp: defaultApplication }
|
|
2637
1551
|
});
|
|
2638
1552
|
} catch (e) {
|
|
2639
|
-
throw
|
|
1553
|
+
throw MicrofrontendError.handle(e, {
|
|
2640
1554
|
fileName: filePath
|
|
2641
1555
|
});
|
|
2642
1556
|
}
|
|
@@ -2646,9 +1560,9 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2646
1560
|
// src/utils/mfe-port.ts
|
|
2647
1561
|
function mfePort(packageDir) {
|
|
2648
1562
|
const { name: appName, version } = getPackageJson(packageDir);
|
|
2649
|
-
const result =
|
|
1563
|
+
const result = loadConfig({ packageDir, appName });
|
|
2650
1564
|
if (!result) {
|
|
2651
|
-
throw new
|
|
1565
|
+
throw new MicrofrontendError(
|
|
2652
1566
|
`Unable to determine configured port for ${appName}`,
|
|
2653
1567
|
{ type: "config", subtype: "not_found" }
|
|
2654
1568
|
);
|
|
@@ -2661,10 +1575,10 @@ function mfePort(packageDir) {
|
|
|
2661
1575
|
};
|
|
2662
1576
|
}
|
|
2663
1577
|
function getPackageJson(packageDir) {
|
|
2664
|
-
const filePath =
|
|
2665
|
-
return JSON.parse(
|
|
1578
|
+
const filePath = import_node_path9.default.join(packageDir, "package.json");
|
|
1579
|
+
return JSON.parse(import_node_fs8.default.readFileSync(filePath, "utf-8"));
|
|
2666
1580
|
}
|
|
2667
|
-
function
|
|
1581
|
+
function loadConfig({
|
|
2668
1582
|
packageDir,
|
|
2669
1583
|
appName
|
|
2670
1584
|
}) {
|
|
@@ -2682,21 +1596,6 @@ function loadV2({
|
|
|
2682
1596
|
const port = app.development.local.port;
|
|
2683
1597
|
return { port };
|
|
2684
1598
|
}
|
|
2685
|
-
function loadV1({
|
|
2686
|
-
packageDir,
|
|
2687
|
-
appName
|
|
2688
|
-
}) {
|
|
2689
|
-
const filePath = import_node_path11.default.join(packageDir, "micro-frontends.jsonc");
|
|
2690
|
-
let config;
|
|
2691
|
-
try {
|
|
2692
|
-
config = MicrofrontendConfig.fromFile({ filePath });
|
|
2693
|
-
} catch (e) {
|
|
2694
|
-
return void 0;
|
|
2695
|
-
}
|
|
2696
|
-
const zone = config.getZone(appName);
|
|
2697
|
-
const port = zone.development.local.port;
|
|
2698
|
-
return { port };
|
|
2699
|
-
}
|
|
2700
1599
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2701
1600
|
0 && (module.exports = {
|
|
2702
1601
|
mfePort
|