@vercel/microfrontends 1.0.1-canary.3 → 1.0.1-canary.5
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 +116 -79
- package/dist/config.cjs +3 -0
- package/dist/config.cjs.map +1 -1
- package/dist/config.js +3 -0
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +82 -72
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +82 -72
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +85 -75
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.js +85 -75
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +82 -45
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.js +82 -45
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends.cjs +3 -0
- package/dist/microfrontends.cjs.map +1 -1
- package/dist/microfrontends.js +3 -0
- package/dist/microfrontends.js.map +1 -1
- package/dist/next/config.cjs +82 -72
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +82 -72
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +3 -0
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +3 -0
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +3 -0
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.js +3 -0
- package/dist/next/testing.js.map +1 -1
- package/dist/utils/mfe-port.cjs +86 -49
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +86 -49
- 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
|
}
|
|
@@ -876,6 +879,9 @@ import fs from "node:fs";
|
|
|
876
879
|
import path from "node:path";
|
|
877
880
|
var GIT_DIRECTORY = ".git";
|
|
878
881
|
function findRepositoryRoot(startDir) {
|
|
882
|
+
if (process.env.NX_WORKSPACE_ROOT) {
|
|
883
|
+
return process.env.NX_WORKSPACE_ROOT;
|
|
884
|
+
}
|
|
879
885
|
let currentDir = startDir || process.cwd();
|
|
880
886
|
while (currentDir !== path.parse(currentDir).root) {
|
|
881
887
|
const gitPath = path.join(currentDir, GIT_DIRECTORY);
|
|
@@ -1033,6 +1039,9 @@ function isMonorepo({
|
|
|
1033
1039
|
if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1034
1040
|
return true;
|
|
1035
1041
|
}
|
|
1042
|
+
if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
|
|
1043
|
+
return true;
|
|
1044
|
+
}
|
|
1036
1045
|
const packageJsonPath = path2.join(repositoryRoot, "package.json");
|
|
1037
1046
|
if (!fs2.existsSync(packageJsonPath)) {
|
|
1038
1047
|
return false;
|
|
@@ -1078,8 +1087,42 @@ function findConfig({ dir }) {
|
|
|
1078
1087
|
return null;
|
|
1079
1088
|
}
|
|
1080
1089
|
|
|
1081
|
-
// src/config/microfrontends/
|
|
1090
|
+
// src/config/microfrontends/utils/get-application-context.ts
|
|
1091
|
+
import fs5 from "node:fs";
|
|
1082
1092
|
import path4 from "node:path";
|
|
1093
|
+
function getApplicationContext(opts) {
|
|
1094
|
+
if (opts?.appName) {
|
|
1095
|
+
return { name: opts.appName };
|
|
1096
|
+
}
|
|
1097
|
+
if (process.env.NX_TASK_TARGET_PROJECT) {
|
|
1098
|
+
return { name: process.env.NX_TASK_TARGET_PROJECT };
|
|
1099
|
+
}
|
|
1100
|
+
try {
|
|
1101
|
+
const packageJsonString = fs5.readFileSync(
|
|
1102
|
+
path4.join(opts?.packageRoot || ".", "package.json"),
|
|
1103
|
+
"utf-8"
|
|
1104
|
+
);
|
|
1105
|
+
const packageJson = JSON.parse(packageJsonString);
|
|
1106
|
+
if (!packageJson.name) {
|
|
1107
|
+
throw new MicrofrontendError(
|
|
1108
|
+
`package.json file missing required field "name"`,
|
|
1109
|
+
{
|
|
1110
|
+
type: "packageJson",
|
|
1111
|
+
subtype: "missing_field_name",
|
|
1112
|
+
source: "@vercel/microfrontends/next"
|
|
1113
|
+
}
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
return { name: packageJson.name };
|
|
1117
|
+
} catch (err) {
|
|
1118
|
+
throw MicrofrontendError.handle(err, {
|
|
1119
|
+
fileName: "package.json"
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1125
|
+
import path5 from "node:path";
|
|
1083
1126
|
|
|
1084
1127
|
// src/config/microfrontends/server/constants.ts
|
|
1085
1128
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1087,7 +1130,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1087
1130
|
|
|
1088
1131
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1089
1132
|
function getOutputFilePath() {
|
|
1090
|
-
return
|
|
1133
|
+
return path5.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1091
1134
|
}
|
|
1092
1135
|
|
|
1093
1136
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1426,8 +1469,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1426
1469
|
pretty: true
|
|
1427
1470
|
}) {
|
|
1428
1471
|
const outputPath = getOutputFilePath();
|
|
1429
|
-
|
|
1430
|
-
|
|
1472
|
+
fs6.mkdirSync(dirname3(outputPath), { recursive: true });
|
|
1473
|
+
fs6.writeFileSync(
|
|
1431
1474
|
outputPath,
|
|
1432
1475
|
JSON.stringify(
|
|
1433
1476
|
this.config.toSchemaJson(),
|
|
@@ -1513,14 +1556,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1513
1556
|
}
|
|
1514
1557
|
try {
|
|
1515
1558
|
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 };
|
|
1559
|
+
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1560
|
+
const configMeta = meta ?? { fromApp: appName };
|
|
1524
1561
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1525
1562
|
if (maybeConfig) {
|
|
1526
1563
|
return MicrofrontendsServer.fromFile({
|
|
@@ -1535,7 +1572,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1535
1572
|
if (isMonorepo2) {
|
|
1536
1573
|
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1537
1574
|
repositoryRoot,
|
|
1538
|
-
applicationName:
|
|
1575
|
+
applicationName: appName
|
|
1539
1576
|
});
|
|
1540
1577
|
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1541
1578
|
if (maybeConfigFromDefault) {
|
|
@@ -1565,7 +1602,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1565
1602
|
options
|
|
1566
1603
|
}) {
|
|
1567
1604
|
try {
|
|
1568
|
-
const configJson =
|
|
1605
|
+
const configJson = fs6.readFileSync(filePath, "utf-8");
|
|
1569
1606
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1570
1607
|
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1571
1608
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1613,7 +1650,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1613
1650
|
overrides
|
|
1614
1651
|
}) {
|
|
1615
1652
|
try {
|
|
1616
|
-
const config =
|
|
1653
|
+
const config = fs6.readFileSync(filePath, "utf-8");
|
|
1617
1654
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1618
1655
|
if (!isMainConfig(validatedConfig)) {
|
|
1619
1656
|
throw new MicrofrontendError(
|
|
@@ -1662,8 +1699,8 @@ function mfePort(packageDir) {
|
|
|
1662
1699
|
};
|
|
1663
1700
|
}
|
|
1664
1701
|
function getPackageJson(packageDir) {
|
|
1665
|
-
const filePath =
|
|
1666
|
-
return JSON.parse(
|
|
1702
|
+
const filePath = path6.join(packageDir, "package.json");
|
|
1703
|
+
return JSON.parse(fs7.readFileSync(filePath, "utf-8"));
|
|
1667
1704
|
}
|
|
1668
1705
|
function loadConfig({
|
|
1669
1706
|
packageDir,
|