@vercel/microfrontends 1.0.1-canary.2 → 1.0.1-canary.4
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 +115 -85
- package/dist/config.cjs +5 -6
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +5 -6
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +81 -78
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +81 -78
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +124 -88
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.d.ts +1 -1
- package/dist/experimental/vite.js +124 -90
- package/dist/experimental/vite.js.map +1 -1
- package/dist/{index-d5994ac5.d.ts → index-2b59c627.d.ts} +1 -1
- package/dist/microfrontends/server.cjs +81 -51
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +1 -1
- package/dist/microfrontends/server.js +81 -51
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends.cjs +5 -6
- package/dist/microfrontends.cjs.map +1 -1
- package/dist/microfrontends.d.ts +1 -1
- package/dist/microfrontends.js +5 -6
- package/dist/microfrontends.js.map +1 -1
- package/dist/next/config.cjs +81 -78
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +81 -78
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +5 -6
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +5 -6
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +5 -6
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +1 -1
- package/dist/next/testing.js +5 -6
- package/dist/next/testing.js.map +1 -1
- package/dist/utils/mfe-port.cjs +85 -55
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +85 -55
- package/dist/utils/mfe-port.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/config/microfrontends/server/index.ts
|
|
2
|
-
import
|
|
3
|
-
import { dirname as dirname3
|
|
2
|
+
import fs6 from "node:fs";
|
|
3
|
+
import { dirname as dirname3 } from "node:path";
|
|
4
4
|
|
|
5
5
|
// src/config/overrides/constants.ts
|
|
6
6
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -183,21 +183,21 @@ var MicrofrontendConfigClient = class {
|
|
|
183
183
|
isEqual(other) {
|
|
184
184
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
185
185
|
}
|
|
186
|
-
getApplicationNameForPath(
|
|
187
|
-
if (!
|
|
186
|
+
getApplicationNameForPath(path6) {
|
|
187
|
+
if (!path6.startsWith("/")) {
|
|
188
188
|
throw new Error(`Path must start with a /`);
|
|
189
189
|
}
|
|
190
|
-
if (this.pathCache[
|
|
191
|
-
return this.pathCache[
|
|
190
|
+
if (this.pathCache[path6]) {
|
|
191
|
+
return this.pathCache[path6];
|
|
192
192
|
}
|
|
193
|
-
const pathname = new URL(
|
|
193
|
+
const pathname = new URL(path6, "https://example.com").pathname;
|
|
194
194
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
195
195
|
if (application.routing) {
|
|
196
196
|
for (const group of application.routing) {
|
|
197
197
|
for (const childPath of group.paths) {
|
|
198
198
|
const regexp = pathToRegexp(childPath);
|
|
199
199
|
if (regexp.test(pathname)) {
|
|
200
|
-
this.pathCache[
|
|
200
|
+
this.pathCache[path6] = name;
|
|
201
201
|
return name;
|
|
202
202
|
}
|
|
203
203
|
}
|
|
@@ -210,7 +210,7 @@ var MicrofrontendConfigClient = class {
|
|
|
210
210
|
if (!defaultApplication) {
|
|
211
211
|
return null;
|
|
212
212
|
}
|
|
213
|
-
this.pathCache[
|
|
213
|
+
this.pathCache[path6] = defaultApplication[0];
|
|
214
214
|
return defaultApplication[0];
|
|
215
215
|
}
|
|
216
216
|
serialize() {
|
|
@@ -232,18 +232,18 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
232
232
|
}
|
|
233
233
|
const childApp = app;
|
|
234
234
|
for (const pathMatch of childApp.routing) {
|
|
235
|
-
for (const
|
|
236
|
-
const maybeError = validatePathExpression(
|
|
235
|
+
for (const path6 of pathMatch.paths) {
|
|
236
|
+
const maybeError = validatePathExpression(path6);
|
|
237
237
|
if (maybeError) {
|
|
238
238
|
errors.push(maybeError);
|
|
239
239
|
} else {
|
|
240
|
-
const existing = pathsByApplicationId.get(
|
|
240
|
+
const existing = pathsByApplicationId.get(path6);
|
|
241
241
|
if (existing) {
|
|
242
242
|
existing.applications.push(id);
|
|
243
243
|
} else {
|
|
244
|
-
pathsByApplicationId.set(
|
|
244
|
+
pathsByApplicationId.set(path6, {
|
|
245
245
|
applications: [id],
|
|
246
|
-
matcher: pathToRegexp2(
|
|
246
|
+
matcher: pathToRegexp2(path6),
|
|
247
247
|
applicationId: id
|
|
248
248
|
});
|
|
249
249
|
}
|
|
@@ -252,24 +252,24 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
255
|
-
for (const [
|
|
255
|
+
for (const [path6, { applications: ids, matcher, applicationId }] of entries) {
|
|
256
256
|
if (ids.length > 1) {
|
|
257
257
|
errors.push(
|
|
258
|
-
`Duplicate path "${
|
|
258
|
+
`Duplicate path "${path6}" for applications "${ids.join(", ")}"`
|
|
259
259
|
);
|
|
260
260
|
}
|
|
261
261
|
for (const [
|
|
262
262
|
matchPath,
|
|
263
263
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
264
264
|
] of entries) {
|
|
265
|
-
if (
|
|
265
|
+
if (path6 === matchPath) {
|
|
266
266
|
continue;
|
|
267
267
|
}
|
|
268
268
|
if (applicationId === matchApplicationId) {
|
|
269
269
|
continue;
|
|
270
270
|
}
|
|
271
271
|
if (matcher.test(matchPath)) {
|
|
272
|
-
const source = `"${
|
|
272
|
+
const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
273
273
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
274
274
|
errors.push(
|
|
275
275
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -285,39 +285,42 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
285
285
|
}
|
|
286
286
|
};
|
|
287
287
|
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
288
|
-
function validatePathExpression(
|
|
288
|
+
function validatePathExpression(path6) {
|
|
289
289
|
try {
|
|
290
|
-
const tokens = parsePathRegexp(
|
|
291
|
-
if (/(?<!\\)\{/.test(
|
|
292
|
-
return `Optional paths are not supported: ${
|
|
290
|
+
const tokens = parsePathRegexp(path6);
|
|
291
|
+
if (/(?<!\\)\{/.test(path6)) {
|
|
292
|
+
return `Optional paths are not supported: ${path6}`;
|
|
293
293
|
}
|
|
294
|
-
if (/(?<!\\|\()\?/.test(
|
|
295
|
-
return `Optional paths are not supported: ${
|
|
294
|
+
if (/(?<!\\|\()\?/.test(path6)) {
|
|
295
|
+
return `Optional paths are not supported: ${path6}`;
|
|
296
296
|
}
|
|
297
|
-
if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(
|
|
298
|
-
return `Only one wildcard is allowed per path segment: ${
|
|
297
|
+
if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path6)) {
|
|
298
|
+
return `Only one wildcard is allowed per path segment: ${path6}`;
|
|
299
299
|
}
|
|
300
300
|
for (let i = 0; i < tokens.length; i++) {
|
|
301
301
|
const token = tokens[i];
|
|
302
302
|
if (token === void 0) {
|
|
303
|
-
return `token ${i} in ${
|
|
303
|
+
return `token ${i} in ${path6} is undefined, this shouldn't happen`;
|
|
304
304
|
}
|
|
305
305
|
if (typeof token !== "string") {
|
|
306
|
+
if (!token.name) {
|
|
307
|
+
return `Only named wildcards are allowed: ${path6} (hint: add ":path" to the wildcard)`;
|
|
308
|
+
}
|
|
306
309
|
if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
307
310
|
// Only limited regex is supported for now, due to performance considerations
|
|
308
311
|
!/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
|
|
309
312
|
token.pattern
|
|
310
313
|
)) {
|
|
311
|
-
return `Path ${
|
|
314
|
+
return `Path ${path6} cannot use unsupported regular expression wildcard`;
|
|
312
315
|
}
|
|
313
316
|
if (token.modifier && i !== tokens.length - 1) {
|
|
314
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${
|
|
317
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
|
|
315
318
|
}
|
|
316
319
|
}
|
|
317
320
|
}
|
|
318
321
|
} catch (e) {
|
|
319
322
|
const message = e instanceof Error ? e.message : String(e);
|
|
320
|
-
return `Path ${
|
|
323
|
+
return `Path ${path6} could not be parsed into regexp: ${message}`;
|
|
321
324
|
}
|
|
322
325
|
return void 0;
|
|
323
326
|
}
|
|
@@ -671,12 +674,8 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
671
674
|
const skipValidation = opts?.skipValidation ?? [];
|
|
672
675
|
const c = typeof config === "string" ? parse(config) : config;
|
|
673
676
|
if (isMainConfig(c)) {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
if (!skipValidation.includes("defaultApplication")) {
|
|
678
|
-
validateConfigDefaultApplication(c.applications);
|
|
679
|
-
}
|
|
677
|
+
validateConfigPaths(c.applications);
|
|
678
|
+
validateConfigDefaultApplication(c.applications);
|
|
680
679
|
if (!skipValidation.includes("deprecatedFields")) {
|
|
681
680
|
validateDeprecatedFields(c);
|
|
682
681
|
}
|
|
@@ -1033,6 +1032,9 @@ function isMonorepo({
|
|
|
1033
1032
|
if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1034
1033
|
return true;
|
|
1035
1034
|
}
|
|
1035
|
+
if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
|
|
1036
|
+
return true;
|
|
1037
|
+
}
|
|
1036
1038
|
const packageJsonPath = path2.join(repositoryRoot, "package.json");
|
|
1037
1039
|
if (!fs2.existsSync(packageJsonPath)) {
|
|
1038
1040
|
return false;
|
|
@@ -1078,8 +1080,42 @@ function findConfig({ dir }) {
|
|
|
1078
1080
|
return null;
|
|
1079
1081
|
}
|
|
1080
1082
|
|
|
1081
|
-
// src/config/microfrontends/
|
|
1083
|
+
// src/config/microfrontends/utils/get-application-context.ts
|
|
1084
|
+
import fs5 from "node:fs";
|
|
1082
1085
|
import path4 from "node:path";
|
|
1086
|
+
function getApplicationContext(opts) {
|
|
1087
|
+
if (opts?.appName) {
|
|
1088
|
+
return { name: opts.appName };
|
|
1089
|
+
}
|
|
1090
|
+
if (process.env.NX_TASK_TARGET_PROJECT) {
|
|
1091
|
+
return { name: process.env.NX_TASK_TARGET_PROJECT };
|
|
1092
|
+
}
|
|
1093
|
+
try {
|
|
1094
|
+
const packageJsonString = fs5.readFileSync(
|
|
1095
|
+
path4.join(opts?.packageRoot || ".", "package.json"),
|
|
1096
|
+
"utf-8"
|
|
1097
|
+
);
|
|
1098
|
+
const packageJson = JSON.parse(packageJsonString);
|
|
1099
|
+
if (!packageJson.name) {
|
|
1100
|
+
throw new MicrofrontendError(
|
|
1101
|
+
`package.json file missing required field "name"`,
|
|
1102
|
+
{
|
|
1103
|
+
type: "packageJson",
|
|
1104
|
+
subtype: "missing_field_name",
|
|
1105
|
+
source: "@vercel/microfrontends/next"
|
|
1106
|
+
}
|
|
1107
|
+
);
|
|
1108
|
+
}
|
|
1109
|
+
return { name: packageJson.name };
|
|
1110
|
+
} catch (err) {
|
|
1111
|
+
throw MicrofrontendError.handle(err, {
|
|
1112
|
+
fileName: "package.json"
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1118
|
+
import path5 from "node:path";
|
|
1083
1119
|
|
|
1084
1120
|
// src/config/microfrontends/server/constants.ts
|
|
1085
1121
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1087,7 +1123,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1087
1123
|
|
|
1088
1124
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1089
1125
|
function getOutputFilePath() {
|
|
1090
|
-
return
|
|
1126
|
+
return path5.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1091
1127
|
}
|
|
1092
1128
|
|
|
1093
1129
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1426,8 +1462,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1426
1462
|
pretty: true
|
|
1427
1463
|
}) {
|
|
1428
1464
|
const outputPath = getOutputFilePath();
|
|
1429
|
-
|
|
1430
|
-
|
|
1465
|
+
fs6.mkdirSync(dirname3(outputPath), { recursive: true });
|
|
1466
|
+
fs6.writeFileSync(
|
|
1431
1467
|
outputPath,
|
|
1432
1468
|
JSON.stringify(
|
|
1433
1469
|
this.config.toSchemaJson(),
|
|
@@ -1513,14 +1549,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1513
1549
|
}
|
|
1514
1550
|
try {
|
|
1515
1551
|
const packageRoot = findPackageRoot(directory);
|
|
1516
|
-
const
|
|
1517
|
-
const
|
|
1518
|
-
fs5.readFileSync(packageJsonPath, "utf-8")
|
|
1519
|
-
);
|
|
1520
|
-
if (!packageJson.name) {
|
|
1521
|
-
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1522
|
-
}
|
|
1523
|
-
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1552
|
+
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1553
|
+
const configMeta = meta ?? { fromApp: appName };
|
|
1524
1554
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1525
1555
|
if (maybeConfig) {
|
|
1526
1556
|
return MicrofrontendsServer.fromFile({
|
|
@@ -1535,7 +1565,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1535
1565
|
if (isMonorepo2) {
|
|
1536
1566
|
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1537
1567
|
repositoryRoot,
|
|
1538
|
-
applicationName:
|
|
1568
|
+
applicationName: appName
|
|
1539
1569
|
});
|
|
1540
1570
|
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1541
1571
|
if (maybeConfigFromDefault) {
|
|
@@ -1565,7 +1595,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1565
1595
|
options
|
|
1566
1596
|
}) {
|
|
1567
1597
|
try {
|
|
1568
|
-
const configJson =
|
|
1598
|
+
const configJson = fs6.readFileSync(filePath, "utf-8");
|
|
1569
1599
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1570
1600
|
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1571
1601
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1613,7 +1643,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1613
1643
|
overrides
|
|
1614
1644
|
}) {
|
|
1615
1645
|
try {
|
|
1616
|
-
const config =
|
|
1646
|
+
const config = fs6.readFileSync(filePath, "utf-8");
|
|
1617
1647
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1618
1648
|
if (!isMainConfig(validatedConfig)) {
|
|
1619
1649
|
throw new MicrofrontendError(
|