Skip to content

Commit

Permalink
src: make the npm source comply with standard
Browse files Browse the repository at this point in the history
This is a huge set of mostly mechanical changes. Going forward, all
changes to the npm source base are expected to comply with `standard`,
and it's been integrated into the test suite to enforce that. There are
a few notes below about specific classes of changes that need to be
handled specially for npm's code base.

standard: "Expected error to be handled."

`standard` only expects errors spelled "err" to be handled.
`npm-registry-mock` never actually invokes its callback with an error,
so in some cases I just changed it to be spelled "er" and called it
good.

standard: "Expected a "break" statement before 'case'."

This behavior is actually on purpose, and I don't feel like rewriting
the affected code right now (or, you know, ever). So I added code
comments disabling the checks in the three applicable changes.

standard: "x is a function."

Rebinding functions created via declarations (as opposed to expressions)
is a no-no?

PR-URL: npm/npm#8668
  • Loading branch information
othiym23 authored and iarna committed Jun 26, 2015
1 parent 7c5ebe0 commit b50be6a
Showing 207 changed files with 6,637 additions and 6,455 deletions.
146 changes: 73 additions & 73 deletions bin/npm-cli.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
#!/usr/bin/env node
;(function () { // wrapper in case we're in module_context mode

// windows: running "npm blah" in this folder will invoke WSH, not node.
if (typeof WScript !== "undefined") {
WScript.echo("npm does not work when run\n"
+"with the Windows Scripting Host\n\n"
+"'cd' to a different directory,\n"
+"or type 'npm.cmd <args>',\n"
+"or type 'node npm <args>'.")
WScript.quit(1)
return
}


process.title = "npm"

var log = require("npmlog")
log.pause() // will be unpaused when config is loaded.
log.enableProgress()

log.info("it worked if it ends with", "ok")

var path = require("path")
, log = require("npmlog")
, npm = require("../lib/npm.js")
, npmconf = require("../lib/config/core.js")
, errorHandler = require("../lib/utils/error-handler.js")

, configDefs = npmconf.defs
, shorthands = configDefs.shorthands
, types = configDefs.types
, nopt = require("nopt")

// if npm is called as "npmg" or "npm_g", then
// run in global mode.
if (path.basename(process.argv[1]).slice(-1) === "g") {
process.argv.splice(1, 1, "npm", "-g")
}

log.verbose("cli", process.argv)

var conf = nopt(types, shorthands)
npm.argv = conf.argv.remain
if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift()
else conf.usage = true


if (conf.version) {
console.log(npm.version)
return
}

if (conf.versions) {
npm.command = "version"
conf.usage = false
npm.argv = []
}

log.info("using", "npm@%s", npm.version)
log.info("using", "node@%s", process.version)

process.on("uncaughtException", errorHandler)

if (conf.usage && npm.command !== "help") {
npm.argv.unshift(npm.command)
npm.command = "help"
}

// now actually fire up npm and run the command.
// this is how to use npm programmatically:
conf._exit = true
npm.load(conf, function (er) {
if (er) return errorHandler(er)
// windows: running "npm blah" in this folder will invoke WSH, not node.
/*global WScript*/
if (typeof WScript !== 'undefined') {
WScript.echo(
'npm does not work when run\n' +
'with the Windows Scripting Host\n\n' +
"'cd' to a different directory,\n" +
"or type 'npm.cmd <args>',\n" +
"or type 'node npm <args>'."
)
WScript.quit(1)
return
}

process.title = 'npm'

var log = require('npmlog')
log.pause() // will be unpaused when config is loaded.
log.enableProgress()
npm.commands[npm.command](npm.argv, errorHandler)
})

log.info('it worked if it ends with', 'ok')

var path = require('path')
var npm = require('../lib/npm.js')
var npmconf = require('../lib/config/core.js')
var errorHandler = require('../lib/utils/error-handler.js')

var configDefs = npmconf.defs
var shorthands = configDefs.shorthands
var types = configDefs.types
var nopt = require('nopt')

// if npm is called as "npmg" or "npm_g", then
// run in global mode.
if (path.basename(process.argv[1]).slice(-1) === 'g') {
process.argv.splice(1, 1, 'npm', '-g')
}

log.verbose('cli', process.argv)

var conf = nopt(types, shorthands)
npm.argv = conf.argv.remain
if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift()
else conf.usage = true

if (conf.version) {
console.log(npm.version)
return
}

if (conf.versions) {
npm.command = 'version'
conf.usage = false
npm.argv = []
}

log.info('using', 'npm@%s', npm.version)
log.info('using', 'node@%s', process.version)

process.on('uncaughtException', errorHandler)

if (conf.usage && npm.command !== 'help') {
npm.argv.unshift(npm.command)
npm.command = 'help'
}

// now actually fire up npm and run the command.
// this is how to use npm programmatically:
conf._exit = true
npm.load(conf, function (er) {
if (er) return errorHandler(er)
log.enableProgress()
npm.commands[npm.command](npm.argv, errorHandler)
})

})()
26 changes: 14 additions & 12 deletions bin/read-package-json.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
var argv = process.argv
if (argv.length < 3) {
console.error("Usage: read-package.json <file> [<fields> ...]")
console.error('Usage: read-package.json <file> [<fields> ...]')
process.exit(1)
}

var fs = require("fs")
, file = argv[2]
, readJson = require("read-package-json")
var file = argv[2]
var readJson = require('read-package-json')

readJson(file, function (er, data) {
if (er) throw er
if (argv.length === 3) console.log(data)
else argv.slice(3).forEach(function (field) {
field = field.split(".")
var val = data
field.forEach(function (f) {
val = val[f]
if (argv.length === 3) {
console.log(data)
} else {
argv.slice(3).forEach(function (field) {
field = field.split('.')
var val = data
field.forEach(function (f) {
val = val[f]
})
console.log(val)
})
console.log(val)
})
}
})
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require("./bin/npm-cli.js")
require('./bin/npm-cli.js')
56 changes: 28 additions & 28 deletions html/static/toc.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
;(function () {
var wrapper = document.getElementById("wrapper")
var els = Array.prototype.slice.call(wrapper.getElementsByTagName("*"), 0)
.filter(function (el) {
return el.parentNode === wrapper
&& el.tagName.match(/H[1-6]/)
&& el.id
})
var l = 2
, toc = document.createElement("ul")
toc.innerHTML = els.map(function (el) {
var i = el.tagName.charAt(1)
, out = ""
while (i > l) {
out += "<ul>"
l ++
}
while (i < l) {
out += "</ul>"
l --
}
out += "<li><a href='#" + el.id + "'>" +
( el.innerText || el.text || el.innerHTML)
+ "</a>"
return out
}).join("\n")
toc.id = "toc"
document.body.appendChild(toc)
})();
var wrapper = document.getElementById('wrapper')
var els = Array.prototype.slice.call(wrapper.getElementsByTagName('*'), 0)
.filter(function (el) {
return el.parentNode === wrapper &&
el.tagName.match(/H[1-6]/) &&
el.id
})
var l = 2
var toc = document.createElement('ul')
toc.innerHTML = els.map(function (el) {
var i = el.tagName.charAt(1)
var out = ''
while (i > l) {
out += '<ul>'
l++
}
while (i < l) {
out += '</ul>'
l--
}
out += '<li><a href=\'#' + el.id + '\'>' +
(el.innerText || el.text || el.innerHTML) +
'</a>'
return out
}).join('\n')
toc.id = 'toc'
document.body.appendChild(toc)
})()
Loading

0 comments on commit b50be6a

Please sign in to comment.