@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
@@ -33,8 +33,8 @@ __export(server_exports, {
33
33
  MicrofrontendsServer: () => MicrofrontendsServer
34
34
  });
35
35
  module.exports = __toCommonJS(server_exports);
36
- var import_node_fs8 = __toESM(require("fs"), 1);
37
- var import_node_path9 = require("path");
36
+ var import_node_fs7 = __toESM(require("fs"), 1);
37
+ var import_node_path8 = require("path");
38
38
 
39
39
  // src/config/overrides/constants.ts
40
40
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
@@ -173,19 +173,177 @@ function getConfigStringFromEnv() {
173
173
  return config;
174
174
  }
175
175
 
176
- // src/config/microfrontends-config/isomorphic/index.ts
176
+ // src/config/schema/utils/is-default-app.ts
177
+ function isDefaultApp(a) {
178
+ return !("routing" in a);
179
+ }
180
+
181
+ // src/config/microfrontends/utils/find-repository-root.ts
182
+ var import_node_fs = __toESM(require("fs"), 1);
183
+ var import_node_path = __toESM(require("path"), 1);
184
+ var GIT_DIRECTORY = ".git";
185
+ function hasGitDirectory(dir) {
186
+ const gitPath = import_node_path.default.join(dir, GIT_DIRECTORY);
187
+ return import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory();
188
+ }
189
+ function hasPnpmWorkspaces(dir) {
190
+ return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
191
+ }
192
+ function findRepositoryRoot(startDir) {
193
+ if (process.env.NX_WORKSPACE_ROOT) {
194
+ return process.env.NX_WORKSPACE_ROOT;
195
+ }
196
+ let currentDir = startDir || process.cwd();
197
+ while (currentDir !== import_node_path.default.parse(currentDir).root) {
198
+ if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
199
+ return currentDir;
200
+ }
201
+ currentDir = import_node_path.default.dirname(currentDir);
202
+ }
203
+ throw new Error(
204
+ "Repository root not found. Specify the root of the repository with the `repository.root` option."
205
+ );
206
+ }
207
+
208
+ // src/config/microfrontends/utils/find-default-package.ts
209
+ var import_node_path2 = require("path");
210
+ var import_node_fs2 = require("fs");
177
211
  var import_jsonc_parser = require("jsonc-parser");
212
+ var import_fast_glob = __toESM(require("fast-glob"), 1);
178
213
 
