@vercel/microfrontends 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +202 -0
- package/cli/index.cjs +21 -0
- package/dist/bin/cli.cjs +1604 -0
- package/dist/config/client.cjs +54 -0
- package/dist/config/client.cjs.map +1 -0
- package/dist/config/client.d.ts +23 -0
- package/dist/config/client.js +28 -0
- package/dist/config/client.js.map +1 -0
- package/dist/config/edge.cjs +508 -0
- package/dist/config/edge.cjs.map +1 -0
- package/dist/config/edge.d.ts +20 -0
- package/dist/config/edge.js +481 -0
- package/dist/config/edge.js.map +1 -0
- package/dist/config.cjs +1254 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.js +1212 -0
- package/dist/config.js.map +1 -0
- package/dist/index-eff254d8.d.ts +175 -0
- package/dist/micro-frontend-config-42886104.d.ts +154 -0
- package/dist/next/client.cjs +3 -0
- package/dist/next/client.cjs.map +1 -0
- package/dist/next/client.d.ts +45 -0
- package/dist/next/client.js +3 -0
- package/dist/next/client.js.map +1 -0
- package/dist/next/config.cjs +1793 -0
- package/dist/next/config.cjs.map +1 -0
- package/dist/next/config.d.ts +22 -0
- package/dist/next/config.js +1758 -0
- package/dist/next/config.js.map +1 -0
- package/dist/next/endpoints.cjs +82 -0
- package/dist/next/endpoints.cjs.map +1 -0
- package/dist/next/endpoints.d.ts +15 -0
- package/dist/next/endpoints.js +57 -0
- package/dist/next/endpoints.js.map +1 -0
- package/dist/next/middleware.cjs +763 -0
- package/dist/next/middleware.cjs.map +1 -0
- package/dist/next/middleware.d.ts +29 -0
- package/dist/next/middleware.js +735 -0
- package/dist/next/middleware.js.map +1 -0
- package/dist/next/testing.cjs +1430 -0
- package/dist/next/testing.cjs.map +1 -0
- package/dist/next/testing.d.ts +53 -0
- package/dist/next/testing.js +1389 -0
- package/dist/next/testing.js.map +1 -0
- package/dist/overrides.cjs +143 -0
- package/dist/overrides.cjs.map +1 -0
- package/dist/overrides.d.ts +2 -0
- package/dist/overrides.js +115 -0
- package/dist/overrides.js.map +1 -0
- package/dist/schema-83a75e61.d.ts +188 -0
- package/dist/types-4fd1c7c6.d.ts +157 -0
- package/dist/v2/config.cjs +720 -0
- package/dist/v2/config.cjs.map +1 -0
- package/dist/v2/config.d.ts +2 -0
- package/dist/v2/config.js +695 -0
- package/dist/v2/config.js.map +1 -0
- package/dist/v2/microfrontends/server.cjs +1312 -0
- package/dist/v2/microfrontends/server.cjs.map +1 -0
- package/dist/v2/microfrontends/server.d.ts +48 -0
- package/dist/v2/microfrontends/server.js +1277 -0
- package/dist/v2/microfrontends/server.js.map +1 -0
- package/dist/v2/microfrontends.cjs +803 -0
- package/dist/v2/microfrontends.cjs.map +1 -0
- package/dist/v2/microfrontends.d.ts +44 -0
- package/dist/v2/microfrontends.js +776 -0
- package/dist/v2/microfrontends.js.map +1 -0
- package/dist/v2/next/client.cjs +3 -0
- package/dist/v2/next/client.cjs.map +1 -0
- package/dist/v2/next/client.d.ts +45 -0
- package/dist/v2/next/client.js +3 -0
- package/dist/v2/next/client.js.map +1 -0
- package/dist/v2/next/config.cjs +1829 -0
- package/dist/v2/next/config.cjs.map +1 -0
- package/dist/v2/next/config.d.ts +22 -0
- package/dist/v2/next/config.js +1794 -0
- package/dist/v2/next/config.js.map +1 -0
- package/dist/v2/next/endpoints.cjs +138 -0
- package/dist/v2/next/endpoints.cjs.map +1 -0
- package/dist/v2/next/endpoints.d.ts +15 -0
- package/dist/v2/next/endpoints.js +113 -0
- package/dist/v2/next/endpoints.js.map +1 -0
- package/dist/v2/next/middleware.cjs +1110 -0
- package/dist/v2/next/middleware.cjs.map +1 -0
- package/dist/v2/next/middleware.d.ts +29 -0
- package/dist/v2/next/middleware.js +1082 -0
- package/dist/v2/next/middleware.js.map +1 -0
- package/dist/v2/schema.cjs +19 -0
- package/dist/v2/schema.cjs.map +1 -0
- package/dist/v2/schema.d.ts +1 -0
- package/dist/v2/schema.js +1 -0
- package/dist/v2/schema.js.map +1 -0
- package/dist/validation.cjs +754 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.ts +163 -0
- package/dist/validation.js +726 -0
- package/dist/validation.js.map +1 -0
- package/package.json +204 -0
- package/schema/schema-v2.json +288 -0
- package/schema/schema.json +352 -0
package/dist/bin/cli.cjs
ADDED
|
@@ -0,0 +1,1604 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/bin/index.ts
|
|
27
|
+
var import_commander = require("commander");
|
|
28
|
+
|
|
29
|
+
// package.json
|
|
30
|
+
var package_default = {
|
|
31
|
+
name: "@vercel/microfrontends",
|
|
32
|
+
version: "0.9.0",
|
|
33
|
+
private: false,
|
|
34
|
+
description: "Defines configuration and utilities for micro-frontend development",
|
|
35
|
+
repository: {
|
|
36
|
+
type: "git",
|
|
37
|
+
url: "https://github.com/vercel/front.git",
|
|
38
|
+
directory: "packages/microfrontends"
|
|
39
|
+
},
|
|
40
|
+
sideEffects: false,
|
|
41
|
+
type: "module",
|
|
42
|
+
bin: {
|
|
43
|
+
"micro-frontends": "./cli/index.cjs"
|
|
44
|
+
},
|
|
45
|
+
exports: {
|
|
46
|
+
"./validation": {
|
|
47
|
+
import: "./dist/validation.js",
|
|
48
|
+
require: "./dist/validation.cjs"
|
|
49
|
+
},
|
|
50
|
+
"./config": {
|
|
51
|
+
import: "./dist/config.js",
|
|
52
|
+
require: "./dist/config.cjs"
|
|
53
|
+
},
|
|
54
|
+
"./config/client": {
|
|
55
|
+
import: "./dist/config/client.js",
|
|
56
|
+
require: "./dist/config/client.cjs"
|
|
57
|
+
},
|
|
58
|
+
"./config/edge": {
|
|
59
|
+
import: "./dist/config/edge.js",
|
|
60
|
+
require: "./dist/config/edge.cjs"
|
|
61
|
+
},
|
|
62
|
+
"./overrides": {
|
|
63
|
+
import: "./dist/overrides.js",
|
|
64
|
+
require: "./dist/overrides.cjs"
|
|
65
|
+
},
|
|
66
|
+
"./next/config": {
|
|
67
|
+
import: "./dist/next/config.js",
|
|
68
|
+
require: "./dist/next/config.cjs"
|
|
69
|
+
},
|
|
70
|
+
"./next/middleware": {
|
|
71
|
+
import: "./dist/next/middleware.js",
|
|
72
|
+
require: "./dist/next/middleware.cjs"
|
|
73
|
+
},
|
|
74
|
+
"./next/endpoints": {
|
|
75
|
+
import: "./dist/next/endpoints.js",
|
|
76
|
+
require: "./dist/next/endpoints.cjs"
|
|
77
|
+
},
|
|
78
|
+
"./next/testing": {
|
|
79
|
+
import: "./dist/next/testing.js",
|
|
80
|
+
require: "./dist/next/testing.cjs"
|
|
81
|
+
},
|
|
82
|
+
"./v2/config": {
|
|
83
|
+
import: "./dist/v2/config.js",
|
|
84
|
+
require: "./dist/v2/config.cjs"
|
|
85
|
+
},
|
|
86
|
+
"./v2/microfrontends": {
|
|
87
|
+
import: "./dist/v2/microfrontends.js",
|
|
88
|
+
require: "./dist/v2/microfrontends.cjs"
|
|
89
|
+
},
|
|
90
|
+
"./v2/microfrontends/server": {
|
|
91
|
+
import: "./dist/v2/microfrontends/server.js",
|
|
92
|
+
require: "./dist/v2/microfrontends/server.cjs"
|
|
93
|
+
},
|
|
94
|
+
"./v2/schema": {
|
|
95
|
+
import: "./dist/v2/schema.js",
|
|
96
|
+
require: "./dist/v2/schema.cjs"
|
|
97
|
+
},
|
|
98
|
+
"./v2/next/config": {
|
|
99
|
+
import: "./dist/v2/next/config.js",
|
|
100
|
+
require: "./dist/v2/next/config.cjs"
|
|
101
|
+
},
|
|
102
|
+
"./v2/next/middleware": {
|
|
103
|
+
import: "./dist/v2/next/middleware.js",
|
|
104
|
+
require: "./dist/v2/next/middleware.cjs"
|
|
105
|
+
},
|
|
106
|
+
"./v2/next/endpoints": {
|
|
107
|
+
import: "./dist/v2/next/endpoints.js",
|
|
108
|
+
require: "./dist/v2/next/endpoints.cjs"
|
|
109
|
+
},
|
|
110
|
+
"./next/client": {
|
|
111
|
+
import: "./dist/next/client.js",
|
|
112
|
+
require: "./dist/next/client.cjs"
|
|
113
|
+
},
|
|
114
|
+
"./v2/next/client": {
|
|
115
|
+
import: "./dist/v2/next/client.js",
|
|
116
|
+
require: "./dist/v2/next/client.cjs"
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
typesVersions: {
|
|
120
|
+
"*": {
|
|
121
|
+
validation: ["./dist/validation.d.ts"],
|
|
122
|
+
config: ["./dist/config.d.ts"],
|
|
123
|
+
"config/client": ["./dist/config/client.d.ts"],
|
|
124
|
+
"config/edge": ["./dist/config/edge.d.ts"],
|
|
125
|
+
overrides: ["./dist/overrides.d.ts"],
|
|
126
|
+
"next/config": ["./dist/next/config.d.ts"],
|
|
127
|
+
"next/middleware": ["./dist/next/middleware.d.ts"],
|
|
128
|
+
"next/endpoints": ["./dist/next/endpoints.d.ts"],
|
|
129
|
+
"next/testing": ["./dist/next/testing.d.ts"],
|
|
130
|
+
"v2/config": ["./dist/v2/config.d.ts"],
|
|
131
|
+
"v2/microfrontends": ["./dist/v2/microfrontends.d.ts"],
|
|
132
|
+
"v2/microfrontends/server": ["./dist/v2/microfrontends/server.d.ts"],
|
|
133
|
+
"v2/schema": ["./dist/v2/schema.d.ts"],
|
|
134
|
+
"v2/next/config": ["./dist/v2/next/config.d.ts"],
|
|
135
|
+
"v2/next/middleware": ["./dist/v2/next/middleware.d.ts"],
|
|
136
|
+
"v2/next/endpoints": ["./dist/v2/next/endpoints.d.ts"],
|
|
137
|
+
"next/client": ["./dist/next/client.d.ts"],
|
|
138
|
+
"v2/next/client": ["./dist/v2/next/client.d.ts"]
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
files: ["dist", "schema"],
|
|
142
|
+
scripts: {
|
|
143
|
+
build: "tsup",
|
|
144
|
+
postbuild: "pnpm generate:exports",
|
|
145
|
+
"generate:schema": "tsx scripts/generate-json-schema.ts",
|
|
146
|
+
"generate:exports": "tsx scripts/generate-exports/index.ts",
|
|
147
|
+
conformance: "vercel conformance",
|
|
148
|
+
eslint: "eslint-runner",
|
|
149
|
+
"eslint-fix": "eslint-runner --fix",
|
|
150
|
+
prepublishOnly: "pnpm build && pnpm generate:exports && pnpm generate:schema",
|
|
151
|
+
"type-check": "tsc --noEmit",
|
|
152
|
+
"unit-test": "cross-env TZ=UTC jest",
|
|
153
|
+
proxy: "tsx src/proxy/index.ts"
|
|
154
|
+
},
|
|
155
|
+
dependencies: {
|
|
156
|
+
ajv: "^8.17.1",
|
|
157
|
+
commander: "^12.1.0",
|
|
158
|
+
cookie: "0.4.0",
|
|
159
|
+
"http-proxy": "^1.18.1",
|
|
160
|
+
"jsonc-parser": "^3.3.1",
|
|
161
|
+
"path-to-regexp": "6.2.1"
|
|
162
|
+
},
|
|
163
|
+
devDependencies: {
|
|
164
|
+
"@edge-runtime/types": "^3.0.2",
|
|
165
|
+
"@pyra/eslint-config": "workspace:*",
|
|
166
|
+
"@pyra/typescript-config": "workspace:*",
|
|
167
|
+
"@testing-library/react": "^15.0.7",
|
|
168
|
+
"@types/cookie": "0.5.1",
|
|
169
|
+
"@types/http-proxy": "^1.17.15",
|
|
170
|
+
"@types/jest": "^29.2.0",
|
|
171
|
+
"@types/json-schema": "^7.0.15",
|
|
172
|
+
"@types/node": "20.11.30",
|
|
173
|
+
"@types/react": "18.3.1",
|
|
174
|
+
"@types/react-dom": "18.3.0",
|
|
175
|
+
"@vercel-private/conformance": "^1.12.2-canary.0",
|
|
176
|
+
jest: "^29.7.0",
|
|
177
|
+
"jest-environment-jsdom": "29.2.2",
|
|
178
|
+
next: "15.0.4-canary.17",
|
|
179
|
+
react: "19.0.0-rc-380f5d67-20241113",
|
|
180
|
+
"react-dom": "19.0.0-rc-380f5d67-20241113",
|
|
181
|
+
"ts-json-schema-generator": "^1.1.2",
|
|
182
|
+
tsup: "^6.6.2",
|
|
183
|
+
tsx: "^4.6.2",
|
|
184
|
+
typescript: "5.6.3",
|
|
185
|
+
webpack: "5"
|
|
186
|
+
},
|
|
187
|
+
peerDependencies: {
|
|
188
|
+
next: "15.0.4-canary.17",
|
|
189
|
+
react: "19.0.0-rc-380f5d67-20241113",
|
|
190
|
+
"react-dom": "19.0.0-rc-380f5d67-20241113"
|
|
191
|
+
},
|
|
192
|
+
publishConfig: {
|
|
193
|
+
access: "restricted"
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/bin/local-proxy.ts
|
|
198
|
+
var http = __toESM(require("http"), 1);
|
|
199
|
+
var https = __toESM(require("https"), 1);
|
|
200
|
+
var import_cookie = require("cookie");
|
|
201
|
+
var import_path_to_regexp2 = require("path-to-regexp");
|
|
202
|
+
var import_http_proxy = __toESM(require("http-proxy"), 1);
|
|
203
|
+
|
|
204
|
+
// src/config/types.ts
|
|
205
|
+
var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
|
|
206
|
+
|
|
207
|
+
// src/config/micro-frontend-config.ts
|
|
208
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
209
|
+
|
|
210
|
+
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
211
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
212
|
+
|
|
213
|
+
// src/config-v2/microfrontends/server/constants.ts
|
|
214
|
+
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
215
|
+
var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
216
|
+
|
|
217
|
+
// src/utils/is-vercel.ts
|
|
218
|
+
function isVercel() {
|
|
219
|
+
return process.env.VERCEL === "1";
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/config-v2/microfrontends/server/utils/get-output-file-path.ts
|
|
223
|
+
function getOutputFilePath() {
|
|
224
|
+
if (isVercel()) {
|
|
225
|
+
return import_node_path.default.join(
|
|
226
|
+
".vercel",
|
|
227
|
+
MFE_CONFIG_DEFAULT_FILE_PATH,
|
|
228
|
+
MFE_CONFIG_DEFAULT_FILE_NAME
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
return import_node_path.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/config/errors.ts
|
|
235
|
+
var MicroFrontendError = class extends Error {
|
|
236
|
+
constructor(message, opts) {
|
|
237
|
+
super(message);
|
|
238
|
+
this.name = "MicroFrontendsError";
|
|
239
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
|
|
240
|
+
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
241
|
+
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
242
|
+
Error.captureStackTrace(this, MicroFrontendError);
|
|
243
|
+
}
|
|
244
|
+
isKnown() {
|
|
245
|
+
return this.type !== "unknown";
|
|
246
|
+
}
|
|
247
|
+
isUnknown() {
|
|
248
|
+
return !this.isKnown();
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Converts an error to a MicroFrontendsError.
|
|
252
|
+
* @param original - The original error to convert.
|
|
253
|
+
* @returns The converted MicroFrontendsError.
|
|
254
|
+
*/
|
|
255
|
+
static convert(original, opts) {
|
|
256
|
+
if (opts == null ? void 0 : opts.fileName) {
|
|
257
|
+
const err = MicroFrontendError.convertFSError(original, opts.fileName);
|
|
258
|
+
if (err) {
|
|
259
|
+
return err;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (original.message.includes(
|
|
263
|
+
"Code generation from strings disallowed for this context"
|
|
264
|
+
)) {
|
|
265
|
+
return new MicroFrontendError(original.message, {
|
|
266
|
+
type: "config",
|
|
267
|
+
subtype: "unsupported_validation_env",
|
|
268
|
+
source: "ajv"
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return new MicroFrontendError(original.message);
|
|
272
|
+
}
|
|
273
|
+
static convertFSError(original, fileName) {
|
|
274
|
+
if (original instanceof Error && "code" in original) {
|
|
275
|
+
if (original.code === "ENOENT") {
|
|
276
|
+
return new MicroFrontendError(`Could not find "${fileName}"`, {
|
|
277
|
+
type: "config",
|
|
278
|
+
subtype: "unable_to_read_file",
|
|
279
|
+
source: "fs"
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
if (original.code === "EACCES") {
|
|
283
|
+
return new MicroFrontendError(
|
|
284
|
+
`Permission denied while accessing "${fileName}"`,
|
|
285
|
+
{
|
|
286
|
+
type: "config",
|
|
287
|
+
subtype: "invalid_permissions",
|
|
288
|
+
source: "fs"
|
|
289
|
+
}
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (original instanceof SyntaxError) {
|
|
294
|
+
return new MicroFrontendError(
|
|
295
|
+
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
296
|
+
{
|
|
297
|
+
type: "config",
|
|
298
|
+
subtype: "invalid_syntax",
|
|
299
|
+
source: "fs"
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Handles an unknown error and returns a MicroFrontendsError instance.
|
|
307
|
+
* @param err - The error to handle.
|
|
308
|
+
* @returns A MicroFrontendsError instance.
|
|
309
|
+
*/
|
|
310
|
+
static handle(err, opts) {
|
|
311
|
+
if (err instanceof MicroFrontendError) {
|
|
312
|
+
return err;
|
|
313
|
+
}
|
|
314
|
+
if (err instanceof Error) {
|
|
315
|
+
return MicroFrontendError.convert(err, opts);
|
|
316
|
+
}
|
|
317
|
+
if (typeof err === "object" && err !== null) {
|
|
318
|
+
if ("message" in err && typeof err.message === "string") {
|
|
319
|
+
return MicroFrontendError.convert(new Error(err.message), opts);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return new MicroFrontendError("An unknown error occurred");
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
// src/routing/url.ts
|
|
327
|
+
function buildUrlSafeString(givenOpts = {}) {
|
|
328
|
+
const options = {
|
|
329
|
+
joinString: "-",
|
|
330
|
+
lowercaseOnly: true,
|
|
331
|
+
maxLen: 100,
|
|
332
|
+
regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,
|
|
333
|
+
trimWhitespace: true,
|
|
334
|
+
...givenOpts
|
|
335
|
+
};
|
|
336
|
+
return {
|
|
337
|
+
generate: (...args) => {
|
|
338
|
+
const reJoinString = new RegExp(`${options.joinString}+`, "g");
|
|
339
|
+
let tag;
|
|
340
|
+
if (args.length === 0) {
|
|
341
|
+
throw new Error("generate method must be passed at least one argument");
|
|
342
|
+
}
|
|
343
|
+
for (let i = 0; i < args.length; i++) {
|
|
344
|
+
const arg = args[i];
|
|
345
|
+
if (typeof arg !== "string")
|
|
346
|
+
throw new Error("all supplied arguments must be Strings");
|
|
347
|
+
if (options.trimWhitespace) {
|
|
348
|
+
args[i] = arg.trim();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
tag = args.join(options.joinString);
|
|
352
|
+
tag = tag.replace(/\s/g, options.joinString);
|
|
353
|
+
if (options.lowercaseOnly)
|
|
354
|
+
tag = tag.toLowerCase();
|
|
355
|
+
tag = tag.replace(options.regexRemovePattern, (match) => {
|
|
356
|
+
if (match === options.joinString)
|
|
357
|
+
return match;
|
|
358
|
+
return "";
|
|
359
|
+
});
|
|
360
|
+
if (tag.length > options.maxLen)
|
|
361
|
+
tag = tag.substring(0, options.maxLen);
|
|
362
|
+
tag = tag.replace(reJoinString, options.joinString);
|
|
363
|
+
return tag;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
var urlSafeString = buildUrlSafeString().generate;
|
|
368
|
+
function makeUrlSafe(name) {
|
|
369
|
+
return urlSafeString(name.replace(/\//g, "-")).replace(/^-*/g, "").replace(/-*$/g, "");
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/config/overrides/config.ts
|
|
373
|
+
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
374
|
+
var _Overrides = class {
|
|
375
|
+
constructor(config) {
|
|
376
|
+
this.config = config;
|
|
377
|
+
}
|
|
378
|
+
static getAppEnvOverrideCookieName(zone) {
|
|
379
|
+
return `${_Overrides.overrideEnvCookiePrefix}${zone}`;
|
|
380
|
+
}
|
|
381
|
+
static isOverrideCookie(cookie) {
|
|
382
|
+
var _a;
|
|
383
|
+
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
384
|
+
}
|
|
385
|
+
static getOverrideFromCookie(cookie) {
|
|
386
|
+
if (!_Overrides.isOverrideCookie(cookie) || !cookie.value)
|
|
387
|
+
return;
|
|
388
|
+
return {
|
|
389
|
+
zone: cookie.name.replace(_Overrides.overrideEnvCookiePrefix, ""),
|
|
390
|
+
host: cookie.value
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
static parseOverrides(cookies) {
|
|
394
|
+
const overridesConfig = { applications: {} };
|
|
395
|
+
cookies.forEach((cookie) => {
|
|
396
|
+
const override = _Overrides.getOverrideFromCookie(cookie);
|
|
397
|
+
if (!override)
|
|
398
|
+
return;
|
|
399
|
+
overridesConfig.applications[override.zone] = {
|
|
400
|
+
environment: { host: override.host }
|
|
401
|
+
};
|
|
402
|
+
});
|
|
403
|
+
return overridesConfig;
|
|
404
|
+
}
|
|
405
|
+
static validOverrideDomainsForZone(microFrontendConfig, zone) {
|
|
406
|
+
var _a, _b, _c, _d, _e;
|
|
407
|
+
const projectName = (_a = microFrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
408
|
+
if (!projectName) {
|
|
409
|
+
return [microFrontendConfig.getZone(zone).production.host];
|
|
410
|
+
}
|
|
411
|
+
const parsedProjectName = makeUrlSafe(projectName);
|
|
412
|
+
const previewDeploymentSuffix = (_c = (_b = microFrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
|
|
413
|
+
const teamSlug = (_e = (_d = microFrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
|
|
414
|
+
if (!teamSlug && !previewDeploymentSuffix) {
|
|
415
|
+
return [microFrontendConfig.getZone(zone).production.host];
|
|
416
|
+
}
|
|
417
|
+
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
418
|
+
return [
|
|
419
|
+
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
420
|
+
microFrontendConfig.getZone(zone).production.host
|
|
421
|
+
];
|
|
422
|
+
}
|
|
423
|
+
static validateOverrideDomain(microFrontendConfig, zone, domain) {
|
|
424
|
+
return new RegExp(
|
|
425
|
+
`^${_Overrides.validOverrideDomainsForZone(microFrontendConfig, zone).join(
|
|
426
|
+
"|"
|
|
427
|
+
)}$`
|
|
428
|
+
).test(domain);
|
|
429
|
+
}
|
|
430
|
+
serialize() {
|
|
431
|
+
return this.config;
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
var Overrides = _Overrides;
|
|
435
|
+
Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
436
|
+
|
|
437
|
+
// src/config/common/host.ts
|
|
438
|
+
var Host = class {
|
|
439
|
+
constructor({ protocol, host, port }) {
|
|
440
|
+
this.protocol = protocol || "https";
|
|
441
|
+
this.host = host;
|
|
442
|
+
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
443
|
+
this.serialized = {
|
|
444
|
+
protocol,
|
|
445
|
+
host,
|
|
446
|
+
...port ? { port } : void 0
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
isLocal() {
|
|
450
|
+
return this.host === "localhost" || this.host === "127.0.0.1";
|
|
451
|
+
}
|
|
452
|
+
static getPort({
|
|
453
|
+
protocol,
|
|
454
|
+
port
|
|
455
|
+
}) {
|
|
456
|
+
if (!port) {
|
|
457
|
+
if (protocol === "http") {
|
|
458
|
+
return 80;
|
|
459
|
+
}
|
|
460
|
+
return 443;
|
|
461
|
+
}
|
|
462
|
+
return port;
|
|
463
|
+
}
|
|
464
|
+
isDefaultPort() {
|
|
465
|
+
return this.port === Host.getPort({ protocol: this.protocol });
|
|
466
|
+
}
|
|
467
|
+
toString(opts = {}) {
|
|
468
|
+
const url = this.toUrl(opts);
|
|
469
|
+
return url.toString().replace(/\/$/, "");
|
|
470
|
+
}
|
|
471
|
+
toUrl(opts = {}) {
|
|
472
|
+
const { includeDefaultPort } = opts;
|
|
473
|
+
const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
|
|
474
|
+
return new URL(url);
|
|
475
|
+
}
|
|
476
|
+
serialize() {
|
|
477
|
+
return this.serialized;
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
// src/config/common/application.ts
|
|
482
|
+
var Application = class {
|
|
483
|
+
constructor(name, {
|
|
484
|
+
app,
|
|
485
|
+
overrides
|
|
486
|
+
}) {
|
|
487
|
+
Application.validate(name, app);
|
|
488
|
+
this.name = name;
|
|
489
|
+
this.default = app.default;
|
|
490
|
+
this.routing = app.routing;
|
|
491
|
+
this.development = {
|
|
492
|
+
local: new Host(app.development.local),
|
|
493
|
+
fallback: app.development.fallback ? new Host(app.development.fallback) : void 0
|
|
494
|
+
};
|
|
495
|
+
this.production = new Host(app.production);
|
|
496
|
+
this.vercel = app.vercel;
|
|
497
|
+
this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
|
|
498
|
+
environment: new Host(overrides.environment)
|
|
499
|
+
} : void 0;
|
|
500
|
+
}
|
|
501
|
+
isDefault() {
|
|
502
|
+
return this.default;
|
|
503
|
+
}
|
|
504
|
+
static validate(name, app) {
|
|
505
|
+
var _a, _b, _c, _d, _e;
|
|
506
|
+
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("/"))) {
|
|
507
|
+
throw new MicroFrontendError(
|
|
508
|
+
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
509
|
+
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
for (const group of ((_e = app.routing) == null ? void 0 : _e.matches) ?? []) {
|
|
513
|
+
for (const p of group.paths) {
|
|
514
|
+
if (p === "/") {
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (p.endsWith("/")) {
|
|
518
|
+
throw new MicroFrontendError(
|
|
519
|
+
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
520
|
+
{ type: "zone", subtype: "invalid_path" }
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
if (!p.startsWith("/")) {
|
|
524
|
+
throw new MicroFrontendError(
|
|
525
|
+
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
526
|
+
{ type: "zone", subtype: "invalid_path" }
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
serialize() {
|
|
533
|
+
var _a, _b;
|
|
534
|
+
if (this.routing === void 0 || this.default) {
|
|
535
|
+
return {
|
|
536
|
+
default: true,
|
|
537
|
+
development: {
|
|
538
|
+
local: this.development.local.serialize(),
|
|
539
|
+
fallback: (_a = this.development.fallback) == null ? void 0 : _a.serialize()
|
|
540
|
+
},
|
|
541
|
+
production: this.production.serialize(),
|
|
542
|
+
vercel: this.vercel
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
return {
|
|
546
|
+
default: false,
|
|
547
|
+
routing: this.routing,
|
|
548
|
+
development: {
|
|
549
|
+
local: this.development.local.serialize(),
|
|
550
|
+
fallback: (_b = this.development.fallback) == null ? void 0 : _b.serialize()
|
|
551
|
+
},
|
|
552
|
+
production: this.production.serialize(),
|
|
553
|
+
vercel: this.vercel
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// src/config/common/micro-frontend-config.ts
|
|
559
|
+
var SUPPORTED_VERSIONS = ["1"];
|
|
560
|
+
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
561
|
+
var MicroFrontendConfigCommon = class {
|
|
562
|
+
constructor({
|
|
563
|
+
config,
|
|
564
|
+
overrides
|
|
565
|
+
}) {
|
|
566
|
+
this.zones = {};
|
|
567
|
+
var _a, _b, _c;
|
|
568
|
+
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
569
|
+
throw new MicroFrontendError(
|
|
570
|
+
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
571
|
+
", "
|
|
572
|
+
)}`,
|
|
573
|
+
{ type: "config", subtype: "unsupported_version" }
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
577
|
+
this.overrides = overrides && !disableOverrides ? new Overrides(overrides) : void 0;
|
|
578
|
+
for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {
|
|
579
|
+
this.zones[zoneName] = new Application(zoneName, {
|
|
580
|
+
app: zoneConfig,
|
|
581
|
+
overrides: !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.config.applications[zoneName] : void 0
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
this.config = config;
|
|
585
|
+
this.name = config.name;
|
|
586
|
+
this.version = config.version;
|
|
587
|
+
this.options = config.options;
|
|
588
|
+
this.$schema = config.$schema;
|
|
589
|
+
}
|
|
590
|
+
isOverridesDisabled() {
|
|
591
|
+
var _a, _b;
|
|
592
|
+
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
593
|
+
}
|
|
594
|
+
static getConfigFromEnv() {
|
|
595
|
+
const config = process.env.MFE_CONFIG;
|
|
596
|
+
if (!config) {
|
|
597
|
+
throw new MicroFrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
598
|
+
type: "config",
|
|
599
|
+
subtype: "not_found_in_env"
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
return config;
|
|
603
|
+
}
|
|
604
|
+
static fromEnv(_) {
|
|
605
|
+
throw new Error("Not implemented");
|
|
606
|
+
}
|
|
607
|
+
getConfig() {
|
|
608
|
+
return this.config;
|
|
609
|
+
}
|
|
610
|
+
getAllApplications() {
|
|
611
|
+
return Object.values(this.zones);
|
|
612
|
+
}
|
|
613
|
+
getZone(name) {
|
|
614
|
+
const zone = this.zones[name];
|
|
615
|
+
if (!zone) {
|
|
616
|
+
throw new MicroFrontendError(
|
|
617
|
+
`Could not find micro-frontends configuration for application "${name}"`,
|
|
618
|
+
{
|
|
619
|
+
type: "zone",
|
|
620
|
+
subtype: "not_found"
|
|
621
|
+
}
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
return zone;
|
|
625
|
+
}
|
|
626
|
+
getApplicationByProjectId(projectId) {
|
|
627
|
+
return Object.values(this.zones).find(
|
|
628
|
+
(zone) => {
|
|
629
|
+
var _a;
|
|
630
|
+
return ((_a = zone.vercel) == null ? void 0 : _a.projectId) === projectId;
|
|
631
|
+
}
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
getDefaultZone() {
|
|
635
|
+
const zone = Object.values(this.zones).find((z) => z.default);
|
|
636
|
+
if (!zone) {
|
|
637
|
+
throw new MicroFrontendError(
|
|
638
|
+
`Could not find default zone in micro-frontends configuration`,
|
|
639
|
+
{
|
|
640
|
+
type: "zone",
|
|
641
|
+
subtype: "not_found"
|
|
642
|
+
}
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
return zone;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Returns the configured port for the local proxy
|
|
649
|
+
*/
|
|
650
|
+
getLocalProxyPort() {
|
|
651
|
+
var _a, _b;
|
|
652
|
+
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Serializes the class back to the Schema type.
|
|
656
|
+
*
|
|
657
|
+
* NOTE: This is used when writing the config to disk and must always match the input Schema
|
|
658
|
+
*/
|
|
659
|
+
toSchemaJson() {
|
|
660
|
+
const applications = {};
|
|
661
|
+
for (const [name, zone] of Object.entries(this.zones)) {
|
|
662
|
+
applications[name] = zone.serialize();
|
|
663
|
+
}
|
|
664
|
+
return {
|
|
665
|
+
$schema: this.$schema,
|
|
666
|
+
name: this.name,
|
|
667
|
+
version: this.version,
|
|
668
|
+
options: this.options,
|
|
669
|
+
applications
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
serialize() {
|
|
673
|
+
var _a;
|
|
674
|
+
const applications = {};
|
|
675
|
+
for (const [name, zone] of Object.entries(this.zones)) {
|
|
676
|
+
applications[name] = zone.serialize();
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
config: {
|
|
680
|
+
name: this.name,
|
|
681
|
+
version: this.version,
|
|
682
|
+
applications,
|
|
683
|
+
options: this.options,
|
|
684
|
+
$schema: this.$schema
|
|
685
|
+
},
|
|
686
|
+
overrides: (_a = this.overrides) == null ? void 0 : _a.serialize()
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
write(_) {
|
|
690
|
+
throw new MicroFrontendError(
|
|
691
|
+
`Writing to file to disk requires using an instance of "MicroFrontendConfig".`,
|
|
692
|
+
{ type: "config", subtype: "unsupported_operation" }
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
// src/config/utils/get-output-file-path.ts
|
|
698
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
699
|
+
|
|
700
|
+
// src/config/constants.ts
|
|
701
|
+
var MFE_CONFIG_DEFAULT_FILE_PATH2 = "micro-frontends";
|
|
702
|
+
var MFE_CONFIG_DEFAULT_FILE_NAME2 = "micro-frontends.config.json";
|
|
703
|
+
|
|
704
|
+
// src/config/utils/get-output-file-path.ts
|
|
705
|
+
function getOutputFilePath2() {
|
|
706
|
+
if (isVercel()) {
|
|
707
|
+
return import_node_path2.default.join(
|
|
708
|
+
".vercel",
|
|
709
|
+
MFE_CONFIG_DEFAULT_FILE_PATH2,
|
|
710
|
+
MFE_CONFIG_DEFAULT_FILE_NAME2
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
return import_node_path2.default.join(MFE_CONFIG_DEFAULT_FILE_PATH2, MFE_CONFIG_DEFAULT_FILE_NAME2);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// src/config/validation.ts
|
|
717
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
718
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
719
|
+
var import_ajv = require("ajv");
|
|
720
|
+
|
|
721
|
+
// schema/schema.json
|
|
722
|
+
var schema_default = {
|
|
723
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
724
|
+
$ref: "#/definitions/Config",
|
|
725
|
+
definitions: {
|
|
726
|
+
Config: {
|
|
727
|
+
type: "object",
|
|
728
|
+
properties: {
|
|
729
|
+
version: {
|
|
730
|
+
type: "string"
|
|
731
|
+
},
|
|
732
|
+
$schema: {
|
|
733
|
+
type: "string"
|
|
734
|
+
},
|
|
735
|
+
name: {
|
|
736
|
+
type: "string",
|
|
737
|
+
description: 'Name for the micro-frontend site (eg. "vercel.com", "vercel-site" etc.).'
|
|
738
|
+
},
|
|
739
|
+
applications: {
|
|
740
|
+
$ref: "#/definitions/ApplicationConfigsById"
|
|
741
|
+
},
|
|
742
|
+
options: {
|
|
743
|
+
$ref: "#/definitions/Options",
|
|
744
|
+
description: "Optional configuration for the entire micro-frontends setup."
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
required: ["version", "applications"],
|
|
748
|
+
description: "Configuration for micro-frontend applications\n\nTODO: Add proxy configuration"
|
|
749
|
+
},
|
|
750
|
+
ApplicationConfigsById: {
|
|
751
|
+
type: "object",
|
|
752
|
+
additionalProperties: {
|
|
753
|
+
$ref: "#/definitions/ApplicationConfig"
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
ApplicationConfig: {
|
|
757
|
+
anyOf: [
|
|
758
|
+
{
|
|
759
|
+
$ref: "#/definitions/DefaultApplicationConfig"
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
$ref: "#/definitions/CommonApplicationConfig"
|
|
763
|
+
}
|
|
764
|
+
],
|
|
765
|
+
description: "A Micro-Frontend Deployment Target"
|
|
766
|
+
},
|
|
767
|
+
DefaultApplicationConfig: {
|
|
768
|
+
type: "object",
|
|
769
|
+
properties: {
|
|
770
|
+
default: {
|
|
771
|
+
type: "boolean",
|
|
772
|
+
const: true,
|
|
773
|
+
description: "The default application is used no other application is matched via the routing config"
|
|
774
|
+
},
|
|
775
|
+
routing: {
|
|
776
|
+
$ref: "#/definitions/Routing"
|
|
777
|
+
},
|
|
778
|
+
development: {
|
|
779
|
+
type: "object",
|
|
780
|
+
properties: {
|
|
781
|
+
local: {
|
|
782
|
+
$ref: "#/definitions/HostConfig"
|
|
783
|
+
},
|
|
784
|
+
fallback: {
|
|
785
|
+
$ref: "#/definitions/HostConfig",
|
|
786
|
+
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."
|
|
787
|
+
},
|
|
788
|
+
task: {
|
|
789
|
+
type: "string",
|
|
790
|
+
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
required: ["local"]
|
|
794
|
+
},
|
|
795
|
+
production: {
|
|
796
|
+
$ref: "#/definitions/HostConfig"
|
|
797
|
+
},
|
|
798
|
+
metadata: {
|
|
799
|
+
type: "object",
|
|
800
|
+
additionalProperties: {
|
|
801
|
+
type: "string"
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
federation: {
|
|
805
|
+
type: "object",
|
|
806
|
+
properties: {
|
|
807
|
+
exposes: {
|
|
808
|
+
type: "array",
|
|
809
|
+
items: {
|
|
810
|
+
type: "object",
|
|
811
|
+
properties: {
|
|
812
|
+
name: {
|
|
813
|
+
type: "string",
|
|
814
|
+
description: "The name of the module - should be used when importing the module from another application"
|
|
815
|
+
},
|
|
816
|
+
path: {
|
|
817
|
+
type: "string",
|
|
818
|
+
description: "Relative path to the module within its `application`"
|
|
819
|
+
}
|
|
820
|
+
},
|
|
821
|
+
required: ["name", "path"]
|
|
822
|
+
},
|
|
823
|
+
description: "Modules that are exposed by this application"
|
|
824
|
+
},
|
|
825
|
+
uses: {
|
|
826
|
+
type: "array",
|
|
827
|
+
items: {
|
|
828
|
+
type: "string"
|
|
829
|
+
},
|
|
830
|
+
description: "Modules that are used by this application. Only the name of the module is required."
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
},
|
|
834
|
+
vercel: {
|
|
835
|
+
$ref: "#/definitions/Vercel"
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
required: ["default", "development", "production"]
|
|
839
|
+
},
|
|
840
|
+
Routing: {
|
|
841
|
+
type: "object",
|
|
842
|
+
properties: {
|
|
843
|
+
assetPrefix: {
|
|
844
|
+
type: "string",
|
|
845
|
+
description: "[assetPrefix] for the application"
|
|
846
|
+
},
|
|
847
|
+
matches: {
|
|
848
|
+
type: "array",
|
|
849
|
+
items: {
|
|
850
|
+
$ref: "#/definitions/PathGroup"
|
|
851
|
+
},
|
|
852
|
+
description: "Path expressions that are routed to this application."
|
|
853
|
+
}
|
|
854
|
+
},
|
|
855
|
+
required: ["matches"]
|
|
856
|
+
},
|
|
857
|
+
PathGroup: {
|
|
858
|
+
type: "object",
|
|
859
|
+
properties: {
|
|
860
|
+
group: {
|
|
861
|
+
type: "string",
|
|
862
|
+
description: "Optional group name for the paths"
|
|
863
|
+
},
|
|
864
|
+
options: {
|
|
865
|
+
type: "object",
|
|
866
|
+
properties: {
|
|
867
|
+
flag: {
|
|
868
|
+
type: "string",
|
|
869
|
+
description: "flag name that can be used to enable/disable all paths in the group"
|
|
870
|
+
},
|
|
871
|
+
routeToDefaultApplication: {
|
|
872
|
+
type: "boolean",
|
|
873
|
+
description: "True to route the request to the default application for this micro-frontends set-up. This must be `true` when using `flag` or when you want to use custom logic to make the routing decision for this group of paths."
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
paths: {
|
|
878
|
+
type: "array",
|
|
879
|
+
items: {
|
|
880
|
+
type: "string"
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
},
|
|
884
|
+
required: ["paths"]
|
|
885
|
+
},
|
|
886
|
+
HostConfig: {
|
|
887
|
+
type: "object",
|
|
888
|
+
properties: {
|
|
889
|
+
protocol: {
|
|
890
|
+
type: "string",
|
|
891
|
+
enum: ["http", "https"],
|
|
892
|
+
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"'
|
|
893
|
+
},
|
|
894
|
+
host: {
|
|
895
|
+
type: "string",
|
|
896
|
+
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`)."
|
|
897
|
+
},
|
|
898
|
+
port: {
|
|
899
|
+
type: "number",
|
|
900
|
+
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"
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
required: ["host"]
|
|
904
|
+
},
|
|
905
|
+
Vercel: {
|
|
906
|
+
type: "object",
|
|
907
|
+
properties: {
|
|
908
|
+
projectId: {
|
|
909
|
+
type: "string",
|
|
910
|
+
description: "Vercel project ID"
|
|
911
|
+
},
|
|
912
|
+
projectName: {
|
|
913
|
+
type: "string",
|
|
914
|
+
description: "Vercel project name (temporary until we can use project ID)"
|
|
915
|
+
},
|
|
916
|
+
defaultRoute: {
|
|
917
|
+
type: "string",
|
|
918
|
+
description: "The default route for the application. Used to render screenshots, favicons, and provide direct zone links"
|
|
919
|
+
},
|
|
920
|
+
routeSpeedInsightsToDefaultZone: {
|
|
921
|
+
type: "boolean",
|
|
922
|
+
description: "Whether to route Speed Insights to the default zone or each individual microfrontend."
|
|
923
|
+
}
|
|
924
|
+
},
|
|
925
|
+
required: ["projectId"]
|
|
926
|
+
},
|
|
927
|
+
CommonApplicationConfig: {
|
|
928
|
+
type: "object",
|
|
929
|
+
properties: {
|
|
930
|
+
default: {
|
|
931
|
+
type: "boolean",
|
|
932
|
+
const: false,
|
|
933
|
+
description: "The default application is used no other application is matched via the routing config"
|
|
934
|
+
},
|
|
935
|
+
routing: {
|
|
936
|
+
$ref: "#/definitions/Routing"
|
|
937
|
+
},
|
|
938
|
+
development: {
|
|
939
|
+
type: "object",
|
|
940
|
+
properties: {
|
|
941
|
+
local: {
|
|
942
|
+
$ref: "#/definitions/HostConfig"
|
|
943
|
+
},
|
|
944
|
+
fallback: {
|
|
945
|
+
$ref: "#/definitions/HostConfig",
|
|
946
|
+
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."
|
|
947
|
+
},
|
|
948
|
+
task: {
|
|
949
|
+
type: "string",
|
|
950
|
+
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
951
|
+
}
|
|
952
|
+
},
|
|
953
|
+
required: ["local"]
|
|
954
|
+
},
|
|
955
|
+
production: {
|
|
956
|
+
$ref: "#/definitions/HostConfig"
|
|
957
|
+
},
|
|
958
|
+
metadata: {
|
|
959
|
+
type: "object",
|
|
960
|
+
additionalProperties: {
|
|
961
|
+
type: "string"
|
|
962
|
+
}
|
|
963
|
+
},
|
|
964
|
+
federation: {
|
|
965
|
+
type: "object",
|
|
966
|
+
properties: {
|
|
967
|
+
exposes: {
|
|
968
|
+
type: "array",
|
|
969
|
+
items: {
|
|
970
|
+
type: "object",
|
|
971
|
+
properties: {
|
|
972
|
+
name: {
|
|
973
|
+
type: "string",
|
|
974
|
+
description: "The name of the module - should be used when importing the module from another application"
|
|
975
|
+
},
|
|
976
|
+
path: {
|
|
977
|
+
type: "string",
|
|
978
|
+
description: "Relative path to the module within its `application`"
|
|
979
|
+
}
|
|
980
|
+
},
|
|
981
|
+
required: ["name", "path"]
|
|
982
|
+
},
|
|
983
|
+
description: "Modules that are exposed by this application"
|
|
984
|
+
},
|
|
985
|
+
uses: {
|
|
986
|
+
type: "array",
|
|
987
|
+
items: {
|
|
988
|
+
type: "string"
|
|
989
|
+
},
|
|
990
|
+
description: "Modules that are used by this application. Only the name of the module is required."
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
vercel: {
|
|
995
|
+
$ref: "#/definitions/Vercel"
|
|
996
|
+
}
|
|
997
|
+
},
|
|
998
|
+
required: ["default", "development", "production", "routing"]
|
|
999
|
+
},
|
|
1000
|
+
Options: {
|
|
1001
|
+
type: "object",
|
|
1002
|
+
properties: {
|
|
1003
|
+
vercel: {
|
|
1004
|
+
$ref: "#/definitions/VercelOptions",
|
|
1005
|
+
description: "Micro-Frontends wide options for Vercel."
|
|
1006
|
+
},
|
|
1007
|
+
localProxy: {
|
|
1008
|
+
$ref: "#/definitions/LocalProxyOptions",
|
|
1009
|
+
description: "Options for local proxy."
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
},
|
|
1013
|
+
VercelOptions: {
|
|
1014
|
+
type: "object",
|
|
1015
|
+
properties: {
|
|
1016
|
+
previewDeploymentSuffix: {
|
|
1017
|
+
type: "string",
|
|
1018
|
+
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`."
|
|
1019
|
+
},
|
|
1020
|
+
teamSlug: {
|
|
1021
|
+
type: "string",
|
|
1022
|
+
description: "Team slug for the Vercel team"
|
|
1023
|
+
},
|
|
1024
|
+
disableOverrides: {
|
|
1025
|
+
type: "boolean",
|
|
1026
|
+
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."
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
},
|
|
1030
|
+
LocalProxyOptions: {
|
|
1031
|
+
type: "object",
|
|
1032
|
+
properties: {
|
|
1033
|
+
port: {
|
|
1034
|
+
type: "number",
|
|
1035
|
+
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
// src/config/utils/load-schema.ts
|
|
1043
|
+
var SCHEMA = schema_default;
|
|
1044
|
+
|
|
1045
|
+
// src/config/validation.ts
|
|
1046
|
+
var validateSchema = (configString) => {
|
|
1047
|
+
const parsedConfig = (0, import_jsonc_parser.parse)(configString);
|
|
1048
|
+
const ajv = new import_ajv.Ajv();
|
|
1049
|
+
const validate = ajv.compile(SCHEMA);
|
|
1050
|
+
const isValid = validate(parsedConfig);
|
|
1051
|
+
if (!isValid) {
|
|
1052
|
+
throw new MicroFrontendError(
|
|
1053
|
+
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
1054
|
+
{ type: "config", subtype: "does_not_match_schema" }
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
return parsedConfig;
|
|
1058
|
+
};
|
|
1059
|
+
var SUPPORTED_VERSIONS2 = ["1"];
|
|
1060
|
+
var validateVersion = (version) => {
|
|
1061
|
+
if (!SUPPORTED_VERSIONS2.includes(version)) {
|
|
1062
|
+
throw new MicroFrontendError(
|
|
1063
|
+
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
|
|
1064
|
+
", "
|
|
1065
|
+
)}`,
|
|
1066
|
+
{ type: "config", subtype: "unsupported_version" }
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
function validateMainPath(applicationConfigsById) {
|
|
1071
|
+
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
1072
|
+
const { defaultRoute } = app.vercel ?? {};
|
|
1073
|
+
if (!defaultRoute) {
|
|
1074
|
+
continue;
|
|
1075
|
+
}
|
|
1076
|
+
if (isDefaultApplicationConfig(app)) {
|
|
1077
|
+
const pathsWithApp = [];
|
|
1078
|
+
for (const [otherId, otherApp] of Object.entries(
|
|
1079
|
+
applicationConfigsById
|
|
1080
|
+
)) {
|
|
1081
|
+
if (isDefaultApplicationConfig(otherApp)) {
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
pathsWithApp.push({
|
|
1085
|
+
id: otherId,
|
|
1086
|
+
paths: otherApp.routing.matches.flatMap((match) => match.paths)
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
for (const { id: otherId, paths } of pathsWithApp) {
|
|
1090
|
+
const isValid = paths.every((path3) => {
|
|
1091
|
+
const matcher = (0, import_path_to_regexp.pathToRegexp)(path3);
|
|
1092
|
+
return !matcher.test(defaultRoute);
|
|
1093
|
+
});
|
|
1094
|
+
if (!isValid) {
|
|
1095
|
+
throw new MicroFrontendError(
|
|
1096
|
+
`default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
|
|
1097
|
+
{ type: "config", subtype: "invalid_main_path" }
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
} else {
|
|
1102
|
+
const allPaths = app.routing.matches.flatMap((match) => match.paths);
|
|
1103
|
+
const isValid = allPaths.some((path3) => {
|
|
1104
|
+
const matcher = (0, import_path_to_regexp.pathToRegexp)(path3);
|
|
1105
|
+
return matcher.test(defaultRoute);
|
|
1106
|
+
});
|
|
1107
|
+
if (!isValid) {
|
|
1108
|
+
throw new MicroFrontendError(
|
|
1109
|
+
`default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
|
|
1110
|
+
{ type: "config", subtype: "invalid_main_path" }
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
var validatePaths = (applicationConfigsById) => {
|
|
1117
|
+
const pathsByApplicationId = /* @__PURE__ */ new Map();
|
|
1118
|
+
const errors = [];
|
|
1119
|
+
for (const [id, app] of Object.entries(applicationConfigsById)) {
|
|
1120
|
+
if (isDefaultApplicationConfig(app)) {
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
for (const pathMatch of app.routing.matches) {
|
|
1124
|
+
for (const path3 of pathMatch.paths) {
|
|
1125
|
+
const maybeError = validatePathExpression(path3);
|
|
1126
|
+
if (maybeError) {
|
|
1127
|
+
errors.push(maybeError);
|
|
1128
|
+
}
|
|
1129
|
+
const existing = pathsByApplicationId.get(path3);
|
|
1130
|
+
if (existing) {
|
|
1131
|
+
existing.applications.push(id);
|
|
1132
|
+
} else {
|
|
1133
|
+
pathsByApplicationId.set(path3, {
|
|
1134
|
+
applications: [id],
|
|
1135
|
+
matcher: (0, import_path_to_regexp.pathToRegexp)(path3),
|
|
1136
|
+
applicationId: id
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
const entries = Array.from(pathsByApplicationId.entries());
|
|
1143
|
+
entries.forEach(([path3, { applications: ids, matcher, applicationId }]) => {
|
|
1144
|
+
if (ids.length > 1) {
|
|
1145
|
+
errors.push(
|
|
1146
|
+
`Duplicate path "${path3}" for applications "${ids.join(", ")}"`
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
entries.forEach(
|
|
1150
|
+
([
|
|
1151
|
+
matchPath,
|
|
1152
|
+
{ applications: matchIds, applicationId: matchApplicationId }
|
|
1153
|
+
]) => {
|
|
1154
|
+
if (path3 === matchPath) {
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
if (applicationId === matchApplicationId) {
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
if (matcher.test(matchPath)) {
|
|
1161
|
+
const source = `"${path3}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
1162
|
+
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
1163
|
+
errors.push(
|
|
1164
|
+
`Overlapping path detected between ${source} and ${destination}`
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
);
|
|
1169
|
+
});
|
|
1170
|
+
if (errors.length) {
|
|
1171
|
+
throw new MicroFrontendError(`Invalid paths: ${errors.join(", ")}`, {
|
|
1172
|
+
type: "config",
|
|
1173
|
+
subtype: "conflicting_paths"
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
1178
|
+
function validatePathExpression(path3) {
|
|
1179
|
+
const tokens = (0, import_path_to_regexp.parse)(path3);
|
|
1180
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
1181
|
+
const token = tokens[i];
|
|
1182
|
+
if (token === void 0) {
|
|
1183
|
+
return `token ${i} in ${path3} is undefined, this shouldn't happen`;
|
|
1184
|
+
}
|
|
1185
|
+
if (typeof token !== "string") {
|
|
1186
|
+
if (token.pattern !== PATH_DEFAULT_PATTERN) {
|
|
1187
|
+
return `Path ${path3} cannot use a regular expression wildcard`;
|
|
1188
|
+
}
|
|
1189
|
+
if (token.prefix !== "/") {
|
|
1190
|
+
return `Wildcard :${token.name} must be immediately after a / in ${path3}`;
|
|
1191
|
+
}
|
|
1192
|
+
if (token.suffix) {
|
|
1193
|
+
return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
|
|
1194
|
+
}
|
|
1195
|
+
if (token.modifier && i !== tokens.length - 1) {
|
|
1196
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path3}. Modifiers are only allowed in the last path component`;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return void 0;
|
|
1201
|
+
}
|
|
1202
|
+
var validateDefaults = (applicationConfigsById) => {
|
|
1203
|
+
const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
|
|
1204
|
+
if (defaultApplicationIds.length === 0) {
|
|
1205
|
+
throw new MicroFrontendError(
|
|
1206
|
+
`No default application found. At least one application must be marked as default.`,
|
|
1207
|
+
{ type: "config", subtype: "no_default_application" }
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
if (defaultApplicationIds.length > 1) {
|
|
1211
|
+
throw new MicroFrontendError(
|
|
1212
|
+
`Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
|
|
1213
|
+
{ type: "config", subtype: "multiple_default_applications" }
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
var validateOptions = (options) => {
|
|
1218
|
+
var _a;
|
|
1219
|
+
if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
|
|
1220
|
+
if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
|
|
1221
|
+
options.vercel.previewDeploymentSuffix
|
|
1222
|
+
)) {
|
|
1223
|
+
throw new MicroFrontendError(
|
|
1224
|
+
`Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
|
|
1225
|
+
{ type: "config", subtype: "invalid_preview_deployment_suffix" }
|
|
1226
|
+
);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
|
|
1231
|
+
// src/config/utils/convert.ts
|
|
1232
|
+
function convertV1RoutingToV2Routing(routing) {
|
|
1233
|
+
return routing.matches.map((group) => {
|
|
1234
|
+
var _a, _b;
|
|
1235
|
+
return {
|
|
1236
|
+
group: group.group,
|
|
1237
|
+
flag: (_a = group.options) == null ? void 0 : _a.flag,
|
|
1238
|
+
routeToDefaultApplication: (_b = group.options) == null ? void 0 : _b.routeToDefaultApplication,
|
|
1239
|
+
paths: group.paths
|
|
1240
|
+
};
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
function convertV1ApplicationToV2Application(application) {
|
|
1244
|
+
const common = {
|
|
1245
|
+
production: application.production,
|
|
1246
|
+
development: application.development,
|
|
1247
|
+
vercel: application.vercel
|
|
1248
|
+
};
|
|
1249
|
+
if (application.default) {
|
|
1250
|
+
return common;
|
|
1251
|
+
}
|
|
1252
|
+
return {
|
|
1253
|
+
...common,
|
|
1254
|
+
routing: convertV1RoutingToV2Routing(application.routing)
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
function convertV1ConfigToV2Config(config, fromApp) {
|
|
1258
|
+
if (!config.applications[fromApp]) {
|
|
1259
|
+
throw new Error(`Application "${fromApp}" not found in the config`);
|
|
1260
|
+
}
|
|
1261
|
+
const common = {
|
|
1262
|
+
version: "2",
|
|
1263
|
+
options: config.options
|
|
1264
|
+
};
|
|
1265
|
+
if (config.applications[fromApp].default) {
|
|
1266
|
+
return {
|
|
1267
|
+
...common,
|
|
1268
|
+
// this is assumed for now, and by the time this is released we won't need this conversion
|
|
1269
|
+
provider: "vercel",
|
|
1270
|
+
applications: Object.fromEntries(
|
|
1271
|
+
Object.entries(config.applications).map(([id, application]) => [
|
|
1272
|
+
id,
|
|
1273
|
+
convertV1ApplicationToV2Application(application)
|
|
1274
|
+
])
|
|
1275
|
+
)
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
return {
|
|
1279
|
+
...common,
|
|
1280
|
+
partOf: fromApp
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// src/config/utils/write-file.ts
|
|
1285
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
1286
|
+
var import_node_path3 = require("path");
|
|
1287
|
+
function writeFile(outputPath, config, prettify) {
|
|
1288
|
+
import_node_fs.default.mkdirSync((0, import_node_path3.dirname)(outputPath), { recursive: true });
|
|
1289
|
+
import_node_fs.default.writeFileSync(
|
|
1290
|
+
outputPath,
|
|
1291
|
+
JSON.stringify(config, null, prettify ? 2 : void 0)
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// src/config/micro-frontend-config.ts
|
|
1296
|
+
var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
|
|
1297
|
+
static validate(configString) {
|
|
1298
|
+
const config = validateSchema(configString);
|
|
1299
|
+
validateVersion(config.version);
|
|
1300
|
+
validatePaths(config.applications);
|
|
1301
|
+
validateMainPath(config.applications);
|
|
1302
|
+
validateDefaults(config.applications);
|
|
1303
|
+
validateOptions(config.options);
|
|
1304
|
+
return config;
|
|
1305
|
+
}
|
|
1306
|
+
static fromEnv({
|
|
1307
|
+
cookies
|
|
1308
|
+
}) {
|
|
1309
|
+
return new MicroFrontendConfigCommon({
|
|
1310
|
+
config: MicroFrontendConfig.validate(
|
|
1311
|
+
MicroFrontendConfigCommon.getConfigFromEnv()
|
|
1312
|
+
),
|
|
1313
|
+
overrides: Overrides.parseOverrides(cookies)
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
static fromFile({
|
|
1317
|
+
filePath
|
|
1318
|
+
}) {
|
|
1319
|
+
try {
|
|
1320
|
+
const config = import_node_fs2.default.readFileSync(filePath, "utf-8");
|
|
1321
|
+
return new MicroFrontendConfig({
|
|
1322
|
+
config: MicroFrontendConfig.validate(config)
|
|
1323
|
+
});
|
|
1324
|
+
} catch (e) {
|
|
1325
|
+
throw MicroFrontendError.handle(e, {
|
|
1326
|
+
fileName: filePath
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Writes the configuration to a file.
|
|
1332
|
+
*/
|
|
1333
|
+
write(fromApp, opts = {}) {
|
|
1334
|
+
const { pretty = true, versions = ["v1", "v2"] } = opts;
|
|
1335
|
+
const config = this.toSchemaJson();
|
|
1336
|
+
if (versions.includes("v1")) {
|
|
1337
|
+
const outputPath = getOutputFilePath2();
|
|
1338
|
+
writeFile(outputPath, config, pretty);
|
|
1339
|
+
}
|
|
1340
|
+
if (versions.includes("v2")) {
|
|
1341
|
+
const outputPath = getOutputFilePath();
|
|
1342
|
+
const v2Config = convertV1ConfigToV2Config(config, fromApp);
|
|
1343
|
+
writeFile(outputPath, v2Config, pretty);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
};
|
|
1347
|
+
|
|
1348
|
+
// src/bin/local-proxy.ts
|
|
1349
|
+
var MFE_DEBUG = process.env.MFE_DEBUG;
|
|
1350
|
+
var mfeDebug = (message) => {
|
|
1351
|
+
if (MFE_DEBUG === "true" || MFE_DEBUG === "1") {
|
|
1352
|
+
console.log(message);
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
var LocalProxy = class {
|
|
1356
|
+
constructor(config, {
|
|
1357
|
+
localApps,
|
|
1358
|
+
proxyPort
|
|
1359
|
+
}) {
|
|
1360
|
+
this.config = config;
|
|
1361
|
+
this.localApps = localApps;
|
|
1362
|
+
this.proxyPort = proxyPort ?? this.config.getLocalProxyPort();
|
|
1363
|
+
this.proxy = import_http_proxy.default.createProxyServer({ secure: true });
|
|
1364
|
+
this.proxy.on("error", (err, req, res) => {
|
|
1365
|
+
if (res instanceof http.ServerResponse) {
|
|
1366
|
+
res.writeHead(500, {
|
|
1367
|
+
"Content-Type": "text/plain"
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
const target = this.getTarget(req);
|
|
1371
|
+
res.end(
|
|
1372
|
+
`Error proxying request to ${target.application}. Is the server running locally on port ${target.port}?`
|
|
1373
|
+
);
|
|
1374
|
+
console.error(`Error proxying request for ${target.application}: `, err);
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1377
|
+
static fromFile(filePath, {
|
|
1378
|
+
localApps,
|
|
1379
|
+
proxyPort
|
|
1380
|
+
}) {
|
|
1381
|
+
const config = MicroFrontendConfig.fromFile({ filePath });
|
|
1382
|
+
return new LocalProxy(config, { localApps, proxyPort });
|
|
1383
|
+
}
|
|
1384
|
+
getDefaultHost(config) {
|
|
1385
|
+
const defaultApp = config.getDefaultZone();
|
|
1386
|
+
return this.getApplicationTarget(defaultApp);
|
|
1387
|
+
}
|
|
1388
|
+
getApplicationTarget(application) {
|
|
1389
|
+
var _a, _b;
|
|
1390
|
+
const useDev = this.localApps.includes(application.name);
|
|
1391
|
+
let host = useDev ? application.development.local : application.production;
|
|
1392
|
+
if ((_b = (_a = application.overrides) == null ? void 0 : _a.environment) == null ? void 0 : _b.host) {
|
|
1393
|
+
host = application.overrides.environment;
|
|
1394
|
+
}
|
|
1395
|
+
const protocol = host.protocol;
|
|
1396
|
+
const hostname = host.host;
|
|
1397
|
+
const port = host.port;
|
|
1398
|
+
return {
|
|
1399
|
+
url: host.toUrl(),
|
|
1400
|
+
protocol,
|
|
1401
|
+
hostname,
|
|
1402
|
+
port,
|
|
1403
|
+
application: application.name
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* To enable preview deployments in localhost, we need to intercept some auth requests
|
|
1408
|
+
* and make sure they proxy to the correct domain. The toolbar will initiate the `vercel-auth-redirect`
|
|
1409
|
+
* with a `_host_override` param so that we can properly trigger the redirect flow for the
|
|
1410
|
+
* protected host.
|
|
1411
|
+
*/
|
|
1412
|
+
getAuthTarget(request2, config) {
|
|
1413
|
+
var _a, _b;
|
|
1414
|
+
const url = new URL(request2.url ?? "", `http://${request2.headers.host}`);
|
|
1415
|
+
const isAuthRedirect = (_a = request2.url) == null ? void 0 : _a.startsWith(
|
|
1416
|
+
"/.well-known/vercel-auth-redirect"
|
|
1417
|
+
);
|
|
1418
|
+
const isSsoRedirect = (_b = request2.url) == null ? void 0 : _b.startsWith("/sso-api");
|
|
1419
|
+
const isJWTRedirect = url.searchParams.has("_vercel_jwt");
|
|
1420
|
+
const defaultHost = this.getDefaultHost(config);
|
|
1421
|
+
let hostname = null;
|
|
1422
|
+
let path3 = request2.url;
|
|
1423
|
+
if (isAuthRedirect) {
|
|
1424
|
+
hostname = url.searchParams.get("_host_override");
|
|
1425
|
+
}
|
|
1426
|
+
if (isSsoRedirect) {
|
|
1427
|
+
hostname = "vercel.com";
|
|
1428
|
+
}
|
|
1429
|
+
if (isJWTRedirect) {
|
|
1430
|
+
hostname = url.searchParams.get("_host_override");
|
|
1431
|
+
url.searchParams.delete("_host_override");
|
|
1432
|
+
path3 = `${url.pathname}${url.search}`;
|
|
1433
|
+
}
|
|
1434
|
+
if (!hostname) {
|
|
1435
|
+
return void 0;
|
|
1436
|
+
}
|
|
1437
|
+
return { ...defaultHost, path: path3, hostname, protocol: "https", port: 443 };
|
|
1438
|
+
}
|
|
1439
|
+
getTarget(request2) {
|
|
1440
|
+
const cookies = (0, import_cookie.parse)(request2.headers.cookie || "");
|
|
1441
|
+
const cookieOverrides = Overrides.parseOverrides(
|
|
1442
|
+
Object.entries(cookies).map(([name, value]) => ({ name, value }))
|
|
1443
|
+
);
|
|
1444
|
+
const hasOverrides = Object.keys(cookieOverrides.applications).length > 0;
|
|
1445
|
+
const config = hasOverrides ? new MicroFrontendConfig({
|
|
1446
|
+
config: this.config.serialize().config,
|
|
1447
|
+
overrides: cookieOverrides
|
|
1448
|
+
}) : this.config;
|
|
1449
|
+
const path3 = request2.url;
|
|
1450
|
+
if (!path3) {
|
|
1451
|
+
return this.getDefaultHost(config);
|
|
1452
|
+
}
|
|
1453
|
+
const authTarget = this.getAuthTarget(request2, config);
|
|
1454
|
+
if (authTarget) {
|
|
1455
|
+
return authTarget;
|
|
1456
|
+
}
|
|
1457
|
+
const url = new URL(`http://example.com${path3}`);
|
|
1458
|
+
const pathname = url.pathname;
|
|
1459
|
+
for (const application of Object.values(config.getAllApplications())) {
|
|
1460
|
+
if (application.routing) {
|
|
1461
|
+
for (const group of application.routing.matches) {
|
|
1462
|
+
for (const childPath of group.paths) {
|
|
1463
|
+
const regexp = (0, import_path_to_regexp2.pathToRegexp)(childPath);
|
|
1464
|
+
if (regexp.test(pathname)) {
|
|
1465
|
+
const target = this.getApplicationTarget(application);
|
|
1466
|
+
mfeDebug(
|
|
1467
|
+
`routing ${path3} to '${target.application}' at ${target.hostname}`
|
|
1468
|
+
);
|
|
1469
|
+
return { path: path3, ...target };
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
if (application.routing.assetPrefix) {
|
|
1473
|
+
const pattern = (0, import_path_to_regexp2.pathToRegexp)(
|
|
1474
|
+
`/${application.routing.assetPrefix}/:path+`
|
|
1475
|
+
);
|
|
1476
|
+
if (pattern.test(pathname)) {
|
|
1477
|
+
const target = this.getApplicationTarget(application);
|
|
1478
|
+
mfeDebug(
|
|
1479
|
+
`routing ${path3} to '${target.application}' at ${target.hostname}`
|
|
1480
|
+
);
|
|
1481
|
+
return { path: path3, ...target };
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
const defaultHost = this.getDefaultHost(config);
|
|
1488
|
+
mfeDebug(
|
|
1489
|
+
`no matching routes, routing ${path3} to default application: ${JSON.stringify(defaultHost)}`
|
|
1490
|
+
);
|
|
1491
|
+
return { path: path3, ...defaultHost };
|
|
1492
|
+
}
|
|
1493
|
+
// Handles requests that return data from the local proxy itself.
|
|
1494
|
+
// Returns true if the request was handled, false otherwise.
|
|
1495
|
+
handleProxyInfoRequest(path3, res) {
|
|
1496
|
+
if (!path3) {
|
|
1497
|
+
return false;
|
|
1498
|
+
}
|
|
1499
|
+
const url = new URL(`http://example.comf${path3}`);
|
|
1500
|
+
const pathname = url.pathname;
|
|
1501
|
+
switch (pathname) {
|
|
1502
|
+
case "/.well-known/vercel/microfrontend-routing": {
|
|
1503
|
+
res.writeHead(200, {
|
|
1504
|
+
"Content-Type": "application/json"
|
|
1505
|
+
});
|
|
1506
|
+
const payload = Object.fromEntries(
|
|
1507
|
+
this.config.getAllApplications().map((app) => {
|
|
1508
|
+
const { hostname, port, protocol } = this.getApplicationTarget(app);
|
|
1509
|
+
return [
|
|
1510
|
+
app.name,
|
|
1511
|
+
{ routing: { host: hostname, port, protocol } }
|
|
1512
|
+
];
|
|
1513
|
+
})
|
|
1514
|
+
);
|
|
1515
|
+
res.end(JSON.stringify(payload));
|
|
1516
|
+
return true;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return false;
|
|
1520
|
+
}
|
|
1521
|
+
handleRequest(req, res) {
|
|
1522
|
+
if (this.handleProxyInfoRequest(req.url, res)) {
|
|
1523
|
+
return;
|
|
1524
|
+
}
|
|
1525
|
+
const target = this.getTarget(req);
|
|
1526
|
+
if (target.protocol === "https") {
|
|
1527
|
+
const { hostname, port, path: path3 } = target;
|
|
1528
|
+
const requestOptions = {
|
|
1529
|
+
hostname,
|
|
1530
|
+
path: path3,
|
|
1531
|
+
method: req.method,
|
|
1532
|
+
headers: {
|
|
1533
|
+
...req.headers,
|
|
1534
|
+
host: hostname
|
|
1535
|
+
},
|
|
1536
|
+
port
|
|
1537
|
+
};
|
|
1538
|
+
const localhost = `http://localhost:${this.proxyPort}`;
|
|
1539
|
+
const proxyReq = https.request(requestOptions, (realRes) => {
|
|
1540
|
+
if (realRes.statusCode === 307) {
|
|
1541
|
+
const locationHeader = realRes.headers.location;
|
|
1542
|
+
if (locationHeader) {
|
|
1543
|
+
const redirectUrl = new URL(
|
|
1544
|
+
locationHeader.replace(/https:\/\/[^/]+\//, "/"),
|
|
1545
|
+
localhost
|
|
1546
|
+
);
|
|
1547
|
+
realRes.headers.location = redirectUrl.toString();
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
res.writeHead(realRes.statusCode || 200, realRes.headers);
|
|
1551
|
+
realRes.pipe(res, { end: true });
|
|
1552
|
+
});
|
|
1553
|
+
req.pipe(proxyReq);
|
|
1554
|
+
proxyReq.on("error", (err) => {
|
|
1555
|
+
console.error("Proxy request error: ", err);
|
|
1556
|
+
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
1557
|
+
res.end(
|
|
1558
|
+
`Error proxying request for ${target.application} to ${hostname}:${port}${path3}`
|
|
1559
|
+
);
|
|
1560
|
+
});
|
|
1561
|
+
} else {
|
|
1562
|
+
this.proxy.web(req, res, {
|
|
1563
|
+
target: target.url
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
startServer() {
|
|
1568
|
+
const httpServer = http.createServer(
|
|
1569
|
+
(req, res) => this.handleRequest(req, res)
|
|
1570
|
+
);
|
|
1571
|
+
httpServer.on("upgrade", (req, socket, head) => {
|
|
1572
|
+
const target = this.getTarget(req);
|
|
1573
|
+
try {
|
|
1574
|
+
this.proxy.ws(req, socket, head, { target: target.url });
|
|
1575
|
+
} catch (err) {
|
|
1576
|
+
console.error("Error proxying ws: ", err);
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1579
|
+
httpServer.listen(this.proxyPort, () => {
|
|
1580
|
+
console.log(`Microfrontends Proxy: http://localhost:${this.proxyPort}`);
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1584
|
+
|
|
1585
|
+
// src/bin/index.ts
|
|
1586
|
+
function main() {
|
|
1587
|
+
const program = new import_commander.Command();
|
|
1588
|
+
program.name(package_default.name).description("Tools for working with micro-frontend applications").version(package_default.version, "-v, --version", "output the current version");
|
|
1589
|
+
program.command("proxy").argument("<filePath>", "Path to the micro-frontend configuration file").option("--names <names...>", "List of locally running applications", []).option("--port <port>", "Port proxy will use", (value) => {
|
|
1590
|
+
const parsedValue = Number.parseInt(value, 10);
|
|
1591
|
+
if (isNaN(parsedValue) || parsedValue <= 0) {
|
|
1592
|
+
throw new Error("Port must be a positive number");
|
|
1593
|
+
}
|
|
1594
|
+
return parsedValue;
|
|
1595
|
+
}).action((filePath, options) => {
|
|
1596
|
+
const localProxy = LocalProxy.fromFile(filePath, {
|
|
1597
|
+
localApps: options.names,
|
|
1598
|
+
proxyPort: options.port
|
|
1599
|
+
});
|
|
1600
|
+
localProxy.startServer();
|
|
1601
|
+
});
|
|
1602
|
+
program.parse(process.argv);
|
|
1603
|
+
}
|
|
1604
|
+
main();
|