aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/index.js
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 /src/index.js
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
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js35
1 files changed, 30 insertions, 5 deletions
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)