fix(node-utils): avoid find-up sync API in monorepo root lookup

vite8^2
xingyu4j 2026-03-15 20:50:07 +08:00
parent 26e9aa244b
commit 70dad0f600
1 changed files with 16 additions and 9 deletions

View File

@ -1,24 +1,31 @@
import type { Package } from '@manypkg/get-packages';
import { dirname } from 'node:path';
import { existsSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import * as manypkg from '@manypkg/get-packages';
import * as findUp from 'find-up';
const { getPackages: getPackagesFunc, getPackagesSync: getPackagesSyncFunc } =
manypkg;
const { findUpSync } = findUp;
/**
*
* @param cwd
*/
function findMonorepoRoot(cwd: string = process.cwd()) {
const lockFile = findUpSync('pnpm-lock.yaml', {
cwd,
type: 'file',
});
return dirname(lockFile || '');
let currentDir = resolve(cwd);
while (true) {
if (existsSync(join(currentDir, 'pnpm-lock.yaml'))) {
return currentDir;
}
const parentDir = dirname(currentDir);
if (parentDir === currentDir) {
return '';
}
currentDir = parentDir;
}
}
/**