diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-06-23 08:18:52 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-06-26 03:27:33 +0300 |
commit | b50be6aff34a739ca43de65f546e743d1a9975b9 (patch) | |
tree | 3153fd3a271245b8a05a9be196286fbe31fc9d44 /lib/access.js | |
parent | 7c5ebe0552b7b5d0cdca34d28c4f16fe794ff2ff (diff) |
src: make the npm source comply with `standard`
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: https://github.com/npm/npm/pull/8668
Diffstat (limited to 'lib/access.js')
-rw-r--r-- | lib/access.js | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/lib/access.js b/lib/access.js index cf960a67d..7a4fda7d3 100644 --- a/lib/access.js +++ b/lib/access.js @@ -1,80 +1,80 @@ -var assert = require("assert") -var resolve = require("path").resolve -var url = require("url") +var assert = require('assert') +var resolve = require('path').resolve +var url = require('url') -var log = require("npmlog") -var readPackageJson = require("read-package-json") +var log = require('npmlog') +var readPackageJson = require('read-package-json') -var mapToRegistry = require("./utils/map-to-registry.js") -var npa = require("npm-package-arg") -var npm = require("./npm.js") +var mapToRegistry = require('./utils/map-to-registry.js') +var npa = require('npm-package-arg') +var npm = require('./npm.js') module.exports = access -access.usage = "npm access public [<package>]" - + "\nnpm access restricted [<package>]" - + "\nnpm access add <read-only|read-write> <entity> [<package>]" - + "\nnpm access rm <entity> [<package>]" - + "\nnpm access ls [<package>]" - + "\nnpm access edit [<package>]" +access.usage = 'npm access public [<package>]' + + '\nnpm access restricted [<package>]' + + '\nnpm access add <read-only|read-write> <entity> [<package>]' + + '\nnpm access rm <entity> [<package>]' + + '\nnpm access ls [<package>]' + + '\nnpm access edit [<package>]' access.completion = function (opts, cb) { var argv = opts.conf.argv.remain if (argv.length === 2) { - return cb(null, ["public", "restricted", "add", "rm", "ls", "edit"]) + return cb(null, ['public', 'restricted', 'add', 'rm', 'ls', 'edit']) } switch (argv[2]) { - case "public": - case "restricted": - case "ls": - case "edit": - return cb(new Error("unimplemented: packages you can change")) - case "add": - if (argv.length === 3) return cb(null, ["read-only", "read-write"]) - - return cb(new Error("unimplemented: entities and packages")) - case "rm": - return cb(new Error("unimplemented: entities and packages")) + case 'public': + case 'restricted': + case 'ls': + case 'edit': + return cb(new Error('unimplemented: packages you can change')) + case 'add': + if (argv.length === 3) return cb(null, ['read-only', 'read-write']) + + return cb(new Error('unimplemented: entities and packages')) + case 'rm': + return cb(new Error('unimplemented: entities and packages')) default: - return cb(new Error(argv[2]+" not recognized")) + return cb(new Error(argv[2] + ' not recognized')) } } function access (args, cb) { var cmd = args.shift() switch (cmd) { - case "public": case "restricted": return changeAccess(args, cmd, cb) - case "add": case "set": return add(args, cb) - case "rm": case "del": case "clear": return rm(args, cb) - case "list": case "sl": case "ls": return ls(args, cb) - case "edit": case "ed": return edit(args, cb) - default: return cb("Usage:\n"+access.usage) + case 'public': case 'restricted': return changeAccess(args, cmd, cb) + case 'add': case 'set': return add(args, cb) + case 'rm': case 'del': case 'clear': return rm(args, cb) + case 'list': case 'sl': case 'ls': return ls(args, cb) + case 'edit': case 'ed': return edit(args, cb) + default: return cb('Usage:\n' + access.usage) } } function changeAccess (args, level, cb) { - assert(Array.isArray(args), "changeAccess requires args be an array") + assert(Array.isArray(args), 'changeAccess requires args be an array') assert( - ["public", "restricted"].indexOf(level) !== -1, + ['public', 'restricted'].indexOf(level) !== -1, "access level must be either 'public' or 'restricted'" ) - assert(typeof cb === "function", "changeAccess requires a callback") + assert(typeof cb === 'function', 'changeAccess requires a callback') - var p = (args.shift() || "").trim() + var p = (args.shift() || '').trim() if (!p) return getCurrentPackage(level, cb) changeAccess_(p, level, cb) } function getCurrentPackage (level, cb) { - var here = resolve(npm.prefix, "package.json") - log.verbose("setPackageLevel", "here", here) + var here = resolve(npm.prefix, 'package.json') + log.verbose('setPackageLevel', 'here', here) readPackageJson(here, function (er, data) { if (er) return cb(er) if (!data.name) { - return cb(new Error("Package must be named")) + return cb(new Error('Package must be named')) } changeAccess_(data.name, level, cb) @@ -82,24 +82,24 @@ function getCurrentPackage (level, cb) { } function changeAccess_ (name, level, cb) { - log.verbose("changeAccess", "name", name, "level", level) + log.verbose('changeAccess', 'name', name, 'level', level) mapToRegistry(name, npm.config, function (er, uri, auth, base) { if (er) return cb(er) var data = npa(name) if (!data.scope) { var msg = "Sorry, you can't change the access level of unscoped packages." - log.error("access", msg) + log.error('access', msg) return cb(new Error(msg)) } // name must be scoped, so escape separator - name = name.replace("/", "%2f") + name = name.replace('/', '%2f') // FIXME: mapToRegistry still isn't generic enough SIGH - uri = url.resolve(base, "-/package/"+name+"/access") + uri = url.resolve(base, '-/package/' + name + '/access') var params = { - level : level, - auth : auth + level: level, + auth: auth } npm.registry.access(uri, params, cb) |