update normalize-package-json

This commit is contained in:
isaacs
2013-05-10 17:24:55 -07:00
parent 25ad746173
commit b2120688f7
8 changed files with 85 additions and 36 deletions

View File

@@ -0,0 +1,30 @@
This package contains code originally written by Isaac Z. Schlueter.
Used with permission.
Copyright (c) Meryn Stol ("Author")
All rights reserved.
The BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -2,6 +2,8 @@
normalize-package data exports a function that normalizes package metadata. This data is typically found in a package.json file, but in principle could come from any source - for example the npm registry.
normalize-package-data is used by [read-package-json](https://npmjs.org/package/read-package-json) to normalize the data it reads from a package.json file. In turn, read-package-json is used by [npm](https://npmjs.org/package/npm) and various npm-related tools.
## Installation
```
@@ -37,19 +39,19 @@ If the supplied data has an invalid name or version vield, `normalizeData` will
## What normalization (currently) entails
* The value of `name` field gets trimmed
* The value of `name` field gets trimmed.
* The value of the `version` field gets cleaned by `semver.clean`. See [documentation for the semver module](https://github.com/isaacs/node-semver).
* If `name` and/or `version` fields are missing, they are set to empty strings.
* If `repository` field is a string, it will become am object with `url` set to the original string value, and `type` set to `"git"`.
* If `files` field is not an array, it will be removed.
* If `bin` field is a string, then `bin` field will become an object with `name` set to the value of the `name` field, and `bin` set to the original string value.
* If `man` field is a string, it will become an array with the original string as its sole member
* If `man` field is a string, it will become an array with the original string as its sole member.
* If `keywords` field is string, it is considered to be a list of keywords separated by one or more white-space characters. It gets converted to an array by splitting on `\s+`.
* If `bundledDependencies` field (a typo) exists and `bundleDependencies` field does not, `bundledDependencies` will get renamed to `bundleDependencies`.
* All people fields (`author`, `maintainers`, `contributors`) get converted into objects with name, email and url properties.
* If the value of any of the depedencies fields (`dependencies`, `devDependencies`, `optionalDependencies`) are strings, they get converted into objects with familiar `name=>value` pairs.
* The values in `optionalDependencies` get added to `dependencies`. `optionalDependencies` array is left untouched.
* If `description` field does not exists, but `readme` field does, then (more or less) the first paragraph of text that's found in the readme is taken a value for `description`.
* If `bundledDependencies` field (a typo) exists and `bundleDependencies` field does not, `bundledDependencies` will get renamed to `bundleDependencies`.
* If the value of any of the dependencies fields (`dependencies`, `devDependencies`, `optionalDependencies`) is a string, it gets converted into an object with familiar `name=>value` pairs.
* The values in `optionalDependencies` get added to `dependencies`. The `optionalDependencies` array is left untouched.
* If `description` field does not exists, but `readme` field does, then (more or less) the first paragraph of text that's found in the readme is taken as value for `description`.
* If `repository` field is a string, it will become an object with `url` set to the original string value, and `type` set to `"git"`.
* If `bugs` field is a string, the value of `bugs` field is changed into an object with `url` set to the original string value.
* If `bugs` field does not exist, but `repository` field points to a repository hosted on GitHub, the value of the `bugs` field gets set to an url in the form of https://github.com/[owner-name]/[repo-name]/issues . If the repository field points to a GitHub Gist repo url, the associated http url is chosen.
* If `bugs` field is an object, the resulting value only has email and url properties. If email and url properties are not strings, they are ignored. If no valid values for either email or url is found, bugs field will be removed.
@@ -70,4 +72,9 @@ If `version` field is given, the value of the version field must be a valid *sem
## Credits
This code is based on read-package-json written by Isaac Schlueter.
This package contains code based on read-package-json written by Isaac Z. Schlueter. Used with permisson.
## License
normalize-package-data is released under the [BSD 2-Clause License](http://opensource.org/licenses/MIT).
Copyright (c) 2013 Meryn Stol

View File

@@ -6,7 +6,7 @@ var url = require("url")
var fixer = module.exports = {
fixRepositoryField: function(data) {
if (data.repostories) {
if (data.repositories) {
this.warn("'repositories' (plural) Not supported.\n" +
"Please pick one as the 'repository' field");
data.repository = data.repositories[0]

View File

@@ -18,7 +18,8 @@ function isValid (data, warnFunc) {
})
checkBugsField(data.bugs, warn)
checkScriptsField(data.scripts, warn)
if (!data.readme) warn("No readme data!")
if (!data.repository) warn("No repository field.")
if (!data.readme) warn("No readme data.")
if (data.description && typeof data.description !== 'string') {
warn("'description' field should be a string")
}
@@ -53,5 +54,5 @@ function makeTypoWarning (providedName, probableName, field) {
providedName = field + "['" + providedName + "']"
probableName = field + "['" + probableName + "']"
}
return providedName + " should probably be " + probableName
return providedName + " should probably be " + probableName + "."
}

File diff suppressed because one or more lines are too long

View File

@@ -47,7 +47,7 @@ tap.test("empty object", function(t) {
}
normalize(packageData, warn)
t.same(packageData, expect)
t.same(warnings, ["No readme data!"])
t.same(warnings, ["No repository field.","No readme data."])
t.end()
})
@@ -73,7 +73,8 @@ tap.test("urls required", function(t) {
console.error(a)
var expect =
[ 'No readme data!',
[ 'No repository field.',
'No readme data.',
'bugs.url field must be a string url. Deleted.',
'bugs.email field must be a string email. Deleted.',
'Normalized value of bugs field is an empty object. Deleted.',
@@ -98,3 +99,10 @@ tap.test('no new globals', function(t) {
t.same(Object.keys(global), globals)
t.end()
})
tap.test("singularize repositories", function(t) {
d = {repositories:["git@gist.github.com:123456.git"]}
normalize(d)
t.same(d.repository, { type: 'git', url: 'git@gist.github.com:123456.git' })
t.end()
});

View File

@@ -9,27 +9,30 @@ test('typos', function(t) {
}
var expect =
[ 'dependancies should probably be dependencies',
'dependecies should probably be dependencies',
'depdenencies should probably be dependencies',
'devEependencies should probably be devDependencies',
'depends should probably be dependencies',
'dev-dependencies should probably be devDependencies',
'devDependences should probably be devDependencies',
'devDepenencies should probably be devDependencies',
'devdependencies should probably be devDependencies',
'repostitory should probably be repository',
'prefereGlobal should probably be preferGlobal',
'hompage should probably be homepage',
'hampage should probably be homepage',
'autohr should probably be author',
'autor should probably be author',
'contributers should probably be contributors',
'publicationConfig should probably be publishConfig',
'No readme data!',
[ 'dependancies should probably be dependencies.',
'dependecies should probably be dependencies.',
'depdenencies should probably be dependencies.',
'devEependencies should probably be devDependencies.',
'depends should probably be dependencies.',
'dev-dependencies should probably be devDependencies.',
'devDependences should probably be devDependencies.',
'devDepenencies should probably be devDependencies.',
'devdependencies should probably be devDependencies.',
'repostitory should probably be repository.',
'prefereGlobal should probably be preferGlobal.',
'hompage should probably be homepage.',
'hampage should probably be homepage.',
'autohr should probably be author.',
'autor should probably be author.',
'contributers should probably be contributors.',
'publicationConfig should probably be publishConfig.',
'No repository field.',
'No repository field.',
'No readme data.',
'bugs.url field must be a string url. Deleted.',
'Normalized value of bugs field is an empty object. Deleted.',
'No readme data!' ]
'No repository field.',
'No readme data.' ]
normalize({"dependancies": "dependencies"
,"dependecies": "dependencies"

View File

@@ -35,5 +35,5 @@
"url": "https://github.com/isaacs/read-package-json/issues"
},
"_id": "read-package-json@0.4.1",
"_from": "read-package-json@latest"
"_from": "read-package-json@~0.4.1"
}