@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
@@ -159,17 +159,27 @@ function hasGitDirectory(dir) {
159
159
  function hasPnpmWorkspaces(dir) {
160
160
  return fs.existsSync(path.join(dir, "pnpm-workspace.yaml"));
161
161
  }
162
+ function hasPackageJson(dir) {
163
+ return fs.existsSync(path.join(dir, "package.json"));
164
+ }
162
165
  function findRepositoryRoot(startDir) {
163
166
  if (process.env.NX_WORKSPACE_ROOT) {
164
167
  return process.env.NX_WORKSPACE_ROOT;
165
168
  }
166
169
  let currentDir = startDir || process.cwd();
170
+ let lastPackageJsonDir = null;
167
171
  while (currentDir !== path.parse(currentDir).root) {
168
172
  if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
169
173
  return currentDir;
170
174
  }
175
+ if (hasPackageJson(currentDir)) {
176
+ lastPackageJsonDir = currentDir;
177
+ }
171
178
  currentDir = path.dirname(currentDir);
172
179
  }
180
+ if (lastPackageJsonDir) {
181
+ return lastPackageJsonDir;
182
+ }
173
183
  throw new Error(
174
184
  `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.`
175
185
  );
@@ -565,33 +575,6 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
565
575
  );
566
576
  }
567
577
  };
