Skip to content

Commit

Permalink
fix: work with empty data
Browse files Browse the repository at this point in the history
  • Loading branch information
rushelex committed Feb 19, 2024
1 parent f6dcc98 commit 694f764
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"type": "module",
"scripts": {
"prepare": "simple-git-hooks",
"start": "nodemon",
"build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-esbuild",
"build:watch": "npm run build -- --watch",
"lint": "NODE_ENV=production eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
Expand Down
6 changes: 5 additions & 1 deletion src/utils/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import { isObject, isString } from 'lodash-es';
import { isNil, isObject, isString } from 'lodash-es';

import { type CircularDependenciesData } from '../types';

Expand All @@ -24,6 +24,10 @@ function PrettyFormatter(config?: PrettyFormatterConfig): Formatter {
const { colors = true } = config || {};

return (data): string => {
if (!isNil(data) && isObject(data) && Object.keys(data).length === 0) {
return '';
}

if (!isValidData(data)) {
throw new Error('Pretty formatter can only be used with original output');
}
Expand Down
11 changes: 6 additions & 5 deletions src/utils/printers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ class FilePrinter extends Printer {
}

class ConsolePrinter extends Printer {
public shouldPrint(): boolean {
return !this.ctx.options.outputFilePath;
public shouldPrint(data: FormattedData): boolean {
const isConsolePrinter = !this.ctx.options.outputFilePath;
const isDataExists = data || data === 0 || (typeof data === 'string' && data.length > 0);

return isConsolePrinter && isDataExists;
}

public print(data: FormattedData): void {
if (data || data === '' || data === 0) {
console.info('\n\n' + data?.toString() + '\n');
}
console.info('\n\n' + data?.toString() + '\n');
}
}

Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.base.json",
"include": ["src"],
}

0 comments on commit 694f764

Please sign in to comment.