@vercel/microfrontends 0.9.0 → 0.10.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 (78) hide show
  1. package/README.md +2 -2
  2. package/dist/bin/cli.cjs +1483 -186
  3. package/dist/config/edge.cjs +47 -47
  4. package/dist/config/edge.cjs.map +1 -1
  5. package/dist/config/edge.d.ts +6 -6
  6. package/dist/config/edge.js +46 -46
  7. package/dist/config/edge.js.map +1 -1
  8. package/dist/config.cjs +66 -60
  9. package/dist/config.cjs.map +1 -1
  10. package/dist/config.d.ts +3 -3
  11. package/dist/config.js +65 -59
  12. package/dist/config.js.map +1 -1
  13. package/dist/{index-eff254d8.d.ts → index-05742bef.d.ts} +11 -22
  14. package/dist/{micro-frontend-config-42886104.d.ts → microfrontend-config-2425db74.d.ts} +12 -12
  15. package/dist/next/config.cjs +83 -77
  16. package/dist/next/config.cjs.map +1 -1
  17. package/dist/next/config.d.ts +3 -3
  18. package/dist/next/config.js +82 -76
  19. package/dist/next/config.js.map +1 -1
  20. package/dist/next/middleware.cjs +55 -55
  21. package/dist/next/middleware.cjs.map +1 -1
  22. package/dist/next/middleware.d.ts +11 -11
  23. package/dist/next/middleware.js +53 -53
  24. package/dist/next/middleware.js.map +1 -1
  25. package/dist/next/testing.cjs +79 -73
  26. package/dist/next/testing.cjs.map +1 -1
  27. package/dist/next/testing.d.ts +9 -9
  28. package/dist/next/testing.js +79 -73
  29. package/dist/next/testing.js.map +1 -1
  30. package/dist/overrides.cjs +9 -9
  31. package/dist/overrides.cjs.map +1 -1
  32. package/dist/overrides.d.ts +1 -1
  33. package/dist/overrides.js +9 -9
  34. package/dist/overrides.js.map +1 -1
  35. package/dist/types-13f3e535.d.ts +15 -0
  36. package/dist/v2/config.cjs +39 -39
  37. package/dist/v2/config.cjs.map +1 -1
  38. package/dist/v2/config.d.ts +2 -1
  39. package/dist/v2/config.js +38 -38
  40. package/dist/v2/config.js.map +1 -1
  41. package/dist/v2/microfrontends/server.cjs +102 -65
  42. package/dist/v2/microfrontends/server.cjs.map +1 -1
  43. package/dist/v2/microfrontends/server.d.ts +6 -1
  44. package/dist/v2/microfrontends/server.js +102 -65
  45. package/dist/v2/microfrontends/server.js.map +1 -1
  46. package/dist/v2/microfrontends.cjs +44 -44
  47. package/dist/v2/microfrontends.cjs.map +1 -1
  48. package/dist/v2/microfrontends.d.ts +5 -4
  49. package/dist/v2/microfrontends.js +44 -44
  50. package/dist/v2/microfrontends.js.map +1 -1
  51. package/dist/v2/next/client.cjs +1 -1
  52. package/dist/v2/next/client.cjs.map +1 -1
  53. package/dist/v2/next/client.js +1 -1
  54. package/dist/v2/next/client.js.map +1 -1
  55. package/dist/v2/next/config.cjs +120 -83
  56. package/dist/v2/next/config.cjs.map +1 -1
  57. package/dist/v2/next/config.d.ts +4 -4
  58. package/dist/v2/next/config.js +119 -82
  59. package/dist/v2/next/config.js.map +1 -1
  60. package/dist/v2/next/endpoints.cjs +5 -5
  61. package/dist/v2/next/endpoints.cjs.map +1 -1
  62. package/dist/v2/next/endpoints.js +5 -5
  63. package/dist/v2/next/endpoints.js.map +1 -1
  64. package/dist/v2/next/middleware.cjs +54 -54
  65. package/dist/v2/next/middleware.cjs.map +1 -1
  66. package/dist/v2/next/middleware.d.ts +8 -8
  67. package/dist/v2/next/middleware.js +52 -52
  68. package/dist/v2/next/middleware.js.map +1 -1
  69. package/dist/v2/overrides.cjs +75 -0
  70. package/dist/v2/overrides.cjs.map +1 -0
  71. package/dist/v2/overrides.d.ts +24 -0
  72. package/dist/v2/overrides.js +45 -0
  73. package/dist/v2/overrides.js.map +1 -0
  74. package/dist/validation.cjs +20 -20
  75. package/dist/validation.cjs.map +1 -1
  76. package/dist/validation.js +20 -20
  77. package/dist/validation.js.map +1 -1
  78. package/package.json +10 -3
