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