@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
@@ -323,10 +323,13 @@ var validateConfigPaths = (applicationConfigsById) => {
323
323
  }
324
324
  }
325
325
  if (errors.length) {
326
- throw new MicrofrontendError(`Invalid paths: ${errors.join(", ")}`, {
327
- type: "config",
328
- subtype: "conflicting_paths"
329
- });
326
+ throw new MicrofrontendError(
327
+ `Invalid paths: ${errors.join(", ")}. See supported paths in the documentation https://vercel.com/docs/microfrontends/path-routing#supported-path-expressions.`,
328
+ {
329
+ type: "config",
330
+ subtype: "conflicting_paths"
331
+ }
332
+ );
330
333
  }
331
334
  };
332
335
  var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
@@ -441,9 +444,40 @@ var validateDeprecatedFields = (config) => {
441
444
  `Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
442
445
  );
443
446
  }
444
- if (application.development?.local) {
447
+ if (application.development?.localPort) {
445
448
  errors.push(
446
- `Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
449
+ `Application '${applicationId}' cannot contain deprecated field 'development.localPort'. Use 'developement.local' instead.`
450
+ );
451
+ }
452
+ if (application.development?.fallback && typeof application.development.fallback !== "string") {
453
+ const fallback = application.development.fallback;
454
+ let asString = fallback.host;
455
+ if (fallback.protocol) {
456
+ asString = `${fallback.protocol}://${asString}`;
457
+ }
458
+ if (fallback.port) {
459
+ asString = `${asString}:${fallback.port}`;
460
+ }
461
+ errors.push(
462
+ `Application '${applicationId}' requires a string (not an object) for the 'development.fallback' field. Please set 'development.fallback' to '${asString}'.`
463
+ );
464
+ }
465
+ if (application.development?.local && typeof application.development.local !== "string" && typeof application.development.local !== "number") {
466
+ const local = application.development.local;
467
+ let asString;
468
+ if (local.port && !local.protocol && !local.host) {
469
+ asString = String(local.port);
470
+ } else {
471
+ asString = local.host ?? "localhost";
472
+ if (local.protocol) {
473
+ asString = `${local.protocol}://${asString}`;
474
+ }
475
+ if (local.port) {
476
+ asString = `${asString}:${local.port}`;
477
+ }
478
+ }
479
+ errors.push(
480
+ `Application '${applicationId}' requires a string or number (not an object) for the 'development.local' field. Please set 'development.local' to '${asString}'.`
447
481
  );
448
482
  }
449
483
  }
@@ -507,10 +541,10 @@ var Host = class {
507
541
  }
508
542
  this.local = options?.isLocal;
509
543
  }
