UNPKG

731 BJavaScriptView Raw
1var max = require("lodash/max");
2var through = require("through2");
3var isArray = require("lodash/isArray");
4
5module.exports = function() {
6 return through.obj(function(data, enc, next) {
7 try {
8 next(null, addBundleIds(data));
9 } catch (err) {
10 next(err);
11 }
12 });
13};
14
15function getModuleIds(graph) {
16 if (isArray(graph)) {
17 return graph.forEach(function(node) {
18 return node.load.uniqueId;
19 });
20 } else {
21 return Object.keys(graph).map(function(name) {
22 return graph[name].load.uniqueId;
23 });
24 }
25}
26
27function addBundleIds(data) {
28 var graph = data.graph;
29
30 var maxModuleId = max(getModuleIds(graph));
31
32 data.bundles.forEach(function(bundle, index) {
33 bundle.uniqueId = maxModuleId + index + 1;
34 });
35
36 return data;
37}