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