Skip to content

Commit

Permalink
Prioritize cwd when resolving load paths
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer committed May 4, 2015
1 parent 7d1b9ca commit 1038223
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
10 changes: 3 additions & 7 deletions sass-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,10 @@ Graph.prototype.addFile = function(filepath, parent) {
var imports = parseImports(fs.readFileSync(filepath, 'utf-8'));
var cwd = path.dirname(filepath);

var i, length = imports.length;
var i, length = imports.length, loadPaths, resolved;
for (i = 0; i < length; i++) {
[this.dir, cwd].forEach(function (path) {
if (path && this.loadPaths.indexOf(path) === -1) {
this.loadPaths.push(path);
}
}.bind(this));
var resolved = resolveSassPath(imports[i], _.uniq(this.loadPaths));
loadPaths = _([cwd, this.dir]).concat(this.loadPaths).filter().uniq().value();
resolved = resolveSassPath(imports[i], loadPaths, this.extensions);
if (!resolved) continue;

// recurse into dependencies if not already enumerated
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/i.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.g { color: strawberry; }
41 changes: 26 additions & 15 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ var path = require("path");

var fixtures = path.resolve("test/fixtures");
var files = {
'a.scss': fixtures + "/a.scss",
'b.scss': fixtures + "/b.scss",
'_c.scss': fixtures + "/_c.scss",
'd.scss': fixtures + "/d.scss",
'_e.scss': fixtures + "/components/_e.scss",
'f.scss': fixtures + "/f.scss",
'g.scss': fixtures + "/g.scss",
'_h.scss': fixtures + "/nested/_h.scss",
'_i.scss': fixtures + "/nested/_i.scss",
'j.scss': fixtures + "/j.scss",
'k.l.scss': fixtures + "/components/k.l.scss",
'm.scss': fixtures + "/m.scss",
'_n.scss': fixtures + "/compass/_n.scss",
'_compass.scss': fixtures + "/components/_compass.scss"
'a.scss': fixtures + '/a.scss',
'b.scss': fixtures + '/b.scss',
'_c.scss': fixtures + '/_c.scss',
'd.scss': fixtures + '/d.scss',
'_e.scss': fixtures + '/components/_e.scss',
'f.scss': fixtures + '/f.scss',
'g.scss': fixtures + '/g.scss',
'_h.scss': fixtures + '/nested/_h.scss',
'_i.scss': fixtures + '/nested/_i.scss',
'i.scss': fixtures + '/_i.scss',
'j.scss': fixtures + '/j.scss',
'k.l.scss': fixtures + '/components/k.l.scss',
'm.scss': fixtures + '/m.scss',
'_n.scss': fixtures + '/compass/_n.scss',
'_compass.scss': fixtures + '/components/_compass.scss'
}

describe('sass-graph', function(){
var sassGraph = require("../sass-graph");
var sassGraph = require('../sass-graph');

describe('parsing a graph of all scss files', function(){
var graph = sassGraph.parseDir(fixtures, {loadPaths: [fixtures + '/components']});
Expand Down Expand Up @@ -59,6 +60,16 @@ describe('sass-graph', function(){
})
assert.deepEqual([files['b.scss'], files['a.scss']], ancestors);
});

it('should prioritize cwd', function() {
var expectedDescendents = [files['_i.scss']];
var descendents = [];

graph.visitDescendents(files['_h.scss'], function (imp) {
descendents.push(imp);
assert.notEqual(expectedDescendents.indexOf(imp), -1);
});
});
})

describe('parseFile', function () {
Expand Down

0 comments on commit 1038223

Please sign in to comment.