Git Product home page Git Product logo

npmrc's Introduction

npmrc

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

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 <name> 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:

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

Awesome People

  • Jaime "the binary wizard" Pillora (github)
  • Tim "two hands" Oxley (github)
  • Jakob "fastest blur in the west" Krigovsky (github)
  • Rod "the destroyer" Vagg (github)
  • Eugene "ludicrous gibs" Asiedu (github)

npmrc's People

Contributors

dead-horse avatar deoxxa avatar dylang avatar jpillora avatar killermonk avatar nanaeasiedu avatar rvagg avatar serby avatar sonicdoe avatar timoxley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

npmrc's Issues

Fails in windows

The command npmrc fails in windows because there is no any environment variable HOME set in windows.

Using process.env.HOME || process.env.USERPROFILE on lines 7 and 8 may resolve this issue.

C:\Users\Ngene>npmrc

path.js:204
        throw new TypeError('Arguments to path.join must be strings');
              ^
TypeError: Arguments to path.join must be strings
    at f (path.js:204:15)
    at Object.filter (native)
    at Object.exports.join (path.js:209:40)
    at Object.<anonymous> (C:\Users\Ngene\AppData\Roaming\npm\node_modules\npmrc\npmrc.js:7:51)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

yarn support

the company i work with have a private npm registry so I constantly switching between public registry and the corp private one, thanks to this great tool, the process has been smooth.
I was just wondering how hard it's to update ~/.yarnrc as well

I know the syntax is different for npmrc and yarnrc file, but, that different should be that big and they are all predictable
any idea in this space? thanks

Feature Request: autocomplete script

I know you can type just the first few letters for the profile you want to switch to, but it would be nice if there was a bash autocomplete script to let you tab-complete the profile name.

Thanks for the cool utility.

`Issue while reading "~/.config/nvm/versions/node/v18.10.0/lib/node_modules/npmrc". EISDIR: illegal operation on a directory, read`

Every time I run pnpm, the first thing that gets printed is the following:

WARN: Issue while reading "~/.config/nvm/versions/node/v18.10.0/lib/node_modules/npmrc". EISDIR: illegal operation on a directory, read

The issue goes away when I run npm rm -g npmrc, however I'd like to keep it installed.

As the error message implies, I am using node 18.10.0 managed by nvm.

Could not create .npmrc file on windows

I was on Win10, but once I manually did touch C:\Users\fritx\.npmrc it began to work

$ npm i -g npmrc
$ npmrc -r cn
Initialising npmrc...
Creating C:\Users\fritx\.npmrcs
Activating .npmrc "default"
fs.js:500
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory 'C:\Users\fritx\.npmrc'
    at Error (native)
    at Object.fs.openSync (fs.js:500:18)
    at Object.fs.readFileSync (fs.js:352:15)
    at replaceRegistry (C:\Users\fritx\AppData\Roaming\npm\node_modules\npmrc\npmrc.js:215:21)
    at handleOPtions (C:\Users\fritx\AppData\Roaming\npm\node_modules\npmrc\npmrc.js:190:5)
    at Object.<anonymous> (C:\Users\fritx\AppData\Roaming\npm\node_modules\npmrc\npmrc.js:191:2)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

able to change to profile that doesn't exist which results in symlink that breaks

npmrc
npmrc test1
npmrc test2 - I was able to change to this profile without a error message then is see the below error:
Current .npmrc (/Users/test/.npmrc) is not a symlink. You may want to copy it into /Users/test/.npmrcs.
From then on running npmrc test1 doesn't properly symlink back to .npmrc.
Have to then start from scratch.

Interactive mode

I have many npm profiles setup on my work machine. I would like to make it slightly easier to switch between them. To do so, I propose an "intactive mode" where I'd be able to type:

$ npmrc

NOTE: this could be added behind an --interactive/-i flag to avoid a breaking change.

Which would bring up the list of profiles (currently exists), and let me select one by using arrow keys. Something like inquirer.prompt() in "list" mode would work perfectly. A working example can be found in the Inquirer.js repository.

I'd be happy to contribute this functionality (if desired). Please let me know what you think!

Add Windows Support

Running on windows causes:

Error: EPERM: operation not permitted, symlink 'C:\Users\user.npmrcs\default' -> 'C:\Users\user.npmrc'

I suspect that is because Windows doesnt support links

npmrc --registry [TLD]

perhaps we could bundle up some of the other global mirrors and allow a simple operation like:

> npmrc --registry au # selects AU npm mirror
> npmrc --registry eu # selects some mirror in europe ?
> npmrc --registry slow # selects US default

This would simply overwrite the registry entry in the current npmrc.

Best case

Auto set the registry based on something like, IP lookup:

>npmrc --registry auto
Looks like you in Australia mate. Selected AU registry.

Worst case

Provide a list of public mirrors in the readme.

Confusing message "You may want to copy..."

this log is confusing:

Current .npmrc (/Users/callum/.npmrc) is not a symlink. You may want to copy it into /Users/callum/.npmrcs.

do you mean you may want to move it (not copy), and then create a symlink to it from ~/.npmrc?

also, why? what's the benefit of it being a symlink?

Instructions on README not working

Not sure if the things on the README are correct, because following it doesn't work for me.

Firstly, README says it would have created the directory if I typed in npmrc without any args.

➜ npmrc
Available npmrcs:

find: /Users/paolo.delmundo/.npmrcs: No such file or directory

Secondly, when trying to switch, I get this error message:

➜  ~  npmrc default
Current .npmrc (/Users/paolo.delmundo/.npmrc) is not a regular file, not removing it

NPM Path Variables

Hello,

the Path Variables in the README seams to be false...

Here your code:

const NPMRC_STORE = process.env.NPM_STORE || path.join(process.env.HOME || process.env.USERPROFILE, '.npmrcs')
    , NPMRC       = process.env.NPMC || path.join(process.env.HOME || process.env.USERPROFILE, '.npmrc')
    , USAGE       = 'Usage: npmrc [-c] [name]'

It seams to be NPM_STORE / NPMC and not NPMRC_STORE / NPMRC...

partial matching not working in 1.0.0

I just upgraded from 0.0.4 and my favorite feature, the partial matching, seems to have stopped working. Typing the full names works, but i can no longer use the first character, or at fewer than all of the characters, to get a match.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.