| 740 | const { createInterface } = await import("node:readline"); |
| 741 | |
| 742 | const prompt = ({ |
| 743 | message, |
| 744 | defaultResponse, |
| 745 | stream, |
| 746 | }: { |
| 747 | message: string; |
| 748 | defaultResponse: string; |
| 749 | stream: NodeJS.WritableStream; |
| 750 | }) => { |
| 751 | const rl = createInterface({ |
| 752 | input: process.stdin, |
| 753 | output: stream, |
| 754 | }); |
| 755 | |
| 756 | return new Promise((resolve) => { |
| 757 | rl.question(`${message} `, (answer: string) => { |
| 758 | // Close the stream |
| 759 | rl.close(); |
| 760 | |
| 761 | const response = (answer || defaultResponse).toLowerCase(); |
| 762 | |
| 763 | // Resolve with the input response |
| 764 | if (response === "y" || response === "yes") { |
| 765 | resolve(true); |
| 766 | } else { |
| 767 | resolve(false); |
| 768 | } |
| 769 | }); |
| 770 | }); |
| 771 | }; |
| 772 | |
| 773 | // yarn uses 'add' command, rest npm and pnpm both use 'install' |
| 774 | const commandArguments = [packageManager === "yarn" ? "add" : "install", "-D", packageName]; |