From 47973be19f453aadfc810a5439a12d48e110984a Mon Sep 17 00:00:00 2001 From: eric thul Date: Mon, 14 Mar 2016 20:35:35 -0400 Subject: Escape path for require Resolves #41 --- src/PursLoader/JsStringEscape.js | 7 +++++++ src/PursLoader/JsStringEscape.purs | 3 +++ src/PursLoader/Loader.purs | 8 ++++---- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/PursLoader/JsStringEscape.js create mode 100644 src/PursLoader/JsStringEscape.purs (limited to 'src') 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 -- cgit v1.2.3