Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

lessc fails to respect relative @import blocks when invoked with an abs. path #13

Closed
rfkrocktk opened this Issue · 9 comments

7 participants

@rfkrocktk

The best way to explain this is to demonstrate it. As noted in this issue in another project 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.<anonymous> (/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.

application.less above simply contains one line:

@import bootstrap-1.4/bootstrap.less

which exists in the bootstrap-1.4 folder in the same directory as application.less.

@Natim

I also have this issue, it would be great if lessc return a warning saying that the file coun't be found.

@kares
Collaborator

I think I might have fixed this as a side effect of my updates towards JRuby compatibility.
could any of you try building the gem from https://github.com/kares/less.rb if it behaves the same ?

@rfkrocktk

How can I build the gem? I'm sorry, I'm kind of new to building gems in Ruby :)

@kares
Collaborator

with bundler in a Gemfile change: gem 'less.rb', :git => 'git://github.com/kares/less.rb.git'
and then bundle install
otherwise clone the repo, cd to it and gem build less.gemspec the gem will be baked in your cwd ...
then install the gem gem install less-2.0.7.gem

@rfkrocktk

So, what command should I run? I'm on Linux.

gem 'less.rb', :git >= 'git://github.com/kares/less.rb.git'

fails to run.

@raldred

This issue still exists in 2.0.9
Changing the dir of the less file before compiling is the only solution at the moment

@diafygi

If you need to include this in bash scripts, I wrap the lessc command with cd commands

Example:

WORKING_PATH=/path/to/working
LESS_PATH=/path/to/less
CSS_PATH=$LESS_PATH
cd $LESS_PATH && lessc myfile.less > $CSS_PATH/myfile.css && cd $WORKING_PATH
@rbu

a fix for this is in pull req #22, please merge this. issue still exists in 2.2.1. lessc from the npm does the right thing, which makes the ruby gem unsuitable as a drop-in replacement.

@kares
Collaborator

@rbu if you want to help try providing a failing spec, I've looked at the fix but there's no spec either + I'm guessing it should be reproducable without lessc as well ? if so than the fix should happen elsewhere since it will still fail when compiled using the API ...

@cowboyd cowboyd closed this issue from a commit
@kares kares bin/lessc more compatible with the JS version
- the main incompatibility being not supporting output to be specified as the node version does `lessc input.less output.css` we accept arbitrary (due backward compatibility but also to avoid confusion) input files and currently always print the output
- fixes #13 and #33 (makes #22 obsolete)
f910958
@cowboyd cowboyd closed this in f910958
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.