2022-08-17 14:18:33 +00:00
|
|
|
import {existsSync} from 'fs';
|
|
|
|
import {dirname, join, parse} from 'path';
|
|
|
|
|
2022-08-31 12:42:53 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2022-08-17 14:18:33 +00:00
|
|
|
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;
|
|
|
|
};
|