aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PsModuleMap.js
diff options
context:
space:
mode:
authoreric <thul.eric@gmail.com>2017-02-25 10:30:44 -0500
committerGitHub <noreply@github.com>2017-02-25 10:30:44 -0500
commit936a04b591f649dbff2a65bbbd291913fc42502d (patch)
treeb426fce8d295591d60ce94c54a157a324e100ffb /src/PsModuleMap.js
parenta3c358f80f8197d5a1d05e42916cd5593b5b2dd5 (diff)
parent806d2915e6579d3dce38de8f2b40b85466ceda05 (diff)
downloadpurs-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.js22
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
9const globby = require('globby'); 9const globby = require('globby');
10 10
11const debug = require('debug')('purs-loader') 11const debug = require('debug')('purs-loader');
12 12
13const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i 13const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i;
14 14
15function match(str) { 15const importModuleRegex = /(?:^|\n)\s*import\s+([\w\.]+)/ig;
16
17function 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}
19module.exports.match = match; 21module.exports.match = matchModule;
22
23function matchImports(str) {
24 const matches = str.match(importModuleRegex);
25 return (matches || []).map(a => a.replace(/\n?\s*import\s+/i, ''));
26}
27module.exports.matchImports = matchImports;
20 28
21function makeMapEntry(filePurs) { 29function 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 }