510
- static parseUrl(url) {
544
+ static parseUrl(url, defaultProtocol = "https") {
511
545
  let hostToParse = url;
512
546
  if (!/^https?:\/\//.exec(hostToParse)) {
513
- hostToParse = `https://${hostToParse}`;
547
+ hostToParse = `${defaultProtocol}://${hostToParse}`;
514
548
  }
515
549
  const parsed = new URL(hostToParse);
516
550
  if (!parsed.hostname) {
@@ -563,12 +597,39 @@ var LocalHost = class extends Host {
563
597
  constructor({
564
598
  appName,
565
599
  localPort,
566
- ...hostConfig
600
+ local
567
601
  }) {
568
- const host = hostConfig.host ?? "localhost";
569
- const port = localPort ?? hostConfig.port ?? generatePortFromName({ name: appName });
570
- const protocol = hostConfig.protocol ?? "http";
571
- super({ protocol, host, port });
602
+ if (localPort && local) {
603
+ throw new Error(
604
+ `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.`
605
+ );
606
+ }
607
+ let protocol;
608
+ let host;
609
+ let port;
610
+ if (localPort) {
611
+ port = localPort;
612
+ } else if (typeof local === "number") {
613
+ port = local;
614
+ } else if (typeof local === "string") {
615
+ if (/^\d+$/.test(local)) {
616
+ port = Number.parseInt(local);
617
+ } else {
618
+ const parsed = Host.parseUrl(local, "http");
619
+ protocol = parsed.protocol;
620
+ host = parsed.host;
621
+ port = parsed.port;
622
+ }
623
+ } else if (local) {
624
+ protocol = local.protocol;
625
+ host = local.host;
626
+ port = local.port;
627
+ }
628
+ super({
629
+ protocol: protocol ?? "http",
630
+ host: host ?? "localhost",
631
+ port: port ?? generatePortFromName({ name: appName })
632
+ });
572
633
  }
573
634
  };
574
635
 
@@ -584,7 +645,7 @@ var Application = class {
584
645
  local: new LocalHost({
585
646
  appName: name,
586
647
  localPort: app.development?.localPort,
587
- ...app.development?.local
648
+ local: app.development?.local
588
649
  }),
589
650
  fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
590
651
  };
@@ -594,6 +655,7 @@ var Application = class {
594
655
  this.fallback = new Host(app.production);
595
656
  }
596
657
  this.projectId = app.projectId ?? app.vercel?.projectId;
658
+ this.packageName = app.packageName;
597
659
  this.overrides = overrides?.environment ? {
598
660
  environment: new Host(overrides.environment)
599
661
  } : void 0;
@@ -759,10 +821,12 @@ var MicrofrontendConfigIsomorphic = class {
759
821
  ].filter(Boolean);
760
822
  }
761
823
  getApplication(name) {
762
- if (this.defaultApplication?.name === name) {
824
+ if (this.defaultApplication?.name === name || this.defaultApplication?.packageName === name) {
763
825
  return this.defaultApplication;
764
826
  }
765
- const app = this.childApplications[name];
827
+ const app = this.childApplications[name] || Object.values(this.childApplications).find(
828
+ (child) => child.packageName === name
829
+ );
766
830
  if (!app) {
767
831
  throw new MicrofrontendError(
768
832
  `Could not find microfrontends configuration for application "${name}"`,
@@ -1211,9 +1275,7 @@ var schema_default = {
1211
1275
  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"
1212
1276
  }
1213
1277
  },
1214
- required: [
1215
- "applications"
1216
- ],
1278
+ required: ["applications"],
1217
1279
  additionalProperties: false
1218
1280
  },
1219
1281
  Options: {
@@ -1266,7 +1328,7 @@ var schema_default = {
1266
1328
  $ref: "#/definitions/Application"
1267
1329
  },
1268
1330
  propertyNames: {
1269
- description: "The unique identifier for a Microfrontend Application. Must match the `name` field of the application's `package.json`."
1331
+ 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."
1270
1332
  }
1271
1333
  },
1272
1334
  Application: {
@@ -1288,7 +1350,12 @@ var schema_default = {
1288
1350
  },
1289
1351
  projectId: {
1290
1352
  type: "string",
1291
- description: "Vercel project ID"
1353
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1354
+ deprecated: "Instead, the application id should match the Vercel project name."
1355
+ },
1356
+ packageName: {
1357
+ type: "string",
1358
+ 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`."
1292
1359
  },
1293
1360
  production: {
1294
1361
  $ref: "#/definitions/HostConfig",
@@ -1308,9 +1375,7 @@ var schema_default = {
1308
1375
  description: "Vercel project ID"
1309
1376
  }
1310
1377
  },
1311
- required: [
1312
- "projectId"
1313
- ],
1378
+ required: ["projectId"],
1314
1379
  additionalProperties: false
1315
1380
  },
1316
1381
  HostConfig: {
@@ -1318,10 +1383,7 @@ var schema_default = {
1318
1383
  properties: {
1319
1384
  protocol: {
1320
1385
  type: "string",
1321
- enum: [
1322
- "http",
1323
- "https"
1324
- ],
1386
+ enum: ["http", "https"],
1325
1387
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1326
1388
  },
1327
1389
  host: {
@@ -1333,21 +1395,30 @@ var schema_default = {
1333
1395
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1334
1396
  }
1335
1397
  },
1336
- required: [
1337
- "host"
1338
- ],
1398
+ required: ["host"],
1339
1399
  additionalProperties: false
1340
1400
  },
1341
1401
  Development: {
1342
1402
  type: "object",
1343
1403
  properties: {
1344
1404
  local: {
1345
- $ref: "#/definitions/LocalHostConfig",
1346
- deprecated: "This is being replaced by the `localPort` field below."
1405
+ anyOf: [
1406
+ {
1407
+ type: "number"
1408
+ },
1409
+ {
1410
+ type: "string"
1411
+ },
1412
+ {
1413
+ $ref: "#/definitions/LocalHostConfig"
1414
+ }
1415
+ ],
1416
+ 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."
1347
1417
  },
1348
1418
  localPort: {
1349
1419
  type: "number",
1350
- 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."
1420
+ 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.",
1421
+ deprecated: "Please set the port with the 'local' field instead."
1351
1422
  },
1352
1423
  fallback: {
1353
1424
  anyOf: [
@@ -1358,7 +1429,7 @@ var schema_default = {
1358
1429
  type: "string"
1359
1430
  }
1360
1431
  ],
1361
- 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."
1432
+ 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."
1362
1433
  },
1363
1434
  task: {
1364
1435
  type: "string",
@@ -1377,10 +1448,7 @@ var schema_default = {
1377
1448
  },
1378
1449
  protocol: {
1379
1450
  type: "string",
1380
- enum: [
1381
- "http",
1382
- "https"
1383
- ],
1451
+ enum: ["http", "https"],
1384
1452
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1385
1453
  },
1386
1454
  port: {
@@ -1398,7 +1466,12 @@ var schema_default = {
1398
1466
  },
1399
1467
  projectId: {
1400
1468
  type: "string",
1401
- description: "Vercel project ID"
1469
+ description: "Vercel project ID, only required if the application name / id is different to the Vercel project name.",
1470
+ deprecated: "Instead, the application id should match the Vercel project name."
1471
+ },
1472
+ packageName: {
1473
+ type: "string",
1474
+ 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`."
1402
1475
  },
1403
1476
  production: {
1404
1477
  $ref: "#/definitions/HostConfig",
@@ -1412,9 +1485,7 @@ var schema_default = {
1412
1485
  description: "Groups of path expressions that are routed to this application."
1413
1486
  }
1414
1487
  },
1415
- required: [
1416
- "routing"
1417
- ],
1488
+ required: ["routing"],
1418
1489
  additionalProperties: false
1419
1490
  },
1420
1491
  Routing: {
@@ -1441,9 +1512,7 @@ var schema_default = {
1441
1512
  }
1442
1513
  }
1443
1514
  },
1444
- required: [
1445
- "paths"
1446
- ],
1515
+ required: ["paths"],
1447
1516
  additionalProperties: false
1448
1517
  },
1449
1518
  ChildConfig: {
@@ -1464,9 +1533,7 @@ var schema_default = {
1464
1533
  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."
1465
1534
  }
1466
1535
  },
1467
- required: [
1468
- "partOf"
1469
- ],
1536
+ required: ["partOf"],
1470
1537
  additionalProperties: false
1471
1538
  }
1472
1539
  }
