Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #113 #115

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { parse as parseArgs } from "https://deno.land/std@0.166.0/flags/mod.ts";
export { parseArgs } from "https://deno.land/std@0.207.0/cli/mod.ts";
export { expandGlob } from "https://deno.land/[email protected]/fs/mod.ts";
export * as colors from "https://deno.land/[email protected]/fmt/colors.ts";
export type { Writer } from "https://deno.land/[email protected]/io/types.ts";
28 changes: 10 additions & 18 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ function testsThunk(tests: string[]): () => Promise<void> {
for (const t of tests) {
// FIXME is there a better way to split / pass arrays?
// This fails if you wanted to pass e.g. --foo="a b"
const p = Deno.run({
cmd: t.split(" "),
stdout: "piped",
const c = new Deno.Command(Deno.execPath(), {
args: t.split(" "),
stderr: "piped",
});
const success = (await p.status()).success;
const { success, stderr } = await c.output();
if (!success) {
console.log();
await Deno.stdout.write(await p.stderrOutput());
await Deno.stdout.write(stderr);
}
// This close handling cleans up resouces but is not required...
p.close();
p.stdout!.close();
p.stderr!.close();
if (!success) {
throw new Error(t);
}
Expand Down Expand Up @@ -58,20 +53,17 @@ function version() {

// https://github.com/jurassiscripts/velociraptor/blob/971b7db71cf635b0c8f2de822aa4270e52cce498/src/util.ts#L22-L39
async function spawn(args: string[], cwd?: string): Promise<string> {
const process = Deno.run({
cmd: args,
const command = new Deno.Command(Deno.execPath(), {
args: args,
cwd,
stdout: "piped",
stderr: "piped",
});
const { code } = await process.status();
const { code, stdout, stderr } = await command.output();
if (code === 0) {
const rawOutput = await process.output();
process.close();
return new TextDecoder().decode(rawOutput);
return new TextDecoder().decode(stdout);
} else {
const error = new TextDecoder().decode(await process.stderrOutput());
process.close();
const error = new TextDecoder().decode(stderr);
throw new Error(error);
}
}
Expand All @@ -83,7 +75,7 @@ async function upgrade() {
console.log(url);

// TODO support alternative name to udd if that's what's been used before.
await spawn([Deno.execPath(), "install", "--reload", "-qAfn", "udd", url]);
await spawn(["install", "--reload", "-qAfn", "udd", url]);
}

async function main(args: string[]) {
Expand Down
8 changes: 5 additions & 3 deletions progress.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Writer } from "./deps.ts";

const { noColor } = Deno;

const START = noColor ? "" : "\x1b[999D\x1b[K";
Expand All @@ -8,9 +10,9 @@ const encoder = new TextEncoder();
export class Progress {
n: number;
step = -1;
writer: Deno.Writer;
writer: Writer;

constructor(n: number, writer: Deno.Writer = Deno.stdout) {
constructor(n: number, writer: Writer = Deno.stdout) {
this.n = n;
this.writer = writer;
}
Expand All @@ -23,5 +25,5 @@ export class Progress {
}

export class SilentProgress extends Progress {
async log(_: string) {}
override async log(_: string) {}
}
5 changes: 2 additions & 3 deletions test_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export {
assert,
assertEquals,
assertThrows,
assertThrowsAsync,
} from "https://deno.land/[email protected]/testing/asserts.ts";
} from "https://deno.land/[email protected]/assert/mod.ts";

export class FakeRegistry implements RegistryUrl {
url: string;
Expand Down Expand Up @@ -34,7 +33,7 @@ export class FakeRegistry implements RegistryUrl {

export class FakeDenoLand extends DenoLand {
// deno-lint-ignore require-await
async all(): Promise<string[]> {
override async all(): Promise<string[]> {
return ["0.35.0", "0.34.0"];
}
}