aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md11
-rw-r--r--package.json6
-rw-r--r--src/index.js33
3 files changed, 24 insertions, 26 deletions
diff --git a/README.md b/README.md
index 9e887dc..ab4d9cd 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,8 @@ Install with [npm](https://npmjs.org/package/purs-loader).
12 12
13``` 13```
14npm install purs-loader --save-dev 14npm install purs-loader --save-dev
15
16npm install purs-loader@next --save-dev
15``` 17```
16 18
17## Example 19## Example
@@ -27,8 +29,7 @@ const webpackConfig = {
27 exclude: /node_modules/, 29 exclude: /node_modules/,
28 query: { 30 query: {
29 psc: 'psa', 31 psc: 'psa',
30 src: ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs'], 32 src: ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs']
31 ffi: ['bower_components/purescript-*/src/**/*.js', 'src/**/*.js'],
32 } 33 }
33 } 34 }
34 // ... 35 // ...
@@ -59,11 +60,7 @@ Default options:
59 src: [ 60 src: [
60 path.join('src', '**', '*.purs'), 61 path.join('src', '**', '*.purs'),
61 path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') 62 path.join('bower_components', 'purescript-*', 'src', '**', '*.purs')
62 ], 63 ]
63 ffi: [
64 path.join('src', '**', '*.js'),
65 path.join('bower_components', 'purescript-*', 'src', '**', '*.js')
66 ],
67} 64}
68``` 65```
69 66
diff --git a/package.json b/package.json
index d06cf53..5fc5a7f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
1{ 1{
2 "name": "purs-loader", 2 "name": "purs-loader",
3 "version": "1.0.0", 3 "version": "2.0.0-rc.0",
4 "description": "A webpack loader for PureScript.", 4 "description": "A webpack loader for PureScript.",
5 "main": "index.js", 5 "main": "index.js",
6 "files": [ 6 "files": [
@@ -34,10 +34,6 @@
34 "url": "https://github.com/ethul/purs-loader/issues" 34 "url": "https://github.com/ethul/purs-loader/issues"
35 }, 35 },
36 "homepage": "https://github.com/ethul/purs-loader#readme", 36 "homepage": "https://github.com/ethul/purs-loader#readme",
37 "peerDependencies": {
38 "webpack": ">=1.0.0 <3.0.0",
39 "purescript": ">=0.8.0"
40 },
41 "dependencies": { 37 "dependencies": {
42 "bluebird": "^3.3.5", 38 "bluebird": "^3.3.5",
43 "chalk": "^1.1.3", 39 "chalk": "^1.1.3",
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 }, {})