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

envinfo

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

envinfo - npm Package Compare versions

Comparing version 3.7.0 to 3.8.0

3

package.json
{
"name": "envinfo",
"version": "3.7.0",
"version": "3.8.0",
"description": "Info about your dev environment for debugging purposes",

@@ -25,2 +25,3 @@ "repository": "https://github.com/tabrindle/envinfo",

"copy-paste": "^1.3.0",
"glob": "^7.1.2",
"minimist": "^1.2.0",

@@ -27,0 +28,0 @@ "os-name": "^2.0.1",

@@ -75,3 +75,3 @@ # envinfo

- --recursive - will search the entire module tree for additional versions installed
- --duplicates - will search given packages for duplicates, display in parentheses

@@ -83,2 +83,14 @@ ```bash

- --fullTree - will traverse and print the entire dependency tree **only works when --packages is array or string
```bash
...
Packages: (wanted => installed)
abab: 1.0.4
xtend: 4.0.1 (2.0.6, 2.1.2, 2.2.0, 3.0.0)
abstract-leveldown: 0.12.4
accepts: 1.3.3
...
```
## Contributing

@@ -85,0 +97,0 @@ PRs for additional features are welcome! Run `npm run lint && npm run format` before commiting.

@@ -8,2 +8,3 @@ #!/usr/bin/env node

var copypasta = require('copy-paste');
var path = require('path');

@@ -27,6 +28,5 @@ module.exports.print = function print(options) {

if (options.packages) {
var packageJson;
try {
packageJson = require(process.cwd() + '/package.json');
} catch (err) {
var packageJson = utils.getPackageJsonByPath('/package.json');
if (!packageJson) {
log.push('ERROR: package.json not found!');

@@ -43,7 +43,7 @@ log.push('');

var dependencies = packageJson.dependencies || {};
var allDependencies = Object.assign({}, devDependencies, dependencies);
var packageTree;
var topLevelDependencies = Object.assign({}, devDependencies, dependencies);
var packagePaths;
if (options.recursive) {
packageTree = helpers.getPackageTree();
if (options.duplicates || options.fullTree) {
packagePaths = helpers.getAllPackageJsonPaths();
}

@@ -53,15 +53,18 @@

var trimmedDep = dep.trim();
if (allDependencies[trimmedDep]) {
var wanted = allDependencies[trimmedDep];
var installed;
if (options.recursive) {
var flatTree = helpers.flattenNodeModuleTree(packageTree.dependencies);
installed = utils.uniq(flatTree[trimmedDep]).join(', ');
} else {
installed = utils.getDependencyPackageJson(dep).version;
}
log.push(' ' + trimmedDep + ': ' + wanted + ' => ' + installed);
} else {
log.push(' ' + trimmedDep + ': Not Found');
var wanted = topLevelDependencies[trimmedDep] || '';
var dependencyPackageJson = utils.getPackageJsonByName(dep);
var installed = dependencyPackageJson ? dependencyPackageJson.version : 'Not Found';
var duplicates = '';
if (options.duplicates) {
duplicates = helpers
.getModuleVersions(dep, packagePaths)
.filter(depVer => depVer !== installed)
.join(', ');
if (duplicates) duplicates = ' (' + duplicates + ')';
}
if (wanted) wanted += ' => ';
log.push(' ' + trimmedDep + ': ' + wanted + installed + duplicates);
};

@@ -74,3 +77,20 @@

} else if (typeof options.packages === 'boolean') {
Object.keys(allDependencies).map(logFunction);
if (options.fullTree) {
var allDependencies = packagePaths
.map(filePath => {
var json = utils.getPackageJsonByPath(filePath);
return {
name: json.name,
version: json.version,
};
})
.reduce((acc, val) => {
return Object.assign(acc, {
[val.name]: acc[val.name] ? acc[val.name].concat([val.version]) : [val.version],
});
}, {});
Object.keys(allDependencies).map(logFunction);
} else {
Object.keys(topLevelDependencies).map(logFunction);
}
}

@@ -77,0 +97,0 @@

@@ -5,2 +5,4 @@ var childProcess = require('child_process');

var which = require('which');
var utils = require('./utils');
var glob = require('glob');

@@ -104,12 +106,2 @@ function run(cmd) {

function getPackageTree() {
var packages;
try {
packages = run('npm ls --json');
} catch (error) {
packages = 'Not able to run `npm ls`';
}
return JSON.parse(packages);
}
function getWatchmanVersion() {

@@ -155,24 +147,35 @@ var watchmanVersion;

function flattenNodeModuleTree(dependencies, acc = {}) {
Object.keys(dependencies).forEach(function each(key) {
if (dependencies[key].dependencies) {
flattenNodeModuleTree(dependencies[key].dependencies, acc);
}
if (acc[key]) {
acc[key].push(dependencies[key].version);
} else {
acc[key] = [dependencies[key].version];
}
});
return acc;
function getAllPackageJsonPaths() {
return glob.sync('node_modules/**/package.json');
}
function getModuleVersions(dependency, packagePaths) {
var paths;
var versions;
try {
paths = packagePaths.filter(function filterPackagePaths(packagePath) {
return packagePath.includes(`/${dependency}/package.json`);
});
versions = paths
.map(function mapPathsForVersion(packageJsonPath) {
var packageJson = utils.getPackageJsonByPath(packageJsonPath);
if (packageJson) return packageJson.version;
return false;
})
.filter(Boolean);
versions = utils.uniq(versions).sort();
} catch (error) {
versions = [];
}
return versions;
}
module.exports = {
flattenNodeModuleTree: flattenNodeModuleTree,
getAllPackageJsonPaths: getAllPackageJsonPaths,
getAndroidStudioVersion: getAndroidStudioVersion,
getCPUInfo: getCPUInfo,
getModuleVersions: getModuleVersions,
getNodeVersion: getNodeVersion,
getNpmVersion: getNpmVersion,
getOperatingSystemInfo: getOperatingSystemInfo,
getPackageTree: getPackageTree,
getWatchmanVersion: getWatchmanVersion,

@@ -179,0 +182,0 @@ getXcodeVersion: getXcodeVersion,

@@ -0,1 +1,4 @@

var path = require('path');
var fs = require('fs');
module.exports.uniq = function uniq(arr) {

@@ -5,4 +8,13 @@ return Array.from(new Set(arr));

module.exports.getDependencyPackageJson = function getDependencyPackageJson(dep) {
return require(process.cwd() + '/node_modules/' + dep + '/package.json');
module.exports.requireJson = function requireJson(filePath) {
if (fs.existsSync(filePath)) return require(filePath);
return false;
};
module.exports.getPackageJsonByName = function getPackageJsonByName(dep) {
return this.requireJson(path.join(process.cwd(), '/node_modules/', dep, '/package.json'));
};
module.exports.getPackageJsonByPath = function getPackageJsonByPath(filePath) {
return this.requireJson(path.join(process.cwd(), filePath));
};
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