Skip to content

Commit

Permalink
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
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/build/slim.js
Expand Up @@ -7,6 +7,7 @@ var streams = {
concat: require("../bundle/concat_slim_bundle"),
addModuleIds: require("../stream/add_module_ids"),
addBundleIds: require("../stream/add_bundle_ids"),
filterGraph: require("../stream/filter_slim_graph"),
write: require("../bundle/write_bundles").createWriteStream,
graph: require("../graph/make_graph_with_bundles").createBundleGraphStream
};
Expand All @@ -23,6 +24,7 @@ module.exports = function(config, options) {
return new Promise(function(resolve, reject) {
var writeSteam = pump(
streams.graph(config, options),
streams.filterGraph(),
streams.addModuleIds(),
streams.transpile({ outputFormat: "slim" }),
streams.bundle(),
Expand Down
45 changes: 45 additions & 0 deletions lib/stream/filter_slim_graph.js
@@ -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 });
}
1 change: 1 addition & 0 deletions test/slim/npm/foo.js
@@ -0,0 +1 @@
module.exports = function() {};
3 changes: 3 additions & 0 deletions test/slim/npm/main.js
@@ -0,0 +1,3 @@
var foo = require("./foo");

foo();
6 changes: 6 additions & 0 deletions test/slim/npm/package.json
@@ -0,0 +1,6 @@
{
"name": "npm",
"main": "main",
"version": "0.0.1",
"dependencies": {}
}
8 changes: 8 additions & 0 deletions test/slim_build_test.js
Expand Up @@ -81,4 +81,12 @@ describe("slim builds", function() {
close();
});
});

it("can build apps using npm plugin", function() {
var options = { quiet: true };
var base = path.join(__dirname, "slim", "npm");
var config = { config: path.join(base, "package.json!npm") };

return slim(config, options);
});
});

0 comments on commit 4016dd0

Please sign in to comment.