@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
@@ -164,17 +164,27 @@ function hasGitDirectory(dir) {
164
164
  function hasPnpmWorkspaces(dir) {
165
165
  return fs.existsSync(path.join(dir, "pnpm-workspace.yaml"));
166
166
  }
167
+ function hasPackageJson(dir) {
168
+ return fs.existsSync(path.join(dir, "package.json"));
169
+ }
167
170
  function findRepositoryRoot(startDir) {
168
171
  if (process.env.NX_WORKSPACE_ROOT) {
169
172
  return process.env.NX_WORKSPACE_ROOT;
170
173
  }
171
174
  let currentDir = startDir || process.cwd();
175
+ let lastPackageJsonDir = null;
172
176
  while (currentDir !== path.parse(currentDir).root) {
173
177
  if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
174
178
  return currentDir;
175
179
  }
180
+ if (hasPackageJson(currentDir)) {
181
+ lastPackageJsonDir = currentDir;
182
+ }
176
183
  currentDir = path.dirname(currentDir);
177
184
  }
185
+ if (lastPackageJsonDir) {
186
+ return lastPackageJsonDir;
187
+ }
178
188
  throw new Error(
179
189
  `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.`
180
190
  );
@@ -570,33 +580,6 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
570
580
  );
571
581
  }
572
582
  };
