aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCyril Sobierajewicz <38043722+cyrilfretlink@users.noreply.github.com>2019-03-22 17:38:38 +0100
committerGitHub <noreply@github.com>2019-03-22 17:38:38 +0100
commit1d773423c3b988f03d87cb4b8f21d15c53877894 (patch)
tree70bec9007e7a07e6ba91eaf8b24e18b19e4c8819
parentd2dedd26a0ff0133904956198ce694c241214dfa (diff)
parent9767783f57f4d10c7633e5a652f81cf13cd5c000 (diff)
downloadpurs-loader-purs-css-modules-webpack-plugin.tar.gz
purs-loader-purs-css-modules-webpack-plugin.tar.zst
purs-loader-purs-css-modules-webpack-plugin.zip
Merge pull request #4 from cyrilfretlink/4.2.0purs-css-modules-webpack-plugin
Version 4.2.0
-rw-r--r--package.json2
-rw-r--r--src/index.js4
-rw-r--r--src/utils.js20
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};
26exports.resolvePursModule = ({ baseModulePath, baseModuleName, targetModuleName }) => { 26
27const normalizeRewriteRuleDest = ({ dest, moduleName }) =>
28 typeof dest === 'function' ? dest(moduleName) : dest;
29const 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
42exports.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('.'),