@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
@@ -282,10 +282,13 @@ var validateConfigPaths = (applicationConfigsById) => {
282
282
  }
283
283
  }
284
284
  if (errors.length) {
285
- throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
286
- type: "config",
287
- subtype: "conflicting_paths"
288
- });
285
+ throw new MicrofrontendError(
286
+ `Invalid paths: ${errors.join(", ")}. See supported paths in the documentation https://vercel.com/docs/microfrontends/path-routing#supported-path-expressions.`,
287
+ {
288
+ type: "config",
289
+ subtype: "conflicting_paths"
290
+ }
291
+ );
289
292
  }
290
293
  };
291
294
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
@@ -400,9 +403,40 @@ var validateDeprecatedFields = (config) => {
400
403
  `Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
401
404
  );
402
405
  }
403
- if (application.development?.local) {
406
+ if (application.development?.localPort) {
404
407
  errors.push(
405
- `Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
408
+ `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
409
+ );
410
+ }
411
+ if (application.development?.fallback && typeof application.development.fallback !== "string") {
412
+ const fallback = application.development.fallback;
413
+ let asString = fallback.host;
414
+ if (fallback.protocol) {
415
+ asString = `${fallback.protocol}://${asString}`;
416
+ }
417
+ if (fallback.port) {
418
+ asString = `${asString}:${fallback.port}`;
419
+ }
420
+ errors.push(
421
+ `Application '${applicationId}' requires a string (not an object) for the 'development.fallback' field. Please set 'development.fallback' to '${asString}'.`
422
+ );
423
+ }
424
+ if (application.development?.local && typeof application.development.local !== "string" && typeof application.development.local !== "number") {
425
+ const local = application.development.local;
426
+ let asString;
427
+ if (local.port && !local.protocol && !local.host) {
428
+ asString = String(local.port);
429
+ } else {
430
+ asString = local.host ?? "localhost";
431
+ if (local.protocol) {
432
+ asString = `${local.protocol}://${asString}`;
433
+ }
434
+ if (local.port) {
435
+ asString = `${asString}:${local.port}`;
436
+ }
437
+ }
438
+ errors.push(
439
+ `Application '${applicationId}' requires a string or number (not an object) for the 'development.local' field. Please set 'development.local' to '${asString}'.`
406
440
  );
407
441
  }
408
442
  }
@@ -466,10 +500,10 @@ var Host = class {
466
500
  }
467
501
  this.local = options?.isLocal;
468
502
  }
