@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
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/next-v2/config/index.ts
31
31
  var config_exports = {};
32
32
  __export(config_exports, {
33
- withMicroFrontends: () => withMicroFrontends
33
+ withMicrofrontends: () => withMicrofrontends
34
34
  });
35
35
  module.exports = __toCommonJS(config_exports);
36
36
  var import_node_fs2 = __toESM(require("fs"), 1);
@@ -74,14 +74,14 @@ function parseOverrides(cookies) {
74
74
  }
75
75
 
76
76
  // src/config-v2/errors.ts
77
- var MicroFrontendError = class extends Error {
77
+ var MicrofrontendError = class extends Error {
78
78
  constructor(message, opts) {
79
79
  super(message);
80
- this.name = "MicroFrontendsError";
81
- this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
80
+ this.name = "MicrofrontendsError";
81
+ this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
82
82
  this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
83
83
  this.subtype = opts == null ? void 0 : opts.subtype;
84
- Error.captureStackTrace(this, MicroFrontendError);
84
+ Error.captureStackTrace(this, MicrofrontendError);
85
85
  }
86
86
  isKnown() {
87
87
  return this.type !== "unknown";
@@ -90,13 +90,13 @@ var MicroFrontendError = class extends Error {
90
90
  return !this.isKnown();
91
91
  }
92
92
  /**
93
- * Converts an error to a MicroFrontendsError.
93
+ * Converts an error to a MicrofrontendsError.
94
94
  * @param original - The original error to convert.
95
- * @returns The converted MicroFrontendsError.
95
+ * @returns The converted MicrofrontendsError.
96
96
  */
97
97
  static convert(original, opts) {
98
98
  if (opts == null ? void 0 : opts.fileName) {
99
- const err = MicroFrontendError.convertFSError(original, opts.fileName);
99
+ const err = MicrofrontendError.convertFSError(original, opts.fileName);
100
100
  if (err) {
101
101
  return err;
102
102
  }
@@ -104,25 +104,25 @@ var MicroFrontendError = class extends Error {
104
104
  if (original.message.includes(
105
105
  "Code generation from strings disallowed for this context"
106
106
  )) {
107
- return new MicroFrontendError(original.message, {
107
+ return new MicrofrontendError(original.message, {
108
108
  type: "config",
109
109
  subtype: "unsupported_validation_env",
110
110
  source: "ajv"
111
111
  });
112
112
  }
113
- return new MicroFrontendError(original.message);
113
+ return new MicrofrontendError(original.message);
114
114
  }
115
115
  static convertFSError(original, fileName) {
116
116
  if (original instanceof Error && "code" in original) {
117
117
  if (original.code === "ENOENT") {
118
- return new MicroFrontendError(`Could not find "${fileName}"`, {
118
+ return new MicrofrontendError(`Could not find "${fileName}"`, {
119
119
  type: "config",
120
120
  subtype: "unable_to_read_file",
121
121
  source: "fs"
122
122
  });
123
123
  }
124
124
  if (original.code === "EACCES") {
125
- return new MicroFrontendError(
125
+ return new MicrofrontendError(
126
126
  `Permission denied while accessing "${fileName}"`,
127
127
  {
128
128
  type: "config",
@@ -133,7 +133,7 @@ var MicroFrontendError = class extends Error {
133
133
  }
134
134
  }
135
135
  if (original instanceof SyntaxError) {
136
- return new MicroFrontendError(
136
+ return new MicrofrontendError(
137
137
  `Failed to parse "${fileName}": Invalid JSON format.`,
138
138
  {
139
139
  type: "config",
@@ -145,23 +145,23 @@ var MicroFrontendError = class extends Error {
145
145
  return null;
146
146
  }
147
147
  /**
148
- * Handles an unknown error and returns a MicroFrontendsError instance.
148
+ * Handles an unknown error and returns a MicrofrontendsError instance.
149
149
  * @param err - The error to handle.
150
- * @returns A MicroFrontendsError instance.
150
+ * @returns A MicrofrontendsError instance.
151
151
  */
152
152
  static handle(err, opts) {
153
- if (err instanceof MicroFrontendError) {
153
+ if (err instanceof MicrofrontendError) {
154
154
  return err;
155
155
  }
156
156
  if (err instanceof Error) {
157
- return MicroFrontendError.convert(err, opts);
157
+ return MicrofrontendError.convert(err, opts);
158
158
  }
159
159
  if (typeof err === "object" && err !== null) {
160
160
  if ("message" in err && typeof err.message === "string") {
161
- return MicroFrontendError.convert(new Error(err.message), opts);
161
+ return MicrofrontendError.convert(new Error(err.message), opts);
162
162
  }
163
163
  }
164
- return new MicroFrontendError("An unknown error occurred");
164
+ return new MicrofrontendError("An unknown error occurred");
165
165
  }
166
166
  };
167
167
 
@@ -169,7 +169,7 @@ var MicroFrontendError = class extends Error {
169
169
  function getConfigStringFromEnv() {
170
170
  const config = process.env.MFE_CONFIG;
171
171
  if (!config) {
172
- throw new MicroFrontendError(`Missing "MFE_CONFIG" in environment.`, {
172
+ throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
173
173
  type: "config",
174
174
  subtype: "not_found_in_env"
175
175
  });
@@ -192,7 +192,7 @@ function isDefaultApp(a) {
192
192
 
193
193
  // src/config-v2/microfrontends-config/client/index.ts
194
194
  var import_path_to_regexp = require("path-to-regexp");
195
- var MicroFrontendConfigClient = class {
195
+ var MicrofrontendConfigClient = class {
196
196
  constructor(config, opts) {
197
197
  this.pathCache = {};
198
198
  this.serialized = config;
@@ -206,14 +206,14 @@ var MicroFrontendConfigClient = class {
206
206
  this.applications = config.applications;
207
207
  }
208
208
  /**
209
- * Create a new `MicroFrontendConfigClient` from a JSON string.
209
+ * Create a new `MicrofrontendConfigClient` from a JSON string.
210
210
  * Config must be passed in to remain framework agnostic
211
211
  */
212
212
  static fromEnv(config, opts) {
213
213
  if (!config) {
214
- throw new Error("No micro-frontends configuration found");
214
+ throw new Error("No microfrontends configuration found");
215
215
  }
216
- return new MicroFrontendConfigClient(
216
+ return new MicrofrontendConfigClient(
217
217
  JSON.parse(config),
218
218
  opts
219
219
  );
@@ -261,7 +261,7 @@ var import_path_to_regexp2 = require("path-to-regexp");
261
261
  var SUPPORTED_VERSIONS = ["2"];
262
262
  var validateConfigVersion = (version) => {
263
263
  if (!SUPPORTED_VERSIONS.includes(version)) {
264
- throw new MicroFrontendError(
264
+ throw new MicrofrontendError(
265
265
  `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
266
266
  ", "
267
267
  )}`,
@@ -331,7 +331,7 @@ var validateConfigPaths = (applicationConfigsById) => {
331
331
  );
332
332
  });
333
333
  if (errors.length) {
334
- throw new MicroFrontendError(`Invalid paths: ${errors.join(", ")}`, {
334
+ throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
335
335
  type: "config",
336
336
  subtype: "conflicting_paths"
337
337
  });
@@ -344,13 +344,13 @@ var validateAppPaths = (name, app) => {
344
344
  continue;
345
345
  }
346
346
  if (p.endsWith("/")) {
347
- throw new MicroFrontendError(
347
+ throw new MicrofrontendError(
348
348
  `Invalid path for application "${name}". ${p} must not end with a slash.`,
349
349
  { type: "application", subtype: "invalid_path" }
350
350
  );
351
351
  }
352
352
  if (!p.startsWith("/")) {
353
- throw new MicroFrontendError(
353
+ throw new MicrofrontendError(
354
354
  `Invalid path for application "${name}". ${p} must start with a slash.`,
355
355
  { type: "application", subtype: "invalid_path" }
356
356
  );
@@ -372,13 +372,13 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
372
372
  const numApplicationsWithRouting = applicationsWithRoutingNames.length;
373
373
  const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
374
374
  if (numApplicationsWithoutRouting === 0) {
375
- throw new MicroFrontendError(
375
+ throw new MicrofrontendError(
376
376
  `No default application found. At least one application needs to be the default by omitting routing.`,
377
377
  { type: "config", subtype: "no_default_application" }
378
378
  );
379
379
  }
380
380
  if (numApplicationsWithoutRouting > 1) {
381
- throw new MicroFrontendError(
381
+ throw new MicrofrontendError(
382
382
  `Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
383
383
  { type: "config", subtype: "multiple_default_applications" }
384
384
  );
@@ -390,7 +390,7 @@ var validateConfigOptions = (options) => {
390
390
  if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
391
391
  options.vercel.previewDeploymentSuffix
392
392
  )) {
393
- throw new MicroFrontendError(
393
+ throw new MicrofrontendError(
394
394
  `Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
395
395
  { type: "config", subtype: "invalid_preview_deployment_suffix" }
396
396
  );
@@ -549,7 +549,7 @@ var ChildApplication = class extends Application {
549
549
  var DEFAULT_LOCAL_PROXY_PORT = 3024;
550
550
 
551
551
  // src/config-v2/microfrontends-config/isomorphic/index.ts
552
- var MicroFrontendConfigIsomorphic = class {
552
+ var MicrofrontendConfigIsomorphic = class {
553
553
  constructor({
554
554
  config,
555
555
  overrides,
@@ -557,7 +557,7 @@ var MicroFrontendConfigIsomorphic = class {
557
557
  }) {
558
558
  this.childApplications = {};
559
559
  var _a, _b, _c, _d;
560
- MicroFrontendConfigIsomorphic.validate(config);
560
+ MicrofrontendConfigIsomorphic.validate(config);
561
561
  const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
562
562
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
563
563
  this.isMainConfig = isMainConfig(config);
@@ -589,7 +589,7 @@ var MicroFrontendConfigIsomorphic = class {
589
589
  );
590
590
  }
591
591
  if (isMainConfig(config) && !this.defaultApplication) {
592
- throw new MicroFrontendError(
592
+ throw new MicrofrontendError(
593
593
  `Could not find default application in microfrontends configuration`,
594
594
  {
595
595
  type: "application",
@@ -619,7 +619,7 @@ var MicroFrontendConfigIsomorphic = class {
619
619
  meta,
620
620
  cookies
621
621
  }) {
622
- return new MicroFrontendConfigIsomorphic({
622
+ return new MicrofrontendConfigIsomorphic({
623
623
  config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
624
624
  overrides: parseOverrides(cookies ?? []),
625
625
  meta
@@ -654,7 +654,7 @@ var MicroFrontendConfigIsomorphic = class {
654
654
  }
655
655
  const app = this.childApplications[name];
656
656
  if (!app) {
657
- throw new MicroFrontendError(
657
+ throw new MicrofrontendError(
658
658
  `Could not find microfrontends configuration for application "${name}"`,
659
659
  {
660
660
  type: "application",
@@ -682,7 +682,7 @@ var MicroFrontendConfigIsomorphic = class {
682
682
  */
683
683
  getDefaultApplication() {
684
684
  if (!this.defaultApplication) {
685
- throw new MicroFrontendError(
685
+ throw new MicrofrontendError(
686
686
  `Could not find default application in microfrontends configuration`,
687
687
  {
688
688
  type: "application",
@@ -722,7 +722,7 @@ var MicroFrontendConfigIsomorphic = class {
722
722
  default: true
723
723
  };
724
724
  }
725
- return new MicroFrontendConfigClient({
725
+ return new MicrofrontendConfigClient({
726
726
  applications
727
727
  });
728
728
  }
@@ -732,7 +732,7 @@ var MicroFrontendConfigIsomorphic = class {
732
732
  };
733
733
 
734
734
  // src/config-v2/microfrontends-config/isomorphic/child.ts
735
- var MicroFrontendChildConfig = class extends MicroFrontendConfigIsomorphic {
735
+ var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
736
736
  constructor({
737
737
  config,
738
738
  overrides,
@@ -745,7 +745,7 @@ var MicroFrontendChildConfig = class extends MicroFrontendConfigIsomorphic {
745
745
  };
746
746
 
747
747
  // src/config-v2/microfrontends-config/isomorphic/main.ts
748
- var MicroFrontendMainConfig = class extends MicroFrontendConfigIsomorphic {
748
+ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
749
749
  constructor({
750
750
  config,
751
751
  overrides,
@@ -772,7 +772,7 @@ var MicroFrontendMainConfig = class extends MicroFrontendConfigIsomorphic {
772
772
  }
773
773
  }
774
774
  if (!defaultApplication) {
775
- throw new MicroFrontendError(
775
+ throw new MicrofrontendError(
776
776
  `Could not find default application in microfrontends configuration`,
777
777
  {
778
778
  type: "application",
@@ -792,19 +792,19 @@ var Microfrontends = class {
792
792
  meta
793
793
  }) {
794
794
  if (isMainConfig(config)) {
795
- this.config = new MicroFrontendMainConfig({ config, overrides, meta });
795
+ this.config = new MicrofrontendMainConfig({ config, overrides, meta });
796
796
  } else {
797
- this.config = new MicroFrontendChildConfig({ config, overrides, meta });
797
+ this.config = new MicrofrontendChildConfig({ config, overrides, meta });
798
798
  }
799
799
  }
800
800
  isChildConfig() {
801
- return this.config instanceof MicroFrontendChildConfig;
801
+ return this.config instanceof MicrofrontendChildConfig;
802
802
  }
803
803
  static fromEnv({
804
804
  cookies,
805
805
  meta
806
806
  }) {
807
- const config = MicroFrontendConfigIsomorphic.fromEnv({
807
+ const config = MicrofrontendConfigIsomorphic.fromEnv({
808
808
  cookies,
809
809
  meta
810
810
  });
@@ -841,14 +841,14 @@ var import_jsonc_parser2 = require("jsonc-parser");
841
841
  var import_ajv = require("ajv");
842
842
 
843
843
  // src/config/errors.ts
844
- var MicroFrontendError2 = class extends Error {
844
+ var MicrofrontendError2 = class extends Error {
845
845
  constructor(message, opts) {
846
846
  super(message);
847
- this.name = "MicroFrontendsError";
848
- this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
847
+ this.name = "MicrofrontendsError";
848
+ this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
849
849
  this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
850
850
  this.subtype = opts == null ? void 0 : opts.subtype;
851
- Error.captureStackTrace(this, MicroFrontendError2);
851
+ Error.captureStackTrace(this, MicrofrontendError2);
852
852
  }
853
853
  isKnown() {
854
854
  return this.type !== "unknown";
@@ -857,13 +857,13 @@ var MicroFrontendError2 = class extends Error {
857
857
  return !this.isKnown();
858
858
  }
859
859
  /**
860
- * Converts an error to a MicroFrontendsError.
860
+ * Converts an error to a MicrofrontendsError.
861
861
  * @param original - The original error to convert.
862
- * @returns The converted MicroFrontendsError.
862
+ * @returns The converted MicrofrontendsError.
863
863
  */
864
864
  static convert(original, opts) {
865
865
  if (opts == null ? void 0 : opts.fileName) {
866
- const err = MicroFrontendError2.convertFSError(original, opts.fileName);
866
+ const err = MicrofrontendError2.convertFSError(original, opts.fileName);
867
867
  if (err) {
868
868
  return err;
869
869
  }
@@ -871,25 +871,25 @@ var MicroFrontendError2 = class extends Error {
871
871
  if (original.message.includes(
872
872
  "Code generation from strings disallowed for this context"
873
873
  )) {
874
- return new MicroFrontendError2(original.message, {
874
+ return new MicrofrontendError2(original.message, {
875
875
  type: "config",
876
876
  subtype: "unsupported_validation_env",
877
877
  source: "ajv"
878
878
  });
879
879
  }
880
- return new MicroFrontendError2(original.message);
880
+ return new MicrofrontendError2(original.message);
881
881
  }
882
882
  static convertFSError(original, fileName) {
883
883
  if (original instanceof Error && "code" in original) {
884
884
  if (original.code === "ENOENT") {
885
- return new MicroFrontendError2(`Could not find "${fileName}"`, {
885
+ return new MicrofrontendError2(`Could not find "${fileName}"`, {
886
886
  type: "config",
887
887
  subtype: "unable_to_read_file",
888
888
  source: "fs"
889
889
  });
890
890
  }
891
891
  if (original.code === "EACCES") {
892
- return new MicroFrontendError2(
892
+ return new MicrofrontendError2(
893
893
  `Permission denied while accessing "${fileName}"`,
894
894
  {
895
895
  type: "config",
@@ -900,7 +900,7 @@ var MicroFrontendError2 = class extends Error {
900
900
  }
901
901
  }
902
902
  if (original instanceof SyntaxError) {
903
- return new MicroFrontendError2(
903
+ return new MicrofrontendError2(
904
904
  `Failed to parse "${fileName}": Invalid JSON format.`,
905
905
  {
906
906
  type: "config",
@@ -912,23 +912,23 @@ var MicroFrontendError2 = class extends Error {
912
912
  return null;
913
913
  }
914
914
  /**
915
- * Handles an unknown error and returns a MicroFrontendsError instance.
915
+ * Handles an unknown error and returns a MicrofrontendsError instance.
916
916
  * @param err - The error to handle.
917
- * @returns A MicroFrontendsError instance.
917
+ * @returns A MicrofrontendsError instance.
918
918
  */
919
919
  static handle(err, opts) {
920
- if (err instanceof MicroFrontendError2) {
920
+ if (err instanceof MicrofrontendError2) {
921
921
  return err;
922
922
  }
923
923
  if (err instanceof Error) {
924
- return MicroFrontendError2.convert(err, opts);
924
+ return MicrofrontendError2.convert(err, opts);
925
925
  }
926
926
  if (typeof err === "object" && err !== null) {
927
927
  if ("message" in err && typeof err.message === "string") {
928
- return MicroFrontendError2.convert(new Error(err.message), opts);
928
+ return MicrofrontendError2.convert(new Error(err.message), opts);
929
929
  }
930
930
  }
931
- return new MicroFrontendError2("An unknown error occurred");
931
+ return new MicrofrontendError2("An unknown error occurred");
932
932
  }
933
933
  };
934
934
 
@@ -1206,7 +1206,7 @@ function validateSchema(configString) {
1206
1206
  const validate = ajv.compile(SCHEMA);
1207
1207
  const isValid = validate(parsedConfig);
1208
1208
  if (!isValid) {
1209
- throw new MicroFrontendError2(
1209
+ throw new MicrofrontendError2(
1210
1210
  `Invalid config: ${ajv.errorsText(validate.errors)}`,
1211
1211
  { type: "config", subtype: "does_not_match_schema" }
1212
1212
  );
@@ -1257,7 +1257,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1257
1257
  meta
1258
1258
  });
1259
1259
  }
1260
- throw new MicroFrontendError(
1260
+ throw new MicrofrontendError(
1261
1261
  "Invalid config: must be a string or an object",
1262
1262
  { type: "config", subtype: "does_not_match_schema" }
1263
1263
  );
@@ -1302,7 +1302,44 @@ var MicrofrontendsServer = class extends Microfrontends {
1302
1302
  meta
1303
1303
  });
1304
1304
  } catch (e) {
1305
- throw MicroFrontendError.handle(e, {
1305
+ throw MicrofrontendError.handle(e, {
1306
+ fileName: filePath
1307
+ });
1308
+ }
1309
+ }
1310
+ /*
1311
+ * Generates a MicrofrontendMainConfig instance from a file.
1312
+ */
1313
+ static fromMainConfigFile({
1314
+ filePath,
1315
+ overrides
1316
+ }) {
1317
+ try {
1318
+ const config = import_node_fs.default.readFileSync(filePath, "utf-8");
1319
+ const validatedConfig = MicrofrontendsServer.validate(config);
1320
+ if (!isMainConfig(validatedConfig)) {
1321
+ throw new MicrofrontendError(
1322
+ `${filePath} is not a main microfrontend config`,
1323
+ {
1324
+ type: "config",
1325
+ subtype: "invalid_main_path"
1326
+ }
1327
+ );
1328
+ }
1329
+ const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
1330
+ if (!defaultApplication) {
1331
+ throw new MicrofrontendError(
1332
+ `No default application found. At least one application needs to be the default by omitting routing.`,
1333
+ { type: "config", subtype: "no_default_application" }
1334
+ );
1335
+ }
1336
+ return new MicrofrontendsServer({
1337
+ config: validatedConfig,
1338
+ overrides,
1339
+ meta: { fromApp: defaultApplication }
1340
+ });
1341
+ } catch (e) {
1342
+ throw MicrofrontendError.handle(e, {
1306
1343
  fileName: filePath
1307
1344
  });
1308
1345
  }
@@ -1533,7 +1570,7 @@ function rewritesMapToArr(rewrites) {
1533
1570
  });
1534
1571
  }
1535
1572
  function transform4(args) {
1536
- const { next, microFrontend, app } = args;
1573
+ const { next, microfrontend, app } = args;
1537
1574
  const buildBeforeFiles = () => {
1538
1575
  var _a;
1539
1576
  const rewrites = /* @__PURE__ */ new Map();
@@ -1548,12 +1585,12 @@ function transform4(args) {
1548
1585
  destination: { pathname: "/_vercel/:path*" }
1549
1586
  });
1550
1587
  }
1551
- } else if (microFrontend instanceof MicroFrontendMainConfig) {
1588
+ } else if (microfrontend instanceof MicrofrontendMainConfig) {
1552
1589
  for (const [_, a] of Object.entries(
1553
- microFrontend.getChildApplications()
1590
+ microfrontend.getChildApplications()
1554
1591
  )) {
1555
1592
  const { routing } = a;
1556
- const domain = getDomainForCurrentEnvironment(microFrontend, a.name);
1593
+ const domain = getDomainForCurrentEnvironment(microfrontend, a.name);
1557
1594
  rewrites.set(`/${a.getAssetPrefix()}/:path+`, {
1558
1595
  destination: {
1559
1596
  domain,
@@ -1616,8 +1653,8 @@ function transform4(args) {
1616
1653
  var formatDomainForServerAction = (domain) => domain.replace(/https?:\/\//, "");
1617
1654
  function transform5(args) {
1618
1655
  var _a;
1619
- const { next, app, microFrontend } = args;
1620
- if (microFrontend instanceof MicroFrontendChildConfig) {
1656
+ const { next, app, microfrontend } = args;
1657
+ if (microfrontend instanceof MicrofrontendChildConfig) {
1621
1658
  console.warn(
1622
1659
  "server actions transform requires the full config - skipping"
1623
1660
  );
@@ -1625,12 +1662,12 @@ function transform5(args) {
1625
1662
  next
1626
1663
  };
1627
1664
  }
1628
- const defaultApplication = microFrontend.getDefaultApplication();
1665
+ const defaultApplication = microfrontend.getDefaultApplication();
1629
1666
  const appsToAllow = [
1630
1667
  // this zone - this is included by default unless allowedOrigins is overridden (which we are)
1631
1668
  // so we re-add it here.
1632
1669
  app,
1633
- // this is the default zone for the micro-frontend. Allow child zones to call server actions
1670
+ // this is the default zone for the microfrontend. Allow child zones to call server actions
1634
1671
  // that are in the default zone.
1635
1672
  defaultApplication
1636
1673
  ];
@@ -1647,7 +1684,7 @@ function transform5(args) {
1647
1684
  defaultApplication.production.toString()
1648
1685
  ),
1649
1686
  formatDomainForServerAction(
1650
- getDomainForCurrentEnvironment(microFrontend, a.name)
1687
+ getDomainForCurrentEnvironment(microfrontend, a.name)
1651
1688
  )
1652
1689
  ])
1653
1690
  ])
@@ -1661,7 +1698,7 @@ function transform5(args) {
1661
1698
 
1662
1699
  // src/next-v2/config/transforms/webpack.ts
1663
1700
  function transform6(args) {
1664
- const { next, microFrontend } = args;
1701
+ const { next, microfrontend } = args;
1665
1702
  const configWithWebpack = {
1666
1703
  ...next,
1667
1704
  webpack(cfg, context) {
@@ -1670,7 +1707,7 @@ function transform6(args) {
1670
1707
  if (isServer || nextRuntime === "edge") {
1671
1708
  config.plugins.push(
1672
1709
  new wpFromNext.EnvironmentPlugin({
1673
- MFE_CONFIG: JSON.stringify(microFrontend.serialize())
1710
+ MFE_CONFIG: JSON.stringify(microfrontend.serialize())
1674
1711
  })
1675
1712
  );
1676
1713
  }
@@ -1766,23 +1803,23 @@ function getApplicationContext(opts) {
1766
1803
  const packageJsonString = import_node_fs2.default.readFileSync("./package.json", "utf-8");
1767
1804
  const packageJson = JSON.parse(packageJsonString);
1768
1805
  if (!packageJson.name) {
1769
- throw new MicroFrontendError(
1806
+ throw new MicrofrontendError(
1770
1807
  `package.json file missing required field "name"`,
1771
1808
  {
1772
1809
  type: "packageJson",
1773
1810
  subtype: "missing_field_name",
1774
- source: "@vercel/micro-frontends/next"
1811
+ source: "@vercel/microfrontends/next"
1775
1812
  }
1776
1813
  );
1777
1814
  }
1778
1815
  return { name: packageJson.name };
1779
1816
  } catch (err) {
1780
- throw MicroFrontendError.handle(err, {
1817
+ throw MicrofrontendError.handle(err, {
1781
1818
  fileName: "package.json"
1782
1819
  });
1783
1820
  }
1784
1821
  }
1785
- function withMicroFrontends(nextConfig, opts) {
1822
+ function withMicrofrontends(nextConfig, opts) {
1786
1823
  var _a;
1787
1824
  if (opts == null ? void 0 : opts.debug) {
1788
1825
  process.env.MFE_DEBUG = "true";
@@ -1806,7 +1843,7 @@ function withMicroFrontends(nextConfig, opts) {
1806
1843
  const transformedConfig = transform7({
1807
1844
  app,
1808
1845
  next,
1809
- microFrontend: microfrontends.config,
1846
+ microfrontend: microfrontends.config,
1810
1847
  opts: {
1811
1848
  isProduction: isProduction(opts)
1812
1849
  }
@@ -1824,6 +1861,6 @@ function withMicroFrontends(nextConfig, opts) {
1824
1861
  }
1825
1862
  // Annotate the CommonJS export names for ESM import in node:
1826
1863
  0 && (module.exports = {
1827
- withMicroFrontends
1864
+ withMicrofrontends
1828
1865
  });
1829
1866
  //# sourceMappingURL=config.cjs.map