blob: d0c5fc4cad2a1386d91d8a151e7cda21e11a9d61 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import {existsSync} from 'fs';
import {dirname, join, parse} from 'path';
/**
* @internal
*/
export const getPackageDirectory = (from: string): string => {
let found = existsSync(join(from, 'package.json'));
const root = parse(from).root;
while (!found) {
if (from === root) {
throw new Error('Cannot find package directory');
}
from = dirname(from);
found = existsSync(join(from, 'package.json'));
}
return from;
};
|