Skip to content

Commit 258f9f4

Browse files
committed
added resolve postprocessing
1 parent bfc627f commit 258f9f4

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,21 @@ You can also save this options object in a JSON file and use it with the shell c
455455
// {test: /\.less$/, loader: "style!css!val!less"}]
456456
// automatically use loaders if filename match RegExp
457457
// and no loader is specified
458+
459+
postprocess: {
460+
normal: [function(filename, callback) {
461+
// webpack will not find files including ".exclude."
462+
if(/\.exclude\.[^\\\/]*/.test(filename))
463+
return callback(new Error("File is excluded"));
464+
callback(null, filename);
465+
}],
466+
// defaults: []
467+
// postprocess resolved filenames by all specified async functions
468+
// a postprocessor must call the callback
469+
470+
context: [],
471+
// same as postprocess.normal but for contextes
472+
}
458473
}
459474
}
460475
```

‎lib/resolve.js‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ var fs = require("fs");
1111
function resolve(context, identifier, options, type, callback) {
1212
function finalResult(err, absoluteFilename) {
1313
if(err) {
14-
callback("Module \"" + identifier + "\" not found in context \"" +
15-
context + "\"\n " + err);
14+
callback(new Error("Module \"" + identifier + "\" not found in context \"" +
15+
context + "\"\n " + err));
1616
return;
1717
}
1818
callback(null, absoluteFilename);
@@ -35,7 +35,7 @@ function resolve(context, identifier, options, type, callback) {
3535
return;
3636
}
3737
if(!stat.isDirectory()) {
38-
finalResult("Context \"" + identifier + "\" in not a directory");
38+
finalResult(new Error("Context \"" + identifier + "\" in not a directory"));
3939
return;
4040
}
4141
callback(null, pathname);
@@ -75,6 +75,12 @@ function doResolve(context, identifier, options, type, callback) {
7575
options.paths = [];
7676
if(!options.alias)
7777
options.alias = {};
78+
if(!options.postprocess)
79+
options.postprocess = {};
80+
if(!options.postprocess.normal)
81+
options.postprocess.normal = [];
82+
if(!options.postprocess.context)
83+
options.postprocess.context = [];
7884
var identifiers = identifier.replace(/^!|!$/g, "").replace(/!!/g, "!").split(/!/g);
7985
var resource = identifiers.pop();
8086
resolve(context, resource, options, type, function(err, resource) {
@@ -94,11 +100,20 @@ function doResolve(context, identifier, options, type, callback) {
94100
count--;
95101
if(count === 0) {
96102
if(errors.length > 0) {
97-
callback(errors.join("\n"));
103+
callback(new Error(errors.join("\n")));
98104
return;
99105
}
100106
identifiers.push(resource);
101-
callback(null, identifiers.join("!"));
107+
var intermediateResult = identifiers.join("!");
108+
var postprocessors = options.postprocess[type].slice(0);
109+
postprocessors.push(function(result) {
110+
callback(null, result);
111+
});
112+
(function next(err, result) {
113+
if(err)
114+
return callback(new Error("File \"" + intermediateResult + "\" is blocked by postprocessors: " + err));
115+
postprocessors.shift()(result, next);
116+
})(null, intermediateResult);
102117
}
103118
}
104119
if(count == 0) endOne(count++);

‎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.13",
3+
"version": "0.4.14",
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)