@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
@@ -396,8 +396,7 @@ var validateConfigPaths = (applicationConfigsById) => {
396
396
  if (isDefaultApp(app)) {
397
397
  continue;
398
398
  }
399
- const childApp = app;
400
- for (const pathMatch of childApp.routing) {
399
+ for (const pathMatch of app.routing) {
401
400
  for (const path7 of pathMatch.paths) {
402
401
  const maybeError = validatePathExpression(path7);
403
402
  if (maybeError) {
@@ -545,64 +544,15 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
545
544
  };
546
545
  var validateDeprecatedFields = (config) => {
547
546
  const errors = [];
548
- if (config.options?.vercel) {
549
- errors.push(
550
- `Configuration cannot contain deprecated field 'options.vercel'. Use 'options.disableOverrides' instead.`
551
- );
552
- }
553
- if (config.options?.localProxy) {
554
- errors.push(
555
- `Configuration cannot contain deprecated field 'options.localProxy'. Use 'options.localProxyPort' instead.`
556
- );
557
- }
558
547
  for (const [applicationId, application] of Object.entries(
559
548
  config.applications
560
549
  )) {
561
- if (application.vercel) {
562
- errors.push(
563
- `Application '${applicationId}' cannot contain deprecated field 'vercel'. Use 'projectId' instead.`
564
- );
565
- }
566
- if (application.production) {
567
- errors.push(
568
- `Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
569
- );
570
- }
571
550
  if (application.development?.localPort) {
572
551
  errors.push(
573
552
  `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
574
553
  );
575
554
  }
576
- if (application.development?.fallback && typeof application.development.fallback !== "string") {
577
- const fallback = application.development.fallback;
578
- let asString = fallback.host;
579
- if (fallback.protocol) {
580
- asString = `${fallback.protocol}://${asString}`;
581
- }
582
- if (fallback.port) {
583
- asString = `${asString}:${fallback.port}`;
584
- }
585
- errors.push(
586
- `Application '${applicationId}' requires a string (not an object) for the 'development.fallback' field. Please set 'development.fallback' to '${asString}'.`
587
- );
588
- }
589
- if (application.development?.local && typeof application.development.local !== "string" && typeof application.development.local !== "number") {
590
- const local = application.development.local;
591
- let asString;
592
- if (local.port && !local.protocol && !local.host) {
593
- asString = String(local.port);
594
- } else {
595
- asString = local.host ?? "localhost";
596
- if (local.protocol) {
597
- asString = `${local.protocol}://${asString}`;
598
- }
599
- if (local.port) {
600
- asString = `${asString}:${local.port}`;
601
- }
602
- }
603
- errors.push(
604
- `Application '${applicationId}' requires a string or number (not an object) for the 'development.local' field. Please set 'development.local' to '${asString}'.`
605
- );
555
+ if (application.projectId) {
606
556
  }
607
557
  }
608
558
  if (errors.length) {
@@ -757,6 +707,13 @@ var LocalHost = class extends Host {
757
707
  }
758
708
  };
759
709
 
710
+ // src/config/microfrontends-config/isomorphic/utils/generate-automation-bypass-env-var-name.ts
711
+ function generateAutomationBypassEnvVarName({
712
+ name
713
+ }) {
714
+ return `AUTOMATION_BYPASS_${name.toUpperCase().replace(/[^a-zA-Z0-9]/g, "_")}`;
715
+ }
716
+
760
717
  // src/config/microfrontends-config/isomorphic/application.ts
761
718
  var Application = class {
762
719
  constructor(name, {
@@ -775,10 +732,8 @@ var Application = class {
775
732
  };
776
733
  if (app.development?.fallback) {
777
734
  this.fallback = new Host(app.development.fallback);
778
- } else if (app.production) {
779
- this.fallback = new Host(app.production);
780
735
  }
781
- this.projectId = app.projectId ?? app.vercel?.projectId;
736
+ this.projectId = app.projectId;
782
737
  this.packageName = app.packageName;
783
738
  this.overrides = overrides?.environment ? {
784
739
  environment: new Host(overrides.environment)
@@ -792,6 +747,9 @@ var Application = class {
792
747
  getAssetPrefix() {
793
748
  return generateAssetPrefixFromName({ name: this.name });
794
749
  }
750
+ getAutomationBypassEnvVarName() {
751
+ return generateAutomationBypassEnvVarName({ name: this.name });
752
+ }
795
753
  serialize() {
796
754
  return this.serialized;
797
755
  }
@@ -807,16 +765,7 @@ var DefaultApplication = class extends Application {
807
765
  isDefault: true
808
766
  });
809
767
  this.default = true;
810
- const fallbackHost = app.development?.fallback ?? app.production;
811
- if (fallbackHost === void 0) {
812
- throw new Error(
813
- "`app.production` or `app.development.fallback` must be set in the default application in microfrontends.json."
814
- );
815
- }
816
- this.fallback = new Host(fallbackHost);
817
- if (app.production) {
818
- this.production = new Host(app.production);
819
- }
768
+ this.fallback = new Host(app.development.fallback);
820
769
  }
821
770
  getAssetPrefix() {
822
771
  return "";
@@ -853,7 +802,7 @@ var MicrofrontendConfigIsomorphic = class {
853
802
  }) {
854
803
  this.childApplications = {};
855
804
  MicrofrontendConfigIsomorphic.validate(config, opts);
856
- const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
805
+ const disableOverrides = config.options?.disableOverrides ?? false;
857
806
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
858
807
  let defaultApplication;
859
808
  for (const [appId, appConfig] of Object.entries(config.applications)) {
@@ -906,7 +855,7 @@ var MicrofrontendConfigIsomorphic = class {
906
855
  });
907
856
  }
908
857
  isOverridesDisabled() {
909
- return this.options?.vercel?.disableOverrides ?? false;
858
+ return this.options?.disableOverrides ?? false;
910
859
  }
911
860
  getConfig() {
912
861
  return this.config;
@@ -944,6 +893,14 @@ var MicrofrontendConfigIsomorphic = class {
944
893
  }
945
894
  return app;
946
895
  }
896
+ hasApplication(name) {
897
+ try {
898
+ this.getApplication(name);
899
+ return true;
900
+ } catch {
901
+ return false;
902
+ }
903
+ }
947
904
  getApplicationByProjectId(projectId) {
948
905
  if (this.defaultApplication.projectId === projectId) {
949
906
  return this.defaultApplication;
@@ -962,7 +919,7 @@ var MicrofrontendConfigIsomorphic = class {
962
919
  * Returns the configured port for the local proxy
963
920
  */
964
921
  getLocalProxyPort() {
965
- return this.config.options?.localProxyPort ?? this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
922
+ return this.config.options?.localProxyPort ?? DEFAULT_LOCAL_PROXY_PORT;
966
923
  }
967
924
  /**
968
925
  * Serializes the class back to the Schema type.
@@ -1073,20 +1030,10 @@ var schema_default = {
1073
1030
  Options: {
1074
1031
  type: "object",
1075
1032
  properties: {
1076
- vercel: {
1077
- $ref: "#/definitions/VercelOptions",
1078
- description: "Microfrontends wide options for Vercel.",
1079
- deprecated: "This is being replaced by the `disableOverrides` field below."
1080
- },
1081
1033
  disableOverrides: {
1082
1034
  type: "boolean",
1083
1035
  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."
1084
1036
  },
1085
- localProxy: {
1086
- $ref: "#/definitions/LocalProxyOptions",
1087
- description: "Options for local proxy.",
1088
- deprecated: "This is being replaced by the `localProxyPort` field below."
1089
- },
1090
1037
  localProxyPort: {
1091
1038
  type: "number",
1092
1039
  description: "The port number used by the local proxy server.\n\nThe default is `3024`."
@@ -1094,26 +1041,6 @@ var schema_default = {
1094
1041
  },
1095
1042
  additionalProperties: false
1096
1043
  },
1097
- VercelOptions: {
1098
- type: "object",
1099
- properties: {
1100
- disableOverrides: {
1101
- type: "boolean",
1102
- 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."
1103
- }
1104
- },
1105
- additionalProperties: false
1106
- },
1107
- LocalProxyOptions: {
1108
- type: "object",
1109
- properties: {
1110
- port: {
1111
- type: "number",
1112
- description: "The port number used by the local proxy server.\n\nThe default is `3024`."
1113
- }
1114
- },
1115
- additionalProperties: false
1116
- },
1117
1044
  ApplicationRouting: {
1118
1045
  type: "object",
1119
1046
  additionalProperties: {
@@ -1136,141 +1063,62 @@ var schema_default = {
1136
1063
  DefaultApplication: {
1137
1064
  type: "object",
1138
1065
  properties: {
1139
- vercel: {
1140
- $ref: "#/definitions/Vercel",
1141
- deprecated: "This is being replaced by the `projectId` field below."
1142
- },
1143
1066
  projectId: {
1144
1067
  type: "string",
1145
1068
  description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1146
- deprecated: "Instead, the application id should match the Vercel project name."
1069
+ 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)."
1147
1070
  },
1148
1071
  packageName: {
1149
1072
  type: "string",
1150
1073
  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`."
1151
1074
  },
1152
- production: {
1153
- $ref: "#/definitions/HostConfig",
1154
- deprecated: "This is a duplicate of the `development.fallback` field and this will be removed soon."
1155
- },
1156
1075
  development: {
1157
- $ref: "#/definitions/Development"
1076
+ $ref: "#/definitions/DefaultDevelopment",
1077
+ description: "Development configuration for the default application."
1158
1078
  }
1159
1079
  },
1080
+ required: ["development"],
1160
1081
  additionalProperties: false
1161
1082
  },
1162
- Vercel: {
1163
- type: "object",
1164
- properties: {
1165
- projectId: {
1166
- type: "string",
1167
- description: "Vercel project ID"
1168
- }
1169
- },
1170
- required: ["projectId"],
1171
- additionalProperties: false
1172
- },
1173
- HostConfig: {
1174
- type: "object",
1175
- properties: {
1176
- protocol: {
1177
- type: "string",
1178
- enum: ["http", "https"],
1179
- description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1180
- },
1181
- host: {
1182
- type: "string",
1183
- 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`)."
1184
- },
1185
- port: {
1186
- type: "number",
1187
- description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1188
- }
1189
- },
1190
- required: ["host"],
1191
- additionalProperties: false
1192
- },
1193
- Development: {
1083
+ DefaultDevelopment: {
1194
1084
  type: "object",
1195
1085
  properties: {
1196
1086
  local: {
1197
- anyOf: [
1198
- {
1199
- type: "number"
1200
- },
1201
- {
1202
- type: "string"
1203
- },
1204
- {
1205
- $ref: "#/definitions/LocalHostConfig"
1206
- }
1207
- ],
1208
- 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."
1087
+ type: ["number", "string"],
1088
+ 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"
1209
1089
  },
1210
1090
  localPort: {
1211
1091
  type: "number",
1212
1092
  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.",
1213
1093
  deprecated: "Please set the port with the 'local' field instead."
1214
1094
  },
1215
- fallback: {
1216
- anyOf: [
1217
- {
1218
- $ref: "#/definitions/HostConfig"
1219
- },
1220
- {
1221
- type: "string"
1222
- }
1223
- ],
1224
- 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."
1225
- },
1226
1095
  task: {
1227
1096
  type: "string",
1228
1097
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
1229
- }
1230
- },
1231
- additionalProperties: false
1232
- },
1233
- LocalHostConfig: {
1234
- type: "object",
1235
- additionalProperties: false,
1236
- properties: {
1237
- host: {
1238
- type: "string",
1239
- 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`)."
1240
1098
  },
1241
- protocol: {
1099
+ fallback: {
1242
1100
  type: "string",
1243
- enum: ["http", "https"],
1244
- description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1245
- },
1246
- port: {
1247
- type: "number",
1248
- description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1101
+ 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."
1249
1102
  }
1250
- }
1103
+ },
1104
+ required: ["fallback"],
1105
+ additionalProperties: false
1251
1106
  },
1252
1107
  ChildApplication: {
1253
1108
  type: "object",
1254
1109
  properties: {
1255
- vercel: {
1256
- $ref: "#/definitions/Vercel",
1257
- deprecated: "This is being replaced by the `projectId` field below."
1258
- },
1259
1110
  projectId: {
1260
1111
  type: "string",
1261
1112
  description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1262
- deprecated: "Instead, the application id should match the Vercel project name."
1113
+ 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)."
1263
1114
  },
1264
1115
  packageName: {
1265
1116
  type: "string",
1266
1117
  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`."
1267
1118
  },
1268
- production: {
1269
- $ref: "#/definitions/HostConfig",
1270
- deprecated: "This is a duplicate of the `development.fallback` field and this will be removed soon."
1271
- },
1272
1119
  development: {
1273
- $ref: "#/definitions/Development"
1120
+ $ref: "#/definitions/ChildDevelopment",
1121
+ description: "Development configuration for the child application."
1274
1122
  },
1275
1123
  routing: {
1276
1124
  $ref: "#/definitions/Routing",
@@ -1280,6 +1128,29 @@ var schema_default = {
1280
1128
  required: ["routing"],
1281
1129
  additionalProperties: false
1282
1130
  },
1131
+ ChildDevelopment: {
1132
+ type: "object",
1133
+ properties: {
1134
+ local: {
1135
+ type: ["number", "string"],
1136
+ 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"
1137
+ },
1138
+ localPort: {
1139
+ type: "number",
1140
+ 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.",
1141
+ deprecated: "Please set the port with the 'local' field instead."
1142
+ },
1143
+ task: {
1144
+ type: "string",
1145
+ description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
1146
+ },
1147
+ fallback: {
1148
+ type: "string",
1149
+ 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."
1150
+ }
1151
+ },
1152
+ additionalProperties: false
1153
+ },
1283
1154
  Routing: {
1284
1155
  type: "array",
1285
1156
  items: {
@@ -1365,7 +1236,7 @@ function formatAjvErrors(errors) {
1365
1236
  }
1366
1237
  function validateSchema(configString) {
1367
1238
  const parsedConfig = parse3(configString);
1368
- const ajv = new Ajv();
1239
+ const ajv = new Ajv({ allowUnionTypes: true });
1369
1240
  const validate = ajv.compile(SCHEMA);
1370
1241
  const isValid = validate(parsedConfig);
1371
1242
  if (!isValid) {