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