From f8d292fbbe2004d209ee78d3432a0340ea6cf858 Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 24 May 2016 08:55:38 -0400 Subject: [PATCH] Escape require paths for windows Resolves #52 --- package.json | 1 + 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 @@ "cross-spawn": "^3.0.1", "debug": "^2.2.0", "globby": "^4.0.0", + "js-string-escape": "^1.0.1", "loader-utils": "^0.2.14", "promise-retry": "^1.1.0" }, 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) + '")' }) } -- 2.41.0