Skip to content

Commit

Permalink
Typing: use WebpackError type definition from webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Oct 11, 2020
1 parent a66eb15 commit c6d0528
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/webpack/compiler/registerReadyCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { MOCHAPACK_NAME } from '../../util/constants'

export default function registerReadyCallback(
compiler: Compiler,
cb: (err: (Error | string) | null, stats: Stats | null) => void
cb: (err: Error, stats: Stats | null) => void
) {
compiler.hooks.failed.tap(MOCHAPACK_NAME, cb)
compiler.hooks.failed.tap(MOCHAPACK_NAME, (err: Error) => {
cb(err, null)
});
compiler.hooks.done.tap(MOCHAPACK_NAME, (stats: Stats) => {
if (stats.hasErrors()) {
const jsonStats = stats.toJson()
Expand Down
11 changes: 2 additions & 9 deletions src/webpack/util/createStatsFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { EOL } from 'os'
import chalk from 'chalk'
import { Stats } from 'webpack'
import RequestShortener from 'webpack/lib/RequestShortener'
import WebpackError from 'webpack/lib/WebpackError'
import { formatErrorMessage, stripLoaderFromPath } from './formatUtil'
import { WebpackError } from '../types'

const createGetFile = (requestShortener: RequestShortener) => (
e: WebpackError
Expand All @@ -29,14 +29,7 @@ const createGetFile = (requestShortener: RequestShortener) => (
const ensureWebpackErrors = (
errors: Array<string | WebpackError>
): Array<WebpackError> =>
errors.map((e: string | WebpackError) => {
/* istanbul ignore if */
if (typeof e === 'string') {
// webpack does this also, so there must be case when this happens
return ({ message: e } as any) as WebpackError
}
return e
})
errors.map((e: WebpackError) => e.toString())

const prependWarning = (message: string) =>
`${chalk.yellow('Warning')} ${message}`
Expand Down

0 comments on commit c6d0528

Please sign in to comment.