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 --- docs/PursLoader/JsStringEscape.md | 9 +++++++++ package.json | 5 ++--- src/PursLoader/JsStringEscape.js | 7 +++++++ src/PursLoader/JsStringEscape.purs | 3 +++ src/PursLoader/Loader.purs | 8 ++++---- 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 docs/PursLoader/JsStringEscape.md create mode 100644 src/PursLoader/JsStringEscape.js create mode 100644 src/PursLoader/JsStringEscape.purs 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 -- cgit v1.2.3