@vercel/microfrontends 1.1.1-canary.3 → 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 (60) hide show
  1. package/dist/bin/cli.cjs +225 -493
  2. package/dist/config.cjs +27 -62
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +153 -4
  5. package/dist/config.js +27 -62
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +228 -480
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +218 -470
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +258 -502
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.js +244 -488
  14. package/dist/experimental/vite.js.map +1 -1
  15. package/dist/microfrontends/server.cjs +227 -476
  16. package/dist/microfrontends/server.cjs.map +1 -1
  17. package/dist/microfrontends/server.d.ts +14 -20
  18. package/dist/microfrontends/server.js +217 -466
  19. package/dist/microfrontends/server.js.map +1 -1
  20. package/dist/next/config.cjs +229 -489
  21. package/dist/next/config.cjs.map +1 -1
  22. package/dist/next/config.js +219 -479
  23. package/dist/next/config.js.map +1 -1
  24. package/dist/next/endpoints.d.ts +2 -2
  25. package/dist/next/middleware.cjs +42 -162
  26. package/dist/next/middleware.cjs.map +1 -1
  27. package/dist/next/middleware.d.ts +2 -4
  28. package/dist/next/middleware.js +42 -162
  29. package/dist/next/middleware.js.map +1 -1
  30. package/dist/next/testing.cjs +28 -64
  31. package/dist/next/testing.cjs.map +1 -1
  32. package/dist/next/testing.d.ts +4 -4
  33. package/dist/next/testing.js +28 -64
  34. package/dist/next/testing.js.map +1 -1
  35. package/dist/overrides.d.ts +3 -3
  36. package/dist/schema.cjs +2 -9
  37. package/dist/schema.cjs.map +1 -1
  38. package/dist/schema.d.ts +3 -4
  39. package/dist/schema.js +1 -7
  40. package/dist/schema.js.map +1 -1
  41. package/dist/{types-6ee19ccc.d.ts → types-54064641.d.ts} +2 -13
  42. package/dist/{types-73527280.d.ts → types-a4add5ab.d.ts} +1 -1
  43. package/dist/{types-74e3336c.d.ts → types-f1260e44.d.ts} +1 -1
  44. package/dist/utils/mfe-port.cjs +232 -483
  45. package/dist/utils/mfe-port.cjs.map +1 -1
  46. package/dist/utils/mfe-port.js +218 -469
  47. package/dist/utils/mfe-port.js.map +1 -1
  48. package/dist/validation.cjs +0 -31
  49. package/dist/validation.cjs.map +1 -1
  50. package/dist/validation.d.ts +1 -1
  51. package/dist/validation.js +0 -31
  52. package/dist/validation.js.map +1 -1
  53. package/package.json +1 -8
  54. package/schema/schema.json +0 -33
  55. package/dist/index-7e69650e.d.ts +0 -165
  56. package/dist/microfrontends.cjs +0 -969
  57. package/dist/microfrontends.cjs.map +0 -1
  58. package/dist/microfrontends.d.ts +0 -45
  59. package/dist/microfrontends.js +0 -942
  60. package/dist/microfrontends.js.map +0 -1
@@ -4,7 +4,7 @@ import fs7 from "node:fs";
4
4
 
5
5
  // src/config/microfrontends/server/index.ts
6
6
  import fs6 from "node:fs";
7
- import { dirname as dirname3 } from "node:path";
7
+ import { dirname as dirname2 } from "node:path";
8
8
 
9
9
  // src/config/overrides/constants.ts
10
10
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
@@ -143,19 +143,177 @@ function getConfigStringFromEnv() {
143
143
  return config;
144
144
  }
145
145
 
146
- // src/config/microfrontends-config/isomorphic/index.ts
146
+ // src/config/schema/utils/is-default-app.ts
147
+ function isDefaultApp(a) {
148
+ return !("routing" in a);
149
+ }
150
+
151
+ // src/config/microfrontends/utils/find-repository-root.ts
152
+ import fs from "node:fs";
153
+ import path from "node:path";
154
+ var GIT_DIRECTORY = ".git";
155
+ function hasGitDirectory(dir) {
156
+ const gitPath = path.join(dir, GIT_DIRECTORY);
157
+ return fs.existsSync(gitPath) && fs.statSync(gitPath).isDirectory();
158
+ }
159
+ function hasPnpmWorkspaces(dir) {
160
+ return fs.existsSync(path.join(dir, "pnpm-workspace.yaml"));
161
+ }
162
+ function findRepositoryRoot(startDir) {
163
+ if (process.env.NX_WORKSPACE_ROOT) {
164
+ return process.env.NX_WORKSPACE_ROOT;
165
+ }
166
+ let currentDir = startDir || process.cwd();
167
+ while (currentDir !== path.parse(currentDir).root) {
168
+ if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
169
+ return currentDir;
170
+ }
171
+ currentDir = path.dirname(currentDir);
172
+ }
173
+ throw new Error(
174
+ "Repository root not found. Specify the root of the repository with the `repository.root` option."
175
+ );
176
+ }
177
+
178
+ // src/config/microfrontends/utils/find-default-package.ts
179
+ import { dirname } from "node:path";
180
+ import { readFileSync } from "node:fs";
147
181
  import { parse } from "jsonc-parser";