573
- var validateDeprecatedFields = (config) => {
574
- const errors = [];
575
- for (const [applicationId, application] of Object.entries(
576
- config.applications
577
- )) {
578
- if (application.development?.localPort) {
579
- errors.push(
580
- `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
581
- );
582
- }
583
- if (application.projectId) {
584
- errors.push(
585
- `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.`
586
- );
587
- }
588
- }
589
- if (errors.length) {
590
- throw new MicrofrontendError(
591
- `Microfrontends configuration file errors:
592
- - ${errors.join("\n- ")}`,
593
- {
594
- type: "config",
595
- subtype: "depcrecated_field"
596
- }
597
- );
598
- }
599
- };
600
583
 
601
584
  // src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
602
585
  var PREFIX = "vc-ap";
@@ -701,20 +684,12 @@ var Host = class {
701
684
  var LocalHost = class extends Host {
702
685
  constructor({
703
686
  appName,
704
- localPort,
705
687
  local
706
688
  }) {
707
- if (localPort && local) {
708
- throw new Error(
709
- `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.`
710
- );
711
- }
712
689
  let protocol;
713
690
  let host;
714
691
  let port;
715
- if (localPort) {
716
- port = localPort;
717
- } else if (typeof local === "number") {
692
+ if (typeof local === "number") {
718
693
  port = local;
719
694
  } else if (typeof local === "string") {
720
695
  if (/^\d+$/.test(local)) {
@@ -756,7 +731,6 @@ var Application = class {
756
731
  this.development = {
757
732
  local: new LocalHost({
758
733
  appName: name,
759
- localPort: app.development?.localPort,
760
734
  local: app.development?.local
761
735
  }),
762
736
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
@@ -764,7 +738,6 @@ var Application = class {
764
738
  if (app.development?.fallback) {
765
739
  this.fallback = new Host(app.development.fallback);
766
740
  }
767
- this.projectId = app.projectId;
768
741
  this.packageName = app.packageName;
769
742
  this.overrides = overrides?.environment ? {
770
743
  environment: new Host(overrides.environment)
@@ -828,11 +801,10 @@ var DEFAULT_LOCAL_PROXY_PORT = 3024;
828
801
  var MicrofrontendConfigIsomorphic = class {
829
802
  constructor({
830
803
  config,
831
- overrides,
832
- opts
804
+ overrides
833
805
  }) {
834
806
  this.childApplications = {};
835
- MicrofrontendConfigIsomorphic.validate(config, opts);
807
+ MicrofrontendConfigIsomorphic.validate(config);
836
808
  const disableOverrides = config.options?.disableOverrides ?? false;
837
809
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
838
810
  let defaultApplication;
@@ -867,14 +839,10 @@ var MicrofrontendConfigIsomorphic = class {
867
839
  overrides
868
840
  };
869
841
  }
870
- static validate(config, opts) {
871
- const skipValidation = opts?.skipValidation ?? [];
842
+ static validate(config) {
872
843
  const c = typeof config === "string" ? parse2(config) : config;
873
844
  validateConfigPaths(c.applications);
874
845
  validateConfigDefaultApplication(c.applications);
875
- if (!skipValidation.includes("deprecatedFields")) {
876
- validateDeprecatedFields(c);
877
- }
878
846
  return c;
879
847
  }
880
848
  static fromEnv({
@@ -1055,7 +1023,9 @@ var schema_default = {
1055
1023
  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"
1056
1024
  }
1057
1025
  },
1058
- required: ["applications"],
1026
+ required: [
1027
+ "applications"
1028
+ ],
1059
1029
  additionalProperties: false
1060
1030
  },
1061
1031
  Options: {
@@ -1094,11 +1064,6 @@ var schema_default = {
1094
1064
  DefaultApplication: {
1095
1065
  type: "object",
1096
1066
  properties: {
1097
- projectId: {
1098
- type: "string",
1099
- description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1100
- 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)."
1101
- },
1102
1067
  packageName: {
1103
1068
  type: "string",
1104
1069
  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`."
@@ -1108,21 +1073,21 @@ var schema_default = {
1108
1073
  description: "Development configuration for the default application."
1109
1074
  }
1110
1075
  },
1111
- required: ["development"],
1076
+ required: [
1077
+ "development"
1078
+ ],
1112
1079
  additionalProperties: false
1113
1080
  },
1114
1081
  DefaultDevelopment: {
1115
1082
  type: "object",
1116
1083
  properties: {
1117
1084
  local: {
1118
- type: ["number", "string"],
1085
+ type: [
1086
+ "number",
1087
+ "string"
1088
+ ],
1119
1089
  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"
1120
1090
  },
1121
- localPort: {
1122
- type: "number",
1123
- 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.",
1124
- deprecated: "Please set the port with the 'local' field instead."
1125
- },
1126
1091
  task: {
1127
1092
  type: "string",
1128
1093
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
@@ -1132,17 +1097,14 @@ var schema_default = {
1132
1097
  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."
1133
1098
  }
1134
1099
  },
1135
- required: ["fallback"],
1100
+ required: [
1101
+ "fallback"
1102
+ ],
1136
1103
  additionalProperties: false
1137
1104
  },
1138
1105
  ChildApplication: {
1139
1106
  type: "object",
1140
1107
  properties: {
1141
- projectId: {
1142
- type: "string",
1143
- description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1144
- 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)."
1145
- },
1146
1108
  packageName: {
1147
1109
  type: "string",
1148
1110
  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`."
@@ -1156,21 +1118,21 @@ var schema_default = {
1156
1118
  description: "Groups of path expressions that are routed to this application."
1157
1119
  }
1158
1120
  },
1159
- required: ["routing"],
1121
+ required: [
1122
+ "routing"
1123
+ ],
1160
1124
  additionalProperties: false
1161
1125
  },
1162
1126
  ChildDevelopment: {
1163
1127
  type: "object",
1164
1128
  properties: {
1165
1129
  local: {
1166
- type: ["number", "string"],
1130
+ type: [
1131
+ "number",
1132
+ "string"
1133
+ ],
1167
1134
  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"
1168
1135
  },
1169
- localPort: {
1170
- type: "number",
1171
- 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.",
1172
- deprecated: "Please set the port with the 'local' field instead."
1173
- },
1174
1136
  task: {
1175
1137
  type: "string",
1176
1138
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
@@ -1206,7 +1168,9 @@ var schema_default = {
1206
1168
  }
1207
1169
  }
1208
1170
  },
1209
- required: ["paths"],
1171
+ required: [
1172
+ "paths"
1173
+ ],
1210
1174
  additionalProperties: false
1211
1175
  }
1212
1176
  }