@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
@@ -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;
@@ -527,17 +514,17 @@ var MicrofrontendConfigIsomorphic = class {
527
514
  constructor({
528
515
  config,
529
516
  overrides,
530
- meta
517
+ meta,
518
+ opts
531
519
  }) {
532
520
  this.childApplications = {};
533
- var _a, _b, _c, _d;
534
- MicrofrontendConfigIsomorphic.validate(config);
535
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
521
+ MicrofrontendConfigIsomorphic.validate(config, opts);
522
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
536
523
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
537
524
  this.isMainConfig = isMainConfig(config);
538
525
  if (isMainConfig(config)) {
539
526
  for (const [appId, appConfig] of Object.entries(config.applications)) {
540
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
527
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
541
528
  if (isDefaultApp(appConfig)) {
542
529
  this.defaultApplication = new DefaultApplication(appId, {
543
530
  app: appConfig,
@@ -552,7 +539,7 @@ var MicrofrontendConfigIsomorphic = class {
552
539
  }
553
540
  } else {
554
541
  this.partOf = config.partOf;
555
- 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;
556
543
  this.childApplications[meta.fromApp] = new ChildApplication(
557
544
  meta.fromApp,
558
545
  {
@@ -580,12 +567,9 @@ var MicrofrontendConfigIsomorphic = class {
580
567
  };
581
568
  }
582
569
  static validate(config, opts) {
583
- const skipValidation = (opts == null ? void 0 : opts.skipValidation) ?? [];
570
+ const skipValidation = opts?.skipValidation ?? [];
584
571
  const c = typeof config === "string" ? parse(config) : config;
585
572
  if (isMainConfig(c)) {
586
- if (!skipValidation.includes("version")) {
587
- validateConfigVersion(c.version);
588
- }
589
573
  if (!skipValidation.includes("paths")) {
590
574
  validateConfigPaths(c.applications);
591
575
  }
@@ -606,8 +590,7 @@ var MicrofrontendConfigIsomorphic = class {
606
590
  });
607
591
  }
608
592
  isOverridesDisabled() {
609
- var _a, _b;
610
- return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
593
+ return this.options?.vercel?.disableOverrides ?? false;
611
594
  }
612
595
  getConfig() {
613
596
  return this.config;
@@ -628,8 +611,7 @@ var MicrofrontendConfigIsomorphic = class {
628
611
  ].filter(Boolean);
629
612
  }
630
613
  getApplication(name) {
631
- var _a;
632
- if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
614
+ if (this.defaultApplication?.name === name) {
633
615
  return this.defaultApplication;
634
616
  }
635
617
  const app = this.childApplications[name];
@@ -645,15 +627,11 @@ var MicrofrontendConfigIsomorphic = class {
645
627
  return app;
646
628
  }
647
629
  getApplicationByProjectId(projectId) {
648
- var _a, _b;
649
- if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
630
+ if (this.defaultApplication?.vercel?.projectId === projectId) {
650
631
  return this.defaultApplication;
651
632
  }
652
633
  return Object.values(this.childApplications).find(
653
- (app) => {
654
- var _a2;
655
- return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
656
- }
634
+ (app) => app.vercel?.projectId === projectId
657
635
  );
658
636
  }
659
637
  /**
@@ -676,8 +654,7 @@ var MicrofrontendConfigIsomorphic = class {
676
654
  * Returns the configured port for the local proxy
677
655
  */
678
656
  getLocalProxyPort() {
679
- var _a, _b;
680
- 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;
681
658
  }
682
659
  /**
683
660
  * Serializes the class back to the Schema type.
@@ -731,13 +708,12 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
731
708
  overrides,
732
709
  meta
733
710
  }) {
734
- var _a, _b, _c;
735
711
  super({ config, overrides, meta });
736
712
  this.isMainConfig = true;
737
- 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;
738
714
  let defaultApplication;
739
715
  for (const [appId, appConfig] of Object.entries(config.applications)) {
740
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
716
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
741
717
  if (isDefaultApp(appConfig)) {
742
718
  defaultApplication = new DefaultApplication(appId, {
743
719
  app: appConfig,
@@ -930,7 +906,7 @@ function findDefaultMicrofrontendsPackage(opts) {
930
906
  const result = findDefaultMicrofrontendsPackages(opts);
931
907
  if (!result) {
932
908
  throw new Error(
933
- `Error trying to resolve the main microfrontends configuration`
909
+ "Error trying to resolve the main microfrontends configuration"
934
910
  );
935
911
  }
936
912
  configCache2[cacheKey] = result;
@@ -1002,20 +978,8 @@ import path4 from "node:path";
1002
978
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
1003
979
  var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1004
980
 
1005
- // src/utils/is-vercel.ts
1006
- function isVercel() {
1007
- return process.env.VERCEL === "1";
1008
- }
1009
-
1010
981
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1011
982
  function getOutputFilePath() {
1012
- if (isVercel()) {
1013
- return path4.join(
1014
- ".vercel",
1015
- MFE_CONFIG_DEFAULT_FILE_PATH,
1016
- MFE_CONFIG_DEFAULT_FILE_NAME
1017
- );
1018
- }
1019
983
  return path4.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1020
984
  }
1021
985
 
@@ -1046,7 +1010,7 @@ var schema_default = {
1046
1010
  },
1047
1011
  version: {
1048
1012
  type: "string",
1049
- const: "2"
1013
+ const: "1"
1050
1014
  },
1051
1015
  options: {
1052
1016
  $ref: "#/definitions/Options"
@@ -1056,6 +1020,9 @@ var schema_default = {
1056
1020
  additionalProperties: {
1057
1021
  $ref: "#/definitions/Application"
1058
1022
  },
1023
+ propertyNames: {
1024
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1025
+ },
1059
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."
1060
1027
  },
1061
1028
  applications: {
@@ -1063,7 +1030,9 @@ var schema_default = {
1063
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"
1064
1031
  }
1065
1032
  },
1066
- required: ["applications", "version"],
1033
+ required: [
1034
+ "applications"
1035
+ ],
1067
1036
  additionalProperties: false
1068
1037
  },
1069
1038
  Options: {
@@ -1127,7 +1096,9 @@ var schema_default = {
1127
1096
  $ref: "#/definitions/HostConfig"
1128
1097
  }
1129
1098
  },
1130
- required: ["production"],
1099
+ required: [
1100
+ "production"
1101
+ ],
1131
1102
  additionalProperties: false
1132
1103
  },
1133
1104
  Vercel: {
@@ -1138,7 +1109,9 @@ var schema_default = {
1138
1109
  description: "Vercel project ID"
1139
1110
  }
1140
1111
  },
1141
- required: ["projectId"],
1112
+ required: [
1113
+ "projectId"
1114
+ ],
1142
1115
  additionalProperties: false
1143
1116
  },
1144
1117
  Development: {
@@ -1168,8 +1141,11 @@ var schema_default = {
1168
1141
  },
1169
1142
  protocol: {
1170
1143
  type: "string",
1171
- enum: ["http", "https"],
1172
- 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*"
1173
1149
  },
1174
1150
  port: {
1175
1151
  type: "number",
@@ -1182,8 +1158,11 @@ var schema_default = {
1182
1158
  properties: {
1183
1159
  protocol: {
1184
1160
  type: "string",
1185
- enum: ["http", "https"],
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* @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*"
1187
1166
  },
1188
1167
  host: {
1189
1168
  type: "string",
@@ -1194,7 +1173,9 @@ var schema_default = {
1194
1173
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1195
1174
  }
1196
1175
  },
1197
- required: ["host"],
1176
+ required: [
1177
+ "host"
1178
+ ],
1198
1179
  additionalProperties: false
1199
1180
  },
1200
1181
  ChildApplication: {
@@ -1214,7 +1195,9 @@ var schema_default = {
1214
1195
  $ref: "#/definitions/HostConfig"
1215
1196
  }
1216
1197
  },
1217
- required: ["routing"],
1198
+ required: [
1199
+ "routing"
1200
+ ],
1218
1201
  additionalProperties: false
1219
1202
  },
1220
1203
  Routing: {
@@ -1241,13 +1224,18 @@ var schema_default = {
1241
1224
  }
1242
1225
  }
1243
1226
  },
1244
- required: ["paths"],
1227
+ required: [
1228
+ "paths"
1229
+ ],
1245
1230
  additionalProperties: false
1246
1231
  },
1247
1232
  ApplicationRouting: {
1248
1233
  type: "object",
1249
1234
  additionalProperties: {
1250
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`."
1251
1239
  }
1252
1240
  },
1253
1241
  ChildConfig: {
@@ -1258,7 +1246,7 @@ var schema_default = {
1258
1246
  },
1259
1247
  version: {
1260
1248
  type: "string",
1261
- const: "2"
1249
+ const: "1"
1262
1250
  },
1263
1251
  options: {
1264
1252
  $ref: "#/definitions/Options"
@@ -1268,6 +1256,9 @@ var schema_default = {
1268
1256
  additionalProperties: {
1269
1257
  $ref: "#/definitions/Application"
1270
1258
  },
1259
+ propertyNames: {
1260
+ description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1261
+ },
1271
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."
1272
1263
  },
1273
1264
  partOf: {
@@ -1275,7 +1266,9 @@ var schema_default = {
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
  },
1278
- required: ["partOf", "version"],
1269
+ required: [
1270
+ "partOf"
1271
+ ],
1279
1272
  additionalProperties: false
1280
1273
  }
1281
1274
  }
@@ -1449,7 +1442,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1449
1442
  try {
1450
1443
  const configJson = fs5.readFileSync(filePath, "utf-8");
1451
1444
  const config = MicrofrontendsServer.validate(configJson);
1452
- if (!isMainConfig(config) && (options == null ? void 0 : options.resolveMainConfig)) {
1445
+ if (!isMainConfig(config) && options?.resolveMainConfig) {
1453
1446
  const repositoryRoot = findRepositoryRoot();
1454
1447
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1455
1448
  if (isMonorepo2) {