mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
prevent cruft in Package objects (#787)
This commit is contained in:
parent
7471685fa9
commit
53d2ed719b
@ -17,9 +17,7 @@ function getLicenses(packageInfo) {
|
||||
licenses.push({ type: packageInfo.license });
|
||||
}
|
||||
|
||||
if (licenses.length) {
|
||||
return licenses;
|
||||
}
|
||||
return licenses;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,12 +86,14 @@ exports.Package = function(json) {
|
||||
packageInfo = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* The package name.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = packageInfo.name;
|
||||
if (packageInfo.name) {
|
||||
/**
|
||||
* The package name.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = packageInfo.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The unique longname for this `Package` object.
|
||||
@ -102,65 +102,79 @@ exports.Package = function(json) {
|
||||
*/
|
||||
this.longname = this.kind + ':' + this.name;
|
||||
|
||||
/**
|
||||
* The author of this package. Contains either a
|
||||
* {@link module:jsdoc/package.Package~PersonInfo PersonInfo} object or a string with
|
||||
* information about the author.
|
||||
*
|
||||
* @type {(module:jsdoc/package.Package~PersonInfo|string)}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.author = packageInfo.author;
|
||||
if (packageInfo.author) {
|
||||
/**
|
||||
* The author of this package. Contains either a
|
||||
* {@link module:jsdoc/package.Package~PersonInfo PersonInfo} object or a string with
|
||||
* information about the author.
|
||||
*
|
||||
* @type {(module:jsdoc/package.Package~PersonInfo|string)}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.author = packageInfo.author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Information about where to report bugs in the project. May contain a URL, as a string, or
|
||||
* an object with more detailed information.
|
||||
*
|
||||
* @type {(string|module:jsdoc/package.Package~BugInfo)}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.bugs = packageInfo.bugs;
|
||||
if (packageInfo.bugs) {
|
||||
/**
|
||||
* Information about where to report bugs in the project. May contain a URL, as a string, or
|
||||
* an object with more detailed information.
|
||||
*
|
||||
* @type {(string|module:jsdoc/package.Package~BugInfo)}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.bugs = packageInfo.bugs;
|
||||
}
|
||||
|
||||
/**
|
||||
* The contributors to this package.
|
||||
*
|
||||
* @type {Array.<(module:jsdoc/package.Package~PersonInfo|string)>}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.contributors = packageInfo.contributors;
|
||||
if (packageInfo.contributors) {
|
||||
/**
|
||||
* The contributors to this package.
|
||||
*
|
||||
* @type {Array.<(module:jsdoc/package.Package~PersonInfo|string)>}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.contributors = packageInfo.contributors;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dependencies for this package.
|
||||
*
|
||||
* @type {Object}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.dependencies = packageInfo.dependencies;
|
||||
if (packageInfo.dependencies) {
|
||||
/**
|
||||
* The dependencies for this package.
|
||||
*
|
||||
* @type {Object}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.dependencies = packageInfo.dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* A brief description of the package.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.description = packageInfo.description;
|
||||
if (packageInfo.description) {
|
||||
/**
|
||||
* A brief description of the package.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.description = packageInfo.description;
|
||||
}
|
||||
|
||||
/**
|
||||
* The development dependencies for this package.
|
||||
*
|
||||
* @type {Object}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.devDependencies = packageInfo.devDependencies;
|
||||
if (packageInfo.devDependencies) {
|
||||
/**
|
||||
* The development dependencies for this package.
|
||||
*
|
||||
* @type {Object}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.devDependencies = packageInfo.devDependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* The JavaScript engines that this package supports. Each key is a string that identifies the
|
||||
* engine (for example, `node`). Each value is a
|
||||
* [semver](https://www.npmjs.org/doc/misc/semver.html)-compliant version number for the engine.
|
||||
*
|
||||
* @type {Object}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.engines = packageInfo.engines;
|
||||
if (packageInfo.engines) {
|
||||
/**
|
||||
* The JavaScript engines that this package supports. Each key is a string that identifies the
|
||||
* engine (for example, `node`). Each value is a
|
||||
* [semver](https://www.npmjs.org/doc/misc/semver.html)-compliant version number for the engine.
|
||||
*
|
||||
* @type {Object}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.engines = packageInfo.engines;
|
||||
}
|
||||
|
||||
/**
|
||||
* The source files associated with the package.
|
||||
@ -175,54 +189,66 @@ exports.Package = function(json) {
|
||||
*/
|
||||
this.files = [];
|
||||
|
||||
/**
|
||||
* The URL for the package's homepage.
|
||||
*
|
||||
* @type {string}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.homepage = packageInfo.homepage;
|
||||
if (packageInfo.homepage) {
|
||||
/**
|
||||
* The URL for the package's homepage.
|
||||
*
|
||||
* @type {string}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.homepage = packageInfo.homepage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keywords to help users find the package.
|
||||
*
|
||||
* @type {Array.<string>}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.keywords = packageInfo.keywords;
|
||||
if (packageInfo.keywords) {
|
||||
/**
|
||||
* Keywords to help users find the package.
|
||||
*
|
||||
* @type {Array.<string>}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.keywords = packageInfo.keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* The licenses used by this package. Combines information from the `package.json` file's
|
||||
* `license` property and the deprecated `licenses` property.
|
||||
*
|
||||
* @type {Array.<module:jsdoc/package.Package~LicenseInfo>}
|
||||
*/
|
||||
this.licenses = getLicenses(packageInfo);
|
||||
if (packageInfo.license || packageInfo.licenses) {
|
||||
/**
|
||||
* The licenses used by this package. Combines information from the `package.json` file's
|
||||
* `license` property and the deprecated `licenses` property.
|
||||
*
|
||||
* @type {Array.<module:jsdoc/package.Package~LicenseInfo>}
|
||||
*/
|
||||
this.licenses = getLicenses(packageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* The module ID that provides the primary entry point to the package. For example, if your
|
||||
* package is a CommonJS module, and the value of this property is `foo`, users should be able
|
||||
* to load your module with `require('foo')`.
|
||||
*
|
||||
* @type {string}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.main = packageInfo.main;
|
||||
if (packageInfo.main) {
|
||||
/**
|
||||
* The module ID that provides the primary entry point to the package. For example, if your
|
||||
* package is a CommonJS module, and the value of this property is `foo`, users should be able
|
||||
* to load your module with `require('foo')`.
|
||||
*
|
||||
* @type {string}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.main = packageInfo.main;
|
||||
}
|
||||
|
||||
/**
|
||||
* The version-control repository for the package.
|
||||
*
|
||||
* @type {module:jsdoc/package.Package~RepositoryInfo}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.repository = packageInfo.repository;
|
||||
if (packageInfo.repository) {
|
||||
/**
|
||||
* The version-control repository for the package.
|
||||
*
|
||||
* @type {module:jsdoc/package.Package~RepositoryInfo}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
this.repository = packageInfo.repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* The [semver](https://www.npmjs.org/doc/misc/semver.html)-compliant version number of the
|
||||
* package.
|
||||
*
|
||||
* @type {string}
|
||||
* @since 3.2.0
|
||||
*/
|
||||
this.version = packageInfo.version;
|
||||
if (packageInfo.version) {
|
||||
/**
|
||||
* The [semver](https://www.npmjs.org/doc/misc/semver.html)-compliant version number of the
|
||||
* package.
|
||||
*
|
||||
* @type {string}
|
||||
* @since 3.2.0
|
||||
*/
|
||||
this.version = packageInfo.version;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
/*global beforeEach, describe, expect, it, spyOn */
|
||||
'use strict';
|
||||
|
||||
var hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
|
||||
describe('jsdoc/package', function() {
|
||||
var emptyPackage;
|
||||
var jsdocPackage = require('jsdoc/package');
|
||||
@ -61,8 +63,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('author', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.author).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'author') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -71,8 +73,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('bugs', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.bugs).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'bugs') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -81,8 +83,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('contributors', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.contributors).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'contributors') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -94,8 +96,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('dependencies', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.dependencies).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'dependencies') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -104,8 +106,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('description', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.description).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'description') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -114,8 +116,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('devDependencies', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.devDependencies).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'devDependencies') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -124,8 +126,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('engines', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.engines).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'engines') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -147,8 +149,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('homepage', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.homepage).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'homepage') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -157,8 +159,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('keywords', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.keywords).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'keywords') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -167,8 +169,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('licenses', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.licenses).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'licenses') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -214,8 +216,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('main', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.main).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'main') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -224,8 +226,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('name', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.name).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'name') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -234,8 +236,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('repository', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.repository).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'repository') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
@ -247,8 +249,8 @@ describe('jsdoc/package', function() {
|
||||
});
|
||||
|
||||
describe('version', function() {
|
||||
it('should be undefined by default', function() {
|
||||
expect(emptyPackage.version).not.toBeDefined();
|
||||
it('should not exist by default', function() {
|
||||
expect( hasOwnProp.call(emptyPackage, 'version') ).toBe(false);
|
||||
});
|
||||
|
||||
it('should contain the value from the package file', function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user