@@ -93,12 +93,18 @@ function downloadFile(url, destPath, expectedSha384) {
9393
9494 function downloadAndVerify ( ) {
9595 console . log ( `Downloading offline dependency: ${ path . basename ( destPath ) } ...` ) ;
96- https . get ( url , ( res ) => {
96+ const req = https . get ( url , ( res ) => {
9797 if ( res . statusCode !== 200 ) {
98+ res . resume ( ) ; // Drain response to free up the socket
9899 reject ( new Error ( `Failed to load ${ url } (${ res . statusCode } )` ) ) ;
99100 return ;
100101 }
101102 const stream = fs . createWriteStream ( destPath ) ;
103+
104+ // Handle stream and response errors
105+ stream . on ( "error" , reject ) ;
106+ res . on ( "error" , reject ) ;
107+
102108 res . pipe ( stream ) ;
103109 stream . on ( "finish" , ( ) => {
104110 stream . close ( ) ;
@@ -114,7 +120,8 @@ function downloadFile(url, destPath, expectedSha384) {
114120 reject ( err ) ;
115121 } ) ;
116122 } ) ;
117- } ) . on ( "error" , reject ) ;
123+ } ) ;
124+ req . on ( "error" , reject ) ;
118125 }
119126 } ) ;
120127}
@@ -143,6 +150,7 @@ async function prepareOfflineDependencies() {
143150
144151 if ( ! expectedSha384 ) {
145152 console . warn ( `⚠ Warning: CDN dependency is missing an integrity hash: ${ url } ` ) ;
153+ throw new Error ( `CDN dependency is missing an integrity hash: ${ url } ` ) ;
146154 }
147155
148156 // Determine local filename - sanitize package version tags or query strings
0 commit comments