Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Filter out npm module from slim graph
Closes #730
- Loading branch information
Manuel Mujica
committed
Jun 6, 2017
1 parent
bf6691a
commit 4016dd0
Showing
6 changed files
with
65 additions
and
0 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,45 @@ | ||
var keys = require("lodash/keys"); | ||
var omit = require("lodash/omit"); | ||
var through = require("through2"); | ||
var assign = require("lodash/assign"); | ||
var includes = require("lodash/includes"); | ||
|
||
module.exports = function() { | ||
return through.obj(function(data, enc, done) { | ||
try { | ||
done(null, filterGraph(data)); | ||
} catch (err) { | ||
done(err); | ||
} | ||
}); | ||
}; | ||
|
||
var blackList = [ | ||
"npm", | ||
"npm-convert", | ||
"npm-crawl", | ||
"npm-extension", | ||
"npm-load", | ||
"npm-utils", | ||
"semver", | ||
"@dev" | ||
]; | ||
|
||
function filterGraph(data) { | ||
var visited = {}; | ||
var filtered = {}; | ||
var graph = data.graph; | ||
|
||
keys(graph).forEach(function visit(name) { | ||
// don't visit a node twice | ||
if (visited[name]) return; | ||
|
||
visited[name] = true; | ||
|
||
if (!includes(blackList, name)) { | ||
filtered[name] = graph[name]; | ||
} | ||
}); | ||
|
||
return assign({}, omit(data, "graph"), { graph: filtered }); | ||
} |
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 @@ | ||
module.exports = function() {}; |
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 @@ | ||
var foo = require("./foo"); | ||
|
||
foo(); |
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,6 @@ | ||
{ | ||
"name": "npm", | ||
"main": "main", | ||
"version": "0.0.1", | ||
"dependencies": {} | ||
} |
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