@vercel/microfrontends 1.4.1 → 1.5.0-canary.0

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 (48) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/bin/cli.cjs +38 -74
  3. package/dist/config.cjs +4 -46
  4. package/dist/config.cjs.map +1 -1
  5. package/dist/config.d.ts +5 -11
  6. package/dist/config.js +4 -46
  7. package/dist/config.js.map +1 -1
  8. package/dist/experimental/sveltekit.cjs +37 -73
  9. package/dist/experimental/sveltekit.cjs.map +1 -1
  10. package/dist/experimental/sveltekit.js +37 -73
  11. package/dist/experimental/sveltekit.js.map +1 -1
  12. package/dist/experimental/vite.cjs +37 -73
  13. package/dist/experimental/vite.cjs.map +1 -1
  14. package/dist/experimental/vite.js +37 -73
  15. package/dist/experimental/vite.js.map +1 -1
  16. package/dist/microfrontends/server.cjs +37 -73
  17. package/dist/microfrontends/server.cjs.map +1 -1
  18. package/dist/microfrontends/server.d.ts +2 -2
  19. package/dist/microfrontends/server.js +37 -73
  20. package/dist/microfrontends/server.js.map +1 -1
  21. package/dist/next/config.cjs +41 -73
  22. package/dist/next/config.cjs.map +1 -1
  23. package/dist/next/config.js +41 -73
  24. package/dist/next/config.js.map +1 -1
  25. package/dist/next/middleware.cjs +4 -46
  26. package/dist/next/middleware.cjs.map +1 -1
  27. package/dist/next/middleware.js +4 -46
  28. package/dist/next/middleware.js.map +1 -1
  29. package/dist/next/testing.cjs +4 -46
  30. package/dist/next/testing.cjs.map +1 -1
  31. package/dist/next/testing.d.ts +2 -2
  32. package/dist/next/testing.js +4 -46
  33. package/dist/next/testing.js.map +1 -1
  34. package/dist/overrides.d.ts +3 -3
  35. package/dist/schema.d.ts +2 -2
  36. package/dist/{types-ab31c948.d.ts → types-1cec43e6.d.ts} +0 -15
  37. package/dist/{types-d3cb74a6.d.ts → types-1fb60496.d.ts} +1 -1
  38. package/dist/utils/mfe-port.cjs +37 -73
  39. package/dist/utils/mfe-port.cjs.map +1 -1
  40. package/dist/utils/mfe-port.js +37 -73
  41. package/dist/utils/mfe-port.js.map +1 -1
  42. package/dist/validation.cjs +23 -27
  43. package/dist/validation.cjs.map +1 -1
  44. package/dist/validation.d.ts +1 -1
  45. package/dist/validation.js +23 -27
  46. package/dist/validation.js.map +1 -1
  47. package/package.json +1 -1
  48. package/schema/schema.json +0 -20
@@ -155,17 +155,27 @@ function hasGitDirectory(dir) {
155
155
  function hasPnpmWorkspaces(dir) {
156
156
  return fs.existsSync(path.join(dir, "pnpm-workspace.yaml"));
157
157
  }
158
+ function hasPackageJson(dir) {
159
+ return fs.existsSync(path.join(dir, "package.json"));
160
+ }
158
161
  function findRepositoryRoot(startDir) {
159
162
  if (process.env.NX_WORKSPACE_ROOT) {
160
163
  return process.env.NX_WORKSPACE_ROOT;
161
164
  }
162
165
  let currentDir = startDir || process.cwd();
166
+ let lastPackageJsonDir = null;
163
167
  while (currentDir !== path.parse(currentDir).root) {
164
168
  if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
165
169
  return currentDir;
166
170
  }
171
+ if (hasPackageJson(currentDir)) {
172
+ lastPackageJsonDir = currentDir;
173
+ }
167
174
  currentDir = path.dirname(currentDir);
168
175
  }
176
+ if (lastPackageJsonDir) {
177
+ return lastPackageJsonDir;
178
+ }
169
179
  throw new Error(
170
180
  `Could not find the root of the repository for ${startDir}. Please ensure that the directory is part of a Git repository. If you suspect that this should work, please file an issue to the Vercel team.`
171
181
  );
@@ -561,33 +571,6 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
561
571
  );
562
572
  }
563
573
  };
