aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2016-03-14 20:35:35 -0400
committereric thul <thul.eric@gmail.com>2016-03-14 20:35:35 -0400
commit47973be19f453aadfc810a5439a12d48e110984a (patch)
treee260c7961d1681a3e94079957fa016c1d452b920
parent99fd1c4f2cf9bec1cb8488551c47ebca247b9497 (diff)
downloadpurs-loader-47973be19f453aadfc810a5439a12d48e110984a.tar.gz
purs-loader-47973be19f453aadfc810a5439a12d48e110984a.tar.zst
purs-loader-47973be19f453aadfc810a5439a12d48e110984a.zip
Escape path for require
Resolves #41
-rw-r--r--docs/PursLoader/JsStringEscape.md9
-rw-r--r--package.json5
-rw-r--r--src/PursLoader/JsStringEscape.js7
-rw-r--r--src/PursLoader/JsStringEscape.purs3
-rw-r--r--src/PursLoader/Loader.purs8
5 files changed, 25 insertions, 7 deletions
diff --git a/docs/PursLoader/JsStringEscape.md b/docs/PursLoader/JsStringEscape.md
new file mode 100644
index 0000000..09f52aa
--- /dev/null
+++ b/docs/PursLoader/JsStringEscape.md
@@ -0,0 +1,9 @@
1## Module PursLoader.JsStringEscape
2
3#### `jsStringEscape`
4
5``` purescript
6jsStringEscape :: String -> String
7```
8
9
diff --git a/package.json b/package.json
index 04fd680..a5c0315 100644
--- a/package.json
+++ b/package.json
@@ -24,8 +24,7 @@
24 "webpack": "^1.8.4" 24 "webpack": "^1.8.4"
25 }, 25 },
26 "dependencies": { 26 "dependencies": {
27 "async": "^1.3.0", 27 "debug": "^2.2.0",
28 "chalk": "^1.1.0", 28 "js-string-escape": "^1.0.1"
29 "debug": "^2.2.0"
30 } 29 }
31} 30}
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