179
- // src/config/schema/utils/is-main-config.ts
180
- function isMainConfig(c) {
181
- return !("partOf" in c);
214
+ // src/config/constants.ts
215
+ var CONFIGURATION_FILENAMES = [
216
+ "microfrontends.jsonc",
217
+ "microfrontends.json"
218
+ ];
219
+
220
+ // src/config/microfrontends/utils/find-default-package.ts
221
+ var configCache = {};
222
+ function findDefaultMicrofrontendsPackages({
223
+ repositoryRoot,
224
+ applicationName
225
+ }) {
226
+ try {
227
+ const microfrontendsJsonPaths = import_fast_glob.default.globSync(
228
+ `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
229
+ {
230
+ cwd: repositoryRoot,
231
+ absolute: true,
232
+ onlyFiles: true,
233
+ followSymbolicLinks: false,
234
+ ignore: ["**/node_modules/**", "**/.git/**"]
235
+ }
236
+ );
237
+ const matchingPaths = [];
238
+ for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
239
+ try {
240
+ const microfrontendsJsonContent = (0, import_node_fs2.readFileSync)(
241
+ microfrontendsJsonPath,
242
+ "utf-8"
243
+ );
244
+ const microfrontendsJson = (0, import_jsonc_parser.parse)(microfrontendsJsonContent);
245
+ if (microfrontendsJson.applications[applicationName]) {
246
+ matchingPaths.push(microfrontendsJsonPath);
247
+ }
248
+ } catch (error) {
249
+ }
250
+ }
251
+ if (matchingPaths.length > 1) {
252
+ throw new Error(
253
+ `Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
254
+ ${matchingPaths.join("\n \u2022 ")}`
255
+ );
256
+ }
257
+ if (matchingPaths.length === 0) {
258
+ throw new Error(
259
+ `Could not find default application with "applications.${applicationName}"`
260
+ );
261
+ }
262
+ const [packageJsonPath] = matchingPaths;
263
+ return (0, import_node_path2.dirname)(packageJsonPath);
264
+ } catch (error) {
265
+ return null;
266
+ }
267
+ }
268
+ function findDefaultMicrofrontendsPackage(opts) {
269
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
270
+ if (configCache[cacheKey]) {
271
+ return configCache[cacheKey];
272
+ }
273
+ const result = findDefaultMicrofrontendsPackages(opts);
274
+ if (!result) {
275
+ throw new Error(
276
+ "Error trying to resolve the main microfrontends configuration"
277
+ );
278
+ }
279
+ configCache[cacheKey] = result;
280
+ return result;
182
281
  }
183
282
 
184
- // src/config/schema/utils/is-default-app.ts
185
- function isDefaultApp(a) {
186
- return !("routing" in a);
283
+ // src/config/microfrontends/utils/is-monorepo.ts
284
+ var import_node_fs3 = __toESM(require("fs"), 1);
285
+ var import_node_path3 = __toESM(require("path"), 1);
286
+ function isMonorepo({
287
+ repositoryRoot
288
+ }) {
289
+ try {
290
+ if (import_node_fs3.default.existsSync(import_node_path3.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
291
+ return true;
292
+ }
293
+ if (import_node_fs3.default.existsSync(import_node_path3.default.join(repositoryRoot, "vlt-workspaces.json"))) {
294
+ return true;
295
+ }
296
+ if (process.env.NX_WORKSPACE_ROOT === import_node_path3.default.resolve(repositoryRoot)) {
297
+ return true;
298
+ }
299
+ const packageJsonPath = import_node_path3.default.join(repositoryRoot, "package.json");
300
+ if (!import_node_fs3.default.existsSync(packageJsonPath)) {
301
+ return false;
302
+ }
303
+ const packageJson = JSON.parse(
304
+ import_node_fs3.default.readFileSync(packageJsonPath, "utf-8")
305
+ );
306
+ return packageJson.workspaces !== void 0;
307
+ } catch (error) {
308
+ console.error("Error determining if repository is a monorepo", error);
309
+ return false;
310
+ }
311
+ }
312
+
313
+ // src/config/microfrontends/utils/find-package-root.ts
314
+ var import_node_fs4 = __toESM(require("fs"), 1);
315
+ var import_node_path4 = __toESM(require("path"), 1);
316
+ var PACKAGE_JSON = "package.json";
317
+ function findPackageRoot(startDir) {
318
+ let currentDir = startDir || process.cwd();
319
+ while (currentDir !== import_node_path4.default.parse(currentDir).root) {
320
+ const pkgJsonPath = import_node_path4.default.join(currentDir, PACKAGE_JSON);
321
+ if (import_node_fs4.default.existsSync(pkgJsonPath)) {
322
+ return currentDir;
323
+ }
324
+ currentDir = import_node_path4.default.dirname(currentDir);
325
+ }
326
+ throw new Error(
327
+ "Package root not found. Specify the root of the package with the `package.root` option."
328
+ );
329
+ }
330
+
331
+ // src/config/microfrontends/utils/find-config.ts
332
+ var import_node_fs5 = __toESM(require("fs"), 1);
333
+ var import_node_path5 = require("path");
334
+ function findConfig({ dir }) {
335
+ for (const filename of CONFIGURATION_FILENAMES) {
336
+ const maybeConfig = (0, import_node_path5.join)(dir, filename);
337
+ if (import_node_fs5.default.existsSync(maybeConfig)) {
338
+ return maybeConfig;
339
+ }
340
+ }
341
+ return null;
187
342
  }
188
343
 
344
+ // src/config/microfrontends-config/isomorphic/index.ts
345
+ var import_jsonc_parser2 = require("jsonc-parser");
346
+
189
347
  // src/config/microfrontends-config/client/index.ts
190
348
  var import_path_to_regexp = require("path-to-regexp");
191
349
  var MicrofrontendConfigClient = class {
@@ -721,42 +879,28 @@ var MicrofrontendConfigIsomorphic = class {
721
879
  constructor({
722
880
  config,
723
881
  overrides,
724
- meta,
725
882
  opts
726
883
  }) {
727
884
  this.childApplications = {};
728
885
  MicrofrontendConfigIsomorphic.validate(config, opts);
729
886
  const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
730
887
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
731
- this.isMainConfig = isMainConfig(config);
732
- if (isMainConfig(config)) {
733
- for (const [appId, appConfig] of Object.entries(config.applications)) {
734
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
735
- if (isDefaultApp(appConfig)) {
736
- this.defaultApplication = new DefaultApplication(appId, {
737
- app: appConfig,
738
- overrides: appOverrides
739
- });
740
- } else {
741
- this.childApplications[appId] = new ChildApplication(appId, {
742
- app: appConfig,
743
- overrides: appOverrides
744
- });
745
- }
746
- }
747
- } else {
748
- this.partOf = config.partOf;
749
- const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
750
- this.childApplications[meta.fromApp] = new ChildApplication(
751
- meta.fromApp,
752
- {
753
- // we don't know routing because we're not in the main config
754
- app: { routing: [] },
888
+ let defaultApplication;
889
+ for (const [appId, appConfig] of Object.entries(config.applications)) {
890
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
891
+ if (isDefaultApp(appConfig)) {
892
+ defaultApplication = new DefaultApplication(appId, {
893
+ app: appConfig,
755
894
  overrides: appOverrides
756
- }
757
- );
895
+ });
896
+ } else {
897
+ this.childApplications[appId] = new ChildApplication(appId, {
898
+ app: appConfig,
899
+ overrides: appOverrides
900
+ });
901
+ }
758
902
  }
759
- if (isMainConfig(config) && !this.defaultApplication) {
903
+ if (!defaultApplication) {
760
904
  throw new MicrofrontendError(
761
905
  "Could not find default application in microfrontends configuration",
762
906
  {
@@ -765,34 +909,30 @@ var MicrofrontendConfigIsomorphic = class {
765
909
  }
766
910
  );
767
911
  }
912
+ this.defaultApplication = defaultApplication;
768
913
  this.config = config;
769
914
  this.options = config.options;
770
915
  this.serialized = {
771
916
  config,
772
- overrides,
773
- meta
917
+ overrides
774
918
  };
775
919
  }
776
920
  static validate(config, opts) {
777
921
  const skipValidation = opts?.skipValidation ?? [];
778
- const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
779
- if (isMainConfig(c)) {
780
- validateConfigPaths(c.applications);
781
- validateConfigDefaultApplication(c.applications);
782
- if (!skipValidation.includes("deprecatedFields")) {
783
- validateDeprecatedFields(c);
784
- }
922
+ const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
923
+ validateConfigPaths(c.applications);
924
+ validateConfigDefaultApplication(c.applications);
925
+ if (!skipValidation.includes("deprecatedFields")) {
926
+ validateDeprecatedFields(c);
785
927
  }
786
928
  return c;
787
929
  }
788
930
  static fromEnv({
789
- meta,
790
931
  cookies
791
932
  }) {
792
933
  return new MicrofrontendConfigIsomorphic({
793
- config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
794
- overrides: parseOverrides(cookies ?? []),
795
- meta
934
+ config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
935
+ overrides: parseOverrides(cookies ?? [])
796
936
  });
797
937
  }
798
938
  isOverridesDisabled() {
@@ -817,7 +957,7 @@ var MicrofrontendConfigIsomorphic = class {
817
957
  ].filter(Boolean);
818
958
  }
819
959
  getApplication(name) {
820
- if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
960
+ if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
821
961
  return this.defaultApplication;
822
962
  }
823
963
  const app = this.childApplications[name] || Object.values(this.childApplications).find(
@@ -835,7 +975,7 @@ var MicrofrontendConfigIsomorphic = class {
835
975
  return app;
836
976
  }
837
977
  getApplicationByProjectId(projectId) {
838
- if (this.defaultApplication?.projectId === projectId) {
978
+ if (this.defaultApplication.projectId === projectId) {
839
979
  return this.defaultApplication;
840
980
  }
841
981
  return Object.values(this.childApplications).find(
@@ -843,19 +983,9 @@ var MicrofrontendConfigIsomorphic = class {
843
983
  );
844
984
  }
845
985
  /**
846
- * Returns the default application. This can throw if the default application
847
- * is undefined ( )
986
+ * Returns the default application.
848
987
  */
849
988
  getDefaultApplication() {
850
- if (!this.defaultApplication) {
851
- throw new MicrofrontendError(
852
- "Could not find default application in microfrontends configuration",
853
- {
854
- type: "application",
855
- subtype: "not_found"
856
- }
857
- );
858
- }
859
989
  return this.defaultApplication;
860
990
  }
861
991
  /**
@@ -882,11 +1012,9 @@ var MicrofrontendConfigIsomorphic = class {
882
1012
  }
883
1013
  ])
884
1014
  );
885
- if (this.defaultApplication) {
886
- applications[this.defaultApplication.name] = {
887
- default: true
888
- };
889
- }
1015
+ applications[this.defaultApplication.name] = {
1016
+ default: true
1017
+ };
890
1018
  return new MicrofrontendConfigClient({
891
1019
  applications
892
1020
  });
@@ -896,307 +1024,9 @@ var MicrofrontendConfigIsomorphic = class {
896
1024
  }
897
1025
  };
898
1026
 
899
- // src/config/microfrontends-config/isomorphic/child.ts
900
- var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
901
- constructor({
902
- config,
903
- overrides,
904
- meta
905
- }) {
906
- super({ config, overrides, meta });
907
- this.isMainConfig = false;
908
- this.partOf = config.partOf;
909
- }
910
- };
911
-
912
- // src/config/microfrontends-config/isomorphic/main.ts
913
- var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
914
- constructor({
915
- config,
916
- overrides,
917
- meta
918
- }) {
919
- super({ config, overrides, meta });
920
- this.isMainConfig = true;
921
- const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
922
- let defaultApplication;
923
- for (const [appId, appConfig] of Object.entries(config.applications)) {
924
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
925
- if (isDefaultApp(appConfig)) {
926
- defaultApplication = new DefaultApplication(appId, {
927
- app: appConfig,
928
- overrides: appOverrides
929
- });
930
- } else {
931
- this.childApplications[appId] = new ChildApplication(appId, {
932
- app: appConfig,
933
- overrides: appOverrides
934
- });
935
- }
936
- }
937
- if (!defaultApplication) {
938
- throw new MicrofrontendError(
939
- "Could not find default application in microfrontends configuration",
940
- {
941
- type: "application",
942
- subtype: "not_found"
943
- }
944
- );
945
- }
946
- this.defaultApplication = defaultApplication;
947
- }
948
- };
949
-
950
- // src/config/microfrontends/isomorphic/index.ts
951
- var Microfrontends = class {
952
- constructor({
953
- config,
954
- overrides,
955
- meta
956
- }) {
957
- if (isMainConfig(config)) {
958
- this.config = new MicrofrontendMainConfig({ config, overrides, meta });
959
- } else {
960
- this.config = new MicrofrontendChildConfig({ config, overrides, meta });
961
- }
962
- }
963
- isChildConfig() {
964
- return this.config instanceof MicrofrontendChildConfig;
965
- }
966
- static fromEnv({
967
- cookies,
968
- meta
969
- }) {
970
- const config = MicrofrontendConfigIsomorphic.fromEnv({
971
- cookies,
972
- meta
973
- });
974
- return new Microfrontends(config.serialize());
975
- }
976
- };
977
-
978
- // src/config/microfrontends/utils/find-repository-root.ts
979
- var import_node_fs = __toESM(require("fs"), 1);
980
- var import_node_path = __toESM(require("path"), 1);
981
- var GIT_DIRECTORY = ".git";
982
- function hasGitDirectory(dir) {
983
- const gitPath = import_node_path.default.join(dir, GIT_DIRECTORY);
984
- return import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory();
985
- }
986
- function hasPnpmWorkspaces(dir) {
987
- return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
988
- }
989
- function findRepositoryRoot(startDir) {
990
- if (process.env.NX_WORKSPACE_ROOT) {
991
- return process.env.NX_WORKSPACE_ROOT;
992
- }
993
- let currentDir = startDir || process.cwd();
994
- while (currentDir !== import_node_path.default.parse(currentDir).root) {
995
- if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
996
- return currentDir;
997
- }
998
- currentDir = import_node_path.default.dirname(currentDir);
999
- }
1000
- throw new Error(
1001
- "Repository root not found. Specify the root of the repository with the `repository.root` option."
1002
- );
1003
- }
1004
-
1005
- // src/config/microfrontends/utils/find-package-path.ts
1006
- var import_node_path2 = require("path");
1007
- var import_node_fs2 = require("fs");
1008
- var import_fast_glob = __toESM(require("fast-glob"), 1);
1009
- var configCache = {};
1010
- function findPackagePathWithGlob({
1011
- repositoryRoot,
1012
- name
1013
- }) {
1014
- try {
1015
- const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
1016
- cwd: repositoryRoot,
1017
- absolute: true,
1018
- onlyFiles: true,
1019
- followSymbolicLinks: false,
1020
- ignore: ["**/node_modules/**", "**/.git/**"]
1021
- });
1022
- const matchingPaths = [];
1023
- for (const packageJsonPath2 of packageJsonPaths) {
1024
- const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
1025
- const packageJson = JSON.parse(packageJsonContent);
1026
- if (packageJson.name === name) {
1027
- matchingPaths.push(packageJsonPath2);
1028
- }
1029
- }
1030
- if (matchingPaths.length > 1) {
1031
- throw new Error(
1032
- `Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
1033
- );
1034
- }
1035
- if (matchingPaths.length === 0) {
1036
- throw new Error(
1037
- `Could not find package with the name "${name}" in the repository`
1038
- );
1039
- }
1040
- const [packageJsonPath] = matchingPaths;
1041
- return (0, import_node_path2.dirname)(packageJsonPath);
1042
- } catch (error) {
1043
- return null;
1044
- }
1045
- }
1046
- function findPackagePath(opts) {
1047
- const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
1048
- if (configCache[cacheKey]) {
1049
- return configCache[cacheKey];
1050
- }
1051
- const result = findPackagePathWithGlob(opts);
1052
- if (!result) {
1053
- throw new Error(
1054
- `Could not find package with the name "${opts.name}" in the repository`
1055
- );
1056
- }
1057
- configCache[cacheKey] = result;
1058
- return result;
1059
- }
1060
-
1061
- // src/config/microfrontends/utils/find-default-package.ts
1062
- var import_node_path3 = require("path");
1063
- var import_node_fs3 = require("fs");
1064
- var import_jsonc_parser2 = require("jsonc-parser");
1065
- var import_fast_glob2 = __toESM(require("fast-glob"), 1);
1066
-
1067
- // src/config/constants.ts
1068
- var CONFIGURATION_FILENAMES = [
1069
- "microfrontends.jsonc",
1070
- "microfrontends.json"
1071
- ];
1072
-
1073
- // src/config/microfrontends/utils/find-default-package.ts
1074
- var configCache2 = {};
1075
- function findDefaultMicrofrontendsPackages({
1076
- repositoryRoot,
1077
- applicationName
1078
- }) {
1079
- try {
1080
- const microfrontendsJsonPaths = import_fast_glob2.default.globSync(
1081
- `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
1082
- {
1083
- cwd: repositoryRoot,
1084
- absolute: true,
1085
- onlyFiles: true,
1086
- followSymbolicLinks: false,
1087
- ignore: ["**/node_modules/**", "**/.git/**"]
1088
- }
1089
- );
1090
- const matchingPaths = [];
1091
- for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
1092
- try {
1093
- const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
1094
- microfrontendsJsonPath,
1095
- "utf-8"
1096
- );
1097
- const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
1098
- if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
1099
- matchingPaths.push(microfrontendsJsonPath);
1100
- }
1101
- } catch (error) {
1102
- }
1103
- }
1104
- if (matchingPaths.length > 1) {
1105
- throw new Error(
1106
- `Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
1107
- ${matchingPaths.join("\n \u2022 ")}`
1108
- );
1109
- }
1110
- if (matchingPaths.length === 0) {
1111
- throw new Error(
1112
- `Could not find default application with "applications.${applicationName}"`
1113
- );
1114
- }
1115
- const [packageJsonPath] = matchingPaths;
1116
- return (0, import_node_path3.dirname)(packageJsonPath);
1117
- } catch (error) {
1118
- return null;
1119
- }
1120
- }
1121
- function findDefaultMicrofrontendsPackage(opts) {
1122
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
1123
- if (configCache2[cacheKey]) {
1124
- return configCache2[cacheKey];
1125
- }
1126
- const result = findDefaultMicrofrontendsPackages(opts);
1127
- if (!result) {
1128
- throw new Error(
1129
- "Error trying to resolve the main microfrontends configuration"
1130
- );
1131
- }
1132
- configCache2[cacheKey] = result;
1133
- return result;
1134
- }
1135
-
1136
- // src/config/microfrontends/utils/is-monorepo.ts
1137
- var import_node_fs4 = __toESM(require("fs"), 1);
1138
- var import_node_path4 = __toESM(require("path"), 1);
1139
- function isMonorepo({
1140
- repositoryRoot
1141
- }) {
1142
- try {
1143
- if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
1144
- return true;
1145
- }
1146
- if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
1147
- return true;
1148
- }
1149
- if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
1150
- return true;
1151
- }
1152
- const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
1153
- if (!import_node_fs4.default.existsSync(packageJsonPath)) {
1154
- return false;
1155
- }
1156
- const packageJson = JSON.parse(
1157
- import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
1158
- );
1159
- return packageJson.workspaces !== void 0;
1160
- } catch (error) {
1161
- console.error("Error determining if repository is a monorepo", error);
1162
- return false;
1163
- }
1164
- }
1165
-
1166
- // src/config/microfrontends/utils/find-package-root.ts
1167
- var import_node_fs5 = __toESM(require("fs"), 1);
1168
- var import_node_path5 = __toESM(require("path"), 1);
1169
- var PACKAGE_JSON = "package.json";
1170
- function findPackageRoot(startDir) {
1171
- let currentDir = startDir || process.cwd();
1172
- while (currentDir !== import_node_path5.default.parse(currentDir).root) {
1173
- const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
1174
- if (import_node_fs5.default.existsSync(pkgJsonPath)) {
1175
- return currentDir;
1176
- }
1177
- currentDir = import_node_path5.default.dirname(currentDir);
1178
- }
1179
- throw new Error(
1180
- "Package root not found. Specify the root of the package with the `package.root` option."
1181
- );
1182
- }
1183
-
1184
- // src/config/microfrontends/utils/find-config.ts
1185
- var import_node_fs6 = __toESM(require("fs"), 1);
1186
- var import_node_path6 = require("path");
1187
- function findConfig({ dir }) {
1188
- for (const filename of CONFIGURATION_FILENAMES) {
1189
- const maybeConfig = (0, import_node_path6.join)(dir, filename);
1190
- if (import_node_fs6.default.existsSync(maybeConfig)) {
1191
- return maybeConfig;
1192
- }
1193
- }
1194
- return null;
1195
- }
1196
-
1197
1027
  // src/config/microfrontends/utils/get-application-context.ts
1198
- var import_node_fs7 = __toESM(require("fs"), 1);
1199
- var import_node_path7 = __toESM(require("path"), 1);
1028
+ var import_node_fs6 = __toESM(require("fs"), 1);
1029
+ var import_node_path6 = __toESM(require("path"), 1);
1200
1030
  function getApplicationContext(opts) {
1201
1031
  if (opts?.appName) {
1202
1032
  return { name: opts.appName };
@@ -1205,8 +1035,8 @@ function getApplicationContext(opts) {
1205
1035
  return { name: process.env.NX_TASK_TARGET_PROJECT };
1206
1036
  }
1207
1037
  try {
1208
- const packageJsonString = import_node_fs7.default.readFileSync(
1209
- import_node_path7.default.join(opts?.packageRoot || ".", "package.json"),
1038
+ const packageJsonString = import_node_fs6.default.readFileSync(
1039
+ import_node_path6.default.join(opts?.packageRoot || ".", "package.json"),
1210
1040
  "utf-8"
1211
1041
  );
1212
1042
  const packageJson = JSON.parse(packageJsonString);
@@ -1229,7 +1059,7 @@ function getApplicationContext(opts) {
1229
1059
  }
1230
1060
 
1231
1061
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1232
- var import_node_path8 = __toESM(require("path"), 1);
1062
+ var import_node_path7 = __toESM(require("path"), 1);
1233
1063
 
1234
1064
  // src/config/microfrontends/server/constants.ts
1235
1065
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -1237,7 +1067,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1237
1067
 
1238
1068
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1239
1069
  function getOutputFilePath() {
1240
- return import_node_path8.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1070
+ return import_node_path7.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
1241
1071
  }
1242
1072
 
1243
1073
  // src/config/microfrontends/server/validation.ts
@@ -1250,16 +1080,6 @@ var schema_default = {
1250
1080
  $ref: "#/definitions/Config",
1251
1081
  definitions: {
1252
1082
  Config: {
1253
- anyOf: [
1254
- {
1255
- $ref: "#/definitions/MainConfig"
1256
- },
1257
- {
1258
- $ref: "#/definitions/ChildConfig"
1259
- }
1260
- ]
1261
- },
1262
- MainConfig: {
1263
1083
  type: "object",
1264
1084
  properties: {
1265
1085
  $schema: {
@@ -1516,27 +1336,6 @@ var schema_default = {
1516
1336
  },
1517
1337
  required: ["paths"],
1518
1338
  additionalProperties: false
1519
- },
1520
- ChildConfig: {
1521
- type: "object",
1522
- properties: {
1523
- $schema: {
1524
- type: "string"
1525
- },
1526
- version: {
1527
- type: "string",
1528
- const: "1"
1529
- },
1530
- options: {
1531
- $ref: "#/definitions/Options"
1532
- },
1533
- partOf: {
1534
- type: "string",
1535
- 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."
1536
- }
1537
- },
1538
- required: ["partOf"],
1539
- additionalProperties: false
1540
1339
  }
1541
1340
  }
1542
1341
  };
@@ -1614,7 +1413,13 @@ See https://openapi.vercel.sh/microfrontends.json for the schema.`,
1614
1413
  }
1615
1414
 
1616
1415
  // src/config/microfrontends/server/index.ts
1617
- var MicrofrontendsServer = class extends Microfrontends {
1416
+ var MicrofrontendsServer = class {
1417
+ constructor({
1418
+ config,
1419
+ overrides
1420
+ }) {
1421
+ this.config = new MicrofrontendConfigIsomorphic({ config, overrides });
1422
+ }
1618
1423
  /**
1619
1424
  * Writes the configuration to a file.
1620
1425
  */
@@ -1622,8 +1427,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1622
1427
  pretty: true
1623
1428
  }) {
1624
1429
  const outputPath = getOutputFilePath();
1625
- import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
1626
- import_node_fs8.default.writeFileSync(
1430
+ import_node_fs7.default.mkdirSync((0, import_node_path8.dirname)(outputPath), { recursive: true });
1431
+ import_node_fs7.default.writeFileSync(
1627
1432
  outputPath,
1628
1433
  JSON.stringify(
1629
1434
  this.config.toSchemaJson(),
@@ -1638,22 +1443,19 @@ var MicrofrontendsServer = class extends Microfrontends {
1638
1443
  */
1639
1444
  static fromUnknown({
1640
1445
  config,
1641
- cookies,
1642
- meta
1446
+ cookies
1643
1447
  }) {
1644
1448
  const overrides = cookies ? parseOverrides(cookies) : void 0;
1645
1449
  if (typeof config === "string") {
1646
1450
  return new MicrofrontendsServer({
1647
1451
  config: MicrofrontendsServer.validate(config),
1648
- overrides,
1649
- meta
1452
+ overrides
1650
1453
  });
1651
1454
  }
1652
1455
  if (typeof config === "object") {
1653
1456
  return new MicrofrontendsServer({
1654
1457
  config,
1655
- overrides,
1656
- meta
1458
+ overrides
1657
1459
  });
1658
1460
  }
1659
1461
  throw new MicrofrontendError(
@@ -1666,13 +1468,11 @@ var MicrofrontendsServer = class extends Microfrontends {
1666
1468
  * Uses additional validation that is only available when in a node runtime
1667
1469
  */
1668
1470
  static fromEnv({
1669
- cookies,
1670
- meta
1471
+ cookies
1671
1472
  }) {
1672
1473
  return new MicrofrontendsServer({
1673
1474
  config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
1674
- overrides: parseOverrides(cookies),
1675
- meta
1475
+ overrides: parseOverrides(cookies)
1676
1476
  });
1677
1477
  }
1678
1478
  /**
@@ -1695,29 +1495,22 @@ var MicrofrontendsServer = class extends Microfrontends {
1695
1495
  static infer({
1696
1496
  directory,
1697
1497
  filePath,
1698
- meta,
1699
- cookies,
1700
- options
1498
+ cookies
1701
1499
  } = {}) {
1702
- if (filePath && meta) {
1500
+ if (filePath) {
1703
1501
  return MicrofrontendsServer.fromFile({
1704
1502
  filePath,
1705
- cookies,
1706
- meta,
1707
- options
1503
+ cookies
1708
1504
  });
1709
1505
  }
1710
1506
  try {
1711
1507
  const packageRoot = findPackageRoot(directory);
1712
1508
  const { name: appName } = getApplicationContext({ packageRoot });
1713
- const configMeta = meta ?? { fromApp: appName };
1714
1509
  const maybeConfig = findConfig({ dir: packageRoot });
1715
1510
  if (maybeConfig) {
1716
1511
  return MicrofrontendsServer.fromFile({
1717
1512
  filePath: maybeConfig,
1718
- cookies,
1719
- meta: configMeta,
1720
- options
1513
+ cookies
1721
1514
  });
1722
1515
  }
1723
1516
  const repositoryRoot = findRepositoryRoot();
@@ -1731,9 +1524,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1731
1524
  if (maybeConfigFromDefault) {
1732
1525
  return MicrofrontendsServer.fromFile({
1733
1526
  filePath: maybeConfigFromDefault,
1734
- cookies,
1735
- meta: configMeta,
1736
- options
1527
+ cookies
1737
1528
  });
1738
1529
  }
1739
1530
  }
@@ -1753,44 +1544,14 @@ var MicrofrontendsServer = class extends Microfrontends {
1753
1544
  */
1754
1545
  static fromFile({
1755
1546
  filePath,
1756
- cookies,
1757
- meta,
1758
- options
1547
+ cookies
1759
1548
  }) {
1760
1549
  try {
1761
- const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
1550
+ const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
1762
1551
  const config = MicrofrontendsServer.validate(configJson);
1763
- if (!isMainConfig(config) && options?.resolveMainConfig) {
1764
- const repositoryRoot = findRepositoryRoot();
1765
- const isMonorepo2 = isMonorepo({ repositoryRoot });
1766
- if (isMonorepo2) {
1767
- const packagePath = findPackagePath({
1768
- repositoryRoot,
1769
- name: config.partOf
1770
- });
1771
- if (!packagePath) {
1772
- throw new MicrofrontendError(
1773
- `Could not find default application "${config.partOf}" in the repository`,
1774
- { type: "config", subtype: "not_found" }
1775
- );
1776
- }
1777
- const maybeConfig = findConfig({ dir: packagePath });
1778
- if (!maybeConfig) {
1779
- throw new MicrofrontendError(
1780
- `Could not find microfrontends configuration in ${packagePath}`,
1781
- { type: "config", subtype: "not_found" }
1782
- );
1783
- }
1784
- return MicrofrontendsServer.fromMainConfigFile({
1785
- filePath: maybeConfig,
1786
- overrides: cookies ? parseOverrides(cookies) : void 0
1787
- });
1788
- }
1789
- }
1790
1552
  return new MicrofrontendsServer({
1791
1553
  config,
1792
- overrides: cookies ? parseOverrides(cookies) : void 0,
1793
- meta
1554
+ overrides: cookies ? parseOverrides(cookies) : void 0
1794
1555
  });
1795
1556
  } catch (e) {
1796
1557
  throw MicrofrontendError.handle(e, {
@@ -1799,24 +1560,15 @@ var MicrofrontendsServer = class extends Microfrontends {
1799
1560
  }
1800
1561
  }
1801
1562
  /*
1802
- * Generates a MicrofrontendMainConfig instance from a file.
1563
+ * Generates a MicrofrontendsServer instance from a file.
1803
1564
  */
1804
1565
  static fromMainConfigFile({
1805
1566
  filePath,
1806
1567
  overrides
1807
1568
  }) {
1808
1569
  try {
1809
- const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
1570
+ const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
1810
1571
  const validatedConfig = MicrofrontendsServer.validate(config);
1811
- if (!isMainConfig(validatedConfig)) {
1812
- throw new MicrofrontendError(
1813
- `${filePath} is not a main microfrontend config`,
1814
- {
1815
- type: "config",
1816
- subtype: "invalid_main_path"
1817
- }
1818
- );
1819
- }
1820
1572
  const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
1821
1573
  if (!defaultApplication) {
1822
1574
  throw new MicrofrontendError(
@@ -1826,8 +1578,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1826
1578
  }
1827
1579
  return new MicrofrontendsServer({
1828
1580
  config: validatedConfig,
1829
- overrides,
1830
- meta: { fromApp: defaultApplication }
1581
+ overrides
1831
1582
  });
1832
1583
  } catch (e) {
1833
1584
  throw MicrofrontendError.handle(e, {