@vercel/microfrontends 0.17.2 → 0.17.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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -89
  3. package/dist/bin/cli.cjs +298 -200
  4. package/dist/config.cjs +19 -43
  5. package/dist/config.cjs.map +1 -1
  6. package/dist/config.d.ts +4 -4
  7. package/dist/config.js +19 -43
  8. package/dist/config.js.map +1 -1
  9. package/dist/{types-a29d224a.d.ts → index-5fcf0863.d.ts} +2 -2
  10. package/dist/{index-09caaa28.d.ts → index-f094deb1.d.ts} +3 -3
  11. package/dist/microfrontends/server.cjs +65 -73
  12. package/dist/microfrontends/server.cjs.map +1 -1
  13. package/dist/microfrontends/server.d.ts +4 -4
  14. package/dist/microfrontends/server.js +65 -73
  15. package/dist/microfrontends/server.js.map +1 -1
  16. package/dist/microfrontends.cjs +21 -46
  17. package/dist/microfrontends.cjs.map +1 -1
  18. package/dist/microfrontends.d.ts +4 -4
  19. package/dist/microfrontends.js +21 -46
  20. package/dist/microfrontends.js.map +1 -1
  21. package/dist/next/client.cjs +1 -1
  22. package/dist/next/client.cjs.map +1 -1
  23. package/dist/next/client.js +1 -1
  24. package/dist/next/client.js.map +1 -1
  25. package/dist/next/config.cjs +83 -99
  26. package/dist/next/config.cjs.map +1 -1
  27. package/dist/next/config.js +83 -99
  28. package/dist/next/config.js.map +1 -1
  29. package/dist/next/endpoints.cjs +1 -1
  30. package/dist/next/endpoints.cjs.map +1 -1
  31. package/dist/next/endpoints.d.ts +2 -2
  32. package/dist/next/endpoints.js +1 -1
  33. package/dist/next/endpoints.js.map +1 -1
  34. package/dist/next/middleware.cjs +29 -61
  35. package/dist/next/middleware.cjs.map +1 -1
  36. package/dist/next/middleware.js +29 -61
  37. package/dist/next/middleware.js.map +1 -1
  38. package/dist/next/testing.cjs +24 -52
  39. package/dist/next/testing.cjs.map +1 -1
  40. package/dist/next/testing.d.ts +4 -4
  41. package/dist/next/testing.js +24 -52
  42. package/dist/next/testing.js.map +1 -1
  43. package/dist/overrides.cjs +1 -2
  44. package/dist/overrides.cjs.map +1 -1
  45. package/dist/overrides.d.ts +3 -3
  46. package/dist/overrides.js +1 -2
  47. package/dist/overrides.js.map +1 -1
  48. package/dist/schema.cjs.map +1 -1
  49. package/dist/schema.d.ts +1 -1
  50. package/dist/{types-fc30696d.d.ts → types-5900be7c.d.ts} +1 -1
  51. package/dist/{types-cfe3308b.d.ts → types-ecd7b91b.d.ts} +1 -1
  52. package/dist/utils/mfe-port.cjs +65 -73
  53. package/dist/utils/mfe-port.cjs.map +1 -1
  54. package/dist/utils/mfe-port.js +65 -73
  55. package/dist/utils/mfe-port.js.map +1 -1
  56. package/dist/validation.cjs +46 -17
  57. package/dist/validation.cjs.map +1 -1
  58. package/dist/validation.d.ts +1 -1
  59. package/dist/validation.js +46 -17
  60. package/dist/validation.js.map +1 -1
  61. package/package.json +20 -24
  62. package/schema/schema.json +15 -8
@@ -46,8 +46,7 @@ var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
46
46
 
47
47
  // src/config/overrides/is-override-cookie.ts
48
48
  function isOverrideCookie(cookie) {
49
- var _a;
50
- return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
49
+ return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));
51
50
  }
52
51
 
53
52
  // src/config/overrides/get-override-from-cookie.ts
