Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
removeRetiredAndDeletedNodes () {
const moves = this.reifyRetiredNodes
const promises = []
const failures = []
const rm = path => rimraf(path)
.catch(
/* istanbul ignore next - hard to make rimraf fail */
er => failures.push([path, er])
)
// XXX get list of removal nodes in an earlier walk instead of here
dfwalk({
tree: this.diff,
visit: diff => {
if (diff.action === 'REMOVE')
promises.push(rm(diff.actual.path))
},
getChildren: diff => diff.action === 'REMOVE' ? [] : diff.children,
})
for (const [realPath, retirePath] of Object.entries(moves)) {
promises.push(rm(retirePath))
}
return promiseAllRejectLate(promises).then(() => {
/* istanbul ignore if - hard to make rimraf fail */
if (failures.length)
this.emit('warn', 'Failed to clean up some directories', failures)
unpackNewModules () {
const unpacks = []
dfwalk({
tree: this.diff,
filter: diff => diff.ideal,
visit: diff => {
const node = diff.ideal
const bd = node.package.bundleDependencies
const sw = node.hasShrinkwrap
// should inBundle differentiate if it's in the root's bundle?
// because in that case, it should still be installed.
if (node && !node.isRoot && !(bd && bd.length) && !sw && !node.inBundle)
unpacks.push(this.reifyNode(node))
},
getChildren: diff => diff.children,
})
return promiseAllRejectLate(unpacks)
.catch(er => this.rollbackCreateSparseTree(er))
}
getBundlesByDepth () {
const bundlesByDepth = new Map()
let maxBundleDepth = -1
dfwalk({
tree: this.diff,
visit: diff => {
const node = diff.ideal
if (node && !node.isRoot && node.package.bundleDependencies &&
node.package.bundleDependencies.length) {
maxBundleDepth = Math.max(maxBundleDepth, node.depth)
if (!bundlesByDepth.has(node.depth))
bundlesByDepth.set(node.depth, [node])
else
bundlesByDepth.get(node.depth).push(node)
}
},
getChildren: diff => diff.children,
})
bundlesByDepth.set('maxBundleDepth', maxBundleDepth)
static calculate ({actual, ideal}) {
return depth({
tree: new Diff({actual, ideal}),
getChildren,
leave,
})
}
}