diff options
author | eric <thul.eric@gmail.com> | 2016-03-14 20:40:54 -0400 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2016-03-14 20:40:54 -0400 |
commit | db384f0be544285fec61869020138100152d3037 (patch) | |
tree | e260c7961d1681a3e94079957fa016c1d452b920 /src | |
parent | 99fd1c4f2cf9bec1cb8488551c47ebca247b9497 (diff) | |
parent | 47973be19f453aadfc810a5439a12d48e110984a (diff) | |
download | purs-loader-db384f0be544285fec61869020138100152d3037.tar.gz purs-loader-db384f0be544285fec61869020138100152d3037.tar.zst purs-loader-db384f0be544285fec61869020138100152d3037.zip |
Merge pull request #45 from ethul/topic/issue-41
Escape path for require
Diffstat (limited to 'src')
-rw-r--r-- | src/PursLoader/JsStringEscape.js | 7 | ||||
-rw-r--r-- | src/PursLoader/JsStringEscape.purs | 3 | ||||
-rw-r--r-- | src/PursLoader/Loader.purs | 8 |
3 files changed, 14 insertions, 4 deletions
diff --git a/src/PursLoader/JsStringEscape.js b/src/PursLoader/JsStringEscape.js new file mode 100644 index 0000000..ff0a1a6 --- /dev/null +++ b/src/PursLoader/JsStringEscape.js | |||
@@ -0,0 +1,7 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | // module PursLoader.JsStringEscape | ||
4 | |||
5 | var jsStringEscape = require('js-string-escape'); | ||
6 | |||
7 | exports.jsStringEscape = jsStringEscape; | ||
diff --git a/src/PursLoader/JsStringEscape.purs b/src/PursLoader/JsStringEscape.purs new file mode 100644 index 0000000..79590ae --- /dev/null +++ b/src/PursLoader/JsStringEscape.purs | |||
@@ -0,0 +1,3 @@ | |||
1 | module PursLoader.JsStringEscape (jsStringEscape) where | ||
2 | |||
3 | foreign import jsStringEscape :: String -> String | ||
diff --git a/src/PursLoader/Loader.purs b/src/PursLoader/Loader.purs index 97954f6..acb0993 100644 --- a/src/PursLoader/Loader.purs +++ b/src/PursLoader/Loader.purs | |||
@@ -21,6 +21,8 @@ import Data.String.Regex (Regex(), match, noFlags, regex) | |||
21 | 21 | ||
22 | import Unsafe.Coerce (unsafeCoerce) | 22 | import Unsafe.Coerce (unsafeCoerce) |
23 | 23 | ||
24 | import PursLoader.Debug (debug) | ||
25 | import PursLoader.JsStringEscape (jsStringEscape) | ||
24 | import PursLoader.LoaderRef | 26 | import PursLoader.LoaderRef |
25 | ( AsyncCallback() | 27 | ( AsyncCallback() |
26 | , LoaderRef() | 28 | , LoaderRef() |
@@ -30,8 +32,6 @@ import PursLoader.LoaderRef | |||
30 | , addDependency | 32 | , addDependency |
31 | , resourcePath | 33 | , resourcePath |
32 | ) | 34 | ) |
33 | |||
34 | import PursLoader.Debug (debug) | ||
35 | import PursLoader.Path (dirname, joinPath, relative) | 35 | import PursLoader.Path (dirname, joinPath, relative) |
36 | import PursLoader.Plugin as Plugin | 36 | import PursLoader.Plugin as Plugin |
37 | 37 | ||
@@ -79,13 +79,13 @@ loader ref source = do | |||
79 | else moduleExport <<< modulePath <$> name | 79 | else moduleExport <<< modulePath <$> name |
80 | where | 80 | where |
81 | bundleExport :: String -> String | 81 | bundleExport :: String -> String |
82 | bundleExport name' = "module.exports = require('" ++ path ++ "')['" ++ name' ++ "'];" | 82 | bundleExport name' = "module.exports = require('" ++ jsStringEscape path ++ "')['" ++ name' ++ "'];" |
83 | where | 83 | where |
84 | path :: String | 84 | path :: String |
85 | path = relative resourceDir pluginContext.options.bundleOutput | 85 | path = relative resourceDir pluginContext.options.bundleOutput |
86 | 86 | ||
87 | moduleExport :: String -> String | 87 | moduleExport :: String -> String |
88 | moduleExport path = "module.exports = require('" ++ path ++ "');" | 88 | moduleExport path = "module.exports = require('" ++ jsStringEscape path ++ "');" |
89 | 89 | ||
90 | modulePath :: String -> String | 90 | modulePath :: String -> String |
91 | modulePath = relative resourceDir <<< joinPath pluginContext.options.output | 91 | modulePath = relative resourceDir <<< joinPath pluginContext.options.output |