diff options
author | Rebecca Turner <me@re-becca.org> | 2015-09-18 23:21:04 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-09-25 01:53:12 +0300 |
commit | 330b49699acecc53ea36c46e05c92dfc092c2c9d (patch) | |
tree | df809557f398a5487ae1a98dbf1f348952faaf9c /lib | |
parent | 829921fac2790f103035a34042b85181d9db1307 (diff) |
pack: Pass in our tree object via closures instead of properties
PR-URL: https://github.com/npm/npm/pull/9667
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils/tar.js | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/lib/utils/tar.js b/lib/utils/tar.js index e31afb80b..1d0c1790e 100644 --- a/lib/utils/tar.js +++ b/lib/utils/tar.js @@ -45,19 +45,9 @@ function pack (tarball, folder, pkg, cb) { function BundledPacker (props) { Packer.call(this, props) - this.tree = props.tree - var flattenTree = require('../install/flatten-tree.js') - this.flatTree = props.flatTree || flattenTree(props.tree) } inherits(BundledPacker, Packer) -BundledPacker.prototype.getChildProps = function (stat) { - var props = Packer.prototype.getChildProps.call(this, stat) - props.tree = this.tree - props.flatTree = this.flatTree - return props -} - BundledPacker.prototype.applyIgnores = function (entry, partial, entryObj) { // package.json files can never be ignored. if (entry === 'package.json') return true @@ -134,36 +124,42 @@ BundledPacker.prototype.applyIgnores = function (entry, partial, entryObj) { function nameMatch (name) { return function (other) { return name === other.package.name } } -BundledPacker.prototype.isBundled = function (name) { - var bd = this.package && this.package.bundleDependencies - if (!bd) return false - - if (!Array.isArray(bd)) { - throw new Error(this.package.name + '\'s `bundledDependencies` should ' + - 'be an array') +function pack_ (tarball, folder, tree, pkg, cb) { + var flattenTree = require('../install/flatten-tree.js') + var flatTree = flattenTree(tree) + function InstancePacker (props) { + BundledPacker.call(this, props) } + inherits(InstancePacker, BundledPacker) + InstancePacker.prototype.isBundled = function (name) { + var bd = this.package && this.package.bundleDependencies + if (!bd) return false + + if (!Array.isArray(bd)) { + throw new Error(this.package.name + '\'s `bundledDependencies` should ' + + 'be an array') + } - if (bd.indexOf(name) !== -1) return true - var pkg = this.tree.children.filter(nameMatch(name))[0] - if (!pkg) return false - var requiredBy = union([], pkg.package._requiredBy) - var seen = {} - while (requiredBy.length) { - var req = requiredBy.shift() - if (seen[req]) continue - seen[req] = true - var reqPkg = this.flatTree[req] - if (!reqPkg) continue - if (reqPkg.parent === this.tree && bd.indexOf(reqPkg.package.name) !== -1) { - return true + if (bd.indexOf(name) !== -1) return true + var pkg = tree.children.filter(nameMatch(name))[0] + if (!pkg) return false + var requiredBy = union([], pkg.package._requiredBy) + var seen = {} + while (requiredBy.length) { + var req = requiredBy.shift() + if (seen[req]) continue + seen[req] = true + var reqPkg = flatTree[req] + if (!reqPkg) continue + if (reqPkg.parent === tree && bd.indexOf(reqPkg.package.name) !== -1) { + return true + } + requiredBy = union(requiredBy, reqPkg.package._requiredBy) } - requiredBy = union(requiredBy, reqPkg.package._requiredBy) + return false } - return false -} -function pack_ (tarball, folder, tree, pkg, cb) { - new BundledPacker({ path: folder, tree: tree, type: 'Directory', isDirectory: true }) + new InstancePacker({ path: folder, type: 'Directory', isDirectory: true }) .on('error', function (er) { if (er) log.error('tar pack', 'Error reading ' + folder) return cb(er) |