Socket
Socket
Sign inDemoInstall

cipm

Package Overview
Dependencies
13
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.7.1 to 0.7.2

16

CHANGELOG.md

@@ -5,2 +5,18 @@ # Change Log

<a name="0.7.2"></a>
## [0.7.2](https://github.com/zkat/cipm/compare/v0.7.1...v0.7.2) (2017-10-13)
### Bug Fixes
* **extract:** idk why this was breaking. Seriously. ([433a2be](https://github.com/zkat/cipm/commit/433a2be))
* **tree:** pass through a custom Promise to logiTree ([2d29efb](https://github.com/zkat/cipm/commit/2d29efb))
### Performance Improvements
* zoomzoom. Even more concurrency! ([db9c2e0](https://github.com/zkat/cipm/commit/db9c2e0))
<a name="0.7.1"></a>

@@ -7,0 +23,0 @@ ## [0.7.1](https://github.com/zkat/cipm/compare/v0.7.0...v0.7.1) (2017-10-13)

150

index.js

@@ -34,3 +34,2 @@ 'use strict'

this.failedDeps = new Set()
this.purgedDeps = new Set()
}

@@ -112,24 +111,17 @@

extractTree (tree) {
return mapTree(tree, (dep, next) => {
return tree.forEachAsync((dep, next) => {
if (dep.dev && this.config.config.production) { return }
const depPath = treePath(dep, this.prefix)
const depPath = dep.path(this.prefix)
// Process children first, then extract this child
return BB.resolve()
.then(() => {
if (dep !== this.tree) {
// Don't try to extract the root
return extract.child(dep.name, dep, depPath, this.config)
}
})
.then(next)
.then(() => {
dep !== this.tree && this.pkgCount++
})
})
return BB.join(
!dep.isRoot && extract.child(dep.name, dep, depPath, this.config),
next()
).then(() => { !dep.isRoot && this.pkgCount++ })
}, {concurrency: 50, Promise: BB})
}
buildTree (tree) {
return mapTree(tree, (dep, next) => {
return tree.forEachAsync((dep, next) => {
if (dep.dev && this.config.config.production) { return }
const depPath = treePath(dep, this.prefix)
const depPath = dep.path(this.prefix)
return readPkgJson(path.join(depPath, 'package.json'))

@@ -158,3 +150,2 @@ .then(pkg => {

this.failedDeps.add(dep)
return rimraf(depPath) // This should probably be gentlyRm
} else {

@@ -165,3 +156,3 @@ throw e

})
})
}, {concurrency: 50, Promise: BB})
}

@@ -172,37 +163,11 @@

if (!this.failedDeps.size) { return }
const liveDeps = new Set()
const installer = this
const seen = new Set()
const failed = this.failedDeps
const purged = this.purgedDeps
mark(tree)
return sweep(tree)
function mark (tree) {
for (let dep of tree.dependencies.values()) {
if (seen.has(dep)) { continue }
seen.add(dep)
if (!failed.has(dep)) {
liveDeps.add(dep)
mark(dep)
}
}
}
function sweep (tree) {
return mapTree(tree, (dep, next) => {
return next().then(() => {
if (
dep !== installer.tree && // never purge root! 🙈
!liveDeps.has(dep) &&
!purged.has(dep)
) {
installer.pkgCount--
purged.add(dep)
return rimraf(treePath(dep, installer.prefix))
}
})
})
}
return sweep(
tree,
this.prefix,
mark(tree, this.failedDeps)
)
.then(purged => {
this.purgedDeps = purged
this.pkgCount -= purged.size
})
}

@@ -219,7 +184,36 @@

}
module.exports = Installer
function mark (tree, failed) {
const liveDeps = new Set()
tree.forEach((dep, next) => {
if (!failed.has(dep)) {
liveDeps.add(dep)
next()
}
})
return liveDeps
}
function sweep (tree, prefix, liveDeps) {
const purged = new Set()
return tree.forEachAsync((dep, next) => {
return next().then(() => {
if (
dep !== tree && // never purge root! 🙈
!liveDeps.has(dep) &&
!purged.has(dep)
) {
purged.add(dep)
return rimraf(dep.path(prefix))
}
})
}, {concurrency: 50, Promise: BB}).then(() => purged)
}
function stripBOM (str) {
return str.replace(/^\uFEFF/, '')
}
module.exports._readJson = readJson
function readJson (jsonPath, name, ignoreMissing) {

@@ -234,45 +228,1 @@ return readFileAsync(path.join(jsonPath, name), 'utf8')

}
function stripBOM (str) {
return str.replace(/^\uFEFF/, '')
}
function treePath (tree, prefix) {
if (tree.address == null) {
// A tree missing its address is the root.
return prefix || ''
} else {
return path.join(
prefix || '.',
'node_modules',
tree.address.replace(/:/g, '/node_modules/')
)
}
}
// This provides a sort of async iterator for a tree
function mapTree (tree, fn, opts, _seen) {
if (!opts) { opts = _seen || {concurrency: 50} }
if (!_seen) { _seen = new Map() }
if (_seen.has(tree)) {
return BB.resolve(hasCycle(tree)) || _seen.get(tree)
}
const pending = BB.resolve(fn(tree, () => {
return BB.map(tree.dependencies.values(), child => {
return mapTree(child, fn, opts, _seen)
}, opts)
}))
_seen.set(tree, pending)
return pending
}
function hasCycle (child, seen) {
seen = seen || new Set()
if (seen.has(child.address)) {
return true
} else {
seen.add(child.address)
const deps = Array.from(child.dependencies.values())
return deps.some(dep => hasCycle(dep, seen))
}
}

@@ -7,3 +7,2 @@ 'use strict'

const pacote = require('pacote')
const rimraf = BB.promisify(require('rimraf'))

@@ -17,5 +16,3 @@ module.exports = (args, cb) => {

log.level = opts.loglevel
return rimraf(extractTo, {ignore: 'node_modules'}).then(() => {
return pacote.extract(spec, extractTo, opts)
}).nodeify(cb)
return BB.resolve(pacote.extract(spec, extractTo, opts)).nodeify(cb)
}

@@ -5,2 +5,17 @@ # Change Log

<a name="1.2.0"></a>
# [1.2.0](https://github.com/npm/logical-tree/compare/v1.1.0...v1.2.0) (2017-10-13)
### Bug Fixes
* **json:** fix repository url ([e51448a](https://github.com/npm/logical-tree/commit/e51448a))
### Features
* **api:** additional utility functions for dealing with trees ([23f6e69](https://github.com/npm/logical-tree/commit/23f6e69))
<a name="1.1.0"></a>

@@ -7,0 +22,0 @@ # [1.1.0](https://github.com/npm/npm-logical-tree/compare/v1.0.0...v1.1.0) (2017-10-11)

'use strict'
let path
class LogicalTree {
constructor (name, lockNode, address) {
constructor (name, address, opts) {
this.name = name
this.version = lockNode.version
this.address = address
this.optional = !!lockNode.optional
this.dev = !!lockNode.dev
this.bundled = !!lockNode.bundled
this.resolved = lockNode.resolved
this.integrity = lockNode.integrity
this.version = opts.version
this.address = address || ''
this.optional = !!opts.optional
this.dev = !!opts.dev
this.bundled = !!opts.bundled
this.resolved = opts.resolved
this.integrity = opts.integrity
this.dependencies = new Map()
this.requiredBy = new Set()
this.pending = null
}
get isRoot () { return !this.requiredBy.size }
addDep (dep) {
this.dependencies.set(dep.name, dep)
dep.requiredBy.add(this)
return this
}
delDep (dep) {
this.dependencies.delete(dep.name)
dep.requiredBy.delete(this)
return this
}
getDep (name) {
return this.dependencies.get(name)
}
path (prefix) {
if (this.isRoot) {
// The address of the root is the prefix itself.
return prefix || ''
} else {
if (!path) { path = require('path') }
return path.join(
prefix || '',
'node_modules',
this.address.replace(/:/g, '/node_modules/')
)
}
}
// This finds cycles _from_ a given node: if some deeper dep has
// its own cycle, but that cycle does not refer to this node,
// it will return false.
hasCycle (_seen, _from) {
if (!_seen) { _seen = new Set() }
if (!_from) { _from = this }
for (let dep of this.dependencies.values()) {
if (_seen.has(dep)) { continue }
_seen.add(dep)
if (dep === _from || dep.hasCycle(_seen, _from)) {
return true
}
}
return false
}
forEachAsync (fn, opts, _pending) {
if (!opts) { opts = _pending || {} }
if (!_pending) { _pending = new Map() }
const P = opts.Promise || Promise
if (_pending.has(this)) {
return P.resolve(this.hasCycle() || _pending.get(this))
}
const pending = P.resolve().then(() => {
return fn(this, () => {
return promiseMap(
this.dependencies.values(),
dep => dep.forEachAsync(fn, opts, _pending),
opts
)
})
})
_pending.set(this, pending)
return pending
}
forEach (fn, _seen) {
if (!_seen) { _seen = new Set() }
if (_seen.has(this)) { return }
_seen.add(this)
fn(this, () => {
for (let dep of this.dependencies.values()) {
dep.forEach(fn, _seen)
}
})
}
}
module.exports = logicalTree
function logicalTree (pkg, pkgLock, opts) {
const tree = new LogicalTree(pkg.name, pkg, null)
module.exports = lockTree
function lockTree (pkg, pkgLock, opts) {
const tree = makeNode(pkg.name, null, pkg)
const allDeps = new Map()

@@ -40,3 +111,3 @@ Array.from(

const depNode = (pkgLock.dependencies || {})[name]
dep = new LogicalTree(name, depNode, name)
dep = makeNode(name, name, depNode)
}

@@ -48,2 +119,7 @@ addChild(dep, tree, allDeps, pkgLock)

module.exports.node = makeNode
function makeNode (name, address, opts) {
return new LogicalTree(name, address, opts || {})
}
function addChild (dep, tree, allDeps, pkgLock) {

@@ -58,3 +134,3 @@ tree.addDep(dep)

if (!tdep) {
tdep = new LogicalTree(name, atAddr(pkgLock, tdepAddr), tdepAddr)
tdep = makeNode(name, tdepAddr, atAddr(pkgLock, tdepAddr))
addChild(tdep, dep, allDeps, pkgLock)

@@ -96,1 +172,19 @@ } else {

}
function promiseMap (arr, fn, opts, _index) {
_index = _index || 0
const P = (opts && opts.Promise) || Promise
if (P.map) {
return P.map(arr, fn, opts)
} else {
if (!(arr instanceof Array)) {
arr = Array.from(arr)
}
if (_index >= arr.length) {
return P.resolve()
} else {
return P.resolve(fn(arr[_index], _index, arr))
.then(() => promiseMap(arr, fn, opts, _index + 1))
}
}
}
{
"_args": [
[
"npm-logical-tree@1.1.0",
"/Users/zkat/Documents/code/cipm"
]
],
"_from": "npm-logical-tree@1.1.0",
"_id": "npm-logical-tree@1.1.0",
"_from": "npm-logical-tree@1.2.0",
"_id": "npm-logical-tree@1.2.0",
"_inBundle": false,
"_integrity": "sha512-xAzsBAUPJPQFbFJ8Ajz8tSXe6w+WZRPNZUCP/pTYvLJa5VTTcAE3jqczQADWMjowGKhSPZIp+W8lF6UN9va4rQ==",
"_integrity": "sha512-rRVqiUshr7JEGEqEM0Kci4fkH8tA30piLmlBUhQzkwJl2c///vOI8AbNsDz1wms6CqPddlpUcTWXywWoC/QQxg==",
"_location": "/npm-logical-tree",

@@ -17,14 +11,16 @@ "_phantomChildren": {},

"registry": true,
"raw": "npm-logical-tree@1.1.0",
"raw": "npm-logical-tree@1.2.0",
"name": "npm-logical-tree",
"escapedName": "npm-logical-tree",
"rawSpec": "1.1.0",
"rawSpec": "1.2.0",
"saveSpec": null,
"fetchSpec": "1.1.0"
"fetchSpec": "1.2.0"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/npm-logical-tree/-/npm-logical-tree-1.1.0.tgz",
"_spec": "1.1.0",
"_resolved": "https://registry.npmjs.org/npm-logical-tree/-/npm-logical-tree-1.2.0.tgz",
"_shasum": "cd1926e80e593c56978fe446d67154752be8a1aa",
"_spec": "npm-logical-tree@1.2.0",
"_where": "/Users/zkat/Documents/code/cipm",

@@ -36,4 +32,5 @@ "author": {

"bugs": {
"url": "https://github.com/npm/npm-logical-tree/issues"
"url": "https://github.com/npm/logical-tree/issues"
},
"bundleDependencies": false,
"config": {

@@ -53,4 +50,6 @@ "nyc": {

],
"deprecated": false,
"description": "Calculate 'logical' trees from a package.json + package-lock",
"devDependencies": {
"bluebird": "^3.5.1",
"nyc": "^11.1.0",

@@ -66,3 +65,3 @@ "standard": "^10.0.2",

],
"homepage": "https://github.com/npm/npm-logical-tree#readme",
"homepage": "https://github.com/npm/logical-tree#readme",
"keywords": [

@@ -77,3 +76,3 @@ "npm",

"type": "git",
"url": "git+https://github.com/npm/npm-logical-tree.git"
"url": "git+https://github.com/npm/logical-tree.git"
},

@@ -89,3 +88,3 @@ "scripts": {

},
"version": "1.1.0"
"version": "1.2.0"
}
{
"name": "cipm",
"version": "0.7.1",
"version": "0.7.2",
"description": "standalone ci-oriented package installer for npm",

@@ -55,3 +55,3 @@ "main": "index.js",

"npm-lifecycle": "^1.0.3",
"npm-logical-tree": "^1.1.0",
"npm-logical-tree": "^1.2.0",
"npm-package-arg": "^5.1.2",

@@ -58,0 +58,0 @@ "npmlog": "^4.1.2",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc