@vercel/microfrontends 1.1.1-canary.2 → 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 (64) hide show
  1. package/dist/bin/cli.cjs +303 -512
  2. package/dist/config.cjs +43 -71
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +153 -4
  5. package/dist/config.js +43 -71
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +296 -489
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +286 -479
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +326 -511
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.js +312 -497
  14. package/dist/experimental/vite.js.map +1 -1
  15. package/dist/microfrontends/server.cjs +295 -485
  16. package/dist/microfrontends/server.cjs.map +1 -1
  17. package/dist/microfrontends/server.d.ts +14 -20
  18. package/dist/microfrontends/server.js +285 -475
  19. package/dist/microfrontends/server.js.map +1 -1
  20. package/dist/next/config.cjs +297 -498
  21. package/dist/next/config.cjs.map +1 -1
  22. package/dist/next/config.js +287 -488
  23. package/dist/next/config.js.map +1 -1
  24. package/dist/next/endpoints.cjs +2 -0
  25. package/dist/next/endpoints.cjs.map +1 -1
  26. package/dist/next/endpoints.d.ts +13 -3
  27. package/dist/next/endpoints.js +1 -0
  28. package/dist/next/endpoints.js.map +1 -1
  29. package/dist/next/middleware.cjs +58 -171
  30. package/dist/next/middleware.cjs.map +1 -1
  31. package/dist/next/middleware.d.ts +2 -4
  32. package/dist/next/middleware.js +58 -171
  33. package/dist/next/middleware.js.map +1 -1
  34. package/dist/next/testing.cjs +44 -73
  35. package/dist/next/testing.cjs.map +1 -1
  36. package/dist/next/testing.d.ts +4 -4
  37. package/dist/next/testing.js +44 -73
  38. package/dist/next/testing.js.map +1 -1
  39. package/dist/overrides.d.ts +3 -3
  40. package/dist/schema.cjs +2 -9
  41. package/dist/schema.cjs.map +1 -1
  42. package/dist/schema.d.ts +3 -4
  43. package/dist/schema.js +1 -7
  44. package/dist/schema.js.map +1 -1
  45. package/dist/{types-6ee19ccc.d.ts → types-54064641.d.ts} +2 -13
  46. package/dist/{types-73527280.d.ts → types-a4add5ab.d.ts} +1 -1
  47. package/dist/{types-74e3336c.d.ts → types-f1260e44.d.ts} +1 -1
  48. package/dist/utils/mfe-port.cjs +300 -492
  49. package/dist/utils/mfe-port.cjs.map +1 -1
  50. package/dist/utils/mfe-port.js +286 -478
  51. package/dist/utils/mfe-port.js.map +1 -1
  52. package/dist/validation.cjs +49 -37
  53. package/dist/validation.cjs.map +1 -1
  54. package/dist/validation.d.ts +1 -1
  55. package/dist/validation.js +49 -37
  56. package/dist/validation.js.map +1 -1
  57. package/package.json +2 -9
  58. package/schema/schema.json +0 -33
  59. package/dist/index-7e69650e.d.ts +0 -165
  60. package/dist/microfrontends.cjs +0 -962
  61. package/dist/microfrontends.cjs.map +0 -1
  62. package/dist/microfrontends.d.ts +0 -45
  63. package/dist/microfrontends.js +0 -935
  64. 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);
215
+
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;
283
+ }
180
284
 
181
- // src/config/schema/utils/is-main-config.ts
182
- function isMainConfig(c) {
183
- return !("partOf" in c);
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
+ }
184
313
  }
185
314
 
186
- // src/config/schema/utils/is-default-app.ts
187
- function isDefaultApp(a) {
188
- return !("routing" in a);
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
+ );
189
331
  }
190
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 {
@@ -256,6 +414,10 @@ var MicrofrontendConfigClient = class {
256
414
 
257
415
  // src/config/microfrontends-config/isomorphic/validation.ts
258
416
  var import_path_to_regexp2 = require("path-to-regexp");
417
+ var LIST_FORMATTER = new Intl.ListFormat("en", {
418
+ style: "long",
419
+ type: "conjunction"
420
+ });
259
421
  var validateConfigPaths = (applicationConfigsById) => {
260
422
  if (!applicationConfigsById) {
261
423
  return;
@@ -388,15 +550,15 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
388
550
  if (!applicationConfigsById) {
389
551
  return;
390
552
  }
391
- const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
392
- ([, app]) => !isDefaultApp(app)
393
- );
394
- const applicationsWithRoutingNames = applicationsWithRouting.map(
395
- ([key]) => key
553
+ const applicationsWithoutRouting = Object.entries(
554
+ applicationConfigsById
555
+ ).filter(([, app]) => isDefaultApp(app));
556
+ const numApplicationsWithoutRouting = applicationsWithoutRouting.reduce(
557
+ (acc) => {
558
+ return acc + 1;
559
+ },
560
+ 0
396
561
  );
397
- const numApplications = Object.keys(applicationConfigsById).length;
398
- const numApplicationsWithRouting = applicationsWithRoutingNames.length;
399
- const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
400
562
  if (numApplicationsWithoutRouting === 0) {
401
563
  throw new MicrofrontendError(
402
564
  "No default application found. At least one application needs to be the default by omitting routing.",
@@ -404,8 +566,11 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
404
566
  );
405
567
  }
406
568
  if (numApplicationsWithoutRouting > 1) {
569
+ const applicationNamesMissingRouting = applicationsWithoutRouting.map(
570
+ ([name]) => name
571
+ );
407
572
  throw new MicrofrontendError(
408
- `Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
573
+ `All applications except for the default app must contain the "routing" field. Applications that are missing routing: ${LIST_FORMATTER.format(applicationNamesMissingRouting)}.`,
409
574
  { type: "config", subtype: "multiple_default_applications" }
410
575
  );
411
576
  }
@@ -716,42 +881,28 @@ var MicrofrontendConfigIsomorphic = class {
716
881
  constructor({
717
882
  config,
718
883
  overrides,
719
- meta,
720
884
  opts
721
885
  }) {
722
886
  this.childApplications = {};
723
887
  MicrofrontendConfigIsomorphic.validate(config, opts);
724
888
  const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
725
889
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
726
- this.isMainConfig = isMainConfig(config);
727
- if (isMainConfig(config)) {
728
- for (const [appId, appConfig] of Object.entries(config.applications)) {
729
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
730
- if (isDefaultApp(appConfig)) {
731
- this.defaultApplication = new DefaultApplication(appId, {
732
- app: appConfig,
733
- overrides: appOverrides
734
- });
735
- } else {
736
- this.childApplications[appId] = new ChildApplication(appId, {
737
- app: appConfig,
738
- overrides: appOverrides
739
- });
740
- }
741
- }
742
- } else {
743
- this.partOf = config.partOf;
744
- const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
745
- this.childApplications[meta.fromApp] = new ChildApplication(
746
- meta.fromApp,
747
- {
748
- // we don't know routing because we're not in the main config
749
- 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,
750
896
  overrides: appOverrides
751
- }
752
- );
897
+ });
898
+ } else {
899
+ this.childApplications[appId] = new ChildApplication(appId, {
900
+ app: appConfig,
901
+ overrides: appOverrides
902
+ });
903
+ }
753
904
  }
754
- if (isMainConfig(config) && !this.defaultApplication) {
905
+ if (!defaultApplication) {
755
906
  throw new MicrofrontendError(
756
907
  "Could not find default application in microfrontends configuration",
757
908
  {
@@ -760,34 +911,30 @@ var MicrofrontendConfigIsomorphic = class {
760
911
  }
761
912
  );
762
913
  }
914
+ this.defaultApplication = defaultApplication;
763
915
  this.config = config;
764
916
  this.options = config.options;
765
917
  this.serialized = {
766
918
  config,
767
- overrides,
768
- meta
919
+ overrides
769
920
  };
770
921
  }
771
922
  static validate(config, opts) {
772
923
  const skipValidation = opts?.skipValidation ?? [];
773
- const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
774
- if (isMainConfig(c)) {
775
- validateConfigPaths(c.applications);
776
- validateConfigDefaultApplication(c.applications);
777
- if (!skipValidation.includes("deprecatedFields")) {
778
- validateDeprecatedFields(c);
779
- }
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);
780
929
  }
781
930
  return c;
782
931
  }
783
932
  static fromEnv({
784
- meta,
785
933
  cookies
786
934
  }) {
787
935
  return new MicrofrontendConfigIsomorphic({
788
- config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
789
- overrides: parseOverrides(cookies ?? []),
790
- meta
936
+ config: (0, import_jsonc_parser2.parse)(getConfigStringFromEnv()),
937
+ overrides: parseOverrides(cookies ?? [])
791
938
  });
792
939
  }
793
940
  isOverridesDisabled() {
@@ -812,7 +959,7 @@ var MicrofrontendConfigIsomorphic = class {
812
959
  ].filter(Boolean);
813
960
  }
814
961
  getApplication(name) {
815
- if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
962
+ if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
816
963
  return this.defaultApplication;
817
964
  }
818
965
  const app = this.childApplications[name] || Object.values(this.childApplications).find(
@@ -830,7 +977,7 @@ var MicrofrontendConfigIsomorphic = class {
830
977
  return app;
831
978
  }
832
979
  getApplicationByProjectId(projectId) {
833
- if (this.defaultApplication?.projectId === projectId) {
980
+ if (this.defaultApplication.projectId === projectId) {
834
981
  return this.defaultApplication;
835
982
  }
836
983
  return Object.values(this.childApplications).find(
@@ -838,19 +985,9 @@ var MicrofrontendConfigIsomorphic = class {
838
985
  );
839
986
  }
840
987
  /**
841
- * Returns the default application. This can throw if the default application
842
- * is undefined ( )
988
+ * Returns the default application.
843
989
  */
844
990
  getDefaultApplication() {
845
- if (!this.defaultApplication) {
846
- throw new MicrofrontendError(
847
- "Could not find default application in microfrontends configuration",
848
- {
849
- type: "application",
850
- subtype: "not_found"
851
- }
852
- );
853
- }
854
991
  return this.defaultApplication;
855
992
  }
856
993
  /**
@@ -877,11 +1014,9 @@ var MicrofrontendConfigIsomorphic = class {
877
1014
  }
878
1015
  ])
879
1016
  );
880
- if (this.defaultApplication) {
881
- applications[this.defaultApplication.name] = {
882
- default: true
883
- };
884
- }
1017
+ applications[this.defaultApplication.name] = {
1018
+ default: true
1019
+ };
885
1020
  return new MicrofrontendConfigClient({
886
1021
  applications
887
1022
  });
@@ -891,301 +1026,9 @@ var MicrofrontendConfigIsomorphic = class {
891
1026
  }
892
1027
  };
893
1028
 
894
- // src/config/microfrontends-config/isomorphic/child.ts
895
- var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
896
- constructor({
897
- config,
898
- overrides,
899
- meta
900
- }) {
901
- super({ config, overrides, meta });
902
- this.isMainConfig = false;
903
- this.partOf = config.partOf;
904
- }
905
- };
906
-
907
- // src/config/microfrontends-config/isomorphic/main.ts
908
- var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
909
- constructor({
910
- config,
911
- overrides,
912
- meta
913
- }) {
914
- super({ config, overrides, meta });
915
- this.isMainConfig = true;
916
- const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
917
- let defaultApplication;
918
- for (const [appId, appConfig] of Object.entries(config.applications)) {
919
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
920
- if (isDefaultApp(appConfig)) {
921
- defaultApplication = new DefaultApplication(appId, {
922
- app: appConfig,
923
- overrides: appOverrides
924
- });
925
- } else {
926
- this.childApplications[appId] = new ChildApplication(appId, {
927
- app: appConfig,
928
- overrides: appOverrides
929
- });
930
- }
931
- }
932
- if (!defaultApplication) {
933
- throw new MicrofrontendError(
934
- "Could not find default application in microfrontends configuration",
935
- {
936
- type: "application",
937
- subtype: "not_found"
938
- }
939
- );
940
- }
941
- this.defaultApplication = defaultApplication;
942
- }
943
- };
944
-
945
- // src/config/microfrontends/isomorphic/index.ts
946
- var Microfrontends = class {
947
- constructor({
948
- config,
949
- overrides,
950
- meta
951
- }) {
952
- if (isMainConfig(config)) {
953
- this.config = new MicrofrontendMainConfig({ config, overrides, meta });
954
- } else {
955
- this.config = new MicrofrontendChildConfig({ config, overrides, meta });
956
- }
957
- }
958
- isChildConfig() {
959
- return this.config instanceof MicrofrontendChildConfig;
960
- }
961
- static fromEnv({
962
- cookies,
963
- meta
964
- }) {
965
- const config = MicrofrontendConfigIsomorphic.fromEnv({
966
- cookies,
967
- meta
968
- });
969
- return new Microfrontends(config.serialize());
970
- }
971
- };
972
-
973
- // src/config/microfrontends/utils/find-repository-root.ts
974
- var import_node_fs = __toESM(require("fs"), 1);
975
- var import_node_path = __toESM(require("path"), 1);
976
- var GIT_DIRECTORY = ".git";
977
- function findRepositoryRoot(startDir) {
978
- if (process.env.NX_WORKSPACE_ROOT) {
979
- return process.env.NX_WORKSPACE_ROOT;
980
- }
981
- let currentDir = startDir || process.cwd();
982
- while (currentDir !== import_node_path.default.parse(currentDir).root) {
983
- const gitPath = import_node_path.default.join(currentDir, GIT_DIRECTORY);
984
- if (import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory()) {
985
- return currentDir;
986
- }
987
- currentDir = import_node_path.default.dirname(currentDir);
988
- }
989
- throw new Error(
990
- "Repository root not found. Specify the root of the repository with the `repository.root` option."
991
- );
992
- }
993
-
994
- // src/config/microfrontends/utils/find-package-path.ts
995
- var import_node_path2 = require("path");
996
- var import_node_fs2 = require("fs");
997
- var import_fast_glob = __toESM(require("fast-glob"), 1);
998
- var configCache = {};
999
- function findPackagePathWithGlob({
1000
- repositoryRoot,
1001
- name
1002
- }) {
1003
- try {
1004
- const packageJsonPaths = import_fast_glob.default.globSync("**/package.json", {
1005
- cwd: repositoryRoot,
1006
- absolute: true,
1007
- onlyFiles: true,
1008
- followSymbolicLinks: false,
1009
- ignore: ["**/node_modules/**", "**/.git/**"]
1010
- });
1011
- const matchingPaths = [];
1012
- for (const packageJsonPath2 of packageJsonPaths) {
1013
- const packageJsonContent = (0, import_node_fs2.readFileSync)(packageJsonPath2, "utf-8");
1014
- const packageJson = JSON.parse(packageJsonContent);
1015
- if (packageJson.name === name) {
1016
- matchingPaths.push(packageJsonPath2);
1017
- }
1018
- }
1019
- if (matchingPaths.length > 1) {
1020
- throw new Error(
1021
- `Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
1022
- );
1023
- }
1024
- if (matchingPaths.length === 0) {
1025
- throw new Error(
1026
- `Could not find package with the name "${name}" in the repository`
1027
- );
1028
- }
1029
- const [packageJsonPath] = matchingPaths;
1030
- return (0, import_node_path2.dirname)(packageJsonPath);
1031
- } catch (error) {
1032
- return null;
1033
- }
1034
- }
1035
- function findPackagePath(opts) {
1036
- const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
1037
- if (configCache[cacheKey]) {
1038
- return configCache[cacheKey];
1039
- }
1040
- const result = findPackagePathWithGlob(opts);
1041
- if (!result) {
1042
- throw new Error(
1043
- `Could not find package with the name "${opts.name}" in the repository`
1044
- );
1045
- }
1046
- configCache[cacheKey] = result;
1047
- return result;
1048
- }
1049
-
1050
- // src/config/microfrontends/utils/find-default-package.ts
1051
- var import_node_path3 = require("path");
1052
- var import_node_fs3 = require("fs");
1053
- var import_jsonc_parser2 = require("jsonc-parser");
1054
- var import_fast_glob2 = __toESM(require("fast-glob"), 1);
1055
-
1056
- // src/config/constants.ts
1057
- var CONFIGURATION_FILENAMES = [
1058
- "microfrontends.jsonc",
1059
- "microfrontends.json"
1060
- ];
1061
-
1062
- // src/config/microfrontends/utils/find-default-package.ts
1063
- var configCache2 = {};
1064
- function findDefaultMicrofrontendsPackages({
1065
- repositoryRoot,
1066
- applicationName
1067
- }) {
1068
- try {
1069
- const microfrontendsJsonPaths = import_fast_glob2.default.globSync(
1070
- `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
1071
- {
1072
- cwd: repositoryRoot,
1073
- absolute: true,
1074
- onlyFiles: true,
1075
- followSymbolicLinks: false,
1076
- ignore: ["**/node_modules/**", "**/.git/**"]
1077
- }
1078
- );
1079
- const matchingPaths = [];
1080
- for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
1081
- try {
1082
- const microfrontendsJsonContent = (0, import_node_fs3.readFileSync)(
1083
- microfrontendsJsonPath,
1084
- "utf-8"
1085
- );
1086
- const microfrontendsJson = (0, import_jsonc_parser2.parse)(microfrontendsJsonContent);
1087
- if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
1088
- matchingPaths.push(microfrontendsJsonPath);
1089
- }
1090
- } catch (error) {
1091
- }
1092
- }
1093
- if (matchingPaths.length > 1) {
1094
- throw new Error(
1095
- `Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
1096
- ${matchingPaths.join("\n \u2022 ")}`
1097
- );
1098
- }
1099
- if (matchingPaths.length === 0) {
1100
- throw new Error(
1101
- `Could not find default application with "applications.${applicationName}"`
1102
- );
1103
- }
1104
- const [packageJsonPath] = matchingPaths;
1105
- return (0, import_node_path3.dirname)(packageJsonPath);
1106
- } catch (error) {
1107
- return null;
1108
- }
1109
- }
1110
- function findDefaultMicrofrontendsPackage(opts) {
1111
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
1112
- if (configCache2[cacheKey]) {
1113
- return configCache2[cacheKey];
1114
- }
1115
- const result = findDefaultMicrofrontendsPackages(opts);
1116
- if (!result) {
1117
- throw new Error(
1118
- "Error trying to resolve the main microfrontends configuration"
1119
- );
1120
- }
1121
- configCache2[cacheKey] = result;
1122
- return result;
1123
- }
1124
-
1125
- // src/config/microfrontends/utils/is-monorepo.ts
1126
- var import_node_fs4 = __toESM(require("fs"), 1);
1127
- var import_node_path4 = __toESM(require("path"), 1);
1128
- function isMonorepo({
1129
- repositoryRoot
1130
- }) {
1131
- try {
1132
- if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "pnpm-workspace.yaml"))) {
1133
- return true;
1134
- }
1135
- if (import_node_fs4.default.existsSync(import_node_path4.default.join(repositoryRoot, "vlt-workspaces.json"))) {
1136
- return true;
1137
- }
1138
- if (process.env.NX_WORKSPACE_ROOT === import_node_path4.default.resolve(repositoryRoot)) {
1139
- return true;
1140
- }
1141
- const packageJsonPath = import_node_path4.default.join(repositoryRoot, "package.json");
1142
- if (!import_node_fs4.default.existsSync(packageJsonPath)) {
1143
- return false;
1144
- }
1145
- const packageJson = JSON.parse(
1146
- import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
1147
- );
1148
- return packageJson.workspaces !== void 0;
1149
- } catch (error) {
1150
- console.error("Error determining if repository is a monorepo", error);
1151
- return false;
1152
- }
1153
- }
1154
-
1155
- // src/config/microfrontends/utils/find-package-root.ts
1156
- var import_node_fs5 = __toESM(require("fs"), 1);
1157
- var import_node_path5 = __toESM(require("path"), 1);
1158
- var PACKAGE_JSON = "package.json";
1159
- function findPackageRoot(startDir) {
1160
- let currentDir = startDir || process.cwd();
1161
- while (currentDir !== import_node_path5.default.parse(currentDir).root) {
1162
- const pkgJsonPath = import_node_path5.default.join(currentDir, PACKAGE_JSON);
1163
- if (import_node_fs5.default.existsSync(pkgJsonPath)) {
1164
- return currentDir;
1165
- }
1166
- currentDir = import_node_path5.default.dirname(currentDir);
1167
- }
1168
- throw new Error(
1169
- "Package root not found. Specify the root of the package with the `package.root` option."
1170
- );
1171
- }
1172
-
1173
- // src/config/microfrontends/utils/find-config.ts
1174
- var import_node_fs6 = __toESM(require("fs"), 1);
1175
- var import_node_path6 = require("path");
1176
- function findConfig({ dir }) {
1177
- for (const filename of CONFIGURATION_FILENAMES) {
1178
- const maybeConfig = (0, import_node_path6.join)(dir, filename);
1179
- if (import_node_fs6.default.existsSync(maybeConfig)) {
1180
- return maybeConfig;
1181
- }
1182
- }
1183
- return null;
1184
- }
1185
-
1186
1029
  // src/config/microfrontends/utils/get-application-context.ts
1187
- var import_node_fs7 = __toESM(require("fs"), 1);
1188
- 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);
1189
1032
  function getApplicationContext(opts) {
1190
1033
  if (opts?.appName) {
1191
1034
  return { name: opts.appName };
@@ -1194,8 +1037,8 @@ function getApplicationContext(opts) {
1194
1037
  return { name: process.env.NX_TASK_TARGET_PROJECT };
1195
1038
  }
1196
1039
  try {
1197
- const packageJsonString = import_node_fs7.default.readFileSync(
1198
- 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"),
1199
1042
  "utf-8"
1200
1043
  );
1201
1044
  const packageJson = JSON.parse(packageJsonString);
@@ -1218,7 +1061,7 @@ function getApplicationContext(opts) {
1218
1061
  }
1219
1062
 
1220
1063
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1221
- var import_node_path8 = __toESM(require("path"), 1);
1064
+ var import_node_path7 = __toESM(require("path"), 1);
1222
1065
 
1223
1066
  // src/config/microfrontends/server/constants.ts
1224
1067
  var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
@@ -1226,7 +1069,7 @@ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
1226
1069
 
1227
1070
  // src/config/microfrontends/server/utils/get-output-file-path.ts
1228
1071
  function getOutputFilePath() {
1229
- 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);
1230
1073
  }
1231
1074
 
1232
1075
  // src/config/microfrontends/server/validation.ts
@@ -1239,16 +1082,6 @@ var schema_default = {
1239
1082
  $ref: "#/definitions/Config",
1240
1083
  definitions: {
1241
1084
  Config: {
1242
- anyOf: [
1243
- {
1244
- $ref: "#/definitions/MainConfig"
1245
- },
1246
- {
1247
- $ref: "#/definitions/ChildConfig"
1248
- }
1249
- ]
1250
- },
1251
- MainConfig: {
1252
1085
  type: "object",
1253
1086
  properties: {
1254
1087
  $schema: {
@@ -1505,27 +1338,6 @@ var schema_default = {
1505
1338
  },
1506
1339
  required: ["paths"],
1507
1340
  additionalProperties: false
1508
- },
1509
- ChildConfig: {
1510
- type: "object",
1511
- properties: {
1512
- $schema: {
1513
- type: "string"
1514
- },
1515
- version: {
1516
- type: "string",
1517
- const: "1"
1518
- },
1519
- options: {
1520
- $ref: "#/definitions/Options"
1521
- },
1522
- partOf: {
1523
- type: "string",
1524
- 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."
1525
- }
1526
- },
1527
- required: ["partOf"],
1528
- additionalProperties: false
1529
1341
  }
1530
1342
  }
1531
1343
  };
@@ -1534,13 +1346,54 @@ var schema_default = {
1534
1346
  var SCHEMA = schema_default;
1535
1347
 
1536
1348
  // src/config/microfrontends/server/validation.ts
1537
- function filterAjvErrors(errors) {
1349
+ var LIST_FORMATTER2 = new Intl.ListFormat("en", {
1350
+ style: "long",
1351
+ type: "disjunction"
1352
+ });
1353
+ function formatAjvErrors(errors) {
1538
1354
  if (!errors) {
1539
1355
  return [];
1540
1356
  }
1541
- return errors.filter((error) => {
1542
- return error.keyword === "additionalProperties" || error.keyword === "required";
1543
- });
1357
+ const errorMessages = [];
1358
+ for (const error of errors) {
1359
+ if (error.instancePath === "" && (error.keyword === "anyOf" || error.keyword === "required" && error.params.missingProperty === "partOf")) {
1360
+ continue;
1361
+ }
1362
+ const instancePath = error.instancePath.slice(1);
1363
+ const formattedInstancePath = instancePath === "" ? "at the root" : `in field ${instancePath}`;
1364
+ if (error.keyword === "required" && error.params.missingProperty === "routing" && instancePath.split("/").length === 2) {
1365
+ errorMessages.push(
1366
+ `Unable to infer if ${instancePath} is the default app or a child app. This usually means that there is another error in the configuration.`
1367
+ );
1368
+ } else if (error.keyword === "anyOf" && instancePath.split("/").length > 2) {
1369
+ const anyOfErrors = errors.filter(
1370
+ (e) => e.instancePath === error.instancePath && e.keyword !== "anyOf"
1371
+ );
1372
+ if (anyOfErrors.every((e) => e.keyword === "type")) {
1373
+ const allowedTypes = LIST_FORMATTER2.format(
1374
+ anyOfErrors.map((e) => {
1375
+ return e.keyword === "type" ? String(e.params.type) : "unknown";
1376
+ })
1377
+ );
1378
+ errorMessages.push(
1379
+ `Incorrect type for ${instancePath}. Must be one of ${allowedTypes}`
1380
+ );
1381
+ } else {
1382
+ errorMessages.push(
1383
+ `Invalid field for ${instancePath}. Possible error messages are ${LIST_FORMATTER2.format(anyOfErrors.map((e) => e.message ?? ""))}`
1384
+ );
1385
+ }
1386
+ } else if (error.keyword === "additionalProperties" && !(error.params.additionalProperty === "routing" && instancePath.split("/").length === 2)) {
1387
+ errorMessages.push(
1388
+ `Property '${error.params.additionalProperty}' is not allowed ${formattedInstancePath}`
1389
+ );
1390
+ } else if (error.keyword === "required") {
1391
+ errorMessages.push(
1392
+ `Property '${error.params.missingProperty}' is required ${formattedInstancePath}`
1393
+ );
1394
+ }
1395
+ }
1396
+ return errorMessages;
1544
1397
  }
1545
1398
  function validateSchema(configString) {
1546
1399
  const parsedConfig = (0, import_jsonc_parser3.parse)(configString);
@@ -1549,8 +1402,10 @@ function validateSchema(configString) {
1549
1402
  const isValid = validate(parsedConfig);
1550
1403
  if (!isValid) {
1551
1404
  throw new MicrofrontendError(
1552
- `Invalid microfrontends config:
1553
- - ${ajv.errorsText(filterAjvErrors(validate.errors), { separator: "\n - " })}
1405
+ `Invalid microfrontends config:${formatAjvErrors(validate.errors).map((error) => `
1406
+ - ${error}`).join(
1407
+ ""
1408
+ )}
1554
1409
 
1555
1410
  See https://openapi.vercel.sh/microfrontends.json for the schema.`,
1556
1411
  { type: "config", subtype: "does_not_match_schema" }
@@ -1560,7 +1415,13 @@ See https://openapi.vercel.sh/microfrontends.json for the schema.`,
1560
1415
  }
1561
1416
 
1562
1417
  // src/config/microfrontends/server/index.ts
1563
- var MicrofrontendsServer = class extends Microfrontends {
1418
+ var MicrofrontendsServer = class {
1419
+ constructor({
1420
+ config,
1421
+ overrides
1422
+ }) {
1423
+ this.config = new MicrofrontendConfigIsomorphic({ config, overrides });
1424
+ }
1564
1425
  /**
1565
1426
  * Writes the configuration to a file.
1566
1427
  */
@@ -1568,8 +1429,8 @@ var MicrofrontendsServer = class extends Microfrontends {
1568
1429
  pretty: true
1569
1430
  }) {
1570
1431
  const outputPath = getOutputFilePath();
1571
- import_node_fs8.default.mkdirSync((0, import_node_path9.dirname)(outputPath), { recursive: true });
1572
- 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(
1573
1434
  outputPath,
1574
1435
  JSON.stringify(
1575
1436
  this.config.toSchemaJson(),
@@ -1584,22 +1445,19 @@ var MicrofrontendsServer = class extends Microfrontends {
1584
1445
  */
1585
1446
  static fromUnknown({
1586
1447
  config,
1587
- cookies,
1588
- meta
1448
+ cookies
1589
1449
  }) {
1590
1450
  const overrides = cookies ? parseOverrides(cookies) : void 0;
1591
1451
  if (typeof config === "string") {
1592
1452
  return new MicrofrontendsServer({
1593
1453
  config: MicrofrontendsServer.validate(config),
1594
- overrides,
1595
- meta
1454
+ overrides
1596
1455
  });
1597
1456
  }
1598
1457
  if (typeof config === "object") {
1599
1458
  return new MicrofrontendsServer({
1600
1459
  config,
1601
- overrides,
1602
- meta
1460
+ overrides
1603
1461
  });
1604
1462
  }
1605
1463
  throw new MicrofrontendError(
@@ -1612,13 +1470,11 @@ var MicrofrontendsServer = class extends Microfrontends {
1612
1470
  * Uses additional validation that is only available when in a node runtime
1613
1471
  */
1614
1472
  static fromEnv({
1615
- cookies,
1616
- meta
1473
+ cookies
1617
1474
  }) {
1618
1475
  return new MicrofrontendsServer({
1619
1476
  config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
1620
- overrides: parseOverrides(cookies),
1621
- meta
1477
+ overrides: parseOverrides(cookies)
1622
1478
  });
1623
1479
  }
1624
1480
  /**
@@ -1641,29 +1497,22 @@ var MicrofrontendsServer = class extends Microfrontends {
1641
1497
  static infer({
1642
1498
  directory,
1643
1499
  filePath,
1644
- meta,
1645
- cookies,
1646
- options
1500
+ cookies
1647
1501
  } = {}) {
1648
- if (filePath && meta) {
1502
+ if (filePath) {
1649
1503
  return MicrofrontendsServer.fromFile({
1650
1504
  filePath,
1651
- cookies,
1652
- meta,
1653
- options
1505
+ cookies
1654
1506
  });
1655
1507
  }
1656
1508
  try {
1657
1509
  const packageRoot = findPackageRoot(directory);
1658
1510
  const { name: appName } = getApplicationContext({ packageRoot });
1659
- const configMeta = meta ?? { fromApp: appName };
1660
1511
  const maybeConfig = findConfig({ dir: packageRoot });
1661
1512
  if (maybeConfig) {
1662
1513
  return MicrofrontendsServer.fromFile({
1663
1514
  filePath: maybeConfig,
1664
- cookies,
1665
- meta: configMeta,
1666
- options
1515
+ cookies
1667
1516
  });
1668
1517
  }
1669
1518
  const repositoryRoot = findRepositoryRoot();
@@ -1677,14 +1526,15 @@ var MicrofrontendsServer = class extends Microfrontends {
1677
1526
  if (maybeConfigFromDefault) {
1678
1527
  return MicrofrontendsServer.fromFile({
1679
1528
  filePath: maybeConfigFromDefault,
1680
- cookies,
1681
- meta: configMeta,
1682
- options
1529
+ cookies
1683
1530
  });
1684
1531
  }
1685
1532
  }
1686
1533
  throw new Error("Unable to infer");
1687
1534
  } catch (e) {
1535
+ if (e instanceof MicrofrontendError) {
1536
+ throw e;
1537
+ }
1688
1538
  throw new MicrofrontendError(
1689
1539
  "Unable to locate and parse microfrontends configuration",
1690
1540
  { cause: e, type: "config", subtype: "inference_failed" }
@@ -1696,44 +1546,14 @@ var MicrofrontendsServer = class extends Microfrontends {
1696
1546
  */
1697
1547
  static fromFile({
1698
1548
  filePath,
1699
- cookies,
1700
- meta,
1701
- options
1549
+ cookies
1702
1550
  }) {
1703
1551
  try {
1704
- const configJson = import_node_fs8.default.readFileSync(filePath, "utf-8");
1552
+ const configJson = import_node_fs7.default.readFileSync(filePath, "utf-8");
1705
1553
  const config = MicrofrontendsServer.validate(configJson);
1706
- if (!isMainConfig(config) && options?.resolveMainConfig) {
1707
- const repositoryRoot = findRepositoryRoot();
1708
- const isMonorepo2 = isMonorepo({ repositoryRoot });
1709
- if (isMonorepo2) {
1710
- const packagePath = findPackagePath({
1711
- repositoryRoot,
1712
- name: config.partOf
1713
- });
1714
- if (!packagePath) {
1715
- throw new MicrofrontendError(
1716
- `Could not find default application "${config.partOf}" in the repository`,
1717
- { type: "config", subtype: "not_found" }
1718
- );
1719
- }
1720
- const maybeConfig = findConfig({ dir: packagePath });
1721
- if (!maybeConfig) {
1722
- throw new MicrofrontendError(
1723
- `Could not find microfrontends configuration in ${packagePath}`,
1724
- { type: "config", subtype: "not_found" }
1725
- );
1726
- }
1727
- return MicrofrontendsServer.fromMainConfigFile({
1728
- filePath: maybeConfig,
1729
- overrides: cookies ? parseOverrides(cookies) : void 0
1730
- });
1731
- }
1732
- }
1733
1554
  return new MicrofrontendsServer({
1734
1555
  config,
1735
- overrides: cookies ? parseOverrides(cookies) : void 0,
1736
- meta
1556
+ overrides: cookies ? parseOverrides(cookies) : void 0
1737
1557
  });
1738
1558
  } catch (e) {
1739
1559
  throw MicrofrontendError.handle(e, {
@@ -1742,24 +1562,15 @@ var MicrofrontendsServer = class extends Microfrontends {
1742
1562
  }
1743
1563
  }
1744
1564
  /*
1745
- * Generates a MicrofrontendMainConfig instance from a file.
1565
+ * Generates a MicrofrontendsServer instance from a file.
1746
1566
  */
1747
1567
  static fromMainConfigFile({
1748
1568
  filePath,
1749
1569
  overrides
1750
1570
  }) {
1751
1571
  try {
1752
- const config = import_node_fs8.default.readFileSync(filePath, "utf-8");
1572
+ const config = import_node_fs7.default.readFileSync(filePath, "utf-8");
1753
1573
  const validatedConfig = MicrofrontendsServer.validate(config);
1754
- if (!isMainConfig(validatedConfig)) {
1755
- throw new MicrofrontendError(
1756
- `${filePath} is not a main microfrontend config`,
1757
- {
1758
- type: "config",
1759
- subtype: "invalid_main_path"
1760
- }
1761
- );
1762
- }
1763
1574
  const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
1764
1575
  if (!defaultApplication) {
1765
1576
  throw new MicrofrontendError(
@@ -1769,8 +1580,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1769
1580
  }
1770
1581
  return new MicrofrontendsServer({
1771
1582
  config: validatedConfig,
1772
- overrides,
1773
- meta: { fromApp: defaultApplication }
1583
+ overrides
1774
1584
  });
1775
1585
  } catch (e) {
1776
1586
  throw MicrofrontendError.handle(e, {
@@ -1781,14 +1591,14 @@ var MicrofrontendsServer = class extends Microfrontends {
1781
1591
  };
1782
1592
 
1783
1593
  // src/vite/detect-framework.ts
1784
- var import_node_fs9 = require("fs");
1785
- var import_node_path10 = require("path");
1594
+ var import_node_fs8 = require("fs");
1595
+ var import_node_path9 = require("path");
1786
1596
  var import_node_process = require("process");
1787
1597
  function detectFramework() {
1788
- 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"))) {
1789
1599
  return "sveltekit";
1790
1600
  }
1791
- 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"))) {
1792
1602
  return "react-router";
1793
1603
  }
1794
1604
  return "unknown";
@@ -1797,43 +1607,39 @@ function detectFramework() {
1797
1607
  // src/vite/index.ts
1798
1608
  function microfrontends(opts) {
1799
1609
  const { name: fromApp } = getApplicationContext();
1800
- const microfrontendsObj = MicrofrontendsServer.infer({
1801
- meta: {
1802
- fromApp
1803
- }
1804
- });
1610
+ const microfrontendsObj = MicrofrontendsServer.infer();
1805
1611
  const app = microfrontendsObj.config.getApplication(fromApp);
1806
1612
  if (app.isDefault() && opts?.basePath) {
1807
1613
  throw new Error(
1808
1614
  "`basePath` can not be set for the default microfrontends application."
1809
1615
  );
1810
1616
  }
1811
- if (opts?.basePath && !opts.basePath.startsWith("/")) {
1812
- 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 `/`");
1813
1623
  }
1814
1624
  const additionalConfigOptions = {};
1815
- const framework = detectFramework();
1816
1625
  if (!app.isDefault()) {
1817
1626
  if (opts?.basePath) {
1627
+ const basePath = opts.basePath;
1818
1628
  if (framework !== "react-router" || !process.env.VERCEL_ENV) {
1819
- let basePath = opts.basePath;
1820
- if (process.env.NODE_ENV === "production" && !basePath.endsWith("/")) {
1821
- basePath = `${basePath}/`;
1822
- }
1823
1629
  additionalConfigOptions.base = basePath;
1824
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
+ }
1825
1640
  } else if (framework !== "sveltekit") {
1826
- additionalConfigOptions.experimental = {
1827
- renderBuiltUrl(filename, { type }) {
1828
- if (type === "asset") {
1829
- return `/${app.getAssetPrefix()}/${filename}`;
1830
- }
1831
- }
1832
- };
1833
- }
1834
- if (framework !== "sveltekit") {
1835
1641
  additionalConfigOptions.build = {
1836
- assetsDir: `./${opts?.basePath ?? app.getAssetPrefix()}`
1642
+ assetsDir: `./${app.getAssetPrefix()}`
1837
1643
  };
1838
1644
  }
1839
1645
  }
@@ -1841,6 +1647,15 @@ function microfrontends(opts) {
1841
1647
  additionalConfigOptions.server = {
1842
1648
  port: app.development.local.port
1843
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
+ );
1844
1659
  }
1845
1660
  return {
1846
1661
  name: "vite-plugin-vercel-microfrontends",