Skip to content

Commit

Permalink
Use npm to load config
Browse files Browse the repository at this point in the history
Fixes #5.
  • Loading branch information
kevva committed May 23, 2017
1 parent a7226ad commit 522f6c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';
const conf = require('rc')('npm');
const npmconf = require('npm/lib/config/core');
const pify = require('pify');

module.exports = () => {
module.exports = () => pify(npmconf.load)().then(conf => {
return process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy ||
conf['https-proxy'] ||
conf['http-proxy'] ||
conf.proxy ||
conf.get('https-proxy') ||
conf.get('http-proxy') ||
conf.get('proxy') ||
null;
};
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"proxy"
],
"dependencies": {
"rc": "^1.1.2"
"npm": "^4.6.1",
"pify": "^2.3.0"
},
"devDependencies": {
"ava": "*",
Expand Down
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import test from 'ava';
import m from './';
import m from '.';

test(t => {
test(async t => {
const proxy = process.env.HTTP_PROXY;
process.env.HTTP_PROXY = 'http://192.168.0.1:8080';
t.is(m(), 'http://192.168.0.1:8080');
t.is(await m(), 'http://192.168.0.1:8080');
process.env.HTTP_PROXY = proxy;
});

0 comments on commit 522f6c4

Please sign in to comment.