Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
pack: Pass in our tree object via closures instead of properties
Browse files Browse the repository at this point in the history
PR-URL: #9667
  • Loading branch information
iarna committed Sep 24, 2015
1 parent 829921f commit 330b496
Showing 1 changed file with 31 additions and 35 deletions.
66 changes: 31 additions & 35 deletions lib/utils/tar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 330b496

Please sign in to comment.