@vercel/microfrontends 1.0.1-canary.5 → 1.1.1-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 (59) hide show
  1. package/dist/bin/cli.cjs +128 -53
  2. package/dist/config.cjs +80 -16
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +4 -4
  5. package/dist/config.js +80 -16
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +116 -49
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +116 -49
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +116 -49
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.js +116 -49
  14. package/dist/experimental/vite.js.map +1 -1
  15. package/dist/{index-2b59c627.d.ts → index-7e69650e.d.ts} +11 -5
  16. package/dist/microfrontends/server.cjs +116 -49
  17. package/dist/microfrontends/server.cjs.map +1 -1
  18. package/dist/microfrontends/server.d.ts +4 -4
  19. package/dist/microfrontends/server.js +116 -49
  20. package/dist/microfrontends/server.js.map +1 -1
  21. package/dist/microfrontends.cjs +80 -16
  22. package/dist/microfrontends.cjs.map +1 -1
  23. package/dist/microfrontends.d.ts +4 -4
  24. package/dist/microfrontends.js +80 -16
  25. package/dist/microfrontends.js.map +1 -1
  26. package/dist/next/config.cjs +133 -56
  27. package/dist/next/config.cjs.map +1 -1
  28. package/dist/next/config.js +133 -56
  29. package/dist/next/config.js.map +1 -1
  30. package/dist/next/endpoints.d.ts +2 -2
  31. package/dist/next/middleware.cjs +90 -16
  32. package/dist/next/middleware.cjs.map +1 -1
  33. package/dist/next/middleware.js +90 -16
  34. package/dist/next/middleware.js.map +1 -1
  35. package/dist/next/testing.cjs +84 -21
  36. package/dist/next/testing.cjs.map +1 -1
  37. package/dist/next/testing.d.ts +4 -4
  38. package/dist/next/testing.js +84 -21
  39. package/dist/next/testing.js.map +1 -1
  40. package/dist/overrides.d.ts +3 -3
  41. package/dist/schema.cjs +23 -0
  42. package/dist/schema.cjs.map +1 -1
  43. package/dist/schema.d.ts +7 -1
  44. package/dist/schema.js +13 -0
  45. package/dist/schema.js.map +1 -1
  46. package/dist/{index-2f78c0ca.d.ts → types-6ee19ccc.d.ts} +40 -9
  47. package/dist/{types-b6d38aea.d.ts → types-73527280.d.ts} +1 -1
  48. package/dist/{types-4ef2bddb.d.ts → types-74e3336c.d.ts} +1 -1
  49. package/dist/utils/mfe-port.cjs +116 -49
  50. package/dist/utils/mfe-port.cjs.map +1 -1
  51. package/dist/utils/mfe-port.js +116 -49
  52. package/dist/utils/mfe-port.js.map +1 -1
  53. package/dist/validation.cjs +36 -33
  54. package/dist/validation.cjs.map +1 -1
  55. package/dist/validation.d.ts +1 -1
  56. package/dist/validation.js +36 -33
  57. package/dist/validation.js.map +1 -1
  58. package/package.json +1 -1
  59. package/schema/schema.json +28 -7
@@ -282,10 +282,13 @@ var validateConfigPaths = (applicationConfigsById) => {
282
282
  }
283
283
  }
284
284
  if (errors.length) {
285
- throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
286
- type: "config",
287
- subtype: "conflicting_paths"
288
- });
285
+ throw new MicrofrontendError(
286
+ `Invalid paths: ${errors.join(", ")}. See supported paths in the documentation https://vercel.com/docs/microfrontends/path-routing#supported-path-expressions.`,
287
+ {
288
+ type: "config",
289
+ subtype: "conflicting_paths"
290
+ }
291
+ );
289
292
  }
290
293
  };
