@vercel/microfrontends 1.1.1-canary.2 → 1.1.1-canary.4

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 (64) hide show
  1. package/dist/bin/cli.cjs +303 -512
  2. package/dist/config.cjs +43 -71
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +153 -4
  5. package/dist/config.js +43 -71
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +296 -489
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +286 -479
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +326 -511
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.js +312 -497
  14. package/dist/experimental/vite.js.map +1 -1
  15. package/dist/microfrontends/server.cjs +295 -485
  16. package/dist/microfrontends/server.cjs.map +1 -1
  17. package/dist/microfrontends/server.d.ts +14 -20
  18. package/dist/microfrontends/server.js +285 -475
  19. package/dist/microfrontends/server.js.map +1 -1
  20. package/dist/next/config.cjs +297 -498
  21. package/dist/next/config.cjs.map +1 -1
  22. package/dist/next/config.js +287 -488
  23. package/dist/next/config.js.map +1 -1
  24. package/dist/next/endpoints.cjs +2 -0
  25. package/dist/next/endpoints.cjs.map +1 -1
  26. package/dist/next/endpoints.d.ts +13 -3
  27. package/dist/next/endpoints.js +1 -0
  28. package/dist/next/endpoints.js.map +1 -1
  29. package/dist/next/middleware.cjs +58 -171
  30. package/dist/next/middleware.cjs.map +1 -1
  31. package/dist/next/middleware.d.ts +2 -4
  32. package/dist/next/middleware.js +58 -171
  33. package/dist/next/middleware.js.map +1 -1
  34. package/dist/next/testing.cjs +44 -73
  35. package/dist/next/testing.cjs.map +1 -1
  36. package/dist/next/testing.d.ts +4 -4
  37. package/dist/next/testing.js +44 -73
  38. package/dist/next/testing.js.map +1 -1
  39. package/dist/overrides.d.ts +3 -3
  40. package/dist/schema.cjs +2 -9
  41. package/dist/schema.cjs.map +1 -1
  42. package/dist/schema.d.ts +3 -4
  43. package/dist/schema.js +1 -7
  44. package/dist/schema.js.map +1 -1
  45. package/dist/{types-6ee19ccc.d.ts → types-54064641.d.ts} +2 -13
  46. package/dist/{types-73527280.d.ts → types-a4add5ab.d.ts} +1 -1
  47. package/dist/{types-74e3336c.d.ts → types-f1260e44.d.ts} +1 -1
  48. package/dist/utils/mfe-port.cjs +300 -492
  49. package/dist/utils/mfe-port.cjs.map +1 -1
  50. package/dist/utils/mfe-port.js +286 -478
  51. package/dist/utils/mfe-port.js.map +1 -1
  52. package/dist/validation.cjs +49 -37
  53. package/dist/validation.cjs.map +1 -1
  54. package/dist/validation.d.ts +1 -1
  55. package/dist/validation.js +49 -37
  56. package/dist/validation.js.map +1 -1
  57. package/package.json +2 -9
  58. package/schema/schema.json +0 -33
  59. package/dist/index-7e69650e.d.ts +0 -165
  60. package/dist/microfrontends.cjs +0 -962
  61. package/dist/microfrontends.cjs.map +0 -1
  62. package/dist/microfrontends.d.ts +0 -45
  63. package/dist/microfrontends.js +0 -935
  64. package/dist/microfrontends.js.map +0 -1
@@ -2,6 +2,12 @@
2
2
  import { NextResponse } from "next/server";
3
3
  import { pathToRegexp as pathToRegexp3 } from "path-to-regexp";
4
4
 
5
+ // src/next/utils/route-to-local-proxy.ts
6
+ function routeToLocalProxy() {
7
+ const isDevEnv = (process.env.VERCEL_ENV ?? "development") === "development";
8
+ return isDevEnv && Boolean(process.env.TURBO_TASK_HAS_MFE_PROXY);
9
+ }
10
+
5
11
  // src/config/microfrontends-config/isomorphic/index.ts
6
12
  import { parse } from "jsonc-parser";
7
13
 
@@ -109,11 +115,6 @@ function getConfigStringFromEnv() {
109
115
  return config;
110
116
  }
111
117
 
112
- // src/config/schema/utils/is-main-config.ts
113
- function isMainConfig(c) {
114
- return !("partOf" in c);
115
- }
116
-
117
118
  // src/config/schema/utils/is-default-app.ts
