@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
@@ -190,17 +190,27 @@ function hasGitDirectory(dir) {
190
190
  function hasPnpmWorkspaces(dir) {
191
191
  return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
192
192
  }
193
+ function hasPackageJson(dir) {
194
+ return import_node_fs.default.existsSync(import_node_path.default.join(dir, "package.json"));
195
+ }
193
196
  function findRepositoryRoot(startDir) {
194
197
  if (process.env.NX_WORKSPACE_ROOT) {
195
198
  return process.env.NX_WORKSPACE_ROOT;
196
199
  }
197
200
  let currentDir = startDir || process.cwd();
201
+ let lastPackageJsonDir = null;
198
202
  while (currentDir !== import_node_path.default.parse(currentDir).root) {
199
203
  if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
200
204
  return currentDir;
201
205
  }
206
+ if (hasPackageJson(currentDir)) {
207
+ lastPackageJsonDir = currentDir;
208
+ }
202
209
  currentDir = import_node_path.default.dirname(currentDir);
203
210
  }
211
+ if (lastPackageJsonDir) {
212
+ return lastPackageJsonDir;
213
+ }
204
214
  throw new Error(
205
215
  `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.`
206
216
  );
@@ -596,33 +606,6 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
596
606
  );
597
607
  }
598
608
  };
