pax_global_header00006660000000000000000000000064122054354070014514gustar00rootroot0000000000000052 comment=5212a28b5713fffb43c7ebc3dfc72c79ec5f3b3e normalize-package-data-0.2.2/000077500000000000000000000000001220543540700160155ustar00rootroot00000000000000normalize-package-data-0.2.2/.gitignore000066400000000000000000000000161220543540700200020ustar00rootroot00000000000000/node_modules/normalize-package-data-0.2.2/.travis.yml000066400000000000000000000000571220543540700201300ustar00rootroot00000000000000language: node_js node_js: - "0.10" - "0.8"normalize-package-data-0.2.2/AUTHORS000066400000000000000000000001651220543540700170670ustar00rootroot00000000000000# Names sorted by how much code was originally theirs. Isaac Z. Schlueter Meryn Stol normalize-package-data-0.2.2/LICENSE000066400000000000000000000025631220543540700170300ustar00rootroot00000000000000This 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. normalize-package-data-0.2.2/README.md000066400000000000000000000134461220543540700173040ustar00rootroot00000000000000# normalize-package-data [![Build Status](https://travis-ci.org/meryn/normalize-package-data.png?branch=master)](https://travis-ci.org/meryn/normalize-package-data) 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 ``` npm install normalize-package-data ``` ## Usage Basic usage is really simple. You call the function that normalize-package-data exports. Let's call it `normalizeData`. ```javascript normalizeData = require('normalize-package-data') packageData = fs.readfileSync("package.json") normalizeData(packageData) // packageData is now normalized ``` #### Strict mode You may activate strict validation by passing true as the second argument. ```javascript normalizeData = require('normalize-package-data') packageData = fs.readfileSync("package.json") warnFn = function(msg) { console.error(msg) } normalizeData(packageData, true) // packageData is now normalized ``` If strict mode is activated, only Semver 2.0 version strings are accepted. Otherwise, Semver 1.0 strings are accepted as well. Packages must have a name, and the name field must not have contain leading or trailing whitespace. #### Warnings Optionally, you may pass a "warning" function. It gets called whenever the `normalizeData` function encounters something that doesn't look right. It indicates less than perfect input data. ```javascript normalizeData = require('normalize-package-data') packageData = fs.readfileSync("package.json") warnFn = function(msg) { console.error(msg) } normalizeData(packageData, warnFn) // packageData is now normalized. Any number of warnings may have been logged. ``` You may combine strict validation with warnings by passing `true` as the second argument, and `warnFn` as third. When `private` field is set to `true`, warnings will be suppressed. ### Potential exceptions If the supplied data has an invalid name or version vield, `normalizeData` will throw an error. Depending on where you call `normalizeData`, you may want to catch these errors so can pass them to a callback. ## What normalization (currently) entails * The value of `name` field gets trimmed (unless in strict mode). * 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 `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 `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+`. * All people fields (`author`, `maintainers`, `contributors`) get converted into objects with name, email and url properties. * 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. * If `homepage` field is not a string, it will be removed. * If the url in the `homepage` field does not specify a protocol, then http is assumed. For example, `myproject.org` will be changed to `http://myproject.org`. ### Rules for name field If `name` field is given, the value of the name field must be a string. The string may not: * start with a period. * contain the following characters: `/@\s+%` * contain and characters that would need to be encoded for use in urls. * resemble the word `node_modules` or `favicon.ico` (case doesn't matter). ### Rules for version field If `version` field is given, the value of the version field must be a valid *semver* string, as determined by the `semver.valid` method. See [documentation for the semver module](https://github.com/isaacs/node-semver). ## Credits 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 normalize-package-data-0.2.2/lib/000077500000000000000000000000001220543540700165635ustar00rootroot00000000000000normalize-package-data-0.2.2/lib/extract_description.js000066400000000000000000000007111220543540700231750ustar00rootroot00000000000000module.exports = extractDescription // Extracts description from contents of a readme file in markdown format function extractDescription (d) { if (!d) return; // the first block of text before the first heading // that isn't the first line heading d = d.trim().split('\n') for (var s = 0; d[s] && d[s].trim().match(/^(#|$)/); s ++); var l = d.length for (var e = s + 1; e < l && d[e].trim(); e ++); return d.slice(s, e).join(' ').trim() } normalize-package-data-0.2.2/lib/fixer.js000066400000000000000000000246641220543540700202520ustar00rootroot00000000000000var semver = require("semver") var parseGitHubURL = require("github-url-from-git") var depTypes = ["dependencies","devDependencies","optionalDependencies"] var extractDescription = require("./extract_description") var url = require("url") var typos = require("./typos") var fixer = module.exports = { // default warning function warn: function() {}, fixRepositoryField: function(data) { if (data.repositories) { this.warn("'repositories' (plural) Not supported.\n" + "Please pick one as the 'repository' field"); data.repository = data.repositories[0] } if (!data.repository) return this.warn('No repository field.') if (typeof data.repository === "string") { data.repository = { type: "git", url: data.repository } } var r = data.repository.url || "" if (r) { var ghurl = parseGitHubURL(r) if (ghurl) { r = ghurl.replace(/^https?:\/\//, 'git://') } else if (/^[\w-]+\/[\w-]+$/.test(r)) { // repo has 'user/reponame' filled in as repo data.repository.url = "git://github.com/" + r } } if (r.match(/github.com\/[^\/]+\/[^\/]+\.git\.git$/)) { this.warn("Probably broken git url: " + r) } } , fixTypos: function(data) { Object.keys(typos.topLevel).forEach(function (d) { if (data.hasOwnProperty(d)) { this.warn(makeTypoWarning(d, typos.topLevel[d])) } }, this) } , fixScriptsField: function(data) { if (!data.scripts) return if (typeof data.scripts !== "object") { this.warn("scripts must be an object") delete data.scripts } Object.keys(data.scripts).forEach(function (k) { if (typeof data.scripts[k] !== "string") { this.warn("script values must be string commands") delete data.scripts[k] } else if (typos.script[k]) { this.warn(makeTypoWarning(k, typos.script[k], "scripts")) } }, this) } , fixFilesField: function(data) { var files = data.files if (files && !Array.isArray(files)) { this.warn("Invalid 'files' member") delete data.files } else if (data.files) { data.files = data.files.filter(function(file) { if (!file || typeof file !== "string") { this.warn("Invalid filename in 'files' list: " + file) return false } else { return true } }, this) } } , fixBinField: function(data) { if (!data.bin) return; if (typeof data.bin === "string") { var b = {} b[data.name] = data.bin data.bin = b } } , fixManField: function(data) { if (!data.man) return; if (typeof data.man === "string") { data.man = [ data.man ] } } , fixBundleDependenciesField: function(data) { var bdd = "bundledDependencies" var bd = "bundleDependencies" if (data[bdd] && !data[bd]) { data[bd] = data[bdd] delete data[bdd] } if (data[bd] && !Array.isArray(data[bd])) { this.warn("Invalid 'bundleDependencies' list. " + "Must be array of package names") delete data[bd] } else if (data[bd]) { data[bd] = data[bd].filter(function(bd) { if (!bd || typeof bd !== 'string') { this.warn("Invalid bundleDependencies member: " + bd) return false } else { return true } }, this) } } , fixDependencies: function(data, strict) { var loose = !strict objectifyDeps(data, this.warn) addOptionalDepsToDeps(data, this.warn) this.fixBundleDependenciesField(data) ;['dependencies','devDependencies'].forEach(function(deps) { if (!(deps in data)) return if (!data[deps] || typeof data[deps] !== "object") { this.warn(deps + " field must be an object") delete data[deps] return } Object.keys(data[deps]).forEach(function (d) { var r = data[deps][d] if (typeof r !== 'string') { this.warn('Invalid dependency: ' + d + ' ' + JSON.stringify(r)) delete data[deps][d] } }, this) }, this) } , fixModulesField: function (data) { if (data.modules) { this.warn("modules field is deprecated") delete data.modules } } , fixKeywordsField: function (data) { if (typeof data.keywords === "string") { data.keywords = data.keywords.split(/,\s+/) } if (data.keywords && !Array.isArray(data.keywords)) { delete data.keywords this.warn("keywords should be an array of strings") } else if (data.keywords) { data.keywords = data.keywords.filter(function(kw) { if (typeof kw !== "string" || !kw) { this.warn("keywords should be an array of strings"); return false } else { return true } }, this) } } , fixVersionField: function(data, strict) { // allow "loose" semver 1.0 versions in non-strict mode // enforce strict semver 2.0 compliance in strict mode var loose = !strict if (!data.version) { data.version = "" return true } if (!semver.valid(data.version, loose)) { throw new Error('Invalid version: "'+ data.version + '"') } data.version = semver.clean(data.version, loose) return true } , fixPeople: function(data) { modifyPeople(data, unParsePerson) modifyPeople(data, parsePerson) } , fixNameField: function(data, strict) { if (!data.name && !strict) { data.name = "" return } if (typeof data.name !== "string") { throw new Error("name field must be a string.") } if (!strict) data.name = data.name.trim() ensureValidName(data.name, strict) } , fixDescriptionField: function (data) { if (data.description && typeof data.description !== 'string') { this.warn("'description' field should be a string") delete data.description } if (data.readme && !data.description) data.description = extractDescription(data.readme) if (!data.description) this.warn('No description') } , fixReadmeField: function (data) { if (!data.readme) { this.warn("No README data") data.readme = "ERROR: No README data found!" } } , fixBugsField: function(data) { if (!data.bugs && data.repository && data.repository.url) { var gh = parseGitHubURL(data.repository.url) if(gh) { if(gh.match(/^https:\/\/github.com\//)) data.bugs = {url: gh + "/issues"} else // gist url data.bugs = {url: gh} } } else if(data.bugs) { var emailRe = /^.+@.*\..+$/ if(typeof data.bugs == "string") { if(emailRe.test(data.bugs)) data.bugs = {email:data.bugs} else if(url.parse(data.bugs).protocol) data.bugs = {url: data.bugs} else this.warn("Bug string field must be url, email, or {email,url}") } else { bugsTypos(data.bugs, this.warn) var oldBugs = data.bugs data.bugs = {} if(oldBugs.url) { if(typeof(oldBugs.url) == "string" && url.parse(oldBugs.url).protocol) data.bugs.url = oldBugs.url else this.warn("bugs.url field must be a string url. Deleted.") } if(oldBugs.email) { if(typeof(oldBugs.email) == "string" && emailRe.test(oldBugs.email)) data.bugs.email = oldBugs.email else this.warn("bugs.email field must be a string email. Deleted.") } } if(!data.bugs.email && !data.bugs.url) { delete data.bugs this.warn("Normalized value of bugs field is an empty object. Deleted.") } } } , fixHomepageField: function(data) { if(!data.homepage) return true; if(typeof data.homepage !== "string") { this.warn("homepage field must be a string url. Deleted.") return delete data.homepage } if(!url.parse(data.homepage).protocol) { this.warn("homepage field must start with a protocol.") data.homepage = "http://" + data.homepage } } } function ensureValidName (name, strict) { if (name.charAt(0) === "." || name.match(/[\/@\s\+%:]/) || name !== encodeURIComponent(name) || (strict && name !== name.toLowerCase()) || name.toLowerCase() === "node_modules" || name.toLowerCase() === "favicon.ico") { throw new Error("Invalid name: " + JSON.stringify(name)) } } function modifyPeople (data, fn) { if (data.author) data.author = fn(data.author) ;["maintainers", "contributors"].forEach(function (set) { if (!Array.isArray(data[set])) return; data[set] = data[set].map(fn) }) return data } function unParsePerson (person) { if (typeof person === "string") return person var name = person.name || "" var u = person.url || person.web var url = u ? (" ("+u+")") : "" var e = person.email || person.mail var email = e ? (" <"+e+">") : "" return name+email+url } function parsePerson (person) { if (typeof person !== "string") return person var name = person.match(/^([^\(<]+)/) var url = person.match(/\(([^\)]+)\)/) var email = person.match(/<([^>]+)>/) var obj = {} if (name && name[0].trim()) obj.name = name[0].trim() if (email) obj.email = email[1]; if (url) obj.url = url[1]; return obj } function addOptionalDepsToDeps (data, warn) { var o = data.optionalDependencies if (!o) return; var d = data.dependencies || {} Object.keys(o).forEach(function (k) { d[k] = o[k] }) data.dependencies = d } function depObjectify (deps) { if (!deps) return {} if (typeof deps === "string") { deps = deps.trim().split(/[\n\r\s\t ,]+/) } if (!Array.isArray(deps)) return deps var o = {} deps.filter(function (d) { return typeof d === "string" }).forEach(function(d) { d = d.trim().split(/(:?[@\s><=])/) var dn = d.shift() var dv = d.join("") dv = dv.trim() dv = dv.replace(/^@/, "") o[dn] = dv }) return o } function objectifyDeps (data, warn) { depTypes.forEach(function (type) { if (!data[type]) return; data[type] = depObjectify(data[type]) }) } function bugsTypos(bugs, warn) { if (!bugs) return Object.keys(bugs).forEach(function (k) { if (typos.bugs[k]) { warn(makeTypoWarning(k, typos.bugs[k], "bugs")) bugs[typos.bugs[k]] = bugs[k] delete bugs[k] } }) } function makeTypoWarning (providedName, probableName, field) { if (field) { providedName = field + "['" + providedName + "']" probableName = field + "['" + probableName + "']" } return providedName + " should probably be " + probableName + "." } normalize-package-data-0.2.2/lib/normalize.js000066400000000000000000000022761220543540700211300ustar00rootroot00000000000000module.exports = normalize var fixer = require("./fixer") var fieldsToFix = ['name','version','description','repository','modules','scripts' ,'files','bin','man','bugs','keywords','readme','homepage'] var otherThingsToFix = ['dependencies','people', 'typos'] var thingsToFix = fieldsToFix.map(function(fieldName) { return ucFirst(fieldName) + "Field" }) // two ways to do this in CoffeeScript on only one line, sub-70 chars: // thingsToFix = fieldsToFix.map (name) -> ucFirst(name) + "Field" // thingsToFix = (ucFirst(name) + "Field" for name in fieldsToFix) thingsToFix = thingsToFix.concat(otherThingsToFix) function normalize (data, warn, strict) { if(warn === true) warn = null, strict = true if(!strict) strict = false if(!warn || data.private) warn = function(msg) { /* noop */ } if (data.scripts && data.scripts.install === "node-gyp rebuild" && !data.scripts.preinstall) { data.gypfile = true } fixer.warn = warn thingsToFix.forEach(function(thingName) { fixer["fix" + ucFirst(thingName)](data, strict) }) data._id = data.name + "@" + data.version } function ucFirst (string) { return string.charAt(0).toUpperCase() + string.slice(1); } normalize-package-data-0.2.2/lib/typos.json000066400000000000000000000013231220543540700206330ustar00rootroot00000000000000{ "topLevel": { "dependancies": "dependencies" ,"dependecies": "dependencies" ,"depdenencies": "dependencies" ,"devEependencies": "devDependencies" ,"depends": "dependencies" ,"dev-dependencies": "devDependencies" ,"devDependences": "devDependencies" ,"devDepenencies": "devDependencies" ,"devdependencies": "devDependencies" ,"repostitory": "repository" ,"prefereGlobal": "preferGlobal" ,"hompage": "homepage" ,"hampage": "homepage" ,"autohr": "author" ,"autor": "author" ,"contributers": "contributors" ,"publicationConfig": "publishConfig" ,"script": "scripts" }, "bugs": { "web": "url", "name": "url" }, "script": { "server": "start", "tests": "test" } } normalize-package-data-0.2.2/package.json000066400000000000000000000010441220543540700203020ustar00rootroot00000000000000{ "name": "normalize-package-data", "version": "0.2.2", "author": "Meryn Stol ", "description": "Normalizes data that can be found in package.json files.", "repository": { "type": "git", "url": "git://github.com/meryn/normalize-package-data.git" }, "main": "lib/normalize.js", "scripts": { "test": "tap test/*.js" }, "dependencies": { "semver": "2", "github-url-from-git": "~1.1.1" }, "devDependencies": { "tap": "~0.2.5", "underscore": "~1.4.4", "async": "~0.2.7" } } normalize-package-data-0.2.2/test/000077500000000000000000000000001220543540700167745ustar00rootroot00000000000000normalize-package-data-0.2.2/test/basic.js000066400000000000000000000027711220543540700204220ustar00rootroot00000000000000var tap = require("tap") var normalize = require("../lib/normalize") var path = require("path") var fs = require("fs") tap.test("basic test", function (t) { var p = path.resolve(__dirname, "./fixtures/read-package-json.json") fs.readFile (p, function (err, contents) { if (err) throw err; var originalData = JSON.parse(contents.toString()) var data = JSON.parse(contents.toString()) normalize(data) t.ok(data) verifyFields(t, data, originalData) t.end() }) }) function verifyFields (t, normalized, original) { t.equal(normalized.version, original.version, "Version field stays same") t.equal(normalized._id, normalized.name + "@" + normalized.version, "It gets good id.") t.equal(normalized.name, original.name, "Name stays the same.") t.type(normalized.author, "object", "author field becomes object") t.deepEqual(normalized.scripts, original.scripts, "scripts field (object) stays same") t.equal(normalized.main, original.main) // optional deps are folded in. t.deepEqual(normalized.optionalDependencies, original.optionalDependencies) t.has(normalized.dependencies, original.optionalDependencies, "opt depedencies are copied into dependencies") t.has(normalized.dependencies, original.dependencies, "regular depedencies stay in place") t.deepEqual(normalized.devDependencies, original.devDependencies) t.type(normalized.bugs, "object", "bugs should become object") t.equal(normalized.bugs.url, "https://github.com/isaacs/read-package-json/issues") } normalize-package-data-0.2.2/test/consistency.js000066400000000000000000000023241220543540700216740ustar00rootroot00000000000000var tap = require("tap") var normalize = require("../lib/normalize") var path = require("path") var fs = require("fs") var _ = require("underscore") var async = require("async") var data, clonedData var warn tap.test("consistent normalization", function(t) { path.resolve(__dirname, "./fixtures/read-package-json.json") fs.readdir (__dirname + "/fixtures", function (err, entries) { // entries = ['coffee-script.json'] // uncomment to limit to a specific file verifyConsistency = function(entryName, next) { warn = function(msg) { // t.equal("",msg) // uncomment to have some kind of logging of warnings } filename = __dirname + "/fixtures/" + entryName fs.readFile(filename, function(err, contents) { if (err) return next(err) data = JSON.parse(contents.toString()) normalize(data, warn) clonedData = _.clone(data) normalize(data, warn) t.deepEqual(clonedData, data, "Normalization of " + entryName + "is consistent.") next(null) }) // fs.readFile } // verifyConsistency async.forEach(entries, verifyConsistency, function(err) { if (err) throw err t.end() }) }) // fs.readdir }) // tap.testnormalize-package-data-0.2.2/test/fixtures/000077500000000000000000000000001220543540700206455ustar00rootroot00000000000000normalize-package-data-0.2.2/test/fixtures/async.json000066400000000000000000000015471220543540700226640ustar00rootroot00000000000000{ "name": "async", "description": "Higher-order functions and common patterns for asynchronous code", "main": "./lib/async", "author": "Caolan McMahon", "version": "0.2.6", "repository" : { "type" : "git", "url" : "http://github.com/caolan/async.git" }, "bugs" : { "url" : "http://github.com/caolan/async/issues" }, "licenses" : [ { "type" : "MIT", "url" : "http://github.com/caolan/async/raw/master/LICENSE" } ], "devDependencies": { "nodeunit": ">0.0.0", "uglify-js": "1.2.x", "nodelint": ">0.0.0" }, "jam": { "main": "lib/async.js", "include": [ "lib/async.js", "README.md", "LICENSE" ] }, "scripts": { "test": "nodeunit test/test-async.js" } }normalize-package-data-0.2.2/test/fixtures/bcrypt.json000066400000000000000000000034351220543540700230500ustar00rootroot00000000000000{ "name": "bcrypt", "description": "A bcrypt library for NodeJS.", "keywords": [ "bcrypt", "password", "auth", "authentication", "encryption", "crypt", "crypto" ], "main": "./bcrypt", "version": "0.7.5", "author": "Nick Campbell (http://github.com/ncb000gt)", "engines": { "node": ">= 0.6.0" }, "repository": { "type": "git", "url": "http://github.com/ncb000gt/node.bcrypt.js.git" }, "licenses": [ { "type": "MIT" } ], "bugs": { "url": "http://github.com/ncb000gt/node.bcrypt.js/issues" }, "scripts": { "test": "node-gyp configure build && nodeunit test" }, "dependencies": { "bindings": "1.0.0" }, "devDependencies": { "nodeunit": ">=0.6.4" }, "contributors": [ "Antonio Salazar Cardozo (https://github.com/Shadowfiend)", "Van Nguyen (https://github.com/thegoleffect)", "David Trejo (https://github.com/dtrejo)", "Ben Glow (https://github.com/pixelglow)", "NewITFarmer.com <> (https://github.com/newitfarmer)", "Alfred Westerveld (https://github.com/alfredwesterveld)", "Vincent Côté-Roy (https://github.com/vincentcr)", "Lloyd Hilaiel (https://github.com/lloyd)", "Roman Shtylman (https://github.com/shtylman)", "Vadim Graboys (https://github.com/vadimg)", "Ben Noorduis <> (https://github.com/bnoordhuis)", "Nate Rajlich (https://github.com/tootallnate)", "Sean McArthur (https://github.com/seanmonstar)", "Fanie Oosthuysen (https://github.com/weareu)" ] }normalize-package-data-0.2.2/test/fixtures/coffee-script.json000066400000000000000000000016721220543540700242770ustar00rootroot00000000000000{ "name": "coffee-script", "description": "Unfancy JavaScript", "keywords": ["javascript", "language", "coffeescript", "compiler"], "author": "Jeremy Ashkenas", "version": "1.6.2", "licenses": [{ "type": "MIT", "url": "https://raw.github.com/jashkenas/coffee-script/master/LICENSE" }], "engines": { "node": ">=0.8.0" }, "directories" : { "lib" : "./lib/coffee-script" }, "main" : "./lib/coffee-script/coffee-script", "bin": { "coffee": "./bin/coffee", "cake": "./bin/cake" }, "scripts": { "test": "node ./bin/cake test" }, "homepage": "http://coffeescript.org", "bugs": "https://github.com/jashkenas/coffee-script/issues", "repository": { "type": "git", "url": "git://github.com/jashkenas/coffee-script.git" }, "devDependencies": { "uglify-js": "~2.2", "jison": ">=0.2.0" } }normalize-package-data-0.2.2/test/fixtures/http-server.json000066400000000000000000000023061220543540700240240ustar00rootroot00000000000000{ "name": "http-server", "preferGlobal": true, "version": "0.3.0", "author": "Nodejitsu ", "description": "a simple zero-configuration command-line http server", "contributors": [ { "name": "Marak Squires", "email": "marak@nodejitsu.com" } ], "bin": { "http-server": "./bin/http-server" }, "scripts": { "start": "node ./bin/http-server", "test": "vows --spec --isolate", "predeploy": "echo This will be run before deploying the app", "postdeploy": "echo This will be run after deploying the app" }, "main": "./lib/http-server", "repository": { "type": "git", "url": "https://github.com/nodejitsu/http-server.git" }, "keywords": [ "cli", "http", "server" ], "dependencies" : { "colors" : "*", "flatiron" : "0.1.x", "optimist" : "0.2.x", "union" : "0.1.x", "ecstatic" : "0.1.x", "plates" : "https://github.com/flatiron/plates/tarball/master" }, "analyze": false, "devDependencies": { "vows" : "0.5.x", "request" : "2.1.x" }, "bundledDependencies": [ "union", "ecstatic" ], "license": "MIT", "engines": { "node": ">=0.6" } }normalize-package-data-0.2.2/test/fixtures/movefile.json000066400000000000000000000010701220543540700233440ustar00rootroot00000000000000{ "name": "movefile", "description": "rename implementation working over devices", "version": "0.2.0", "author": "yazgazan ", "main": "./build/Release/movefile", "keywords": ["move", "file", "rename"], "repository": "git://github.com/yazgazan/movefile.git", "directories": { "lib": "./build/Release/" }, "scripts": { "install": "./node_modules/node-gyp/bin/node-gyp.js configure && ./node_modules/node-gyp/bin/node-gyp.js build" }, "engines": { "node": "*" }, "dependencies": { "node-gyp": "~0.9.1" } }normalize-package-data-0.2.2/test/fixtures/node-module_exist.json000066400000000000000000000011161220543540700251630ustar00rootroot00000000000000{ "name": "node-module_exist", "description": "Find if a NodeJS module is available to require or not", "version": "0.0.1", "main": "module_exist.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git@gist.github.com:3135914.git" }, "homepage": "https://github.com/FGRibreau", "author": { "name": "Francois-Guillaume Ribreau", "url": "http://fgribreau.com.com/" }, "devDependencies": { "nodeunit": "~0.7.4" }, "keywords": [ "core", "modules" ], "license": "MIT" }normalize-package-data-0.2.2/test/fixtures/npm.json000066400000000000000000000054121220543540700223340ustar00rootroot00000000000000{ "version": "1.2.17", "name": "npm", "publishConfig": { "proprietary-attribs": false }, "description": "A package manager for node", "keywords": [ "package manager", "modules", "install", "package.json" ], "preferGlobal": true, "config": { "publishtest": false }, "homepage": "https://npmjs.org/doc/", "author": "Isaac Z. Schlueter (http://blog.izs.me)", "repository": { "type": "git", "url": "https://github.com/isaacs/npm" }, "bugs": { "email": "npm-@googlegroups.com", "url": "http://github.com/isaacs/npm/issues" }, "directories": { "doc": "./doc", "man": "./man", "lib": "./lib", "bin": "./bin" }, "main": "./lib/npm.js", "bin": "./bin/npm-cli.js", "dependencies": { "semver": "~1.1.2", "ini": "~1.1.0", "slide": "1", "abbrev": "~1.0.4", "graceful-fs": "~1.2.0", "minimatch": "~0.2.11", "nopt": "~2.1.1", "rimraf": "2", "request": "~2.9", "which": "1", "tar": "~0.1.17", "fstream": "~0.1.22", "block-stream": "*", "inherits": "1", "mkdirp": "~0.3.3", "read": "~1.0.4", "lru-cache": "~2.3.0", "node-gyp": "~0.9.3", "fstream-npm": "~0.1.3", "uid-number": "0", "archy": "0", "chownr": "0", "npmlog": "0", "ansi": "~0.1.2", "npm-registry-client": "~0.2.18", "read-package-json": "~0.3.0", "read-installed": "0", "glob": "~3.1.21", "init-package-json": "0.0.6", "osenv": "0", "lockfile": "~0.3.0", "retry": "~0.6.0", "once": "~1.1.1", "npmconf": "0", "opener": "~1.3.0", "chmodr": "~0.1.0", "cmd-shim": "~1.1.0" }, "bundleDependencies": [ "semver", "ini", "slide", "abbrev", "graceful-fs", "minimatch", "nopt", "rimraf", "request", "which", "tar", "fstream", "block-stream", "inherits", "mkdirp", "read", "lru-cache", "node-gyp", "fstream-npm", "uid-number", "archy", "chownr", "npmlog", "ansi", "npm-registry-client", "read-package-json", "read-installed", "glob", "init-package-json", "osenv", "lockfile", "retry", "once", "npmconf", "opener", "chmodr", "cmd-shim" ], "devDependencies": { "ronn": "~0.3.6", "tap": "~0.4.0" }, "engines": { "node": ">=0.6", "npm": "1" }, "scripts": { "test": "node ./test/run.js && tap test/tap/*.js", "tap": "tap test/tap/*.js", "prepublish": "node bin/npm-cli.js prune ; rm -rf test/*/*/node_modules ; make -j4 doc", "dumpconf": "env | grep npm | sort | uniq", "echo": "node bin/npm-cli.js" }, "licenses": [ { "type": "MIT +no-false-attribs", "url": "https://github.com/isaacs/npm/raw/master/LICENSE" } ] }normalize-package-data-0.2.2/test/fixtures/read-package-json.json000066400000000000000000000012171220543540700250140ustar00rootroot00000000000000{ "name": "read-package-json", "version": "0.1.1", "author": "Isaac Z. Schlueter (http://blog.izs.me/)", "description": "The thing npm uses to read package.json files with semantics and defaults and validation", "repository": { "type": "git", "url": "git://github.com/isaacs/read-package-json.git" }, "main": "read-json.js", "scripts": { "test": "tap test/*.js" }, "dependencies": { "glob": "~3.1.9", "lru-cache": "~1.1.0", "semver": "~1.0.14", "slide": "~1.1.3" }, "devDependencies": { "tap": "~0.2.5" }, "optionalDependencies": { "npmlog": "0", "graceful-fs": "~1.1.8" } }normalize-package-data-0.2.2/test/fixtures/request.json000066400000000000000000000014651220543540700232360ustar00rootroot00000000000000{ "name": "request", "description": "Simplified HTTP request client.", "tags": [ "http", "simple", "util", "utility" ], "version": "2.16.7", "author": "Mikeal Rogers ", "repository": { "type": "git", "url": "http://github.com/mikeal/request.git" }, "bugs": { "url": "http://github.com/mikeal/request/issues" }, "engines": [ "node >= 0.8.0" ], "main": "index.js", "dependencies": { "form-data": "~0.0.3", "mime": "~1.2.7", "hawk": "~0.10.2", "node-uuid": "~1.4.0", "cookie-jar": "~0.2.0", "aws-sign": "~0.2.0", "oauth-sign": "~0.2.0", "forever-agent": "~0.2.0", "tunnel-agent": "~0.2.0", "json-stringify-safe": "~3.0.0", "qs": "~0.5.4" }, "scripts": { "test": "node tests/run.js" } }normalize-package-data-0.2.2/test/fixtures/underscore.json000066400000000000000000000011751220543540700237150ustar00rootroot00000000000000{ "name" : "underscore", "description" : "JavaScript's functional programming helper library.", "homepage" : "http://underscorejs.org", "keywords" : ["util", "functional", "server", "client", "browser"], "author" : "Jeremy Ashkenas ", "repository" : {"type": "git", "url": "git://github.com/documentcloud/underscore.git"}, "main" : "underscore.js", "version" : "1.4.4", "devDependencies": { "phantomjs": "1.9.0-1" }, "scripts": { "test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true" }, "license" : "MIT" }normalize-package-data-0.2.2/test/github-urls.js000066400000000000000000000026351220543540700216050ustar00rootroot00000000000000var tap = require("tap") var normalize = require("../lib/normalize") var path = require("path") var fs = require("fs") var _ = require("underscore") var async = require("async") var data, clonedData var warn tap.test("consistent normalization", function(t) { entries = [ 'read-package-json.json', 'http-server.json', "movefile.json", "node-module_exist.json" ] verifyConsistency = function(entryName, next) { warn = function(msg) { // t.equal("",msg) // uncomment to have some kind of logging of warnings } filename = __dirname + "/fixtures/" + entryName fs.readFile(filename, function(err, contents) { if (err) return next(err) data = JSON.parse(contents.toString()) normalize(data, warn) if(data.name == "node-module_exist") { t.same(data.bugs.url, "https://gist.github.com/3135914") } if(data.name == "read-package-json") { t.same(data.bugs.url, "https://github.com/isaacs/read-package-json/issues") } if(data.name == "http-server") { t.same(data.bugs.url, "https://github.com/nodejitsu/http-server/issues") } if(data.name == "movefile") { t.same(data.bugs.url, "https://github.com/yazgazan/movefile/issues") } next(null) }) // fs.readFile } // verifyConsistency async.forEach(entries, verifyConsistency, function(err) { if (err) throw err t.end() }) }) // tap.testnormalize-package-data-0.2.2/test/normalize.js000066400000000000000000000074351220543540700213430ustar00rootroot00000000000000var tap = require("tap") var fs = require("fs") var path = require("path") var globals = Object.keys(global) var normalize = require("../lib/normalize") var rpjPath = path.resolve(__dirname,"./fixtures/read-package-json.json") tap.test("normalize some package data", function(t) { var packageData = require(rpjPath) var warnings = [] normalize(packageData, function(warning) { warnings.push(warning) }) // there's no readme data in this particular object t.equal( warnings.length, 1, "There's exactly one warning.") fs.readFile(rpjPath, function(err, data) { if(err) throw err // Various changes have been made t.notEqual(packageData, JSON.parse(data), "Output is different from input.") t.end() }) }) tap.test("runs without passing warning function", function(t) { var packageData = require(rpjPath) fs.readFile(rpjPath, function(err, data) { if(err) throw err normalize(JSON.parse(data)) t.ok(true, "If you read this, this means I'm still alive.") t.end() }) }) tap.test("empty object", function(t) { var packageData = {} var expect = { name: '', version: '', readme: 'ERROR: No README data found!', _id: '@' } var warnings = [] function warn(m) { warnings.push(m) } normalize(packageData, warn) t.same(packageData, expect) t.same(warnings, [ "No description", "No repository field.", "No README data" ]) t.end() }) tap.test("urls required", function(t) { var warnings = [] function warn(w) { warnings.push(w) } normalize({ bugs: { url: "/1", email: "not an email address" } }, warn) var a normalize(a={ readme: "read yourself how about", homepage: 123, bugs: "what is this i don't even", repository: "Hello." }, warn) console.error(a) var expect = [ "No description", "No repository field.", "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.", "No README data", "Bug string field must be url, email, or {email,url}", "Normalized value of bugs field is an empty object. Deleted.", "homepage field must be a string url. Deleted." ] t.same(warnings, expect) t.end() }) tap.test("homepage field must start with a protocol.", function(t) { var warnings = [] function warn(w) { warnings.push(w) } var a normalize(a={ homepage: 'example.org' }, warn) console.error(a) var expect = [ "No description", "No repository field.", "No README data", "homepage field must start with a protocol." ] t.same(warnings, expect) t.same(a.homepage, 'http://example.org') t.end() }) tap.test("gist bugs url", function(t) { var d = { repository: "git@gist.github.com:123456.git" } normalize(d) t.same(d.repository, { type: 'git', url: 'git@gist.github.com:123456.git' }) t.same(d.bugs, { url: 'https://gist.github.com/123456' }) t.end(); }); tap.test("singularize repositories", function(t) { var 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() }); tap.test("treat visionmedia/express as github repo", function(t) { var d = {repository: {type: "git", url: "visionmedia/express"}} normalize(d) t.same(d.repository, { type: "git", url: "git://github.com/visionmedia/express" }) t.end() }); tap.test("treat isaacs/node-graceful-fs as github repo", function(t) { var d = {repository: {type: "git", url: "isaacs/node-graceful-fs"}} normalize(d) t.same(d.repository, { type: "git", url: "git://github.com/isaacs/node-graceful-fs" }) t.end() }); tap.test('no new globals', function(t) { t.same(Object.keys(global), globals) t.end() }) normalize-package-data-0.2.2/test/strict.js000066400000000000000000000022321220543540700206410ustar00rootroot00000000000000var test = require("tap").test var normalize = require("../") test("strict", function(t) { var threw try { threw = false normalize({name: "X"}, true) } catch (er) { threw = true t.equal(er.message, 'Invalid name: "X"') } finally { t.equal(threw, true) } try { threw = false normalize({name:" x "}, true) } catch (er) { threw = true t.equal(er.message, 'Invalid name: " x "') } finally { t.equal(threw, true) } try { threw = false normalize({name:"x",version:"01.02.03"}, true) } catch (er) { threw = true t.equal(er.message, 'Invalid version: "01.02.03"') } finally { t.equal(threw, true) } // these should not throw var slob = {name:" X ",version:"01.02.03",dependencies:{ y:">01.02.03", z:"! 99 $$ASFJ(Aawenf90awenf as;naw.3j3qnraw || an elephant" }} normalize(slob, false) t.same(slob, { name: 'X', version: '1.2.3', dependencies: { y: '>01.02.03', z: '! 99 $$ASFJ(Aawenf90awenf as;naw.3j3qnraw || an elephant' }, readme: 'ERROR: No README data found!', _id: 'X@1.2.3' }) t.end() }) normalize-package-data-0.2.2/test/typo.js000066400000000000000000000065261220543540700203360ustar00rootroot00000000000000var test = require('tap').test var normalize = require('../') var typos = require('../lib/typos.json') test('typos', function(t) { var warnings = [] function warn(m) { warnings.push(m) } var expect = [ 'No repository field.', '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.' ] normalize({"dependancies": "dependencies" ,"dependecies": "dependencies" ,"depdenencies": "dependencies" ,"devEependencies": "devDependencies" ,"depends": "dependencies" ,"dev-dependencies": "devDependencies" ,"devDependences": "devDependencies" ,"devDepenencies": "devDependencies" ,"devdependencies": "devDependencies" ,"repostitory": "repository" ,"prefereGlobal": "preferGlobal" ,"hompage": "homepage" ,"hampage": "homepage" ,"autohr": "author" ,"autor": "author" ,"contributers": "contributors" ,"publicationConfig": "publishConfig" ,readme:"asdf" ,name:"name" ,version:"1.2.5"}, warn) t.same(warnings, expect) warnings.length = 0 var expect = [ 'No description', 'No repository field.', 'bugs[\'web\'] should probably be bugs[\'url\'].', 'bugs[\'name\'] should probably be bugs[\'url\'].', 'bugs.url field must be a string url. Deleted.', 'Normalized value of bugs field is an empty object. Deleted.', "No README data" ] normalize({name:"name" ,version:"1.2.5" ,bugs:{web:"url",name:"url"}}, warn) t.same(warnings, expect) warnings.length = 0 var expect = [ 'No description', 'No repository field.', "No README data", 'script should probably be scripts.' ] normalize({name:"name" ,version:"1.2.5" ,script:{server:"start",tests:"test"}}, warn) t.same(warnings, expect) warnings.length = 0 expect = [ 'No description', 'No repository field.', 'scripts[\'server\'] should probably be scripts[\'start\'].', 'scripts[\'tests\'] should probably be scripts[\'test\'].', "No README data" ] normalize({name:"name" ,version:"1.2.5" ,scripts:{server:"start",tests:"test"}}, warn) t.same(warnings, expect) warnings.length = 0 expect = [] normalize({private: true ,name:"name" ,version:"1.2.5" ,scripts:{server:"start",tests:"test"}}, warn) t.same(warnings, expect) t.end(); })