@vercel/microfrontends 1.1.1-canary.6 → 1.2.0

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 (55) hide show
  1. package/dist/bin/cli.cjs +405 -204
  2. package/dist/config.cjs +25 -68
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +5 -5
  5. package/dist/config.js +25 -68
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +64 -193
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +64 -193
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +64 -193
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.js +64 -193
  14. package/dist/experimental/vite.js.map +1 -1
  15. package/dist/microfrontends/server.cjs +64 -193
  16. package/dist/microfrontends/server.cjs.map +1 -1
  17. package/dist/microfrontends/server.d.ts +3 -3
  18. package/dist/microfrontends/server.js +64 -193
  19. package/dist/microfrontends/server.js.map +1 -1
  20. package/dist/next/config.cjs +69 -358
  21. package/dist/next/config.cjs.map +1 -1
  22. package/dist/next/config.d.ts +1 -1
  23. package/dist/next/config.js +69 -358
  24. package/dist/next/config.js.map +1 -1
  25. package/dist/next/endpoints.d.ts +2 -2
  26. package/dist/next/middleware.cjs +25 -68
  27. package/dist/next/middleware.cjs.map +1 -1
  28. package/dist/next/middleware.js +25 -68
  29. package/dist/next/middleware.js.map +1 -1
  30. package/dist/next/testing.cjs +123 -144
  31. package/dist/next/testing.cjs.map +1 -1
  32. package/dist/next/testing.d.ts +36 -5
  33. package/dist/next/testing.js +122 -143
  34. package/dist/next/testing.js.map +1 -1
  35. package/dist/overrides.d.ts +3 -3
  36. package/dist/schema.d.ts +2 -2
  37. package/dist/{types-f1260e44.d.ts → types-b970b583.d.ts} +1 -1
  38. package/dist/{types-a4add5ab.d.ts → types-bee19651.d.ts} +11 -2
  39. package/dist/{types-54064641.d.ts → types-c9f15465.d.ts} +31 -85
  40. package/dist/utils/mfe-port.cjs +64 -193
  41. package/dist/utils/mfe-port.cjs.map +1 -1
  42. package/dist/utils/mfe-port.js +64 -193
  43. package/dist/utils/mfe-port.js.map +1 -1
  44. package/dist/validation.cjs +39 -125
  45. package/dist/validation.cjs.map +1 -1
  46. package/dist/validation.d.ts +1 -1
  47. package/dist/validation.js +39 -125
  48. package/dist/validation.js.map +1 -1
  49. package/package.json +2 -8
  50. package/schema/schema.json +45 -131
  51. package/dist/routing.cjs +0 -19
  52. package/dist/routing.cjs.map +0 -1
  53. package/dist/routing.d.ts +0 -26
  54. package/dist/routing.js +0 -1
  55. package/dist/routing.js.map +0 -1