291
294
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
@@ -400,9 +403,40 @@ var validateDeprecatedFields = (config) => {
400
403
  `Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
401
404
  );
402
405
  }
403
- if (application.development?.local) {
406
+ if (application.development?.localPort) {
407
+ errors.push(
408
+ `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
409
+ );
410
+ }
411
+ if (application.development?.fallback && typeof application.development.fallback !== "string") {
412
+ const fallback = application.development.fallback;
413
+ let asString = fallback.host;
414
+ if (fallback.protocol) {
415
+ asString = `${fallback.protocol}://${asString}`;
416
+ }
417
+ if (fallback.port) {
418
+ asString = `${asString}:${fallback.port}`;
419
+ }
420
+ errors.push(
421
+ `Application '${applicationId}' requires a string (not an object) for the 'development.fallback' field. Please set 'development.fallback' to '${asString}'.`
422
+ );
423
+ }
424
+ if (application.development?.local && typeof application.development.local !== "string" && typeof application.development.local !== "number") {
425
+ const local = application.development.local;
426
+ let asString;
427
+ if (local.port && !local.protocol && !local.host) {
428
+ asString = String(local.port);
429
+ } else {
430
+ asString = local.host ?? "localhost";
431
+ if (local.protocol) {
432
+ asString = `${local.protocol}://${asString}`;
433
+ }
434
+ if (local.port) {
435
+ asString = `${asString}:${local.port}`;
436
+ }
437
+ }
404
438
  errors.push(
405
- `Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
439
+ `Application '${applicationId}' requires a string or number (not an object) for the 'development.local' field. Please set 'development.local' to '${asString}'.`
406
440
  );
407
441
  }
408
442
  }
@@ -466,10 +500,10 @@ var Host = class {
466
500
  }
467
501
  this.local = options?.isLocal;
468
502
  }
469
- static parseUrl(url) {
503
+ static parseUrl(url, defaultProtocol = "https") {
470
504
  let hostToParse = url;
471
505
  if (!/^https?:\/\//.exec(hostToParse)) {
472
- hostToParse = `https://${hostToParse}`;
506
+ hostToParse = `${defaultProtocol}://${hostToParse}`;
473
507
  }
474
508
  const parsed = new URL(hostToParse);
475
509
  if (!parsed.hostname) {
@@ -522,12 +556,39 @@ var LocalHost = class extends Host {
522
556
  constructor({
523
557
  appName,
524
558
  localPort,
525
- ...hostConfig
559
+ local
526
560
  }) {
527
- const host = hostConfig.host ?? "localhost";
528
- const port = localPort ?? hostConfig.port ?? generatePortFromName({ name: appName });
529
- const protocol = hostConfig.protocol ?? "http";
530
- super({ protocol, host, port });
561
+ if (localPort && local) {
562
+ throw new Error(
563
+ `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.`
564
+ );
565
+ }
566
+ let protocol;
567
+ let host;
568
+ let port;
569
+ if (localPort) {
570
+ port = localPort;
571
+ } else if (typeof local === "number") {
572
+ port = local;
573
+ } else if (typeof local === "string") {
574
+ if (/^\d+$/.test(local)) {
575
+ port = Number.parseInt(local);
576
+ } else {
577
+ const parsed = Host.parseUrl(local, "http");
578
+ protocol = parsed.protocol;
579
+ host = parsed.host;
580
+ port = parsed.port;
581
+ }
582
+ } else if (local) {
583
+ protocol = local.protocol;
584
+ host = local.host;
585
+ port = local.port;
586
+ }
587
+ super({
588
+ protocol: protocol ?? "http",
589
+ host: host ?? "localhost",
590
+ port: port ?? generatePortFromName({ name: appName })
591
+ });
531
592
  }
532
593
  };
533
594
 
@@ -543,7 +604,7 @@ var Application = class {
543
604
  local: new LocalHost({
544
605
  appName: name,
545
606
  localPort: app.development?.localPort,
546
- ...app.development?.local
607
+ local: app.development?.local
547
608
  }),
548
609
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
549
610
  };
@@ -553,6 +614,7 @@ var Application = class {
553
614
  this.fallback = new Host(app.production);
554
615
  }
555
616
  this.projectId = app.projectId ?? app.vercel?.projectId;
617
+ this.packageName = app.packageName;
556
618
  this.overrides = overrides?.environment ? {
557
619
  environment: new Host(overrides.environment)
558
620
  } : void 0;
@@ -718,10 +780,12 @@ var MicrofrontendConfigIsomorphic = class {
718
780
  ].filter(Boolean);
719
781
  }
720
782
  getApplication(name) {
721
- if (this.defaultApplication?.name === name) {
783
+ if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
722
784
  return this.defaultApplication;
723
785
  }
724
- const app = this.childApplications[name];
786
+ const app = this.childApplications[name] || Object.values(this.childApplications).find(
787
+ (child) => child.packageName === name
788
+ );
725
789
  if (!app) {
726
790
  throw new MicrofrontendError(
727
791
  `Could not find microfrontends configuration for application "${name}"`,
@@ -1170,9 +1234,7 @@ var schema_default = {
1170
1234
  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"
1171
1235
  }
1172
1236
  },
1173
- required: [
1174
- "applications"
1175
- ],
1237
+ required: ["applications"],
1176
1238
  additionalProperties: false
1177
1239
  },
1178
1240
  Options: {
@@ -1225,7 +1287,7 @@ var schema_default = {
1225
1287
  $ref: "#/definitions/Application"
1226
1288
  },
1227
1289
  propertyNames: {
1228
- description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1290
+ 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."
1229
1291
  }
1230
1292
  },
1231
1293
  Application: {
@@ -1247,7 +1309,12 @@ var schema_default = {
1247
1309
  },
1248
1310
  projectId: {
1249
1311
  type: "string",
1250
- description: "Vercel project ID"
1312
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1313
+ deprecated: "Instead, the application id should match the Vercel project name."
1314
+ },
1315
+ packageName: {
1316
+ type: "string",
1317
+ 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`."
1251
1318
  },
1252
1319
  production: {
1253
1320
  $ref: "#/definitions/HostConfig",
@@ -1267,9 +1334,7 @@ var schema_default = {
1267
1334
  description: "Vercel project ID"
1268
1335
  }
1269
1336
  },
1270
- required: [
1271
- "projectId"
1272
- ],
1337
+ required: ["projectId"],
1273
1338
  additionalProperties: false
1274
1339
  },
1275
1340
  HostConfig: {
@@ -1277,10 +1342,7 @@ var schema_default = {
1277
1342
  properties: {
1278
1343
  protocol: {
1279
1344
  type: "string",
1280
- enum: [
1281
- "http",
1282
- "https"
1283
- ],
1345
+ enum: ["http", "https"],
1284
1346
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1285
1347
  },
1286
1348
  host: {
@@ -1292,21 +1354,30 @@ var schema_default = {
1292
1354
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1293
1355
  }
1294
1356
  },
1295
- required: [
1296
- "host"
1297
- ],
1357
+ required: ["host"],
1298
1358
  additionalProperties: false
1299
1359
  },
1300
1360
  Development: {
1301
1361
  type: "object",
1302
1362
  properties: {
1303
1363
  local: {
1304
- $ref: "#/definitions/LocalHostConfig",
1305
- deprecated: "This is being replaced by the `localPort` field below."
1364
+ anyOf: [
1365
+ {
1366
+ type: "number"
1367
+ },
1368
+ {
1369
+ type: "string"
1370
+ },
1371
+ {
1372
+ $ref: "#/definitions/LocalHostConfig"
1373
+ }
1374
+ ],
1375
+ 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\n\nPassing a LocalHostConfig is deprecated and will go away soon, please pass a number or string."
1306
1376
  },
1307
1377
  localPort: {
1308
1378
  type: "number",
1309
- 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."
1379
+ 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.",
1380
+ deprecated: "Please set the port with the 'local' field instead."
1310
1381
  },
1311
1382
  fallback: {
1312
1383
  anyOf: [
@@ -1317,7 +1388,7 @@ var schema_default = {
1317
1388
  type: "string"
1318
1389
  }
1319
1390
  ],
1320
- description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error.\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."
1391
+ description: "Fallback for local development, could point to any environment. If this is not provided, or the application is not running - requests to the application in local development will error.\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\nPassing a HostConfig is deprecated and will go away soon, please pass a string."
1321
1392
  },
1322
1393
  task: {
1323
1394
  type: "string",
@@ -1336,10 +1407,7 @@ var schema_default = {
1336
1407
  },
1337
1408
  protocol: {
1338
1409
  type: "string",
1339
- enum: [
1340
- "http",
1341
- "https"
1342
- ],
1410
+ enum: ["http", "https"],
1343
1411
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1344
1412
  },
1345
1413
  port: {
@@ -1357,7 +1425,12 @@ var schema_default = {
1357
1425
  },
1358
1426
  projectId: {
1359
1427
  type: "string",
1360
- description: "Vercel project ID"
1428
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1429
+ deprecated: "Instead, the application id should match the Vercel project name."
1430
+ },
1431
+ packageName: {
1432
+ type: "string",
1433
+ 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`."
1361
1434
  },
1362
1435
  production: {
1363
1436
  $ref: "#/definitions/HostConfig",
@@ -1371,9 +1444,7 @@ var schema_default = {
1371
1444
  description: "Groups of path expressions that are routed to this application."
1372
1445
  }
1373
1446
  },
1374
- required: [
1375
- "routing"
1376
- ],
1447
+ required: ["routing"],
1377
1448
  additionalProperties: false
1378
1449
  },
1379
1450
  Routing: {
@@ -1400,9 +1471,7 @@ var schema_default = {
1400
1471
  }
1401
1472
  }
1402
1473
  },
1403
- required: [
1404
- "paths"
1405
- ],
1474
+ required: ["paths"],
1406
1475
  additionalProperties: false
1407
1476
  },
1408
1477
  ChildConfig: {
@@ -1423,9 +1492,7 @@ var schema_default = {
1423
1492
  description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
1424
1493
  }
1425
1494
  },
1426
- required: [
1427
- "partOf"
1428
- ],
1495
+ required: ["partOf"],
1429
1496
  additionalProperties: false
1430
1497
  }
1431
1498
  }