@vercel/microfrontends 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/bin/cli.cjs +403 -1627
- package/dist/config.cjs +460 -1004
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -25
- package/dist/config.js +456 -983
- package/dist/config.js.map +1 -1
- package/dist/{index-83133f2d.d.ts → index-bf67a461.d.ts} +3 -10
- package/dist/{v2/microfrontends → microfrontends}/server.cjs +128 -194
- package/dist/microfrontends/server.cjs.map +1 -0
- package/dist/{v2/microfrontends → microfrontends}/server.d.ts +6 -5
- package/dist/{v2/microfrontends → microfrontends}/server.js +125 -191
- package/dist/microfrontends/server.js.map +1 -0
- package/dist/{v2/microfrontends.cjs → microfrontends.cjs} +21 -35
- package/dist/microfrontends.cjs.map +1 -0
- package/dist/{v2/microfrontends.d.ts → microfrontends.d.ts} +4 -3
- package/dist/{v2/microfrontends.js → microfrontends.js} +20 -34
- 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 +1323 -1024
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +1 -1
- package/dist/next/config.js +1327 -1028
- 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 +14 -3
- package/dist/next/endpoints.js +77 -18
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +745 -425
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +10 -5
- package/dist/next/middleware.js +745 -425
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +595 -1032
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +14 -12
- package/dist/next/testing.js +589 -1016
- 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/routing.cjs +19 -0
- package/dist/routing.cjs.map +1 -0
- package/dist/routing.d.ts +26 -0
- package/dist/routing.js +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/schema.js.map +1 -0
- package/dist/{types-a995174e.d.ts → types-a29d224a.d.ts} +1 -7
- package/dist/{types-15b7f215.d.ts → types-cfe3308b.d.ts} +1 -1
- package/dist/types-fc30696d.d.ts +11 -0
- package/dist/utils/mfe-port.cjs +254 -1362
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +250 -1358
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +31 -365
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +3 -152
- package/dist/validation.js +30 -363
- package/dist/validation.js.map +1 -1
- package/package.json +32 -80
- 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 -723
- package/dist/v2/config.cjs.map +0 -1
- package/dist/v2/config.d.ts +0 -3
- package/dist/v2/config.js +0 -698
- 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 -2132
- 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 -2097
- 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 -15
- package/dist/v2/next/endpoints.js +0 -116
- package/dist/v2/next/endpoints.js.map +0 -1
- package/dist/v2/next/middleware.cjs +0 -1143
- package/dist/v2/next/middleware.cjs.map +0 -1
- package/dist/v2/next/middleware.d.ts +0 -29
- package/dist/v2/next/middleware.js +0 -1115
- package/dist/v2/next/middleware.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/schema.cjs.map +0 -1
- package/dist/v2/schema.d.ts +0 -1
- package/schema/schema-v2.json +0 -270
- /package/dist/{v2/schema.js.map → routing.js.map} +0 -0
- /package/dist/{v2/schema.js → schema.js} +0 -0
package/dist/utils/mfe-port.cjs
CHANGED
|
@@ -33,1167 +33,24 @@ __export(mfe_port_exports, {
|
|
|
33
33
|
mfePort: () => mfePort
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(mfe_port_exports);
|
|
36
|
-
var
|
|
37
|
-
var import_node_fs9 = __toESM(require("fs"), 1);
|
|
38
|
-
|
|
39
|
-
// src/config/types.ts
|
|
40
|
-
var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
|
|
41
|
-
|
|
42
|
-
// src/config/microfrontend-config.ts
|
|
43
|
-
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
44
|
-
|
|
45
|
-
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
46
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
47
|
-
|
|
48
|
-
// src/config-v2/microfrontends/server/constants.ts
|
|
49
|
-
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
50
|
-
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
51
|
-
|
|
52
|
-
// src/utils/is-vercel.ts
|
|
53
|
-
function isVercel() {
|
|
54
|
-
return process.env.VERCEL === "1";
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
58
|
-
function getOutputFilePath() {
|
|
59
|
-
if (isVercel()) {
|
|
60
|
-
return import_node_path.default.join(
|
|
61
|
-
".vercel",
|
|
62
|
-
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
63
|
-
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
return import_node_path.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// src/config/errors.ts
|
|
70
|
-
var MicrofrontendError = class extends Error {
|
|
71
|
-
constructor(message, opts) {
|
|
72
|
-
super(message);
|
|
73
|
-
this.name = "MicrofrontendsError";
|
|
74
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
75
|
-
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
76
|
-
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
77
|
-
Error.captureStackTrace(this, MicrofrontendError);
|
|
78
|
-
}
|
|
79
|
-
isKnown() {
|
|
80
|
-
return this.type !== "unknown";
|
|
81
|
-
}
|
|
82
|
-
isUnknown() {
|
|
83
|
-
return !this.isKnown();
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Converts an error to a MicrofrontendsError.
|
|
87
|
-
* @param original - The original error to convert.
|
|
88
|
-
* @returns The converted MicrofrontendsError.
|
|
89
|
-
*/
|
|
90
|
-
static convert(original, opts) {
|
|
91
|
-
if (opts == null ? void 0 : opts.fileName) {
|
|
92
|
-
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
93
|
-
if (err) {
|
|
94
|
-
return err;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (original.message.includes(
|
|
98
|
-
"Code generation from strings disallowed for this context"
|
|
99
|
-
)) {
|
|
100
|
-
return new MicrofrontendError(original.message, {
|
|
101
|
-
type: "config",
|
|
102
|
-
subtype: "unsupported_validation_env",
|
|
103
|
-
source: "ajv"
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return new MicrofrontendError(original.message);
|
|
107
|
-
}
|
|
108
|
-
static convertFSError(original, fileName) {
|
|
109
|
-
if (original instanceof Error && "code" in original) {
|
|
110
|
-
if (original.code === "ENOENT") {
|
|
111
|
-
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
112
|
-
type: "config",
|
|
113
|
-
subtype: "unable_to_read_file",
|
|
114
|
-
source: "fs"
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (original.code === "EACCES") {
|
|
118
|
-
return new MicrofrontendError(
|
|
119
|
-
`Permission denied while accessing "${fileName}"`,
|
|
120
|
-
{
|
|
121
|
-
type: "config",
|
|
122
|
-
subtype: "invalid_permissions",
|
|
123
|
-
source: "fs"
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (original instanceof SyntaxError) {
|
|
129
|
-
return new MicrofrontendError(
|
|
130
|
-
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
131
|
-
{
|
|
132
|
-
type: "config",
|
|
133
|
-
subtype: "invalid_syntax",
|
|
134
|
-
source: "fs"
|
|
135
|
-
}
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
142
|
-
* @param err - The error to handle.
|
|
143
|
-
* @returns A MicrofrontendsError instance.
|
|
144
|
-
*/
|
|
145
|
-
static handle(err, opts) {
|
|
146
|
-
if (err instanceof MicrofrontendError) {
|
|
147
|
-
return err;
|
|
148
|
-
}
|
|
149
|
-
if (err instanceof Error) {
|
|
150
|
-
return MicrofrontendError.convert(err, opts);
|
|
151
|
-
}
|
|
152
|
-
if (typeof err === "object" && err !== null) {
|
|
153
|
-
if ("message" in err && typeof err.message === "string") {
|
|
154
|
-
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return new MicrofrontendError("An unknown error occurred");
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// src/routing/url.ts
|
|
162
|
-
function buildUrlSafeString(givenOpts = {}) {
|
|
163
|
-
const options = {
|
|
164
|
-
joinString: "-",
|
|
165
|
-
lowercaseOnly: true,
|
|
166
|
-
maxLen: 100,
|
|
167
|
-
regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,
|
|
168
|
-
trimWhitespace: true,
|
|
169
|
-
...givenOpts
|
|
170
|
-
};
|
|
171
|
-
return {
|
|
172
|
-
generate: (...args) => {
|
|
173
|
-
const reJoinString = new RegExp(`${options.joinString}+`, "g");
|
|
174
|
-
let tag;
|
|
175
|
-
if (args.length === 0) {
|
|
176
|
-
throw new Error("generate method must be passed at least one argument");
|
|
177
|
-
}
|
|
178
|
-
for (let i = 0; i < args.length; i++) {
|
|
179
|
-
const arg = args[i];
|
|
180
|
-
if (typeof arg !== "string")
|
|
181
|
-
throw new Error("all supplied arguments must be Strings");
|
|
182
|
-
if (options.trimWhitespace) {
|
|
183
|
-
args[i] = arg.trim();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
tag = args.join(options.joinString);
|
|
187
|
-
tag = tag.replace(/\s/g, options.joinString);
|
|
188
|
-
if (options.lowercaseOnly)
|
|
189
|
-
tag = tag.toLowerCase();
|
|
190
|
-
tag = tag.replace(options.regexRemovePattern, (match) => {
|
|
191
|
-
if (match === options.joinString)
|
|
192
|
-
return match;
|
|
193
|
-
return "";
|
|
194
|
-
});
|
|
195
|
-
if (tag.length > options.maxLen)
|
|
196
|
-
tag = tag.substring(0, options.maxLen);
|
|
197
|
-
tag = tag.replace(reJoinString, options.joinString);
|
|
198
|
-
return tag;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
var urlSafeString = buildUrlSafeString().generate;
|
|
203
|
-
function makeUrlSafe(name) {
|
|
204
|
-
return urlSafeString(name.replace(/\//g, "-")).replace(/^-*/g, "").replace(/-*$/g, "");
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// src/config/overrides/config.ts
|
|
208
|
-
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
209
|
-
var _Overrides = class {
|
|
210
|
-
constructor(config) {
|
|
211
|
-
this.config = config;
|
|
212
|
-
}
|
|
213
|
-
static getAppEnvOverrideCookieName(zone) {
|
|
214
|
-
return `${_Overrides.overrideEnvCookiePrefix}${zone}`;
|
|
215
|
-
}
|
|
216
|
-
static isOverrideCookie(cookie) {
|
|
217
|
-
var _a;
|
|
218
|
-
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
219
|
-
}
|
|
220
|
-
static getOverrideFromCookie(cookie) {
|
|
221
|
-
if (!_Overrides.isOverrideCookie(cookie) || !cookie.value)
|
|
222
|
-
return;
|
|
223
|
-
return {
|
|
224
|
-
zone: cookie.name.replace(_Overrides.overrideEnvCookiePrefix, ""),
|
|
225
|
-
host: cookie.value
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
static parseOverrides(cookies) {
|
|
229
|
-
const overridesConfig = { applications: {} };
|
|
230
|
-
cookies.forEach((cookie) => {
|
|
231
|
-
const override = _Overrides.getOverrideFromCookie(cookie);
|
|
232
|
-
if (!override)
|
|
233
|
-
return;
|
|
234
|
-
overridesConfig.applications[override.zone] = {
|
|
235
|
-
environment: { host: override.host }
|
|
236
|
-
};
|
|
237
|
-
});
|
|
238
|
-
return overridesConfig;
|
|
239
|
-
}
|
|
240
|
-
static validOverrideDomainsForZone(microfrontendConfig, zone) {
|
|
241
|
-
var _a, _b, _c, _d, _e;
|
|
242
|
-
const projectName = (_a = microfrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
243
|
-
if (!projectName) {
|
|
244
|
-
return [microfrontendConfig.getZone(zone).production.host];
|
|
245
|
-
}
|
|
246
|
-
const parsedProjectName = makeUrlSafe(projectName);
|
|
247
|
-
const previewDeploymentSuffix = (_c = (_b = microfrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
|
|
248
|
-
const teamSlug = (_e = (_d = microfrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
|
|
249
|
-
if (!teamSlug && !previewDeploymentSuffix) {
|
|
250
|
-
return [microfrontendConfig.getZone(zone).production.host];
|
|
251
|
-
}
|
|
252
|
-
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
253
|
-
return [
|
|
254
|
-
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
255
|
-
microfrontendConfig.getZone(zone).production.host
|
|
256
|
-
];
|
|
257
|
-
}
|
|
258
|
-
static validateOverrideDomain(microfrontendConfig, zone, domain) {
|
|
259
|
-
return new RegExp(
|
|
260
|
-
`^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
|
|
261
|
-
"|"
|
|
262
|
-
)}$`
|
|
263
|
-
).test(domain);
|
|
264
|
-
}
|
|
265
|
-
serialize() {
|
|
266
|
-
return this.config;
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
var Overrides = _Overrides;
|
|
270
|
-
Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
271
|
-
|
|
272
|
-
// src/config/common/host.ts
|
|
273
|
-
var Host = class {
|
|
274
|
-
constructor({ protocol, host, port }) {
|
|
275
|
-
this.protocol = protocol || "https";
|
|
276
|
-
this.host = host;
|
|
277
|
-
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
278
|
-
this.serialized = {
|
|
279
|
-
protocol,
|
|
280
|
-
host,
|
|
281
|
-
...port ? { port } : void 0
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
isLocal() {
|
|
285
|
-
return this.host === "localhost" || this.host === "127.0.0.1";
|
|
286
|
-
}
|
|
287
|
-
static getPort({
|
|
288
|
-
protocol,
|
|
289
|
-
port
|
|
290
|
-
}) {
|
|
291
|
-
if (!port) {
|
|
292
|
-
if (protocol === "http") {
|
|
293
|
-
return 80;
|
|
294
|
-
}
|
|
295
|
-
return 443;
|
|
296
|
-
}
|
|
297
|
-
return port;
|
|
298
|
-
}
|
|
299
|
-
isDefaultPort() {
|
|
300
|
-
return this.port === Host.getPort({ protocol: this.protocol });
|
|
301
|
-
}
|
|
302
|
-
toString(opts = {}) {
|
|
303
|
-
const url = this.toUrl(opts);
|
|
304
|
-
return url.toString().replace(/\/$/, "");
|
|
305
|
-
}
|
|
306
|
-
toUrl(opts = {}) {
|
|
307
|
-
const { includeDefaultPort } = opts;
|
|
308
|
-
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
309
|
-
return new URL(url);
|
|
310
|
-
}
|
|
311
|
-
serialize() {
|
|
312
|
-
return this.serialized;
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// src/config/common/application.ts
|
|
317
|
-
var Application = class {
|
|
318
|
-
constructor(name, {
|
|
319
|
-
app,
|
|
320
|
-
overrides
|
|
321
|
-
}) {
|
|
322
|
-
Application.validate(name, app);
|
|
323
|
-
this.name = name;
|
|
324
|
-
this.default = app.default;
|
|
325
|
-
this.routing = app.routing;
|
|
326
|
-
this.development = {
|
|
327
|
-
local: new Host(app.development.local),
|
|
328
|
-
fallback: app.development.fallback ? new Host(app.development.fallback) : void 0
|
|
329
|
-
};
|
|
330
|
-
this.production = new Host(app.production);
|
|
331
|
-
this.vercel = app.vercel;
|
|
332
|
-
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
333
|
-
environment: new Host(overrides.environment)
|
|
334
|
-
} : void 0;
|
|
335
|
-
}
|
|
336
|
-
isDefault() {
|
|
337
|
-
return this.default;
|
|
338
|
-
}
|
|
339
|
-
static validate(name, app) {
|
|
340
|
-
var _a, _b, _c, _d, _e;
|
|
341
|
-
if (((_b = (_a = app.routing) == null ? void 0 : _a.assetPrefix) == null ? void 0 : _b.startsWith("/")) || ((_d = (_c = app.routing) == null ? void 0 : _c.assetPrefix) == null ? void 0 : _d.endsWith("/"))) {
|
|
342
|
-
throw new MicrofrontendError(
|
|
343
|
-
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
344
|
-
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
for (const group of ((_e = app.routing) == null ? void 0 : _e.matches) ?? []) {
|
|
348
|
-
for (const p of group.paths) {
|
|
349
|
-
if (p === "/") {
|
|
350
|
-
continue;
|
|
351
|
-
}
|
|
352
|
-
if (p.endsWith("/")) {
|
|
353
|
-
throw new MicrofrontendError(
|
|
354
|
-
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
355
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
if (!p.startsWith("/")) {
|
|
359
|
-
throw new MicrofrontendError(
|
|
360
|
-
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
361
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
serialize() {
|
|
368
|
-
var _a, _b;
|
|
369
|
-
if (this.routing === void 0 || this.default) {
|
|
370
|
-
return {
|
|
371
|
-
default: true,
|
|
372
|
-
development: {
|
|
373
|
-
local: this.development.local.serialize(),
|
|
374
|
-
fallback: (_a = this.development.fallback) == null ? void 0 : _a.serialize()
|
|
375
|
-
},
|
|
376
|
-
production: this.production.serialize(),
|
|
377
|
-
vercel: this.vercel
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
default: false,
|
|
382
|
-
routing: this.routing,
|
|
383
|
-
development: {
|
|
384
|
-
local: this.development.local.serialize(),
|
|
385
|
-
fallback: (_b = this.development.fallback) == null ? void 0 : _b.serialize()
|
|
386
|
-
},
|
|
387
|
-
production: this.production.serialize(),
|
|
388
|
-
vercel: this.vercel
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
// src/config/common/microfrontend-config.ts
|
|
394
|
-
var SUPPORTED_VERSIONS = ["1"];
|
|
395
|
-
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
396
|
-
var MicrofrontendConfigCommon = class {
|
|
397
|
-
constructor({
|
|
398
|
-
config,
|
|
399
|
-
overrides
|
|
400
|
-
}) {
|
|
401
|
-
this.zones = {};
|
|
402
|
-
var _a, _b, _c;
|
|
403
|
-
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
404
|
-
throw new MicrofrontendError(
|
|
405
|
-
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
406
|
-
", "
|
|
407
|
-
)}`,
|
|
408
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
412
|
-
this.overrides = overrides && !disableOverrides ? new Overrides(overrides) : void 0;
|
|
413
|
-
for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {
|
|
414
|
-
this.zones[zoneName] = new Application(zoneName, {
|
|
415
|
-
app: zoneConfig,
|
|
416
|
-
overrides: !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.config.applications[zoneName] : void 0
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
this.config = config;
|
|
420
|
-
this.name = config.name;
|
|
421
|
-
this.version = config.version;
|
|
422
|
-
this.options = config.options;
|
|
423
|
-
this.$schema = config.$schema;
|
|
424
|
-
}
|
|
425
|
-
isOverridesDisabled() {
|
|
426
|
-
var _a, _b;
|
|
427
|
-
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
428
|
-
}
|
|
429
|
-
static getConfigFromEnv() {
|
|
430
|
-
const config = process.env.MFE_CONFIG;
|
|
431
|
-
if (!config) {
|
|
432
|
-
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
433
|
-
type: "config",
|
|
434
|
-
subtype: "not_found_in_env"
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
return config;
|
|
438
|
-
}
|
|
439
|
-
static fromEnv(_) {
|
|
440
|
-
throw new Error("Not implemented");
|
|
441
|
-
}
|
|
442
|
-
getConfig() {
|
|
443
|
-
return this.config;
|
|
444
|
-
}
|
|
445
|
-
getAllApplications() {
|
|
446
|
-
return Object.values(this.zones);
|
|
447
|
-
}
|
|
448
|
-
getZone(name) {
|
|
449
|
-
const zone = this.zones[name];
|
|
450
|
-
if (!zone) {
|
|
451
|
-
throw new MicrofrontendError(
|
|
452
|
-
`Could not find microfrontends configuration for application "${name}"`,
|
|
453
|
-
{
|
|
454
|
-
type: "zone",
|
|
455
|
-
subtype: "not_found"
|
|
456
|
-
}
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
return zone;
|
|
460
|
-
}
|
|
461
|
-
getApplicationByProjectId(projectId) {
|
|
462
|
-
return Object.values(this.zones).find(
|
|
463
|
-
(zone) => {
|
|
464
|
-
var _a;
|
|
465
|
-
return ((_a = zone.vercel) == null ? void 0 : _a.projectId) === projectId;
|
|
466
|
-
}
|
|
467
|
-
);
|
|
468
|
-
}
|
|
469
|
-
getDefaultZone() {
|
|
470
|
-
const zone = Object.values(this.zones).find((z) => z.default);
|
|
471
|
-
if (!zone) {
|
|
472
|
-
throw new MicrofrontendError(
|
|
473
|
-
`Could not find default zone in microfrontends configuration`,
|
|
474
|
-
{
|
|
475
|
-
type: "zone",
|
|
476
|
-
subtype: "not_found"
|
|
477
|
-
}
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
return zone;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Returns the configured port for the local proxy
|
|
484
|
-
*/
|
|
485
|
-
getLocalProxyPort() {
|
|
486
|
-
var _a, _b;
|
|
487
|
-
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Serializes the class back to the Schema type.
|
|
491
|
-
*
|
|
492
|
-
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
493
|
-
*/
|
|
494
|
-
toSchemaJson() {
|
|
495
|
-
const applications = {};
|
|
496
|
-
for (const [name, zone] of Object.entries(this.zones)) {
|
|
497
|
-
applications[name] = zone.serialize();
|
|
498
|
-
}
|
|
499
|
-
return {
|
|
500
|
-
$schema: this.$schema,
|
|
501
|
-
name: this.name,
|
|
502
|
-
version: this.version,
|
|
503
|
-
options: this.options,
|
|
504
|
-
applications
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
serialize() {
|
|
508
|
-
var _a;
|
|
509
|
-
const applications = {};
|
|
510
|
-
for (const [name, zone] of Object.entries(this.zones)) {
|
|
511
|
-
applications[name] = zone.serialize();
|
|
512
|
-
}
|
|
513
|
-
return {
|
|
514
|
-
config: {
|
|
515
|
-
name: this.name,
|
|
516
|
-
version: this.version,
|
|
517
|
-
applications,
|
|
518
|
-
options: this.options,
|
|
519
|
-
$schema: this.$schema
|
|
520
|
-
},
|
|
521
|
-
overrides: (_a = this.overrides) == null ? void 0 : _a.serialize()
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
write(_) {
|
|
525
|
-
throw new MicrofrontendError(
|
|
526
|
-
`Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
|
|
527
|
-
{ type: "config", subtype: "unsupported_operation" }
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
// src/config/utils/get-output-file-path.ts
|
|
533
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
534
|
-
|
|
535
|
-
// src/config/constants.ts
|
|
536
|
-
var MFE_CONFIG_DEFAULT_FILE_PATH2 = "micro-frontends";
|
|
537
|
-
var MFE_CONFIG_DEFAULT_FILE_NAME2 = "micro-frontends.config.json";
|
|
538
|
-
|
|
539
|
-
// src/config/utils/get-output-file-path.ts
|
|
540
|
-
function getOutputFilePath2() {
|
|
541
|
-
if (isVercel()) {
|
|
542
|
-
return import_node_path2.default.join(
|
|
543
|
-
".vercel",
|
|
544
|
-
MFE_CONFIG_DEFAULT_FILE_PATH2,
|
|
545
|
-
MFE_CONFIG_DEFAULT_FILE_NAME2
|
|
546
|
-
);
|
|
547
|
-
}
|
|
548
|
-
return import_node_path2.default.join(MFE_CONFIG_DEFAULT_FILE_PATH2, MFE_CONFIG_DEFAULT_FILE_NAME2);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// src/config/validation.ts
|
|
552
|
-
var import_jsonc_parser = require("jsonc-parser");
|
|
553
|
-
var import_path_to_regexp = require("path-to-regexp");
|
|
554
|
-
var import_ajv = require("ajv");
|
|
555
|
-
|
|
556
|
-
// schema/schema.json
|
|
557
|
-
var schema_default = {
|
|
558
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
559
|
-
$ref: "#/definitions/Config",
|
|
560
|
-
definitions: {
|
|
561
|
-
Config: {
|
|
562
|
-
type: "object",
|
|
563
|
-
properties: {
|
|
564
|
-
version: {
|
|
565
|
-
type: "string"
|
|
566
|
-
},
|
|
567
|
-
$schema: {
|
|
568
|
-
type: "string"
|
|
569
|
-
},
|
|
570
|
-
name: {
|
|
571
|
-
type: "string",
|
|
572
|
-
description: 'Name for the micro-frontend site (eg. "vercel.com", "vercel-site" etc.).'
|
|
573
|
-
},
|
|
574
|
-
applications: {
|
|
575
|
-
$ref: "#/definitions/ApplicationConfigsById"
|
|
576
|
-
},
|
|
577
|
-
options: {
|
|
578
|
-
$ref: "#/definitions/Options",
|
|
579
|
-
description: "Optional configuration for the entire micro-frontends setup."
|
|
580
|
-
}
|
|
581
|
-
},
|
|
582
|
-
required: ["version", "applications"],
|
|
583
|
-
description: "Configuration for micro-frontend applications\n\nTODO: Add proxy configuration"
|
|
584
|
-
},
|
|
585
|
-
ApplicationConfigsById: {
|
|
586
|
-
type: "object",
|
|
587
|
-
additionalProperties: {
|
|
588
|
-
$ref: "#/definitions/ApplicationConfig"
|
|
589
|
-
}
|
|
590
|
-
},
|
|
591
|
-
ApplicationConfig: {
|
|
592
|
-
anyOf: [
|
|
593
|
-
{
|
|
594
|
-
$ref: "#/definitions/DefaultApplicationConfig"
|
|
595
|
-
},
|
|
596
|
-
{
|
|
597
|
-
$ref: "#/definitions/CommonApplicationConfig"
|
|
598
|
-
}
|
|
599
|
-
],
|
|
600
|
-
description: "A Micro-Frontend Deployment Target"
|
|
601
|
-
},
|
|
602
|
-
DefaultApplicationConfig: {
|
|
603
|
-
type: "object",
|
|
604
|
-
properties: {
|
|
605
|
-
default: {
|
|
606
|
-
type: "boolean",
|
|
607
|
-
const: true,
|
|
608
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
609
|
-
},
|
|
610
|
-
routing: {
|
|
611
|
-
$ref: "#/definitions/Routing"
|
|
612
|
-
},
|
|
613
|
-
development: {
|
|
614
|
-
type: "object",
|
|
615
|
-
properties: {
|
|
616
|
-
local: {
|
|
617
|
-
$ref: "#/definitions/HostConfig"
|
|
618
|
-
},
|
|
619
|
-
fallback: {
|
|
620
|
-
$ref: "#/definitions/HostConfig",
|
|
621
|
-
description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error."
|
|
622
|
-
},
|
|
623
|
-
task: {
|
|
624
|
-
type: "string",
|
|
625
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
626
|
-
}
|
|
627
|
-
},
|
|
628
|
-
required: ["local"]
|
|
629
|
-
},
|
|
630
|
-
production: {
|
|
631
|
-
$ref: "#/definitions/HostConfig"
|
|
632
|
-
},
|
|
633
|
-
metadata: {
|
|
634
|
-
type: "object",
|
|
635
|
-
additionalProperties: {
|
|
636
|
-
type: "string"
|
|
637
|
-
}
|
|
638
|
-
},
|
|
639
|
-
federation: {
|
|
640
|
-
type: "object",
|
|
641
|
-
properties: {
|
|
642
|
-
exposes: {
|
|
643
|
-
type: "array",
|
|
644
|
-
items: {
|
|
645
|
-
type: "object",
|
|
646
|
-
properties: {
|
|
647
|
-
name: {
|
|
648
|
-
type: "string",
|
|
649
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
650
|
-
},
|
|
651
|
-
path: {
|
|
652
|
-
type: "string",
|
|
653
|
-
description: "Relative path to the module within its `application`"
|
|
654
|
-
}
|
|
655
|
-
},
|
|
656
|
-
required: ["name", "path"]
|
|
657
|
-
},
|
|
658
|
-
description: "Modules that are exposed by this application"
|
|
659
|
-
},
|
|
660
|
-
uses: {
|
|
661
|
-
type: "array",
|
|
662
|
-
items: {
|
|
663
|
-
type: "string"
|
|
664
|
-
},
|
|
665
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
},
|
|
669
|
-
vercel: {
|
|
670
|
-
$ref: "#/definitions/Vercel"
|
|
671
|
-
}
|
|
672
|
-
},
|
|
673
|
-
required: ["default", "development", "production"]
|
|
674
|
-
},
|
|
675
|
-
Routing: {
|
|
676
|
-
type: "object",
|
|
677
|
-
properties: {
|
|
678
|
-
assetPrefix: {
|
|
679
|
-
type: "string",
|
|
680
|
-
description: "[assetPrefix] for the application"
|
|
681
|
-
},
|
|
682
|
-
matches: {
|
|
683
|
-
type: "array",
|
|
684
|
-
items: {
|
|
685
|
-
$ref: "#/definitions/PathGroup"
|
|
686
|
-
},
|
|
687
|
-
description: "Path expressions that are routed to this application."
|
|
688
|
-
}
|
|
689
|
-
},
|
|
690
|
-
required: ["matches"]
|
|
691
|
-
},
|
|
692
|
-
PathGroup: {
|
|
693
|
-
type: "object",
|
|
694
|
-
properties: {
|
|
695
|
-
group: {
|
|
696
|
-
type: "string",
|
|
697
|
-
description: "Optional group name for the paths"
|
|
698
|
-
},
|
|
699
|
-
options: {
|
|
700
|
-
type: "object",
|
|
701
|
-
properties: {
|
|
702
|
-
flag: {
|
|
703
|
-
type: "string",
|
|
704
|
-
description: "flag name that can be used to enable/disable all paths in the group"
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
},
|
|
708
|
-
paths: {
|
|
709
|
-
type: "array",
|
|
710
|
-
items: {
|
|
711
|
-
type: "string"
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
},
|
|
715
|
-
required: ["paths"]
|
|
716
|
-
},
|
|
717
|
-
HostConfig: {
|
|
718
|
-
type: "object",
|
|
719
|
-
properties: {
|
|
720
|
-
protocol: {
|
|
721
|
-
type: "string",
|
|
722
|
-
enum: ["http", "https"],
|
|
723
|
-
description: 'The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n* @defaultValue "https"'
|
|
724
|
-
},
|
|
725
|
-
host: {
|
|
726
|
-
type: "string",
|
|
727
|
-
description: "The hostname or IP address of the server. This can be a domain name (e.g., `example.com`) or an IP address (e.g., `192.168.1.1`)."
|
|
728
|
-
},
|
|
729
|
-
port: {
|
|
730
|
-
type: "number",
|
|
731
|
-
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS.\n\nThis field is optional and can be omitted if the default ports for the specified protocol are used"
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
required: ["host"]
|
|
735
|
-
},
|
|
736
|
-
Vercel: {
|
|
737
|
-
type: "object",
|
|
738
|
-
properties: {
|
|
739
|
-
projectId: {
|
|
740
|
-
type: "string",
|
|
741
|
-
description: "Vercel project ID"
|
|
742
|
-
},
|
|
743
|
-
projectName: {
|
|
744
|
-
type: "string",
|
|
745
|
-
description: "Vercel project name (temporary until we can use project ID)"
|
|
746
|
-
},
|
|
747
|
-
defaultRoute: {
|
|
748
|
-
type: "string",
|
|
749
|
-
description: "The default route for the application. Used to render screenshots, favicons, and provide direct zone links"
|
|
750
|
-
},
|
|
751
|
-
routeSpeedInsightsToDefaultZone: {
|
|
752
|
-
type: "boolean",
|
|
753
|
-
description: "Whether to route Speed Insights to the default zone or each individual microfrontend."
|
|
754
|
-
}
|
|
755
|
-
},
|
|
756
|
-
required: ["projectId"]
|
|
757
|
-
},
|
|
758
|
-
CommonApplicationConfig: {
|
|
759
|
-
type: "object",
|
|
760
|
-
properties: {
|
|
761
|
-
default: {
|
|
762
|
-
type: "boolean",
|
|
763
|
-
const: false,
|
|
764
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
765
|
-
},
|
|
766
|
-
routing: {
|
|
767
|
-
$ref: "#/definitions/Routing"
|
|
768
|
-
},
|
|
769
|
-
development: {
|
|
770
|
-
type: "object",
|
|
771
|
-
properties: {
|
|
772
|
-
local: {
|
|
773
|
-
$ref: "#/definitions/HostConfig"
|
|
774
|
-
},
|
|
775
|
-
fallback: {
|
|
776
|
-
$ref: "#/definitions/HostConfig",
|
|
777
|
-
description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error."
|
|
778
|
-
},
|
|
779
|
-
task: {
|
|
780
|
-
type: "string",
|
|
781
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
782
|
-
}
|
|
783
|
-
},
|
|
784
|
-
required: ["local"]
|
|
785
|
-
},
|
|
786
|
-
production: {
|
|
787
|
-
$ref: "#/definitions/HostConfig"
|
|
788
|
-
},
|
|
789
|
-
metadata: {
|
|
790
|
-
type: "object",
|
|
791
|
-
additionalProperties: {
|
|
792
|
-
type: "string"
|
|
793
|
-
}
|
|
794
|
-
},
|
|
795
|
-
federation: {
|
|
796
|
-
type: "object",
|
|
797
|
-
properties: {
|
|
798
|
-
exposes: {
|
|
799
|
-
type: "array",
|
|
800
|
-
items: {
|
|
801
|
-
type: "object",
|
|
802
|
-
properties: {
|
|
803
|
-
name: {
|
|
804
|
-
type: "string",
|
|
805
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
806
|
-
},
|
|
807
|
-
path: {
|
|
808
|
-
type: "string",
|
|
809
|
-
description: "Relative path to the module within its `application`"
|
|
810
|
-
}
|
|
811
|
-
},
|
|
812
|
-
required: ["name", "path"]
|
|
813
|
-
},
|
|
814
|
-
description: "Modules that are exposed by this application"
|
|
815
|
-
},
|
|
816
|
-
uses: {
|
|
817
|
-
type: "array",
|
|
818
|
-
items: {
|
|
819
|
-
type: "string"
|
|
820
|
-
},
|
|
821
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
},
|
|
825
|
-
vercel: {
|
|
826
|
-
$ref: "#/definitions/Vercel"
|
|
827
|
-
}
|
|
828
|
-
},
|
|
829
|
-
required: ["default", "development", "production", "routing"]
|
|
830
|
-
},
|
|
831
|
-
Options: {
|
|
832
|
-
type: "object",
|
|
833
|
-
properties: {
|
|
834
|
-
vercel: {
|
|
835
|
-
$ref: "#/definitions/VercelOptions",
|
|
836
|
-
description: "Micro-Frontends wide options for Vercel."
|
|
837
|
-
},
|
|
838
|
-
localProxy: {
|
|
839
|
-
$ref: "#/definitions/LocalProxyOptions",
|
|
840
|
-
description: "Options for local proxy."
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
},
|
|
844
|
-
VercelOptions: {
|
|
845
|
-
type: "object",
|
|
846
|
-
properties: {
|
|
847
|
-
previewDeploymentSuffix: {
|
|
848
|
-
type: "string",
|
|
849
|
-
description: "If your team uses a custom Preview Deployment Suffix, please specify it here. See https://vercel.com/docs/deployments/preview-deployment-suffix. The default is `vercel.app`."
|
|
850
|
-
},
|
|
851
|
-
teamSlug: {
|
|
852
|
-
type: "string",
|
|
853
|
-
description: "Team slug for the Vercel team"
|
|
854
|
-
},
|
|
855
|
-
disableOverrides: {
|
|
856
|
-
type: "boolean",
|
|
857
|
-
description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
},
|
|
861
|
-
LocalProxyOptions: {
|
|
862
|
-
type: "object",
|
|
863
|
-
properties: {
|
|
864
|
-
port: {
|
|
865
|
-
type: "number",
|
|
866
|
-
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
|
|
873
|
-
// src/config/utils/load-schema.ts
|
|
874
|
-
var SCHEMA = schema_default;
|
|
875
|
-
|
|
876
|
-
// src/config/validation.ts
|
|
877
|
-
var validateSchema = (configString) => {
|
|
878
|
-
const parsedConfig = (0, import_jsonc_parser.parse)(configString);
|
|
879
|
-
const ajv = new import_ajv.Ajv();
|
|
880
|
-
const validate = ajv.compile(SCHEMA);
|
|
881
|
-
const isValid = validate(parsedConfig);
|
|
882
|
-
if (!isValid) {
|
|
883
|
-
throw new MicrofrontendError(
|
|
884
|
-
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
885
|
-
{ type: "config", subtype: "does_not_match_schema" }
|
|
886
|
-
);
|
|
887
|
-
}
|
|
888
|
-
return parsedConfig;
|
|
889
|
-
};
|
|
890
|
-
var SUPPORTED_VERSIONS2 = ["1"];
|
|
891
|
-
var validateVersion = (version) => {
|
|
892
|
-
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
893
|
-
throw new MicrofrontendError(
|
|
894
|
-
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
895
|
-
", "
|
|
896
|
-
)}`,
|
|
897
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
898
|
-
);
|
|
899
|
-
}
|
|
900
|
-
};
|
|
901
|
-
function validateMainPath(applicationConfigsById) {
|
|
902
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
903
|
-
const { defaultRoute } = app.vercel ?? {};
|
|
904
|
-
if (!defaultRoute) {
|
|
905
|
-
continue;
|
|
906
|
-
}
|
|
907
|
-
if (isDefaultApplicationConfig(app)) {
|
|
908
|
-
const pathsWithApp = [];
|
|
909
|
-
for (const [otherId, otherApp] of Object.entries(
|
|
910
|
-
applicationConfigsById
|
|
911
|
-
)) {
|
|
912
|
-
if (isDefaultApplicationConfig(otherApp)) {
|
|
913
|
-
continue;
|
|
914
|
-
}
|
|
915
|
-
pathsWithApp.push({
|
|
916
|
-
id: otherId,
|
|
917
|
-
paths: otherApp.routing.matches.flatMap((match) => match.paths)
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
for (const { id: otherId, paths } of pathsWithApp) {
|
|
921
|
-
const isValid = paths.every((path7) => {
|
|
922
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(path7);
|
|
923
|
-
return !matcher.test(defaultRoute);
|
|
924
|
-
});
|
|
925
|
-
if (!isValid) {
|
|
926
|
-
throw new MicrofrontendError(
|
|
927
|
-
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
928
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
929
|
-
);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
} else {
|
|
933
|
-
const allPaths = app.routing.matches.flatMap((match) => match.paths);
|
|
934
|
-
const isValid = allPaths.some((path7) => {
|
|
935
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(path7);
|
|
936
|
-
return matcher.test(defaultRoute);
|
|
937
|
-
});
|
|
938
|
-
if (!isValid) {
|
|
939
|
-
throw new MicrofrontendError(
|
|
940
|
-
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
941
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
942
|
-
);
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
var validatePaths = (applicationConfigsById) => {
|
|
948
|
-
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
949
|
-
const errors = [];
|
|
950
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
951
|
-
if (isDefaultApplicationConfig(app)) {
|
|
952
|
-
continue;
|
|
953
|
-
}
|
|
954
|
-
for (const pathMatch of app.routing.matches) {
|
|
955
|
-
for (const path7 of pathMatch.paths) {
|
|
956
|
-
const maybeError = validatePathExpression(path7);
|
|
957
|
-
if (maybeError) {
|
|
958
|
-
errors.push(maybeError);
|
|
959
|
-
}
|
|
960
|
-
const existing = pathsByApplicationId.get(path7);
|
|
961
|
-
if (existing) {
|
|
962
|
-
existing.applications.push(id);
|
|
963
|
-
} else {
|
|
964
|
-
pathsByApplicationId.set(path7, {
|
|
965
|
-
applications: [id],
|
|
966
|
-
matcher: (0, import_path_to_regexp.pathToRegexp)(path7),
|
|
967
|
-
applicationId: id
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
const entries = Array.from(pathsByApplicationId.entries());
|
|
974
|
-
entries.forEach(([path7, { applications: ids, matcher, applicationId }]) => {
|
|
975
|
-
if (ids.length > 1) {
|
|
976
|
-
errors.push(
|
|
977
|
-
`Duplicate path "${path7}" for applications "${ids.join(", ")}"`
|
|
978
|
-
);
|
|
979
|
-
}
|
|
980
|
-
entries.forEach(
|
|
981
|
-
([
|
|
982
|
-
matchPath,
|
|
983
|
-
{ applications: matchIds, applicationId: matchApplicationId }
|
|
984
|
-
]) => {
|
|
985
|
-
if (path7 === matchPath) {
|
|
986
|
-
return;
|
|
987
|
-
}
|
|
988
|
-
if (applicationId === matchApplicationId) {
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
if (matcher.test(matchPath)) {
|
|
992
|
-
const source = `"${path7}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
993
|
-
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
994
|
-
errors.push(
|
|
995
|
-
`Overlapping path detected between ${source} and ${destination}`
|
|
996
|
-
);
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
);
|
|
1000
|
-
});
|
|
1001
|
-
if (errors.length) {
|
|
1002
|
-
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1003
|
-
type: "config",
|
|
1004
|
-
subtype: "conflicting_paths"
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
};
|
|
1008
|
-
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
1009
|
-
function validatePathExpression(path7) {
|
|
1010
|
-
const tokens = (0, import_path_to_regexp.parse)(path7);
|
|
1011
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
1012
|
-
const token = tokens[i];
|
|
1013
|
-
if (token === void 0) {
|
|
1014
|
-
return `token ${i} in ${path7} is undefined, this shouldn't happen`;
|
|
1015
|
-
}
|
|
1016
|
-
if (typeof token !== "string") {
|
|
1017
|
-
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
1018
|
-
return `Path ${path7} cannot use a regular expression wildcard`;
|
|
1019
|
-
}
|
|
1020
|
-
if (token.prefix !== "/") {
|
|
1021
|
-
return `Wildcard :${token.name} must be immediately after a / in ${path7}`;
|
|
1022
|
-
}
|
|
1023
|
-
if (token.suffix) {
|
|
1024
|
-
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
1025
|
-
}
|
|
1026
|
-
if (token.modifier && i !== tokens.length - 1) {
|
|
1027
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path7}. Modifiers are only allowed in the last path component`;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
return void 0;
|
|
1032
|
-
}
|
|
1033
|
-
var validateDefaults = (applicationConfigsById) => {
|
|
1034
|
-
const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
|
|
1035
|
-
if (defaultApplicationIds.length === 0) {
|
|
1036
|
-
throw new MicrofrontendError(
|
|
1037
|
-
`No default application found. At least one application must be marked as default.`,
|
|
1038
|
-
{ type: "config", subtype: "no_default_application" }
|
|
1039
|
-
);
|
|
1040
|
-
}
|
|
1041
|
-
if (defaultApplicationIds.length > 1) {
|
|
1042
|
-
throw new MicrofrontendError(
|
|
1043
|
-
`Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
|
|
1044
|
-
{ type: "config", subtype: "multiple_default_applications" }
|
|
1045
|
-
);
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
var validateOptions = (options) => {
|
|
1049
|
-
var _a;
|
|
1050
|
-
if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
|
|
1051
|
-
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1052
|
-
options.vercel.previewDeploymentSuffix
|
|
1053
|
-
)) {
|
|
1054
|
-
throw new MicrofrontendError(
|
|
1055
|
-
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1056
|
-
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1057
|
-
);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
// src/config/utils/convert.ts
|
|
1063
|
-
function convertV1RoutingToV2Routing(routing) {
|
|
1064
|
-
return routing.matches.map((group) => {
|
|
1065
|
-
var _a;
|
|
1066
|
-
return {
|
|
1067
|
-
group: group.group,
|
|
1068
|
-
flag: (_a = group.options) == null ? void 0 : _a.flag,
|
|
1069
|
-
paths: group.paths
|
|
1070
|
-
};
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
function convertV1ApplicationToV2Application(application) {
|
|
1074
|
-
const common = {
|
|
1075
|
-
production: application.production,
|
|
1076
|
-
development: application.development,
|
|
1077
|
-
vercel: application.vercel
|
|
1078
|
-
};
|
|
1079
|
-
if (application.default) {
|
|
1080
|
-
return common;
|
|
1081
|
-
}
|
|
1082
|
-
return {
|
|
1083
|
-
...common,
|
|
1084
|
-
routing: convertV1RoutingToV2Routing(application.routing)
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
function convertV1ConfigToV2Config(config, fromApp) {
|
|
1088
|
-
if (!config.applications[fromApp]) {
|
|
1089
|
-
throw new Error(`Application "${fromApp}" not found in the config`);
|
|
1090
|
-
}
|
|
1091
|
-
const common = {
|
|
1092
|
-
version: "2",
|
|
1093
|
-
options: config.options
|
|
1094
|
-
};
|
|
1095
|
-
if (config.applications[fromApp].default) {
|
|
1096
|
-
return {
|
|
1097
|
-
...common,
|
|
1098
|
-
applications: Object.fromEntries(
|
|
1099
|
-
Object.entries(config.applications).map(([id, application]) => [
|
|
1100
|
-
id,
|
|
1101
|
-
convertV1ApplicationToV2Application(application)
|
|
1102
|
-
])
|
|
1103
|
-
)
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
const defaultApplication = Object.entries(config.applications).find(
|
|
1107
|
-
([, application]) => application.default
|
|
1108
|
-
);
|
|
1109
|
-
if (!defaultApplication) {
|
|
1110
|
-
throw new Error("No default application found in the config");
|
|
1111
|
-
}
|
|
1112
|
-
return {
|
|
1113
|
-
...common,
|
|
1114
|
-
partOf: defaultApplication[0]
|
|
1115
|
-
};
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
// src/config/utils/write-file.ts
|
|
1119
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
1120
|
-
var import_node_path3 = require("path");
|
|
1121
|
-
function writeFile(outputPath, config, prettify) {
|
|
1122
|
-
import_node_fs.default.mkdirSync((0, import_node_path3.dirname)(outputPath), { recursive: true });
|
|
1123
|
-
import_node_fs.default.writeFileSync(
|
|
1124
|
-
outputPath,
|
|
1125
|
-
JSON.stringify(config, null, prettify ? 2 : void 0)
|
|
1126
|
-
);
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
// src/config/microfrontend-config.ts
|
|
1130
|
-
var MicrofrontendConfig = class extends MicrofrontendConfigCommon {
|
|
1131
|
-
static validate(configString) {
|
|
1132
|
-
const config = validateSchema(configString);
|
|
1133
|
-
validateVersion(config.version);
|
|
1134
|
-
validatePaths(config.applications);
|
|
1135
|
-
validateMainPath(config.applications);
|
|
1136
|
-
validateDefaults(config.applications);
|
|
1137
|
-
validateOptions(config.options);
|
|
1138
|
-
return config;
|
|
1139
|
-
}
|
|
1140
|
-
static fromEnv({
|
|
1141
|
-
cookies
|
|
1142
|
-
}) {
|
|
1143
|
-
return new MicrofrontendConfigCommon({
|
|
1144
|
-
config: MicrofrontendConfig.validate(
|
|
1145
|
-
MicrofrontendConfigCommon.getConfigFromEnv()
|
|
1146
|
-
),
|
|
1147
|
-
overrides: Overrides.parseOverrides(cookies)
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
static fromFile({
|
|
1151
|
-
filePath
|
|
1152
|
-
}) {
|
|
1153
|
-
try {
|
|
1154
|
-
const config = import_node_fs2.default.readFileSync(filePath, "utf-8");
|
|
1155
|
-
return new MicrofrontendConfig({
|
|
1156
|
-
config: MicrofrontendConfig.validate(config)
|
|
1157
|
-
});
|
|
1158
|
-
} catch (e) {
|
|
1159
|
-
throw MicrofrontendError.handle(e, {
|
|
1160
|
-
fileName: filePath
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Writes the configuration to a file.
|
|
1166
|
-
*/
|
|
1167
|
-
write(fromApp, opts = {}) {
|
|
1168
|
-
const { pretty = true, versions = ["v1", "v2"] } = opts;
|
|
1169
|
-
const config = this.toSchemaJson();
|
|
1170
|
-
if (versions.includes("v1")) {
|
|
1171
|
-
const outputPath = getOutputFilePath2();
|
|
1172
|
-
writeFile(outputPath, config, pretty);
|
|
1173
|
-
}
|
|
1174
|
-
if (versions.includes("v2")) {
|
|
1175
|
-
const outputPath = getOutputFilePath();
|
|
1176
|
-
const v2Config = convertV1ConfigToV2Config(config, fromApp);
|
|
1177
|
-
writeFile(outputPath, v2Config, pretty);
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
};
|
|
1181
|
-
|
|
1182
|
-
// src/config-v2/microfrontends/server/index.ts
|
|
36
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
1183
37
|
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
1184
|
-
var import_node_path9 = require("path");
|
|
1185
38
|
|
|
1186
|
-
// src/config
|
|
1187
|
-
var
|
|
1188
|
-
var
|
|
39
|
+
// src/config/microfrontends/server/index.ts
|
|
40
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
41
|
+
var import_node_path8 = require("path");
|
|
42
|
+
|
|
43
|
+
// src/config/overrides/constants.ts
|
|
44
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
45
|
+
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
1189
46
|
|
|
1190
|
-
// src/config
|
|
47
|
+
// src/config/overrides/is-override-cookie.ts
|
|
1191
48
|
function isOverrideCookie(cookie) {
|
|
1192
49
|
var _a;
|
|
1193
|
-
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(
|
|
50
|
+
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
1194
51
|
}
|
|
1195
52
|
|
|
1196
|
-
// src/config
|
|
53
|
+
// src/config/overrides/get-override-from-cookie.ts
|
|
1197
54
|
function getOverrideFromCookie(cookie) {
|
|
1198
55
|
if (!isOverrideCookie(cookie) || !cookie.value)
|
|
1199
56
|
return;
|
|
@@ -1203,7 +60,7 @@ function getOverrideFromCookie(cookie) {
|
|
|
1203
60
|
};
|
|
1204
61
|
}
|
|
1205
62
|
|
|
1206
|
-
// src/config
|
|
63
|
+
// src/config/overrides/parse-overrides.ts
|
|
1207
64
|
function parseOverrides(cookies) {
|
|
1208
65
|
const overridesConfig = { applications: {} };
|
|
1209
66
|
cookies.forEach((cookie) => {
|
|
@@ -1217,15 +74,15 @@ function parseOverrides(cookies) {
|
|
|
1217
74
|
return overridesConfig;
|
|
1218
75
|
}
|
|
1219
76
|
|
|
1220
|
-
// src/config
|
|
1221
|
-
var
|
|
77
|
+
// src/config/errors.ts
|
|
78
|
+
var MicrofrontendError = class extends Error {
|
|
1222
79
|
constructor(message, opts) {
|
|
1223
80
|
super(message);
|
|
1224
81
|
this.name = "MicrofrontendsError";
|
|
1225
82
|
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
1226
83
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
1227
84
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
1228
|
-
Error.captureStackTrace(this,
|
|
85
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
1229
86
|
}
|
|
1230
87
|
isKnown() {
|
|
1231
88
|
return this.type !== "unknown";
|
|
@@ -1240,7 +97,7 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1240
97
|
*/
|
|
1241
98
|
static convert(original, opts) {
|
|
1242
99
|
if (opts == null ? void 0 : opts.fileName) {
|
|
1243
|
-
const err =
|
|
100
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
1244
101
|
if (err) {
|
|
1245
102
|
return err;
|
|
1246
103
|
}
|
|
@@ -1248,25 +105,25 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1248
105
|
if (original.message.includes(
|
|
1249
106
|
"Code generation from strings disallowed for this context"
|
|
1250
107
|
)) {
|
|
1251
|
-
return new
|
|
108
|
+
return new MicrofrontendError(original.message, {
|
|
1252
109
|
type: "config",
|
|
1253
110
|
subtype: "unsupported_validation_env",
|
|
1254
111
|
source: "ajv"
|
|
1255
112
|
});
|
|
1256
113
|
}
|
|
1257
|
-
return new
|
|
114
|
+
return new MicrofrontendError(original.message);
|
|
1258
115
|
}
|
|
1259
116
|
static convertFSError(original, fileName) {
|
|
1260
117
|
if (original instanceof Error && "code" in original) {
|
|
1261
118
|
if (original.code === "ENOENT") {
|
|
1262
|
-
return new
|
|
119
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
1263
120
|
type: "config",
|
|
1264
121
|
subtype: "unable_to_read_file",
|
|
1265
122
|
source: "fs"
|
|
1266
123
|
});
|
|
1267
124
|
}
|
|
1268
125
|
if (original.code === "EACCES") {
|
|
1269
|
-
return new
|
|
126
|
+
return new MicrofrontendError(
|
|
1270
127
|
`Permission denied while accessing "${fileName}"`,
|
|
1271
128
|
{
|
|
1272
129
|
type: "config",
|
|
@@ -1277,7 +134,7 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1277
134
|
}
|
|
1278
135
|
}
|
|
1279
136
|
if (original instanceof SyntaxError) {
|
|
1280
|
-
return new
|
|
137
|
+
return new MicrofrontendError(
|
|
1281
138
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
1282
139
|
{
|
|
1283
140
|
type: "config",
|
|
@@ -1294,26 +151,26 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1294
151
|
* @returns A MicrofrontendsError instance.
|
|
1295
152
|
*/
|
|
1296
153
|
static handle(err, opts) {
|
|
1297
|
-
if (err instanceof
|
|
154
|
+
if (err instanceof MicrofrontendError) {
|
|
1298
155
|
return err;
|
|
1299
156
|
}
|
|
1300
157
|
if (err instanceof Error) {
|
|
1301
|
-
return
|
|
158
|
+
return MicrofrontendError.convert(err, opts);
|
|
1302
159
|
}
|
|
1303
160
|
if (typeof err === "object" && err !== null) {
|
|
1304
161
|
if ("message" in err && typeof err.message === "string") {
|
|
1305
|
-
return
|
|
162
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
1306
163
|
}
|
|
1307
164
|
}
|
|
1308
|
-
return new
|
|
165
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
1309
166
|
}
|
|
1310
167
|
};
|
|
1311
168
|
|
|
1312
|
-
// src/config
|
|
169
|
+
// src/config/microfrontends-config/utils/get-config-from-env.ts
|
|
1313
170
|
function getConfigStringFromEnv() {
|
|
1314
171
|
const config = process.env.MFE_CONFIG;
|
|
1315
172
|
if (!config) {
|
|
1316
|
-
throw new
|
|
173
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
1317
174
|
type: "config",
|
|
1318
175
|
subtype: "not_found_in_env"
|
|
1319
176
|
});
|
|
@@ -1321,21 +178,21 @@ function getConfigStringFromEnv() {
|
|
|
1321
178
|
return config;
|
|
1322
179
|
}
|
|
1323
180
|
|
|
1324
|
-
// src/config
|
|
1325
|
-
var
|
|
181
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
182
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
1326
183
|
|
|
1327
|
-
// src/config
|
|
184
|
+
// src/config/schema/utils/is-main-config.ts
|
|
1328
185
|
function isMainConfig(c) {
|
|
1329
186
|
return !("partOf" in c);
|
|
1330
187
|
}
|
|
1331
188
|
|
|
1332
|
-
// src/config
|
|
189
|
+
// src/config/schema/utils/is-default-app.ts
|
|
1333
190
|
function isDefaultApp(a) {
|
|
1334
191
|
return !("routing" in a);
|
|
1335
192
|
}
|
|
1336
193
|
|
|
1337
|
-
// src/config
|
|
1338
|
-
var
|
|
194
|
+
// src/config/microfrontends-config/client/index.ts
|
|
195
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
1339
196
|
var MicrofrontendConfigClient = class {
|
|
1340
197
|
constructor(config, opts) {
|
|
1341
198
|
this.pathCache = {};
|
|
@@ -1365,21 +222,21 @@ var MicrofrontendConfigClient = class {
|
|
|
1365
222
|
isEqual(other) {
|
|
1366
223
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
1367
224
|
}
|
|
1368
|
-
getApplicationNameForPath(
|
|
1369
|
-
if (!
|
|
225
|
+
getApplicationNameForPath(path6) {
|
|
226
|
+
if (!path6.startsWith("/")) {
|
|
1370
227
|
throw new Error(`Path must start with a /`);
|
|
1371
228
|
}
|
|
1372
|
-
if (this.pathCache[
|
|
1373
|
-
return this.pathCache[
|
|
229
|
+
if (this.pathCache[path6]) {
|
|
230
|
+
return this.pathCache[path6];
|
|
1374
231
|
}
|
|
1375
|
-
const pathname = new URL(
|
|
232
|
+
const pathname = new URL(path6, "https://example.com").pathname;
|
|
1376
233
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
1377
234
|
if (application.routing) {
|
|
1378
235
|
for (const group of application.routing) {
|
|
1379
236
|
for (const childPath of group.paths) {
|
|
1380
|
-
const regexp = (0,
|
|
237
|
+
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
1381
238
|
if (regexp.test(pathname)) {
|
|
1382
|
-
this.pathCache[
|
|
239
|
+
this.pathCache[path6] = name;
|
|
1383
240
|
return name;
|
|
1384
241
|
}
|
|
1385
242
|
}
|
|
@@ -1392,7 +249,7 @@ var MicrofrontendConfigClient = class {
|
|
|
1392
249
|
if (!defaultApplication) {
|
|
1393
250
|
return null;
|
|
1394
251
|
}
|
|
1395
|
-
this.pathCache[
|
|
252
|
+
this.pathCache[path6] = defaultApplication[0];
|
|
1396
253
|
return defaultApplication[0];
|
|
1397
254
|
}
|
|
1398
255
|
serialize() {
|
|
@@ -1400,13 +257,13 @@ var MicrofrontendConfigClient = class {
|
|
|
1400
257
|
}
|
|
1401
258
|
};
|
|
1402
259
|
|
|
1403
|
-
// src/config
|
|
1404
|
-
var
|
|
1405
|
-
var
|
|
260
|
+
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
261
|
+
var import_path_to_regexp2 = require("path-to-regexp");
|
|
262
|
+
var SUPPORTED_VERSIONS = ["2"];
|
|
1406
263
|
var validateConfigVersion = (version) => {
|
|
1407
|
-
if (!
|
|
1408
|
-
throw new
|
|
1409
|
-
`Unsupported version: ${version}. Supported versions are: ${
|
|
264
|
+
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
265
|
+
throw new MicrofrontendError(
|
|
266
|
+
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
1410
267
|
", "
|
|
1411
268
|
)}`,
|
|
1412
269
|
{ type: "config", subtype: "unsupported_version" }
|
|
@@ -1424,22 +281,22 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1424
281
|
continue;
|
|
1425
282
|
}
|
|
1426
283
|
for (const pathMatch of app.routing) {
|
|
1427
|
-
for (const
|
|
1428
|
-
const tokens = (0,
|
|
284
|
+
for (const path6 of pathMatch.paths) {
|
|
285
|
+
const tokens = (0, import_path_to_regexp2.parse)(path6);
|
|
1429
286
|
for (const token of tokens.slice(0, -1)) {
|
|
1430
287
|
if (typeof token !== "string") {
|
|
1431
288
|
errors.push(
|
|
1432
|
-
`Path ${
|
|
289
|
+
`Path ${path6} may only have a :wildcard in the last path component`
|
|
1433
290
|
);
|
|
1434
291
|
}
|
|
1435
292
|
}
|
|
1436
|
-
const existing = pathsByApplicationId.get(
|
|
293
|
+
const existing = pathsByApplicationId.get(path6);
|
|
1437
294
|
if (existing) {
|
|
1438
295
|
existing.applications.push(id);
|
|
1439
296
|
} else {
|
|
1440
|
-
pathsByApplicationId.set(
|
|
297
|
+
pathsByApplicationId.set(path6, {
|
|
1441
298
|
applications: [id],
|
|
1442
|
-
matcher: (0,
|
|
299
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path6),
|
|
1443
300
|
applicationId: id
|
|
1444
301
|
});
|
|
1445
302
|
}
|
|
@@ -1447,10 +304,10 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1447
304
|
}
|
|
1448
305
|
}
|
|
1449
306
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
1450
|
-
entries.forEach(([
|
|
307
|
+
entries.forEach(([path6, { applications: ids, matcher, applicationId }]) => {
|
|
1451
308
|
if (ids.length > 1) {
|
|
1452
309
|
errors.push(
|
|
1453
|
-
`Duplicate path "${
|
|
310
|
+
`Duplicate path "${path6}" for applications "${ids.join(", ")}"`
|
|
1454
311
|
);
|
|
1455
312
|
}
|
|
1456
313
|
entries.forEach(
|
|
@@ -1458,14 +315,14 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1458
315
|
matchPath,
|
|
1459
316
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
1460
317
|
]) => {
|
|
1461
|
-
if (
|
|
318
|
+
if (path6 === matchPath) {
|
|
1462
319
|
return;
|
|
1463
320
|
}
|
|
1464
321
|
if (applicationId === matchApplicationId) {
|
|
1465
322
|
return;
|
|
1466
323
|
}
|
|
1467
324
|
if (matcher.test(matchPath)) {
|
|
1468
|
-
const source = `"${
|
|
325
|
+
const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
1469
326
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
1470
327
|
errors.push(
|
|
1471
328
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -1475,7 +332,7 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1475
332
|
);
|
|
1476
333
|
});
|
|
1477
334
|
if (errors.length) {
|
|
1478
|
-
throw new
|
|
335
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1479
336
|
type: "config",
|
|
1480
337
|
subtype: "conflicting_paths"
|
|
1481
338
|
});
|
|
@@ -1488,13 +345,13 @@ var validateAppPaths = (name, app) => {
|
|
|
1488
345
|
continue;
|
|
1489
346
|
}
|
|
1490
347
|
if (p.endsWith("/")) {
|
|
1491
|
-
throw new
|
|
348
|
+
throw new MicrofrontendError(
|
|
1492
349
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
1493
350
|
{ type: "application", subtype: "invalid_path" }
|
|
1494
351
|
);
|
|
1495
352
|
}
|
|
1496
353
|
if (!p.startsWith("/")) {
|
|
1497
|
-
throw new
|
|
354
|
+
throw new MicrofrontendError(
|
|
1498
355
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
1499
356
|
{ type: "application", subtype: "invalid_path" }
|
|
1500
357
|
);
|
|
@@ -1516,33 +373,20 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
1516
373
|
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
1517
374
|
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
1518
375
|
if (numApplicationsWithoutRouting === 0) {
|
|
1519
|
-
throw new
|
|
376
|
+
throw new MicrofrontendError(
|
|
1520
377
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
1521
378
|
{ type: "config", subtype: "no_default_application" }
|
|
1522
379
|
);
|
|
1523
380
|
}
|
|
1524
381
|
if (numApplicationsWithoutRouting > 1) {
|
|
1525
|
-
throw new
|
|
382
|
+
throw new MicrofrontendError(
|
|
1526
383
|
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
1527
384
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
1528
385
|
);
|
|
1529
386
|
}
|
|
1530
387
|
};
|
|
1531
|
-
var validateConfigOptions = (options) => {
|
|
1532
|
-
var _a;
|
|
1533
|
-
if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
|
|
1534
|
-
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1535
|
-
options.vercel.previewDeploymentSuffix
|
|
1536
|
-
)) {
|
|
1537
|
-
throw new MicrofrontendError2(
|
|
1538
|
-
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1539
|
-
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1540
|
-
);
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
};
|
|
1544
388
|
|
|
1545
|
-
// src/config
|
|
389
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
1546
390
|
var PREFIX = "vc-ap";
|
|
1547
391
|
function generateAssetPrefixFromName({
|
|
1548
392
|
name
|
|
@@ -1553,7 +397,7 @@ function generateAssetPrefixFromName({
|
|
|
1553
397
|
return `${PREFIX}-${name}`;
|
|
1554
398
|
}
|
|
1555
399
|
|
|
1556
|
-
// src/config
|
|
400
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-port.ts
|
|
1557
401
|
function generatePortFromName({
|
|
1558
402
|
name,
|
|
1559
403
|
minPort = 3e3,
|
|
@@ -1573,13 +417,13 @@ function generatePortFromName({
|
|
|
1573
417
|
return port;
|
|
1574
418
|
}
|
|
1575
419
|
|
|
1576
|
-
// src/config
|
|
1577
|
-
var
|
|
420
|
+
// src/config/microfrontends-config/isomorphic/host.ts
|
|
421
|
+
var Host = class {
|
|
1578
422
|
constructor(hostConfig, options) {
|
|
1579
423
|
const { protocol = "https", host, port } = hostConfig;
|
|
1580
424
|
this.protocol = protocol;
|
|
1581
425
|
this.host = host;
|
|
1582
|
-
this.port =
|
|
426
|
+
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
1583
427
|
this.local = options == null ? void 0 : options.isLocal;
|
|
1584
428
|
}
|
|
1585
429
|
isLocal() {
|
|
@@ -1598,7 +442,7 @@ var Host2 = class {
|
|
|
1598
442
|
return port;
|
|
1599
443
|
}
|
|
1600
444
|
isDefaultPort() {
|
|
1601
|
-
return this.port ===
|
|
445
|
+
return this.port === Host.getPort({ protocol: this.protocol });
|
|
1602
446
|
}
|
|
1603
447
|
toString(opts = {}) {
|
|
1604
448
|
const url = this.toUrl(opts);
|
|
@@ -1610,7 +454,7 @@ var Host2 = class {
|
|
|
1610
454
|
return new URL(url);
|
|
1611
455
|
}
|
|
1612
456
|
};
|
|
1613
|
-
var LocalHost = class extends
|
|
457
|
+
var LocalHost = class extends Host {
|
|
1614
458
|
constructor({
|
|
1615
459
|
appName,
|
|
1616
460
|
...hostConfig
|
|
@@ -1622,8 +466,8 @@ var LocalHost = class extends Host2 {
|
|
|
1622
466
|
}
|
|
1623
467
|
};
|
|
1624
468
|
|
|
1625
|
-
// src/config
|
|
1626
|
-
var
|
|
469
|
+
// src/config/microfrontends-config/isomorphic/application.ts
|
|
470
|
+
var Application = class {
|
|
1627
471
|
constructor(name, {
|
|
1628
472
|
app,
|
|
1629
473
|
overrides,
|
|
@@ -1636,12 +480,12 @@ var Application2 = class {
|
|
|
1636
480
|
appName: name,
|
|
1637
481
|
...(_a = app.development) == null ? void 0 : _a.local
|
|
1638
482
|
}),
|
|
1639
|
-
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new
|
|
483
|
+
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
|
|
1640
484
|
};
|
|
1641
|
-
this.production = app.production ? new
|
|
485
|
+
this.production = app.production ? new Host(app.production) : void 0;
|
|
1642
486
|
this.vercel = app.vercel;
|
|
1643
487
|
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
1644
|
-
environment: new
|
|
488
|
+
environment: new Host(overrides.environment)
|
|
1645
489
|
} : void 0;
|
|
1646
490
|
this.default = isDefault ?? false;
|
|
1647
491
|
this.serialized = app;
|
|
@@ -1656,7 +500,7 @@ var Application2 = class {
|
|
|
1656
500
|
return this.serialized;
|
|
1657
501
|
}
|
|
1658
502
|
};
|
|
1659
|
-
var DefaultApplication = class extends
|
|
503
|
+
var DefaultApplication = class extends Application {
|
|
1660
504
|
constructor(name, {
|
|
1661
505
|
app,
|
|
1662
506
|
overrides
|
|
@@ -1667,13 +511,13 @@ var DefaultApplication = class extends Application2 {
|
|
|
1667
511
|
isDefault: true
|
|
1668
512
|
});
|
|
1669
513
|
this.default = true;
|
|
1670
|
-
this.production = new
|
|
514
|
+
this.production = new Host(app.production);
|
|
1671
515
|
}
|
|
1672
516
|
getAssetPrefix() {
|
|
1673
517
|
return "";
|
|
1674
518
|
}
|
|
1675
519
|
};
|
|
1676
|
-
var ChildApplication = class extends
|
|
520
|
+
var ChildApplication = class extends Application {
|
|
1677
521
|
constructor(name, {
|
|
1678
522
|
app,
|
|
1679
523
|
overrides
|
|
@@ -1692,10 +536,10 @@ var ChildApplication = class extends Application2 {
|
|
|
1692
536
|
}
|
|
1693
537
|
};
|
|
1694
538
|
|
|
1695
|
-
// src/config
|
|
1696
|
-
var
|
|
539
|
+
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
540
|
+
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
1697
541
|
|
|
1698
|
-
// src/config
|
|
542
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
1699
543
|
var MicrofrontendConfigIsomorphic = class {
|
|
1700
544
|
constructor({
|
|
1701
545
|
config,
|
|
@@ -1736,7 +580,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1736
580
|
);
|
|
1737
581
|
}
|
|
1738
582
|
if (isMainConfig(config) && !this.defaultApplication) {
|
|
1739
|
-
throw new
|
|
583
|
+
throw new MicrofrontendError(
|
|
1740
584
|
`Could not find default application in microfrontends configuration`,
|
|
1741
585
|
{
|
|
1742
586
|
type: "application",
|
|
@@ -1753,13 +597,12 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1753
597
|
};
|
|
1754
598
|
}
|
|
1755
599
|
static validate(config) {
|
|
1756
|
-
const c = typeof config === "string" ? (0,
|
|
600
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
1757
601
|
if (isMainConfig(c)) {
|
|
1758
602
|
validateConfigVersion(c.version);
|
|
1759
603
|
validateConfigPaths(c.applications);
|
|
1760
604
|
validateConfigDefaultApplication(c.applications);
|
|
1761
605
|
}
|
|
1762
|
-
validateConfigOptions(c.options);
|
|
1763
606
|
return c;
|
|
1764
607
|
}
|
|
1765
608
|
static fromEnv({
|
|
@@ -1767,7 +610,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1767
610
|
cookies
|
|
1768
611
|
}) {
|
|
1769
612
|
return new MicrofrontendConfigIsomorphic({
|
|
1770
|
-
config: (0,
|
|
613
|
+
config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
|
|
1771
614
|
overrides: parseOverrides(cookies ?? []),
|
|
1772
615
|
meta
|
|
1773
616
|
});
|
|
@@ -1801,7 +644,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1801
644
|
}
|
|
1802
645
|
const app = this.childApplications[name];
|
|
1803
646
|
if (!app) {
|
|
1804
|
-
throw new
|
|
647
|
+
throw new MicrofrontendError(
|
|
1805
648
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
1806
649
|
{
|
|
1807
650
|
type: "application",
|
|
@@ -1829,7 +672,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1829
672
|
*/
|
|
1830
673
|
getDefaultApplication() {
|
|
1831
674
|
if (!this.defaultApplication) {
|
|
1832
|
-
throw new
|
|
675
|
+
throw new MicrofrontendError(
|
|
1833
676
|
`Could not find default application in microfrontends configuration`,
|
|
1834
677
|
{
|
|
1835
678
|
type: "application",
|
|
@@ -1844,7 +687,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1844
687
|
*/
|
|
1845
688
|
getLocalProxyPort() {
|
|
1846
689
|
var _a, _b;
|
|
1847
|
-
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ??
|
|
690
|
+
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
1848
691
|
}
|
|
1849
692
|
/**
|
|
1850
693
|
* Serializes the class back to the Schema type.
|
|
@@ -1878,7 +721,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1878
721
|
}
|
|
1879
722
|
};
|
|
1880
723
|
|
|
1881
|
-
// src/config
|
|
724
|
+
// src/config/microfrontends-config/isomorphic/child.ts
|
|
1882
725
|
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
1883
726
|
constructor({
|
|
1884
727
|
config,
|
|
@@ -1891,7 +734,7 @@ var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
1891
734
|
}
|
|
1892
735
|
};
|
|
1893
736
|
|
|
1894
|
-
// src/config
|
|
737
|
+
// src/config/microfrontends-config/isomorphic/main.ts
|
|
1895
738
|
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
1896
739
|
constructor({
|
|
1897
740
|
config,
|
|
@@ -1918,7 +761,7 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
1918
761
|
}
|
|
1919
762
|
}
|
|
1920
763
|
if (!defaultApplication) {
|
|
1921
|
-
throw new
|
|
764
|
+
throw new MicrofrontendError(
|
|
1922
765
|
`Could not find default application in microfrontends configuration`,
|
|
1923
766
|
{
|
|
1924
767
|
type: "application",
|
|
@@ -1930,7 +773,7 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
1930
773
|
}
|
|
1931
774
|
};
|
|
1932
775
|
|
|
1933
|
-
// src/config
|
|
776
|
+
// src/config/microfrontends/isomorphic/index.ts
|
|
1934
777
|
var Microfrontends = class {
|
|
1935
778
|
constructor({
|
|
1936
779
|
config,
|
|
@@ -1958,27 +801,27 @@ var Microfrontends = class {
|
|
|
1958
801
|
}
|
|
1959
802
|
};
|
|
1960
803
|
|
|
1961
|
-
// src/config
|
|
1962
|
-
var
|
|
1963
|
-
var
|
|
804
|
+
// src/config/microfrontends/utils/find-repository-root.ts
|
|
805
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
806
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
1964
807
|
var GIT_DIRECTORY = ".git";
|
|
1965
808
|
function findRepositoryRoot(startDir) {
|
|
1966
809
|
let currentDir = startDir || process.cwd();
|
|
1967
|
-
while (currentDir !==
|
|
1968
|
-
const gitPath =
|
|
1969
|
-
if (
|
|
810
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
811
|
+
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
812
|
+
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
1970
813
|
return currentDir;
|
|
1971
814
|
}
|
|
1972
|
-
currentDir =
|
|
815
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
1973
816
|
}
|
|
1974
817
|
throw new Error(
|
|
1975
818
|
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
1976
819
|
);
|
|
1977
820
|
}
|
|
1978
821
|
|
|
1979
|
-
// src/config
|
|
1980
|
-
var
|
|
1981
|
-
var
|
|
822
|
+
// src/config/microfrontends/utils/find-package-path.ts
|
|
823
|
+
var import_node_path2 = require("path");
|
|
824
|
+
var import_node_fs2 = require("fs");
|
|
1982
825
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
1983
826
|
var configCache = {};
|
|
1984
827
|
function findPackagePathWithGlob({
|
|
@@ -1995,7 +838,7 @@ function findPackagePathWithGlob({
|
|
|
1995
838
|
});
|
|
1996
839
|
const matchingPaths = [];
|
|
1997
840
|
for (const packageJsonPath2 of packageJsonPaths) {
|
|
1998
|
-
const packageJsonContent = (0,
|
|
841
|
+
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
1999
842
|
const packageJson = JSON.parse(packageJsonContent);
|
|
2000
843
|
if (packageJson.name === name) {
|
|
2001
844
|
matchingPaths.push(packageJsonPath2);
|
|
@@ -2012,7 +855,7 @@ function findPackagePathWithGlob({
|
|
|
2012
855
|
);
|
|
2013
856
|
}
|
|
2014
857
|
const [packageJsonPath] = matchingPaths;
|
|
2015
|
-
return (0,
|
|
858
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
2016
859
|
} catch (error) {
|
|
2017
860
|
return null;
|
|
2018
861
|
}
|
|
@@ -2032,32 +875,42 @@ function findPackagePath(opts) {
|
|
|
2032
875
|
return result;
|
|
2033
876
|
}
|
|
2034
877
|
|
|
2035
|
-
// src/config
|
|
2036
|
-
var
|
|
2037
|
-
var
|
|
878
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
879
|
+
var import_node_path3 = require("path");
|
|
880
|
+
var import_node_fs3 = require("fs");
|
|
881
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
2038
882
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
883
|
+
|
|
884
|
+
// src/config/constants.ts
|
|
885
|
+
var CONFIGURATION_FILENAMES = [
|
|
886
|
+
"microfrontends.jsonc",
|
|
887
|
+
"microfrontends.json"
|
|
888
|
+
];
|
|
889
|
+
|
|
890
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
2039
891
|
var configCache2 = {};
|
|
2040
892
|
function findDefaultMicrofrontendsPackages({
|
|
2041
893
|
repositoryRoot,
|
|
2042
894
|
applicationName
|
|
2043
895
|
}) {
|
|
2044
896
|
try {
|
|
2045
|
-
const microfrontendsJsonPaths = import_fast_glob2.default.globSync(
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
897
|
+
const microfrontendsJsonPaths = import_fast_glob2.default.globSync(
|
|
898
|
+
`**/{${CONFIGURATION_FILENAMES.join(",")}}`,
|
|
899
|
+
{
|
|
900
|
+
cwd: repositoryRoot,
|
|
901
|
+
absolute: true,
|
|
902
|
+
onlyFiles: true,
|
|
903
|
+
followSymbolicLinks: false,
|
|
904
|
+
ignore: ["**/node_modules/**", "**/.git/**"]
|
|
905
|
+
}
|
|
906
|
+
);
|
|
2052
907
|
const matchingPaths = [];
|
|
2053
908
|
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
2054
|
-
const microfrontendsJsonContent = (0,
|
|
909
|
+
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
2055
910
|
microfrontendsJsonPath,
|
|
2056
911
|
"utf-8"
|
|
2057
912
|
);
|
|
2058
|
-
const microfrontendsJson =
|
|
2059
|
-
microfrontendsJsonContent
|
|
2060
|
-
);
|
|
913
|
+
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
2061
914
|
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
2062
915
|
matchingPaths.push(microfrontendsJsonPath);
|
|
2063
916
|
}
|
|
@@ -2074,7 +927,7 @@ ${matchingPaths.join("\n \u2022 ")}`
|
|
|
2074
927
|
);
|
|
2075
928
|
}
|
|
2076
929
|
const [packageJsonPath] = matchingPaths;
|
|
2077
|
-
return (0,
|
|
930
|
+
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
2078
931
|
} catch (error) {
|
|
2079
932
|
return null;
|
|
2080
933
|
}
|
|
@@ -2087,32 +940,32 @@ function findDefaultMicrofrontendsPackage(opts) {
|
|
|
2087
940
|
const result = findDefaultMicrofrontendsPackages(opts);
|
|
2088
941
|
if (!result) {
|
|
2089
942
|
throw new Error(
|
|
2090
|
-
`Error trying to resolve the main microfrontends
|
|
943
|
+
`Error trying to resolve the main microfrontends configuration`
|
|
2091
944
|
);
|
|
2092
945
|
}
|
|
2093
946
|
configCache2[cacheKey] = result;
|
|
2094
947
|
return result;
|
|
2095
948
|
}
|
|
2096
949
|
|
|
2097
|
-
// src/config
|
|
2098
|
-
var
|
|
2099
|
-
var
|
|
950
|
+
// src/config/microfrontends/utils/is-monorepo.ts
|
|
951
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
952
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
2100
953
|
function isMonorepo({
|
|
2101
954
|
repositoryRoot
|
|
2102
955
|
}) {
|
|
2103
956
|
try {
|
|
2104
|
-
if (
|
|
957
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
2105
958
|
return true;
|
|
2106
959
|
}
|
|
2107
|
-
if (
|
|
960
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
2108
961
|
return true;
|
|
2109
962
|
}
|
|
2110
|
-
const packageJsonPath =
|
|
2111
|
-
if (!
|
|
963
|
+
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
964
|
+
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
2112
965
|
return false;
|
|
2113
966
|
}
|
|
2114
967
|
const packageJson = JSON.parse(
|
|
2115
|
-
|
|
968
|
+
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
2116
969
|
);
|
|
2117
970
|
return packageJson.workspaces !== void 0;
|
|
2118
971
|
} catch (error) {
|
|
@@ -2121,30 +974,67 @@ function isMonorepo({
|
|
|
2121
974
|
}
|
|
2122
975
|
}
|
|
2123
976
|
|
|
2124
|
-
// src/config
|
|
2125
|
-
var
|
|
2126
|
-
var
|
|
977
|
+
// src/config/microfrontends/utils/find-package-root.ts
|
|
978
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
979
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
2127
980
|
var PACKAGE_JSON = "package.json";
|
|
2128
981
|
function findPackageRoot(startDir) {
|
|
2129
982
|
let currentDir = startDir || process.cwd();
|
|
2130
|
-
while (currentDir !==
|
|
2131
|
-
const pkgJsonPath =
|
|
2132
|
-
if (
|
|
983
|
+
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
984
|
+
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
985
|
+
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
2133
986
|
return currentDir;
|
|
2134
987
|
}
|
|
2135
|
-
currentDir =
|
|
988
|
+
currentDir = import_node_path5.default.dirname(currentDir);
|
|
2136
989
|
}
|
|
2137
990
|
throw new Error(
|
|
2138
991
|
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
2139
992
|
);
|
|
2140
993
|
}
|
|
2141
994
|
|
|
2142
|
-
// src/config
|
|
995
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
996
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
997
|
+
var import_node_path6 = require("path");
|
|
998
|
+
function findConfig({ dir }) {
|
|
999
|
+
for (const filename of CONFIGURATION_FILENAMES) {
|
|
1000
|
+
const maybeConfig = (0, import_node_path6.join)(dir, filename);
|
|
1001
|
+
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
1002
|
+
return maybeConfig;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return null;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1009
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1010
|
+
|
|
1011
|
+
// src/config/microfrontends/server/constants.ts
|
|
1012
|
+
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
1013
|
+
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
1014
|
+
|
|
1015
|
+
// src/utils/is-vercel.ts
|
|
1016
|
+
function isVercel() {
|
|
1017
|
+
return process.env.VERCEL === "1";
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1021
|
+
function getOutputFilePath() {
|
|
1022
|
+
if (isVercel()) {
|
|
1023
|
+
return import_node_path7.default.join(
|
|
1024
|
+
".vercel",
|
|
1025
|
+
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
1026
|
+
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
// src/config/microfrontends/server/validation.ts
|
|
2143
1033
|
var import_jsonc_parser3 = require("jsonc-parser");
|
|
2144
|
-
var
|
|
1034
|
+
var import_ajv = require("ajv");
|
|
2145
1035
|
|
|
2146
|
-
// schema/schema
|
|
2147
|
-
var
|
|
1036
|
+
// schema/schema.json
|
|
1037
|
+
var schema_default = {
|
|
2148
1038
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
2149
1039
|
$ref: "#/definitions/Config",
|
|
2150
1040
|
definitions: {
|
|
@@ -2183,7 +1073,8 @@ var schema_v2_default = {
|
|
|
2183
1073
|
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"
|
|
2184
1074
|
}
|
|
2185
1075
|
},
|
|
2186
|
-
required: ["applications", "version"]
|
|
1076
|
+
required: ["applications", "version"],
|
|
1077
|
+
additionalProperties: false
|
|
2187
1078
|
},
|
|
2188
1079
|
Options: {
|
|
2189
1080
|
type: "object",
|
|
@@ -2196,15 +1087,12 @@ var schema_v2_default = {
|
|
|
2196
1087
|
$ref: "#/definitions/LocalProxyOptions",
|
|
2197
1088
|
description: "Options for local proxy."
|
|
2198
1089
|
}
|
|
2199
|
-
}
|
|
1090
|
+
},
|
|
1091
|
+
additionalProperties: false
|
|
2200
1092
|
},
|
|
2201
1093
|
VercelOptions: {
|
|
2202
1094
|
type: "object",
|
|
2203
1095
|
properties: {
|
|
2204
|
-
previewDeploymentSuffix: {
|
|
2205
|
-
type: "string",
|
|
2206
|
-
description: "If your team uses a custom Preview Deployment Suffix, please specify it here. See https://vercel.com/docs/deployments/preview-deployment-suffix. The default is `vercel.app`."
|
|
2207
|
-
},
|
|
2208
1096
|
teamSlug: {
|
|
2209
1097
|
type: "string",
|
|
2210
1098
|
description: "Team slug for the Vercel team"
|
|
@@ -2213,7 +1101,8 @@ var schema_v2_default = {
|
|
|
2213
1101
|
type: "boolean",
|
|
2214
1102
|
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."
|
|
2215
1103
|
}
|
|
2216
|
-
}
|
|
1104
|
+
},
|
|
1105
|
+
additionalProperties: false
|
|
2217
1106
|
},
|
|
2218
1107
|
LocalProxyOptions: {
|
|
2219
1108
|
type: "object",
|
|
@@ -2222,7 +1111,8 @@ var schema_v2_default = {
|
|
|
2222
1111
|
type: "number",
|
|
2223
1112
|
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
2224
1113
|
}
|
|
2225
|
-
}
|
|
1114
|
+
},
|
|
1115
|
+
additionalProperties: false
|
|
2226
1116
|
},
|
|
2227
1117
|
Application: {
|
|
2228
1118
|
anyOf: [
|
|
@@ -2247,7 +1137,8 @@ var schema_v2_default = {
|
|
|
2247
1137
|
$ref: "#/definitions/HostConfig"
|
|
2248
1138
|
}
|
|
2249
1139
|
},
|
|
2250
|
-
required: ["production"]
|
|
1140
|
+
required: ["production"],
|
|
1141
|
+
additionalProperties: false
|
|
2251
1142
|
},
|
|
2252
1143
|
Vercel: {
|
|
2253
1144
|
type: "object",
|
|
@@ -2257,7 +1148,8 @@ var schema_v2_default = {
|
|
|
2257
1148
|
description: "Vercel project ID"
|
|
2258
1149
|
}
|
|
2259
1150
|
},
|
|
2260
|
-
required: ["projectId"]
|
|
1151
|
+
required: ["projectId"],
|
|
1152
|
+
additionalProperties: false
|
|
2261
1153
|
},
|
|
2262
1154
|
Development: {
|
|
2263
1155
|
type: "object",
|
|
@@ -2273,10 +1165,12 @@ var schema_v2_default = {
|
|
|
2273
1165
|
type: "string",
|
|
2274
1166
|
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
2275
1167
|
}
|
|
2276
|
-
}
|
|
1168
|
+
},
|
|
1169
|
+
additionalProperties: false
|
|
2277
1170
|
},
|
|
2278
1171
|
LocalHostConfig: {
|
|
2279
1172
|
type: "object",
|
|
1173
|
+
additionalProperties: false,
|
|
2280
1174
|
properties: {
|
|
2281
1175
|
host: {
|
|
2282
1176
|
type: "string",
|
|
@@ -2310,7 +1204,8 @@ var schema_v2_default = {
|
|
|
2310
1204
|
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
2311
1205
|
}
|
|
2312
1206
|
},
|
|
2313
|
-
required: ["host"]
|
|
1207
|
+
required: ["host"],
|
|
1208
|
+
additionalProperties: false
|
|
2314
1209
|
},
|
|
2315
1210
|
ChildApplication: {
|
|
2316
1211
|
type: "object",
|
|
@@ -2329,7 +1224,8 @@ var schema_v2_default = {
|
|
|
2329
1224
|
$ref: "#/definitions/HostConfig"
|
|
2330
1225
|
}
|
|
2331
1226
|
},
|
|
2332
|
-
required: ["routing"]
|
|
1227
|
+
required: ["routing"],
|
|
1228
|
+
additionalProperties: false
|
|
2333
1229
|
},
|
|
2334
1230
|
Routing: {
|
|
2335
1231
|
type: "array",
|
|
@@ -2355,7 +1251,8 @@ var schema_v2_default = {
|
|
|
2355
1251
|
}
|
|
2356
1252
|
}
|
|
2357
1253
|
},
|
|
2358
|
-
required: ["paths"]
|
|
1254
|
+
required: ["paths"],
|
|
1255
|
+
additionalProperties: false
|
|
2359
1256
|
},
|
|
2360
1257
|
ApplicationRouting: {
|
|
2361
1258
|
type: "object",
|
|
@@ -2388,19 +1285,20 @@ var schema_v2_default = {
|
|
|
2388
1285
|
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."
|
|
2389
1286
|
}
|
|
2390
1287
|
},
|
|
2391
|
-
required: ["partOf", "version"]
|
|
1288
|
+
required: ["partOf", "version"],
|
|
1289
|
+
additionalProperties: false
|
|
2392
1290
|
}
|
|
2393
1291
|
}
|
|
2394
1292
|
};
|
|
2395
1293
|
|
|
2396
|
-
// src/config
|
|
2397
|
-
var
|
|
1294
|
+
// src/config/schema/utils/load.ts
|
|
1295
|
+
var SCHEMA = schema_default;
|
|
2398
1296
|
|
|
2399
|
-
// src/config
|
|
2400
|
-
function
|
|
1297
|
+
// src/config/microfrontends/server/validation.ts
|
|
1298
|
+
function validateSchema(configString) {
|
|
2401
1299
|
const parsedConfig = (0, import_jsonc_parser3.parse)(configString);
|
|
2402
|
-
const ajv = new
|
|
2403
|
-
const validate = ajv.compile(
|
|
1300
|
+
const ajv = new import_ajv.Ajv();
|
|
1301
|
+
const validate = ajv.compile(SCHEMA);
|
|
2404
1302
|
const isValid = validate(parsedConfig);
|
|
2405
1303
|
if (!isValid) {
|
|
2406
1304
|
throw new MicrofrontendError(
|
|
@@ -2411,7 +1309,7 @@ function validateSchema2(configString) {
|
|
|
2411
1309
|
return parsedConfig;
|
|
2412
1310
|
}
|
|
2413
1311
|
|
|
2414
|
-
// src/config
|
|
1312
|
+
// src/config/microfrontends/server/index.ts
|
|
2415
1313
|
var MicrofrontendsServer = class extends Microfrontends {
|
|
2416
1314
|
/**
|
|
2417
1315
|
* Writes the configuration to a file.
|
|
@@ -2420,8 +1318,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2420
1318
|
pretty: true
|
|
2421
1319
|
}) {
|
|
2422
1320
|
const outputPath = getOutputFilePath();
|
|
2423
|
-
|
|
2424
|
-
|
|
1321
|
+
import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
|
|
1322
|
+
import_node_fs7.default.writeFileSync(
|
|
2425
1323
|
outputPath,
|
|
2426
1324
|
JSON.stringify(
|
|
2427
1325
|
this.config.toSchemaJson(),
|
|
@@ -2454,7 +1352,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2454
1352
|
meta
|
|
2455
1353
|
});
|
|
2456
1354
|
}
|
|
2457
|
-
throw new
|
|
1355
|
+
throw new MicrofrontendError(
|
|
2458
1356
|
"Invalid config: must be a string or an object",
|
|
2459
1357
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
2460
1358
|
);
|
|
@@ -2478,14 +1376,14 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2478
1376
|
*/
|
|
2479
1377
|
static validate(config) {
|
|
2480
1378
|
if (typeof config === "string") {
|
|
2481
|
-
const c =
|
|
1379
|
+
const c = validateSchema(config);
|
|
2482
1380
|
return c;
|
|
2483
1381
|
}
|
|
2484
1382
|
return config;
|
|
2485
1383
|
}
|
|
2486
1384
|
/**
|
|
2487
|
-
* Looks up the configuration by inferring the package root and looking for a microfrontends
|
|
2488
|
-
* it will look for a package in the repository with a microfrontends
|
|
1385
|
+
* Looks up the configuration by inferring the package root and looking for a microfrontends config file. If a file is not found,
|
|
1386
|
+
* it will look for a package in the repository with a microfrontends file that contains the current application
|
|
2489
1387
|
* and use that configuration.
|
|
2490
1388
|
*
|
|
2491
1389
|
* This can return either a Child or Main configuration.
|
|
@@ -2507,16 +1405,16 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2507
1405
|
}
|
|
2508
1406
|
try {
|
|
2509
1407
|
const packageRoot = findPackageRoot(directory);
|
|
2510
|
-
const packageJsonPath = (0,
|
|
1408
|
+
const packageJsonPath = (0, import_node_path8.join)(packageRoot, "package.json");
|
|
2511
1409
|
const packageJson = JSON.parse(
|
|
2512
|
-
|
|
1410
|
+
import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
|
|
2513
1411
|
);
|
|
2514
1412
|
if (!packageJson.name) {
|
|
2515
1413
|
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
2516
1414
|
}
|
|
2517
1415
|
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
2518
|
-
const maybeConfig = (
|
|
2519
|
-
if (
|
|
1416
|
+
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1417
|
+
if (maybeConfig) {
|
|
2520
1418
|
return MicrofrontendsServer.fromFile({
|
|
2521
1419
|
filePath: maybeConfig,
|
|
2522
1420
|
cookies,
|
|
@@ -2531,16 +1429,19 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2531
1429
|
repositoryRoot,
|
|
2532
1430
|
applicationName: packageJson.name
|
|
2533
1431
|
});
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
1432
|
+
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1433
|
+
if (maybeConfigFromDefault) {
|
|
1434
|
+
return MicrofrontendsServer.fromFile({
|
|
1435
|
+
filePath: maybeConfigFromDefault,
|
|
1436
|
+
cookies,
|
|
1437
|
+
meta: configMeta,
|
|
1438
|
+
options
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
2540
1441
|
}
|
|
2541
1442
|
throw new Error("Unable to infer");
|
|
2542
1443
|
} catch (e) {
|
|
2543
|
-
throw new
|
|
1444
|
+
throw new MicrofrontendError(
|
|
2544
1445
|
"Unable to infer microfrontends configuration",
|
|
2545
1446
|
{ type: "config", subtype: "inference_failed" }
|
|
2546
1447
|
);
|
|
@@ -2556,7 +1457,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2556
1457
|
options
|
|
2557
1458
|
}) {
|
|
2558
1459
|
try {
|
|
2559
|
-
const configJson =
|
|
1460
|
+
const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
2560
1461
|
const config = MicrofrontendsServer.validate(configJson);
|
|
2561
1462
|
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
2562
1463
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -2567,14 +1468,20 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2567
1468
|
name: config.partOf
|
|
2568
1469
|
});
|
|
2569
1470
|
if (!packagePath) {
|
|
2570
|
-
throw new
|
|
1471
|
+
throw new MicrofrontendError(
|
|
2571
1472
|
`Could not find default application "${config.partOf}" in the repository`,
|
|
2572
1473
|
{ type: "config", subtype: "not_found" }
|
|
2573
1474
|
);
|
|
2574
1475
|
}
|
|
2575
|
-
const
|
|
1476
|
+
const maybeConfig = findConfig({ dir: packagePath });
|
|
1477
|
+
if (!maybeConfig) {
|
|
1478
|
+
throw new MicrofrontendError(
|
|
1479
|
+
`Could not find microfrontends configuration in ${packagePath}`,
|
|
1480
|
+
{ type: "config", subtype: "not_found" }
|
|
1481
|
+
);
|
|
1482
|
+
}
|
|
2576
1483
|
return MicrofrontendsServer.fromMainConfigFile({
|
|
2577
|
-
filePath:
|
|
1484
|
+
filePath: maybeConfig,
|
|
2578
1485
|
overrides: cookies ? parseOverrides(cookies) : void 0
|
|
2579
1486
|
});
|
|
2580
1487
|
}
|
|
@@ -2585,7 +1492,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2585
1492
|
meta
|
|
2586
1493
|
});
|
|
2587
1494
|
} catch (e) {
|
|
2588
|
-
throw
|
|
1495
|
+
throw MicrofrontendError.handle(e, {
|
|
2589
1496
|
fileName: filePath
|
|
2590
1497
|
});
|
|
2591
1498
|
}
|
|
@@ -2598,10 +1505,10 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2598
1505
|
overrides
|
|
2599
1506
|
}) {
|
|
2600
1507
|
try {
|
|
2601
|
-
const config =
|
|
1508
|
+
const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
2602
1509
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
2603
1510
|
if (!isMainConfig(validatedConfig)) {
|
|
2604
|
-
throw new
|
|
1511
|
+
throw new MicrofrontendError(
|
|
2605
1512
|
`${filePath} is not a main microfrontend config`,
|
|
2606
1513
|
{
|
|
2607
1514
|
type: "config",
|
|
@@ -2611,7 +1518,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2611
1518
|
}
|
|
2612
1519
|
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
2613
1520
|
if (!defaultApplication) {
|
|
2614
|
-
throw new
|
|
1521
|
+
throw new MicrofrontendError(
|
|
2615
1522
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
2616
1523
|
{ type: "config", subtype: "no_default_application" }
|
|
2617
1524
|
);
|
|
@@ -2622,7 +1529,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2622
1529
|
meta: { fromApp: defaultApplication }
|
|
2623
1530
|
});
|
|
2624
1531
|
} catch (e) {
|
|
2625
|
-
throw
|
|
1532
|
+
throw MicrofrontendError.handle(e, {
|
|
2626
1533
|
fileName: filePath
|
|
2627
1534
|
});
|
|
2628
1535
|
}
|
|
@@ -2632,9 +1539,9 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2632
1539
|
// src/utils/mfe-port.ts
|
|
2633
1540
|
function mfePort(packageDir) {
|
|
2634
1541
|
const { name: appName, version } = getPackageJson(packageDir);
|
|
2635
|
-
const result =
|
|
1542
|
+
const result = loadConfig({ packageDir, appName });
|
|
2636
1543
|
if (!result) {
|
|
2637
|
-
throw new
|
|
1544
|
+
throw new MicrofrontendError(
|
|
2638
1545
|
`Unable to determine configured port for ${appName}`,
|
|
2639
1546
|
{ type: "config", subtype: "not_found" }
|
|
2640
1547
|
);
|
|
@@ -2647,10 +1554,10 @@ function mfePort(packageDir) {
|
|
|
2647
1554
|
};
|
|
2648
1555
|
}
|
|
2649
1556
|
function getPackageJson(packageDir) {
|
|
2650
|
-
const filePath =
|
|
2651
|
-
return JSON.parse(
|
|
1557
|
+
const filePath = import_node_path9.default.join(packageDir, "package.json");
|
|
1558
|
+
return JSON.parse(import_node_fs8.default.readFileSync(filePath, "utf-8"));
|
|
2652
1559
|
}
|
|
2653
|
-
function
|
|
1560
|
+
function loadConfig({
|
|
2654
1561
|
packageDir,
|
|
2655
1562
|
appName
|
|
2656
1563
|
}) {
|
|
@@ -2668,21 +1575,6 @@ function loadV2({
|
|
|
2668
1575
|
const port = app.development.local.port;
|
|
2669
1576
|
return { port };
|
|
2670
1577
|
}
|
|
2671
|
-
function loadV1({
|
|
2672
|
-
packageDir,
|
|
2673
|
-
appName
|
|
2674
|
-
}) {
|
|
2675
|
-
const filePath = import_node_path10.default.join(packageDir, "micro-frontends.jsonc");
|
|
2676
|
-
let config;
|
|
2677
|
-
try {
|
|
2678
|
-
config = MicrofrontendConfig.fromFile({ filePath });
|
|
2679
|
-
} catch (e) {
|
|
2680
|
-
return void 0;
|
|
2681
|
-
}
|
|
2682
|
-
const zone = config.getZone(appName);
|
|
2683
|
-
const port = zone.development.local.port;
|
|
2684
|
-
return { port };
|
|
2685
|
-
}
|
|
2686
1578
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2687
1579
|
0 && (module.exports = {
|
|
2688
1580
|
mfePort
|