include-folder
include-folder copied to clipboard
include-folder fails if given a Windows-style path name
Trying to use include-folder on Windows fails with an error like this:
undefined:4
self["foo"] = fs.readFileSync("C:\Users\rob\Documents\xdev\foo.js","utf8");
^^^^
SyntaxError: Invalid hexadecimal escape sequence
at new Function (
I believe the problem is in the includeFolder.buildSource function where it creates a string that is then parsed via the javascript Function object. If this string has characters that should be escaped then the subsequent parsing will fail.
The following change fixed the issue for me:
- var jsStringEscape = require('js-string-escape');
- return 'self["' + name + '"] = fs.readFileSync("' + folderName + '/' + fileName + '","utf8");';
- return 'self["' + name + '"] = fs.readFileSync("' + jsStringEscape(folderName) + '/' + fileName + '","utf8");';