@vercel/microfrontends 2.0.1 → 2.1.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.
package/CHANGELOG.md CHANGED
@@ -1,10 +1,26 @@
1
1
  # @vercel/microfrontends
2
2
 
3
+ ## 2.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 96f0ea5:
8
+ - Add support for locally overriding to MFE aliases: https://vercel.com/changelog/preview-links-between-microfrontends-projects-now-serve-all-paths
9
+ - Fix local Next.js image optimization. Next.js released a security fix which removes headers from being passed on image optimization requests. The microfrontends local proxy previously relied on the headers being passed.
10
+
11
+ ## 2.1.0
12
+
13
+ ### Minor Changes
14
+
15
+ - c856a5d:
16
+ - Add support for custom `microfrontends.json` file names. This enables a single application to be deployed as multiple different vercel projects / microfrontends.
17
+ - Strip asset prefix from Vercel Firewall rate limit paths. Support Vercel Firewall rate limit requests when they go to a child application.
18
+
3
19
  ## 2.0.1
4
20
 
5
21
  ### Patch Changes
6
22
 
7
- - 8c11bdc:
23
+ - 8c11bdc:
8
24
  - Support hyphens and escaped special characters in supported path matching regex https://vercel.com/docs/microfrontends/path-routing#supported-path-expressions
9
25
  - Improve error message for when local development proxy can't determine the port
10
26
  - Update local proxy double slash routing behaviour to match the production proxy
package/README.md CHANGED
@@ -1,8 +1,4 @@
1
- <picture>
2
- <source srcset="https://assets.vercel.com/image/upload/v1689795055/docs-assets/static/docs/microfrontends/mfe-package-banner-dark.png" media="(prefers-color-scheme: dark)">
3
- <source srcset="https://assets.vercel.com/image/upload/v1689795055/docs-assets/static/docs/microfrontends/mfe-package-banner-light.png" media="(prefers-color-scheme: light)">
4
- <img src="https://assets.vercel.com/image/upload/v1689795055/docs-assets/static/docs/microfrontends/mfe-package-banner-dark.png" alt="hero banner">
5
- </picture>
1
+ ![hero banner](./assets/mfe-package-banner-dark.png)
6
2
 
7
3
  # @vercel/microfrontends
8
4
 
package/dist/bin/cli.cjs CHANGED
@@ -30,7 +30,7 @@ var import_env = require("@next/env");
30
30
  // package.json
