aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
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 /src
parent8963e41464123c7cb9b8493451df277280437ee2 (diff)
downloadpurs-loader-f8d292fbbe2004d209ee78d3432a0340ea6cf858.tar.gz
purs-loader-f8d292fbbe2004d209ee78d3432a0340ea6cf858.tar.zst
purs-loader-f8d292fbbe2004d209ee78d3432a0340ea6cf858.zip
Escape require paths for windows
Resolves #52
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