Huge News!Announcing our $40M Series B led by Abstract Ventures.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 0.9.0 to 0.9.1

.prettierrc

17

dist/check.js

@@ -62,11 +62,6 @@ "use strict";

function discoverPropertyDep(rootDir, deps, property, depName) {
try {
const file = _path.default.resolve(rootDir, 'node_modules', depName, 'package.json');
const metadata = (0, _utils.readJSON)(file);
const propertyDeps = Object.keys(metadata[property] || {});
return _lodash.default.intersection(deps, propertyDeps);
} catch (error) {
return [];
}
const metadata = (0, _utils.loadMetadata)(depName, rootDir);
if (!metadata) return [];
const propertyDeps = Object.keys(metadata[property] || {});
return _lodash.default.intersection(deps, propertyDeps);
}

@@ -89,5 +84,5 @@

// when parser returns string array, skip detector step and treat them as dependencies.
const dependencies = _lodash.default.isArray(ast) && ast.every(_lodash.default.isString) ? ast : (0, _lodash.default)((0, _parser.default)(ast)).map(node => detect(detectors, node)).flatten().uniq().map(_requirePackageName.default).thru(_dependencies => parser === _constants.availableParsers.typescript // If this is a typescript file, importing foo would also use @types/foo, but
const dependencies = _lodash.default.isArray(ast) && ast.every(_lodash.default.isString) ? ast : (0, _lodash.default)((0, _parser.default)(ast)).map(node => detect(detectors, node)).flatten().uniq().map(_requirePackageName.default).thru(_dependencies => parser === _constants.availableParsers.typescript ? // If this is a typescript file, importing foo would also use @types/foo, but
// only if @types/foo is already a specified dependency.
? (0, _lodash.default)(_dependencies).map(dependency => {
(0, _lodash.default)(_dependencies).map(dependency => {
const atTypesName = (0, _typescript.getAtTypesName)(dependency);

@@ -94,0 +89,0 @@ return deps.includes(atTypesName) ? [dependency, atTypesName] : [dependency];

@@ -85,3 +85,3 @@ "use strict";

skipMissing: opt.argv.skipMissing
})).then(result => print(result, log, opt.argv.json, rootDir)).then(result => exit(opt.argv.json || noIssue(result) ? 0 : -1)).catch(errorMessage => {
})).then(result => print(result, log, opt.argv.json, rootDir)).then(result => exit(noIssue(result) ? 0 : -1)).catch(errorMessage => {
error(errorMessage);

@@ -88,0 +88,0 @@ exit(-1);

@@ -30,8 +30,12 @@ {

"gulp-load-plugins",
"husky",
"jest",
"karma",
"lint-staged",
"mocha",
"prettier",
"tslint",
"ttypescript",
"webpack"
]
}

@@ -8,2 +8,4 @@ "use strict";

var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));

@@ -25,2 +27,20 @@

function registerTs(rootDir) {
if (!require.extensions['.ts']) {
const ts = (0, _utils.tryRequire)('typescript', [rootDir, process.cwd(), __dirname]);
if (ts) {
require.extensions['.ts'] = (module, filename) => {
const content = _fs.default.readFileSync(filename, 'utf8');
const options = (0, _utils.tryRequire)(_path.default.join(rootDir, 'package.json')) || {};
options.fileName = filename;
const transpiled = ts.transpileModule(content.charCodeAt(0) === 0xfeff ? content.slice(1) : content, options); // eslint-disable-next-line no-underscore-dangle
module._compile(transpiled.outputText, filename);
};
}
}
}
function isIgnored(ignoreMatches, dependency) {

@@ -33,8 +53,4 @@ const match = _lodash.default.partial(_minimatch.default, dependency);

function hasBin(rootDir, dependency) {
try {
const metadata = (0, _utils.readJSON)(_path.default.join(rootDir, 'node_modules', dependency, 'package.json'));
return {}.hasOwnProperty.call(metadata, 'bin');
} catch (error) {
return rootDir === _path.default.parse(rootDir).root ? false : hasBin(_path.default.dirname(rootDir), dependency);
}
const metadata = (0, _utils.loadMetadata)(dependency, rootDir);
return !!metadata && {}.hasOwnProperty.call(metadata, 'bin');
}

@@ -47,2 +63,4 @@

function depcheck(rootDir, options, callback) {
registerTs(rootDir);
const getOption = key => _lodash.default.isUndefined(options[key]) ? _constants.defaultOptions[key] : options[key];

@@ -49,0 +67,0 @@

@@ -12,2 +12,4 @@ "use strict";

var _requireFromString = _interopRequireDefault(require("require-from-string"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -79,2 +81,7 @@

if (filename === 'babel.config.js') {
const options = (0, _requireFromString.default)(content);
return checkOptions(deps, options);
}
if (filename === 'package.json') {

@@ -81,0 +88,0 @@ const metadata = parse(content);

@@ -16,23 +16,23 @@ "use strict";

const metadataCache = {};
const binaryCache = {};
function getCacheOrRequire(packagePath) {
if (metadataCache[packagePath]) {
return metadataCache[packagePath];
function getCacheOrLoad(dep, dir) {
const index = `${dir}/${dep}`;
if (!binaryCache[index]) {
const metadata = (0, _utils.loadMetadata)(dep, dir) || {};
binaryCache[index] = metadata.bin || {};
}
const metadata = (0, _utils.readJSON)(packagePath);
metadataCache[packagePath] = metadata;
return metadata;
return binaryCache[index];
}
function loadMetadata(dep, dir) {
try {
const packagePath = _path.default.resolve(dir, 'node_modules', dep, 'package.json');
function getBinaries(dep, dir) {
const binMetadata = getCacheOrLoad(dep, dir);
return getCacheOrRequire(packagePath);
} catch (error) {
return dir === _path.default.parse(dir).root ? {} // ignore silently
: loadMetadata(dep, _path.default.dirname(dir));
if (typeof binMetadata === 'string') {
return [[dep, binMetadata]];
}
return _lodash.default.toPairs(binMetadata);
}

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

function getBinaries(dep, dir) {
const metadata = loadMetadata(dep, dir);
if (typeof metadata.bin === 'string') {
return [[dep, metadata.bin]];
}
return _lodash.default.toPairs(metadata.bin || {});
}
function isBinaryInUse(dep, scripts, dir) {

@@ -59,0 +49,0 @@ const binaries = getBinaries(dep, dir);

@@ -99,3 +99,10 @@ "use strict";

const plugins = (0, _index.wrapToArray)(config.plugins).map(plugin => normalizePackageName(plugin, 'eslint-plugin'));
const presets = (0, _index.wrapToArray)(config.extends).filter(preset => !['eslint:recommended', 'eslint:all'].includes(preset)).map(preset => resolvePresetPackage(preset, rootDir));
const extendsArray = (0, _index.wrapToArray)(config.extends);
const presets = extendsArray.filter(preset => !['eslint:recommended', 'eslint:all'].includes(preset)).map(preset => resolvePresetPackage(preset, rootDir)); // prettier/recommended extends eslint-config-prettier
// https://github.com/prettier/eslint-plugin-prettier#recommended-configuration
if (extendsArray.includes('plugin:prettier/recommended')) {
presets.push('eslint-config-prettier');
}
const presetPackages = presets.filter(preset => !_path.default.isAbsolute(preset)).map(_requirePackageName.default);

@@ -102,0 +109,0 @@ const presetDeps = (0, _lodash.default)(presets).map(preset => requireConfig(preset, rootDir)).map(presetConfig => checkConfig(presetConfig, rootDir)).flatten().value();

@@ -31,3 +31,12 @@ "use strict";

function checkConfig(config, rootDir) {
return (0, _index.wrapToArray)(config.extends).filter(preset => !preset.startsWith('tslint:')).map(preset => resolvePresetPackage(preset, rootDir)).filter(preset => !path.isAbsolute(preset)).map(_requirePackageName.default);
let rules = (0, _index.wrapToArray)(config.rulesDirectory).filter(ruleDir => !path.isAbsolute(ruleDir));
const prettierPlugin = 'tslint-plugin-prettier'; // If tslint-plugin-prettier is in tslint file
// then it should also be activated, if not,
// remove it from the list of used dependencies.
if (rules.includes(prettierPlugin) && config.rules.prettier !== true) {
rules = rules.filter(rule => rule !== prettierPlugin);
}
return (0, _index.wrapToArray)(config.extends).filter(preset => !preset.startsWith('tslint:')).map(preset => resolvePresetPackage(preset, rootDir)).filter(preset => !path.isAbsolute(preset)).map(_requirePackageName.default).concat(rules);
}

@@ -34,0 +43,0 @@

@@ -8,2 +8,3 @@ "use strict";

exports.evaluate = evaluate;
exports.loadMetadata = loadMetadata;
exports.tryRequire = tryRequire;

@@ -43,5 +44,21 @@ exports.wrapToArray = wrapToArray;

function tryRequire(module) {
function loadMetadata(moduleName, rootDir) {
try {
return require(module); // eslint-disable-line global-require
const file = require.resolve(`${moduleName}/package.json`, {
paths: [rootDir]
});
return readJSON(file);
} catch (error) {
return null;
}
}
function tryRequire(module, paths = []) {
try {
let moduleName = module;
if (paths.length > 0) moduleName = require.resolve(moduleName, {
paths
});
return require(moduleName); // eslint-disable-line global-require
} catch (e) {

@@ -48,0 +65,0 @@ return null;

@@ -20,1 +20,6 @@ /**

import '@babel/register';
/**
* Typescript is loaded using tryRequire and is therefore not detected.
*/
import 'typescript';
{
"name": "depcheck",
"version": "0.9.0",
"version": "0.9.1",
"description": "Check dependencies in your node module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"engines": {
"node": ">=6"
"node": ">=10"
},

@@ -17,3 +18,3 @@ "bin": {

"scripts": {
"component": "node -r @babel/register ./build/component.js > ./dist/component.json",
"component": "node -r @babel/register ./build/component.js > ./dist/component.json && node -r @babel/register ./build/component.js ./index.d.tmpl > ./dist/index.d.ts",
"compile": "babel src/ -d dist/",

@@ -60,2 +61,3 @@ "depcheck": "node ./bin/depcheck.js --ignore-dirs=fake_modules",

"please-upgrade-node": "^3.2.0",
"require-from-string": "^2.0.2",
"require-package-name": "^2.0.1",

@@ -82,4 +84,6 @@ "resolve": "^1.12.0",

"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.16.0",

@@ -91,4 +95,6 @@ "fs-extra": "^8.1.0",

"patch-version": "^0.1.1",
"prettier": "^1.18.2",
"proxyquire": "^2.1.3",
"should": "^13.2.3"
"should": "^13.2.3",
"typescript": "^3.6.4"
},

@@ -95,0 +101,0 @@ "nyc": {

@@ -20,3 +20,3 @@ # depcheck

*Notice:* depcheck needs node.js >= 6.
*Notice:* depcheck needs node.js >= 10.

@@ -56,2 +56,5 @@ ## Syntax Support

- `gatsby` - [Gatsby](https://www.npmjs.com/package/gatsby) configuration parser
- `husky` - [Husky](https://www.npmjs.com/package/husky) configuration parser
- `lint-staged` - [Lint-staged](https://www.npmjs.com/package/lint-staged) configuration parser
- `ttypescript` - [ttypescript](https://github.com/cevek/ttypescript) transformer parser

@@ -58,0 +61,0 @@ The logic of a special is not perfect. There might be [false alerts](#false-alert). If this happens, please open an issue for us.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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