@vercel/microfrontends 1.1.1-canary.2 → 1.1.1-canary.3
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 +79 -20
- package/dist/config.cjs +16 -9
- package/dist/config.cjs.map +1 -1
- package/dist/config.js +16 -9
- package/dist/config.js.map +1 -1
- package/dist/experimental/sveltekit.cjs +77 -18
- package/dist/experimental/sveltekit.cjs.map +1 -1
- package/dist/experimental/sveltekit.js +77 -18
- package/dist/experimental/sveltekit.js.map +1 -1
- package/dist/experimental/vite.cjs +77 -18
- package/dist/experimental/vite.cjs.map +1 -1
- package/dist/experimental/vite.js +77 -18
- package/dist/experimental/vite.js.map +1 -1
- package/dist/microfrontends/server.cjs +77 -18
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.js +77 -18
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends.cjs +16 -9
- package/dist/microfrontends.cjs.map +1 -1
- package/dist/microfrontends.js +16 -9
- package/dist/microfrontends.js.map +1 -1
- package/dist/next/config.cjs +77 -18
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +77 -18
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.cjs +2 -0
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.d.ts +11 -1
- package/dist/next/endpoints.js +1 -0
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +16 -9
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +16 -9
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +16 -9
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.js +16 -9
- package/dist/next/testing.js.map +1 -1
- package/dist/utils/mfe-port.cjs +77 -18
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +77 -18
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +49 -6
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.js +49 -6
- package/dist/validation.js.map +1 -1
- package/package.json +2 -2
|
@@ -254,6 +254,10 @@ var MicrofrontendConfigClient = class {
|
|
|
254
254
|
|
|
255
255
|
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
256
256
|
var import_path_to_regexp2 = require("path-to-regexp");
|
|
257
|
+
var LIST_FORMATTER = new Intl.ListFormat("en", {
|
|
258
|
+
style: "long",
|
|
259
|
+
type: "conjunction"
|
|
260
|
+
});
|
|
257
261
|
var validateConfigPaths = (applicationConfigsById) => {
|
|
258
262
|
if (!applicationConfigsById) {
|
|
259
263
|
return;
|
|
@@ -386,15 +390,15 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
386
390
|
if (!applicationConfigsById) {
|
|
387
391
|
return;
|
|
388
392
|
}
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
);
|
|
392
|
-
const
|
|
393
|
-
(
|
|
393
|
+
const applicationsWithoutRouting = Object.entries(
|
|
394
|
+
applicationConfigsById
|
|
395
|
+
).filter(([, app]) => isDefaultApp(app));
|
|
396
|
+
const numApplicationsWithoutRouting = applicationsWithoutRouting.reduce(
|
|
397
|
+
(acc) => {
|
|
398
|
+
return acc + 1;
|
|
399
|
+
},
|
|
400
|
+
0
|
|
394
401
|
);
|
|
395
|
-
const numApplications = Object.keys(applicationConfigsById).length;
|
|
396
|
-
const numApplicationsWithRouting = applicationsWithRoutingNames.length;
|
|
397
|
-
const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
|
|
398
402
|
if (numApplicationsWithoutRouting === 0) {
|
|
399
403
|
throw new MicrofrontendError(
|
|
400
404
|
"No default application found. At least one application needs to be the default by omitting routing.",
|
|
@@ -402,8 +406,11 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
|
|
|
402
406
|
);
|
|
403
407
|
}
|
|
404
408
|
if (numApplicationsWithoutRouting > 1) {
|
|
409
|
+
const applicationNamesMissingRouting = applicationsWithoutRouting.map(
|
|
410
|
+
([name]) => name
|
|
411
|
+
);
|
|
405
412
|
throw new MicrofrontendError(
|
|
406
|
-
`
|
|
413
|
+
`All applications except for the default app must contain the "routing" field. Applications that are missing routing: ${LIST_FORMATTER.format(applicationNamesMissingRouting)}.`,
|
|
407
414
|
{ type: "config", subtype: "multiple_default_applications" }
|
|
408
415
|
);
|
|
409
416
|
}
|
|
@@ -972,14 +979,20 @@ var Microfrontends = class {
|
|
|
972
979
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
973
980
|
var import_node_path = __toESM(require("path"), 1);
|
|
974
981
|
var GIT_DIRECTORY = ".git";
|
|
982
|
+
function hasGitDirectory(dir) {
|
|
983
|
+
const gitPath = import_node_path.default.join(dir, GIT_DIRECTORY);
|
|
984
|
+
return import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory();
|
|
985
|
+
}
|
|
986
|
+
function hasPnpmWorkspaces(dir) {
|
|
987
|
+
return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
|
|
988
|
+
}
|
|
975
989
|
function findRepositoryRoot(startDir) {
|
|
976
990
|
if (process.env.NX_WORKSPACE_ROOT) {
|
|
977
991
|
return process.env.NX_WORKSPACE_ROOT;
|
|
978
992
|
}
|
|
979
993
|
let currentDir = startDir || process.cwd();
|
|
980
994
|
while (currentDir !== import_node_path.default.parse(currentDir).root) {
|
|
981
|
-
|
|
982
|
-
if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
|
|
995
|
+
if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
|
|
983
996
|
return currentDir;
|
|
984
997
|
}
|
|
985
998
|
currentDir = import_node_path.default.dirname(currentDir);
|
|
@@ -1090,7 +1103,7 @@ function findDefaultMicrofrontendsPackages({
|
|
|
1090
1103
|
}
|
|
1091
1104
|
if (matchingPaths.length > 1) {
|
|
1092
1105
|
throw new Error(
|
|
1093
|
-
`Found multiple default applications referencing "${applicationName}" in the repository,
|
|
1106
|
+
`Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
|
|
1094
1107
|
${matchingPaths.join("\n \u2022 ")}`
|
|
1095
1108
|
);
|
|
1096
1109
|
}
|
|
@@ -1532,13 +1545,54 @@ var schema_default = {
|
|
|
1532
1545
|
var SCHEMA = schema_default;
|
|
1533
1546
|
|
|
1534
1547
|
// src/config/microfrontends/server/validation.ts
|
|
1535
|
-
|
|
1548
|
+
var LIST_FORMATTER2 = new Intl.ListFormat("en", {
|
|
1549
|
+
style: "long",
|
|
1550
|
+
type: "disjunction"
|
|
1551
|
+
});
|
|
1552
|
+
function formatAjvErrors(errors) {
|
|
1536
1553
|
if (!errors) {
|
|
1537
1554
|
return [];
|
|
1538
1555
|
}
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1556
|
+
const errorMessages = [];
|
|
1557
|
+
for (const error of errors) {
|
|
1558
|
+
if (error.instancePath === "" && (error.keyword === "anyOf" || error.keyword === "required" && error.params.missingProperty === "partOf")) {
|
|
1559
|
+
continue;
|
|
1560
|
+
}
|
|
1561
|
+
const instancePath = error.instancePath.slice(1);
|
|
1562
|
+
const formattedInstancePath = instancePath === "" ? "at the root" : `in field ${instancePath}`;
|
|
1563
|
+
if (error.keyword === "required" && error.params.missingProperty === "routing" && instancePath.split("/").length === 2) {
|
|
1564
|
+
errorMessages.push(
|
|
1565
|
+
`Unable to infer if ${instancePath} is the default app or a child app. This usually means that there is another error in the configuration.`
|
|
1566
|
+
);
|
|
1567
|
+
} else if (error.keyword === "anyOf" && instancePath.split("/").length > 2) {
|
|
1568
|
+
const anyOfErrors = errors.filter(
|
|
1569
|
+
(e) => e.instancePath === error.instancePath && e.keyword !== "anyOf"
|
|
1570
|
+
);
|
|
1571
|
+
if (anyOfErrors.every((e) => e.keyword === "type")) {
|
|
1572
|
+
const allowedTypes = LIST_FORMATTER2.format(
|
|
1573
|
+
anyOfErrors.map((e) => {
|
|
1574
|
+
return e.keyword === "type" ? String(e.params.type) : "unknown";
|
|
1575
|
+
})
|
|
1576
|
+
);
|
|
1577
|
+
errorMessages.push(
|
|
1578
|
+
`Incorrect type for ${instancePath}. Must be one of ${allowedTypes}`
|
|
1579
|
+
);
|
|
1580
|
+
} else {
|
|
1581
|
+
errorMessages.push(
|
|
1582
|
+
`Invalid field for ${instancePath}. Possible error messages are ${LIST_FORMATTER2.format(anyOfErrors.map((e) => e.message ?? ""))}`
|
|
1583
|
+
);
|
|
1584
|
+
}
|
|
1585
|
+
} else if (error.keyword === "additionalProperties" && !(error.params.additionalProperty === "routing" && instancePath.split("/").length === 2)) {
|
|
1586
|
+
errorMessages.push(
|
|
1587
|
+
`Property '${error.params.additionalProperty}' is not allowed ${formattedInstancePath}`
|
|
1588
|
+
);
|
|
1589
|
+
} else if (error.keyword === "required") {
|
|
1590
|
+
errorMessages.push(
|
|
1591
|
+
`Property '${error.params.missingProperty}' is required ${formattedInstancePath}`
|
|
1592
|
+
);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
return errorMessages;
|
|
1542
1596
|
}
|
|
1543
1597
|
function validateSchema(configString) {
|
|
1544
1598
|
const parsedConfig = (0, import_jsonc_parser3.parse)(configString);
|
|
@@ -1547,8 +1601,10 @@ function validateSchema(configString) {
|
|
|
1547
1601
|
const isValid = validate(parsedConfig);
|
|
1548
1602
|
if (!isValid) {
|
|
1549
1603
|
throw new MicrofrontendError(
|
|
1550
|
-
`Invalid microfrontends config
|
|
1551
|
-
- ${
|
|
1604
|
+
`Invalid microfrontends config:${formatAjvErrors(validate.errors).map((error) => `
|
|
1605
|
+
- ${error}`).join(
|
|
1606
|
+
""
|
|
1607
|
+
)}
|
|
1552
1608
|
|
|
1553
1609
|
See https://openapi.vercel.sh/microfrontends.json for the schema.`,
|
|
1554
1610
|
{ type: "config", subtype: "does_not_match_schema" }
|
|
@@ -1683,6 +1739,9 @@ var MicrofrontendsServer = class extends Microfrontends {
|
|
|
1683
1739
|
}
|
|
1684
1740
|
throw new Error("Unable to infer");
|
|
1685
1741
|
} catch (e) {
|
|
1742
|
+
if (e instanceof MicrofrontendError) {
|
|
1743
|
+
throw e;
|
|
1744
|
+
}
|
|
1686
1745
|
throw new MicrofrontendError(
|
|
1687
1746
|
"Unable to locate and parse microfrontends configuration",
|
|
1688
1747
|
{ cause: e, type: "config", subtype: "inference_failed" }
|