Skip to content

Commit

Permalink
fix: group the download prompt together (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored Feb 21, 2024
1 parent 476b7dc commit 00506b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions sources/httpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ export async function fetchAsJson(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}.`);
console.error(`Corepack is about to download ${input}`);
if (stdin.isTTY && !process.env.CI) {
stderr.write(`\nDo you want to continue? [Y/n] `);
stderr.write(`Do 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
) {

// n / N
if (chars[0][0] === 0x6e || chars[0][0] === 0x4e)
throw new UsageError(`Aborted by the user`);
}

// Add a newline to separate Corepack output from the package manager
console.error();
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ it(`should show a warning on stderr before downloading when enable`, async() =>
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
exitCode: 0,
stdout: `3.0.0\n`,
stderr: `Corepack is about to download https://repo.yarnpkg.com/3.0.0/packages/yarnpkg-cli/bin/yarn.js.\n`,
stderr: `Corepack is about to download https://repo.yarnpkg.com/3.0.0/packages/yarnpkg-cli/bin/yarn.js\n`,
});
});
});
Expand Down

0 comments on commit 00506b2

Please sign in to comment.