@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
@@ -4,7 +4,7 @@ import fs7 from "node:fs";
4
4
 
5
5
  // src/config/microfrontends/server/index.ts
6
6
  import fs6 from "node:fs";
7
- import { dirname as dirname3 } from "node:path";
7
+ import { dirname as dirname2 } from "node:path";
8
8
 
9
9
  // src/config/overrides/constants.ts
10
10
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
@@ -143,19 +143,177 @@ function getConfigStringFromEnv() {
143
143
  return config;
144
144
  }
145
145
 
146
- // src/config/microfrontends-config/isomorphic/index.ts
146
+ // src/config/schema/utils/is-default-app.ts
147
+ function isDefaultApp(a) {
148
+ return !("routing" in a);
149
+ }
150
+
151
+ // src/config/microfrontends/utils/find-repository-root.ts
152
+ import fs from "node:fs";
153
+ import path from "node:path";
154
+ var GIT_DIRECTORY = ".git";
155
+ function hasGitDirectory(dir) {
156
+ const gitPath = path.join(dir, GIT_DIRECTORY);
157
+ return fs.existsSync(gitPath) && fs.statSync(gitPath).isDirectory();
158
+ }
159
+ function hasPnpmWorkspaces(dir) {
160
+ return fs.existsSync(path.join(dir, "pnpm-workspace.yaml"));
161
+ }
162
+ function findRepositoryRoot(startDir) {
163
+ if (process.env.NX_WORKSPACE_ROOT) {
164
+ return process.env.NX_WORKSPACE_ROOT;
165
+ }
166
+ let currentDir = startDir || process.cwd();
167
+ while (currentDir !== path.parse(currentDir).root) {
168
+ if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
169
+ return currentDir;
170
+ }
171
+ currentDir = path.dirname(currentDir);
172
+ }
173
+ throw new Error(
174
+ "Repository root not found. Specify the root of the repository with the `repository.root` option."
175
+ );
176
+ }
177
+
178
+ // src/config/microfrontends/utils/find-default-package.ts
179
+ import { dirname } from "node:path";
180
+ import { readFileSync } from "node:fs";
147
181
  import { parse } from "jsonc-parser";
182
+ import fg from "fast-glob";
183
+
184
+ // src/config/constants.ts
185
+ var CONFIGURATION_FILENAMES = [
186
+ "microfrontends.jsonc",
187
+ "microfrontends.json"
188
+ ];
148
189
 
