Comparing version 0.1.2 to 0.2.0
@@ -15,3 +15,2 @@ var fs = require('fs'), | ||
exports.createBuilder = createBuilder; | ||
@@ -33,18 +32,41 @@ exports.create = createBuilder; | ||
var deps = result.dependencies, | ||
output = '', | ||
lazyEval = this.lazyEval; | ||
lazyEval = null, | ||
output = ''; | ||
output += Object.keys(deps).map(function(id) { | ||
if (this.lazyEval === true) { | ||
// if lazy-eval is true, all modules are lazy-evaled. | ||
if (lazyEval === true) { | ||
return this.toLazyEvalTransport(deps[id]); | ||
lazyEval = deps; | ||
} else if (this.lazyEval) { | ||
// Else `this.lazyEval` is an array of modules ids that | ||
// are to be lazy-evaled. Convert it to id/module object | ||
// pairs. | ||
var ids = this.lazyEval, | ||
modules = {}; | ||
for (var i = 0; i < ids.length; i++) { | ||
var id = ids[i], | ||
module = deps[id]; | ||
if (module) { | ||
modules[id] = module; | ||
} else { | ||
var err = new Error('lazyEval config option only accepts modules which are dependencies of "' + result.main + '". "' + id + '" is not.'); | ||
callback(err); | ||
return; | ||
} | ||
} | ||
// Else lazyEval is an array of modules that are to be lazy-evaled. | ||
if (lazyEval && lazyEval.indexOf(id) > -1) { | ||
return this.toLazyEvalTransport(deps[id]); | ||
// Find their dependencies. | ||
lazyEval = this.findScopedDependencies(modules); | ||
} | ||
result.lazyEval = lazyEval; | ||
for (var id in deps) { | ||
if (lazyEval && (id in lazyEval)) { | ||
output += this.toLazyEvalTransport(deps[id]); | ||
} else { | ||
output += this.toTransport(deps[id]); | ||
} | ||
return this.toTransport(deps[id]); | ||
}, this).join(''); | ||
} | ||
@@ -80,2 +102,35 @@ if (result.main) { | ||
p.findScopedDependencies = findScopedDependencies; | ||
function findScopedDependencies(modules) { | ||
var output = {}; | ||
for (var id in modules) { | ||
var module = modules[id], | ||
deps = module.getDependencies(); | ||
output[id] = module; | ||
for (var k in deps) { output[k] = deps[k]; } | ||
} | ||
// Loop over the collected modules. Eliminate those that were | ||
// not directly specified (i.e. not members of `modules`) | ||
// and which are required by modules which themselves aren't | ||
// members of `modules`. | ||
var modified = true; | ||
while (modified) { | ||
modified = false; | ||
for (var id in output) { | ||
var reqs = output[id].getRequirers(); | ||
for (var k in reqs) { | ||
if (!(k in output) && !(id in modules)) { | ||
modified = true; | ||
delete output[id]; | ||
} | ||
} | ||
} | ||
} | ||
return output; | ||
} | ||
p.escape = escape; | ||
@@ -82,0 +137,0 @@ function escape(str, inlineSafe) { |
42
main.js
@@ -14,3 +14,10 @@ var fs = require('fs'), | ||
moduleGrapher.graph(main, config, function(err, result) { | ||
err ? callback(err) : builder.create(config).build(result, callback); | ||
if (err) { | ||
callback(err) | ||
} else { | ||
builder.create(config).build(result, function(err, output) { | ||
log(result); | ||
callback(err, output); | ||
}); | ||
} | ||
}); | ||
@@ -36,9 +43,6 @@ } | ||
} else { | ||
var paths = []; | ||
if (json.builder_paths) { | ||
paths.push.apply(paths, json.builder_paths); | ||
} | ||
paths.push('.'); | ||
config.paths = paths; | ||
config.paths = json.builder_paths ? json.builder_paths : []; | ||
config.paths.push('.'); | ||
config.lazyEval = json.builder_lazy_eval_modules; | ||
config.isPackageAware = true; | ||
build(json.main, config, callback); | ||
@@ -49,2 +53,26 @@ } | ||
}); | ||
} | ||
function log(result) { | ||
console.log('Successfully resolved dependencies for module "'+ result.main + '".'); | ||
var d = result.resolvedAt - result.instantiatedAt; | ||
console.log('This took ' + d + ' ms.'); | ||
var modCountText = 'Found ' + result.getModuleCount() + ' module(s)'; | ||
if (result.getPackageCount) { | ||
console.log(modCountText + ' and '+ result.getPackageCount() + ' package(s).'); | ||
} else { | ||
console.log(modCountText + '.'); | ||
} | ||
if (result.lazyEval) { | ||
var modules = Object.keys(result.lazyEval).sort().join(', '); | ||
console.log('The following modules will be lazy-evaled: ' + modules + '.'); | ||
} | ||
var size = Math.round((result.getSize() / 1024) * 10) / 10; | ||
console.log('The total size is ' + size + ' kb unminified.'); | ||
console.log('There are', result.getLoc(), 'LOC and', result.getSloc(), 'SLOC.'); | ||
} |
@@ -5,5 +5,5 @@ { | ||
"main": "./main", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"dependencies": { | ||
"module-grapher" : ">=0.4.0" | ||
"module-grapher" : ">=0.5.0" | ||
}, | ||
@@ -10,0 +10,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12752
266
Updatedmodule-grapher@>=0.5.0