Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

depensitor

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

depensitor - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

127

dist/es.js
import globby from 'globby';
import get from 'lodash.get';
import flow from 'lodash.flow';
import uniq from 'lodash.uniq';
import _ from 'lodash/fp';
import { parse } from 'babylon';

@@ -12,6 +10,18 @@ import traverse from 'babel-traverse';

import throat from 'throat';
import filter from 'lodash.filter';
import flattenDeep from 'lodash.flattendeep';
import builtinModules from 'builtin-modules';
import _$1 from 'lodash';
var groupPlugins = (function (plugins) {
return plugins.reduce(function (obj, plugin) {
if (plugin.visitor && _.isFunction(plugin.visitor)) {
obj.visitors.push(plugin.visitor);
}
if (plugin.diff && _.isFunction(plugin.diff)) {
obj.diffs.push(plugin.diff);
}
return obj;
}, { visitors: [], diffs: [] });
});
// Module RegExp from https://github.com/webpack/enhanced-resolve/blob/master/lib/Resolver.js

@@ -55,5 +65,5 @@ var NOT_MODULE_REGEXP = /^\.$|^\.[\\\/]|^\.\.$|^\.\.[\/\\]|^\/|^[A-Z]:[\\\/]/i;

// Getters
var getCallee = get(['node.callee.name']);
var getRequireDepName = flow(get('node.arguments[0].value'), getRootDep);
var getImportDepName = flow(get('node.source.value'), getRootDep);
var getCallee = _.get('node.callee.name');
var getRequireDepName = _.flow(_.get('node.arguments[0].value'), getRootDep);
var getImportDepName = _.flow(_.get('node.source.value'), getRootDep);

