pax_global_header00006660000000000000000000000064132046656060014522gustar00rootroot0000000000000052 comment=ac25ad306bcca8f1b497ac6a0bd918dfa9932a7e node-npmrc-1.1.1/000077500000000000000000000000001320466560600135645ustar00rootroot00000000000000node-npmrc-1.1.1/.npmignore000066400000000000000000000000151320466560600155570ustar00rootroot00000000000000node_modules node-npmrc-1.1.1/.travis.yml000066400000000000000000000000421320466560600156710ustar00rootroot00000000000000language: node_js node_js: '0.10' node-npmrc-1.1.1/LICENSE.md000066400000000000000000000027771320466560600152050ustar00rootroot00000000000000Copyright (c) 2012, Deoxxa Development ====================================== All rights reserved. -------------------- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Deoxxa Development nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY DEOXXA DEVELOPMENT ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DEOXXA DEVELOPMENT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. node-npmrc-1.1.1/README.md000066400000000000000000000104651320466560600150510ustar00rootroot00000000000000npmrc ===== Switch between different .npmrc files with ease and grace. Overview -------- If you use a private npm registry, you know the pain of switching between a bunch of different .npmrc files and manually managing symlinks. Let that be a problem no more! `npmrc` is here to save the day, by making it dead simple to switch out your .npmrc with a specific named version. It also tries to protect you from your own stupid self by making sure you don't accidentally overwrite an .npmrc that you actually want to keep. Installation ------------ ``` sh npm install -g npmrc ``` Usage ----- ``` ➜ ~ npmrc --help npmrc Switch between different .npmrc files with ease and grace. Usage: npmrc list all profiles npmrc [name] change npmrc profile (uses fuzzy matching) npmrc -c [name] create a new npmrc profile called name npmrc -r [registry] use an npm mirror Available mirrors for npmrc -r: au - Australian registry mirror eu - European registry mirror cn - Chinese registry mirror default - Default registry ``` #### Initialisation Calling `npmrc` without arguments creates an `~/.npmrcs/` directory if it doesn't exist, and copies your current `~/.npmrc` as the 'default' .npmrc profile. ``` ➜ ~ npmrc Creating /Users/conrad/.npmrcs Making /Users/conrad/.npmrc the default npmrc file Activating .npmrc 'default' ``` #### Create a new .npmrc profile ``` ➜ ~ npmrc -c newprofile Removing old .npmrc (/home/rvagg/.npmrcs/default) Activating .npmrc 'newprofile' ``` A blank profile will be created. To point your profile to a non-default registry: ``` ➜ ~ npm config set registry http://npm.nodejs.org.au:5984/registry/_design/app/_rewrite ``` Then use `npm adduser` or `npm login` to authenticate with the new profile. #### List available .npmrc profiles ``` ➜ ~ npmrc Available npmrcs: * default work ``` #### Switch to a specific .npmrc ``` ➜ ~ npmrc work Removing old .npmrc (/Users/conrad/.npmrcs/default) Activating .npmrc 'work' ``` You can also pass only the first few characters of a profile and `npmrc` will autocomplete the profile's name. ``` ➜ ~ npmrc def Removing old .npmrc (/Users/conrad/.npmrcs/work) Activating .npmrc 'default' ``` `npmrc ` will also go to some lengths to make sure you don't overwrite anything you might care about: ``` ➜ ~ npmrc default Removing old .npmrc (/Users/conrad/.npmrcs/work) Activating .npmrc 'default' ➜ ~ npmrc default Current .npmrc (/Users/conrad/.npmrc) is already 'default' (/Users/conrad/.npmrcs/default) ➜ ~ rm ~/.npmrc ➜ ~ touch ~/.npmrc ➜ ~ npmrc default Current .npmrc (/Users/conrad/.npmrc) is not a regular file, not removing it ➜ ~ rm ~/.npmrc ➜ ~ npmrc default Activating .npmrc 'default' ``` Note For Windows Users ---------------------- You may have to run npmrc in a shell (cmd, PowerShell, Git Bash, etc) with elevated (Administrative) privileges to get it to run. Environment Variables --------------------- * `NPMRC_STORE` - Path to directory of profiles. Default: `~/.npmrcs/` * `NPMRC` - Path to the npmrc file used by npm. Default: `~/.npmrc` Known npm registry Mirrors --------------------- For your convenience, you can change registries easily using the `-r` flag. Currently we provide aliases for: * [Australia](http://registry.npmjs.org.au/): `npmrc -r au` * [Europe](http://registry.npmjs.eu/): `npmrc -r eu` * [China](http://r.cnpmjs.org): `npmrc -r cn` #### Switching registry example ``` ➜ ~ npm -r eu Using eu registry ➜ ~ npm info npmrc npm http GET http://registry.npmjs.eu/npmrc ^C ➜ ~ npm -r default Using default registry ➜ ~ npm info npmrc npm http GET https://registry.npmjs.org/npmrc ^C ``` License ------- 3-clause BSD. A copy is included with the source. Contact ------- * GitHub ([deoxxa](http://github.com/deoxxa)) * Twitter ([@deoxxa](http://twitter.com/deoxxa)) * Email ([deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz)) Awesome People -------------- * Jaime "the binary wizard" Pillora ([github](https://github.com/jpillora)) * Tim "two hands" Oxley ([github](https://github.com/timoxley)) * Jakob "fastest blur in the west" Krigovsky ([github](https://github.com/SonicHedgehog)) * Rod "the destroyer" Vagg ([github](https://github.com/rvagg)) * Eugene "ludicrous gibs" Asiedu ([github](https://github.com/ngenerio)) node-npmrc-1.1.1/npmrc.js000077500000000000000000000154101320466560600152450ustar00rootroot00000000000000#!/usr/bin/env node const path = require('path') , fs = require('fs') , os = require('os'); const NPMRC_STORE = process.env.NPMRC_STORE || path.join(process.env.HOME || process.env.USERPROFILE, '.npmrcs') , NPMRC = process.env.NPMRC || path.join(process.env.HOME || process.env.USERPROFILE, '.npmrc') , registries = { au: 'http://registry.npmjs.org.au/' , eu: 'http://registry.npmjs.eu/' , cn: 'http://r.cnpmjs.org/' , defaultReg: 'https://registry.npmjs.org/' } , USAGE = 'Usage:\n' + ' npmrc list all profiles\n' + ' npmrc [name] change npmrc profile (uses fuzzy matching)\n' + ' npmrc -c [name] create a new npmrc profile called name\n' + ' npmrc -r [registry] use an npm mirror\n\n' + 'Available mirrors for npmrc -r:\n' + ' au - Australian registry mirror\n' + ' eu - European registry mirror\n' + ' cn - Chinese registry mirror\n' + ' default - Default registry\n' var opts , name function printUsage () { console.error(USAGE) process.exit(1) } function printHelp () { process.stdout.write( 'npmrc\n' + '\n' + ' Switch between different .npmrc files with ease and grace.\n\n' + USAGE + '\n' + 'Example:\n\n' + ' # Creating and activating a new .npmrc called "work":\n' + ' $ npmrc -c work\n\n' + ' # Switch betwen "work" and "default"\n' + ' $ npmrc work\n' + ' $ npmrc default\n' + ' # Use the European npm mirror' + ' $ npmrc -r eu\n' ) process.exit(1) } function printNpmrcs () { console.log('Available npmrcs:\n') fs.readlink(NPMRC, function (err, link) { link = link && path.basename(link) fs.readdirSync(NPMRC_STORE).forEach(function (npmrc) { if (npmrc[0] !== '.') { console.log(' %s %s', link == npmrc ? '*' : ' ', npmrc) } }) }) } // safety check so we don't go overwriting accidentally function checkSymlink (stat) { if (!stat.isSymbolicLink()) { console.log('Current .npmrc (%s) is not a symlink. You may want to copy it into %s.', NPMRC, NPMRC_STORE) process.exit(1) } } // make the symlink function link (name) { var ln = path.join(NPMRC_STORE, name || '') , stat if (ln == NPMRC_STORE || !fs.existsSync(ln)) { console.error('Couldn\'t find npmrc file "%s".', name) return process.exit(1) } try { stat = fs.lstatSync(NPMRC) checkSymlink(stat) } catch (e) {} if (stat) { console.log('Removing old .npmrc (%s)', path.basename(fs.readlinkSync(NPMRC))) fs.unlinkSync(NPMRC) } console.log('Activating .npmrc "%s"', path.basename(ln)) fs.symlinkSync(ln, NPMRC, 'file') } // partial match npmrc names function partialMatch(match, files) { files.sort() // own the sort order // try exact match var exactMatch = files.filter(function(file) { return file === match }).shift() if (exactMatch) return exactMatch // try starts with match var matchesStart = files.filter(function(file) { return file.indexOf(match) === 0 }).shift() if (matchesStart) return matchesStart // try whatever match var matchesAnything = files.filter(function(file) { return file.match(new RegExp(match)) }).shift() if (matchesAnything) return matchesAnything } // simplistic cmdline parser, sets "name" as the first non-'-' arg // and sets "opts" as '-'-stripped characters (first char only) ;(function processCmdline () { opts = process.argv.slice(2).map(function (a) { return a[0] == '-' && a.replace(/^-+/, '')[0] }).filter(Boolean) name = process.argv.slice(2).filter(function (a) { return a[0] != '-' })[0] // first non '-' arg opts.filter(function (o) { if (o == 'c' || o == 'h' || o == 'r' || o === 'registry') // other known opts go here return false console.error('Unknown option: -' + o) return true }).length && printUsage() if (opts.indexOf('h') > -1) printHelp() }()) // set up .npmrcs if it doesn't exist ;(function makeStore () { function make () { var def = path.join(NPMRC_STORE, 'default') console.log('Initialising npmrc...') console.log('Creating %s', NPMRC_STORE) fs.mkdirSync(NPMRC_STORE) if (fs.existsSync(NPMRC)) { console.log('Making %s the default npmrc file', NPMRC) fs.renameSync(NPMRC, def) } else { fs.writeFileSync(def, '') } link('default') process.exit(0) } try { var stat = fs.statSync(NPMRC_STORE) if (!stat.isDirectory()) { console.error('Error: %s is not a directory', NPMRC_STORE) process.exit(1) } } catch (e) { make() } }()) // no name and no args if (!name && !opts.length) return printNpmrcs() ;(function handleOPtions() { if (~opts.indexOf('c')) createNew() else if (~opts.indexOf('r') || ~opts.indexOf('registry')) replaceRegistry() }()) // handle -r function replaceRegistry() { if (!name) { console.error('Specify the registry you want to use') return printUsage() } var registry = registries[(name === 'slow' || name === 'default') ? 'defaultReg' : name] , fileContents try { fs.existsSync(NPMRC) } catch (e) { console.warn('Make sure a .npmrc file exits at %s.', NPMRC) process.exit(1) } if (!registry) { console.error('%s value is not a valid registry name', name) printUsage() } fileContents = fs.readFileSync(NPMRC, 'utf8').split(os.EOL) for (var i = 0, l = fileContents.length; i < l; i++) { if (~fileContents[i].indexOf('registry')) { fileContents[i] = 'registry = ' + registry break; } } if (i === l) fileContents.unshift('registry = ' + registry) fs.writeFileSync(NPMRC, fileContents.join(os.EOL)) console.log('Using %s registry.', registry) process.exit(0) } // handle -c function createNew () { if (!name) { console.error('What do you want to call your new npm configuration?') return printUsage() } var c = path.join(NPMRC_STORE, name) if (fs.existsSync(c)) { console.log('npmrc file "%s", already exists (%s/%s)', name, NPMRC_STORE, name) return process.exit(1) } fs.writeFileSync(c, '') } if (name) name = partialMatch(name, fs.readdirSync(NPMRC_STORE)) || name // sanity/safety check, also check if they want to switch // to the already active one ;(function checkExisting () { var stat try { stat = fs.lstatSync(NPMRC) checkSymlink(stat) } catch (e) { // ignore } if (name && stat && fs.readlinkSync(NPMRC) == path.join(NPMRC_STORE, name)) { console.log('Current .npmrc (%s) is already "%s" (%s/%s)', NPMRC, name, NPMRC_STORE, name) return process.exit(0) } }()) // if we got here, then we're ready to switch link(name) node-npmrc-1.1.1/package.json000066400000000000000000000011171320466560600160520ustar00rootroot00000000000000{ "name": "npmrc", "version": "1.1.1", "description": "Switch between different .npmrc files with ease and grace", "preferGlobal": true, "bin": { "npmrc": "./npmrc.js" }, "repository": { "type": "git", "url": "git://github.com/deoxxa/npmrc.git" }, "keywords": [ "npmrc", "utility", "shell", "npm" ], "author": "Conrad Pankoff (http://www.fknsrs.biz/)", "license": "BSD", "devDependencies": { "rimraf": "*", "mkdirp": "*", "tape": "*", "xtend": "*" }, "scripts": { "test": "tape test.js" } } node-npmrc-1.1.1/test.js000066400000000000000000000201061320466560600151000ustar00rootroot00000000000000const test = require('tape') , path = require('path') , os = require('os') , fs = require('fs') , rimraf = require('rimraf') , mkdirp = require('mkdirp') , tmpdir = require('os').tmpDir() , exec = require('child_process').exec , xtend = require('xtend') , cmd = '"' + process.execPath + '" ' + path.join(__dirname, 'npmrc.js') , homedir = path.join(tmpdir, '.npmrcs_test.' + process.pid) , options = { env: xtend(process.env, { HOME: homedir }) } , npmrc = path.join(homedir, '.npmrc') , npmrcs = path.join(homedir, '.npmrcs') , def = path.join(homedir, '.npmrcs/default') , dotfile = path.join(homedir, '.npmrcs/.dotfile') function cleanup (t) { rimraf(homedir, t.end.bind(t)) } test('blank slate', function (t) { mkdirp.sync(homedir) exec(cmd, options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Initialising/.test(stdout), 'got "initialising" msg') t.ok(/Creating .*\.npmrcs/.test(stdout), 'got "creating" msg') t.ok(/Activating .npmrc "default"/, 'got "activating" msg') t.end() }) }) test('change the registry url', function (t) { exec(cmd + ' -r au', options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.ok(fs.existsSync(npmrc), '.npmrc file exists') t.ok(fs.existsSync(def), '.npmrc default file exists') t.equal(fs.readFileSync(def, 'utf-8').split(os.EOL)[0], 'registry = http://registry.npmjs.org.au/', 'got the right registry url') t.end() }) }) test('error occurs when the wrong argument is supplied to -r', function (t) { exec(cmd + ' -r foo', options, function (err, stdout, stderr) { t.ok(err, 'error occured') t.equal(err.code, 1, 'process exited with the right code') t.end() }) }) test('cleanup', cleanup) test('standard .npmrcs', function (t) { mkdirp.sync(homedir) fs.writeFileSync(npmrc, 'foobar', 'utf8') exec(cmd, options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Initialising/.test(stdout), 'got "initialising" msg') t.ok(/Creating .*\.npmrcs/.test(stdout), 'got "creating" msg') t.ok(/Activating .npmrc "default"/, 'got "activating" msg') t.ok(/Making .*\.npmrc the default/, 'got "making default" msg') t.equal(fs.readFileSync(npmrc, 'utf8'), 'foobar', 'got expected contents of .npmrc') t.equal(fs.readFileSync(def, 'utf8'), 'foobar', 'got expected contents of .npmrcs/default') t.ok(fs.lstatSync(npmrc).isSymbolicLink(), '.npmrc is symlink') t.equal(fs.readlinkSync(npmrc), def, '.npmrc points to "default"') t.deepEqual(fs.readdirSync(npmrcs), [ 'default' ], 'only "default" in .npmrcs') t.end() }) }) test('create noarg', function (t) { exec(cmd + ' -c', options, function (err, stdout, stderr) { t.ok(err, 'got error') t.equal(err.code, 1, 'got correct exit code') t.equal(stdout, '', 'no stdout') t.ok(/Usage/.test(stderr), 'got Usage') t.equal(fs.readFileSync(npmrc, 'utf8'), 'foobar', 'got expected contents of .npmrc') t.deepEqual(fs.readdirSync(npmrcs), [ 'default' ], 'only "default" in .npmrcs') t.end() }) }) test('create new config', function (t) { var foobar = path.join(npmrcs, 'foobar') exec(cmd + ' -c foobar', options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Removing old .+\Wdefault\W/.test(stdout), 'got "removing" msg') t.ok(/Activating .npmrc "foobar"/.test(stdout), 'got "activating" msg') t.equal(fs.readFileSync(npmrc, 'utf8'), '', 'got expected contents of .npmrc') t.equal(fs.readFileSync(def, 'utf8'), 'foobar', 'got expected contents of .npmrcs/default') t.equal(fs.readFileSync(foobar, 'utf8'), '', 'got expected contents of .npmrcs/foobar') t.ok(fs.lstatSync(npmrc).isSymbolicLink(), '.npmrc is symlink') t.equal(fs.readlinkSync(npmrc), foobar, '.npmrc points to "foobar"') t.deepEqual(fs.readdirSync(npmrcs), [ 'default', 'foobar' ], '"default" and "foobar" in .npmrcs') t.end() }) }) test('switch config', function (t) { var foobar = path.join(npmrcs, 'foobar') exec(cmd + ' default', options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Removing old .+\Wfoobar\W/.test(stdout), 'got "removing" msg') t.ok(/Activating .npmrc "default"/.test(stdout), 'got "activating" msg') t.equal(fs.readFileSync(npmrc, 'utf8'), 'foobar', 'got expected contents of .npmrc') t.equal(fs.readFileSync(def, 'utf8'), 'foobar', 'got expected contents of .npmrcs/default') t.equal(fs.readFileSync(foobar, 'utf8'), '', 'got expected contents of .npmrcs/foobar') t.ok(fs.lstatSync(npmrc).isSymbolicLink(), '.npmrc is symlink') t.equal(fs.readlinkSync(npmrc), def, '.npmrc points to "foobar"') t.deepEqual(fs.readdirSync(npmrcs), [ 'default', 'foobar' ], '"default" and "foobar" in .npmrcs') t.end() }) }) test('list config', function (t) { fs.writeFileSync(dotfile, '.dotfile', 'utf8') exec(cmd, options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Available npmrcs/.test(stdout), 'got "available" msg') t.ok((/\* default$/m).test(stdout), 'listed "default"') t.ok((/ foobar$/m).test(stdout), 'listed "foobar"') t.notOk((/\.dotfile$/m).test(stdout), 'listed "dotfile"') t.end() }) }) test('switch to non-existent config', function (t) { exec(cmd + ' doobar', options, function (err, stdout, stderr) { t.ok(err, 'got error') t.equal(err.code, 1, 'got correct exit code') t.equal(stdout, '', 'no stdout') t.ok(/Couldn't find npmrc file "doobar"/.test(stderr), 'got expected error message') t.end() }) }) test('partial matching start of npmrc', function (t) { exec(cmd + ' foo', options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Activating .npmrc "foobar"/.test(stdout), 'got "activating" msg') t.end() }) }) test('partial matching prefers full match over partial', function (t) { exec(cmd + ' -c foo', options, function (err, stdout, stderr) { // create foo t.notOk(err, 'no error') // match against foobar should pick foobar not foo exec(cmd + ' foobar', options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Activating .npmrc "foobar"/.test(stdout), 'got "activating" msg') t.end() }) }) }) test('partial matching prefers start of word match over partial match', function (t) { exec(cmd + ' -c bar', options, function (err, stdout, stderr) { // create bar t.notOk(err, 'no error') exec(cmd + ' default', options, function (err, stdout, stderr) { // switch to default t.notOk(err, 'no error') exec(cmd + ' ba', options, function (err, stdout, stderr) { // ensure 'ba' switches to bar not foobar. t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Activating .npmrc "bar"/.test(stdout), 'got "activating" msg') t.end() }) }) }) }) test('partial matching can match any part of npmrc', function (t) { exec(cmd + ' ooba', options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Activating .npmrc "foobar"/.test(stdout), 'got "activating" msg') t.end() }) }) test('partial matching matches alphabetically', function (t) { exec(cmd + ' -c car', options, function (err, stdout, stderr) { // create car t.notOk(err, 'no error') exec(cmd + ' default', options, function (err, stdout, stderr) { // switch to default t.notOk(err, 'no error') var foobar = path.join(npmrcs, 'foobar') // try match ar from bar, car, foobar // should pick bar exec(cmd + ' ar', options, function (err, stdout, stderr) { t.notOk(err, 'no error') t.equal(stderr, '', 'no stderr') t.ok(/Activating .npmrc "bar"/.test(stdout), 'got "activating" msg') t.end() }) }) }) }) test('cleanup', cleanup)