@vercel/microfrontends 1.1.0 → 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 +120 -27
  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 +108 -23
  8. package/dist/experimental/sveltekit.cjs.map +1 -1
  9. package/dist/experimental/sveltekit.js +108 -23
  10. package/dist/experimental/sveltekit.js.map +1 -1
  11. package/dist/experimental/vite.cjs +108 -23
  12. package/dist/experimental/vite.cjs.map +1 -1
  13. package/dist/experimental/vite.js +108 -23
  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 +108 -23
  17. package/dist/microfrontends/server.cjs.map +1 -1
  18. package/dist/microfrontends/server.d.ts +4 -4
  19. package/dist/microfrontends/server.js +108 -23
  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 +125 -30
  27. package/dist/next/config.cjs.map +1 -1
  28. package/dist/next/config.js +125 -30
  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 +108 -23
  50. package/dist/utils/mfe-port.cjs.map +1 -1
  51. package/dist/utils/mfe-port.js +108 -23
  52. package/dist/utils/mfe-port.js.map +1 -1
  53. package/dist/validation.cjs +28 -7
  54. package/dist/validation.cjs.map +1 -1
  55. package/dist/validation.d.ts +1 -1
  56. package/dist/validation.js +28 -7
  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) {
436
439
  errors.push(
437
- `Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
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
+ }
470
+ errors.push(
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}"`,
@@ -1255,7 +1319,7 @@ var schema_default = {
1255
1319
  $ref: "#/definitions/Application"
1256
1320
  },
1257
1321
  propertyNames: {
1258
- 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."
1259
1323
  }
1260
1324
  },
1261
1325
  Application: {
@@ -1277,7 +1341,12 @@ var schema_default = {
1277
1341
  },
1278
1342
  projectId: {
1279
1343
  type: "string",
1280
- 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`."
1281
1350
  },
1282
1351
  production: {
1283
1352
  $ref: "#/definitions/HostConfig",
@@ -1324,12 +1393,23 @@ var schema_default = {
1324
1393
  type: "object",
1325
1394
  properties: {
1326
1395
  local: {
1327
- $ref: "#/definitions/LocalHostConfig",
1328
- 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."
1329
1408
  },
1330
1409
  localPort: {
1331
1410
  type: "number",
1332
- 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."
1333
1413
  },
1334
1414
  fallback: {
1335
1415
  anyOf: [
@@ -1340,7 +1420,7 @@ var schema_default = {
1340
1420
  type: "string"
1341
1421
  }
1342
1422
  ],
1343
- 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."
1344
1424
  },
1345
1425
  task: {
1346
1426
  type: "string",
@@ -1377,7 +1457,12 @@ var schema_default = {
1377
1457
  },
1378
1458
  projectId: {
1379
1459
  type: "string",
1380
- 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`."
1381
1466
  },
1382
1467
  production: {
1383
1468
  $ref: "#/definitions/HostConfig",