diff --git a/lib/package.js b/lib/package.js index c0bc395e5..6504ee6fc 100644 --- a/lib/package.js +++ b/lib/package.js @@ -145,11 +145,11 @@ exports.getVersionMatch = function(pkg, versions) { versionList.push(v); } - branchVersions.sort(semver.compare); - versionList.sort(semver.compare); + branchVersions.sort(semver.compare).reverse(); + versionList.sort(semver.compare).reverse(); // find highest stable match in tags - for (var i = versionList.length - 1; i >=0; i--) { + for (var i = 0; i < versionList.length; i++) { var version = versionList[i]; var semverMatch = version.match(semver.semverRegEx); @@ -279,7 +279,7 @@ exports.download = function(pkg, jspmPackages, options, preload) { var downloadDir = path.resolve(jspmPackages, pkg.endpoint, pkg.exactPackage); var cacheDir = path.resolve(config.HOME, '.jspm', 'packages', pkg.endpoint, pkg.exactPackage); - var exactVersion, lastNamePart, main; + var lastNamePart, main; var override; @@ -290,9 +290,6 @@ exports.download = function(pkg, jspmPackages, options, preload) { var endpoint = ep.load(pkg.endpoint); return Promise.resolve() - .then(function() { - exactVersion = pkg.version; - }) // get the override .then(function() { @@ -377,7 +374,7 @@ exports.download = function(pkg, jspmPackages, options, preload) { if (endpoint.getPackageConfig) // we only use the getPackageConfig pjson if // we are going to run a build, otherwise we use the saved one - return Promise.resolve(endpoint.getPackageConfig(pkg.package, exactVersion, pkg.hash)) + return Promise.resolve(endpoint.getPackageConfig(pkg.package, pkg.version, pkg.hash)) .then(function(_pjson) { // apply the override and package config operations if (!pjson) @@ -408,7 +405,7 @@ exports.download = function(pkg, jspmPackages, options, preload) { }) // do the download .then(function() { - return endpoint.download(pkg.package, exactVersion, pkg.hash, cacheDir); + return endpoint.download(pkg.package, pkg.version, pkg.hash, cacheDir); }) // process the package fully @@ -466,6 +463,7 @@ exports.download = function(pkg, jspmPackages, options, preload) { exports.processPackage = function(pkg, dir, pjson) { var endpoint = ep.load(pkg.endpoint); var deps; + var buildErrors = []; return Promise.resolve() @@ -476,7 +474,10 @@ exports.processPackage = function(pkg, dir, pjson) { }) // apply build operations from the package.json - .then(function() { + .then(function(_buildErrors) { + if (_buildErrors) + buildErrors = buildErrors.concat(_buildErrors); + // don't build in dependencies deps = pjson.dependencies; delete pjson.dependencies; @@ -484,8 +485,17 @@ exports.processPackage = function(pkg, dir, pjson) { }) // save the final calculated package.json in place - .then(function() { + .then(function(_buildErrors) { + if (_buildErrors) + buildErrors = buildErrors.concat(_buildErrors); pjson.dependencies = deps; + }) + .then(function() { + // write build errors + if (buildErrors.length) + return asp(fs.writeFile)(path.resolve(dir, '.jspm.errors'), buildErrors.join('\n\n')); + }) + .then(function() { return asp(fs.writeFile)(path.resolve(dir, '.jspm.json'), JSON.stringify(pjson, null, 2)); }); }