Escaping problem
Referencing a module with NodeRequirer will end in a "slash" / "backslash" mixed filepath. Don't know if this issue is tackled due my brain...
In the *.sublime-project file, I made the "path" absolute (works well in st):
{
"folders": [{
"follow_symlinks": true,
"path": "d:/path/to/my/awesome/project"
}]
}
The result looks like something like this:
var emitter = require("./..\..\src\scripts\lib\emitter");
Any ideas how we could resolve this issue?
Call a path.normpath(path) before placing it in a template?
@megawac Wow, faster than "speed of light"! :+1:
My python knowledge is really restricted. To fix this issue by myself, I have to dive a bit deeper into the matter. ;)
Hehe, good catch try adding that line to https://github.com/ganemone/NodeRequirer/blob/master/Require.py#L128 and testing if that fixes it for you and send a pr. I can't test it at the moment
(Testing on osx) ntpath.normpath (os.path on Windows) converts \ -> / and posixpath does not do the reverse. I'm not sure what os.path.normpath would fix. That's what I'd use to fix './foo/../bar'.
Right now the code replaces os.sep with '/' when os.sep is not '/'.
Tangentially, I think the more ideal way to reformat the path instead would be something like this and then to use posixpath once we've escaped the paths that actually refer to files.
path_parts = []
path = os.path.normpath(module_path)
while path:
path, tail = os.path.split(path)
path_parts.insert(0, tail)
module_path = posixpath.join(*path_parts)
But anyways, since I see the os.sep -> '/' in the code, does this bug still occur?