aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2016-05-24 08:55:38 -0400
committereric thul <thul.eric@gmail.com>2016-05-24 08:55:38 -0400
commitf8d292fbbe2004d209ee78d3432a0340ea6cf858 (patch)
tree31dd4191fc2018bffc956926c8b2e7e73b270412
parent8963e41464123c7cb9b8493451df277280437ee2 (diff)
downloadpurs-loader-f8d292fbbe2004d209ee78d3432a0340ea6cf858.tar.gz
purs-loader-f8d292fbbe2004d209ee78d3432a0340ea6cf858.tar.zst
purs-loader-f8d292fbbe2004d209ee78d3432a0340ea6cf858.zip
Escape require paths for windows
Resolves #52
-rw-r--r--package.json1
-rw-r--r--src/index.js7
2 files changed, 5 insertions, 3 deletions
diff --git a/package.json b/package.json
index 4924fc3..c2643a3 100644
--- a/package.json
+++ b/package.json
@@ -44,6 +44,7 @@
44 "cross-spawn": "^3.0.1", 44 "cross-spawn": "^3.0.1",
45 "debug": "^2.2.0", 45 "debug": "^2.2.0",
46 "globby": "^4.0.0", 46 "globby": "^4.0.0",
47 "js-string-escape": "^1.0.1",
47 "loader-utils": "^0.2.14", 48 "loader-utils": "^0.2.14",
48 "promise-retry": "^1.1.0" 49 "promise-retry": "^1.1.0"
49 }, 50 },
diff --git a/src/index.js b/src/index.js
index 6bf1e09..cd85c89 100644
--- a/src/index.js
+++ b/src/index.js
@@ -9,6 +9,7 @@ const fs = Promise.promisifyAll(require('fs'))
9const spawn = require('cross-spawn') 9const spawn = require('cross-spawn')
10const path = require('path') 10const path = require('path')
11const retryPromise = require('promise-retry') 11const retryPromise = require('promise-retry')
12const jsStringEscape = require('js-string-escape')
12 13
13const ffiModuleRegex = /\/\/\s+module\s+([\w\.]+)/i 14const ffiModuleRegex = /\/\/\s+module\s+([\w\.]+)/i
14const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i 15const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i
@@ -143,17 +144,17 @@ function toJavaScript(psModule) {
143 if (options.bundle) { 144 if (options.bundle) {
144 // if bundling, return a reference to the bundle 145 // if bundling, return a reference to the bundle
145 js = 'module.exports = require("' 146 js = 'module.exports = require("'
146 + path.relative(psModule.srcDir, options.bundleOutput) 147 + jsStringEscape(path.relative(psModule.srcDir, options.bundleOutput))
147 + '")["' + psModule.name + '"]' 148 + '")["' + psModule.name + '"]'
148 } else { 149 } else {
149 // replace require paths to output files generated by psc with paths 150 // replace require paths to output files generated by psc with paths
150 // to purescript sources, which are then also run through this loader. 151 // to purescript sources, which are then also run through this loader.
151 js = result.js 152 js = result.js
152 .replace(requireRegex, (m, p1) => { 153 .replace(requireRegex, (m, p1) => {
153 return 'require("' + result.psModuleMap[p1].src + '")' 154 return 'require("' + jsStringEscape(result.psModuleMap[p1].src) + '")'
154 }) 155 })
155 .replace(/require\(['"]\.\/foreign['"]\)/g, (m, p1) => { 156 .replace(/require\(['"]\.\/foreign['"]\)/g, (m, p1) => {
156 return 'require("' + result.psModuleMap[psModule.name].ffi + '")' 157 return 'require("' + jsStringEscape(result.psModuleMap[psModule.name].ffi) + '")'
157 }) 158 })
158 } 159 }
159 160