package/dist/config.js CHANGED
@@ -61,7 +61,7 @@ async function getWellKnownClientData(flagValues = {}) {
61
61
  var isCommonApplicationConfig = (app) => !app.default && typeof app.routing === "object";
62
62
  var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
63
63
 
64
- // src/config/micro-frontend-config.ts
64
+ // src/config/microfrontend-config.ts
65
65
  import fs2 from "node:fs";
66
66
 
67
67
  // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
@@ -89,14 +89,14 @@ function getOutputFilePath() {
89
89
  }
90
90
 
91
91
  // src/config/errors.ts
92
- var MicroFrontendError = class extends Error {
92
+ var MicrofrontendError = class extends Error {
93
93
  constructor(message, opts) {
94
94
  super(message);
95
- this.name = "MicroFrontendsError";
96
- this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
95
+ this.name = "MicrofrontendsError";
96
+ this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
97
97
  this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
98
98
  this.subtype = opts == null ? void 0 : opts.subtype;
99
- Error.captureStackTrace(this, MicroFrontendError);
99
+ Error.captureStackTrace(this, MicrofrontendError);
100
100
  }
101
101
  isKnown() {
102
102
  return this.type !== "unknown";
@@ -105,13 +105,13 @@ var MicroFrontendError = class extends Error {
105
105
  return !this.isKnown();
106
106
  }
107
107
  /**
108
- * Converts an error to a MicroFrontendsError.
108
+ * Converts an error to a MicrofrontendsError.
109
109
  * @param original - The original error to convert.
110
- * @returns The converted MicroFrontendsError.
110
+ * @returns The converted MicrofrontendsError.
111
111
  */
112
112
  static convert(original, opts) {
113
113
  if (opts == null ? void 0 : opts.fileName) {
114
- const err = MicroFrontendError.convertFSError(original, opts.fileName);
114
+ const err = MicrofrontendError.convertFSError(original, opts.fileName);
115
115
  if (err) {
116
116
  return err;
117
117
  }
@@ -119,25 +119,25 @@ var MicroFrontendError = class extends Error {
119
119
  if (original.message.includes(
120
120
  "Code generation from strings disallowed for this context"
121
121
  )) {
122
- return new MicroFrontendError(original.message, {
122
+ return new MicrofrontendError(original.message, {
123
123
  type: "config",
124
124
  subtype: "unsupported_validation_env",
125
125
  source: "ajv"
126
126
  });
127
127
  }
128
- return new MicroFrontendError(original.message);
128
+ return new MicrofrontendError(original.message);
129
129
  }
130
130
  static convertFSError(original, fileName) {
131
131
  if (original instanceof Error && "code" in original) {
132
132
  if (original.code === "ENOENT") {
133
- return new MicroFrontendError(`Could not find "${fileName}"`, {
133
+ return new MicrofrontendError(`Could not find "${fileName}"`, {
134
134
  type: "config",
135
135
  subtype: "unable_to_read_file",
136
136
  source: "fs"
137
137
  });
138
138
  }
139
139
  if (original.code === "EACCES") {
140
- return new MicroFrontendError(
140
+ return new MicrofrontendError(
141
141
  `Permission denied while accessing "${fileName}"`,
142
142
  {
143
143
  type: "config",
@@ -148,7 +148,7 @@ var MicroFrontendError = class extends Error {
148
148
  }
149
149
  }
150
150
  if (original instanceof SyntaxError) {
151
- return new MicroFrontendError(
151
+ return new MicrofrontendError(
152
152
  `Failed to parse "${fileName}": Invalid JSON format.`,
153
153
  {
154
154
  type: "config",
@@ -160,23 +160,23 @@ var MicroFrontendError = class extends Error {
160
160
  return null;
161
161
  }
162
162
  /**
163
- * Handles an unknown error and returns a MicroFrontendsError instance.
163
+ * Handles an unknown error and returns a MicrofrontendsError instance.
164
164
  * @param err - The error to handle.
165
- * @returns A MicroFrontendsError instance.
165
+ * @returns A MicrofrontendsError instance.
166
166
  */
167
167
  static handle(err, opts) {
168
- if (err instanceof MicroFrontendError) {
168
+ if (err instanceof MicrofrontendError) {
169
169
  return err;
170
170
  }
171
171
  if (err instanceof Error) {
172
- return MicroFrontendError.convert(err, opts);
172
+ return MicrofrontendError.convert(err, opts);
173
173
  }
174
174
  if (typeof err === "object" && err !== null) {
175
175
  if ("message" in err && typeof err.message === "string") {
176
- return MicroFrontendError.convert(new Error(err.message), opts);
176
+ return MicrofrontendError.convert(new Error(err.message), opts);
177
177
  }
178
178
  }
179
- return new MicroFrontendError("An unknown error occurred");
179
+ return new MicrofrontendError("An unknown error occurred");
180
180
  }
181
181
  };
182
182
 
@@ -259,27 +259,27 @@ var _Overrides = class {
259
259
  });
260
260
  return overridesConfig;
261
261
  }
262
- static validOverrideDomainsForZone(microFrontendConfig, zone) {
262
+ static validOverrideDomainsForZone(microfrontendConfig, zone) {
263
263
  var _a, _b, _c, _d, _e;
264
- const projectName = (_a = microFrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
264
+ const projectName = (_a = microfrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
265
265
  if (!projectName) {
266
- return [microFrontendConfig.getZone(zone).production.host];
266
+ return [microfrontendConfig.getZone(zone).production.host];
267
267
  }
268
268
  const parsedProjectName = makeUrlSafe(projectName);
269
- const previewDeploymentSuffix = (_c = (_b = microFrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
270
- const teamSlug = (_e = (_d = microFrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
269
+ const previewDeploymentSuffix = (_c = (_b = microfrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
270
+ const teamSlug = (_e = (_d = microfrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
271
271
  if (!teamSlug && !previewDeploymentSuffix) {
272
- return [microFrontendConfig.getZone(zone).production.host];
272
+ return [microfrontendConfig.getZone(zone).production.host];
273
273
  }
274
274
  const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
275
275
  return [
276
276
  `${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
277
- microFrontendConfig.getZone(zone).production.host
277
+ microfrontendConfig.getZone(zone).production.host
278
278
  ];
279
279
  }
280
- static validateOverrideDomain(microFrontendConfig, zone, domain) {
280
+ static validateOverrideDomain(microfrontendConfig, zone, domain) {
281
281
  return new RegExp(
282
- `^${_Overrides.validOverrideDomainsForZone(microFrontendConfig, zone).join(
282
+ `^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
283
283
  "|"
284
284
  )}$`
285
285
  ).test(domain);
@@ -361,7 +361,7 @@ var Application = class {
361
361
  static validate(name, app) {
362
362
  var _a, _b, _c, _d, _e;
363
363
  if (((_b = (_a = app.routing) == null ? void 0 : _a.assetPrefix) == null ? void 0 : _b.startsWith("/")) || ((_d = (_c = app.routing) == null ? void 0 : _c.assetPrefix) == null ? void 0 : _d.endsWith("/"))) {
364
- throw new MicroFrontendError(
364
+ throw new MicrofrontendError(
365
365
  `Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
366
366
  { type: "zone", subtype: "invalid_asset_prefix" }
367
367
  );
@@ -372,13 +372,13 @@ var Application = class {
372
372
  continue;
373
373
  }
374
374
  if (p.endsWith("/")) {
375
- throw new MicroFrontendError(
375
+ throw new MicrofrontendError(
376
376
  `Invalid path for application "${name}". ${p} must not end with a slash.`,
377
377
  { type: "zone", subtype: "invalid_path" }
378
378
  );
379
379
  }
380
380
  if (!p.startsWith("/")) {
381
- throw new MicroFrontendError(
381
+ throw new MicrofrontendError(
382
382
  `Invalid path for application "${name}". ${p} must start with a slash.`,
383
383
  { type: "zone", subtype: "invalid_path" }
384
384
  );
@@ -412,10 +412,10 @@ var Application = class {
412
412
  }
413
413
  };
414
414
 
415
- // src/config/common/micro-frontend-config.ts
415
+ // src/config/common/microfrontend-config.ts
416
416
  var SUPPORTED_VERSIONS = ["1"];
417
417
  var DEFAULT_LOCAL_PROXY_PORT = 3024;
418
- var MicroFrontendConfigCommon = class {
418
+ var MicrofrontendConfigCommon = class {
419
419
  constructor({
420
420
  config,
421
421
  overrides
@@ -423,7 +423,7 @@ var MicroFrontendConfigCommon = class {
423
423
  this.zones = {};
424
424
  var _a, _b, _c;
425
425
  if (!SUPPORTED_VERSIONS.includes(config.version)) {
426
- throw new MicroFrontendError(
426
+ throw new MicrofrontendError(
427
427
  `Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
428
428
  ", "
429
429
  )}`,
@@ -451,7 +451,7 @@ var MicroFrontendConfigCommon = class {
451
451
  static getConfigFromEnv() {
452
452
  const config = process.env.MFE_CONFIG;
453
453
  if (!config) {
454
- throw new MicroFrontendError(`Missing "MFE_CONFIG" in environment.`, {
454
+ throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
455
455
  type: "config",
456
456
  subtype: "not_found_in_env"
457
457
  });
@@ -470,8 +470,8 @@ var MicroFrontendConfigCommon = class {
470
470
  getZone(name) {
471
471
  const zone = this.zones[name];
472
472
  if (!zone) {
473
- throw new MicroFrontendError(
474
- `Could not find micro-frontends configuration for application "${name}"`,
473
+ throw new MicrofrontendError(
474
+ `Could not find microfrontends configuration for application "${name}"`,
475
475
  {
476
476
  type: "zone",
477
477
  subtype: "not_found"
@@ -491,8 +491,8 @@ var MicroFrontendConfigCommon = class {
491
491
  getDefaultZone() {
492
492
  const zone = Object.values(this.zones).find((z) => z.default);
493
493
  if (!zone) {
494
- throw new MicroFrontendError(
495
- `Could not find default zone in micro-frontends configuration`,
494
+ throw new MicrofrontendError(
495
+ `Could not find default zone in microfrontends configuration`,
496
496
  {
497
497
  type: "zone",
498
498
  subtype: "not_found"
@@ -544,8 +544,8 @@ var MicroFrontendConfigCommon = class {
544
544
  };
545
545
  }
546
546
  write(_) {
547
- throw new MicroFrontendError(
548
- `Writing to file to disk requires using an instance of "MicroFrontendConfig".`,
547
+ throw new MicrofrontendError(
548
+ `Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
549
549
  { type: "config", subtype: "unsupported_operation" }
550
550
  );
551
551
  }
@@ -906,7 +906,7 @@ var validateSchema = (configString) => {
906
906
  const validate = ajv.compile(SCHEMA);
907
907
  const isValid = validate(parsedConfig);
908
908
  if (!isValid) {
909
- throw new MicroFrontendError(
909
+ throw new MicrofrontendError(
910
910
  `Invalid config: ${ajv.errorsText(validate.errors)}`,
911
911
  { type: "config", subtype: "does_not_match_schema" }
912
912
  );
@@ -916,7 +916,7 @@ var validateSchema = (configString) => {
916
916
  var SUPPORTED_VERSIONS2 = ["1"];
917
917
  var validateVersion = (version) => {
918
918
  if (!SUPPORTED_VERSIONS2.includes(version)) {
919
- throw new MicroFrontendError(
919
+ throw new MicrofrontendError(
920
920
  `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
921
921
  ", "
922
922
  )}`,
@@ -949,7 +949,7 @@ function validateMainPath(applicationConfigsById) {
949
949
  return !matcher.test(defaultRoute);
950
950
  });
951
951
  if (!isValid) {
952
- throw new MicroFrontendError(
952
+ throw new MicrofrontendError(
953
953
  `default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
954
954
  { type: "config", subtype: "invalid_main_path" }
955
955
  );
@@ -962,7 +962,7 @@ function validateMainPath(applicationConfigsById) {
962
962
  return matcher.test(defaultRoute);
963
963
  });
964
964
  if (!isValid) {
965
- throw new MicroFrontendError(
965
+ throw new MicrofrontendError(
966
966
  `default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
967
967
  { type: "config", subtype: "invalid_main_path" }
968
968
  );
@@ -1025,7 +1025,7 @@ var validatePaths = (applicationConfigsById) => {
1025
1025
  );
1026
1026
  });
1027
1027
  if (errors.length) {
1028
- throw new MicroFrontendError(`Invalid paths: ${errors.join(", ")}`, {
1028
+ throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
1029
1029
  type: "config",
1030
1030
  subtype: "conflicting_paths"
1031
1031
  });
@@ -1059,13 +1059,13 @@ function validatePathExpression(path3) {
1059
1059
  var validateDefaults = (applicationConfigsById) => {
1060
1060
  const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
1061
1061
  if (defaultApplicationIds.length === 0) {
1062
- throw new MicroFrontendError(
1062
+ throw new MicrofrontendError(
1063
1063
  `No default application found. At least one application must be marked as default.`,
1064
1064
  { type: "config", subtype: "no_default_application" }
1065
1065
  );
1066
1066
  }
1067
1067
  if (defaultApplicationIds.length > 1) {
1068
- throw new MicroFrontendError(
1068
+ throw new MicrofrontendError(
1069
1069
  `Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
1070
1070
  { type: "config", subtype: "multiple_default_applications" }
1071
1071
  );
@@ -1077,7 +1077,7 @@ var validateOptions = (options) => {
1077
1077
  if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
1078
1078
  options.vercel.previewDeploymentSuffix
1079
1079
  )) {
1080
- throw new MicroFrontendError(
1080
+ throw new MicrofrontendError(
1081
1081
  `Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
1082
1082
  { type: "config", subtype: "invalid_preview_deployment_suffix" }
1083
1083
  );
@@ -1132,9 +1132,15 @@ function convertV1ConfigToV2Config(config, fromApp) {
1132
1132
  )
1133
1133
  };
1134
1134
  }
1135
+ const defaultApplication = Object.entries(config.applications).find(
1136
+ ([, application]) => application.default
1137
+ );
1138
+ if (!defaultApplication) {
1139
+ throw new Error("No default application found in the config");
1140
+ }
1135
1141
  return {
1136
1142
  ...common,
1137
- partOf: fromApp
1143
+ partOf: defaultApplication[0]
1138
1144
  };
1139
1145
  }
1140
1146
 
@@ -1149,8 +1155,8 @@ function writeFile(outputPath, config, prettify) {
1149
1155
  );
1150
1156
  }
1151
1157
 
1152
- // src/config/micro-frontend-config.ts
1153
- var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
1158
+ // src/config/microfrontend-config.ts
1159
+ var MicrofrontendConfig = class extends MicrofrontendConfigCommon {
1154
1160
  static validate(configString) {
1155
1161
  const config = validateSchema(configString);
1156
1162
  validateVersion(config.version);
@@ -1163,9 +1169,9 @@ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
1163
1169
  static fromEnv({
1164
1170
  cookies
1165
1171
  }) {
1166
- return new MicroFrontendConfigCommon({
1167
- config: MicroFrontendConfig.validate(
1168
- MicroFrontendConfigCommon.getConfigFromEnv()
1172
+ return new MicrofrontendConfigCommon({
1173
+ config: MicrofrontendConfig.validate(
1174
+ MicrofrontendConfigCommon.getConfigFromEnv()
1169
1175
  ),
1170
1176
  overrides: Overrides.parseOverrides(cookies)
1171
1177
  });
@@ -1175,11 +1181,11 @@ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
1175
1181
  }) {
1176
1182
  try {
1177
1183
  const config = fs2.readFileSync(filePath, "utf-8");
1178
- return new MicroFrontendConfig({
1179
- config: MicroFrontendConfig.validate(config)
1184
+ return new MicrofrontendConfig({
1185
+ config: MicrofrontendConfig.validate(config)
1180
1186
  });
1181
1187
  } catch (e) {
1182
- throw MicroFrontendError.handle(e, {
1188
+ throw MicrofrontendError.handle(e, {
1183
1189
  fileName: filePath
1184
1190
  });
1185
1191
  }
@@ -1202,7 +1208,7 @@ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
1202
1208
  }
1203
1209
  };
1204
1210
  export {
1205
- MicroFrontendConfig,
1211
+ MicrofrontendConfig,
1206
1212
  getClientConfigFromEnv,
1207
1213
  getConfigForClient,
1208
1214
  getWellKnownClientData,