@@ -20,6 +20,7 @@ type FailedAttemptErrors = pRetry.FailedAttemptError | FetchError | Error;
2020// not sure what to call this function, but we're not exporting it
2121async function registryFetch ( url : string ) {
2222 const response = await fetch ( url , getFetchOptions ( url ) ) ;
23+
2324 if ( response . ok ) {
2425 return response ;
2526 } else {
@@ -34,7 +35,14 @@ async function registryFetch(url: string) {
3435 }
3536}
3637
37- export async function getResponse ( url : string , retries : number = 5 ) : Promise < Response > {
38+ export async function getResponse ( url : string , retries : number = 5 ) : Promise < Response | null > {
39+ const logger = appContextService . getLogger ( ) ;
40+
41+ if ( appContextService . getConfig ( ) ?. isAirGapped ) {
42+ logger . debug ( 'isAirGapped enabled, not reaching package registry' ) ;
43+ return null ;
44+ }
45+
3846 try {
3947 // we only want to retry certain failures like network issues
4048 // the rest should only try the one time then fail as they do now
@@ -70,13 +78,22 @@ export async function getResponse(url: string, retries: number = 5): Promise<Res
7078export async function getResponseStream (
7179 url : string ,
7280 retries ?: number
73- ) : Promise < NodeJS . ReadableStream > {
81+ ) : Promise < NodeJS . ReadableStream | null > {
7482 const res = await getResponse ( url , retries ) ;
75- return res . body ;
83+ if ( res ) {
84+ return res . body ;
85+ }
86+ return null ;
7687}
7788
78- export async function fetchUrl ( url : string , retries ?: number ) : Promise < string > {
79- return getResponseStream ( url , retries ) . then ( streamToString ) ;
89+ export async function fetchUrl ( url : string , retries ?: number ) : Promise < string | null > {
90+ const stream = getResponseStream ( url , retries ) ;
91+
92+ if ( appContextService . getConfig ( ) ?. isAirGapped || stream === null ) {
93+ return null ;
94+ }
95+
96+ return stream . then ( streamToString ) ;
8097}
8198
8299// node-fetch throws a FetchError for those types of errors and
0 commit comments