aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PsModuleMap.js
diff options
context:
space:
mode:
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 }