@@ -4,28 +4,12 @@ import {once} from 'events';
4
4
import { stderr , stdin } from 'process' ;
5
5
import { Readable } from 'stream' ;
6
6
7
- export async function fetch ( input : string | URL , init ?: RequestInit ) {
7
+ async function fetch ( input : string | URL , init ?: RequestInit ) {
8
8
if ( process . env . COREPACK_ENABLE_NETWORK === `0` )
9
9
throw new UsageError ( `Network access disabled by the environment; can't reach ${ input } ` ) ;
10
10
11
11
const agent = await getProxyAgent ( input ) ;
12
12
13
- if ( process . env . COREPACK_ENABLE_DOWNLOAD_PROMPT === `1` ) {
14
- console . error ( `Corepack is about to download ${ input } .` ) ;
15
- if ( stdin . isTTY && ! process . env . CI ) {
16
- stderr . write ( `\nDo you want to continue? [Y/n] ` ) ;
17
- stdin . resume ( ) ;
18
- const chars = await once ( stdin , `data` ) ;
19
- stdin . pause ( ) ;
20
- if (
21
- chars [ 0 ] [ 0 ] === 0x6e || // n
22
- chars [ 0 ] [ 0 ] === 0x4e // N
23
- ) {
24
- throw new UsageError ( `Aborted by the user` ) ;
25
- }
26
- }
27
- }
28
-
29
13
let response ;
30
14
try {
31
15
response = await globalThis . fetch ( input , {
@@ -55,6 +39,22 @@ export async function fetchAsJson(input: string | URL, init?: RequestInit) {
55
39
}
56
40
57
41
export async function fetchUrlStream ( input : string | URL , init ?: RequestInit ) {
42
+ if ( process . env . COREPACK_ENABLE_DOWNLOAD_PROMPT === `1` ) {
43
+ console . error ( `Corepack is about to download ${ input } .` ) ;
44
+ if ( stdin . isTTY && ! process . env . CI ) {
45
+ stderr . write ( `\nDo you want to continue? [Y/n] ` ) ;
46
+ stdin . resume ( ) ;
47
+ const chars = await once ( stdin , `data` ) ;
48
+ stdin . pause ( ) ;
49
+ if (
50
+ chars [ 0 ] [ 0 ] === 0x6e || // n
51
+ chars [ 0 ] [ 0 ] === 0x4e // N
52
+ ) {
53
+ throw new UsageError ( `Aborted by the user` ) ;
54
+ }
55
+ }
56
+ }
57
+
58
58
const response = await fetch ( input , init ) ;
59
59
const webStream = response . body ;
60
60
assert ( webStream , `Expected stream to be set` ) ;
0 commit comments