electron-compilers icon indicating copy to clipboard operation
electron-compilers copied to clipboard

Respect less includePaths if specified in .compilerc

Open achingbrain opened this issue 8 years ago • 3 comments

I have a .less file, /me/project/foo.less that looks like this:

@import (css, inline) 'ace-css/css/ace.css';
//... some other stuff

ace-css is present in the node_modules folder, so I configure .compilerc as so:

{
  "env": {
    "development": {
      // ...
      "text/less": {
        "paths": [
          "./node_modules"
        ]
      // ...

The file is compiled and placed into the cache. Problem is the dependentFiles field of the cache entry for /me/project/foo.less looks like this:

{
// ...
  "dependentFiles": [
    "/me/project/ace-css/css/ace.css"
  ]
// ...
}

So the next time /me/project/foo.less is requested, everything explodes because /me/project/ace-css/css/ace.css does not exist.

The change in this PR is to look through the paths specified in the .compilerc file when working out the paths to dependent files before placing them into the cache.

achingbrain avatar May 10 '17 13:05 achingbrain

I like the general idea of this patch, but I'm not sure about the actual logic - why the find and fs.existsSync?

anaisbetts avatar May 13 '17 20:05 anaisbetts

Sorry that it's not clear.

Let's say my project has a file layout something like this:

my-project
|── node_modules
|   └─ foo.css
|── shared
|   └─ bar.css
|── client
|   └─ baz.css
└─ .compilerc

In client/baz.css I do this:

@import (css, inline) 'foo.css';
@import (css, inline) 'bar.css';

In my .compilerc I set up the paths for less to contain both folders I'm trying to import from:

{
  "env": {
    "development": {
      // ...
      "text/less": {
        "paths": [
          "./node_modules",
          "./shared"
        ]
      // ...

Taking bar.css as an example, obviously we don't want to import node_modules/bar.css because it doesn't exist so the change I have made first creates a list of where the dependencies could live - paths:

node_modules/bar.css
shared/bar.css

It then uses the find and existsSync to return the first file in the list that exists:

shared/bar.css

At the moment if the file does not exist it will silently ignore it, perhaps it should throw an error?

achingbrain avatar May 15 '17 08:05 achingbrain

@paulcbetts any further comments on this or can it be merged?

achingbrain avatar Jun 09 '17 15:06 achingbrain