Skip to content

Commit

Permalink
feat(resolve): add support for git dependencies
Browse files Browse the repository at this point in the history
fixes #12, #18, #19
  • Loading branch information
JamieMason committed Apr 3, 2016
1 parent ce673a4 commit 13b8604
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
18 changes: 18 additions & 0 deletions src/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var exec = require('child_process').exec;
var when = require('when');

module.exports = executeShellScript;

function executeShellScript(command) {
return when.promise(function(resolve, reject, notify) {
exec(command, function onExec(err, stdout, stderr) {
if (err) {
reject(err);
} else if (stderr) {
reject(err);
} else {
resolve(stdout.trim());
}
});
});
}
44 changes: 26 additions & 18 deletions src/npmCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,41 @@

// 3rd party modules

var exec = require('./exec');
var guard = require('when/guard');
var npm = require('npm');
var when = require('when');

// Public
// public

module.exports = {
ensure: guard(guard.n(10), ensurePackageIsCached)
};

// Implementation
// implementation

function ensurePackageIsCached(dep) {
return when.promise(promiseCacheEntry);

function promiseCacheEntry(resolve, reject, notify) {

notify('cache ' + dep.id);
return isCached(dep)
.then(function onCacheCheck(inCache) {
return inCache ? dep : addToCache(dep)
.then(function onCached() {
return dep;
});
});
}

npm.commands.cache.read(dep.name, dep.shrinkwrap.version, false, onComplete);
function isCached(dep) {
return exec('npm cache ls ' + dep.id)
.then(function onComplete(stdout) {
return stdout.indexOf('package.json') !== -1;
}, function onError(err) {
throw new Error('error checking if ' + dep.id + ' is already in npm cache: ' + err.toString());
});
}

function onComplete(err) {
if (err) {
reject('error adding ' + dep.id + ' to npm cache: ' + err.toString());
} else {
resolve(dep);
}
}
}
function addToCache(dep) {
return exec('npm cache add ' + dep.shrinkwrap.resolved)
.then(function onComplete() {
return dep;
}, function onError(err) {
throw new Error('error checking if ' + dep.id + ' is already in npm cache: ' + err.toString());
});
}

0 comments on commit 13b8604

Please sign in to comment.