Browse Source

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

pull/7666/head
xingyu4j 1 week ago
parent
commit
70dad0f600
  1. 25
      internal/node-utils/src/monorepo.ts

25
internal/node-utils/src/monorepo.ts

@ -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;
}
}
/**

Loading…
Cancel
Save