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: update imports in errors/cli.ts #325

Merged
merged 1 commit into from
Dec 17, 2021
Merged
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
30 changes: 9 additions & 21 deletions src/errors/errors/cli.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// tslint:disable no-implicit-dependencies

import * as Chalk from 'chalk'
import Clean = require('clean-stack')
import Indent = require('indent-string')
import * as Wrap from 'wrap-ansi'
import * as chalk from 'chalk'
import * as indent from 'indent-string'
import * as cs from 'clean-stack'
import * as wrap from 'wrap-ansi'

import * as screen from '../../screen'
import {config} from '../config'
import {PrettyPrintableError, OclifError} from '../../interfaces/errors'

Expand Down Expand Up @@ -33,8 +32,7 @@ export class CLIError extends Error implements OclifError {
}

get stack(): string {
const clean: typeof Clean = require('clean-stack')
return clean(super.stack!, {pretty: true})
return cs(super.stack!, {pretty: true})
}

/**
Expand All @@ -46,25 +44,18 @@ export class CLIError extends Error implements OclifError {
return this.stack
}

const wrap: typeof Wrap = require('wrap-ansi')
const indent: typeof Indent = require('indent-string')

let output = `${this.name}: ${this.message}`
// eslint-disable-next-line node/no-missing-require
output = wrap(output, require('../screen').errtermwidth - 6, {trim: false, hard: true} as any)
output = wrap(output, screen.errtermwidth - 6, {trim: false, hard: true} as any)
output = indent(output, 3)
output = indent(output, 1, {indent: this.bang, includeEmptyLines: true} as any)
output = indent(output, 1)
return output
}

get bang() {
let red: typeof Chalk.red = ((s: string) => s) as any
try {
red = require('chalk').red
return chalk.red(process.platform === 'win32' ? '»' : '›')
} catch {}

return red(process.platform === 'win32' ? '»' : '›')
}
}

Expand All @@ -76,12 +67,9 @@ export namespace CLIError {
}

get bang() {
let yellow: typeof Chalk.yellow = ((s: string) => s) as any
try {
yellow = require('chalk').yellow
return chalk.yellow(process.platform === 'win32' ? '»' : '›')
} catch {}

return yellow(process.platform === 'win32' ? '»' : '›')
}
}
}