Skip to content

Commit 44f919e

Browse files
committed
Merge branch 'master' into webpack-2
Conflicts: test/statsCases/chunks/expected.txtT
2 parents 7887d61 + 5335781 commit 44f919e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+332
-14
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ root = true
22

33
[*.js]
44
indent_style=tab
5+
trim_trailing_whitespace=true

lib/Dependency.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Dependency.compareLocations = function(a, b) {
3939
if(typeof b === "string") {
4040
return -1;
4141
} else if(typeof b === "object") {
42+
if(a.start) a = a.start;
43+
if(b.start) b = b.start;
4244
if(a.line < b.line) return -1;
4345
if(a.line > b.line) return 1;
4446
if(a.column < b.column) return -1;

lib/Stats.js

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ Stats.prototype.hasErrors = function() {
1919
};
2020

2121
Stats.prototype.toJson = function toJson(options, forToString) {
22-
if(!options) options = {};
22+
if(typeof options === "boolean" || typeof options === "string") {
23+
options = Stats.presetToOptions(options);
24+
} else if(!options) {
25+
options = {};
26+
}
2327

2428
function d(v, def) {
2529
return v === undefined ? def : v;
@@ -39,7 +43,9 @@ Stats.prototype.toJson = function toJson(options, forToString) {
3943
var showReasons = d(options.reasons, !forToString);
4044
var showChildren = d(options.children, true);
4145
var showSource = d(options.source, !forToString);
46+
var showErrors = d(options.errors, true);
4247
var showErrorDetails = d(options.errorDetails, !forToString);
48+
var showWarnings = d(options.warnings, true);
4349
var showPublicPath = d(options.publicPath, !forToString);
4450
var excludeModules = [].concat(d(options.exclude, [])).map(function(str) {
4551
if(typeof str !== "string") return str;
@@ -112,11 +118,23 @@ Stats.prototype.toJson = function toJson(options, forToString) {
112118
}
113119
return text;
114120
}
121+
115122
var obj = {
116123
errors: compilation.errors.map(formatError),
117124
warnings: compilation.warnings.map(formatError)
118125
};
119126

127+
//We just hint other renderers since actually omitting
128+
//errors/warnings from the JSON would be kind of weird.
129+
Object.defineProperty(obj, "_showWarnings", {
130+
value: showWarnings,
131+
enumerable: false
132+
});
133+
Object.defineProperty(obj, "_showErrors", {
134+
value: showErrors,
135+
enumerable: false
136+
});
137+
120138
if(showVersion) {
121139
obj.version = require("../package.json").version;
122140
}
@@ -173,6 +191,8 @@ Stats.prototype.toJson = function toJson(options, forToString) {
173191
id: module.id,
174192
identifier: module.identifier(),
175193
name: module.readableIdentifier(requestShortener),
194+
index: module.index,
195+
index2: module.index2,
176196
size: module.size(),
177197
cacheable: !!module.cacheable,
178198
built: !!module.built,
@@ -275,7 +295,9 @@ Stats.prototype.toJson = function toJson(options, forToString) {
275295
};
276296

277297
Stats.prototype.toString = function toString(options) {
278-
if(!options) options = {};
298+
if(typeof options === "boolean" || typeof options === "string") {
299+
options = Stats.presetToOptions(options);
300+
} else if(!options) options = {};
279301

280302
function d(v, def) {
281303
return v === undefined ? def : v;
@@ -642,14 +664,14 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
642664
newline();
643665
}
644666
}
645-
if(obj.warnings) {
667+
if(obj._showWarnings && obj.warnings) {
646668
obj.warnings.forEach(function(warning) {
647669
newline();
648670
yellow("WARNING in " + warning);
649671
newline();
650672
});
651673
}
652-
if(obj.errors) {
674+
if(obj._showErrors && obj.errors) {
653675
obj.errors.forEach(function(error) {
654676
newline();
655677
red("ERROR in " + error);
@@ -678,3 +700,39 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
678700
while(buf[buf.length - 1] === "\n") buf.pop();
679701
return buf.join("");
680702
};
703+
704+
Stats.presetToOptions = function(name) {
705+
//Accepted values: none, errors-only, minimal, normal, verbose
706+
//Any other falsy value will behave as 'none', truthy values as 'normal'
707+
var pn = (typeof name === "string") && name.toLowerCase() || name;
708+
if(pn === "none" || !pn) {
709+
return {
710+
hash: false,
711+
version: false,
712+
timings: false,
713+
assets: false,
714+
chunks: false,
715+
modules: false,
716+
reasons: false,
717+
children: false,
718+
source: false,
719+
errors: false,
720+
errorDetails: false,
721+
warnings: false,
722+
publicPath: false
723+
};
724+
} else {
725+
return {
726+
assets: pn === "verbose",
727+
version: pn === "verbose",
728+
timings: pn !== "errors-only" && pn !== "minimal",
729+
hash: pn !== "errors-only" && pn !== "minimal",
730+
chunks: pn !== "errors-only",
731+
chunkModules: pn === "verbose",
732+
//warnings: pn !== "errors-only",
733+
errorDetails: pn !== "errors-only" && pn !== "minimal",
734+
reasons: pn === "verbose",
735+
colors: true
736+
};
737+
}
738+
};

lib/optimize/UglifyJsPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
9292
ast.mangle_names(options.mangle || {});
9393
}
9494
var output = {};
95-
output.comments = options.comments || /^\**!|@preserve|@license/;
95+
output.comments = Object.prototype.hasOwnProperty.call(options, "comments") ? options.comments : /^\**!|@preserve|@license/;
9696
output.beautify = options.beautify;
9797
for(var k in options.output) {
9898
output[k] = options.output[k];

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "1.10.5",
3+
"version": "1.11.0",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
66
"dependencies": {
@@ -79,7 +79,7 @@
7979
"lint": "eslint lib",
8080
"beautify-lint": "node ./scripts/beautify-check",
8181
"beautify": "node ./scripts/beautify-rewrite",
82-
"precover": "npm run lint",
82+
"precover": "npm run lint && npm run beautify-lint",
8383
"cover": "istanbul cover -x *.runtime.js node_modules/mocha/bin/_mocha",
8484
"publish-patch": "mocha && npm version patch && git push && git push --tags && npm publish"
8585
}

test/Stats.test.js

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*globals describe it */
2-
require("should");
2+
var should = require("should");
33
var path = require("path");
44
var fs = require("fs");
55

@@ -47,11 +47,26 @@ describe("Stats", function() {
4747
c.apply(new webpack.optimize.OccurrenceOrderPlugin());
4848
c.run(function(err, stats) {
4949
if(err) return done(err);
50-
var actual = stats.toString({
51-
colors: false
52-
});
50+
51+
if(/error$/.test(testName)) {
52+
stats.compilation.errors.length.should.be.above(0);
53+
} else {
54+
stats.compilation.errors.length.should.equal(0);
55+
}
56+
57+
var toStringOptions = { colors: false };
58+
if(typeof options.stats !== "undefined") {
59+
toStringOptions = options.stats;
60+
}
61+
62+
var actual = stats.toString(toStringOptions);
5363
(typeof actual).should.be.eql("string");
54-
actual = actual.replace(/Version:.+\n/, "").replace(/[0-9]+(\s?ms)/g, "X$1").replace(/\r/g, "");
64+
actual =
65+
actual.replace(/\u001b\[[0-9;]*m/g, "")
66+
.replace(/Version:.+\n/, "")
67+
.replace(/[0-9]+(\s?ms)/g, "X$1")
68+
.replace(/\r/g, "")
69+
.replace(path.join(base, testName), "Xdir/" + testName);
5570
var expected = fs.readFileSync(path.join(base, testName, "expected.txt"), "utf-8").replace(/\r/g, "");
5671
if(actual !== expected) {
5772
fs.writeFileSync(path.join(base, testName, "actual.txt"), actual, "utf-8");
@@ -101,5 +116,55 @@ describe("Stats", function() {
101116
obj.errors[0].should.be.equal('firstError');
102117
});
103118
});
104-
119+
describe("Presets", function(){
120+
describe("presetToOptions", function() {
121+
it("returns correct object with 'Normal'", function() {
122+
Stats.presetToOptions("Normal").should.eql({
123+
assets: false,
124+
version: false,
125+
timings: true,
126+
hash: true,
127+
chunks: true,
128+
chunkModules: false,
129+
errorDetails: true,
130+
reasons: false,
131+
colors: true
132+
});
133+
});
134+
it("truthy values behave as 'normal'", function() {
135+
var normalOpts = Stats.presetToOptions('normal');
136+
Stats.presetToOptions("pizza").should.eql(normalOpts);
137+
Stats.presetToOptions(true).should.eql(normalOpts);
138+
Stats.presetToOptions(1).should.eql(normalOpts);
139+
140+
Stats.presetToOptions("verbose").should.not.eql(normalOpts);
141+
Stats.presetToOptions(false).should.not.eql(normalOpts);
142+
});
143+
it("returns correct object with 'none'", function() {
144+
Stats.presetToOptions("none").should.eql({
145+
hash: false,
146+
version: false,
147+
timings: false,
148+
assets: false,
149+
chunks: false,
150+
modules: false,
151+
reasons: false,
152+
children: false,
153+
source: false,
154+
errors: false,
155+
errorDetails: false,
156+
warnings: false,
157+
publicPath: false
158+
});
159+
});
160+
it("falsy values behave as 'none'", function() {
161+
var noneOpts = Stats.presetToOptions('none');
162+
Stats.presetToOptions("").should.eql(noneOpts);
163+
Stats.presetToOptions(null).should.eql(noneOpts);
164+
Stats.presetToOptions().should.eql(noneOpts);
165+
Stats.presetToOptions(0).should.eql(noneOpts);
166+
Stats.presetToOptions(false).should.eql(noneOpts);
167+
});
168+
});
169+
});
105170
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
it("should contain no comments in out chunk", function() {
2+
var fs = require("fs");
3+
var source = fs.readFileSync(__filename, "utf-8");
4+
source.should.not.match(/[^\"]comment should be stripped test\.1[^\"]/);
5+
source.should.not.match(/[^\"]comment should be stripped test\.2[^\"]/);
6+
source.should.not.match(/[^\"]comment should be stripped test\.3[^\"]/);
7+
});
8+
9+
it("should contain comments in vendors chunk", function() {
10+
var fs = require("fs"),
11+
path = require("path");
12+
var source = fs.readFileSync(path.join(__dirname, "vendors.js"), "utf-8");
13+
source.should.containEql("comment should not be stripped vendors.1");
14+
source.should.containEql("// comment should not be stripped vendors.2");
15+
source.should.containEql(" * comment should not be stripped vendors.3");
16+
});
17+
18+
19+
require.include("./test.js");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @preserve comment should be stripped test.1 */
2+
3+
var foo = {};
4+
5+
// comment should be stripped test.2
6+
7+
/**
8+
* comment should be stripped test.3
9+
*/
10+
11+
module.exports = foo;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @preserve comment should not be stripped vendors.1 */
2+
3+
var bar = {};
4+
5+
// comment should not be stripped vendors.2
6+
7+
/**
8+
* comment should not be stripped vendors.3
9+
*/
10+
11+
module.exports = bar;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var webpack = require("../../../../");
2+
module.exports = {
3+
node: {
4+
__dirname: false,
5+
__filename: false
6+
},
7+
entry: {
8+
bundle0: ["./index.js"],
9+
vendors: ["./vendors.js"]
10+
},
11+
output: {
12+
filename: "[name].js"
13+
},
14+
plugins: [
15+
new webpack.optimize.UglifyJsPlugin({
16+
comments: false,
17+
exclude: ["vendors.js"]
18+
})
19+
]
20+
};

0 commit comments

Comments
 (0)