Skip to content

Commit 5212ce7

Browse files
chore: fix failing tests (#96)
1 parent b507e9c commit 5212ce7

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/pkg_manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ function toPackageArgs(pkgs: JsrPackage[]): string[] {
2929

3030
async function isYarnBerry(cwd: string) {
3131
// this command works for both yarn classic and berry
32-
const version = await exec("yarn", ["--version"], cwd, undefined, true);
32+
const output = await exec("yarn", ["--version"], cwd, undefined, true);
33+
const version = output.stdout;
3334
if (!version) {
3435
logDebug("Unable to detect yarn version, assuming classic");
3536
return false;

src/utils.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,19 @@ export class ExecError extends Error {
205205
}
206206
}
207207

208+
export interface ExecOutput {
209+
combined: string;
210+
stdout: string;
211+
stderr: string;
212+
}
213+
208214
export async function exec(
209215
cmd: string,
210216
args: string[],
211217
cwd: string,
212218
env?: Record<string, string | undefined>,
213219
captureOutput?: boolean,
214-
) {
220+
): Promise<ExecOutput> {
215221
const cp = spawn(
216222
cmd,
217223
args.map((arg) => process.platform === "win32" ? `"${arg}"` : `'${arg}'`),
@@ -223,20 +229,24 @@ export async function exec(
223229
},
224230
);
225231

226-
let output = "";
232+
let combined = "";
233+
let stdout = "";
234+
let stderr = "";
227235

228236
if (captureOutput) {
229237
cp.stdout?.on("data", (data) => {
230-
output += data;
238+
combined += data;
239+
stdout += data;
231240
});
232241
cp.stderr?.on("data", (data) => {
233-
output += data;
242+
combined += data;
243+
stderr += data;
234244
});
235245
}
236246

237-
return new Promise<string>((resolve, reject) => {
247+
return new Promise<ExecOutput>((resolve, reject) => {
238248
cp.on("exit", (code) => {
239-
if (code === 0) resolve(output);
249+
if (code === 0) resolve({ combined, stdout, stderr });
240250
else reject(new ExecError(code ?? 1));
241251
});
242252
});

test/commands.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe("install", () => {
196196

197197
assert.match(
198198
pkgJson.dependencies["@std/encoding"],
199-
/^npm:@jsr\/std__encoding@\^\d+\.\d+\.\d+.*$/,
199+
/^npm:@jsr\/std__encoding@\d+\.\d+\.\d+.*$/,
200200
);
201201

202202
const npmRc = await readTextFile(path.join(dir, ".npmrc"));
@@ -770,7 +770,7 @@ describe("show", () => {
770770
undefined,
771771
true,
772772
);
773-
const txt = kl.stripColors(output);
773+
const txt = kl.stripColors(output.combined);
774774
assert.ok(txt.includes("latest:"));
775775
assert.ok(txt.includes("npm tarball:"));
776776
});
@@ -796,7 +796,7 @@ describe("show", () => {
796796
undefined,
797797
true,
798798
);
799-
const txt = kl.stripColors(output);
799+
const txt = kl.stripColors(output.combined);
800800
assert.ok(txt.includes("latest: -"));
801801
assert.ok(txt.includes("npm tarball:"));
802802
});

0 commit comments

Comments
 (0)