@vercel/microfrontends 2.1.2 → 2.2.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 +20 -0
  2. package/README.md +4 -0
  3. package/dist/bin/cli.cjs +125 -89
  4. package/dist/config.d.ts +2 -2
  5. package/dist/experimental/sveltekit.cjs +97 -62
  6. package/dist/experimental/sveltekit.cjs.map +1 -1
  7. package/dist/experimental/sveltekit.d.ts +6 -0
  8. package/dist/experimental/sveltekit.js +97 -62
  9. package/dist/experimental/sveltekit.js.map +1 -1
  10. package/dist/experimental/vite.cjs +96 -65
  11. package/dist/experimental/vite.cjs.map +1 -1
  12. package/dist/experimental/vite.js +96 -65
  13. package/dist/experimental/vite.js.map +1 -1
  14. package/dist/microfrontends/server.cjs +92 -59
  15. package/dist/microfrontends/server.cjs.map +1 -1
  16. package/dist/microfrontends/server.d.ts +2 -2
  17. package/dist/microfrontends/server.js +92 -59
  18. package/dist/microfrontends/server.js.map +1 -1
  19. package/dist/microfrontends/utils.cjs +3 -3
  20. package/dist/microfrontends/utils.cjs.map +1 -1
  21. package/dist/microfrontends/utils.d.ts +1 -1
  22. package/dist/microfrontends/utils.js +3 -3
  23. package/dist/microfrontends/utils.js.map +1 -1
  24. package/dist/next/config.cjs +133 -115
  25. package/dist/next/config.cjs.map +1 -1
  26. package/dist/next/config.d.ts +11 -1
  27. package/dist/next/config.js +133 -115
  28. package/dist/next/config.js.map +1 -1
  29. package/dist/next/middleware.cjs +35 -17
  30. package/dist/next/middleware.cjs.map +1 -1
  31. package/dist/next/middleware.js +35 -17
  32. package/dist/next/middleware.js.map +1 -1
  33. package/dist/next/testing.d.ts +2 -2
  34. package/dist/overrides.d.ts +3 -3
  35. package/dist/schema.d.ts +2 -2
  36. package/dist/{types-88602303.d.ts → types-b9ea41b2.d.ts} +1 -1
  37. package/dist/{types-e7523e61.d.ts → types-dcd8b17a.d.ts} +71 -24
  38. package/dist/utils/mfe-port.cjs +92 -59
  39. package/dist/utils/mfe-port.cjs.map +1 -1
  40. package/dist/utils/mfe-port.js +92 -59
  41. package/dist/utils/mfe-port.js.map +1 -1
  42. package/dist/validation.cjs +47 -38
  43. package/dist/validation.cjs.map +1 -1
  44. package/dist/validation.d.ts +1 -1
  45. package/dist/validation.js +47 -38
  46. package/dist/validation.js.map +1 -1
  47. package/package.json +1 -1
  48. package/schema/schema.json +47 -38
@@ -224,8 +224,8 @@ var import_fast_glob = __toESM(require("fast-glob"), 1);
224
224
 
225
225
  // src/config/microfrontends/utils/get-config-file-name.ts
226
226
  var DEFAULT_CONFIGURATION_FILENAMES = [
227
- "microfrontends.jsonc",
228
- "microfrontends.json"
227
+ "microfrontends.json",
228
+ "microfrontends.jsonc"
229
229
  ];