@@ -79,9 +78,9 @@ var MicrofrontendError = class extends Error {
79
78
  constructor(message, opts) {
80
79
  super(message);
81
80
  this.name = "MicrofrontendsError";
82
- this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
83
- this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
84
- this.subtype = opts == null ? void 0 : opts.subtype;
81
+ this.source = opts?.source ?? "@vercel/microfrontends";
82
+ this.type = opts?.type ?? "unknown";
83
+ this.subtype = opts?.subtype;
85
84
  Error.captureStackTrace(this, MicrofrontendError);
86
85
  }
87
86
  isKnown() {
@@ -96,7 +95,7 @@ var MicrofrontendError = class extends Error {
96
95
  * @returns The converted MicrofrontendsError.
97
96
  */
98
97
  static convert(original, opts) {
99
- if (opts == null ? void 0 : opts.fileName) {
98
+ if (opts?.fileName) {
100
99
  const err = MicrofrontendError.convertFSError(original, opts.fileName);
101
100
  if (err) {
102
101
  return err;
@@ -197,7 +196,7 @@ var MicrofrontendConfigClient = class {
197
196
  constructor(config, opts) {
198
197
  this.pathCache = {};
199
198
  this.serialized = config;
200
- if (opts == null ? void 0 : opts.removeFlaggedPaths) {
199
+ if (opts?.removeFlaggedPaths) {
201
200
  for (const app of Object.values(config.applications)) {
202
201
  if (app.routing) {
203
202
  app.routing = app.routing.filter((match) => !match.flag);
@@ -259,17 +258,6 @@ var MicrofrontendConfigClient = class {
259
258
 
260
259
  // src/config/microfrontends-config/isomorphic/validation.ts
261
260
  var import_path_to_regexp2 = require("path-to-regexp");
262
- var SUPPORTED_VERSIONS = ["2"];
263
- var validateConfigVersion = (version) => {
264
- if (!SUPPORTED_VERSIONS.includes(version)) {
265
- throw new MicrofrontendError(
266
- `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
267
- ", "
268
- )}`,
269
- { type: "config", subtype: "unsupported_version" }
270
- );
271
- }
272
- };
273
261
  var validateConfigPaths = (applicationConfigsById) => {
274
262
  if (!applicationConfigsById) {
275
263
  return;
@@ -445,7 +433,7 @@ var Host = class {
445
433
  this.protocol = protocol;
446
434
  this.host = host;
447
435
  this.port = Host.getPort({ port, protocol: this.protocol });
448
- this.local = options == null ? void 0 : options.isLocal;
436
+ this.local = options?.isLocal;
449
437
  }
450
438
  isLocal() {
451
439
  return this.local || this.host === "localhost" || this.host === "127.0.0.1";
@@ -494,18 +482,17 @@ var Application = class {
494
482
  overrides,
495
483
  isDefault
496
484
  }) {
497
- var _a, _b;
498
485
  this.name = name;
499
486
  this.development = {
500
487
  local: new LocalHost({
501
488
  appName: name,
502
- ...(_a = app.development) == null ? void 0 : _a.local
489
+ ...app.development?.local
503
490
  }),
504
- fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
491
+ fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
505
492
  };
506
493
  this.production = app.production ? new Host(app.production) : void 0;
507
494
  this.vercel = app.vercel;
508
- this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
495
+ this.overrides = overrides?.environment ? {
509
496
  environment: new Host(overrides.environment)
510
497
  } : void 0;
511
498
  this.default = isDefault ?? false;
@@ -569,14 +556,13 @@ var MicrofrontendConfigIsomorphic = class {
569
556
  opts
570
557
  }) {
571
558
  this.childApplications = {};
572
- var _a, _b, _c, _d;
573
559
  MicrofrontendConfigIsomorphic.validate(config, opts);
574
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
560
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
575
561
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
576
562
  this.isMainConfig = isMainConfig(config);
577
563
  if (isMainConfig(config)) {
578
564
  for (const [appId, appConfig] of Object.entries(config.applications)) {
579
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
565
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
580
566
  if (isDefaultApp(appConfig)) {
581
567
  this.defaultApplication = new DefaultApplication(appId, {
582
568
  app: appConfig,
@@ -591,7 +577,7 @@ var MicrofrontendConfigIsomorphic = class {
591
577
  }
592
578
  } else {
593
579
  this.partOf = config.partOf;
594
- const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
580
+ const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
595
581
  this.childApplications[meta.fromApp] = new ChildApplication(
596
582
  meta.fromApp,
597
583
  {
@@ -619,12 +605,9 @@ var MicrofrontendConfigIsomorphic = class {
619
605
  };
620
606
  }
621
607
  static validate(config, opts) {
622
- const skipValidation = (opts == null ? void 0 : opts.skipValidation) ?? [];
608
+ const skipValidation = opts?.skipValidation ?? [];
623
609
  const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
624
610
  if (isMainConfig(c)) {
625
- if (!skipValidation.includes("version")) {
626
- validateConfigVersion(c.version);
627
- }
628
611
  if (!skipValidation.includes("paths")) {
629
612
  validateConfigPaths(c.applications);
630
613
  }
@@ -645,8 +628,7 @@ var MicrofrontendConfigIsomorphic = class {
645
628
  });
646
629
  }
647
630
  isOverridesDisabled() {
648
- var _a, _b;
649
- return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
631
+ return this.options?.vercel?.disableOverrides ?? false;
650
632
  }
651
633
  getConfig() {
652
634
  return this.config;
@@ -667,8 +649,7 @@ var MicrofrontendConfigIsomorphic = class {
667
649
  ].filter(Boolean);
668
650
  }
669
651
  getApplication(name) {
670
- var _a;
671
- if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
652
+ if (this.defaultApplication?.name === name) {
672
653
  return this.defaultApplication;
673
654
  }
674
655
  const app = this.childApplications[name];
@@ -684,15 +665,11 @@ var MicrofrontendConfigIsomorphic = class {
684
665
  return app;
685
666
  }
686
667
  getApplicationByProjectId(projectId) {
687
- var _a, _b;
688
- if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
668
+ if (this.defaultApplication?.vercel?.projectId === projectId) {
689
669
  return this.defaultApplication;
690
670
  }
691
671
  return Object.values(this.childApplications).find(
692
- (app) => {
693
- var _a2;
694
- return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
695
- }
672
+ (app) => app.vercel?.projectId === projectId
696
673
  );
697
674
  }
698
675
  /**
@@ -715,8 +692,7 @@ var MicrofrontendConfigIsomorphic = class {
715
692
  * Returns the configured port for the local proxy
716
693
  */
717
694
  getLocalProxyPort() {
718
- var _a, _b;
719
- return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
695
+ return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
720
696
  }
721
697
  /**
722
698
  * Serializes the class back to the Schema type.
@@ -770,13 +746,12 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
770
746
  overrides,
771
747
  meta
772
748
  }) {
773
- var _a, _b, _c;
774
749
  super({ config, overrides, meta });
775
750
  this.isMainConfig = true;
776
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
751
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
777
752
  let defaultApplication;
778
753
  for (const [appId, appConfig] of Object.entries(config.applications)) {
779
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
754
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
780
755
  if (isDefaultApp(appConfig)) {
781
756
  defaultApplication = new DefaultApplication(appId, {
782
757
  app: appConfig,
@@ -969,7 +944,7 @@ function findDefaultMicrofrontendsPackage(opts) {
969
944
  const result = findDefaultMicrofrontendsPackages(opts);
970
945
  if (!result) {
971
946
  throw new Error(
972
- `Error trying to resolve the main microfrontends configuration`
947
+ "Error trying to resolve the main microfrontends configuration"
973
948
  );
974
949
  }
975
950
  configCache2[cacheKey] = result;
@@ -1041,20 +1016,8 @@ var import_node_path7 = __toESM(require("path"), 1);
1041
1016
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
1042
1017
  var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1043
1018
 
1044
- // src/utils/is-vercel.ts
1045
- function isVercel() {
1046
- return process.env.VERCEL === "1";
1047
- }
1048
-
1049
1019
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1050
1020
  function getOutputFilePath() {
1051
- if (isVercel()) {
1052
- return import_node_path7.default.join(
1053
- ".vercel",
1054
- MFE_CONFIG_DEFAULT_FILE_PATH,
1055
- MFE_CONFIG_DEFAULT_FILE_NAME
1056
- );
1057
- }
1058
1021
  return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1059
1022
  }
1060
1023
 
@@ -1085,7 +1048,7 @@ var schema_default = {
1085
1048
  },
1086
1049
  version: {
1087
1050
  type: "string",
1088
- const: "2"
1051
+ const: "1"
1089
1052
  },
1090
1053
  options: {
1091
1054
  $ref: "#/definitions/Options"
@@ -1095,6 +1058,9 @@ var schema_default = {
1095
1058
  additionalProperties: {
1096
1059
  $ref: "#/definitions/Application"
1097
1060
  },
1061
+ propertyNames: {
1062
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1063
+ },
1098
1064
  description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
1099
1065
  },
1100
1066
  applications: {
@@ -1102,7 +1068,9 @@ var schema_default = {
1102
1068
  description: "Mapping of application names to the routes that they host. Only needs to be defined in the application that owns the primary microfrontend domain"
1103
1069
  }
1104
1070
  },
1105
- required: ["applications", "version"],
1071
+ required: [
1072
+ "applications"
1073
+ ],
1106
1074
  additionalProperties: false
1107
1075
  },
1108
1076
  Options: {
@@ -1166,7 +1134,9 @@ var schema_default = {
1166
1134
  $ref: "#/definitions/HostConfig"
1167
1135
  }
1168
1136
  },
1169
- required: ["production"],
1137
+ required: [
1138
+ "production"
1139
+ ],
1170
1140
  additionalProperties: false
1171
1141
  },
1172
1142
  Vercel: {
@@ -1177,7 +1147,9 @@ var schema_default = {
1177
1147
  description: "Vercel project ID"
1178
1148
  }
1179
1149
  },
1180
- required: ["projectId"],
1150
+ required: [
1151
+ "projectId"
1152
+ ],
1181
1153
  additionalProperties: false
1182
1154
  },
1183
1155
  Development: {
@@ -1207,8 +1179,11 @@ var schema_default = {
1207
1179
  },
1208
1180
  protocol: {
1209
1181
  type: "string",
1210
- enum: ["http", "https"],
1211
- description: 'The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n* @defaultValue "http" for local development, "https" for otherwise'
1182
+ enum: [
1183
+ "http",
1184
+ "https"
1185
+ ],
1186
+ description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1212
1187
  },
1213
1188
  port: {
1214
1189
  type: "number",
@@ -1221,8 +1196,11 @@ var schema_default = {
1221
1196
  properties: {
1222
1197
  protocol: {
1223
1198
  type: "string",
1224
- enum: ["http", "https"],
1225
- description: 'The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n* @defaultValue "http" for local development, "https" for otherwise'
1199
+ enum: [
1200
+ "http",
1201
+ "https"
1202
+ ],
1203
+ description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1226
1204
  },
1227
1205
  host: {
1228
1206
  type: "string",
@@ -1233,7 +1211,9 @@ var schema_default = {
1233
1211
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1234
1212
  }
1235
1213
  },
1236
- required: ["host"],
1214
+ required: [
1215
+ "host"
1216
+ ],
1237
1217
  additionalProperties: false
1238
1218
  },
1239
1219
  ChildApplication: {
@@ -1253,7 +1233,9 @@ var schema_default = {
1253
1233
  $ref: "#/definitions/HostConfig"
1254
1234
  }
1255
1235
  },
1256
- required: ["routing"],
1236
+ required: [
1237
+ "routing"
1238
+ ],
1257
1239
  additionalProperties: false
1258
1240
  },
1259
1241
  Routing: {
@@ -1280,13 +1262,18 @@ var schema_default = {
1280
1262
  }
1281
1263
  }
1282
1264
  },
1283
- required: ["paths"],
1265
+ required: [
1266
+ "paths"
1267
+ ],
1284
1268
  additionalProperties: false
1285
1269
  },
1286
1270
  ApplicationRouting: {
1287
1271
  type: "object",
1288
1272
  additionalProperties: {
1289
1273
  $ref: "#/definitions/Application"
1274
+ },
1275
+ propertyNames: {
1276
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1290
1277
  }
1291
1278
  },
1292
1279
  ChildConfig: {
@@ -1297,7 +1284,7 @@ var schema_default = {
1297
1284
  },
1298
1285
  version: {
1299
1286
  type: "string",
1300
- const: "2"
1287
+ const: "1"
1301
1288
  },
1302
1289
  options: {
1303
1290
  $ref: "#/definitions/Options"
@@ -1307,6 +1294,9 @@ var schema_default = {
1307
1294
  additionalProperties: {
1308
1295
  $ref: "#/definitions/Application"
1309
1296
  },
1297
+ propertyNames: {
1298
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1299
+ },
1310
1300
  description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
1311
1301
  },
1312
1302
  partOf: {
@@ -1314,7 +1304,9 @@ var schema_default = {
1314
1304
  description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
1315
1305
  }
1316
1306
  },
1317
- required: ["partOf", "version"],
1307
+ required: [
1308
+ "partOf"
1309
+ ],
1318
1310
  additionalProperties: false
1319
1311
  }
1320
1312
  }
@@ -1488,7 +1480,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1488
1480
  try {
1489
1481
  const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
1490
1482
  const config = MicrofrontendsServer.validate(configJson);
1491
- if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
1483
+ if (!isMainConfig(config) && options?.resolveMainConfig) {
1492
1484
  const repositoryRoot = findRepositoryRoot();
1493
1485
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1494
1486
  if (isMonorepo2) {