@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
package/dist/utils/mfe-port.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/utils/mfe-port.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import path6 from "node:path";
|
|
3
|
+
import fs7 from "node:fs";
|
|
4
4
|
|
|
5
5
|
// src/config/microfrontends/server/index.ts
|
|
6
|
-
import
|
|
7
|
-
import { dirname as dirname3
|
|
6
|
+
import fs6 from "node:fs";
|
|
7
|
+
import { dirname as dirname3 } from "node:path";
|
|
8
8
|
|
|
9
9
|
// src/config/overrides/constants.ts
|
|
10
10
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -187,21 +187,21 @@ var MicrofrontendConfigClient = class {
|
|
|
187
187
|
isEqual(other) {
|
|
188
188
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
189
189
|
}
|
|
190
|
-
getApplicationNameForPath(
|
|
191
|
-
if (!
|
|
190
|
+
getApplicationNameForPath(path7) {
|
|
191
|
+
if (!path7.startsWith("/")) {
|
|
192
192
|
throw new Error(`Path must start with a /`);
|
|
193
193
|
}
|
|
194
|
-
if (this.pathCache[
|
|
195
|
-
return this.pathCache[
|
|
194
|
+
if (this.pathCache[path7]) {
|
|
195
|
+
return this.pathCache[path7];
|
|
196
196
|
}
|
|
197
|
-
const pathname = new URL(
|
|
197
|
+
const pathname = new URL(path7, "https://example.com").pathname;
|
|
198
198
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
199
199
|
if (application.routing) {
|
|
200
200
|
for (const group of application.routing) {
|
|
201
201
|
for (const childPath of group.paths) {
|
|
202
202
|
const regexp = pathToRegexp(childPath);
|
|
203
203
|
if (regexp.test(pathname)) {
|
|
204
|
-
this.pathCache[
|
|
204
|
+
this.pathCache[path7] = name;
|
|
205
205
|
return name;
|
|
206
206
|
}
|
|
207
207
|
}
|
|
@@ -214,7 +214,7 @@ var MicrofrontendConfigClient = class {
|
|
|
214
214
|
if (!defaultApplication) {
|
|
215
215
|
return null;
|
|
216
216
|
}
|
|
217
|
-
this.pathCache[
|
|
217
|
+
this.pathCache[path7] = defaultApplication[0];
|
|
218
218
|
return defaultApplication[0];
|
|
219
219
|
}
|
|
220
220
|
serialize() {
|
|
@@ -236,18 +236,18 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
236
236
|
}
|
|
237
237
|
const childApp = app;
|
|
238
238
|
for (const pathMatch of childApp.routing) {
|
|
239
|
-
for (const
|
|
240
|
-
const maybeError = validatePathExpression(
|
|
239
|
+
for (const path7 of pathMatch.paths) {
|
|
240
|
+
const maybeError = validatePathExpression(path7);
|
|
241
241
|
if (maybeError) {
|
|
242
242
|
errors.push(maybeError);
|
|
243
243
|
} else {
|
|
244
|
-
const existing = pathsByApplicationId.get(
|
|
244
|
+
const existing = pathsByApplicationId.get(path7);
|
|
245
245
|
if (existing) {
|
|
246
246
|
existing.applications.push(id);
|
|
247
247
|
} else {
|
|
248
|
-
pathsByApplicationId.set(
|
|
248
|
+
pathsByApplicationId.set(path7, {
|
|
249
249
|
applications: [id],
|
|
250
|
-
matcher: pathToRegexp2(
|
|
250
|
+
matcher: pathToRegexp2(path7),
|
|
251
251
|
applicationId: id
|
|
252
252
|
});
|
|
253
253
|
}
|
|
@@ -256,24 +256,24 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
259
|
-
for (const [
|
|
259
|
+
for (const [path7, { applications: ids, matcher, applicationId }] of entries) {
|
|
260
260
|
if (ids.length > 1) {
|
|
261
261
|
errors.push(
|
|
262
|
-
`Duplicate path "${
|
|
262
|
+
`Duplicate path "${path7}" for applications "${ids.join(", ")}"`
|
|
263
263
|
);
|
|
264
264
|
}
|
|
265
265
|
for (const [
|
|
266
266
|
matchPath,
|
|
267
267
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
268
268
|
] of entries) {
|
|
269
|
-
if (
|
|
269
|
+
if (path7 === matchPath) {
|
|
270
270
|
continue;
|
|
271
271
|
}
|
|
272
272
|
if (applicationId === matchApplicationId) {
|
|
273
273
|
continue;
|
|
274
274
|
}
|
|
275
275
|
if (matcher.test(matchPath)) {
|
|
276
|
-
const source = `"${
|
|
276
|
+
const source = `"${path7}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
277
277
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
278
278
|
errors.push(
|
|
279
279
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -289,39 +289,42 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
289
289
|
}
|
|
290
290
|
};
|
|
291
291
|
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
292
|
-
function validatePathExpression(
|
|
292
|
+
function validatePathExpression(path7) {
|
|
293
293
|
try {
|
|
294
|
-
const tokens = parsePathRegexp(
|
|
295
|
-
if (/(?<!\\)\{/.test(
|
|
296
|
-
return `Optional paths are not supported: ${
|
|
294
|
+
const tokens = parsePathRegexp(path7);
|
|
295
|
+
if (/(?<!\\)\{/.test(path7)) {
|
|
296
|
+
return `Optional paths are not supported: ${path7}`;
|
|
297
297
|
}
|
|
298
|
-
if (/(?<!\\|\()\?/.test(
|
|
299
|
-
return `Optional paths are not supported: ${
|
|
298
|
+
if (/(?<!\\|\()\?/.test(path7)) {
|
|
299
|
+
return `Optional paths are not supported: ${path7}`;
|
|
300
300
|
}
|
|
301
|
-
if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(
|
|
302
|
-
return `Only one wildcard is allowed per path segment: ${
|
|
301
|
+
if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path7)) {
|
|
302
|
+
return `Only one wildcard is allowed per path segment: ${path7}`;
|
|
303
303
|
}
|
|
304
304
|
for (let i = 0; i < tokens.length; i++) {
|
|
305
305
|
const token = tokens[i];
|
|
306
306
|
if (token === void 0) {
|
|
307
|
-
return `token ${i} in ${
|
|
307
|
+
return `token ${i} in ${path7} is undefined, this shouldn't happen`;
|
|
308
308
|
}
|
|
309
309
|
if (typeof token !== "string") {
|
|
310
|
+
if (!token.name) {
|
|
311
|
+
return `Only named wildcards are allowed: ${path7} (hint: add ":path" to the wildcard)`;
|
|
312
|
+
}
|
|
310
313
|
if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
311
314
|
// Only limited regex is supported for now, due to performance considerations
|
|
312
315
|
!/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
|
|
313
316
|
token.pattern
|
|
314
317
|
)) {
|
|
315
|
-
return `Path ${
|
|
318
|
+
return `Path ${path7} cannot use unsupported regular expression wildcard`;
|
|
316
319
|
}
|
|
317
320
|
if (token.modifier && i !== tokens.length - 1) {
|
|
318
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${
|
|
321
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path7}. Modifiers are only allowed in the last path component`;
|
|
319
322
|
}
|
|
320
323
|
}
|
|
321
324
|
}
|
|
322
325
|
} catch (e) {
|
|
323
326
|
const message = e instanceof Error ? e.message : String(e);
|
|
324
|
-
return `Path ${
|
|
327
|
+
return `Path ${path7} could not be parsed into regexp: ${message}`;
|
|
325
328
|
}
|
|
326
329
|
return void 0;
|
|
327
330
|
}
|
|
@@ -675,12 +678,8 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
675
678
|
const skipValidation = opts?.skipValidation ?? [];
|
|
676
679
|
const c = typeof config === "string" ? parse(config) : config;
|
|
677
680
|
if (isMainConfig(c)) {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
}
|
|
681
|
-
if (!skipValidation.includes("defaultApplication")) {
|
|
682
|
-
validateConfigDefaultApplication(c.applications);
|
|
683
|
-
}
|
|
681
|
+
validateConfigPaths(c.applications);
|
|
682
|
+
validateConfigDefaultApplication(c.applications);
|
|
684
683
|
if (!skipValidation.includes("deprecatedFields")) {
|
|
685
684
|
validateDeprecatedFields(c);
|
|
686
685
|
}
|
|
@@ -1037,6 +1036,9 @@ function isMonorepo({
|
|
|
1037
1036
|
if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1038
1037
|
return true;
|
|
1039
1038
|
}
|
|
1039
|
+
if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
|
|
1040
|
+
return true;
|
|
1041
|
+
}
|
|
1040
1042
|
const packageJsonPath = path2.join(repositoryRoot, "package.json");
|
|
1041
1043
|
if (!fs2.existsSync(packageJsonPath)) {
|
|
1042
1044
|
return false;
|
|
@@ -1082,8 +1084,42 @@ function findConfig({ dir }) {
|
|
|
1082
1084
|
return null;
|
|
1083
1085
|
}
|
|
1084
1086
|
|
|
1085
|
-
// src/config/microfrontends/
|
|
1087
|
+
// src/config/microfrontends/utils/get-application-context.ts
|
|
1088
|
+
import fs5 from "node:fs";
|
|
1086
1089
|
import path4 from "node:path";
|
|
1090
|
+
function getApplicationContext(opts) {
|
|
1091
|
+
if (opts?.appName) {
|
|
1092
|
+
return { name: opts.appName };
|
|
1093
|
+
}
|
|
1094
|
+
if (process.env.NX_TASK_TARGET_PROJECT) {
|
|
1095
|
+
return { name: process.env.NX_TASK_TARGET_PROJECT };
|
|
1096
|
+
}
|
|
1097
|
+
try {
|
|
1098
|
+
const packageJsonString = fs5.readFileSync(
|
|
1099
|
+
path4.join(opts?.packageRoot || ".", "package.json"),
|
|
1100
|
+
"utf-8"
|
|
1101
|
+
);
|
|
1102
|
+
const packageJson = JSON.parse(packageJsonString);
|
|
1103
|
+
if (!packageJson.name) {
|
|
1104
|
+
throw new MicrofrontendError(
|
|
1105
|
+
`package.json file missing required field "name"`,
|
|
1106
|
+
{
|
|
1107
|
+
type: "packageJson",
|
|
1108
|
+
subtype: "missing_field_name",
|
|
1109
|
+
source: "@vercel/microfrontends/next"
|
|
1110
|
+
}
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
return { name: packageJson.name };
|
|
1114
|
+
} catch (err) {
|
|
1115
|
+
throw MicrofrontendError.handle(err, {
|
|
1116
|
+
fileName: "package.json"
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1122
|
+
import path5 from "node:path";
|
|
1087
1123
|
|
|
1088
1124
|
// src/config/microfrontends/server/constants.ts
|
|
1089
1125
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1091,7 +1127,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1091
1127
|
|
|
1092
1128
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1093
1129
|
function getOutputFilePath() {
|
|
1094
|
-
return
|
|
1130
|
+
return path5.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1095
1131
|
}
|
|
1096
1132
|
|
|
1097
1133
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1430,8 +1466,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1430
1466
|
pretty: true
|
|
1431
1467
|
}) {
|
|
1432
1468
|
const outputPath = getOutputFilePath();
|
|
1433
|
-
|
|
1434
|
-
|
|
1469
|
+
fs6.mkdirSync(dirname3(outputPath), { recursive: true });
|
|
1470
|
+
fs6.writeFileSync(
|
|
1435
1471
|
outputPath,
|
|
1436
1472
|
JSON.stringify(
|
|
1437
1473
|
this.config.toSchemaJson(),
|
|
@@ -1517,14 +1553,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1517
1553
|
}
|
|
1518
1554
|
try {
|
|
1519
1555
|
const packageRoot = findPackageRoot(directory);
|
|
1520
|
-
const
|
|
1521
|
-
const
|
|
1522
|
-
fs5.readFileSync(packageJsonPath, "utf-8")
|
|
1523
|
-
);
|
|
1524
|
-
if (!packageJson.name) {
|
|
1525
|
-
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1526
|
-
}
|
|
1527
|
-
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1556
|
+
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1557
|
+
const configMeta = meta ?? { fromApp: appName };
|
|
1528
1558
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1529
1559
|
if (maybeConfig) {
|
|
1530
1560
|
return MicrofrontendsServer.fromFile({
|
|
@@ -1539,7 +1569,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1539
1569
|
if (isMonorepo2) {
|
|
1540
1570
|
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1541
1571
|
repositoryRoot,
|
|
1542
|
-
applicationName:
|
|
1572
|
+
applicationName: appName
|
|
1543
1573
|
});
|
|
1544
1574
|
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1545
1575
|
if (maybeConfigFromDefault) {
|
|
@@ -1569,7 +1599,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1569
1599
|
options
|
|
1570
1600
|
}) {
|
|
1571
1601
|
try {
|
|
1572
|
-
const configJson =
|
|
1602
|
+
const configJson = fs6.readFileSync(filePath, "utf-8");
|
|
1573
1603
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1574
1604
|
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1575
1605
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1617,7 +1647,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1617
1647
|
overrides
|
|
1618
1648
|
}) {
|
|
1619
1649
|
try {
|
|
1620
|
-
const config =
|
|
1650
|
+
const config = fs6.readFileSync(filePath, "utf-8");
|
|
1621
1651
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1622
1652
|
if (!isMainConfig(validatedConfig)) {
|
|
1623
1653
|
throw new MicrofrontendError(
|
|
@@ -1666,8 +1696,8 @@ function mfePort(packageDir) {
|
|
|
1666
1696
|
};
|
|
1667
1697
|
}
|
|
1668
1698
|
function getPackageJson(packageDir) {
|
|
1669
|
-
const filePath =
|
|
1670
|
-
return JSON.parse(
|
|
1699
|
+
const filePath = path6.join(packageDir, "package.json");
|
|
1700
|
+
return JSON.parse(fs7.readFileSync(filePath, "utf-8"));
|
|
1671
1701
|
}
|
|
1672
1702
|
function loadConfig({
|
|
1673
1703
|
packageDir,
|