@vercel/microfrontends 1.0.0 → 1.0.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 (49) hide show
  1. package/dist/bin/cli.cjs +183 -27
  2. package/dist/config.cjs +46 -1
  3. package/dist/config.cjs.map +1 -1
  4. package/dist/config.d.ts +1 -1
  5. package/dist/config.js +46 -1
  6. package/dist/config.js.map +1 -1
  7. package/dist/experimental/sveltekit.cjs +1735 -0
  8. package/dist/experimental/sveltekit.cjs.map +1 -0
  9. package/dist/experimental/sveltekit.d.ts +12 -0
  10. package/dist/experimental/sveltekit.js +1698 -0
  11. package/dist/experimental/sveltekit.js.map +1 -0
  12. package/dist/experimental/vite.cjs +1745 -0
  13. package/dist/experimental/vite.cjs.map +1 -0
  14. package/dist/experimental/vite.d.ts +29 -0
  15. package/dist/experimental/vite.js +1710 -0
  16. package/dist/experimental/vite.js.map +1 -0
  17. package/dist/{index-09b1ddf9.d.ts → index-d5994ac5.d.ts} +1 -1
  18. package/dist/microfrontends/server.cjs +73 -10
  19. package/dist/microfrontends/server.cjs.map +1 -1
  20. package/dist/microfrontends/server.d.ts +1 -1
  21. package/dist/microfrontends/server.js +73 -10
  22. package/dist/microfrontends/server.js.map +1 -1
  23. package/dist/microfrontends.cjs +47 -2
  24. package/dist/microfrontends.cjs.map +1 -1
  25. package/dist/microfrontends.d.ts +1 -1
  26. package/dist/microfrontends.js +47 -2
  27. package/dist/microfrontends.js.map +1 -1
  28. package/dist/next/config.cjs +123 -51
  29. package/dist/next/config.cjs.map +1 -1
  30. package/dist/next/config.js +122 -52
  31. package/dist/next/config.js.map +1 -1
  32. package/dist/next/middleware.cjs +77 -7
  33. package/dist/next/middleware.cjs.map +1 -1
  34. package/dist/next/middleware.js +77 -7
  35. package/dist/next/middleware.js.map +1 -1
  36. package/dist/next/testing.cjs +46 -5
  37. package/dist/next/testing.cjs.map +1 -1
  38. package/dist/next/testing.d.ts +1 -1
  39. package/dist/next/testing.js +46 -5
  40. package/dist/next/testing.js.map +1 -1
  41. package/dist/utils/mfe-port.cjs +73 -10
  42. package/dist/utils/mfe-port.cjs.map +1 -1
  43. package/dist/utils/mfe-port.js +73 -10
  44. package/dist/utils/mfe-port.js.map +1 -1
  45. package/dist/validation.cjs +26 -8
  46. package/dist/validation.cjs.map +1 -1
  47. package/dist/validation.js +26 -8
  48. package/dist/validation.js.map +1 -1
  49. package/package.json +26 -2
@@ -1,5 +1,11 @@
1
- // src/next/config/index.ts
2
- import fs6 from "node:fs";
1
+ // src/bin/check-proxy.ts
2
+ function displayLocalProxyInfo(port) {
3
+ const { MFE_PROXY_MESSAGE_PRINTED, TURBO_TASK_HAS_MFE_PROXY } = process.env;
4
+ if (TURBO_TASK_HAS_MFE_PROXY === "true" && MFE_PROXY_MESSAGE_PRINTED !== "true") {
5
+ process.env.MFE_PROXY_MESSAGE_PRINTED = "true";
6
+ console.log(`Microfrontends Proxy running on http://localhost:${port}`);
7
+ }
8
+ }
3
9
 
4
10
  // src/config/microfrontends/server/index.ts
5
11
  import fs5 from "node:fs";
@@ -358,6 +364,48 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
358
364
  );
359
365
  }
360
366
  };
367
+ var validateDeprecatedFields = (config) => {
368
+ const errors = [];
369
+ if (config.options?.vercel) {
370
+ errors.push(
371
+ `Configuration cannot contain deprecated field 'options.vercel'. Use 'options.disableOverrides' instead.`
372
+ );
373
+ }
374
+ if (config.options?.localProxy) {
375
+ errors.push(
376
+ `Configuration cannot contain deprecated field 'options.localProxy'. Use 'options.localProxyPort' instead.`
377
+ );
378
+ }
379
+ for (const [applicationId, application] of Object.entries(
380
+ config.applications
381
+ )) {
382
+ if (application.vercel) {
383
+ errors.push(
384
+ `Application '${applicationId}' cannot contain deprecated field 'vercel'. Use 'projectId' instead.`
385
+ );
386
+ }
387
+ if (application.production) {
388
+ errors.push(
389
+ `Application '${applicationId}' cannot contain deprecated field 'production'. Use 'development.fallback' instead.`
390
+ );
391
+ }
392
+ if (application.development?.local) {
393
+ errors.push(
394
+ `Application '${applicationId}' cannot contain deprecated field 'development.local'. Use 'developement.localPort' instead.`
395
+ );
396
+ }
397
+ }
398
+ if (errors.length) {
399
+ throw new MicrofrontendError(
400
+ `Microfrontends configuration file errors:
401
+ - ${errors.join("\n- ")}`,
402
+ {
403
+ type: "config",
404
+ subtype: "depcrecated_field"
405
+ }
406
+ );
407
+ }
408
+ };
361
409
 
