From f8d292fbbe2004d209ee78d3432a0340ea6cf858 Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 24 May 2016 08:55:38 -0400 Subject: Escape require paths for windows Resolves #52 --- src/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') 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')) const spawn = require('cross-spawn') const path = require('path') const retryPromise = require('promise-retry') +const jsStringEscape = require('js-string-escape') const ffiModuleRegex = /\/\/\s+module\s+([\w\.]+)/i const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i @@ -143,17 +144,17 @@ function toJavaScript(psModule) { if (options.bundle) { // if bundling, return a reference to the bundle js = 'module.exports = require("' - + path.relative(psModule.srcDir, options.bundleOutput) + + jsStringEscape(path.relative(psModule.srcDir, options.bundleOutput)) + '")["' + psModule.name + '"]' } else { // replace require paths to output files generated by psc with paths // to purescript sources, which are then also run through this loader. js = result.js .replace(requireRegex, (m, p1) => { - return 'require("' + result.psModuleMap[p1].src + '")' + return 'require("' + jsStringEscape(result.psModuleMap[p1].src) + '")' }) .replace(/require\(['"]\.\/foreign['"]\)/g, (m, p1) => { - return 'require("' + result.psModuleMap[psModule.name].ffi + '")' + return 'require("' + jsStringEscape(result.psModuleMap[psModule.name].ffi) + '")' }) } -- cgit v1.2.3