@vercel/microfrontends 0.14.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/dist/bin/cli.cjs +377 -1626
- 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/{v2/microfrontends → microfrontends}/server.cjs +63 -143
- package/dist/microfrontends/server.cjs.map +1 -0
- package/dist/{v2/microfrontends → microfrontends}/server.d.ts +4 -4
- package/dist/{v2/microfrontends → microfrontends}/server.js +63 -143
- package/dist/microfrontends/server.js.map +1 -0
- package/dist/{v2/microfrontends.cjs → microfrontends.cjs} +21 -21
- package/dist/microfrontends.cjs.map +1 -0
- package/dist/{v2/microfrontends.d.ts → microfrontends.d.ts} +4 -4
- package/dist/{v2/microfrontends.js → microfrontends.js} +20 -20
- 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 +13 -2
- package/dist/next/endpoints.js +77 -18
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +745 -396
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +10 -5
- package/dist/next/middleware.js +745 -396
- 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/{v2/routing.cjs → routing.cjs} +3 -3
- package/dist/routing.cjs.map +1 -0
- package/dist/{v2/schema.cjs → schema.cjs} +1 -1
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.ts +1 -0
- package/dist/utils/mfe-port.cjs +211 -1333
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +204 -1326
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +31 -361
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +3 -146
- package/dist/validation.js +30 -359
- package/dist/validation.js.map +1 -1
- package/package.json +29 -92
- package/schema/schema.json +174 -244
- package/dist/config/client.cjs +0 -54
- package/dist/config/client.cjs.map +0 -1
- package/dist/config/client.d.ts +0 -23
- package/dist/config/client.js +0 -28
- package/dist/config/client.js.map +0 -1
- package/dist/config/edge.cjs +0 -508
- package/dist/config/edge.cjs.map +0 -1
- package/dist/config/edge.d.ts +0 -20
- package/dist/config/edge.js +0 -481
- package/dist/config/edge.js.map +0 -1
- package/dist/microfrontend-config-983a5139.d.ts +0 -154
- package/dist/schema-2922d49e.d.ts +0 -182
- package/dist/v2/config.cjs +0 -709
- package/dist/v2/config.cjs.map +0 -1
- package/dist/v2/config.d.ts +0 -4
- package/dist/v2/config.js +0 -684
- package/dist/v2/config.js.map +0 -1
- package/dist/v2/microfrontends/server.cjs.map +0 -1
- package/dist/v2/microfrontends/server.js.map +0 -1
- package/dist/v2/microfrontends.cjs.map +0 -1
- package/dist/v2/microfrontends.js.map +0 -1
- package/dist/v2/next/client.cjs +0 -3
- package/dist/v2/next/client.cjs.map +0 -1
- package/dist/v2/next/client.d.ts +0 -45
- package/dist/v2/next/client.js +0 -3
- package/dist/v2/next/client.js.map +0 -1
- package/dist/v2/next/config.cjs +0 -2178
- package/dist/v2/next/config.cjs.map +0 -1
- package/dist/v2/next/config.d.ts +0 -22
- package/dist/v2/next/config.js +0 -2143
- package/dist/v2/next/config.js.map +0 -1
- package/dist/v2/next/endpoints.cjs +0 -141
- package/dist/v2/next/endpoints.cjs.map +0 -1
- package/dist/v2/next/endpoints.d.ts +0 -26
- package/dist/v2/next/endpoints.js +0 -116
- package/dist/v2/next/endpoints.js.map +0 -1
- package/dist/v2/next/middleware.cjs +0 -1099
- package/dist/v2/next/middleware.cjs.map +0 -1
- package/dist/v2/next/middleware.d.ts +0 -34
- package/dist/v2/next/middleware.js +0 -1071
- package/dist/v2/next/middleware.js.map +0 -1
- package/dist/v2/next/testing.cjs +0 -992
- package/dist/v2/next/testing.cjs.map +0 -1
- package/dist/v2/next/testing.d.ts +0 -55
- package/dist/v2/next/testing.js +0 -961
- package/dist/v2/next/testing.js.map +0 -1
- package/dist/v2/overrides.cjs +0 -75
- package/dist/v2/overrides.cjs.map +0 -1
- package/dist/v2/overrides.d.ts +0 -24
- package/dist/v2/overrides.js +0 -45
- package/dist/v2/overrides.js.map +0 -1
- package/dist/v2/routing.cjs.map +0 -1
- package/dist/v2/schema.cjs.map +0 -1
- package/dist/v2/schema.d.ts +0 -1
- package/schema/schema-v2.json +0 -266
- /package/dist/{v2/routing.d.ts → routing.d.ts} +0 -0
- /package/dist/{v2/routing.js → routing.js} +0 -0
- /package/dist/{v2/routing.js.map → routing.js.map} +0 -0
- /package/dist/{v2/schema.js → schema.js} +0 -0
- /package/dist/{v2/schema.js.map → schema.js.map} +0 -0
package/dist/bin/cli.cjs
CHANGED
|
@@ -29,7 +29,7 @@ var import_commander = require("commander");
|
|
|
29
29
|
// package.json
|
|
30
30
|
var package_default = {
|
|
31
31
|
name: "@vercel/microfrontends",
|
|
32
|
-
version: "0.
|
|
32
|
+
version: "0.15.0",
|
|
33
33
|
private: false,
|
|
34
34
|
description: "Defines configuration and utilities for micro-frontend development",
|
|
35
35
|
repository: {
|
|
@@ -53,1335 +53,146 @@ var package_default = {
|
|
|
53
53
|
import: "./dist/config.js",
|
|
54
54
|
require: "./dist/config.cjs"
|
|
55
55
|
},
|
|
56
|
-
"./
|
|
57
|
-
import: "./dist/
|
|
58
|
-
require: "./dist/
|
|
56
|
+
"./microfrontends": {
|
|
57
|
+
import: "./dist/microfrontends.js",
|
|
58
|
+
require: "./dist/microfrontends.cjs"
|
|
59
59
|
},
|
|
60
|
-
"./
|
|
61
|
-
import: "./dist/
|
|
62
|
-
require: "./dist/
|
|
63
|
-
},
|
|
64
|
-
"./
|
|
65
|
-
import: "./dist/
|
|
66
|
-
require: "./dist/
|
|
67
|
-
},
|
|
68
|
-
"./
|
|
69
|
-
import: "./dist/
|
|
70
|
-
require: "./dist/
|
|
71
|
-
},
|
|
72
|
-
"./
|
|
73
|
-
import: "./dist/
|
|
74
|
-
require: "./dist/
|
|
75
|
-
},
|
|
76
|
-
"./next/
|
|
77
|
-
import: "./dist/next/
|
|
78
|
-
require: "./dist/next/
|
|
79
|
-
},
|
|
80
|
-
"./next/
|
|
81
|
-
import: "./dist/next/
|
|
82
|
-
require: "./dist/next/
|
|
83
|
-
},
|
|
84
|
-
"./
|
|
85
|
-
import: "./dist/
|
|
86
|
-
require: "./dist/
|
|
87
|
-
},
|
|
88
|
-
"./
|
|
89
|
-
import: "./dist/
|
|
90
|
-
require: "./dist/
|
|
91
|
-
},
|
|
92
|
-
"./
|
|
93
|
-
import: "./dist/
|
|
94
|
-
require: "./dist/
|
|
95
|
-
},
|
|
96
|
-
"./
|
|
97
|
-
import: "./dist/
|
|
98
|
-
require: "./dist/
|
|
99
|
-
},
|
|
100
|
-
"./v2/microfrontends/server": {
|
|
101
|
-
import: "./dist/v2/microfrontends/server.js",
|
|
102
|
-
require: "./dist/v2/microfrontends/server.cjs"
|
|
103
|
-
},
|
|
104
|
-
"./v2/schema": {
|
|
105
|
-
import: "./dist/v2/schema.js",
|
|
106
|
-
require: "./dist/v2/schema.cjs"
|
|
107
|
-
},
|
|
108
|
-
"./v2/next/config": {
|
|
109
|
-
import: "./dist/v2/next/config.js",
|
|
110
|
-
require: "./dist/v2/next/config.cjs"
|
|
111
|
-
},
|
|
112
|
-
"./v2/next/middleware": {
|
|
113
|
-
import: "./dist/v2/next/middleware.js",
|
|
114
|
-
require: "./dist/v2/next/middleware.cjs"
|
|
115
|
-
},
|
|
116
|
-
"./v2/next/endpoints": {
|
|
117
|
-
import: "./dist/v2/next/endpoints.js",
|
|
118
|
-
require: "./dist/v2/next/endpoints.cjs"
|
|
119
|
-
},
|
|
120
|
-
"./v2/next/testing": {
|
|
121
|
-
import: "./dist/v2/next/testing.js",
|
|
122
|
-
require: "./dist/v2/next/testing.cjs"
|
|
123
|
-
},
|
|
124
|
-
"./next/client": {
|
|
125
|
-
import: "./dist/next/client.js",
|
|
126
|
-
require: "./dist/next/client.cjs"
|
|
127
|
-
},
|
|
128
|
-
"./v2/next/client": {
|
|
129
|
-
import: "./dist/v2/next/client.js",
|
|
130
|
-
require: "./dist/v2/next/client.cjs"
|
|
131
|
-
},
|
|
132
|
-
"./utils/mfe-port": {
|
|
133
|
-
import: "./dist/utils/mfe-port.js",
|
|
134
|
-
require: "./dist/utils/mfe-port.cjs"
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
typesVersions: {
|
|
138
|
-
"*": {
|
|
139
|
-
validation: ["./dist/validation.d.ts"],
|
|
140
|
-
config: ["./dist/config.d.ts"],
|
|
141
|
-
"config/client": ["./dist/config/client.d.ts"],
|
|
142
|
-
"config/edge": ["./dist/config/edge.d.ts"],
|
|
143
|
-
overrides: ["./dist/overrides.d.ts"],
|
|
144
|
-
"next/config": ["./dist/next/config.d.ts"],
|
|
145
|
-
"next/middleware": ["./dist/next/middleware.d.ts"],
|
|
146
|
-
"next/endpoints": ["./dist/next/endpoints.d.ts"],
|
|
147
|
-
"next/testing": ["./dist/next/testing.d.ts"],
|
|
148
|
-
"v2/config": ["./dist/v2/config.d.ts"],
|
|
149
|
-
"v2/microfrontends": ["./dist/v2/microfrontends.d.ts"],
|
|
150
|
-
"v2/overrides": ["./dist/v2/overrides.d.ts"],
|
|
151
|
-
"v2/routing": ["./dist/v2/routing.d.ts"],
|
|
152
|
-
"v2/microfrontends/server": ["./dist/v2/microfrontends/server.d.ts"],
|
|
153
|
-
"v2/schema": ["./dist/v2/schema.d.ts"],
|
|
154
|
-
"v2/next/config": ["./dist/v2/next/config.d.ts"],
|
|
155
|
-
"v2/next/middleware": ["./dist/v2/next/middleware.d.ts"],
|
|
156
|
-
"v2/next/endpoints": ["./dist/v2/next/endpoints.d.ts"],
|
|
157
|
-
"v2/next/testing": ["./dist/v2/next/testing.d.ts"],
|
|
158
|
-
"next/client": ["./dist/next/client.d.ts"],
|
|
159
|
-
"v2/next/client": ["./dist/v2/next/client.d.ts"],
|
|
160
|
-
"utils/mfe-port": ["./dist/utils/mfe-port.d.ts"]
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
files: ["dist", "schema"],
|
|
164
|
-
scripts: {
|
|
165
|
-
build: "tsup",
|
|
166
|
-
postbuild: "pnpm generate:exports",
|
|
167
|
-
"generate:schema": "tsx scripts/generate-json-schema.ts",
|
|
168
|
-
"generate:exports": "tsx scripts/generate-exports/index.ts",
|
|
169
|
-
conformance: "vercel conformance",
|
|
170
|
-
eslint: "eslint-runner",
|
|
171
|
-
"eslint-fix": "eslint-runner --fix",
|
|
172
|
-
prepublishOnly: "pnpm build && pnpm generate:exports && pnpm generate:schema",
|
|
173
|
-
"type-check": "tsc --noEmit",
|
|
174
|
-
"unit-test": "cross-env TZ=UTC jest",
|
|
175
|
-
proxy: "tsx src/proxy/index.ts"
|
|
176
|
-
},
|
|
177
|
-
dependencies: {
|
|
178
|
-
ajv: "^8.17.1",
|
|
179
|
-
commander: "^12.1.0",
|
|
180
|
-
cookie: "0.4.0",
|
|
181
|
-
"fast-glob": "^3.3.2",
|
|
182
|
-
"http-proxy": "^1.18.1",
|
|
183
|
-
"jsonc-parser": "^3.3.1",
|
|
184
|
-
"path-to-regexp": "6.2.1"
|
|
185
|
-
},
|
|
186
|
-
devDependencies: {
|
|
187
|
-
"@edge-runtime/types": "^3.0.2",
|
|
188
|
-
"@pyra/eslint-config": "workspace:*",
|
|
189
|
-
"@pyra/typescript-config": "workspace:*",
|
|
190
|
-
"@testing-library/react": "^15.0.7",
|
|
191
|
-
"@types/cookie": "0.5.1",
|
|
192
|
-
"@types/http-proxy": "^1.17.15",
|
|
193
|
-
"@types/jest": "^29.2.0",
|
|
194
|
-
"@types/json-schema": "^7.0.15",
|
|
195
|
-
"@types/node": "20.11.30",
|
|
196
|
-
"@types/react": "18.3.1",
|
|
197
|
-
"@types/react-dom": "18.3.0",
|
|
198
|
-
"@vercel-private/conformance": "^1.12.2-canary.0",
|
|
199
|
-
jest: "^29.7.0",
|
|
200
|
-
"jest-environment-jsdom": "29.2.2",
|
|
201
|
-
next: "15.2.0-canary.14",
|
|
202
|
-
react: "19.0.0",
|
|
203
|
-
"react-dom": "19.0.0",
|
|
204
|
-
"ts-json-schema-generator": "^1.1.2",
|
|
205
|
-
tsup: "^6.6.2",
|
|
206
|
-
tsx: "^4.6.2",
|
|
207
|
-
typescript: "5.6.3",
|
|
208
|
-
webpack: "5"
|
|
209
|
-
},
|
|
210
|
-
peerDependencies: {
|
|
211
|
-
next: "15.2.0-canary.14",
|
|
212
|
-
react: "19.0.0",
|
|
213
|
-
"react-dom": "19.0.0"
|
|
214
|
-
},
|
|
215
|
-
publishConfig: {
|
|
216
|
-
access: "restricted"
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
// src/bin/local-proxy.ts
|
|
221
|
-
var http = __toESM(require("http"), 1);
|
|
222
|
-
var https = __toESM(require("https"), 1);
|
|
223
|
-
var import_types2 = require("util/types");
|
|
224
|
-
var import_cookie = require("cookie");
|
|
225
|
-
var import_path_to_regexp4 = require("path-to-regexp");
|
|
226
|
-
var import_http_proxy = __toESM(require("http-proxy"), 1);
|
|
227
|
-
|
|
228
|
-
// src/config/types.ts
|
|
229
|
-
var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
|
|
230
|
-
|
|
231
|
-
// src/config/microfrontend-config.ts
|
|
232
|
-
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
233
|
-
|
|
234
|
-
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
235
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
236
|
-
|
|
237
|
-
// src/config-v2/microfrontends/server/constants.ts
|
|
238
|
-
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
239
|
-
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
240
|
-
|
|
241
|
-
// src/utils/is-vercel.ts
|
|
242
|
-
function isVercel() {
|
|
243
|
-
return process.env.VERCEL === "1";
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
247
|
-
function getOutputFilePath() {
|
|
248
|
-
if (isVercel()) {
|
|
249
|
-
return import_node_path.default.join(
|
|
250
|
-
".vercel",
|
|
251
|
-
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
252
|
-
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
return import_node_path.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// src/config/errors.ts
|
|
259
|
-
var MicrofrontendError = class extends Error {
|
|
260
|
-
constructor(message, opts) {
|
|
261
|
-
super(message);
|
|
262
|
-
this.name = "MicrofrontendsError";
|
|
263
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
264
|
-
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
265
|
-
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
266
|
-
Error.captureStackTrace(this, MicrofrontendError);
|
|
267
|
-
}
|
|
268
|
-
isKnown() {
|
|
269
|
-
return this.type !== "unknown";
|
|
270
|
-
}
|
|
271
|
-
isUnknown() {
|
|
272
|
-
return !this.isKnown();
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Converts an error to a MicrofrontendsError.
|
|
276
|
-
* @param original - The original error to convert.
|
|
277
|
-
* @returns The converted MicrofrontendsError.
|
|
278
|
-
*/
|
|
279
|
-
static convert(original, opts) {
|
|
280
|
-
if (opts == null ? void 0 : opts.fileName) {
|
|
281
|
-
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
282
|
-
if (err) {
|
|
283
|
-
return err;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (original.message.includes(
|
|
287
|
-
"Code generation from strings disallowed for this context"
|
|
288
|
-
)) {
|
|
289
|
-
return new MicrofrontendError(original.message, {
|
|
290
|
-
type: "config",
|
|
291
|
-
subtype: "unsupported_validation_env",
|
|
292
|
-
source: "ajv"
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
return new MicrofrontendError(original.message);
|
|
296
|
-
}
|
|
297
|
-
static convertFSError(original, fileName) {
|
|
298
|
-
if (original instanceof Error && "code" in original) {
|
|
299
|
-
if (original.code === "ENOENT") {
|
|
300
|
-
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
301
|
-
type: "config",
|
|
302
|
-
subtype: "unable_to_read_file",
|
|
303
|
-
source: "fs"
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
if (original.code === "EACCES") {
|
|
307
|
-
return new MicrofrontendError(
|
|
308
|
-
`Permission denied while accessing "${fileName}"`,
|
|
309
|
-
{
|
|
310
|
-
type: "config",
|
|
311
|
-
subtype: "invalid_permissions",
|
|
312
|
-
source: "fs"
|
|
313
|
-
}
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (original instanceof SyntaxError) {
|
|
318
|
-
return new MicrofrontendError(
|
|
319
|
-
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
320
|
-
{
|
|
321
|
-
type: "config",
|
|
322
|
-
subtype: "invalid_syntax",
|
|
323
|
-
source: "fs"
|
|
324
|
-
}
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
return null;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
331
|
-
* @param err - The error to handle.
|
|
332
|
-
* @returns A MicrofrontendsError instance.
|
|
333
|
-
*/
|
|
334
|
-
static handle(err, opts) {
|
|
335
|
-
if (err instanceof MicrofrontendError) {
|
|
336
|
-
return err;
|
|
337
|
-
}
|
|
338
|
-
if (err instanceof Error) {
|
|
339
|
-
return MicrofrontendError.convert(err, opts);
|
|
340
|
-
}
|
|
341
|
-
if (typeof err === "object" && err !== null) {
|
|
342
|
-
if ("message" in err && typeof err.message === "string") {
|
|
343
|
-
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return new MicrofrontendError("An unknown error occurred");
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
// src/routing/url.ts
|
|
351
|
-
function buildUrlSafeString(givenOpts = {}) {
|
|
352
|
-
const options = {
|
|
353
|
-
joinString: "-",
|
|
354
|
-
lowercaseOnly: true,
|
|
355
|
-
maxLen: 100,
|
|
356
|
-
regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,
|
|
357
|
-
trimWhitespace: true,
|
|
358
|
-
...givenOpts
|
|
359
|
-
};
|
|
360
|
-
return {
|
|
361
|
-
generate: (...args) => {
|
|
362
|
-
const reJoinString = new RegExp(`${options.joinString}+`, "g");
|
|
363
|
-
let tag;
|
|
364
|
-
if (args.length === 0) {
|
|
365
|
-
throw new Error("generate method must be passed at least one argument");
|
|
366
|
-
}
|
|
367
|
-
for (let i = 0; i < args.length; i++) {
|
|
368
|
-
const arg = args[i];
|
|
369
|
-
if (typeof arg !== "string")
|
|
370
|
-
throw new Error("all supplied arguments must be Strings");
|
|
371
|
-
if (options.trimWhitespace) {
|
|
372
|
-
args[i] = arg.trim();
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
tag = args.join(options.joinString);
|
|
376
|
-
tag = tag.replace(/\s/g, options.joinString);
|
|
377
|
-
if (options.lowercaseOnly)
|
|
378
|
-
tag = tag.toLowerCase();
|
|
379
|
-
tag = tag.replace(options.regexRemovePattern, (match) => {
|
|
380
|
-
if (match === options.joinString)
|
|
381
|
-
return match;
|
|
382
|
-
return "";
|
|
383
|
-
});
|
|
384
|
-
if (tag.length > options.maxLen)
|
|
385
|
-
tag = tag.substring(0, options.maxLen);
|
|
386
|
-
tag = tag.replace(reJoinString, options.joinString);
|
|
387
|
-
return tag;
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
var urlSafeString = buildUrlSafeString().generate;
|
|
392
|
-
function makeUrlSafe(name) {
|
|
393
|
-
return urlSafeString(name.replace(/\//g, "-")).replace(/^-*/g, "").replace(/-*$/g, "");
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// src/config/overrides/config.ts
|
|
397
|
-
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
398
|
-
var _Overrides = class {
|
|
399
|
-
constructor(config) {
|
|
400
|
-
this.config = config;
|
|
401
|
-
}
|
|
402
|
-
static getAppEnvOverrideCookieName(zone) {
|
|
403
|
-
return `${_Overrides.overrideEnvCookiePrefix}${zone}`;
|
|
404
|
-
}
|
|
405
|
-
static isOverrideCookie(cookie) {
|
|
406
|
-
var _a;
|
|
407
|
-
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
408
|
-
}
|
|
409
|
-
static getOverrideFromCookie(cookie) {
|
|
410
|
-
if (!_Overrides.isOverrideCookie(cookie) || !cookie.value)
|
|
411
|
-
return;
|
|
412
|
-
return {
|
|
413
|
-
zone: cookie.name.replace(_Overrides.overrideEnvCookiePrefix, ""),
|
|
414
|
-
host: cookie.value
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
static parseOverrides(cookies) {
|
|
418
|
-
const overridesConfig = { applications: {} };
|
|
419
|
-
cookies.forEach((cookie) => {
|
|
420
|
-
const override = _Overrides.getOverrideFromCookie(cookie);
|
|
421
|
-
if (!override)
|
|
422
|
-
return;
|
|
423
|
-
overridesConfig.applications[override.zone] = {
|
|
424
|
-
environment: { host: override.host }
|
|
425
|
-
};
|
|
426
|
-
});
|
|
427
|
-
return overridesConfig;
|
|
428
|
-
}
|
|
429
|
-
static validOverrideDomainsForZone(microfrontendConfig, zone) {
|
|
430
|
-
var _a, _b, _c, _d, _e;
|
|
431
|
-
const projectName = (_a = microfrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
432
|
-
if (!projectName) {
|
|
433
|
-
return [microfrontendConfig.getZone(zone).production.host];
|
|
434
|
-
}
|
|
435
|
-
const parsedProjectName = makeUrlSafe(projectName);
|
|
436
|
-
const previewDeploymentSuffix = (_c = (_b = microfrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
|
|
437
|
-
const teamSlug = (_e = (_d = microfrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
|
|
438
|
-
if (!teamSlug && !previewDeploymentSuffix) {
|
|
439
|
-
return [microfrontendConfig.getZone(zone).production.host];
|
|
440
|
-
}
|
|
441
|
-
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
442
|
-
return [
|
|
443
|
-
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
444
|
-
microfrontendConfig.getZone(zone).production.host
|
|
445
|
-
];
|
|
446
|
-
}
|
|
447
|
-
static validateOverrideDomain(microfrontendConfig, zone, domain) {
|
|
448
|
-
return new RegExp(
|
|
449
|
-
`^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
|
|
450
|
-
"|"
|
|
451
|
-
)}$`
|
|
452
|
-
).test(domain);
|
|
453
|
-
}
|
|
454
|
-
serialize() {
|
|
455
|
-
return this.config;
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
var Overrides = _Overrides;
|
|
459
|
-
Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
460
|
-
|
|
461
|
-
// src/config/common/host.ts
|
|
462
|
-
var Host = class {
|
|
463
|
-
constructor({ protocol, host, port }) {
|
|
464
|
-
this.protocol = protocol || "https";
|
|
465
|
-
this.host = host;
|
|
466
|
-
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
467
|
-
this.serialized = {
|
|
468
|
-
protocol,
|
|
469
|
-
host,
|
|
470
|
-
...port ? { port } : void 0
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
isLocal() {
|
|
474
|
-
return this.host === "localhost" || this.host === "127.0.0.1";
|
|
475
|
-
}
|
|
476
|
-
static getPort({
|
|
477
|
-
protocol,
|
|
478
|
-
port
|
|
479
|
-
}) {
|
|
480
|
-
if (!port) {
|
|
481
|
-
if (protocol === "http") {
|
|
482
|
-
return 80;
|
|
483
|
-
}
|
|
484
|
-
return 443;
|
|
485
|
-
}
|
|
486
|
-
return port;
|
|
487
|
-
}
|
|
488
|
-
isDefaultPort() {
|
|
489
|
-
return this.port === Host.getPort({ protocol: this.protocol });
|
|
490
|
-
}
|
|
491
|
-
toString(opts = {}) {
|
|
492
|
-
const url = this.toUrl(opts);
|
|
493
|
-
return url.toString().replace(/\/$/, "");
|
|
494
|
-
}
|
|
495
|
-
toUrl(opts = {}) {
|
|
496
|
-
const { includeDefaultPort } = opts;
|
|
497
|
-
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
498
|
-
return new URL(url);
|
|
499
|
-
}
|
|
500
|
-
serialize() {
|
|
501
|
-
return this.serialized;
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
// src/config/common/application.ts
|
|
506
|
-
var Application = class {
|
|
507
|
-
constructor(name, {
|
|
508
|
-
app,
|
|
509
|
-
overrides
|
|
510
|
-
}) {
|
|
511
|
-
Application.validate(name, app);
|
|
512
|
-
this.name = name;
|
|
513
|
-
this.default = app.default;
|
|
514
|
-
this.routing = app.routing;
|
|
515
|
-
this.development = {
|
|
516
|
-
local: new Host(app.development.local),
|
|
517
|
-
fallback: app.development.fallback ? new Host(app.development.fallback) : void 0
|
|
518
|
-
};
|
|
519
|
-
this.production = new Host(app.production);
|
|
520
|
-
this.vercel = app.vercel;
|
|
521
|
-
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
522
|
-
environment: new Host(overrides.environment)
|
|
523
|
-
} : void 0;
|
|
524
|
-
}
|
|
525
|
-
isDefault() {
|
|
526
|
-
return this.default;
|
|
527
|
-
}
|
|
528
|
-
static validate(name, app) {
|
|
529
|
-
var _a, _b, _c, _d, _e;
|
|
530
|
-
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("/"))) {
|
|
531
|
-
throw new MicrofrontendError(
|
|
532
|
-
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
533
|
-
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
534
|
-
);
|
|
535
|
-
}
|
|
536
|
-
for (const group of ((_e = app.routing) == null ? void 0 : _e.matches) ?? []) {
|
|
537
|
-
for (const p of group.paths) {
|
|
538
|
-
if (p === "/") {
|
|
539
|
-
continue;
|
|
540
|
-
}
|
|
541
|
-
if (p.endsWith("/")) {
|
|
542
|
-
throw new MicrofrontendError(
|
|
543
|
-
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
544
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
545
|
-
);
|
|
546
|
-
}
|
|
547
|
-
if (!p.startsWith("/")) {
|
|
548
|
-
throw new MicrofrontendError(
|
|
549
|
-
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
550
|
-
{ type: "zone", subtype: "invalid_path" }
|
|
551
|
-
);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
serialize() {
|
|
557
|
-
var _a, _b;
|
|
558
|
-
if (this.routing === void 0 || this.default) {
|
|
559
|
-
return {
|
|
560
|
-
default: true,
|
|
561
|
-
development: {
|
|
562
|
-
local: this.development.local.serialize(),
|
|
563
|
-
fallback: (_a = this.development.fallback) == null ? void 0 : _a.serialize()
|
|
564
|
-
},
|
|
565
|
-
production: this.production.serialize(),
|
|
566
|
-
vercel: this.vercel
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
return {
|
|
570
|
-
default: false,
|
|
571
|
-
routing: this.routing,
|
|
572
|
-
development: {
|
|
573
|
-
local: this.development.local.serialize(),
|
|
574
|
-
fallback: (_b = this.development.fallback) == null ? void 0 : _b.serialize()
|
|
575
|
-
},
|
|
576
|
-
production: this.production.serialize(),
|
|
577
|
-
vercel: this.vercel
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
// src/config/common/microfrontend-config.ts
|
|
583
|
-
var SUPPORTED_VERSIONS = ["1"];
|
|
584
|
-
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
585
|
-
var MicrofrontendConfigCommon = class {
|
|
586
|
-
constructor({
|
|
587
|
-
config,
|
|
588
|
-
overrides
|
|
589
|
-
}) {
|
|
590
|
-
this.zones = {};
|
|
591
|
-
var _a, _b, _c;
|
|
592
|
-
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
593
|
-
throw new MicrofrontendError(
|
|
594
|
-
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
595
|
-
", "
|
|
596
|
-
)}`,
|
|
597
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
601
|
-
this.overrides = overrides && !disableOverrides ? new Overrides(overrides) : void 0;
|
|
602
|
-
for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {
|
|
603
|
-
this.zones[zoneName] = new Application(zoneName, {
|
|
604
|
-
app: zoneConfig,
|
|
605
|
-
overrides: !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.config.applications[zoneName] : void 0
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
this.config = config;
|
|
609
|
-
this.name = config.name;
|
|
610
|
-
this.version = config.version;
|
|
611
|
-
this.options = config.options;
|
|
612
|
-
this.$schema = config.$schema;
|
|
613
|
-
}
|
|
614
|
-
isOverridesDisabled() {
|
|
615
|
-
var _a, _b;
|
|
616
|
-
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
617
|
-
}
|
|
618
|
-
static getConfigFromEnv() {
|
|
619
|
-
const config = process.env.MFE_CONFIG;
|
|
620
|
-
if (!config) {
|
|
621
|
-
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
622
|
-
type: "config",
|
|
623
|
-
subtype: "not_found_in_env"
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
return config;
|
|
627
|
-
}
|
|
628
|
-
static fromEnv(_) {
|
|
629
|
-
throw new Error("Not implemented");
|
|
630
|
-
}
|
|
631
|
-
getConfig() {
|
|
632
|
-
return this.config;
|
|
633
|
-
}
|
|
634
|
-
getAllApplications() {
|
|
635
|
-
return Object.values(this.zones);
|
|
636
|
-
}
|
|
637
|
-
getZone(name) {
|
|
638
|
-
const zone = this.zones[name];
|
|
639
|
-
if (!zone) {
|
|
640
|
-
throw new MicrofrontendError(
|
|
641
|
-
`Could not find microfrontends configuration for application "${name}"`,
|
|
642
|
-
{
|
|
643
|
-
type: "zone",
|
|
644
|
-
subtype: "not_found"
|
|
645
|
-
}
|
|
646
|
-
);
|
|
647
|
-
}
|
|
648
|
-
return zone;
|
|
649
|
-
}
|
|
650
|
-
getApplicationByProjectId(projectId) {
|
|
651
|
-
return Object.values(this.zones).find(
|
|
652
|
-
(zone) => {
|
|
653
|
-
var _a;
|
|
654
|
-
return ((_a = zone.vercel) == null ? void 0 : _a.projectId) === projectId;
|
|
655
|
-
}
|
|
656
|
-
);
|
|
657
|
-
}
|
|
658
|
-
getDefaultZone() {
|
|
659
|
-
const zone = Object.values(this.zones).find((z) => z.default);
|
|
660
|
-
if (!zone) {
|
|
661
|
-
throw new MicrofrontendError(
|
|
662
|
-
`Could not find default zone in microfrontends configuration`,
|
|
663
|
-
{
|
|
664
|
-
type: "zone",
|
|
665
|
-
subtype: "not_found"
|
|
666
|
-
}
|
|
667
|
-
);
|
|
668
|
-
}
|
|
669
|
-
return zone;
|
|
670
|
-
}
|
|
671
|
-
/**
|
|
672
|
-
* Returns the configured port for the local proxy
|
|
673
|
-
*/
|
|
674
|
-
getLocalProxyPort() {
|
|
675
|
-
var _a, _b;
|
|
676
|
-
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* Serializes the class back to the Schema type.
|
|
680
|
-
*
|
|
681
|
-
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
682
|
-
*/
|
|
683
|
-
toSchemaJson() {
|
|
684
|
-
const applications = {};
|
|
685
|
-
for (const [name, zone] of Object.entries(this.zones)) {
|
|
686
|
-
applications[name] = zone.serialize();
|
|
687
|
-
}
|
|
688
|
-
return {
|
|
689
|
-
$schema: this.$schema,
|
|
690
|
-
name: this.name,
|
|
691
|
-
version: this.version,
|
|
692
|
-
options: this.options,
|
|
693
|
-
applications
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
serialize() {
|
|
697
|
-
var _a;
|
|
698
|
-
const applications = {};
|
|
699
|
-
for (const [name, zone] of Object.entries(this.zones)) {
|
|
700
|
-
applications[name] = zone.serialize();
|
|
701
|
-
}
|
|
702
|
-
return {
|
|
703
|
-
config: {
|
|
704
|
-
name: this.name,
|
|
705
|
-
version: this.version,
|
|
706
|
-
applications,
|
|
707
|
-
options: this.options,
|
|
708
|
-
$schema: this.$schema
|
|
709
|
-
},
|
|
710
|
-
overrides: (_a = this.overrides) == null ? void 0 : _a.serialize()
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
write(_) {
|
|
714
|
-
throw new MicrofrontendError(
|
|
715
|
-
`Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
|
|
716
|
-
{ type: "config", subtype: "unsupported_operation" }
|
|
717
|
-
);
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
// src/config/utils/get-output-file-path.ts
|
|
722
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
723
|
-
|
|
724
|
-
// src/config/constants.ts
|
|
725
|
-
var MFE_CONFIG_DEFAULT_FILE_PATH2 = "micro-frontends";
|
|
726
|
-
var MFE_CONFIG_DEFAULT_FILE_NAME2 = "micro-frontends.config.json";
|
|
727
|
-
|
|
728
|
-
// src/config/utils/get-output-file-path.ts
|
|
729
|
-
function getOutputFilePath2() {
|
|
730
|
-
if (isVercel()) {
|
|
731
|
-
return import_node_path2.default.join(
|
|
732
|
-
".vercel",
|
|
733
|
-
MFE_CONFIG_DEFAULT_FILE_PATH2,
|
|
734
|
-
MFE_CONFIG_DEFAULT_FILE_NAME2
|
|
735
|
-
);
|
|
736
|
-
}
|
|
737
|
-
return import_node_path2.default.join(MFE_CONFIG_DEFAULT_FILE_PATH2, MFE_CONFIG_DEFAULT_FILE_NAME2);
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
// src/config/validation.ts
|
|
741
|
-
var import_jsonc_parser = require("jsonc-parser");
|
|
742
|
-
var import_path_to_regexp = require("path-to-regexp");
|
|
743
|
-
var import_ajv = require("ajv");
|
|
744
|
-
|
|
745
|
-
// schema/schema.json
|
|
746
|
-
var schema_default = {
|
|
747
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
748
|
-
$ref: "#/definitions/Config",
|
|
749
|
-
definitions: {
|
|
750
|
-
Config: {
|
|
751
|
-
type: "object",
|
|
752
|
-
properties: {
|
|
753
|
-
version: {
|
|
754
|
-
type: "string"
|
|
755
|
-
},
|
|
756
|
-
$schema: {
|
|
757
|
-
type: "string"
|
|
758
|
-
},
|
|
759
|
-
name: {
|
|
760
|
-
type: "string",
|
|
761
|
-
description: 'Name for the micro-frontend site (eg. "vercel.com", "vercel-site" etc.).'
|
|
762
|
-
},
|
|
763
|
-
applications: {
|
|
764
|
-
$ref: "#/definitions/ApplicationConfigsById"
|
|
765
|
-
},
|
|
766
|
-
options: {
|
|
767
|
-
$ref: "#/definitions/Options",
|
|
768
|
-
description: "Optional configuration for the entire micro-frontends setup."
|
|
769
|
-
}
|
|
770
|
-
},
|
|
771
|
-
required: ["version", "applications"],
|
|
772
|
-
description: "Configuration for micro-frontend applications\n\nTODO: Add proxy configuration"
|
|
773
|
-
},
|
|
774
|
-
ApplicationConfigsById: {
|
|
775
|
-
type: "object",
|
|
776
|
-
additionalProperties: {
|
|
777
|
-
$ref: "#/definitions/ApplicationConfig"
|
|
778
|
-
}
|
|
779
|
-
},
|
|
780
|
-
ApplicationConfig: {
|
|
781
|
-
anyOf: [
|
|
782
|
-
{
|
|
783
|
-
$ref: "#/definitions/DefaultApplicationConfig"
|
|
784
|
-
},
|
|
785
|
-
{
|
|
786
|
-
$ref: "#/definitions/CommonApplicationConfig"
|
|
787
|
-
}
|
|
788
|
-
],
|
|
789
|
-
description: "A Micro-Frontend Deployment Target"
|
|
790
|
-
},
|
|
791
|
-
DefaultApplicationConfig: {
|
|
792
|
-
type: "object",
|
|
793
|
-
properties: {
|
|
794
|
-
default: {
|
|
795
|
-
type: "boolean",
|
|
796
|
-
const: true,
|
|
797
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
798
|
-
},
|
|
799
|
-
routing: {
|
|
800
|
-
$ref: "#/definitions/Routing"
|
|
801
|
-
},
|
|
802
|
-
development: {
|
|
803
|
-
type: "object",
|
|
804
|
-
properties: {
|
|
805
|
-
local: {
|
|
806
|
-
$ref: "#/definitions/HostConfig"
|
|
807
|
-
},
|
|
808
|
-
fallback: {
|
|
809
|
-
$ref: "#/definitions/HostConfig",
|
|
810
|
-
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."
|
|
811
|
-
},
|
|
812
|
-
task: {
|
|
813
|
-
type: "string",
|
|
814
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
815
|
-
}
|
|
816
|
-
},
|
|
817
|
-
required: ["local"]
|
|
818
|
-
},
|
|
819
|
-
production: {
|
|
820
|
-
$ref: "#/definitions/HostConfig"
|
|
821
|
-
},
|
|
822
|
-
metadata: {
|
|
823
|
-
type: "object",
|
|
824
|
-
additionalProperties: {
|
|
825
|
-
type: "string"
|
|
826
|
-
}
|
|
827
|
-
},
|
|
828
|
-
federation: {
|
|
829
|
-
type: "object",
|
|
830
|
-
properties: {
|
|
831
|
-
exposes: {
|
|
832
|
-
type: "array",
|
|
833
|
-
items: {
|
|
834
|
-
type: "object",
|
|
835
|
-
properties: {
|
|
836
|
-
name: {
|
|
837
|
-
type: "string",
|
|
838
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
839
|
-
},
|
|
840
|
-
path: {
|
|
841
|
-
type: "string",
|
|
842
|
-
description: "Relative path to the module within its `application`"
|
|
843
|
-
}
|
|
844
|
-
},
|
|
845
|
-
required: ["name", "path"]
|
|
846
|
-
},
|
|
847
|
-
description: "Modules that are exposed by this application"
|
|
848
|
-
},
|
|
849
|
-
uses: {
|
|
850
|
-
type: "array",
|
|
851
|
-
items: {
|
|
852
|
-
type: "string"
|
|
853
|
-
},
|
|
854
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
},
|
|
858
|
-
vercel: {
|
|
859
|
-
$ref: "#/definitions/Vercel"
|
|
860
|
-
}
|
|
861
|
-
},
|
|
862
|
-
required: ["default", "development", "production"]
|
|
863
|
-
},
|
|
864
|
-
Routing: {
|
|
865
|
-
type: "object",
|
|
866
|
-
properties: {
|
|
867
|
-
assetPrefix: {
|
|
868
|
-
type: "string",
|
|
869
|
-
description: "[assetPrefix] for the application"
|
|
870
|
-
},
|
|
871
|
-
matches: {
|
|
872
|
-
type: "array",
|
|
873
|
-
items: {
|
|
874
|
-
$ref: "#/definitions/PathGroup"
|
|
875
|
-
},
|
|
876
|
-
description: "Path expressions that are routed to this application."
|
|
877
|
-
}
|
|
878
|
-
},
|
|
879
|
-
required: ["matches"]
|
|
880
|
-
},
|
|
881
|
-
PathGroup: {
|
|
882
|
-
type: "object",
|
|
883
|
-
properties: {
|
|
884
|
-
group: {
|
|
885
|
-
type: "string",
|
|
886
|
-
description: "Optional group name for the paths"
|
|
887
|
-
},
|
|
888
|
-
options: {
|
|
889
|
-
type: "object",
|
|
890
|
-
properties: {
|
|
891
|
-
flag: {
|
|
892
|
-
type: "string",
|
|
893
|
-
description: "flag name that can be used to enable/disable all paths in the group"
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
},
|
|
897
|
-
paths: {
|
|
898
|
-
type: "array",
|
|
899
|
-
items: {
|
|
900
|
-
type: "string"
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
},
|
|
904
|
-
required: ["paths"]
|
|
905
|
-
},
|
|
906
|
-
HostConfig: {
|
|
907
|
-
type: "object",
|
|
908
|
-
properties: {
|
|
909
|
-
protocol: {
|
|
910
|
-
type: "string",
|
|
911
|
-
enum: ["http", "https"],
|
|
912
|
-
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"'
|
|
913
|
-
},
|
|
914
|
-
host: {
|
|
915
|
-
type: "string",
|
|
916
|
-
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`)."
|
|
917
|
-
},
|
|
918
|
-
port: {
|
|
919
|
-
type: "number",
|
|
920
|
-
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"
|
|
921
|
-
}
|
|
922
|
-
},
|
|
923
|
-
required: ["host"]
|
|
924
|
-
},
|
|
925
|
-
Vercel: {
|
|
926
|
-
type: "object",
|
|
927
|
-
properties: {
|
|
928
|
-
projectId: {
|
|
929
|
-
type: "string",
|
|
930
|
-
description: "Vercel project ID"
|
|
931
|
-
},
|
|
932
|
-
projectName: {
|
|
933
|
-
type: "string",
|
|
934
|
-
description: "Vercel project name (temporary until we can use project ID)"
|
|
935
|
-
},
|
|
936
|
-
defaultRoute: {
|
|
937
|
-
type: "string",
|
|
938
|
-
description: "The default route for the application. Used to render screenshots, favicons, and provide direct zone links"
|
|
939
|
-
},
|
|
940
|
-
routeSpeedInsightsToDefaultZone: {
|
|
941
|
-
type: "boolean",
|
|
942
|
-
description: "Whether to route Speed Insights to the default zone or each individual microfrontend."
|
|
943
|
-
}
|
|
944
|
-
},
|
|
945
|
-
required: ["projectId"]
|
|
946
|
-
},
|
|
947
|
-
CommonApplicationConfig: {
|
|
948
|
-
type: "object",
|
|
949
|
-
properties: {
|
|
950
|
-
default: {
|
|
951
|
-
type: "boolean",
|
|
952
|
-
const: false,
|
|
953
|
-
description: "The default application is used no other application is matched via the routing config"
|
|
954
|
-
},
|
|
955
|
-
routing: {
|
|
956
|
-
$ref: "#/definitions/Routing"
|
|
957
|
-
},
|
|
958
|
-
development: {
|
|
959
|
-
type: "object",
|
|
960
|
-
properties: {
|
|
961
|
-
local: {
|
|
962
|
-
$ref: "#/definitions/HostConfig"
|
|
963
|
-
},
|
|
964
|
-
fallback: {
|
|
965
|
-
$ref: "#/definitions/HostConfig",
|
|
966
|
-
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."
|
|
967
|
-
},
|
|
968
|
-
task: {
|
|
969
|
-
type: "string",
|
|
970
|
-
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
971
|
-
}
|
|
972
|
-
},
|
|
973
|
-
required: ["local"]
|
|
974
|
-
},
|
|
975
|
-
production: {
|
|
976
|
-
$ref: "#/definitions/HostConfig"
|
|
977
|
-
},
|
|
978
|
-
metadata: {
|
|
979
|
-
type: "object",
|
|
980
|
-
additionalProperties: {
|
|
981
|
-
type: "string"
|
|
982
|
-
}
|
|
983
|
-
},
|
|
984
|
-
federation: {
|
|
985
|
-
type: "object",
|
|
986
|
-
properties: {
|
|
987
|
-
exposes: {
|
|
988
|
-
type: "array",
|
|
989
|
-
items: {
|
|
990
|
-
type: "object",
|
|
991
|
-
properties: {
|
|
992
|
-
name: {
|
|
993
|
-
type: "string",
|
|
994
|
-
description: "The name of the module - should be used when importing the module from another application"
|
|
995
|
-
},
|
|
996
|
-
path: {
|
|
997
|
-
type: "string",
|
|
998
|
-
description: "Relative path to the module within its `application`"
|
|
999
|
-
}
|
|
1000
|
-
},
|
|
1001
|
-
required: ["name", "path"]
|
|
1002
|
-
},
|
|
1003
|
-
description: "Modules that are exposed by this application"
|
|
1004
|
-
},
|
|
1005
|
-
uses: {
|
|
1006
|
-
type: "array",
|
|
1007
|
-
items: {
|
|
1008
|
-
type: "string"
|
|
1009
|
-
},
|
|
1010
|
-
description: "Modules that are used by this application. Only the name of the module is required."
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
},
|
|
1014
|
-
vercel: {
|
|
1015
|
-
$ref: "#/definitions/Vercel"
|
|
1016
|
-
}
|
|
1017
|
-
},
|
|
1018
|
-
required: ["default", "development", "production", "routing"]
|
|
1019
|
-
},
|
|
1020
|
-
Options: {
|
|
1021
|
-
type: "object",
|
|
1022
|
-
properties: {
|
|
1023
|
-
vercel: {
|
|
1024
|
-
$ref: "#/definitions/VercelOptions",
|
|
1025
|
-
description: "Micro-Frontends wide options for Vercel."
|
|
1026
|
-
},
|
|
1027
|
-
localProxy: {
|
|
1028
|
-
$ref: "#/definitions/LocalProxyOptions",
|
|
1029
|
-
description: "Options for local proxy."
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
},
|
|
1033
|
-
VercelOptions: {
|
|
1034
|
-
type: "object",
|
|
1035
|
-
properties: {
|
|
1036
|
-
previewDeploymentSuffix: {
|
|
1037
|
-
type: "string",
|
|
1038
|
-
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`."
|
|
1039
|
-
},
|
|
1040
|
-
teamSlug: {
|
|
1041
|
-
type: "string",
|
|
1042
|
-
description: "Team slug for the Vercel team"
|
|
1043
|
-
},
|
|
1044
|
-
disableOverrides: {
|
|
1045
|
-
type: "boolean",
|
|
1046
|
-
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."
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
},
|
|
1050
|
-
LocalProxyOptions: {
|
|
1051
|
-
type: "object",
|
|
1052
|
-
properties: {
|
|
1053
|
-
port: {
|
|
1054
|
-
type: "number",
|
|
1055
|
-
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
// src/config/utils/load-schema.ts
|
|
1063
|
-
var SCHEMA = schema_default;
|
|
1064
|
-
|
|
1065
|
-
// src/config/validation.ts
|
|
1066
|
-
var validateSchema = (configString) => {
|
|
1067
|
-
const parsedConfig = (0, import_jsonc_parser.parse)(configString);
|
|
1068
|
-
const ajv = new import_ajv.Ajv();
|
|
1069
|
-
const validate = ajv.compile(SCHEMA);
|
|
1070
|
-
const isValid = validate(parsedConfig);
|
|
1071
|
-
if (!isValid) {
|
|
1072
|
-
throw new MicrofrontendError(
|
|
1073
|
-
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
1074
|
-
{ type: "config", subtype: "does_not_match_schema" }
|
|
1075
|
-
);
|
|
1076
|
-
}
|
|
1077
|
-
return parsedConfig;
|
|
1078
|
-
};
|
|
1079
|
-
var SUPPORTED_VERSIONS2 = ["1"];
|
|
1080
|
-
var validateVersion = (version) => {
|
|
1081
|
-
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
1082
|
-
throw new MicrofrontendError(
|
|
1083
|
-
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
1084
|
-
", "
|
|
1085
|
-
)}`,
|
|
1086
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
1087
|
-
);
|
|
1088
|
-
}
|
|
1089
|
-
};
|
|
1090
|
-
function validateMainPath(applicationConfigsById) {
|
|
1091
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
1092
|
-
const { defaultRoute } = app.vercel ?? {};
|
|
1093
|
-
if (!defaultRoute) {
|
|
1094
|
-
continue;
|
|
1095
|
-
}
|
|
1096
|
-
if (isDefaultApplicationConfig(app)) {
|
|
1097
|
-
const pathsWithApp = [];
|
|
1098
|
-
for (const [otherId, otherApp] of Object.entries(
|
|
1099
|
-
applicationConfigsById
|
|
1100
|
-
)) {
|
|
1101
|
-
if (isDefaultApplicationConfig(otherApp)) {
|
|
1102
|
-
continue;
|
|
1103
|
-
}
|
|
1104
|
-
pathsWithApp.push({
|
|
1105
|
-
id: otherId,
|
|
1106
|
-
paths: otherApp.routing.matches.flatMap((match) => match.paths)
|
|
1107
|
-
});
|
|
1108
|
-
}
|
|
1109
|
-
for (const { id: otherId, paths } of pathsWithApp) {
|
|
1110
|
-
const isValid = paths.every((path7) => {
|
|
1111
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(path7);
|
|
1112
|
-
return !matcher.test(defaultRoute);
|
|
1113
|
-
});
|
|
1114
|
-
if (!isValid) {
|
|
1115
|
-
throw new MicrofrontendError(
|
|
1116
|
-
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
1117
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
1118
|
-
);
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
} else {
|
|
1122
|
-
const allPaths = app.routing.matches.flatMap((match) => match.paths);
|
|
1123
|
-
const isValid = allPaths.some((path7) => {
|
|
1124
|
-
const matcher = (0, import_path_to_regexp.pathToRegexp)(path7);
|
|
1125
|
-
return matcher.test(defaultRoute);
|
|
1126
|
-
});
|
|
1127
|
-
if (!isValid) {
|
|
1128
|
-
throw new MicrofrontendError(
|
|
1129
|
-
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
1130
|
-
{ type: "config", subtype: "invalid_main_path" }
|
|
1131
|
-
);
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
var validatePaths = (applicationConfigsById) => {
|
|
1137
|
-
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
1138
|
-
const errors = [];
|
|
1139
|
-
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
1140
|
-
if (isDefaultApplicationConfig(app)) {
|
|
1141
|
-
continue;
|
|
1142
|
-
}
|
|
1143
|
-
for (const pathMatch of app.routing.matches) {
|
|
1144
|
-
for (const path7 of pathMatch.paths) {
|
|
1145
|
-
const maybeError = validatePathExpression(path7);
|
|
1146
|
-
if (maybeError) {
|
|
1147
|
-
errors.push(maybeError);
|
|
1148
|
-
}
|
|
1149
|
-
const existing = pathsByApplicationId.get(path7);
|
|
1150
|
-
if (existing) {
|
|
1151
|
-
existing.applications.push(id);
|
|
1152
|
-
} else {
|
|
1153
|
-
pathsByApplicationId.set(path7, {
|
|
1154
|
-
applications: [id],
|
|
1155
|
-
matcher: (0, import_path_to_regexp.pathToRegexp)(path7),
|
|
1156
|
-
applicationId: id
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
const entries = Array.from(pathsByApplicationId.entries());
|
|
1163
|
-
entries.forEach(([path7, { applications: ids, matcher, applicationId }]) => {
|
|
1164
|
-
if (ids.length > 1) {
|
|
1165
|
-
errors.push(
|
|
1166
|
-
`Duplicate path "${path7}" for applications "${ids.join(", ")}"`
|
|
1167
|
-
);
|
|
1168
|
-
}
|
|
1169
|
-
entries.forEach(
|
|
1170
|
-
([
|
|
1171
|
-
matchPath,
|
|
1172
|
-
{ applications: matchIds, applicationId: matchApplicationId }
|
|
1173
|
-
]) => {
|
|
1174
|
-
if (path7 === matchPath) {
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
if (applicationId === matchApplicationId) {
|
|
1178
|
-
return;
|
|
1179
|
-
}
|
|
1180
|
-
if (matcher.test(matchPath)) {
|
|
1181
|
-
const source = `"${path7}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
1182
|
-
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
1183
|
-
errors.push(
|
|
1184
|
-
`Overlapping path detected between ${source} and ${destination}`
|
|
1185
|
-
);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
);
|
|
1189
|
-
});
|
|
1190
|
-
if (errors.length) {
|
|
1191
|
-
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1192
|
-
type: "config",
|
|
1193
|
-
subtype: "conflicting_paths"
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
};
|
|
1197
|
-
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
1198
|
-
function validatePathExpression(path7) {
|
|
1199
|
-
const tokens = (0, import_path_to_regexp.parse)(path7);
|
|
1200
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
1201
|
-
const token = tokens[i];
|
|
1202
|
-
if (token === void 0) {
|
|
1203
|
-
return `token ${i} in ${path7} is undefined, this shouldn't happen`;
|
|
1204
|
-
}
|
|
1205
|
-
if (typeof token !== "string") {
|
|
1206
|
-
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
1207
|
-
return `Path ${path7} cannot use a regular expression wildcard`;
|
|
1208
|
-
}
|
|
1209
|
-
if (token.prefix !== "/") {
|
|
1210
|
-
return `Wildcard :${token.name} must be immediately after a / in ${path7}`;
|
|
1211
|
-
}
|
|
1212
|
-
if (token.suffix) {
|
|
1213
|
-
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
1214
|
-
}
|
|
1215
|
-
if (token.modifier && i !== tokens.length - 1) {
|
|
1216
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path7}. Modifiers are only allowed in the last path component`;
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
return void 0;
|
|
1221
|
-
}
|
|
1222
|
-
var validateDefaults = (applicationConfigsById) => {
|
|
1223
|
-
const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
|
|
1224
|
-
if (defaultApplicationIds.length === 0) {
|
|
1225
|
-
throw new MicrofrontendError(
|
|
1226
|
-
`No default application found. At least one application must be marked as default.`,
|
|
1227
|
-
{ type: "config", subtype: "no_default_application" }
|
|
1228
|
-
);
|
|
1229
|
-
}
|
|
1230
|
-
if (defaultApplicationIds.length > 1) {
|
|
1231
|
-
throw new MicrofrontendError(
|
|
1232
|
-
`Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
|
|
1233
|
-
{ type: "config", subtype: "multiple_default_applications" }
|
|
1234
|
-
);
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
|
-
var validateOptions = (options) => {
|
|
1238
|
-
var _a;
|
|
1239
|
-
if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
|
|
1240
|
-
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1241
|
-
options.vercel.previewDeploymentSuffix
|
|
1242
|
-
)) {
|
|
1243
|
-
throw new MicrofrontendError(
|
|
1244
|
-
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1245
|
-
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1246
|
-
);
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
};
|
|
1250
|
-
|
|
1251
|
-
// src/config/utils/convert.ts
|
|
1252
|
-
function convertV1RoutingToV2Routing(routing) {
|
|
1253
|
-
return routing.matches.map((group) => {
|
|
1254
|
-
var _a;
|
|
1255
|
-
return {
|
|
1256
|
-
group: group.group,
|
|
1257
|
-
flag: (_a = group.options) == null ? void 0 : _a.flag,
|
|
1258
|
-
paths: group.paths
|
|
1259
|
-
};
|
|
1260
|
-
});
|
|
1261
|
-
}
|
|
1262
|
-
function convertV1ApplicationToV2Application(application) {
|
|
1263
|
-
const common = {
|
|
1264
|
-
production: application.production,
|
|
1265
|
-
development: application.development,
|
|
1266
|
-
vercel: application.vercel
|
|
1267
|
-
};
|
|
1268
|
-
if (application.default) {
|
|
1269
|
-
return common;
|
|
1270
|
-
}
|
|
1271
|
-
return {
|
|
1272
|
-
...common,
|
|
1273
|
-
routing: convertV1RoutingToV2Routing(application.routing)
|
|
1274
|
-
};
|
|
1275
|
-
}
|
|
1276
|
-
function convertV1ConfigToV2Config(config, fromApp) {
|
|
1277
|
-
if (!config.applications[fromApp]) {
|
|
1278
|
-
throw new Error(`Application "${fromApp}" not found in the config`);
|
|
1279
|
-
}
|
|
1280
|
-
const common = {
|
|
1281
|
-
version: "2",
|
|
1282
|
-
options: config.options
|
|
1283
|
-
};
|
|
1284
|
-
if (config.applications[fromApp].default) {
|
|
1285
|
-
return {
|
|
1286
|
-
...common,
|
|
1287
|
-
applications: Object.fromEntries(
|
|
1288
|
-
Object.entries(config.applications).map(([id, application]) => [
|
|
1289
|
-
id,
|
|
1290
|
-
convertV1ApplicationToV2Application(application)
|
|
1291
|
-
])
|
|
1292
|
-
)
|
|
1293
|
-
};
|
|
1294
|
-
}
|
|
1295
|
-
const defaultApplication = Object.entries(config.applications).find(
|
|
1296
|
-
([, application]) => application.default
|
|
1297
|
-
);
|
|
1298
|
-
if (!defaultApplication) {
|
|
1299
|
-
throw new Error("No default application found in the config");
|
|
1300
|
-
}
|
|
1301
|
-
return {
|
|
1302
|
-
...common,
|
|
1303
|
-
partOf: defaultApplication[0]
|
|
1304
|
-
};
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
// src/config/utils/write-file.ts
|
|
1308
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
1309
|
-
var import_node_path3 = require("path");
|
|
1310
|
-
function writeFile(outputPath, config, prettify) {
|
|
1311
|
-
import_node_fs.default.mkdirSync((0, import_node_path3.dirname)(outputPath), { recursive: true });
|
|
1312
|
-
import_node_fs.default.writeFileSync(
|
|
1313
|
-
outputPath,
|
|
1314
|
-
JSON.stringify(config, null, prettify ? 2 : void 0)
|
|
1315
|
-
);
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
// src/config/microfrontend-config.ts
|
|
1319
|
-
var MicrofrontendConfig = class extends MicrofrontendConfigCommon {
|
|
1320
|
-
static validate(configString) {
|
|
1321
|
-
const config = validateSchema(configString);
|
|
1322
|
-
validateVersion(config.version);
|
|
1323
|
-
validatePaths(config.applications);
|
|
1324
|
-
validateMainPath(config.applications);
|
|
1325
|
-
validateDefaults(config.applications);
|
|
1326
|
-
validateOptions(config.options);
|
|
1327
|
-
return config;
|
|
1328
|
-
}
|
|
1329
|
-
static fromEnv({
|
|
1330
|
-
cookies
|
|
1331
|
-
}) {
|
|
1332
|
-
return new MicrofrontendConfigCommon({
|
|
1333
|
-
config: MicrofrontendConfig.validate(
|
|
1334
|
-
MicrofrontendConfigCommon.getConfigFromEnv()
|
|
1335
|
-
),
|
|
1336
|
-
overrides: Overrides.parseOverrides(cookies)
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
|
-
static fromFile({
|
|
1340
|
-
filePath
|
|
1341
|
-
}) {
|
|
1342
|
-
try {
|
|
1343
|
-
const config = import_node_fs2.default.readFileSync(filePath, "utf-8");
|
|
1344
|
-
return new MicrofrontendConfig({
|
|
1345
|
-
config: MicrofrontendConfig.validate(config)
|
|
1346
|
-
});
|
|
1347
|
-
} catch (e) {
|
|
1348
|
-
throw MicrofrontendError.handle(e, {
|
|
1349
|
-
fileName: filePath
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* Writes the configuration to a file.
|
|
1355
|
-
*/
|
|
1356
|
-
write(fromApp, opts = {}) {
|
|
1357
|
-
const { pretty = true, versions = ["v1", "v2"] } = opts;
|
|
1358
|
-
const config = this.toSchemaJson();
|
|
1359
|
-
if (versions.includes("v1")) {
|
|
1360
|
-
const outputPath = getOutputFilePath2();
|
|
1361
|
-
writeFile(outputPath, config, pretty);
|
|
60
|
+
"./overrides": {
|
|
61
|
+
import: "./dist/overrides.js",
|
|
62
|
+
require: "./dist/overrides.cjs"
|
|
63
|
+
},
|
|
64
|
+
"./routing": {
|
|
65
|
+
import: "./dist/routing.js",
|
|
66
|
+
require: "./dist/routing.cjs"
|
|
67
|
+
},
|
|
68
|
+
"./microfrontends/server": {
|
|
69
|
+
import: "./dist/microfrontends/server.js",
|
|
70
|
+
require: "./dist/microfrontends/server.cjs"
|
|
71
|
+
},
|
|
72
|
+
"./schema": {
|
|
73
|
+
import: "./dist/schema.js",
|
|
74
|
+
require: "./dist/schema.cjs"
|
|
75
|
+
},
|
|
76
|
+
"./next/config": {
|
|
77
|
+
import: "./dist/next/config.js",
|
|
78
|
+
require: "./dist/next/config.cjs"
|
|
79
|
+
},
|
|
80
|
+
"./next/middleware": {
|
|
81
|
+
import: "./dist/next/middleware.js",
|
|
82
|
+
require: "./dist/next/middleware.cjs"
|
|
83
|
+
},
|
|
84
|
+
"./next/endpoints": {
|
|
85
|
+
import: "./dist/next/endpoints.js",
|
|
86
|
+
require: "./dist/next/endpoints.cjs"
|
|
87
|
+
},
|
|
88
|
+
"./next/testing": {
|
|
89
|
+
import: "./dist/next/testing.js",
|
|
90
|
+
require: "./dist/next/testing.cjs"
|
|
91
|
+
},
|
|
92
|
+
"./next/client": {
|
|
93
|
+
import: "./dist/next/client.js",
|
|
94
|
+
require: "./dist/next/client.cjs"
|
|
95
|
+
},
|
|
96
|
+
"./utils/mfe-port": {
|
|
97
|
+
import: "./dist/utils/mfe-port.js",
|
|
98
|
+
require: "./dist/utils/mfe-port.cjs"
|
|
1362
99
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
100
|
+
},
|
|
101
|
+
typesVersions: {
|
|
102
|
+
"*": {
|
|
103
|
+
validation: ["./dist/validation.d.ts"],
|
|
104
|
+
config: ["./dist/config.d.ts"],
|
|
105
|
+
microfrontends: ["./dist/microfrontends.d.ts"],
|
|
106
|
+
overrides: ["./dist/overrides.d.ts"],
|
|
107
|
+
routing: ["./dist/routing.d.ts"],
|
|
108
|
+
"microfrontends/server": ["./dist/microfrontends/server.d.ts"],
|
|
109
|
+
schema: ["./dist/schema.d.ts"],
|
|
110
|
+
"next/config": ["./dist/next/config.d.ts"],
|
|
111
|
+
"next/middleware": ["./dist/next/middleware.d.ts"],
|
|
112
|
+
"next/endpoints": ["./dist/next/endpoints.d.ts"],
|
|
113
|
+
"next/testing": ["./dist/next/testing.d.ts"],
|
|
114
|
+
"next/client": ["./dist/next/client.d.ts"],
|
|
115
|
+
"utils/mfe-port": ["./dist/utils/mfe-port.d.ts"]
|
|
1367
116
|
}
|
|
117
|
+
},
|
|
118
|
+
files: ["dist", "schema"],
|
|
119
|
+
scripts: {
|
|
120
|
+
build: "tsup",
|
|
121
|
+
postbuild: "pnpm generate:exports",
|
|
122
|
+
"generate:schema": "tsx scripts/generate-json-schema.ts",
|
|
123
|
+
"generate:exports": "tsx scripts/generate-exports/index.ts",
|
|
124
|
+
conformance: "vercel conformance",
|
|
125
|
+
eslint: "eslint-runner",
|
|
126
|
+
"eslint-fix": "eslint-runner --fix",
|
|
127
|
+
prepublishOnly: "pnpm build && pnpm generate:exports && pnpm generate:schema",
|
|
128
|
+
"type-check": "tsc --noEmit",
|
|
129
|
+
"unit-test": "cross-env TZ=UTC jest",
|
|
130
|
+
proxy: "tsx src/proxy/index.ts"
|
|
131
|
+
},
|
|
132
|
+
dependencies: {
|
|
133
|
+
ajv: "^8.17.1",
|
|
134
|
+
commander: "^12.1.0",
|
|
135
|
+
cookie: "0.4.0",
|
|
136
|
+
"fast-glob": "^3.3.2",
|
|
137
|
+
"http-proxy": "^1.18.1",
|
|
138
|
+
"jsonc-parser": "^3.3.1",
|
|
139
|
+
"path-to-regexp": "6.2.1"
|
|
140
|
+
},
|
|
141
|
+
devDependencies: {
|
|
142
|
+
"@edge-runtime/types": "^3.0.2",
|
|
143
|
+
"@pyra/eslint-config": "workspace:*",
|
|
144
|
+
"@pyra/typescript-config": "workspace:*",
|
|
145
|
+
"@testing-library/react": "^15.0.7",
|
|
146
|
+
"@types/cookie": "0.5.1",
|
|
147
|
+
"@types/http-proxy": "^1.17.15",
|
|
148
|
+
"@types/jest": "^29.2.0",
|
|
149
|
+
"@types/json-schema": "^7.0.15",
|
|
150
|
+
"@types/node": "20.11.30",
|
|
151
|
+
"@types/react": "18.3.1",
|
|
152
|
+
"@types/react-dom": "18.3.0",
|
|
153
|
+
"@vercel-private/conformance": "^1.12.2-canary.0",
|
|
154
|
+
jest: "^29.7.0",
|
|
155
|
+
"jest-environment-jsdom": "29.2.2",
|
|
156
|
+
next: "15.2.0-canary.17",
|
|
157
|
+
react: "19.0.0",
|
|
158
|
+
"react-dom": "19.0.0",
|
|
159
|
+
"ts-json-schema-generator": "^1.1.2",
|
|
160
|
+
tsup: "^6.6.2",
|
|
161
|
+
tsx: "^4.6.2",
|
|
162
|
+
typescript: "5.6.3",
|
|
163
|
+
webpack: "5"
|
|
164
|
+
},
|
|
165
|
+
peerDependencies: {
|
|
166
|
+
next: "15.2.0-canary.17",
|
|
167
|
+
react: "19.0.0",
|
|
168
|
+
"react-dom": "19.0.0"
|
|
169
|
+
},
|
|
170
|
+
publishConfig: {
|
|
171
|
+
access: "restricted"
|
|
1368
172
|
}
|
|
1369
173
|
};
|
|
1370
174
|
|
|
1371
|
-
// src/
|
|
175
|
+
// src/bin/local-proxy.ts
|
|
176
|
+
var http = __toESM(require("http"), 1);
|
|
177
|
+
var https = __toESM(require("https"), 1);
|
|
178
|
+
var import_cookie = require("cookie");
|
|
179
|
+
var import_path_to_regexp3 = require("path-to-regexp");
|
|
180
|
+
var import_http_proxy = __toESM(require("http-proxy"), 1);
|
|
181
|
+
|
|
182
|
+
// src/config/schema/utils/is-default-app.ts
|
|
1372
183
|
function isDefaultApp(a) {
|
|
1373
184
|
return !("routing" in a);
|
|
1374
185
|
}
|
|
1375
186
|
|
|
1376
|
-
// src/config
|
|
1377
|
-
var
|
|
187
|
+
// src/config/errors.ts
|
|
188
|
+
var MicrofrontendError = class extends Error {
|
|
1378
189
|
constructor(message, opts) {
|
|
1379
190
|
super(message);
|
|
1380
191
|
this.name = "MicrofrontendsError";
|
|
1381
192
|
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
1382
193
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
1383
194
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
1384
|
-
Error.captureStackTrace(this,
|
|
195
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
1385
196
|
}
|
|
1386
197
|
isKnown() {
|
|
1387
198
|
return this.type !== "unknown";
|
|
@@ -1396,7 +207,7 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1396
207
|
*/
|
|
1397
208
|
static convert(original, opts) {
|
|
1398
209
|
if (opts == null ? void 0 : opts.fileName) {
|
|
1399
|
-
const err =
|
|
210
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
1400
211
|
if (err) {
|
|
1401
212
|
return err;
|
|
1402
213
|
}
|
|
@@ -1404,25 +215,25 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1404
215
|
if (original.message.includes(
|
|
1405
216
|
"Code generation from strings disallowed for this context"
|
|
1406
217
|
)) {
|
|
1407
|
-
return new
|
|
218
|
+
return new MicrofrontendError(original.message, {
|
|
1408
219
|
type: "config",
|
|
1409
220
|
subtype: "unsupported_validation_env",
|
|
1410
221
|
source: "ajv"
|
|
1411
222
|
});
|
|
1412
223
|
}
|
|
1413
|
-
return new
|
|
224
|
+
return new MicrofrontendError(original.message);
|
|
1414
225
|
}
|
|
1415
226
|
static convertFSError(original, fileName) {
|
|
1416
227
|
if (original instanceof Error && "code" in original) {
|
|
1417
228
|
if (original.code === "ENOENT") {
|
|
1418
|
-
return new
|
|
229
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
1419
230
|
type: "config",
|
|
1420
231
|
subtype: "unable_to_read_file",
|
|
1421
232
|
source: "fs"
|
|
1422
233
|
});
|
|
1423
234
|
}
|
|
1424
235
|
if (original.code === "EACCES") {
|
|
1425
|
-
return new
|
|
236
|
+
return new MicrofrontendError(
|
|
1426
237
|
`Permission denied while accessing "${fileName}"`,
|
|
1427
238
|
{
|
|
1428
239
|
type: "config",
|
|
@@ -1433,7 +244,7 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1433
244
|
}
|
|
1434
245
|
}
|
|
1435
246
|
if (original instanceof SyntaxError) {
|
|
1436
|
-
return new
|
|
247
|
+
return new MicrofrontendError(
|
|
1437
248
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
1438
249
|
{
|
|
1439
250
|
type: "config",
|
|
@@ -1450,28 +261,28 @@ var MicrofrontendError2 = class extends Error {
|
|
|
1450
261
|
* @returns A MicrofrontendsError instance.
|
|
1451
262
|
*/
|
|
1452
263
|
static handle(err, opts) {
|
|
1453
|
-
if (err instanceof
|
|
264
|
+
if (err instanceof MicrofrontendError) {
|
|
1454
265
|
return err;
|
|
1455
266
|
}
|
|
1456
267
|
if (err instanceof Error) {
|
|
1457
|
-
return
|
|
268
|
+
return MicrofrontendError.convert(err, opts);
|
|
1458
269
|
}
|
|
1459
270
|
if (typeof err === "object" && err !== null) {
|
|
1460
271
|
if ("message" in err && typeof err.message === "string") {
|
|
1461
|
-
return
|
|
272
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
1462
273
|
}
|
|
1463
274
|
}
|
|
1464
|
-
return new
|
|
275
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
1465
276
|
}
|
|
1466
277
|
};
|
|
1467
278
|
|
|
1468
|
-
// src/config
|
|
1469
|
-
var
|
|
1470
|
-
var
|
|
279
|
+
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
280
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
281
|
+
var SUPPORTED_VERSIONS = ["2"];
|
|
1471
282
|
var validateConfigVersion = (version) => {
|
|
1472
|
-
if (!
|
|
1473
|
-
throw new
|
|
1474
|
-
`Unsupported version: ${version}. Supported versions are: ${
|
|
283
|
+
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
284
|
+
throw new MicrofrontendError(
|
|
285
|
+
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
1475
286
|
", "
|
|
1476
287
|
)}`,
|
|
1477
288
|
{ type: "config", subtype: "unsupported_version" }
|
|
@@ -1489,22 +300,22 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1489
300
|
continue;
|
|
1490
301
|
}
|
|
1491
302
|
for (const pathMatch of app.routing) {
|
|
1492
|
-
for (const
|
|
1493
|
-
const tokens = (0,
|
|
303
|
+
for (const path6 of pathMatch.paths) {
|
|
304
|
+
const tokens = (0, import_path_to_regexp.parse)(path6);
|
|
1494
305
|
for (const token of tokens.slice(0, -1)) {
|
|
1495
306
|
if (typeof token !== "string") {
|
|
1496
307
|
errors.push(
|
|
1497
|
-
`Path ${
|
|
308
|
+
`Path ${path6} may only have a :wildcard in the last path component`
|
|
1498
309
|
);
|
|
1499
310
|
}
|
|
1500
311
|
}
|
|
1501
|
-
const existing = pathsByApplicationId.get(
|
|
312
|
+
const existing = pathsByApplicationId.get(path6);
|
|
1502
313
|
if (existing) {
|
|
1503
314
|
existing.applications.push(id);
|
|
1504
315
|
} else {
|
|
1505
|
-
pathsByApplicationId.set(
|
|
316
|
+
pathsByApplicationId.set(path6, {
|
|
1506
317
|
applications: [id],
|
|
1507
|
-
matcher: (0,
|
|
318
|
+
matcher: (0, import_path_to_regexp.pathToRegexp)(path6),
|
|
1508
319
|
applicationId: id
|
|
1509
320
|
});
|
|
1510
321
|
}
|
|
@@ -1512,10 +323,10 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1512
323
|
}
|
|
1513
324
|
}
|
|
1514
325
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
1515
|
-
entries.forEach(([
|
|
326
|
+
entries.forEach(([path6, { applications: ids, matcher, applicationId }]) => {
|
|
1516
327
|
if (ids.length > 1) {
|
|
1517
328
|
errors.push(
|
|
1518
|
-
`Duplicate path "${
|
|
329
|
+
`Duplicate path "${path6}" for applications "${ids.join(", ")}"`
|
|
1519
330
|
);
|
|
1520
331
|
}
|
|
1521
332
|
entries.forEach(
|
|
@@ -1523,14 +334,14 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1523
334
|
matchPath,
|
|
1524
335
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
1525
336
|
]) => {
|
|
1526
|
-
if (
|
|
337
|
+
if (path6 === matchPath) {
|
|
1527
338
|
return;
|
|
1528
339
|
}
|
|
1529
340
|
if (applicationId === matchApplicationId) {
|
|
1530
341
|
return;
|
|
1531
342
|
}
|
|
1532
343
|
if (matcher.test(matchPath)) {
|
|
1533
|
-
const source = `"${
|
|
344
|
+
const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
1534
345
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
1535
346
|
errors.push(
|
|
1536
347
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -1540,7 +351,7 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
1540
351
|
);
|
|
1541
352
|
});
|
|
1542
353
|
if (errors.length) {
|
|
1543
|
-
throw new
|
|
354
|
+
throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1544
355
|
type: "config",
|
|
1545
356
|
subtype: "conflicting_paths"
|
|
1546
357
|
});
|
|
@@ -1553,13 +364,13 @@ var validateAppPaths = (name, app) => {
|
|
|
1553
364
|
continue;
|
|
1554
365
|
}
|
|
1555
366
|
if (p.endsWith("/")) {
|
|
1556
|
-
throw new
|
|
367
|
+
throw new MicrofrontendError(
|
|
1557
368
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
1558
369
|
{ type: "application", subtype: "invalid_path" }
|
|
1559
370
|
);
|
|
1560
371
|
}
|
|
1561
372
|
if (!p.startsWith("/")) {
|
|
1562
|
-
throw new
|
|
373
|
+
throw new MicrofrontendError(
|
|
1563
374
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
1564
375
|
{ type: "application", subtype: "invalid_path" }
|
|
1565
376
|
);
|
|
@@ -1581,20 +392,20 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
1581
392
|
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
1582
393
|
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
1583
394
|
if (numApplicationsWithoutRouting === 0) {
|
|
1584
|
-
throw new
|
|
395
|
+
throw new MicrofrontendError(
|
|
1585
396
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
1586
397
|
{ type: "config", subtype: "no_default_application" }
|
|
1587
398
|
);
|
|
1588
399
|
}
|
|
1589
400
|
if (numApplicationsWithoutRouting > 1) {
|
|
1590
|
-
throw new
|
|
401
|
+
throw new MicrofrontendError(
|
|
1591
402
|
`Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
|
|
1592
403
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
1593
404
|
);
|
|
1594
405
|
}
|
|
1595
406
|
};
|
|
1596
407
|
|
|
1597
|
-
// src/config
|
|
408
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
|
|
1598
409
|
var PREFIX = "vc-ap";
|
|
1599
410
|
function generateAssetPrefixFromName({
|
|
1600
411
|
name
|
|
@@ -1605,7 +416,7 @@ function generateAssetPrefixFromName({
|
|
|
1605
416
|
return `${PREFIX}-${name}`;
|
|
1606
417
|
}
|
|
1607
418
|
|
|
1608
|
-
// src/config
|
|
419
|
+
// src/config/microfrontends-config/isomorphic/utils/generate-port.ts
|
|
1609
420
|
function generatePortFromName({
|
|
1610
421
|
name,
|
|
1611
422
|
minPort = 3e3,
|
|
@@ -1625,13 +436,13 @@ function generatePortFromName({
|
|
|
1625
436
|
return port;
|
|
1626
437
|
}
|
|
1627
438
|
|
|
1628
|
-
// src/config
|
|
1629
|
-
var
|
|
439
|
+
// src/config/microfrontends-config/isomorphic/host.ts
|
|
440
|
+
var Host = class {
|
|
1630
441
|
constructor(hostConfig, options) {
|
|
1631
442
|
const { protocol = "https", host, port } = hostConfig;
|
|
1632
443
|
this.protocol = protocol;
|
|
1633
444
|
this.host = host;
|
|
1634
|
-
this.port =
|
|
445
|
+
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
1635
446
|
this.local = options == null ? void 0 : options.isLocal;
|
|
1636
447
|
}
|
|
1637
448
|
isLocal() {
|
|
@@ -1650,7 +461,7 @@ var Host2 = class {
|
|
|
1650
461
|
return port;
|
|
1651
462
|
}
|
|
1652
463
|
isDefaultPort() {
|
|
1653
|
-
return this.port ===
|
|
464
|
+
return this.port === Host.getPort({ protocol: this.protocol });
|
|
1654
465
|
}
|
|
1655
466
|
toString(opts = {}) {
|
|
1656
467
|
const url = this.toUrl(opts);
|
|
@@ -1662,7 +473,7 @@ var Host2 = class {
|
|
|
1662
473
|
return new URL(url);
|
|
1663
474
|
}
|
|
1664
475
|
};
|
|
1665
|
-
var LocalHost = class extends
|
|
476
|
+
var LocalHost = class extends Host {
|
|
1666
477
|
constructor({
|
|
1667
478
|
appName,
|
|
1668
479
|
...hostConfig
|
|
@@ -1674,8 +485,8 @@ var LocalHost = class extends Host2 {
|
|
|
1674
485
|
}
|
|
1675
486
|
};
|
|
1676
487
|
|
|
1677
|
-
// src/config
|
|
1678
|
-
var
|
|
488
|
+
// src/config/microfrontends-config/isomorphic/application.ts
|
|
489
|
+
var Application = class {
|
|
1679
490
|
constructor(name, {
|
|
1680
491
|
app,
|
|
1681
492
|
overrides,
|
|
@@ -1688,12 +499,12 @@ var Application2 = class {
|
|
|
1688
499
|
appName: name,
|
|
1689
500
|
...(_a = app.development) == null ? void 0 : _a.local
|
|
1690
501
|
}),
|
|
1691
|
-
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new
|
|
502
|
+
fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
|
|
1692
503
|
};
|
|
1693
|
-
this.production = app.production ? new
|
|
504
|
+
this.production = app.production ? new Host(app.production) : void 0;
|
|
1694
505
|
this.vercel = app.vercel;
|
|
1695
506
|
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
1696
|
-
environment: new
|
|
507
|
+
environment: new Host(overrides.environment)
|
|
1697
508
|
} : void 0;
|
|
1698
509
|
this.default = isDefault ?? false;
|
|
1699
510
|
this.serialized = app;
|
|
@@ -1708,7 +519,7 @@ var Application2 = class {
|
|
|
1708
519
|
return this.serialized;
|
|
1709
520
|
}
|
|
1710
521
|
};
|
|
1711
|
-
var DefaultApplication = class extends
|
|
522
|
+
var DefaultApplication = class extends Application {
|
|
1712
523
|
constructor(name, {
|
|
1713
524
|
app,
|
|
1714
525
|
overrides
|
|
@@ -1719,13 +530,13 @@ var DefaultApplication = class extends Application2 {
|
|
|
1719
530
|
isDefault: true
|
|
1720
531
|
});
|
|
1721
532
|
this.default = true;
|
|
1722
|
-
this.production = new
|
|
533
|
+
this.production = new Host(app.production);
|
|
1723
534
|
}
|
|
1724
535
|
getAssetPrefix() {
|
|
1725
536
|
return "";
|
|
1726
537
|
}
|
|
1727
538
|
};
|
|
1728
|
-
var ChildApplication = class extends
|
|
539
|
+
var ChildApplication = class extends Application {
|
|
1729
540
|
constructor(name, {
|
|
1730
541
|
app,
|
|
1731
542
|
overrides
|
|
@@ -1744,14 +555,14 @@ var ChildApplication = class extends Application2 {
|
|
|
1744
555
|
}
|
|
1745
556
|
};
|
|
1746
557
|
|
|
1747
|
-
// src/config
|
|
1748
|
-
var
|
|
558
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
559
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
1749
560
|
|
|
1750
|
-
// src/config
|
|
561
|
+
// src/config/microfrontends-config/utils/get-config-from-env.ts
|
|
1751
562
|
function getConfigStringFromEnv() {
|
|
1752
563
|
const config = process.env.MFE_CONFIG;
|
|
1753
564
|
if (!config) {
|
|
1754
|
-
throw new
|
|
565
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
1755
566
|
type: "config",
|
|
1756
567
|
subtype: "not_found_in_env"
|
|
1757
568
|
});
|
|
@@ -1759,13 +570,13 @@ function getConfigStringFromEnv() {
|
|
|
1759
570
|
return config;
|
|
1760
571
|
}
|
|
1761
572
|
|
|
1762
|
-
// src/config
|
|
573
|
+
// src/config/schema/utils/is-main-config.ts
|
|
1763
574
|
function isMainConfig(c) {
|
|
1764
575
|
return !("partOf" in c);
|
|
1765
576
|
}
|
|
1766
577
|
|
|
1767
|
-
// src/config
|
|
1768
|
-
var
|
|
578
|
+
// src/config/microfrontends-config/client/index.ts
|
|
579
|
+
var import_path_to_regexp2 = require("path-to-regexp");
|
|
1769
580
|
var MicrofrontendConfigClient = class {
|
|
1770
581
|
constructor(config, opts) {
|
|
1771
582
|
this.pathCache = {};
|
|
@@ -1795,21 +606,21 @@ var MicrofrontendConfigClient = class {
|
|
|
1795
606
|
isEqual(other) {
|
|
1796
607
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
1797
608
|
}
|
|
1798
|
-
getApplicationNameForPath(
|
|
1799
|
-
if (!
|
|
609
|
+
getApplicationNameForPath(path6) {
|
|
610
|
+
if (!path6.startsWith("/")) {
|
|
1800
611
|
throw new Error(`Path must start with a /`);
|
|
1801
612
|
}
|
|
1802
|
-
if (this.pathCache[
|
|
1803
|
-
return this.pathCache[
|
|
613
|
+
if (this.pathCache[path6]) {
|
|
614
|
+
return this.pathCache[path6];
|
|
1804
615
|
}
|
|
1805
|
-
const pathname = new URL(
|
|
616
|
+
const pathname = new URL(path6, "https://example.com").pathname;
|
|
1806
617
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
1807
618
|
if (application.routing) {
|
|
1808
619
|
for (const group of application.routing) {
|
|
1809
620
|
for (const childPath of group.paths) {
|
|
1810
|
-
const regexp = (0,
|
|
621
|
+
const regexp = (0, import_path_to_regexp2.pathToRegexp)(childPath);
|
|
1811
622
|
if (regexp.test(pathname)) {
|
|
1812
|
-
this.pathCache[
|
|
623
|
+
this.pathCache[path6] = name;
|
|
1813
624
|
return name;
|
|
1814
625
|
}
|
|
1815
626
|
}
|
|
@@ -1822,7 +633,7 @@ var MicrofrontendConfigClient = class {
|
|
|
1822
633
|
if (!defaultApplication) {
|
|
1823
634
|
return null;
|
|
1824
635
|
}
|
|
1825
|
-
this.pathCache[
|
|
636
|
+
this.pathCache[path6] = defaultApplication[0];
|
|
1826
637
|
return defaultApplication[0];
|
|
1827
638
|
}
|
|
1828
639
|
serialize() {
|
|
@@ -1830,17 +641,17 @@ var MicrofrontendConfigClient = class {
|
|
|
1830
641
|
}
|
|
1831
642
|
};
|
|
1832
643
|
|
|
1833
|
-
// src/config
|
|
1834
|
-
var
|
|
1835
|
-
var OVERRIDES_ENV_COOKIE_PREFIX = `${
|
|
644
|
+
// src/config/overrides/constants.ts
|
|
645
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
646
|
+
var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
1836
647
|
|
|
1837
|
-
// src/config
|
|
648
|
+
// src/config/overrides/is-override-cookie.ts
|
|
1838
649
|
function isOverrideCookie(cookie) {
|
|
1839
650
|
var _a;
|
|
1840
|
-
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(
|
|
651
|
+
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
1841
652
|
}
|
|
1842
653
|
|
|
1843
|
-
// src/config
|
|
654
|
+
// src/config/overrides/get-override-from-cookie.ts
|
|
1844
655
|
function getOverrideFromCookie(cookie) {
|
|
1845
656
|
if (!isOverrideCookie(cookie) || !cookie.value)
|
|
1846
657
|
return;
|
|
@@ -1850,7 +661,7 @@ function getOverrideFromCookie(cookie) {
|
|
|
1850
661
|
};
|
|
1851
662
|
}
|
|
1852
663
|
|
|
1853
|
-
// src/config
|
|
664
|
+
// src/config/overrides/parse-overrides.ts
|
|
1854
665
|
function parseOverrides(cookies) {
|
|
1855
666
|
const overridesConfig = { applications: {} };
|
|
1856
667
|
cookies.forEach((cookie) => {
|
|
@@ -1864,10 +675,10 @@ function parseOverrides(cookies) {
|
|
|
1864
675
|
return overridesConfig;
|
|
1865
676
|
}
|
|
1866
677
|
|
|
1867
|
-
// src/config
|
|
1868
|
-
var
|
|
678
|
+
// src/config/microfrontends-config/isomorphic/constants.ts
|
|
679
|
+
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
1869
680
|
|
|
1870
|
-
// src/config
|
|
681
|
+
// src/config/microfrontends-config/isomorphic/index.ts
|
|
1871
682
|
var MicrofrontendConfigIsomorphic = class {
|
|
1872
683
|
constructor({
|
|
1873
684
|
config,
|
|
@@ -1908,7 +719,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1908
719
|
);
|
|
1909
720
|
}
|
|
1910
721
|
if (isMainConfig(config) && !this.defaultApplication) {
|
|
1911
|
-
throw new
|
|
722
|
+
throw new MicrofrontendError(
|
|
1912
723
|
`Could not find default application in microfrontends configuration`,
|
|
1913
724
|
{
|
|
1914
725
|
type: "application",
|
|
@@ -1925,7 +736,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1925
736
|
};
|
|
1926
737
|
}
|
|
1927
738
|
static validate(config) {
|
|
1928
|
-
const c = typeof config === "string" ? (0,
|
|
739
|
+
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
1929
740
|
if (isMainConfig(c)) {
|
|
1930
741
|
validateConfigVersion(c.version);
|
|
1931
742
|
validateConfigPaths(c.applications);
|
|
@@ -1938,7 +749,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1938
749
|
cookies
|
|
1939
750
|
}) {
|
|
1940
751
|
return new MicrofrontendConfigIsomorphic({
|
|
1941
|
-
config: (0,
|
|
752
|
+
config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
|
|
1942
753
|
overrides: parseOverrides(cookies ?? []),
|
|
1943
754
|
meta
|
|
1944
755
|
});
|
|
@@ -1972,7 +783,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
1972
783
|
}
|
|
1973
784
|
const app = this.childApplications[name];
|
|
1974
785
|
if (!app) {
|
|
1975
|
-
throw new
|
|
786
|
+
throw new MicrofrontendError(
|
|
1976
787
|
`Could not find microfrontends configuration for application "${name}"`,
|
|
1977
788
|
{
|
|
1978
789
|
type: "application",
|
|
@@ -2000,7 +811,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
2000
811
|
*/
|
|
2001
812
|
getDefaultApplication() {
|
|
2002
813
|
if (!this.defaultApplication) {
|
|
2003
|
-
throw new
|
|
814
|
+
throw new MicrofrontendError(
|
|
2004
815
|
`Could not find default application in microfrontends configuration`,
|
|
2005
816
|
{
|
|
2006
817
|
type: "application",
|
|
@@ -2015,7 +826,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
2015
826
|
*/
|
|
2016
827
|
getLocalProxyPort() {
|
|
2017
828
|
var _a, _b;
|
|
2018
|
-
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ??
|
|
829
|
+
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
2019
830
|
}
|
|
2020
831
|
/**
|
|
2021
832
|
* Serializes the class back to the Schema type.
|
|
@@ -2049,7 +860,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
2049
860
|
}
|
|
2050
861
|
};
|
|
2051
862
|
|
|
2052
|
-
// src/config
|
|
863
|
+
// src/config/microfrontends-config/isomorphic/main.ts
|
|
2053
864
|
var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
2054
865
|
constructor({
|
|
2055
866
|
config,
|
|
@@ -2076,7 +887,7 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
2076
887
|
}
|
|
2077
888
|
}
|
|
2078
889
|
if (!defaultApplication) {
|
|
2079
|
-
throw new
|
|
890
|
+
throw new MicrofrontendError(
|
|
2080
891
|
`Could not find default application in microfrontends configuration`,
|
|
2081
892
|
{
|
|
2082
893
|
type: "application",
|
|
@@ -2088,16 +899,16 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
2088
899
|
}
|
|
2089
900
|
};
|
|
2090
901
|
|
|
2091
|
-
// src/config
|
|
902
|
+
// src/config/microfrontends/utils/is-main-config.ts
|
|
2092
903
|
function isMainConfig2(c) {
|
|
2093
904
|
return !("partOf" in c);
|
|
2094
905
|
}
|
|
2095
906
|
|
|
2096
|
-
// src/config
|
|
2097
|
-
var
|
|
2098
|
-
var
|
|
907
|
+
// src/config/microfrontends/server/index.ts
|
|
908
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
909
|
+
var import_node_path8 = require("path");
|
|
2099
910
|
|
|
2100
|
-
// src/config
|
|
911
|
+
// src/config/microfrontends-config/isomorphic/child.ts
|
|
2101
912
|
var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
2102
913
|
constructor({
|
|
2103
914
|
config,
|
|
@@ -2110,7 +921,7 @@ var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
2110
921
|
}
|
|
2111
922
|
};
|
|
2112
923
|
|
|
2113
|
-
// src/config
|
|
924
|
+
// src/config/microfrontends/isomorphic/index.ts
|
|
2114
925
|
var Microfrontends = class {
|
|
2115
926
|
constructor({
|
|
2116
927
|
config,
|
|
@@ -2138,27 +949,27 @@ var Microfrontends = class {
|
|
|
2138
949
|
}
|
|
2139
950
|
};
|
|
2140
951
|
|
|
2141
|
-
// src/config
|
|
2142
|
-
var
|
|
2143
|
-
var
|
|
952
|
+
// src/config/microfrontends/utils/find-repository-root.ts
|
|
953
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
954
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
2144
955
|
var GIT_DIRECTORY = ".git";
|
|
2145
956
|
function findRepositoryRoot(startDir) {
|
|
2146
957
|
let currentDir = startDir || process.cwd();
|
|
2147
|
-
while (currentDir !==
|
|
2148
|
-
const gitPath =
|
|
2149
|
-
if (
|
|
958
|
+
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
959
|
+
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
960
|
+
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
2150
961
|
return currentDir;
|
|
2151
962
|
}
|
|
2152
|
-
currentDir =
|
|
963
|
+
currentDir = import_node_path.default.dirname(currentDir);
|
|
2153
964
|
}
|
|
2154
965
|
throw new Error(
|
|
2155
966
|
"Repository root not found. Specify the root of the repository with the `repository.root` option."
|
|
2156
967
|
);
|
|
2157
968
|
}
|
|
2158
969
|
|
|
2159
|
-
// src/config
|
|
2160
|
-
var
|
|
2161
|
-
var
|
|
970
|
+
// src/config/microfrontends/utils/find-package-path.ts
|
|
971
|
+
var import_node_path2 = require("path");
|
|
972
|
+
var import_node_fs2 = require("fs");
|
|
2162
973
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
2163
974
|
var configCache = {};
|
|
2164
975
|
function findPackagePathWithGlob({
|
|
@@ -2175,7 +986,7 @@ function findPackagePathWithGlob({
|
|
|
2175
986
|
});
|
|
2176
987
|
const matchingPaths = [];
|
|
2177
988
|
for (const packageJsonPath2 of packageJsonPaths) {
|
|
2178
|
-
const packageJsonContent = (0,
|
|
989
|
+
const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
|
|
2179
990
|
const packageJson = JSON.parse(packageJsonContent);
|
|
2180
991
|
if (packageJson.name === name) {
|
|
2181
992
|
matchingPaths.push(packageJsonPath2);
|
|
@@ -2192,7 +1003,7 @@ function findPackagePathWithGlob({
|
|
|
2192
1003
|
);
|
|
2193
1004
|
}
|
|
2194
1005
|
const [packageJsonPath] = matchingPaths;
|
|
2195
|
-
return (0,
|
|
1006
|
+
return (0, import_node_path2.dirname)(packageJsonPath);
|
|
2196
1007
|
} catch (error) {
|
|
2197
1008
|
return null;
|
|
2198
1009
|
}
|
|
@@ -2212,19 +1023,19 @@ function findPackagePath(opts) {
|
|
|
2212
1023
|
return result;
|
|
2213
1024
|
}
|
|
2214
1025
|
|
|
2215
|
-
// src/config
|
|
2216
|
-
var
|
|
2217
|
-
var
|
|
2218
|
-
var
|
|
1026
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
1027
|
+
var import_node_path3 = require("path");
|
|
1028
|
+
var import_node_fs3 = require("fs");
|
|
1029
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
2219
1030
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
2220
1031
|
|
|
2221
|
-
// src/config
|
|
1032
|
+
// src/config/constants.ts
|
|
2222
1033
|
var CONFIGURATION_FILENAMES = [
|
|
2223
1034
|
"microfrontends.jsonc",
|
|
2224
1035
|
"microfrontends.json"
|
|
2225
1036
|
];
|
|
2226
1037
|
|
|
2227
|
-
// src/config
|
|
1038
|
+
// src/config/microfrontends/utils/find-default-package.ts
|
|
2228
1039
|
var configCache2 = {};
|
|
2229
1040
|
function findDefaultMicrofrontendsPackages({
|
|
2230
1041
|
repositoryRoot,
|
|
@@ -2243,11 +1054,11 @@ function findDefaultMicrofrontendsPackages({
|
|
|
2243
1054
|
);
|
|
2244
1055
|
const matchingPaths = [];
|
|
2245
1056
|
for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
|
|
2246
|
-
const microfrontendsJsonContent = (0,
|
|
1057
|
+
const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
|
|
2247
1058
|
microfrontendsJsonPath,
|
|
2248
1059
|
"utf-8"
|
|
2249
1060
|
);
|
|
2250
|
-
const microfrontendsJson = (0,
|
|
1061
|
+
const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
|
|
2251
1062
|
if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
|
|
2252
1063
|
matchingPaths.push(microfrontendsJsonPath);
|
|
2253
1064
|
}
|
|
@@ -2264,7 +1075,7 @@ ${matchingPaths.join("\n \u2022 ")}`
|
|
|
2264
1075
|
);
|
|
2265
1076
|
}
|
|
2266
1077
|
const [packageJsonPath] = matchingPaths;
|
|
2267
|
-
return (0,
|
|
1078
|
+
return (0, import_node_path3.dirname)(packageJsonPath);
|
|
2268
1079
|
} catch (error) {
|
|
2269
1080
|
return null;
|
|
2270
1081
|
}
|
|
@@ -2284,25 +1095,25 @@ function findDefaultMicrofrontendsPackage(opts) {
|
|
|
2284
1095
|
return result;
|
|
2285
1096
|
}
|
|
2286
1097
|
|
|
2287
|
-
// src/config
|
|
2288
|
-
var
|
|
2289
|
-
var
|
|
1098
|
+
// src/config/microfrontends/utils/is-monorepo.ts
|
|
1099
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1100
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
2290
1101
|
function isMonorepo({
|
|
2291
1102
|
repositoryRoot
|
|
2292
1103
|
}) {
|
|
2293
1104
|
try {
|
|
2294
|
-
if (
|
|
1105
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
|
|
2295
1106
|
return true;
|
|
2296
1107
|
}
|
|
2297
|
-
if (
|
|
1108
|
+
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
2298
1109
|
return true;
|
|
2299
1110
|
}
|
|
2300
|
-
const packageJsonPath =
|
|
2301
|
-
if (!
|
|
1111
|
+
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
1112
|
+
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
2302
1113
|
return false;
|
|
2303
1114
|
}
|
|
2304
1115
|
const packageJson = JSON.parse(
|
|
2305
|
-
|
|
1116
|
+
import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
|
|
2306
1117
|
);
|
|
2307
1118
|
return packageJson.workspaces !== void 0;
|
|
2308
1119
|
} catch (error) {
|
|
@@ -2311,43 +1122,67 @@ function isMonorepo({
|
|
|
2311
1122
|
}
|
|
2312
1123
|
}
|
|
2313
1124
|
|
|
2314
|
-
// src/config
|
|
2315
|
-
var
|
|
2316
|
-
var
|
|
1125
|
+
// src/config/microfrontends/utils/find-package-root.ts
|
|
1126
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1127
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
2317
1128
|
var PACKAGE_JSON = "package.json";
|
|
2318
1129
|
function findPackageRoot(startDir) {
|
|
2319
1130
|
let currentDir = startDir || process.cwd();
|
|
2320
|
-
while (currentDir !==
|
|
2321
|
-
const pkgJsonPath =
|
|
2322
|
-
if (
|
|
1131
|
+
while (currentDir !== import_node_path5.default.parse(currentDir).root) {
|
|
1132
|
+
const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
|
|
1133
|
+
if (import_node_fs5.default.existsSync(pkgJsonPath)) {
|
|
2323
1134
|
return currentDir;
|
|
2324
1135
|
}
|
|
2325
|
-
currentDir =
|
|
1136
|
+
currentDir = import_node_path5.default.dirname(currentDir);
|
|
2326
1137
|
}
|
|
2327
1138
|
throw new Error(
|
|
2328
1139
|
"Package root not found. Specify the root of the package with the `package.root` option."
|
|
2329
1140
|
);
|
|
2330
1141
|
}
|
|
2331
1142
|
|
|
2332
|
-
// src/config
|
|
2333
|
-
var
|
|
2334
|
-
var
|
|
1143
|
+
// src/config/microfrontends/utils/find-config.ts
|
|
1144
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1145
|
+
var import_node_path6 = require("path");
|
|
2335
1146
|
function findConfig({ dir }) {
|
|
2336
1147
|
for (const filename of CONFIGURATION_FILENAMES) {
|
|
2337
|
-
const maybeConfig = (0,
|
|
2338
|
-
if (
|
|
1148
|
+
const maybeConfig = (0, import_node_path6.join)(dir, filename);
|
|
1149
|
+
if (import_node_fs6.default.existsSync(maybeConfig)) {
|
|
2339
1150
|
return maybeConfig;
|
|
2340
1151
|
}
|
|
2341
1152
|
}
|
|
2342
1153
|
return null;
|
|
2343
1154
|
}
|
|
2344
1155
|
|
|
2345
|
-
// src/config
|
|
2346
|
-
var
|
|
2347
|
-
|
|
1156
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1157
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1158
|
+
|
|
1159
|
+
// src/config/microfrontends/server/constants.ts
|
|
1160
|
+
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
1161
|
+
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
1162
|
+
|
|
1163
|
+
// src/utils/is-vercel.ts
|
|
1164
|
+
function isVercel() {
|
|
1165
|
+
return process.env.VERCEL === "1";
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1169
|
+
function getOutputFilePath() {
|
|
1170
|
+
if (isVercel()) {
|
|
1171
|
+
return import_node_path7.default.join(
|
|
1172
|
+
".vercel",
|
|
1173
|
+
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
1174
|
+
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// src/config/microfrontends/server/validation.ts
|
|
1181
|
+
var import_jsonc_parser3 = require("jsonc-parser");
|
|
1182
|
+
var import_ajv = require("ajv");
|
|
2348
1183
|
|
|
2349
|
-
// schema/schema
|
|
2350
|
-
var
|
|
1184
|
+
// schema/schema.json
|
|
1185
|
+
var schema_default = {
|
|
2351
1186
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
2352
1187
|
$ref: "#/definitions/Config",
|
|
2353
1188
|
definitions: {
|
|
@@ -2386,7 +1221,8 @@ var schema_v2_default = {
|
|
|
2386
1221
|
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"
|
|
2387
1222
|
}
|
|
2388
1223
|
},
|
|
2389
|
-
required: ["applications", "version"]
|
|
1224
|
+
required: ["applications", "version"],
|
|
1225
|
+
additionalProperties: false
|
|
2390
1226
|
},
|
|
2391
1227
|
Options: {
|
|
2392
1228
|
type: "object",
|
|
@@ -2399,7 +1235,8 @@ var schema_v2_default = {
|
|
|
2399
1235
|
$ref: "#/definitions/LocalProxyOptions",
|
|
2400
1236
|
description: "Options for local proxy."
|
|
2401
1237
|
}
|
|
2402
|
-
}
|
|
1238
|
+
},
|
|
1239
|
+
additionalProperties: false
|
|
2403
1240
|
},
|
|
2404
1241
|
VercelOptions: {
|
|
2405
1242
|
type: "object",
|
|
@@ -2412,7 +1249,8 @@ var schema_v2_default = {
|
|
|
2412
1249
|
type: "boolean",
|
|
2413
1250
|
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."
|
|
2414
1251
|
}
|
|
2415
|
-
}
|
|
1252
|
+
},
|
|
1253
|
+
additionalProperties: false
|
|
2416
1254
|
},
|
|
2417
1255
|
LocalProxyOptions: {
|
|
2418
1256
|
type: "object",
|
|
@@ -2421,7 +1259,8 @@ var schema_v2_default = {
|
|
|
2421
1259
|
type: "number",
|
|
2422
1260
|
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
2423
1261
|
}
|
|
2424
|
-
}
|
|
1262
|
+
},
|
|
1263
|
+
additionalProperties: false
|
|
2425
1264
|
},
|
|
2426
1265
|
Application: {
|
|
2427
1266
|
anyOf: [
|
|
@@ -2446,7 +1285,8 @@ var schema_v2_default = {
|
|
|
2446
1285
|
$ref: "#/definitions/HostConfig"
|
|
2447
1286
|
}
|
|
2448
1287
|
},
|
|
2449
|
-
required: ["production"]
|
|
1288
|
+
required: ["production"],
|
|
1289
|
+
additionalProperties: false
|
|
2450
1290
|
},
|
|
2451
1291
|
Vercel: {
|
|
2452
1292
|
type: "object",
|
|
@@ -2456,7 +1296,8 @@ var schema_v2_default = {
|
|
|
2456
1296
|
description: "Vercel project ID"
|
|
2457
1297
|
}
|
|
2458
1298
|
},
|
|
2459
|
-
required: ["projectId"]
|
|
1299
|
+
required: ["projectId"],
|
|
1300
|
+
additionalProperties: false
|
|
2460
1301
|
},
|
|
2461
1302
|
Development: {
|
|
2462
1303
|
type: "object",
|
|
@@ -2472,10 +1313,12 @@ var schema_v2_default = {
|
|
|
2472
1313
|
type: "string",
|
|
2473
1314
|
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
2474
1315
|
}
|
|
2475
|
-
}
|
|
1316
|
+
},
|
|
1317
|
+
additionalProperties: false
|
|
2476
1318
|
},
|
|
2477
1319
|
LocalHostConfig: {
|
|
2478
1320
|
type: "object",
|
|
1321
|
+
additionalProperties: false,
|
|
2479
1322
|
properties: {
|
|
2480
1323
|
host: {
|
|
2481
1324
|
type: "string",
|
|
@@ -2509,7 +1352,8 @@ var schema_v2_default = {
|
|
|
2509
1352
|
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
2510
1353
|
}
|
|
2511
1354
|
},
|
|
2512
|
-
required: ["host"]
|
|
1355
|
+
required: ["host"],
|
|
1356
|
+
additionalProperties: false
|
|
2513
1357
|
},
|
|
2514
1358
|
ChildApplication: {
|
|
2515
1359
|
type: "object",
|
|
@@ -2528,7 +1372,8 @@ var schema_v2_default = {
|
|
|
2528
1372
|
$ref: "#/definitions/HostConfig"
|
|
2529
1373
|
}
|
|
2530
1374
|
},
|
|
2531
|
-
required: ["routing"]
|
|
1375
|
+
required: ["routing"],
|
|
1376
|
+
additionalProperties: false
|
|
2532
1377
|
},
|
|
2533
1378
|
Routing: {
|
|
2534
1379
|
type: "array",
|
|
@@ -2554,7 +1399,8 @@ var schema_v2_default = {
|
|
|
2554
1399
|
}
|
|
2555
1400
|
}
|
|
2556
1401
|
},
|
|
2557
|
-
required: ["paths"]
|
|
1402
|
+
required: ["paths"],
|
|
1403
|
+
additionalProperties: false
|
|
2558
1404
|
},
|
|
2559
1405
|
ApplicationRouting: {
|
|
2560
1406
|
type: "object",
|
|
@@ -2587,19 +1433,20 @@ var schema_v2_default = {
|
|
|
2587
1433
|
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."
|
|
2588
1434
|
}
|
|
2589
1435
|
},
|
|
2590
|
-
required: ["partOf", "version"]
|
|
1436
|
+
required: ["partOf", "version"],
|
|
1437
|
+
additionalProperties: false
|
|
2591
1438
|
}
|
|
2592
1439
|
}
|
|
2593
1440
|
};
|
|
2594
1441
|
|
|
2595
|
-
// src/config
|
|
2596
|
-
var
|
|
1442
|
+
// src/config/schema/utils/load.ts
|
|
1443
|
+
var SCHEMA = schema_default;
|
|
2597
1444
|
|
|
2598
|
-
// src/config
|
|
2599
|
-
function
|
|
2600
|
-
const parsedConfig = (0,
|
|
2601
|
-
const ajv = new
|
|
2602
|
-
const validate = ajv.compile(
|
|
1445
|
+
// src/config/microfrontends/server/validation.ts
|
|
1446
|
+
function validateSchema(configString) {
|
|
1447
|
+
const parsedConfig = (0, import_jsonc_parser3.parse)(configString);
|
|
1448
|
+
const ajv = new import_ajv.Ajv();
|
|
1449
|
+
const validate = ajv.compile(SCHEMA);
|
|
2603
1450
|
const isValid = validate(parsedConfig);
|
|
2604
1451
|
if (!isValid) {
|
|
2605
1452
|
throw new MicrofrontendError(
|
|
@@ -2610,7 +1457,7 @@ function validateSchema2(configString) {
|
|
|
2610
1457
|
return parsedConfig;
|
|
2611
1458
|
}
|
|
2612
1459
|
|
|
2613
|
-
// src/config
|
|
1460
|
+
// src/config/microfrontends/server/index.ts
|
|
2614
1461
|
var MicrofrontendsServer = class extends Microfrontends {
|
|
2615
1462
|
/**
|
|
2616
1463
|
* Writes the configuration to a file.
|
|
@@ -2619,8 +1466,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2619
1466
|
pretty: true
|
|
2620
1467
|
}) {
|
|
2621
1468
|
const outputPath = getOutputFilePath();
|
|
2622
|
-
|
|
2623
|
-
|
|
1469
|
+
import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
|
|
1470
|
+
import_node_fs7.default.writeFileSync(
|
|
2624
1471
|
outputPath,
|
|
2625
1472
|
JSON.stringify(
|
|
2626
1473
|
this.config.toSchemaJson(),
|
|
@@ -2653,7 +1500,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2653
1500
|
meta
|
|
2654
1501
|
});
|
|
2655
1502
|
}
|
|
2656
|
-
throw new
|
|
1503
|
+
throw new MicrofrontendError(
|
|
2657
1504
|
"Invalid config: must be a string or an object",
|
|
2658
1505
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
2659
1506
|
);
|
|
@@ -2677,7 +1524,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2677
1524
|
*/
|
|
2678
1525
|
static validate(config) {
|
|
2679
1526
|
if (typeof config === "string") {
|
|
2680
|
-
const c =
|
|
1527
|
+
const c = validateSchema(config);
|
|
2681
1528
|
return c;
|
|
2682
1529
|
}
|
|
2683
1530
|
return config;
|
|
@@ -2706,9 +1553,9 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2706
1553
|
}
|
|
2707
1554
|
try {
|
|
2708
1555
|
const packageRoot = findPackageRoot(directory);
|
|
2709
|
-
const packageJsonPath = (0,
|
|
1556
|
+
const packageJsonPath = (0, import_node_path8.join)(packageRoot, "package.json");
|
|
2710
1557
|
const packageJson = JSON.parse(
|
|
2711
|
-
|
|
1558
|
+
import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
|
|
2712
1559
|
);
|
|
2713
1560
|
if (!packageJson.name) {
|
|
2714
1561
|
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
@@ -2742,7 +1589,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2742
1589
|
}
|
|
2743
1590
|
throw new Error("Unable to infer");
|
|
2744
1591
|
} catch (e) {
|
|
2745
|
-
throw new
|
|
1592
|
+
throw new MicrofrontendError(
|
|
2746
1593
|
"Unable to infer microfrontends configuration",
|
|
2747
1594
|
{ type: "config", subtype: "inference_failed" }
|
|
2748
1595
|
);
|
|
@@ -2758,7 +1605,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2758
1605
|
options
|
|
2759
1606
|
}) {
|
|
2760
1607
|
try {
|
|
2761
|
-
const configJson =
|
|
1608
|
+
const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
2762
1609
|
const config = MicrofrontendsServer.validate(configJson);
|
|
2763
1610
|
if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
|
|
2764
1611
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -2769,14 +1616,14 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2769
1616
|
name: config.partOf
|
|
2770
1617
|
});
|
|
2771
1618
|
if (!packagePath) {
|
|
2772
|
-
throw new
|
|
1619
|
+
throw new MicrofrontendError(
|
|
2773
1620
|
`Could not find default application "${config.partOf}" in the repository`,
|
|
2774
1621
|
{ type: "config", subtype: "not_found" }
|
|
2775
1622
|
);
|
|
2776
1623
|
}
|
|
2777
1624
|
const maybeConfig = findConfig({ dir: packagePath });
|
|
2778
1625
|
if (!maybeConfig) {
|
|
2779
|
-
throw new
|
|
1626
|
+
throw new MicrofrontendError(
|
|
2780
1627
|
`Could not find microfrontends configuration in ${packagePath}`,
|
|
2781
1628
|
{ type: "config", subtype: "not_found" }
|
|
2782
1629
|
);
|
|
@@ -2793,7 +1640,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2793
1640
|
meta
|
|
2794
1641
|
});
|
|
2795
1642
|
} catch (e) {
|
|
2796
|
-
throw
|
|
1643
|
+
throw MicrofrontendError.handle(e, {
|
|
2797
1644
|
fileName: filePath
|
|
2798
1645
|
});
|
|
2799
1646
|
}
|
|
@@ -2806,10 +1653,10 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2806
1653
|
overrides
|
|
2807
1654
|
}) {
|
|
2808
1655
|
try {
|
|
2809
|
-
const config =
|
|
1656
|
+
const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
|
|
2810
1657
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
2811
1658
|
if (!isMainConfig(validatedConfig)) {
|
|
2812
|
-
throw new
|
|
1659
|
+
throw new MicrofrontendError(
|
|
2813
1660
|
`${filePath} is not a main microfrontend config`,
|
|
2814
1661
|
{
|
|
2815
1662
|
type: "config",
|
|
@@ -2819,7 +1666,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2819
1666
|
}
|
|
2820
1667
|
const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
|
|
2821
1668
|
if (!defaultApplication) {
|
|
2822
|
-
throw new
|
|
1669
|
+
throw new MicrofrontendError(
|
|
2823
1670
|
`No default application found. At least one application needs to be the default by omitting routing.`,
|
|
2824
1671
|
{ type: "config", subtype: "no_default_application" }
|
|
2825
1672
|
);
|
|
@@ -2830,7 +1677,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
2830
1677
|
meta: { fromApp: defaultApplication }
|
|
2831
1678
|
});
|
|
2832
1679
|
} catch (e) {
|
|
2833
|
-
throw
|
|
1680
|
+
throw MicrofrontendError.handle(e, {
|
|
2834
1681
|
fileName: filePath
|
|
2835
1682
|
});
|
|
2836
1683
|
}
|
|
@@ -2844,9 +1691,6 @@ var mfeDebug = (message) => {
|
|
|
2844
1691
|
console.log(message);
|
|
2845
1692
|
}
|
|
2846
1693
|
};
|
|
2847
|
-
function isV2Config(c) {
|
|
2848
|
-
return "isMainConfig" in c;
|
|
2849
|
-
}
|
|
2850
1694
|
var LocalProxy = class {
|
|
2851
1695
|
constructor(config, {
|
|
2852
1696
|
localApps,
|
|
@@ -2873,51 +1717,24 @@ var LocalProxy = class {
|
|
|
2873
1717
|
localApps,
|
|
2874
1718
|
proxyPort
|
|
2875
1719
|
}) {
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
});
|
|
2882
|
-
} catch (error) {
|
|
2883
|
-
if ((0, import_types2.isNativeError)(error)) {
|
|
2884
|
-
configV2Err = error;
|
|
2885
|
-
}
|
|
2886
|
-
}
|
|
2887
|
-
if (configV2) {
|
|
2888
|
-
if (isMainConfig2(configV2.config)) {
|
|
2889
|
-
return new LocalProxy(configV2.config, { localApps, proxyPort });
|
|
2890
|
-
}
|
|
2891
|
-
throw new Error("Got child config after parsing main config");
|
|
2892
|
-
}
|
|
2893
|
-
try {
|
|
2894
|
-
const configV1 = MicrofrontendConfig.fromFile({ filePath });
|
|
2895
|
-
return new LocalProxy(configV1, { localApps, proxyPort });
|
|
2896
|
-
} catch (error) {
|
|
2897
|
-
if (configV2Err) {
|
|
2898
|
-
throw configV2Err;
|
|
2899
|
-
}
|
|
2900
|
-
throw error;
|
|
1720
|
+
const microfrontends = MicrofrontendsServer.infer({
|
|
1721
|
+
directory: filePath
|
|
1722
|
+
});
|
|
1723
|
+
if (isMainConfig2(microfrontends.config)) {
|
|
1724
|
+
return new LocalProxy(microfrontends.config, { localApps, proxyPort });
|
|
2901
1725
|
}
|
|
1726
|
+
throw new Error(
|
|
1727
|
+
`Unable to find main config from child application (${filePath})`
|
|
1728
|
+
);
|
|
2902
1729
|
}
|
|
2903
1730
|
getDefaultHost(config) {
|
|
2904
|
-
|
|
2905
|
-
if (isV2Config(config)) {
|
|
2906
|
-
defaultApp = config.getDefaultApplication();
|
|
2907
|
-
} else {
|
|
2908
|
-
defaultApp = config.getDefaultZone();
|
|
2909
|
-
}
|
|
1731
|
+
const defaultApp = config.getDefaultApplication();
|
|
2910
1732
|
return this.getApplicationTarget(defaultApp);
|
|
2911
1733
|
}
|
|
2912
1734
|
getApplicationTarget(application) {
|
|
2913
1735
|
var _a, _b;
|
|
2914
1736
|
const useDev = this.localApps.includes(application.name);
|
|
2915
|
-
let host = useDev ? application.development.local : application.production;
|
|
2916
|
-
if (!host) {
|
|
2917
|
-
throw new Error(
|
|
2918
|
-
`${application.name} does not have a production host configured`
|
|
2919
|
-
);
|
|
2920
|
-
}
|
|
1737
|
+
let host = useDev ? application.development.local : application.production ?? this.config.getDefaultApplication().production;
|
|
2921
1738
|
if ((_b = (_a = application.overrides) == null ? void 0 : _a.environment) == null ? void 0 : _b.host) {
|
|
2922
1739
|
host = application.overrides.environment;
|
|
2923
1740
|
}
|
|
@@ -2948,7 +1765,7 @@ var LocalProxy = class {
|
|
|
2948
1765
|
const isJWTRedirect = url.searchParams.has("_vercel_jwt");
|
|
2949
1766
|
const defaultHost = this.getDefaultHost(config);
|
|
2950
1767
|
let hostname = null;
|
|
2951
|
-
let
|
|
1768
|
+
let path6 = request2.url;
|
|
2952
1769
|
if (isAuthRedirect) {
|
|
2953
1770
|
hostname = url.searchParams.get("_host_override");
|
|
2954
1771
|
}
|
|
@@ -2958,117 +1775,66 @@ var LocalProxy = class {
|
|
|
2958
1775
|
if (isJWTRedirect) {
|
|
2959
1776
|
hostname = url.searchParams.get("_host_override");
|
|
2960
1777
|
url.searchParams.delete("_host_override");
|
|
2961
|
-
|
|
1778
|
+
path6 = `${url.pathname}${url.search}`;
|
|
2962
1779
|
}
|
|
2963
1780
|
if (!hostname) {
|
|
2964
1781
|
return void 0;
|
|
2965
1782
|
}
|
|
2966
|
-
return { ...defaultHost, path:
|
|
1783
|
+
return { ...defaultHost, path: path6, hostname, protocol: "https", port: 443 };
|
|
2967
1784
|
}
|
|
2968
1785
|
getConfigWithOverrides(cookies) {
|
|
2969
|
-
|
|
2970
|
-
const cookieOverrides2 = parseOverrides(
|
|
2971
|
-
Object.entries(cookies).map(([name, value]) => ({ name, value }))
|
|
2972
|
-
);
|
|
2973
|
-
const hasOverrides2 = Object.keys(cookieOverrides2.applications).length > 0;
|
|
2974
|
-
const fromApp = this.config.getDefaultApplication().name;
|
|
2975
|
-
const serialized = this.config.serialize().config;
|
|
2976
|
-
if (!isMainConfig(serialized)) {
|
|
2977
|
-
throw new Error("unreachable");
|
|
2978
|
-
}
|
|
2979
|
-
return hasOverrides2 ? new MicrofrontendMainConfig({
|
|
2980
|
-
config: serialized,
|
|
2981
|
-
meta: { fromApp },
|
|
2982
|
-
overrides: cookieOverrides2
|
|
2983
|
-
}) : this.config;
|
|
2984
|
-
}
|
|
2985
|
-
const cookieOverrides = Overrides.parseOverrides(
|
|
1786
|
+
const cookieOverrides = parseOverrides(
|
|
2986
1787
|
Object.entries(cookies).map(([name, value]) => ({ name, value }))
|
|
2987
1788
|
);
|
|
2988
1789
|
const hasOverrides = Object.keys(cookieOverrides.applications).length > 0;
|
|
2989
|
-
|
|
2990
|
-
|
|
1790
|
+
const fromApp = this.config.getDefaultApplication().name;
|
|
1791
|
+
const serialized = this.config.serialize().config;
|
|
1792
|
+
if (!isMainConfig(serialized)) {
|
|
1793
|
+
throw new Error("unreachable");
|
|
1794
|
+
}
|
|
1795
|
+
return hasOverrides ? new MicrofrontendMainConfig({
|
|
1796
|
+
config: serialized,
|
|
1797
|
+
meta: { fromApp },
|
|
2991
1798
|
overrides: cookieOverrides
|
|
2992
1799
|
}) : this.config;
|
|
2993
1800
|
}
|
|
2994
1801
|
getTarget(request2) {
|
|
2995
1802
|
const cookies = (0, import_cookie.parse)(request2.headers.cookie || "");
|
|
2996
1803
|
const config = this.getConfigWithOverrides(cookies);
|
|
2997
|
-
const
|
|
2998
|
-
if (!
|
|
1804
|
+
const path6 = request2.url;
|
|
1805
|
+
if (!path6) {
|
|
2999
1806
|
return this.getDefaultHost(config);
|
|
3000
1807
|
}
|
|
3001
1808
|
const authTarget = this.getAuthTarget(request2, config);
|
|
3002
1809
|
if (authTarget) {
|
|
3003
1810
|
return authTarget;
|
|
3004
1811
|
}
|
|
3005
|
-
const url = new URL(`http://example.com${
|
|
1812
|
+
const url = new URL(`http://example.com${path6}`);
|
|
3006
1813
|
const pathname = url.pathname;
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
return target;
|
|
3015
|
-
} else {
|
|
3016
|
-
const target = this.findMatchingApplicationV1(
|
|
3017
|
-
path7,
|
|
3018
|
-
pathname,
|
|
3019
|
-
config.getAllApplications()
|
|
3020
|
-
);
|
|
3021
|
-
if (target)
|
|
3022
|
-
return target;
|
|
3023
|
-
}
|
|
1814
|
+
const target = this.findMatchingApplication(
|
|
1815
|
+
path6,
|
|
1816
|
+
pathname,
|
|
1817
|
+
config.getChildApplications()
|
|
1818
|
+
);
|
|
1819
|
+
if (target)
|
|
1820
|
+
return target;
|
|
3024
1821
|
const defaultHost = this.getDefaultHost(config);
|
|
3025
1822
|
mfeDebug(
|
|
3026
|
-
`no matching routes, routing ${
|
|
1823
|
+
`no matching routes, routing ${path6} to default application: ${JSON.stringify(defaultHost)}`
|
|
3027
1824
|
);
|
|
3028
|
-
return { path:
|
|
3029
|
-
}
|
|
3030
|
-
findMatchingApplicationV1(path7, pathname, applications) {
|
|
3031
|
-
for (const application of Object.values(applications)) {
|
|
3032
|
-
if (application.routing) {
|
|
3033
|
-
for (const group of application.routing.matches) {
|
|
3034
|
-
for (const childPath of group.paths) {
|
|
3035
|
-
const regexp = (0, import_path_to_regexp4.pathToRegexp)(childPath);
|
|
3036
|
-
if (regexp.test(pathname)) {
|
|
3037
|
-
const target = this.getApplicationTarget(application);
|
|
3038
|
-
mfeDebug(
|
|
3039
|
-
`routing ${path7} to '${target.application}' at ${target.hostname}`
|
|
3040
|
-
);
|
|
3041
|
-
return { path: path7, ...target };
|
|
3042
|
-
}
|
|
3043
|
-
}
|
|
3044
|
-
if (application.routing.assetPrefix) {
|
|
3045
|
-
const pattern = (0, import_path_to_regexp4.pathToRegexp)(
|
|
3046
|
-
`/${application.routing.assetPrefix}/:path+`
|
|
3047
|
-
);
|
|
3048
|
-
if (pattern.test(pathname)) {
|
|
3049
|
-
const target = this.getApplicationTarget(application);
|
|
3050
|
-
mfeDebug(
|
|
3051
|
-
`routing ${path7} to '${target.application}' at ${target.hostname}`
|
|
3052
|
-
);
|
|
3053
|
-
return { path: path7, ...target };
|
|
3054
|
-
}
|
|
3055
|
-
}
|
|
3056
|
-
}
|
|
3057
|
-
}
|
|
3058
|
-
}
|
|
3059
|
-
return null;
|
|
1825
|
+
return { path: path6, ...defaultHost };
|
|
3060
1826
|
}
|
|
3061
|
-
|
|
1827
|
+
findMatchingApplication(path6, pathname, applications) {
|
|
3062
1828
|
for (const application of Object.values(applications)) {
|
|
3063
1829
|
for (const group of application.routing) {
|
|
3064
1830
|
for (const childPath of group.paths) {
|
|
3065
|
-
const regexp = (0,
|
|
1831
|
+
const regexp = (0, import_path_to_regexp3.pathToRegexp)(childPath);
|
|
3066
1832
|
if (regexp.test(pathname)) {
|
|
3067
1833
|
const target = this.getApplicationTarget(application);
|
|
3068
1834
|
mfeDebug(
|
|
3069
|
-
`routing ${
|
|
1835
|
+
`routing ${path6} to '${target.application}' at ${target.hostname}`
|
|
3070
1836
|
);
|
|
3071
|
-
return { path:
|
|
1837
|
+
return { path: path6, ...target };
|
|
3072
1838
|
}
|
|
3073
1839
|
}
|
|
3074
1840
|
}
|
|
@@ -3077,11 +1843,11 @@ var LocalProxy = class {
|
|
|
3077
1843
|
}
|
|
3078
1844
|
// Handles requests that return data from the local proxy itself.
|
|
3079
1845
|
// Returns true if the request was handled, false otherwise.
|
|
3080
|
-
handleProxyInfoRequest(
|
|
3081
|
-
if (!
|
|
1846
|
+
handleProxyInfoRequest(path6, res) {
|
|
1847
|
+
if (!path6) {
|
|
3082
1848
|
return false;
|
|
3083
1849
|
}
|
|
3084
|
-
const url = new URL(`http://example.comf${
|
|
1850
|
+
const url = new URL(`http://example.comf${path6}`);
|
|
3085
1851
|
const pathname = url.pathname;
|
|
3086
1852
|
switch (pathname) {
|
|
3087
1853
|
case "/.well-known/vercel/microfrontends/routing": {
|
|
@@ -3109,10 +1875,10 @@ var LocalProxy = class {
|
|
|
3109
1875
|
}
|
|
3110
1876
|
const target = this.getTarget(req);
|
|
3111
1877
|
if (target.protocol === "https") {
|
|
3112
|
-
const { hostname, port, path:
|
|
1878
|
+
const { hostname, port, path: path6 } = target;
|
|
3113
1879
|
const requestOptions = {
|
|
3114
1880
|
hostname,
|
|
3115
|
-
path:
|
|
1881
|
+
path: path6,
|
|
3116
1882
|
method: req.method,
|
|
3117
1883
|
headers: {
|
|
3118
1884
|
...req.headers,
|
|
@@ -3140,7 +1906,7 @@ var LocalProxy = class {
|
|
|
3140
1906
|
console.error("Proxy request error: ", err);
|
|
3141
1907
|
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
3142
1908
|
res.end(
|
|
3143
|
-
`Error proxying request for ${target.application} to ${hostname}:${port}${
|
|
1909
|
+
`Error proxying request for ${target.application} to ${hostname}:${port}${path6}`
|
|
3144
1910
|
);
|
|
3145
1911
|
});
|
|
3146
1912
|
} else {
|
|
@@ -3171,13 +1937,13 @@ var LocalProxy = class {
|
|
|
3171
1937
|
var import_node_process = require("process");
|
|
3172
1938
|
|
|
3173
1939
|
// src/utils/mfe-port.ts
|
|
3174
|
-
var
|
|
3175
|
-
var
|
|
1940
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
1941
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
3176
1942
|
function mfePort(packageDir) {
|
|
3177
1943
|
const { name: appName, version } = getPackageJson(packageDir);
|
|
3178
|
-
const result =
|
|
1944
|
+
const result = loadConfig({ packageDir, appName });
|
|
3179
1945
|
if (!result) {
|
|
3180
|
-
throw new
|
|
1946
|
+
throw new MicrofrontendError(
|
|
3181
1947
|
`Unable to determine configured port for ${appName}`,
|
|
3182
1948
|
{ type: "config", subtype: "not_found" }
|
|
3183
1949
|
);
|
|
@@ -3190,10 +1956,10 @@ function mfePort(packageDir) {
|
|
|
3190
1956
|
};
|
|
3191
1957
|
}
|
|
3192
1958
|
function getPackageJson(packageDir) {
|
|
3193
|
-
const filePath =
|
|
3194
|
-
return JSON.parse(
|
|
1959
|
+
const filePath = import_node_path9.default.join(packageDir, "package.json");
|
|
1960
|
+
return JSON.parse(import_node_fs8.default.readFileSync(filePath, "utf-8"));
|
|
3195
1961
|
}
|
|
3196
|
-
function
|
|
1962
|
+
function loadConfig({
|
|
3197
1963
|
packageDir,
|
|
3198
1964
|
appName
|
|
3199
1965
|
}) {
|
|
@@ -3211,21 +1977,6 @@ function loadV2({
|
|
|
3211
1977
|
const port = app.development.local.port;
|
|
3212
1978
|
return { port };
|
|
3213
1979
|
}
|
|
3214
|
-
function loadV1({
|
|
3215
|
-
packageDir,
|
|
3216
|
-
appName
|
|
3217
|
-
}) {
|
|
3218
|
-
const filePath = import_node_path11.default.join(packageDir, "micro-frontends.jsonc");
|
|
3219
|
-
let config;
|
|
3220
|
-
try {
|
|
3221
|
-
config = MicrofrontendConfig.fromFile({ filePath });
|
|
3222
|
-
} catch (e) {
|
|
3223
|
-
return void 0;
|
|
3224
|
-
}
|
|
3225
|
-
const zone = config.getZone(appName);
|
|
3226
|
-
const port = zone.development.local.port;
|
|
3227
|
-
return { port };
|
|
3228
|
-
}
|
|
3229
1980
|
|
|
3230
1981
|
// src/bin/port.ts
|
|
3231
1982
|
function displayPort() {
|