@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
package/dist/utils/mfe-port.cjs
CHANGED
|
@@ -33,12 +33,12 @@ __export(mfe_port_exports, {
|
|
|
33
33
|
mfePort: () => mfePort
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(mfe_port_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
36
|
+
var import_node_path10 = __toESM(require("path"), 1);
|
|
37
|
+
var import_node_fs9 = __toESM(require("fs"), 1);
|
|
38
38
|
|
|
39
39
|
// src/config/microfrontends/server/index.ts
|
|
40
|
-
var
|
|
41
|
-
var
|
|
40
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
41
|
+
var import_node_path9 = require("path");
|
|
42
42
|
|
|
43
43
|
// src/config/overrides/constants.ts
|
|
44
44
|
var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
|
|
@@ -221,21 +221,21 @@ var MicrofrontendConfigClient = class {
|
|
|
221
221
|
isEqual(other) {
|
|
222
222
|
return JSON.stringify(this.applications) === JSON.stringify(other.applications);
|
|
223
223
|
}
|
|
224
|
-
getApplicationNameForPath(
|
|
225
|
-
if (!
|
|
224
|
+
getApplicationNameForPath(path7) {
|
|
225
|
+
if (!path7.startsWith("/")) {
|
|
226
226
|
throw new Error(`Path must start with a /`);
|
|
227
227
|
}
|
|
228
|
-
if (this.pathCache[
|
|
229
|
-
return this.pathCache[
|
|
228
|
+
if (this.pathCache[path7]) {
|
|
229
|
+
return this.pathCache[path7];
|
|
230
230
|
}
|
|
231
|
-
const pathname = new URL(
|
|
231
|
+
const pathname = new URL(path7, "https://example.com").pathname;
|
|
232
232
|
for (const [name, application] of Object.entries(this.applications)) {
|
|
233
233
|
if (application.routing) {
|
|
234
234
|
for (const group of application.routing) {
|
|
235
235
|
for (const childPath of group.paths) {
|
|
236
236
|
const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
|
|
237
237
|
if (regexp.test(pathname)) {
|
|
238
|
-
this.pathCache[
|
|
238
|
+
this.pathCache[path7] = name;
|
|
239
239
|
return name;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
@@ -248,7 +248,7 @@ var MicrofrontendConfigClient = class {
|
|
|
248
248
|
if (!defaultApplication) {
|
|
249
249
|
return null;
|
|
250
250
|
}
|
|
251
|
-
this.pathCache[
|
|
251
|
+
this.pathCache[path7] = defaultApplication[0];
|
|
252
252
|
return defaultApplication[0];
|
|
253
253
|
}
|
|
254
254
|
serialize() {
|
|
@@ -270,18 +270,18 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
270
270
|
}
|
|
271
271
|
const childApp = app;
|
|
272
272
|
for (const pathMatch of childApp.routing) {
|
|
273
|
-
for (const
|
|
274
|
-
const maybeError = validatePathExpression(
|
|
273
|
+
for (const path7 of pathMatch.paths) {
|
|
274
|
+
const maybeError = validatePathExpression(path7);
|
|
275
275
|
if (maybeError) {
|
|
276
276
|
errors.push(maybeError);
|
|
277
277
|
} else {
|
|
278
|
-
const existing = pathsByApplicationId.get(
|
|
278
|
+
const existing = pathsByApplicationId.get(path7);
|
|
279
279
|
if (existing) {
|
|
280
280
|
existing.applications.push(id);
|
|
281
281
|
} else {
|
|
282
|
-
pathsByApplicationId.set(
|
|
282
|
+
pathsByApplicationId.set(path7, {
|
|
283
283
|
applications: [id],
|
|
284
|
-
matcher: (0, import_path_to_regexp2.pathToRegexp)(
|
|
284
|
+
matcher: (0, import_path_to_regexp2.pathToRegexp)(path7),
|
|
285
285
|
applicationId: id
|
|
286
286
|
});
|
|
287
287
|
}
|
|
@@ -290,24 +290,24 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
const entries = Array.from(pathsByApplicationId.entries());
|
|
293
|
-
for (const [
|
|
293
|
+
for (const [path7, { applications: ids, matcher, applicationId }] of entries) {
|
|
294
294
|
if (ids.length > 1) {
|
|
295
295
|
errors.push(
|
|
296
|
-
`Duplicate path "${
|
|
296
|
+
`Duplicate path "${path7}" for applications "${ids.join(", ")}"`
|
|
297
297
|
);
|
|
298
298
|
}
|
|
299
299
|
for (const [
|
|
300
300
|
matchPath,
|
|
301
301
|
{ applications: matchIds, applicationId: matchApplicationId }
|
|
302
302
|
] of entries) {
|
|
303
|
-
if (
|
|
303
|
+
if (path7 === matchPath) {
|
|
304
304
|
continue;
|
|
305
305
|
}
|
|
306
306
|
if (applicationId === matchApplicationId) {
|
|
307
307
|
continue;
|
|
308
308
|
}
|
|
309
309
|
if (matcher.test(matchPath)) {
|
|
310
|
-
const source = `"${
|
|
310
|
+
const source = `"${path7}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
|
|
311
311
|
const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
|
|
312
312
|
errors.push(
|
|
313
313
|
`Overlapping path detected between ${source} and ${destination}`
|
|
@@ -323,39 +323,42 @@ var validateConfigPaths = (applicationConfigsById) => {
|
|
|
323
323
|
}
|
|
324
324
|
};
|
|
325
325
|
var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
|
|
326
|
-
function validatePathExpression(
|
|
326
|
+
function validatePathExpression(path7) {
|
|
327
327
|
try {
|
|
328
|
-
const tokens = (0, import_path_to_regexp2.parse)(
|
|
329
|
-
if (/(?<!\\)\{/.test(
|
|
330
|
-
return `Optional paths are not supported: ${
|
|
328
|
+
const tokens = (0, import_path_to_regexp2.parse)(path7);
|
|
329
|
+
if (/(?<!\\)\{/.test(path7)) {
|
|
330
|
+
return `Optional paths are not supported: ${path7}`;
|
|
331
331
|
}
|
|
332
|
-
if (/(?<!\\|\()\?/.test(
|
|
333
|
-
return `Optional paths are not supported: ${
|
|
332
|
+
if (/(?<!\\|\()\?/.test(path7)) {
|
|
333
|
+
return `Optional paths are not supported: ${path7}`;
|
|
334
334
|
}
|
|
335
|
-
if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(
|
|
336
|
-
return `Only one wildcard is allowed per path segment: ${
|
|
335
|
+
if (/\/[^/]*(?<!\\):[^/]*(?<!\\):[^/]*/.test(path7)) {
|
|
336
|
+
return `Only one wildcard is allowed per path segment: ${path7}`;
|
|
337
337
|
}
|
|
338
338
|
for (let i = 0; i < tokens.length; i++) {
|
|
339
339
|
const token = tokens[i];
|
|
340
340
|
if (token === void 0) {
|
|
341
|
-
return `token ${i} in ${
|
|
341
|
+
return `token ${i} in ${path7} is undefined, this shouldn't happen`;
|
|
342
342
|
}
|
|
343
343
|
if (typeof token !== "string") {
|
|
344
|
+
if (!token.name) {
|
|
345
|
+
return `Only named wildcards are allowed: ${path7} (hint: add ":path" to the wildcard)`;
|
|
346
|
+
}
|
|
344
347
|
if (token.pattern !== PATH_DEFAULT_PATTERN && // Allows (a|b|c) and ((?!a|b|c).*) regex
|
|
345
348
|
// Only limited regex is supported for now, due to performance considerations
|
|
346
349
|
!/^(?<allowed>[\w]+(?:\|[^|()]+)+)$|^\(\?!(?<disallowed>[\w]+(?:\|[^|()]+)+)\)\.\*$/.test(
|
|
347
350
|
token.pattern
|
|
348
351
|
)) {
|
|
349
|
-
return `Path ${
|
|
352
|
+
return `Path ${path7} cannot use unsupported regular expression wildcard`;
|
|
350
353
|
}
|
|
351
354
|
if (token.modifier && i !== tokens.length - 1) {
|
|
352
|
-
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${
|
|
355
|
+
return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path7}. Modifiers are only allowed in the last path component`;
|
|
353
356
|
}
|
|
354
357
|
}
|
|
355
358
|
}
|
|
356
359
|
} catch (e) {
|
|
357
360
|
const message = e instanceof Error ? e.message : String(e);
|
|
358
|
-
return `Path ${
|
|
361
|
+
return `Path ${path7} could not be parsed into regexp: ${message}`;
|
|
359
362
|
}
|
|
360
363
|
return void 0;
|
|
361
364
|
}
|
|
@@ -709,12 +712,8 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
709
712
|
const skipValidation = opts?.skipValidation ?? [];
|
|
710
713
|
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
711
714
|
if (isMainConfig(c)) {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
}
|
|
715
|
-
if (!skipValidation.includes("defaultApplication")) {
|
|
716
|
-
validateConfigDefaultApplication(c.applications);
|
|
717
|
-
}
|
|
715
|
+
validateConfigPaths(c.applications);
|
|
716
|
+
validateConfigDefaultApplication(c.applications);
|
|
718
717
|
if (!skipValidation.includes("deprecatedFields")) {
|
|
719
718
|
validateDeprecatedFields(c);
|
|
720
719
|
}
|
|
@@ -1071,6 +1070,9 @@ function isMonorepo({
|
|
|
1071
1070
|
if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
|
|
1072
1071
|
return true;
|
|
1073
1072
|
}
|
|
1073
|
+
if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
|
|
1074
|
+
return true;
|
|
1075
|
+
}
|
|
1074
1076
|
const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
|
|
1075
1077
|
if (!import_node_fs4.default.existsSync(packageJsonPath)) {
|
|
1076
1078
|
return false;
|
|
@@ -1116,8 +1118,42 @@ function findConfig({ dir }) {
|
|
|
1116
1118
|
return null;
|
|
1117
1119
|
}
|
|
1118
1120
|
|
|
1119
|
-
// src/config/microfrontends/
|
|
1121
|
+
// src/config/microfrontends/utils/get-application-context.ts
|
|
1122
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
1120
1123
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
1124
|
+
function getApplicationContext(opts) {
|
|
1125
|
+
if (opts?.appName) {
|
|
1126
|
+
return { name: opts.appName };
|
|
1127
|
+
}
|
|
1128
|
+
if (process.env.NX_TASK_TARGET_PROJECT) {
|
|
1129
|
+
return { name: process.env.NX_TASK_TARGET_PROJECT };
|
|
1130
|
+
}
|
|
1131
|
+
try {
|
|
1132
|
+
const packageJsonString = import_node_fs7.default.readFileSync(
|
|
1133
|
+
import_node_path7.default.join(opts?.packageRoot || ".", "package.json"),
|
|
1134
|
+
"utf-8"
|
|
1135
|
+
);
|
|
1136
|
+
const packageJson = JSON.parse(packageJsonString);
|
|
1137
|
+
if (!packageJson.name) {
|
|
1138
|
+
throw new MicrofrontendError(
|
|
1139
|
+
`package.json file missing required field "name"`,
|
|
1140
|
+
{
|
|
1141
|
+
type: "packageJson",
|
|
1142
|
+
subtype: "missing_field_name",
|
|
1143
|
+
source: "@vercel/microfrontends/next"
|
|
1144
|
+
}
|
|
1145
|
+
);
|
|
1146
|
+
}
|
|
1147
|
+
return { name: packageJson.name };
|
|
1148
|
+
} catch (err) {
|
|
1149
|
+
throw MicrofrontendError.handle(err, {
|
|
1150
|
+
fileName: "package.json"
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1156
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
1121
1157
|
|
|
1122
1158
|
// src/config/microfrontends/server/constants.ts
|
|
1123
1159
|
var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
|
|
@@ -1125,7 +1161,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
|
|
|
1125
1161
|
|
|
1126
1162
|
// src/config/microfrontends/server/utils/get-output-file-path.ts
|
|
1127
1163
|
function getOutputFilePath() {
|
|
1128
|
-
return
|
|
1164
|
+
return import_node_path8.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
|
|
1129
1165
|
}
|
|
1130
1166
|
|
|
1131
1167
|
// src/config/microfrontends/server/validation.ts
|
|
@@ -1464,8 +1500,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1464
1500
|
pretty: true
|
|
1465
1501
|
}) {
|
|
1466
1502
|
const outputPath = getOutputFilePath();
|
|
1467
|
-
|
|
1468
|
-
|
|
1503
|
+
import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
|
|
1504
|
+
import_node_fs8.default.writeFileSync(
|
|
1469
1505
|
outputPath,
|
|
1470
1506
|
JSON.stringify(
|
|
1471
1507
|
this.config.toSchemaJson(),
|
|
@@ -1551,14 +1587,8 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1551
1587
|
}
|
|
1552
1588
|
try {
|
|
1553
1589
|
const packageRoot = findPackageRoot(directory);
|
|
1554
|
-
const
|
|
1555
|
-
const
|
|
1556
|
-
import_node_fs7.default.readFileSync(packageJsonPath, "utf-8")
|
|
1557
|
-
);
|
|
1558
|
-
if (!packageJson.name) {
|
|
1559
|
-
throw new Error(`No name found in package.json at ${packageJsonPath}`);
|
|
1560
|
-
}
|
|
1561
|
-
const configMeta = meta ?? { fromApp: packageJson.name };
|
|
1590
|
+
const { name: appName } = getApplicationContext({ packageRoot });
|
|
1591
|
+
const configMeta = meta ?? { fromApp: appName };
|
|
1562
1592
|
const maybeConfig = findConfig({ dir: packageRoot });
|
|
1563
1593
|
if (maybeConfig) {
|
|
1564
1594
|
return MicrofrontendsServer.fromFile({
|
|
@@ -1573,7 +1603,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1573
1603
|
if (isMonorepo2) {
|
|
1574
1604
|
const defaultPackage = findDefaultMicrofrontendsPackage({
|
|
1575
1605
|
repositoryRoot,
|
|
1576
|
-
applicationName:
|
|
1606
|
+
applicationName: appName
|
|
1577
1607
|
});
|
|
1578
1608
|
const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
|
|
1579
1609
|
if (maybeConfigFromDefault) {
|
|
@@ -1603,7 +1633,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1603
1633
|
options
|
|
1604
1634
|
}) {
|
|
1605
1635
|
try {
|
|
1606
|
-
const configJson =
|
|
1636
|
+
const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
1607
1637
|
const config = MicrofrontendsServer.validate(configJson);
|
|
1608
1638
|
if (!isMainConfig(config) && options?.resolveMainConfig) {
|
|
1609
1639
|
const repositoryRoot = findRepositoryRoot();
|
|
@@ -1651,7 +1681,7 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1651
1681
|
overrides
|
|
1652
1682
|
}) {
|
|
1653
1683
|
try {
|
|
1654
|
-
const config =
|
|
1684
|
+
const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
|
|
1655
1685
|
const validatedConfig = MicrofrontendsServer.validate(config);
|
|
1656
1686
|
if (!isMainConfig(validatedConfig)) {
|
|
1657
1687
|
throw new MicrofrontendError(
|
|
@@ -1700,8 +1730,8 @@ function mfePort(packageDir) {
|
|
|
1700
1730
|
};
|
|
1701
1731
|
}
|
|
1702
1732
|
function getPackageJson(packageDir) {
|
|
1703
|
-
const filePath =
|
|
1704
|
-
return JSON.parse(
|
|
1733
|
+
const filePath = import_node_path10.default.join(packageDir, "package.json");
|
|
1734
|
+
return JSON.parse(import_node_fs9.default.readFileSync(filePath, "utf-8"));
|
|
1705
1735
|
}
|
|
1706
1736
|
function loadConfig({
|
|
1707
1737
|
packageDir,
|