Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sass-graph for accurate sass watching #629

Merged
merged 1 commit into from
Jan 15, 2015

Conversation

xzyfer
Copy link
Contributor

@xzyfer xzyfer commented Jan 15, 2015

Problem

The watcher is broken. So very broken. Two major problems with it

  • it compiles files starting with underscores (_) which is a big no-no
  • it has no awareness of the the import graph

Assuming the following directory structure

src
|--foo.scss
|--bar.scss
|-- components
   |-- _baz.scss

where foo.scss and bar.scss, and running the following command node-sass -w -r --output dist src.

A modification to src/components/_baz.scss should not compile _baz.scss. It should traverse the import graph and compile dist/foo.css and dist/bar.css.

This is how the native sass watcher works.

Solution

Use sass-graph to build an in memory graph of the @imports to determine the correct compilation targets for a modified file.

I believe this is the issue at the heart of #157.

@xzyfer xzyfer force-pushed the feat/better-watcher-compilation-targets branch from bf0d744 to 030f8cc Compare January 15, 2015 05:07
@am11
Copy link
Contributor

am11 commented Jan 15, 2015

This is super awesome. 👍

Considering this request: #590, I didn't knew something like sass-graph existed! 😄 I think node-sass should not expose this functionality (or expose the show-graph feature) to its API. That would be against the laws of DRY (especially now where have package referenced here).

@xzyfer
Copy link
Contributor Author

xzyfer commented Jan 15, 2015

I didn't knew something like sass-graph existed

It didn't really til today...

@xzyfer xzyfer force-pushed the feat/better-watcher-compilation-targets branch from 030f8cc to 91d26b8 Compare January 15, 2015 05:14
@browniefed
Copy link

@xzyfer any idea how it will play with custom importers in 2.0?
I can imagine that people will write some compass stuff to process Sprites, or other arbitrary things that aren't true file paths.

@xzyfer
Copy link
Contributor Author

xzyfer commented Jan 15, 2015

I think node-sass should not expose this functionality (or expose the show-graph feature) to its API.

I've isolated this functionality explicitly to the watch function in the cli. The graph doesn't even exist until you being watch so there shouldn't be any leakage.

@am11
Copy link
Contributor

am11 commented Jan 15, 2015

oOo.. Did you release it today for the first time? I saw old PRs in your repo, thought it out there for a while.. :)

@xzyfer
Copy link
Contributor Author

xzyfer commented Jan 15, 2015

@browniefed sass-graph currently follows the native sass model. It'll walk imports, if the file exists on disk in an include path it's be added to an in memory graph. That graph is then used to find the collection or top-most ancestors which should be re-compiled.

ATM it has no knowledge of custom importers.

@browniefed
Copy link

@xzyfer I guess I was implying it'd be cool if it could accept an importer, likely the same one that would be used for node-sass, so both things could pair up in terms of custom importer logic.

@am11
Copy link
Contributor

am11 commented Jan 15, 2015

Can we take the *cookie approach here as well to save the require('path/to/my-importer.js') object in graph?

Or if it is not possible to retain the JS object, then perhaps function-to-string approach: require('path/to/my-importer.js').toString() and eval it before usage.

@xzyfer
Copy link
Contributor Author

xzyfer commented Jan 15, 2015

@am11 It's been in various stages of development for a while, but I released 1.0.0 a couple hours ago in preparation for getting it into node-sass for my dev team :)

@xzyfer
Copy link
Contributor Author

xzyfer commented Jan 15, 2015

Custom importers may very well be possible in future versions.

@am11
Copy link
Contributor

am11 commented Jan 15, 2015

On second thought, we may only want to store the path to custom importer in graph and then re-require it in watch even handler. (whichever approach is elegant).

Yes the importers can certainly wait, since you might like to consider providing room for the future "custom functions" as well (which will behave the same way, except there will by a multiplicity factor -- spoiler alert!!). :)

@xzyfer xzyfer force-pushed the feat/better-watcher-compilation-targets branch 2 times, most recently from b7f9e0a to 81f76fc Compare January 15, 2015 07:03
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 81f76fc on xzyfer:feat/better-watcher-compilation-targets into c9e3eaa on sass:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 81f76fc on xzyfer:feat/better-watcher-compilation-targets into c9e3eaa on sass:master.

@xzyfer
Copy link
Contributor Author

xzyfer commented Jan 15, 2015

aha! CI is passing :D 🎉

@@ -139,6 +139,8 @@ describe('cli', function() {

bin.stderr.setEncoding('utf8');
bin.stderr.on('data', function(data) {
console.log('=> changed: ' + src);
console.log(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be rebased out. :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in a35326a

@xzyfer xzyfer force-pushed the feat/better-watcher-compilation-targets branch from 81f76fc to a35326a Compare January 15, 2015 07:12
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling a35326a on xzyfer:feat/better-watcher-compilation-targets into c9e3eaa on sass:master.

@am11
Copy link
Contributor

am11 commented Jan 15, 2015

🎉

Feel free to merge it whenever you think this is ready.

Maybe we can set sass-graph to ^1.0.1 in package.json.

@xzyfer xzyfer force-pushed the feat/better-watcher-compilation-targets branch from a35326a to fa13e98 Compare January 15, 2015 07:22
@xzyfer
Copy link
Contributor Author

xzyfer commented Jan 15, 2015

Maybe we can set sass-graph to ^1.0.1 in package.json.

I generally give npm the benefit of the doubt but better safe than sorry. I've update this. When all the builds pass I'll give it a run on my local Libsass 3.2.0 fork then ship it.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling fa13e98 on xzyfer:feat/better-watcher-compilation-targets into c9e3eaa on sass:master.

@xzyfer
Copy link
Contributor Author

xzyfer commented Jan 15, 2015

Works amazingly! Are those AppVeyor failures expected?

@am11
Copy link
Contributor

am11 commented Jan 15, 2015

Yup! :)

xzyfer added a commit that referenced this pull request Jan 15, 2015
…argets

Use sass-graph for accurate sass watching
@xzyfer xzyfer merged commit 604ccf5 into sass:master Jan 15, 2015
@xzyfer
Copy link
Contributor Author

xzyfer commented Jan 15, 2015

🎉 🚀

@xzyfer xzyfer deleted the feat/better-watcher-compilation-targets branch January 15, 2015 13:02
@am11
Copy link
Contributor

am11 commented Jan 15, 2015

Yay! :)

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

Successfully merging this pull request may close these issues.

None yet

4 participants