@@ -83,10 +93,23 @@ var getFileDependencies = (function (file) {

return uniq(imports);
return _.uniq(imports);
});
var flattenDedupe = flow(flattenDeep, filter(function (val) {
var flattenDedupe = _$1.flow(_$1.filter(function (val) {
return val;
}), uniq);
}), _$1.flattenDeep, _$1.uniq);
var getFolderDependencies = (function (files, dependencyFinder) {
var getFolderDependencies = (function (files, visitors) {
var visitor = visitors;
if (_$1.isArray(visitor) && visitor.length > 0) {
if (visitor.length === 1) {
visitor = visitor[0];
} else {
visitor = function visitor(content) {
return visitors.map(function (v) {
return v(content);
});
};
}
}
var deps = files.map(throat(os.cpus().length, function (file) {

@@ -100,3 +123,4 @@ var resolvedName = path.resolve(process.cwd(), file);

var fileContent = fs.readFileSync(resolvedName, 'utf8');
return dependencyFinder(fileContent);
return visitor(fileContent);
}));

@@ -109,3 +133,19 @@

var packageDiff = (function (deps, pkg) {
var getPluginDiff = (function (pkgDiff, pluginDiff) {
var pkg = Object.assign({}, pkgDiff);
var plug = Object.assign({}, pluginDiff);
return {
missing: {
added: _.difference(plug.missing, pkg.missing),
removed: _.difference(pkg.missing, plug.missing)
},
unused: {
added: _.difference(plug.unused, pkg.unused),
removed: _.difference(pkg.unused, plug.unused)
}
};
});
var packageDiff = (function (deps, pkg, plugins) {
if (!pkg) {

@@ -125,13 +165,47 @@ throw new Error('You need to provide a package.json file');

var missing = deps.filter(function (dep) {
return builtinModules.indexOf(dep) === -1;
}).filter(function (dep) {
return pkgDeps.indexOf(dep) === -1;
});
var diff = {
missing: _.difference(deps, pkgDeps),
unused: _.difference(pkgDeps, deps)
};
var unused = pkgDeps.filter(function (dep) {
return deps.indexOf(dep) === -1;
if (!plugins || plugins.length === 0) {
return diff;
}
var pluginDiffs = plugins.map(function (plugin) {
return getPluginDiff(diff, plugin(diff));
});
return { missing: missing, unused: unused };
// Merge all plugin arrays
var reducedPluginDiff = pluginDiffs.reduce(function (obj, pluginDiff) {
obj.missing.added = obj.missing.added.concat(pluginDiff.missing.added);
obj.missing.removed = obj.missing.removed.concat(pluginDiff.missing.removed);
obj.unused.added = obj.unused.added.concat(pluginDiff.unused.added);
obj.unused.removed = obj.unused.removed.concat(pluginDiff.unused.removed);
return obj;
}, { missing: { added: [], removed: [] }, unused: { added: [], removed: [] } });
// Dedupe these arrays
var dedupePluginDiff = {
missing: {
added: _.uniq(reducedPluginDiff.missing.added),
removed: _.uniq(reducedPluginDiff.missing.removed)
},
unused: {
added: _.uniq(reducedPluginDiff.unused.added),
removed: _.uniq(reducedPluginDiff.unused.removed)
}
};
var finalDiffs = Object.assign({}, diff);
// Add added dependencies
finalDiffs.missing = finalDiffs.missing.concat(dedupePluginDiff.missing.added);
finalDiffs.unused = finalDiffs.unused.concat(dedupePluginDiff.unused.added);
// Remove removed dependencies
finalDiffs.missing = _.difference(finalDiffs.missing, dedupePluginDiff.missing.removed);
finalDiffs.unused = _.difference(finalDiffs.unused, dedupePluginDiff.unused.removed);
return finalDiffs;
});

@@ -142,5 +216,8 @@

var pkg = _ref.pkg;
var plugins = _ref.plugins;
return getFolderDependencies(globby.sync(paths), getFileDependencies).then(function (deps) {
return packageDiff(deps, pkg);
var composedPlugins = groupPlugins(plugins);
return getFolderDependencies(globby.sync(paths), [getFileDependencies].concat(composedPlugins.visitors)).then(function (deps) {
return packageDiff(deps, pkg, composedPlugins.diffs);
});

@@ -147,0 +224,0 @@ });

135

dist/index.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('globby'), require('lodash.get'), require('lodash.flow'), require('lodash.uniq'), require('babylon'), require('babel-traverse'), require('babel-types'), require('fs'), require('path'), require('os'), require('throat'), require('lodash.filter'), require('lodash.flattendeep'), require('builtin-modules')) :
typeof define === 'function' && define.amd ? define(['globby', 'lodash.get', 'lodash.flow', 'lodash.uniq', 'babylon', 'babel-traverse', 'babel-types', 'fs', 'path', 'os', 'throat', 'lodash.filter', 'lodash.flattendeep', 'builtin-modules'], factory) :
(global.depensitor = factory(global.globby,global.get,global.flow,global.uniq,global.babylon,global.traverse,global.t,global.fs,global.path,global.os,global.throat,global.filter,global.flattenDeep,global.builtinModules));
}(this, (function (globby,get,flow,uniq,babylon,traverse,t,fs,path,os,throat,filter,flattenDeep,builtinModules) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('globby'), require('lodash/fp'), require('babylon'), require('babel-traverse'), require('babel-types'), require('fs'), require('path'), require('os'), require('throat'), require('lodash')) :
typeof define === 'function' && define.amd ? define(['globby', 'lodash/fp', 'babylon', 'babel-traverse', 'babel-types', 'fs', 'path', 'os', 'throat', 'lodash'], factory) :
(global.depensitor = factory(global.globby,global._,global.babylon,global.traverse,global.t,global.fs,global.path,global.os,global.throat,global._$1));
}(this, (function (globby,_,babylon,traverse,t,fs,path,os,throat,_$1) { 'use strict';
globby = 'default' in globby ? globby['default'] : globby;
get = 'default' in get ? get['default'] : get;
flow = 'default' in flow ? flow['default'] : flow;
uniq = 'default' in uniq ? uniq['default'] : uniq;
_ = 'default' in _ ? _['default'] : _;
traverse = 'default' in traverse ? traverse['default'] : traverse;

@@ -16,6 +14,18 @@ fs = 'default' in fs ? fs['default'] : fs;

throat = 'default' in throat ? throat['default'] : throat;
filter = 'default' in filter ? filter['default'] : filter;
flattenDeep = 'default' in flattenDeep ? flattenDeep['default'] : flattenDeep;
builtinModules = 'default' in builtinModules ? builtinModules['default'] : builtinModules;
_$1 = 'default' in _$1 ? _$1['default'] : _$1;
var groupPlugins = (function (plugins) {
return plugins.reduce(function (obj, plugin) {
if (plugin.visitor && _.isFunction(plugin.visitor)) {
obj.visitors.push(plugin.visitor);
}
if (plugin.diff && _.isFunction(plugin.diff)) {
obj.diffs.push(plugin.diff);
}
return obj;
}, { visitors: [], diffs: [] });
});
// Module RegExp from https://github.com/webpack/enhanced-resolve/blob/master/lib/Resolver.js

@@ -59,5 +69,5 @@ var NOT_MODULE_REGEXP = /^\.$|^\.[\\\/]|^\.\.$|^\.\.[\/\\]|^\/|^[A-Z]:[\\\/]/i;

// Getters
var getCallee = get(['node.callee.name']);
var getRequireDepName = flow(get('node.arguments[0].value'), getRootDep);
var getImportDepName = flow(get('node.source.value'), getRootDep);
var getCallee = _.get('node.callee.name');
var getRequireDepName = _.flow(_.get('node.arguments[0].value'), getRootDep);
var getImportDepName = _.flow(_.get('node.source.value'), getRootDep);

@@ -87,10 +97,23 @@ var getFileDependencies = (function (file) {

return uniq(imports);
return _.uniq(imports);
});
var flattenDedupe = flow(flattenDeep, filter(function (val) {
var flattenDedupe = _$1.flow(_$1.filter(function (val) {
return val;
}), uniq);
}), _$1.flattenDeep, _$1.uniq);
var getFolderDependencies = (function (files, dependencyFinder) {
var getFolderDependencies = (function (files, visitors) {
var visitor = visitors;
if (_$1.isArray(visitor) && visitor.length > 0) {
if (visitor.length === 1) {
visitor = visitor[0];
} else {
visitor = function visitor(content) {
return visitors.map(function (v) {
return v(content);
});
};
}
}
var deps = files.map(throat(os.cpus().length, function (file) {

@@ -104,3 +127,4 @@ var resolvedName = path.resolve(process.cwd(), file);

var fileContent = fs.readFileSync(resolvedName, 'utf8');
return dependencyFinder(fileContent);
return visitor(fileContent);
}));

@@ -113,3 +137,19 @@

var packageDiff = (function (deps, pkg) {
var getPluginDiff = (function (pkgDiff, pluginDiff) {
var pkg = Object.assign({}, pkgDiff);
var plug = Object.assign({}, pluginDiff);
return {
missing: {
added: _.difference(plug.missing, pkg.missing),
removed: _.difference(pkg.missing, plug.missing)
},
unused: {
added: _.difference(plug.unused, pkg.unused),
removed: _.difference(pkg.unused, plug.unused)
}
};
});
var packageDiff = (function (deps, pkg, plugins) {
if (!pkg) {

@@ -129,13 +169,47 @@ throw new Error('You need to provide a package.json file');

var missing = deps.filter(function (dep) {
return builtinModules.indexOf(dep) === -1;
}).filter(function (dep) {
return pkgDeps.indexOf(dep) === -1;
});
var diff = {
missing: _.difference(deps, pkgDeps),
unused: _.difference(pkgDeps, deps)
};
var unused = pkgDeps.filter(function (dep) {
return deps.indexOf(dep) === -1;
if (!plugins || plugins.length === 0) {
return diff;
}
var pluginDiffs = plugins.map(function (plugin) {
return getPluginDiff(diff, plugin(diff));
});
return { missing: missing, unused: unused };
// Merge all plugin arrays
var reducedPluginDiff = pluginDiffs.reduce(function (obj, pluginDiff) {
obj.missing.added = obj.missing.added.concat(pluginDiff.missing.added);
obj.missing.removed = obj.missing.removed.concat(pluginDiff.missing.removed);
obj.unused.added = obj.unused.added.concat(pluginDiff.unused.added);
obj.unused.removed = obj.unused.removed.concat(pluginDiff.unused.removed);
return obj;
}, { missing: { added: [], removed: [] }, unused: { added: [], removed: [] } });
// Dedupe these arrays
var dedupePluginDiff = {
missing: {
added: _.uniq(reducedPluginDiff.missing.added),
removed: _.uniq(reducedPluginDiff.missing.removed)
},
unused: {
added: _.uniq(reducedPluginDiff.unused.added),
removed: _.uniq(reducedPluginDiff.unused.removed)
}
};
var finalDiffs = Object.assign({}, diff);
// Add added dependencies
finalDiffs.missing = finalDiffs.missing.concat(dedupePluginDiff.missing.added);
finalDiffs.unused = finalDiffs.unused.concat(dedupePluginDiff.unused.added);
// Remove removed dependencies
finalDiffs.missing = _.difference(finalDiffs.missing, dedupePluginDiff.missing.removed);
finalDiffs.unused = _.difference(finalDiffs.unused, dedupePluginDiff.unused.removed);
return finalDiffs;
});

@@ -146,5 +220,8 @@

var pkg = _ref.pkg;
var plugins = _ref.plugins;
return getFolderDependencies(globby.sync(paths), getFileDependencies).then(function (deps) {
return packageDiff(deps, pkg);
var composedPlugins = groupPlugins(plugins);
return getFolderDependencies(globby.sync(paths), [getFileDependencies].concat(composedPlugins.visitors)).then(function (deps) {
return packageDiff(deps, pkg, composedPlugins.diffs);
});

@@ -151,0 +228,0 @@ });

{
"license": "ISC",
"name": "depensitor",
"version": "1.1.0",
"description": "clean up your package.json file in a fast and efficient way",
"version": "1.2.0",
"description": "dependencies visitor",
"main": "dist/index.js",
"jsnext:main": "dist/es.js",
"keywords": [],
"author": "",
"author": "Adrien Antoine <adriantoine@gmail.com> (http://adriantoine.com)",
"dependencies": {

@@ -14,9 +14,4 @@ "babel-traverse": "^6.13.0",

"babylon": "^6.9.0",
"builtin-modules": "^1.1.1",
"globby": "^6.0.0",
"lodash.filter": "^4.6.0",
"lodash.flattendeep": "^4.4.0",
"lodash.flow": "^3.5.0",
"lodash.get": "^4.4.2",
"lodash.uniq": "^4.5.0",
"lodash": "^4.15.0",
"throat": "^3.0.0"

@@ -23,0 +18,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc