From 10382239a1ca1513db6f7f66d331a00dafcd068a Mon Sep 17 00:00:00 2001 From: xzyfer Date: Mon, 4 May 2015 11:58:09 +1000 Subject: [PATCH] Prioritize cwd when resolving load paths --- sass-graph.js | 10 +++------- test/fixtures/i.scss | 1 + test/test.js | 41 ++++++++++++++++++++++++++--------------- 3 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 test/fixtures/i.scss diff --git a/sass-graph.js b/sass-graph.js index b807d64..9f8ba8e 100644 --- a/sass-graph.js +++ b/sass-graph.js @@ -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 diff --git a/test/fixtures/i.scss b/test/fixtures/i.scss new file mode 100644 index 0000000..6560533 --- /dev/null +++ b/test/fixtures/i.scss @@ -0,0 +1 @@ +.g { color: strawberry; } diff --git a/test/test.js b/test/test.js index 1298af8..8905689 100644 --- a/test/test.js +++ b/test/test.js @@ -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']}); @@ -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 () {