@@ -41,56 +41,61 @@ class Registry {
41
41
throw new Error ( `Failed to extract package ${ pkgName } @${ version } : ${ err . message } ` ) ;
42
42
}
43
43
}
44
+
44
45
async _getPacote ( ) {
45
- return {
46
- pacote : ( await import ( "pacote" ) ) . default ,
47
- pacoteOptions : await this . _getPacoteOptions ( )
48
- } ;
49
- }
50
- async _getPacoteOptions ( ) {
51
- if ( ! this . _npmConfig ) {
52
- const { default : libnpmconfig } = await import ( "libnpmconfig" ) ;
53
- const opts = {
54
- cache : this . _cacheDir ,
46
+ if ( this . _pGetPacote ) {
47
+ return this . _pGetPacote ;
48
+ }
49
+ return this . _pGetPacote = ( async ( ) => {
50
+ return {
51
+ pacote : ( await import ( "pacote" ) ) . default ,
52
+ pacoteOptions : await this . _getPacoteOptions ( )
55
53
} ;
56
- const config = libnpmconfig . read ( opts , {
57
- cwd : this . _cwd
58
- } ) . toJSON ( ) ;
54
+ } ) ( ) ;
55
+ }
59
56
60
- // Rename https-proxy to httpsProxy so that it is picked up by npm-registry-fetch (via pacote)
61
- if ( config [ "https-proxy" ] ) {
62
- config . httpsProxy = config [ "https-proxy" ] ;
63
- delete config [ "https-proxy" ] ;
64
- }
57
+ async _getPacoteOptions ( ) {
58
+ const { default : Config } = await import ( "@npmcli/ config" ) ;
59
+ const {
60
+ default : { flatten , definitions , shorthands , defaults } ,
61
+ } = await import ( "@npmcli/config/lib/definitions/index.js" ) ;
65
62
66
- if ( ! config . proxy && ! config . httpsProxy ) {
67
- // Disable usage of shared keep-alive agents unless a proxy is configured
68
- // which only works with agents.
63
+ const configuration = new Config ( {
64
+ cwd : this . _cwd ,
65
+ npmPath : this . _cwd ,
66
+ definitions,
67
+ flatten,
68
+ shorthands,
69
+ defaults
70
+ } ) ;
69
71
70
- // make-fetch-happen uses a hard-coded 15 seconds freeSocketTimeout
71
- // that can be easily reached (Error: Socket timeout) and there doesn't
72
- // seem to be another way to disable or increase it.
73
- // Also see: https://github.com/node-modules/agentkeepalive/issues/106
74
- config . agent = false ;
75
- }
72
+ await configuration . load ( ) ; // Reads through the configurations
73
+ const config = configuration . flat ; // JSON. Formatted via "flatten"
76
74
77
- log . verbose ( `Using npm configuration (extract):` ) ;
78
- // Do not log full configuration as it may contain authentication tokens
79
- logConfig ( config , "registry" ) ;
80
- logConfig ( config , "@sapui5:registry" ) ;
81
- logConfig ( config , "@openui5:registry" ) ;
82
- logConfig ( config , "proxy" ) ;
83
- logConfig ( config , "httpsProxy" ) ;
84
- logConfig ( config , "globalconfig" ) ;
85
- logConfig ( config , "userconfig" ) ;
86
- logConfig ( config , "cache" ) ;
87
- logConfig ( config , "cwd" ) ;
75
+ if ( ! config . proxy && ! config . httpsProxy ) {
76
+ // Disable usage of shared keep-alive agents unless a proxy is configured
77
+ // which only works with agents.
88
78
89
- this . _npmConfig = config ;
79
+ // make-fetch-happen uses a hard-coded 15 seconds freeSocketTimeout
80
+ // that can be easily reached (Error: Socket timeout) and there doesn't
81
+ // seem to be another way to disable or increase it.
82
+ // Also see: https://github.com/node-modules/agentkeepalive/issues/106
83
+ config . agent = false ;
90
84
}
91
85
92
- // Use cached config
93
- return this . _npmConfig ;
86
+ log . verbose ( `Using npm configuration (extract):` ) ;
87
+ // Do not log full configuration as it may contain authentication tokens
88
+ logConfig ( config , "registry" ) ;
89
+ logConfig ( config , "@sapui5:registry" ) ;
90
+ logConfig ( config , "@openui5:registry" ) ;
91
+ logConfig ( config , "proxy" ) ;
92
+ logConfig ( config , "httpsProxy" ) ;
93
+ logConfig ( config , "globalconfig" ) ;
94
+ logConfig ( config , "userconfig" ) ;
95
+ logConfig ( config , "cache" ) ;
96
+ logConfig ( config , "cwd" ) ;
97
+
98
+ return config ;
94
99
}
95
100
}
96
101
0 commit comments