Open achingbrain opened 7 years ago
I like the general idea of this patch, but I'm not sure about the actual logic - why the find
and fs.existsSync
?
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?
@paulcbetts any further comments on this or can it be merged?
I have a .less file,
/me/project/foo.less
that looks like this:ace-css
is present in thenode_modules
folder, so I configure.compilerc
as so: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: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.