@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
|
@@ -33,8 +33,8 @@ __export(server_exports, {
|
|
|
33
33
|
MicrofrontendsServer: () => MicrofrontendsServer
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(server_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
36
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
37
|
+
var import_node_path9 = require("path");
|
|
38
38
|
|
|
39
39
|
// src/config/overrides/constants.ts
|
|
40
40
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -217,21 +217,21 @@ var MicrofrontendConfigClient = class {
|
|
|
217
217
|
isEqual(other) {
|
|
218
218
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
219
219
|
}
|
|
220
|
-
getApplicationNameForPath(
|
|
221
|
-
if (!
|
|
220
|
+
getApplicationNameForPath(path6) {
|
|
221
|
+
if (!path6.startsWith("/")) {
|
|
222
222
|
throw new Error(`Path must start with a /`);
|
|
223
223
|
}
|
|
224
|
-
if (this.pathCache[
|
|
225
|
-
return this.pathCache[
|
|
224
|
+
if (this.pathCache[path6]) {
|
|
225
|
+
return this.pathCache[path6];
|
|
226
226
|
}
|
|
227
|
-
const pathname = new URL(
|
|
227
|
+
const pathname = new URL(path6, "https://example.com").pathname;
|
|
228
228
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
229
229
|
if (application.routing) {
|
|
230
230
|
for (const group of application.routing) {
|
|
231
231
|
for (const childPath of group.paths) {
|
|
232
232
|
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
233
233
|
if (regexp.test(pathname)) {
|
|
234
|
-
this.pathCache[
|
|
234
|
+
this.pathCache[path6] = name;
|
|
235
235
|
return name;
|
|
236
236
|
}
|
|
237
237
|
}
|
|
@@ -244,7 +244,7 @@ var MicrofrontendConfigClient = class {
|
|
|
244
244
|
if (!defaultApplication) {
|
|
245
245
|
return null;
|
|
246
246
|
}
|
|
247
|
-
this.pathCache[
|
|
247
|
+
this.pathCache[path6] = defaultApplication[0];
|
|
248
248
|
return defaultApplication[0];
|
|
249
249
|
}
|
|
250
250
|
serialize() {
|
|
@@ -266,18 +266,18 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
266
266
|
}
|
|
267
267
|
const childApp = app;
|
|
268
268
|
for (const pathMatch of childApp.routing) {
|
|
269
|
-
for (const
|
|
270
|
-
const maybeError = validatePathExpression(
|
|
269
|
+
for (const path6 of pathMatch.paths) {
|
|
270
|
+
const maybeError = validatePathExpression(path6);
|
|
271
271
|
if (maybeError) {
|
|
272
272
|
errors.push(maybeError);
|
|
273
273
|
} else {
|
|
274
|
-
const existing = pathsByApplicationId.get(
|
|
274
|
+
const existing = pathsByApplicationId.get(path6);
|
|
275
275
|
if (existing) {
|
|
276
276
|
existing.applications.push(id);
|
|
277
277
|
} else {
|
|
278
|
-
pathsByApplicationId.set(
|
|
278
|
+
pathsByApplicationId.set(path6, {
|
|
279
279
|
applications: [id],
|
|
280
|
-
matcher: (0, import_path_to_regexp2.pathToRegexp)(
|
|
280
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path6),
|
|
281
281
|
applicationId: id
|
|
282
282
|
});
|
|
283
283
|
}
|
|
@@ -286,24 +286,24 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
289
|
-
for (const [
|
|
289
|
+
for (const [path6, { applications: ids, matcher, applicationId }] of entries) {
|
|
290
290
|
if (ids.length > 1) {
|
|
291
291
|
errors.push(
|
|
292
|
-
`Duplicate path "${
|
|
292
|
+
`Duplicate path "${path6}" for applications "${ids.join(", ")}"`
|
|
293
293
|
);
|
|
294
294
|
}
|
|
295
295
|
for (const [
|
|
296
296
|
matchPath,
|
|
297
297
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
298
298
|
] of entries) {
|
|
299
|
-
if (
|
|
299
|
+
if (path6 === matchPath) {
|
|
300
300
|
continue;
|
|
301
301
|
}
|
|
302
302
|
if (applicationId === matchApplicationId) {
|
|
303
303
|
continue;
|
|
304
304
|
}
|
|
305
305
|
if (matcher.test(matchPath)) {
|
|
306
|
-
const source = `"${
|
|
306
|
+
const source = `"${path6}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
307
307
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
308
308
|
errors.push(
|
|
309
309
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -319,39 +319,42 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
319
319
|
}
|
|
320
320
|
};
|
|
321
321
|
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
322
|
-
function validatePathExpression(
|
|
322
|
+
function validatePathExpression(path6) {
|
|
323
323
|
try {
|
|
324
|
-
const tokens = (0, import_path_to_regexp2.parse)(
|
|
325
|
-
if (/(?<!\\)\{/.test(
|
|
326
|
-
return `Optional paths are not supported: ${
|
|
324
|
+
const tokens = (0, import_path_to_regexp2.parse)(path6);
|
|
325
|
+
if (/(?<!\\)\{/.test(path6)) {
|
|
326
|
+
return `Optional paths are not supported: ${path6}`;
|
|
327
327
|
}
|
|
328
|
-
if (/(?<!\\|\()\?/.test(
|
|
329
|
-
return `Optional paths are not supported: ${
|
|
328
|
+
if (/(?<!\\|\()\?/.test(path6)) {
|
|
329
|
+
return `Optional paths are not supported: ${path6}`;
|
|
330
330
|
}
|
|
331
|
-
if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(
|
|
332
|
-
return `Only one wildcard is allowed per path segment: ${
|
|
331
|
+
if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path6)) {
|
|
332
|
+
return `Only one wildcard is allowed per path segment: ${path6}`;
|
|
333
333
|
}
|
|
334
334
|
for (let i = 0; i < tokens.length; i++) {
|
|
335
335
|
const token = tokens[i];
|
|
336
336
|
if (token === void 0) {
|
|
337
|
-
return `token ${i} in ${
|
|
337
|
+
return `token ${i} in ${path6} is undefined, this shouldn't happen`;
|
|
338
338
|
}
|
|
339
339
|
if (typeof token !== "string") {
|
|
340
|
+
if (!token.name) {
|
|
341
|
+
return `Only named wildcards are allowed: ${path6} (hint: add ":path" to the wildcard)`;
|
|
342
|
+
}
|
|
340
343
|
if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
341
344
|
// Only limited regex is supported for now, due to performance considerations
|
|
342
345
|
!/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
|
|
343
346
|
token.pattern
|
|
344
347
|
)) {
|
|
345
|
-
return `Path ${
|
|
348
|
+
return `Path ${path6} cannot use unsupported regular expression wildcard`;
|
|
346
349
|
}
|
|
347
350
|
if (token.modifier && i !== tokens.length - 1) {
|
|
348
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${
|
|
351
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path6}. Modifiers are only allowed in the last path component`;
|
|
349
352
|
}
|
|
350
353
|
}
|
|
351
354
|
}
|
|
352
355
|
} catch (e) {
|
|
353
356
|
const message = e instanceof Error ? e.message : String(e);
|
|
354
|
-
return `Path ${
|
|
357
|
+
return `Path ${path6} could not be parsed into regexp: ${message}`;
|
|
355
358
|
}
|
|
356
359
|
return void 0;
|
|
357
360
|
}
|
|
@@ -906,6 +909,9 @@ var import_node_fs = __toESM(require("fs"), 1);
|
|
|
906
909
|
var import_node_path = __toESM(require("path"), 1);
|
|
907
910
|
var GIT_DIRECTORY = ".git";
|
|
908
911
|
function findRepositoryRoot(startDir) {
|
|
912
|
+
if (process.env.NX_WORKSPACE_ROOT) {
|
|
913
|
+
return process.env.NX_WORKSPACE_ROOT;
|
|
914
|
+
}
|
|
909
915
|
let currentDir = startDir || process.cwd();
|
|
910
916
|
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
911
917
|
const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
|
|
@@ -1063,6 +1069,9 @@ function isMonorepo({
|
|
|
1063
1069
|
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1064
1070
|
return true;
|
|
1065
1071
|
}
|
|
1072
|
+
if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
|
|
1073
|
+
return true;
|
|
1074
|
+
}
|
|
1066
1075
|
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
1067
1076
|
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
1068
1077
|
return false;
|
|
@@ -1108,8 +1117,42 @@ function findConfig({ dir }) {
|
|
|
1108
1117
|
return null;
|
|
1109
1118
|
}
|
|
1110
1119
|
|
|
1111
|
-
// src/config/microfrontends/
|
|
1120
|
+
// src/config/microfrontends/utils/get-application-context.ts
|
|
1121
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
1112
1122
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
1123
|
+
function getApplicationContext(opts) {
|
|
1124
|
+
if (opts?.appName) {
|
|
1125
|
+
return { name: opts.appName };
|
|
1126
|
+
}
|
|
1127
|
+
if (process.env.NX_TASK_TARGET_PROJECT) {
|
|
1128
|
+
return { name: process.env.NX_TASK_TARGET_PROJECT };
|
|
1129
|
+
}
|
|
1130
|
+
try {
|
|
1131
|
+
const packageJsonString = import_node_fs7.default.readFileSync(
|
|
1132
|
+
import_node_path7.default.join(opts?.packageRoot || ".", "package.json"),
|
|
1133
|
+
"utf-8"
|
|
1134
|
+
);
|
|
1135
|
+
const packageJson = JSON.parse(packageJsonString);
|
|
1136
|
+
if (!packageJson.name) {
|
|
1137
|
+
throw new MicrofrontendError(
|
|
1138
|
+
`package.json file missing required field "name"`,
|
|
1139
|
+
{
|
|
1140
|
+
type: "packageJson",
|
|
1141
|
+
subtype: "missing_field_name",
|
|
1142
|
+
source: "@vercel/microfrontends/next"
|
|
1143
|
+
}
|
|
1144
|
+
);
|
|
1145
|
+
}
|
|
1146
|
+
return { name: packageJson.name };
|
|
1147
|
+
} catch (err) {
|
|
1148
|
+
throw MicrofrontendError.handle(err, {
|
|
1149
|
+
fileName: "package.json"
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1155
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
1113
1156
|
|
|
1114
1157
|
// src/config/microfrontends/server/constants.ts
|
|
1115
1158
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1117,7 +1160,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1117
1160
|
|
|
1118
1161
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1119
1162
|
function getOutputFilePath() {
|
|
1120
|
-
return
|
|
1163
|
+
return import_node_path8.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1121
1164
|
}
|
|
1122
1165
|
|
|
1123
1166
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1456,8 +1499,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1456
1499
|
pretty: true
|
|
1457
1500
|
}) {
|
|
1458
1501
|
const outputPath = getOutputFilePath();
|
|
1459
|
-
|
|
1460
|
-
|
|
1502
|
+
import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
|
|
1503
|
+
import_node_fs8.default.writeFileSync(
|
|
1461
1504
|
outputPath,
|
|
1462
1505
|
JSON.stringify(
|
|
1463
1506
|
this.config.toSchemaJson(),
|
|
@@ -1543,14 +1586,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1543
1586
|
}
|
|
1544
1587
|
try {
|
|
1545
1588
|
const packageRoot = findPackageRoot(directory);
|
|
1546
|
-
const
|
|
1547
|
-
const
|
|
1548
|
-
import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
|
|
1549
|
-
);
|
|
1550
|
-
if (!packageJson.name) {
|
|
1551
|
-
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1552
|
-
}
|
|
1553
|
-
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1589
|
+
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1590
|
+
const configMeta = meta ?? { fromApp: appName };
|
|
1554
1591
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1555
1592
|
if (maybeConfig) {
|
|
1556
1593
|
return MicrofrontendsServer.fromFile({
|
|
@@ -1565,7 +1602,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1565
1602
|
if (isMonorepo2) {
|
|
1566
1603
|
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1567
1604
|
repositoryRoot,
|
|
1568
|
-
applicationName:
|
|
1605
|
+
applicationName: appName
|
|
1569
1606
|
});
|
|
1570
1607
|
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1571
1608
|
if (maybeConfigFromDefault) {
|
|
@@ -1595,7 +1632,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1595
1632
|
options
|
|
1596
1633
|
}) {
|
|
1597
1634
|
try {
|
|
1598
|
-
const configJson =
|
|
1635
|
+
const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
1599
1636
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1600
1637
|
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1601
1638
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1643,7 +1680,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1643
1680
|
overrides
|
|
1644
1681
|
}) {
|
|
1645
1682
|
try {
|
|
1646
|
-
const config =
|
|
1683
|
+
const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
1647
1684
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1648
1685
|
if (!isMainConfig(validatedConfig)) {
|
|
1649
1686
|
throw new MicrofrontendError(
|