lessphp
lessphp copied to clipboard
Imports on relative paths with symlinks don't behave the same way as node.js lessc
Node.js lessc resolves the relative paths without checking for symlinks, in PHP (or any *nix based system) resolves the symlinks as it resolves the relative paths.
For example:
/code/less --symlink-to-> /other_path/foo/bar/less
if we compile /code/less/main.less that contains @import "../less2/bar.less" node.js lessc is going to import the file in /code/less2/bar.less but in lessphp is going to import /other_path/foo/less2/bar.less.
In there a reason why it doesn't follow symlinks?
Not sure, but it seems that the node.js implementation is handling the paths like an url. So it solves the relative part first and then sends it to to the filesystem.
In the previous example node.js transforms /code/less/../less2/bar.less to /code/less2/bar.less and then sends it to the OS instead of making the OS figure it out on his own.
This is what I found checking node.js source code: https://github.com/joyent/node/blob/master/lib/fs.js#L1013.
It seems that they using path.normalize but I couldn't find when node.js is using it. If they do it would explain the behaviour differences. For LessPHP to be a drop in replacement for Node.js less compiler, I think it's going to need to resolve paths before opening the files.
Nice find. Well, this is unfortunately complicated :)
If anything this seems like a bug in node.js's real path, not a feature.
Not sure if it's a bug, just different behaviour of the platform. If drop-in replacement of Node.js lessc is not part of lessphp's goals I'm going to close this issue (maybe add a comment about it somewhere).
I'm going to keep the issue open for now until I decide what I am going to do.
+1