mirror of https://github.com/nodejs/corepack.git
fix: do not show download prompt when downloading JSON (#383)
This commit is contained in:
parent
6aab5fc17f
commit
bc137a0073
|
|
@ -4,28 +4,12 @@ import {once} from 'events';
|
||||||
import {stderr, stdin} from 'process';
|
import {stderr, stdin} from 'process';
|
||||||
import {Readable} from 'stream';
|
import {Readable} from 'stream';
|
||||||
|
|
||||||
export async function fetch(input: string | URL, init?: RequestInit) {
|
async function fetch(input: string | URL, init?: RequestInit) {
|
||||||
if (process.env.COREPACK_ENABLE_NETWORK === `0`)
|
if (process.env.COREPACK_ENABLE_NETWORK === `0`)
|
||||||
throw new UsageError(`Network access disabled by the environment; can't reach ${input}`);
|
throw new UsageError(`Network access disabled by the environment; can't reach ${input}`);
|
||||||
|
|
||||||
const agent = await getProxyAgent(input);
|
const agent = await getProxyAgent(input);
|
||||||
|
|
||||||
if (process.env.COREPACK_ENABLE_DOWNLOAD_PROMPT === `1`) {
|
|
||||||
console.error(`Corepack is about to download ${input}.`);
|
|
||||||
if (stdin.isTTY && !process.env.CI) {
|
|
||||||
stderr.write(`\nDo you want to continue? [Y/n] `);
|
|
||||||
stdin.resume();
|
|
||||||
const chars = await once(stdin, `data`);
|
|
||||||
stdin.pause();
|
|
||||||
if (
|
|
||||||
chars[0][0] === 0x6e || // n
|
|
||||||
chars[0][0] === 0x4e // N
|
|
||||||
) {
|
|
||||||
throw new UsageError(`Aborted by the user`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
response = await globalThis.fetch(input, {
|
response = await globalThis.fetch(input, {
|
||||||
|
|
@ -55,6 +39,22 @@ export async function fetchAsJson(input: string | URL, init?: RequestInit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchUrlStream(input: string | URL, init?: RequestInit) {
|
export async function fetchUrlStream(input: string | URL, init?: RequestInit) {
|
||||||
|
if (process.env.COREPACK_ENABLE_DOWNLOAD_PROMPT === `1`) {
|
||||||
|
console.error(`Corepack is about to download ${input}.`);
|
||||||
|
if (stdin.isTTY && !process.env.CI) {
|
||||||
|
stderr.write(`\nDo you want to continue? [Y/n] `);
|
||||||
|
stdin.resume();
|
||||||
|
const chars = await once(stdin, `data`);
|
||||||
|
stdin.pause();
|
||||||
|
if (
|
||||||
|
chars[0][0] === 0x6e || // n
|
||||||
|
chars[0][0] === 0x4e // N
|
||||||
|
) {
|
||||||
|
throw new UsageError(`Aborted by the user`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(input, init);
|
const response = await fetch(input, init);
|
||||||
const webStream = response.body;
|
const webStream = response.body;
|
||||||
assert(webStream, `Expected stream to be set`);
|
assert(webStream, `Expected stream to be set`);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue