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