diff options
author | Cyril Sobierajewicz <cyril.sobierajewicz@fretlink.com> | 2019-03-22 17:39:38 +0100 |
---|---|---|
committer | Cyril Sobierajewicz <cyril.sobierajewicz@fretlink.com> | 2019-03-22 17:39:38 +0100 |
commit | 1f4d8537a6df81c27f9d59b4195b6e72c84a5623 (patch) | |
tree | ce7c1505c931fce494ae61c27a4848b23cf8b8d4 | |
parent | e28cbb4ec85b3292814d91e357a3b39115d12232 (diff) | |
parent | 1d773423c3b988f03d87cb4b8f21d15c53877894 (diff) | |
download | purs-loader-1f4d8537a6df81c27f9d59b4195b6e72c84a5623.tar.gz purs-loader-1f4d8537a6df81c27f9d59b4195b6e72c84a5623.tar.zst purs-loader-1f4d8537a6df81c27f9d59b4195b6e72c84a5623.zip |
Merge remote-tracking branch 'fretlink/master' into latest
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/index.js | 4 | ||||
-rw-r--r-- | src/utils.js | 20 |
3 files changed, 23 insertions, 3 deletions
diff --git a/package.json b/package.json index 1faef7b..d9235c8 100644 --- a/package.json +++ b/package.json | |||
@@ -1,6 +1,6 @@ | |||
1 | { | 1 | { |
2 | "name": "purs-loader", | 2 | "name": "purs-loader", |
3 | "version": "4.1.0", | 3 | "version": "4.2.0", |
4 | "description": "A webpack loader for PureScript.", | 4 | "description": "A webpack loader for PureScript.", |
5 | "main": "lib/index.js", | 5 | "main": "lib/index.js", |
6 | "files": [ | 6 | "files": [ |
diff --git a/src/index.js b/src/index.js index be809c6..d713737 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -126,7 +126,8 @@ module.exports = function purescriptLoader(source, map) { | |||
126 | warnings: true, | 126 | warnings: true, |
127 | watch: false, | 127 | watch: false, |
128 | output: 'output', | 128 | output: 'output', |
129 | src: [] | 129 | src: [], |
130 | rewriteRules: {} | ||
130 | }, loaderOptions, { | 131 | }, loaderOptions, { |
131 | src: srcOption | 132 | src: srcOption |
132 | }); | 133 | }); |
@@ -227,6 +228,7 @@ module.exports = function purescriptLoader(source, map) { | |||
227 | const resolved = utils.resolvePursModule({ | 228 | const resolved = utils.resolvePursModule({ |
228 | baseModulePath, | 229 | baseModulePath, |
229 | baseModuleName, | 230 | baseModuleName, |
231 | rewriteRules: options.rewriteRules, | ||
230 | targetModuleName | 232 | targetModuleName |
231 | }); | 233 | }); |
232 | this.addDependency(resolved); | 234 | this.addDependency(resolved); |
diff --git a/src/utils.js b/src/utils.js index 829ba72..446402c 100644 --- a/src/utils.js +++ b/src/utils.js | |||
@@ -23,7 +23,25 @@ const diffPursModuleNames = (from, target, parts) => { | |||
23 | ? diffPursModuleNames(tail_from, tail_target, parts) | 23 | ? diffPursModuleNames(tail_from, tail_target, parts) |
24 | : parts.concat(repeat('..', from.length), target); | 24 | : parts.concat(repeat('..', from.length), target); |
25 | }; | 25 | }; |
26 | exports.resolvePursModule = ({ baseModulePath, baseModuleName, targetModuleName }) => { | 26 | |
27 | const normalizeRewriteRuleDest = ({ dest, moduleName }) => | ||
28 | typeof dest === 'function' ? dest(moduleName) : dest; | ||
29 | const rewrite = ({ rules, moduleName }) => { | ||
30 | const moduleNameParts = moduleName.split('.') | ||
31 | for (const [rule, dest] of Object.entries(rules)) { | ||
32 | const ruleParts = rule.split('.'); | ||
33 | const matched = ruleParts.every((part, i) => | ||
34 | part === '*' || part === moduleNameParts[i]); | ||
35 | if (!matched) continue; | ||
36 | const rest = moduleNameParts.slice(ruleParts.length); | ||
37 | const base = normalizeRewriteRuleDest({ dest, moduleName }); | ||
38 | return `${path.join(base, ...rest)}.purs`; | ||
39 | } | ||
40 | }; | ||
41 | |||
42 | exports.resolvePursModule = ({ baseModulePath, baseModuleName, rewriteRules, targetModuleName }) => { | ||
43 | const rewrittenModulePath = rewrite({ rules: rewriteRules, moduleName: targetModuleName }); | ||
44 | if (rewrittenModulePath) return rewrittenModulePath; | ||
27 | const parts = diffPursModuleNames( | 45 | const parts = diffPursModuleNames( |
28 | baseModuleName.split('.'), | 46 | baseModuleName.split('.'), |
29 | targetModuleName.split('.'), | 47 | targetModuleName.split('.'), |