Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix missing package.json handling

  • Loading branch information...
commit ecebc46ab44059da41ed770c274535c3b3a86fa0 1 parent 9294447
@kriszyp authored
Showing with 15 additions and 7 deletions.
  1. +15 −7 lib/model/package.js
View
22 lib/model/package.js
@@ -135,6 +135,9 @@ function updateVersions(pckg, force){
packageUpdates.push(request({url:repo.url + "/raw/" + gitVersion + "/package.json"}).then(function(response){
return response && response.body.join("");
}).then(function(packageJson){
+ if(packageJson == null){
+ return;
+ }
try{
var packageData = JSON.parse(packageJson);
var dependencies = {};
@@ -217,13 +220,17 @@ function publish(url, asName, force){
// an archive, need to download the archive, extract the package.json
}
return packageJson.then(function(packageJson){
- try{
- // fix trailing commas
- packageJson = packageJson.replace(/,\s*}/g, ']');
- var packageData = JSON.parse(packageJson);
- }catch(e){
- e.message += " in package.json: " + packageJson;
- throw e;
+ if(packageJson == null){
+ var packageData = {name: asName || url.match(/https?:\/\/github\.com\/[^\/]+\/([^\/]+)/)[1]};
+ }else{
+ try{
+ // fix trailing commas
+ packageJson = packageJson.replace(/,\s*}/g, ']');
+ var packageData = JSON.parse(packageJson);
+ }catch(e){
+ e.message += " in package.json: " + packageJson;
+ throw e;
+ }
}
var existing = packageStore.get(packageData.name);
if(existing){
@@ -258,6 +265,7 @@ function cacheArchive(url){
function request(args, tries){
tries = tries || 1;
+ (args.headers = args.headers || {})["user-agent"] = "CommonJS Package Repository 0.1";
print("Downloading " + args.url + (tries > 1 ? " attempt #" + tries : ""));
return httpClient.request(args).then(function(response){
if(response.status == 302 || response.status == 301){
Please sign in to comment.
Something went wrong with that request. Please try again.