Skip to content

Commit

Permalink
fix: handle author as object in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra authored and jantimon committed Aug 14, 2019
1 parent c663cfe commit 06da1f8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ const fs = require('fs');
const path = require('path');
const parseAuthor = require('parse-author');

/**
* Normalize author to {name, email, url}
*/
function getAuthor (pkg) {
return (
typeof pkg.author === 'string'
? parseAuthor(pkg.author)
: pkg.author && typeof pkg.author === 'object'
? {
name: pkg.author.name,
email: pkg.author.email,
url: pkg.author.url,
}
: {}
);
}

/**
* Reads file if it exists
*/
Expand Down Expand Up @@ -49,13 +66,13 @@ guessVersion (compilerWorkingDirectory) {
* Tries to guess the author name from the package.json
*/
guessDeveloperName (compilerWorkingDirectory) {
return parseAuthor(readPackageJson(compilerWorkingDirectory).author || "").name;
return getAuthor(readPackageJson(compilerWorkingDirectory)).name;
},

/**
* Tries to guess the author URL from the package.json
*/
guessDeveloperURL (compilerWorkingDirectory) {
return parseAuthor(readPackageJson(compilerWorkingDirectory).author || "").url;
return getAuthor(readPackageJson(compilerWorkingDirectory)).url;
},
};

0 comments on commit 06da1f8

Please sign in to comment.