@@ -1808,6 +1875,17 @@ function transform4(args) {
1808
1875
  } else {
1809
1876
  next.redirects = async () => proxyRedirects;
1810
1877
  }
1878
+ if (process.env.MFE_DEBUG) {
1879
+ const indent = " ".repeat(4);
1880
+ const header = "redirects";
1881
+ const separator = "\u23AF".repeat(header.length);
1882
+ console.log(
1883
+ `${indent}${header}
1884
+ ${indent}${separator}
1885
+ ${indent} - Automatically redirecting all requests to local microfrontends proxy
1886
+ `
1887
+ );
1888
+ }
1811
1889
  }
1812
1890
  return { next };
1813
1891
  }
@@ -1823,13 +1901,12 @@ function getDomainFromEnvironment({
1823
1901
  if (mfeProjects.length === 0) {
1824
1902
  throw new Error("Missing related microfrontends project information");
1825
1903
  }
1826
- if (!app.projectId) {
1827
- throw new Error(`Missing applications[${app.name}].vercel.projectId`);
1828
- }
1829
- const vercelProject = mfeProjects.find((p) => p.project.id === app.projectId);
1904
+ const vercelProject = mfeProjects.find(
1905
+ (p) => p.project.name === app.name || p.project.id === app.projectId
1906
+ );
1830
1907
  if (!vercelProject) {
1831
1908
  throw new Error(
1832
- `Missing related microfrontends project information for application "${app.name}"`
1909
+ `Could not find the Vercel project for application "${app.name}". If the name does not match the Vercel project name, set the \`projectId\` field in the application config.`
1833
1910
  );
1834
1911
  }
1835
1912
  const domain = target === "preview" && vercelProject.preview.branch ? vercelProject.preview.branch : vercelProject.production.alias ?? vercelProject.production.url;
@@ -1897,7 +1974,7 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
1897
1974
 
1898
1975
  // src/next/config/transforms/rewrites.ts
1899
1976
  function debugRewrites(rewrites) {
1900
- if (process.env.MFE_DEBUG === "true" || process.env.MFE_DEBUG === "1") {
1977
+ if (process.env.MFE_DEBUG) {
1901
1978
  const indent = " ".repeat(4);
1902
1979
  const header = "rewrites (source \u2192 destination)";
1903
1980
  const separator = "\u23AF".repeat(header.length);
@@ -2153,7 +2230,7 @@ var transforms = {
2153
2230
 
2154
2231
  // src/next/config/env.ts
2155
2232
  function debugEnv(env) {
2156
- if (process.env.MFE_DEBUG === "true") {
2233
+ if (process.env.MFE_DEBUG) {
2157
2234
  const indent = " ".repeat(4);
2158
2235
  const header = "env (key \u2192 val)";
2159
2236
  const separator = "\u23AF".repeat(header.length);