@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
@@ -1,6 +1,6 @@
1
- import { H as HostConfig, L as LocalHostConfig, D as DefaultApplication$1, P as PathGroup, b as ChildApplication$1, c as Application$1, C as Config } from './index-2f78c0ca.js';
2
- import { C as ClientConfig } from './types-4ef2bddb.js';
3
- import { A as ApplicationOverrideConfig, O as OverridesConfig } from './types-b6d38aea.js';
1
+ import { H as HostConfig, L as LocalHostConfig, D as DefaultApplication$1, P as PathGroup, b as ChildApplication$1, A as Application$1, C as Config } from './types-6ee19ccc.js';
2
+ import { C as ClientConfig } from './types-74e3336c.js';
3
+ import { A as ApplicationOverrideConfig, O as OverridesConfig } from './types-73527280.js';
4
4
 
5
5
  interface MicrofrontendConfigClientOptions {
6
6
  removeFlaggedPaths?: boolean;
@@ -29,7 +29,11 @@ declare class Host {
29
29
  port?: number;
30
30
  local: boolean | undefined;
31
31
  constructor(hostConfig: HostConfig | string, options?: HostOptions);
32
- private static parseUrl;
32
+ protected static parseUrl(url: string, defaultProtocol?: string): {
33
+ protocol: Host['protocol'];
34
+ host: string;
35
+ port?: number;
36
+ };
33
37
  private static getMicrofrontendsError;
34
38
  isLocal(): boolean;
35
39
  toString(): string;
@@ -39,9 +43,10 @@ declare class Host {
39
43
  * A Host subclass with defaults for locally running applications
40
44
  */
41
45
  declare class LocalHost extends Host {
42
- constructor({ appName, localPort, ...hostConfig }: LocalHostConfig & {
46
+ constructor({ appName, localPort, local, }: {
43
47
  appName: string;
44
48
  localPort?: number;
49
+ local?: string | number | LocalHostConfig;
45
50
  });
46
51
  }
47
52
 
@@ -54,6 +59,7 @@ declare class Application {
54
59
  };
55
60
  fallback?: Host;
56
61
  projectId?: string;
62
+ packageName?: string;
57
63
  overrides?: {
58
64
  environment?: Host;
59
65
  };
@@ -312,10 +312,13 @@ var validateConfigPaths = (applicationConfigsById) => {
312
312
  }
313
313
  }
314
314
  if (errors.length) {
315
- throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
316
- type: "config",
317
- subtype: "conflicting_paths"
318
- });
315
+ throw new MicrofrontendError(
316
+ `Invalid paths: ${errors.join(", ")}. See supported paths in the documentation https://vercel.com/docs/microfrontends/path-routing#supported-path-expressions.`,
317
+ {
318
+ type: "config",
319
+ subtype: "conflicting_paths"
320
+ }
321
+ );
319
322
  }
320
323
  };
321
324
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
@@ -430,9 +433,40 @@ var validateDeprecatedFields = (config) => {
430
433
  `Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
431
434
  );
432
435
  }
433
- if (application.development?.local) {
436
+ if (application.development?.localPort) {
434
437
  errors.push(
435
- `Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
438
+ `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
439
+ );
440
+ }
441
+ if (application.development?.fallback && typeof application.development.fallback !== "string") {
442
+ const fallback = application.development.fallback;
443
+ let asString = fallback.host;
444
+ if (fallback.protocol) {
445
+ asString = `${fallback.protocol}://${asString}`;
446
+ }
447
+ if (fallback.port) {
448
+ asString = `${asString}:${fallback.port}`;
449
+ }
450
+ errors.push(
451
+ `Application '${applicationId}' requires a string (not an object) for the 'development.fallback' field. Please set 'development.fallback' to '${asString}'.`
452
+ );
453
+ }
454
+ if (application.development?.local && typeof application.development.local !== "string" && typeof application.development.local !== "number") {
455
+ const local = application.development.local;
456
+ let asString;
457
+ if (local.port && !local.protocol && !local.host) {
458
+ asString = String(local.port);
459
+ } else {
460
+ asString = local.host ?? "localhost";
461
+ if (local.protocol) {
462
+ asString = `${local.protocol}://${asString}`;
463
+ }
464
+ if (local.port) {
465
+ asString = `${asString}:${local.port}`;
466
+ }
467
+ }
468
+ errors.push(
469
+ `Application '${applicationId}' requires a string or number (not an object) for the 'development.local' field. Please set 'development.local' to '${asString}'.`
436
470
  );
437
471
  }
438
472
  }
@@ -496,10 +530,10 @@ var Host = class {
496
530
  }
497
531
  this.local = options?.isLocal;
498
532
  }