469
- static parseUrl(url) {
503
+ static parseUrl(url, defaultProtocol = "https") {
470
504
  let hostToParse = url;
471
505
  if (!/^https?:\/\//.exec(hostToParse)) {
472
- hostToParse = `https://${hostToParse}`;
506
+ hostToParse = `${defaultProtocol}://${hostToParse}`;
473
507
  }
474
508
  const parsed = new URL(hostToParse);
475
509
  if (!parsed.hostname) {
@@ -522,12 +556,39 @@ var LocalHost = class extends Host {
522
556
  constructor({
523
557
  appName,
524
558
  localPort,
525
- ...hostConfig
559
+ local
526
560
  }) {
527
- const host = hostConfig.host ?? "localhost";
528
- const port = localPort ?? hostConfig.port ?? generatePortFromName({ name: appName });
529
- const protocol = hostConfig.protocol ?? "http";
530
- super({ protocol, host, port });
561
+ if (localPort && local) {
562
+ throw new Error(
563
+ `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.`
564
+ );
565
+ }
566
+ let protocol;
567
+ let host;
568
+ let port;
569
+ if (localPort) {
570
+ port = localPort;
571
+ } else if (typeof local === "number") {
572
+ port = local;
573
+ } else if (typeof local === "string") {
574
+ if (/^\d+$/.test(local)) {
575
+ port = Number.parseInt(local);
576
+ } else {
577
+ const parsed = Host.parseUrl(local, "http");
578
+ protocol = parsed.protocol;
579
+ host = parsed.host;
580
+ port = parsed.port;
581
+ }
582
+ } else if (local) {
583
+ protocol = local.protocol;
584
+ host = local.host;
585
+ port = local.port;
586
+ }
587
+ super({
588
+ protocol: protocol ?? "http",
589
+ host: host ?? "localhost",
590
+ port: port ?? generatePortFromName({ name: appName })
591
+ });
531
592
  }
532
593
  };
533
594
 
@@ -543,7 +604,7 @@ var Application = class {
543
604
  local: new LocalHost({
544
605
  appName: name,
545
606
  localPort: app.development?.localPort,
546
- ...app.development?.local
607
+ local: app.development?.local
547
608
  }),
548
609
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
549
610
  };
@@ -553,6 +614,7 @@ var Application = class {
553
614
  this.fallback = new Host(app.production);
554
615
  }
555
616
  this.projectId = app.projectId ?? app.vercel?.projectId;
617
+ this.packageName = app.packageName;
556
618
  this.overrides = overrides?.environment ? {
557
619
  environment: new Host(overrides.environment)
558
620
  } : void 0;
@@ -718,10 +780,12 @@ var MicrofrontendConfigIsomorphic = class {
718
780
  ].filter(Boolean);
719
781
  }
720
782
  getApplication(name) {
721
- if (this.defaultApplication?.name === name) {
783
+ if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
722
784
  return this.defaultApplication;
723
785
  }
724
- const app = this.childApplications[name];
786
+ const app = this.childApplications[name] || Object.values(this.childApplications).find(
787
+ (child) => child.packageName === name
788
+ );
725
789
  if (!app) {
726
790
  throw new MicrofrontendError(
727
791
  `Could not find microfrontends configuration for application "${name}"`,
@@ -1223,7 +1287,7 @@ var schema_default = {
1223
1287
  $ref: "#/definitions/Application"
1224
1288
  },
1225
1289
  propertyNames: {
1226
- description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1290
+ 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."
1227
1291
  }
1228
1292
  },
1229
1293
  Application: {
@@ -1245,7 +1309,12 @@ var schema_default = {
1245
1309
  },
1246
1310
  projectId: {
1247
1311
  type: "string",
1248
- description: "Vercel project ID"
1312
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1313
+ deprecated: "Instead, the application id should match the Vercel project name."
1314
+ },
1315
+ packageName: {
1316
+ type: "string",
1317
+ 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`."
1249
1318
  },
1250
1319
  production: {
1251
1320
  $ref: "#/definitions/HostConfig",
@@ -1292,12 +1361,23 @@ var schema_default = {
1292
1361
  type: "object",
1293
1362
  properties: {
1294
1363
  local: {
1295
- $ref: "#/definitions/LocalHostConfig",
1296
- deprecated: "This is being replaced by the `localPort` field below."
1364
+ anyOf: [
1365
+ {
1366
+ type: "number"
1367
+ },
1368
+ {
1369
+ type: "string"
1370
+ },
1371
+ {
1372
+ $ref: "#/definitions/LocalHostConfig"
1373
+ }
1374
+ ],
1375
+ 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."
1297
1376
  },
1298
1377
  localPort: {
1299
1378
  type: "number",
1300
- 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."
1379
+ 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.",
1380
+ deprecated: "Please set the port with the 'local' field instead."
1301
1381
  },
1302
1382
  fallback: {
1303
1383
  anyOf: [
@@ -1308,7 +1388,7 @@ var schema_default = {
1308
1388
  type: "string"
1309
1389
  }
1310
1390
  ],
1311
- 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."
1391
+ 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."
1312
1392
  },
1313
1393
  task: {
1314
1394
  type: "string",
@@ -1345,7 +1425,12 @@ var schema_default = {
1345
1425
  },
1346
1426
  projectId: {
1347
1427
  type: "string",
1348
- description: "Vercel project ID"
1428
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1429
+ deprecated: "Instead, the application id should match the Vercel project name."
1430
+ },
1431
+ packageName: {
1432
+ type: "string",
1433
+ 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`."
1349
1434
  },
1350
1435
  production: {
1351
1436
  $ref: "#/definitions/HostConfig",