@vercel/microfrontends 1.1.0 → 1.1.1-canary.1

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 (63) 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.cjs +9 -0
  31. package/dist/next/endpoints.cjs.map +1 -1
  32. package/dist/next/endpoints.d.ts +36 -4
  33. package/dist/next/endpoints.js +8 -0
  34. package/dist/next/endpoints.js.map +1 -1
  35. package/dist/next/middleware.cjs +90 -16
  36. package/dist/next/middleware.cjs.map +1 -1
  37. package/dist/next/middleware.js +90 -16
  38. package/dist/next/middleware.js.map +1 -1
  39. package/dist/next/testing.cjs +84 -21
  40. package/dist/next/testing.cjs.map +1 -1
  41. package/dist/next/testing.d.ts +4 -4
  42. package/dist/next/testing.js +84 -21
  43. package/dist/next/testing.js.map +1 -1
  44. package/dist/overrides.d.ts +3 -3
  45. package/dist/schema.cjs +23 -0
  46. package/dist/schema.cjs.map +1 -1
  47. package/dist/schema.d.ts +7 -1
  48. package/dist/schema.js +13 -0
  49. package/dist/schema.js.map +1 -1
  50. package/dist/{index-2f78c0ca.d.ts → types-6ee19ccc.d.ts} +40 -9
  51. package/dist/{types-b6d38aea.d.ts → types-73527280.d.ts} +1 -1
  52. package/dist/{types-4ef2bddb.d.ts → types-74e3336c.d.ts} +1 -1
  53. package/dist/utils/mfe-port.cjs +108 -23
  54. package/dist/utils/mfe-port.cjs.map +1 -1
  55. package/dist/utils/mfe-port.js +108 -23
  56. package/dist/utils/mfe-port.js.map +1 -1
  57. package/dist/validation.cjs +28 -7
  58. package/dist/validation.cjs.map +1 -1
  59. package/dist/validation.d.ts +1 -1
  60. package/dist/validation.js +28 -7
  61. package/dist/validation.js.map +1 -1
  62. package/package.json +1 -1
  63. package/schema/schema.json +28 -7
@@ -316,10 +316,13 @@ var validateConfigPaths = (applicationConfigsById) => {
316
316
  }
317
317
  }
318
318
  if (errors.length) {
319
- throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
320
- type: "config",
321
- subtype: "conflicting_paths"
322
- });
319
+ throw new MicrofrontendError(
320
+ `Invalid paths: ${errors.join(", ")}. See supported paths in the documentation https://vercel.com/docs/microfrontends/path-routing#supported-path-expressions.`,
321
+ {
322
+ type: "config",
323
+ subtype: "conflicting_paths"
324
+ }
325
+ );
323
326
  }
324
327
  };
325
328
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
@@ -434,9 +437,40 @@ var validateDeprecatedFields = (config) => {
434
437
  `Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
435
438
  );
436
439
  }
437
- if (application.development?.local) {
440
+ if (application.development?.localPort) {
438
441
  errors.push(
439
- `Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
442
+ `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
443
+ );
444
+ }
445
+ if (application.development?.fallback && typeof application.development.fallback !== "string") {
446
+ const fallback = application.development.fallback;
447
+ let asString = fallback.host;
448
+ if (fallback.protocol) {
449
+ asString = `${fallback.protocol}://${asString}`;
450
+ }
451
+ if (fallback.port) {
452
+ asString = `${asString}:${fallback.port}`;
453
+ }
454
+ errors.push(
455
+ `Application '${applicationId}' requires a string (not an object) for the 'development.fallback' field. Please set 'development.fallback' to '${asString}'.`
456
+ );
457
+ }
458
+ if (application.development?.local && typeof application.development.local !== "string" && typeof application.development.local !== "number") {
459
+ const local = application.development.local;
460
+ let asString;
461
+ if (local.port && !local.protocol && !local.host) {
462
+ asString = String(local.port);
463
+ } else {
464
+ asString = local.host ?? "localhost";
465
+ if (local.protocol) {
466
+ asString = `${local.protocol}://${asString}`;
467
+ }
468
+ if (local.port) {
469
+ asString = `${asString}:${local.port}`;
470
+ }
471
+ }
472
+ errors.push(
473
+ `Application '${applicationId}' requires a string or number (not an object) for the 'development.local' field. Please set 'development.local' to '${asString}'.`
440
474
  );
441
475
  }
442
476
  }
@@ -500,10 +534,10 @@ var Host = class {
500
534
  }
501
535
  this.local = options?.isLocal;
502
536
  }