149
- // src/config/schema/utils/is-main-config.ts
150
- function isMainConfig(c) {
151
- return !("partOf" in c);
190
+ // src/config/microfrontends/utils/find-default-package.ts
191
+ var configCache = {};
192
+ function findDefaultMicrofrontendsPackages({
193
+ repositoryRoot,
194
+ applicationName
195
+ }) {
196
+ try {
197
+ const microfrontendsJsonPaths = fg.globSync(
198
+ `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
199
+ {
200
+ cwd: repositoryRoot,
201
+ absolute: true,
202
+ onlyFiles: true,
203
+ followSymbolicLinks: false,
204
+ ignore: ["**/node_modules/**", "**/.git/**"]
205
+ }
206
+ );
207
+ const matchingPaths = [];
208
+ for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
209
+ try {
210
+ const microfrontendsJsonContent = readFileSync(
211
+ microfrontendsJsonPath,
212
+ "utf-8"
213
+ );
214
+ const microfrontendsJson = parse(microfrontendsJsonContent);
215
+ if (microfrontendsJson.applications[applicationName]) {
216
+ matchingPaths.push(microfrontendsJsonPath);
217
+ }
218
+ } catch (error) {
219
+ }
220
+ }
221
+ if (matchingPaths.length > 1) {
222
+ throw new Error(
223
+ `Found multiple default applications referencing "${applicationName}" in the repository, but only one is allowed.
224
+ ${matchingPaths.join("\n \u2022 ")}`
225
+ );
226
+ }
227
+ if (matchingPaths.length === 0) {
228
+ throw new Error(
229
+ `Could not find default application with "applications.${applicationName}"`
230
+ );
231
+ }
232
+ const [packageJsonPath] = matchingPaths;
233
+ return dirname(packageJsonPath);
234
+ } catch (error) {
235
+ return null;
236
+ }
237
+ }
238
+ function findDefaultMicrofrontendsPackage(opts) {
239
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
240
+ if (configCache[cacheKey]) {
241
+ return configCache[cacheKey];
242
+ }
243
+ const result = findDefaultMicrofrontendsPackages(opts);
244
+ if (!result) {
245
+ throw new Error(
246
+ "Error trying to resolve the main microfrontends configuration"
247
+ );
248
+ }
249
+ configCache[cacheKey] = result;
250
+ return result;
152
251
  }
153
252
 
154
- // src/config/schema/utils/is-default-app.ts
155
- function isDefaultApp(a) {
156
- return !("routing" in a);
253
+ // src/config/microfrontends/utils/is-monorepo.ts
254
+ import fs2 from "node:fs";
255
+ import path2 from "node:path";
256
+ function isMonorepo({
257
+ repositoryRoot
258
+ }) {
259
+ try {
260
+ if (fs2.existsSync(path2.join(repositoryRoot, "pnpm-workspace.yaml"))) {
261
+ return true;
262
+ }
263
+ if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
264
+ return true;
265
+ }
266
+ if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
267
+ return true;
268
+ }
269
+ const packageJsonPath = path2.join(repositoryRoot, "package.json");
270
+ if (!fs2.existsSync(packageJsonPath)) {
271
+ return false;
272
+ }
273
+ const packageJson = JSON.parse(
274
+ fs2.readFileSync(packageJsonPath, "utf-8")
275
+ );
276
+ return packageJson.workspaces !== void 0;
277
+ } catch (error) {
278
+ console.error("Error determining if repository is a monorepo", error);
279
+ return false;
280
+ }
281
+ }
282
+
283
+ // src/config/microfrontends/utils/find-package-root.ts
284
+ import fs3 from "node:fs";
285
+ import path3 from "node:path";
286
+ var PACKAGE_JSON = "package.json";
287
+ function findPackageRoot(startDir) {
288
+ let currentDir = startDir || process.cwd();
289
+ while (currentDir !== path3.parse(currentDir).root) {
290
+ const pkgJsonPath = path3.join(currentDir, PACKAGE_JSON);
291
+ if (fs3.existsSync(pkgJsonPath)) {
292
+ return currentDir;
293
+ }
294
+ currentDir = path3.dirname(currentDir);
295
+ }
296
+ throw new Error(
297
+ "Package root not found. Specify the root of the package with the `package.root` option."
298
+ );
299
+ }
300
+
301
+ // src/config/microfrontends/utils/find-config.ts
302
+ import fs4 from "node:fs";
303
+ import { join } from "node:path";
304
+ function findConfig({ dir }) {
305
+ for (const filename of CONFIGURATION_FILENAMES) {
306
+ const maybeConfig = join(dir, filename);
307
+ if (fs4.existsSync(maybeConfig)) {
308
+ return maybeConfig;
309
+ }
310
+ }
311
+ return null;
157
312
  }
158
313
 
314
+ // src/config/microfrontends-config/isomorphic/index.ts
315
+ import { parse as parse2 } from "jsonc-parser";
316
+
159
317
  // src/config/microfrontends-config/client/index.ts
160
318
  import { pathToRegexp } from "path-to-regexp";
161
319
  var MicrofrontendConfigClient = class {
@@ -224,6 +382,10 @@ var MicrofrontendConfigClient = class {
224
382
 
225
383
  // src/config/microfrontends-config/isomorphic/validation.ts
226
384
  import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to-regexp";
385
+ var LIST_FORMATTER = new Intl.ListFormat("en", {
386
+ style: "long",
387
+ type: "conjunction"
388
+ });
227
389
  var validateConfigPaths = (applicationConfigsById) => {
228
390
  if (!applicationConfigsById) {
229
391
  return;
@@ -356,15 +518,15 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
356
518
  if (!applicationConfigsById) {
357
519
  return;
358
520
  }
359
- const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
360
- ([, app]) => !isDefaultApp(app)
361
- );
362
- const applicationsWithRoutingNames = applicationsWithRouting.map(
363
- ([key]) => key
521
+ const applicationsWithoutRouting = Object.entries(
522
+ applicationConfigsById
523
+ ).filter(([, app]) => isDefaultApp(app));
524
+ const numApplicationsWithoutRouting = applicationsWithoutRouting.reduce(
525
+ (acc) => {
526
+ return acc + 1;
527
+ },
528
+ 0
364
529
  );
365
- const numApplications = Object.keys(applicationConfigsById).length;
366
- const numApplicationsWithRouting = applicationsWithRoutingNames.length;
367
- const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
368
530
  if (numApplicationsWithoutRouting === 0) {
369
531
  throw new MicrofrontendError(
370
532
  "No default application found. At least one application needs to be the default by omitting routing.",
@@ -372,8 +534,11 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
372
534
  );
373
535
  }
374
536
  if (numApplicationsWithoutRouting > 1) {
537
+ const applicationNamesMissingRouting = applicationsWithoutRouting.map(
538
+ ([name]) => name
539
+ );
375
540
  throw new MicrofrontendError(
376
- `Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
541
+ `All applications except for the default app must contain the "routing" field. Applications that are missing routing: ${LIST_FORMATTER.format(applicationNamesMissingRouting)}.`,
377
542
  { type: "config", subtype: "multiple_default_applications" }
378
543
  );
379
544
  }
@@ -684,42 +849,28 @@ var MicrofrontendConfigIsomorphic = class {
684
849
  constructor({
685
850
  config,
686
851
  overrides,
687
- meta,
688
852
  opts
689
853
  }) {
690
854
  this.childApplications = {};
691
855
  MicrofrontendConfigIsomorphic.validate(config, opts);
692
856
  const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
693
857
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
694
- this.isMainConfig = isMainConfig(config);
695
- if (isMainConfig(config)) {
696
- for (const [appId, appConfig] of Object.entries(config.applications)) {
697
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
698
- if (isDefaultApp(appConfig)) {
699
- this.defaultApplication = new DefaultApplication(appId, {
700
- app: appConfig,
701
- overrides: appOverrides
702
- });
703
- } else {
704
- this.childApplications[appId] = new ChildApplication(appId, {
705
- app: appConfig,
706
- overrides: appOverrides
707
- });
708
- }
709
- }
710
- } else {
711
- this.partOf = config.partOf;
712
- const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
713
- this.childApplications[meta.fromApp] = new ChildApplication(
714
- meta.fromApp,
715
- {
716
- // we don't know routing because we're not in the main config
717
- app: { routing: [] },
858
+ let defaultApplication;
859
+ for (const [appId, appConfig] of Object.entries(config.applications)) {
860
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
861
+ if (isDefaultApp(appConfig)) {
862
+ defaultApplication = new DefaultApplication(appId, {
863
+ app: appConfig,
718
864
  overrides: appOverrides
719
- }
720
- );
865
+ });
866
+ } else {
867
+ this.childApplications[appId] = new ChildApplication(appId, {
868
+ app: appConfig,
869
+ overrides: appOverrides
870
+ });
871
+ }
721
872
  }
722
- if (isMainConfig(config) && !this.defaultApplication) {
873
+ if (!defaultApplication) {
723
874
  throw new MicrofrontendError(
724
875
  "Could not find default application in microfrontends configuration",
725
876
  {
@@ -728,34 +879,30 @@ var MicrofrontendConfigIsomorphic = class {
728
879
  }
729
880
  );
730
881
  }
882
+ this.defaultApplication = defaultApplication;
731
883
  this.config = config;
732
884
  this.options = config.options;
733
885
  this.serialized = {
734
886
  config,
735
- overrides,
736
- meta
887
+ overrides
737
888
  };
738
889
  }
739
890
  static validate(config, opts) {
740
891
  const skipValidation = opts?.skipValidation ?? [];
741
- const c = typeof config === "string" ? parse(config) : config;
742
- if (isMainConfig(c)) {
743
- validateConfigPaths(c.applications);
744
- validateConfigDefaultApplication(c.applications);
745
- if (!skipValidation.includes("deprecatedFields")) {
746
- validateDeprecatedFields(c);
747
- }
892
+ const c = typeof config === "string" ? parse2(config) : config;
893
+ validateConfigPaths(c.applications);
894
+ validateConfigDefaultApplication(c.applications);
895
+ if (!skipValidation.includes("deprecatedFields")) {
896
+ validateDeprecatedFields(c);
748
897
  }
749
898
  return c;
750
899
  }
751
900
  static fromEnv({
752
- meta,
753
901
  cookies
754
902
  }) {
755
903
  return new MicrofrontendConfigIsomorphic({
756
- config: parse(getConfigStringFromEnv()),
757
- overrides: parseOverrides(cookies ?? []),
758
- meta
904
+ config: parse2(getConfigStringFromEnv()),
905
+ overrides: parseOverrides(cookies ?? [])
759
906
  });
760
907
  }
761
908
  isOverridesDisabled() {
@@ -780,7 +927,7 @@ var MicrofrontendConfigIsomorphic = class {
780
927
  ].filter(Boolean);
781
928
  }
782
929
  getApplication(name) {
783
- if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
930
+ if (this.defaultApplication.name === name || this.defaultApplication.packageName === name) {
784
931
  return this.defaultApplication;
785
932
  }
786
933
  const app = this.childApplications[name] || Object.values(this.childApplications).find(
@@ -798,7 +945,7 @@ var MicrofrontendConfigIsomorphic = class {
798
945
  return app;
799
946
  }
800
947
  getApplicationByProjectId(projectId) {
801
- if (this.defaultApplication?.projectId === projectId) {
948
+ if (this.defaultApplication.projectId === projectId) {
802
949
  return this.defaultApplication;
803
950
  }
804
951
  return Object.values(this.childApplications).find(
@@ -806,19 +953,9 @@ var MicrofrontendConfigIsomorphic = class {
806
953
  );
807
954
  }
808
955
  /**
809
- * Returns the default application. This can throw if the default application
810
- * is undefined ( )
956
+ * Returns the default application.
811
957
  */
812
958
  getDefaultApplication() {
813
- if (!this.defaultApplication) {
814
- throw new MicrofrontendError(
815
- "Could not find default application in microfrontends configuration",
816
- {
817
- type: "application",
818
- subtype: "not_found"
819
- }
820
- );
821
- }
822
959
  return this.defaultApplication;
823
960
  }
824
961
  /**
@@ -845,11 +982,9 @@ var MicrofrontendConfigIsomorphic = class {
845
982
  }
846
983
  ])
847
984
  );
848
- if (this.defaultApplication) {
849
- applications[this.defaultApplication.name] = {
850
- default: true
851
- };
852
- }
985
+ applications[this.defaultApplication.name] = {
986
+ default: true
987
+ };
853
988
  return new MicrofrontendConfigClient({
854
989
  applications
855
990
  });
@@ -859,298 +994,6 @@ var MicrofrontendConfigIsomorphic = class {
859
994
  }
860
995
  };
861
996
 
862
- // src/config/microfrontends-config/isomorphic/child.ts
863
- var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
864
- constructor({
865
- config,
866
- overrides,
867
- meta
868
- }) {
869
- super({ config, overrides, meta });
870
- this.isMainConfig = false;
871
- this.partOf = config.partOf;
872
- }
873
- };
874
-
875
- // src/config/microfrontends-config/isomorphic/main.ts
876
- var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
877
- constructor({
878
- config,
879
- overrides,
880
- meta
881
- }) {
882
- super({ config, overrides, meta });
883
- this.isMainConfig = true;
884
- const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
885
- let defaultApplication;
886
- for (const [appId, appConfig] of Object.entries(config.applications)) {
887
- const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
888
- if (isDefaultApp(appConfig)) {
889
- defaultApplication = new DefaultApplication(appId, {
890
- app: appConfig,
891
- overrides: appOverrides
892
- });
893
- } else {
894
- this.childApplications[appId] = new ChildApplication(appId, {
895
- app: appConfig,
896
- overrides: appOverrides
897
- });
898
- }
899
- }
900
- if (!defaultApplication) {
901
- throw new MicrofrontendError(
902
- "Could not find default application in microfrontends configuration",
903
- {
904
- type: "application",
905
- subtype: "not_found"
906
- }
907
- );
908
- }
909
- this.defaultApplication = defaultApplication;
910
- }
911
- };
912
-
913
- // src/config/microfrontends/isomorphic/index.ts
914
- var Microfrontends = class {
915
- constructor({
916
- config,
917
- overrides,
918
- meta
919
- }) {
920
- if (isMainConfig(config)) {
921
- this.config = new MicrofrontendMainConfig({ config, overrides, meta });
922
- } else {
923
- this.config = new MicrofrontendChildConfig({ config, overrides, meta });
924
- }
925
- }
926
- isChildConfig() {
927
- return this.config instanceof MicrofrontendChildConfig;
928
- }
929
- static fromEnv({
930
- cookies,
931
- meta
932
- }) {
933
- const config = MicrofrontendConfigIsomorphic.fromEnv({
934
- cookies,
935
- meta
936
- });
937
- return new Microfrontends(config.serialize());
938
- }
939
- };
940
-
941
- // src/config/microfrontends/utils/find-repository-root.ts
942
- import fs from "node:fs";
943
- import path from "node:path";
944
- var GIT_DIRECTORY = ".git";
945
- function findRepositoryRoot(startDir) {
946
- if (process.env.NX_WORKSPACE_ROOT) {
947
- return process.env.NX_WORKSPACE_ROOT;
948
- }
949
- let currentDir = startDir || process.cwd();
950
- while (currentDir !== path.parse(currentDir).root) {
951
- const gitPath = path.join(currentDir, GIT_DIRECTORY);
952
- if (fs.existsSync(gitPath) && fs.statSync(gitPath).isDirectory()) {
953
- return currentDir;
954
- }
955
- currentDir = path.dirname(currentDir);
956
- }
957
- throw new Error(
958
- "Repository root not found. Specify the root of the repository with the `repository.root` option."
959
- );
960
- }
961
-
962
- // src/config/microfrontends/utils/find-package-path.ts
963
- import { dirname } from "node:path";
964
- import { readFileSync } from "node:fs";
965
- import fg from "fast-glob";
966
- var configCache = {};
967
- function findPackagePathWithGlob({
968
- repositoryRoot,
969
- name
970
- }) {
971
- try {
972
- const packageJsonPaths = fg.globSync("**/package.json", {
973
- cwd: repositoryRoot,
974
- absolute: true,
975
- onlyFiles: true,
976
- followSymbolicLinks: false,
977
- ignore: ["**/node_modules/**", "**/.git/**"]
978
- });
979
- const matchingPaths = [];
980
- for (const packageJsonPath2 of packageJsonPaths) {
981
- const packageJsonContent = readFileSync(packageJsonPath2, "utf-8");
982
- const packageJson = JSON.parse(packageJsonContent);
983
- if (packageJson.name === name) {
984
- matchingPaths.push(packageJsonPath2);
985
- }
986
- }
987
- if (matchingPaths.length > 1) {
988
- throw new Error(
989
- `Found multiple packages with the name "${name}" in the repository: ${matchingPaths.join(", ")}`
990
- );
991
- }
992
- if (matchingPaths.length === 0) {
993
- throw new Error(
994
- `Could not find package with the name "${name}" in the repository`
995
- );
996
- }
997
- const [packageJsonPath] = matchingPaths;
998
- return dirname(packageJsonPath);
999
- } catch (error) {
1000
- return null;
1001
- }
1002
- }
1003
- function findPackagePath(opts) {
1004
- const cacheKey = `${opts.repositoryRoot}-${opts.name}`;
1005
- if (configCache[cacheKey]) {
1006
- return configCache[cacheKey];
1007
- }
1008
- const result = findPackagePathWithGlob(opts);
1009
- if (!result) {
1010
- throw new Error(
1011
- `Could not find package with the name "${opts.name}" in the repository`
1012
- );
1013
- }
1014
- configCache[cacheKey] = result;
1015
- return result;
1016
- }
1017
-
1018
- // src/config/microfrontends/utils/find-default-package.ts
1019
- import { dirname as dirname2 } from "node:path";
1020
- import { readFileSync as readFileSync2 } from "node:fs";
1021
- import { parse as parse2 } from "jsonc-parser";
1022
- import fg2 from "fast-glob";
1023
-
1024
- // src/config/constants.ts
1025
- var CONFIGURATION_FILENAMES = [
1026
- "microfrontends.jsonc",
1027
- "microfrontends.json"
1028
- ];
1029
-
1030
- // src/config/microfrontends/utils/find-default-package.ts
1031
- var configCache2 = {};
1032
- function findDefaultMicrofrontendsPackages({
1033
- repositoryRoot,
1034
- applicationName
1035
- }) {
1036
- try {
1037
- const microfrontendsJsonPaths = fg2.globSync(
1038
- `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
1039
- {
1040
- cwd: repositoryRoot,
1041
- absolute: true,
1042
- onlyFiles: true,
1043
- followSymbolicLinks: false,
1044
- ignore: ["**/node_modules/**", "**/.git/**"]
1045
- }
1046
- );
1047
- const matchingPaths = [];
1048
- for (const microfrontendsJsonPath of microfrontendsJsonPaths) {
1049
- try {
1050
- const microfrontendsJsonContent = readFileSync2(
1051
- microfrontendsJsonPath,
1052
- "utf-8"
1053
- );
1054
- const microfrontendsJson = parse2(microfrontendsJsonContent);
1055
- if (isMainConfig(microfrontendsJson) && microfrontendsJson.applications[applicationName]) {
1056
- matchingPaths.push(microfrontendsJsonPath);
1057
- }
1058
- } catch (error) {
1059
- }
1060
- }
1061
- if (matchingPaths.length > 1) {
1062
- throw new Error(
1063
- `Found multiple default applications referencing "${applicationName}" in the repository, this is not yet supported.
1064
- ${matchingPaths.join("\n \u2022 ")}`
1065
- );
1066
- }
1067
- if (matchingPaths.length === 0) {
1068
- throw new Error(
1069
- `Could not find default application with "applications.${applicationName}"`
1070
- );
1071
- }
1072
- const [packageJsonPath] = matchingPaths;
1073
- return dirname2(packageJsonPath);
1074
- } catch (error) {
1075
- return null;
1076
- }
1077
- }
1078
- function findDefaultMicrofrontendsPackage(opts) {
1079
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationName}`;
1080
- if (configCache2[cacheKey]) {
1081
- return configCache2[cacheKey];
1082
- }
1083
- const result = findDefaultMicrofrontendsPackages(opts);
1084
- if (!result) {
1085
- throw new Error(
1086
- "Error trying to resolve the main microfrontends configuration"
1087
- );
1088
- }
1089
- configCache2[cacheKey] = result;
1090
- return result;
1091
- }
1092
-
1093
- // src/config/microfrontends/utils/is-monorepo.ts
1094
- import fs2 from "node:fs";
1095
- import path2 from "node:path";
1096
- function isMonorepo({
1097
- repositoryRoot
1098
- }) {
1099
- try {
1100
- if (fs2.existsSync(path2.join(repositoryRoot, "pnpm-workspace.yaml"))) {
1101
- return true;
1102
- }
1103
- if (fs2.existsSync(path2.join(repositoryRoot, "vlt-workspaces.json"))) {
1104
- return true;
1105
- }
1106
- if (process.env.NX_WORKSPACE_ROOT === path2.resolve(repositoryRoot)) {
1107
- return true;
1108
- }
1109
- const packageJsonPath = path2.join(repositoryRoot, "package.json");
1110
- if (!fs2.existsSync(packageJsonPath)) {
1111
- return false;
1112
- }
1113
- const packageJson = JSON.parse(
1114
- fs2.readFileSync(packageJsonPath, "utf-8")
1115
- );
1116
- return packageJson.workspaces !== void 0;
1117
- } catch (error) {
1118
- console.error("Error determining if repository is a monorepo", error);
1119
- return false;
1120
- }
1121
- }
1122
-
1123
- // src/config/microfrontends/utils/find-package-root.ts
1124
- import fs3 from "node:fs";
1125
- import path3 from "node:path";
1126
- var PACKAGE_JSON = "package.json";
1127
- function findPackageRoot(startDir) {
1128
- let currentDir = startDir || process.cwd();
1129
- while (currentDir !== path3.parse(currentDir).root) {
1130
- const pkgJsonPath = path3.join(currentDir, PACKAGE_JSON);
1131
- if (fs3.existsSync(pkgJsonPath)) {
1132
- return currentDir;
1133
- }
1134
- currentDir = path3.dirname(currentDir);
1135
- }
1136
- throw new Error(
1137
- "Package root not found. Specify the root of the package with the `package.root` option."
1138
- );
1139
- }
1140
-
1141
- // src/config/microfrontends/utils/find-config.ts
1142
- import fs4 from "node:fs";
1143
- import { join } from "node:path";
1144
- function findConfig({ dir }) {
1145
- for (const filename of CONFIGURATION_FILENAMES) {
1146
- const maybeConfig = join(dir, filename);
1147
- if (fs4.existsSync(maybeConfig)) {
1148
- return maybeConfig;
1149
- }
1150
- }
1151
- return null;
1152
- }
1153
-
1154
997
  // src/config/microfrontends/utils/get-application-context.ts
1155
998
  import fs5 from "node:fs";
1156
999
  import path4 from "node:path";
@@ -1207,16 +1050,6 @@ var schema_default = {
1207
1050
  $ref: "#/definitions/Config",
1208
1051
  definitions: {
1209
1052
  Config: {
1210
- anyOf: [
1211
- {
1212
- $ref: "#/definitions/MainConfig"
1213
- },
1214
- {
1215
- $ref: "#/definitions/ChildConfig"
1216
- }
1217
- ]
1218
- },
1219
- MainConfig: {
1220
1053
  type: "object",
1221
1054
  properties: {
1222
1055
  $schema: {
@@ -1473,27 +1306,6 @@ var schema_default = {
1473
1306
  },
1474
1307
  required: ["paths"],
1475
1308
  additionalProperties: false
1476
- },
1477
- ChildConfig: {
1478
- type: "object",
1479
- properties: {
1480
- $schema: {
1481
- type: "string"
1482
- },
1483
- version: {
1484
- type: "string",
1485
- const: "1"
1486
- },
1487
- options: {
1488
- $ref: "#/definitions/Options"
1489
- },
1490
- partOf: {
1491
- type: "string",
1492
- 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."
1493
- }
1494
- },
1495
- required: ["partOf"],
1496
- additionalProperties: false
1497
1309
  }
1498
1310
  }
1499
1311
  };
@@ -1502,13 +1314,54 @@ var schema_default = {
1502
1314
  var SCHEMA = schema_default;
1503
1315
 
1504
1316
  // src/config/microfrontends/server/validation.ts
1505
- function filterAjvErrors(errors) {
1317
+ var LIST_FORMATTER2 = new Intl.ListFormat("en", {
1318
+ style: "long",
1319
+ type: "disjunction"
1320
+ });
1321
+ function formatAjvErrors(errors) {
1506
1322
  if (!errors) {
1507
1323
  return [];
1508
1324
  }
1509
- return errors.filter((error) => {
1510
- return error.keyword === "additionalProperties" || error.keyword === "required";
1511
- });
1325
+ const errorMessages = [];
1326
+ for (const error of errors) {
1327
+ if (error.instancePath === "" && (error.keyword === "anyOf" || error.keyword === "required" && error.params.missingProperty === "partOf")) {
1328
+ continue;
1329
+ }
1330
+ const instancePath = error.instancePath.slice(1);
1331
+ const formattedInstancePath = instancePath === "" ? "at the root" : `in field ${instancePath}`;
1332
+ if (error.keyword === "required" && error.params.missingProperty === "routing" && instancePath.split("/").length === 2) {
1333
+ errorMessages.push(
1334
+ `Unable to infer if ${instancePath} is the default app or a child app. This usually means that there is another error in the configuration.`
1335
+ );
1336
+ } else if (error.keyword === "anyOf" && instancePath.split("/").length > 2) {
1337
+ const anyOfErrors = errors.filter(
1338
+ (e) => e.instancePath === error.instancePath && e.keyword !== "anyOf"
1339
+ );
1340
+ if (anyOfErrors.every((e) => e.keyword === "type")) {
1341
+ const allowedTypes = LIST_FORMATTER2.format(
1342
+ anyOfErrors.map((e) => {
1343
+ return e.keyword === "type" ? String(e.params.type) : "unknown";
1344
+ })
1345
+ );
1346
+ errorMessages.push(
1347
+ `Incorrect type for ${instancePath}. Must be one of ${allowedTypes}`
1348
+ );
1349
+ } else {
1350
+ errorMessages.push(
1351
+ `Invalid field for ${instancePath}. Possible error messages are ${LIST_FORMATTER2.format(anyOfErrors.map((e) => e.message ?? ""))}`
1352
+ );
1353
+ }
1354
+ } else if (error.keyword === "additionalProperties" && !(error.params.additionalProperty === "routing" && instancePath.split("/").length === 2)) {
1355
+ errorMessages.push(
1356
+ `Property '${error.params.additionalProperty}' is not allowed ${formattedInstancePath}`
1357
+ );
1358
+ } else if (error.keyword === "required") {
1359
+ errorMessages.push(
1360
+ `Property '${error.params.missingProperty}' is required ${formattedInstancePath}`
1361
+ );
1362
+ }
1363
+ }
1364
+ return errorMessages;
1512
1365
  }
1513
1366
  function validateSchema(configString) {
1514
1367
  const parsedConfig = parse3(configString);
@@ -1517,8 +1370,10 @@ function validateSchema(configString) {
1517
1370
  const isValid = validate(parsedConfig);
1518
1371
  if (!isValid) {
1519
1372
  throw new MicrofrontendError(
1520
- `Invalid microfrontends config:
1521
- - ${ajv.errorsText(filterAjvErrors(validate.errors), { separator: "\n - " })}
1373
+ `Invalid microfrontends config:${formatAjvErrors(validate.errors).map((error) => `
1374
+ - ${error}`).join(
1375
+ ""
1376
+ )}
1522
1377
 
1523
1378
  See https://openapi.vercel.sh/microfrontends.json for the schema.`,
1524
1379
  { type: "config", subtype: "does_not_match_schema" }
@@ -1528,7 +1383,13 @@ See https://openapi.vercel.sh/microfrontends.json for the schema.`,
1528
1383
  }
1529
1384
 
1530
1385
  // src/config/microfrontends/server/index.ts
1531
- var MicrofrontendsServer = class extends Microfrontends {
1386
+ var MicrofrontendsServer = class {
1387
+ constructor({
1388
+ config,
1389
+ overrides
1390
+ }) {
1391
+ this.config = new MicrofrontendConfigIsomorphic({ config, overrides });
1392
+ }
1532
1393
  /**
1533
1394
  * Writes the configuration to a file.
1534
1395
  */
@@ -1536,7 +1397,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1536
1397
  pretty: true
1537
1398
  }) {
1538
1399
  const outputPath = getOutputFilePath();
1539
- fs6.mkdirSync(dirname3(outputPath), { recursive: true });
1400
+ fs6.mkdirSync(dirname2(outputPath), { recursive: true });
1540
1401
  fs6.writeFileSync(
1541
1402
  outputPath,
1542
1403
  JSON.stringify(
@@ -1552,22 +1413,19 @@ var MicrofrontendsServer = class extends Microfrontends {
1552
1413
  */
1553
1414
  static fromUnknown({
1554
1415
  config,
1555
- cookies,
1556
- meta
1416
+ cookies
1557
1417
  }) {
1558
1418
  const overrides = cookies ? parseOverrides(cookies) : void 0;
1559
1419
  if (typeof config === "string") {
1560
1420
  return new MicrofrontendsServer({
1561
1421
  config: MicrofrontendsServer.validate(config),
1562
- overrides,
1563
- meta
1422
+ overrides
1564
1423
  });
1565
1424
  }
1566
1425
  if (typeof config === "object") {
1567
1426
  return new MicrofrontendsServer({
1568
1427
  config,
1569
- overrides,
1570
- meta
1428
+ overrides
1571
1429
  });
1572
1430
  }
1573
1431
  throw new MicrofrontendError(
@@ -1580,13 +1438,11 @@ var MicrofrontendsServer = class extends Microfrontends {
1580
1438
  * Uses additional validation that is only available when in a node runtime
1581
1439
  */
1582
1440
  static fromEnv({
1583
- cookies,
1584
- meta
1441
+ cookies
1585
1442
  }) {
1586
1443
  return new MicrofrontendsServer({
1587
1444
  config: MicrofrontendsServer.validate(getConfigStringFromEnv()),
1588
- overrides: parseOverrides(cookies),
1589
- meta
1445
+ overrides: parseOverrides(cookies)
1590
1446
  });
1591
1447
  }
1592
1448
  /**
@@ -1609,29 +1465,22 @@ var MicrofrontendsServer = class extends Microfrontends {
1609
1465
  static infer({
1610
1466
  directory,
1611
1467
  filePath,
1612
- meta,
1613
- cookies,
1614
- options
1468
+ cookies
1615
1469
  } = {}) {
1616
- if (filePath && meta) {
1470
+ if (filePath) {
1617
1471
  return MicrofrontendsServer.fromFile({
1618
1472
  filePath,
1619
- cookies,
1620
- meta,
1621
- options
1473
+ cookies
1622
1474
  });
1623
1475
  }
1624
1476
  try {
1625
1477
  const packageRoot = findPackageRoot(directory);
1626
1478
  const { name: appName } = getApplicationContext({ packageRoot });
1627
- const configMeta = meta ?? { fromApp: appName };
1628
1479
  const maybeConfig = findConfig({ dir: packageRoot });
1629
1480
  if (maybeConfig) {
1630
1481
  return MicrofrontendsServer.fromFile({
1631
1482
  filePath: maybeConfig,
1632
- cookies,
1633
- meta: configMeta,
1634
- options
1483
+ cookies
1635
1484
  });
1636
1485
  }
1637
1486
  const repositoryRoot = findRepositoryRoot();
@@ -1645,14 +1494,15 @@ var MicrofrontendsServer = class extends Microfrontends {
1645
1494
  if (maybeConfigFromDefault) {
1646
1495
  return MicrofrontendsServer.fromFile({
1647
1496
  filePath: maybeConfigFromDefault,
1648
- cookies,
1649
- meta: configMeta,
1650
- options
1497
+ cookies
1651
1498
  });
1652
1499
  }
1653
1500
  }
1654
1501
  throw new Error("Unable to infer");
1655
1502
  } catch (e) {
1503
+ if (e instanceof MicrofrontendError) {
1504
+ throw e;
1505
+ }
1656
1506
  throw new MicrofrontendError(
1657
1507
  "Unable to locate and parse microfrontends configuration",
1658
1508
  { cause: e, type: "config", subtype: "inference_failed" }
@@ -1664,44 +1514,14 @@ var MicrofrontendsServer = class extends Microfrontends {
1664
1514
  */
1665
1515
  static fromFile({
1666
1516
  filePath,
1667
- cookies,
1668
- meta,
1669
- options
1517
+ cookies
1670
1518
  }) {
1671
1519
  try {
1672
1520
  const configJson = fs6.readFileSync(filePath, "utf-8");
1673
1521
  const config = MicrofrontendsServer.validate(configJson);
1674
- if (!isMainConfig(config) && options?.resolveMainConfig) {
1675
- const repositoryRoot = findRepositoryRoot();
1676
- const isMonorepo2 = isMonorepo({ repositoryRoot });
1677
- if (isMonorepo2) {
1678
- const packagePath = findPackagePath({
1679
- repositoryRoot,
1680
- name: config.partOf
1681
- });
1682
- if (!packagePath) {
1683
- throw new MicrofrontendError(
1684
- `Could not find default application "${config.partOf}" in the repository`,
1685
- { type: "config", subtype: "not_found" }
1686
- );
1687
- }
1688
- const maybeConfig = findConfig({ dir: packagePath });
1689
- if (!maybeConfig) {
1690
- throw new MicrofrontendError(
1691
- `Could not find microfrontends configuration in ${packagePath}`,
1692
- { type: "config", subtype: "not_found" }
1693
- );
1694
- }
1695
- return MicrofrontendsServer.fromMainConfigFile({
1696
- filePath: maybeConfig,
1697
- overrides: cookies ? parseOverrides(cookies) : void 0
1698
- });
1699
- }
1700
- }
1701
1522
  return new MicrofrontendsServer({
1702
1523
  config,
1703
- overrides: cookies ? parseOverrides(cookies) : void 0,
1704
- meta
1524
+ overrides: cookies ? parseOverrides(cookies) : void 0
1705
1525
  });
1706
1526
  } catch (e) {
1707
1527
  throw MicrofrontendError.handle(e, {
@@ -1710,7 +1530,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1710
1530
  }
1711
1531
  }
1712
1532
  /*
1713
- * Generates a MicrofrontendMainConfig instance from a file.
1533
+ * Generates a MicrofrontendsServer instance from a file.
1714
1534
  */
1715
1535
  static fromMainConfigFile({
1716
1536
  filePath,
@@ -1719,15 +1539,6 @@ var MicrofrontendsServer = class extends Microfrontends {
1719
1539
  try {
1720
1540
  const config = fs6.readFileSync(filePath, "utf-8");
1721
1541
  const validatedConfig = MicrofrontendsServer.validate(config);
1722
- if (!isMainConfig(validatedConfig)) {
1723
- throw new MicrofrontendError(
1724
- `${filePath} is not a main microfrontend config`,
1725
- {
1726
- type: "config",
1727
- subtype: "invalid_main_path"
1728
- }
1729
- );
1730
- }
1731
1542
  const [defaultApplication] = Object.entries(validatedConfig.applications).filter(([, app]) => isDefaultApp(app)).map(([name]) => name);
1732
1543
  if (!defaultApplication) {
1733
1544
  throw new MicrofrontendError(
@@ -1737,8 +1548,7 @@ var MicrofrontendsServer = class extends Microfrontends {
1737
1548
  }
1738
1549
  return new MicrofrontendsServer({
1739
1550
  config: validatedConfig,
1740
- overrides,
1741
- meta: { fromApp: defaultApplication }
1551
+ overrides
1742
1552
  });
1743
1553
  } catch (e) {
1744
1554
  throw MicrofrontendError.handle(e, {
@@ -1776,9 +1586,7 @@ function loadConfig({
1776
1586
  let config;
1777
1587
  try {
1778
1588
  config = MicrofrontendsServer.infer({
1779
- directory: packageDir,
1780
- meta: { fromApp: appName },
1781
- options: { resolveMainConfig: true }
1589
+ directory: packageDir
1782
1590
  });
1783
1591
  } catch (e) {
1784
1592
  return void 0;