@vercel/microfrontends 0.17.2 → 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 +296 -198
  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 +18 -22
  62. package/schema/schema.json +15 -8
@@ -12,8 +12,7 @@ var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
12
12
 
13
13
  // src/config/overrides/is-override-cookie.ts
14
14
  function isOverrideCookie(cookie) {
15
- var _a;
16
- return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
15
+ return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));
17
16
  }
18
17
 
19
18
  // src/config/overrides/get-override-from-cookie.ts
@@ -45,9 +44,9 @@ var MicrofrontendError = class extends Error {
45
44
  constructor(message, opts) {
46
45
  super(message);
47
46
  this.name = "MicrofrontendsError";
48
- this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
49
- this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
50
- this.subtype = opts == null ? void 0 : opts.subtype;
47
+ this.source = opts?.source ?? "@vercel/microfrontends";
48
+ this.type = opts?.type ?? "unknown";
49
+ this.subtype = opts?.subtype;
51
50
  Error.captureStackTrace(this, MicrofrontendError);
52
51
  }
53
52
  isKnown() {
@@ -62,7 +61,7 @@ var MicrofrontendError = class extends Error {
62
61
  * @returns The converted MicrofrontendsError.
63
62
  */
64
63
  static convert(original, opts) {
65
- if (opts == null ? void 0 : opts.fileName) {
64
+ if (opts?.fileName) {
66
65
  const err = MicrofrontendError.convertFSError(original, opts.fileName);
67
66
  if (err) {
68
67
  return err;
@@ -163,7 +162,7 @@ var MicrofrontendConfigClient = class {
163
162
  constructor(config, opts) {
164
163
  this.pathCache = {};
165
164
  this.serialized = config;
166
- if (opts == null ? void 0 : opts.removeFlaggedPaths) {
165
+ if (opts?.removeFlaggedPaths) {
167
166
  for (const app of Object.values(config.applications)) {
168
167
  if (app.routing) {
169
168
  app.routing = app.routing.filter((match) => !match.flag);
@@ -225,17 +224,6 @@ var MicrofrontendConfigClient = class {
225
224
 
226
225
  // src/config/microfrontends-config/isomorphic/validation.ts
227
226
  import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to-regexp";
228
- var SUPPORTED_VERSIONS = ["2"];
229
- var validateConfigVersion = (version) => {
230
- if (!SUPPORTED_VERSIONS.includes(version)) {
231
- throw new MicrofrontendError(
232
- `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
233
- ", "
234
- )}`,
235
- { type: "config", subtype: "unsupported_version" }
236
- );
237
- }
238
- };
239
227
  var validateConfigPaths = (applicationConfigsById) => {
240
228
  if (!applicationConfigsById) {
241
229
  return;
@@ -411,7 +399,7 @@ var Host = class {
411
399
  this.protocol = protocol;
412
400
  this.host = host;
413
401
  this.port = Host.getPort({ port, protocol: this.protocol });
414
- this.local = options == null ? void 0 : options.isLocal;
402
+ this.local = options?.isLocal;
415
403
  }
416
404
  isLocal() {
417
405
  return this.local || this.host === "localhost" || this.host === "127.0.0.1";
@@ -460,18 +448,17 @@ var Application = class {
460
448
  overrides,
461
449
  isDefault
462
450
  }) {
463
- var _a, _b;
464
451
  this.name = name;
465
452
  this.development = {
466
453
  local: new LocalHost({
467
454
  appName: name,
468
- ...(_a = app.development) == null ? void 0 : _a.local
455
+ ...app.development?.local
469
456
  }),
470
- fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
457
+ fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
471
458
  };
472
459
  this.production = app.production ? new Host(app.production) : void 0;
473
460
  this.vercel = app.vercel;
474
- this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
461
+ this.overrides = overrides?.environment ? {
475
462
  environment: new Host(overrides.environment)
476
463
  } : void 0;
477
464
  this.default = isDefault ?? false;
@@ -535,14 +522,13 @@ var MicrofrontendConfigIsomorphic = class {
535
522
  opts
536
523
  }) {
537
524
  this.childApplications = {};
538
- var _a, _b, _c, _d;
539
525
  MicrofrontendConfigIsomorphic.validate(config, opts);
540
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
526
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
541
527
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
542
528
  this.isMainConfig = isMainConfig(config);
543
529
  if (isMainConfig(config)) {
544
530
  for (const [appId, appConfig] of Object.entries(config.applications)) {
545
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
531
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
546
532
  if (isDefaultApp(appConfig)) {
547
533
  this.defaultApplication = new DefaultApplication(appId, {
548
534
  app: appConfig,
@@ -557,7 +543,7 @@ var MicrofrontendConfigIsomorphic = class {
557
543
  }
558
544
  } else {
559
545
  this.partOf = config.partOf;
560
- const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
546
+ const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
561
547
  this.childApplications[meta.fromApp] = new ChildApplication(
562
548
  meta.fromApp,
563
549
  {
@@ -585,12 +571,9 @@ var MicrofrontendConfigIsomorphic = class {
585
571
  };
586
572
  }
587
573
  static validate(config, opts) {
588
- const skipValidation = (opts == null ? void 0 : opts.skipValidation) ?? [];
574
+ const skipValidation = opts?.skipValidation ?? [];
589
575
  const c = typeof config === "string" ? parse(config) : config;
590
576
  if (isMainConfig(c)) {
591
- if (!skipValidation.includes("version")) {
592
- validateConfigVersion(c.version);
593
- }
594
577
  if (!skipValidation.includes("paths")) {
595
578
  validateConfigPaths(c.applications);
596
579
  }
@@ -611,8 +594,7 @@ var MicrofrontendConfigIsomorphic = class {
611
594
  });
612
595
  }
613
596
  isOverridesDisabled() {
614
- var _a, _b;
615
- return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
597
+ return this.options?.vercel?.disableOverrides ?? false;
616
598
  }
617
599
  getConfig() {
618
600
  return this.config;
@@ -633,8 +615,7 @@ var MicrofrontendConfigIsomorphic = class {
633
615
  ].filter(Boolean);
634
616
  }
635
617
  getApplication(name) {
636
- var _a;
637
- if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
618
+ if (this.defaultApplication?.name === name) {
638
619
  return this.defaultApplication;
639
620
  }
640
621
  const app = this.childApplications[name];
@@ -650,15 +631,11 @@ var MicrofrontendConfigIsomorphic = class {
650
631
  return app;
651
632
  }
652
633
  getApplicationByProjectId(projectId) {
653
- var _a, _b;
654
- if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
634
+ if (this.defaultApplication?.vercel?.projectId === projectId) {
655
635
  return this.defaultApplication;
656
636
  }
657
637
  return Object.values(this.childApplications).find(
658
- (app) => {
659
- var _a2;
660
- return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
661
- }
638
+ (app) => app.vercel?.projectId === projectId
662
639
  );
663
640
  }
664
641
  /**
@@ -681,8 +658,7 @@ var MicrofrontendConfigIsomorphic = class {
681
658
  * Returns the configured port for the local proxy
682
659
  */
683
660
  getLocalProxyPort() {
684
- var _a, _b;
685
- return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
661
+ return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
686
662
  }
687
663
  /**
688
664
  * Serializes the class back to the Schema type.
@@ -736,13 +712,12 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
736
712
  overrides,
737
713
  meta
738
714
  }) {
739
- var _a, _b, _c;
740
715
  super({ config, overrides, meta });
741
716
  this.isMainConfig = true;
742
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
717
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
743
718
  let defaultApplication;
744
719
  for (const [appId, appConfig] of Object.entries(config.applications)) {
745
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
720
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
746
721
  if (isDefaultApp(appConfig)) {
747
722
  defaultApplication = new DefaultApplication(appId, {
748
723
  app: appConfig,
@@ -935,7 +910,7 @@ function findDefaultMicrofrontendsPackage(opts) {
935
910
  const result = findDefaultMicrofrontendsPackages(opts);
936
911
  if (!result) {
937
912
  throw new Error(
938
- `Error trying to resolve the main microfrontends configuration`
913
+ "Error trying to resolve the main microfrontends configuration"
939
914
  );
940
915
  }
941
916
  configCache2[cacheKey] = result;
@@ -1007,20 +982,8 @@ import path4 from "node:path";
1007
982
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
1008
983
  var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1009
984
 
1010
- // src/utils/is-vercel.ts
1011
- function isVercel() {
1012
- return process.env.VERCEL === "1";
1013
- }
1014
-
1015
985
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1016
986
  function getOutputFilePath() {
1017
- if (isVercel()) {
1018
- return path4.join(
1019
- ".vercel",
1020
- MFE_CONFIG_DEFAULT_FILE_PATH,
1021
- MFE_CONFIG_DEFAULT_FILE_NAME
1022
- );
1023
- }
1024
987
  return path4.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1025
988
  }
1026
989
 
@@ -1051,7 +1014,7 @@ var schema_default = {
1051
1014
  },
1052
1015
  version: {
1053
1016
  type: "string",
1054
- const: "2"
1017
+ const: "1"
1055
1018
  },
1056
1019
  options: {
1057
1020
  $ref: "#/definitions/Options"
@@ -1061,6 +1024,9 @@ var schema_default = {
1061
1024
  additionalProperties: {
1062
1025
  $ref: "#/definitions/Application"
1063
1026
  },
1027
+ propertyNames: {
1028
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1029
+ },
1064
1030
  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."
1065
1031
  },
1066
1032
  applications: {
@@ -1068,7 +1034,9 @@ var schema_default = {
1068
1034
  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"
1069
1035
  }
1070
1036
  },
1071
- required: ["applications", "version"],
1037
+ required: [
1038
+ "applications"
1039
+ ],
1072
1040
  additionalProperties: false
1073
1041
  },
1074
1042
  Options: {
@@ -1132,7 +1100,9 @@ var schema_default = {
1132
1100
  $ref: "#/definitions/HostConfig"
1133
1101
  }
1134
1102
  },
1135
- required: ["production"],
1103
+ required: [
1104
+ "production"
1105
+ ],
1136
1106
  additionalProperties: false
1137
1107
  },
1138
1108
  Vercel: {
@@ -1143,7 +1113,9 @@ var schema_default = {
1143
1113
  description: "Vercel project ID"
1144
1114
  }
1145
1115
  },
1146
- required: ["projectId"],
1116
+ required: [
1117
+ "projectId"
1118
+ ],
1147
1119
  additionalProperties: false
1148
1120
  },
1149
1121
  Development: {
@@ -1173,8 +1145,11 @@ var schema_default = {
1173
1145
  },
1174
1146
  protocol: {
1175
1147
  type: "string",
1176
- enum: ["http", "https"],
1177
- 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'
1148
+ enum: [
1149
+ "http",
1150
+ "https"
1151
+ ],
1152
+ description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1178
1153
  },
1179
1154
  port: {
1180
1155
  type: "number",
@@ -1187,8 +1162,11 @@ var schema_default = {
1187
1162
  properties: {
1188
1163
  protocol: {
1189
1164
  type: "string",
1190
- enum: ["http", "https"],
1191
- 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'
1165
+ enum: [
1166
+ "http",
1167
+ "https"
1168
+ ],
1169
+ description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1192
1170
  },
1193
1171
  host: {
1194
1172
  type: "string",
@@ -1199,7 +1177,9 @@ var schema_default = {
1199
1177
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1200
1178
  }
1201
1179
  },
1202
- required: ["host"],
1180
+ required: [
1181
+ "host"
1182
+ ],
1203
1183
  additionalProperties: false
1204
1184
  },
1205
1185
  ChildApplication: {
@@ -1219,7 +1199,9 @@ var schema_default = {
1219
1199
  $ref: "#/definitions/HostConfig"
1220
1200
  }
1221
1201
  },
1222
- required: ["routing"],
1202
+ required: [
1203
+ "routing"
1204
+ ],
1223
1205
  additionalProperties: false
1224
1206
  },
1225
1207
  Routing: {
@@ -1246,13 +1228,18 @@ var schema_default = {
1246
1228
  }
1247
1229
  }
1248
1230
  },
1249
- required: ["paths"],
1231
+ required: [
1232
+ "paths"
1233
+ ],
1250
1234
  additionalProperties: false
1251
1235
  },
1252
1236
  ApplicationRouting: {
1253
1237
  type: "object",
1254
1238
  additionalProperties: {
1255
1239
  $ref: "#/definitions/Application"
1240
+ },
1241
+ propertyNames: {
1242
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1256
1243
  }
1257
1244
  },
1258
1245
  ChildConfig: {
@@ -1263,7 +1250,7 @@ var schema_default = {
1263
1250
  },
1264
1251
  version: {
1265
1252
  type: "string",
1266
- const: "2"
1253
+ const: "1"
1267
1254
  },
1268
1255
  options: {
1269
1256
  $ref: "#/definitions/Options"
@@ -1273,6 +1260,9 @@ var schema_default = {
1273
1260
  additionalProperties: {
1274
1261
  $ref: "#/definitions/Application"
1275
1262
  },
1263
+ propertyNames: {
1264
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1265
+ },
1276
1266
  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."
1277
1267
  },
1278
1268
  partOf: {
@@ -1280,7 +1270,9 @@ var schema_default = {
1280
1270
  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."
1281
1271
  }
1282
1272
  },
1283
- required: ["partOf", "version"],
1273
+ required: [
1274
+ "partOf"
1275
+ ],
1284
1276
  additionalProperties: false
1285
1277
  }
1286
1278
  }
@@ -1454,7 +1446,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1454
1446
  try {
1455
1447
  const configJson = fs5.readFileSync(filePath, "utf-8");
1456
1448
  const config = MicrofrontendsServer.validate(configJson);
1457
- if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
1449
+ if (!isMainConfig(config) && options?.resolveMainConfig) {
1458
1450
  const repositoryRoot = findRepositoryRoot();
1459
1451
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1460
1452
  if (isMonorepo2) {