Skip to content

Commit

Permalink
fix(metro-config): handle apps in nested folders (#2995)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Mar 11, 2024
1 parent 8033573 commit 3f48b88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-gorillas-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/metro-config": patch
---

Handle apps in nested folders
19 changes: 12 additions & 7 deletions packages/metro-config/src/defaultConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
const { findUp } = require("@rnx-kit/tools-node/path");
const { requireModuleFromMetro } = require("@rnx-kit/tools-react-native/metro");
const fs = require("fs");
const path = require("path");

/**
* @typedef {import("metro-config").MetroConfig} MetroConfig;
Expand Down Expand Up @@ -104,10 +104,14 @@ function outOfTreePlatformResolver(implementations, projectRoot) {
* @returns {MetroConfig[]}
*/
function getDefaultConfig(projectRoot) {
try {
const pkgJson = path.join(projectRoot, "package.json");
const manifest = fs.readFileSync(pkgJson, { encoding: "utf-8" });
if (manifest.includes("@react-native/metro-config")) {
const pkgJson = findUp("package.json", { startDir: projectRoot });
if (!pkgJson) {
return [];
}

const manifest = fs.readFileSync(pkgJson, { encoding: "utf-8" });
if (manifest.includes("@react-native/metro-config")) {
try {
const metroConfigPath = require.resolve("@react-native/metro-config", {
paths: [projectRoot],
});
Expand All @@ -129,10 +133,11 @@ function getDefaultConfig(projectRoot) {
};

return [defaultConfig];
} catch (_) {
// Ignore
}
} catch (_) {
// Ignore
}

return [];
}

Expand Down

0 comments on commit 3f48b88

Please sign in to comment.