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