Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/read-package-json.js2
-rw-r--r--lib/build.js2
-rw-r--r--lib/cache.js2
-rw-r--r--lib/init.js8
-rw-r--r--lib/install.js9
-rw-r--r--lib/link.js6
-rw-r--r--lib/outdated.js6
-rw-r--r--lib/owner.js2
-rw-r--r--lib/publish.js4
-rw-r--r--lib/run-script.js4
-rw-r--r--lib/submodule.js1
-rw-r--r--lib/unbuild.js4
-rw-r--r--lib/uninstall.js2
-rw-r--r--lib/unpublish.js2
-rw-r--r--lib/utils/completion/installed-shallow.js2
-rw-r--r--lib/utils/lifecycle.js1
-rw-r--r--lib/utils/read-installed.js2
-rw-r--r--lib/utils/read-json.js570
-rw-r--r--lib/utils/tar.js2
-rw-r--r--lib/version.js18
-rw-r--r--lib/view.js6
21 files changed, 40 insertions, 615 deletions
diff --git a/bin/read-package-json.js b/bin/read-package-json.js
index 8c95d86e8..3e5a0c77f 100755
--- a/bin/read-package-json.js
+++ b/bin/read-package-json.js
@@ -6,7 +6,7 @@ if (argv.length < 3) {
var fs = require("fs")
, file = argv[2]
- , readJson = require("../lib/utils/read-json")
+ , readJson = require("read-package-json")
readJson(file, function (er, data) {
if (er) throw er
diff --git a/lib/build.js b/lib/build.js
index c0dcbf7fb..9d1a99111 100644
--- a/lib/build.js
+++ b/lib/build.js
@@ -14,7 +14,7 @@ var npm = require("./npm.js")
, fs = require("graceful-fs")
, path = require("path")
, lifecycle = require("./utils/lifecycle.js")
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
, link = require("./utils/link.js")
, linkIfExists = link.ifExists
, cmdShim = require("./utils/cmd-shim.js")
diff --git a/lib/cache.js b/lib/cache.js
index e2e037ebe..bab38041f 100644
--- a/lib/cache.js
+++ b/lib/cache.js
@@ -37,7 +37,7 @@ var mkdir = require("mkdirp")
, npm = require("./npm.js")
, fs = require("graceful-fs")
, rm = require("rimraf")
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
, registry = npm.registry
, log = require("npmlog")
, path = require("path")
diff --git a/lib/init.js b/lib/init.js
index 0d96e07ac..f0e7dc5dc 100644
--- a/lib/init.js
+++ b/lib/init.js
@@ -5,7 +5,7 @@ module.exports = init
var read = require("read")
, path = require("path")
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
, fs = require("graceful-fs")
, promiseChain = require("./utils/promise-chain.js")
, exec = require("./utils/exec.js")
@@ -150,12 +150,6 @@ function init_ (data, folder, cb) {
)
(cleanupPaths, [data, folder])
(function (cb) {
- try { data = readJson.processJson(data) }
- catch (er) { return cb(er) }
- Object.keys(data)
- .filter(function (k) { return k.match(/^_/) })
- .forEach(function (k) { delete data[k] })
- readJson.unParsePeople(data)
var str = JSON.stringify(data, null, 2)
, msg = "About to write to "
+ path.join(folder, "package.json")
diff --git a/lib/install.js b/lib/install.js
index 26a5a63ee..3bd54d51d 100644
--- a/lib/install.js
+++ b/lib/install.js
@@ -57,7 +57,7 @@ install.completion = function (opts, cb) {
var npm = require("./npm.js")
, semver = require("semver")
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
, log = require("npmlog")
, path = require("path")
, fs = require("graceful-fs")
@@ -174,10 +174,15 @@ function readDependencies (context, where, opts, cb) {
var wrap = context ? context.wrap : null
readJson( path.resolve(where, "package.json")
- , opts
, function (er, data) {
if (er) return cb(er)
+ if (opts && opts.dev) {
+ Object.keys(data.devDependencies || {}).forEach(function (k) {
+ data.dependencies[k] = data.devDependencies[k]
+ })
+ }
+
if (wrap) {
log.verbose("readDependencies: using existing wrap", [where, wrap])
var rv = {}
diff --git a/lib/link.js b/lib/link.js
index de3d09c1c..df153cb02 100644
--- a/lib/link.js
+++ b/lib/link.js
@@ -114,13 +114,11 @@ function linkInstall (pkgs, cb) {
function linkPkg (folder, cb_) {
var me = folder || npm.prefix
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
log.verbose("linkPkg", folder)
- readJson( path.resolve(me, "package.json")
- , { dev: true }
- , function (er, d) {
+ readJson(path.resolve(me, "package.json"), function (er, d) {
function cb (er) {
return cb_(er, [[d && d._id, target, null, null]])
}
diff --git a/lib/outdated.js b/lib/outdated.js
index d87dc9ab6..32f9b9422 100644
--- a/lib/outdated.js
+++ b/lib/outdated.js
@@ -20,7 +20,7 @@ outdated.completion = require("./utils/completion/installed-deep.js")
var path = require("path")
, fs = require("graceful-fs")
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
, cache = require("./cache.js")
, asyncMap = require("slide").asyncMap
, npm = require("./npm.js")
@@ -89,8 +89,8 @@ function outdated_ (args, dir, parentHas, cb) {
return next()
}
asyncMap(pkgs, function (pkg, cb) {
- readJson( path.resolve(dir, "node_modules", pkg, "package.json")
- , function (er, d) {
+ var jsonFile = path.resolve(dir, "node_modules", pkg, "package.json")
+ readJson(jsonFile, function (er, d) {
cb(null, er ? [] : [[d.name, d.version]])
})
}, function (er, pvs) {
diff --git a/lib/owner.js b/lib/owner.js
index 6a38625e5..a7cc5bdac 100644
--- a/lib/owner.js
+++ b/lib/owner.js
@@ -68,6 +68,7 @@ var npm = require("./npm.js")
, registry = npm.registry
, log = require("npmlog")
, output
+ , readJson = require("read-package-json")
function owner (args, cb) {
var action = args.shift()
@@ -189,7 +190,6 @@ function mutate (pkg, user, mutation, cb) {
function readLocalPkg (cb) {
if (npm.config.get("global")) return cb()
var path = require("path")
- , readJson = require("./utils/read-json.js")
readJson(path.resolve(npm.prefix, "package.json"), function (er, d) {
return cb(er, d && d.name)
})
diff --git a/lib/publish.js b/lib/publish.js
index dfe21c251..dd15a7df4 100644
--- a/lib/publish.js
+++ b/lib/publish.js
@@ -7,7 +7,7 @@ var npm = require("./npm.js")
, tar = require("./utils/tar.js")
, sha = require("./utils/sha.js")
, path = require("path")
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
, fs = require("graceful-fs")
, lifecycle = require("./utils/lifecycle.js")
, chain = require("slide").chain
@@ -39,6 +39,8 @@ function publish (args, isRetry, cb) {
// to the cache.
if (er) return cacheAddPublish(arg, false, isRetry, cb)
+ data._npmUser = { name: npm.config.get("username")
+ , email: npm.config.get("email") }
cacheAddPublish(arg, true, isRetry, cb)
})
}
diff --git a/lib/run-script.js b/lib/run-script.js
index 17b48abf8..3291ae552 100644
--- a/lib/run-script.js
+++ b/lib/run-script.js
@@ -4,7 +4,7 @@ module.exports = runScript
var lifecycle = require("./utils/lifecycle.js")
, npm = require("./npm.js")
, path = require("path")
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
, log = require("npmlog")
, chain = require("slide").chain
, fs = require("graceful-fs")
@@ -34,8 +34,6 @@ runScript.completion = function (opts, cb) {
: npm.prefix
var pkgDir = path.resolve( pref, "node_modules"
, argv[2], "package.json" )
- console.error("global?", npm.config.get("global"))
- console.error(pkgDir, "package dir")
readJson(pkgDir, function (er, d) {
if (er) d = {}
var scripts = Object.keys(d.scripts || {})
diff --git a/lib/submodule.js b/lib/submodule.js
index 9a2cffa9e..a0d215994 100644
--- a/lib/submodule.js
+++ b/lib/submodule.js
@@ -5,7 +5,6 @@
module.exports = submodule
var npm = require("./npm.js")
- , readJson = require("./utils/read-json.js")
, exec = require("./utils/exec.js")
, output = require("./utils/output.js")
, cache = require("./cache.js")
diff --git a/lib/unbuild.js b/lib/unbuild.js
index dd0293be5..a7dc217ef 100644
--- a/lib/unbuild.js
+++ b/lib/unbuild.js
@@ -1,7 +1,7 @@
module.exports = unbuild
unbuild.usage = "npm unbuild <folder>\n(this is plumbing)"
-var readJson = require("./utils/read-json.js")
+var readJson = require("read-package-json")
, rm = require("rimraf")
, gentlyRm = require("./utils/gently-rm.js")
, npm = require("./npm.js")
@@ -24,7 +24,7 @@ function unbuild_ (folder, cb) {
readJson(path.resolve(folder, "package.json"), function (er, pkg) {
// if no json, then just trash it, but no scripts or whatever.
if (er) return rm(folder, cb)
- readJson.clearCache(folder)
+ readJson.cache.del(folder)
chain
( [ [lifecycle, pkg, "preuninstall", folder, false, true]
, [lifecycle, pkg, "uninstall", folder, false, true]
diff --git a/lib/uninstall.js b/lib/uninstall.js
index a1998e7fe..ca9d0edde 100644
--- a/lib/uninstall.js
+++ b/lib/uninstall.js
@@ -10,7 +10,7 @@ uninstall.completion = require("./utils/completion/installed-shallow.js")
var fs = require("graceful-fs")
, log = require("npmlog")
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
, path = require("path")
, npm = require("./npm.js")
, semver = require("semver")
diff --git a/lib/unpublish.js b/lib/unpublish.js
index 8aae12c3d..9d0c955f9 100644
--- a/lib/unpublish.js
+++ b/lib/unpublish.js
@@ -4,7 +4,7 @@ module.exports = unpublish
var log = require("npmlog")
, npm = require("./npm.js")
, registry = npm.registry
- , readJson = require("./utils/read-json.js")
+ , readJson = require("read-package-json")
, path = require("path")
, output = require("./utils/output.js")
diff --git a/lib/utils/completion/installed-shallow.js b/lib/utils/completion/installed-shallow.js
index 1ee3cce66..8d64649d5 100644
--- a/lib/utils/completion/installed-shallow.js
+++ b/lib/utils/completion/installed-shallow.js
@@ -4,7 +4,7 @@ module.exports = installedShallow
var npm = require("../../npm.js")
, fs = require("graceful-fs")
, path = require("path")
- , readJson = require("../read-json.js")
+ , readJson = require("read-package-json")
, asyncMap = require("slide").asyncMap
function installedShallow (opts, filter, cb) {
diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js
index 2f31af007..7fc5e7112 100644
--- a/lib/utils/lifecycle.js
+++ b/lib/utils/lifecycle.js
@@ -6,7 +6,6 @@ var log = require("npmlog")
, exec = require("./exec.js")
, npm = require("../npm.js")
, path = require("path")
- , readJson = require("./read-json.js")
, fs = require("graceful-fs")
, chain = require("slide").chain
, constants = require("constants")
diff --git a/lib/utils/read-installed.js b/lib/utils/read-installed.js
index 3776f9019..709d746c6 100644
--- a/lib/utils/read-installed.js
+++ b/lib/utils/read-installed.js
@@ -92,7 +92,7 @@ var npm = require("../npm.js")
, path = require("path")
, asyncMap = require("slide").asyncMap
, semver = require("semver")
- , readJson = require("./read-json.js")
+ , readJson = require("read-package-json")
, log = require("npmlog")
, url = require("url")
diff --git a/lib/utils/read-json.js b/lib/utils/read-json.js
deleted file mode 100644
index 146f46062..000000000
--- a/lib/utils/read-json.js
+++ /dev/null
@@ -1,570 +0,0 @@
-
-module.exports = readJson
-readJson.processJson = processJson
-readJson.unParsePeople = unParsePeople
-readJson.parsePeople = parsePeople
-readJson.clearCache = clearCache
-
-var fs = require("graceful-fs")
- , semver = require("semver")
- , path = require("path")
- , log = require("npmlog")
- , npm = require("../npm.js")
- , cache = {}
- , timers = {}
- , loadPackageDefaults = require("./load-package-defaults.js")
-
-function readJson (jsonFile, opts, cb) {
- if (typeof cb !== "function") cb = opts, opts = {}
- if (cache.hasOwnProperty(jsonFile)) {
- log.verbose("json from cache", jsonFile)
- return cb(null, cache[jsonFile])
- }
- log.verbose("read json", jsonFile)
-
- opts.file = jsonFile
-
- var wscript = null
- , contributors = null
- , serverjs = null
- , gypfile = null
-
- if (opts.gypfile !== null && opts.gypfile !== undefined) {
- gypfile = opts.gypfile
- next()
- } else {
- var pkgdir = path.dirname(jsonFile)
-
- function hasGyp (has) {
- gypfile = opts.gypfile = has
- next()
- }
-
- fs.readdir(pkgdir, function (er, gf) {
- // this would be weird.
- if (er) return hasGyp(false)
-
- // see if there are any *.gyp files in there.
- gf = gf.filter(function (f) {
- return f.match(/\.gyp$/)
- })
- gf = gf[0]
- return hasGyp(!!gf)
- })
- }
-
- if (opts.wscript !== null && opts.wscript !== undefined) {
- wscript = opts.wscript
- next()
- } else fs.readFile( path.join(path.dirname(jsonFile), "wscript")
- , function (er, data) {
- if (er) opts.wscript = false
- else opts.wscript = !!(data.toString().match(/(^|\n)def build\b/)
- && data.toString().match(/(^|\n)def configure\b/))
- wscript = opts.wscript
- next()
- })
-
- if (opts.contributors !== null && opts.contributors !== undefined) {
- contributors = opts.contributors
- next()
- } else fs.readFile( path.join(path.dirname(jsonFile), "AUTHORS")
- , function (er, data) {
- if (er) opts.contributors = false
- else {
- data = data.toString().split(/\r?\n/).map(function (l) {
- l = l.trim().split("#").shift()
- return l
- }).filter(function (l) { return l })
- opts.contributors = data
- }
- contributors = opts.contributors
- next()
- })
-
- if (opts.serverjs !== null && opts.serverjs !== undefined) {
- serverjs = opts.serverjs
- next()
- } else fs.stat( path.join(path.dirname(jsonFile), "server.js")
- , function (er, st) {
- if (er) opts.serverjs = false
- else opts.serverjs = st.isFile()
- serverjs = opts.serverjs
- next()
- })
-
- function next () {
- if (wscript === null ||
- contributors === null ||
- gypfile === null ||
- serverjs === null) {
- return
- }
-
- // XXX this api here is insane. being internal is no excuse.
- // please refactor.
- var thenLoad = processJson(opts, function (er, data) {
- if (er) return cb(er)
- var doLoad = !(jsonFile.indexOf(npm.cache) === 0 &&
- path.basename(path.dirname(jsonFile)) !== "package")
- if (!doLoad) return cb(er, data)
- loadPackageDefaults(data, path.dirname(jsonFile), cb)
- })
-
- fs.readFile(jsonFile, function (er, data) {
- if (er && er.code === "ENOENT") {
- // single-file module, maybe?
- // check index.js for a /**package { ... } **/ section.
- var indexFile = path.resolve(path.dirname(jsonFile), "index.js")
- return fs.readFile(indexFile, function (er2, data) {
- // if this doesn't work, then die with the original error.
- if (er2) return cb(er)
- data = parseIndex(data)
- if (!data) return cb(er)
- thenLoad(null, data)
- })
- }
- thenLoad(er, data)
- })
- }
-}
-
-// sync. no io.
-// /**package { "name": "foo", "version": "1.2.3", ... } **/
-function parseIndex (data) {
- data = data.toString()
- data = data.split(/^\/\*\*package(?:\s|$)/m)
- if (data.length < 2) return null
- data = data[1]
- data = data.split(/\*\*\/$/m)
- if (data.length < 2) return null
- data = data[0]
- data = data.replace(/^\s*\*/mg, "")
- return data
-}
-
-function processJson (opts, cb) {
- if (typeof cb !== "function") cb = opts, opts = {}
- if (typeof cb !== "function") {
- var thing = cb, cb = null
- return P(null, thing)
- } else return P
-
- function P (er, thing) {
- if (er) {
- if (cb) return cb(er, thing)
- throw er
- }
- if (typeof thing === "object" && !Buffer.isBuffer(thing)) {
- return processObject(opts, cb)(er, thing)
- } else {
- return processJsonString(opts, cb)(er, thing)
- }
- }
-}
-
-function processJsonString (opts, cb) { return function (er, jsonString) {
- if (er) return cb(er, jsonString)
- jsonString += ""
- var json
- try {
- json = JSON.parse(jsonString)
- } catch (ex) {
- if (opts.file && opts.file.indexOf(npm.dir) === 0) {
- try {
- json = require("vm").runInNewContext("(\n"+jsonString+"\n)")
- log.error("Error parsing json", opts.file, ex)
- } catch (ex2) {
- return jsonParseFail(ex, opts.file, cb)
- }
- } else {
- return jsonParseFail(ex, opts.file, cb)
- }
- }
- return processObject(opts, cb)(er, json)
-}}
-
-
-function jsonParseFail (ex, file, cb) {
- var e = new Error(
- "Failed to parse json\n"+ex.message)
- e.code = "EJSONPARSE"
- e.file = file
- if (cb) return cb(e)
- throw e
-}
-
-// 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.verbose("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"
- , "dev-dependencies": "devDependencies"
- , "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( json._id, "package.json: '" + d + "' should probably be '"
- + typos[d] + "'" )
- }
- })
-
- // bugs typos
- var bugsTypos = { "web": "url"
- , "name": "url"
- }
-
- if (typeof json.bugs === "object") {
- // just go ahead and correct these.
- Object.keys(bugsTypos).forEach(function (d) {
- if (json.bugs.hasOwnProperty(d)) {
- json.bugs[ bugsTypos[d] ] = json.bugs[d]
- delete json.bugs[d]
- }
- })
- }
-
- // script typos
- var scriptTypos = { "server": "start" }
- if (json.scripts) Object.keys(scriptTypos).forEach(function (d) {
- if (json.scripts.hasOwnProperty(d)) {
- log.warn( json._id
- , "package.json: scripts['" + d + "'] should probably be "
- + "scripts['" + scriptTypos[d] + "']" )
- }
- })
-}
-
-
-function processObject (opts, cb) { return function (er, json) {
- // json._npmJsonOpts = opts
- if (npm.config.get("username")) {
- json._npmUser = { name: npm.config.get("username")
- , email: npm.config.get("email") }
- }
-
- // slashes would be a security risk.
- // anything else will just fail harmlessly.
- if (!json.name) {
- var e = new Error("No 'name' field found in package.json")
- if (cb) return cb(e)
- throw e
- }
- json.name = json.name.trim()
- if (json.name.charAt(0) === "." || json.name.match(/[\/@\s\+%:]/)) {
- var msg = "Invalid name: "
- + JSON.stringify(json.name)
- + " may not start with '.' or contain %/@+: or whitespace"
- , e = new Error(msg)
- if (cb) return cb(e)
- throw e
- }
- if (json.name.toLowerCase() === "node_modules") {
- var msg = "Invalid package name: node_modules"
- , e = new Error(msg)
- if (cb) return cb(e)
- throw e
- }
- if (json.name.toLowerCase() === "favicon.ico") {
- var msg = "Sorry, favicon.ico is a picture, not a package."
- , e = new Error(msg)
- if (cb) return cb(e)
- throw e
- }
-
- if (json.repostories) {
- var msg = "'repositories' (plural) No longer supported.\n"
- + "Please pick one, and put it in the 'repository' field."
- , e = new Error(msg)
- // uncomment once this is no longer an issue.
- // if (cb) return cb(e)
- // throw e
- log.error("json", "incorrect json: "+json.name, msg)
- json.repostory = json.repositories[0]
- delete json.repositories
- }
-
- if (json.repository) {
- if (typeof json.repository === "string") {
- json.repository = { type : "git"
- , url : json.repository }
- }
- var repo = json.repository.url || ""
- repo = repo.replace(/^(https?|git):\/\/[^\@]+\@github.com/
- ,'$1://github.com')
- if (json.repository.type === "git"
- && ( repo.match(/^https?:\/\/github.com/)
- || repo.match(/github.com\/[^\/]+\/[^\/]+\/?$/)
- && !repo.match(/\.git$/)
- )) {
- repo = repo.replace(/^https?:\/\/github.com/, 'git://github.com')
- if (!repo.match(/\.git$/)) {
- repo = repo.replace(/\/?$/, '.git')
- }
- }
- if (repo.match(/github\.com\/[^\/]+\/[^\/]+\/?$/)
- && repo.match(/\.git\.git$/)) {
- log.warn(json._id, "Probably broken git url", repo)
- }
- json.repository.url = repo
- }
-
- var files = json.files
- if (files && !Array.isArray(files)) {
- log.warn(json._id, "Invalid 'files' member. See 'npm help json'", files)
- delete json.files
- }
-
- var kw = json.keywords
- if (typeof kw === "string") {
- kw = kw.split(/,\s+/)
- json.keywords = kw
- }
-
- json._id = json.name+"@"+json.version
-
- var scripts = json.scripts || {}
-
- // if it has a bindings.gyp, then build with node-gyp
- if (opts.gypfile && !json.prebuilt) {
- log.verbose(json._id, "has bindings.gyp", [json.prebuilt, opts])
- if (!scripts.install && !scripts.preinstall) {
- scripts.install = "node-gyp rebuild"
- json.scripts = scripts
- }
- }
-
- // if it has a wscript, then build it.
- if (opts.wscript && !json.prebuilt) {
- log.verbose(json._id, "has wscript", [json.prebuilt, opts])
- if (!scripts.install && !scripts.preinstall) {
- // don't fail if it was unexpected, just try.
- scripts.preinstall = "node-waf clean || (exit 0); node-waf configure build"
- json.scripts = scripts
- }
- }
-
- // if it has an AUTHORS, then credit them
- if (opts.contributors && Array.isArray(opts.contributors)
- && opts.contributors.length) {
- json.contributors = opts.contributors
- }
-
- // if it has a server.js, then start it.
- if (opts.serverjs && !scripts.start) {
- scripts.start = "node server.js"
- json.scripts = scripts
- }
-
- if (!(semver.valid(json.version))) {
- var m
- if (!json.version) {
- m = "'version' field missing\n"
- } else {
- m = "Invalid 'version' field: "+json.version+"\n"
- }
-
- m += "'version' Must be X.Y.Z, with an optional trailing tag.\n"
- + "See the section on 'version' in `npm help json`"
-
- var e = new Error(m)
- if (cb) return cb(e)
- throw e
- }
- json.version = semver.clean(json.version)
-
- if (json.bin && typeof json.bin === "string") {
- var b = {}
- b[ json.name ] = json.bin
- json.bin = b
- }
-
- if (json.bundledDependencies && !json.bundleDependencies) {
- json.bundleDependencies = json.bundledDependencies
- delete json.bundledDependencies
- }
-
- if (json.bundleDependencies && !Array.isArray(json.bundleDependencies)) {
- var e = new Error("bundleDependencies must be an array.\n"
- +"See `npm help json`")
- if (cb) return cb(e)
- throw e
- }
-
- if (json["dev-dependencies"] && !json.devDependencies) {
- json.devDependencies = json["dev-dependencies"]
- delete json["dev-dependencies"]
- }
-
- ; [ "dependencies"
- , "devDependencies"
- , "optionalDependencies"
- ].forEach(function (d) {
- json[d] = json.hasOwnProperty(d)
- ? depObjectify(json[d], d, json._id)
- : {}
- })
-
- // always merge optionals into deps
- Object.keys(json.optionalDependencies).forEach(function (d) {
- json.dependencies[d] = json.optionalDependencies[d]
- })
-
- if (opts.dev
- || npm.config.get("dev")
- || npm.config.get("npat")) {
- Object.keys(json.devDependencies || {}).forEach(function (d) {
- json.dependencies[d] = json.devDependencies[d]
- })
- }
-
- typoWarn(json)
-
- json = testEngine(json)
- json = parsePeople(unParsePeople(json))
- if ( json.bugs ) json.bugs = parsePerson(unParsePerson(json.bugs))
- json._npmVersion = npm.version
- json._nodeVersion = process.version
- if (opts.file) {
- log.verbose("caching json", opts.file)
- cache[opts.file] = json
- // arbitrary
- var keys = Object.keys(cache)
- , l = keys.length
- if (l > 10000) for (var i = 0; i < l - 5000; i ++) {
- delete cache[keys[i]]
- }
- }
- if (cb) cb(null,json)
- return json
-}}
-
-var depObjectifyWarn = {}
-function depObjectify (deps, d, id) {
- if (!deps) return {}
- if (typeof deps === "string") {
- deps = deps.trim().split(/[\n\r\s\t ,]+/)
- }
- if (!Array.isArray(deps)) return deps
- var o = {}
- deps.forEach(function (d) {
- d = d.trim().split(/(:?[@\s><=])/)
- o[d.shift()] = d.join("").trim().replace(/^@/, "")
- })
- return o
-}
-
-function testEngine (json) {
- // if engines is empty, then assume that node is allowed.
- if ( !json.engines
- || Array.isArray(json.engines)
- && !json.engines.length
- || typeof json.engines === "object"
- && !Object.keys(json.engines).length
- ) {
- json.engines = { "node" : "*" }
- }
- if (typeof json.engines === "string") {
- if (semver.validRange(json.engines) !== null) {
- json.engines = { "node" : json.engines }
- } else json.engines = [ json.engines ]
- }
-
- var nodeVer = npm.config.get("node-version")
- , ok = false
- if (nodeVer) nodeVer = nodeVer.replace(/\+$/, '')
- if (Array.isArray(json.engines)) {
- // Packages/1.0 commonjs style, with an array.
- // hack it to just hang a "node" member with the version range,
- // then do the npm-style check below.
- for (var i = 0, l = json.engines.length; i < l; i ++) {
- var e = json.engines[i].trim()
- if (e.substr(0, 4) === "node") {
- json.engines.node = e.substr(4)
- } else if (e.substr(0, 3) === "npm") {
- json.engines.npm = e.substr(3)
- }
- }
- }
- if (json.engines.node === "") json.engines.node = "*"
- if (json.engines.node && null === semver.validRange(json.engines.node)) {
- log.warn( json._id
- , "Invalid range in engines.node. Please see `npm help json`"
- , json.engines.node )
- }
-
- if (nodeVer) {
- json._engineSupported = semver.satisfies( nodeVer
- , json.engines.node || "null" )
- }
- if (json.engines.hasOwnProperty("npm") && json._engineSupported) {
- json._engineSupported = semver.satisfies(npm.version, json.engines.npm)
- }
- return json
-}
-
-function unParsePeople (json) { return parsePeople(json, true) }
-
-function parsePeople (json, un) {
- var fn = un ? unParsePerson : parsePerson
- if (json.author) json.author = fn(json.author)
- ;["maintainers", "contributors"].forEach(function (set) {
- if (Array.isArray(json[set])) json[set] = json[set].map(fn)
- })
- return json
-}
-
-function unParsePerson (person) {
- if (typeof person === "string") return person
- var name = person.name || ""
- , u = person.url || person.web
- , url = u ? (" ("+u+")") : ""
- , e = person.email || person.mail
- , email = e ? (" <"+e+">") : ""
- return name+email+url
-}
-
-function parsePerson (person) {
- if (typeof person !== "string") return person
- var name = person.match(/^([^\(<]+)/)
- , url = person.match(/\(([^\)]+)\)/)
- , email = person.match(/<([^>]+)>/)
- , 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 clearCache (prefix) {
- if (!prefix) {
- cache = {}
- return
- }
- Object.keys(cache).forEach(function (c) {
- if (c.indexOf(prefix) === 0) delete cache[c]
- })
-}
diff --git a/lib/utils/tar.js b/lib/utils/tar.js
index 22a4a852c..a060c9154 100644
--- a/lib/utils/tar.js
+++ b/lib/utils/tar.js
@@ -7,7 +7,7 @@ var npm = require("../npm.js")
, log = require("npmlog")
, uidNumber = require("uid-number")
, rm = require("rimraf")
- , readJson = require("./read-json.js")
+ , readJson = require("read-package-json")
, relativize = require("./relativize.js")
, cache = require("../cache.js")
, myUid = process.getuid && process.getuid()
diff --git a/lib/version.js b/lib/version.js
index 35329760e..d1a6b563e 100644
--- a/lib/version.js
+++ b/lib/version.js
@@ -3,7 +3,6 @@
module.exports = version
var exec = require("./utils/exec.js")
- , readJson = require("./utils/read-json.js")
, semver = require("semver")
, path = require("path")
, fs = require("graceful-fs")
@@ -21,20 +20,25 @@ version.usage = "npm version <newversion> [--message commit-message]"
function version (args, cb) {
if (args.length !== 1) return cb(version.usage)
- readJson(path.join(process.cwd(), "package.json"), function (er, data) {
+ fs.readFile(path.join(process.cwd(), "package.json"), function (er, data) {
if (er) {
log.error("version", "No package.json found")
return cb(er)
}
+
+ try {
+ data = JSON.parse(data)
+ } catch (er) {
+ log.error("version", "Bad package.json data")
+ return cb(er)
+ }
+
var newVer = semver.valid(args[0])
if (!newVer) newVer = semver.inc(data.version, args[0])
if (!newVer) return cb(version.usage)
if (data.version === newVer) return cb(new Error("Version not changed"))
data.version = newVer
- Object.keys(data).forEach(function (k) {
- if (k.charAt(0) === "_") delete data[k]
- })
- readJson.unParsePeople(data)
+
fs.stat(path.join(process.cwd(), ".git"), function (er, s) {
var doGit = !er && s.isDirectory()
if (!doGit) return write(data, cb)
@@ -42,6 +46,7 @@ function version (args, cb) {
})
})
}
+
function checkGit (data, cb) {
exec( npm.config.get("git"), ["status", "--porcelain"], process.env, false
, function (er, code, stdout, stderr) {
@@ -64,6 +69,7 @@ function checkGit (data, cb) {
})
})
}
+
function write (data, cb) {
fs.writeFile( path.join(process.cwd(), "package.json")
, new Buffer(JSON.stringify(data, null, 2) + "\n")
diff --git a/lib/view.js b/lib/view.js
index 6ffde4c28..e291031c1 100644
--- a/lib/view.js
+++ b/lib/view.js
@@ -46,7 +46,6 @@ var npm = require("./npm.js")
, util = require("util")
, output
, semver = require("semver")
- , readJson = require("./utils/read-json.js")
function view (args, silent, cb) {
if (typeof cb !== "function") cb = silent, silent = false
@@ -76,11 +75,6 @@ function view (args, silent, cb) {
}
Object.keys(versions).forEach(function (v) {
- try {
- versions[v] = readJson.processJson(versions[v])
- } catch (ex) {
- delete versions[v]
- }
if (semver.satisfies(v, version)) args.forEach(function (args) {
// remove readme unless we asked for it
if (-1 === args.indexOf("readme")) {