@vercel/microfrontends 1.0.1-canary.3 → 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 +113 -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 +79 -72
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +79 -72
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +82 -75
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.js +82 -75
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +79 -45
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.js +79 -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 +79 -72
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +79 -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 +83 -49
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +83 -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
|
}
|
|
@@ -1063,6 +1066,9 @@ function isMonorepo({
|
|
|
1063
1066
|
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1064
1067
|
return true;
|
|
1065
1068
|
}
|
|
1069
|
+
if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
|
|
1070
|
+
return true;
|
|
1071
|
+
}
|
|
1066
1072
|
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
1067
1073
|
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
1068
1074
|
return false;
|
|
@@ -1108,8 +1114,42 @@ function findConfig({ dir }) {
|
|
|
1108
1114
|
return null;
|
|
1109
1115
|
}
|
|
1110
1116
|
|
|
1111
|
-
// src/config/microfrontends/
|
|
1117
|
+
// src/config/microfrontends/utils/get-application-context.ts
|
|
1118
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
1112
1119
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
1120
|
+
function getApplicationContext(opts) {
|
|
1121
|
+
if (opts?.appName) {
|
|
1122
|
+
return { name: opts.appName };
|
|
1123
|
+
}
|
|
1124
|
+
if (process.env.NX_TASK_TARGET_PROJECT) {
|
|
1125
|
+
return { name: process.env.NX_TASK_TARGET_PROJECT };
|
|
1126
|
+
}
|
|
1127
|
+
try {
|
|
1128
|
+
const packageJsonString = import_node_fs7.default.readFileSync(
|
|
1129
|
+
import_node_path7.default.join(opts?.packageRoot || ".", "package.json"),
|
|
1130
|
+
"utf-8"
|
|
1131
|
+
);
|
|
1132
|
+
const packageJson = JSON.parse(packageJsonString);
|
|
1133
|
+
if (!packageJson.name) {
|
|
1134
|
+
throw new MicrofrontendError(
|
|
1135
|
+
`package.json file missing required field "name"`,
|
|
1136
|
+
{
|
|
1137
|
+
type: "packageJson",
|
|
1138
|
+
subtype: "missing_field_name",
|
|
1139
|
+
source: "@vercel/microfrontends/next"
|
|
1140
|
+
}
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
return { name: packageJson.name };
|
|
1144
|
+
} catch (err) {
|
|
1145
|
+
throw MicrofrontendError.handle(err, {
|
|
1146
|
+
fileName: "package.json"
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1152
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
1113
1153
|
|
|
1114
1154
|
// src/config/microfrontends/server/constants.ts
|
|
1115
1155
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1117,7 +1157,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1117
1157
|
|
|
1118
1158
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1119
1159
|
function getOutputFilePath() {
|
|
1120
|
-
return
|
|
1160
|
+
return import_node_path8.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1121
1161
|
}
|
|
1122
1162
|
|
|
1123
1163
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1456,8 +1496,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1456
1496
|
pretty: true
|
|
1457
1497
|
}) {
|
|
1458
1498
|
const outputPath = getOutputFilePath();
|
|
1459
|
-
|
|
1460
|
-
|
|
1499
|
+
import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
|
|
1500
|
+
import_node_fs8.default.writeFileSync(
|
|
1461
1501
|
outputPath,
|
|
1462
1502
|
JSON.stringify(
|
|
1463
1503
|
this.config.toSchemaJson(),
|
|
@@ -1543,14 +1583,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1543
1583
|
}
|
|
1544
1584
|
try {
|
|
1545
1585
|
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 };
|
|
1586
|
+
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1587
|
+
const configMeta = meta ?? { fromApp: appName };
|
|
1554
1588
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1555
1589
|
if (maybeConfig) {
|
|
1556
1590
|
return MicrofrontendsServer.fromFile({
|
|
@@ -1565,7 +1599,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1565
1599
|
if (isMonorepo2) {
|
|
1566
1600
|
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1567
1601
|
repositoryRoot,
|
|
1568
|
-
applicationName:
|
|
1602
|
+
applicationName: appName
|
|
1569
1603
|
});
|
|
1570
1604
|
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1571
1605
|
if (maybeConfigFromDefault) {
|
|
@@ -1595,7 +1629,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1595
1629
|
options
|
|
1596
1630
|
}) {
|
|
1597
1631
|
try {
|
|
1598
|
-
const configJson =
|
|
1632
|
+
const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
1599
1633
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1600
1634
|
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1601
1635
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1643,7 +1677,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1643
1677
|
overrides
|
|
1644
1678
|
}) {
|
|
1645
1679
|
try {
|
|
1646
|
-
const config =
|
|
1680
|
+
const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
1647
1681
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1648
1682
|
if (!isMainConfig(validatedConfig)) {
|
|
1649
1683
|
throw new MicrofrontendError(
|