@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
|
@@ -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
|
}
|
|
@@ -705,12 +708,8 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
705
708
|
const skipValidation = opts?.skipValidation ?? [];
|
|
706
709
|
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
707
710
|
if (isMainConfig(c)) {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
if (!skipValidation.includes("defaultApplication")) {
|
|
712
|
-
validateConfigDefaultApplication(c.applications);
|
|
713
|
-
}
|
|
711
|
+
validateConfigPaths(c.applications);
|
|
712
|
+
validateConfigDefaultApplication(c.applications);
|
|
714
713
|
if (!skipValidation.includes("deprecatedFields")) {
|
|
715
714
|
validateDeprecatedFields(c);
|
|
716
715
|
}
|
|
@@ -1067,6 +1066,9 @@ function isMonorepo({
|
|
|
1067
1066
|
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1068
1067
|
return true;
|
|
1069
1068
|
}
|
|
1069
|
+
if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
|
|
1070
|
+
return true;
|
|
1071
|
+
}
|
|
1070
1072
|
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
1071
1073
|
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
1072
1074
|
return false;
|
|
@@ -1112,8 +1114,42 @@ function findConfig({ dir }) {
|
|
|
1112
1114
|
return null;
|
|
1113
1115
|
}
|
|
1114
1116
|
|
|
1115
|
-
// src/config/microfrontends/
|
|
1117
|
+
// src/config/microfrontends/utils/get-application-context.ts
|
|
1118
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
1116
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);
|
|
1117
1153
|
|
|
1118
1154
|
// src/config/microfrontends/server/constants.ts
|
|
1119
1155
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1121,7 +1157,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1121
1157
|
|
|
1122
1158
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1123
1159
|
function getOutputFilePath() {
|
|
1124
|
-
return
|
|
1160
|
+
return import_node_path8.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1125
1161
|
}
|
|
1126
1162
|
|
|
1127
1163
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1460,8 +1496,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1460
1496
|
pretty: true
|
|
1461
1497
|
}) {
|
|
1462
1498
|
const outputPath = getOutputFilePath();
|
|
1463
|
-
|
|
1464
|
-
|
|
1499
|
+
import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
|
|
1500
|
+
import_node_fs8.default.writeFileSync(
|
|
1465
1501
|
outputPath,
|
|
1466
1502
|
JSON.stringify(
|
|
1467
1503
|
this.config.toSchemaJson(),
|
|
@@ -1547,14 +1583,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1547
1583
|
}
|
|
1548
1584
|
try {
|
|
1549
1585
|
const packageRoot = findPackageRoot(directory);
|
|
1550
|
-
const
|
|
1551
|
-
const
|
|
1552
|
-
import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
|
|
1553
|
-
);
|
|
1554
|
-
if (!packageJson.name) {
|
|
1555
|
-
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1556
|
-
}
|
|
1557
|
-
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1586
|
+
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1587
|
+
const configMeta = meta ?? { fromApp: appName };
|
|
1558
1588
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1559
1589
|
if (maybeConfig) {
|
|
1560
1590
|
return MicrofrontendsServer.fromFile({
|
|
@@ -1569,7 +1599,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1569
1599
|
if (isMonorepo2) {
|
|
1570
1600
|
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1571
1601
|
repositoryRoot,
|
|
1572
|
-
applicationName:
|
|
1602
|
+
applicationName: appName
|
|
1573
1603
|
});
|
|
1574
1604
|
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1575
1605
|
if (maybeConfigFromDefault) {
|
|
@@ -1599,7 +1629,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1599
1629
|
options
|
|
1600
1630
|
}) {
|
|
1601
1631
|
try {
|
|
1602
|
-
const configJson =
|
|
1632
|
+
const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
1603
1633
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1604
1634
|
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1605
1635
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1647,7 +1677,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1647
1677
|
overrides
|
|
1648
1678
|
}) {
|
|
1649
1679
|
try {
|
|
1650
|
-
const config =
|
|
1680
|
+
const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
1651
1681
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1652
1682
|
if (!isMainConfig(validatedConfig)) {
|
|
1653
1683
|
throw new MicrofrontendError(
|