@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
@@ -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;
@@ -531,17 +518,17 @@ var MicrofrontendConfigIsomorphic = class {
531
518
  constructor({
532
519
  config,
533
520
  overrides,
534
- meta
521
+ meta,
522
+ opts
535
523
  }) {
536
524
  this.childApplications = {};
537
- var _a, _b, _c, _d;
538
- MicrofrontendConfigIsomorphic.validate(config);
539
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
525
+ MicrofrontendConfigIsomorphic.validate(config, opts);
526
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
540
527
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
541
528
  this.isMainConfig = isMainConfig(config);
542
529
  if (isMainConfig(config)) {
543
530
  for (const [appId, appConfig] of Object.entries(config.applications)) {
544
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
531
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
545
532
  if (isDefaultApp(appConfig)) {
546
533
  this.defaultApplication = new DefaultApplication(appId, {
547
534
  app: appConfig,
@@ -556,7 +543,7 @@ var MicrofrontendConfigIsomorphic = class {
556
543
  }
557
544
  } else {
558
545
  this.partOf = config.partOf;
559
- 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;
560
547
  this.childApplications[meta.fromApp] = new ChildApplication(
561
548
  meta.fromApp,
562
549
  {
@@ -584,12 +571,9 @@ var MicrofrontendConfigIsomorphic = class {
584
571
  };
585
572
  }
586
573
  static validate(config, opts) {
587
- const skipValidation = (opts == null ? void 0 : opts.skipValidation) ?? [];
574
+ const skipValidation = opts?.skipValidation ?? [];
588
575
  const c = typeof config === "string" ? parse(config) : config;
589
576
  if (isMainConfig(c)) {
590
- if (!skipValidation.includes("version")) {
591
- validateConfigVersion(c.version);
592
- }
593
577
  if (!skipValidation.includes("paths")) {
594
578
  validateConfigPaths(c.applications);
595
579
  }
@@ -610,8 +594,7 @@ var MicrofrontendConfigIsomorphic = class {
610
594
  });
611
595
  }
612
596
  isOverridesDisabled() {
613
- var _a, _b;
614
- return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
597
+ return this.options?.vercel?.disableOverrides ?? false;
615
598
  }
616
599
  getConfig() {
617
600
  return this.config;
@@ -632,8 +615,7 @@ var MicrofrontendConfigIsomorphic = class {
632
615
  ].filter(Boolean);
633
616
  }
634
617
  getApplication(name) {
635
- var _a;
636
- if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
618
+ if (this.defaultApplication?.name === name) {
637
619
  return this.defaultApplication;
638
620
  }
639
621
  const app = this.childApplications[name];
@@ -649,15 +631,11 @@ var MicrofrontendConfigIsomorphic = class {
649
631
  return app;
650
632
  }
651
633
  getApplicationByProjectId(projectId) {
652
- var _a, _b;
653
- if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
634
+ if (this.defaultApplication?.vercel?.projectId === projectId) {
654
635
  return this.defaultApplication;
655
636
  }
656
637
  return Object.values(this.childApplications).find(
657
- (app) => {
658
- var _a2;
659
- return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
660
- }
638
+ (app) => app.vercel?.projectId === projectId
661
639
  );
662
640
  }
663
641
  /**
@@ -680,8 +658,7 @@ var MicrofrontendConfigIsomorphic = class {
680
658
  * Returns the configured port for the local proxy
681
659
  */
682
660
  getLocalProxyPort() {
683
- var _a, _b;
684
- 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;
685
662
  }
686
663
  /**
687
664
  * Serializes the class back to the Schema type.
@@ -735,13 +712,12 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
735
712
  overrides,
736
713
  meta
737
714
  }) {
738
- var _a, _b, _c;
739
715
  super({ config, overrides, meta });
740
716
  this.isMainConfig = true;
741
- 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;
742
718
  let defaultApplication;
743
719
  for (const [appId, appConfig] of Object.entries(config.applications)) {
744
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
720
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
745
721
  if (isDefaultApp(appConfig)) {
746
722
  defaultApplication = new DefaultApplication(appId, {
747
723
  app: appConfig,
@@ -934,7 +910,7 @@ function findDefaultMicrofrontendsPackage(opts) {
934
910
  const result = findDefaultMicrofrontendsPackages(opts);
935
911
  if (!result) {
936
912
  throw new Error(
937
- `Error trying to resolve the main microfrontends configuration`
913
+ "Error trying to resolve the main microfrontends configuration"
938
914
  );
939
915
  }
940
916
  configCache2[cacheKey] = result;
@@ -1006,20 +982,8 @@ import path4 from "node:path";
1006
982
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
1007
983
  var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1008
984
 
1009
- // src/utils/is-vercel.ts
1010
- function isVercel() {
1011
- return process.env.VERCEL === "1";
1012
- }
1013
-
1014
985
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1015
986
  function getOutputFilePath() {
1016
- if (isVercel()) {
1017
- return path4.join(
1018
- ".vercel",
1019
- MFE_CONFIG_DEFAULT_FILE_PATH,
1020
- MFE_CONFIG_DEFAULT_FILE_NAME
1021
- );
1022
- }
1023
987
  return path4.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1024
988
  }
1025
989
 
@@ -1050,7 +1014,7 @@ var schema_default = {
1050
1014
  },
1051
1015
  version: {
1052
1016
  type: "string",
1053
- const: "2"
1017
+ const: "1"
1054
1018
  },
1055
1019
  options: {
1056
1020
  $ref: "#/definitions/Options"
@@ -1060,6 +1024,9 @@ var schema_default = {
1060
1024
  additionalProperties: {
1061
1025
  $ref: "#/definitions/Application"
1062
1026
  },
1027
+ propertyNames: {
1028
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1029
+ },
1063
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."
1064
1031
  },
1065
1032
  applications: {
@@ -1067,7 +1034,9 @@ var schema_default = {
1067
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"
1068
1035
  }
1069
1036
  },
1070
- required: ["applications", "version"],
1037
+ required: [
1038
+ "applications"
1039
+ ],
1071
1040
  additionalProperties: false
1072
1041
  },
1073
1042
  Options: {
@@ -1131,7 +1100,9 @@ var schema_default = {
1131
1100
  $ref: "#/definitions/HostConfig"
1132
1101
  }
1133
1102
  },
1134
- required: ["production"],
1103
+ required: [
1104
+ "production"
1105
+ ],
1135
1106
  additionalProperties: false
1136
1107
  },
1137
1108
  Vercel: {
@@ -1142,7 +1113,9 @@ var schema_default = {
1142
1113
  description: "Vercel project ID"
1143
1114
  }
1144
1115
  },
1145
- required: ["projectId"],
1116
+ required: [
1117
+ "projectId"
1118
+ ],
1146
1119
  additionalProperties: false
1147
1120
  },
1148
1121
  Development: {
@@ -1172,8 +1145,11 @@ var schema_default = {
1172
1145
  },
1173
1146
  protocol: {
1174
1147
  type: "string",
1175
- enum: ["http", "https"],
1176
- 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*"
1177
1153
  },
1178
1154
  port: {
1179
1155
  type: "number",
@@ -1186,8 +1162,11 @@ var schema_default = {
1186
1162
  properties: {
1187
1163
  protocol: {
1188
1164
  type: "string",
1189
- enum: ["http", "https"],
1190
- 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*"
1191
1170
  },
1192
1171
  host: {
1193
1172
  type: "string",
@@ -1198,7 +1177,9 @@ var schema_default = {
1198
1177
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1199
1178
  }
1200
1179
  },
1201
- required: ["host"],
1180
+ required: [
1181
+ "host"
1182
+ ],
1202
1183
  additionalProperties: false
1203
1184
  },
1204
1185
  ChildApplication: {
@@ -1218,7 +1199,9 @@ var schema_default = {
1218
1199
  $ref: "#/definitions/HostConfig"
1219
1200
  }
1220
1201
  },
1221
- required: ["routing"],
1202
+ required: [
1203
+ "routing"
1204
+ ],
1222
1205
  additionalProperties: false
1223
1206
  },
1224
1207
  Routing: {
@@ -1245,13 +1228,18 @@ var schema_default = {
1245
1228
  }
1246
1229
  }
1247
1230
  },
1248
- required: ["paths"],
1231
+ required: [
1232
+ "paths"
1233
+ ],
1249
1234
  additionalProperties: false
1250
1235
  },
1251
1236
  ApplicationRouting: {
1252
1237
  type: "object",
1253
1238
  additionalProperties: {
1254
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`."
1255
1243
  }
1256
1244
  },
1257
1245
  ChildConfig: {
@@ -1262,7 +1250,7 @@ var schema_default = {
1262
1250
  },
1263
1251
  version: {
1264
1252
  type: "string",
1265
- const: "2"
1253
+ const: "1"
1266
1254
  },
1267
1255
  options: {
1268
1256
  $ref: "#/definitions/Options"
@@ -1272,6 +1260,9 @@ var schema_default = {
1272
1260
  additionalProperties: {
1273
1261
  $ref: "#/definitions/Application"
1274
1262
  },
1263
+ propertyNames: {
1264
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1265
+ },
1275
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."
1276
1267
  },
1277
1268
  partOf: {
@@ -1279,7 +1270,9 @@ var schema_default = {
1279
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."
1280
1271
  }
1281
1272
  },
1282
- required: ["partOf", "version"],
1273
+ required: [
1274
+ "partOf"
1275
+ ],
1283
1276
  additionalProperties: false
1284
1277
  }
1285
1278
  }
@@ -1453,7 +1446,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1453
1446
  try {
1454
1447
  const configJson = fs5.readFileSync(filePath, "utf-8");
1455
1448
  const config = MicrofrontendsServer.validate(configJson);
1456
- if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
1449
+ if (!isMainConfig(config) && options?.resolveMainConfig) {
1457
1450
  const repositoryRoot = findRepositoryRoot();
1458
1451
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1459
1452
  if (isMonorepo2) {