New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

depcheck

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

depcheck - npm Package Compare versions

Comparing version

to
0.7.0-beta.1

dist/check.js

95

dist/cli.js

@@ -6,7 +6,2 @@ 'use strict';

});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = cli;

@@ -26,2 +21,6 @@

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _index = require('./index');

@@ -31,6 +30,2 @@

var _output = require('./utils/output');
var _output2 = _interopRequireDefault(_output);
var _package = require('../package.json');

@@ -40,10 +35,6 @@

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function checkPathExist(dir) {
function checkPathExist(dir, errorMessage) {
return new Promise(function (resolve, reject) {
return _fs2.default.exists(dir, function (result) {
return result ? resolve() : reject();
return result ? resolve() : reject(errorMessage);
});

@@ -54,18 +45,13 @@ });

function getParsers(parsers) {
return typeof parsers === 'undefined' ? undefined : _extends.apply(undefined, [{}].concat(_toConsumableArray(parsers.split(',').map(function (keyValuePair) {
var _keyValuePair$split = keyValuePair.split(':');
var _keyValuePair$split2 = _slicedToArray(_keyValuePair$split, 2);
var glob = _keyValuePair$split2[0];
var value = _keyValuePair$split2[1];
return _defineProperty({}, glob, value.split('&').map(function (name) {
return _lodash2.default.isUndefined(parsers) ? undefined : (0, _lodash2.default)(parsers).split(',').map(function (keyValuePair) {
return keyValuePair.split(':');
}).fromPairs().mapValues(function (value) {
return value.split('&').map(function (name) {
return _index2.default.parser[name];
}));
}))));
});
}).value();
}
function getDetectors(detectors) {
return typeof detectors === 'undefined' ? undefined : detectors.split(',').map(function (name) {
return _lodash2.default.isUndefined(detectors) ? undefined : detectors.split(',').map(function (name) {
return _index2.default.detector[name];

@@ -76,3 +62,3 @@ });

function getSpecials(specials) {
return typeof specials === 'undefined' ? undefined : specials.split(',').map(function (name) {
return _lodash2.default.isUndefined(specials) ? undefined : specials.split(',').map(function (name) {
return _index2.default.special[name];

@@ -82,2 +68,31 @@ });

function noIssue(result) {
return _lodash2.default.isEmpty(result.dependencies) && _lodash2.default.isEmpty(result.devDependencies) && _lodash2.default.isEmpty(result.missing);
}
function prettify(caption, deps) {
var list = deps.map(function (dep) {
return '* ' + dep;
});
return list.length ? [caption].concat(list) : [];
}
function print(result, log, json) {
if (json) {
log(JSON.stringify(result, function (key, value) {
return _lodash2.default.isError(value) ? value.stack : value;
}));
} else if (noIssue(result)) {
log('No depcheck issue');
} else {
var deps = prettify('Unused dependencies', result.dependencies);
var devDeps = prettify('Unused devDependencies', result.devDependencies);
var missing = prettify('Missing dependencies', Object.keys(result.missing));
var content = deps.concat(devDeps, missing).join('\n');
log(content);
}
return result;
}
function cli(args, log, error, exit) {

@@ -92,12 +107,5 @@ var opt = (0, _yargs2.default)(args).usage('Usage: $0 [DIRECTORY]').boolean(['dev', 'ignore-bin-package']).default({

checkPathExist(rootDir).catch(function () {
error('Path ' + dir + ' does not exist');
exit(-1);
checkPathExist(rootDir, 'Path ' + dir + ' does not exist').then(function () {
return checkPathExist(_path2.default.resolve(rootDir, 'package.json'), 'Path ' + dir + ' does not contain a package.json file');
}).then(function () {
return checkPathExist(_path2.default.resolve(rootDir, 'package.json'));
}).catch(function () {
error('Path ' + dir + ' does not contain a package.json file');
log(opt.getUsageInstance().help());
exit(-1);
}).then(function () {
return (0, _index2.default)(rootDir, {

@@ -113,9 +121,12 @@ withoutDev: !opt.argv.dev,

}).then(function (result) {
return (0, _output2.default)(result, log, opt.argv.json);
}).then(function (_ref2) {
var dependencies = _ref2.dependencies;
var devDependencies = _ref2.devDependencies;
return exit(opt.argv.json || dependencies.length === 0 && devDependencies.length === 0 ? 0 : -1);
return print(result, log, opt.argv.json);
}).then(function (_ref) {
var deps = _ref.dependencies;
var devDeps = _ref.devDependencies;
return exit(opt.argv.json || deps.length === 0 && devDeps.length === 0 ? 0 : -1);
}).catch(function (errorMessage) {
error(errorMessage);
exit(-1);
});
}
module.exports = exports['default'];

@@ -6,7 +6,6 @@ 'use strict';

});
exports.default = function (node) {
exports.default = detectGruntLoadTaskCallExpression;
function detectGruntLoadTaskCallExpression(node) {
return node.type === 'CallExpression' && node.callee && node.callee.property && node.callee.property.name === 'loadNpmTasks' && node.arguments[0] ? [node.arguments[0].value] : [];
};
}
module.exports = exports['default'];

@@ -6,7 +6,6 @@ 'use strict';

});
exports.default = function (node) {
exports.default = detectImportDeclaration;
function detectImportDeclaration(node) {
return node.type === 'ImportDeclaration' && node.source && node.source.value ? [node.source.value] : [];
};
}
module.exports = exports['default'];

@@ -6,7 +6,13 @@ 'use strict';

});
exports.default = detectRequireCallExpression;
exports.default = function (node) {
return node.type === 'CallExpression' && node.callee && node.callee.type === 'Identifier' && node.callee.name === 'require' && node.arguments[0] && typeof node.arguments[0].value === 'string' ? [node.arguments[0].value] : [];
};
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function detectRequireCallExpression(node) {
return node.type === 'CallExpression' && node.callee && node.callee.type === 'Identifier' && node.callee.name === 'require' && node.arguments[0] && _lodash2.default.isString(node.arguments[0].value) ? [node.arguments[0].value] : [];
}
module.exports = exports['default'];

@@ -6,11 +6,4 @@ 'use strict';

});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = depcheck;
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _path = require('path');

@@ -20,5 +13,5 @@

var _walkdir = require('walkdir');
var _lodash = require('lodash');
var _walkdir2 = _interopRequireDefault(_walkdir);
var _lodash2 = _interopRequireDefault(_lodash);

@@ -29,220 +22,11 @@ var _minimatch = require('minimatch');

var _builtinModules = require('builtin-modules');
var _check = require('./check');
var _builtinModules2 = _interopRequireDefault(_builtinModules);
var _constants = require('./constants');
var _requirePackageName = require('require-package-name');
var _requirePackageName2 = _interopRequireDefault(_requirePackageName);
var _component = require('./component');
var _component2 = _interopRequireDefault(_component);
var _getNodes = require('./utils/get-nodes');
var _getNodes2 = _interopRequireDefault(_getNodes);
var _discoverPropertyDep = require('./utils/discover-property-dep');
var _discoverPropertyDep2 = _interopRequireDefault(_discoverPropertyDep);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function constructComponent(source, name) {
return source[name].reduce(function (result, current) {
return _extends(result, _defineProperty({}, current, require(_path2.default.resolve(__dirname, name, current))));
}, {});
}
function objectValues(object) {
return Object.keys(object).map(function (key) {
return object[key];
});
}
var availableParsers = constructComponent(_component2.default, 'parser');
var availableDetectors = constructComponent(_component2.default, 'detector');
var availableSpecials = constructComponent(_component2.default, 'special');
var defaultOptions = {
withoutDev: false,
ignoreBinPackage: false,
ignoreMatches: [],
ignoreDirs: ['.git', '.svn', '.hg', '.idea', 'node_modules', 'bower_components'],
parsers: {
'*.js': availableParsers.jsx,
'*.jsx': availableParsers.jsx,
'*.coffee': availableParsers.coffee,
'*.litcoffee': availableParsers.coffee,
'*.coffee.md': availableParsers.coffee
},
detectors: [availableDetectors.importDeclaration, availableDetectors.requireCallExpression, availableDetectors.gruntLoadTaskCallExpression],
specials: objectValues(availableSpecials)
};
function getOrDefault(opt, key) {
return typeof opt[key] !== 'undefined' ? opt[key] : defaultOptions[key];
}
function unifyParser(parsers) {
return _extends.apply(undefined, [{}].concat(_toConsumableArray(Object.keys(parsers).map(function (key) {
return _defineProperty({}, key, parsers[key] instanceof Array ? parsers[key] : [parsers[key]]);
}))));
}
function safeDetect(detector, node) {
try {
return detector(node);
} catch (error) {
return [];
}
}
function minus(array1, array2) {
return array1.filter(function (item) {
return array2.indexOf(item) === -1;
});
}
function unique(array, item) {
return array.indexOf(item) === -1 ? array.concat([item]) : array;
}
function concat(array, item) {
return array.concat(item);
}
function isStringArray(obj) {
return obj instanceof Array && obj.every(function (item) {
return typeof item === 'string';
});
}
function isNpmPackage(dep) {
return dep && dep !== '.' && dep !== '..' && _builtinModules2.default.indexOf(dep) === -1;
}
function isModule(dir) {
try {
require(_path2.default.resolve(dir, 'package.json'));
return true;
} catch (error) {
return false;
}
}
function mergeBuckets(object1, object2) {
return Object.keys(object2).reduce(function (result, key) {
return _extends({}, result, _defineProperty({}, key, object2[key].concat(object1[key] || [])));
}, object1);
}
function getDependencies(dir, filename, deps, parser, detectors) {
var detect = function detect(node) {
return detectors.map(function (detector) {
return safeDetect(detector, node);
}).reduce(concat, []);
};
return new Promise(function (resolve, reject) {
_fs2.default.readFile(filename, 'utf8', function (error, content) {
if (error) {
reject(error);
}
try {
resolve(parser(content, filename, deps, dir));
} catch (syntaxError) {
reject(syntaxError);
}
});
}).then(function (ast) {
// when parser returns string array, skip detector step and treat them as dependencies directly.
if (isStringArray(ast)) {
return ast;
}
var dependencies = (0, _getNodes2.default)(ast).map(detect).reduce(concat, []).reduce(unique, []).map(_requirePackageName2.default);
var peerDeps = dependencies.map(function (dep) {
return (0, _discoverPropertyDep2.default)(dep, 'peerDependencies', deps, dir);
}).reduce(concat, []);
var optionalDeps = dependencies.map(function (dep) {
return (0, _discoverPropertyDep2.default)(dep, 'optionalDependencies', deps, dir);
}).reduce(concat, []);
return dependencies.concat(peerDeps).concat(optionalDeps);
});
}
function checkFile(dir, filename, deps, parsers, detectors) {
var basename = _path2.default.basename(filename);
var targets = Object.keys(parsers).filter(function (glob) {
return (0, _minimatch2.default)(basename, glob, { dot: true });
}).map(function (key) {
return parsers[key];
}).reduce(concat, []);
return targets.map(function (parser) {
return getDependencies(dir, filename, deps, parser, detectors).then(function (using) {
return {
using: _defineProperty({}, filename, using.filter(isNpmPackage).reduce(unique, []))
};
}, function (error) {
return {
invalidFiles: _defineProperty({}, filename, error)
};
});
});
}
function checkDirectory(dir, rootDir, ignoreDirs, deps, parsers, detectors) {
return new Promise(function (resolve) {
var promises = [];
var finder = (0, _walkdir2.default)(dir, { no_recurse: true });
finder.on('directory', function (subdir) {
return ignoreDirs.indexOf(_path2.default.basename(subdir)) === -1 && !isModule(subdir) ? promises.push(checkDirectory(subdir, rootDir, ignoreDirs, deps, parsers, detectors)) : null;
});
finder.on('file', function (filename) {
return promises.push.apply(promises, _toConsumableArray(checkFile(rootDir, filename, deps, parsers, detectors)));
});
finder.on('error', function (dirPath, error) {
return promises.push(Promise.resolve({
invalidDirs: _defineProperty({}, dirPath, error)
}));
});
finder.on('end', function () {
return resolve(Promise.all(promises).then(function (results) {
return results.reduce(function (obj, current) {
return {
using: mergeBuckets(obj.using, current.using || {}),
invalidFiles: _extends(obj.invalidFiles, current.invalidFiles),
invalidDirs: _extends(obj.invalidDirs, current.invalidDirs)
};
}, {
using: {},
invalidFiles: {},
invalidDirs: {}
});
}));
});
});
}
function isIgnored(ignoreMatches, dependency) {
return ignoreMatches.some(function (match) {
return (0, _minimatch2.default)(dependency, match);
});
var match = _lodash2.default.partial(_minimatch2.default, dependency);
return ignoreMatches.some(match);
}

@@ -260,39 +44,21 @@

function filterDependencies(rootDir, ignoreBinPackage, ignoreMatches, dependencies) {
return Object.keys(dependencies).filter(function (dependency) {
return !(ignoreBinPackage && hasBin(rootDir, dependency) || isIgnored(ignoreMatches, dependency));
});
return (0, _lodash2.default)(dependencies).keys().reject(function (dep) {
return isIgnored(ignoreMatches, dep) || ignoreBinPackage && hasBin(rootDir, dep);
}).value();
}
function buildResult(result, deps, devDeps) {
var usingDepsLookup = Object.keys(result.using).reduce(function (obj, filename) {
return result.using[filename].reduce(function (object, dep) {
return _extends({}, object, _defineProperty({}, dep, [filename].concat(object[dep] || [])));
}, obj);
}, {});
var usingDeps = Object.keys(usingDepsLookup);
var missingDeps = minus(usingDeps, deps.concat(devDeps));
var missingDepsLookup = missingDeps.reduce(function (obj, missingDep) {
return _extends({}, obj, _defineProperty({}, missingDep, usingDepsLookup[missingDep]));
}, {});
return {
dependencies: minus(deps, usingDeps),
devDependencies: minus(devDeps, usingDeps),
missing: missingDepsLookup,
using: usingDepsLookup,
invalidFiles: result.invalidFiles,
invalidDirs: result.invalidDirs
function depcheck(rootDir, options, callback) {
var getOption = function getOption(key) {
return _lodash2.default.isUndefined(options[key]) ? _constants.defaultOptions[key] : options[key];
};
}
function depcheck(rootDir, options, callback) {
var withoutDev = getOrDefault(options, 'withoutDev');
var ignoreBinPackage = getOrDefault(options, 'ignoreBinPackage');
var ignoreMatches = getOrDefault(options, 'ignoreMatches');
var ignoreDirs = defaultOptions.ignoreDirs.concat(options.ignoreDirs).reduce(unique, []);
var withoutDev = getOption('withoutDev');
var ignoreBinPackage = getOption('ignoreBinPackage');
var ignoreMatches = getOption('ignoreMatches');
var ignoreDirs = _lodash2.default.union(_constants.defaultOptions.ignoreDirs, options.ignoreDirs);
var detectors = getOrDefault(options, 'detectors');
var parsers = _extends({ '*': getOrDefault(options, 'specials') }, unifyParser(getOrDefault(options, 'parsers')));
var detectors = getOption('detectors');
var parsers = (0, _lodash2.default)(getOption('parsers')).mapValues(function (value) {
return _lodash2.default.isArray(value) ? value : [value];
}).merge({ '**/*': getOption('specials') }).value();

@@ -304,12 +70,9 @@ var metadata = options.package || require(_path2.default.join(rootDir, 'package.json'));

var devDeps = filterDependencies(rootDir, ignoreBinPackage, ignoreMatches, devDependencies);
var allDeps = deps.concat(devDeps).reduce(unique, []);
return checkDirectory(rootDir, rootDir, ignoreDirs, allDeps, parsers, detectors).then(function (result) {
return buildResult(result, deps, devDeps);
}).then(callback);
return (0, _check.check)(rootDir, ignoreDirs, deps, devDeps, parsers, detectors).then(callback);
}
depcheck.parser = availableParsers;
depcheck.detector = availableDetectors;
depcheck.special = availableSpecials;
depcheck.parser = _constants.availableParsers;
depcheck.detector = _constants.availableDetectors;
depcheck.special = _constants.availableSpecials;
module.exports = exports['default'];

@@ -6,2 +6,3 @@ 'use strict';

});
exports.default = parseCoffeeScript;

@@ -16,6 +17,5 @@ var _depsRegex = require('deps-regex');

exports.default = function (content) {
function parseCoffeeScript(content) {
return re.getDependencies(content);
};
}
module.exports = exports['default'];

@@ -6,11 +6,11 @@ 'use strict';

});
exports.default = parseES6;
var _babylon = require('babylon');
exports.default = function (content) {
function parseES6(content) {
return (0, _babylon.parse)(content, {
sourceType: 'module'
});
};
}
module.exports = exports['default'];

@@ -6,6 +6,7 @@ 'use strict';

});
exports.default = parseES7;
var _babylon = require('babylon');
exports.default = function (content) {
function parseES7(content) {
return (0, _babylon.parse)(content, {

@@ -18,4 +19,3 @@ sourceType: 'module',

});
};
}
module.exports = exports['default'];

@@ -6,6 +6,7 @@ 'use strict';

});
exports.default = parseJSX;
var _babylon = require('babylon');
exports.default = function (content) {
function parseJSX(content) {
return (0, _babylon.parse)(content, {

@@ -18,4 +19,3 @@ sourceType: 'module',

});
};
}
module.exports = exports['default'];