499
- static parseUrl(url) {
533
+ static parseUrl(url, defaultProtocol = "https") {
500
534
  let hostToParse = url;
501
535
  if (!/^https?:\/\//.exec(hostToParse)) {
502
- hostToParse = `https://${hostToParse}`;
536
+ hostToParse = `${defaultProtocol}://${hostToParse}`;
503
537
  }
504
538
  const parsed = new URL(hostToParse);
505
539
  if (!parsed.hostname) {
@@ -552,12 +586,39 @@ var LocalHost = class extends Host {
552
586
  constructor({
553
587
  appName,
554
588
  localPort,
555
- ...hostConfig
589
+ local
556
590
  }) {
557
- const host = hostConfig.host ?? "localhost";
558
- const port = localPort ?? hostConfig.port ?? generatePortFromName({ name: appName });
559
- const protocol = hostConfig.protocol ?? "http";
560
- super({ protocol, host, port });
591
+ if (localPort && local) {
592
+ throw new Error(
593
+ `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.`
594
+ );
595
+ }
596
+ let protocol;
597
+ let host;
598
+ let port;
599
+ if (localPort) {
600
+ port = localPort;
601
+ } else if (typeof local === "number") {
602
+ port = local;
603
+ } else if (typeof local === "string") {
604
+ if (/^\d+$/.test(local)) {
605
+ port = Number.parseInt(local);
606
+ } else {
607
+ const parsed = Host.parseUrl(local, "http");
608
+ protocol = parsed.protocol;
609
+ host = parsed.host;
610
+ port = parsed.port;
611
+ }
612
+ } else if (local) {
613
+ protocol = local.protocol;
614
+ host = local.host;
615
+ port = local.port;
616
+ }
617
+ super({
618
+ protocol: protocol ?? "http",
619
+ host: host ?? "localhost",
620
+ port: port ?? generatePortFromName({ name: appName })
621
+ });
561
622
  }
562
623
  };
563
624
 
@@ -573,7 +634,7 @@ var Application = class {
573
634
  local: new LocalHost({
574
635
  appName: name,
575
636
  localPort: app.development?.localPort,
576
- ...app.development?.local
637
+ local: app.development?.local
577
638
  }),
578
639
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
579
640
  };
@@ -583,6 +644,7 @@ var Application = class {
583
644
  this.fallback = new Host(app.production);
584
645
  }
585
646
  this.projectId = app.projectId ?? app.vercel?.projectId;
647
+ this.packageName = app.packageName;
586
648
  this.overrides = overrides?.environment ? {
587
649
  environment: new Host(overrides.environment)
588
650
  } : void 0;
@@ -748,10 +810,12 @@ var MicrofrontendConfigIsomorphic = class {
748
810
  ].filter(Boolean);
749
811
  }
750
812
  getApplication(name) {
751
- if (this.defaultApplication?.name === name) {
813
+ if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
752
814
  return this.defaultApplication;
753
815
  }
754
- const app = this.childApplications[name];
816
+ const app = this.childApplications[name] || Object.values(this.childApplications).find(
817
+ (child) => child.packageName === name
818
+ );
755
819
  if (!app) {
756
820
  throw new MicrofrontendError(
757
821
  `Could not find microfrontends configuration for application "${name}"`,
@@ -1253,7 +1317,7 @@ var schema_default = {
1253
1317
  $ref: "#/definitions/Application"
1254
1318
  },
1255
1319
  propertyNames: {
1256
- description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1320
+ 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."
1257
1321
  }
1258
1322
  },
1259
1323
  Application: {
@@ -1275,7 +1339,12 @@ var schema_default = {
1275
1339
  },
1276
1340
  projectId: {
1277
1341
  type: "string",
1278
- description: "Vercel project ID"
1342
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1343
+ deprecated: "Instead, the application id should match the Vercel project name."
1344
+ },
1345
+ packageName: {
1346
+ type: "string",
1347
+ 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`."
1279
1348
  },
1280
1349
  production: {
1281
1350
  $ref: "#/definitions/HostConfig",
@@ -1322,12 +1391,23 @@ var schema_default = {
1322
1391
  type: "object",
1323
1392
  properties: {
1324
1393
  local: {
1325
- $ref: "#/definitions/LocalHostConfig",
1326
- deprecated: "This is being replaced by the `localPort` field below."
1394
+ anyOf: [
1395
+ {
1396
+ type: "number"
1397
+ },
1398
+ {
1399
+ type: "string"
1400
+ },
1401
+ {
1402
+ $ref: "#/definitions/LocalHostConfig"
1403
+ }
1404
+ ],
1405
+ 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."
1327
1406
  },
1328
1407
  localPort: {
1329
1408
  type: "number",
1330
- 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."
1409
+ 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.",
1410
+ deprecated: "Please set the port with the 'local' field instead."
1331
1411
  },
1332
1412
  fallback: {
1333
1413
  anyOf: [
@@ -1338,7 +1418,7 @@ var schema_default = {
1338
1418
  type: "string"
1339
1419
  }
1340
1420
  ],
1341
- 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."
1421
+ 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."
1342
1422
  },
1343
1423
  task: {
1344
1424
  type: "string",
@@ -1375,7 +1455,12 @@ var schema_default = {
1375
1455
  },
1376
1456
  projectId: {
1377
1457
  type: "string",
1378
- description: "Vercel project ID"
1458
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1459
+ deprecated: "Instead, the application id should match the Vercel project name."
1460
+ },
1461
+ packageName: {
1462
+ type: "string",
1463
+ 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`."
1379
1464
  },
1380
1465
  production: {
1381
1466
  $ref: "#/definitions/HostConfig",