pax_global_header00006660000000000000000000000064134512771440014522gustar00rootroot0000000000000052 comment=834d89118d7445bf8f6dfc23c09582ea6dfe845c registry-url-5.1.0/000077500000000000000000000000001345127714400141755ustar00rootroot00000000000000registry-url-5.1.0/.editorconfig000066400000000000000000000002571345127714400166560ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 registry-url-5.1.0/.gitattributes000066400000000000000000000000231345127714400170630ustar00rootroot00000000000000* text=auto eol=lf registry-url-5.1.0/.gitignore000066400000000000000000000000271345127714400161640ustar00rootroot00000000000000node_modules yarn.lock registry-url-5.1.0/.travis.yml000066400000000000000000000000541345127714400163050ustar00rootroot00000000000000language: node_js node_js: - '10' - '8' registry-url-5.1.0/index.d.ts000066400000000000000000000016651345127714400161060ustar00rootroot00000000000000declare const registryUrl: { /** Get the set npm registry URL. @param scope - Retrieve the registry URL associated with an [npm scope](https://docs.npmjs.com/misc/scope). If the provided scope is not in the user's `.npmrc` file, then `registry-url` will check for the existence of `registry`, or if that's not set, fallback to the default npm registry. @example ``` import registryUrl = require('registry-url'); // # .npmrc // registry = 'https://custom-registry.com/' console.log(registryUrl()); //=> 'https://custom-registry.com/' // # .npmrc // @myco:registry = 'https://custom-registry.com/' console.log(registryUrl('@myco')); //=> 'https://custom-registry.com/' ``` */ (scope?: string): string; // TODO: Remove this for the next major release, refactor the whole definition to: // declare function registryUrl(scope?: string): string; // export = registryUrl; default: typeof registryUrl; }; export = registryUrl; registry-url-5.1.0/index.js000066400000000000000000000006161345127714400156450ustar00rootroot00000000000000'use strict'; const rc = require('rc'); const registryUrl = scope => { const result = rc('npm', {registry: 'https://registry.npmjs.org/'}); const url = result[`${scope}:registry`] || result.config_registry || result.registry; return url.slice(-1) === '/' ? url : `${url}/`; }; module.exports = registryUrl; // TODO: Remove this for the next major release module.exports.default = registryUrl; registry-url-5.1.0/index.test-d.ts000066400000000000000000000002211345127714400170460ustar00rootroot00000000000000import {expectType} from 'tsd'; import registryUrl = require('.'); expectType(registryUrl()); expectType(registryUrl('@myco')); registry-url-5.1.0/license000066400000000000000000000021251345127714400155420ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. registry-url-5.1.0/package.json000066400000000000000000000012511345127714400164620ustar00rootroot00000000000000{ "name": "registry-url", "version": "5.1.0", "description": "Get the set npm registry URL", "license": "MIT", "repository": "sindresorhus/registry-url", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "npm", "conf", "config", "npmconf", "registry", "url", "uri", "scope" ], "dependencies": { "rc": "^1.2.8" }, "devDependencies": { "ava": "^1.4.1", "import-fresh": "^3.0.0", "tsd": "^0.7.2", "xo": "^0.24.0" }, "ava": { "serial": true } } registry-url-5.1.0/readme.md000066400000000000000000000022471345127714400157610ustar00rootroot00000000000000# registry-url [![Build Status](https://travis-ci.org/sindresorhus/registry-url.svg?branch=master)](https://travis-ci.org/sindresorhus/registry-url) > Get the set npm registry URL It's usually `https://registry.npmjs.org/`, but it's [configurable](https://docs.npmjs.com/misc/registry). Use this if you do anything with the npm registry as users will expect it to use their configured registry. ## Install ``` $ npm install registry-url ``` ## Usage ```ini # .npmrc registry = 'https://custom-registry.com/' ``` ```js const registryUrl = require('registry-url'); console.log(registryUrl()); //=> 'https://custom-registry.com/' ``` It can also retrieve the registry URL associated with an [npm scope](https://docs.npmjs.com/misc/scope). ```ini # .npmrc @myco:registry = 'https://custom-registry.com/' ``` ```js const registryUrl = require('registry-url'); console.log(registryUrl('@myco')); //=> 'https://custom-registry.com/' ``` If the provided scope is not in the user's `.npmrc` file, then `registry-url` will check for the existence of `registry`, or if that's not set, fallback to the default npm registry. ## License MIT © [Sindre Sorhus](https://sindresorhus.com) registry-url-5.1.0/test.js000066400000000000000000000031551345127714400155160ustar00rootroot00000000000000import {promisify} from 'util'; import fs from 'fs'; import test from 'ava'; import importFresh from 'import-fresh'; const unlinkP = promisify(fs.unlink); const writeFileP = promisify(fs.writeFile); delete process.env.npm_config_registry; test.afterEach(async () => { try { await unlinkP('.npmrc'); } catch (_) {} }); test('get the npm registry URL globally', t => { t.truthy(importFresh('.')().length); }); test('works with npm_config_registry in the environment', t => { // eslint-disable-next-line camelcase process.env.npm_config_registry = 'http://registry.example'; t.is(importFresh('.')(), 'http://registry.example/'); delete process.env.npm_config_registry; }); test('get the npm registry URL locally', async t => { await writeFileP('.npmrc', 'registry=http://registry.npmjs.eu/'); t.is(importFresh('.')(), 'http://registry.npmjs.eu/'); }); test('get local scope registry URL', async t => { await writeFileP('.npmrc', '@myco:registry=http://reg.example.com/'); t.is(importFresh('.')('@myco'), 'http://reg.example.com/'); }); test('return default npm registry when scope registry is not set', async t => { await writeFileP('.npmrc', ''); t.is(importFresh('.')('@invalidScope'), 'https://registry.npmjs.org/'); }); test('add trailing slash to local npm registry URL', async t => { await writeFileP('.npmrc', 'registry=http://registry.npmjs.eu'); t.is(importFresh('.')(), 'http://registry.npmjs.eu/'); }); test('add trailing slash to local scope registry URL', async t => { await writeFileP('.npmrc', '@myco:registry=http://reg.example.com'); t.is(importFresh('.')('@myco'), 'http://reg.example.com/'); });