564
- var validateDeprecatedFields = (config) => {
565
- const errors = [];
566
- for (const [applicationId, application] of Object.entries(
567
- config.applications
568
- )) {
569
- if (application.development?.localPort) {
570
- errors.push(
571
- `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
572
- );
573
- }
574
- if (application.projectId) {
575
- errors.push(
576
- `Application '${applicationId}' cannot contain deprecated field 'projectId'. If the application ID matches the Vercel project name, then please remove the 'projectId' field. Otherwise, either update the application ID / Vercel project name to match, or set the 'packageName' field to the name of the package.json name.`
577
- );
578
- }
579
- }
580
- if (errors.length) {
581
- throw new MicrofrontendError(
582
- `Microfrontends configuration file errors:
583
- - ${errors.join("\n- ")}`,
584
- {
585
- type: "config",
586
- subtype: "depcrecated_field"
587
- }
588
- );
589
- }
590
- };
591
574
 
592
575
  // src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
593
576
  var PREFIX = "vc-ap";
@@ -692,20 +675,12 @@ var Host = class {
692
675
  var LocalHost = class extends Host {
693
676
  constructor({
694
677
  appName,
695
- localPort,
696
678
  local
697
679
  }) {
698
- if (localPort && local) {
699
- throw new Error(
700
- `Microfrontends configuration error: '${appName}' has both the 'development.local' and 'development.localPort' fields set. Please remove the 'development.localPort' field and ensure the 'development.local' field has the correct port.`
701
- );
702
- }
703
680
  let protocol;
704
681
  let host;
705
682
  let port;
706
- if (localPort) {
707
- port = localPort;
708
- } else if (typeof local === "number") {
683
+ if (typeof local === "number") {
709
684
  port = local;
710
685
  } else if (typeof local === "string") {
711
686
  if (/^\d+$/.test(local)) {
@@ -747,7 +722,6 @@ var Application = class {
747
722
  this.development = {
748
723
  local: new LocalHost({
749
724
  appName: name,
750
- localPort: app.development?.localPort,
751
725
  local: app.development?.local
752
726
  }),
753
727
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
@@ -755,7 +729,6 @@ var Application = class {
755
729
  if (app.development?.fallback) {
756
730
  this.fallback = new Host(app.development.fallback);
757
731
  }
758
- this.projectId = app.projectId;
759
732
  this.packageName = app.packageName;
760
733
  this.overrides = overrides?.environment ? {
761
734
  environment: new Host(overrides.environment)
@@ -819,11 +792,10 @@ var DEFAULT_LOCAL_PROXY_PORT = 3024;
819
792
  var MicrofrontendConfigIsomorphic = class {
820
793
  constructor({
821
794
  config,
822
- overrides,
823
- opts
795
+ overrides
824
796
  }) {
825
797
  this.childApplications = {};
826
- MicrofrontendConfigIsomorphic.validate(config, opts);
798
+ MicrofrontendConfigIsomorphic.validate(config);
827
799
  const disableOverrides = config.options?.disableOverrides ?? false;
828
800
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
829
801
  let defaultApplication;
@@ -858,14 +830,10 @@ var MicrofrontendConfigIsomorphic = class {
858
830
  overrides
859
831
  };
860
832
  }
861
- static validate(config, opts) {
862
- const skipValidation = opts?.skipValidation ?? [];
833
+ static validate(config) {
863
834
  const c = typeof config === "string" ? parse2(config) : config;
864
835
  validateConfigPaths(c.applications);
865
836
  validateConfigDefaultApplication(c.applications);
866
- if (!skipValidation.includes("deprecatedFields")) {
867
- validateDeprecatedFields(c);
868
- }
869
837
  return c;
870
838
  }
871
839
  static fromEnv({
@@ -1046,7 +1014,9 @@ var schema_default = {
1046
1014
  description: "Mapping of application names to the routes that they host. Only needs to be defined in the application that owns the primary microfrontend domain"
1047
1015
  }
1048
1016
  },
1049
- required: ["applications"],
1017
+ required: [
1018
+ "applications"
1019
+ ],
1050
1020
  additionalProperties: false
1051
1021
  },
1052
1022
  Options: {
@@ -1085,11 +1055,6 @@ var schema_default = {
1085
1055
  DefaultApplication: {
1086
1056
  type: "object",
1087
1057
  properties: {
1088
- projectId: {
1089
- type: "string",
1090
- description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1091
- deprecated: "Instead, the application id should match the Vercel project name. `packageName` can optionally\nbe set to the name of the package.json (if it is different from the project name)."
1092
- },
1093
1058
  packageName: {
1094
1059
  type: "string",
1095
1060
  description: "The name used to run the application, e.g. the `name` field in the `package.json`.\n\nThis is used by the local proxy to map the application config to the locally running app.\n\nThis is only necessary when the application name does not match the `name` used in `package.json`."
@@ -1099,21 +1064,21 @@ var schema_default = {
1099
1064
  description: "Development configuration for the default application."
1100
1065
  }
1101
1066
  },
1102
- required: ["development"],
1067
+ required: [
1068
+ "development"
1069
+ ],
1103
1070
  additionalProperties: false
1104
1071
  },
1105
1072
  DefaultDevelopment: {
1106
1073
  type: "object",
1107
1074
  properties: {
1108
1075
  local: {
1109
- type: ["number", "string"],
1076
+ type: [
1077
+ "number",
1078
+ "string"
1079
+ ],
1110
1080
  description: "A local port number or host string that this application runs on when it is running locally. If passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTP. If omitted, the port defaults to a unique, but stable (based on the application name) number.\n\nExamples of valid values:\n- 8080\n- my.localhost.me\n- my.localhost.me:8080\n- https://my.localhost.me\n- https://my.localhost.me:8080"
1111
1081
  },
1112
- localPort: {
1113
- type: "number",
1114
- description: "The local port number that this application runs on when it is running locally. Common values include `80` for HTTP and `443` for HTTPS. If omitted, the port defaults to a unique, but stable (based on the application name) number.",
1115
- deprecated: "Please set the port with the 'local' field instead."
1116
- },
1117
1082
  task: {
1118
1083
  type: "string",
1119
1084
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
@@ -1123,17 +1088,14 @@ var schema_default = {
1123
1088
  description: "Fallback for local development, could point to any environment. This is required for the default app. This value is used as the fallback for child apps as well if they do not have a fallback.\n\nIf passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTPS. If omitted, the port defaults to `80` for HTTP and `443` for HTTPS."
1124
1089
  }
1125
1090
  },
1126
- required: ["fallback"],
1091
+ required: [
1092
+ "fallback"
1093
+ ],
1127
1094
  additionalProperties: false
1128
1095
  },
1129
1096
  ChildApplication: {
1130
1097
  type: "object",
1131
1098
  properties: {
1132
- projectId: {
1133
- type: "string",
1134
- description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1135
- deprecated: "Instead, the application id should match the Vercel project name. `packageName` can optionally\nbe set to the name of the package.json (if it is different from the project name)."
1136
- },
1137
1099
  packageName: {
1138
1100
  type: "string",
1139
1101
  description: "The name used to run the application, e.g. the `name` field in the `package.json`.\n\nThis is used by the local proxy to map the application config to the locally running app.\n\nThis is only necessary when the application name does not match the `name` used in `package.json`."
@@ -1147,21 +1109,21 @@ var schema_default = {
1147
1109
  description: "Groups of path expressions that are routed to this application."
1148
1110
  }
1149
1111
  },
1150
- required: ["routing"],
1112
+ required: [
1113
+ "routing"
1114
+ ],
1151
1115
  additionalProperties: false
1152
1116
  },
1153
1117
  ChildDevelopment: {
1154
1118
  type: "object",
1155
1119
  properties: {
1156
1120
  local: {
1157
- type: ["number", "string"],
1121
+ type: [
1122
+ "number",
1123
+ "string"
1124
+ ],
1158
1125
  description: "A local port number or host string that this application runs on when it is running locally. If passing a string, include the protocol (optional), host (required) and port (optional). For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTP. If omitted, the port defaults to a unique, but stable (based on the application name) number.\n\nExamples of valid values:\n- 8080\n- my.localhost.me\n- my.localhost.me:8080\n- https://my.localhost.me\n- https://my.localhost.me:8080"
1159
1126
  },
1160
- localPort: {
1161
- type: "number",
1162
- description: "The local port number that this application runs on when it is running locally. Common values include `80` for HTTP and `443` for HTTPS. If omitted, the port defaults to a unique, but stable (based on the application name) number.",
1163
- deprecated: "Please set the port with the 'local' field instead."
1164
- },
1165
1127
  task: {
1166
1128
  type: "string",
1167
1129
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
@@ -1197,7 +1159,9 @@ var schema_default = {
1197
1159
  }
1198
1160
  }
1199
1161
  },
1200
- required: ["paths"],
1162
+ required: [
1163
+ "paths"
1164
+ ],
1201
1165
  additionalProperties: false
1202
1166
  }
1203
1167
  }