diff --git a/src/pkg_manager.ts b/src/pkg_manager.ts index 7580ebf..df0d87c 100644 --- a/src/pkg_manager.ts +++ b/src/pkg_manager.ts @@ -29,7 +29,8 @@ function toPackageArgs(pkgs: JsrPackage[]): string[] { async function isYarnBerry(cwd: string) { // this command works for both yarn classic and berry - const version = await exec("yarn", ["--version"], cwd, undefined, true); + const output = await exec("yarn", ["--version"], cwd, undefined, true); + const version = output.stdout; if (!version) { logDebug("Unable to detect yarn version, assuming classic"); return false; diff --git a/src/utils.ts b/src/utils.ts index 8c52283..a83fcb0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -205,13 +205,19 @@ export class ExecError extends Error { } } +export interface ExecOutput { + combined: string; + stdout: string; + stderr: string; +} + export async function exec( cmd: string, args: string[], cwd: string, env?: Record, captureOutput?: boolean, -) { +): Promise { const cp = spawn( cmd, args.map((arg) => process.platform === "win32" ? `"${arg}"` : `'${arg}'`), @@ -223,20 +229,24 @@ export async function exec( }, ); - let output = ""; + let combined = ""; + let stdout = ""; + let stderr = ""; if (captureOutput) { cp.stdout?.on("data", (data) => { - output += data; + combined += data; + stdout += data; }); cp.stderr?.on("data", (data) => { - output += data; + combined += data; + stderr += data; }); } - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { cp.on("exit", (code) => { - if (code === 0) resolve(output); + if (code === 0) resolve({ combined, stdout, stderr }); else reject(new ExecError(code ?? 1)); }); }); diff --git a/test/commands.test.ts b/test/commands.test.ts index 6c58702..dacdea4 100644 --- a/test/commands.test.ts +++ b/test/commands.test.ts @@ -196,7 +196,7 @@ describe("install", () => { assert.match( pkgJson.dependencies["@std/encoding"], - /^npm:@jsr\/std__encoding@\^\d+\.\d+\.\d+.*$/, + /^npm:@jsr\/std__encoding@\d+\.\d+\.\d+.*$/, ); const npmRc = await readTextFile(path.join(dir, ".npmrc")); @@ -770,7 +770,7 @@ describe("show", () => { undefined, true, ); - const txt = kl.stripColors(output); + const txt = kl.stripColors(output.combined); assert.ok(txt.includes("latest:")); assert.ok(txt.includes("npm tarball:")); }); @@ -796,7 +796,7 @@ describe("show", () => { undefined, true, ); - const txt = kl.stripColors(output); + const txt = kl.stripColors(output.combined); assert.ok(txt.includes("latest: -")); assert.ok(txt.includes("npm tarball:")); });