568
- var validateDeprecatedFields = (config) => {
569
- const errors = [];
570
- for (const [applicationId, application] of Object.entries(
571
- config.applications
572
- )) {
573
- if (application.development?.localPort) {
574
- errors.push(
575
- `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
576
- );
577
- }
578
- if (application.projectId) {
579
- errors.push(
580
- `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.`
581
- );
582
- }
583
- }
584
- if (errors.length) {
585
- throw new MicrofrontendError(
586
- `Microfrontends configuration file errors:
587
- - ${errors.join("\n- ")}`,
588
- {
589
- type: "config",
590
- subtype: "depcrecated_field"
591
- }
592
- );
593
- }
594
- };
595
578
 
596
579
  // src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
597
580
  var PREFIX = "vc-ap";
@@ -696,20 +679,12 @@ var Host = class {
696
679
  var LocalHost = class extends Host {
697
680
  constructor({
698
681
  appName,
699
- localPort,
700
682
  local
701
683
  }) {
702
- if (localPort && local) {
703
- throw new Error(
704
- `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.`
705
- );
706
- }
707
684
  let protocol;
708
685
  let host;
709
686
  let port;
710
- if (localPort) {
711
- port = localPort;
712
- } else if (typeof local === "number") {
687
+ if (typeof local === "number") {
713
688
  port = local;
714
689
  } else if (typeof local === "string") {
715
690
  if (/^\d+$/.test(local)) {
@@ -751,7 +726,6 @@ var Application = class {
751
726
  this.development = {
752
727
  local: new LocalHost({
753
728
  appName: name,
754
- localPort: app.development?.localPort,
755
729
  local: app.development?.local
756
730
  }),
757
731
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
@@ -759,7 +733,6 @@ var Application = class {
759
733
  if (app.development?.fallback) {
760
734
  this.fallback = new Host(app.development.fallback);
761
735
  }
762
- this.projectId = app.projectId;
763
736
  this.packageName = app.packageName;
764
737
  this.overrides = overrides?.environment ? {
765
738
  environment: new Host(overrides.environment)
@@ -823,11 +796,10 @@ var DEFAULT_LOCAL_PROXY_PORT = 3024;
823
796
  var MicrofrontendConfigIsomorphic = class {
824
797
  constructor({
825
798
  config,
826
- overrides,
827
- opts
799
+ overrides
828
800
  }) {
829
801
  this.childApplications = {};
830
- MicrofrontendConfigIsomorphic.validate(config, opts);
802
+ MicrofrontendConfigIsomorphic.validate(config);
831
803
  const disableOverrides = config.options?.disableOverrides ?? false;
832
804
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
833
805
  let defaultApplication;
@@ -862,14 +834,10 @@ var MicrofrontendConfigIsomorphic = class {
862
834
  overrides
863
835
  };
864
836
  }
865
- static validate(config, opts) {
866
- const skipValidation = opts?.skipValidation ?? [];
837
+ static validate(config) {
867
838
  const c = typeof config === "string" ? parse2(config) : config;
868
839
  validateConfigPaths(c.applications);
869
840
  validateConfigDefaultApplication(c.applications);
870
- if (!skipValidation.includes("deprecatedFields")) {
871
- validateDeprecatedFields(c);
872
- }
873
841
  return c;
874
842
  }
875
843
  static fromEnv({
@@ -1050,7 +1018,9 @@ var schema_default = {
1050
1018
  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"
1051
1019
  }
1052
1020
  },
1053
- required: ["applications"],
1021
+ required: [
1022
+ "applications"
1023
+ ],
1054
1024
  additionalProperties: false
1055
1025
  },
1056
1026
  Options: {
@@ -1089,11 +1059,6 @@ var schema_default = {
1089
1059
  DefaultApplication: {
1090
1060
  type: "object",
1091
1061
  properties: {
1092
- projectId: {
1093
- type: "string",
1094
- description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1095
- 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)."
1096
- },
1097
1062
  packageName: {
1098
1063
  type: "string",
1099
1064
  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`."
@@ -1103,21 +1068,21 @@ var schema_default = {
1103
1068
  description: "Development configuration for the default application."
1104
1069
  }
1105
1070
  },
1106
- required: ["development"],
1071
+ required: [
1072
+ "development"
1073
+ ],
1107
1074
  additionalProperties: false
1108
1075
  },
1109
1076
  DefaultDevelopment: {
1110
1077
  type: "object",
1111
1078
  properties: {
1112
1079
  local: {
1113
- type: ["number", "string"],
1080
+ type: [
1081
+ "number",
1082
+ "string"
1083
+ ],
1114
1084
  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"
1115
1085
  },
1116
- localPort: {
1117
- type: "number",
1118
- 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.",
1119
- deprecated: "Please set the port with the 'local' field instead."
1120
- },
1121
1086
  task: {
1122
1087
  type: "string",
1123
1088
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
@@ -1127,17 +1092,14 @@ var schema_default = {
1127
1092
  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."
1128
1093
  }
1129
1094
  },
1130
- required: ["fallback"],
1095
+ required: [
1096
+ "fallback"
1097
+ ],
1131
1098
  additionalProperties: false
1132
1099
  },
1133
1100
  ChildApplication: {
1134
1101
  type: "object",
1135
1102
  properties: {
1136
- projectId: {
1137
- type: "string",
1138
- description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1139
- 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)."
1140
- },
1141
1103
  packageName: {
1142
1104
  type: "string",
1143
1105
  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`."
@@ -1151,21 +1113,21 @@ var schema_default = {
1151
1113
  description: "Groups of path expressions that are routed to this application."
1152
1114
  }
1153
1115
  },
1154
- required: ["routing"],
1116
+ required: [
1117
+ "routing"
1118
+ ],
1155
1119
  additionalProperties: false
1156
1120
  },
1157
1121
  ChildDevelopment: {
1158
1122
  type: "object",
1159
1123
  properties: {
1160
1124
  local: {
1161
- type: ["number", "string"],
1125
+ type: [
1126
+ "number",
1127
+ "string"
1128
+ ],
1162
1129
  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"
1163
1130
  },
1164
- localPort: {
1165
- type: "number",
1166
- 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.",
1167
- deprecated: "Please set the port with the 'local' field instead."
1168
- },
1169
1131
  task: {
1170
1132
  type: "string",
1171
1133
  description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
@@ -1201,7 +1163,9 @@ var schema_default = {
1201
1163
  }
1202
1164
  }
1203
1165
  },
1204
- required: ["paths"],
1166
+ required: [
1167
+ "paths"
1168
+ ],
1205
1169
  additionalProperties: false
1206
1170
  }
1207
1171
  }