This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple the graph and render logic from the fs watcher (#2020)
This logic is all tightly coupled in the bin. This logic has been notoriously impossible to test due to weird fs timing issues. By extracting the actual logic we're now able to test it in isolation. With this in place replacing Gaze (#636) becomes a viable option. This PR not only massively increases our test coverage for the watcher but also address a bunch of known edge cases i.e. orphaned imports when a files is deleted. Closes #1896 Fixes #1891
- Loading branch information
Showing
11 changed files
with
327 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var grapher = require('sass-graph'), | ||
clonedeep = require('lodash.clonedeep'), | ||
config = {}, | ||
watcher = {}, | ||
graph = null; | ||
|
||
watcher.reset = function(opts) { | ||
config = clonedeep(opts || config || {}); | ||
var options = { | ||
loadPaths: config.includePath, | ||
extensions: ['scss', 'sass', 'css'] | ||
}; | ||
|
||
if (config.directory) { | ||
graph = grapher.parseDir(config.directory, options); | ||
} else { | ||
graph = grapher.parseFile(config.src, options); | ||
} | ||
|
||
return Object.keys(graph.index); | ||
}; | ||
|
||
watcher.changed = function(absolutePath) { | ||
var files = { | ||
added: [], | ||
changed: [], | ||
removed: [], | ||
}; | ||
|
||
this.reset(); | ||
|
||
graph.visitAncestors(absolutePath, function(parent) { | ||
files.changed.push(parent); | ||
}); | ||
|
||
graph.visitDescendents(absolutePath, function(child) { | ||
files.added.push(child); | ||
}); | ||
|
||
return files; | ||
}; | ||
|
||
watcher.added = function(absolutePath) { | ||
var files = { | ||
added: [], | ||
changed: [], | ||
removed: [], | ||
}; | ||
|
||
this.reset(); | ||
|
||
if (Object.keys(graph.index).indexOf(absolutePath) !== -1) { | ||
files.added.push(absolutePath); | ||
} | ||
|
||
graph.visitDescendents(absolutePath, function(child) { | ||
files.added.push(child); | ||
}); | ||
|
||
return files; | ||
}; | ||
|
||
watcher.removed = function(absolutePath) { | ||
var files = { | ||
added: [], | ||
changed: [], | ||
removed: [], | ||
}; | ||
|
||
graph.visitAncestors(absolutePath, function(parent) { | ||
files.changed.push(parent); | ||
}); | ||
|
||
if (Object.keys(graph.index).indexOf(absolutePath) !== -1) { | ||
files.removed.push(absolutePath); | ||
} | ||
|
||
this.reset(); | ||
|
||
return files; | ||
}; | ||
|
||
module.exports = watcher; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import "partials/one"; | ||
|
||
.one { | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.one { | ||
color: darkred; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.three { | ||
color: darkgreen; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.two { | ||
color: darkblue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import "partials/two"; | ||
|
||
.two { | ||
color: blue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.three { | ||
color: darkgreen; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import "partials/three"; | ||
|
||
.three { | ||
color: green; | ||
} |
Oops, something went wrong.
@xzyfer this is seems to be missing from the refactored version (
gaze.add(child)
in the on.changed graph.visitDescendents) Maybe it's what's causing the watchers to still fail?