aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authoreric <thul.eric@gmail.com>2016-03-14 20:40:54 -0400
committereric <thul.eric@gmail.com>2016-03-14 20:40:54 -0400
commitdb384f0be544285fec61869020138100152d3037 (patch)
treee260c7961d1681a3e94079957fa016c1d452b920 /src
parent99fd1c4f2cf9bec1cb8488551c47ebca247b9497 (diff)
parent47973be19f453aadfc810a5439a12d48e110984a (diff)
downloadpurs-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.js7
-rw-r--r--src/PursLoader/JsStringEscape.purs3
-rw-r--r--src/PursLoader/Loader.purs8
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
5var jsStringEscape = require('js-string-escape');
6
7exports.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 @@
1module PursLoader.JsStringEscape (jsStringEscape) where
2
3foreign 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
22import Unsafe.Coerce (unsafeCoerce) 22import Unsafe.Coerce (unsafeCoerce)
23 23
24import PursLoader.Debug (debug)
25import PursLoader.JsStringEscape (jsStringEscape)
24import PursLoader.LoaderRef 26import 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
34import PursLoader.Debug (debug)
35import PursLoader.Path (dirname, joinPath, relative) 35import PursLoader.Path (dirname, joinPath, relative)
36import PursLoader.Plugin as Plugin 36import 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