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

read-installed

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-installed - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

5

package.json
{
"name": "read-installed",
"description": "Read all the installed packages in a folder, and return a tree structure with all the data.",
"version": "1.0.1",
"version": "2.0.0",
"repository": {

@@ -14,5 +14,6 @@ "type": "git",

"dependencies": {
"read-package-json": "1",
"semver": "2",
"slide": "~1.1.3",
"read-package-json": "1"
"util-extend": "^1.0.1"
},

@@ -19,0 +20,0 @@ "optionalDependencies": {

61

read-installed.js

@@ -101,2 +101,4 @@

var url = require("url")
var util = require("util")
var extend = require("util-extend")

@@ -109,12 +111,21 @@ module.exports = readInstalled

opts = {}
} else {
opts = extend({}, opts)
}
var depth = (typeof opts.depth === 'number') ? opts.depth : Infinity
, log = (typeof opts.log === 'function') ? opts.log : function () {}
, dev = !!opts.dev;
readInstalled_(folder, null, null, null, 0, depth, dev, function (er, obj) {
if (typeof opts.depth !== 'number')
opts.depth = Infinity
opts.depth = Math.max(0, opts.depth)
if (typeof opts.log !== 'function')
opts.log = function () {}
opts.dev = !!opts.dev
readInstalled_(folder, null, null, null, 0, opts, function (er, obj) {
if (er) return cb(er)
// now obj has all the installed things, where they're installed
// figure out the inheritance links, now that the object is built.
resolveInheritance(obj, log)
resolveInheritance(obj, opts)
cb(null, obj)

@@ -125,3 +136,3 @@ })

var rpSeen = {}
function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, dev, cb) {
function readInstalled_ (folder, parent, name, reqver, depth, opts, cb) {
var installed

@@ -189,7 +200,12 @@ , obj

if (parent
&& !(name in parent.dependencies)
&& (dev || !(name in (parent.devDependencies || {})))) {
obj.extraneous = true
if (parent) {
var deps = parent.dependencies || {}
var inDeps = name in deps
var devDeps = parent.devDependencies || {}
var inDev = opts.dev && (name in devDeps)
if (!inDeps && !inDev) {
obj.extraneous = true
}
}
obj.path = obj.path || folder

@@ -201,7 +217,9 @@ obj.realPath = real

obj.depth = depth
//if (depth >= maxDepth) return cb(null, obj)
//if (depth >= opts.depth) return cb(null, obj)
asyncMap(installed, function (pkg, cb) {
var rv = obj.dependencies[pkg]
if (!rv && obj.devDependencies && !dev) rv = obj.devDependencies[pkg]
if (depth >= maxDepth) {
if (!rv && obj.devDependencies && opts.dev)
rv = obj.devDependencies[pkg]
if (depth >= opts.depth) {
// just try to get the version number

@@ -213,3 +231,3 @@ var pkgfolder = path.resolve(folder, "node_modules", pkg)

if (er || !depData || !depData.version) return cb(null, obj)
if (depth === maxDepth) {
if (depth === opts.depth) {
// edge case, ignore dependencies

@@ -227,4 +245,3 @@ depData.dependencies = {}

readInstalled_( path.resolve(folder, "node_modules/"+pkg)
, obj, pkg, obj.dependencies[pkg], depth + 1, maxDepth
, dev
, obj, pkg, obj.dependencies[pkg], depth + 1, opts
, cb )

@@ -254,3 +271,3 @@

var riSeen = []
function resolveInheritance (obj, log) {
function resolveInheritance (obj, opts) {
if (typeof obj !== "object") return

@@ -263,8 +280,8 @@ if (riSeen.indexOf(obj) !== -1) return

Object.keys(obj.dependencies).forEach(function (dep) {
findUnmet(obj.dependencies[dep], log)
findUnmet(obj.dependencies[dep], opts)
})
Object.keys(obj.dependencies).forEach(function (dep) {
resolveInheritance(obj.dependencies[dep], log)
resolveInheritance(obj.dependencies[dep], opts)
})
findUnmet(obj, log)
findUnmet(obj, opts)
}

@@ -275,3 +292,3 @@

var fuSeen = []
function findUnmet (obj, log) {
function findUnmet (obj, opts) {
if (fuSeen.indexOf(obj) !== -1) return

@@ -303,3 +320,3 @@ fuSeen.push(obj)

// the bad thing will happen
log("unmet dependency", obj.path + " requires "+d+"@'"+deps[d]
opts.log("unmet dependency", obj.path + " requires "+d+"@'"+deps[d]
+"' but will load\n"

@@ -306,0 +323,0 @@ +found.path+",\nwhich is version "+found.version

@@ -8,5 +8,5 @@ # read-installed

## 1.0.0
## 2.0.0
Breaking changes in `1.0.0`:
Breaking changes in `2.0.0`:

@@ -17,3 +17,3 @@ The second argument is now an `Object` that contains the following keys:

* `log` optional log Function
* `dev` optional, dev=true to mark devDeps as extraneous
* `dev` optional, default false, set to true to include devDependencies

@@ -24,5 +24,7 @@ ## Usage

var readInstalled = require("read-installed")
readInstalled(folder, { depth, log, dev }, function (er, data) {
// optional options
var options = { dev: false, log: fn, depth: 2 }
readInstalled(folder, options, function (er, data) {
...
})
```

@@ -11,2 +11,3 @@ var readInstalled = require("../read-installed.js")

readInstalled(path.join(__dirname, "../"), {
dev: true,
log: console.error

@@ -25,2 +26,3 @@ }, function (er, map) {

})
var seen = []

@@ -27,0 +29,0 @@ function cleanup (map) {

@@ -11,4 +11,5 @@ var readInstalled = require("../read-installed.js")

readInstalled(path.join(__dirname, "../"), {
log: console.error
, dev: true }, function (er, map) {
log: console.error,
dev: false
}, function (er, map) {
t.notOk(er, "er should be bull")

@@ -15,0 +16,0 @@ t.ok(map, "map should be data")

@@ -16,3 +16,4 @@ {

"slide": "~1.1.3",
"read-package-json": "1"
"read-package-json": "1",
"util-extend":"1"
},

@@ -19,0 +20,0 @@ "optionalDependencies": {

@@ -17,3 +17,3 @@ var readInstalled = require("../read-installed.js")

t.deepEqual(deps, known, "arrays should be equal")
t.notOk(map.dependencies.tap.extraneous, 'extraneous is set on devDep')
t.ok(map.dependencies.tap.extraneous, 'extraneous is set on devDep')
t.end()

@@ -20,0 +20,0 @@ })

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