( pkgManager: PackageManager, projectDir: string )
| 105 | } |
| 106 | |
| 107 | async function runInstallCommand( |
| 108 | pkgManager: PackageManager, |
| 109 | projectDir: string |
| 110 | ): Promise<Ora | null> { |
| 111 | switch (pkgManager) { |
| 112 | // When using npm, inherit the stderr stream so that the progress bar is shown |
| 113 | case "npm": |
| 114 | await execa(pkgManager, ["install"], { |
| 115 | cwd: projectDir, |
| 116 | stderr: "inherit", |
| 117 | }); |
| 118 | |
| 119 | return null; |
| 120 | // When using yarn or pnpm, use the stdout stream and ora spinner to show the progress |
| 121 | case "pnpm": |
| 122 | const pnpmSpinner = ora("Running pnpm install...").start(); |
| 123 | const pnpmSubprocess = execa(pkgManager, ["install"], { |
| 124 | cwd: projectDir, |
| 125 | stdout: "pipe", |
| 126 | }); |
| 127 | |
| 128 | await new Promise<void>((res, rej) => { |
| 129 | pnpmSubprocess.stdout?.on("data", (data: Buffer) => { |
| 130 | const text = data.toString(); |
| 131 | |
| 132 | if (text.includes("Progress")) { |
| 133 | pnpmSpinner.text = text.includes("|") ? text.split(" | ")[1] ?? "" : text; |
| 134 | } |
| 135 | }); |
| 136 | pnpmSubprocess.on("error", (e) => rej(e)); |
| 137 | pnpmSubprocess.on("close", () => res()); |
| 138 | }); |
| 139 | |
| 140 | return pnpmSpinner; |
| 141 | case "yarn": |
| 142 | const yarnSpinner = ora("Running yarn...").start(); |
| 143 | const yarnSubprocess = execa(pkgManager, [], { |
| 144 | cwd: projectDir, |
| 145 | stdout: "pipe", |
| 146 | }); |
| 147 | |
| 148 | await new Promise<void>((res, rej) => { |
| 149 | yarnSubprocess.stdout?.on("data", (data: Buffer) => { |
| 150 | yarnSpinner.text = data.toString(); |
| 151 | }); |
| 152 | yarnSubprocess.on("error", (e) => rej(e)); |
| 153 | yarnSubprocess.on("close", () => res()); |
| 154 | }); |
| 155 | |
| 156 | return yarnSpinner; |
| 157 | } |
| 158 | } |
no test coverage detected
searching dependent graphs…