* Searches the PATH environment variable for the given file. * @param {string} file The file to locate on the PATH. * @param {boolean=} opt_checkCwd Whether to always start with the search with * the current working directory, regardless of whether it is explicitly * listed on th
(file, opt_checkCwd)
| 208 | * not be found. |
| 209 | */ |
| 210 | function findInPath(file, opt_checkCwd) { |
| 211 | const dirs = [] |
| 212 | if (opt_checkCwd) { |
| 213 | dirs.push(process.cwd()) |
| 214 | } |
| 215 | dirs.push.apply(dirs, process.env['PATH'].split(path.delimiter)) |
| 216 | |
| 217 | let foundInDir = dirs.find((dir) => { |
| 218 | let tmp = path.join(dir, file) |
| 219 | try { |
| 220 | let stats = fs.statSync(tmp) |
| 221 | return stats.isFile() && !stats.isDirectory() |
| 222 | /*eslint no-unused-vars: "off"*/ |
| 223 | } catch (ex) { |
| 224 | return false |
| 225 | } |
| 226 | }) |
| 227 | |
| 228 | return foundInDir ? path.join(foundInDir, file) : null |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Reads the contents of the given file. |