Socket
Socket
Sign inDemoInstall

webpack

Package Overview
Dependencies
Maintainers
1
Versions
837
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack - npm Package Compare versions

Comparing version 0.6.2 to 0.7.0-beta

lib/buildModule.js

34

bin/webpack.js

@@ -59,2 +59,6 @@ #!/usr/bin/env node

.boolean("profile")
.describe("profile", "Capture timings for modules")
.default("profile", false)
.string("alias")

@@ -71,6 +75,9 @@ .describe("alias", "Set a alias name for a module. ex. http=http-browserify")

.string("watch-delay")
.describe("watch-delay", "Timeout to wait for the last change")
.default("watch", false)
.boolean("workers")
.describe("workers", "Use worker processes to be faster (BETA)")
.default("workers", false)
.boolean("progress")

@@ -127,4 +134,12 @@ .describe("progress", "Displays a progress while compiling")

if(argv.workers) {
options.workers = true;
}
if(argv.profile) {
options.profile = true;
}
if(argv["watch-delay"]) {
options.watchDelay = parseInt(argv["watch-delay"], 10);
options.watchDelay = argv["watch-delay"];
}

@@ -170,13 +185,21 @@

var nextUpdate = 0;
var sum = 0;
var finished = 0;
var chars = 0;
function print() {
function print(force) {
if(!force && nextUpdate > new Date().getTime()) return;
nextUpdate = new Date().getTime() + 100;
var msg = "";
if(sum > 0) {
var precentage = Math.floor(finished*100/sum);
msg += "compiling... (" + c("\033[1m\033[33m");
msg += sprintf("%4s", finished+"") + "/" + sprintf("%4s", sum+"");
msg += " " + sprintf("%4s", Math.floor(finished*100/sum)+"%");
msg += " " + sprintf("%4s", precentage+"%");
msg += c("\033[39m\033[22m") + ")";
for(var i = 0; i < Math.floor(precentage/2); i++)
msg += "#";
}
for(var i = msg.length; i < chars; i++)
msg += " ";
for(var i = 0; i < chars; i++)

@@ -198,2 +221,3 @@ process.stderr.write("\b");

chars = 0;
return print(true);
}

@@ -218,3 +242,3 @@ print();

if(argv.json)
console.log(JSON.stringify(stats));
console.log(JSON.stringify(stats, null, 2));
else {

@@ -221,0 +245,0 @@ console.log(formatOutput(stats, {

33

bm.js

@@ -8,3 +8,3 @@ /*

var TIMES = 5;
var TIMES = 2;

@@ -31,13 +31,18 @@ /* TESTS */

Object.keys(testCases).forEach(function(name) {
TESTS[name + " "] = runWebpack.bind(null, name, testCases[name], false, false, false);
TESTS[name + " single "] = runWebpack.bind(null, name, testCases[name], true, false, false);
TESTS[name + " debug "] = runWebpack.bind(null, name, testCases[name], false, true, false);
TESTS[name + " single debug "] = runWebpack.bind(null, name, testCases[name], true, true, false);
TESTS[name + " min"] = runWebpack.bind(null, name, testCases[name], false, false, true );
TESTS[name + " single min"] = runWebpack.bind(null, name, testCases[name], true, false, true );
TESTS[name + " debug min"] = runWebpack.bind(null, name, testCases[name], false, true, true );
TESTS[name + " single debug min"] = runWebpack.bind(null, name, testCases[name], true, true, true );
TESTS[name + " "] = runWebpack.bind(null, name, testCases[name], false, false, false, false);
TESTS[name + " workers"] = runWebpack.bind(null, name, testCases[name], false, false, false, true);
TESTS[name + " single "] = runWebpack.bind(null, name, testCases[name], true, false, false, false);
TESTS[name + " single workers"] = runWebpack.bind(null, name, testCases[name], true, false, false, true);
TESTS[name + " debug "] = runWebpack.bind(null, name, testCases[name], false, true, false, false);
TESTS[name + " debug workers"] = runWebpack.bind(null, name, testCases[name], false, true, false, true);
TESTS[name + " single debug "] = runWebpack.bind(null, name, testCases[name], true, true, false, false);
TESTS[name + " single debug workers"] = runWebpack.bind(null, name, testCases[name], true, true, false, true);
TESTS[name + " min "] = runWebpack.bind(null, name, testCases[name], false, false, true , false);
TESTS[name + " min workers"] = runWebpack.bind(null, name, testCases[name], false, false, true , true);
TESTS[name + " single min "] = runWebpack.bind(null, name, testCases[name], true, false, true , false);
TESTS[name + " single min workers"] = runWebpack.bind(null, name, testCases[name], true, false, true , true);
});
function runWebpack(name, file, single, debug, min, cb) {
var workers = new (require("./lib/Workers"))(path.join(__dirname, "lib", "buildModuleFork.js"), require("os").cpus().length)
function runWebpack(name, file, single, debug, min, withWorkers, cb) {
webpack(file, {

@@ -47,3 +52,5 @@ output: path.join(root, "js", "bm", name.trim() + ".js"),

debug: debug,
minimize: min
minimize: min,
workers: withWorkers && workers,
closeWorkers: false
}, cb);

@@ -66,3 +73,5 @@ }

});
}, function() {});
}, function() {
workers.close();
});

