@vercel/microfrontends 0.9.0 → 0.10.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 (78) hide show
  1. package/README.md +2 -2
  2. package/dist/bin/cli.cjs +1483 -186
  3. package/dist/config/edge.cjs +47 -47
  4. package/dist/config/edge.cjs.map +1 -1
  5. package/dist/config/edge.d.ts +6 -6
  6. package/dist/config/edge.js +46 -46
  7. package/dist/config/edge.js.map +1 -1
  8. package/dist/config.cjs +66 -60
  9. package/dist/config.cjs.map +1 -1
  10. package/dist/config.d.ts +3 -3
  11. package/dist/config.js +65 -59
  12. package/dist/config.js.map +1 -1
  13. package/dist/{index-eff254d8.d.ts → index-05742bef.d.ts} +11 -22
  14. package/dist/{micro-frontend-config-42886104.d.ts → microfrontend-config-2425db74.d.ts} +12 -12
  15. package/dist/next/config.cjs +83 -77
  16. package/dist/next/config.cjs.map +1 -1
  17. package/dist/next/config.d.ts +3 -3
  18. package/dist/next/config.js +82 -76
  19. package/dist/next/config.js.map +1 -1
  20. package/dist/next/middleware.cjs +55 -55
  21. package/dist/next/middleware.cjs.map +1 -1
  22. package/dist/next/middleware.d.ts +11 -11
  23. package/dist/next/middleware.js +53 -53
  24. package/dist/next/middleware.js.map +1 -1
  25. package/dist/next/testing.cjs +79 -73
  26. package/dist/next/testing.cjs.map +1 -1
  27. package/dist/next/testing.d.ts +9 -9
  28. package/dist/next/testing.js +79 -73
  29. package/dist/next/testing.js.map +1 -1
  30. package/dist/overrides.cjs +9 -9
  31. package/dist/overrides.cjs.map +1 -1
  32. package/dist/overrides.d.ts +1 -1
  33. package/dist/overrides.js +9 -9
  34. package/dist/overrides.js.map +1 -1
  35. package/dist/types-13f3e535.d.ts +15 -0
  36. package/dist/v2/config.cjs +39 -39
  37. package/dist/v2/config.cjs.map +1 -1
  38. package/dist/v2/config.d.ts +2 -1
  39. package/dist/v2/config.js +38 -38
  40. package/dist/v2/config.js.map +1 -1
  41. package/dist/v2/microfrontends/server.cjs +102 -65
  42. package/dist/v2/microfrontends/server.cjs.map +1 -1
  43. package/dist/v2/microfrontends/server.d.ts +6 -1
  44. package/dist/v2/microfrontends/server.js +102 -65
  45. package/dist/v2/microfrontends/server.js.map +1 -1
  46. package/dist/v2/microfrontends.cjs +44 -44
  47. package/dist/v2/microfrontends.cjs.map +1 -1
  48. package/dist/v2/microfrontends.d.ts +5 -4
  49. package/dist/v2/microfrontends.js +44 -44
  50. package/dist/v2/microfrontends.js.map +1 -1
  51. package/dist/v2/next/client.cjs +1 -1
  52. package/dist/v2/next/client.cjs.map +1 -1
  53. package/dist/v2/next/client.js +1 -1
  54. package/dist/v2/next/client.js.map +1 -1
  55. package/dist/v2/next/config.cjs +120 -83
  56. package/dist/v2/next/config.cjs.map +1 -1
  57. package/dist/v2/next/config.d.ts +4 -4
  58. package/dist/v2/next/config.js +119 -82
  59. package/dist/v2/next/config.js.map +1 -1
  60. package/dist/v2/next/endpoints.cjs +5 -5
  61. package/dist/v2/next/endpoints.cjs.map +1 -1
  62. package/dist/v2/next/endpoints.js +5 -5
  63. package/dist/v2/next/endpoints.js.map +1 -1
  64. package/dist/v2/next/middleware.cjs +54 -54
  65. package/dist/v2/next/middleware.cjs.map +1 -1
  66. package/dist/v2/next/middleware.d.ts +8 -8
  67. package/dist/v2/next/middleware.js +52 -52
  68. package/dist/v2/next/middleware.js.map +1 -1
  69. package/dist/v2/overrides.cjs +75 -0
  70. package/dist/v2/overrides.cjs.map +1 -0
  71. package/dist/v2/overrides.d.ts +24 -0
  72. package/dist/v2/overrides.js +45 -0
  73. package/dist/v2/overrides.js.map +1 -0
  74. package/dist/validation.cjs +20 -20
  75. package/dist/validation.cjs.map +1 -1
  76. package/dist/validation.js +20 -20
  77. package/dist/validation.js.map +1 -1
  78. package/package.json +10 -3