362
410
  // src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
363
411
  var PREFIX = "vc-ap";
@@ -568,7 +616,7 @@ var MicrofrontendConfigIsomorphic = class {
568
616
  }) {
569
617
  this.childApplications = {};
570
618
  MicrofrontendConfigIsomorphic.validate(config, opts);
571
- const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
619
+ const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
572
620
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
573
621
  this.isMainConfig = isMainConfig(config);
574
622
  if (isMainConfig(config)) {
@@ -625,6 +673,9 @@ var MicrofrontendConfigIsomorphic = class {
625
673
  if (!skipValidation.includes("defaultApplication")) {
626
674
  validateConfigDefaultApplication(c.applications);
627
675
  }
676
+ if (!skipValidation.includes("deprecatedFields")) {
677
+ validateDeprecatedFields(c);
678
+ }
628
679
  }
629
680
  return c;
630
681
  }
@@ -759,7 +810,7 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
759
810
  }) {
760
811
  super({ config, overrides, meta });
761
812
  this.isMainConfig = true;
762
- const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
813
+ const disableOverrides = config.options?.disableOverrides ?? config.options?.vercel?.disableOverrides ?? false;
763
814
  let defaultApplication;
764
815
  for (const [appId, appConfig] of Object.entries(config.applications)) {
765
816
  const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
@@ -1072,7 +1123,9 @@ var schema_default = {
1072
1123
  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"
1073
1124
  }
1074
1125
  },
1075
- required: ["applications"],
1126
+ required: [
1127
+ "applications"
1128
+ ],
1076
1129
  additionalProperties: false
1077
1130
  },
1078
1131
  Options: {
@@ -1167,7 +1220,9 @@ var schema_default = {
1167
1220
  description: "Vercel project ID"
1168
1221
  }
1169
1222
  },
1170
- required: ["projectId"],
1223
+ required: [
1224
+ "projectId"
1225
+ ],
1171
1226
  additionalProperties: false
1172
1227
  },
1173
1228
  HostConfig: {
@@ -1175,7 +1230,10 @@ var schema_default = {
1175
1230
  properties: {
1176
1231
  protocol: {
1177
1232
  type: "string",
1178
- enum: ["http", "https"],
1233
+ enum: [
1234
+ "http",
1235
+ "https"
1236
+ ],
1179
1237
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1180
1238
  },
1181
1239
  host: {
@@ -1187,7 +1245,9 @@ var schema_default = {
1187
1245
  description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
1188
1246
  }
1189
1247
  },
1190
- required: ["host"],
1248
+ required: [
1249
+ "host"
1250
+ ],
1191
1251
  additionalProperties: false
1192
1252
  },
1193
1253
  Development: {
@@ -1229,7 +1289,10 @@ var schema_default = {
1229
1289
  },
1230
1290
  protocol: {
1231
1291
  type: "string",
1232
- enum: ["http", "https"],
1292
+ enum: [
1293
+ "http",
1294
+ "https"
1295
+ ],
1233
1296
  description: "The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n*"
1234
1297
  },
1235
1298
  port: {
@@ -1261,7 +1324,9 @@ var schema_default = {
1261
1324
  description: "Groups of path expressions that are routed to this application."
1262
1325
  }
1263
1326
  },
1264
- required: ["routing"],
1327
+ required: [
1328
+ "routing"
1329
+ ],
1265
1330
  additionalProperties: false
1266
1331
  },
1267
1332
  Routing: {
@@ -1288,7 +1353,9 @@ var schema_default = {
1288
1353
  }
1289
1354
  }
1290
1355
  },
1291
- required: ["paths"],
1356
+ required: [
1357
+ "paths"
1358
+ ],
1292
1359
  additionalProperties: false
1293
1360
  },
1294
1361
  ChildConfig: {
@@ -1309,7 +1376,9 @@ var schema_default = {
1309
1376
  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."
1310
1377
  }
1311
1378
  },
1312
- required: ["partOf"],
1379
+ required: [
1380
+ "partOf"
1381
+ ],
1313
1382
  additionalProperties: false
1314
1383
  }
1315
1384
  }
@@ -1571,12 +1640,30 @@ var MicrofrontendsServer = class extends Microfrontends {
1571
1640
  }
1572
1641
  };
1573
1642
 
