@vercel/microfrontends 0.17.1 → 0.17.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 (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -89
  3. package/dist/bin/cli.cjs +299 -200
  4. package/dist/config.cjs +22 -45
  5. package/dist/config.cjs.map +1 -1
  6. package/dist/config.d.ts +4 -4
  7. package/dist/config.js +22 -45
  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-4399aa8e.d.ts → index-f094deb1.d.ts} +5 -4
  11. package/dist/microfrontends/server.cjs +68 -75
  12. package/dist/microfrontends/server.cjs.map +1 -1
  13. package/dist/microfrontends/server.d.ts +4 -4
  14. package/dist/microfrontends/server.js +68 -75
  15. package/dist/microfrontends/server.js.map +1 -1
  16. package/dist/microfrontends.cjs +24 -48
  17. package/dist/microfrontends.cjs.map +1 -1
  18. package/dist/microfrontends.d.ts +4 -4
  19. package/dist/microfrontends.js +24 -48
  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 +86 -101
  26. package/dist/next/config.cjs.map +1 -1
  27. package/dist/next/config.js +86 -101
  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 +32 -63
  35. package/dist/next/middleware.cjs.map +1 -1
  36. package/dist/next/middleware.js +32 -63
  37. package/dist/next/middleware.js.map +1 -1
  38. package/dist/next/testing.cjs +27 -54
  39. package/dist/next/testing.cjs.map +1 -1
  40. package/dist/next/testing.d.ts +4 -4
  41. package/dist/next/testing.js +27 -54
  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 +68 -75
  53. package/dist/utils/mfe-port.cjs.map +1 -1
  54. package/dist/utils/mfe-port.js +68 -75
  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 +18 -22
  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;
