Skip to content

Commit

Permalink
clean up Project name and license accessors
Browse files Browse the repository at this point in the history
There is no case where we want #license() to return a different value
than #get('license') and the implementation of #name() needs an
explanation for why the same is not true for it and #get('name').
  • Loading branch information
rmg committed Jan 30, 2017
1 parent 913c92b commit a99b947
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/project.js
Expand Up @@ -78,21 +78,18 @@ function Project$gather(cb) {
}
}

// returns the project name, defaulting to the package's directory name.
// Note that this cannot defer to this.get('name') because that can return an
// empty string when the name is missing.
function Project$name() {
if (this.normalizedPkgJSON && this.normalizedPkgJSON.name)
return this.normalizedPkgJSON.name;
if (this.rawPkgJSON && this.rawPkgJSON.name)
return this.rawPkgJSON.name;
if (this.rootPath)
return path.basename(this.rootPath);
}

function Project$license() {
if (this.normalizedPkgJSON && this.normalizedPkgJSON.license)
return this.normalizedPkgJSON.license;
if (this.rawPkgJSON && this.rawPkgJSON.license)
return this.rawPkgJSON.license;
return 'SEE LICENSE.md';
return this.get('license');
}

function Project$get(key, dflt) {
Expand Down
2 changes: 2 additions & 0 deletions test/test-project.js
Expand Up @@ -44,6 +44,7 @@ test('package parsing', function(t) {
t.ok(!('version' in p1.rawPkgJSON),
'does not modify data on load');
t.strictEqual(p1.nameVer(), 'testing@1.0.0-0');
t.strictEqual(p1.license(), 'SEE LICENSE.md');
t.strictEqual(p1.version(), '1.0.0-0',
'reports 1.0.0-0 as version if missing');
p1.version(p1.version());
Expand Down Expand Up @@ -148,5 +149,6 @@ test('package inference without package.json', function(t) {
mkdirp.sync(SANDBOX_NOJSON);
var p1 = new Project(SANDBOX_NOJSON);
t.equal(p1.nameVer(), 'SANDBOX-no-json@1.0.0-0');
t.equal(p1.license(), 'SEE LICENSE.md');
t.end();
});

0 comments on commit a99b947

Please sign in to comment.