From: eric thul Date: Tue, 15 Mar 2016 00:35:35 +0000 (-0400) Subject: Escape path for require X-Git-Tag: 0.6.0-beta.6~1^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=47973be19f453aadfc810a5439a12d48e110984a;p=github%2Ffretlink%2Fpurs-loader.git Escape path for require Resolves #41 --- 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 @@ +## Module PursLoader.JsStringEscape + +#### `jsStringEscape` + +``` purescript +jsStringEscape :: String -> String +``` + + diff --git a/package.json b/package.json index 04fd680..a5c0315 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,7 @@ "webpack": "^1.8.4" }, "dependencies": { - "async": "^1.3.0", - "chalk": "^1.1.0", - "debug": "^2.2.0" + "debug": "^2.2.0", + "js-string-escape": "^1.0.1" } } 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 @@ +'use strict'; + +// module PursLoader.JsStringEscape + +var jsStringEscape = require('js-string-escape'); + +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 @@ +module PursLoader.JsStringEscape (jsStringEscape) where + +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) import Unsafe.Coerce (unsafeCoerce) +import PursLoader.Debug (debug) +import PursLoader.JsStringEscape (jsStringEscape) import PursLoader.LoaderRef ( AsyncCallback() , LoaderRef() @@ -30,8 +32,6 @@ import PursLoader.LoaderRef , addDependency , resourcePath ) - -import PursLoader.Debug (debug) import PursLoader.Path (dirname, joinPath, relative) import PursLoader.Plugin as Plugin @@ -79,13 +79,13 @@ loader ref source = do else moduleExport <<< modulePath <$> name where bundleExport :: String -> String - bundleExport name' = "module.exports = require('" ++ path ++ "')['" ++ name' ++ "'];" + bundleExport name' = "module.exports = require('" ++ jsStringEscape path ++ "')['" ++ name' ++ "'];" where path :: String path = relative resourceDir pluginContext.options.bundleOutput moduleExport :: String -> String - moduleExport path = "module.exports = require('" ++ path ++ "');" + moduleExport path = "module.exports = require('" ++ jsStringEscape path ++ "');" modulePath :: String -> String modulePath = relative resourceDir <<< joinPath pluginContext.options.output