503
- static parseUrl(url) {
537
+ static parseUrl(url, defaultProtocol = "https") {
504
538
  let hostToParse = url;
505
539
  if (!/^https?:\/\//.exec(hostToParse)) {
506
- hostToParse = `https://${hostToParse}`;
540
+ hostToParse = `${defaultProtocol}://${hostToParse}`;
507
541
  }
508
542
  const parsed = new URL(hostToParse);
509
543
  if (!parsed.hostname) {
@@ -556,12 +590,39 @@ var LocalHost = class extends Host {
556
590
  constructor({
557
591
  appName,
558
592
  localPort,
559
- ...hostConfig
593
+ local
560
594
  }) {
561
- const host = hostConfig.host ?? "localhost";
562
- const port = localPort ?? hostConfig.port ?? generatePortFromName({ name: appName });
563
- const protocol = hostConfig.protocol ?? "http";
564
- super({ protocol, host, port });
595
+ if (localPort && local) {
596
+ throw new Error(
597
+ `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.`
598
+ );
599
+ }
600
+ let protocol;
601
+ let host;
602
+ let port;
603
+ if (localPort) {
604
+ port = localPort;
605
+ } else if (typeof local === "number") {
606
+ port = local;
607
+ } else if (typeof local === "string") {
608
+ if (/^\d+$/.test(local)) {
609
+ port = Number.parseInt(local);
610
+ } else {
611
+ const parsed = Host.parseUrl(local, "http");
612
+ protocol = parsed.protocol;
613
+ host = parsed.host;
614
+ port = parsed.port;
615
+ }
616
+ } else if (local) {
617
+ protocol = local.protocol;
618
+ host = local.host;
619
+ port = local.port;
620
+ }
621
+ super({
622
+ protocol: protocol ?? "http",
623
+ host: host ?? "localhost",
624
+ port: port ?? generatePortFromName({ name: appName })
625
+ });
565
626
  }
566
627
  };
567
628
 
@@ -577,7 +638,7 @@ var Application = class {
577
638
  local: new LocalHost({
578
639
  appName: name,
579
640
  localPort: app.development?.localPort,
580
- ...app.development?.local
641
+ local: app.development?.local
581
642
  }),
582
643
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
583
644
  };
@@ -587,6 +648,7 @@ var Application = class {
587
648
  this.fallback = new Host(app.production);
588
649
  }
589
650
  this.projectId = app.projectId ?? app.vercel?.projectId;
651
+ this.packageName = app.packageName;
590
652
  this.overrides = overrides?.environment ? {
591
653
  environment: new Host(overrides.environment)
592
654
  } : void 0;
@@ -752,10 +814,12 @@ var MicrofrontendConfigIsomorphic = class {
752
814
  ].filter(Boolean);
753
815
  }
754
816
  getApplication(name) {
755
- if (this.defaultApplication?.name === name) {
817
+ if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
756
818
  return this.defaultApplication;
757
819
  }
758
- const app = this.childApplications[name];
820
+ const app = this.childApplications[name] || Object.values(this.childApplications).find(
821
+ (child) => child.packageName === name
822
+ );
759
823
  if (!app) {
760
824
  throw new MicrofrontendError(
761
825
  `Could not find microfrontends configuration for application "${name}"`,
@@ -1257,7 +1321,7 @@ var schema_default = {
1257
1321
  $ref: "#/definitions/Application"
1258
1322
  },
1259
1323
  propertyNames: {
1260
- description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1324
+ 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
1325
  }
1262
1326
  },
1263
1327
  Application: {
@@ -1279,7 +1343,12 @@ var schema_default = {
1279
1343
  },
1280
1344
  projectId: {
1281
1345
  type: "string",
1282
- description: "Vercel project ID"
1346
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1347
+ deprecated: "Instead, the application id should match the Vercel project name."
1348
+ },
1349
+ packageName: {
1350
+ type: "string",
1351
+ 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
1352
  },
1284
1353
  production: {
1285
1354
  $ref: "#/definitions/HostConfig",
@@ -1326,12 +1395,23 @@ var schema_default = {
1326
1395
  type: "object",
1327
1396
  properties: {
1328
1397
  local: {
1329
- $ref: "#/definitions/LocalHostConfig",
1330
- deprecated: "This is being replaced by the `localPort` field below."
1398
+ anyOf: [
1399
+ {
1400
+ type: "number"
1401
+ },
1402
+ {
1403
+ type: "string"
1404
+ },
1405
+ {
1406
+ $ref: "#/definitions/LocalHostConfig"
1407
+ }
1408
+ ],
1409
+ 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."
1331
1410
  },
1332
1411
  localPort: {
1333
1412
  type: "number",
1334
- 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."
1413
+ 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.",
1414
+ deprecated: "Please set the port with the 'local' field instead."
1335
1415
  },
1336
1416
  fallback: {
1337
1417
  anyOf: [
@@ -1342,7 +1422,7 @@ var schema_default = {
1342
1422
  type: "string"
1343
1423
  }
1344
1424
  ],
1345
- 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."
1425
+ 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."
1346
1426
  },
1347
1427
  task: {
1348
1428
  type: "string",
@@ -1379,7 +1459,12 @@ var schema_default = {
1379
1459
  },
1380
1460
  projectId: {
1381
1461
  type: "string",
1382
- description: "Vercel project ID"
1462
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1463
+ deprecated: "Instead, the application id should match the Vercel project name."
1464
+ },
1465
+ packageName: {
1466
+ type: "string",
1467
+ 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`."
1383
1468
  },
1384
1469
  production: {
1385
1470
  $ref: "#/definitions/HostConfig",