diff options
author | isaacs <i@izs.me> | 2011-10-03 03:38:54 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-10-03 03:38:54 +0400 |
commit | f7b6671b605a7201332fea16fb2c4b4ba2f7f38d (patch) | |
tree | d8c7dbe493c47460b5e65913da168bde7c49323d /lib/utils/read-json.js | |
parent | 6faa70cfcdeeb019b24b58566c86728db018de6d (diff) |
Warn about probable typos in package.json files
Diffstat (limited to 'lib/utils/read-json.js')
-rw-r--r-- | lib/utils/read-json.js | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/lib/utils/read-json.js b/lib/utils/read-json.js index 617c0e569..ac978e8cc 100644 --- a/lib/utils/read-json.js +++ b/lib/utils/read-json.js @@ -144,7 +144,54 @@ function jsonParseFail (ex, file, cb) { throw e } -var modulesWarned = {} +// a warning for deprecated or likely-incorrect fields +var typoWarned = {} +function typoWarn (json) { + if (typoWarned[json._id]) return + typoWarned[json._id] = true + + if (json.modules) { + log.warn("package.json: 'modules' object is deprecated", json._id) + delete json.modules + } + + // http://registry.npmjs.org/-/fields + var typos = { "dependancies": "dependencies" + , "dependecies": "dependencies" + , "depdenencies": "dependencies" + , "devEependencies": "devDependencies" + , "depends": "dependencies" + , "devDependences": "devDependencies" + , "devDepenencies": "devDependencies" + , "devdependencies": "devDependencies" + , "repostitory": "repository" + , "prefereGlobal": "preferGlobal" + , "hompage": "homepage" + , "hampage": "homepage" // XXX maybe not a typo, just delicious? + , "autohr": "author" + , "autor": "author" + , "contributers": "contributors" + , "publicationConfig": "publishConfig" + } + + Object.keys(typos).forEach(function (d) { + if (json.hasOwnProperty(d)) { + log.warn( "package.json: '" + d + "' should probably be '" + + typos[d] + "'", json._id) + } + }) + + // script typos + var scriptTypos = { "server": "start" } + if (json.scripts) Object.keys(scriptTypos).forEach(function (d) { + if (json.scripts.hasOwnProperty(d)) { + log.warn( "package.json: scripts['" + d + "'] should probably be " + + "scripts['" + scriptTypos[d] + "']", json._id) + } + }) +} + + function processObject (opts, cb) { return function (er, json) { // json._npmJsonOpts = opts // log.warn(json, "processing json") @@ -236,12 +283,6 @@ function processObject (opts, cb) { return function (er, json) { var tag = opts.tag if (tag) json.version = tag - if (json.modules && !modulesWarned[json._id]) { - log.warn("package.json: 'modules' object is deprecated", json._id) - modulesWarned[json._id] = true - delete json.modules - } - var scripts = json.scripts || {} // if it has a wscript, then build it. @@ -318,6 +359,8 @@ function processObject (opts, cb) { return function (er, json) { // log.warn(json.dependencies, "Added devdeps") } + typoWarn(json) + json = testEngine(json) json = parsePeople(unParsePeople(json)) if ( json.bugs ) json.bugs = parsePerson(unParsePerson(json.bugs)) |