182
+ import fg from "fast-glob";
183
+
184
+ // src/config/constants.ts
185
+ var CONFIGURATION_FILENAMES = [
186
+ "microfrontends.jsonc",
187
+ "microfrontends.json"
188
+ ];
148
189
 
149
- // src/config/schema/utils/is-main-config.ts
150
- function isMainConfig(c) {
151
- return !("partOf" in c);
190
+ // src/config/microfrontends/utils/find-default-package.ts
191
+ var configCache = {};
192
+ function findDefaultMicrofrontendsPackages({
193
+ repositoryRoot,
194
+ applicationName
195
+ }) {
196
+ try {
197
+ const microfrontendsJsonPaths = fg.globSync(
198
+ `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
199
+ {
200
+ cwd: repositoryRoot,
201
+ absolute: true,
202
+ onlyFiles: true,
203
+ followSymbolicLinks: false,
204
+ ignore: ["**/node_modules/**", "**/.git/**"]
205
+ }
206
+ );
207
+ const matchingPaths = [];
208
+ for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
209
+ try {
210
+ const microfrontendsJsonContent = readFileSync(
211
+ microfrontendsJsonPath,
212
+ "utf-8"
213
+ );
214
+ const microfrontendsJson = parse(microfrontendsJsonContent);
215
+ if (microfrontendsJson.applications[applicationName]) {
216
+ matchingPaths.push(microfrontendsJsonPath);
217
+ }
218
+ } catch (error) {
219
+ }
220
+ }
221
+ if (matchingPaths.length > 1) {
222
+ throw new Error(
223
+ `Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
224
+ ${matchingPaths.join("\n \u2022 ")}`
225
+ );
226
+ }
227
+ if (matchingPaths.length === 0) {
228
+ throw new Error(
229
+ `Could not find default application with "applications.${applicationName}"`
230
+ );
231
+ }
232
+ const [packageJsonPath] = matchingPaths;
233
+ return dirname(packageJsonPath);
234
+ } catch (error) {
235
+ return null;
236
+ }
237
+ }
238
+ function findDefaultMicrofrontendsPackage(opts) {
239
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
240
+ if (configCache[cacheKey]) {
241
+ return configCache[cacheKey];
242
+ }
243
+ const result = findDefaultMicrofrontendsPackages(opts);
244
+ if (!result) {
245
+ throw new Error(
246
+ "Error trying to resolve the main microfrontends configuration"
247
+ );
248
+ }
249
+ configCache[cacheKey] = result;
250
+ return result;
152
251
  }
153
252
 
154
- // src/config/schema/utils/is-default-app.ts
155
- function isDefaultApp(a) {
156
- return !("routing" in a);
253
+ // src/config/microfrontends/utils/is-monorepo.ts
254
+ import fs2 from "node:fs";
255
+ import path2 from "node:path";
256
+ function isMonorepo({
257
+ repositoryRoot
258
+ }) {
259
+ try {
260
+ if (fs2.existsSync(path2.join(repositoryRoot, "pnpm-workspace.yaml"))) {
261
+ return true;
262
+ }
263
+ if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
264
+ return true;
265
+ }
266
+ if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
267
+ return true;
268
+ }
269
+ const packageJsonPath = path2.join(repositoryRoot, "package.json");
270
+ if (!fs2.existsSync(packageJsonPath)) {
271
+ return false;
272
+ }
273
+ const packageJson = JSON.parse(
274
+ fs2.readFileSync(packageJsonPath, "utf-8")
275
+ );
276
+ return packageJson.workspaces !== void 0;
277
+ } catch (error) {
278
+ console.error("Error determining if repository is a monorepo", error);
279
+ return false;
280
+ }
281
+ }
282
+
283
+ // src/config/microfrontends/utils/find-package-root.ts
284
+ import fs3 from "node:fs";
285
+ import path3 from "node:path";
286
+ var PACKAGE_JSON = "package.json";
287
+ function findPackageRoot(startDir) {
288
+ let currentDir = startDir || process.cwd();
289
+ while (currentDir !== path3.parse(currentDir).root) {
290
+ const pkgJsonPath = path3.join(currentDir, PACKAGE_JSON);
291
+ if (fs3.existsSync(pkgJsonPath)) {
292
+ return currentDir;
293
+ }
294
+ currentDir = path3.dirname(currentDir);
295
+ }
296
+ throw new Error(
297
+ "Package root not found. Specify the root of the package with the `package.root` option."
298
+ );
299
+ }
300
+
301
+ // src/config/microfrontends/utils/find-config.ts
302
+ import fs4 from "node:fs";
303
+ import { join } from "node:path";
304
+ function findConfig({ dir }) {
305
+ for (const filename of CONFIGURATION_FILENAMES) {
306
+ const maybeConfig = join(dir, filename);
307
+ if (fs4.existsSync(maybeConfig)) {
308
+ return maybeConfig;
309
+ }
310
+ }
311
+ return null;
157
312
  }
158
313
 
314
+ // src/config/microfrontends-config/isomorphic/index.ts
315
+ import { parse as parse2 } from "jsonc-parser";
316
+
159
317
  // src/config/microfrontends-config/client/index.ts
160
318
  import { pathToRegexp } from "path-to-regexp";
161
319
  var MicrofrontendConfigClient = class {
@@ -691,42 +849,28 @@ var MicrofrontendConfigIsomorphic = class {
691
849
  constructor({
692
850
  config,
693
851
  overrides,
694
- meta,
695
852
  opts
696
853
  }) {
697
854
  this.childApplications = {};
698
855
  MicrofrontendConfigIsomorphic.validate(config, opts);
699
856
  const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
700
857
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
701
- this.isMainConfig = isMainConfig(config);
702
- if (isMainConfig(config)) {
703
- for (const [appId, appConfig] of Object.entries(config.applications)) {
704
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
705
- if (isDefaultApp(appConfig)) {
706
- this.defaultApplication = new DefaultApplication(appId, {
707
- app: appConfig,
708
- overrides: appOverrides
709
- });
710
- } else {
711
- this.childApplications[appId] = new ChildApplication(appId, {
712
- app: appConfig,
713
- overrides: appOverrides
714
- });
715
- }
716
- }
717
- } else {
718
- this.partOf = config.partOf;
719
- const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
720
- this.childApplications[meta.fromApp] = new ChildApplication(
721
- meta.fromApp,
722
- {
723
- // we don't know routing because we're not in the main config
724
- app: { routing: [] },
858
+ let defaultApplication;
859
+ for (const [appId, appConfig] of Object.entries(config.applications)) {
860
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
861
+ if (isDefaultApp(appConfig)) {
862
+ defaultApplication = new DefaultApplication(appId, {
863
+ app: appConfig,
725
864
  overrides: appOverrides
726
- }
727
- );
865
+ });
866
+ } else {
867
+ this.childApplications[appId] = new ChildApplication(appId, {
868
+ app: appConfig,
869
+ overrides: appOverrides
870
+ });
871
+ }
728
872
  }
729
- if (isMainConfig(config) && !this.defaultApplication) {
873
+ if (!defaultApplication) {
730
874
  throw new MicrofrontendError(
731
875
  "Could not find default application in microfrontends configuration",
732
876
  {
@@ -735,34 +879,30 @@ var MicrofrontendConfigIsomorphic = class {
735
879
  }
736
880
  );
737
881
  }
882
+ this.defaultApplication = defaultApplication;
738
883
  this.config = config;
739
884
  this.options = config.options;
740
885
  this.serialized = {
741
886
  config,
742
- overrides,
743
- meta
887
+ overrides
744
888
  };
745
889
  }
746
890
  static validate(config, opts) {
747
891
  const skipValidation = opts?.skipValidation ?? [];
748
- const c = typeof config === "string" ? parse(config) : config;
749
- if (isMainConfig(c)) {
750
- validateConfigPaths(c.applications);
751
- validateConfigDefaultApplication(c.applications);
752
- if (!skipValidation.includes("deprecatedFields")) {
753
- validateDeprecatedFields(c);
754
- }
892
+ const c = typeof config === "string" ? parse2(config) : config;
893
+ validateConfigPaths(c.applications);
894
+ validateConfigDefaultApplication(c.applications);
895
+ if (!skipValidation.includes("deprecatedFields")) {
896
+ validateDeprecatedFields(c);
755
897
  }
756
898
  return c;
757
899
  }
758
900
  static fromEnv({
759
- meta,
760
901
  cookies
761
902
  }) {
762
903
  return new MicrofrontendConfigIsomorphic({
763
- config: parse(getConfigStringFromEnv()),
764
- overrides: parseOverrides(cookies ?? []),
765
- meta
904
+ config: parse2(getConfigStringFromEnv()),
905
+ overrides: parseOverrides(cookies ?? [])
766
906
  });
767
907
  }
768
908
  isOverridesDisabled() {
@@ -787,7 +927,7 @@ var MicrofrontendConfigIsomorphic = class {
787
927
  ].filter(Boolean);
788
928
  }
789
929
  getApplication(name) {
790
- if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
930
+ if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
791
931
  return this.defaultApplication;
792
932
  }
793
933
  const app = this.childApplications[name] || Object.values(this.childApplications).find(
@@ -805,7 +945,7 @@ var MicrofrontendConfigIsomorphic = class {
805
945
  return app;
806
946
  }
807
947
  getApplicationByProjectId(projectId) {
808
- if (this.defaultApplication?.projectId === projectId) {
948
+ if (this.defaultApplication.projectId === projectId) {
809
949
  return this.defaultApplication;
810
950
  }
811
951
  return Object.values(this.childApplications).find(
@@ -813,19 +953,9 @@ var MicrofrontendConfigIsomorphic = class {
813
953
  );
814
954
  }
815
955
  /**
816
- * Returns the default application. This can throw if the default application
817
- * is undefined ( )
956
+ * Returns the default application.
818
957
  */
819
958
  getDefaultApplication() {
820
- if (!this.defaultApplication) {
821
- throw new MicrofrontendError(
822
- "Could not find default application in microfrontends configuration",
823
- {
824
- type: "application",
825
- subtype: "not_found"
826
- }
827
- );
828
- }
829
959
  return this.defaultApplication;
830
960
  }
831
961
  /**
@@ -852,11 +982,9 @@ var MicrofrontendConfigIsomorphic = class {
852
982
  }
853
983
  ])
854
984
  );
855
- if (this.defaultApplication) {
856
- applications[this.defaultApplication.name] = {
857
- default: true
858
- };
859
- }
985
+ applications[this.defaultApplication.name] = {
986
+ default: true
987
+ };
860
988
  return new MicrofrontendConfigClient({
861
989
  applications
862
990
  });
@@ -866,304 +994,6 @@ var MicrofrontendConfigIsomorphic = class {
866
994
  }
867
995
  };
868
996
 
869
- // src/config/microfrontends-config/isomorphic/child.ts
870
- var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
871
- constructor({
872
- config,
873
- overrides,
874
- meta
875
- }) {
876
- super({ config, overrides, meta });
877
- this.isMainConfig = false;
878
- this.partOf = config.partOf;
879
- }
880
- };
881
-
882
- // src/config/microfrontends-config/isomorphic/main.ts
883
- var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
884
- constructor({
885
- config,
886
- overrides,
887
- meta
888
- }) {
889
- super({ config, overrides, meta });
890
- this.isMainConfig = true;
891
- const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
892
- let defaultApplication;
893
- for (const [appId, appConfig] of Object.entries(config.applications)) {
894
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
895
- if (isDefaultApp(appConfig)) {
896
- defaultApplication = new DefaultApplication(appId, {
897
- app: appConfig,
898
- overrides: appOverrides
899
- });
900
- } else {
901
- this.childApplications[appId] = new ChildApplication(appId, {
902
- app: appConfig,
903
- overrides: appOverrides
904
- });
905
- }
906
- }
907
- if (!defaultApplication) {
908
- throw new MicrofrontendError(
909
- "Could not find default application in microfrontends configuration",
910
- {
911
- type: "application",
912
- subtype: "not_found"
913
- }
914
- );
915
- }
916
- this.defaultApplication = defaultApplication;
917
- }
918
- };
919
-
920
- // src/config/microfrontends/isomorphic/index.ts
921
- var Microfrontends = class {
922
- constructor({
923
- config,
924
- overrides,
925
- meta
926
- }) {
927
- if (isMainConfig(config)) {
928
- this.config = new MicrofrontendMainConfig({ config, overrides, meta });
929
- } else {
930
- this.config = new MicrofrontendChildConfig({ config, overrides, meta });
931
- }
932
- }
933
- isChildConfig() {
934
- return this.config instanceof MicrofrontendChildConfig;
935
- }
936
- static fromEnv({
937
- cookies,
938
- meta
939
- }) {
940
- const config = MicrofrontendConfigIsomorphic.fromEnv({
941
- cookies,
942
- meta
943
- });
944
- return new Microfrontends(config.serialize());
945
- }
946
- };
947
-
948
- // src/config/microfrontends/utils/find-repository-root.ts
949
- import fs from "node:fs";
950
- import path from "node:path";
951
- var GIT_DIRECTORY = ".git";
952
- function hasGitDirectory(dir) {
953
- const gitPath = path.join(dir, GIT_DIRECTORY);
954
- return fs.existsSync(gitPath) && fs.statSync(gitPath).isDirectory();
955
- }
956
- function hasPnpmWorkspaces(dir) {
957
- return fs.existsSync(path.join(dir, "pnpm-workspace.yaml"));
958
- }
959
- function findRepositoryRoot(startDir) {
960
- if (process.env.NX_WORKSPACE_ROOT) {
961
- return process.env.NX_WORKSPACE_ROOT;
962
- }
963
- let currentDir = startDir || process.cwd();
964
- while (currentDir !== path.parse(currentDir).root) {
965
- if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
966
- return currentDir;
967
- }
968
- currentDir = path.dirname(currentDir);
969
- }
970
- throw new Error(
971
- "Repository root not found. Specify the root of the repository with the `repository.root` option."
972
- );
973
- }
974
-
975
- // src/config/microfrontends/utils/find-package-path.ts
976
- import { dirname } from "node:path";
977
- import { readFileSync } from "node:fs";
978
- import fg from "fast-glob";
979
- var configCache = {};
980
- function findPackagePathWithGlob({
981
- repositoryRoot,
982
- name
983
- }) {
984
- try {
985
- const packageJsonPaths = fg.globSync("**/package.json", {
986
- cwd: repositoryRoot,
987
- absolute: true,
988
- onlyFiles: true,
989
- followSymbolicLinks: false,
990
- ignore: ["**/node_modules/**", "**/.git/**"]
991
- });
992
- const matchingPaths = [];
993
- for (const packageJsonPath2 of packageJsonPaths) {
994
- const packageJsonContent = readFileSync(packageJsonPath2, "utf-8");
995
- const packageJson = JSON.parse(packageJsonContent);
996
- if (packageJson.name === name) {
997
- matchingPaths.push(packageJsonPath2);
998
- }
999
- }
1000
- if (matchingPaths.length > 1) {
1001
- throw new Error(
1002
- `Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
1003
- );
1004
- }
1005
- if (matchingPaths.length === 0) {
1006
- throw new Error(
1007
- `Could not find package with the name "${name}" in the repository`
1008
- );
1009
- }
1010
- const [packageJsonPath] = matchingPaths;
1011
- return dirname(packageJsonPath);
1012
- } catch (error) {
1013
- return null;
1014
- }
1015
- }
1016
- function findPackagePath(opts) {
1017
- const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
1018
- if (configCache[cacheKey]) {
1019
- return configCache[cacheKey];
1020
- }
1021
- const result = findPackagePathWithGlob(opts);
1022
- if (!result) {
1023
- throw new Error(
1024
- `Could not find package with the name "${opts.name}" in the repository`
1025
- );
1026
- }
1027
- configCache[cacheKey] = result;
1028
- return result;
1029
- }
1030
-
1031
- // src/config/microfrontends/utils/find-default-package.ts
1032
- import { dirname as dirname2 } from "node:path";
1033
- import { readFileSync as readFileSync2 } from "node:fs";
1034
- import { parse as parse2 } from "jsonc-parser";
1035
- import fg2 from "fast-glob";
1036
-
1037
- // src/config/constants.ts
1038
- var CONFIGURATION_FILENAMES = [
1039
- "microfrontends.jsonc",
1040
- "microfrontends.json"
1041
- ];
1042
-
1043
- // src/config/microfrontends/utils/find-default-package.ts
1044
- var configCache2 = {};
1045
- function findDefaultMicrofrontendsPackages({
1046
- repositoryRoot,
1047
- applicationName
1048
- }) {
1049
- try {
1050
- const microfrontendsJsonPaths = fg2.globSync(
1051
- `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
1052
- {
1053
- cwd: repositoryRoot,
1054
- absolute: true,
1055
- onlyFiles: true,
1056
- followSymbolicLinks: false,
1057
- ignore: ["**/node_modules/**", "**/.git/**"]
1058
- }
1059
- );
1060
- const matchingPaths = [];
1061
- for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
1062
- try {
1063
- const microfrontendsJsonContent = readFileSync2(
1064
- microfrontendsJsonPath,
1065
- "utf-8"
1066
- );
1067
- const microfrontendsJson = parse2(microfrontendsJsonContent);
1068
- if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
1069
- matchingPaths.push(microfrontendsJsonPath);
1070
- }
1071
- } catch (error) {
1072
- }
1073
- }
1074
- if (matchingPaths.length > 1) {
1075
- throw new Error(
1076
- `Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
1077
- ${matchingPaths.join("\n \u2022 ")}`
1078
- );
1079
- }
1080
- if (matchingPaths.length === 0) {
1081
- throw new Error(
1082
- `Could not find default application with "applications.${applicationName}"`
1083
- );
1084
- }
1085
- const [packageJsonPath] = matchingPaths;
1086
- return dirname2(packageJsonPath);
1087
- } catch (error) {
1088
- return null;
1089
- }
1090
- }
1091
- function findDefaultMicrofrontendsPackage(opts) {
1092
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
1093
- if (configCache2[cacheKey]) {
1094
- return configCache2[cacheKey];
1095
- }
1096
- const result = findDefaultMicrofrontendsPackages(opts);
1097
- if (!result) {
1098
- throw new Error(
1099
- "Error trying to resolve the main microfrontends configuration"
1100
- );
1101
- }
1102
- configCache2[cacheKey] = result;
1103
- return result;
1104
- }
1105
-
1106
- // src/config/microfrontends/utils/is-monorepo.ts
1107
- import fs2 from "node:fs";
1108
- import path2 from "node:path";
1109
- function isMonorepo({
1110
- repositoryRoot
1111
- }) {
1112
- try {
1113
- if (fs2.existsSync(path2.join(repositoryRoot, "pnpm-workspace.yaml"))) {
1114
- return true;
1115
- }
1116
- if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
1117
- return true;
1118
- }
1119
- if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
1120
- return true;
1121
- }
1122
- const packageJsonPath = path2.join(repositoryRoot, "package.json");
1123
- if (!fs2.existsSync(packageJsonPath)) {
1124
- return false;
1125
- }
1126
- const packageJson = JSON.parse(
1127
- fs2.readFileSync(packageJsonPath, "utf-8")
1128
- );
1129
- return packageJson.workspaces !== void 0;
1130
- } catch (error) {
1131
- console.error("Error determining if repository is a monorepo", error);
1132
- return false;
1133
- }
1134
- }
1135
-
1136
- // src/config/microfrontends/utils/find-package-root.ts
1137
- import fs3 from "node:fs";
1138
- import path3 from "node:path";
1139
- var PACKAGE_JSON = "package.json";
1140
- function findPackageRoot(startDir) {
1141
- let currentDir = startDir || process.cwd();
1142
- while (currentDir !== path3.parse(currentDir).root) {
1143
- const pkgJsonPath = path3.join(currentDir, PACKAGE_JSON);
1144
- if (fs3.existsSync(pkgJsonPath)) {
1145
- return currentDir;
1146
- }
1147
- currentDir = path3.dirname(currentDir);
1148
- }
1149
- throw new Error(
1150
- "Package root not found. Specify the root of the package with the `package.root` option."
1151
- );
1152
- }
1153
-
1154
- // src/config/microfrontends/utils/find-config.ts
1155
- import fs4 from "node:fs";
1156
- import { join } from "node:path";
1157
- function findConfig({ dir }) {
1158
- for (const filename of CONFIGURATION_FILENAMES) {
1159
- const maybeConfig = join(dir, filename);
1160
- if (fs4.existsSync(maybeConfig)) {
1161
- return maybeConfig;
1162
- }
1163
- }
1164
- return null;
1165
- }
1166
-
1167
997
  // src/config/microfrontends/utils/get-application-context.ts
1168
998
  import fs5 from "node:fs";
1169
999
  import path4 from "node:path";
@@ -1220,16 +1050,6 @@ var schema_default = {
1220
1050
  $ref: "#/definitions/Config",
1221
1051
  definitions: {
1222
1052
  Config: {
1223
- anyOf: [
1224
- {
1225
- $ref: "#/definitions/MainConfig"
1226
- },
1227
- {
1228
- $ref: "#/definitions/ChildConfig"
1229
- }
1230
- ]
1231
- },
1232
- MainConfig: {
1233
1053
  type: "object",
1234
1054
  properties: {
1235
1055
  $schema: {
@@ -1486,27 +1306,6 @@ var schema_default = {
1486
1306
  },
1487
1307
  required: ["paths"],
1488
1308
  additionalProperties: false
1489
- },
1490
- ChildConfig: {
1491
- type: "object",
1492
- properties: {
1493
- $schema: {
1494
- type: "string"
1495
- },
1496
- version: {
1497
- type: "string",
1498
- const: "1"
1499
- },
1500
- options: {
1501
- $ref: "#/definitions/Options"
1502
- },
1503
- partOf: {
1504
- type: "string",
1505
- description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
1506
- }
1507
- },
1508
- required: ["partOf"],
1509
- additionalProperties: false
1510
1309
  }
1511
1310
  }
1512
1311
  };
@@ -1584,7 +1383,13 @@ See https://openapi.vercel.sh/microfrontends.json for the schema.`,
1584
1383
  }
1585
1384
 
1586
1385
  // src/config/microfrontends/server/index.ts
1587
- var MicrofrontendsServer = class extends Microfrontends {
1386
+ var MicrofrontendsServer = class {
1387
+ constructor({
1388
+ config,
1389
+ overrides
1390
+ }) {
1391
+ this.config = new MicrofrontendConfigIsomorphic({ config, overrides });
1392
+ }
1588
1393
  /**
1589
1394
  * Writes the configuration to a file.
1590
1395
  */
@@ -1592,7 +1397,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1592
1397
  pretty: true
1593
1398
  }) {
1594
1399
  const outputPath = getOutputFilePath();
1595
- fs6.mkdirSync(dirname3(outputPath), { recursive: true });
1400
+ fs6.mkdirSync(dirname2(outputPath), { recursive: true });
1596
1401
  fs6.writeFileSync(
1597
1402
  outputPath,
1598
1403
  JSON.stringify(
@@ -1608,22 +1413,19 @@ var MicrofrontendsServer = class extends Microfrontends {
1608
1413
  */
1609
1414
  static fromUnknown({
1610
1415
  config,
1611
- cookies,
1612
- meta
1416
+ cookies
1613
1417
  }) {
1614
1418
  const overrides = cookies ? parseOverrides(cookies) : void 0;
1615
1419
  if (typeof config === "string") {
1616
1420
  return new MicrofrontendsServer({
1617
1421
  config: MicrofrontendsServer.validate(config),
1618
- overrides,
1619
- meta
1422
+ overrides
1620
1423
  });
1621
1424
  }
1622
1425
  if (typeof config === "object") {
1623
1426
  return new MicrofrontendsServer({
1624
1427
  config,
1625
- overrides,
1626
- meta
1428
+ overrides
1627
1429
  });
1628
1430
  }
1629
1431
  throw new MicrofrontendError(
@@ -1636,13 +1438,11 @@ var MicrofrontendsServer = class extends Microfrontends {
1636
1438
  * Uses additional validation that is only available when in a node runtime
1637
1439
  */
1638
1440
  static fromEnv({
1639
- cookies,
1640
- meta
1441
+ cookies
1641
1442
  }) {
1642
1443
  return new MicrofrontendsServer({
1643
1444
  config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
1644
- overrides: parseOverrides(cookies),
1645
- meta
1445
+ overrides: parseOverrides(cookies)
1646
1446
  });
1647
1447
  }
1648
1448
  /**
@@ -1665,29 +1465,22 @@ var MicrofrontendsServer = class extends Microfrontends {
1665
1465
  static infer({
1666
1466
  directory,
1667
1467
  filePath,
1668
- meta,
1669
- cookies,
1670
- options
1468
+ cookies
1671
1469
  } = {}) {
1672
- if (filePath && meta) {
1470
+ if (filePath) {
1673
1471
  return MicrofrontendsServer.fromFile({
1674
1472
  filePath,
1675
- cookies,
1676
- meta,
1677
- options
1473
+ cookies
1678
1474
  });
1679
1475
  }
1680
1476
  try {
1681
1477
  const packageRoot = findPackageRoot(directory);
1682
1478
  const { name: appName } = getApplicationContext({ packageRoot });
1683
- const configMeta = meta ?? { fromApp: appName };
1684
1479
  const maybeConfig = findConfig({ dir: packageRoot });
1685
1480
  if (maybeConfig) {
1686
1481
  return MicrofrontendsServer.fromFile({
1687
1482
  filePath: maybeConfig,
1688
- cookies,
1689
- meta: configMeta,
1690
- options
1483
+ cookies
1691
1484
  });
1692
1485
  }
1693
1486
  const repositoryRoot = findRepositoryRoot();
@@ -1701,9 +1494,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1701
1494
  if (maybeConfigFromDefault) {
1702
1495
  return MicrofrontendsServer.fromFile({
1703
1496
  filePath: maybeConfigFromDefault,
1704
- cookies,
1705
- meta: configMeta,
1706
- options
1497
+ cookies
1707
1498
  });
1708
1499
  }
1709
1500
  }
@@ -1723,44 +1514,14 @@ var MicrofrontendsServer = class extends Microfrontends {
1723
1514
  */
1724
1515
  static fromFile({
1725
1516
  filePath,
1726
- cookies,
1727
- meta,
1728
- options
1517
+ cookies
1729
1518
  }) {
1730
1519
  try {
1731
1520
  const configJson = fs6.readFileSync(filePath, "utf-8");
1732
1521
  const config = MicrofrontendsServer.validate(configJson);
1733
- if (!isMainConfig(config) && options?.resolveMainConfig) {
1734
- const repositoryRoot = findRepositoryRoot();
1735
- const isMonorepo2 = isMonorepo({ repositoryRoot });
1736
- if (isMonorepo2) {
1737
- const packagePath = findPackagePath({
1738
- repositoryRoot,
1739
- name: config.partOf
1740
- });
1741
- if (!packagePath) {
1742
- throw new MicrofrontendError(
1743
- `Could not find default application "${config.partOf}" in the repository`,
1744
- { type: "config", subtype: "not_found" }
1745
- );
1746
- }
1747
- const maybeConfig = findConfig({ dir: packagePath });
1748
- if (!maybeConfig) {
1749
- throw new MicrofrontendError(
1750
- `Could not find microfrontends configuration in ${packagePath}`,
1751
- { type: "config", subtype: "not_found" }
1752
- );
1753
- }
1754
- return MicrofrontendsServer.fromMainConfigFile({
1755
- filePath: maybeConfig,
1756
- overrides: cookies ? parseOverrides(cookies) : void 0
1757
- });
1758
- }
1759
- }
1760
1522
  return new MicrofrontendsServer({
1761
1523
  config,
1762
- overrides: cookies ? parseOverrides(cookies) : void 0,
1763
- meta
1524
+ overrides: cookies ? parseOverrides(cookies) : void 0
1764
1525
  });
1765
1526
  } catch (e) {
1766
1527
  throw MicrofrontendError.handle(e, {
@@ -1769,7 +1530,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1769
1530
  }
1770
1531
  }
1771
1532
  /*
1772
- * Generates a MicrofrontendMainConfig instance from a file.
1533
+ * Generates a MicrofrontendsServer instance from a file.
1773
1534
  */
1774
1535
  static fromMainConfigFile({
1775
1536
  filePath,
@@ -1778,15 +1539,6 @@ var MicrofrontendsServer = class extends Microfrontends {
1778
1539
  try {
1779
1540
  const config = fs6.readFileSync(filePath, "utf-8");
1780
1541
  const validatedConfig = MicrofrontendsServer.validate(config);
1781
- if (!isMainConfig(validatedConfig)) {
1782
- throw new MicrofrontendError(
1783
- `${filePath} is not a main microfrontend config`,
1784
- {
1785
- type: "config",
1786
- subtype: "invalid_main_path"
1787
- }
1788
- );
1789
- }
1790
1542
  const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
1791
1543
  if (!defaultApplication) {
1792
1544
  throw new MicrofrontendError(
@@ -1796,8 +1548,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1796
1548
  }
1797
1549
  return new MicrofrontendsServer({
1798
1550
  config: validatedConfig,
1799
- overrides,
1800
- meta: { fromApp: defaultApplication }
1551
+ overrides
1801
1552
  });
1802
1553
  } catch (e) {
1803
1554
  throw MicrofrontendError.handle(e, {
@@ -1835,9 +1586,7 @@ function loadConfig({
1835
1586
  let config;
1836
1587
  try {
1837
1588
  config = MicrofrontendsServer.infer({
1838
- directory: packageDir,
1839
- meta: { fromApp: appName },
1840
- options: { resolveMainConfig: true }
1589
+ directory: packageDir
1841
1590
  });
1842
1591
  } catch (e) {
1843
1592
  return void 0;