Skip to content
This repository was archived by the owner on Oct 2, 2020. It is now read-only.

Respect less includePaths if specified in .compilerc #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

achingbrain
Copy link

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.

@anaisbetts
Copy link
Contributor

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

@achingbrain
Copy link
Author

achingbrain commented May 15, 2017

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
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants