delfrrr / npm-consider

Check package dependencies before installing it
Other
463 stars 15 forks source link

support for scoped registry urls #4

Closed killerfurbel closed 6 years ago

killerfurbel commented 6 years ago

I got across this when checking one of my projects which contains modules from SAP (@sap/ prefix), those modules are hosted on npm.sap.com. To be able to npm install those modules, you need to add this setting to the npm config (for example, to the user config):

@sap:registry = "https://npm.sap.com"

see https://docs.npmjs.com/misc/scope#associating-a-scope-with-a-registry

I was looking for a way to get these npm settings and came across npm-conf, but this module mainly relied on a dependency config-chain to get the configuration. I checked this one and it said:

This module is frozen.
In general, I'd recommend using rc instead, but as npm depends on this, it cannot be changed.

So I went with rc, which does the job.

rc has the following dependencies:

┌───────────────────────────┬─────────┬──────────────┬──────────────────────────────────────────────────┬────────────────────────────┐
│ Package                   │ Size    │ Updated      │ License                                          │ Dependencies               │
├───────────────────────────┼─────────┼──────────────┼────────────┬─────────────────────────────────────┼────────────────────────────┤
│ rc@1.2.8                  │ 6.98 KB │ a month ago  │ Permissive │ (BSD-2-Clause OR MIT OR Apache-2.0) │ deep-extend@^0.6.0,        │
│                           │         │              │            │                                     │ ini@~1.3.0,                │
│                           │         │              │            │                                     │ minimist@^1.2.0,           │
│                           │         │              │            │                                     │ strip-json-comments@~2.0.1 │
├───────────────────────────┼─────────┼──────────────┼────────────┼─────────────────────────────────────┼────────────────────────────┤
│ ini@1.3.5                 │ 3.8 KB  │ 7 months ago │ Permissive │ ISC                                 │                            │
├───────────────────────────┼─────────┼──────────────┼────────────┼─────────────────────────────────────┼────────────────────────────┤
│ minimist@1.2.0            │ 7.54 KB │ 3 years ago  │ Permissive │ MIT                                 │                            │
├───────────────────────────┼─────────┼──────────────┼────────────┼─────────────────────────────────────┼────────────────────────────┤
│ strip-json-comments@2.0.1 │ 2.22 KB │ 2 years ago  │ Permissive │ MIT                                 │                            │
├───────────────────────────┼─────────┼──────────────┼────────────┼─────────────────────────────────────┼────────────────────────────┤
│ deep-extend@0.6.0         │ 3.54 KB │ a month ago  │ Permissive │ MIT                                 │                            │
└───────────────────────────┴─────────┴──────────────┴────────────┴─────────────────────────────────────┴────────────────────────────┘

Now rc is used to get the config (global and project specific), the module key is checked for a scope using a regex (starting with @, containing a /). If there is a scope, try to use the registry url of the scope, fallback to the official registry.npmjs.org

npm config is fine when the scoped registry URL does not end with a /, but since we just concaternate the module name, we need to add a / to the url if it doesn't end with one...

delfrrr commented 6 years ago

Hi! Thank you for the pull request and detailed explanation of how it works! Overall the approach of using of rc looks good to me. I will check the code soon.

delfrrr commented 6 years ago

Thank you @killerfurbel !

delfrrr commented 6 years ago

Published as 1.6.0 on npm and GitHub https://github.com/delfrrr/npm-consider/releases