@vercel/microfrontends 1.4.0 → 1.4.2

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,5 +1,18 @@
1
1
  # @vercel/microfrontends
2
2
 
3
+ ## 1.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - df9826a: Improve repository root inference for CLI deployments. For repositories missing `.git` and `pnpm-workspace.yaml`, `@vercel/microfrontends` will now use the directory
8
+ closest to the root that contains a `package.json` as the root of the repository.
9
+
10
+ ## 1.4.1
11
+
12
+ ### Patch Changes
13
+
14
+ - 10b74ed: Route next/image requests to the correct microfrontends application in the local development proxy.
15
+
3
16
  ## 1.4.0
4
17
 
5
18
  ### Minor Changes
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: "1.4.0",
33
+ version: "1.4.2",
34
34
  private: false,
35
35
  description: "Defines configuration and utilities for microfrontends development",
36
36
  keywords: [
@@ -1057,17 +1057,27 @@ function hasGitDirectory(dir) {
1057
1057
  function hasPnpmWorkspaces(dir) {
1058
1058
  return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
1059
1059
  }
1060
+ function hasPackageJson(dir) {
1061
+ return import_node_fs.default.existsSync(import_node_path.default.join(dir, "package.json"));
1062
+ }
1060
1063
  function findRepositoryRoot(startDir) {
1061
1064
  if (process.env.NX_WORKSPACE_ROOT) {
1062
1065
  return process.env.NX_WORKSPACE_ROOT;
1063
1066
  }
1064
1067
  let currentDir = startDir || process.cwd();
1068
+ let lastPackageJsonDir = null;
1065
1069
  while (currentDir !== import_node_path.default.parse(currentDir).root) {
1066
1070
  if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
1067
1071
  return currentDir;
1068
1072
  }
1073
+ if (hasPackageJson(currentDir)) {
1074
+ lastPackageJsonDir = currentDir;
1075
+ }
1069
1076
  currentDir = import_node_path.default.dirname(currentDir);
1070
1077
  }
1078
+ if (lastPackageJsonDir) {
1079
+ return lastPackageJsonDir;
1080
+ }
1071
1081
  throw new Error(
1072
1082
  `Could not find the root of the repository for ${startDir}. Please ensure that the directory is part of a Git repository. If you suspect that this should work, please file an issue to the Vercel team.`
1073
1083
  );
@@ -2175,7 +2185,7 @@ var ProxyRequestRouter = class {
2175
2185
  path: path7,
2176
2186
  url,
2177
2187
  app: application
2178
- }) || this.checkNextOriginalFrame({ url, referer, applications }) || this.checkNextSourceMap({ url });
2188
+ }) || this.checkNextOriginalFrame({ url, referer, applications }) || this.checkNextSourceMap({ url }) || this.checkNextImage({ url, applications });
2179
2189
  if (builtInRewrite) {
2180
2190
  return builtInRewrite;
2181
2191
  }
@@ -2261,9 +2271,7 @@ var ProxyRequestRouter = class {
2261
2271
  path: `${url.pathname}${url.search}`
2262
2272
  } : null;
2263
2273
  }
2264
- checkNextSourceMap({
2265
- url
2266
- }) {
2274
+ checkNextSourceMap({ url }) {
2267
2275
  const isSourceMap = (0, import_path_to_regexp3.pathToRegexp)("/__nextjs_source-map").test(url.pathname);
2268
2276
  if (!isSourceMap) {
2269
2277
  return null;
@@ -2280,6 +2288,32 @@ var ProxyRequestRouter = class {
2280
2288
  path: `${url.pathname}${url.search}`
2281
2289
  };
2282
2290
  }
2291
+ checkNextImage({
2292
+ url,
2293
+ applications
2294
+ }) {
2295
+ const isNextImage = (0, import_path_to_regexp3.pathToRegexp)("/_next/image").test(url.pathname);
2296
+ if (!isNextImage) {
2297
+ return null;
2298
+ }
2299
+ const imageUrl = url.searchParams.get("url");
2300
+ if (!imageUrl) {
2301
+ mfeDebug("no url parameter found in _next/image request");
2302
+ return null;
2303
+ }
2304
+ const decodedPath = decodeURIComponent(imageUrl);
2305
+ const imageURL = new import_node_url.URL(`http://example.com${decodedPath}`);
2306
+ const imageApp = this.findMatchingApplication({
2307
+ path: decodedPath,
2308
+ url: imageURL,
2309
+ applications
2310
+ });
2311
+ mfeDebug(`routing nextjs image request to ${imageApp?.application}`);
2312
+ return imageApp ? {
2313
+ ...imageApp,
2314
+ path: `${url.pathname}${url.search}`
2315
+ } : null;
2316
+ }
2283
2317
  isDefaultAppLocal() {
2284
2318
  const defaultApp = this.config.getDefaultApplication();
2285
2319
  return Boolean(
@@ -200,17 +200,27 @@ function hasGitDirectory(dir) {
200
200
  function hasPnpmWorkspaces(dir) {
201
201
  return import_node_fs.default.existsSync(import_node_path.default.join(dir, "pnpm-workspace.yaml"));
202
202
  }
203
+ function hasPackageJson(dir) {
204
+ return import_node_fs.default.existsSync(import_node_path.default.join(dir, "package.json"));
205
+ }
203
206
  function findRepositoryRoot(startDir) {
204
207
  if (process.env.NX_WORKSPACE_ROOT) {
205
208
  return process.env.NX_WORKSPACE_ROOT;
206
209
  }
207
210
  let currentDir = startDir || process.cwd();
211
+ let lastPackageJsonDir = null;
208
212
  while (currentDir !== import_node_path.default.parse(currentDir).root) {
209
213
  if (hasGitDirectory(currentDir) || hasPnpmWorkspaces(currentDir)) {
210
214
  return currentDir;
211
215
  }
216
+ if (hasPackageJson(currentDir)) {
217
+ lastPackageJsonDir = currentDir;
218
+ }
212
219
  currentDir = import_node_path.default.dirname(currentDir);
213
220
  }
221
+ if (lastPackageJsonDir) {
222
+ return lastPackageJsonDir;
223
+ }
214
224
  throw new Error(
215
225
  `Could not find the root of the repository for ${startDir}. Please ensure that the directory is part of a Git repository. If you suspect that this should work, please file an issue to the Vercel team.`
216
226
  );