diff options
author | eric <thul.eric@gmail.com> | 2017-02-25 10:30:44 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-25 10:30:44 -0500 |
commit | 936a04b591f649dbff2a65bbbd291913fc42502d (patch) | |
tree | b426fce8d295591d60ce94c54a157a324e100ffb /src/PsModuleMap.js | |
parent | a3c358f80f8197d5a1d05e42916cd5593b5b2dd5 (diff) | |
parent | 806d2915e6579d3dce38de8f2b40b85466ceda05 (diff) | |
download | purs-loader-936a04b591f649dbff2a65bbbd291913fc42502d.tar.gz purs-loader-936a04b591f649dbff2a65bbbd291913fc42502d.tar.zst purs-loader-936a04b591f649dbff2a65bbbd291913fc42502d.zip |
Merge pull request #84 from ethul/topic/error-handling
Topic/error handling
Diffstat (limited to 'src/PsModuleMap.js')
-rw-r--r-- | src/PsModuleMap.js | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/PsModuleMap.js b/src/PsModuleMap.js index 2193f02..0ae687c 100644 --- a/src/PsModuleMap.js +++ b/src/PsModuleMap.js | |||
@@ -8,15 +8,23 @@ const fs = Promise.promisifyAll(require('fs')); | |||
8 | 8 | ||
9 | const globby = require('globby'); | 9 | const globby = require('globby'); |
10 | 10 | ||
11 | const debug = require('debug')('purs-loader') | 11 | const debug = require('debug')('purs-loader'); |
12 | 12 | ||
13 | const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i | 13 | const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i; |
14 | 14 | ||
15 | function match(str) { | 15 | const importModuleRegex = /(?:^|\n)\s*import\s+([\w\.]+)/ig; |
16 | |||
17 | function matchModule(str) { | ||
16 | const matches = str.match(srcModuleRegex); | 18 | const matches = str.match(srcModuleRegex); |
17 | return matches && matches[1]; | 19 | return matches && matches[1]; |
18 | } | 20 | } |
19 | module.exports.match = match; | 21 | module.exports.match = matchModule; |
22 | |||
23 | function matchImports(str) { | ||
24 | const matches = str.match(importModuleRegex); | ||
25 | return (matches || []).map(a => a.replace(/\n?\s*import\s+/i, '')); | ||
26 | } | ||
27 | module.exports.matchImports = matchImports; | ||
20 | 28 | ||
21 | function makeMapEntry(filePurs) { | 29 | function makeMapEntry(filePurs) { |
22 | const dirname = path.dirname(filePurs); | 30 | const dirname = path.dirname(filePurs); |
@@ -33,7 +41,9 @@ function makeMapEntry(filePurs) { | |||
33 | 41 | ||
34 | const sourceJs = fileMap.fileJs; | 42 | const sourceJs = fileMap.fileJs; |
35 | 43 | ||
36 | const moduleName = match(sourcePurs); | 44 | const moduleName = matchModule(sourcePurs); |
45 | |||
46 | const imports = matchImports(sourcePurs); | ||
37 | 47 | ||
38 | const map = {}; | 48 | const map = {}; |
39 | 49 | ||
@@ -41,6 +51,8 @@ function makeMapEntry(filePurs) { | |||
41 | 51 | ||
42 | map[moduleName].src = path.resolve(filePurs); | 52 | map[moduleName].src = path.resolve(filePurs); |
43 | 53 | ||
54 | map[moduleName].imports = imports; | ||
55 | |||
44 | if (sourceJs) { | 56 | if (sourceJs) { |
45 | map[moduleName].ffi = path.resolve(fileJs); | 57 | map[moduleName].ffi = path.resolve(fileJs); |
46 | } | 58 | } |