fix(node-utils): avoid find-up sync API in monorepo root lookup
parent
26e9aa244b
commit
70dad0f600
|
|
@ -1,24 +1,31 @@
|
||||||
import type { Package } from '@manypkg/get-packages';
|
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 manypkg from '@manypkg/get-packages';
|
||||||
import * as findUp from 'find-up';
|
|
||||||
|
|
||||||
const { getPackages: getPackagesFunc, getPackagesSync: getPackagesSyncFunc } =
|
const { getPackages: getPackagesFunc, getPackagesSync: getPackagesSyncFunc } =
|
||||||
manypkg;
|
manypkg;
|
||||||
const { findUpSync } = findUp;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找大仓的根目录
|
* 查找大仓的根目录
|
||||||
* @param cwd
|
* @param cwd
|
||||||
*/
|
*/
|
||||||
function findMonorepoRoot(cwd: string = process.cwd()) {
|
function findMonorepoRoot(cwd: string = process.cwd()) {
|
||||||
const lockFile = findUpSync('pnpm-lock.yaml', {
|
let currentDir = resolve(cwd);
|
||||||
cwd,
|
|
||||||
type: 'file',
|
while (true) {
|
||||||
});
|
if (existsSync(join(currentDir, 'pnpm-lock.yaml'))) {
|
||||||
return dirname(lockFile || '');
|
return currentDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parentDir = dirname(currentDir);
|
||||||
|
if (parentDir === currentDir) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDir = parentDir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue