1
- var path = require ( 'path' )
2
- var fs = require ( 'fs' )
3
- var readPackage = require ( 'read-package-json' )
4
- var builtins = require ( 'builtins' ) ( )
5
- var resolveModule = require ( 'resolve' )
6
- var debug = require ( 'debug' ) ( 'dependency-check' )
7
- var isRelative = require ( 'is-relative' )
8
-
9
- var promisedReadPackage = function ( pkgPath ) {
1
+ const path = require ( 'path' )
2
+ const fs = require ( 'fs' )
3
+ const readPackage = require ( 'read-package-json' )
4
+ const builtins = require ( 'builtins' ) ( )
5
+ const resolveModule = require ( 'resolve' )
6
+ const debug = require ( 'debug' ) ( 'dependency-check' )
7
+ const isRelative = require ( 'is-relative' )
8
+
9
+ const promisedReadPackage = function ( pkgPath ) {
10
10
return new Promise ( ( resolve , reject ) => {
11
11
readPackage ( pkgPath , ( err , pkg ) => {
12
12
if ( err ) return reject ( err )
@@ -16,8 +16,8 @@ var promisedReadPackage = function (pkgPath) {
16
16
}
17
17
18
18
module . exports = function ( opts , cb ) {
19
- var pkgPath = opts . path
20
- var result = promisedReadPackage ( pkgPath )
19
+ let pkgPath = opts . path
20
+ const result = promisedReadPackage ( pkgPath )
21
21
. catch ( err => {
22
22
if ( err && err . code === 'EISDIR' ) {
23
23
pkgPath = path . join ( pkgPath , 'package.json' )
@@ -45,8 +45,8 @@ module.exports = function (opts, cb) {
45
45
}
46
46
47
47
module . exports . missing = function ( pkg , deps , options ) {
48
- var missing = [ ]
49
- var config = configure ( pkg , options )
48
+ const missing = [ ]
49
+ const config = configure ( pkg , options )
50
50
51
51
deps . map ( used => {
52
52
if ( config . allDeps . indexOf ( used ) === - 1 && config . ignore . indexOf ( used ) === - 1 ) {
@@ -58,8 +58,8 @@ module.exports.missing = function (pkg, deps, options) {
58
58
}
59
59
60
60
module . exports . extra = function ( pkg , deps , options ) {
61
- var missing = [ ]
62
- var config = configure ( pkg , options )
61
+ const missing = [ ]
62
+ const config = configure ( pkg , options )
63
63
64
64
config . allDeps . map ( dep => {
65
65
if ( deps . indexOf ( dep ) === - 1 && config . ignore . indexOf ( dep ) === - 1 ) {
@@ -84,7 +84,7 @@ function noopDetective () {
84
84
85
85
function getExtensions ( extensions , detective ) {
86
86
// Initialize extensions with node.js default handlers.
87
- var result = {
87
+ const result = {
88
88
'.js' : noopDetective ,
89
89
'.node' : noopDetective ,
90
90
'.json' : noopDetective
@@ -113,8 +113,8 @@ function getExtensions (extensions, detective) {
113
113
function configure ( pkg , options ) {
114
114
options = options || { }
115
115
116
- var allDeps = Object . keys ( pkg . dependencies || { } ) . concat ( Object . keys ( pkg . peerDependencies || { } ) )
117
- var ignore = options . ignore || [ ]
116
+ let allDeps = Object . keys ( pkg . dependencies || { } ) . concat ( Object . keys ( pkg . peerDependencies || { } ) )
117
+ let ignore = options . ignore || [ ]
118
118
119
119
if ( typeof ignore === 'string' ) ignore = [ ignore ]
120
120
@@ -137,23 +137,23 @@ function isNotRelative (file) {
137
137
}
138
138
139
139
function parse ( opts ) {
140
- var pkgPath = opts . path
141
- var pkg = opts . package
142
- var extensions = opts . extensions
143
-
144
- var deps = { }
145
- var paths = [ ]
146
- var seen = [ ]
147
- var core = [ ]
148
- var mainPath = path . resolve ( pkg . main || path . join ( path . dirname ( pkgPath ) , 'index.js' ) )
140
+ const pkgPath = opts . path
141
+ const pkg = opts . package
142
+ const extensions = opts . extensions
143
+
144
+ const deps = { }
145
+ const paths = [ ]
146
+ const seen = [ ]
147
+ const core = [ ]
148
+ const mainPath = path . resolve ( pkg . main || path . join ( path . dirname ( pkgPath ) , 'index.js' ) )
149
149
if ( ! opts . noDefaultEntries && fs . existsSync ( mainPath ) ) paths . push ( mainPath )
150
150
151
151
if ( ! opts . noDefaultEntries && pkg . bin ) {
152
152
if ( typeof pkg . bin === 'string' ) {
153
153
paths . push ( path . resolve ( path . join ( path . dirname ( pkgPath ) , pkg . bin ) ) )
154
154
} else {
155
155
Object . keys ( pkg . bin ) . forEach ( cmdName => {
156
- var cmd = pkg . bin [ cmdName ]
156
+ const cmd = pkg . bin [ cmdName ]
157
157
paths . push ( path . resolve ( path . join ( path . dirname ( pkgPath ) , cmd ) ) )
158
158
} )
159
159
}
@@ -176,7 +176,7 @@ function parse (opts) {
176
176
177
177
return Promise . all ( paths . map ( file => resolveDep ( file ) ) )
178
178
. then ( allDeps => {
179
- var used = { }
179
+ const used = { }
180
180
// merge all deps into one unique list
181
181
allDeps . forEach ( deps => {
182
182
Object . keys ( deps ) . forEach ( dep => {
@@ -207,8 +207,8 @@ function parse (opts) {
207
207
}
208
208
209
209
function getDeps ( file ) {
210
- var ext = path . extname ( file )
211
- var detective = extensions [ ext ] || extensions [ '.js' ]
210
+ const ext = path . extname ( file )
211
+ const detective = extensions [ ext ] || extensions [ '.js' ]
212
212
213
213
if ( typeof detective !== 'function' ) {
214
214
return Promise . reject ( new Error ( 'Detective function missing for "' + file + '"' ) )
@@ -221,10 +221,10 @@ function parse (opts) {
221
221
} )
222
222
} )
223
223
. then ( contents => {
224
- var requires = detective ( contents )
225
- var relatives = [ ]
224
+ const requires = detective ( contents )
225
+ const relatives = [ ]
226
226
requires . map ( req => {
227
- var isCore = builtins . indexOf ( req ) > - 1
227
+ const isCore = builtins . indexOf ( req ) > - 1
228
228
if ( isNotRelative ( req ) && ! isCore ) {
229
229
// require('foo/bar') -> require('foo')
230
230
if ( req [ 0 ] !== '@' && req . indexOf ( '/' ) > - 1 ) req = req . split ( '/' ) [ 0 ]
0 commit comments