@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/v2/config.cjs
DELETED
|
@@ -1,709 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/config-v2/microfrontends-config/isomorphic/index.ts
|
|
21
|
-
var isomorphic_exports = {};
|
|
22
|
-
__export(isomorphic_exports, {
|
|
23
|
-
MicrofrontendConfigIsomorphic: () => MicrofrontendConfigIsomorphic
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(isomorphic_exports);
|
|
26
|
-
var import_jsonc_parser = require("jsonc-parser");
|
|
27
|
-
|
|
28
|
-
// src/config-v2/errors.ts
|
|
29
|
-
var MicrofrontendError = class extends Error {
|
|
30
|
-
constructor(message, opts) {
|
|
31
|
-
super(message);
|
|
32
|
-
this.name = "MicrofrontendsError";
|
|
33
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
34
|
-
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
35
|
-
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
36
|
-
Error.captureStackTrace(this, MicrofrontendError);
|
|
37
|
-
}
|
|
38
|
-
isKnown() {
|
|
39
|
-
return this.type !== "unknown";
|
|
40
|
-
}
|
|
41
|
-
isUnknown() {
|
|
42
|
-
return !this.isKnown();
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Converts an error to a MicrofrontendsError.
|
|
46
|
-
* @param original - The original error to convert.
|
|
47
|
-
* @returns The converted MicrofrontendsError.
|
|
48
|
-
*/
|
|
49
|
-
static convert(original, opts) {
|
|
50
|
-
if (opts == null ? void 0 : opts.fileName) {
|
|
51
|
-
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
52
|
-
if (err) {
|
|
53
|
-
return err;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (original.message.includes(
|
|
57
|
-
"Code generation from strings disallowed for this context"
|
|
58
|
-
)) {
|
|
59
|
-
return new MicrofrontendError(original.message, {
|
|
60
|
-
type: "config",
|
|
61
|
-
subtype: "unsupported_validation_env",
|
|
62
|
-
source: "ajv"
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return new MicrofrontendError(original.message);
|
|
66
|
-
}
|
|
67
|
-
static convertFSError(original, fileName) {
|
|
68
|
-
if (original instanceof Error && "code" in original) {
|
|
69
|
-
if (original.code === "ENOENT") {
|
|
70
|
-
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
71
|
-
type: "config",
|
|
72
|
-
subtype: "unable_to_read_file",
|
|
73
|
-
source: "fs"
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (original.code === "EACCES") {
|
|
77
|
-
return new MicrofrontendError(
|
|
78
|
-
`Permission denied while accessing "${fileName}"`,
|
|
79
|
-
{
|
|
80
|
-
type: "config",
|
|
81
|
-
subtype: "invalid_permissions",
|
|
82
|
-
source: "fs"
|
|
83
|
-
}
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (original instanceof SyntaxError) {
|
|
88
|
-
return new MicrofrontendError(
|
|
89
|
-
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
90
|
-
{
|
|
91
|
-
type: "config",
|
|
92
|
-
subtype: "invalid_syntax",
|
|
93
|
-
source: "fs"
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
101
|
-
* @param err - The error to handle.
|
|
102
|
-
* @returns A MicrofrontendsError instance.
|
|
103
|
-
*/
|
|
104
|
-
static handle(err, opts) {
|
|
105
|
-
if (err instanceof MicrofrontendError) {
|
|
106
|
-
return err;
|
|
107
|
-
}
|
|
108
|
-
if (err instanceof Error) {
|
|
109
|
-
return MicrofrontendError.convert(err, opts);
|
|
110
|
-
}
|
|
111
|
-
if (typeof err === "object" && err !== null) {
|
|
112
|
-
if ("message" in err && typeof err.message === "string") {
|
|
113
|
-
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return new MicrofrontendError("An unknown error occurred");
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// src/config-v2/microfrontends-config/utils/get-config-from-env.ts
|
|
121
|
-
function getConfigStringFromEnv() {
|
|
122
|
-
const config = process.env.MFE_CONFIG;
|
|
123
|
-
if (!config) {
|
|
124
|
-
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
125
|
-
type: "config",
|
|
126
|
-
subtype: "not_found_in_env"
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
return config;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// src/config-v2/schema/utils/is-main-config.ts
|
|
133
|
-
function isMainConfig(c) {
|
|
134
|
-
return !("partOf" in c);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/config-v2/schema/utils/is-default-app.ts
|
|
138
|
-
function isDefaultApp(a) {
|
|
139
|
-
return !("routing" in a);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// src/config-v2/microfrontends-config/client/index.ts
|
|
143
|
-
var import_path_to_regexp = require("path-to-regexp");
|
|
144
|
-
var MicrofrontendConfigClient = class {
|
|
145
|
-
constructor(config, opts) {
|
|
146
|
-
this.pathCache = {};
|
|
147
|
-
this.serialized = config;
|
|
148
|
-
if (opts == null ? void 0 : opts.removeFlaggedPaths) {
|
|
149
|
-
for (const app of Object.values(config.applications)) {
|
|
150
|
-
if (app.routing) {
|
|
151
|
-
app.routing = app.routing.filter((match) => !match.flag);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
this.applications = config.applications;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Create a new `MicrofrontendConfigClient` from a JSON string.
|
|
159
|
-
* Config must be passed in to remain framework agnostic
|
|
160
|
-
*/
|
|
161
|
-
static fromEnv(config, opts) {
|
|
162
|
-
if (!config) {
|
|
163
|
-
throw new Error("No microfrontends configuration found");
|
|
164
|
-
}
|
|
165
|
-
return new MicrofrontendConfigClient(
|
|
166
|
-
JSON.parse(config),
|
|
167
|
-
opts
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
isEqual(other) {
|
|
171
|
-
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
172
|
-
}
|
|
173
|
-
getApplicationNameForPath(path) {
|
|
174
|
-
if (!path.startsWith("/")) {
|
|
175
|
-
throw new Error(`Path must start with a /`);
|
|
176
|
-
}
|
|
177
|
-
if (this.pathCache[path]) {
|
|
178
|
-
return this.pathCache[path];
|
|
179
|
-
}
|
|
180
|
-
const pathname = new URL(path, "https://example.com").pathname;
|
|
181
|
-
for (const [name, application] of Object.entries(this.applications)) {
|
|
182
|
-
if (application.routing) {
|
|
183
|
-
for (const group of application.routing) {
|
|
184
|
-
for (const childPath of group.paths) {
|
|
185
|
-
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
186
|
-
if (regexp.test(pathname)) {
|
|
187
|
-
this.pathCache[path] = name;
|
|
188
|
-
return name;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
const defaultApplication = Object.entries(this.applications).find(
|
|
195
|
-
([, application]) => application.default
|
|
196
|
-
);
|
|
197
|
-
if (!defaultApplication) {
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
this.pathCache[path] = defaultApplication[0];
|
|
201
|
-
return defaultApplication[0];
|
|
202
|
-
}
|
|
203
|
-
serialize() {
|
|
204
|
-
return this.serialized;
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
// src/config-v2/overrides/constants.ts
|
|
209
|
-
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
210
|
-
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
211
|
-
|
|
212
|
-
// src/config-v2/overrides/is-override-cookie.ts
|
|
213
|
-
function isOverrideCookie(cookie) {
|
|
214
|
-
var _a;
|
|
215
|
-
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// src/config-v2/overrides/get-override-from-cookie.ts
|
|
219
|
-
function getOverrideFromCookie(cookie) {
|
|
220
|
-
if (!isOverrideCookie(cookie) || !cookie.value)
|
|
221
|
-
return;
|
|
222
|
-
return {
|
|
223
|
-
application: cookie.name.replace(OVERRIDES_ENV_COOKIE_PREFIX, ""),
|
|
224
|
-
host: cookie.value
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// src/config-v2/overrides/parse-overrides.ts
|
|
229
|
-
function parseOverrides(cookies) {
|
|
230
|
-
const overridesConfig = { applications: {} };
|
|
231
|
-
cookies.forEach((cookie) => {
|
|
232
|
-
const override = getOverrideFromCookie(cookie);
|
|
233
|
-
if (!override)
|
|
234
|
-
return;
|
|
235
|
-
overridesConfig.applications[override.application] = {
|
|
236
|
-
environment: { host: override.host }
|
|
237
|
-
};
|
|
238
|
-
});
|
|
239
|
-
return overridesConfig;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// src/config-v2/microfrontends-config/isomorphic/validation.ts
|
|
243
|
-
var import_path_to_regexp2 = require("path-to-regexp");
|
|
244
|
-
var SUPPORTED_VERSIONS = ["2"];
|
|
245
|
-
var validateConfigVersion = (version) => {
|
|
246
|
-
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
247
|
-
throw new MicrofrontendError(
|
|
248
|
-
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
249
|
-
", "
|
|
250
|
-
)}`,
|
|
251
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
var validateConfigPaths = (applicationConfigsById) => {
|
|
256
|
-
if (!applicationConfigsById) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
260
|
-
const errors = [];
|
|
261
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
262
|
-
if (isDefaultApp(app)) {
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
for (const pathMatch of app.routing) {
|
|
266
|
-
for (const path of pathMatch.paths) {
|
|
267
|
-
const tokens = (0, import_path_to_regexp2.parse)(path);
|
|
268
|
-
for (const token of tokens.slice(0, -1)) {
|
|
269
|
-
if (typeof token !== "string") {
|
|
270
|
-
errors.push(
|
|
271
|
-
`Path ${path} may only have a :wildcard in the last path component`
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
const existing = pathsByApplicationId.get(path);
|
|
276
|
-
if (existing) {
|
|
277
|
-
existing.applications.push(id);
|
|
278
|
-
} else {
|
|
279
|
-
pathsByApplicationId.set(path, {
|
|
280
|
-
applications: [id],
|
|
281
|
-
matcher: (0, import_path_to_regexp2.pathToRegexp)(path),
|
|
282
|
-
applicationId: id
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
const entries = Array.from(pathsByApplicationId.entries());
|
|
289
|
-
entries.forEach(([path, { applications: ids, matcher, applicationId }]) => {
|
|
290
|
-
if (ids.length > 1) {
|
|
291
|
-
errors.push(
|
|
292
|
-
`Duplicate path "${path}" for applications "${ids.join(", ")}"`
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
entries.forEach(
|
|
296
|
-
([
|
|
297
|
-
matchPath,
|
|
298
|
-
{ applications: matchIds, applicationId: matchApplicationId }
|
|
299
|
-
]) => {
|
|
300
|
-
if (path === matchPath) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
if (applicationId === matchApplicationId) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
if (matcher.test(matchPath)) {
|
|
307
|
-
const source = `"${path}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
308
|
-
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
309
|
-
errors.push(
|
|
310
|
-
`Overlapping path detected between ${source} and ${destination}`
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
);
|
|
315
|
-
});
|
|
316
|
-
if (errors.length) {
|
|
317
|
-
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
318
|
-
type: "config",
|
|
319
|
-
subtype: "conflicting_paths"
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
var validateAppPaths = (name, app) => {
|
|
324
|
-
for (const group of app.routing) {
|
|
325
|
-
for (const p of group.paths) {
|
|
326
|
-
if (p === "/") {
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
if (p.endsWith("/")) {
|
|
330
|
-
throw new MicrofrontendError(
|
|
331
|
-
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
332
|
-
{ type: "application", subtype: "invalid_path" }
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
if (!p.startsWith("/")) {
|
|
336
|
-
throw new MicrofrontendError(
|
|
337
|
-
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
338
|
-
{ type: "application", subtype: "invalid_path" }
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
345
|
-
if (!applicationConfigsById) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
|
|
349
|
-
([, app]) => !isDefaultApp(app)
|
|
350
|
-
);
|
|
351
|
-
const applicationsWithRoutingNames = applicationsWithRouting.map(
|
|
352
|
-
([key]) => key
|
|
353
|
-
);
|
|
354
|
-
const numApplications = Object.keys(applicationConfigsById).length;
|
|
355
|
-
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
356
|
-
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
357
|
-
if (numApplicationsWithoutRouting === 0) {
|
|
358
|
-
throw new MicrofrontendError(
|
|
359
|
-
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
360
|
-
{ type: "config", subtype: "no_default_application" }
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
if (numApplicationsWithoutRouting > 1) {
|
|
364
|
-
throw new MicrofrontendError(
|
|
365
|
-
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
366
|
-
{ type: "config", subtype: "multiple_default_applications" }
|
|
367
|
-
);
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
// src/config-v2/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
372
|
-
var PREFIX = "vc-ap";
|
|
373
|
-
function generateAssetPrefixFromName({
|
|
374
|
-
name
|
|
375
|
-
}) {
|
|
376
|
-
if (!name) {
|
|
377
|
-
throw new Error("Name is required to generate an asset prefix");
|
|
378
|
-
}
|
|
379
|
-
return `${PREFIX}-${name}`;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// src/config-v2/microfrontends-config/isomorphic/utils/generate-port.ts
|
|
383
|
-
function generatePortFromName({
|
|
384
|
-
name,
|
|
385
|
-
minPort = 3e3,
|
|
386
|
-
maxPort = 8e3
|
|
387
|
-
}) {
|
|
388
|
-
if (!name) {
|
|
389
|
-
throw new Error("Name is required to generate a port");
|
|
390
|
-
}
|
|
391
|
-
let hash = 0;
|
|
392
|
-
for (let i = 0; i < name.length; i++) {
|
|
393
|
-
hash = (hash << 5) - hash + name.charCodeAt(i);
|
|
394
|
-
hash |= 0;
|
|
395
|
-
}
|
|
396
|
-
hash = Math.abs(hash);
|
|
397
|
-
const range = maxPort - minPort;
|
|
398
|
-
const port = minPort + hash % range;
|
|
399
|
-
return port;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// src/config-v2/microfrontends-config/isomorphic/host.ts
|
|
403
|
-
var Host = class {
|
|
404
|
-
constructor(hostConfig, options) {
|
|
405
|
-
const { protocol = "https", host, port } = hostConfig;
|
|
406
|
-
this.protocol = protocol;
|
|
407
|
-
this.host = host;
|
|
408
|
-
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
409
|
-
this.local = options == null ? void 0 : options.isLocal;
|
|
410
|
-
}
|
|
411
|
-
isLocal() {
|
|
412
|
-
return this.local || this.host === "localhost" || this.host === "127.0.0.1";
|
|
413
|
-
}
|
|
414
|
-
static getPort({
|
|
415
|
-
protocol,
|
|
416
|
-
port
|
|
417
|
-
}) {
|
|
418
|
-
if (!port) {
|
|
419
|
-
if (protocol === "http") {
|
|
420
|
-
return 80;
|
|
421
|
-
}
|
|
422
|
-
return 443;
|
|
423
|
-
}
|
|
424
|
-
return port;
|
|
425
|
-
}
|
|
426
|
-
isDefaultPort() {
|
|
427
|
-
return this.port === Host.getPort({ protocol: this.protocol });
|
|
428
|
-
}
|
|
429
|
-
toString(opts = {}) {
|
|
430
|
-
const url = this.toUrl(opts);
|
|
431
|
-
return url.toString().replace(/\/$/, "");
|
|
432
|
-
}
|
|
433
|
-
toUrl(opts = {}) {
|
|
434
|
-
const { includeDefaultPort } = opts;
|
|
435
|
-
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
436
|
-
return new URL(url);
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
var LocalHost = class extends Host {
|
|
440
|
-
constructor({
|
|
441
|
-
appName,
|
|
442
|
-
...hostConfig
|
|
443
|
-
}) {
|
|
444
|
-
const host = hostConfig.host ?? "localhost";
|
|
445
|
-
const port = hostConfig.port ?? generatePortFromName({ name: appName });
|
|
446
|
-
const protocol = hostConfig.protocol ?? "http";
|
|
447
|
-
super({ protocol, host, port });
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
// src/config-v2/microfrontends-config/isomorphic/application.ts
|
|
452
|
-
var Application = class {
|
|
453
|
-
constructor(name, {
|
|
454
|
-
app,
|
|
455
|
-
overrides,
|
|
456
|
-
isDefault
|
|
457
|
-
}) {
|
|
458
|
-
var _a, _b;
|
|
459
|
-
this.name = name;
|
|
460
|
-
this.development = {
|
|
461
|
-
local: new LocalHost({
|
|
462
|
-
appName: name,
|
|
463
|
-
...(_a = app.development) == null ? void 0 : _a.local
|
|
464
|
-
}),
|
|
465
|
-
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
|
|
466
|
-
};
|
|
467
|
-
this.production = app.production ? new Host(app.production) : void 0;
|
|
468
|
-
this.vercel = app.vercel;
|
|
469
|
-
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
470
|
-
environment: new Host(overrides.environment)
|
|
471
|
-
} : void 0;
|
|
472
|
-
this.default = isDefault ?? false;
|
|
473
|
-
this.serialized = app;
|
|
474
|
-
}
|
|
475
|
-
isDefault() {
|
|
476
|
-
return this.default;
|
|
477
|
-
}
|
|
478
|
-
getAssetPrefix() {
|
|
479
|
-
return generateAssetPrefixFromName({ name: this.name });
|
|
480
|
-
}
|
|
481
|
-
serialize() {
|
|
482
|
-
return this.serialized;
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
var DefaultApplication = class extends Application {
|
|
486
|
-
constructor(name, {
|
|
487
|
-
app,
|
|
488
|
-
overrides
|
|
489
|
-
}) {
|
|
490
|
-
super(name, {
|
|
491
|
-
app,
|
|
492
|
-
overrides,
|
|
493
|
-
isDefault: true
|
|
494
|
-
});
|
|
495
|
-
this.default = true;
|
|
496
|
-
this.production = new Host(app.production);
|
|
497
|
-
}
|
|
498
|
-
getAssetPrefix() {
|
|
499
|
-
return "";
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
var ChildApplication = class extends Application {
|
|
503
|
-
constructor(name, {
|
|
504
|
-
app,
|
|
505
|
-
overrides
|
|
506
|
-
}) {
|
|
507
|
-
ChildApplication.validate(name, app);
|
|
508
|
-
super(name, {
|
|
509
|
-
app,
|
|
510
|
-
overrides,
|
|
511
|
-
isDefault: false
|
|
512
|
-
});
|
|
513
|
-
this.default = false;
|
|
514
|
-
this.routing = app.routing;
|
|
515
|
-
}
|
|
516
|
-
static validate(name, app) {
|
|
517
|
-
validateAppPaths(name, app);
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
// src/config-v2/microfrontends-config/isomorphic/constants.ts
|
|
522
|
-
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
523
|
-
|
|
524
|
-
// src/config-v2/microfrontends-config/isomorphic/index.ts
|
|
525
|
-
var MicrofrontendConfigIsomorphic = class {
|
|
526
|
-
constructor({
|
|
527
|
-
config,
|
|
528
|
-
overrides,
|
|
529
|
-
meta
|
|
530
|
-
}) {
|
|
531
|
-
this.childApplications = {};
|
|
532
|
-
var _a, _b, _c, _d;
|
|
533
|
-
MicrofrontendConfigIsomorphic.validate(config);
|
|
534
|
-
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
535
|
-
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
536
|
-
this.isMainConfig = isMainConfig(config);
|
|
537
|
-
if (isMainConfig(config)) {
|
|
538
|
-
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
539
|
-
const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
|
|
540
|
-
if (isDefaultApp(appConfig)) {
|
|
541
|
-
this.defaultApplication = new DefaultApplication(appId, {
|
|
542
|
-
app: appConfig,
|
|
543
|
-
overrides: appOverrides
|
|
544
|
-
});
|
|
545
|
-
} else {
|
|
546
|
-
this.childApplications[appId] = new ChildApplication(appId, {
|
|
547
|
-
app: appConfig,
|
|
548
|
-
overrides: appOverrides
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
} else {
|
|
553
|
-
this.partOf = config.partOf;
|
|
554
|
-
const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
|
|
555
|
-
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
556
|
-
meta.fromApp,
|
|
557
|
-
{
|
|
558
|
-
// we don't know routing because we're not in the main config
|
|
559
|
-
app: { routing: [] },
|
|
560
|
-
overrides: appOverrides
|
|
561
|
-
}
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
if (isMainConfig(config) && !this.defaultApplication) {
|
|
565
|
-
throw new MicrofrontendError(
|
|
566
|
-
`Could not find default application in microfrontends configuration`,
|
|
567
|
-
{
|
|
568
|
-
type: "application",
|
|
569
|
-
subtype: "not_found"
|
|
570
|
-
}
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
this.config = config;
|
|
574
|
-
this.options = config.options;
|
|
575
|
-
this.serialized = {
|
|
576
|
-
config,
|
|
577
|
-
overrides,
|
|
578
|
-
meta
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
static validate(config) {
|
|
582
|
-
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
583
|
-
if (isMainConfig(c)) {
|
|
584
|
-
validateConfigVersion(c.version);
|
|
585
|
-
validateConfigPaths(c.applications);
|
|
586
|
-
validateConfigDefaultApplication(c.applications);
|
|
587
|
-
}
|
|
588
|
-
return c;
|
|
589
|
-
}
|
|
590
|
-
static fromEnv({
|
|
591
|
-
meta,
|
|
592
|
-
cookies
|
|
593
|
-
}) {
|
|
594
|
-
return new MicrofrontendConfigIsomorphic({
|
|
595
|
-
config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
|
|
596
|
-
overrides: parseOverrides(cookies ?? []),
|
|
597
|
-
meta
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
isOverridesDisabled() {
|
|
601
|
-
var _a, _b;
|
|
602
|
-
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
603
|
-
}
|
|
604
|
-
getConfig() {
|
|
605
|
-
return this.config;
|
|
606
|
-
}
|
|
607
|
-
getApplicationsByType() {
|
|
608
|
-
return {
|
|
609
|
-
defaultApplication: this.defaultApplication,
|
|
610
|
-
applications: Object.values(this.childApplications)
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
getChildApplications() {
|
|
614
|
-
return Object.values(this.childApplications);
|
|
615
|
-
}
|
|
616
|
-
getAllApplications() {
|
|
617
|
-
return [
|
|
618
|
-
this.defaultApplication,
|
|
619
|
-
...Object.values(this.childApplications)
|
|
620
|
-
].filter(Boolean);
|
|
621
|
-
}
|
|
622
|
-
getApplication(name) {
|
|
623
|
-
var _a;
|
|
624
|
-
if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
|
|
625
|
-
return this.defaultApplication;
|
|
626
|
-
}
|
|
627
|
-
const app = this.childApplications[name];
|
|
628
|
-
if (!app) {
|
|
629
|
-
throw new MicrofrontendError(
|
|
630
|
-
`Could not find microfrontends configuration for application "${name}"`,
|
|
631
|
-
{
|
|
632
|
-
type: "application",
|
|
633
|
-
subtype: "not_found"
|
|
634
|
-
}
|
|
635
|
-
);
|
|
636
|
-
}
|
|
637
|
-
return app;
|
|
638
|
-
}
|
|
639
|
-
getApplicationByProjectId(projectId) {
|
|
640
|
-
var _a, _b;
|
|
641
|
-
if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
|
|
642
|
-
return this.defaultApplication;
|
|
643
|
-
}
|
|
644
|
-
return Object.values(this.childApplications).find(
|
|
645
|
-
(app) => {
|
|
646
|
-
var _a2;
|
|
647
|
-
return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
|
|
648
|
-
}
|
|
649
|
-
);
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* Returns the default application. This can throw if the default application
|
|
653
|
-
* is undefined ( )
|
|
654
|
-
*/
|
|
655
|
-
getDefaultApplication() {
|
|
656
|
-
if (!this.defaultApplication) {
|
|
657
|
-
throw new MicrofrontendError(
|
|
658
|
-
`Could not find default application in microfrontends configuration`,
|
|
659
|
-
{
|
|
660
|
-
type: "application",
|
|
661
|
-
subtype: "not_found"
|
|
662
|
-
}
|
|
663
|
-
);
|
|
664
|
-
}
|
|
665
|
-
return this.defaultApplication;
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Returns the configured port for the local proxy
|
|
669
|
-
*/
|
|
670
|
-
getLocalProxyPort() {
|
|
671
|
-
var _a, _b;
|
|
672
|
-
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* Serializes the class back to the Schema type.
|
|
676
|
-
*
|
|
677
|
-
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
678
|
-
*/
|
|
679
|
-
toSchemaJson() {
|
|
680
|
-
return this.serialized.config;
|
|
681
|
-
}
|
|
682
|
-
toClientConfig() {
|
|
683
|
-
const applications = Object.fromEntries(
|
|
684
|
-
Object.entries(this.childApplications).map(([name, application]) => [
|
|
685
|
-
name,
|
|
686
|
-
{
|
|
687
|
-
default: false,
|
|
688
|
-
routing: application.routing
|
|
689
|
-
}
|
|
690
|
-
])
|
|
691
|
-
);
|
|
692
|
-
if (this.defaultApplication) {
|
|
693
|
-
applications[this.defaultApplication.name] = {
|
|
694
|
-
default: true
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
|
-
return new MicrofrontendConfigClient({
|
|
698
|
-
applications
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
serialize() {
|
|
702
|
-
return this.serialized;
|
|
703
|
-
}
|
|
704
|
-
};
|
|
705
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
706
|
-
0 && (module.exports = {
|
|
707
|
-
MicrofrontendConfigIsomorphic
|
|
708
|
-
});
|
|
709
|
-
//# sourceMappingURL=config.cjs.map
|