Skip to content

Commit

Permalink
feat(npm/webpack-preprocessor): WIP support webpack 5 alongside webpa…
Browse files Browse the repository at this point in the history
…ck 4 (#16493) (#16504)

* feat: support webpack 5 alongside webpack 5

* revert code
  • Loading branch information
lmiller1990 committed May 13, 2021
1 parent ae33b5c commit c9fb982
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions npm/webpack-preprocessor/index.ts
Expand Up @@ -330,8 +330,6 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F
// when we should watch, we hook into the 'compile' hook so we know when
// to rerun the tests
if (file.shouldWatch) {
debug('watching')

if (compiler.hooks) {
// TODO compile.tap takes "string | Tap"
// so seems we just need to pass plugin.name
Expand All @@ -352,7 +350,9 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F

if (file.shouldWatch) {
// in this case the bundler is webpack.Compiler.Watching
(bundler as webpack.Compiler.Watching).close(cb)
if (bundler && 'close' in bundler) {
bundler.close(cb)
}
}
})

Expand Down Expand Up @@ -380,8 +380,10 @@ preprocessor.__reset = () => {
bundles = {}
}

function cleanseError (err: string) {
return err.replace(/\n\s*at.*/g, '').replace(/From previous event:\n?/g, '')
function cleanseError (err: string | Error) {
let msg = typeof err === 'string' ? err : err.message

return msg.replace(/\n\s*at.*/g, '').replace(/From previous event:\n?/g, '')
}

export = preprocessor

0 comments on commit c9fb982

Please sign in to comment.