1574
- // src/next/utils/check-proxy.ts
1575
- function displayLocalProxyInfo(port) {
1576
- const { MFE_PROXY_MESSAGE_PRINTED, TURBO_TASK_HAS_MFE_PROXY } = process.env;
1577
- if (TURBO_TASK_HAS_MFE_PROXY === "true" && MFE_PROXY_MESSAGE_PRINTED !== "true") {
1578
- process.env.MFE_PROXY_MESSAGE_PRINTED = "true";
1579
- console.log(`Microfrontends Proxy running on http://localhost:${port}`);
1643
+ // src/config/microfrontends/utils/get-application-context.ts
1644
+ import fs6 from "node:fs";
1645
+ function getApplicationContext(opts) {
1646
+ if (opts?.appName) {
1647
+ return { name: opts.appName };
1648
+ }
1649
+ try {
1650
+ const packageJsonString = fs6.readFileSync("./package.json", "utf-8");
1651
+ const packageJson = JSON.parse(packageJsonString);
1652
+ if (!packageJson.name) {
1653
+ throw new MicrofrontendError(
1654
+ `package.json file missing required field "name"`,
1655
+ {
1656
+ type: "packageJson",
1657
+ subtype: "missing_field_name",
1658
+ source: "@vercel/microfrontends/next"
1659
+ }
1660
+ );
1661
+ }
1662
+ return { name: packageJson.name };
1663
+ } catch (err) {
1664
+ throw MicrofrontendError.handle(err, {
1665
+ fileName: "package.json"
1666
+ });
1580
1667
  }
1581
1668
  }
1582
1669
 
@@ -1615,27 +1702,34 @@ function transform2(args) {
1615
1702
  };
1616
1703
  }
1617
1704
 
1705
+ // src/next/utils/route-to-local-proxy.ts
1706
+ function routeToLocalProxy() {
1707
+ const isDevEnv = (process.env.VERCEL_ENV ?? "development") === "development";
1708
+ return isDevEnv && Boolean(process.env.TURBO_TASK_HAS_MFE_PROXY);
1709
+ }
1710
+
1618
1711
  // src/next/config/transforms/redirects.ts
1619
1712
  function transform3(args) {
1620
1713
  const { next, microfrontend, opts } = args;
1621
1714
  const isProduction2 = opts?.isProduction ?? false;
1622
- const isDevEnv = (process.env.VERCEL_ENV ?? "development") === "development";
1623
- const requireLocalProxyHeader = !isProduction2 && isDevEnv && Boolean(process.env.TURBO_TASK_HAS_MFE_PROXY) && !process.env.MFE_DISABLE_LOCAL_PROXY_REWRITE;
1715
+ const requireLocalProxyHeader = routeToLocalProxy() && !isProduction2 && !process.env.MFE_DISABLE_LOCAL_PROXY_REWRITE;
1624
1716
  if (requireLocalProxyHeader) {
1625
- const proxyRedirect = {
1626
- source: "/:path*",
1627
- destination: `http://localhost:${microfrontend.getLocalProxyPort()}/:path*`,
1628
- permanent: false,
1629
- missing: [{ type: "header", key: "x-vercel-mfe-local-proxy-origin" }]
1630
- };
1717
+ const proxyRedirects = [
1718
+ {
1719
+ source: "/:path*",
1720
+ destination: `http://localhost:${microfrontend.getLocalProxyPort()}/:path*`,
1721
+ permanent: false,
1722
+ missing: [{ type: "header", key: "x-vercel-mfe-local-proxy-origin" }]
1723
+ }
1724
+ ];
1631
1725
  if (next.redirects && typeof next.redirects === "function") {
1632
1726
  const originalRedirectsFn = next.redirects;
1633
1727
  next.redirects = async () => {
1634
1728
  const originalRedirects = await originalRedirectsFn();
1635
- return [proxyRedirect, ...originalRedirects];
1729
+ return [...proxyRedirects, ...originalRedirects];
1636
1730
  };
1637
1731
  } else {
1638
- next.redirects = async () => [proxyRedirect];
1732
+ next.redirects = async () => proxyRedirects;
1639
1733
  }
1640
1734
  }
1641
1735
  return { next };
@@ -1989,30 +2083,6 @@ function isProduction(opts) {
1989
2083
  }
1990
2084
  return process.env.VERCEL_ENV === "production";
1991
2085
  }
1992
- function getApplicationContext(opts) {
1993
- if (opts?.appName) {
1994
- return { name: opts.appName };
1995
- }
1996
- try {
1997
- const packageJsonString = fs6.readFileSync("./package.json", "utf-8");
1998
- const packageJson = JSON.parse(packageJsonString);
1999
- if (!packageJson.name) {
2000
- throw new MicrofrontendError(
2001
- `package.json file missing required field "name"`,
2002
- {
2003
- type: "packageJson",
2004
- subtype: "missing_field_name",
2005
- source: "@vercel/microfrontends/next"
2006
- }
2007
- );
2008
- }
2009
- return { name: packageJson.name };
2010
- } catch (err) {
2011
- throw MicrofrontendError.handle(err, {
2012
- fileName: "package.json"
2013
- });
2014
- }
2015
- }
2016
2086
  function withMicrofrontends(nextConfig, opts) {
2017
2087
  if (opts?.debug) {
2018
2088
  process.env.MFE_DEBUG = "true";