Skip to content

Commit 259fb52

Browse files
committed
expose context
1 parent 451f92b commit 259fb52

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

lib/buildDeps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function addModule(depTree, context, modu, options, reason, finalCallback) {
101101
}
102102

103103
// resolve the filename of the required module
104-
resolve(context || path.dirname(modu), modu, options.resolve, resolved);
104+
resolve(context = context || path.dirname(modu), modu, options.resolve, resolved);
105105
function resolved(err, filename) {
106106
if(err) {
107107
callback(err);
@@ -134,7 +134,7 @@ function addModule(depTree, context, modu, options, reason, finalCallback) {
134134
}
135135

136136
// exec the loaders
137-
execLoaders(filenameWithLoaders, loaders, [filename], [content], options, processJs);
137+
execLoaders(context, filenameWithLoaders, loaders, [filename], [content], options, processJs);
138138

139139
// process the finished javascript code
140140
// for inclusion into the result

lib/execLoaders.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ var path = require("path");
88

99
/**
1010
* execLoaders
11+
* @param context {string} the context from which this request is coming
1112
* @param request {string} the compile request string
1213
* @param loaders {string[]} the absolute filenames of the loaders
1314
* @param filenames {string[]} the filenames of "contents"
1415
* @param contents {Buffer[]} read contents
1516
* @param options {object} the options of the module system
1617
* @param callback {function} (err, resultingJavascriptCode)
1718
*/
18-
module.exports = function(request, loaders, filenames, contents, options, callback) {
19+
module.exports = function(context, request, loaders, filenames, contents, options, callback) {
1920
if(loaders.length === 0)
2021
// if no loaders are used, the file content is the resulting code
2122
callback(null, contents[0].toString("utf-8"));
@@ -49,7 +50,8 @@ module.exports = function(request, loaders, filenames, contents, options, callba
4950
try {
5051
// prepare the loader "this" context
5152
// see "Loader Specification" in wiki
52-
var context = {
53+
var loaderContext = {
54+
context: context,
5355
request: request,
5456
filenames: filenames,
5557
exec: function(code, filename) {
@@ -65,7 +67,7 @@ module.exports = function(request, loaders, filenames, contents, options, callba
6567
},
6668
async: function() {
6769
async = true;
68-
return context.callback;
70+
return loaderContext.callback;
6971
},
7072
callback: function(err) {
7173
async = true;
@@ -98,7 +100,7 @@ module.exports = function(request, loaders, filenames, contents, options, callba
98100

99101
// add additional loader context params or functions
100102
if(options.loader) for(var key in options.loader)
101-
context[key] = options.loader[key];
103+
loaderContext[key] = options.loader[key];
102104

103105
// convert all parameters to strings if they are Buffers
104106
var params = [];
@@ -110,7 +112,7 @@ module.exports = function(request, loaders, filenames, contents, options, callba
110112
});
111113

112114
// exec to loader
113-
var retVal = loaderFunctions.pop().apply(context, params);
115+
var retVal = loaderFunctions.pop().apply(loaderContext, params);
114116

115117
// if it isn't asynchron, use the return value
116118
if(!async) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs 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.",
66
"dependencies": {

0 commit comments

Comments
 (0)