@@ -40,14 +40,14 @@ function parseOverrides(cookies) {
40
40
  }
41
41
 
42
42
  // src/config-v2/errors.ts
43
- var MicroFrontendError = class extends Error {
43
+ var MicrofrontendError = class extends Error {
44
44
  constructor(message, opts) {
45
45
  super(message);
46
- this.name = "MicroFrontendsError";
47
- this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
46
+ this.name = "MicrofrontendsError";
47
+ this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
48
48
  this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
49
49
  this.subtype = opts == null ? void 0 : opts.subtype;
50
- Error.captureStackTrace(this, MicroFrontendError);
50
+ Error.captureStackTrace(this, MicrofrontendError);
51
51
  }
52
52
  isKnown() {
53
53
  return this.type !== "unknown";
@@ -56,13 +56,13 @@ var MicroFrontendError = class extends Error {
56
56
  return !this.isKnown();
57
57
  }
58
58
  /**
59
- * Converts an error to a MicroFrontendsError.
59
+ * Converts an error to a MicrofrontendsError.
60
60
  * @param original - The original error to convert.
61
- * @returns The converted MicroFrontendsError.
61
+ * @returns The converted MicrofrontendsError.
62
62
  */
63
63
  static convert(original, opts) {
64
64
  if (opts == null ? void 0 : opts.fileName) {
65
- const err = MicroFrontendError.convertFSError(original, opts.fileName);
65
+ const err = MicrofrontendError.convertFSError(original, opts.fileName);
66
66
  if (err) {
67
67
  return err;
68
68
  }
@@ -70,25 +70,25 @@ var MicroFrontendError = class extends Error {
70
70
  if (original.message.includes(
71
71
  "Code generation from strings disallowed for this context"
72
72
  )) {
73
- return new MicroFrontendError(original.message, {
73
+ return new MicrofrontendError(original.message, {
74
74
  type: "config",
75
75
  subtype: "unsupported_validation_env",
76
76
  source: "ajv"
77
77
  });
78
78
  }
79
- return new MicroFrontendError(original.message);
79
+ return new MicrofrontendError(original.message);
80
80
  }
81
81
  static convertFSError(original, fileName) {
82
82
  if (original instanceof Error && "code" in original) {
83
83
  if (original.code === "ENOENT") {
84
- return new MicroFrontendError(`Could not find "${fileName}"`, {
84
+ return new MicrofrontendError(`Could not find "${fileName}"`, {
85
85
  type: "config",
86
86
  subtype: "unable_to_read_file",
87
87
  source: "fs"
88
88
  });
89
89
  }
90
90
  if (original.code === "EACCES") {
91
- return new MicroFrontendError(
91
+ return new MicrofrontendError(
92
92
  `Permission denied while accessing "${fileName}"`,
93
93
  {
94
94
  type: "config",
@@ -99,7 +99,7 @@ var MicroFrontendError = class extends Error {
99
99
  }
100
100
  }
101
101
  if (original instanceof SyntaxError) {
102
- return new MicroFrontendError(
102
+ return new MicrofrontendError(
103
103
  `Failed to parse "${fileName}": Invalid JSON format.`,
104
104
  {
105
105
  type: "config",
@@ -111,23 +111,23 @@ var MicroFrontendError = class extends Error {
111
111
  return null;
112
112
  }
113
113
  /**
114
- * Handles an unknown error and returns a MicroFrontendsError instance.
114
+ * Handles an unknown error and returns a MicrofrontendsError instance.
115
115
  * @param err - The error to handle.
116
- * @returns A MicroFrontendsError instance.
116
+ * @returns A MicrofrontendsError instance.
117
117
  */
118
118
  static handle(err, opts) {
119
- if (err instanceof MicroFrontendError) {
119
+ if (err instanceof MicrofrontendError) {
120
120
  return err;
121
121
  }
122
122
  if (err instanceof Error) {
123
- return MicroFrontendError.convert(err, opts);
123
+ return MicrofrontendError.convert(err, opts);
124
124
  }
125
125
  if (typeof err === "object" && err !== null) {
126
126
  if ("message" in err && typeof err.message === "string") {
127
- return MicroFrontendError.convert(new Error(err.message), opts);
127
+ return MicrofrontendError.convert(new Error(err.message), opts);
128
128
  }
129
129
  }
130
- return new MicroFrontendError("An unknown error occurred");
130
+ return new MicrofrontendError("An unknown error occurred");
131
131
  }
132
132
  };
133
133
 
@@ -135,7 +135,7 @@ var MicroFrontendError = class extends Error {
135
135
  function getConfigStringFromEnv() {
136
136
  const config = process.env.MFE_CONFIG;
137
137
  if (!config) {
138
- throw new MicroFrontendError(`Missing "MFE_CONFIG" in environment.`, {
138
+ throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
139
139
  type: "config",
140
140
  subtype: "not_found_in_env"
141
141
  });
@@ -158,7 +158,7 @@ function isDefaultApp(a) {
158
158
 
159
159
  // src/config-v2/microfrontends-config/client/index.ts
160
160
  import { pathToRegexp } from "path-to-regexp";
161
- var MicroFrontendConfigClient = class {
161
+ var MicrofrontendConfigClient = class {
162
162
  constructor(config, opts) {
163
163
  this.pathCache = {};
164
164
  this.serialized = config;
@@ -172,14 +172,14 @@ var MicroFrontendConfigClient = class {
172
172
  this.applications = config.applications;
173
173
  }
174
174
  /**
175
- * Create a new `MicroFrontendConfigClient` from a JSON string.
175
+ * Create a new `MicrofrontendConfigClient` from a JSON string.
176
176
  * Config must be passed in to remain framework agnostic
177
177
  */
178
178
  static fromEnv(config, opts) {
179
179
  if (!config) {
180
- throw new Error("No micro-frontends configuration found");
180
+ throw new Error("No microfrontends configuration found");
181
181
  }
182
- return new MicroFrontendConfigClient(
182
+ return new MicrofrontendConfigClient(
183
183
  JSON.parse(config),
184
184
  opts
185
185
  );
@@ -227,7 +227,7 @@ import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to
227
227
  var SUPPORTED_VERSIONS = ["2"];
228
228
  var validateConfigVersion = (version) => {
229
229
  if (!SUPPORTED_VERSIONS.includes(version)) {
230
- throw new MicroFrontendError(
230
+ throw new MicrofrontendError(
231
231
  `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
232
232
  ", "
233
233
  )}`,
@@ -297,7 +297,7 @@ var validateConfigPaths = (applicationConfigsById) => {
297
297
  );
298
298
  });
299
299
  if (errors.length) {
300
- throw new MicroFrontendError(`Invalid paths: ${errors.join(", ")}`, {
300
+ throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
301
301
  type: "config",
302
302
  subtype: "conflicting_paths"
303
303
  });
@@ -310,13 +310,13 @@ var validateAppPaths = (name, app) => {
310
310
  continue;
311
311
  }
312
312
  if (p.endsWith("/")) {
313
- throw new MicroFrontendError(
313
+ throw new MicrofrontendError(
314
314
  `Invalid path for application "${name}". ${p} must not end with a slash.`,
315
315
  { type: "application", subtype: "invalid_path" }
316
316
  );
317
317
  }
318
318
  if (!p.startsWith("/")) {
319
- throw new MicroFrontendError(
319
+ throw new MicrofrontendError(
320
320
  `Invalid path for application "${name}". ${p} must start with a slash.`,
321
321
  { type: "application", subtype: "invalid_path" }
322
322
  );
@@ -338,13 +338,13 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
338
338
  const numApplicationsWithRouting = applicationsWithRoutingNames.length;
339
339
  const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
340
340
  if (numApplicationsWithoutRouting === 0) {
341
- throw new MicroFrontendError(
341
+ throw new MicrofrontendError(
342
342
  `No default application found. At least one application needs to be the default by omitting routing.`,
343
343
  { type: "config", subtype: "no_default_application" }
344
344
  );
345
345
  }
346
346
  if (numApplicationsWithoutRouting > 1) {
347
- throw new MicroFrontendError(
347
+ throw new MicrofrontendError(
348
348
  `Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
349
349
  { type: "config", subtype: "multiple_default_applications" }
350
350
  );
@@ -356,7 +356,7 @@ var validateConfigOptions = (options) => {
356
356
  if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
357
357
  options.vercel.previewDeploymentSuffix
358
358
  )) {
359
- throw new MicroFrontendError(
359
+ throw new MicrofrontendError(
360
360
  `Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
361
361
  { type: "config", subtype: "invalid_preview_deployment_suffix" }
362
362
  );
@@ -515,7 +515,7 @@ var ChildApplication = class extends Application {
515
515
  var DEFAULT_LOCAL_PROXY_PORT = 3024;
516
516
 
517
517
  // src/config-v2/microfrontends-config/isomorphic/index.ts
518
- var MicroFrontendConfigIsomorphic = class {
518
+ var MicrofrontendConfigIsomorphic = class {
519
519
  constructor({
520
520
  config,
521
521
  overrides,
@@ -523,7 +523,7 @@ var MicroFrontendConfigIsomorphic = class {
523
523
  }) {
524
524
  this.childApplications = {};
525
525
  var _a, _b, _c, _d;
526
- MicroFrontendConfigIsomorphic.validate(config);
526
+ MicrofrontendConfigIsomorphic.validate(config);
527
527
  const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
528
528
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
529
529
  this.isMainConfig = isMainConfig(config);
@@ -555,7 +555,7 @@ var MicroFrontendConfigIsomorphic = class {
555
555
  );
556
556
  }
557
557
  if (isMainConfig(config) && !this.defaultApplication) {
558
- throw new MicroFrontendError(
558
+ throw new MicrofrontendError(
559
559
  `Could not find default application in microfrontends configuration`,
560
560
  {
561
561
  type: "application",
@@ -585,7 +585,7 @@ var MicroFrontendConfigIsomorphic = class {
585
585
  meta,
586
586
  cookies
587
587
  }) {
588
- return new MicroFrontendConfigIsomorphic({
588
+ return new MicrofrontendConfigIsomorphic({
589
589
  config: parse(getConfigStringFromEnv()),
590
590
  overrides: parseOverrides(cookies ?? []),
591
591
  meta
@@ -620,7 +620,7 @@ var MicroFrontendConfigIsomorphic = class {
620
620
  }
621
621
  const app = this.childApplications[name];
622
622
  if (!app) {
623
- throw new MicroFrontendError(
623
+ throw new MicrofrontendError(
624
624
  `Could not find microfrontends configuration for application "${name}"`,
625
625
  {
626
626
  type: "application",
@@ -648,7 +648,7 @@ var MicroFrontendConfigIsomorphic = class {
648
648
  */
649
649
  getDefaultApplication() {
650
650
  if (!this.defaultApplication) {
651
- throw new MicroFrontendError(
651
+ throw new MicrofrontendError(
652
652
  `Could not find default application in microfrontends configuration`,
653
653
  {
654
654
  type: "application",
@@ -688,7 +688,7 @@ var MicroFrontendConfigIsomorphic = class {
688
688
  default: true
689
689
  };
690
690
  }
691
- return new MicroFrontendConfigClient({
691
+ return new MicrofrontendConfigClient({
692
692
  applications
693
693
  });
694
694
  }
@@ -698,7 +698,7 @@ var MicroFrontendConfigIsomorphic = class {
698
698
  };
699
699
 
700
700
  // src/config-v2/microfrontends-config/isomorphic/child.ts
701
- var MicroFrontendChildConfig = class extends MicroFrontendConfigIsomorphic {
701
+ var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
702
702
  constructor({
703
703
  config,
704
704
  overrides,
@@ -711,7 +711,7 @@ var MicroFrontendChildConfig = class extends MicroFrontendConfigIsomorphic {
711
711
  };
712
712
 
713
713
  // src/config-v2/microfrontends-config/isomorphic/main.ts
714
- var MicroFrontendMainConfig = class extends MicroFrontendConfigIsomorphic {
714
+ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
715
715
  constructor({
716
716
  config,
717
717
  overrides,
@@ -738,7 +738,7 @@ var MicroFrontendMainConfig = class extends MicroFrontendConfigIsomorphic {
738
738
  }
739
739
  }
740
740
  if (!defaultApplication) {
741
- throw new MicroFrontendError(
741
+ throw new MicrofrontendError(
742
742
  `Could not find default application in microfrontends configuration`,
743
743
  {
744
744
  type: "application",
@@ -758,19 +758,19 @@ var Microfrontends = class {
758
758
  meta
759
759
  }) {
760
760
  if (isMainConfig(config)) {
761
- this.config = new MicroFrontendMainConfig({ config, overrides, meta });
761
+ this.config = new MicrofrontendMainConfig({ config, overrides, meta });
762
762
  } else {
763
- this.config = new MicroFrontendChildConfig({ config, overrides, meta });
763
+ this.config = new MicrofrontendChildConfig({ config, overrides, meta });
764
764
  }
765
765
  }
766
766
  isChildConfig() {
767
- return this.config instanceof MicroFrontendChildConfig;
767
+ return this.config instanceof MicrofrontendChildConfig;
768
768
  }
769
769
  static fromEnv({
770
770
  cookies,
771
771
  meta
772
772
  }) {
773
- const config = MicroFrontendConfigIsomorphic.fromEnv({
773
+ const config = MicrofrontendConfigIsomorphic.fromEnv({
774
774
  cookies,
775
775
  meta
776
776
  });
@@ -807,14 +807,14 @@ import { parse as parse2 } from "jsonc-parser";
807
807
  import { Ajv } from "ajv";
808
808
 
809
809
  // src/config/errors.ts
810
- var MicroFrontendError2 = class extends Error {
810
+ var MicrofrontendError2 = class extends Error {
811
811
  constructor(message, opts) {
812
812
  super(message);
813
- this.name = "MicroFrontendsError";
814
- this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
813
+ this.name = "MicrofrontendsError";
814
+ this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
815
815
  this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
816
816
  this.subtype = opts == null ? void 0 : opts.subtype;
817
- Error.captureStackTrace(this, MicroFrontendError2);
817
+ Error.captureStackTrace(this, MicrofrontendError2);
818
818
  }
819
819
  isKnown() {
820
820
  return this.type !== "unknown";
@@ -823,13 +823,13 @@ var MicroFrontendError2 = class extends Error {
823
823
  return !this.isKnown();
824
824
  }
825
825
  /**
826
- * Converts an error to a MicroFrontendsError.
826
+ * Converts an error to a MicrofrontendsError.
827
827
  * @param original - The original error to convert.
828
- * @returns The converted MicroFrontendsError.
828
+ * @returns The converted MicrofrontendsError.
829
829
  */
830
830
  static convert(original, opts) {
831
831
  if (opts == null ? void 0 : opts.fileName) {
832
- const err = MicroFrontendError2.convertFSError(original, opts.fileName);
832
+ const err = MicrofrontendError2.convertFSError(original, opts.fileName);
833
833
  if (err) {
834
834
  return err;
835
835
  }
@@ -837,25 +837,25 @@ var MicroFrontendError2 = class extends Error {
837
837
  if (original.message.includes(
838
838
  "Code generation from strings disallowed for this context"
839
839
  )) {
840
- return new MicroFrontendError2(original.message, {
840
+ return new MicrofrontendError2(original.message, {
841
841
  type: "config",
842
842
  subtype: "unsupported_validation_env",
843
843
  source: "ajv"
844
844
  });
845
845
  }
846
- return new MicroFrontendError2(original.message);
846
+ return new MicrofrontendError2(original.message);
847
847
  }
848
848
  static convertFSError(original, fileName) {
849
849
  if (original instanceof Error && "code" in original) {
850
850
  if (original.code === "ENOENT") {
851
- return new MicroFrontendError2(`Could not find "${fileName}"`, {
851
+ return new MicrofrontendError2(`Could not find "${fileName}"`, {
852
852
  type: "config",
853
853
  subtype: "unable_to_read_file",
854
854
  source: "fs"
855
855
  });
856
856
  }
857
857
  if (original.code === "EACCES") {
858
- return new MicroFrontendError2(
858
+ return new MicrofrontendError2(
859
859
  `Permission denied while accessing "${fileName}"`,
860
860
  {
861
861
  type: "config",
@@ -866,7 +866,7 @@ var MicroFrontendError2 = class extends Error {
866
866
  }
867
867
  }
868
868
  if (original instanceof SyntaxError) {
869
- return new MicroFrontendError2(
869
+ return new MicrofrontendError2(
870
870
  `Failed to parse "${fileName}": Invalid JSON format.`,
871
871
  {
872
872
  type: "config",
@@ -878,23 +878,23 @@ var MicroFrontendError2 = class extends Error {
878
878
  return null;
879
879
  }
880
880
  /**
881
- * Handles an unknown error and returns a MicroFrontendsError instance.
881
+ * Handles an unknown error and returns a MicrofrontendsError instance.
882
882
  * @param err - The error to handle.
883
- * @returns A MicroFrontendsError instance.
883
+ * @returns A MicrofrontendsError instance.
884
884
  */
885
885
  static handle(err, opts) {
886
- if (err instanceof MicroFrontendError2) {
886
+ if (err instanceof MicrofrontendError2) {
887
887
  return err;
888
888
  }
889
889
  if (err instanceof Error) {
890
- return MicroFrontendError2.convert(err, opts);
890
+ return MicrofrontendError2.convert(err, opts);
891
891
  }
892
892
  if (typeof err === "object" && err !== null) {
893
893
  if ("message" in err && typeof err.message === "string") {
894
- return MicroFrontendError2.convert(new Error(err.message), opts);
894
+ return MicrofrontendError2.convert(new Error(err.message), opts);
895
895
  }
896
896
  }
897
- return new MicroFrontendError2("An unknown error occurred");
897
+ return new MicrofrontendError2("An unknown error occurred");
898
898
  }
899
899
  };
900
900
 
@@ -1172,7 +1172,7 @@ function validateSchema(configString) {
1172
1172
  const validate = ajv.compile(SCHEMA);
1173
1173
  const isValid = validate(parsedConfig);
1174
1174
  if (!isValid) {
1175
- throw new MicroFrontendError2(
1175
+ throw new MicrofrontendError2(
1176
1176
  `Invalid config: ${ajv.errorsText(validate.errors)}`,
1177
1177
  { type: "config", subtype: "does_not_match_schema" }
1178
1178
  );
@@ -1223,7 +1223,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1223
1223
  meta
1224
1224
  });
1225
1225
  }
1226
- throw new MicroFrontendError(
1226
+ throw new MicrofrontendError(
1227
1227
  "Invalid config: must be a string or an object",
1228
1228
  { type: "config", subtype: "does_not_match_schema" }
1229
1229
  );
@@ -1268,7 +1268,44 @@ var MicrofrontendsServer = class extends Microfrontends {
1268
1268
  meta
1269
1269
  });
1270
1270
  } catch (e) {
1271
- throw MicroFrontendError.handle(e, {
1271
+ throw MicrofrontendError.handle(e, {
1272
+ fileName: filePath
1273
+ });
1274
+ }
1275
+ }
1276
+ /*
1277
+ * Generates a MicrofrontendMainConfig instance from a file.
1278
+ */
1279
+ static fromMainConfigFile({
1280
+ filePath,
1281
+ overrides
1282
+ }) {
1283
+ try {
1284
+ const config = fs.readFileSync(filePath, "utf-8");
1285
+ const validatedConfig = MicrofrontendsServer.validate(config);
1286
+ if (!isMainConfig(validatedConfig)) {
1287
+ throw new MicrofrontendError(
1288
+ `${filePath} is not a main microfrontend config`,
1289
+ {
1290
+ type: "config",
1291
+ subtype: "invalid_main_path"
1292
+ }
1293
+ );
1294
+ }
1295
+ const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
1296
+ if (!defaultApplication) {
1297
+ throw new MicrofrontendError(
1298
+ `No default application found. At least one application needs to be the default by omitting routing.`,
1299
+ { type: "config", subtype: "no_default_application" }
1300
+ );
1301
+ }
1302
+ return new MicrofrontendsServer({
1303
+ config: validatedConfig,
1304
+ overrides,
1305
+ meta: { fromApp: defaultApplication }
1306
+ });
1307
+ } catch (e) {
1308
+ throw MicrofrontendError.handle(e, {
1272
1309
  fileName: filePath
1273
1310
  });
1274
1311
  }
@@ -1499,7 +1536,7 @@ function rewritesMapToArr(rewrites) {
1499
1536
  });
1500
1537
  }
1501
1538
  function transform4(args) {
1502
- const { next, microFrontend, app } = args;
1539
+ const { next, microfrontend, app } = args;
1503
1540
  const buildBeforeFiles = () => {
1504
1541
  var _a;
1505
1542
  const rewrites = /* @__PURE__ */ new Map();
@@ -1514,12 +1551,12 @@ function transform4(args) {
1514
1551
  destination: { pathname: "/_vercel/:path*" }
1515
1552
  });
1516
1553
  }
1517
- } else if (microFrontend instanceof MicroFrontendMainConfig) {
1554
+ } else if (microfrontend instanceof MicrofrontendMainConfig) {
1518
1555
  for (const [_, a] of Object.entries(
1519
- microFrontend.getChildApplications()
1556
+ microfrontend.getChildApplications()
1520
1557
  )) {
1521
1558
  const { routing } = a;
1522
- const domain = getDomainForCurrentEnvironment(microFrontend, a.name);
1559
+ const domain = getDomainForCurrentEnvironment(microfrontend, a.name);
1523
1560
  rewrites.set(`/${a.getAssetPrefix()}/:path+`, {
1524
1561
  destination: {
1525
1562
  domain,
@@ -1582,8 +1619,8 @@ function transform4(args) {
1582
1619
  var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
1583
1620
  function transform5(args) {
1584
1621
  var _a;
1585
- const { next, app, microFrontend } = args;
1586
- if (microFrontend instanceof MicroFrontendChildConfig) {
1622
+ const { next, app, microfrontend } = args;
1623
+ if (microfrontend instanceof MicrofrontendChildConfig) {
1587
1624
  console.warn(
1588
1625
  "server actions transform requires the full config - skipping"
1589
1626
  );
@@ -1591,12 +1628,12 @@ function transform5(args) {
1591
1628
  next
1592
1629
  };
1593
1630
  }
1594
- const defaultApplication = microFrontend.getDefaultApplication();
1631
+ const defaultApplication = microfrontend.getDefaultApplication();
1595
1632
  const appsToAllow = [
1596
1633
  // this zone - this is included by default unless allowedOrigins is overridden (which we are)
1597
1634
  // so we re-add it here.
1598
1635
  app,
1599
- // this is the default zone for the micro-frontend. Allow child zones to call server actions
1636
+ // this is the default zone for the microfrontend. Allow child zones to call server actions
1600
1637
  // that are in the default zone.
1601
1638
  defaultApplication
1602
1639
  ];
@@ -1613,7 +1650,7 @@ function transform5(args) {
1613
1650
  defaultApplication.production.toString()
1614
1651
  ),
1615
1652
  formatDomainForServerAction(
1616
- getDomainForCurrentEnvironment(microFrontend, a.name)
1653
+ getDomainForCurrentEnvironment(microfrontend, a.name)
1617
1654
  )
1618
1655
  ])
1619
1656
  ])
@@ -1627,7 +1664,7 @@ function transform5(args) {
1627
1664
 
1628
1665
  // src/next-v2/config/transforms/webpack.ts
1629
1666
  function transform6(args) {
1630
- const { next, microFrontend } = args;
1667
+ const { next, microfrontend } = args;
1631
1668
  const configWithWebpack = {
1632
1669
  ...next,
1633
1670
  webpack(cfg, context) {
@@ -1636,7 +1673,7 @@ function transform6(args) {
1636
1673
  if (isServer || nextRuntime === "edge") {
1637
1674
  config.plugins.push(
1638
1675
  new wpFromNext.EnvironmentPlugin({
1639
- MFE_CONFIG: JSON.stringify(microFrontend.serialize())
1676
+ MFE_CONFIG: JSON.stringify(microfrontend.serialize())
1640
1677
  })
1641
1678
  );
1642
1679
  }
@@ -1732,23 +1769,23 @@ function getApplicationContext(opts) {
1732
1769
  const packageJsonString = fs2.readFileSync("./package.json", "utf-8");
1733
1770
  const packageJson = JSON.parse(packageJsonString);
1734
1771
  if (!packageJson.name) {
1735
- throw new MicroFrontendError(
1772
+ throw new MicrofrontendError(
1736
1773
  `package.json file missing required field "name"`,
1737
1774
  {
1738
1775
  type: "packageJson",
1739
1776
  subtype: "missing_field_name",
1740
- source: "@vercel/micro-frontends/next"
1777
+ source: "@vercel/microfrontends/next"
1741
1778
  }
1742
1779
  );
1743
1780
  }
1744
1781
  return { name: packageJson.name };
1745
1782
  } catch (err) {
1746
- throw MicroFrontendError.handle(err, {
1783
+ throw MicrofrontendError.handle(err, {
1747
1784
  fileName: "package.json"
1748
1785
  });
1749
1786
  }
1750
1787
  }
1751
- function withMicroFrontends(nextConfig, opts) {
1788
+ function withMicrofrontends(nextConfig, opts) {
1752
1789
  var _a;
1753
1790
  if (opts == null ? void 0 : opts.debug) {
1754
1791
  process.env.MFE_DEBUG = "true";
@@ -1772,7 +1809,7 @@ function withMicroFrontends(nextConfig, opts) {
1772
1809
  const transformedConfig = transform7({
1773
1810
  app,
1774
1811
  next,
1775
- microFrontend: microfrontends.config,
1812
+ microfrontend: microfrontends.config,
1776
1813
  opts: {
1777
1814
  isProduction: isProduction(opts)
1778
1815
  }
@@ -1789,6 +1826,6 @@ function withMicroFrontends(nextConfig, opts) {
1789
1826
  return next;
1790
1827
  }
1791
1828
  export {
1792
- withMicroFrontends
1829
+ withMicrofrontends
1793
1830
  };
1794
1831
  //# sourceMappingURL=config.js.map