@vercel/microfrontends 1.0.0 → 1.0.1-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.cjs +183 -27
- package/dist/config.cjs +46 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +46 -1
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +1735 -0
- package/dist/experimental/sveltekit.cjs.map +1 -0
- package/dist/experimental/sveltekit.d.ts +12 -0
- package/dist/experimental/sveltekit.js +1698 -0
- package/dist/experimental/sveltekit.js.map +1 -0
- package/dist/experimental/vite.cjs +1745 -0
- package/dist/experimental/vite.cjs.map +1 -0
- package/dist/experimental/vite.d.ts +29 -0
- package/dist/experimental/vite.js +1710 -0
- package/dist/experimental/vite.js.map +1 -0
- package/dist/{index-09b1ddf9.d.ts → index-d5994ac5.d.ts} +1 -1
- package/dist/microfrontends/server.cjs +73 -10
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +1 -1
- package/dist/microfrontends/server.js +73 -10
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends.cjs +47 -2
- package/dist/microfrontends.cjs.map +1 -1
- package/dist/microfrontends.d.ts +1 -1
- package/dist/microfrontends.js +47 -2
- package/dist/microfrontends.js.map +1 -1
- package/dist/next/config.cjs +123 -51
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +122 -52
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +77 -7
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +77 -7
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +46 -5
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +1 -1
- package/dist/next/testing.js +46 -5
- package/dist/next/testing.js.map +1 -1
- package/dist/utils/mfe-port.cjs +73 -10
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +73 -10
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +26 -8
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.js +26 -8
- package/dist/validation.js.map +1 -1
- package/package.json +26 -2
|
@@ -0,0 +1,1735 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/sveltekit/index.ts
|
|
31
|
+
var sveltekit_exports = {};
|
|
32
|
+
__export(sveltekit_exports, {
|
|
33
|
+
withMicrofrontends: () => withMicrofrontends
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(sveltekit_exports);
|
|
36
|
+
|
|
37
|
+
// src/bin/check-proxy.ts
|
|
38
|
+
function displayLocalProxyInfo(port) {
|
|
39
|
+
const { MFE_PROXY_MESSAGE_PRINTED, TURBO_TASK_HAS_MFE_PROXY } = process.env;
|
|
40
|
+
if (TURBO_TASK_HAS_MFE_PROXY === "true" && MFE_PROXY_MESSAGE_PRINTED !== "true") {
|
|
41
|
+
process.env.MFE_PROXY_MESSAGE_PRINTED = "true";
|
|
42
|
+
console.log(`Microfrontends Proxy running on http://localhost:${port}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/config/microfrontends/server/index.ts
|
|
47
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
48
|
+
var import_node_path8 = require("path");
|
|
49
|
+
|
|
50
|
+
// src/config/overrides/constants.ts
|
|
51
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
52
|
+
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
53
|
+
|
|
54
|
+
// src/config/overrides/is-override-cookie.ts
|
|
55
|
+
function isOverrideCookie(cookie) {
|
|
56
|
+
return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/config/overrides/get-override-from-cookie.ts
|
|
60
|
+
function getOverrideFromCookie(cookie) {
|
|
61
|
+
if (!isOverrideCookie(cookie) || !cookie.value)
|
|
62
|
+
return;
|
|
63
|
+
return {
|
|
64
|
+
application: cookie.name.replace(OVERRIDES_ENV_COOKIE_PREFIX, ""),
|
|
65
|
+
host: cookie.value
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/config/overrides/parse-overrides.ts
|
|
70
|
+
function parseOverrides(cookies) {
|
|
71
|
+
const overridesConfig = { applications: {} };
|
|
72
|
+
cookies.forEach((cookie) => {
|
|
73
|
+
const override = getOverrideFromCookie(cookie);
|
|
74
|
+
if (!override)
|
|
75
|
+
return;
|
|
76
|
+
overridesConfig.applications[override.application] = {
|
|
77
|
+
environment: { host: override.host }
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
return overridesConfig;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/config/errors.ts
|
|
84
|
+
var MicrofrontendError = class extends Error {
|
|
85
|
+
constructor(message, opts) {
|
|
86
|
+
super(message, { cause: opts?.cause });
|
|
87
|
+
this.name = "MicrofrontendsError";
|
|
88
|
+
this.source = opts?.source ?? "@vercel/microfrontends";
|
|
89
|
+
this.type = opts?.type ?? "unknown";
|
|
90
|
+
this.subtype = opts?.subtype;
|
|
91
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
92
|
+
}
|
|
93
|
+
isKnown() {
|
|
94
|
+
return this.type !== "unknown";
|
|
95
|
+
}
|
|
96
|
+
isUnknown() {
|
|
97
|
+
return !this.isKnown();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Converts an error to a MicrofrontendsError.
|
|
101
|
+
* @param original - The original error to convert.
|
|
102
|
+
* @returns The converted MicrofrontendsError.
|
|
103
|
+
*/
|
|
104
|
+
static convert(original, opts) {
|
|
105
|
+
if (opts?.fileName) {
|
|
106
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
107
|
+
if (err) {
|
|
108
|
+
return err;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (original.message.includes(
|
|
112
|
+
"Code generation from strings disallowed for this context"
|
|
113
|
+
)) {
|
|
114
|
+
return new MicrofrontendError(original.message, {
|
|
115
|
+
type: "config",
|
|
116
|
+
subtype: "unsupported_validation_env",
|
|
117
|
+
source: "ajv"
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return new MicrofrontendError(original.message);
|
|
121
|
+
}
|
|
122
|
+
static convertFSError(original, fileName) {
|
|
123
|
+
if (original instanceof Error && "code" in original) {
|
|
124
|
+
if (original.code === "ENOENT") {
|
|
125
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
126
|
+
type: "config",
|
|
127
|
+
subtype: "unable_to_read_file",
|
|
128
|
+
source: "fs"
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (original.code === "EACCES") {
|
|
132
|
+
return new MicrofrontendError(
|
|
133
|
+
`Permission denied while accessing "${fileName}"`,
|
|
134
|
+
{
|
|
135
|
+
type: "config",
|
|
136
|
+
subtype: "invalid_permissions",
|
|
137
|
+
source: "fs"
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (original instanceof SyntaxError) {
|
|
143
|
+
return new MicrofrontendError(
|
|
144
|
+
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
145
|
+
{
|
|
146
|
+
type: "config",
|
|
147
|
+
subtype: "invalid_syntax",
|
|
148
|
+
source: "fs"
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
156
|
+
* @param err - The error to handle.
|
|
157
|
+
* @returns A MicrofrontendsError instance.
|
|
158
|
+
*/
|
|
159
|
+
static handle(err, opts) {
|
|
160
|
+
if (err instanceof MicrofrontendError) {
|
|
161
|
+
return err;
|
|
162
|
+
}
|
|
163
|
+
if (err instanceof Error) {
|
|
164
|
+
return MicrofrontendError.convert(err, opts);
|
|
165
|
+
}
|
|
166
|
+
if (typeof err === "object" && err !== null) {
|
|
167
|
+
if ("message" in err && typeof err.message === "string") {
|
|
168
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// src/config/microfrontends-config/utils/get-config-from-env.ts
|
|
176
|
+
function getConfigStringFromEnv() {
|
|
177
|
+
const config = process.env.MFE_CONFIG;
|
|
178
|
+
if (!config) {
|
|
179
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
180
|
+
type: "config",
|
|
181
|
+
subtype: "not_found_in_env"
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return config;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
188
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
189
|
+
|
|
190
|
+
// src/config/schema/utils/is-main-config.ts
|
|
191
|
+
function isMainConfig(c) {
|
|
192
|
+
return !("partOf" in c);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/config/schema/utils/is-default-app.ts
|
|
196
|
+
function isDefaultApp(a) {
|
|
197
|
+
return !("routing" in a);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/config/microfrontends-config/client/index.ts
|
|
201
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
202
|
+
var MicrofrontendConfigClient = class {
|
|
203
|
+
constructor(config, opts) {
|
|
204
|
+
this.pathCache = {};
|
|
205
|
+
this.serialized = config;
|
|
206
|
+
if (opts?.removeFlaggedPaths) {
|
|
207
|
+
for (const app of Object.values(config.applications)) {
|
|
208
|
+
if (app.routing) {
|
|
209
|
+
app.routing = app.routing.filter((match) => !match.flag);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
this.applications = config.applications;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Create a new `MicrofrontendConfigClient` from a JSON string.
|
|
217
|
+
* Config must be passed in to remain framework agnostic
|
|
218
|
+
*/
|
|
219
|
+
static fromEnv(config, opts) {
|
|
220
|
+
if (!config) {
|
|
221
|
+
throw new Error("No microfrontends configuration found");
|
|
222
|
+
}
|
|
223
|
+
return new MicrofrontendConfigClient(
|
|
224
|
+
JSON.parse(config),
|
|
225
|
+
opts
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
isEqual(other) {
|
|
229
|
+
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
230
|
+
}
|
|
231
|
+
getApplicationNameForPath(path5) {
|
|
232
|
+
if (!path5.startsWith("/")) {
|
|
233
|
+
throw new Error(`Path must start with a /`);
|
|
234
|
+
}
|
|
235
|
+
if (this.pathCache[path5]) {
|
|
236
|
+
return this.pathCache[path5];
|
|
237
|
+
}
|
|
238
|
+
const pathname = new URL(path5, "https://example.com").pathname;
|
|
239
|
+
for (const [name, application] of Object.entries(this.applications)) {
|
|
240
|
+
if (application.routing) {
|
|
241
|
+
for (const group of application.routing) {
|
|
242
|
+
for (const childPath of group.paths) {
|
|
243
|
+
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
244
|
+
if (regexp.test(pathname)) {
|
|
245
|
+
this.pathCache[path5] = name;
|
|
246
|
+
return name;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const defaultApplication = Object.entries(this.applications).find(
|
|
253
|
+
([, application]) => application.default
|
|
254
|
+
);
|
|
255
|
+
if (!defaultApplication) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
this.pathCache[path5] = defaultApplication[0];
|
|
259
|
+
return defaultApplication[0];
|
|
260
|
+
}
|
|
261
|
+
serialize() {
|
|
262
|
+
return this.serialized;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
267
|
+
var import_path_to_regexp2 = require("path-to-regexp");
|
|
268
|
+
var validateConfigPaths = (applicationConfigsById) => {
|
|
269
|
+
if (!applicationConfigsById) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
273
|
+
const errors = [];
|
|
274
|
+
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
275
|
+
if (isDefaultApp(app)) {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const childApp = app;
|
|
279
|
+
for (const pathMatch of childApp.routing) {
|
|
280
|
+
for (const path5 of pathMatch.paths) {
|
|
281
|
+
const maybeError = validatePathExpression(path5);
|
|
282
|
+
if (maybeError) {
|
|
283
|
+
errors.push(maybeError);
|
|
284
|
+
}
|
|
285
|
+
const existing = pathsByApplicationId.get(path5);
|
|
286
|
+
if (existing) {
|
|
287
|
+
existing.applications.push(id);
|
|
288
|
+
} else {
|
|
289
|
+
pathsByApplicationId.set(path5, {
|
|
290
|
+
applications: [id],
|
|
291
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path5),
|
|
292
|
+
applicationId: id
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const entries = Array.from(pathsByApplicationId.entries());
|
|
299
|
+
for (const [path5, { applications: ids, matcher, applicationId }] of entries) {
|
|
300
|
+
if (ids.length > 1) {
|
|
301
|
+
errors.push(
|
|
302
|
+
`Duplicate path "${path5}" for applications "${ids.join(", ")}"`
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
for (const [
|
|
306
|
+
matchPath,
|
|
307
|
+
{ applications: matchIds, applicationId: matchApplicationId }
|
|
308
|
+
] of entries) {
|
|
309
|
+
if (path5 === matchPath) {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (applicationId === matchApplicationId) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (matcher.test(matchPath)) {
|
|
316
|
+
const source = `"${path5}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
317
|
+
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
318
|
+
errors.push(
|
|
319
|
+
`Overlapping path detected between ${source} and ${destination}`
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (errors.length) {
|
|
325
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
326
|
+
type: "config",
|
|
327
|
+
subtype: "conflicting_paths"
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
332
|
+
function validatePathExpression(path5) {
|
|
333
|
+
const tokens = (0, import_path_to_regexp2.parse)(path5);
|
|
334
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
335
|
+
const token = tokens[i];
|
|
336
|
+
if (token === void 0) {
|
|
337
|
+
return `token ${i} in ${path5} is undefined, this shouldn't happen`;
|
|
338
|
+
}
|
|
339
|
+
if (typeof token !== "string") {
|
|
340
|
+
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
341
|
+
return `Path ${path5} cannot use a regular expression wildcard`;
|
|
342
|
+
}
|
|
343
|
+
if (token.prefix !== "/") {
|
|
344
|
+
return `Wildcard :${token.name} must be immediately after a / in ${path5}`;
|
|
345
|
+
}
|
|
346
|
+
if (token.suffix) {
|
|
347
|
+
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
348
|
+
}
|
|
349
|
+
if (token.modifier && i !== tokens.length - 1) {
|
|
350
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path5}. Modifiers are only allowed in the last path component`;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return void 0;
|
|
355
|
+
}
|
|
356
|
+
var validateAppPaths = (name, app) => {
|
|
357
|
+
for (const group of app.routing) {
|
|
358
|
+
for (const p of group.paths) {
|
|
359
|
+
if (p === "/") {
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (p.endsWith("/")) {
|
|
363
|
+
throw new MicrofrontendError(
|
|
364
|
+
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
365
|
+
{ type: "application", subtype: "invalid_path" }
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
if (!p.startsWith("/")) {
|
|
369
|
+
throw new MicrofrontendError(
|
|
370
|
+
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
371
|
+
{ type: "application", subtype: "invalid_path" }
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
378
|
+
if (!applicationConfigsById) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
|
|
382
|
+
([, app]) => !isDefaultApp(app)
|
|
383
|
+
);
|
|
384
|
+
const applicationsWithRoutingNames = applicationsWithRouting.map(
|
|
385
|
+
([key]) => key
|
|
386
|
+
);
|
|
387
|
+
const numApplications = Object.keys(applicationConfigsById).length;
|
|
388
|
+
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
389
|
+
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
390
|
+
if (numApplicationsWithoutRouting === 0) {
|
|
391
|
+
throw new MicrofrontendError(
|
|
392
|
+
"No default application found. At least one application needs to be the default by omitting routing.",
|
|
393
|
+
{ type: "config", subtype: "no_default_application" }
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
if (numApplicationsWithoutRouting > 1) {
|
|
397
|
+
throw new MicrofrontendError(
|
|
398
|
+
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
399
|
+
{ type: "config", subtype: "multiple_default_applications" }
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
var validateDeprecatedFields = (config) => {
|
|
404
|
+
const errors = [];
|
|
405
|
+
if (config.options?.vercel) {
|
|
406
|
+
errors.push(
|
|
407
|
+
`Configuration cannot contain deprecated field 'options.vercel'. Use 'options.disableOverrides' instead.`
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
if (config.options?.localProxy) {
|
|
411
|
+
errors.push(
|
|
412
|
+
`Configuration cannot contain deprecated field 'options.localProxy'. Use 'options.localProxyPort' instead.`
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
for (const [applicationId, application] of Object.entries(
|
|
416
|
+
config.applications
|
|
417
|
+
)) {
|
|
418
|
+
if (application.vercel) {
|
|
419
|
+
errors.push(
|
|
420
|
+
`Application '${applicationId}' cannot contain deprecated field 'vercel'. Use 'projectId' instead.`
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
if (application.production) {
|
|
424
|
+
errors.push(
|
|
425
|
+
`Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
if (application.development?.local) {
|
|
429
|
+
errors.push(
|
|
430
|
+
`Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (errors.length) {
|
|
435
|
+
throw new MicrofrontendError(
|
|
436
|
+
`Microfrontends configuration file errors:
|
|
437
|
+
- ${errors.join("\n- ")}`,
|
|
438
|
+
{
|
|
439
|
+
type: "config",
|
|
440
|
+
subtype: "depcrecated_field"
|
|
441
|
+
}
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
447
|
+
var PREFIX = "vc-ap";
|
|
448
|
+
function generateAssetPrefixFromName({
|
|
449
|
+
name
|
|
450
|
+
}) {
|
|
451
|
+
if (!name) {
|
|
452
|
+
throw new Error("Name is required to generate an asset prefix");
|
|
453
|
+
}
|
|
454
|
+
return `${PREFIX}-${name}`;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-port.ts
|
|
458
|
+
function generatePortFromName({
|
|
459
|
+
name,
|
|
460
|
+
minPort = 3e3,
|
|
461
|
+
maxPort = 8e3
|
|
462
|
+
}) {
|
|
463
|
+
if (!name) {
|
|
464
|
+
throw new Error("Name is required to generate a port");
|
|
465
|
+
}
|
|
466
|
+
let hash = 0;
|
|
467
|
+
for (let i = 0; i < name.length; i++) {
|
|
468
|
+
hash = (hash << 5) - hash + name.charCodeAt(i);
|
|
469
|
+
hash |= 0;
|
|
470
|
+
}
|
|
471
|
+
hash = Math.abs(hash);
|
|
472
|
+
const range = maxPort - minPort;
|
|
473
|
+
const port = minPort + hash % range;
|
|
474
|
+
return port;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// src/config/microfrontends-config/isomorphic/host.ts
|
|
478
|
+
var Host = class {
|
|
479
|
+
constructor(hostConfig, options) {
|
|
480
|
+
if (typeof hostConfig === "string") {
|
|
481
|
+
({
|
|
482
|
+
protocol: this.protocol,
|
|
483
|
+
host: this.host,
|
|
484
|
+
port: this.port
|
|
485
|
+
} = Host.parseUrl(hostConfig));
|
|
486
|
+
} else {
|
|
487
|
+
const { protocol = "https", host, port } = hostConfig;
|
|
488
|
+
this.protocol = protocol;
|
|
489
|
+
this.host = host;
|
|
490
|
+
this.port = port;
|
|
491
|
+
}
|
|
492
|
+
this.local = options?.isLocal;
|
|
493
|
+
}
|
|
494
|
+
static parseUrl(url) {
|
|
495
|
+
let hostToParse = url;
|
|
496
|
+
if (!/^https?:\/\//.exec(hostToParse)) {
|
|
497
|
+
hostToParse = `https://${hostToParse}`;
|
|
498
|
+
}
|
|
499
|
+
const parsed = new URL(hostToParse);
|
|
500
|
+
if (!parsed.hostname) {
|
|
501
|
+
throw new Error(Host.getMicrofrontendsError(url, "requires a host"));
|
|
502
|
+
}
|
|
503
|
+
if (parsed.hash) {
|
|
504
|
+
throw new Error(
|
|
505
|
+
Host.getMicrofrontendsError(url, "cannot have a fragment")
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
if (parsed.username || parsed.password) {
|
|
509
|
+
throw new Error(
|
|
510
|
+
Host.getMicrofrontendsError(
|
|
511
|
+
url,
|
|
512
|
+
"cannot have authentication credentials (username and/or password)"
|
|
513
|
+
)
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
if (parsed.pathname !== "/") {
|
|
517
|
+
throw new Error(Host.getMicrofrontendsError(url, "cannot have a path"));
|
|
518
|
+
}
|
|
519
|
+
if (parsed.search) {
|
|
520
|
+
throw new Error(
|
|
521
|
+
Host.getMicrofrontendsError(url, "cannot have query parameters")
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
const protocol = parsed.protocol.slice(0, -1);
|
|
525
|
+
return {
|
|
526
|
+
protocol,
|
|
527
|
+
host: parsed.hostname,
|
|
528
|
+
port: parsed.port ? Number.parseInt(parsed.port) : void 0
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
static getMicrofrontendsError(url, message) {
|
|
532
|
+
return `Microfrontends configuration error: the URL ${url} in your microfrontends.json ${message}.`;
|
|
533
|
+
}
|
|
534
|
+
isLocal() {
|
|
535
|
+
return this.local || this.host === "localhost" || this.host === "127.0.0.1";
|
|
536
|
+
}
|
|
537
|
+
toString() {
|
|
538
|
+
const url = this.toUrl();
|
|
539
|
+
return url.toString().replace(/\/$/, "");
|
|
540
|
+
}
|
|
541
|
+
toUrl() {
|
|
542
|
+
const url = `${this.protocol}://${this.host}${this.port ? `:${this.port}` : ""}`;
|
|
543
|
+
return new URL(url);
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
var LocalHost = class extends Host {
|
|
547
|
+
constructor({
|
|
548
|
+
appName,
|
|
549
|
+
localPort,
|
|
550
|
+
...hostConfig
|
|
551
|
+
}) {
|
|
552
|
+
const host = hostConfig.host ?? "localhost";
|
|
553
|
+
const port = localPort ?? hostConfig.port ?? generatePortFromName({ name: appName });
|
|
554
|
+
const protocol = hostConfig.protocol ?? "http";
|
|
555
|
+
super({ protocol, host, port });
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// src/config/microfrontends-config/isomorphic/application.ts
|
|
560
|
+
var Application = class {
|
|
561
|
+
constructor(name, {
|
|
562
|
+
app,
|
|
563
|
+
overrides,
|
|
564
|
+
isDefault
|
|
565
|
+
}) {
|
|
566
|
+
this.name = name;
|
|
567
|
+
this.development = {
|
|
568
|
+
local: new LocalHost({
|
|
569
|
+
appName: name,
|
|
570
|
+
localPort: app.development?.localPort,
|
|
571
|
+
...app.development?.local
|
|
572
|
+
}),
|
|
573
|
+
fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
|
|
574
|
+
};
|
|
575
|
+
if (app.development?.fallback) {
|
|
576
|
+
this.fallback = new Host(app.development.fallback);
|
|
577
|
+
} else if (app.production) {
|
|
578
|
+
this.fallback = new Host(app.production);
|
|
579
|
+
}
|
|
580
|
+
this.projectId = app.projectId ?? app.vercel?.projectId;
|
|
581
|
+
this.overrides = overrides?.environment ? {
|
|
582
|
+
environment: new Host(overrides.environment)
|
|
583
|
+
} : void 0;
|
|
584
|
+
this.default = isDefault ?? false;
|
|
585
|
+
this.serialized = app;
|
|
586
|
+
}
|
|
587
|
+
isDefault() {
|
|
588
|
+
return this.default;
|
|
589
|
+
}
|
|
590
|
+
getAssetPrefix() {
|
|
591
|
+
return generateAssetPrefixFromName({ name: this.name });
|
|
592
|
+
}
|
|
593
|
+
serialize() {
|
|
594
|
+
return this.serialized;
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
var DefaultApplication = class extends Application {
|
|
598
|
+
constructor(name, {
|
|
599
|
+
app,
|
|
600
|
+
overrides
|
|
601
|
+
}) {
|
|
602
|
+
super(name, {
|
|
603
|
+
app,
|
|
604
|
+
overrides,
|
|
605
|
+
isDefault: true
|
|
606
|
+
});
|
|
607
|
+
this.default = true;
|
|
608
|
+
const fallbackHost = app.development?.fallback ?? app.production;
|
|
609
|
+
if (fallbackHost === void 0) {
|
|
610
|
+
throw new Error(
|
|
611
|
+
"`app.production` or `app.development.fallback` must be set in the default application in microfrontends.json."
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
this.fallback = new Host(fallbackHost);
|
|
615
|
+
if (app.production) {
|
|
616
|
+
this.production = new Host(app.production);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
getAssetPrefix() {
|
|
620
|
+
return "";
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
var ChildApplication = class extends Application {
|
|
624
|
+
constructor(name, {
|
|
625
|
+
app,
|
|
626
|
+
overrides
|
|
627
|
+
}) {
|
|
628
|
+
ChildApplication.validate(name, app);
|
|
629
|
+
super(name, {
|
|
630
|
+
app,
|
|
631
|
+
overrides,
|
|
632
|
+
isDefault: false
|
|
633
|
+
});
|
|
634
|
+
this.default = false;
|
|
635
|
+
this.routing = app.routing;
|
|
636
|
+
}
|
|
637
|
+
static validate(name, app) {
|
|
638
|
+
validateAppPaths(name, app);
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
643
|
+
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
644
|
+
|
|
645
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
646
|
+
var MicrofrontendConfigIsomorphic = class {
|
|
647
|
+
constructor({
|
|
648
|
+
config,
|
|
649
|
+
overrides,
|
|
650
|
+
meta,
|
|
651
|
+
opts
|
|
652
|
+
}) {
|
|
653
|
+
this.childApplications = {};
|
|
654
|
+
MicrofrontendConfigIsomorphic.validate(config, opts);
|
|
655
|
+
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
656
|
+
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
657
|
+
this.isMainConfig = isMainConfig(config);
|
|
658
|
+
if (isMainConfig(config)) {
|
|
659
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
660
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
661
|
+
if (isDefaultApp(appConfig)) {
|
|
662
|
+
this.defaultApplication = new DefaultApplication(appId, {
|
|
663
|
+
app: appConfig,
|
|
664
|
+
overrides: appOverrides
|
|
665
|
+
});
|
|
666
|
+
} else {
|
|
667
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
668
|
+
app: appConfig,
|
|
669
|
+
overrides: appOverrides
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
} else {
|
|
674
|
+
this.partOf = config.partOf;
|
|
675
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
|
|
676
|
+
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
677
|
+
meta.fromApp,
|
|
678
|
+
{
|
|
679
|
+
// we don't know routing because we're not in the main config
|
|
680
|
+
app: { routing: [] },
|
|
681
|
+
overrides: appOverrides
|
|
682
|
+
}
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
if (isMainConfig(config) && !this.defaultApplication) {
|
|
686
|
+
throw new MicrofrontendError(
|
|
687
|
+
"Could not find default application in microfrontends configuration",
|
|
688
|
+
{
|
|
689
|
+
type: "application",
|
|
690
|
+
subtype: "not_found"
|
|
691
|
+
}
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
this.config = config;
|
|
695
|
+
this.options = config.options;
|
|
696
|
+
this.serialized = {
|
|
697
|
+
config,
|
|
698
|
+
overrides,
|
|
699
|
+
meta
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
static validate(config, opts) {
|
|
703
|
+
const skipValidation = opts?.skipValidation ?? [];
|
|
704
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
705
|
+
if (isMainConfig(c)) {
|
|
706
|
+
if (!skipValidation.includes("paths")) {
|
|
707
|
+
validateConfigPaths(c.applications);
|
|
708
|
+
}
|
|
709
|
+
if (!skipValidation.includes("defaultApplication")) {
|
|
710
|
+
validateConfigDefaultApplication(c.applications);
|
|
711
|
+
}
|
|
712
|
+
if (!skipValidation.includes("deprecatedFields")) {
|
|
713
|
+
validateDeprecatedFields(c);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return c;
|
|
717
|
+
}
|
|
718
|
+
static fromEnv({
|
|
719
|
+
meta,
|
|
720
|
+
cookies
|
|
721
|
+
}) {
|
|
722
|
+
return new MicrofrontendConfigIsomorphic({
|
|
723
|
+
config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
|
|
724
|
+
overrides: parseOverrides(cookies ?? []),
|
|
725
|
+
meta
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
isOverridesDisabled() {
|
|
729
|
+
return this.options?.vercel?.disableOverrides ?? false;
|
|
730
|
+
}
|
|
731
|
+
getConfig() {
|
|
732
|
+
return this.config;
|
|
733
|
+
}
|
|
734
|
+
getApplicationsByType() {
|
|
735
|
+
return {
|
|
736
|
+
defaultApplication: this.defaultApplication,
|
|
737
|
+
applications: Object.values(this.childApplications)
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
getChildApplications() {
|
|
741
|
+
return Object.values(this.childApplications);
|
|
742
|
+
}
|
|
743
|
+
getAllApplications() {
|
|
744
|
+
return [
|
|
745
|
+
this.defaultApplication,
|
|
746
|
+
...Object.values(this.childApplications)
|
|
747
|
+
].filter(Boolean);
|
|
748
|
+
}
|
|
749
|
+
getApplication(name) {
|
|
750
|
+
if (this.defaultApplication?.name === name) {
|
|
751
|
+
return this.defaultApplication;
|
|
752
|
+
}
|
|
753
|
+
const app = this.childApplications[name];
|
|
754
|
+
if (!app) {
|
|
755
|
+
throw new MicrofrontendError(
|
|
756
|
+
`Could not find microfrontends configuration for application "${name}"`,
|
|
757
|
+
{
|
|
758
|
+
type: "application",
|
|
759
|
+
subtype: "not_found"
|
|
760
|
+
}
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
return app;
|
|
764
|
+
}
|
|
765
|
+
getApplicationByProjectId(projectId) {
|
|
766
|
+
if (this.defaultApplication?.projectId === projectId) {
|
|
767
|
+
return this.defaultApplication;
|
|
768
|
+
}
|
|
769
|
+
return Object.values(this.childApplications).find(
|
|
770
|
+
(app) => app.projectId === projectId
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Returns the default application. This can throw if the default application
|
|
775
|
+
* is undefined ( )
|
|
776
|
+
*/
|
|
777
|
+
getDefaultApplication() {
|
|
778
|
+
if (!this.defaultApplication) {
|
|
779
|
+
throw new MicrofrontendError(
|
|
780
|
+
"Could not find default application in microfrontends configuration",
|
|
781
|
+
{
|
|
782
|
+
type: "application",
|
|
783
|
+
subtype: "not_found"
|
|
784
|
+
}
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
return this.defaultApplication;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Returns the configured port for the local proxy
|
|
791
|
+
*/
|
|
792
|
+
getLocalProxyPort() {
|
|
793
|
+
return this.config.options?.localProxyPort ?? this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Serializes the class back to the Schema type.
|
|
797
|
+
*
|
|
798
|
+
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
799
|
+
*/
|
|
800
|
+
toSchemaJson() {
|
|
801
|
+
return this.serialized.config;
|
|
802
|
+
}
|
|
803
|
+
toClientConfig() {
|
|
804
|
+
const applications = Object.fromEntries(
|
|
805
|
+
Object.entries(this.childApplications).map(([name, application]) => [
|
|
806
|
+
name,
|
|
807
|
+
{
|
|
808
|
+
default: false,
|
|
809
|
+
routing: application.routing
|
|
810
|
+
}
|
|
811
|
+
])
|
|
812
|
+
);
|
|
813
|
+
if (this.defaultApplication) {
|
|
814
|
+
applications[this.defaultApplication.name] = {
|
|
815
|
+
default: true
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
return new MicrofrontendConfigClient({
|
|
819
|
+
applications
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
serialize() {
|
|
823
|
+
return this.serialized;
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
// src/config/microfrontends-config/isomorphic/child.ts
|
|
828
|
+
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
829
|
+
constructor({
|
|
830
|
+
config,
|
|
831
|
+
overrides,
|
|
832
|
+
meta
|
|
833
|
+
}) {
|
|
834
|
+
super({ config, overrides, meta });
|
|
835
|
+
this.isMainConfig = false;
|
|
836
|
+
this.partOf = config.partOf;
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
// src/config/microfrontends-config/isomorphic/main.ts
|
|
841
|
+
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
842
|
+
constructor({
|
|
843
|
+
config,
|
|
844
|
+
overrides,
|
|
845
|
+
meta
|
|
846
|
+
}) {
|
|
847
|
+
super({ config, overrides, meta });
|
|
848
|
+
this.isMainConfig = true;
|
|
849
|
+
const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
|
|
850
|
+
let defaultApplication;
|
|
851
|
+
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
852
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
853
|
+
if (isDefaultApp(appConfig)) {
|
|
854
|
+
defaultApplication = new DefaultApplication(appId, {
|
|
855
|
+
app: appConfig,
|
|
856
|
+
overrides: appOverrides
|
|
857
|
+
});
|
|
858
|
+
} else {
|
|
859
|
+
this.childApplications[appId] = new ChildApplication(appId, {
|
|
860
|
+
app: appConfig,
|
|
861
|
+
overrides: appOverrides
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
if (!defaultApplication) {
|
|
866
|
+
throw new MicrofrontendError(
|
|
867
|
+
"Could not find default application in microfrontends configuration",
|
|
868
|
+
{
|
|
869
|
+
type: "application",
|
|
870
|
+
subtype: "not_found"
|
|
871
|
+
}
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
this.defaultApplication = defaultApplication;
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
// src/config/microfrontends/isomorphic/index.ts
|
|
879
|
+
var Microfrontends = class {
|
|
880
|
+
constructor({
|
|
881
|
+
config,
|
|
882
|
+
overrides,
|
|
883
|
+
meta
|
|
884
|
+
}) {
|
|
885
|
+
if (isMainConfig(config)) {
|
|
886
|
+
this.config = new MicrofrontendMainConfig({ config, overrides, meta });
|
|
887
|
+
} else {
|
|
888
|
+
this.config = new MicrofrontendChildConfig({ config, overrides, meta });
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
isChildConfig() {
|
|
892
|
+
return this.config instanceof MicrofrontendChildConfig;
|
|
893
|
+
}
|
|
894
|
+
static fromEnv({
|
|
895
|
+
cookies,
|
|
896
|
+
meta
|
|
897
|
+
}) {
|
|
898
|
+
const config = MicrofrontendConfigIsomorphic.fromEnv({
|
|
899
|
+
cookies,
|
|
900
|
+
meta
|
|
901
|
+
});
|
|
902
|
+
return new Microfrontends(config.serialize());
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
// src/config/microfrontends/utils/find-repository-root.ts
|
|
907
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
908
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
909
|
+
var GIT_DIRECTORY = ".git";
|
|
910
|
+
function findRepositoryRoot(startDir) {
|
|
911
|
+
let currentDir = startDir || process.cwd();
|
|
912
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
913
|
+
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
914
|
+
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
915
|
+
return currentDir;
|
|
916
|
+
}
|
|
917
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
918
|
+
}
|
|
919
|
+
throw new Error(
|
|
920
|
+
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// src/config/microfrontends/utils/find-package-path.ts
|
|
925
|
+
var import_node_path2 = require("path");
|
|
926
|
+
var import_node_fs2 = require("fs");
|
|
927
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
928
|
+
var configCache = {};
|
|
929
|
+
function findPackagePathWithGlob({
|
|
930
|
+
repositoryRoot,
|
|
931
|
+
name
|
|
932
|
+
}) {
|
|
933
|
+
try {
|
|
934
|
+
const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
|
|
935
|
+
cwd: repositoryRoot,
|
|
936
|
+
absolute: true,
|
|
937
|
+
onlyFiles: true,
|
|
938
|
+
followSymbolicLinks: false,
|
|
939
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
940
|
+
});
|
|
941
|
+
const matchingPaths = [];
|
|
942
|
+
for (const packageJsonPath2 of packageJsonPaths) {
|
|
943
|
+
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
944
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
945
|
+
if (packageJson.name === name) {
|
|
946
|
+
matchingPaths.push(packageJsonPath2);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
if (matchingPaths.length > 1) {
|
|
950
|
+
throw new Error(
|
|
951
|
+
`Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
if (matchingPaths.length === 0) {
|
|
955
|
+
throw new Error(
|
|
956
|
+
`Could not find package with the name "${name}" in the repository`
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
const [packageJsonPath] = matchingPaths;
|
|
960
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
961
|
+
} catch (error) {
|
|
962
|
+
return null;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
function findPackagePath(opts) {
|
|
966
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
|
|
967
|
+
if (configCache[cacheKey]) {
|
|
968
|
+
return configCache[cacheKey];
|
|
969
|
+
}
|
|
970
|
+
const result = findPackagePathWithGlob(opts);
|
|
971
|
+
if (!result) {
|
|
972
|
+
throw new Error(
|
|
973
|
+
`Could not find package with the name "${opts.name}" in the repository`
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
configCache[cacheKey] = result;
|
|
977
|
+
return result;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
981
|
+
var import_node_path3 = require("path");
|
|
982
|
+
var import_node_fs3 = require("fs");
|
|
983
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
984
|
+
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
985
|
+
|
|
986
|
+
// src/config/constants.ts
|
|
987
|
+
var CONFIGURATION_FILENAMES = [
|
|
988
|
+
"microfrontends.jsonc",
|
|
989
|
+
"microfrontends.json"
|
|
990
|
+
];
|
|
991
|
+
|
|
992
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
993
|
+
var configCache2 = {};
|
|
994
|
+
function findDefaultMicrofrontendsPackages({
|
|
995
|
+
repositoryRoot,
|
|
996
|
+
applicationName
|
|
997
|
+
}) {
|
|
998
|
+
try {
|
|
999
|
+
const microfrontendsJsonPaths = import_fast_glob2.default.globSync(
|
|
1000
|
+
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
1001
|
+
{
|
|
1002
|
+
cwd: repositoryRoot,
|
|
1003
|
+
absolute: true,
|
|
1004
|
+
onlyFiles: true,
|
|
1005
|
+
followSymbolicLinks: false,
|
|
1006
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
1007
|
+
}
|
|
1008
|
+
);
|
|
1009
|
+
const matchingPaths = [];
|
|
1010
|
+
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
1011
|
+
try {
|
|
1012
|
+
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
1013
|
+
microfrontendsJsonPath,
|
|
1014
|
+
"utf-8"
|
|
1015
|
+
);
|
|
1016
|
+
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
1017
|
+
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
1018
|
+
matchingPaths.push(microfrontendsJsonPath);
|
|
1019
|
+
}
|
|
1020
|
+
} catch (error) {
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
if (matchingPaths.length > 1) {
|
|
1024
|
+
throw new Error(
|
|
1025
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
|
|
1026
|
+
${matchingPaths.join("\n \u2022 ")}`
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
if (matchingPaths.length === 0) {
|
|
1030
|
+
throw new Error(
|
|
1031
|
+
`Could not find default application with "applications.${applicationName}"`
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
const [packageJsonPath] = matchingPaths;
|
|
1035
|
+
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
1036
|
+
} catch (error) {
|
|
1037
|
+
return null;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function findDefaultMicrofrontendsPackage(opts) {
|
|
1041
|
+
const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
|
|
1042
|
+
if (configCache2[cacheKey]) {
|
|
1043
|
+
return configCache2[cacheKey];
|
|
1044
|
+
}
|
|
1045
|
+
const result = findDefaultMicrofrontendsPackages(opts);
|
|
1046
|
+
if (!result) {
|
|
1047
|
+
throw new Error(
|
|
1048
|
+
"Error trying to resolve the main microfrontends configuration"
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
configCache2[cacheKey] = result;
|
|
1052
|
+
return result;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1056
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1057
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
1058
|
+
function isMonorepo({
|
|
1059
|
+
repositoryRoot
|
|
1060
|
+
}) {
|
|
1061
|
+
try {
|
|
1062
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
1063
|
+
return true;
|
|
1064
|
+
}
|
|
1065
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1066
|
+
return true;
|
|
1067
|
+
}
|
|
1068
|
+
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
1069
|
+
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
1070
|
+
return false;
|
|
1071
|
+
}
|
|
1072
|
+
const packageJson = JSON.parse(
|
|
1073
|
+
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
1074
|
+
);
|
|
1075
|
+
return packageJson.workspaces !== void 0;
|
|
1076
|
+
} catch (error) {
|
|
1077
|
+
console.error("Error determining if repository is a monorepo", error);
|
|
1078
|
+
return false;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// src/config/microfrontends/utils/find-package-root.ts
|
|
1083
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1084
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
1085
|
+
var PACKAGE_JSON = "package.json";
|
|
1086
|
+
function findPackageRoot(startDir) {
|
|
1087
|
+
let currentDir = startDir || process.cwd();
|
|
1088
|
+
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
1089
|
+
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
1090
|
+
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
1091
|
+
return currentDir;
|
|
1092
|
+
}
|
|
1093
|
+
currentDir = import_node_path5.default.dirname(currentDir);
|
|
1094
|
+
}
|
|
1095
|
+
throw new Error(
|
|
1096
|
+
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
1097
|
+
);
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
1101
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1102
|
+
var import_node_path6 = require("path");
|
|
1103
|
+
function findConfig({ dir }) {
|
|
1104
|
+
for (const filename of CONFIGURATION_FILENAMES) {
|
|
1105
|
+
const maybeConfig = (0, import_node_path6.join)(dir, filename);
|
|
1106
|
+
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
1107
|
+
return maybeConfig;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
return null;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1114
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1115
|
+
|
|
1116
|
+
// src/config/microfrontends/server/constants.ts
|
|
1117
|
+
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
1118
|
+
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
1119
|
+
|
|
1120
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1121
|
+
function getOutputFilePath() {
|
|
1122
|
+
return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// src/config/microfrontends/server/validation.ts
|
|
1126
|
+
var import_jsonc_parser3 = require("jsonc-parser");
|
|
1127
|
+
var import_ajv = require("ajv");
|
|
1128
|
+
|
|
1129
|
+
// schema/schema.json
|
|
1130
|
+
var schema_default = {
|
|
1131
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
1132
|
+
$ref: "#/definitions/Config",
|
|
1133
|
+
definitions: {
|
|
1134
|
+
Config: {
|
|
1135
|
+
anyOf: [
|
|
1136
|
+
{
|
|
1137
|
+
$ref: "#/definitions/MainConfig"
|
|
1138
|
+
},
|
|
1139
|
+
{
|
|
1140
|
+
$ref: "#/definitions/ChildConfig"
|
|
1141
|
+
}
|
|
1142
|
+
]
|
|
1143
|
+
},
|
|
1144
|
+
MainConfig: {
|
|
1145
|
+
type: "object",
|
|
1146
|
+
properties: {
|
|
1147
|
+
$schema: {
|
|
1148
|
+
type: "string"
|
|
1149
|
+
},
|
|
1150
|
+
version: {
|
|
1151
|
+
type: "string",
|
|
1152
|
+
const: "1"
|
|
1153
|
+
},
|
|
1154
|
+
options: {
|
|
1155
|
+
$ref: "#/definitions/Options"
|
|
1156
|
+
},
|
|
1157
|
+
applications: {
|
|
1158
|
+
$ref: "#/definitions/ApplicationRouting",
|
|
1159
|
+
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"
|
|
1160
|
+
}
|
|
1161
|
+
},
|
|
1162
|
+
required: [
|
|
1163
|
+
"applications"
|
|
1164
|
+
],
|
|
1165
|
+
additionalProperties: false
|
|
1166
|
+
},
|
|
1167
|
+
Options: {
|
|
1168
|
+
type: "object",
|
|
1169
|
+
properties: {
|
|
1170
|
+
vercel: {
|
|
1171
|
+
$ref: "#/definitions/VercelOptions",
|
|
1172
|
+
description: "Microfrontends wide options for Vercel.",
|
|
1173
|
+
deprecated: "This is being replaced by the `disableOverrides` field below."
|
|
1174
|
+
},
|
|
1175
|
+
disableOverrides: {
|
|
1176
|
+
type: "boolean",
|
|
1177
|
+
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."
|
|
1178
|
+
},
|
|
1179
|
+
localProxy: {
|
|
1180
|
+
$ref: "#/definitions/LocalProxyOptions",
|
|
1181
|
+
description: "Options for local proxy.",
|
|
1182
|
+
deprecated: "This is being replaced by the `localProxyPort` field below."
|
|
1183
|
+
},
|
|
1184
|
+
localProxyPort: {
|
|
1185
|
+
type: "number",
|
|
1186
|
+
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
1187
|
+
}
|
|
1188
|
+
},
|
|
1189
|
+
additionalProperties: false
|
|
1190
|
+
},
|
|
1191
|
+
VercelOptions: {
|
|
1192
|
+
type: "object",
|
|
1193
|
+
properties: {
|
|
1194
|
+
disableOverrides: {
|
|
1195
|
+
type: "boolean",
|
|
1196
|
+
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."
|
|
1197
|
+
}
|
|
1198
|
+
},
|
|
1199
|
+
additionalProperties: false
|
|
1200
|
+
},
|
|
1201
|
+
LocalProxyOptions: {
|
|
1202
|
+
type: "object",
|
|
1203
|
+
properties: {
|
|
1204
|
+
port: {
|
|
1205
|
+
type: "number",
|
|
1206
|
+
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
additionalProperties: false
|
|
1210
|
+
},
|
|
1211
|
+
ApplicationRouting: {
|
|
1212
|
+
type: "object",
|
|
1213
|
+
additionalProperties: {
|
|
1214
|
+
$ref: "#/definitions/Application"
|
|
1215
|
+
},
|
|
1216
|
+
propertyNames: {
|
|
1217
|
+
description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
|
|
1218
|
+
}
|
|
1219
|
+
},
|
|
1220
|
+
Application: {
|
|
1221
|
+
anyOf: [
|
|
1222
|
+
{
|
|
1223
|
+
$ref: "#/definitions/DefaultApplication"
|
|
1224
|
+
},
|
|
1225
|
+
{
|
|
1226
|
+
$ref: "#/definitions/ChildApplication"
|
|
1227
|
+
}
|
|
1228
|
+
]
|
|
1229
|
+
},
|
|
1230
|
+
DefaultApplication: {
|
|
1231
|
+
type: "object",
|
|
1232
|
+
properties: {
|
|
1233
|
+
vercel: {
|
|
1234
|
+
$ref: "#/definitions/Vercel",
|
|
1235
|
+
deprecated: "This is being replaced by the `projectId` field below."
|
|
1236
|
+
},
|
|
1237
|
+
projectId: {
|
|
1238
|
+
type: "string",
|
|
1239
|
+
description: "Vercel project ID"
|
|
1240
|
+
},
|
|
1241
|
+
production: {
|
|
1242
|
+
$ref: "#/definitions/HostConfig",
|
|
1243
|
+
deprecated: "This is a duplicate of the `development.fallback` field and this will be removed soon."
|
|
1244
|
+
},
|
|
1245
|
+
development: {
|
|
1246
|
+
$ref: "#/definitions/Development"
|
|
1247
|
+
}
|
|
1248
|
+
},
|
|
1249
|
+
additionalProperties: false
|
|
1250
|
+
},
|
|
1251
|
+
Vercel: {
|
|
1252
|
+
type: "object",
|
|
1253
|
+
properties: {
|
|
1254
|
+
projectId: {
|
|
1255
|
+
type: "string",
|
|
1256
|
+
description: "Vercel project ID"
|
|
1257
|
+
}
|
|
1258
|
+
},
|
|
1259
|
+
required: [
|
|
1260
|
+
"projectId"
|
|
1261
|
+
],
|
|
1262
|
+
additionalProperties: false
|
|
1263
|
+
},
|
|
1264
|
+
HostConfig: {
|
|
1265
|
+
type: "object",
|
|
1266
|
+
properties: {
|
|
1267
|
+
protocol: {
|
|
1268
|
+
type: "string",
|
|
1269
|
+
enum: [
|
|
1270
|
+
"http",
|
|
1271
|
+
"https"
|
|
1272
|
+
],
|
|
1273
|
+
description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
|
|
1274
|
+
},
|
|
1275
|
+
host: {
|
|
1276
|
+
type: "string",
|
|
1277
|
+
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`)."
|
|
1278
|
+
},
|
|
1279
|
+
port: {
|
|
1280
|
+
type: "number",
|
|
1281
|
+
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
1282
|
+
}
|
|
1283
|
+
},
|
|
1284
|
+
required: [
|
|
1285
|
+
"host"
|
|
1286
|
+
],
|
|
1287
|
+
additionalProperties: false
|
|
1288
|
+
},
|
|
1289
|
+
Development: {
|
|
1290
|
+
type: "object",
|
|
1291
|
+
properties: {
|
|
1292
|
+
local: {
|
|
1293
|
+
$ref: "#/definitions/LocalHostConfig",
|
|
1294
|
+
deprecated: "This is being replaced by the `localPort` field below."
|
|
1295
|
+
},
|
|
1296
|
+
localPort: {
|
|
1297
|
+
type: "number",
|
|
1298
|
+
description: "The local port number that this application runs on when it is running locally. Common values include `80` for HTTP and `443` for HTTPS."
|
|
1299
|
+
},
|
|
1300
|
+
fallback: {
|
|
1301
|
+
anyOf: [
|
|
1302
|
+
{
|
|
1303
|
+
$ref: "#/definitions/HostConfig"
|
|
1304
|
+
},
|
|
1305
|
+
{
|
|
1306
|
+
type: "string"
|
|
1307
|
+
}
|
|
1308
|
+
],
|
|
1309
|
+
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.\n\nIf passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTPS. If omitted, the port defaults to `80` for HTTP and `443` for HTTPS."
|
|
1310
|
+
},
|
|
1311
|
+
task: {
|
|
1312
|
+
type: "string",
|
|
1313
|
+
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
1314
|
+
}
|
|
1315
|
+
},
|
|
1316
|
+
additionalProperties: false
|
|
1317
|
+
},
|
|
1318
|
+
LocalHostConfig: {
|
|
1319
|
+
type: "object",
|
|
1320
|
+
additionalProperties: false,
|
|
1321
|
+
properties: {
|
|
1322
|
+
host: {
|
|
1323
|
+
type: "string",
|
|
1324
|
+
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`)."
|
|
1325
|
+
},
|
|
1326
|
+
protocol: {
|
|
1327
|
+
type: "string",
|
|
1328
|
+
enum: [
|
|
1329
|
+
"http",
|
|
1330
|
+
"https"
|
|
1331
|
+
],
|
|
1332
|
+
description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
|
|
1333
|
+
},
|
|
1334
|
+
port: {
|
|
1335
|
+
type: "number",
|
|
1336
|
+
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
},
|
|
1340
|
+
ChildApplication: {
|
|
1341
|
+
type: "object",
|
|
1342
|
+
properties: {
|
|
1343
|
+
vercel: {
|
|
1344
|
+
$ref: "#/definitions/Vercel",
|
|
1345
|
+
deprecated: "This is being replaced by the `projectId` field below."
|
|
1346
|
+
},
|
|
1347
|
+
projectId: {
|
|
1348
|
+
type: "string",
|
|
1349
|
+
description: "Vercel project ID"
|
|
1350
|
+
},
|
|
1351
|
+
production: {
|
|
1352
|
+
$ref: "#/definitions/HostConfig",
|
|
1353
|
+
deprecated: "This is a duplicate of the `development.fallback` field and this will be removed soon."
|
|
1354
|
+
},
|
|
1355
|
+
development: {
|
|
1356
|
+
$ref: "#/definitions/Development"
|
|
1357
|
+
},
|
|
1358
|
+
routing: {
|
|
1359
|
+
$ref: "#/definitions/Routing",
|
|
1360
|
+
description: "Groups of path expressions that are routed to this application."
|
|
1361
|
+
}
|
|
1362
|
+
},
|
|
1363
|
+
required: [
|
|
1364
|
+
"routing"
|
|
1365
|
+
],
|
|
1366
|
+
additionalProperties: false
|
|
1367
|
+
},
|
|
1368
|
+
Routing: {
|
|
1369
|
+
type: "array",
|
|
1370
|
+
items: {
|
|
1371
|
+
$ref: "#/definitions/PathGroup"
|
|
1372
|
+
}
|
|
1373
|
+
},
|
|
1374
|
+
PathGroup: {
|
|
1375
|
+
type: "object",
|
|
1376
|
+
properties: {
|
|
1377
|
+
group: {
|
|
1378
|
+
type: "string",
|
|
1379
|
+
description: "Optional group name for the paths"
|
|
1380
|
+
},
|
|
1381
|
+
flag: {
|
|
1382
|
+
type: "string",
|
|
1383
|
+
description: "flag name that can be used to enable/disable all paths in the group"
|
|
1384
|
+
},
|
|
1385
|
+
paths: {
|
|
1386
|
+
type: "array",
|
|
1387
|
+
items: {
|
|
1388
|
+
type: "string"
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
},
|
|
1392
|
+
required: [
|
|
1393
|
+
"paths"
|
|
1394
|
+
],
|
|
1395
|
+
additionalProperties: false
|
|
1396
|
+
},
|
|
1397
|
+
ChildConfig: {
|
|
1398
|
+
type: "object",
|
|
1399
|
+
properties: {
|
|
1400
|
+
$schema: {
|
|
1401
|
+
type: "string"
|
|
1402
|
+
},
|
|
1403
|
+
version: {
|
|
1404
|
+
type: "string",
|
|
1405
|
+
const: "1"
|
|
1406
|
+
},
|
|
1407
|
+
options: {
|
|
1408
|
+
$ref: "#/definitions/Options"
|
|
1409
|
+
},
|
|
1410
|
+
partOf: {
|
|
1411
|
+
type: "string",
|
|
1412
|
+
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."
|
|
1413
|
+
}
|
|
1414
|
+
},
|
|
1415
|
+
required: [
|
|
1416
|
+
"partOf"
|
|
1417
|
+
],
|
|
1418
|
+
additionalProperties: false
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
// src/config/schema/utils/load.ts
|
|
1424
|
+
var SCHEMA = schema_default;
|
|
1425
|
+
|
|
1426
|
+
// src/config/microfrontends/server/validation.ts
|
|
1427
|
+
function filterAjvErrors(errors) {
|
|
1428
|
+
if (!errors) {
|
|
1429
|
+
return [];
|
|
1430
|
+
}
|
|
1431
|
+
return errors.filter((error) => {
|
|
1432
|
+
return error.keyword === "additionalProperties" || error.keyword === "required";
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
function validateSchema(configString) {
|
|
1436
|
+
const parsedConfig = (0, import_jsonc_parser3.parse)(configString);
|
|
1437
|
+
const ajv = new import_ajv.Ajv();
|
|
1438
|
+
const validate = ajv.compile(SCHEMA);
|
|
1439
|
+
const isValid = validate(parsedConfig);
|
|
1440
|
+
if (!isValid) {
|
|
1441
|
+
throw new MicrofrontendError(
|
|
1442
|
+
`Invalid microfrontends config:
|
|
1443
|
+
- ${ajv.errorsText(filterAjvErrors(validate.errors), { separator: "\n - " })}
|
|
1444
|
+
|
|
1445
|
+
See https://openapi.vercel.sh/microfrontends.json for the schema.`,
|
|
1446
|
+
{ type: "config", subtype: "does_not_match_schema" }
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
return parsedConfig;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
// src/config/microfrontends/server/index.ts
|
|
1453
|
+
var MicrofrontendsServer = class extends Microfrontends {
|
|
1454
|
+
/**
|
|
1455
|
+
* Writes the configuration to a file.
|
|
1456
|
+
*/
|
|
1457
|
+
writeConfig(opts = {
|
|
1458
|
+
pretty: true
|
|
1459
|
+
}) {
|
|
1460
|
+
const outputPath = getOutputFilePath();
|
|
1461
|
+
import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
|
|
1462
|
+
import_node_fs7.default.writeFileSync(
|
|
1463
|
+
outputPath,
|
|
1464
|
+
JSON.stringify(
|
|
1465
|
+
this.config.toSchemaJson(),
|
|
1466
|
+
null,
|
|
1467
|
+
opts.pretty ?? true ? 2 : void 0
|
|
1468
|
+
)
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
// --------- Static Methods ---------
|
|
1472
|
+
/**
|
|
1473
|
+
* Generates a MicrofrontendsServer instance from an unknown object.
|
|
1474
|
+
*/
|
|
1475
|
+
static fromUnknown({
|
|
1476
|
+
config,
|
|
1477
|
+
cookies,
|
|
1478
|
+
meta
|
|
1479
|
+
}) {
|
|
1480
|
+
const overrides = cookies ? parseOverrides(cookies) : void 0;
|
|
1481
|
+
if (typeof config === "string") {
|
|
1482
|
+
return new MicrofrontendsServer({
|
|
1483
|
+
config: MicrofrontendsServer.validate(config),
|
|
1484
|
+
overrides,
|
|
1485
|
+
meta
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
if (typeof config === "object") {
|
|
1489
|
+
return new MicrofrontendsServer({
|
|
1490
|
+
config,
|
|
1491
|
+
overrides,
|
|
1492
|
+
meta
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
throw new MicrofrontendError(
|
|
1496
|
+
"Invalid config: must be a string or an object",
|
|
1497
|
+
{ type: "config", subtype: "does_not_match_schema" }
|
|
1498
|
+
);
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Generates a MicrofrontendsServer instance from the environment.
|
|
1502
|
+
* Uses additional validation that is only available when in a node runtime
|
|
1503
|
+
*/
|
|
1504
|
+
static fromEnv({
|
|
1505
|
+
cookies,
|
|
1506
|
+
meta
|
|
1507
|
+
}) {
|
|
1508
|
+
return new MicrofrontendsServer({
|
|
1509
|
+
config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
|
|
1510
|
+
overrides: parseOverrides(cookies),
|
|
1511
|
+
meta
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Validates the configuration against the JSON schema
|
|
1516
|
+
*/
|
|
1517
|
+
static validate(config) {
|
|
1518
|
+
if (typeof config === "string") {
|
|
1519
|
+
const c = validateSchema(config);
|
|
1520
|
+
return c;
|
|
1521
|
+
}
|
|
1522
|
+
return config;
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Looks up the configuration by inferring the package root and looking for a microfrontends config file. If a file is not found,
|
|
1526
|
+
* it will look for a package in the repository with a microfrontends file that contains the current application
|
|
1527
|
+
* and use that configuration.
|
|
1528
|
+
*
|
|
1529
|
+
* This can return either a Child or Main configuration.
|
|
1530
|
+
*/
|
|
1531
|
+
static infer({
|
|
1532
|
+
directory,
|
|
1533
|
+
filePath,
|
|
1534
|
+
meta,
|
|
1535
|
+
cookies,
|
|
1536
|
+
options
|
|
1537
|
+
} = {}) {
|
|
1538
|
+
if (filePath && meta) {
|
|
1539
|
+
return MicrofrontendsServer.fromFile({
|
|
1540
|
+
filePath,
|
|
1541
|
+
cookies,
|
|
1542
|
+
meta,
|
|
1543
|
+
options
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
try {
|
|
1547
|
+
const packageRoot = findPackageRoot(directory);
|
|
1548
|
+
const packageJsonPath = (0, import_node_path8.join)(packageRoot, "package.json");
|
|
1549
|
+
const packageJson = JSON.parse(
|
|
1550
|
+
import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
|
|
1551
|
+
);
|
|
1552
|
+
if (!packageJson.name) {
|
|
1553
|
+
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1554
|
+
}
|
|
1555
|
+
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1556
|
+
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1557
|
+
if (maybeConfig) {
|
|
1558
|
+
return MicrofrontendsServer.fromFile({
|
|
1559
|
+
filePath: maybeConfig,
|
|
1560
|
+
cookies,
|
|
1561
|
+
meta: configMeta,
|
|
1562
|
+
options
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
const repositoryRoot = findRepositoryRoot();
|
|
1566
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1567
|
+
if (isMonorepo2) {
|
|
1568
|
+
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1569
|
+
repositoryRoot,
|
|
1570
|
+
applicationName: packageJson.name
|
|
1571
|
+
});
|
|
1572
|
+
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1573
|
+
if (maybeConfigFromDefault) {
|
|
1574
|
+
return MicrofrontendsServer.fromFile({
|
|
1575
|
+
filePath: maybeConfigFromDefault,
|
|
1576
|
+
cookies,
|
|
1577
|
+
meta: configMeta,
|
|
1578
|
+
options
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
throw new Error("Unable to infer");
|
|
1583
|
+
} catch (e) {
|
|
1584
|
+
throw new MicrofrontendError(
|
|
1585
|
+
"Unable to locate and parse microfrontends configuration",
|
|
1586
|
+
{ cause: e, type: "config", subtype: "inference_failed" }
|
|
1587
|
+
);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
/*
|
|
1591
|
+
* Generates a MicrofrontendsServer instance from a file.
|
|
1592
|
+
*/
|
|
1593
|
+
static fromFile({
|
|
1594
|
+
filePath,
|
|
1595
|
+
cookies,
|
|
1596
|
+
meta,
|
|
1597
|
+
options
|
|
1598
|
+
}) {
|
|
1599
|
+
try {
|
|
1600
|
+
const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1601
|
+
const config = MicrofrontendsServer.validate(configJson);
|
|
1602
|
+
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1603
|
+
const repositoryRoot = findRepositoryRoot();
|
|
1604
|
+
const isMonorepo2 = isMonorepo({ repositoryRoot });
|
|
1605
|
+
if (isMonorepo2) {
|
|
1606
|
+
const packagePath = findPackagePath({
|
|
1607
|
+
repositoryRoot,
|
|
1608
|
+
name: config.partOf
|
|
1609
|
+
});
|
|
1610
|
+
if (!packagePath) {
|
|
1611
|
+
throw new MicrofrontendError(
|
|
1612
|
+
`Could not find default application "${config.partOf}" in the repository`,
|
|
1613
|
+
{ type: "config", subtype: "not_found" }
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
const maybeConfig = findConfig({ dir: packagePath });
|
|
1617
|
+
if (!maybeConfig) {
|
|
1618
|
+
throw new MicrofrontendError(
|
|
1619
|
+
`Could not find microfrontends configuration in ${packagePath}`,
|
|
1620
|
+
{ type: "config", subtype: "not_found" }
|
|
1621
|
+
);
|
|
1622
|
+
}
|
|
1623
|
+
return MicrofrontendsServer.fromMainConfigFile({
|
|
1624
|
+
filePath: maybeConfig,
|
|
1625
|
+
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
return new MicrofrontendsServer({
|
|
1630
|
+
config,
|
|
1631
|
+
overrides: cookies ? parseOverrides(cookies) : void 0,
|
|
1632
|
+
meta
|
|
1633
|
+
});
|
|
1634
|
+
} catch (e) {
|
|
1635
|
+
throw MicrofrontendError.handle(e, {
|
|
1636
|
+
fileName: filePath
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
/*
|
|
1641
|
+
* Generates a MicrofrontendMainConfig instance from a file.
|
|
1642
|
+
*/
|
|
1643
|
+
static fromMainConfigFile({
|
|
1644
|
+
filePath,
|
|
1645
|
+
overrides
|
|
1646
|
+
}) {
|
|
1647
|
+
try {
|
|
1648
|
+
const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
1649
|
+
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1650
|
+
if (!isMainConfig(validatedConfig)) {
|
|
1651
|
+
throw new MicrofrontendError(
|
|
1652
|
+
`${filePath} is not a main microfrontend config`,
|
|
1653
|
+
{
|
|
1654
|
+
type: "config",
|
|
1655
|
+
subtype: "invalid_main_path"
|
|
1656
|
+
}
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
1660
|
+
if (!defaultApplication) {
|
|
1661
|
+
throw new MicrofrontendError(
|
|
1662
|
+
"No default application found. At least one application needs to be the default by omitting routing.",
|
|
1663
|
+
{ type: "config", subtype: "no_default_application" }
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
return new MicrofrontendsServer({
|
|
1667
|
+
config: validatedConfig,
|
|
1668
|
+
overrides,
|
|
1669
|
+
meta: { fromApp: defaultApplication }
|
|
1670
|
+
});
|
|
1671
|
+
} catch (e) {
|
|
1672
|
+
throw MicrofrontendError.handle(e, {
|
|
1673
|
+
fileName: filePath
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
|
|
1679
|
+
// src/config/microfrontends/utils/get-application-context.ts
|
|
1680
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
1681
|
+
function getApplicationContext(opts) {
|
|
1682
|
+
if (opts?.appName) {
|
|
1683
|
+
return { name: opts.appName };
|
|
1684
|
+
}
|
|
1685
|
+
try {
|
|
1686
|
+
const packageJsonString = import_node_fs8.default.readFileSync("./package.json", "utf-8");
|
|
1687
|
+
const packageJson = JSON.parse(packageJsonString);
|
|
1688
|
+
if (!packageJson.name) {
|
|
1689
|
+
throw new MicrofrontendError(
|
|
1690
|
+
`package.json file missing required field "name"`,
|
|
1691
|
+
{
|
|
1692
|
+
type: "packageJson",
|
|
1693
|
+
subtype: "missing_field_name",
|
|
1694
|
+
source: "@vercel/microfrontends/next"
|
|
1695
|
+
}
|
|
1696
|
+
);
|
|
1697
|
+
}
|
|
1698
|
+
return { name: packageJson.name };
|
|
1699
|
+
} catch (err) {
|
|
1700
|
+
throw MicrofrontendError.handle(err, {
|
|
1701
|
+
fileName: "package.json"
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
// src/sveltekit/config/index.ts
|
|
1707
|
+
function withMicrofrontends(config, opts) {
|
|
1708
|
+
const { name: fromApp } = getApplicationContext(opts);
|
|
1709
|
+
const microfrontends = MicrofrontendsServer.infer({
|
|
1710
|
+
filePath: opts?.configPath,
|
|
1711
|
+
meta: {
|
|
1712
|
+
fromApp
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
const app = microfrontends.config.getApplication(fromApp);
|
|
1716
|
+
if (!app.isDefault()) {
|
|
1717
|
+
const assetPrefix = app.getAssetPrefix();
|
|
1718
|
+
if (config.kit?.appDir !== void 0 && config.kit.appDir !== assetPrefix) {
|
|
1719
|
+
throw new Error(
|
|
1720
|
+
`"appDir" is already set and does not equal ${assetPrefix}. Either omit "appDir" in your Svelte config, or set it to "${assetPrefix}".`
|
|
1721
|
+
);
|
|
1722
|
+
}
|
|
1723
|
+
if (!config.kit) {
|
|
1724
|
+
config.kit = {};
|
|
1725
|
+
}
|
|
1726
|
+
config.kit.appDir = assetPrefix;
|
|
1727
|
+
}
|
|
1728
|
+
displayLocalProxyInfo(microfrontends.config.getLocalProxyPort());
|
|
1729
|
+
return config;
|
|
1730
|
+
}
|
|
1731
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1732
|
+
0 && (module.exports = {
|
|
1733
|
+
withMicrofrontends
|
|
1734
|
+
});
|
|
1735
|
+
//# sourceMappingURL=sveltekit.cjs.map
|