230
230
  function getPossibleConfigurationFilenames({
231
231
  customConfigFilename
@@ -233,7 +233,7 @@ function getPossibleConfigurationFilenames({
233
233
  if (customConfigFilename) {
234
234
  if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
235
235
  throw new Error(
236
- `The VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable must end with '.json' or '.jsonc'. Received: ${customConfigFilename}`
236
+ `Found VC_MICROFRONTENDS_CONFIG_FILE_NAME but the name is invalid. Received: ${customConfigFilename}. The file name must end with '.json' or '.jsonc'. It's also possible for the env var to include the path, eg microfrontends-dev.json or /path/to/microfrontends-dev.json.`
237
237
  );
238
238
  }
239
239
  return Array.from(
@@ -281,7 +281,7 @@ function findPackageWithMicrofrontendsConfig({
281
281
  }
282
282
  }
283
283
  }
284
- } catch (error) {
284
+ } catch (error2) {
285
285
  }
286
286
  }
287
287
  if (matchingPaths.length > 1) {
@@ -317,9 +317,9 @@ If you suspect this is thrown in error, please reach out to the Vercel team.`,
317
317
  }
318
318
  const [packageJsonPath] = matchingPaths;
319
319
  return (0, import_node_path2.dirname)(packageJsonPath);
320
- } catch (error) {
321
- if (error instanceof MicrofrontendError) {
322
- throw error;
320
+ } catch (error2) {
321
+ if (error2 instanceof MicrofrontendError) {
322
+ throw error2;
323
323
  }
324
324
  return null;
325
325
  }
@@ -343,6 +343,30 @@ function inferMicrofrontendsLocation(opts) {
343
343
  // src/config/microfrontends/utils/is-monorepo.ts
344
344
  var import_node_fs3 = __toESM(require("fs"), 1);
345
345
  var import_node_path3 = __toESM(require("path"), 1);
346
+
347
+ // src/bin/logger.ts
348
+ function debug(...args) {
349
+ if (process.env.MFE_DEBUG) {
350
+ console.log(...args);
351
+ }
352
+ }
353
+ function info(...args) {
354
+ console.log(...args);
355
+ }
356
+ function warn(...args) {
357
+ console.warn(...args);
358
+ }
359
+ function error(...args) {
360
+ console.error(...args);
361
+ }
362
+ var logger = {
363
+ debug,
364
+ info,
365
+ warn,
366
+ error
367
+ };
368
+
369
+ // src/config/microfrontends/utils/is-monorepo.ts
346
370
  function isMonorepo({
347
371
  repositoryRoot
348
372
  }) {
@@ -364,8 +388,8 @@ function isMonorepo({
364
388
  import_node_fs3.default.readFileSync(packageJsonPath, "utf-8")
365
389
  );
366
390
  return packageJson.workspaces !== void 0;
367
- } catch (error) {
368
- console.error("Error determining if repository is a monorepo", error);
391
+ } catch (error2) {
392
+ logger.error("Error determining if repository is a monorepo", error2);
369
393
  return false;
370
394
  }
371
395
  }
@@ -1159,38 +1183,28 @@ var schema_default = {
1159
1183
  type: "object",
1160
1184
  properties: {
1161
1185
  $schema: {
1162
- type: "string"
1186
+ type: "string",
1187
+ description: "See https://openapi.vercel.sh/microfrontends.json."
1163
1188
  },
1164
1189
  version: {
1165
1190
  type: "string",
1166
- const: "1"
1167
- },
1168
- options: {
1169
- $ref: "#/definitions/Options"
1191
+ const: "1",
1192
+ description: "The version of the microfrontends config schema."
1170
1193
  },
1171
1194
  applications: {
1172
1195
  $ref: "#/definitions/ApplicationRouting",
1173
- 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"
1196
+ description: "Mapping of Vercel project names to their microfrontend configurations."
1197
+ },
1198
+ options: {
1199
+ $ref: "#/definitions/Options",
1200
+ description: "Optional configuration options for the microfrontend."
1174
1201
  }
1175
1202
  },
1176
1203
  required: [
1177
1204
  "applications"
1178
1205
  ],
1179
- additionalProperties: false
1180
- },
1181
- Options: {
1182
- type: "object",
1183
- properties: {
1184
- disableOverrides: {
1185
- type: "boolean",
1186
- description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
1187
- },
1188
- localProxyPort: {
1189
- type: "number",
1190
- description: "The port number used by the local proxy server.\n\nThe default is `3024`."
1191
- }
1192
- },
1193
- additionalProperties: false
1206
+ additionalProperties: false,
1207
+ description: "The microfrontends configuration schema. See https://vercel.com/docs/microfrontends/configuration."
1194
1208
  },
1195
1209
  ApplicationRouting: {
1196
1210
  type: "object",
@@ -1198,8 +1212,9 @@ var schema_default = {
1198
1212
  $ref: "#/definitions/Application"
1199
1213
  },
1200
1214
  propertyNames: {
1201
- description: "The unique identifier for a Microfrontend Application.\n\nMust match the Vercel project name.\n\nNote: If this name does not also match the name used to run the application, (e.g. the `name` from the `package.json`), then the `packageName` field should be set."
1202
- }
1215
+ description: "The Vercel project name of the microfrontend application.\n\nNote: If this name does not also match the name `name` from the `package.json`, set `packageName` with the name used in `package.json`.\n\nSee https://vercel.com/docs/microfrontends/configuration#application-naming."
1216
+ },
1217
+ description: "Mapping of Vercel project names to their microfrontend configurations."
1203
1218
  },
1204
1219
  Application: {
1205
1220
  anyOf: [
@@ -1209,14 +1224,15 @@ var schema_default = {
1209
1224
  {
1210
1225
  $ref: "#/definitions/ChildApplication"
1211
1226
  }
1212
- ]
1227
+ ],
1228
+ description: "The configuration for a microfrontend application. There must always be one default application."
1213
1229
  },
1214
1230
  DefaultApplication: {
1215
1231
  type: "object",
1216
1232
  properties: {
1217
1233
  packageName: {
1218
1234
  type: "string",
1219
- 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`."
1235
+ 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`.\n\nSee https://vercel.com/docs/microfrontends/configuration#application-naming."
1220
1236
  },
1221
1237
  development: {
1222
1238
  $ref: "#/definitions/DefaultDevelopment",
@@ -1236,15 +1252,15 @@ var schema_default = {
1236
1252
  "number",
1237
1253
  "string"
1238
1254
  ],
1239
- 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"
1255
+ description: "A local port number or host that this application runs on when it is running locally. If passing a string, include the protocol (optional), host (required) and port (optional).\n\nExamples of valid values: 8080, my.localhost.me, my.localhost.me:8080, https://my.localhost.me, https://my.localhost.me:8080.\n\nThe default value is http://localhost:<port> where port is a stable, unique port number (based on the application name).\n\nSee https://vercel.com/docs/microfrontends/local-development."
1240
1256
  },
1241
1257
  task: {
1242
1258
  type: "string",
1243
- description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
1259
+ description: 'The task to run when starting the development server. Should reference a script in the package.json of the application.\n\nThe default value is "dev".\n\nSee https://vercel.com/docs/microfrontends/local-development.'
1244
1260
  },
1245
1261
  fallback: {
1246
1262
  type: "string",
1247
- 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."
1263
+ 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.\n\nSee https://vercel.com/docs/microfrontends/local-development."
1248
1264
  }
1249
1265
  },
1250
1266
  required: [
@@ -1257,7 +1273,7 @@ var schema_default = {
1257
1273
  properties: {
1258
1274
  packageName: {
1259
1275
  type: "string",
1260
- 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`."
1276
+ 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`.\n\nSee https://vercel.com/docs/microfrontends/configuration#application-naming."
1261
1277
  },
1262
1278
  development: {
1263
1279
  $ref: "#/definitions/ChildDevelopment",
@@ -1265,11 +1281,11 @@ var schema_default = {
1265
1281
  },
1266
1282
  routing: {
1267
1283
  $ref: "#/definitions/Routing",
1268
- description: "Groups of path expressions that are routed to this application."
1284
+ description: "Groups of path expressions that are routed to this application.\n\nSee https://vercel.com/docs/microfrontends/path-routing."
1269
1285
  },
1270
1286
  assetPrefix: {
1271
1287
  type: "string",
1272
- description: "The name of the asset prefix to use instead of the auto-generated name.\n\nThe asset prefix is used to prefix all paths to static assets, such as JS, CSS, or images that are served by a specific application. It is necessary to ensure there are no conflicts with other applications on the same domain.\n\nAn auto-generated asset prefix of the form `vc-ap-<hash>` is used when this field is not provided.\n\nWhen this field is provided, `/${assetPrefix}/:path*` must also be added to the list of paths in the `routing` field. Changing the asset prefix after a microfrontend application has already been deployed is not a forwards and backwards compatible change, and the asset prefix should be added to the `routing` field and deployed before setting the `assetPrefix` field."
1288
+ description: "The name of the asset prefix to use instead of the auto-generated name.\n\nThe asset prefix is used to prefix all paths to static assets, such as JS, CSS, or images that are served by a specific application. It is necessary to ensure there are no conflicts with other applications on the same domain.\n\nAn auto-generated asset prefix of the form `vc-ap-<hash>` is used when this field is not provided.\n\nWhen this field is provided, `/${assetPrefix}/:path*` must also be added to the list of paths in the `routing` field. Changing the asset prefix after a microfrontend application has already been deployed is not a forwards and backwards compatible change, and the asset prefix should be added to the `routing` field and deployed before setting the `assetPrefix` field.\n\nThe default value is the auto-generated asset prefix of the form `vc-ap-<hash>`.\n\nSee https://vercel.com/docs/microfrontends/path-routing#asset-prefix."
1273
1289
  }
1274
1290
  },
1275
1291
  required: [
@@ -1285,15 +1301,15 @@ var schema_default = {
1285
1301
  "number",
1286
1302
  "string"
1287
1303
  ],
1288
- 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"
1304
+ description: "A local port number or host that this application runs on when it is running locally. If passing a string, include the protocol (optional), host (required) and port (optional).\n\nExamples of valid values: 8080, my.localhost.me, my.localhost.me:8080, https://my.localhost.me, https://my.localhost.me:8080.\n\nThe default value is http://localhost:<port> where port is a stable, unique port number (based on the application name).\n\nSee https://vercel.com/docs/microfrontends/local-development."
1289
1305
  },
1290
1306
  task: {
1291
1307
  type: "string",
1292
- description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
1308
+ description: 'The task to run when starting the development server. Should reference a script in the package.json of the application.\n\nThe default value is "dev".\n\nSee https://vercel.com/docs/microfrontends/local-development.'
1293
1309
  },
1294
1310
  fallback: {
1295
1311
  type: "string",
1296
- description: "Fallback for local development, could point to any environment. This is optional for child apps. If not provided, the fallback of the default app will be used.\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."
1312
+ description: "Fallback for local development, could point to any environment. If not provided for child apps, the fallback of the default app will be used.\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.\n\nSee https://vercel.com/docs/microfrontends/local-development."
1297
1313
  }
1298
1314
  },
1299
1315
  additionalProperties: false
@@ -1302,29 +1318,46 @@ var schema_default = {
1302
1318
  type: "array",
1303
1319
  items: {
1304
1320
  $ref: "#/definitions/PathGroup"
1305
- }
1321
+ },
1322
+ description: "A list of path groups that are routed to this application."
1306
1323
  },
1307
1324
  PathGroup: {
1308
1325
  type: "object",
1309
1326
  properties: {
1310
1327
  group: {
1311
1328
  type: "string",
1312
- description: "Optional group name for the paths"
1329
+ description: "Group name for the paths."
1313
1330
  },
1314
1331
  flag: {
1315
1332
  type: "string",
1316
- description: "flag name that can be used to enable/disable all paths in the group"
1333
+ description: "The name of the feature flag that controls routing for this group of paths. See https://vercel.com/docs/microfrontends/path-routing#routing-changes-safely-with-flags."
1317
1334
  },
1318
1335
  paths: {
1319
1336
  type: "array",
1320
1337
  items: {
1321
1338
  type: "string"
1322
- }
1339
+ },
1340
+ description: "A list of path expressions that are routed to this application. See https://vercel.com/docs/microfrontends/path-routing#supported-path-expressions."
1323
1341
  }
1324
1342
  },
1325
1343
  required: [
1326
1344
  "paths"
1327
1345
  ],
1346
+ additionalProperties: false,
1347
+ description: "A group of paths that is routed to this application."
1348
+ },
1349
+ Options: {
1350
+ type: "object",
1351
+ properties: {
1352
+ disableOverrides: {
1353
+ type: "boolean",
1354
+ description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect.\n\nSee https://vercel.com/docs/microfrontends/managing-microfrontends/vercel-toolbar#routing-overrides."
1355
+ },
1356
+ localProxyPort: {
1357
+ type: "number",
1358
+ description: "The port number used by the local proxy server.\n\nThe default value is 3024.\n\nSee https://vercel.com/docs/microfrontends/local-development."
1359
+ }
1360
+ },
1328
1361
  additionalProperties: false
1329
1362
  }
1330
1363
  }
@@ -1343,19 +1376,19 @@ function formatAjvErrors(errors) {
1343
1376
  return [];
1344
1377
  }
1345
1378
  const errorMessages = [];
1346
- for (const error of errors) {
1347
- if (error.instancePath === "" && (error.keyword === "anyOf" || error.keyword === "required" && error.params.missingProperty === "partOf")) {
1379
+ for (const error2 of errors) {
1380
+ if (error2.instancePath === "" && (error2.keyword === "anyOf" || error2.keyword === "required" && error2.params.missingProperty === "partOf")) {
1348
1381
  continue;
1349
1382
  }
1350
- const instancePath = error.instancePath.slice(1);
1383
+ const instancePath = error2.instancePath.slice(1);
1351
1384
  const formattedInstancePath = instancePath === "" ? "at the root" : `in field ${instancePath}`;
1352
- if (error.keyword === "required" && error.params.missingProperty === "routing" && instancePath.split("/").length === 2) {
1385
+ if (error2.keyword === "required" && error2.params.missingProperty === "routing" && instancePath.split("/").length === 2) {
1353
1386
  errorMessages.push(
1354
1387
  `Unable to infer if ${instancePath} is the default app or a child app. This usually means that there is another error in the configuration.`
1355
1388
  );
1356
- } else if (error.keyword === "anyOf" && instancePath.split("/").length > 2) {
1389
+ } else if (error2.keyword === "anyOf" && instancePath.split("/").length > 2) {
1357
1390
  const anyOfErrors = errors.filter(
1358
- (e) => e.instancePath === error.instancePath && e.keyword !== "anyOf"
1391
+ (e) => e.instancePath === error2.instancePath && e.keyword !== "anyOf"
1359
1392
  );
1360
1393
  if (anyOfErrors.every((e) => e.keyword === "type")) {
1361
1394
  const allowedTypes = LIST_FORMATTER2.format(
@@ -1371,13 +1404,13 @@ function formatAjvErrors(errors) {
1371
1404
  `Invalid field for ${instancePath}. Possible error messages are ${LIST_FORMATTER2.format(anyOfErrors.map((e) => e.message ?? ""))}`
1372
1405
  );
1373
1406
  }
1374
- } else if (error.keyword === "additionalProperties" && !(error.params.additionalProperty === "routing" && instancePath.split("/").length === 2)) {
1407
+ } else if (error2.keyword === "additionalProperties" && !(error2.params.additionalProperty === "routing" && instancePath.split("/").length === 2)) {
1375
1408
  errorMessages.push(
1376
- `Property '${error.params.additionalProperty}' is not allowed ${formattedInstancePath}`
1409
+ `Property '${error2.params.additionalProperty}' is not allowed ${formattedInstancePath}`
1377
1410
  );
1378
- } else if (error.keyword === "required") {
1411
+ } else if (error2.keyword === "required") {
1379
1412
  errorMessages.push(
1380
- `Property '${error.params.missingProperty}' is required ${formattedInstancePath}`
1413
+ `Property '${error2.params.missingProperty}' is required ${formattedInstancePath}`
1381
1414
  );
1382
1415
  }
1383
1416
  }
@@ -1390,8 +1423,8 @@ function validateSchema(configString) {
1390
1423
  const isValid = validate(parsedConfig);
1391
1424
  if (!isValid) {
1392
1425
  throw new MicrofrontendError(
1393
- `Invalid microfrontends config:${formatAjvErrors(validate.errors).map((error) => `
1394
- - ${error}`).join(
1426
+ `Invalid microfrontends config:${formatAjvErrors(validate.errors).map((error2) => `
1427
+ - ${error2}`).join(
1395
1428
  ""
1396
1429
  )}
1397
1430