fix(utils): fix cross-platform root detection in findPackageRoot
Improve the findPackageRoot function to correctly detect filesystem root on all platforms by checking if dirname returns the same path, replacing the Unix-specific '/' check.
This commit is contained in:
@@ -41,12 +41,17 @@ export function extractModulePath(error) {
|
|||||||
export function findPackageRoot(nodeFilePath) {
|
export function findPackageRoot(nodeFilePath) {
|
||||||
// Walk up from the .node file to find package.json
|
// Walk up from the .node file to find package.json
|
||||||
let dir = dirname(nodeFilePath);
|
let dir = dirname(nodeFilePath);
|
||||||
while (dir && dir !== '/') {
|
while (dir) {
|
||||||
const packageJsonPath = join(dir, 'package.json');
|
const packageJsonPath = join(dir, 'package.json');
|
||||||
if (existsSync(packageJsonPath)) {
|
if (existsSync(packageJsonPath)) {
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
dir = dirname(dir);
|
const parentDir = dirname(dir);
|
||||||
|
// Stop when we've reached the filesystem root (dirname returns same path)
|
||||||
|
if (parentDir === dir) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dir = parentDir;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user