aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2016-11-19 21:08:47 -0500
committereric thul <thul.eric@gmail.com>2016-11-19 21:08:47 -0500
commitb683b0b17cde53739ccb22da93ffb2bba2719667 (patch)
treeff604c372a8cb2c0a2e11142661d591680ed872b
parent5b28db7d119dc46c382e666fbb2110b611398c4a (diff)
downloadpurs-loader-b683b0b17cde53739ccb22da93ffb2bba2719667.tar.gz
purs-loader-b683b0b17cde53739ccb22da93ffb2bba2719667.tar.zst
purs-loader-b683b0b17cde53739ccb22da93ffb2bba2719667.zip
Emit warnings/errors to the compilation instance
Avoids duplication of warnings. Resolves #78
-rw-r--r--src/Psc.js5
-rw-r--r--src/index.js35
2 files changed, 33 insertions, 7 deletions
diff --git a/src/Psc.js b/src/Psc.js
index 8fe8437..4991d5f 100644
--- a/src/Psc.js
+++ b/src/Psc.js
@@ -33,8 +33,9 @@ function compile(psModule) {
33 33
34 const compilation = spawn(options.psc, args) 34 const compilation = spawn(options.psc, args)
35 35
36 compilation.stdout.on('data', data => stderr.push(data.toString())) 36 compilation.stderr.on('data', data => {
37 compilation.stderr.on('data', data => stderr.push(data.toString())) 37 stderr.push(data.toString());
38 });
38 39
39 compilation.on('close', code => { 40 compilation.on('close', code => {
40 debug('finished compiling PureScript.') 41 debug('finished compiling PureScript.')
diff --git a/src/index.js b/src/index.js
index 7c29650..f3390dc 100644
--- a/src/index.js
+++ b/src/index.js
@@ -44,7 +44,9 @@ module.exports = function purescriptLoader(source, map) {
44 let cache = config.purescriptLoaderCache = config.purescriptLoaderCache || { 44 let cache = config.purescriptLoaderCache = config.purescriptLoaderCache || {
45 rebuild: false, 45 rebuild: false,
46 deferred: [], 46 deferred: [],
47 bundleModules: [] 47 bundleModules: [],
48 warnings: [],
49 errors: []
48 } 50 }
49 51
50 if (!config.purescriptLoaderInstalled) { 52 if (!config.purescriptLoaderInstalled) {
@@ -59,9 +61,24 @@ module.exports = function purescriptLoader(source, map) {
59 deferred: [], 61 deferred: [],
60 bundleModules: [], 62 bundleModules: [],
61 ideServer: cache.ideServer, 63 ideServer: cache.ideServer,
62 psModuleMap: cache.psModuleMap 64 psModuleMap: cache.psModuleMap,
65 warnings: [],
66 errors: []
63 } 67 }
64 }) 68 });
69
70 // add psc warnings to webpack compilation warnings
71 this._compiler.plugin('after-compile', (compilation, callback) => {
72 cache.warnings.forEach(warning => {
73 compilation.warnings.push(warning);
74 });
75
76 cache.errors.forEach(error => {
77 compilation.errors.push(error);
78 });
79
80 callback()
81 });
65 } 82 }
66 83
67 const psModuleName = PsModuleMap.match(source) 84 const psModuleName = PsModuleMap.match(source)
@@ -74,8 +91,16 @@ module.exports = function purescriptLoader(source, map) {
74 jsPath: path.resolve(path.join(options.output, psModuleName, 'index.js')), 91 jsPath: path.resolve(path.join(options.output, psModuleName, 'index.js')),
75 options: options, 92 options: options,
76 cache: cache, 93 cache: cache,
77 emitWarning: warning => this.emitWarning(warning), 94 emitWarning: warning => {
78 emitError: error => this.emitError(error) 95 if (options.warnings && warning.length) {
96 cache.warnings.push(warning);
97 }
98 },
99 emitError: error => {
100 if (error.length) {
101 cache.errors.push(error);
102 }
103 }
79 } 104 }
80 105
81 debug('loader called', psModule.name) 106 debug('loader called', psModule.name)