Skip to content

Commit

Permalink
refactor: remove global async option
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 10, 2023
1 parent cabd04f commit edd1bb9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
21 changes: 2 additions & 19 deletions src/consola.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class Consola {

_logFn(defaults: ConsolaLogObject, args: any[], isRaw?: boolean) {
if (((defaults.level as number) || 0) > this.level) {
return this.options.async ? Promise.resolve(false) : false;
return false;
}

// Construct a new log object
Expand Down Expand Up @@ -304,11 +304,7 @@ export class Consola {
// Log
if (newLog) {
this._lastLog.object = logObj as ConsolaReporterLogObject;
if (this.options.async) {
return this._logAsync(logObj as ConsolaReporterLogObject);
} else {
this._log(logObj as ConsolaReporterLogObject);
}
this._log(logObj as ConsolaReporterLogObject);
}
};

Expand Down Expand Up @@ -350,24 +346,11 @@ export class Consola {
_log(logObj: ConsolaReporterLogObject) {
for (const reporter of this.options.reporters) {
reporter.log(logObj, {
async: false,
stdout: this.stdout,
stderr: this.stderr,
});
}
}

_logAsync(logObj: ConsolaReporterLogObject) {
return Promise.all(
this.options.reporters.map((reporter) =>
reporter.log(logObj, {
async: true,
stdout: this.stdout,
stderr: this.stderr,
})
)
);
}
}

export interface ConsolaInstance extends Consola {
Expand Down
8 changes: 2 additions & 6 deletions src/reporters/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ export default class BasicReporter {
]);
}

log(logObj: ConsolaReporterLogObject, { async, stdout, stderr }: any = {}) {
log(logObj: ConsolaReporterLogObject, { stdout, stderr }: any = {}) {
const line = this.formatLogObj(logObj, {
width: stdout.columns || 0,
});

return writeStream(
line + "\n",
logObj.level < 2 ? stderr : stdout,
async ? "async" : "default"
);
return writeStream(line + "\n", logObj.level < 2 ? stderr : stdout);
}
}
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export type ConsolaMockFn = (
) => ConsolaMock;

export interface ConsolaReporterArgs {
async: boolean;
stdout: NodeJS.WritableStream;
stderr: NodeJS.WritableStream;
}
Expand All @@ -70,7 +69,6 @@ export interface ConsolaOptions {
defaults: ConsolaLogObject;
throttle: number;
throttleMin: number;
async?: boolean;
stdout?: NodeJS.WritableStream;
stderr?: NodeJS.WritableStream;
mockFn?: ConsolaMockFn;
Expand Down

0 comments on commit edd1bb9

Please sign in to comment.