Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Move from "var" to "const"/"let"
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Jan 15, 2018
1 parent e5fdc3a commit ac7a817
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
20 changes: 10 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node

var check = require('./')
const check = require('./')

var args = require('minimist')(process.argv.slice(2), {
const args = require('minimist')(process.argv.slice(2), {
default: {
missing: false,
extra: false,
Expand Down Expand Up @@ -44,10 +44,10 @@ if (args.help || args._.length === 0) {

function extensions (arg) {
if (!arg) return undefined
var extensions = {}
const extensions = {}

function add (value) {
var parts = value.trim().split(':', 2)
const parts = value.trim().split(':', 2)

parts[0].split(',').forEach(function (ext) {
extensions[ext.charAt(0) === '.' ? ext : '.' + ext] = parts[1]
Expand All @@ -71,16 +71,16 @@ check({
detective: args.detective
})
.then(data => {
var pkg = data.package
var deps = data.used
var failed = 0
var options = {
const pkg = data.package
const deps = data.used
let failed = 0
const options = {
excludeDev: args.dev === false,
excludePeer: args.peer === false,
ignore: [].concat(args.i || [])
}
if (args.extra) {
var extras = check.extra(pkg, deps, options)
const extras = check.extra(pkg, deps, options)
failed += extras.length
if (extras.length) {
console.error('Fail! Modules in package.json not used in code: ' + extras.join(', '))
Expand All @@ -89,7 +89,7 @@ check({
}
}
if (args.missing || !args.extra) {
var missing = check.missing(pkg, deps, options)
const missing = check.missing(pkg, deps, options)
failed += missing.length
if (missing.length) {
console.error('Fail! Dependencies not listed in package.json: ' + missing.join(', '))
Expand Down
68 changes: 34 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var path = require('path')
var fs = require('fs')
var readPackage = require('read-package-json')
var builtins = require('builtins')()
var resolveModule = require('resolve')
var debug = require('debug')('dependency-check')
var isRelative = require('is-relative')

var promisedReadPackage = function (pkgPath) {
const path = require('path')
const fs = require('fs')
const readPackage = require('read-package-json')
const builtins = require('builtins')()
const resolveModule = require('resolve')
const debug = require('debug')('dependency-check')
const isRelative = require('is-relative')

const promisedReadPackage = function (pkgPath) {
return new Promise((resolve, reject) => {
readPackage(pkgPath, (err, pkg) => {
if (err) return reject(err)
Expand All @@ -16,8 +16,8 @@ var promisedReadPackage = function (pkgPath) {
}

module.exports = function (opts, cb) {
var pkgPath = opts.path
var result = promisedReadPackage(pkgPath)
let pkgPath = opts.path
const result = promisedReadPackage(pkgPath)
.catch(err => {
if (err && err.code === 'EISDIR') {
pkgPath = path.join(pkgPath, 'package.json')
Expand Down Expand Up @@ -45,8 +45,8 @@ module.exports = function (opts, cb) {
}

module.exports.missing = function (pkg, deps, options) {
var missing = []
var config = configure(pkg, options)
const missing = []
const config = configure(pkg, options)

deps.map(used => {
if (config.allDeps.indexOf(used) === -1 && config.ignore.indexOf(used) === -1) {
Expand All @@ -58,8 +58,8 @@ module.exports.missing = function (pkg, deps, options) {
}

module.exports.extra = function (pkg, deps, options) {
var missing = []
var config = configure(pkg, options)
const missing = []
const config = configure(pkg, options)

config.allDeps.map(dep => {
if (deps.indexOf(dep) === -1 && config.ignore.indexOf(dep) === -1) {
Expand All @@ -84,7 +84,7 @@ function noopDetective () {

function getExtensions (extensions, detective) {
// Initialize extensions with node.js default handlers.
var result = {
const result = {
'.js': noopDetective,
'.node': noopDetective,
'.json': noopDetective
Expand Down Expand Up @@ -113,8 +113,8 @@ function getExtensions (extensions, detective) {
function configure (pkg, options) {
options = options || {}

var allDeps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}))
var ignore = options.ignore || []
let allDeps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}))
let ignore = options.ignore || []

if (typeof ignore === 'string') ignore = [ignore]

Expand All @@ -137,23 +137,23 @@ function isNotRelative (file) {
}

function parse (opts) {
var pkgPath = opts.path
var pkg = opts.package
var extensions = opts.extensions

var deps = {}
var paths = []
var seen = []
var core = []
var mainPath = path.resolve(pkg.main || path.join(path.dirname(pkgPath), 'index.js'))
const pkgPath = opts.path
const pkg = opts.package
const extensions = opts.extensions

const deps = {}
const paths = []
const seen = []
const core = []
const mainPath = path.resolve(pkg.main || path.join(path.dirname(pkgPath), 'index.js'))
if (!opts.noDefaultEntries && fs.existsSync(mainPath)) paths.push(mainPath)

if (!opts.noDefaultEntries && pkg.bin) {
if (typeof pkg.bin === 'string') {
paths.push(path.resolve(path.join(path.dirname(pkgPath), pkg.bin)))
} else {
Object.keys(pkg.bin).forEach(cmdName => {
var cmd = pkg.bin[cmdName]
const cmd = pkg.bin[cmdName]
paths.push(path.resolve(path.join(path.dirname(pkgPath), cmd)))
})
}
Expand All @@ -176,7 +176,7 @@ function parse (opts) {

return Promise.all(paths.map(file => resolveDep(file)))
.then(allDeps => {
var used = {}
const used = {}
// merge all deps into one unique list
allDeps.forEach(deps => {
Object.keys(deps).forEach(dep => {
Expand Down Expand Up @@ -207,8 +207,8 @@ function parse (opts) {
}

function getDeps (file) {
var ext = path.extname(file)
var detective = extensions[ext] || extensions['.js']
const ext = path.extname(file)
const detective = extensions[ext] || extensions['.js']

if (typeof detective !== 'function') {
return Promise.reject(new Error('Detective function missing for "' + file + '"'))
Expand All @@ -221,10 +221,10 @@ function parse (opts) {
})
})
.then(contents => {
var requires = detective(contents)
var relatives = []
const requires = detective(contents)
const relatives = []
requires.map(req => {
var isCore = builtins.indexOf(req) > -1
const isCore = builtins.indexOf(req) > -1
if (isNotRelative(req) && !isCore) {
// require('foo/bar') -> require('foo')
if (req[0] !== '@' && req.indexOf('/') > -1) req = req.split('/')[0]
Expand Down

0 comments on commit ac7a817

Please sign in to comment.