find.js 316 B

123456789101112131415
  1. const is = require('./is.js')
  2. const { dirname } = require('path')
  3. module.exports = async ({ cwd = process.cwd(), root } = {}) => {
  4. while (true) {
  5. if (await is({ cwd })) {
  6. return cwd
  7. }
  8. const next = dirname(cwd)
  9. if (cwd === root || cwd === next) {
  10. return null
  11. }
  12. cwd = next
  13. }
  14. }