index.js 380 B

123456789101112
  1. import path from 'node:path';
  2. import {findUp, findUpSync} from 'find-up';
  3. export async function packageDirectory({cwd} = {}) {
  4. const filePath = await findUp('package.json', {cwd});
  5. return filePath && path.dirname(filePath);
  6. }
  7. export function packageDirectorySync({cwd} = {}) {
  8. const filePath = findUpSync('package.json', {cwd});
  9. return filePath && path.dirname(filePath);
  10. }