cowboyd/less.rb — Issue #13: lessc fails to respect relative @import blocks when invoked with an abs. path
Author: rfkrocktk
Created: 2011-11-17 17:24:21+00:00
State: open

The best way to explain this is to demonstrate it. As noted in [this issue in another project](https://github.com/cyberdelia/django-pipeline/issues/45#issuecomment-2778646) which uses `lessc` provided here, `lessc` won't respect relative paths with the `@import` statement when invoked with an absolute path:

$ lessc /home/rfkrocktk/Desktop/myproject/src/myproject/web/static/styles/application.less
/var/lib/gems/1.8/gems/less-2.0.7/lib/less/loader.rb:46:in `error': file 'bootstrap-1.4/bootstrap.less' wasn't found. (Less::ParseError)
from at Function.importer (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/index.js:114:13)
from at Object.push (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:73:25)
from at Object. (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/tree/import.js:30:17)
from at Object.import (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:953:28)
from at $ (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:103:24)
from at Object.directive (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:967:29)
from at $ (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:103:24)
from at Object.primary (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:428:80)
from at $ (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:103:24)
from at Object.parse (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:264:42)
from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:65:in `parse'
from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:13:in `calljs'
from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:27:in `lock'
from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:25:in `lock'
from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:12:in `calljs'
from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:63:in `parse'
from /var/lib/gems/1.8/gems/less-2.0.7/bin/lessc:22
from /usr/local/bin/lessc:19:in `load'
from /usr/local/bin/lessc:19

However, if I invoke it from the current directory, it works fine:

( cd /home/rfkrocktk/Desktop/myproject/src/myproject/web/static/styles && lessc application.less )

Evidently, it's not resolving paths relative to the target file, but relative to the directory in which `lessc` is invoked.