Skip to content

Commit

Permalink
refactor(options): pass unprocessed options to Formatter and parse …
Browse files Browse the repository at this point in the history
…in its constructor
  • Loading branch information
jdbruijn committed Mar 25, 2022
1 parent 2d5a629 commit 468dfdd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/bunyan-pretty-stream.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Options, schema } from './options';
import { Transform, TransformCallback } from 'stream';
import { fromString, isBunyanRecord } from './bunyan-record';
import { Formatter } from './formatter';
import { Options } from './options';
import is from '@sindresorhus/is';

class PrettyStream extends Transform {
Expand All @@ -10,7 +10,7 @@ class PrettyStream extends Transform {
constructor(options: Options = {}) {
super({ objectMode: true });

this._formatter = new Formatter(schema.parse(options));
this._formatter = new Formatter(options);
}

_transform(
Expand Down
9 changes: 5 additions & 4 deletions src/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BunyanRecord, coreFields } from './bunyan-record';
import { ParsedOptions } from './options';
import { Options, ParsedOptions, schema } from './options';
import bunyan from 'bunyan';
import chalk from 'chalk';
import is from '@sindresorhus/is';
Expand Down Expand Up @@ -48,9 +48,10 @@ class Formatter {
} as const;
private readonly _levels: Readonly<Record<number, string>>;

constructor(options: ParsedOptions) {
options.basePath = path.normalize(options.basePath);
this._options = options;
constructor(options: Options) {
const parsedOptions = schema.parse(options);
parsedOptions.basePath = path.normalize(parsedOptions.basePath);
this._options = parsedOptions;

this._levels = {
[bunyan.levelFromName.trace]: chalk.gray('TRACE'),
Expand Down

0 comments on commit 468dfdd

Please sign in to comment.