aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Psc.js22
-rw-r--r--src/PscIde.js33
-rw-r--r--src/index.js17
3 files changed, 38 insertions, 34 deletions
diff --git a/src/Psc.js b/src/Psc.js
index 0aa9fe2..8fe8437 100644
--- a/src/Psc.js
+++ b/src/Psc.js
@@ -29,7 +29,7 @@ function compile(psModule) {
29 debug('spawning compiler %s %o', options.psc, args) 29 debug('spawning compiler %s %o', options.psc, args)
30 30
31 return (new Promise((resolve, reject) => { 31 return (new Promise((resolve, reject) => {
32 debug('\nCompiling PureScript...') 32 debug('compiling PureScript...')
33 33
34 const compilation = spawn(options.psc, args) 34 const compilation = spawn(options.psc, args)
35 35
@@ -37,13 +37,19 @@ function compile(psModule) {
37 compilation.stderr.on('data', data => stderr.push(data.toString())) 37 compilation.stderr.on('data', data => stderr.push(data.toString()))
38 38
39 compilation.on('close', code => { 39 compilation.on('close', code => {
40 debug('Finished compiling PureScript.') 40 debug('finished compiling PureScript.')
41 cache.compilationFinished = true 41 cache.compilationFinished = true
42 if (code !== 0) { 42 if (code !== 0) {
43 cache.errors = stderr.join('') 43 const errorMessage = stderr.join('');
44 if (errorMessage.length) {
45 psModule.emitError(errorMessage);
46 }
44 reject(new Error('compilation failed')) 47 reject(new Error('compilation failed'))
45 } else { 48 } else {
46 cache.warnings = stderr.join('') 49 const warningMessage = stderr.join('');
50 if (options.warnings && warningMessage.length) {
51 psModule.emitWarning(warningMessage);
52 }
47 resolve(psModule) 53 resolve(psModule)
48 } 54 }
49 }) 55 })
@@ -74,15 +80,19 @@ function bundle(options, cache) {
74 debug('spawning bundler %s %o', options.pscBundle, args.join(' ')) 80 debug('spawning bundler %s %o', options.pscBundle, args.join(' '))
75 81
76 return (new Promise((resolve, reject) => { 82 return (new Promise((resolve, reject) => {
77 debug('Bundling PureScript...') 83 debug('bundling PureScript...')
78 84
79 const compilation = spawn(options.pscBundle, args) 85 const compilation = spawn(options.pscBundle, args)
80 86
81 compilation.stdout.on('data', data => stdout.push(data.toString())) 87 compilation.stdout.on('data', data => stdout.push(data.toString()))
82 compilation.stderr.on('data', data => stderr.push(data.toString())) 88 compilation.stderr.on('data', data => stderr.push(data.toString()))
83 compilation.on('close', code => { 89 compilation.on('close', code => {
90 debug('finished bundling PureScript.')
84 if (code !== 0) { 91 if (code !== 0) {
85 cache.errors = (cache.errors || '') + stderr.join('') 92 const errorMessage = stderr.join('');
93 if (errorMessage.length) {
94 psModule.emitError(errorMessage);
95 }
86 return reject(new Error('bundling failed')) 96 return reject(new Error('bundling failed'))
87 } 97 }
88 cache.bundle = stderr 98 cache.bundle = stderr
diff --git a/src/PscIde.js b/src/PscIde.js
index c9d0cfa..27b49f6 100644
--- a/src/PscIde.js
+++ b/src/PscIde.js
@@ -77,10 +77,7 @@ function connect(psModule) {
77 if (!cache.ideServer && number === 9) { 77 if (!cache.ideServer && number === 9) {
78 debug(error) 78 debug(error)
79 79
80 console.log( 80 console.warn('Failed to connect to or start psc-ide-server. A full compilation will occur on rebuild');
81 'failed to connect to or start psc-ide-server, ' +
82 'full compilation will occur on rebuild'
83 )
84 81
85 return Promise.resolve(psModule) 82 return Promise.resolve(psModule)
86 } 83 }
@@ -133,9 +130,7 @@ function rebuild(psModule) {
133 } 130 }
134 131
135 if (res && !Array.isArray(res.result)) { 132 if (res && !Array.isArray(res.result)) {
136 return res.resultType === 'success' 133 return resolve(psModule);
137 ? resolve(psModule)
138 : reject(new Error('psc-ide rebuild failed'))
139 } 134 }
140 135
141 Promise.map(res.result, (item, i) => { 136 Promise.map(res.result, (item, i) => {
@@ -144,7 +139,13 @@ function rebuild(psModule) {
144 }) 139 })
145 .then(compileMessages => { 140 .then(compileMessages => {
146 if (res.resultType === 'error') { 141 if (res.resultType === 'error') {
147 if (res.result.some(item => item.errorCode === 'UnknownModule' || item.errorCode === 'UnknownName')) { 142 if (res.result.some(item => {
143 const isUnknownModule = item.errorCode === 'UnknownModule';
144
145 const isUnknownModuleImport = item.errorCode === 'UnknownName' && /Unknown module/.test(item.message);
146
147 return isUnknownModule || isUnknownModuleImport;
148 })) {
148 debug('unknown module, attempting full recompile') 149 debug('unknown module, attempting full recompile')
149 return Psc.compile(psModule) 150 return Psc.compile(psModule)
150 .then(() => PsModuleMap.makeMap(options.src).then(map => { 151 .then(() => PsModuleMap.makeMap(options.src).then(map => {
@@ -153,13 +154,19 @@ function rebuild(psModule) {
153 })) 154 }))
154 .then(() => request({ command: 'load' })) 155 .then(() => request({ command: 'load' }))
155 .then(resolve) 156 .then(resolve)
156 .catch(() => reject(new Error('psc-ide rebuild failed'))) 157 .catch(() => resolve(psModule))
158 }
159 const errorMessage = compileMessages.join('\n');
160 if (errorMessage.length) {
161 psModule.emitError(errorMessage);
157 } 162 }
158 cache.errors = compileMessages.join('\n') 163 resolve(psModule);
159 reject(new Error('psc-ide rebuild failed'))
160 } else { 164 } else {
161 cache.warnings = compileMessages.join('\n') 165 const warningMessage = compileMessages.join('\n');
162 resolve(psModule) 166 if (options.warnings && warningMessage.length) {
167 psModule.emitWarning(warningMessage);
168 }
169 resolve(psModule);
163 } 170 }
164 }) 171 })
165 }) 172 })
diff --git a/src/index.js b/src/index.js
index f3b2fde..7c29650 100644
--- a/src/index.js
+++ b/src/index.js
@@ -62,21 +62,6 @@ module.exports = function purescriptLoader(source, map) {
62 psModuleMap: cache.psModuleMap 62 psModuleMap: cache.psModuleMap
63 } 63 }
64 }) 64 })
65
66 // add psc warnings to webpack compilation warnings
67 this._compiler.plugin('after-compile', (compilation, callback) => {
68 if (options.warnings && cache.warnings) {
69 compilation.warnings.unshift(`PureScript compilation:\n${cache.warnings}`)
70 cache.warnings = null;
71 }
72
73 if (cache.errors) {
74 compilation.errors.unshift(`PureScript compilation:\n${cache.errors}`)
75 cache.errors = null;
76 }
77
78 callback()
79 })
80 } 65 }
81 66
82 const psModuleName = PsModuleMap.match(source) 67 const psModuleName = PsModuleMap.match(source)
@@ -89,6 +74,8 @@ module.exports = function purescriptLoader(source, map) {
89 jsPath: path.resolve(path.join(options.output, psModuleName, 'index.js')), 74 jsPath: path.resolve(path.join(options.output, psModuleName, 'index.js')),
90 options: options, 75 options: options,
91 cache: cache, 76 cache: cache,
77 emitWarning: warning => this.emitWarning(warning),
78 emitError: error => this.emitError(error)
92 } 79 }
93 80
94 debug('loader called', psModule.name) 81 debug('loader called', psModule.name)