diff options
author | eric thul <thul.eric@gmail.com> | 2017-02-12 18:05:07 -0500 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2017-02-19 12:09:16 -0500 |
commit | 8e21ab0ab3f8ba9d129f1cf3b59f87d7a2b5bfc2 (patch) | |
tree | 0db1cffab8462d919299ab87eba42200748be632 /src/PsModuleMap.js | |
parent | a3c358f80f8197d5a1d05e42916cd5593b5b2dd5 (diff) | |
download | purs-loader-8e21ab0ab3f8ba9d129f1cf3b59f87d7a2b5bfc2.tar.gz purs-loader-8e21ab0ab3f8ba9d129f1cf3b59f87d7a2b5bfc2.tar.zst purs-loader-8e21ab0ab3f8ba9d129f1cf3b59f87d7a2b5bfc2.zip |
Ensure that all imported files are watched
In order to handle the case where a new PureScript file is imported, but
fails to compile, the purs-loader now tracks imports for each PureScript
file in order to append any additional imports to the resulting JS.
This ensures that webpack will watch the new file even before it
successfully compiles.
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 | } |