1
- import { UsageError } from 'clipanion' ;
2
- import { RequestOptions } from 'https' ;
3
- import { IncomingMessage , ClientRequest } from 'http' ;
1
+ import { UsageError } from 'clipanion' ;
2
+ import { once } from 'events' ;
3
+ import type { RequestOptions } from 'https' ;
4
+ import type { IncomingMessage , ClientRequest } from 'http' ;
5
+ import { stderr , stdin } from 'process' ;
4
6
5
7
export async function fetchUrlStream ( url : string , options : RequestOptions = { } ) {
6
8
if ( process . env . COREPACK_ENABLE_NETWORK === `0` )
@@ -12,6 +14,22 @@ export async function fetchUrlStream(url: string, options: RequestOptions = {})
12
14
13
15
const proxyAgent = new ProxyAgent ( ) ;
14
16
17
+ if ( process . env . COREPACK_ENABLE_DOWNLOAD_PROMPT === `1` ) {
18
+ console . error ( `Corepack is about to download ${ url } .` ) ;
19
+ if ( stdin . isTTY && ! process . env . CI ) {
20
+ stderr . write ( `\nDo you want to continue? [Y/n] ` ) ;
21
+ stdin . resume ( ) ;
22
+ const chars = await once ( stdin , `data` ) ;
23
+ stdin . pause ( ) ;
24
+ if (
25
+ chars [ 0 ] [ 0 ] === 0x6e || // n
26
+ chars [ 0 ] [ 0 ] === 0x4e // N
27
+ ) {
28
+ throw new UsageError ( `Aborted by the user` ) ;
29
+ }
30
+ }
31
+ }
32
+
15
33
return new Promise < IncomingMessage > ( ( resolve , reject ) => {
16
34
const createRequest = ( url : string ) => {
17
35
const request : ClientRequest = https . get ( url , { ...options , agent : proxyAgent } , response => {
0 commit comments