599
- var validateDeprecatedFields = (config) => {
600
- const errors = [];
601
- for (const [applicationId, application] of Object.entries(
602
- config.applications
603
- )) {
604
- if (application.development?.localPort) {
605
- errors.push(
606
- `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
607
- );
608
- }
609
- if (application.projectId) {
610
- errors.push(
611
- `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.`
612
- );
613
- }
614
- }
615
- if (errors.length) {
616
- throw new MicrofrontendError(
617
- `Microfrontends configuration file errors:
618
- - ${errors.join("\n- ")}`,
619
- {
620
- type: "config",
621
- subtype: "depcrecated_field"
622
- }
623
- );
624
- }
625
- };
626
609
 
627
610
  // src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
628
611
  var PREFIX = "vc-ap";
@@ -727,20 +710,12 @@ var Host = class {
727
710
  var LocalHost = class extends Host {
728
711
  constructor({
729
712
  appName,
730
- localPort,
731
713
  local
732
714
  }) {
733
- if (localPort && local) {
734
- throw new Error(
735
- `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.`
736
- );
737
- }
738
715
  let protocol;
739
716
  let host;
740
717
  let port;
741
- if (localPort) {
742
- port = localPort;
743
- } else if (typeof local === "number") {
718
+ if (typeof local === "number") {
744
719
  port = local;
745
720
  } else if (typeof local === "string") {
746
721
  if (/^\d+$/.test(local)) {
@@ -782,7 +757,6 @@ var Application = class {
782
757
  this.development = {
783
758
  local: new LocalHost({
784
759
  appName: name,
785
- localPort: app.development?.localPort,
786
760
  local: app.development?.local
787
761
  }),
788
762
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
@@ -790,7 +764,6 @@ var Application = class {
790
764
  if (app.development?.fallback) {
791
765
  this.fallback = new Host(app.development.fallback);
792
766
  }
793
- this.projectId = app.projectId;
794
767
  this.packageName = app.packageName;
795
768
  this.overrides = overrides?.environment ? {
796
769
  environment: new Host(overrides.environment)
@@ -854,11 +827,10 @@ var DEFAULT_LOCAL_PROXY_PORT = 3024;
854
827
  var MicrofrontendConfigIsomorphic = class {
855
828
  constructor({
856
829
  config,
857
- overrides,
858
- opts
830
+ overrides
859
831
  }) {
860
832
  this.childApplications = {};
861
- MicrofrontendConfigIsomorphic.validate(config, opts);
833
+ MicrofrontendConfigIsomorphic.validate(config);
862
834
  const disableOverrides = config.options?.disableOverrides ?? false;
863
835
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
864
836
  let defaultApplication;
@@ -893,14 +865,10 @@ var MicrofrontendConfigIsomorphic = class {
893
865
  overrides
894
866
  };
895
867
  }
896
- static validate(config, opts) {
897
- const skipValidation = opts?.skipValidation ?? [];
868
+ static validate(config) {
898
869
  const c = typeof config === "string" ? (0, import_jsonc_parser2.parse)(config) : config;
899
870
  validateConfigPaths(c.applications);
900
871
  validateConfigDefaultApplication(c.applications);
901
- if (!skipValidation.includes("deprecatedFields")) {
902
- validateDeprecatedFields(c);
903
- }
904
872
  return c;
905
873
  }
906
874
  static fromEnv({
@@ -1081,7 +1049,9 @@ var schema_default = {
1081
1049
  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"
1082
1050
  }
1083
1051
  },
1084
- required: ["applications"],
1052
+ required: [
1053
+ "applications"
1054
+ ],
1085
1055
  additionalProperties: false
1086
1056
  },
1087
1057
  Options: {
@@ -1120,11 +1090,6 @@ var schema_default = {
1120
1090
  DefaultApplication: {
1121
1091
  type: "object",
1122
1092
  properties: {
1123
- projectId: {
1124
- type: "string",
1125
- description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1126
- 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)."
1127
- },
1128
1093
  packageName: {
1129
1094
  type: "string",
1130
1095
  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`."
@@ -1134,21 +1099,21 @@ var schema_default = {
1134
1099
  description: "Development configuration for the default application."
1135
1100
  }
1136
1101
  },
1137
- required: ["development"],
1102
+ required: [
1103
+ "development"
1104
+ ],
1138
1105
  additionalProperties: false
1139
1106
  },
1140
1107
  DefaultDevelopment: {
1141
1108
  type: "object",
1142
1109
  properties: {
1143
1110
  local: {
1144
- type: ["number", "string"],
1111
+ type: [
1112
+ "number",
1113
+ "string"
1114
+ ],
1145
1115
  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"
1146
1116
  },
1147
- localPort: {
1148
- type: "number",
1149
- 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.",
1150
- deprecated: "Please set the port with the 'local' field instead."
1151
- },
1152
1117
  task: {
1153
1118
  type: "string",
1154
1119
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
@@ -1158,17 +1123,14 @@ var schema_default = {
1158
1123
  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."
1159
1124
  }
1160
1125
  },
1161
- required: ["fallback"],
1126
+ required: [
1127
+ "fallback"
1128
+ ],
1162
1129
  additionalProperties: false
1163
1130
  },
1164
1131
  ChildApplication: {
1165
1132
  type: "object",
1166
1133
  properties: {
1167
- projectId: {
1168
- type: "string",
1169
- description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1170
- 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)."
1171
- },
1172
1134
  packageName: {
1173
1135
  type: "string",
1174
1136
  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`."
@@ -1182,21 +1144,21 @@ var schema_default = {
1182
1144
  description: "Groups of path expressions that are routed to this application."
1183
1145
  }
1184
1146
  },
1185
- required: ["routing"],
1147
+ required: [
1148
+ "routing"
1149
+ ],
1186
1150
  additionalProperties: false
1187
1151
  },
1188
1152
  ChildDevelopment: {
1189
1153
  type: "object",
1190
1154
  properties: {
1191
1155
  local: {
1192
- type: ["number", "string"],
1156
+ type: [
1157
+ "number",
1158
+ "string"
1159
+ ],
1193
1160
  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"
1194
1161
  },
1195
- localPort: {
1196
- type: "number",
1197
- 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.",
1198
- deprecated: "Please set the port with the 'local' field instead."
1199
- },
1200
1162
  task: {
1201
1163
  type: "string",
1202
1164
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
@@ -1232,7 +1194,9 @@ var schema_default = {
1232
1194
  }
1233
1195
  }
1234
1196
  },
1235
- required: ["paths"],
1197
+ required: [
1198
+ "paths"
1199
+ ],
1236
1200
  additionalProperties: false
1237
1201
  }
1238
1202
  }