Skip to content

Commit bc137a0

Browse files
authored
fix: do not show download prompt when downloading JSON (#383)
1 parent 6aab5fc commit bc137a0

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

sources/httpUtils.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,12 @@ import {once} from 'events';
44
import {stderr, stdin} from 'process';
55
import {Readable} from 'stream';
66

7-
export async function fetch(input: string | URL, init?: RequestInit) {
7+
async function fetch(input: string | URL, init?: RequestInit) {
88
if (process.env.COREPACK_ENABLE_NETWORK === `0`)
99
throw new UsageError(`Network access disabled by the environment; can't reach ${input}`);
1010

1111
const agent = await getProxyAgent(input);
1212

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-
2913
let response;
3014
try {
3115
response = await globalThis.fetch(input, {
@@ -55,6 +39,22 @@ export async function fetchAsJson(input: string | URL, init?: RequestInit) {
5539
}
5640

5741
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+
5858
const response = await fetch(input, init);
5959
const webStream = response.body;
6060
assert(webStream, `Expected stream to be set`);

0 commit comments

Comments
 (0)