From 58fb80fa2c0bf07b08c1aa201a2bac3b3091142f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 22 Nov 2017 15:37:31 -0800 Subject: [PATCH] Report relay-compiler errors as webpack errors --- dist/index.js | 22 +++++++++++++++------- src/index.js | 22 +++++++++++++--------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/dist/index.js b/dist/index.js index acd2864..b755483 100644 --- a/dist/index.js +++ b/dist/index.js @@ -51,7 +51,6 @@ class RelayCompilerWebpackPlugin { parser: 'default' } }; - this.reporter = {}; if (!options) { throw new Error('You must provide options to RelayCompilerWebpackPlugin.'); @@ -91,8 +90,6 @@ class RelayCompilerWebpackPlugin { this.parserConfigs.default.filepaths = watchman ? null : (0, _getFilepathsFromGlob2.default)(options.src, fileOptions); this.writerConfigs.default.getWriter = (0, _getWriter2.default)(options.src); - - this.reporter = options.reporter ? options.reporter : new _relayCompiler.ConsoleReporter({ verbose: false }); } apply(compiler) { @@ -100,21 +97,32 @@ class RelayCompilerWebpackPlugin { compiler.plugin('before-compile', (() => { var _ref = _asyncToGenerator(function* (compilationParams, callback) { + const errors = []; try { + const reporter = { + reportError: function reportError(area, error) { + return errors.push(error); + } + }; + const runner = new _relayCompiler.Runner({ parserConfigs: _this.parserConfigs, writerConfigs: _this.writerConfigs, - reporter: _this.reporter, + reporter: reporter, onlyValidate: false, skipPersist: true }); yield runner.compileAll(); } catch (error) { - callback(error); - return; + errors.push(error); + } + + if (errors.length) { + callback(errors[0]); + } else { + callback(); } - callback(); }); return function (_x, _x2) { diff --git a/src/index.js b/src/index.js index a26cb3e..5f50ffa 100644 --- a/src/index.js +++ b/src/index.js @@ -33,8 +33,6 @@ class RelayCompilerWebpackPlugin { }, } - reporter = {} - constructor (options: { schema: string, src: string, @@ -42,7 +40,6 @@ class RelayCompilerWebpackPlugin { include: Array, exclude: Array, watchman: boolean, - reporter: {reportError: (area: string, error: string) => void}, }) { if (!options) { throw new Error('You must provide options to RelayCompilerWebpackPlugin.') @@ -87,27 +84,34 @@ class RelayCompilerWebpackPlugin { this.parserConfigs.default.filepaths = watchman ? null : getFilepathsFromGlob(options.src, fileOptions) this.writerConfigs.default.getWriter = getWriter(options.src) - - this.reporter = options.reporter ? options.reporter : new ConsoleReporter({ verbose: false }); } apply (compiler: Compiler) { compiler.plugin('before-compile', async (compilationParams, callback) => { + const errors = [] try { + const reporter = { + reportError: (area, error) => errors.push(error) + } + const runner = new Runner({ parserConfigs: this.parserConfigs, writerConfigs: this.writerConfigs, - reporter: this.reporter, + reporter: reporter, onlyValidate: false, skipPersist: true, }) await runner.compileAll() } catch (error) { - callback(error) - return + errors.push(error) + } + + if (errors.length) { + callback(errors[0]) + } else { + callback() } - callback() }) } }