@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
@@ -314,10 +314,13 @@ var validateConfigPaths = (applicationConfigsById) => {
314
314
  }
315
315
  }
316
316
  if (errors.length) {
317
- throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
318
- type: "config",
319
- subtype: "conflicting_paths"
320
- });
317
+ throw new MicrofrontendError(
318
+ `Invalid paths: ${errors.join(", ")}. See supported paths in the documentation https://vercel.com/docs/microfrontends/path-routing#supported-path-expressions.`,
319
+ {
320
+ type: "config",
321
+ subtype: "conflicting_paths"
322
+ }
323
+ );
321
324
  }
322
325
  };
323
326
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
@@ -432,9 +435,40 @@ var validateDeprecatedFields = (config) => {
432
435
  `Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
433
436
  );
434
437
  }
435
- if (application.development?.local) {
438
+ if (application.development?.localPort) {
439
+ errors.push(
440
+ `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
441
+ );
442
+ }
443
+ if (application.development?.fallback && typeof application.development.fallback !== "string") {
444
+ const fallback = application.development.fallback;
445
+ let asString = fallback.host;
446
+ if (fallback.protocol) {
447
+ asString = `${fallback.protocol}://${asString}`;
448
+ }
449
+ if (fallback.port) {
450
+ asString = `${asString}:${fallback.port}`;
451
+ }
452
+ errors.push(
453
+ `Application '${applicationId}' requires a string (not an object) for the 'development.fallback' field. Please set 'development.fallback' to '${asString}'.`
454
+ );
455
+ }
456
+ if (application.development?.local && typeof application.development.local !== "string" && typeof application.development.local !== "number") {
457
+ const local = application.development.local;
458
+ let asString;
459
+ if (local.port && !local.protocol && !local.host) {
460
+ asString = String(local.port);
461
+ } else {
462
+ asString = local.host ?? "localhost";
463
+ if (local.protocol) {
464
+ asString = `${local.protocol}://${asString}`;
465
+ }
466
+ if (local.port) {
467
+ asString = `${asString}:${local.port}`;
468
+ }
469
+ }
436
470
  errors.push(
437
- `Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
471
+ `Application '${applicationId}' requires a string or number (not an object) for the 'development.local' field. Please set 'development.local' to '${asString}'.`
438
472
  );
439
473
  }
440
474
  }
@@ -498,10 +532,10 @@ var Host = class {
498
532
  }
499
533
  this.local = options?.isLocal;
500
534
  }
501
- static parseUrl(url) {
535
+ static parseUrl(url, defaultProtocol = "https") {
502
536
  let hostToParse = url;
503
537
  if (!/^https?:\/\//.exec(hostToParse)) {
504
- hostToParse = `https://${hostToParse}`;
538
+ hostToParse = `${defaultProtocol}://${hostToParse}`;
505
539
  }
506
540
  const parsed = new URL(hostToParse);
507
541
  if (!parsed.hostname) {
@@ -554,12 +588,39 @@ var LocalHost = class extends Host {
554
588
  constructor({
555
589
  appName,
556
590
  localPort,
557
- ...hostConfig
591
+ local
558
592
  }) {
559
- const host = hostConfig.host ?? "localhost";
560
- const port = localPort ?? hostConfig.port ?? generatePortFromName({ name: appName });
561
- const protocol = hostConfig.protocol ?? "http";
562
- super({ protocol, host, port });
593
+ if (localPort && local) {
594
+ throw new Error(
595
+ `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.`
596
+ );
597
+ }
598
+ let protocol;
599
+ let host;
600
+ let port;
601
+ if (localPort) {
602
+ port = localPort;
603
+ } else if (typeof local === "number") {
604
+ port = local;
605
+ } else if (typeof local === "string") {
606
+ if (/^\d+$/.test(local)) {
607
+ port = Number.parseInt(local);
608
+ } else {
609
+ const parsed = Host.parseUrl(local, "http");
610
+ protocol = parsed.protocol;
611
+ host = parsed.host;
612
+ port = parsed.port;
613
+ }
614
+ } else if (local) {
615
+ protocol = local.protocol;
616
+ host = local.host;
617
+ port = local.port;
618
+ }
619
+ super({
620
+ protocol: protocol ?? "http",
621
+ host: host ?? "localhost",
622
+ port: port ?? generatePortFromName({ name: appName })
623
+ });
563
624
  }
564
625
  };
565
626
 
@@ -575,7 +636,7 @@ var Application = class {
575
636
  local: new LocalHost({
576
637
  appName: name,
577
638
  localPort: app.development?.localPort,
578
- ...app.development?.local
639
+ local: app.development?.local
579
640
  }),
580
641
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
581
642
  };
@@ -585,6 +646,7 @@ var Application = class {
585
646
  this.fallback = new Host(app.production);
586
647
  }
587
648
  this.projectId = app.projectId ?? app.vercel?.projectId;
649
+ this.packageName = app.packageName;
588
650
  this.overrides = overrides?.environment ? {
589
651
  environment: new Host(overrides.environment)
590
652
  } : void 0;
@@ -750,10 +812,12 @@ var MicrofrontendConfigIsomorphic = class {
750
812
  ].filter(Boolean);
751
813
  }
752
814
  getApplication(name) {
753
- if (this.defaultApplication?.name === name) {
815
+ if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
754
816
  return this.defaultApplication;
755
817
  }
756
- const app = this.childApplications[name];
818
+ const app = this.childApplications[name] || Object.values(this.childApplications).find(
819
+ (child) => child.packageName === name
820
+ );
757
821
  if (!app) {
758
822
  throw new MicrofrontendError(
759
823
  `Could not find microfrontends configuration for application "${name}"`,
@@ -1202,9 +1266,7 @@ var schema_default = {
1202
1266
  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"
1203
1267
  }
1204
1268
  },
1205
- required: [
1206
- "applications"
1207
- ],
1269
+ required: ["applications"],
1208
1270
  additionalProperties: false
1209
1271
  },
1210
1272
  Options: {
@@ -1257,7 +1319,7 @@ var schema_default = {
1257
1319
  $ref: "#/definitions/Application"
1258
1320
  },
1259
1321
  propertyNames: {
1260
- description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1322
+ 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."
1261
1323
  }
1262
1324
  },
1263
1325
  Application: {
@@ -1279,7 +1341,12 @@ var schema_default = {
1279
1341
  },
1280
1342
  projectId: {
1281
1343
  type: "string",
1282
- description: "Vercel project ID"
1344
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1345
+ deprecated: "Instead, the application id should match the Vercel project name."
1346
+ },
1347
+ packageName: {
1348
+ type: "string",
1349
+ 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`."
1283
1350
  },
1284
1351
  production: {
1285
1352
  $ref: "#/definitions/HostConfig",
@@ -1299,9 +1366,7 @@ var schema_default = {
1299
1366
  description: "Vercel project ID"
1300
1367
  }
1301
1368
  },
1302
- required: [
1303
- "projectId"
1304
- ],
1369
+ required: ["projectId"],
1305
1370
  additionalProperties: false
1306
1371
  },
1307
1372
  HostConfig: {
@@ -1309,10 +1374,7 @@ var schema_default = {
1309
1374
  properties: {
1310
1375
  protocol: {
1311
1376
  type: "string",
1312
- enum: [
1313
- "http",
1314
- "https"
1315
- ],
1377
+ enum: ["http", "https"],
1316
1378
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1317
1379
  },
1318
1380
  host: {
@@ -1324,21 +1386,30 @@ var schema_default = {
1324
1386
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1325
1387
  }
1326
1388
  },
1327
- required: [
1328
- "host"
1329
- ],
1389
+ required: ["host"],
1330
1390
  additionalProperties: false
1331
1391
  },
1332
1392
  Development: {
1333
1393
  type: "object",
1334
1394
  properties: {
1335
1395
  local: {
1336
- $ref: "#/definitions/LocalHostConfig",
1337
- deprecated: "This is being replaced by the `localPort` field below."
1396
+ anyOf: [
1397
+ {
1398
+ type: "number"
1399
+ },
1400
+ {
1401
+ type: "string"
1402
+ },
1403
+ {
1404
+ $ref: "#/definitions/LocalHostConfig"
1405
+ }
1406
+ ],
1407
+ 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."
1338
1408
  },
1339
1409
  localPort: {
1340
1410
  type: "number",
1341
- 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."
1411
+ 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.",
1412
+ deprecated: "Please set the port with the 'local' field instead."
1342
1413
  },
1343
1414
  fallback: {
1344
1415
  anyOf: [
@@ -1349,7 +1420,7 @@ var schema_default = {
1349
1420
  type: "string"
1350
1421
  }
1351
1422
  ],
1352
- 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."
1423
+ 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."
1353
1424
  },
1354
1425
  task: {
1355
1426
  type: "string",
@@ -1368,10 +1439,7 @@ var schema_default = {
1368
1439
  },
1369
1440
  protocol: {
1370
1441
  type: "string",
1371
- enum: [
1372
- "http",
1373
- "https"
1374
- ],
1442
+ enum: ["http", "https"],
1375
1443
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1376
1444
  },
1377
1445
  port: {
@@ -1389,7 +1457,12 @@ var schema_default = {
1389
1457
  },
1390
1458
  projectId: {
1391
1459
  type: "string",
1392
- description: "Vercel project ID"
1460
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1461
+ deprecated: "Instead, the application id should match the Vercel project name."
1462
+ },
1463
+ packageName: {
1464
+ type: "string",
1465
+ 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`."
1393
1466
  },
1394
1467
  production: {
1395
1468
  $ref: "#/definitions/HostConfig",
@@ -1403,9 +1476,7 @@ var schema_default = {
1403
1476
  description: "Groups of path expressions that are routed to this application."
1404
1477
  }
1405
1478
  },
1406
- required: [
1407
- "routing"
1408
- ],
1479
+ required: ["routing"],
1409
1480
  additionalProperties: false
1410
1481
  },
1411
1482
  Routing: {
@@ -1432,9 +1503,7 @@ var schema_default = {
1432
1503
  }
1433
1504
  }
1434
1505
  },
1435
- required: [
1436
- "paths"
1437
- ],
1506
+ required: ["paths"],
1438
1507
  additionalProperties: false
1439
1508
  },
1440
1509
  ChildConfig: {
@@ -1455,9 +1524,7 @@ var schema_default = {
1455
1524
  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."
1456
1525
  }
1457
1526
  },
1458
- required: [
1459
- "partOf"
1460
- ],
1527
+ required: ["partOf"],
1461
1528
  additionalProperties: false
1462
1529
  }
1463
1530
  }