@@ -565,17 +552,17 @@ var MicrofrontendConfigIsomorphic = class {
565
552
  constructor({
566
553
  config,
567
554
  overrides,
568
- meta
555
+ meta,
556
+ opts
569
557
  }) {
570
558
  this.childApplications = {};
571
- var _a, _b, _c, _d;
572
- MicrofrontendConfigIsomorphic.validate(config);
573
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
559
+ MicrofrontendConfigIsomorphic.validate(config, opts);
560
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
574
561
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
575
562
  this.isMainConfig = isMainConfig(config);
576
563
  if (isMainConfig(config)) {
577
564
  for (const [appId, appConfig] of Object.entries(config.applications)) {
578
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
565
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
579
566
  if (isDefaultApp(appConfig)) {
580
567
  this.defaultApplication = new DefaultApplication(appId, {
581
568
  app: appConfig,
@@ -590,7 +577,7 @@ var MicrofrontendConfigIsomorphic = class {
590
577
  }
591
578
  } else {
592
579
  this.partOf = config.partOf;
593
- 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;
594
581
  this.childApplications[meta.fromApp] = new ChildApplication(
595
582
  meta.fromApp,
596
583
  {
@@ -618,12 +605,9 @@ var MicrofrontendConfigIsomorphic = class {
618
605
  };
619
606
  }
620
607
  static validate(config, opts) {
621
- const skipValidation = (opts == null ? void 0 : opts.skipValidation) ?? [];
608
+ const skipValidation = opts?.skipValidation ?? [];
622
609
  const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
623
610
  if (isMainConfig(c)) {
624
- if (!skipValidation.includes("version")) {
625
- validateConfigVersion(c.version);
626
- }
627
611
  if (!skipValidation.includes("paths")) {
628
612
  validateConfigPaths(c.applications);
629
613
  }
@@ -644,8 +628,7 @@ var MicrofrontendConfigIsomorphic = class {
644
628
  });
645
629
  }
646
630
  isOverridesDisabled() {
647
- var _a, _b;
648
- return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
631
+ return this.options?.vercel?.disableOverrides ?? false;
649
632
  }
650
633
  getConfig() {
651
634
  return this.config;
@@ -666,8 +649,7 @@ var MicrofrontendConfigIsomorphic = class {
666
649
  ].filter(Boolean);
667
650
  }
668
651
  getApplication(name) {
669
- var _a;
670
- if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
652
+ if (this.defaultApplication?.name === name) {
671
653
  return this.defaultApplication;
672
654
  }
673
655
  const app = this.childApplications[name];
@@ -683,15 +665,11 @@ var MicrofrontendConfigIsomorphic = class {
683
665
  return app;
684
666
  }
685
667
  getApplicationByProjectId(projectId) {
686
- var _a, _b;
687
- if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
668
+ if (this.defaultApplication?.vercel?.projectId === projectId) {
688
669
  return this.defaultApplication;
689
670
  }
690
671
  return Object.values(this.childApplications).find(
691
- (app) => {
692
- var _a2;
693
- return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
694
- }
672
+ (app) => app.vercel?.projectId === projectId
695
673
  );
696
674
  }
697
675
  /**
@@ -714,8 +692,7 @@ var MicrofrontendConfigIsomorphic = class {
714
692
  * Returns the configured port for the local proxy
715
693
  */
716
694
  getLocalProxyPort() {
717
- var _a, _b;
718
- 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;
719
696
  }
720
697
  /**
721
698
  * Serializes the class back to the Schema type.
@@ -769,13 +746,12 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
769
746
  overrides,
770
747
  meta
771
748
  }) {
772
- var _a, _b, _c;
773
749
  super({ config, overrides, meta });
774
750
  this.isMainConfig = true;
775
- 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;
776
752
  let defaultApplication;
777
753
  for (const [appId, appConfig] of Object.entries(config.applications)) {
778
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
754
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
779
755
  if (isDefaultApp(appConfig)) {
780
756
  defaultApplication = new DefaultApplication(appId, {
781
757
  app: appConfig,
@@ -968,7 +944,7 @@ function findDefaultMicrofrontendsPackage(opts) {
968
944
  const result = findDefaultMicrofrontendsPackages(opts);
969
945
  if (!result) {
970
946
  throw new Error(
971
- `Error trying to resolve the main microfrontends configuration`
947
+ "Error trying to resolve the main microfrontends configuration"
972
948
  );
973
949
  }
974
950
  configCache2[cacheKey] = result;
@@ -1040,20 +1016,8 @@ var import_node_path7 = __toESM(require("path"), 1);
1040
1016
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
1041
1017
  var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1042
1018
 
1043
- // src/utils/is-vercel.ts
1044
- function isVercel() {
1045
- return process.env.VERCEL === "1";
1046
- }
1047
-
1048
1019
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1049
1020
  function getOutputFilePath() {
1050
- if (isVercel()) {
1051
- return import_node_path7.default.join(
1052
- ".vercel",
1053
- MFE_CONFIG_DEFAULT_FILE_PATH,
1054
- MFE_CONFIG_DEFAULT_FILE_NAME
1055
- );
1056
- }
1057
1021
  return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1058
1022
  }
1059
1023
 
@@ -1084,7 +1048,7 @@ var schema_default = {
1084
1048
  },
1085
1049
  version: {
1086
1050
  type: "string",
1087
- const: "2"
1051
+ const: "1"
1088
1052
  },
1089
1053
  options: {
1090
1054
  $ref: "#/definitions/Options"
@@ -1094,6 +1058,9 @@ var schema_default = {
1094
1058
  additionalProperties: {
1095
1059
  $ref: "#/definitions/Application"
1096
1060
  },
1061
+ propertyNames: {
1062
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1063
+ },
1097
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."
1098
1065
  },
1099
1066
  applications: {
@@ -1101,7 +1068,9 @@ var schema_default = {
1101
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"
1102
1069
  }
1103
1070
  },
1104
- required: ["applications", "version"],
1071
+ required: [
1072
+ "applications"
1073
+ ],
1105
1074
  additionalProperties: false
1106
1075
  },
1107
1076
  Options: {
@@ -1165,7 +1134,9 @@ var schema_default = {
1165
1134
  $ref: "#/definitions/HostConfig"
1166
1135
  }
1167
1136
  },
1168
- required: ["production"],
1137
+ required: [
1138
+ "production"
1139
+ ],
1169
1140
  additionalProperties: false
1170
1141
  },
1171
1142
  Vercel: {
@@ -1176,7 +1147,9 @@ var schema_default = {
1176
1147
  description: "Vercel project ID"
1177
1148
  }
1178
1149
  },
1179
- required: ["projectId"],
1150
+ required: [
1151
+ "projectId"
1152
+ ],
1180
1153
  additionalProperties: false
1181
1154
  },
1182
1155
  Development: {
@@ -1206,8 +1179,11 @@ var schema_default = {
1206
1179
  },
1207
1180
  protocol: {
1208
1181
  type: "string",
1209
- enum: ["http", "https"],
1210
- 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*"
1211
1187
  },
1212
1188
  port: {
1213
1189
  type: "number",
@@ -1220,8 +1196,11 @@ var schema_default = {
1220
1196
  properties: {
1221
1197
  protocol: {
1222
1198
  type: "string",
1223
- enum: ["http", "https"],
1224
- 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*"
1225
1204
  },
1226
1205
  host: {
1227
1206
  type: "string",
@@ -1232,7 +1211,9 @@ var schema_default = {
1232
1211
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1233
1212
  }
1234
1213
  },
1235
- required: ["host"],
1214
+ required: [
1215
+ "host"
1216
+ ],
1236
1217
  additionalProperties: false
1237
1218
  },
1238
1219
  ChildApplication: {
@@ -1252,7 +1233,9 @@ var schema_default = {
1252
1233
  $ref: "#/definitions/HostConfig"
1253
1234
  }
1254
1235
  },
1255
- required: ["routing"],
1236
+ required: [
1237
+ "routing"
1238
+ ],
1256
1239
  additionalProperties: false
1257
1240
  },
1258
1241
  Routing: {
@@ -1279,13 +1262,18 @@ var schema_default = {
1279
1262
  }
1280
1263
  }
1281
1264
  },
1282
- required: ["paths"],
1265
+ required: [
1266
+ "paths"
1267
+ ],
1283
1268
  additionalProperties: false
1284
1269
  },
1285
1270
  ApplicationRouting: {
1286
1271
  type: "object",
1287
1272
  additionalProperties: {
1288
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`."
1289
1277
  }
1290
1278
  },
1291
1279
  ChildConfig: {
@@ -1296,7 +1284,7 @@ var schema_default = {
1296
1284
  },
1297
1285
  version: {
1298
1286
  type: "string",
1299
- const: "2"
1287
+ const: "1"
1300
1288
  },
1301
1289
  options: {
1302
1290
  $ref: "#/definitions/Options"
@@ -1306,6 +1294,9 @@ var schema_default = {
1306
1294
  additionalProperties: {
1307
1295
  $ref: "#/definitions/Application"
1308
1296
  },
1297
+ propertyNames: {
1298
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1299
+ },
1309
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."
1310
1301
  },
1311
1302
  partOf: {
@@ -1313,7 +1304,9 @@ var schema_default = {
1313
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."
1314
1305
  }
1315
1306
  },
1316
- required: ["partOf", "version"],
1307
+ required: [
1308
+ "partOf"
1309
+ ],
1317
1310
  additionalProperties: false
1318
1311
  }
1319
1312
  }
@@ -1487,7 +1480,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1487
1480
  try {
1488
1481
  const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
1489
1482
  const config = MicrofrontendsServer.validate(configJson);
1490
- if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
1483
+ if (!isMainConfig(config) && options?.resolveMainConfig) {
1491
1484
  const repositoryRoot = findRepositoryRoot();
1492
1485
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1493
1486
  if (isMonorepo2) {