31
31
  var package_default = {
32
32
  name: "@vercel/microfrontends",
33
- version: "2.0.1",
33
+ version: "2.1.1",
34
34
  private: false,
35
35
  description: "Defines configuration and utilities for microfrontends development",
36
36
  keywords: [
@@ -397,6 +397,11 @@ function parseOverrides(cookies) {
397
397
  return overridesConfig;
398
398
  }
399
399
 
400
+ // src/config/overrides/get-app-env-override-cookie-name.ts
401
+ function getAppEnvOverrideCookieName(application) {
402
+ return `${OVERRIDES_ENV_COOKIE_PREFIX}${application}`;
403
+ }
404
+
400
405
  // src/config/microfrontends-config/client/index.ts
401
406
  var import_path_to_regexp = require("path-to-regexp");
402
407
  var regexpCache = /* @__PURE__ */ new Map();
@@ -1112,22 +1117,38 @@ var import_node_fs2 = require("fs");
1112
1117
  var import_jsonc_parser2 = require("jsonc-parser");
1113
1118
  var import_fast_glob = __toESM(require("fast-glob"), 1);
1114
1119
 
1115
- // src/config/constants.ts
1116
- var CONFIGURATION_FILENAMES = [
1120
+ // src/config/microfrontends/utils/get-config-file-name.ts
1121
+ var DEFAULT_CONFIGURATION_FILENAMES = [
1117
1122
  "microfrontends.jsonc",
1118
1123
  "microfrontends.json"
1119
1124
  ];
1125
+ function getPossibleConfigurationFilenames({
1126
+ customConfigFilename
1127
+ }) {
1128
+ if (customConfigFilename) {
1129
+ if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
1130
+ throw new Error(
1131
+ `The VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable must end with '.json' or '.jsonc'. Received: ${customConfigFilename}`
1132
+ );
1133
+ }
1134
+ return Array.from(
1135
+ /* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
1136
+ );
1137
+ }
1138
+ return DEFAULT_CONFIGURATION_FILENAMES;
1139
+ }
1120
1140
 
1121
1141
  // src/config/microfrontends/utils/infer-microfrontends-location.ts
1122
1142
  var configCache = {};
1123
1143
  function findPackageWithMicrofrontendsConfig({
1124
1144
  repositoryRoot,
1125
- applicationContext
1145
+ applicationContext,
1146
+ customConfigFilename
1126
1147
  }) {
1127
1148
  const applicationName = applicationContext.name;
1128
1149
  try {
1129
1150
  const microfrontendsJsonPaths = import_fast_glob.default.globSync(
1130
- `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
1151
+ `**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
1131
1152
  {
1132
1153
  cwd: repositoryRoot,
1133
1154
  absolute: true,
@@ -1183,6 +1204,8 @@ Names of applications in \`microfrontends.json\` must match the Vercel Project n
1183
1204
 
1184
1205
  If your Vercel Microfrontends configuration is not in this repository, you can use the Vercel CLI to pull the Vercel Microfrontends configuration using the "vercel microfrontends pull" command, or you can specify the path manually using the VC_MICROFRONTENDS_CONFIG environment variable.
1185
1206
 
1207
+ If your Vercel Microfrontends configuration has a custom name, ensure the VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable is set, you can pull the vercel project environment variables using the "vercel env pull" command.
1208
+
1186
1209
  If you suspect this is thrown in error, please reach out to the Vercel team.`,
1187
1210
  { type: "config", subtype: "inference_failed" }
1188
1211
  );
@@ -1197,7 +1220,7 @@ If you suspect this is thrown in error, please reach out to the Vercel team.`,
1197
1220
  }
1198
1221
  }
1199
1222
  function inferMicrofrontendsLocation(opts) {
1200
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}`;
1223
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
1201
1224
  if (configCache[cacheKey]) {
1202
1225
  return configCache[cacheKey];
1203
1226
  }
@@ -1263,8 +1286,13 @@ function findPackageRoot(startDir) {
1263
1286
  // src/config/microfrontends/utils/find-config.ts
1264
1287
  var import_node_fs5 = __toESM(require("fs"), 1);
1265
1288
  var import_node_path5 = require("path");
1266
- function findConfig({ dir }) {
1267
- for (const filename of CONFIGURATION_FILENAMES) {
1289
+ function findConfig({
1290
+ dir,
1291
+ customConfigFilename
1292
+ }) {
1293
+ for (const filename of getPossibleConfigurationFilenames({
1294
+ customConfigFilename
1295
+ })) {
1268
1296
  const maybeConfig = (0, import_node_path5.join)(dir, filename);
1269
1297
  if (import_node_fs5.default.existsSync(maybeConfig)) {
1270
1298
  return maybeConfig;
@@ -1696,7 +1724,11 @@ var MicrofrontendsServer = class {
1696
1724
  appName,
1697
1725
  packageRoot
1698
1726
  });
1699
- const maybeConfig = findConfig({ dir: packageRoot });
1727
+ const customConfigFilename = process.env.VC_MICROFRONTENDS_CONFIG_FILE_NAME;
1728
+ const maybeConfig = findConfig({
1729
+ dir: packageRoot,
1730
+ customConfigFilename
1731
+ });
1700
1732
  if (maybeConfig) {
1701
1733
  return MicrofrontendsServer.fromFile({
1702
1734
  filePath: maybeConfig,
@@ -1705,11 +1737,9 @@ var MicrofrontendsServer = class {
1705
1737
  }
1706
1738
  const repositoryRoot = findRepositoryRoot();
1707
1739
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1708
- if (typeof process.env.VC_MICROFRONTENDS_CONFIG === "string") {
1709
- const maybeConfigFromEnv = (0, import_node_path8.resolve)(
1710
- packageRoot,
1711
- process.env.VC_MICROFRONTENDS_CONFIG
1712
- );
1740
+ const configFromEnv = process.env.VC_MICROFRONTENDS_CONFIG;
1741
+ if (typeof configFromEnv === "string") {
1742
+ const maybeConfigFromEnv = (0, import_node_path8.resolve)(packageRoot, configFromEnv);
1713
1743
  if (maybeConfigFromEnv) {
1714
1744
  return MicrofrontendsServer.fromFile({
1715
1745
  filePath: maybeConfigFromEnv,
@@ -1718,7 +1748,8 @@ var MicrofrontendsServer = class {
1718
1748
  }
1719
1749
  } else {
1720
1750
  const maybeConfigFromVercel = findConfig({
1721
- dir: (0, import_node_path8.join)(packageRoot, ".vercel")
1751
+ dir: (0, import_node_path8.join)(packageRoot, ".vercel"),
1752
+ customConfigFilename
1722
1753
  });
1723
1754
  if (maybeConfigFromVercel) {
1724
1755
  return MicrofrontendsServer.fromFile({
@@ -1729,9 +1760,13 @@ var MicrofrontendsServer = class {
1729
1760
  if (isMonorepo2) {
1730
1761
  const defaultPackage = inferMicrofrontendsLocation({
1731
1762
  repositoryRoot,
1732
- applicationContext
1763
+ applicationContext,
1764
+ customConfigFilename
1765
+ });
1766
+ const maybeConfigFromDefault = findConfig({
1767
+ dir: defaultPackage,
1768
+ customConfigFilename
1733
1769
  });
1734
- const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1735
1770
  if (maybeConfigFromDefault) {
1736
1771
  return MicrofrontendsServer.fromFile({
1737
1772
  filePath: maybeConfigFromDefault,
@@ -1810,9 +1845,12 @@ var localAuthHtml = ({
1810
1845
  hostname,
1811
1846
  defaultApp,
1812
1847
  automationBypassEnvVarName,
1813
- automationBypass
1848
+ automationBypass,
1849
+ override
1814
1850
  }) => {
1851
+ const intro = override ? `<b><code>${app}</code></b> is overriding to a protected deployment <a target="_blank" href="https://${override}">${override}</a>.` : `<b><code>${app}</code></b> is falling back to a protected deployment <a target="_blank" href="https://${hostname}">${hostname}</a>.`;
1815
1852
  const content = automationBypass ? `<b><code>${automationBypassEnvVarName}</code></b> is set with the value <b><code>${automationBypass}</code></b>, please verify this value equals the <a href="https://vercel.com/docs/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation">Protection Bypass for Automation</a> for the Vercel project hosting the deployment.` : `To access, set a local environment variable <b><code>${automationBypassEnvVarName}</code></b> with the value of the <a href="https://vercel.com/docs/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation">Protection Bypass for Automation</a> for the Vercel project hosting the deployment.`;
1853
+ const action = override ? `<buttton onClick="clearOverride()" class="button">Clear Override</button>` : "";
1816
1854
  return `<!DOCTYPE html>
1817
1855
  <html lang="en">
1818
1856
  <head>
@@ -1857,12 +1895,32 @@ var localAuthHtml = ({
1857
1895
  ::-moz-selection {
1858
1896
  background: #79FFE1;
1859
1897
  }
1898
+
1899
+ .button {
1900
+ border: 1px solid black;
1901
+ padding: 10px 20px;
1902
+ text-align: center;
1903
+ text-decoration: none;
1904
+ display: inline-block;
1905
+ font-size: 16px;
1906
+ margin: 4px 2px;
1907
+ cursor: pointer;
1908
+ border-radius: 5px;
1909
+ align-self: flex-end;
1910
+ font-size: 14px;
1911
+ line-height: 1.8;
1912
+ }
1913
+
1914
+ .button:hover {
1915
+ background-color: #ddd;
1916
+ }
1860
1917
 
1861
1918
  a {
1862
1919
  cursor: pointer;
1863
1920
  color: #0070f3;
1864
1921
  text-decoration: none;
1865
1922
  transition: all .2s ease;
1923
+ border-radius: 5px;
1866
1924
  border-bottom: 1px solid transparent
1867
1925
  }
1868
1926
 
@@ -1912,7 +1970,10 @@ var localAuthHtml = ({
1912
1970
  main {
1913
1971
  max-width: 80rem;
1914
1972
  padding: 4rem 6rem;
1915
- margin: auto
1973
+ margin: auto;
1974
+ display: flex;
1975
+ flex-direction: column;
1976
+ row-gap: 32px;
1916
1977
  }
1917
1978
 
1918
1979
  ul {
@@ -1944,7 +2005,7 @@ var localAuthHtml = ({
1944
2005
  padding: 2rem;
1945
2006
  display: flex;
1946
2007
  flex-direction: column;
1947
- margin-bottom: 32px
2008
+ margin: 0px;
1948
2009
  }
1949
2010
 
1950
2011
  .error-code {
@@ -2091,18 +2152,26 @@ var localAuthHtml = ({
2091
2152
  }
2092
2153
  </style>
2093
2154
  </head>
2155
+ <script>
2156
+ function clearOverride() {
2157
+ document.cookie = 'vercel-micro-frontends-override:env:${app}=; expires=Thu, 01 Jan 1970 00:00:00 GMT';
2158
+ window.location.reload();
2159
+ }
2160
+ </script>
2094
2161
  <body>
2095
2162
  <div class="container">
2096
2163
  <main>
2097
2164
  <p class="devinfo-container">
2098
- <span><b><code>${app}</code></b> is falling back to a protected deployment <a target="_blank" href="https://${hostname}">${hostname}</a>.</span>
2099
- <br>
2100
- <span>${content}</span>
2101
- <br>
2102
- <span>The environment variable should be set in the default app <b><code>${defaultApp}</code></b>, where the local proxy is running.</span>
2165
+ <span>${intro}</span>
2166
+ <br/>
2167
+ <span>${content}</span>
2168
+ <br/>
2169
+ <span>The environment variable should be set in the default app <b><code>${defaultApp}</code></b>, where the local proxy is running.</span>
2103
2170
  </p>
2104
2171
 
2105
2172
  <a href="https://vercel.com/docs/microfrontends/local-development#falling-back-to-protected-deployments"><div class="note">Click here to learn more about setting up the environment variable.</div></a>
2173
+
2174
+ ${action}
2106
2175
  </main>
2107
2176
  </div>
2108
2177
  </body>
@@ -2537,6 +2606,10 @@ var LocalProxy = class {
2537
2606
  const { hostname, port, path: path7 } = target;
2538
2607
  const app = this.router.config.getApplication(target.application);
2539
2608
  const automationBypass = process.env[app.getAutomationBypassEnvVarName()];
2609
+ const cookies = (0, import_cookie.parse)(req.headers.cookie || "");
2610
+ const overrideCookieName = getAppEnvOverrideCookieName(
2611
+ target.application
2612
+ );
2540
2613
  const requestOptions = {
2541
2614
  hostname,
2542
2615
  path: path7,
@@ -2544,6 +2617,15 @@ var LocalProxy = class {
2544
2617
  headers: {
2545
2618
  ...req.headers,
2546
2619
  host: hostname,
2620
+ cookie: Object.entries(cookies).reduce((acc, [name, value]) => {
2621
+ if (value && // strip the override cookie if present, as this causes an auth redirect. The
2622
+ // override is handled by the local proxy.
2623
+ name !== overrideCookieName && // strip the VERCEL_MFE_DEBUG cookie if present, as this causes an auth redirect
2624
+ name !== "VERCEL_MFE_DEBUG") {
2625
+ acc.push((0, import_cookie.serialize)(name, value));
2626
+ }
2627
+ return acc;
2628
+ }, []).join("; "),
2547
2629
  ...automationBypass ? { "x-vercel-protection-bypass": automationBypass } : {}
2548
2630
  },
2549
2631
  port
@@ -2560,7 +2642,8 @@ var LocalProxy = class {
2560
2642
  hostname,
2561
2643
  defaultApp: defaultApp.packageName || defaultApp.name,
2562
2644
  automationBypassEnvVarName: app.getAutomationBypassEnvVarName(),
2563
- automationBypass
2645
+ automationBypass,
2646
+ override: cookies[overrideCookieName]
2564
2647
  })
2565
2648
  );
2566
2649
  }
@@ -232,22 +232,38 @@ var import_node_fs2 = require("fs");
232
232
  var import_jsonc_parser = require("jsonc-parser");
233
233
  var import_fast_glob = __toESM(require("fast-glob"), 1);
234
234
 
235
- // src/config/constants.ts
236
- var CONFIGURATION_FILENAMES = [
235
+ // src/config/microfrontends/utils/get-config-file-name.ts
236
+ var DEFAULT_CONFIGURATION_FILENAMES = [
237
237
  "microfrontends.jsonc",
238
238
  "microfrontends.json"
239
239
  ];
240
+ function getPossibleConfigurationFilenames({
241
+ customConfigFilename
242
+ }) {
243
+ if (customConfigFilename) {
244
+ if (!customConfigFilename.endsWith(".json") && !customConfigFilename.endsWith(".jsonc")) {
245
+ throw new Error(
246
+ `The VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable must end with '.json' or '.jsonc'. Received: ${customConfigFilename}`
247
+ );
248
+ }
249
+ return Array.from(
250
+ /* @__PURE__ */ new Set([customConfigFilename, ...DEFAULT_CONFIGURATION_FILENAMES])
251
+ );
252
+ }
253
+ return DEFAULT_CONFIGURATION_FILENAMES;
254
+ }
240
255
 
241
256
  // src/config/microfrontends/utils/infer-microfrontends-location.ts
242
257
  var configCache = {};
243
258
  function findPackageWithMicrofrontendsConfig({
244
259
  repositoryRoot,
245
- applicationContext
260
+ applicationContext,
261
+ customConfigFilename
246
262
  }) {
247
263
  const applicationName = applicationContext.name;
248
264
  try {
249
265
  const microfrontendsJsonPaths = import_fast_glob.default.globSync(
250
- `**/{${CONFIGURATION_FILENAMES.join(",")}}`,
266
+ `**/{${getPossibleConfigurationFilenames({ customConfigFilename }).join(",")}}`,
251
267
  {
252
268
  cwd: repositoryRoot,
253
269
  absolute: true,
@@ -303,6 +319,8 @@ Names of applications in \`microfrontends.json\` must match the Vercel Project n
303
319
 
304
320
  If your Vercel Microfrontends configuration is not in this repository, you can use the Vercel CLI to pull the Vercel Microfrontends configuration using the "vercel microfrontends pull" command, or you can specify the path manually using the VC_MICROFRONTENDS_CONFIG environment variable.
305
321
 
322
+ If your Vercel Microfrontends configuration has a custom name, ensure the VC_MICROFRONTENDS_CONFIG_FILE_NAME environment variable is set, you can pull the vercel project environment variables using the "vercel env pull" command.
323
+
306
324
  If you suspect this is thrown in error, please reach out to the Vercel team.`,
307
325
  { type: "config", subtype: "inference_failed" }
308
326
  );
@@ -317,7 +335,7 @@ If you suspect this is thrown in error, please reach out to the Vercel team.`,
317
335
  }
318
336
  }
319
337
  function inferMicrofrontendsLocation(opts) {
320
- const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}`;
338
+ const cacheKey = `${opts.repositoryRoot}-${opts.applicationContext.name}${opts.customConfigFilename ? `-${opts.customConfigFilename}` : ""}`;
321
339
  if (configCache[cacheKey]) {
322
340
  return configCache[cacheKey];
323
341
  }
@@ -383,8 +401,13 @@ function findPackageRoot(startDir) {
383
401
  // src/config/microfrontends/utils/find-config.ts
384
402
  var import_node_fs5 = __toESM(require("fs"), 1);
385
403
  var import_node_path5 = require("path");
386
- function findConfig({ dir }) {
387
- for (const filename of CONFIGURATION_FILENAMES) {
404
+ function findConfig({
405
+ dir,
406
+ customConfigFilename
407
+ }) {
408
+ for (const filename of getPossibleConfigurationFilenames({
409
+ customConfigFilename
410
+ })) {
388
411
  const maybeConfig = (0, import_node_path5.join)(dir, filename);
389
412
  if (import_node_fs5.default.existsSync(maybeConfig)) {
390
413
  return maybeConfig;
@@ -1487,7 +1510,11 @@ var MicrofrontendsServer = class {
1487
1510
  appName,
1488
1511
  packageRoot
1489
1512
  });
1490
- const maybeConfig = findConfig({ dir: packageRoot });
1513
+ const customConfigFilename = process.env.VC_MICROFRONTENDS_CONFIG_FILE_NAME;
1514
+ const maybeConfig = findConfig({
1515
+ dir: packageRoot,
1516
+ customConfigFilename
1517
+ });
1491
1518
  if (maybeConfig) {
1492
1519
  return MicrofrontendsServer.fromFile({
1493
1520
  filePath: maybeConfig,
@@ -1496,11 +1523,9 @@ var MicrofrontendsServer = class {
1496
1523
  }
1497
1524
  const repositoryRoot = findRepositoryRoot();
1498
1525
  const isMonorepo2 = isMonorepo({ repositoryRoot });
1499
- if (typeof process.env.VC_MICROFRONTENDS_CONFIG === "string") {
1500
- const maybeConfigFromEnv = (0, import_node_path8.resolve)(
1501
- packageRoot,
1502
- process.env.VC_MICROFRONTENDS_CONFIG
1503
- );
1526
+ const configFromEnv = process.env.VC_MICROFRONTENDS_CONFIG;
1527
+ if (typeof configFromEnv === "string") {
1528
+ const maybeConfigFromEnv = (0, import_node_path8.resolve)(packageRoot, configFromEnv);
1504
1529
  if (maybeConfigFromEnv) {
1505
1530
  return MicrofrontendsServer.fromFile({
1506
1531
  filePath: maybeConfigFromEnv,
@@ -1509,7 +1534,8 @@ var MicrofrontendsServer = class {
1509
1534
  }
1510
1535
  } else {
1511
1536
  const maybeConfigFromVercel = findConfig({
1512
- dir: (0, import_node_path8.join)(packageRoot, ".vercel")
1537
+ dir: (0, import_node_path8.join)(packageRoot, ".vercel"),
1538
+ customConfigFilename
1513
1539
  });
1514
1540
  if (maybeConfigFromVercel) {
1515
1541
  return MicrofrontendsServer.fromFile({
@@ -1520,9 +1546,13 @@ var MicrofrontendsServer = class {
1520
1546
  if (isMonorepo2) {
1521
1547
  const defaultPackage = inferMicrofrontendsLocation({
1522
1548
  repositoryRoot,
1523
- applicationContext
1549
+ applicationContext,
1550
+ customConfigFilename
1551
+ });
1552
+ const maybeConfigFromDefault = findConfig({
1553
+ dir: defaultPackage,
1554
+ customConfigFilename
1524
1555
  });
1525
- const maybeConfigFromDefault = findConfig({ dir: defaultPackage });
1526
1556
  if (maybeConfigFromDefault) {
1527
1557
  return MicrofrontendsServer.fromFile({
1528
1558
  filePath: maybeConfigFromDefault,