aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlex Mingoia <talk@alexmingoia.com>2016-05-14 13:55:04 -0700
committerAlex Mingoia <talk@alexmingoia.com>2016-05-14 13:55:04 -0700
commit678884960a53c8c60bbfdfd6389e08580a9ad03e (patch)
treeb1158c76376d21c3d3bfcf85e000c737797652c0
parent0da4ad1982dec8fd03a9b5a3f56a5e4be43376c3 (diff)
downloadpurs-loader-678884960a53c8c60bbfdfd6389e08580a9ad03e.tar.gz
purs-loader-678884960a53c8c60bbfdfd6389e08580a9ad03e.tar.zst
purs-loader-678884960a53c8c60bbfdfd6389e08580a9ad03e.zip
Use more descriptive names for compile state.
-rw-r--r--src/index.js16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/index.js b/src/index.js
index 9db8a63..26b0d81 100644
--- a/src/index.js
+++ b/src/index.js
@@ -89,6 +89,8 @@ module.exports = function purescriptLoader(source, map) {
89 cache: cache, 89 cache: cache,
90 } 90 }
91 91
92 debug('loader called', psModule.name)
93
92 if (options.bundle) { 94 if (options.bundle) {
93 cache.bundleModules.push(psModule.name) 95 cache.bundleModules.push(psModule.name)
94 } 96 }
@@ -101,7 +103,7 @@ module.exports = function purescriptLoader(source, map) {
101 .catch(psModule.reject) 103 .catch(psModule.reject)
102 } 104 }
103 105
104 if (cache.compilation && cache.compilation.length) { 106 if (cache.compilationFinished) {
105 return toJavaScript(psModule).then(psModule.load).catch(psModule.reject) 107 return toJavaScript(psModule).then(psModule.load).catch(psModule.reject)
106 } 108 }
107 109
@@ -109,7 +111,7 @@ module.exports = function purescriptLoader(source, map) {
109 // references to compiled output are valid. 111 // references to compiled output are valid.
110 cache.deferred.push(psModule) 112 cache.deferred.push(psModule)
111 113
112 if (!cache.compilation) { 114 if (!cache.compilationStarted) {
113 return compile(psModule) 115 return compile(psModule)
114 .then(() => Promise.map(cache.deferred, psModule => { 116 .then(() => Promise.map(cache.deferred, psModule => {
115 if (typeof cache.ideServer === 'object') cache.ideServer.kill() 117 if (typeof cache.ideServer === 'object') cache.ideServer.kill()
@@ -129,7 +131,7 @@ function toJavaScript(psModule) {
129 const bundlePath = path.resolve(options.bundleOutput) 131 const bundlePath = path.resolve(options.bundleOutput)
130 const jsPath = cache.bundle ? bundlePath : psModule.jsPath 132 const jsPath = cache.bundle ? bundlePath : psModule.jsPath
131 133
132 debug('loading JavaScript for', psModule.srcPath) 134 debug('loading JavaScript for', psModule.name)
133 135
134 return Promise.props({ 136 return Promise.props({
135 js: fs.readFileAsync(jsPath, 'utf8'), 137 js: fs.readFileAsync(jsPath, 'utf8'),
@@ -165,12 +167,9 @@ function compile(psModule) {
165 const cache = psModule.cache 167 const cache = psModule.cache
166 const stderr = [] 168 const stderr = []
167 169
168 if (cache.compilation) return Promise.resolve(cache.compilation) 170 if (cache.compilationStarted) return Promise.resolve(psModule)
169
170 cache.compilation = []
171 cache.warnings = []
172 cache.errors = []
173 171
172 cache.compilationStarted = true
174 173
175 const args = dargs(Object.assign({ 174 const args = dargs(Object.assign({
176 _: options.src, 175 _: options.src,
@@ -189,6 +188,7 @@ function compile(psModule) {
189 188
190 compilation.on('close', code => { 189 compilation.on('close', code => {
191 console.log('Finished compiling PureScript.') 190 console.log('Finished compiling PureScript.')
191 cache.compilationFinished = true
192 if (code !== 0) { 192 if (code !== 0) {
193 cache.compilation = cache.errors = stderr 193 cache.compilation = cache.errors = stderr
194 reject(true) 194 reject(true)