blob: a115be14b00427112d98e464a5823b89caa9e47e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
const { resolve } = require('path')
const { promisify } = require('util')
const stat = promisify(require('fs').stat)
const walkUp = require('walk-up-path')
const fileExists = (file) => stat(file)
.then((stat) => stat.isFile())
.catch(() => false)
const localFileExists = async (dir, binName, root = '/') => {
root = resolve(root).toLowerCase()
for (const path of walkUp(resolve(dir))) {
const binDir = resolve(path, 'node_modules', '.bin')
if (await fileExists(resolve(binDir, binName)))
return binDir
if (path.toLowerCase() === root)
return false
}
return false
}
module.exports = {
fileExists,
localFileExists,
}
|