118
119
  function isDefaultApp(a) {
119
120
  return !("routing" in a);
@@ -220,6 +221,10 @@ function parseOverrides(cookies) {
220
221
 
221
222
  // src/config/microfrontends-config/isomorphic/validation.ts
222
223
  import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to-regexp";
224
+ var LIST_FORMATTER = new Intl.ListFormat("en", {
225
+ style: "long",
226
+ type: "conjunction"
227
+ });
223
228
  var validateConfigPaths = (applicationConfigsById) => {
224
229
  if (!applicationConfigsById) {
225
230
  return;
@@ -352,15 +357,15 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
352
357
  if (!applicationConfigsById) {
353
358
  return;
354
359
  }
355
- const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
356
- ([, app]) => !isDefaultApp(app)
357
- );
358
- const applicationsWithRoutingNames = applicationsWithRouting.map(
359
- ([key]) => key
360
+ const applicationsWithoutRouting = Object.entries(
361
+ applicationConfigsById
362
+ ).filter(([, app]) => isDefaultApp(app));
363
+ const numApplicationsWithoutRouting = applicationsWithoutRouting.reduce(
364
+ (acc) => {
365
+ return acc + 1;
366
+ },
367
+ 0
360
368
  );
361
- const numApplications = Object.keys(applicationConfigsById).length;
362
- const numApplicationsWithRouting = applicationsWithRoutingNames.length;
363
- const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
364
369
  if (numApplicationsWithoutRouting === 0) {
365
370
  throw new MicrofrontendError(
366
371
  "No default application found. At least one application needs to be the default by omitting routing.",
@@ -368,8 +373,11 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
368
373
  );
369
374
  }
370
375
  if (numApplicationsWithoutRouting > 1) {
376
+ const applicationNamesMissingRouting = applicationsWithoutRouting.map(
377
+ ([name]) => name
378
+ );
371
379
  throw new MicrofrontendError(
372
- `Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
380
+ `All applications except for the default app must contain the "routing" field. Applications that are missing routing: ${LIST_FORMATTER.format(applicationNamesMissingRouting)}.`,
373
381
  { type: "config", subtype: "multiple_default_applications" }
374
382
  );
375
383
  }
@@ -680,42 +688,28 @@ var MicrofrontendConfigIsomorphic = class {
680
688
  constructor({
681
689
  config,
682
690
  overrides,
683
- meta,
684
691
  opts
685
692
  }) {
686
693
  this.childApplications = {};
687
694
  MicrofrontendConfigIsomorphic.validate(config, opts);
688
695
  const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
689
696
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
690
- this.isMainConfig = isMainConfig(config);
691
- if (isMainConfig(config)) {
692
- for (const [appId, appConfig] of Object.entries(config.applications)) {
693
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
694
- if (isDefaultApp(appConfig)) {
695
- this.defaultApplication = new DefaultApplication(appId, {
696
- app: appConfig,
697
- overrides: appOverrides
698
- });
699
- } else {
700
- this.childApplications[appId] = new ChildApplication(appId, {
701
- app: appConfig,
702
- overrides: appOverrides
703
- });
704
- }
705
- }
706
- } else {
707
- this.partOf = config.partOf;
708
- const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
709
- this.childApplications[meta.fromApp] = new ChildApplication(
710
- meta.fromApp,
711
- {
712
- // we don't know routing because we're not in the main config
713
- app: { routing: [] },
697
+ let defaultApplication;
698
+ for (const [appId, appConfig] of Object.entries(config.applications)) {
699
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
700
+ if (isDefaultApp(appConfig)) {
701
+ defaultApplication = new DefaultApplication(appId, {
702
+ app: appConfig,
714
703
  overrides: appOverrides
715
- }
716
- );
704
+ });
705
+ } else {
706
+ this.childApplications[appId] = new ChildApplication(appId, {
707
+ app: appConfig,
708
+ overrides: appOverrides
709
+ });
710
+ }
717
711
  }
718
- if (isMainConfig(config) && !this.defaultApplication) {
712
+ if (!defaultApplication) {
719
713
  throw new MicrofrontendError(
720
714
  "Could not find default application in microfrontends configuration",
721
715
  {
@@ -724,34 +718,30 @@ var MicrofrontendConfigIsomorphic = class {
724
718
  }
725
719
  );
726
720
  }
721
+ this.defaultApplication = defaultApplication;
727
722
  this.config = config;
728
723
  this.options = config.options;
729
724
  this.serialized = {
730
725
  config,
731
- overrides,
732
- meta
726
+ overrides
733
727
  };
734
728
  }
735
729
  static validate(config, opts) {
736
730
  const skipValidation = opts?.skipValidation ?? [];
737
731
  const c = typeof config === "string" ? parse(config) : config;
738
- if (isMainConfig(c)) {
739
- validateConfigPaths(c.applications);
740
- validateConfigDefaultApplication(c.applications);
741
- if (!skipValidation.includes("deprecatedFields")) {
742
- validateDeprecatedFields(c);
743
- }
732
+ validateConfigPaths(c.applications);
733
+ validateConfigDefaultApplication(c.applications);
734
+ if (!skipValidation.includes("deprecatedFields")) {
735
+ validateDeprecatedFields(c);
744
736
  }
745
737
  return c;
746
738
  }
747
739
  static fromEnv({
748
- meta,
749
740
  cookies
750
741
  }) {
751
742
  return new MicrofrontendConfigIsomorphic({
752
743
  config: parse(getConfigStringFromEnv()),
753
- overrides: parseOverrides(cookies ?? []),
754
- meta
744
+ overrides: parseOverrides(cookies ?? [])
755
745
  });
756
746
  }
757
747
  isOverridesDisabled() {
@@ -776,7 +766,7 @@ var MicrofrontendConfigIsomorphic = class {
776
766
  ].filter(Boolean);
777
767
  }
778
768
  getApplication(name) {
779
- if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
769
+ if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
780
770
  return this.defaultApplication;
781
771
  }
782
772
  const app = this.childApplications[name] || Object.values(this.childApplications).find(
@@ -794,7 +784,7 @@ var MicrofrontendConfigIsomorphic = class {
794
784
  return app;
795
785
  }
796
786
  getApplicationByProjectId(projectId) {
797
- if (this.defaultApplication?.projectId === projectId) {
787
+ if (this.defaultApplication.projectId === projectId) {
798
788
  return this.defaultApplication;
799
789
  }
800
790
  return Object.values(this.childApplications).find(
@@ -802,19 +792,9 @@ var MicrofrontendConfigIsomorphic = class {
802
792
  );
803
793
  }
804
794
  /**
805
- * Returns the default application. This can throw if the default application
806
- * is undefined ( )
795
+ * Returns the default application.
807
796
  */
808
797
  getDefaultApplication() {
809
- if (!this.defaultApplication) {
810
- throw new MicrofrontendError(
811
- "Could not find default application in microfrontends configuration",
812
- {
813
- type: "application",
814
- subtype: "not_found"
815
- }
816
- );
817
- }
818
798
  return this.defaultApplication;
819
799
  }
820
800
  /**
@@ -841,11 +821,9 @@ var MicrofrontendConfigIsomorphic = class {
841
821
  }
842
822
  ])
843
823
  );
844
- if (this.defaultApplication) {
845
- applications[this.defaultApplication.name] = {
846
- default: true
847
- };
848
- }
824
+ applications[this.defaultApplication.name] = {
825
+ default: true
826
+ };
849
827
  return new MicrofrontendConfigClient({
850
828
  applications
851
829
  });
@@ -855,97 +833,13 @@ var MicrofrontendConfigIsomorphic = class {
855
833
  }
856
834
  };
857
835
 
858
- // src/config/microfrontends-config/isomorphic/child.ts
859
- var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
860
- constructor({
861
- config,
862
- overrides,
863
- meta
864
- }) {
865
- super({ config, overrides, meta });
866
- this.isMainConfig = false;
867
- this.partOf = config.partOf;
868
- }
869
- };
870
-
871
- // src/config/microfrontends-config/isomorphic/main.ts
872
- var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
873
- constructor({
874
- config,
875
- overrides,
876
- meta
877
- }) {
878
- super({ config, overrides, meta });
879
- this.isMainConfig = true;
880
- const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
881
- let defaultApplication;
882
- for (const [appId, appConfig] of Object.entries(config.applications)) {
883
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
884
- if (isDefaultApp(appConfig)) {
885
- defaultApplication = new DefaultApplication(appId, {
886
- app: appConfig,
887
- overrides: appOverrides
888
- });
889
- } else {
890
- this.childApplications[appId] = new ChildApplication(appId, {
891
- app: appConfig,
892
- overrides: appOverrides
893
- });
894
- }
895
- }
896
- if (!defaultApplication) {
897
- throw new MicrofrontendError(
898
- "Could not find default application in microfrontends configuration",
899
- {
900
- type: "application",
901
- subtype: "not_found"
902
- }
903
- );
904
- }
905
- this.defaultApplication = defaultApplication;
906
- }
907
- };
908
-
909
- // src/config/microfrontends/isomorphic/index.ts
910
- var Microfrontends = class {
911
- constructor({
912
- config,
913
- overrides,
914
- meta
915
- }) {
916
- if (isMainConfig(config)) {
917
- this.config = new MicrofrontendMainConfig({ config, overrides, meta });
918
- } else {
919
- this.config = new MicrofrontendChildConfig({ config, overrides, meta });
920
- }
921
- }
922
- isChildConfig() {
923
- return this.config instanceof MicrofrontendChildConfig;
924
- }
925
- static fromEnv({
926
- cookies,
927
- meta
928
- }) {
929
- const config = MicrofrontendConfigIsomorphic.fromEnv({
930
- cookies,
931
- meta
932
- });
933
- return new Microfrontends(config.serialize());
934
- }
935
- };
936
-
937
- // src/next/utils/route-to-local-proxy.ts
938
- function routeToLocalProxy() {
939
- const isDevEnv = (process.env.VERCEL_ENV ?? "development") === "development";
940
- return isDevEnv && Boolean(process.env.TURBO_TASK_HAS_MFE_PROXY);
941
- }
942
-
943
836
  // src/next/middleware/middleware.ts
944
837
  function getMfeFlagHeader(req) {
945
838
  const flagValue = req.headers.get("x-vercel-mfe-flag-value");
946
839
  if (flagValue === "true") {
947
840
  return true;
948
- } else if (flagValue === "false") {
841
+ }
842
+ if (flagValue === "false") {
949
843
  return false;
950
844
  }
951
845
  return null;
@@ -997,28 +891,23 @@ function getFlagHandler({
997
891
  }
998
892
  function getMicrofrontendsMiddleware({
999
893
  request,
1000
- flagValues,
1001
- fromApp
894
+ flagValues
1002
895
  }) {
1003
- const microfrontends = Microfrontends.fromEnv({
1004
- cookies: request.cookies.getAll(),
1005
- meta: {
1006
- fromApp
1007
- }
896
+ const microfrontends = MicrofrontendConfigIsomorphic.fromEnv({
897
+ cookies: request.cookies.getAll()
1008
898
  });
1009
899
  const middlewares = [];
1010
900
  if (!process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {
1011
901
  throw new Error("NEXT_PUBLIC_MFE_CURRENT_APPLICATION is not set");
1012
902
  }
1013
- const currentApplication = microfrontends.config.getApplication(
903
+ const currentApplication = microfrontends.getApplication(
1014
904
  process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION
1015
905
  );
1016
906
  if (!currentApplication.isDefault()) {
1017
907
  return middlewares;
1018
908
  }
1019
- const config = microfrontends.config;
1020
- const localProxyPort = microfrontends.config.getLocalProxyPort();
1021
- for (const application of config.getChildApplications()) {
909
+ const localProxyPort = microfrontends.getLocalProxyPort();
910
+ for (const application of microfrontends.getChildApplications()) {
1022
911
  for (const pathGroup of application.routing) {
1023
912
  const flagName = pathGroup.flag;
1024
913
  if (flagName) {
@@ -1048,14 +937,12 @@ function getMicrofrontendsMiddleware({
1048
937
  }
1049
938
  async function runMicrofrontendsMiddleware({
1050
939
  request,
1051
- fromApp,
1052
940
  flagValues
1053
941
  }) {
1054
942
  const pathname = request.nextUrl.pathname;
1055
943
  const middlewares = getMicrofrontendsMiddleware({
1056
944
  request,
1057
- flagValues,
1058
- fromApp
945
+ flagValues
1059
946
  });
1060
947
  for (const mware of middlewares) {
1061
948
  if (typeof mware.src === "string" ? pathname === mware.src : mware.src.test(pathname)) {