1
- 'use strict' ;
2
1
'use babel' ;
3
2
4
- Object . defineProperty ( exports , "__esModule" , {
5
- value : true
6
- } ) ;
7
- exports . spawnWorker = spawnWorker ;
8
- exports . getModulesDirectory = getModulesDirectory ;
9
- exports . getIgnoresFile = getIgnoresFile ;
10
- exports . getEslintFromDirectory = getEslintFromDirectory ;
11
- exports . getNodePrefixPath = getNodePrefixPath ;
12
- exports . getBundledEslintDirectory = getBundledEslintDirectory ;
13
- exports . getEslintDirectory = getEslintDirectory ;
14
- exports . getEslintConfig = getEslintConfig ;
15
- exports . getEslint = getEslint ;
3
+ import Path from 'path' ;
4
+ import FS from 'fs' ;
5
+ import ChildProcess from 'child_process' ;
6
+ import CP from 'childprocess-promise' ;
7
+ import { findFile as find } from 'atom-linter' ;
16
8
17
- var _path = require ( 'path' ) ;
18
-
19
- var _path2 = _interopRequireDefault ( _path ) ;
20
-
21
- var _fs = require ( 'fs' ) ;
22
-
23
- var _fs2 = _interopRequireDefault ( _fs ) ;
24
-
25
- var _child_process = require ( 'child_process' ) ;
26
-
27
- var _child_process2 = _interopRequireDefault ( _child_process ) ;
28
-
29
- var _childprocessPromise = require ( 'childprocess-promise' ) ;
30
-
31
- var _childprocessPromise2 = _interopRequireDefault ( _childprocessPromise ) ;
32
-
33
- var _atomLinter = require ( 'atom-linter' ) ;
34
-
35
- function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
36
-
37
- function spawnWorker ( ) {
9
+ export function spawnWorker ( ) {
38
10
let shouldLive = true ;
39
11
const env = Object . create ( process . env ) ;
40
12
delete env . NODE_PATH ;
41
13
delete env . NODE_ENV ;
42
14
const data = { stdout : [ ] , stderr : [ ] } ;
43
- const child = _child_process2 . default . fork ( __dirname + '/worker.js' , [ ] , { env : env , silent : true } ) ;
44
- const worker = new _childprocessPromise2 . default ( child ) ;
15
+ const child = ChildProcess . fork ( __dirname + '/worker.js' , [ ] , { env, silent : true } ) ;
16
+ const worker = new CP ( child ) ;
45
17
function killer ( ) {
46
18
shouldLive = false ;
47
19
child . kill ( ) ;
@@ -60,23 +32,23 @@ function spawnWorker() {
60
32
child . emit ( 'exit-linter' , shouldLive ) ;
61
33
} ) ;
62
34
process . on ( 'exit' , killer ) ;
63
- return { child : child , worker : worker , subscription : { dispose : function ( ) {
35
+ return { child, worker, subscription : { dispose : function ( ) {
64
36
killer ( ) ;
65
37
process . removeListener ( 'exit' , killer ) ;
66
38
} } } ;
67
39
}
68
40
69
- function getModulesDirectory ( fileDir ) {
70
- return ( 0 , _atomLinter . findFile ) ( fileDir , 'node_modules' ) ;
41
+ export function getModulesDirectory ( fileDir ) {
42
+ return find ( fileDir , 'node_modules' ) ;
71
43
}
72
44
73
- function getIgnoresFile ( fileDir ) {
74
- return _path2 . default . dirname ( ( 0 , _atomLinter . findFile ) ( fileDir , '.eslintignore' ) ) ;
45
+ export function getIgnoresFile ( fileDir ) {
46
+ return Path . dirname ( find ( fileDir , '.eslintignore' ) ) ;
75
47
}
76
48
77
- function getEslintFromDirectory ( path ) {
49
+ export function getEslintFromDirectory ( path ) {
78
50
try {
79
- return require ( _path2 . default . join ( path , 'lib' , 'cli.js' ) ) ;
51
+ return require ( Path . join ( path , 'lib' , 'cli.js' ) ) ;
80
52
} catch ( e ) {
81
53
if ( e . code === 'MODULE_NOT_FOUND' ) {
82
54
throw new Error ( 'ESLint not found, Please install or make sure Atom is getting $PATH correctly' ) ;
@@ -86,11 +58,11 @@ function getEslintFromDirectory(path) {
86
58
87
59
let nodePrefixPath = null ;
88
60
89
- function getNodePrefixPath ( ) {
61
+ export function getNodePrefixPath ( ) {
90
62
if ( nodePrefixPath === null ) {
91
63
const npmCommand = process . platform === 'win32' ? 'npm.cmd' : 'npm' ;
92
64
try {
93
- nodePrefixPath = _child_process2 . default . spawnSync ( npmCommand , [ 'get' , 'prefix' ] ) . output [ 1 ] . toString ( ) . trim ( ) ;
65
+ nodePrefixPath = ChildProcess . spawnSync ( npmCommand , [ 'get' , 'prefix' ] ) . output [ 1 ] . toString ( ) . trim ( ) ;
94
66
} catch ( e ) {
95
67
throw new Error ( 'Unable to execute `npm get prefix`. Please make sure Atom is getting $PATH correctly' ) ;
96
68
}
@@ -100,41 +72,37 @@ function getNodePrefixPath() {
100
72
101
73
let bundledEslintDirectory = null ;
102
74
103
- function getBundledEslintDirectory ( ) {
75
+ export function getBundledEslintDirectory ( ) {
104
76
if ( bundledEslintDirectory === null ) {
105
- bundledEslintDirectory = _path2 . default . normalize ( _path2 . default . join ( __dirname , '..' , 'node_modules' , 'eslint' ) ) ;
77
+ bundledEslintDirectory = Path . normalize ( Path . join ( __dirname , '..' , 'node_modules' , 'eslint' ) ) ;
106
78
}
107
79
return bundledEslintDirectory ;
108
80
}
109
81
110
- function getEslintDirectory ( params ) {
111
- let modulesPath = arguments . length <= 1 || arguments [ 1 ] === undefined ? null : arguments [ 1 ] ;
112
-
82
+ export function getEslintDirectory ( params , modulesPath = null ) {
113
83
if ( params . global ) {
114
84
const prefixPath = getNodePrefixPath ( ) ;
115
85
if ( process . platform === 'win32' ) {
116
- return _path2 . default . join ( params . nodePath || prefixPath , 'node_modules' , 'eslint' ) ;
117
- } else {
118
- return _path2 . default . join ( params . nodePath || prefixPath , 'lib' , 'node_modules' , 'eslint' ) ;
119
- }
120
- } else {
121
- const eslintPath = _path2 . default . join ( modulesPath || getModulesDirectory ( params . fileDir ) , 'eslint' ) ;
122
- try {
123
- _fs2 . default . accessSync ( eslintPath , _fs2 . default . R_OK ) ;
124
- return eslintPath ;
125
- } catch ( _ ) {
126
- return getBundledEslintDirectory ( ) ;
86
+ return Path . join ( params . nodePath || prefixPath , 'node_modules' , 'eslint' ) ;
127
87
}
88
+ return Path . join ( params . nodePath || prefixPath , 'lib' , 'node_modules' , 'eslint' ) ;
89
+ }
90
+ const eslintPath = Path . join ( modulesPath || getModulesDirectory ( params . fileDir ) , 'eslint' ) ;
91
+ try {
92
+ FS . accessSync ( eslintPath , FS . R_OK ) ;
93
+ return eslintPath ;
94
+ } catch ( _ ) {
95
+ return getBundledEslintDirectory ( ) ;
128
96
}
129
97
}
130
98
131
- function getEslintConfig ( params ) {
132
- const configFile = ( 0 , _atomLinter . findFile ) ( params . fileDir , [ '.eslintrc.js' , '.eslintrc.yaml' , '.eslintrc.yml' , '.eslintrc.json' , '.eslintrc' ] ) || null ;
99
+ export function getEslintConfig ( params ) {
100
+ const configFile = find ( params . fileDir , [ '.eslintrc.js' , '.eslintrc.yaml' , '.eslintrc.yml' , '.eslintrc.json' , '.eslintrc' ] ) || null ;
133
101
if ( configFile ) {
134
102
return configFile ;
135
103
}
136
104
137
- const packagePath = ( 0 , _atomLinter . findFile ) ( params . fileDir , 'package.json' ) ;
105
+ const packagePath = find ( params . fileDir , 'package.json' ) ;
138
106
if ( packagePath && Boolean ( require ( packagePath ) . eslintConfig ) ) {
139
107
return packagePath ;
140
108
}
@@ -152,7 +120,7 @@ let eslint;
152
120
let lastEslintDirectory ;
153
121
let lastModulesPath ;
154
122
155
- function getEslint ( params ) {
123
+ export function getEslint ( params ) {
156
124
const modulesPath = getModulesDirectory ( params . fileDir ) ;
157
125
const eslintDirectory = getEslintDirectory ( params , modulesPath ) ;
158
126
if ( eslintDirectory !== lastEslintDirectory ) {
@@ -166,5 +134,5 @@ function getEslint(params) {
166
134
} else process . env . NODE_PATH = '' ;
167
135
require ( 'module' ) . Module . _initPaths ( ) ;
168
136
}
169
- return { eslint : eslint , eslintDirectory : eslintDirectory } ;
137
+ return { eslint, eslintDirectory } ;
170
138
}
0 commit comments