fourseven/meteor-scss — pull request #35 by rdickert (2014-08-06 01:34:44+00:00)
Title: Import globbing (@import "*")

Having to specify exact paths to imported sass partials doesn't feel very meteoric:

//...after importing variables used by the partials below

// Views
@import "../views/accounts/accounts";
@import "../views/gameBoard/gameBoard";
@import "../views/gameManagement/gameLists";

It's a hassle, and it's fragile - you have to update the master file every time you add or move a file; but you still need to do it that way if you want to be able to use app-wide variables and mix-ins. Wouldn't it be nicer if you could use globbing:

// Views
@import "../views/**/*"; //globstar `**` matches files in all subdirectories

Well, that's what I thought. With globbing, you could add partials to your heart's content and have them just show up the same way they would if you were using regular css with Meteor. I was going to ask what it would take to add it, but instead I ended up making this PR.

There is a [sass-globbing](https://github.com/chriseppstein/sass-globbing) Ruby module, but it doesn't appear to be implented in node-sass yet. Rather than wait for it, we can glob things ourselves. This involves scanning the files that do the importing and expanding their targets. The implementation basically looks at `@import "../views/**/*";` and makes an `@import` statement for each glob result as shown in the code at the top, inserting it at the same place in the file. It then passes the parsed file, rather than the filename, to node-sass for compilation. It will ignore urls, and although it will expand commented-out imports, they will remain commented out, and import targets (such as `@import "screen.scss" screen;`) are also preserved. [Nested @imports](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#nested-import) should also have no problem. Globbing is performed by the [node glob module](https://github.com/isaacs/node-glob) and supports globstars like shown above, which will recursively match files down the directory tree. It also lets you leave off the underscore and the file extension in the `@import` statement as you normally can in scss.

@fourseven, have a look and see what you think. The implementation of this currently has globbing always on (although it shouldn't have any effect if you don't use globs). It's not highly tested, and it currently only works on scss files, not sass. If you are interested in this, I'd be up for making improvements and adding tests to the code. I don't really expect this to be very expensive from a performance perspective, but we are parsing files and there's a chance it might add up on a project with many large files (the number of partials is not relevant, though, as partials still aren't scanned). The code has a lot of comments, including a couple of XXX comments where things are a bit hacky/in need of further thought.

Some options: Globbing could be made optional (perhaps specify in scss.json or set up the globbing part as a separate smart package). If you like the separate package idea, I'd just need to be able to hook in and replace the filename with the parsed file. You can see there are very few changes to `compile-scss.js`.