@@ -7,2 +7,6 @@ 'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.default = parseBabel;
var _path = require('path');

@@ -12,2 +16,6 @@

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -23,10 +31,4 @@

function values(object) {
return Object.keys(object || {}).map(function (key) {
return object[key];
});
}
function isPlugin(target, plugin) {
return typeof target === 'string' ? target === plugin || target === 'babel-plugin-' + plugin : target[0] === plugin || target[0] === 'babel-plugin-' + plugin;
return _lodash2.default.isString(target) ? target === plugin || target === 'babel-plugin-' + plugin : target[0] === plugin || target[0] === 'babel-plugin-' + plugin;
}

@@ -41,3 +43,3 @@

var names = array.map(function (item) {
return typeof item === 'string' ? item : item[0];
return _lodash2.default.isString(item) ? item : item[0];
});

@@ -56,21 +58,15 @@ if (names.indexOf(dep) !== -1) {

function getReactTransforms(deps, plugins) {
if (!plugins) {
return [];
}
var transforms = (0, _lodash2.default)(plugins || []).filter(function (plugin) {
return isPlugin(plugin, 'react-transform');
}).map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2);
var transforms = plugins.filter(function (plugin) {
return isPlugin(plugin, 'react-transform');
}).map(function (plugin) {
return plugin[1].transforms.map(function (transform) {
return transform.transform;
var plugin = _ref2[1];
return plugin.transforms.map(function (_ref3) {
var transform = _ref3.transform;
return transform;
});
})[0];
}).first();
if (!transforms) {
return [];
}
return transforms.filter(function (transform) {
return deps.indexOf(transform) !== -1;
});
return _lodash2.default.intersection(transforms, deps);
}

