@@ -21,8 +21,11 @@ const npmPackageJsonCache = new Map<string, Observable<NpmRepositoryPackageJson>
21
21
let npmrc : { [ key : string ] : string } ;
22
22
23
23
24
- function readOptions ( yarn = false ) : { [ key : string ] : string } {
25
- // TODO: have a way to read options without using fs directly.
24
+ function readOptions (
25
+ logger : logging . LoggerApi ,
26
+ yarn = false ,
27
+ showPotentials = false ,
28
+ ) : Record < string , string > {
26
29
const cwd = process . cwd ( ) ;
27
30
const baseFilename = yarn ? 'yarnrc' : 'npmrc' ;
28
31
const dotFilename = '.' + baseFilename ;
@@ -42,16 +45,25 @@ function readOptions(yarn = false): { [key: string]: string } {
42
45
path . join ( homedir ( ) , dotFilename ) ,
43
46
] ;
44
47
45
- const projectConfigLocations : string [ ] = [ ] ;
48
+ const projectConfigLocations : string [ ] = [
49
+ path . join ( cwd , dotFilename ) ,
50
+ ] ;
46
51
const root = path . parse ( cwd ) . root ;
47
52
for ( let curDir = path . dirname ( cwd ) ; curDir && curDir !== root ; curDir = path . dirname ( curDir ) ) {
48
53
projectConfigLocations . unshift ( path . join ( curDir , dotFilename ) ) ;
49
54
}
50
- projectConfigLocations . push ( path . join ( cwd , dotFilename ) ) ;
55
+
56
+ if ( showPotentials ) {
57
+ logger . info ( `Locating potential ${ baseFilename } files:` ) ;
58
+ }
51
59
52
60
let options : { [ key : string ] : string } = { } ;
53
61
for ( const location of [ ...defaultConfigLocations , ...projectConfigLocations ] ) {
54
62
if ( existsSync ( location ) ) {
63
+ if ( showPotentials ) {
64
+ logger . info ( `Trying '${ location } '...found.` ) ;
65
+ }
66
+
55
67
const data = readFileSync ( location , 'utf8' ) ;
56
68
options = {
57
69
...options ,
@@ -65,6 +77,8 @@ function readOptions(yarn = false): { [key: string]: string } {
65
77
options . ca = readFileSync ( cafile , 'utf8' ) . replace ( / \r ? \n / , '\\n' ) ;
66
78
} catch { }
67
79
}
80
+ } else if ( showPotentials ) {
81
+ logger . info ( `Trying '${ location } '...not found.` ) ;
68
82
}
69
83
}
70
84
@@ -86,9 +100,12 @@ function readOptions(yarn = false): { [key: string]: string } {
86
100
*/
87
101
export function getNpmPackageJson (
88
102
packageName : string ,
89
- registryUrl : string | undefined ,
90
- _logger : logging . LoggerApi ,
91
- usingYarn = false ,
103
+ logger : logging . LoggerApi ,
104
+ options ?: {
105
+ registryUrl ?: string ;
106
+ usingYarn ?: boolean ;
107
+ verbose ?: boolean ;
108
+ } ,
92
109
) : Observable < Partial < NpmRepositoryPackageJson > > {
93
110
const cachedResponse = npmPackageJsonCache . get ( packageName ) ;
94
111
if ( cachedResponse ) {
@@ -97,12 +114,12 @@ export function getNpmPackageJson(
97
114
98
115
if ( ! npmrc ) {
99
116
try {
100
- npmrc = readOptions ( ) ;
117
+ npmrc = readOptions ( logger , false , options && options . verbose ) ;
101
118
} catch { }
102
119
103
- if ( usingYarn ) {
120
+ if ( options && options . usingYarn ) {
104
121
try {
105
- npmrc = { ...npmrc , ...readOptions ( true ) } ;
122
+ npmrc = { ...npmrc , ...readOptions ( logger , true , options && options . verbose ) } ;
106
123
} catch { }
107
124
}
108
125
}
@@ -112,7 +129,7 @@ export function getNpmPackageJson(
112
129
{
113
130
'full-metadata' : true ,
114
131
...npmrc ,
115
- registry : registryUrl ,
132
+ registry : options && options . registryUrl ,
116
133
} ,
117
134
) ;
118
135
0 commit comments