diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-05-20 00:57:05 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-05-20 00:57:05 +0300 |
commit | 133f882250dfeeafac613364ec4b772b9da72b86 (patch) | |
tree | b64b9a8522543f5cffdc3b2a7203c2cecccb6312 | |
parent | 8a46136f42e416cbadb533bcf89d73d681ed421d (diff) |
validate-npm-package-name@2.2.0
For use by the error handler.
10 files changed, 491 insertions, 0 deletions
diff --git a/node_modules/validate-npm-package-name/.npmignore b/node_modules/validate-npm-package-name/.npmignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/node_modules/validate-npm-package-name/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/validate-npm-package-name/README.md b/node_modules/validate-npm-package-name/README.md new file mode 100644 index 000000000..91a963b76 --- /dev/null +++ b/node_modules/validate-npm-package-name/README.md @@ -0,0 +1,86 @@ +# validate-npm-package-name + +Give me a string and I'll tell you if it's a valid npm package name. + +This package exports a single synchronous function that takes a string as +input and returns an object: + +## Valid Names + +```js +var validate = require("validate-npm-package-name") + +validate("some-package") +validate("example.com") +validate("under_score") +validate("123numeric") +validate("crazy!") +validate("@npm/thingy") +validate("@jane/foo.js") +``` + +All of the above names are valid, so you'll get this object back: + +```js +{ + validForNewPackages: true, + validForOldPackages: true +} +``` + +## Invalid Names + +```js + validate(" leading-space:and:weirdchars") +``` + +That was never a valid package name, so you get this: + +```js +{ + validForNewPackages: false, + validForOldPackages: false, + errors: [ + 'name cannot contain leading or trailing spaces', + 'name can only contain URL-friendly characters' + ] +} +``` + +## Legacy Names + +In the old days of npm, package names were wild. They could have capital +letters in them. They could be really long. They could be the name of an +existing module in node core. + +If you give this function a package name that **used to be valid**, you'll see +a change in the value of `validForNewPackages` property, and a warnings array +will be present: + +```js +validate("cRaZY-paCkAgE-with-mixed-case-and-more-than-214-characters-----------------------------------------------------------------------------------------------------------------------------------------------------------") +``` + +returns: + +```js +{ + validForNewPackages: false, + validForOldPackages: true, + warnings: [ + "name can no longer contain capital letters", + "name can no longer contain more than 214 characters" + ] +} +``` + +## Tests + +```sh +npm install +npm test +``` + +## License + +ISC diff --git a/node_modules/validate-npm-package-name/index.js b/node_modules/validate-npm-package-name/index.js new file mode 100644 index 000000000..66a1d4732 --- /dev/null +++ b/node_modules/validate-npm-package-name/index.js @@ -0,0 +1,102 @@ +var scopedPackagePattern = new RegExp("^(?:@([^/]+?)[/])?([^/]+?)$"); +var builtins = require("builtins") +var blacklist = [ + "node_modules", + "favicon.ico" +]; + +var validate = module.exports = function(name) { + + var warnings = [] + var errors = [] + + if (name === null) { + errors.push("name cannot be null") + return done(warnings, errors) + } + + if (name === undefined) { + errors.push("name cannot be undefined") + return done(warnings, errors) + } + + if (typeof name !== "string") { + errors.push("name must be a string") + return done(warnings, errors) + } + + if (!name.length) { + errors.push("name length must be greater than zero") + } + + if (name.match(/^\./)) { + errors.push("name cannot start with a period") + } + + if (name.match(/^_/)) { + errors.push("name cannot start with an underscore") + } + + if (name.trim() !== name) { + errors.push("name cannot contain leading or trailing spaces") + } + + // No funny business + blacklist.forEach(function(blacklistedName){ + if (name.toLowerCase() === blacklistedName) { + errors.push(blacklistedName + " is a blacklisted name") + } + }) + + // Generate warnings for stuff that used to be allowed + + // core module names like http, events, util, etc + builtins.forEach(function(builtin){ + if (name.toLowerCase() === builtin) { + warnings.push(builtin + " is a core module name") + } + }) + + // really-long-package-names-------------------------------such--length-----many---wow + // the thisisareallyreallylongpackagenameitshouldpublishdowenowhavealimittothelengthofpackagenames-poch. + if (name.length > 214) { + warnings.push("name can no longer contain more than 214 characters") + } + + // mIxeD CaSe nAMEs + if (name.toLowerCase() !== name) { + warnings.push("name can no longer contain capital letters") + } + + if (encodeURIComponent(name) !== name) { + + // Maybe it's a scoped package name, like @user/package + var nameMatch = name.match(scopedPackagePattern) + if (nameMatch) { + var user = nameMatch[1] + var pkg = nameMatch[2] + if (encodeURIComponent(user) === user && encodeURIComponent(pkg) === pkg) { + return done(warnings, errors) + } + } + + errors.push("name can only contain URL-friendly characters") + } + + return done(warnings, errors) + +} + +validate.scopedPackagePattern = scopedPackagePattern + +var done = function (warnings, errors) { + var result = { + validForNewPackages: errors.length === 0 && warnings.length === 0, + validForOldPackages: errors.length === 0, + warnings: warnings, + errors: errors + } + if (!result.warnings.length) delete result.warnings + if (!result.errors.length) delete result.errors + return result +} diff --git a/node_modules/validate-npm-package-name/node_modules/builtins/.travis.yml b/node_modules/validate-npm-package-name/node_modules/builtins/.travis.yml new file mode 100644 index 000000000..cc4dba29d --- /dev/null +++ b/node_modules/validate-npm-package-name/node_modules/builtins/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - "0.8" + - "0.10" diff --git a/node_modules/validate-npm-package-name/node_modules/builtins/History.md b/node_modules/validate-npm-package-name/node_modules/builtins/History.md new file mode 100644 index 000000000..0eb45c420 --- /dev/null +++ b/node_modules/validate-npm-package-name/node_modules/builtins/History.md @@ -0,0 +1,39 @@ + +0.0.7 / 2014-09-01 +================== + + * update .repository + +0.0.6 / 2014-09-01 +================== + + * add travis + * add test script + * add constants + +0.0.5 / 2014-06-27 +================== + + * add module + * publish to public npm + +0.0.4 / 2014-04-25 +================== + + * add timers + +0.0.3 / 2014-02-22 +================== + + * add buffer + +0.0.2 / 2014-02-11 +================== + + * add assert + +0.0.1 / 2014-02-11 +================== + + * add main + * initial commit diff --git a/node_modules/validate-npm-package-name/node_modules/builtins/Readme.md b/node_modules/validate-npm-package-name/node_modules/builtins/Readme.md new file mode 100644 index 000000000..96f4b1f6c --- /dev/null +++ b/node_modules/validate-npm-package-name/node_modules/builtins/Readme.md @@ -0,0 +1,18 @@ + +# builtins + + List of node.js [builtin modules](http://nodejs.org/api/). + + [![build status](https://secure.travis-ci.org/juliangruber/builtins.svg)](http://travis-ci.org/juliangruber/builtins) + +## Example + +```js +var builtins = require('builtins'); + +assert(builtins.indexOf('http') > -1); +``` + +## License + + MIT diff --git a/node_modules/validate-npm-package-name/node_modules/builtins/builtins.json b/node_modules/validate-npm-package-name/node_modules/builtins/builtins.json new file mode 100644 index 000000000..c52221d77 --- /dev/null +++ b/node_modules/validate-npm-package-name/node_modules/builtins/builtins.json @@ -0,0 +1,31 @@ +[ + "assert", + "buffer", + "child_process", + "cluster", + "constants", + "crypto", + "dns", + "domain", + "events", + "fs", + "http", + "https", + "module", + "net", + "os", + "path", + "punycode", + "querystring", + "repl", + "stream", + "string_decoder", + "timers", + "tls", + "tty", + "dgram", + "url", + "util", + "vm", + "zlib" +] diff --git a/node_modules/validate-npm-package-name/node_modules/builtins/package.json b/node_modules/validate-npm-package-name/node_modules/builtins/package.json new file mode 100644 index 000000000..c5ec77f13 --- /dev/null +++ b/node_modules/validate-npm-package-name/node_modules/builtins/package.json @@ -0,0 +1,46 @@ +{ + "name": "builtins", + "version": "0.0.7", + "description": "List of node.js builtin modules", + "repository": { + "type": "git", + "url": "git://github.com/juliangruber/builtins.git" + }, + "license": "MIT", + "main": "builtins.json", + "publishConfig": { + "registry": "https://registry.npmjs.org" + }, + "scripts": { + "test": "node -e \"require('./builtins.json')\"" + }, + "bugs": { + "url": "https://github.com/juliangruber/builtins/issues" + }, + "homepage": "https://github.com/juliangruber/builtins", + "_id": "builtins@0.0.7", + "dist": { + "shasum": "355219cd6cf18dbe7c01cc7fd2dce765cfdc549a", + "tarball": "http://registry.npmjs.org/builtins/-/builtins-0.0.7.tgz" + }, + "_from": "builtins@0.0.7", + "_npmVersion": "1.3.22", + "_npmUser": { + "name": "juliangruber", + "email": "julian@juliangruber.com" + }, + "maintainers": [ + { + "name": "juliangruber", + "email": "julian@juliangruber.com" + }, + { + "name": "segment", + "email": "tj@segment.io" + } + ], + "directories": {}, + "_shasum": "355219cd6cf18dbe7c01cc7fd2dce765cfdc549a", + "_resolved": "https://registry.npmjs.org/builtins/-/builtins-0.0.7.tgz", + "readme": "ERROR: No README data found!" +} diff --git a/node_modules/validate-npm-package-name/package.json b/node_modules/validate-npm-package-name/package.json new file mode 100644 index 000000000..a809d7ac5 --- /dev/null +++ b/node_modules/validate-npm-package-name/package.json @@ -0,0 +1,62 @@ +{ + "name": "validate-npm-package-name", + "version": "2.2.0", + "description": "Give me a string and I'll tell you if it's a valid npm package name", + "main": "index.js", + "directories": { + "test": "test" + }, + "dependencies": { + "builtins": "0.0.7" + }, + "devDependencies": { + "tap": "^0.4.13" + }, + "scripts": { + "test": "tap test/*.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/npm/validate-npm-package-name.git" + }, + "keywords": [ + "npm", + "package", + "names", + "validation" + ], + "author": { + "name": "zeke" + }, + "license": "ISC", + "bugs": { + "url": "https://github.com/npm/validate-npm-package-name/issues" + }, + "homepage": "https://github.com/npm/validate-npm-package-name", + "gitHead": "acef1219c13a0cf4cf6b8706d65f606d82a7d472", + "_id": "validate-npm-package-name@2.2.0", + "_shasum": "4cb6ff120bd7afb0b5681406cfaea8df2d763477", + "_from": "validate-npm-package-name@2.2.0", + "_npmVersion": "2.7.6", + "_nodeVersion": "1.6.2", + "_npmUser": { + "name": "bcoe", + "email": "ben@npmjs.com" + }, + "dist": { + "shasum": "4cb6ff120bd7afb0b5681406cfaea8df2d763477", + "tarball": "http://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-2.2.0.tgz" + }, + "maintainers": [ + { + "name": "zeke", + "email": "zeke@npmjs.com" + }, + { + "name": "bcoe", + "email": "ben@npmjs.com" + } + ], + "_resolved": "https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-2.2.0.tgz", + "readme": "ERROR: No README data found!" +} diff --git a/node_modules/validate-npm-package-name/test/index.js b/node_modules/validate-npm-package-name/test/index.js new file mode 100644 index 000000000..1a7dca5de --- /dev/null +++ b/node_modules/validate-npm-package-name/test/index.js @@ -0,0 +1,102 @@ +var validate = require("..") +var test = require("tap").test +var path = require("path") +var fs = require("fs") + +test("validate-npm-package-name", function (t) { + + // Traditional + + t.deepEqual(validate("some-package"), {validForNewPackages: true, validForOldPackages: true}) + t.deepEqual(validate("example.com"), {validForNewPackages: true, validForOldPackages: true}) + t.deepEqual(validate("under_score"), {validForNewPackages: true, validForOldPackages: true}) + t.deepEqual(validate("period.js"), {validForNewPackages: true, validForOldPackages: true}) + t.deepEqual(validate("123numeric"), {validForNewPackages: true, validForOldPackages: true}) + t.deepEqual(validate("crazy!"), {validForNewPackages: true, validForOldPackages: true}) + + // Scoped (npm 2+) + + t.deepEqual(validate("@npm/thingy"), {validForNewPackages: true, validForOldPackages: true}) + t.deepEqual(validate("@npm-zors/money!time.js"), {validForNewPackages: true, validForOldPackages: true}) + + // Invalid + + t.deepEqual(validate(""), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["name length must be greater than zero"]}) + + t.deepEqual(validate(""), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["name length must be greater than zero"]}) + + t.deepEqual(validate(".start-with-period"), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["name cannot start with a period"]}) + + t.deepEqual(validate("_start-with-underscore"), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["name cannot start with an underscore"]}) + + t.deepEqual(validate("contain:colons"), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["name can only contain URL-friendly characters"]}) + + t.deepEqual(validate(" leading-space"), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["name cannot contain leading or trailing spaces", "name can only contain URL-friendly characters"]}) + + t.deepEqual(validate("trailing-space "), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["name cannot contain leading or trailing spaces", "name can only contain URL-friendly characters"]}) + + t.deepEqual(validate("s/l/a/s/h/e/s"), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["name can only contain URL-friendly characters"]}) + + t.deepEqual(validate("node_modules"), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["node_modules is a blacklisted name"]}) + + t.deepEqual(validate("favicon.ico"), { + validForNewPackages: false, + validForOldPackages: false, + errors: ["favicon.ico is a blacklisted name"]}) + + // Node/IO Core + + t.deepEqual(validate("http"), { + validForNewPackages: false, + validForOldPackages: true, + warnings: ["http is a core module name"]}) + + // Long Package Names + + t.deepEqual(validate("ifyouwanttogetthesumoftwonumberswherethosetwonumbersarechosenbyfindingthelargestoftwooutofthreenumbersandsquaringthemwhichismultiplyingthembyitselfthenyoushouldinputthreenumbersintothisfunctionanditwilldothatforyou-"), { + validForNewPackages: false, + validForOldPackages: true, + warnings: ["name can no longer contain more than 214 characters"] + }) + + t.deepEqual(validate("ifyouwanttogetthesumoftwonumberswherethosetwonumbersarechosenbyfindingthelargestoftwooutofthreenumbersandsquaringthemwhichismultiplyingthembyitselfthenyoushouldinputthreenumbersintothisfunctionanditwilldothatforyou"), { + validForNewPackages: true, + validForOldPackages: true + }) + + // Legacy Mixed-Case + + t.deepEqual(validate("CAPITAL-LETTERS"), { + validForNewPackages: false, + validForOldPackages: true, + warnings: ["name can no longer contain capital letters"]}) + + t.end() +}) |