From 91e5711bf5952ff1b472fb2d3507f6d767f51921 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Fri, 14 May 2021 01:58:45 +1000 Subject: [PATCH] feat(npm/webpack-preprocessor): WIP support webpack 5 alongside webpack 4 (#16493) * feat: support webpack 5 alongside webpack 5 * revert code --- npm/webpack-preprocessor/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/npm/webpack-preprocessor/index.ts b/npm/webpack-preprocessor/index.ts index ccf236584ab9..11c30660e832 100644 --- a/npm/webpack-preprocessor/index.ts +++ b/npm/webpack-preprocessor/index.ts @@ -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 @@ -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) + } } }) @@ -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