Skip to content

Commit

Permalink
build fix for ignore and files, version order, auto .js main check
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Mar 21, 2014
1 parent 9351f1a commit 3bc6d7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ function inDir(fileName, dir) {

exports.filterIgnoreAndFiles = function(dir, ignore, files) {

if (!ignore || !files)
if (!ignore && !files)
return Promise.resolve();

return asp(glob)(dir + path.sep + '**' + path.sep + '*')
.then(function(allFiles) {
var removeFiles = [];

allFiles.forEach(function(file) {
var fileName = path.resolve(dir, file);
var fileName = path.relative(dir, file);

// if files, remove all files except those in the files list
if (files && !files.some(function(keepFile) {
Expand All @@ -143,7 +143,11 @@ exports.filterIgnoreAndFiles = function(dir, ignore, files) {

// do removal
return Promise.all(removeFiles.map(function(removeFile) {
return asp(fs.unlink)(path.resolve(dir, removeFile));
return asp(fs.unlink)(path.resolve(dir, removeFile)).catch(function(e) {
if (e.code == 'EPERM')
return;
throw e;
});
}));
});
}
Expand Down
11 changes: 7 additions & 4 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,17 @@ exports.lookup = function(pkg) {
for (var v in versionMap)
versionList.push(v);

versionList = versionList.filter(function(v) {
return versionMap[v].stable;
});

versionList.sort(semver.compare);

// find highest stable match
// latest is empty string
for (var i = versionList.length - 1; i >=0; i--) {
if (!pkg.version || semver.match(pkg.version, versionList[i])) {
if (versionMap[versionList[i]].stable)
return { version: versionList[i], hash: versionMap[versionList[i]] };
return { version: versionList[i], hash: versionMap[versionList[i]] };
}
}

Expand Down Expand Up @@ -421,7 +424,7 @@ exports.download = function(pkg, jspmPackages, override, force) {
// don't build in dependencies
var pjsonObj = extend({}, pjson);
delete pjsonObj.dependencies;
return build.buildPackage(downloadDir, pjsonObj, path.relative(__dirname, downloadDir))
return build.buildPackage(downloadDir, pjsonObj, path.relative(process.cwd(), downloadDir))
.then(function() {
return pjson;
});
Expand Down Expand Up @@ -454,7 +457,7 @@ exports.download = function(pkg, jspmPackages, override, force) {

// try the package.json main
return new Promise(function(resolve, reject) {
fs.exists(path.resolve(downloadDir, main + '.js'), resolve);
fs.exists(path.resolve(downloadDir, main.substr(main.length - 3, 3) != '.js' ? main + '.js' : main), resolve);
})
.then(function(exists) {
if (!exists && hasMain)
Expand Down

0 comments on commit 3bc6d7f

Please sign in to comment.