@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
@@ -225,8 +225,8 @@ var import_fast_glob = __toESM(require("fast-glob"), 1);
225
225
 
226
226
  // src/config/microfrontends/utils/get-config-file-name.ts
227
227
  var DEFAULT_CONFIGURATION_FILENAMES = [
228
- "microfrontends.jsonc",
229
- "microfrontends.json"
228
+ "microfrontends.json",
229
+ "microfrontends.jsonc"
230
230
  ];
231
231
  function getPossibleConfigurationFilenames({
232
232
  customConfigFilename
@@ -234,7 +234,7 @@ function getPossibleConfigurationFilenames({
234
234
  if (customConfigFilename) {
235
235
  if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
236
236
  throw new Error(
237
- `The VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable must end with '.json' or '.jsonc'. Received: ${customConfigFilename}`
237
+ `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.`
238
238
  );
239
239
  }
240
240
  return Array.from(
@@ -282,7 +282,7 @@ function findPackageWithMicrofrontendsConfig({
282
282
  }
283
283
  }
284
284
  }
285
- } catch (error) {
285
+ } catch (error2) {
286
286
  }
287
287
  }
288
288
  if (matchingPaths.length > 1) {
@@ -318,9 +318,9 @@ If you suspect this is thrown in error, please reach out to the Vercel team.`,
318
318
  }
319
319
  const [packageJsonPath] = matchingPaths;
320
320
  return (0, import_node_path2.dirname)(packageJsonPath);
321
- } catch (error) {
322
- if (error instanceof MicrofrontendError) {
323
- throw error;
321
+ } catch (error2) {
322
+ if (error2 instanceof MicrofrontendError) {
323
+ throw error2;
324
324
  }
325
325
  return null;
326
326
  }
@@ -344,6 +344,30 @@ function inferMicrofrontendsLocation(opts) {
344
344
  // src/config/microfrontends/utils/is-monorepo.ts
345
345
  var import_node_fs3 = __toESM(require("fs"), 1);
346
346
  var import_node_path3 = __toESM(require("path"), 1);
347
+
348
+ // src/bin/logger.ts
349
+ function debug(...args) {
350
+ if (process.env.MFE_DEBUG) {
351
+ console.log(...args);
352
+ }
353
+ }
354
+ function info(...args) {
355
+ console.log(...args);
356
+ }
357
+ function warn(...args) {
358
+ console.warn(...args);
359
+ }
360
+ function error(...args) {
361
+ console.error(...args);
362
+ }
363
+ var logger = {
364
+ debug,
365
+ info,
366
+ warn,
367
+ error
368
+ };
369
+
370
+ // src/config/microfrontends/utils/is-monorepo.ts
347
371
  function isMonorepo({
348
372
  repositoryRoot
349
373
  }) {
@@ -365,8 +389,8 @@ function isMonorepo({
365
389
  import_node_fs3.default.readFileSync(packageJsonPath, "utf-8")
366
390
  );
367
391
  return packageJson.workspaces !== void 0;
368
- } catch (error) {
369
- console.error("Error determining if repository is a monorepo", error);
392
+ } catch (error2) {
393
+ logger.error("Error determining if repository is a monorepo", error2);
370
394
  return false;
371
395
  }
372
396
  }
@@ -1160,38 +1184,28 @@ var schema_default = {
1160
1184
  type: "object",
1161
1185
  properties: {
1162
1186
  $schema: {
1163
- type: "string"
1187
+ type: "string",
1188
+ description: "See https://openapi.vercel.sh/microfrontends.json."
1164
1189
  },
1165
1190
  version: {
1166
1191
  type: "string",
1167
- const: "1"
1168
- },
1169
- options: {
1170
- $ref: "#/definitions/Options"
1192
+ const: "1",
1193
+ description: "The version of the microfrontends config schema."
1171
1194
  },
1172
1195
  applications: {
1173
1196
  $ref: "#/definitions/ApplicationRouting",
1174
- 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"
1197
+ description: "Mapping of Vercel project names to their microfrontend configurations."
1198
+ },
1199
+ options: {
1200
+ $ref: "#/definitions/Options",
1201
+ description: "Optional configuration options for the microfrontend."
1175
1202
  }
1176
1203
  },
1177
1204
  required: [
1178
1205
  "applications"
1179
1206
  ],
1180
- additionalProperties: false
1181
- },
1182
- Options: {
1183
- type: "object",
1184
- properties: {
1185
- disableOverrides: {
1186
- type: "boolean",
1187
- 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."
1188
- },
1189
- localProxyPort: {
1190
- type: "number",
1191
- description: "The port number used by the local proxy server.\n\nThe default is `3024`."
1192
- }
1193
- },
1194
- additionalProperties: false
1207
+ additionalProperties: false,
1208
+ description: "The microfrontends configuration schema. See https://vercel.com/docs/microfrontends/configuration."
1195
1209
  },
1196
1210
  ApplicationRouting: {
1197
1211
  type: "object",
@@ -1199,8 +1213,9 @@ var schema_default = {
1199
1213
  $ref: "#/definitions/Application"
1200
1214
  },
1201
1215
  propertyNames: {
1202
- 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."
1203
- }
1216
+ 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."
1217
+ },
1218
+ description: "Mapping of Vercel project names to their microfrontend configurations."
1204
1219
  },
1205
1220
  Application: {
1206
1221
  anyOf: [
@@ -1210,14 +1225,15 @@ var schema_default = {
1210
1225
  {
1211
1226
  $ref: "#/definitions/ChildApplication"
1212
1227
  }
1213
- ]
1228
+ ],
1229
+ description: "The configuration for a microfrontend application. There must always be one default application."
1214
1230
  },
1215
1231
  DefaultApplication: {
1216
1232
  type: "object",
1217
1233
  properties: {
1218
1234
  packageName: {
1219
1235
  type: "string",
1220
- 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`."
1236
+ 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."
1221
1237
  },
1222
1238
  development: {
1223
1239
  $ref: "#/definitions/DefaultDevelopment",
@@ -1237,15 +1253,15 @@ var schema_default = {
1237
1253
  "number",
1238
1254
  "string"
1239
1255
  ],
1240
- 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"
1256
+ 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."
1241
1257
  },
1242
1258
  task: {
1243
1259
  type: "string",
1244
- description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
1260
+ 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.'
1245
1261
  },
1246
1262
  fallback: {
1247
1263
  type: "string",
1248
- 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."
1264
+ 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."
1249
1265
  }
1250
1266
  },
1251
1267
  required: [
@@ -1258,7 +1274,7 @@ var schema_default = {
1258
1274
  properties: {
1259
1275
  packageName: {
1260
1276
  type: "string",
1261
- 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`."
1277
+ 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."
1262
1278
  },
1263
1279
  development: {
1264
1280
  $ref: "#/definitions/ChildDevelopment",
@@ -1266,11 +1282,11 @@ var schema_default = {
1266
1282
  },
1267
1283
  routing: {
1268
1284
  $ref: "#/definitions/Routing",
1269
- description: "Groups of path expressions that are routed to this application."
1285
+ description: "Groups of path expressions that are routed to this application.\n\nSee https://vercel.com/docs/microfrontends/path-routing."
1270
1286
  },
1271
1287
  assetPrefix: {
1272
1288
  type: "string",
1273
- 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."
1289
+ 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."
1274
1290
  }
1275
1291
  },
1276
1292
  required: [
@@ -1286,15 +1302,15 @@ var schema_default = {
1286
1302
  "number",
1287
1303
  "string"
1288
1304
  ],
1289
- 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"
1305
+ 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."
1290
1306
  },
1291
1307
  task: {
1292
1308
  type: "string",
1293
- description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
1309
+ 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.'
1294
1310
  },
1295
1311
  fallback: {
1296
1312
  type: "string",
1297
- 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."
1313
+ 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."
1298
1314
  }
1299
1315
  },
1300
1316
  additionalProperties: false
@@ -1303,29 +1319,46 @@ var schema_default = {
1303
1319
  type: "array",
1304
1320
  items: {
1305
1321
  $ref: "#/definitions/PathGroup"
1306
- }
1322
+ },
1323
+ description: "A list of path groups that are routed to this application."
1307
1324
  },
1308
1325
  PathGroup: {
1309
1326
  type: "object",
1310
1327
  properties: {
1311
1328
  group: {
1312
1329
  type: "string",
1313
- description: "Optional group name for the paths"
1330
+ description: "Group name for the paths."
1314
1331
  },
1315
1332
  flag: {
1316
1333
  type: "string",
1317
- description: "flag name that can be used to enable/disable all paths in the group"
1334
+ 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."
1318
1335
  },
1319
1336
  paths: {
1320
1337
  type: "array",
1321
1338
  items: {
1322
1339
  type: "string"
1323
- }
1340
+ },
1341
+ description: "A list of path expressions that are routed to this application. See https://vercel.com/docs/microfrontends/path-routing#supported-path-expressions."
1324
1342
  }
1325
1343
  },
1326
1344
  required: [
1327
1345
  "paths"
1328
1346
  ],
1347
+ additionalProperties: false,
1348
+ description: "A group of paths that is routed to this application."
1349
+ },
1350
+ Options: {
1351
+ type: "object",
1352
+ properties: {
1353
+ disableOverrides: {
1354
+ type: "boolean",
1355
+ 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."
1356
+ },
1357
+ localProxyPort: {
1358
+ type: "number",
1359
+ 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."
1360
+ }
1361
+ },
1329
1362
  additionalProperties: false
1330
1363
  }
1331
1364
  }
@@ -1344,19 +1377,19 @@ function formatAjvErrors(errors) {
1344
1377
  return [];
1345
1378
  }
1346
1379
  const errorMessages = [];
1347
- for (const error of errors) {
1348
- if (error.instancePath === "" && (error.keyword === "anyOf" || error.keyword === "required" && error.params.missingProperty === "partOf")) {
1380
+ for (const error2 of errors) {
1381
+ if (error2.instancePath === "" && (error2.keyword === "anyOf" || error2.keyword === "required" && error2.params.missingProperty === "partOf")) {
1349
1382
  continue;
1350
1383
  }
1351
- const instancePath = error.instancePath.slice(1);
1384
+ const instancePath = error2.instancePath.slice(1);
1352
1385
  const formattedInstancePath = instancePath === "" ? "at the root" : `in field ${instancePath}`;
1353
- if (error.keyword === "required" && error.params.missingProperty === "routing" && instancePath.split("/").length === 2) {
1386
+ if (error2.keyword === "required" && error2.params.missingProperty === "routing" && instancePath.split("/").length === 2) {
1354
1387
  errorMessages.push(
1355
1388
  `Unable to infer if ${instancePath} is the default app or a child app. This usually means that there is another error in the configuration.`
1356
1389
  );
1357
- } else if (error.keyword === "anyOf" && instancePath.split("/").length > 2) {
1390
+ } else if (error2.keyword === "anyOf" && instancePath.split("/").length > 2) {
1358
1391
  const anyOfErrors = errors.filter(
1359
- (e) => e.instancePath === error.instancePath && e.keyword !== "anyOf"
1392
+ (e) => e.instancePath === error2.instancePath && e.keyword !== "anyOf"
1360
1393
  );
1361
1394
  if (anyOfErrors.every((e) => e.keyword === "type")) {
1362
1395
  const allowedTypes = LIST_FORMATTER2.format(
@@ -1372,13 +1405,13 @@ function formatAjvErrors(errors) {
1372
1405
  `Invalid field for ${instancePath}. Possible error messages are ${LIST_FORMATTER2.format(anyOfErrors.map((e) => e.message ?? ""))}`
1373
1406
  );
1374
1407
  }
1375
- } else if (error.keyword === "additionalProperties" && !(error.params.additionalProperty === "routing" && instancePath.split("/").length === 2)) {
1408
+ } else if (error2.keyword === "additionalProperties" && !(error2.params.additionalProperty === "routing" && instancePath.split("/").length === 2)) {
1376
1409
  errorMessages.push(
1377
- `Property '${error.params.additionalProperty}' is not allowed ${formattedInstancePath}`
1410
+ `Property '${error2.params.additionalProperty}' is not allowed ${formattedInstancePath}`
1378
1411
  );
1379
- } else if (error.keyword === "required") {
1412
+ } else if (error2.keyword === "required") {
1380
1413
  errorMessages.push(
1381
- `Property '${error.params.missingProperty}' is required ${formattedInstancePath}`
1414
+ `Property '${error2.params.missingProperty}' is required ${formattedInstancePath}`
1382
1415
  );
1383
1416
  }
1384
1417
  }
@@ -1391,8 +1424,8 @@ function validateSchema(configString) {
1391
1424
  const isValid = validate(parsedConfig);
1392
1425
  if (!isValid) {
1393
1426
  throw new MicrofrontendError(
1394
- `Invalid microfrontends config:${formatAjvErrors(validate.errors).map((error) => `
1395
- - ${error}`).join(
1427
+ `Invalid microfrontends config:${formatAjvErrors(validate.errors).map((error2) => `
1428
+ - ${error2}`).join(
1396
1429
  ""
1397
1430
  )}
1398
1431
 
@@ -1677,12 +1710,10 @@ function microfrontends(opts) {
1677
1710
  port: app.development.local.port
1678
1711
  };
1679
1712
  }
1680
- if (process.env.MFE_DEBUG) {
1681
- console.log(
1682
- "[@vercel/microfrontends] Updating Vite configuration with the following changes:",
1683
- additionalConfigOptions
1684
- );
1685
- }
1713
+ logger.debug(
1714
+ "[@vercel/microfrontends] Updating Vite configuration with the following changes:",
1715
+ additionalConfigOptions
1716
+ );
1686
1717
  return {
1687
1718
  name: "vite-plugin-vercel-microfrontends",
1688
1719
  config: () => {