Skip to content

Commit

Permalink
fixed webpack#1415
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Sep 3, 2015
1 parent 1ed92ea commit 159ef42
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 25 deletions.
5 changes: 5 additions & 0 deletions lib/dependencies/ConstDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ ConstDependency.Template.prototype.apply = function(dep, source) {
else
source.replace(dep.range[0], dep.range[1] - 1, dep.expression);
};

ConstDependency.prototype.updateHash = function(hash) {
hash.update(this.range + "");
hash.update(this.expression + "");
};
56 changes: 31 additions & 25 deletions test/Stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,43 @@ describe("Stats", function() {
if(fs.existsSync(path.join(base, testName, "webpack.config.js"))) {
options = require(path.join(base, testName, "webpack.config.js"));
}
options.context = path.join(base, testName);
(Array.isArray(options) ? options : [options]).forEach(function(options) {
options.context = path.join(base, testName);
});
var c = webpack(options);
var files = {};
c.outputFileSystem = {
join: path.join.bind(path),
mkdirp: function(path, callback) {
callback();
},
writeFile: function(name, content, callback) {
files[name] = content.toString("utf-8");
callback();
}
};
var ifs = c.inputFileSystem;
c.inputFileSystem = Object.create(ifs);
c.inputFileSystem.readFile = function() {
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
ifs.readFile.apply(ifs, args.concat([function(err, result) {
if(err) return callback(err);
callback(null, result.toString("utf-8").replace(/\r/g, ""));
}]));
};
c.apply(new webpack.optimize.OccurrenceOrderPlugin());
var compilers = c.compilers ? c.compilers : [c];
compilers.forEach(function(c) {
c.outputFileSystem = {
join: path.join.bind(path),
mkdirp: function(path, callback) {
callback();
},
writeFile: function(name, content, callback) {
files[name] = content.toString("utf-8");
callback();
}
};

var ifs = c.inputFileSystem;
c.inputFileSystem = Object.create(ifs);
c.inputFileSystem.readFile = function() {
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
ifs.readFile.apply(ifs, args.concat([function(err, result) {
if(err) return callback(err);
callback(null, result.toString("utf-8").replace(/\r/g, ""));
}]));
};
c.apply(new webpack.optimize.OccurrenceOrderPlugin());
});
c.run(function(err, stats) {
if(err) return done(err);

if(/error$/.test(testName)) {
stats.compilation.errors.length.should.be.above(0);
} else {
stats.compilation.errors.length.should.equal(0);
stats.hasErrors().should.be.equal(true);
} else if(stats.hasErrors()) {
done(new Error(stats.toJson().errors.join("\n\n")));
}

var toStringOptions = {
Expand Down
17 changes: 17 additions & 0 deletions test/statsCases/define-plugin/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Hash: 22655fdde3386763624eb84e3c3c9ea7106aac84
Child
Hash: 22655fdde3386763624e
Version: webpack 1.12.0
Time: Xms
Asset Size Chunks Chunk Names
bundle.js 1.43 kB 0 [emitted] main
chunk {0} bundle.js (main) 24 bytes [rendered]
[0] (webpack)/test/statsCases/define-plugin/index.js 24 bytes {0} [built]
Child
Hash: b84e3c3c9ea7106aac84
Version: webpack 1.12.0
Time: Xms
Asset Size Chunks Chunk Names
bundle.js 1.43 kB 0 [emitted] main
chunk {0} bundle.js (main) 24 bytes [rendered]
[0] (webpack)/test/statsCases/define-plugin/index.js 24 bytes {0} [built]
1 change: 1 addition & 0 deletions test/statsCases/define-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = VALUE;
21 changes: 21 additions & 0 deletions test/statsCases/define-plugin/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var webpack = require("../../../");
module.exports = [
{
entry: "./index",
stats: "errors-only",
plugins: [
new webpack.DefinePlugin({
VALUE: "123"
})
]
},
{
entry: "./index",
stats: "errors-only",
plugins: [
new webpack.DefinePlugin({
VALUE: "321"
})
]
}
];

0 comments on commit 159ef42

Please sign in to comment.