@@ -197,12 +197,29 @@ function findPackageJson(nodeFile: string) {
197
197
return dir ;
198
198
}
199
199
200
+ function getPrebuildEnvPrefix ( pkgName : string ) : string {
201
+ return `npm_config_${ ( pkgName || '' ) . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '_' ) . replace ( / ^ _ / , '' ) } `
202
+ }
203
+
200
204
function nativePrebuildInstall ( target : Target , nodeFile : string ) {
201
205
const prebuildInstall = path . join (
202
206
__dirname ,
203
207
'../node_modules/.bin/prebuild-install' ,
204
208
) ;
205
209
const dir = findPackageJson ( nodeFile ) ;
210
+ const packageJson = JSON . parse (
211
+ fs . readFileSync ( path . join ( dir , 'package.json' ) , { encoding : 'utf-8' } ) ) ;
212
+
213
+ // only try prebuild-install for packages that actually use it or if
214
+ // explicitly configured via environment variables
215
+ const envPrefix = getPrebuildEnvPrefix ( packageJson . name ) ;
216
+ if ( packageJson . dependencies ?. [ 'prebuild-install' ] == null &&
217
+ ! ( [ `${ envPrefix } _binary_host` ,
218
+ `${ envPrefix } _binary_host_mirror` ,
219
+ `${ envPrefix } _local_prebuilds` ] . some ( ( i ) => i in process . env ) ) ) {
220
+ return ;
221
+ }
222
+
206
223
// parse the target node version from the binaryPath
207
224
const nodeVersion = path . basename ( target . binaryPath ) . split ( '-' ) [ 1 ] ;
208
225
@@ -221,9 +238,7 @@ function nativePrebuildInstall(target: Target, nodeFile: string) {
221
238
fs . copyFileSync ( nodeFile , `${ nodeFile } .bak` ) ;
222
239
}
223
240
224
- const napiVersions = JSON . parse (
225
- fs . readFileSync ( path . join ( dir , 'package.json' ) , { encoding : 'utf-8' } ) ,
226
- ) ?. binary ?. napi_versions ;
241
+ const napiVersions = packageJson ?. binary ?. napi_versions ;
227
242
228
243
const options = [
229
244
'--platform' ,
0 commit comments