UNPKG

450 BJavaScriptView Raw
1/* eslint import/no-commonjs:0 no-useless-escape:0*/
2
3const path = require('path')
4
5const findNodeModules = (start) => {
6 const inner = (p) => {
7 if (path.dirname(p) === p) {
8 // root
9 throw new Error('Cannot find node modules directory')
10 } else {
11 return path.basename(p) === 'node_modules' ? p : inner(path.dirname(p))
12 }
13 }
14 return inner(start)
15}
16
17module.exports = {findNodeModules}