diff options
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/index.js | 7 |
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')) | |||
9 | const spawn = require('cross-spawn') | 9 | const spawn = require('cross-spawn') |
10 | const path = require('path') | 10 | const path = require('path') |
11 | const retryPromise = require('promise-retry') | 11 | const retryPromise = require('promise-retry') |
12 | const jsStringEscape = require('js-string-escape') | ||
12 | 13 | ||
13 | const ffiModuleRegex = /\/\/\s+module\s+([\w\.]+)/i | 14 | const ffiModuleRegex = /\/\/\s+module\s+([\w\.]+)/i |
14 | const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i | 15 | const 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 | ||