@@ -69,0 +78,0 @@ /* HELPERS */

@@ -8,2 +8,3 @@ /*

var execLoaders = require("enhanced-require/lib/execLoaders");
var buildModule = require("./buildModule");
var fs = require("fs");

@@ -98,5 +99,20 @@ var path = require("path");

function addModule(depTree, context, modu, options, reason, finalCallback) {
var profile = options.profile && {
start: new Date()
};
options.events.emit("task");
function callback(err, result) {
options.events.emit("task-end");
if(profile && profile.module) {
profile.end = new Date();
profile.module.profile = {
time: profile.end - profile.start,
timeResolve: profile.resolveEnd - profile.start,
timeResolvePrePostLoaders: profile.resolvePrePostLoadersEnd - profile.resolveEnd,
timeLoadersCheck: profile.loadersCheckEnd - profile.resolvePrePostLoadersEnd,
timeBuildModule: profile.buildModuleEnd - profile.loadersCheckEnd,
timeChildren: profile.end - profile.buildModuleEnd
}
}
finalCallback(err, result);

@@ -117,2 +133,3 @@ }

} else {
profile && (profile.resolveEnd = new Date());
// create a new module

@@ -126,2 +143,4 @@ var modu = depTree.modules[filename] = {

profile && (profile.module = modu);
// split the loaders from the require

@@ -131,3 +150,2 @@ var filenameWithLoaders = filename;

filename = loaders.pop();
options.events.emit("module", modu, filename);

@@ -137,4 +155,9 @@ if(options.cache) {

if(err) return readFile();
if(profile) {
profile.buildModuleEnd = profile.loadersCheckEnd = profile.resolvePrePostLoadersEnd = new Date()
}
modu.fromCache = true;
cachedData = JSON.parse(cachedData);
modu.dependencies = cachedData.dependencies;
modu.loaders = cachedData.loaders;
processParsedJs(cachedData.source, cachedData.deps);

@@ -147,34 +170,57 @@ });

// [this step is cached]
var cacheEntry;
function readFile() {
cacheEntry = options.cache && options.cache.create(filenameWithLoaders);
// read file content
if(cacheEntry) cacheEntry.add(filename);
fs.readFile(filename, function(err, content) {
if(err) {
callback(err);
return;
}
var preLoaders = options.preLoaders ? matchLoadersList(options.preLoaders) : "";
var postLoaders = options.postLoaders ? matchLoadersList(options.postLoaders) : "";
var preLoaders = options.preLoaders ? matchLoadersList(options.preLoaders) : "";
var postLoaders = options.postLoaders ? matchLoadersList(options.postLoaders) : "";
resolve.loaders(context, preLoaders, options.resolve, function(err, preLoaders) {
resolve.loaders(context, preLoaders, options.resolve, function(err, preLoaders) {
if(err) return callback(err);
resolve.loaders(context, postLoaders, options.resolve, function(err, postLoaders) {
if(err) return callback(err);
resolve.loaders(context, postLoaders, options.resolve, function(err, postLoaders) {
profile && (profile.resolvePrePostLoadersEnd = new Date());
var allLoaders = [];
allLoaders.push.apply(allLoaders, preLoaders);
allLoaders.push.apply(allLoaders, loaders);
allLoaders.push.apply(allLoaders, postLoaders);
var seperate = !!options.workers;
try {
for(var i = 0; i < allLoaders.length && seperate; i++) {
var loaderFilename = allLoaders[i];
options.events && options.events.emit("loader", loaderFilename);
if(!require(loaderFilename).seperable)
seperate = false;
}
} catch(e) {
return callback(e);
}
var buildModuleStart = new Date();
profile && (profile.loadersCheckEnd = buildModuleStart);
(seperate ? seperateBuildModule : buildModule)({
context: context,
filenameWithLoaders: filenameWithLoaders,
preLoaders: preLoaders,
loaders: loaders,
postLoaders: postLoaders,
filename: filename,
options: options
}, function(err, source, deps, dependencyInfo, profileBuild) {
if(err) return callback(err);
execLoaders(context, filenameWithLoaders, preLoaders, [filename], [content], cacheEntry, options,
function(err, result, preLoadersCacheable) {
if(err) return callback(err);
execLoaders(context, filenameWithLoaders, loaders, [filename], result, cacheEntry, options,
function(err, result, loadersCacheable) {
if(err) return callback(err);
execLoaders(context, filenameWithLoaders, postLoaders, [filename], result, cacheEntry, options,
function(err, result, postLoadersCacheable) {
if(err) return callback(err);
return processJs(result, loadersCacheable && preLoadersCacheable && postLoadersCacheable)
});
});
});
if(profile) {
profile.buildModule = profileBuild;
profile.buildModuleEnd = new Date();
}
modu.seperate = seperate;
modu.dependencies = dependencyInfo.files;
modu.loaders = allLoaders;
if(dependencyInfo.cacheable && options.cache) {
modu.toCache = true;
options.cache.store(filenameWithLoaders, dependencyInfo.files, buildModuleStart, JSON.stringify({
deps: deps,
source: source,
dependencies: dependencyInfo.files,
loaders: allLoaders
}));
}
return processParsedJs(source, deps);
});

@@ -193,26 +239,25 @@ });

// process the result delivered from loaders or direct from file
// for inclusion into the result
// (static code analysis for requires and other stuff)
// [this step is cached]
function processJs(resultBuffers, cacheable) {
var source = resultBuffers[0].toString("utf-8")
var deps;
try {
deps = parse(source, options.parse);
} catch(e) {
callback("File \"" + filenameWithLoaders + "\" parsing failed: " + e);
return;
}
if(cacheable && cacheEntry) {
modu.toCache = true;
cacheEntry.save(JSON.stringify({
deps: deps,
source: source
}));
}
return processParsedJs(source, deps);
function seperateBuildModule(parameters, callback) {
var opt = {};
Object.keys(parameters.options).forEach(function(name) {
if(name == "internal") return;
if(name == "events") return;
if(name == "resolve") return;
opt[name] = parameters.options[name];
});
parameters.options = opt;
options.workers.run(parameters, function(err, source, deps, cacheInfo, profileBuild) {
if(err) err = {
message: err.message,
stack: err.stack,
_toString: err._toString,
toString: function() {
return this._toString
}
}
callback(err, source, deps, cacheInfo, profileBuild);
});
}
// process the final parsed javascript code

@@ -317,2 +362,3 @@ function processParsedJs(source, deps) {

} else {
options.events.emit("module", modu, filename);
callback(null, modu.id);

@@ -361,3 +407,3 @@ }

dirname = loaders.pop();
options.events.emit("context", contextModule, dirname);
options.events.emit("context-enum", contextModule, dirname);
var prependLoaders = loaders.length === 0 ? "" : loaders.join("!") + "!";

@@ -447,2 +493,3 @@ var extensions = (options.resolve && options.resolve.extensions) || [".web.js", ".js"];

}
options.events.emit("context", contextModule, dirname);
callback(null, contextModule.id);

@@ -449,0 +496,0 @@ });

@@ -9,2 +9,3 @@ /*

this.options = options = options || {};
if(!this.options.stat) this.options.stat = fs.stat;
this.map = {};

@@ -22,3 +23,3 @@ }

item.files.forEach(function(file) {
fs.stat(file.path, function(err, stat) {
this.options.stat(file.path, function(err, stat) {
if(err) return invalidate(err.toString());

@@ -30,3 +31,3 @@ if(!stat) return invalidate("Cannot read stat");

});
});
}, this);
if(item.files.length === 0) valid();

@@ -46,25 +47,25 @@ function invalidate(msg) {

$.create = function(request) {
var self = this;
var item = {
files: []
};
var cacheEntry = {
add: function(path) {
item.files.push({
path: path,
// TODO do it asynchronly
time: fs.statSync(path).mtime.getTime()
$.store = function(request, dependencies, startTime, value) {
var count = dependencies.length + 1;
var files = [];
var endOne = function() {
if(--count == 0) {
this.map[request] = {
files: files,
value: value
}
}
}.bind(this);
dependencies.forEach(function(file) {
this.options.stat(file, function(err, stat) {
if(err) return; // do not cache it.
if(stat.mtime.getTime() > startTime.getTime()) return; // do not cache it.
files.unshift({
path: file,
time: stat.mtime.getTime()
});
},
clear: function() {
item.files.length = 0;
},
save: function(value) {
item.value = value;
self.map[request] = item;
cacheEntry.saved = true;
}
}
return cacheEntry;
}
endOne();
});
}, this);
endOne();
}

@@ -20,8 +20,20 @@ /*

buf.push("Modules including duplicates: "+c("\033[1m") + stats.modulesIncludingDuplicates + c("\033[22m"));
buf.push("Modules per chunk: "+c("\033[1m") + stats.modulesPerChunk + c("\033[22m"));
buf.push("Modules first chunk: "+c("\033[1m") + stats.modulesFirstChunk + c("\033[22m"));
if(stats.fileSizes)
if(stats.fileSizes) {
var maxLenFilename = 0;
var maxLenChunkname = 0;
Object.keys(stats.fileSizes).forEach(function(file) {
buf.push(c("\033[1m") + sprintf("%" + (3 + Object.keys(stats.fileSizes)[0].length) + "s", file) + c("\033[22m")+": "+c("\033[1m") + sprintf("%8d", stats.fileSizes[file]) + c("\033[22m") + " characters");
if(file.length > maxLenFilename) maxLenFilename = file.length;
});
var fileChunkNames = {};
Object.keys(stats.chunkNameFiles).forEach(function(name) {
if(name.length > maxLenChunkname) maxLenChunkname = name.length;
fileChunkNames[stats.chunkNameFiles[name]] = name;
});
Object.keys(stats.fileSizes).forEach(function(file) {
var name = fileChunkNames[file] || "";
var fileLine = sprintf("%" + maxLenChunkname + "s", name) + c("\033[1m") + sprintf("%" + (3 + maxLenFilename) + "s", file) + c("\033[22m")+": "+c("\033[1m") + sprintf("%8d", stats.fileSizes[file]) + c("\033[22m") + " chars/bytes ";
buf.push(fileLine);
});
}
var compressFilename = options.context ? createFilenameShortener(options.context) : function(f) { return f };

@@ -33,14 +45,41 @@ if(stats.fileModules) {

buf.push(" <reason> from <filename>");
var maxTime = 0;
Object.keys(stats.fileModules).forEach(function(file) {
stats.fileModules[file].forEach(function(module) {
if(!module.profile) return;
var time = module.profile.time - module.profile.timeChildren;
if(maxTime < time) maxTime = time;
});
});
var middleTime = maxTime * 0.7;
maxTime *= 0.9;
Object.keys(stats.fileModules).forEach(function(file) {
buf.push(c("\033[1m\033[32m") + file + c("\033[39m\033[22m"));
var modules = stats.fileModules[file];
if(options["by-size"])
modules.sort(function(a, b) {
return b.size - a.size;
});
if(options["by-size"]) {
modules.sort(function(a, b) {
return b.size - a.size;
});
}
modules.forEach(function(module) {
buf.push(" "+c("\033[1m") + sprintf("%3s", module.id+"") + " " + (typeof module.size === "number" ? sprintf("%9s", Math.round(module.size)+"") : " ") + " " +
var moduleLine = " "+(module.fromCache?"":c("\033[1m")) + sprintf("%3s", module.id+"") + " " + (typeof module.size === "number" ? sprintf("%9s", Math.round(module.size)+"") : " ") + " " +
(compressFilename(module.filename) ||
(module.dirname && ("[context] " + compressFilename(module.dirname))) ||
"[unknown]") + c("\033[22m") + (module.fromCache ? " [from cache]" : module.toCache ? " [caching]" : ""));
"[unknown]") + (module.fromCache?"":c("\033[22m"))
if(module.fromCache) moduleLine += c("\033[1m\033[32m") + " [from cache]" + c("\033[39m\033[22m");
else if(module.toCache) moduleLine += c("\033[1m\033[33m") + " [caching]" + c("\033[39m\033[22m");
if(module.seperate) moduleLine += " [seperate]";
if(module.profile) {
var valueTime = module.profile.time - module.profile.timeChildren;
if(valueTime > maxTime) moduleLine += c("\033[1m\033[31m");
else if(valueTime > middleTime) moduleLine += c("\033[1m\033[33m");
var buildProfile = module.profile.buildModule;
if(buildProfile) buildProfile = " (" +
(buildProfile.loaders && buildProfile.loaders.length > 0 ? "loaders: " + buildProfile.loaders.join("ms, ") + "ms" : "") +
")";
else buildProfile = "";
moduleLine += " [" + module.profile.time + "ms: " + (module.profile.timeResolve + module.profile.timeResolvePrePostLoaders) + "ms resolving, " + module.profile.timeBuildModule + "ms build" + buildProfile + ", " + module.profile.timeChildren + "ms children]";
if(valueTime > middleTime) moduleLine += c("\033[39m\033[22m");
}
buf.push(moduleLine);
if(options.verbose) {

@@ -47,0 +86,0 @@ module.reasons.forEach(function(reason) {

@@ -9,33 +9,33 @@ /*

function walkStatements(context, statements) {
function walkStatements(options, context, statements) {
statements.forEach(function(statement) {
walkStatement(context, statement);
walkStatement(options, context, statement);
});
}
function walkStatement(context, statement) {
function walkStatement(options, context, statement) {
switch(statement.type) {
// Real Statements
case "BlockStatement":
walkStatements(context, statement.body);
walkStatements(options, context, statement.body);
break;
case "ExpressionStatement":
walkExpression(context, statement.expression);
walkExpression(options, context, statement.expression);
break;
case "IfStatement":
walkExpression(context, statement.test);
walkStatement(context, statement.consequent);
walkExpression(options, context, statement.test);
walkStatement(options, context, statement.consequent);
if(statement.alternate)
walkStatement(context, statement.alternate);
walkStatement(options, context, statement.alternate);
break;
case "LabeledStatement":
walkStatement(context, statement.body);
walkStatement(options, context, statement.body);
break;
case "WithStatement":
walkExpression(context, statement.object);
walkStatement(context, statement.body);
walkExpression(options, context, statement.object);
walkStatement(options, context, statement.body);
break;
case "SwitchStatement":
walkExpression(context, statement.discriminant);
walkSwitchCases(context, statement.cases);
walkExpression(options, context, statement.discriminant);
walkSwitchCases(options, context, statement.cases);
break;

@@ -45,14 +45,14 @@ case "ReturnStatement":

if(statement.argument)
walkExpression(context, statement.argument);
walkExpression(options, context, statement.argument);
break;
case "TryStatement":
walkStatement(context, statement.block);
walkCatchClauses(context, statement.handlers);
walkStatement(options, context, statement.block);
walkCatchClauses(options, context, statement.handlers);
if(statement.finalizer)
walkStatement(context, statement.finalizer);
walkStatement(options, context, statement.finalizer);
break;
case "WhileStatement":
case "DoWhileStatement":
walkExpression(context, statement.test);
walkStatement(context, statement.body);
walkExpression(options, context, statement.test);
walkStatement(options, context, statement.body);
break;

@@ -62,19 +62,19 @@ case "ForStatement":

if(statement.init.type === "VariableDeclaration")
walkStatement(context, statement.init);
walkStatement(options, context, statement.init);
else
walkExpression(context, statement.init);
walkExpression(options, context, statement.init);
}
if(statement.test)
walkExpression(context, statement.test);
walkExpression(options, context, statement.test);
if(statement.update)
walkExpression(context, statement.update);
walkStatement(context, statement.body);
walkExpression(options, context, statement.update);
walkStatement(options, context, statement.body);
break;
case "ForInStatement":
if(statement.left.type === "VariableDeclaration")
walkStatement(context, statement.left);
walkStatement(options, context, statement.left);
else
walkExpression(context, statement.left);
walkExpression(context, statement.right);
walkStatement(context, statement.body);
walkExpression(options, context, statement.left);
walkExpression(options, context, statement.right);
walkStatement(options, context, statement.body);
break;

@@ -84,10 +84,10 @@

case "FunctionDeclaration":
if(context.options.overwrites.hasOwnProperty(statement.name)) {
if(options.overwrites.hasOwnProperty(statement.name)) {
context.overwrite.push(statement.name);
}
var old = addOverwrites(context, statement.params);
var old = addOverwrites(options, context, statement.params);
if(statement.body.type === "BlockStatement")
walkStatement(context, statement.body);
walkStatement(options, context, statement.body);
else
walkExpression(context, statement.body);
walkExpression(options, context, statement.body);
context.overwrite.length = old;

@@ -97,3 +97,3 @@ break;

if(statement.declarations)
walkVariableDeclarators(context, statement.declarations);
walkVariableDeclarators(options, context, statement.declarations);
break;

@@ -103,19 +103,19 @@ }

function walkSwitchCases(context, switchCases) {
function walkSwitchCases(options, context, switchCases) {
switchCases.forEach(function(switchCase) {
if(switchCase.test)
walkExpression(context, switchCase.test);
walkStatements(context, switchCase.consequent);
walkExpression(options, context, switchCase.test);
walkStatements(options, context, switchCase.consequent);
});
}
function walkCatchClauses(context, catchClauses) {
function walkCatchClauses(options, context, catchClauses) {
catchClauses.forEach(function(catchClause) {
if(catchClause.guard)
walkExpression(context, catchClause.guard);
walkStatement(context, catchClause.body);
walkExpression(options, context, catchClause.guard);
walkStatement(options, context, catchClause.body);
});
}
function walkVariableDeclarators(context, declarators) {
function walkVariableDeclarators(options, context, declarators) {
declarators.forEach(function(declarator) {

@@ -125,7 +125,7 @@ switch(declarator.type) {

if(declarator.id.type === "Identifier" &&
context.options.overwrites.hasOwnProperty(declarator.id.name)) {
options.overwrites.hasOwnProperty(declarator.id.name)) {
context.overwrite.push(declarator.id.name);
}
if(declarator.init)
walkExpression(context, declarator.init);
walkExpression(options, context, declarator.init);
break;

@@ -136,25 +136,25 @@ }

function walkExpressions(context, expressions) {
function walkExpressions(options, context, expressions) {
expressions.forEach(function(expression) {
walkExpression(context, expression);
walkExpression(options, context, expression);
});
}
function walkExpression(context, expression) {
function walkExpression(options, context, expression) {
switch(expression.type) {
case "ArrayExpression":
if(expression.elements)
walkExpressions(context, expression.elements);
walkExpressions(options, context, expression.elements);
break;
case "ObjectExpression":
expression.properties.forEach(function(prop) {
walkExpression(context, prop.value);
walkExpression(options, context, prop.value);
});
break;
case "FunctionExpression":
var old = addOverwrites(context, expression.params);
var old = addOverwrites(options, context, expression.params);
if(expression.body.type === "BlockStatement")
walkStatement(context, expression.body);
walkStatement(options, context, expression.body);
else
walkExpression(context, expression.body);
walkExpression(options, context, expression.body);
context.overwrite.length = old;

@@ -164,6 +164,6 @@ break;

if(expression.expressions)
walkExpressions(context, expression.expressions);
walkExpressions(options, context, expression.expressions);
break;
case "UpdateExpression":
walkExpression(context, expression.argument);
walkExpression(options, context, expression.argument);
break;

@@ -176,8 +176,8 @@ case "UnaryExpression":

break;
walkExpression(context, expression.argument);
walkExpression(options, context, expression.argument);
break;
case "BinaryExpression":
case "LogicalExpression":
walkExpression(context, expression.left);
walkExpression(context, expression.right);
walkExpression(options, context, expression.left);
walkExpression(options, context, expression.right);
break;

@@ -187,14 +187,14 @@ case "AssignmentExpression":

expression.left.name !== "require")
walkExpression(context, expression.left);
walkExpression(context, expression.right);
walkExpression(options, context, expression.left);
walkExpression(options, context, expression.right);
break;
case "ConditionalExpression":
walkExpression(context, expression.test);
walkExpression(context, expression.alternate);
walkExpression(context, expression.consequent);
walkExpression(options, context, expression.test);
walkExpression(options, context, expression.alternate);
walkExpression(options, context, expression.consequent);
break;
case "NewExpression":
walkExpression(context, expression.callee);
walkExpression(options, context, expression.callee);
if(expression.arguments)
walkExpressions(context, expression.arguments);
walkExpressions(options, context, expression.arguments);
break;

@@ -301,3 +301,3 @@ case "CallExpression":

overwrite: context.overwrite.slice(),
options: context.options
options: options
};

@@ -463,3 +463,3 @@ if(expression.arguments.length >= 2 &&

overwrite: context.overwrite.slice(),
options: context.options
options: options
};

@@ -547,5 +547,5 @@ param.forEach(function(r) {

if(expression.callee && !noCallee)
walkExpression(context, expression.callee);
walkExpression(options, context, expression.callee);
if(expression.arguments)
walkExpressions(context, expression.arguments);
walkExpressions(options, context, expression.arguments);
break;

@@ -562,5 +562,5 @@ case "MemberExpression":

break;
walkExpression(context, expression.object);
walkExpression(options, context, expression.object);
if(expression.property.type !== "Identifier")
walkExpression(context, expression.property);
walkExpression(options, context, expression.property);
break;

@@ -581,5 +581,5 @@ case "Identifier":

} else if(context.overwrite.indexOf(expression.name) === -1 &&
context.options.overwrites.hasOwnProperty(expression.name)) {
options.overwrites.hasOwnProperty(expression.name)) {
context.requires = context.requires || [];
var overwrite = context.options.overwrites[expression.name];
var overwrite = options.overwrites[expression.name];
var append = undefined;

@@ -602,3 +602,3 @@ if(overwrite.indexOf("+") !== -1) {

function addOverwrites(context, params) {
function addOverwrites(options, context, params) {
var l = context.overwrite.length;

@@ -612,3 +612,3 @@ if(!params) return l;

if(param.type === "Identifier" &&
context.options.overwrites.hasOwnProperty(param.name))
options.overwrites.hasOwnProperty(param.name))
context.overwrite.push(param.name);

@@ -702,8 +702,7 @@ });

var context = {
options: options,
overwrite: []
};
walkStatements(context, ast.body);
delete context.options;
walkStatements(options, context, ast.body);
JSON.stringify(context);
return context;
}

@@ -22,38 +22,5 @@ /*

options:
- outputJsonpFunction
JSONP function used to load chunks
- publicPrefix
Path from where chunks are loaded
- outputDirectory
write files to this directory (absolute path)
- output
write first chunk to this file
- outputPostfix
write chunks to files named chunkId plus outputPostfix
- libary
exports of input file are stored in this variable
- watch
recompile on file change
- watchDelay
delay before recompile after the last file change
- minimize
minimize outputs with uglify-js
- includeFilenames
add absolute filenames of input files as comments
- resolve.alias (object)
replace a module. ex {"old-module": "new-module"}
- resolve.extensions (object)
possible extensions for files
- resolve.paths (array)
search paths
- resolve.loaders (array)
extension to loader mappings
{test: /\.extension$/, loader: "myloader"}
loads files that matches the RegExp to the loader if no other loader set
- parse.overwrites (object)
free module varables which are replaced with a module
ex. { "$": "jquery" }
options: see README.md
*/
module.exports = function(context, moduleName, options, callback) {
module.exports = function webpackMain(context, moduleName, options, callback) {
// Support multiple call signitures

@@ -71,2 +38,6 @@ if(typeof moduleName === "object") {

// Defaults
// Create a options.events as EventEmitter
if(!options.events) options.events = new (require("events").EventEmitter)();
if(!options.outputJsonpFunction)

@@ -82,2 +53,22 @@ options.outputJsonpFunction = "webpackJsonp" + (options.libary || "");

if(options.workers === true) {
options.workers = require("os").cpus().length;
}
if(typeof options.workers == "number") {
options.workers = new (require("./Workers"))(path.join(__dirname, "buildModuleFork.js"), options.workers);
}
if(options.workers && options.closeWorkers !== false) {
if(options.watch) {
options.events.on("watch-end", function() {
if(options.closeWorkers === false) return;
options.workers.close();
});
} else {
options.events.on("bundle", function() {
if(options.closeWorkers === false) return;
options.workers.close();
});
}
}
if(options.output) {

@@ -146,5 +137,2 @@ if(!options.outputDirectory) {

// Create a options.events as EventEmitter
if(!options.events) options.events = new (require("events").EventEmitter)();
// Register listeners to support watch mode

@@ -173,6 +161,8 @@ if(options.watch) {

if(staticChanges.length > 0)
return callback(new Error(
if(staticChanges.length > 0) {
callback(new Error(
"Files (" + staticChanges.join(", ") +
") changed. Webpack cannot recompile in this watch step."));
return options.events.emit("watch-end");
}

@@ -194,23 +184,12 @@ runAgain = false;

startAgain()
}
function staticChange(filename) {
if(staticChanges.indexOf(filename) == -1)
staticChanges.push(filename);
change();
}
// on before a module is read
options.events.on("module", function(module, filename) {
if(!filename) return;
watchers.push(fs.watch(filename, function() {
change();
}));
});
// on before a loader dependency is read
options.events.on("dependency", function(filename) {
if(!filename) return;
watchers.push(fs.watch(filename, function() {
change();
}));
});
// on before a context is enumerated
options.events.on("context", function(module, dirname) {
options.events.on("context-enum", function(module, dirname) {
if(!dirname) return;

@@ -222,20 +201,2 @@ watchers.push(fs.watch(dirname, function() {

// on before a loader is read
options.events.on("loader", function(filename) {
if(!filename) return;
watchers.push(fs.watch(filename, function() {
change();
}));
});
// on before a static dependency is read
options.events.on("static-dependency", function(filename) {
if(!filename) return;
watchers.push(fs.watch(filename, function() {
if(staticChanges.indexOf(filename) == -1)
staticChanges.push(filename);
change();
}));
});
// on user defines the bundle as invalid

@@ -247,6 +208,30 @@ options.events.on("invalid", function() {

// on bundle finished compiling
var bundleToken = null;
options.events.on("bundle", function(stats) {
isRunning = false;
bundleToken = "" + Math.random();
if(runAgain)
startAgain();
else {
// Bind watchers
var token = bundleToken;
stats.dependencies.forEach(function(dep) {
watchers.push(fs.watch(dep, change));
fs.stat(dep, function(err, stat) {
if(bundleToken != token) return;
if(err) return change();
if(stat.mtime.getTime() > stats.startTime)
change();
});
});
stats.loaders.forEach(function(dep) {
watchers.push(fs.watch(dep, staticChange.bind(null, dep)));
fs.stat(dep, function(err, stat) {
if(bundleToken != token) return;
if(err) return staticChange(dep);
if(stat.mtime.getTime() > stats.startTime)
staticChange(dep);
});
});
}
});

@@ -285,5 +270,2 @@

// collect which module is in which file
var fileModulesMap = {};
// collect which chunks exists

@@ -461,2 +443,9 @@ var chunksCount = 0;

var sum = 0;
// collect which module is in which file
var fileModulesMap = {};
// collect named chunks filenames
var chunkNameMap = {};
chunkIds.reverse().forEach(function(chunkId) {

@@ -476,5 +465,8 @@ var chunk = depTree.chunks[chunkId]

toCache: modu.toCache,
seperate: modu.seperate,
profile: modu.profile,
reasons: modu.reasons});
sum++;
}
}

@@ -485,5 +477,5 @@ modulesArray.sort(function(a, b) {

fileModulesMap[path.basename(chunk.filename)] = modulesArray;
chunkNameMap[chunkId] = path.basename(chunk.filename);
});
buffer.modulesIncludingDuplicates = sum;
buffer.modulesPerChunk = Math.round(sum / chunksCount*10)/10; // DEPRECATED: useless info
sum = 0;

@@ -494,2 +486,18 @@ for(var moduleId in depTree.chunks.main.modules) {

}
var dependencies = {};
var loaders = {};
var contexts = [];
Object.keys(depTree.modules).forEach(function(moduleId) {
var module = depTree.modules[moduleId];
if(module.dependencies) module.dependencies.forEach(function(dep) {
dependencies[dep] = true;
});
if(module.loaders) module.loaders.forEach(function(loader) {
loaders[loader] = true;
});
if(module.dirname) contexts.push(module.dirname);
});
buffer.dependencies = Object.keys(dependencies);
buffer.loaders = Object.keys(loaders);
buffer.contexts = contexts;
buffer.modulesFirstChunk = sum;

@@ -500,3 +508,5 @@ buffer.fileSizes = fileSizeMap;

buffer.fileModules = fileModulesMap;
buffer.chunkNameFiles = chunkNameMap;
buffer.subStats = subStats;
buffer.startTime = startTime.getTime();
buffer.time = new Date() - startTime;

@@ -503,0 +513,0 @@ options.events.emit("task-end", "statistics");

{
"name": "webpack",
"version": "0.6.2",
"version": "0.7.0-beta",
"author": "Tobias Koppers @sokra",

@@ -13,11 +13,11 @@ "description": "Packs CommonJs/AMD Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loading of js, json, jade, coffee, css, ... out of the box and more with custom loaders.",

"enhanced-resolve": "0.2.x",
"raw-loader": "0.1.x",
"json-loader": "0.1.x",
"jade-loader": "0.1.x",
"coffee-loader": "0.1.x",
"raw-loader": "0.2.x",
"json-loader": "0.2.x",
"jade-loader": "0.2.x",
"coffee-loader": "0.2.x",
"css-loader": "0.2.x",
"less-loader": "0.2.x",
"style-loader": "0.1.x",
"script-loader": "0.1.x",
"bundle-loader": "0.1.x",
"script-loader": "0.2.x",
"bundle-loader": "0.2.x",
"file-loader": "0.1.x",

@@ -24,0 +24,0 @@ "val-loader": "0.1.x"

@@ -328,17 +328,19 @@ # webpack

Options:
--min Minimize it with uglifyjs [boolean] [default: false]
--filenames Output Filenames Into File [boolean] [default: false]
--options Options JSON File [string]
--public-prefix Path Prefix For JavaScript Loading [string]
--libary Stores the exports into this variable [string]
--colors Output Stats with colors [boolean] [default: false]
--single Disable lazy loading [boolean] [default: false]
--json Output Stats as JSON [boolean] [default: false]
--by-size Sort modules by size in Stats [boolean] [default: false]
--verbose Output dependencies in Stats [boolean] [default: false]
--alias Set a alias name for a module. ex. http=http-browserify [string]
--debug Prints debug info to output files [boolean] [default: false]
--watch Recompiles on changes (except loaders) [boolean] [default: false]
--watch-delay Timeout to wait for the last change [string]
--progress Displays a progress while compiling [boolean] [default: false]
--min Minimize it with uglifyjs [boolean] [default: false]
--filenames Output Filenames Into File [boolean] [default: false]
--options Options JSON File [string]
--public-prefix Path Prefix For JavaScript Loading [string]
--libary Stores the exports into this variable [string]
--colors Output Stats with colors [boolean] [default: false]
--single Disable lazy loading [boolean] [default: false]
--json Output Stats as JSON [boolean] [default: false]
--by-size Sort modules by size in Stats [boolean] [default: false]
--verbose Output dependencies in Stats [boolean] [default: false]
--profile Capture timings for modules [boolean] [default: false]
--alias Set a alias name for a module. ex. http=http-browserify [string]
--debug Prints debug info to output files [boolean] [default: false]
--watch Recompiles on changes (except loaders) [boolean] [default: false]
--watch-delay Timeout to wait for the last change
--workers Use worker processes to be faster (BETA) [boolean] [default: false]
--progress Displays a progress while compiling [boolean] [default: false]
```

@@ -411,8 +413,7 @@

// "start-writing" (hash) fired when webpack starts writing
// -- events for dependencies --
// "module" (module, filename) before a module is loaded
// "context" (module, dirname) before a context is loaded
// "dependency" (filename) before a dependency is loaded
// "static-dependency"(filename) after a dependency is flagged as not recompile-able
// "loader" (filename) before a loader is required
// "watch-end" () watch ended because of loader change
// -- events for modules --
// "module" (module, filename) after a module is loaded
// "context-enum" (module, dirname) before a context is enumerated
// "context" (module, dirname) after a context is loaded
// -- events for progress --

@@ -518,2 +519,22 @@ // "task" (name?) start of a task

// normal loaders. This cannot be overridden in the require call.
workers: true,
// default: false
// options: true, false, number > 0, object of type webpack/lib/Workers
// Use worker processes to do some work.
// This *can* boost performance, but starting these processes has some
// overhead (~100-200ms). If loaders are used they need to have the
// seperable flag to work in worker process. If they havn't they work in
// the main process.
// In watch mode, worker processes only start once. So workers = true
// is recommended for watch mode.
closeWorkers: false,
// default: true
// close the worker processes on webpack exit.
profile: true,
// default: false
// capture timings for the build.
// they are stored in the stats
}

@@ -531,2 +552,3 @@ ```

hash: "52bd9213...38d",
startTime: 237467691, // in ms since 1.1.1990
time: 1234, // in ms

@@ -541,2 +563,6 @@ chunkCount: 2,

},
chunkNameFiles: {
"main": "output.js",
"namedChunk": "1.output.js"
}
warnings: [ "Some warning" ],

@@ -548,3 +574,6 @@ errors: [ "Some error" ],

{ type: "main" }
]},
],
dependencies: [ "filename", ... ],
loaders: [ "filename of loader", ... ]
},
{ id: 1, size: 234, filename: "...", reasons: [

@@ -928,5 +957,3 @@ { type: "require", // or "context", "async require", "async context"

* more and better polyfills for node.js buildin modules
* cache in folder and allow reuseing it
* write it into the wiki if you have more ideas...
see [/webpack/webpack/wiki/Ideas](wiki Ideas)

@@ -933,0 +960,0 @@ ## License

@@ -36,3 +36,3 @@ /*

if(code === 0) {
var main = cp.spawn("node", join(["../../bin/webpack.js", "--colors", "--alias", "vm=vm-browserify",
var main = cp.spawn("node", join(["../../bin/webpack.js", "--colors", "--alias", "vm=vm-browserify", "--workers",
"--public-prefix", "js/", "lib/index", "js/web.js"], extraArgs));

@@ -39,0 +39,0 @@ bindOutput(main);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc