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