diff --git a/lib/pipeline/npm.js b/lib/pipeline/npm.js index 286754db..09b00431 100644 --- a/lib/pipeline/npm.js +++ b/lib/pipeline/npm.js @@ -2,9 +2,6 @@ // TODO: this is horrible and needs to be refactored ASAP let utils = require('../utils/utils.js'); let fs = require('../core/fs.js'); -let o_fs = require('fs-extra'); - -var tar = require('tar'); class Npm { @@ -46,19 +43,14 @@ class Npm { self.logger.info("downloading " + packageName + " " + version + "...."); utils.downloadFile(fileLocation, packageDirectory + "/" + packageName + ".js", function() { - o_fs.createReadStream(packageDirectory + "/" + packageName + ".js").pipe( - tar.x({ - strip: 1, - C: packageDirectory - }).on('end', function() { + utils.extractTar(packageDirectory + "/" + packageName + ".js", packageDirectory, function() { if (returnContent) { let distFile = packageDirectory + packageName + ".js"; callback(fs.readFileSync(distFile).toString()); } else { callback(packageDirectory); } - }) - ); + }); }); } @@ -77,19 +69,14 @@ class Npm { self.logger.info("downloading " + packageName + " " + version + "...."); utils.downloadFile(tarball, packageDirectory + "/downloaded_package.tgz", function() { - o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe( - tar.x({ - strip: 1, - C: packageDirectory - }).on('end', function() { + utils.extractTar(packageDirectory + "/downloaded_package.tgz", packageDirectory, function() { if (returnContent) { let distFile = packageDirectory + returnContent; callback(fs.readFileSync(distFile).toString()); } else { callback(packageDirectory); } - }) - ); + }); }); } } diff --git a/lib/utils/utils.js b/lib/utils/utils.js index d18b5b0a..742a3547 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -4,6 +4,7 @@ let merge = require('merge'); let http = require('follow-redirects').http; let https = require('follow-redirects').https; let shelljs = require('shelljs'); +var tar = require('tar'); //let fs = require('../core/fs.js'); let o_fs = require('fs-extra'); @@ -92,6 +93,17 @@ function downloadFile(url, dest, cb) { }); } +function extractTar(filename, packageDirectory, cb) { + o_fs.createReadStream(filename).pipe( + tar.x({ + strip: 1, + C: packageDirectory + }).on('end', function() { + cb(); + }) + ); +} + module.exports = { joinPath: joinPath, filesMatchingPattern: filesMatchingPattern, @@ -104,5 +116,6 @@ module.exports = { cd: cd, sed: sed, exit: exit, - downloadFile: downloadFile + downloadFile: downloadFile, + extractTar: extractTar };