sass / node-sass

:rainbow: Node.js bindings to libsass
https://npmjs.org/package/node-sass
MIT License
8.51k stars 1.32k forks source link

Imported files outside the source directory built when changed in watch mode #2491

Open paulcpederson opened 6 years ago

paulcpederson commented 6 years ago

I have a fix for this, will try to pr shortly. It's kind of an edge case, but replication is fairly straight forward.

Assume we have the following file tree:

src/
  file1.scss
  file2.scss
dist/
library/
  include.scss

And file1 imports the library, like this:

@import "library/include";

We build all the sass files in src/ with the CLI using node-sass src/ -o dist/. This works correctly. If, we watch for changes and change the files in src, it also still works correctly.

But if we change library/include.scss, the CLI will build a new file at library/include.css. Then, node-sass will throw an error:

It's not clear which file to import for '@import "library/include". 
Candidates:
    library/include.scss
    library/include.css

Even though it is outside the source directory, it's included in the watched files, and because it doesn't have an underscore preceding it's name, we render it to the default location (right next to itself).

The fix is pretty simple, basically when using a directory for multiple file compilation, when files change, check that they are actually inside the directory before rendering. I added multiple file compilation once upon a time so this is mostly my fault 😬 I'll try to get a pr for this fix in soon.


paulcpederson commented 6 years ago

pr submitted

swervo commented 6 years ago

I think I may be seeing a related issue. My command:

node-sass --include-path 'node_modules/@salesforce-ux/design-system/scss' --source-map true sass/ -wo app/styles

has started hanging. If I run the same command without the -w flag it completes correctly. I'm guessing it is trying to compile files outside of the source directory - maybe in the include path?

I'm sorry I can't be more precise here. If you can give me a hint how I can diagnose this more effectively I'm happy to do this.

node -v 8.12.0 npm -v 6.4.1


node-sass       4.9.3   (Wrapper)       [JavaScript]
libsass         3.5.4   (Sass Compiler) [C/C++]```
paulcpederson commented 6 years ago

@swervo if you point node-sass in your package.json to paulcpederson/node-sass#watch-directory and npm install again does the command work?

swervo commented 6 years ago

@paulcpederson I tried that. It's the same. I think I am seeing a different problem. Here are the symptoms that I'm seeing with both your version and the node-sass 4.9.3:

Apologies if I've taken you off track.