@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
@@ -23,7 +23,11 @@ interface ChildConfig extends CommonConfig {
23
23
  type ApplicationRouting = Record<ApplicationId, Application>;
24
24
  /**
25
25
  * The unique identifier for a Microfrontend Application.
26
- * Must match the `name` field of the application's `package.json`.
26
+ *
27
+ * Must match the Vercel project name.
28
+ *
29
+ * Note: If this name does not also match the name used to run the application, (e.g.
30
+ * the `name` from the `package.json`), then the `packageName` field should be set.
27
31
  */
28
32
  type ApplicationId = string;
29
33
  type Routing = PathGroup[];
@@ -67,22 +71,39 @@ type LocalHostConfig = Omit<HostConfig, 'host'> & {
67
71
  };
68
72
  interface Development {
69
73
  /**
70
- * @deprecated This is being replaced by the `localPort` field below.
74
+ * A local port number or host string that this application runs on when it is running locally.
75
+ * If passing a string, include the protocol (optional), host (required) and port (optional).
76
+ * For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTP. If
77
+ * omitted, the port defaults to a unique, but stable (based on the application name) number.
78
+ *
79
+ * Examples of valid values:
80
+ * - 8080
81
+ * - my.localhost.me
82
+ * - my.localhost.me:8080
83
+ * - https://my.localhost.me
84
+ * - https://my.localhost.me:8080
85
+ *
86
+ * Passing a LocalHostConfig is deprecated and will go away soon, please pass a number or string.
71
87
  */
72
- local?: LocalHostConfig;
88
+ local?: number | string | LocalHostConfig;
73
89
  /**
74
90
  * The local port number that this application runs on when it is running locally.
75
- * Common values include `80` for HTTP and `443` for HTTPS.
91
+ * Common values include `80` for HTTP and `443` for HTTPS. If omitted, the port
92
+ * defaults to a unique, but stable (based on the application name) number.
93
+ *
94
+ * @deprecated Please set the port with the 'local' field instead.
76
95
  */
77
96
  localPort?: number;
78
97
  /**
79
- * Fallback for local development, could be a host config that points to any environment.
80
- * If this is not provided, or the application is not running - requests to the application
81
- * in local development will error.
98
+ * Fallback for local development, could point to any environment. If this is not provided,
99
+ * or the application is not running - requests to the application in local development will
100
+ * error.
82
101
  *
83
102
  * If passing a string, include the protocol (optional), host (required) and port (optional).
84
103
  * For example: `https://this.ismyhost:8080`. If omitted, the protocol defaults to HTTPS. If
85
104
  * omitted, the port defaults to `80` for HTTP and `443` for HTTPS.
105
+ *
106
+ * Passing a HostConfig is deprecated and will go away soon, please pass a string.
86
107
  */
87
108
  fallback?: HostConfig | string;
88
109
  /**
@@ -99,9 +120,19 @@ interface CommonApplication {
99
120
  */
100
121
  vercel?: Vercel;
101
122
  /**
102
- * Vercel project ID
123
+ * Vercel project ID, only required if the application name / id is different to the Vercel project name.
124
+ *
125
+ * @deprecated Instead, the application id should match the Vercel project name.
103
126
  */
104
127
  projectId?: string;
128
+ /**
129
+ * The name used to run the application, e.g. the `name` field in the `package.json`.
130
+ *
131
+ * This is used by the local proxy to map the application config to the locally running app.
132
+ *
133
+ * This is only necessary when the application name does not match the `name` used in `package.json`.
134
+ */
135
+ packageName?: string;
105
136
  /**
106
137
  * @deprecated This is a duplicate of the `development.fallback` field and this will be removed soon.
107
138
  */
@@ -166,4 +197,4 @@ interface LocalProxyOptions {
166
197
  port?: number;
167
198
  }
168
199
 
169
- export { ApplicationId as A, Config as C, DefaultApplication as D, HostConfig as H, LocalHostConfig as L, MainConfig as M, PathGroup as P, ChildConfig as a, ChildApplication as b, Application as c };
200
+ export { Application as A, Config as C, DefaultApplication as D, HostConfig as H, LocalHostConfig as L, MainConfig as M, PathGroup as P, ChildConfig as a, ChildApplication as b, ApplicationId as c };
@@ -1,4 +1,4 @@
1
- import { H as HostConfig, A as ApplicationId } from './index-2f78c0ca.js';
1
+ import { H as HostConfig, c as ApplicationId } from './types-6ee19ccc.js';
2
2
 
3
3
  interface ApplicationOverrideConfig {
4
4
  environment?: HostConfig;
@@ -1,4 +1,4 @@
1
- import { A as ApplicationId, P as PathGroup } from './index-2f78c0ca.js';
1
+ import { c as ApplicationId, P as PathGroup } from './types-6ee19ccc.js';
2
2
 
3
3
  interface ClientApplication {
4
4
  routing?: PathGroup[];
@@ -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) {
441
+ errors.push(
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
+ }
438
472
  errors.push(
439
- `Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
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}"`,
@@ -1204,9 +1268,7 @@ var schema_default = {
1204
1268
  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"
1205
1269
  }
1206
1270
  },
1207
- required: [
1208
- "applications"
1209
- ],
1271
+ required: ["applications"],
1210
1272
  additionalProperties: false
1211
1273
  },
1212
1274
  Options: {
@@ -1259,7 +1321,7 @@ var schema_default = {
1259
1321
  $ref: "#/definitions/Application"
1260
1322
  },
1261
1323
  propertyNames: {
1262
- 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."
1263
1325
  }
1264
1326
  },
1265
1327
  Application: {
@@ -1281,7 +1343,12 @@ var schema_default = {
1281
1343
  },
1282
1344
  projectId: {
1283
1345
  type: "string",
1284
- 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`."
1285
1352
  },
1286
1353
  production: {
1287
1354
  $ref: "#/definitions/HostConfig",
@@ -1301,9 +1368,7 @@ var schema_default = {
1301
1368
  description: "Vercel project ID"
1302
1369
  }
1303
1370
  },
1304
- required: [
1305
- "projectId"
1306
- ],
1371
+ required: ["projectId"],
1307
1372
  additionalProperties: false
1308
1373
  },
1309
1374
  HostConfig: {
@@ -1311,10 +1376,7 @@ var schema_default = {
1311
1376
  properties: {
1312
1377
  protocol: {
1313
1378
  type: "string",
1314
- enum: [
1315
- "http",
1316
- "https"
1317
- ],
1379
+ enum: ["http", "https"],
1318
1380
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1319
1381
  },
1320
1382
  host: {
@@ -1326,21 +1388,30 @@ var schema_default = {
1326
1388
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1327
1389
  }
1328
1390
  },
1329
- required: [
1330
- "host"
1331
- ],
1391
+ required: ["host"],
1332
1392
  additionalProperties: false
1333
1393
  },
1334
1394
  Development: {
1335
1395
  type: "object",
1336
1396
  properties: {
1337
1397
  local: {
1338
- $ref: "#/definitions/LocalHostConfig",
1339
- 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."
1340
1410
  },
1341
1411
  localPort: {
1342
1412
  type: "number",
1343
- 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."
1344
1415
  },
1345
1416
  fallback: {
1346
1417
  anyOf: [
@@ -1351,7 +1422,7 @@ var schema_default = {
1351
1422
  type: "string"
1352
1423
  }
1353
1424
  ],
1354
- 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."
1355
1426
  },
1356
1427
  task: {
1357
1428
  type: "string",
@@ -1370,10 +1441,7 @@ var schema_default = {
1370
1441
  },
1371
1442
  protocol: {
1372
1443
  type: "string",
1373
- enum: [
1374
- "http",
1375
- "https"
1376
- ],
1444
+ enum: ["http", "https"],
1377
1445
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1378
1446
  },
1379
1447
  port: {
@@ -1391,7 +1459,12 @@ var schema_default = {
1391
1459
  },
1392
1460
  projectId: {
1393
1461
  type: "string",
1394
- 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`."
1395
1468
  },
1396
1469
  production: {
1397
1470
  $ref: "#/definitions/HostConfig",
@@ -1405,9 +1478,7 @@ var schema_default = {
1405
1478
  description: "Groups of path expressions that are routed to this application."
1406
1479
  }
1407
1480
  },
1408
- required: [
1409
- "routing"
1410
- ],
1481
+ required: ["routing"],
1411
1482
  additionalProperties: false
1412
1483
  },
1413
1484
  Routing: {
@@ -1434,9 +1505,7 @@ var schema_default = {
1434
1505
  }
1435
1506
  }
1436
1507
  },
1437
- required: [
1438
- "paths"
1439
- ],
1508
+ required: ["paths"],
1440
1509
  additionalProperties: false
1441
1510
  },
1442
1511
  ChildConfig: {
@@ -1457,9 +1526,7 @@ var schema_default = {
1457
1526
  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."
1458
1527
  }
1459
1528
  },
1460
- required: [
1461
- "partOf"
1462
- ],
1529
+ required: ["partOf"],
1463
1530
  additionalProperties: false
1464
1531
  }
1465
1532
  }