@@ -14,6 +14,8 @@ const NpmConfig = figgyPudding({}, {
14
14
15
15
const ConfigOpts = figgyPudding ( {
16
16
cache : { default : path . join ( os . homedir ( ) , '.npm' ) } ,
17
+ configNames : { default : [ 'npmrc' , '.npmrc' ] } ,
18
+ envPrefix : { default : / ^ n p m _ c o n f i g _ / i } ,
17
19
cwd : { default : ( ) => process . cwd ( ) } ,
18
20
globalconfig : {
19
21
default : ( ) => path . join ( getGlobalPrefix ( ) , 'etc' , 'npmrc' )
@@ -26,9 +28,9 @@ function getNpmConfig (_opts, _builtin) {
26
28
const builtin = ConfigOpts ( _builtin )
27
29
const env = { }
28
30
for ( let key of Object . keys ( process . env ) ) {
29
- if ( ! / ^ n p m _ c o n f i g _ / i . test ( key ) ) continue
31
+ if ( ! key . match ( builtin . envPrefix ) ) continue
30
32
const newKey = key . toLowerCase ( )
31
- . replace ( / ^ n p m _ c o n f i g _ / i , '' )
33
+ . replace ( builtin . envPrefix , '' )
32
34
. replace ( / (? ! ^ ) _ / g, '-' )
33
35
env [ newKey ] = process . env [ key ]
34
36
}
@@ -45,15 +47,28 @@ function getNpmConfig (_opts, _builtin) {
45
47
env . globalconfig
46
48
)
47
49
const global = globalConfPath && maybeReadIni ( globalConfPath )
48
- const projConfPath = findUp . sync ( [ '.npmrc' , 'npmrc' ] , { cwd : builtin . cwd } )
50
+ const projConfPath = findUp . sync ( builtin . configNames , { cwd : builtin . cwd } )
49
51
let proj
50
52
if ( projConfPath && projConfPath !== userConfPath ) {
51
53
proj = maybeReadIni ( projConfPath )
52
54
}
53
55
const newOpts = NpmConfig ( builtin , global , user , proj , env , cli )
54
56
if ( newOpts . cache ) {
55
57
return newOpts . concat ( {
56
- cache : path . join ( newOpts . cache , '_cacache' )
58
+ cache : path . resolve (
59
+ (
60
+ ( cli . cache || env . cache )
61
+ ? builtin . cwd
62
+ : proj . cache
63
+ ? path . dirname ( projConfPath )
64
+ : user . cache
65
+ ? path . dirname ( userConfPath )
66
+ : global . cache
67
+ ? path . dirname ( globalConfPath )
68
+ : path . dirname ( userConfPath )
69
+ ) ,
70
+ newOpts . cache
71
+ )
57
72
} )
58
73
} else {
59
74
return newOpts
0 commit comments