Skip to content

Commit

Permalink
CB-8154 Fix errors adding platforms or plugins
Browse files Browse the repository at this point in the history
- Added utility function to unpack a package.tgz file (gzip + tar)
- Use the new utility function when fetching plugins from the registry
- Use the new utility function when downloading platforms from the registry
- This compensates for the change in npm behaviour that no longer unpacks
  files that are added to the npm cached (change in 1.4.10)

GitHub: close #130
  • Loading branch information
jpchase authored and kamrik committed Dec 15, 2014
1 parent 6b022a9 commit 2021987
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cordova-lib/src/cordova/lazy_load.js
Expand Up @@ -39,6 +39,7 @@ var path = require('path'),
URL = require('url'),
Q = require('q'),
npm = require('npm'),
unpack = require('../util/unpack'),
util = require('./util'),
stubplatform = {
url : undefined,
Expand Down Expand Up @@ -160,7 +161,9 @@ function npm_cache_add(pkg) {
return Q.ninvoke(npm.commands, 'cache', ['add', pkg]);
}).then(function(info) {
var pkgDir = path.resolve(npm.cache, info.name, info.version, 'package');
return pkgDir;
// Unpack the package that was added to the cache (CB-8154)
var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
return unpack.unpackTgz(package_tgz, pkgDir);
});
}

Expand Down
5 changes: 4 additions & 1 deletion cordova-lib/src/plugman/registry/registry.js
Expand Up @@ -32,6 +32,7 @@ var npm = require('npm'),
request = require('request'),
home = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE,
events = require('../../events'),
unpack = require('../../util/unpack'),
plugmanConfigDir = path.resolve(home, '.plugman'),
plugmanCacheDir = path.resolve(plugmanConfigDir, 'cache');

Expand Down Expand Up @@ -166,7 +167,9 @@ module.exports = {
var cl = (client === 'plugman' ? 'plugman' : 'cordova-cli');
bumpCounter(info, cl);
var pluginDir = path.resolve(npm.cache, info.name, info.version, 'package');
return pluginDir;
// Unpack the plugin that was added to the cache (CB-8154)
var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
return unpack.unpackTgz(package_tgz, pluginDir);
});
},

Expand Down
38 changes: 38 additions & 0 deletions cordova-lib/src/util/unpack.js
@@ -0,0 +1,38 @@
// commands for packing and unpacking tarballs
// this file is used by lib/cache.js

var events = require('../events'),
fs = require("fs"),
path = require("path"),
Q = require('q'),
tar = require("tar"),
zlib = require("zlib");

exports.unpackTgz = unpackTgz;

// Returns a promise for the path to the unpacked tarball (unzip + untar).
function unpackTgz(package_tgz, unpackTarget) {
return Q.promise(function(resolve, reject) {
var extractOpts = { type: "Directory", path: unpackTarget, strip: 1 };

fs.createReadStream(package_tgz)
.on("error", function (err) {
events.emit('verbose', 'Unable to open tarball ' + package_tgz + ': ' + err);
reject(err);
})
.pipe(zlib.createUnzip())
.on("error", function (err) {
events.emit('verbose', 'Error during unzip for ' + package_tgz + ': ' + err);
reject(err);
})
.pipe(tar.Extract(extractOpts))
.on('error', function(err) {
events.emit('verbose', 'Error during untar for ' + package_tgz + ': ' + err);
reject(err);
})
.on("end", resolve);
})
.then(function() {
return unpackTarget;
});
}

0 comments on commit 2021987

Please sign in to comment.