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