lessphp icon indicating copy to clipboard operation
lessphp copied to clipboard

Imports on relative paths with symlinks don't behave the same way as node.js lessc

Open fran6co opened this issue 13 years ago • 7 comments
trafficstars

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.

fran6co avatar Aug 22 '12 13:08 fran6co

In there a reason why it doesn't follow symlinks?

leafo avatar Aug 22 '12 15:08 leafo

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.

fran6co avatar Aug 22 '12 16:08 fran6co

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.

fran6co avatar Aug 22 '12 16:08 fran6co

Nice find. Well, this is unfortunately complicated :)

If anything this seems like a bug in node.js's real path, not a feature.

leafo avatar Aug 22 '12 17:08 leafo

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).

fran6co avatar Aug 22 '12 17:08 fran6co

I'm going to keep the issue open for now until I decide what I am going to do.

leafo avatar Aug 22 '12 17:08 leafo

+1

roytruelove avatar Jan 29 '16 00:01 roytruelove