@@ -89,3 +85,3 @@

return presets.concat(plugins).concat(reactTransforms);
return presets.concat(plugins, reactTransforms);
}

@@ -97,7 +93,5 @@

var optDeps = filter(deps, options);
var envDeps = values(options.env).map(function (env) {
var envDeps = (0, _lodash2.default)(options.env).values().map(function (env) {
return filter(deps, env);
}).reduce(function (array, item) {
return array.concat(item);
}, []);
}).flatten().value();

@@ -107,3 +101,3 @@ return optDeps.concat(envDeps);

exports.default = function (content, filePath, deps) {
function parseBabel(content, filePath, deps) {
var filename = _path2.default.basename(filePath);

@@ -122,4 +116,3 @@

return [];
};
}
module.exports = exports['default'];

@@ -7,2 +7,6 @@ 'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.default = parseBinary;
var _path = require('path');

@@ -12,2 +16,6 @@

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _getScripts = require('../utils/get-scripts');

@@ -21,8 +29,2 @@

function toKeyValuePair(object) {
return Object.keys(object).map(function (key) {
return { key: key, value: object[key] };
});
}
function getCacheOrRequire(packagePath) {

@@ -47,14 +49,11 @@ if (metadataCache[packagePath]) {

function toMetadata(dep, dir) {
var metadata = loadMetadata(dep, dir);
var binaryLookup = metadata.bin || {};
var binaries = toKeyValuePair(binaryLookup);
function getBinaryFeatures(dep, _ref) {
var _ref2 = _slicedToArray(_ref, 2);
return { dep: dep, binaries: binaries };
}
var key = _ref2[0];
var value = _ref2[1];
function getBinFeatures(dep, bin) {
var binPath = _path2.default.join('node_modules', dep, bin.value).replace(/\\/g, '/');
var binPath = _path2.default.join('node_modules', dep, value).replace(/\\/g, '/');
var features = [bin.key, '$(npm bin)/' + bin.key, 'node_modules/.bin/' + bin.key, './node_modules/.bin/' + bin.key, binPath, './' + binPath];
var features = [key, '$(npm bin)/' + key, 'node_modules/.bin/' + key, './node_modules/.bin/' + key, binPath, './' + binPath];

@@ -64,7 +63,10 @@ return features;

function isUsedBin(dep, bin, scripts) {
var features = getBinFeatures(dep, bin);
return scripts.some(function (script) {
return features.some(function (char) {
return (' ' + script + ' ').indexOf(' ' + char + ' ') !== -1;
function isBinaryInUse(dep, scripts, dir) {
var metadata = loadMetadata(dep, dir);
var binaries = _lodash2.default.toPairs(metadata.bin || {});
return binaries.some(function (bin) {
return getBinaryFeatures(dep, bin).some(function (feature) {
return scripts.some(function (script) {
return _lodash2.default.includes(' ' + script + ' ', ' ' + feature + ' ');
});
});

@@ -74,19 +76,8 @@ });

function getUsedDeps(deps, scripts, dir) {
return deps.map(function (dep) {
return toMetadata(dep, dir);
}).filter(function (metadata) {
return metadata.binaries.some(function (bin) {
return isUsedBin(metadata.dep, bin, scripts);
});
}).map(function (metadata) {
return metadata.dep;
function parseBinary(content, filepath, deps, dir) {
var scripts = (0, _getScripts2.default)(filepath, content);
return deps.filter(function (dep) {
return isBinaryInUse(dep, scripts, dir);
});
}
exports.default = function (content, filepath, deps, dir) {
var scripts = (0, _getScripts2.default)(filepath, content);
return getUsedDeps(deps, scripts, dir);
};
module.exports = exports['default'];

@@ -6,2 +6,3 @@ 'use strict';

});
exports.default = parseESLint;

@@ -16,2 +17,6 @@ var _path = require('path');

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _requirePackageName = require('require-package-name');

@@ -21,16 +26,8 @@

var _load = require('../utils/load');
var _evaluate = require('../utils/evaluate');
var _load2 = _interopRequireDefault(_load);
var _evaluate2 = _interopRequireDefault(_evaluate);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function concat(array, item) {
return array.concat(item);
}
function unique(array, item) {
return array.indexOf(item) === -1 ? array.concat([item]) : array;
}
function parse(content) {

@@ -50,3 +47,3 @@ try {

try {
return (0, _load2.default)('module.exports = ' + content);
return (0, _evaluate2.default)('module.exports = ' + content);
} catch (error) {}

@@ -63,3 +60,3 @@ // not valid JavaScript code

return [];
} else if (obj instanceof Array) {
} else if (_lodash2.default.isArray(obj)) {
return obj;

@@ -114,21 +111,20 @@ }

var presetDeps = presets.map(function (preset) {
var presetDeps = (0, _lodash2.default)(presets).map(function (preset) {
return loadConfig(preset, rootDir);
}).map(function (presetConfig) {
return checkConfig(presetConfig, rootDir);
}).reduce(concat, []);
}).flatten().value();
return parser.concat(plugins).concat(presetPackages).concat(presetDeps);
return _lodash2.default.union(parser, plugins, presetPackages, presetDeps);
}
exports.default = function (content, filename, deps, rootDir) {
function parseESLint(content, filename, deps, rootDir) {
var basename = _path2.default.basename(filename);
if (basename === '.eslintrc') {
var config = parse(content);
return checkConfig(config, rootDir).reduce(unique, []);
return checkConfig(config, rootDir);
}
return [];
};
}
module.exports = exports['default'];

@@ -6,2 +6,3 @@ 'use strict';

});
exports.default = parseMocha;

@@ -16,2 +17,6 @@ var _fs = require('fs');

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _requirePackageName = require('require-package-name');

@@ -27,6 +32,2 @@

function concat(result, array) {
return result.concat(array);
}
function getOpts(script) {

@@ -52,3 +53,3 @@ var argvs = script.split(' ').filter(function (argv) {

exports.default = function (content, filepath, deps, rootDir) {
function parseMocha(content, filepath, deps, rootDir) {
var defaultOptPath = _path2.default.resolve(rootDir, 'test/mocha.opts');

@@ -60,3 +61,3 @@ if (filepath === defaultOptPath) {

// get mocha.opts from scripts
var requires = (0, _getScripts2.default)(filepath, content).filter(function (script) {
var requires = (0, _lodash2.default)((0, _getScripts2.default)(filepath, content)).filter(function (script) {
return script.indexOf('mocha') !== -1;

@@ -74,7 +75,6 @@ }).map(function (script) {

return getRequires(optContent, deps);
}).reduce(concat, []);
}).flatten().value();
return requires;
};
}
module.exports = exports['default'];

@@ -6,2 +6,3 @@ 'use strict';

});
exports.default = parseWebpack;

@@ -12,12 +13,10 @@ var _path = require('path');

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function concat(array, item) {
return array.concat(item);
}
var loaderTemplates = ['*-webpack-loader', '*-web-loader', '*-loader', '*'];
function duplicate(array, item) {
return array.indexOf(item) === -1 ? array.concat([item]) : array;
}
function extractLoaders(item) {

@@ -39,14 +38,11 @@ if (item.loader) {

function normalizeLoader(deps, loader) {
var templates = ['*-webpack-loader', '*-web-loader', '*-loader', '*'];
var names = templates.map(function (template) {
var name = (0, _lodash2.default)(loaderTemplates).map(function (template) {
return template.replace('*', loader);
}).filter(function (name) {
return deps.indexOf(name) !== -1;
});
}).intersection(deps).first();
return names[0];
return name;
}
function getLoaders(deps, loaders) {
return (loaders || []).map(extractLoaders).reduce(concat, []).map(function (loader) {
return (0, _lodash2.default)(loaders || []).map(extractLoaders).flatten().map(function (loader) {
return stripQueryParameter(loader);

@@ -57,6 +53,6 @@ }).map(function (loader) {

return loader;
}).reduce(duplicate, []);
}).uniq().value();
}
exports.default = function (content, filepath, deps) {
function parseWebpack(content, filepath, deps) {
var filename = _path2.default.basename(filepath);

@@ -72,4 +68,3 @@ if (filename === 'webpack.config.js') {

return [];
};
}
module.exports = exports['default'];

@@ -23,2 +23,6 @@ 'use strict';

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -43,12 +47,2 @@

function concat(array, item) {
return array.concat(item);
}
function getObjectValues(object) {
return Object.keys(object).map(function (key) {
return object[key];
});
}
function getScripts(filepath) {

@@ -62,3 +56,3 @@ var content = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];

if (basename === 'package.json') {
return getObjectValues(JSON.parse(fileContent).scripts || {});
return _lodash2.default.values(JSON.parse(fileContent).scripts || {});
} else if (basename === '.travis.yml') {

@@ -68,5 +62,5 @@ var _ret = function () {

return {
v: travisCommands.map(function (cmd) {
v: (0, _lodash2.default)(travisCommands).map(function (cmd) {
return metadata[cmd] || [];
}).reduce(concat, [])
}).flatten().value()
};

@@ -73,0 +67,0 @@ }();

{
"name": "depcheck",
"version": "0.6.0",
"version": "0.7.0-beta.1",
"description": "Check dependencies in your node module",

@@ -48,2 +48,3 @@ "main": "dist/index.js",

"js-yaml": "^3.4.2",
"lodash": "^4.5.1",
"minimatch": "^3.0.0",

@@ -63,3 +64,3 @@ "require-package-name": "^2.0.1",

"depcheck-web": "^0.1.0",
"eslint": "^2.2.0",
"eslint": "=2.2.0",
"eslint-config-airbnb": "^6.0.1",

@@ -66,0 +67,0 @@ "fs-promise": "^0.4.1",

@@ -76,4 +76,4 @@ # depcheck

parsers: { // the target parsers
'*.js': depcheck.parser.es6,
'*.jsx': depcheck.parser.jsx
'**/*.js': depcheck.parser.es6,
'**/*.jsx': depcheck.parser.jsx
},

@@ -80,0 +80,0 @@ detectors: [ // the target detectors

Sorry, the diff of this file is not supported yet