UNPKG

770 BJavaScriptView Raw
1#!/usr/bin/env node
2
3const fs = require('fs')
4const path = require('path');
5
6const binPath = path.join('node_modules', 'eslint', 'bin', 'eslint.js');
7
8const fileExists = function (path) {
9 let exists;
10 try {
11 fs.accessSync(path, fs.F_OK);
12 exists = true;
13 } catch (e) {
14 exists = false;
15 }
16 return exists;
17};
18
19const findBin = function (search) {
20 const searchPath = path.join(search, binPath);
21 const exists = fileExists(searchPath);
22 if (!exists) {
23 const nextSearchPath = path.join(search, '..');
24 if (nextSearchPath === '/') return null;
25 return findBin(nextSearchPath);
26 }
27 return searchPath;
28};
29
30const bin = findBin(__dirname);
31if (!bin) throw new Error(`Unable to find ESLint executable. Did you run 'npm install'?`);
32
33module.exports = require(bin);
\No newline at end of file