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