aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.js')
-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