@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
@@ -8,8 +8,7 @@ var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
8
8
 
9
9
  // src/config/overrides/is-override-cookie.ts
10
10
  function isOverrideCookie(cookie) {
11
- var _a;
12
- return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
11
+ return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));
13
12
  }
14
13
 
15
14
  // src/config/overrides/get-override-from-cookie.ts
@@ -41,9 +40,9 @@ var MicrofrontendError = class extends Error {
41
40
  constructor(message, opts) {
42
41
  super(message);
43
42
  this.name = "MicrofrontendsError";
44
- this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
45
- this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
46
- this.subtype = opts == null ? void 0 : opts.subtype;
43
+ this.source = opts?.source ?? "@vercel/microfrontends";
44
+ this.type = opts?.type ?? "unknown";
45
+ this.subtype = opts?.subtype;
47
46
  Error.captureStackTrace(this, MicrofrontendError);
48
47
  }
49
48
  isKnown() {
@@ -58,7 +57,7 @@ var MicrofrontendError = class extends Error {
58
57
  * @returns The converted MicrofrontendsError.
59
58
  */
60
59
  static convert(original, opts) {
61
- if (opts == null ? void 0 : opts.fileName) {
60
+ if (opts?.fileName) {
62
61
  const err = MicrofrontendError.convertFSError(original, opts.fileName);
63
62
  if (err) {
64
63
  return err;
@@ -159,7 +158,7 @@ var MicrofrontendConfigClient = class {
159
158
  constructor(config, opts) {
160
159
  this.pathCache = {};
161
160
  this.serialized = config;
162
- if (opts == null ? void 0 : opts.removeFlaggedPaths) {
161
+ if (opts?.removeFlaggedPaths) {
163
162
  for (const app of Object.values(config.applications)) {
164
163
  if (app.routing) {
165
164
  app.routing = app.routing.filter((match) => !match.flag);
@@ -221,17 +220,6 @@ var MicrofrontendConfigClient = class {
221
220
 
222
221
  // src/config/microfrontends-config/isomorphic/validation.ts
223
222
  import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to-regexp";
224
- var SUPPORTED_VERSIONS = ["2"];
225
- var validateConfigVersion = (version) => {
226
- if (!SUPPORTED_VERSIONS.includes(version)) {
227
- throw new MicrofrontendError(
228
- `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
229
- ", "
230
- )}`,
231
- { type: "config", subtype: "unsupported_version" }
232
- );
233
- }
234
- };
235
223
  var validateConfigPaths = (applicationConfigsById) => {
236
224
  if (!applicationConfigsById) {
237
225
  return;
@@ -407,7 +395,7 @@ var Host = class {
407
395
  this.protocol = protocol;
408
396
  this.host = host;
409
397
  this.port = Host.getPort({ port, protocol: this.protocol });
410
- this.local = options == null ? void 0 : options.isLocal;
398
+ this.local = options?.isLocal;
411
399
  }
412
400
  isLocal() {
413
401
  return this.local || this.host === "localhost" || this.host === "127.0.0.1";
@@ -456,18 +444,17 @@ var Application = class {
456
444
  overrides,
457
445
  isDefault
458
446
  }) {
459
- var _a, _b;
460
447
  this.name = name;
461
448
  this.development = {
462
449
  local: new LocalHost({
463
450
  appName: name,
464
- ...(_a = app.development) == null ? void 0 : _a.local
451
+ ...app.development?.local
465
452
  }),
466
- fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
453
+ fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
467
454
  };
468
455
  this.production = app.production ? new Host(app.production) : void 0;
469
456
  this.vercel = app.vercel;
470
- this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
457
+ this.overrides = overrides?.environment ? {
471
458
  environment: new Host(overrides.environment)
472
459
  } : void 0;
473
460
  this.default = isDefault ?? false;
@@ -531,14 +518,13 @@ var MicrofrontendConfigIsomorphic = class {
531
518
  opts
532
519
  }) {
533
520
  this.childApplications = {};
534
- var _a, _b, _c, _d;
535
521
  MicrofrontendConfigIsomorphic.validate(config, opts);
536
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
522
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
537
523
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
538
524
  this.isMainConfig = isMainConfig(config);
539
525
  if (isMainConfig(config)) {
540
526
  for (const [appId, appConfig] of Object.entries(config.applications)) {
541
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
527
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
542
528
  if (isDefaultApp(appConfig)) {
543
529
  this.defaultApplication = new DefaultApplication(appId, {
544
530
  app: appConfig,
@@ -553,7 +539,7 @@ var MicrofrontendConfigIsomorphic = class {
553
539
  }
554
540
  } else {
555
541
  this.partOf = config.partOf;
556
- const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
542
+ const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
557
543
  this.childApplications[meta.fromApp] = new ChildApplication(
558
544
  meta.fromApp,
559
545
  {
@@ -581,12 +567,9 @@ var MicrofrontendConfigIsomorphic = class {
581
567
  };
582
568
  }
583
569
  static validate(config, opts) {
584
- const skipValidation = (opts == null ? void 0 : opts.skipValidation) ?? [];
570
+ const skipValidation = opts?.skipValidation ?? [];
585
571
  const c = typeof config === "string" ? parse(config) : config;
586
572
  if (isMainConfig(c)) {
587
- if (!skipValidation.includes("version")) {
588
- validateConfigVersion(c.version);
589
- }
590
573
  if (!skipValidation.includes("paths")) {
591
574
  validateConfigPaths(c.applications);
592
575
  }
@@ -607,8 +590,7 @@ var MicrofrontendConfigIsomorphic = class {
607
590
  });
608
591
  }
609
592
  isOverridesDisabled() {
610
- var _a, _b;
611
- return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
593
+ return this.options?.vercel?.disableOverrides ?? false;
612
594
  }
613
595
  getConfig() {
614
596
  return this.config;
@@ -629,8 +611,7 @@ var MicrofrontendConfigIsomorphic = class {
629
611
  ].filter(Boolean);
630
612
  }
631
613
  getApplication(name) {
632
- var _a;
633
- if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
614
+ if (this.defaultApplication?.name === name) {
634
615
  return this.defaultApplication;
635
616
  }
636
617
  const app = this.childApplications[name];
@@ -646,15 +627,11 @@ var MicrofrontendConfigIsomorphic = class {
646
627
  return app;
647
628
  }
648
629
  getApplicationByProjectId(projectId) {
649
- var _a, _b;
650
- if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
630
+ if (this.defaultApplication?.vercel?.projectId === projectId) {
651
631
  return this.defaultApplication;
652
632
  }
653
633
  return Object.values(this.childApplications).find(
654
- (app) => {
655
- var _a2;
656
- return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
657
- }
634
+ (app) => app.vercel?.projectId === projectId
658
635
  );
659
636
  }
660
637
  /**
@@ -677,8 +654,7 @@ var MicrofrontendConfigIsomorphic = class {
677
654
  * Returns the configured port for the local proxy
678
655
  */
679
656
  getLocalProxyPort() {
680
- var _a, _b;
681
- return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
657
+ return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
682
658
  }
683
659
  /**
684
660
  * Serializes the class back to the Schema type.
@@ -732,13 +708,12 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
732
708
  overrides,
733
709
  meta
734
710
  }) {
735
- var _a, _b, _c;
736
711
  super({ config, overrides, meta });
737
712
  this.isMainConfig = true;
738
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
713
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
739
714
  let defaultApplication;
740
715
  for (const [appId, appConfig] of Object.entries(config.applications)) {
741
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
716
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
742
717
  if (isDefaultApp(appConfig)) {
743
718
  defaultApplication = new DefaultApplication(appId, {
744
719
  app: appConfig,
@@ -931,7 +906,7 @@ function findDefaultMicrofrontendsPackage(opts) {
931
906
  const result = findDefaultMicrofrontendsPackages(opts);
932
907
  if (!result) {
933
908
  throw new Error(
934
- `Error trying to resolve the main microfrontends configuration`
909
+ "Error trying to resolve the main microfrontends configuration"
935
910
  );
936
911
  }
937
912
  configCache2[cacheKey] = result;
@@ -1003,20 +978,8 @@ import path4 from "node:path";
1003
978
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
1004
979
  var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1005
980
 
1006
- // src/utils/is-vercel.ts
1007
- function isVercel() {
1008
- return process.env.VERCEL === "1";
1009
- }
1010
-
1011
981
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1012
982
  function getOutputFilePath() {
1013
- if (isVercel()) {
1014
- return path4.join(
1015
- ".vercel",
1016
- MFE_CONFIG_DEFAULT_FILE_PATH,
1017
- MFE_CONFIG_DEFAULT_FILE_NAME
1018
- );
1019
- }
1020
983
  return path4.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1021
984
  }
1022
985
 
@@ -1047,7 +1010,7 @@ var schema_default = {
1047
1010
  },
1048
1011
  version: {
1049
1012
  type: "string",
1050
- const: "2"
1013
+ const: "1"
1051
1014
  },
1052
1015
  options: {
1053
1016
  $ref: "#/definitions/Options"
@@ -1057,6 +1020,9 @@ var schema_default = {
1057
1020
  additionalProperties: {
1058
1021
  $ref: "#/definitions/Application"
1059
1022
  },
1023
+ propertyNames: {
1024
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1025
+ },
1060
1026
  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."
1061
1027
  },
1062
1028
  applications: {
@@ -1064,7 +1030,9 @@ var schema_default = {
1064
1030
  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"
1065
1031
  }
1066
1032
  },
1067
- required: ["applications", "version"],
1033
+ required: [
1034
+ "applications"
1035
+ ],
1068
1036
  additionalProperties: false
1069
1037
  },
1070
1038
  Options: {
@@ -1128,7 +1096,9 @@ var schema_default = {
1128
1096
  $ref: "#/definitions/HostConfig"
1129
1097
  }
1130
1098
  },
1131
- required: ["production"],
1099
+ required: [
1100
+ "production"
1101
+ ],
1132
1102
  additionalProperties: false
1133
1103
  },
1134
1104
  Vercel: {
@@ -1139,7 +1109,9 @@ var schema_default = {
1139
1109
  description: "Vercel project ID"
1140
1110
  }
1141
1111
  },
1142
- required: ["projectId"],
1112
+ required: [
1113
+ "projectId"
1114
+ ],
1143
1115
  additionalProperties: false
1144
1116
  },
1145
1117
  Development: {
@@ -1169,8 +1141,11 @@ var schema_default = {
1169
1141
  },
1170
1142
  protocol: {
1171
1143
  type: "string",
1172
- enum: ["http", "https"],
1173
- 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'
1144
+ enum: [
1145
+ "http",
1146
+ "https"
1147
+ ],
1148
+ description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1174
1149
  },
1175
1150
  port: {
1176
1151
  type: "number",
@@ -1183,8 +1158,11 @@ var schema_default = {
1183
1158
  properties: {
1184
1159
  protocol: {
1185
1160
  type: "string",
1186
- enum: ["http", "https"],
1187
- 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'
1161
+ enum: [
1162
+ "http",
1163
+ "https"
1164
+ ],
1165
+ description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1188
1166
  },
1189
1167
  host: {
1190
1168
  type: "string",
@@ -1195,7 +1173,9 @@ var schema_default = {
1195
1173
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1196
1174
  }
1197
1175
  },
1198
- required: ["host"],
1176
+ required: [
1177
+ "host"
1178
+ ],
1199
1179
  additionalProperties: false
1200
1180
  },
1201
1181
  ChildApplication: {
@@ -1215,7 +1195,9 @@ var schema_default = {
1215
1195
  $ref: "#/definitions/HostConfig"
1216
1196
  }
1217
1197
  },
1218
- required: ["routing"],
1198
+ required: [
1199
+ "routing"
1200
+ ],
1219
1201
  additionalProperties: false
1220
1202
  },
1221
1203
  Routing: {
@@ -1242,13 +1224,18 @@ var schema_default = {
1242
1224
  }
1243
1225
  }
1244
1226
  },
1245
- required: ["paths"],
1227
+ required: [
1228
+ "paths"
1229
+ ],
1246
1230
  additionalProperties: false
1247
1231
  },
1248
1232
  ApplicationRouting: {
1249
1233
  type: "object",
1250
1234
  additionalProperties: {
1251
1235
  $ref: "#/definitions/Application"
1236
+ },
1237
+ propertyNames: {
1238
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1252
1239
  }
1253
1240
  },
1254
1241
  ChildConfig: {
@@ -1259,7 +1246,7 @@ var schema_default = {
1259
1246
  },
1260
1247
  version: {
1261
1248
  type: "string",
1262
- const: "2"
1249
+ const: "1"
1263
1250
  },
1264
1251
  options: {
1265
1252
  $ref: "#/definitions/Options"
@@ -1269,6 +1256,9 @@ var schema_default = {
1269
1256
  additionalProperties: {
1270
1257
  $ref: "#/definitions/Application"
1271
1258
  },
1259
+ propertyNames: {
1260
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1261
+ },
1272
1262
  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."
1273
1263
  },
1274
1264
  partOf: {
@@ -1276,7 +1266,9 @@ var schema_default = {
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
  },
1279
- required: ["partOf", "version"],
1269
+ required: [
1270
+ "partOf"
1271
+ ],
1280
1272
  additionalProperties: false
1281
1273
  }
1282
1274
  }
@@ -1450,7 +1442,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1450
1442
  try {
1451
1443
  const configJson = fs5.readFileSync(filePath, "utf-8");
1452
1444
  const config = MicrofrontendsServer.validate(configJson);
1453
- if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
1445
+ if (!isMainConfig(config) && options?.resolveMainConfig) {
1454
1446
  const repositoryRoot = findRepositoryRoot();
1455
1447
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1456
1448
  if (isMonorepo2) {