Skip to content

Commit

Permalink
Style tweak for simple returns, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jul 16, 2024
1 parent 8578263 commit d4f895b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
14 changes: 5 additions & 9 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ async function mainWorker(d: D) {

const herebyfilePath = path.resolve(d.cwd(), args.herebyfile ?? findHerebyfile(d.cwd()));

if (await reexec(herebyfilePath)) {
return;
}
if (await reexec(herebyfilePath)) return;

if (args.version) {
d.log(`hereby ${d.version()}`);
Expand Down Expand Up @@ -85,12 +83,10 @@ export async function selectTasks(
taskNames: string[],
): Promise<Task[]> {
if (taskNames.length === 0) {
if (!herebyfile.defaultTask) {
throw new UserError(
`No default task has been exported from ${d.simplifyPath(herebyfilePath)}; please specify a task name.`,
);
}
return [herebyfile.defaultTask];
if (herebyfile.defaultTask) return [herebyfile.defaultTask];
throw new UserError(
`No default task has been exported from ${d.simplifyPath(herebyfilePath)}; please specify a task name.`,
);
}

const tasks: Task[] = [];
Expand Down
20 changes: 9 additions & 11 deletions src/cli/loadHerebyfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export async function loadHerebyfile(herebyfilePath: string): Promise<Herebyfile
let defaultTask: Task | undefined;

for (const [key, value] of Object.entries(herebyfile)) {
if (value instanceof Task) {
if (key === "default") {
defaultTask = value;
} else if (exportedTasks.has(value)) {
throw new UserError(`Task "${pc.blue(value.options.name)}" has been exported twice.`);
} else {
exportedTasks.add(value);
}
if (!(value instanceof Task)) continue;

if (key === "default") {
defaultTask = value;
} else if (exportedTasks.has(value)) {
throw new UserError(`Task "${pc.blue(value.options.name)}" has been exported twice.`);
} else {
exportedTasks.add(value);
}
}

Expand Down Expand Up @@ -87,9 +87,7 @@ function checkTaskInvariants(tasks: Iterable<Task>) {

function checkTaskInvariantsWorker(tasks: Iterable<Task>) {
for (const task of tasks) {
if (checkedTasks.has(task)) {
continue;
}
if (checkedTasks.has(task)) continue;

if (taskStack.has(task)) {
throw new UserError(`Task "${pc.blue(task.options.name)}" references itself.`);
Expand Down
20 changes: 5 additions & 15 deletions src/cli/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export class Runner {
const results = await Promise.allSettled(
tasks.map((task) => {
const cached = this._addedTasks.get(task);
if (cached) {
return cached;
}
if (cached) return cached;

const promise = this._runTask(task);
this._addedTasks.set(task, promise);
Expand All @@ -45,9 +43,7 @@ export class Runner {
await this.runTasks(...dependencies);
}

if (!run) {
return;
}
if (!run) return;

try {
this.onTaskStart(task);
Expand All @@ -62,26 +58,20 @@ export class Runner {
protected onTaskStart(task: Task): void {
this._startTimes.set(task, performance.now());

if (this._errored) {
return; // Skip logging.
}
if (this._errored) return; // Skip logging.

this._d.log(`Starting ${pc.blue(task.options.name)}`);
}

protected onTaskFinish(task: Task): void {
if (this._errored) {
return; // Skip logging.
}
if (this._errored) return; // Skip logging.

const took = performance.now() - this._startTimes.get(task)!;
this._d.log(`Finished ${pc.green(task.options.name)} in ${this._d.prettyMilliseconds(took)}`);
}

protected onTaskError(task: Task, e: unknown): void {
if (this._errored) {
return; // Skip logging.
}
if (this._errored) return; // Skip logging.

this._errored = true;
const took = performance.now() - this._startTimes.get(task)!;
Expand Down

0 comments on commit d4f895b

Please sign in to comment.