aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authoreric <thul.eric@gmail.com>2016-06-04 00:15:57 -0400
committereric <thul.eric@gmail.com>2016-06-04 00:15:57 -0400
commit7243be70a2163be2230a5f2739768137305a24ef (patch)
treed8096c69a513124b4c173adee29a96d42c047a19 /src
parenta9a26a84a97102474501f5463d529ae35399cb5a (diff)
parent2b2207bda69a8a948b7fb3aef583b183f7fca87f (diff)
downloadpurs-loader-7243be70a2163be2230a5f2739768137305a24ef.tar.gz
purs-loader-7243be70a2163be2230a5f2739768137305a24ef.tar.zst
purs-loader-7243be70a2163be2230a5f2739768137305a24ef.zip
Merge pull request #55 from ethul/topic/issue-542.0.0-rc.0
Bumping version number to 2.0.0-rc.0
Diffstat (limited to 'src')
-rw-r--r--src/index.js33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/index.js b/src/index.js
index cd85c89..cfba1e2 100644
--- a/src/index.js
+++ b/src/index.js
@@ -11,7 +11,6 @@ const path = require('path')
11const retryPromise = require('promise-retry') 11const retryPromise = require('promise-retry')
12const jsStringEscape = require('js-string-escape') 12const jsStringEscape = require('js-string-escape')
13 13
14const ffiModuleRegex = /\/\/\s+module\s+([\w\.]+)/i
15const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i 14const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i
16const requireRegex = /require\(['"]\.\.\/([\w\.]+)['"]\)/g 15const requireRegex = /require\(['"]\.\.\/([\w\.]+)['"]\)/g
17 16
@@ -38,11 +37,7 @@ module.exports = function purescriptLoader(source, map) {
38 src: [ 37 src: [
39 path.join('src', '**', '*.purs'), 38 path.join('src', '**', '*.purs'),
40 path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') 39 path.join('bower_components', 'purescript-*', 'src', '**', '*.purs')
41 ], 40 ]
42 ffi: [
43 path.join('src', '**', '*.js'),
44 path.join('bower_components', 'purescript-*', 'src', '**', '*.js')
45 ],
46 }, webpackOptions, query) 41 }, webpackOptions, query)
47 42
48 this.cacheable && this.cacheable() 43 this.cacheable && this.cacheable()
@@ -173,7 +168,6 @@ function compile(psModule) {
173 168
174 const args = dargs(Object.assign({ 169 const args = dargs(Object.assign({
175 _: options.src, 170 _: options.src,
176 ffi: options.ffi,
177 output: options.output, 171 output: options.output,
178 }, options.pscArgs)) 172 }, options.pscArgs))
179 173
@@ -374,26 +368,37 @@ function bundle(options, cache) {
374function psModuleMap(options, cache) { 368function psModuleMap(options, cache) {
375 if (cache.psModuleMap) return Promise.resolve(cache.psModuleMap) 369 if (cache.psModuleMap) return Promise.resolve(cache.psModuleMap)
376 370
377 const globs = [].concat(options.src).concat(options.ffi) 371 const globs = [].concat(options.src);
372
373 function pursToJs(file){
374 const dirname = path.dirname(file)
375 const basename = path.basename(file, '.purs')
376 const fileJS = path.join(dirname, `${basename}.js`)
377 return fileJS
378 }
378 379
379 return globby(globs).then(paths => { 380 return globby(globs).then(paths => {
380 return Promise 381 return Promise
381 .props(paths.reduce((map, file) => { 382 .props(paths.reduce((map, file) => {
383 const fileJS = pursToJs(file)
382 map[file] = fs.readFileAsync(file, 'utf8') 384 map[file] = fs.readFileAsync(file, 'utf8')
385 map[fileJS] = fs.readFileAsync(fileJS, 'utf8').catch(() => undefined)
383 return map 386 return map
384 }, {})) 387 }, {}))
385 .then(fileMap => { 388 .then(fileMap => {
386 cache.psModuleMap = Object.keys(fileMap).reduce((map, file) => { 389 cache.psModuleMap = Object.keys(fileMap).reduce((map, file) => {
387 const source = fileMap[file]
388 const ext = path.extname(file) 390 const ext = path.extname(file)
389 const isPurs = ext.match(/purs$/i) 391 const isPurs = ext.match(/purs$/i)
390 const moduleRegex = isPurs ? srcModuleRegex : ffiModuleRegex
391 const moduleName = match(moduleRegex, source)
392 map[moduleName] = map[moduleName] || {}
393 if (isPurs) { 392 if (isPurs) {
393 const fileJs = pursToJs(file)
394 const source = fileMap[file]
395 const ffi = fileMap[fileJs]
396 const moduleName = match(srcModuleRegex, source)
397 map[moduleName] = map[moduleName] || {}
394 map[moduleName].src = path.resolve(file) 398 map[moduleName].src = path.resolve(file)
395 } else { 399 if (ffi) {
396 map[moduleName].ffi = path.resolve(file) 400 map[moduleName].ffi = path.resolve(fileJs)
401 }
397 } 402 }
398 return map 403 return map
399 }, {}) 404 }, {})