Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

feat: log error on fail hook #111

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/friendly-errors-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,19 @@ class FriendlyErrorsWebpackPlugin {
output.title('info', 'WAIT', 'Compiling...');
};

const failedFn = (error) => {
this.clearConsole();
this.displayErrors([error], 'error');
}

if (compiler.hooks) {
const plugin = { name: 'FriendlyErrorsWebpackPlugin' };

compiler.hooks.done.tap(plugin, doneFn);
compiler.hooks.invalid.tap(plugin, invalidFn);
if (compiler.hooks.failed) {
compiler.hooks.failed.tap(plugin, failedFn)
}
} else {
compiler.plugin('done', doneFn);
compiler.plugin('invalid', invalidFn);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "I am an entry point";
19 changes: 19 additions & 0 deletions test/fixtures/error/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const FriendlyErrorsWebpackPlugin = require("../../../index");

class WebpackPluginWithError {
apply(compiler) {
compiler.hooks.run.tap("WebpackPluginWithError", compilation => {
throw new Error("Error");
});
}
}

module.exports = {
mode: "development",
entry: __dirname + "/index.js",
output: {
path: __dirname + "/dist",
filename: "bundle.js"
},
plugins: [new FriendlyErrorsWebpackPlugin(), new WebpackPluginWithError()]
};
19 changes: 19 additions & 0 deletions test/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,23 @@ Warning
(3:2) grid-auto-flow works only if grid-template-rows and grid-template-columns are present in the same rule`,
''
]);
});

it('integration : error', (done) => {
const compiler = webpack(require('./fixtures/error/webpack.config'));
compiler.outputFileSystem = new MemoryFileSystem();

output.capture();
compiler.run(() => {
expect(output.capturedMessages).toEqual([
'ERROR Failed to compile with 1 errors',
'',
'error',
'',
'Error',
''
]);
output.endCapture();
done();
})
});