@@ -401,8 +401,7 @@ var validateConfigPaths = (applicationConfigsById) => {
401
401
  if (isDefaultApp(app)) {
402
402
  continue;
403
403
  }
404
- const childApp = app;
405
- for (const pathMatch of childApp.routing) {
404
+ for (const pathMatch of app.routing) {
406
405
  for (const path6 of pathMatch.paths) {
407
406
  const maybeError = validatePathExpression(path6);
408
407
  if (maybeError) {
@@ -550,64 +549,15 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
550
549
  };
551
550
  var validateDeprecatedFields = (config) => {
552
551
  const errors = [];
553
- if (config.options?.vercel) {
554
- errors.push(
555
- `Configuration cannot contain deprecated field 'options.vercel'. Use 'options.disableOverrides' instead.`
556
- );
557
- }
558
- if (config.options?.localProxy) {
559
- errors.push(
560
- `Configuration cannot contain deprecated field 'options.localProxy'. Use 'options.localProxyPort' instead.`
561
- );
562
- }
563
552
  for (const [applicationId, application] of Object.entries(
564
553
  config.applications
565
554
  )) {
566
- if (application.vercel) {
567
- errors.push(
568
- `Application '${applicationId}' cannot contain deprecated field 'vercel'. Use 'projectId' instead.`
569
- );
570
- }
571
- if (application.production) {
572
- errors.push(
573
- `Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
574
- );
575
- }
576
555
  if (application.development?.localPort) {
577
556
  errors.push(
578
557
  `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
579
558
  );
580
559
  }
581
- if (application.development?.fallback && typeof application.development.fallback !== "string") {
582
- const fallback = application.development.fallback;
583
- let asString = fallback.host;
584
- if (fallback.protocol) {
585
- asString = `${fallback.protocol}://${asString}`;
586
- }
587
- if (fallback.port) {
588
- asString = `${asString}:${fallback.port}`;
589
- }
590
- errors.push(
591
- `Application '${applicationId}' requires a string (not an object) for the 'development.fallback' field. Please set 'development.fallback' to '${asString}'.`
592
- );
593
- }
594
- if (application.development?.local && typeof application.development.local !== "string" && typeof application.development.local !== "number") {
595
- const local = application.development.local;
596
- let asString;
597
- if (local.port && !local.protocol && !local.host) {
598
- asString = String(local.port);
599
- } else {
600
- asString = local.host ?? "localhost";
601
- if (local.protocol) {
602
- asString = `${local.protocol}://${asString}`;
603
- }
604
- if (local.port) {
605
- asString = `${asString}:${local.port}`;
606
- }
607
- }
608
- errors.push(
609
- `Application '${applicationId}' requires a string or number (not an object) for the 'development.local' field. Please set 'development.local' to '${asString}'.`
610
- );
560
+ if (application.projectId) {
611
561
  }
612
562
  }
613
563
  if (errors.length) {
@@ -762,6 +712,13 @@ var LocalHost = class extends Host {
762
712
  }
763
713
  };
764
714
 
715
+ // src/config/microfrontends-config/isomorphic/utils/generate-automation-bypass-env-var-name.ts
716
+ function generateAutomationBypassEnvVarName({
717
+ name
718
+ }) {
719
+ return `AUTOMATION_BYPASS_${name.toUpperCase().replace(/[^a-zA-Z0-9]/g, "_")}`;
720
+ }
721
+
765
722
  // src/config/microfrontends-config/isomorphic/application.ts
766
723
  var Application = class {
767
724
  constructor(name, {
@@ -780,10 +737,8 @@ var Application = class {
780
737
  };
781
738
  if (app.development?.fallback) {
782
739
  this.fallback = new Host(app.development.fallback);
783
- } else if (app.production) {
784
- this.fallback = new Host(app.production);
785
740
  }
786
- this.projectId = app.projectId ?? app.vercel?.projectId;
741
+ this.projectId = app.projectId;
787
742
  this.packageName = app.packageName;
788
743
  this.overrides = overrides?.environment ? {
789
744
  environment: new Host(overrides.environment)
@@ -797,6 +752,9 @@ var Application = class {
797
752
  getAssetPrefix() {
798
753
  return generateAssetPrefixFromName({ name: this.name });
799
754
  }
755
+ getAutomationBypassEnvVarName() {
756
+ return generateAutomationBypassEnvVarName({ name: this.name });
757
+ }
800
758
  serialize() {
801
759
  return this.serialized;
802
760
  }
@@ -812,16 +770,7 @@ var DefaultApplication = class extends Application {
812
770
  isDefault: true
813
771
  });
814
772
  this.default = true;
815
- const fallbackHost = app.development?.fallback ?? app.production;
816
- if (fallbackHost === void 0) {
817
- throw new Error(
818
- "`app.production` or `app.development.fallback` must be set in the default application in microfrontends.json."
819
- );
820
- }
821
- this.fallback = new Host(fallbackHost);
822
- if (app.production) {
823
- this.production = new Host(app.production);
824
- }
773
+ this.fallback = new Host(app.development.fallback);
825
774
  }
826
775
  getAssetPrefix() {
827
776
  return "";
@@ -858,7 +807,7 @@ var MicrofrontendConfigIsomorphic = class {
858
807
  }) {
859
808
  this.childApplications = {};
860
809
  MicrofrontendConfigIsomorphic.validate(config, opts);
861
- const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
810
+ const disableOverrides = config.options?.disableOverrides ?? false;
862
811
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
863
812
  let defaultApplication;
864
813
  for (const [appId, appConfig] of Object.entries(config.applications)) {
@@ -911,7 +860,7 @@ var MicrofrontendConfigIsomorphic = class {
911
860
  });
912
861
  }
913
862
  isOverridesDisabled() {
914
- return this.options?.vercel?.disableOverrides ?? false;
863
+ return this.options?.disableOverrides ?? false;
915
864
  }
916
865
  getConfig() {
917
866
  return this.config;
@@ -949,6 +898,14 @@ var MicrofrontendConfigIsomorphic = class {
949
898
  }
950
899
  return app;
951
900
  }
901
+ hasApplication(name) {
902
+ try {
903
+ this.getApplication(name);
904
+ return true;
905
+ } catch {
906
+ return false;
907
+ }
908
+ }
952
909
  getApplicationByProjectId(projectId) {
953
910
  if (this.defaultApplication.projectId === projectId) {
954
911
  return this.defaultApplication;
@@ -967,7 +924,7 @@ var MicrofrontendConfigIsomorphic = class {
967
924
  * Returns the configured port for the local proxy
968
925
  */
969
926
  getLocalProxyPort() {
970
- return this.config.options?.localProxyPort ?? this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
927
+ return this.config.options?.localProxyPort ?? DEFAULT_LOCAL_PROXY_PORT;
971
928
  }
972
929
  /**
973
930
  * Serializes the class back to the Schema type.
@@ -1078,20 +1035,10 @@ var schema_default = {
1078
1035
  Options: {
1079
1036
  type: "object",
1080
1037
  properties: {
1081
- vercel: {
1082
- $ref: "#/definitions/VercelOptions",
1083
- description: "Microfrontends wide options for Vercel.",
1084
- deprecated: "This is being replaced by the `disableOverrides` field below."
1085
- },
1086
1038
  disableOverrides: {
1087
1039
  type: "boolean",
1088
1040
  description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
1089
1041
  },
1090
- localProxy: {
1091
- $ref: "#/definitions/LocalProxyOptions",
1092
- description: "Options for local proxy.",
1093
- deprecated: "This is being replaced by the `localProxyPort` field below."
1094
- },
1095
1042
  localProxyPort: {
1096
1043
  type: "number",
1097
1044
  description: "The port number used by the local proxy server.\n\nThe default is `3024`."
@@ -1099,26 +1046,6 @@ var schema_default = {
1099
1046
  },
1100
1047
  additionalProperties: false
1101
1048
  },
1102
- VercelOptions: {
1103
- type: "object",
1104
- properties: {
1105
- disableOverrides: {
1106
- type: "boolean",
1107
- description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
1108
- }
1109
- },
1110
- additionalProperties: false
1111
- },
1112
- LocalProxyOptions: {
1113
- type: "object",
1114
- properties: {
1115
- port: {
1116
- type: "number",
1117
- description: "The port number used by the local proxy server.\n\nThe default is `3024`."
1118
- }
1119
- },
1120
- additionalProperties: false
1121
- },
1122
1049
  ApplicationRouting: {
1123
1050
  type: "object",
1124
1051
  additionalProperties: {
@@ -1141,141 +1068,62 @@ var schema_default = {
1141
1068
  DefaultApplication: {
1142
1069
  type: "object",
1143
1070
  properties: {
1144
- vercel: {
1145
- $ref: "#/definitions/Vercel",
1146
- deprecated: "This is being replaced by the `projectId` field below."
1147
- },
1148
1071
  projectId: {
1149
1072
  type: "string",
1150
1073
  description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1151
- deprecated: "Instead, the application id should match the Vercel project name."
1074
+ deprecated: "Instead, the application id should match the Vercel project name. `packageName` can optionally\nbe set to the name of the package.json (if it is different from the project name)."
1152
1075
  },
1153
1076
  packageName: {
1154
1077
  type: "string",
1155
1078
  description: "The name used to run the application, e.g. the `name` field in the `package.json`.\n\nThis is used by the local proxy to map the application config to the locally running app.\n\nThis is only necessary when the application name does not match the `name` used in `package.json`."
1156
1079
  },
1157
- production: {
1158
- $ref: "#/definitions/HostConfig",
1159
- deprecated: "This is a duplicate of the `development.fallback` field and this will be removed soon."
1160
- },
1161
1080
  development: {
1162
- $ref: "#/definitions/Development"
1081
+ $ref: "#/definitions/DefaultDevelopment",
1082
+ description: "Development configuration for the default application."
1163
1083
  }
1164
1084
  },
1085
+ required: ["development"],
1165
1086
  additionalProperties: false
1166
1087
  },
1167
- Vercel: {
1168
- type: "object",
1169
- properties: {
1170
- projectId: {
1171
- type: "string",
1172
- description: "Vercel project ID"
1173
- }
1174
- },
1175
- required: ["projectId"],
1176
- additionalProperties: false
1177
- },
1178
- HostConfig: {
1179
- type: "object",
1180
- properties: {
1181
- protocol: {
1182
- type: "string",
1183
- enum: ["http", "https"],
1184
- description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1185
- },
1186
- host: {
1187
- type: "string",
1188
- description: "The hostname or IP address of the server. This can be a domain name (e.g., `example.com`) or an IP address (e.g., `192.168.1.1`)."
1189
- },
1190
- port: {
1191
- type: "number",
1192
- description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1193
- }
1194
- },
1195
- required: ["host"],
1196
- additionalProperties: false
1197
- },
1198
- Development: {
1088
+ DefaultDevelopment: {
1199
1089
  type: "object",
1200
1090
  properties: {
1201
1091
  local: {
1202
- anyOf: [
1203
- {
1204
- type: "number"
1205
- },
1206
- {
1207
- type: "string"
1208
- },
1209
- {
1210
- $ref: "#/definitions/LocalHostConfig"
1211
- }
1212
- ],
1213
- description: "A local port number or host string that this application runs on when it is running locally. If passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTP. If omitted, the port defaults to a unique, but stable (based on the application name) number.\n\nExamples of valid values:\n- 8080\n- my.localhost.me\n- my.localhost.me:8080\n- https://my.localhost.me\n- https://my.localhost.me:8080\n\nPassing a LocalHostConfig is deprecated and will go away soon, please pass a number or string."
1092
+ type: ["number", "string"],
1093
+ description: "A local port number or host string that this application runs on when it is running locally. If passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTP. If omitted, the port defaults to a unique, but stable (based on the application name) number.\n\nExamples of valid values:\n- 8080\n- my.localhost.me\n- my.localhost.me:8080\n- https://my.localhost.me\n- https://my.localhost.me:8080"
1214
1094
  },
1215
1095
  localPort: {
1216
1096
  type: "number",
1217
1097
  description: "The local port number that this application runs on when it is running locally. Common values include `80` for HTTP and `443` for HTTPS. If omitted, the port defaults to a unique, but stable (based on the application name) number.",
1218
1098
  deprecated: "Please set the port with the 'local' field instead."
1219
1099
  },
1220
- fallback: {
1221
- anyOf: [
1222
- {
1223
- $ref: "#/definitions/HostConfig"
1224
- },
1225
- {
1226
- type: "string"
1227
- }
1228
- ],
1229
- description: "Fallback for local development, could point to any environment. If this is not provided, or the application is not running - requests to the application in local development will error.\n\nIf passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTPS. If omitted, the port defaults to `80` for HTTP and `443` for HTTPS.\n\nPassing a HostConfig is deprecated and will go away soon, please pass a string."
1230
- },
1231
1100
  task: {
1232
1101
  type: "string",
1233
1102
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
1234
- }
1235
- },
1236
- additionalProperties: false
1237
- },
1238
- LocalHostConfig: {
1239
- type: "object",
1240
- additionalProperties: false,
1241
- properties: {
1242
- host: {
1243
- type: "string",
1244
- description: "The hostname or IP address of the server. This can be a domain name (e.g., `example.com`) or an IP address (e.g., `192.168.1.1`)."
1245
1103
  },
1246
- protocol: {
1104
+ fallback: {
1247
1105
  type: "string",
1248
- enum: ["http", "https"],
1249
- description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1250
- },
1251
- port: {
1252
- type: "number",
1253
- description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1106
+ description: "Fallback for local development, could point to any environment. This is required for the default app. This value is used as the fallback for child apps as well if they do not have a fallback.\n\nIf passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTPS. If omitted, the port defaults to `80` for HTTP and `443` for HTTPS."
1254
1107
  }
1255
- }
1108
+ },
1109
+ required: ["fallback"],
1110
+ additionalProperties: false
1256
1111
  },
1257
1112
  ChildApplication: {
1258
1113
  type: "object",
1259
1114
  properties: {
1260
- vercel: {
1261
- $ref: "#/definitions/Vercel",
1262
- deprecated: "This is being replaced by the `projectId` field below."
1263
- },
1264
1115
  projectId: {
1265
1116
  type: "string",
1266
1117
  description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1267
- deprecated: "Instead, the application id should match the Vercel project name."
1118
+ deprecated: "Instead, the application id should match the Vercel project name. `packageName` can optionally\nbe set to the name of the package.json (if it is different from the project name)."
1268
1119
  },
1269
1120
  packageName: {
1270
1121
  type: "string",
1271
1122
  description: "The name used to run the application, e.g. the `name` field in the `package.json`.\n\nThis is used by the local proxy to map the application config to the locally running app.\n\nThis is only necessary when the application name does not match the `name` used in `package.json`."
1272
1123
  },
1273
- production: {
1274
- $ref: "#/definitions/HostConfig",
1275
- deprecated: "This is a duplicate of the `development.fallback` field and this will be removed soon."
1276
- },
1277
1124
  development: {
1278
- $ref: "#/definitions/Development"
1125
+ $ref: "#/definitions/ChildDevelopment",
1126
+ description: "Development configuration for the child application."
1279
1127
  },
1280
1128
  routing: {
1281
1129
  $ref: "#/definitions/Routing",
@@ -1285,6 +1133,29 @@ var schema_default = {
1285
1133
  required: ["routing"],
1286
1134
  additionalProperties: false
1287
1135
  },
1136
+ ChildDevelopment: {
1137
+ type: "object",
1138
+ properties: {
1139
+ local: {
1140
+ type: ["number", "string"],
1141
+ description: "A local port number or host string that this application runs on when it is running locally. If passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTP. If omitted, the port defaults to a unique, but stable (based on the application name) number.\n\nExamples of valid values:\n- 8080\n- my.localhost.me\n- my.localhost.me:8080\n- https://my.localhost.me\n- https://my.localhost.me:8080"
1142
+ },
1143
+ localPort: {
1144
+ type: "number",
1145
+ description: "The local port number that this application runs on when it is running locally. Common values include `80` for HTTP and `443` for HTTPS. If omitted, the port defaults to a unique, but stable (based on the application name) number.",
1146
+ deprecated: "Please set the port with the 'local' field instead."
1147
+ },
1148
+ task: {
1149
+ type: "string",
1150
+ description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
1151
+ },
1152
+ fallback: {
1153
+ type: "string",
1154
+ description: "Fallback for local development, could point to any environment. This is optional for child apps. If not provided, the fallback of the default app will be used.\n\nIf passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTPS. If omitted, the port defaults to `80` for HTTP and `443` for HTTPS."
1155
+ }
1156
+ },
1157
+ additionalProperties: false
1158
+ },
1288
1159
  Routing: {
1289
1160
  type: "array",
1290
1161
  items: {
@@ -1370,7 +1241,7 @@ function formatAjvErrors(errors) {
1370
1241
  }
1371
1242
  function validateSchema(configString) {
1372
1243
  const parsedConfig = parse3(configString);
1373
- const ajv = new Ajv();
1244
+ const ajv = new Ajv({ allowUnionTypes: true });
1374
1245
  const validate = ajv.compile(SCHEMA);
1375
1246
  const isValid = validate(parsedConfig);
1376
1247
  if (!isValid) {