aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authoreric <thul.eric@gmail.com>2016-05-24 08:56:59 -0400
committereric <thul.eric@gmail.com>2016-05-24 08:56:59 -0400
commit8f850fa1983a9cab69bd979483b42955828e980d (patch)
tree31dd4191fc2018bffc956926c8b2e7e73b270412 /src
parent8963e41464123c7cb9b8493451df277280437ee2 (diff)
parentf8d292fbbe2004d209ee78d3432a0340ea6cf858 (diff)
downloadpurs-loader-8f850fa1983a9cab69bd979483b42955828e980d.tar.gz
purs-loader-8f850fa1983a9cab69bd979483b42955828e980d.tar.zst
purs-loader-8f850fa1983a9cab69bd979483b42955828e980d.zip
Merge pull request #53 from ethul/topic/issue-52
Escape require paths for windows
Diffstat (limited to 'src')
-rw-r--r--src/index.js7
1 files changed, 4 insertions, 3 deletions
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