Skip to content

Commit d3a9712

Browse files
committed
bug fixing
1 parent 6cb4a7f commit d3a9712

File tree

13 files changed

+62
-23
lines changed

13 files changed

+62
-23
lines changed

lib/Chunk.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ Chunk.prototype.remove = function(reason) {
100100
};
101101

102102
Chunk.prototype.integrate = function(other, reason) {
103-
// console.log("integrate " + other.toString() + " into " + this.toString());
103+
if(!this.canBeIntegrated(other)) return false;
104+
104105
var otherModules = other.modules.slice();
105106
otherModules.forEach(function(m) {
106107
m.removeChunk(other);
@@ -135,6 +136,7 @@ Chunk.prototype.integrate = function(other, reason) {
135136
else if(origin.reasons[0] !== reason) origin.reasons.unshift(reason);
136137
this.origins.push(origin);
137138
}, this);
139+
return true;
138140
};
139141

140142
Chunk.prototype.isEmpty = function() {
@@ -162,7 +164,18 @@ Chunk.prototype.size = function(options) {
162164
return modulesSize * (this.initial ? ENTRY_CHUNK_MULTIPLICATOR : 1) + CHUNK_OVERHEAD;
163165
};
164166

167+
Chunk.prototype.canBeIntegrated = function(other) {
168+
if(other.initial) return false;
169+
if(this.initial) {
170+
if(other.parents.length !== 1 || other.parents[0] !== this) return false;
171+
}
172+
return true;
173+
};
174+
165175
Chunk.prototype.integratedSize = function(other, options) {
176+
// Chunk if it's possible to integrate this chunks
177+
if(!this.canBeIntegrated(other)) return false;
178+
166179
var CHUNK_OVERHEAD = options.chunkOverhead || 10000;
167180
var ENTRY_CHUNK_MULTIPLICATOR = options.entryChunkMultiplicator || 10;
168181

lib/Compilation.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,13 @@ Compilation.prototype.addModuleDependencies = function(module, dependencies, bai
194194
dependantModule.issuer = module.identifier();
195195
var newModule = this.addModule(dependantModule, cacheGroup);
196196

197-
if(!newModule) {
197+
if(!newModule) { // from cache
198198
dependantModule = this.getModule(dependantModule);
199199

200+
if(dependantModule.id === 0) return errorOrWarningAndCallback(
201+
new ModuleNotFoundError(module, new Error("a dependency to an entry point is not allowed"))
202+
);
203+
200204
dependencies.forEach(function(dep) {
201205
dep.module = dependantModule;
202206
dependantModule.addReason(module, dep);
@@ -212,7 +216,7 @@ Compilation.prototype.addModuleDependencies = function(module, dependencies, bai
212216
return callback();
213217
}
214218

215-
if(newModule instanceof Module) { // from cache
219+
if(newModule instanceof Module) {
216220
if(this.profile)
217221
newModule.profile = dependantModule.profile;
218222

@@ -337,6 +341,7 @@ Compilation.prototype.addEntry = function process(context, entry, name, callback
337341
if(err) return callback(err);
338342

339343
if(module) {
344+
if(module.reasons.length > 0) return callback(new Error("module cannot be added as entry point, because its already in the bundle"));
340345
this.preparedChunks.push({
341346
name: name,
342347
module: module
@@ -486,6 +491,9 @@ Compilation.prototype.sortItems = function sortItems() {
486491
this.modules.sort(byId);
487492
this.modules.forEach(function(module) {
488493
module.chunks.sort(byId);
494+
module.reasons.sort(function(a, b) {
495+
return byId(a.module, b.module)
496+
});
489497
});
490498
this.chunks.forEach(function(chunk) {
491499
chunk.modules.sort(byId);

lib/optimize/LimitChunkCountPlugin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ LimitChunkCountPlugin.prototype.apply = function(compiler) {
3131
var ab = pair[0].integratedSize(pair[1], options);
3232
pair.unshift(a + b - ab, ab);
3333
});
34+
combinations = combinations.filter(function(pair) {
35+
return pair[1] !== false;
36+
});
3437
combinations.sort(function(a,b) {
3538
var diff = b[0] - a[0];
3639
if(diff != 0) return diff;
@@ -39,9 +42,10 @@ LimitChunkCountPlugin.prototype.apply = function(compiler) {
3942

4043
var pair = combinations[0];
4144

42-
pair[2].integrate(pair[3], "limit");
43-
chunks.splice(chunks.indexOf(pair[3]), 1);
44-
this.restartApplyPlugins();
45+
if(pair[2].integrate(pair[3], "limit")) {
46+
chunks.splice(chunks.indexOf(pair[3]), 1);
47+
this.restartApplyPlugins();
48+
}
4549
}
4650
});
4751
});

lib/optimize/MergeDuplicateChunksPlugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ MergeDuplicateChunksPlugin.prototype.apply = function(compiler) {
1717
compilation.plugin("optimize-chunks", function(chunks) {
1818
var map = {};
1919
chunks.slice().forEach(function(chunk) {
20+
if(chunk.initial) return;
2021
var ident = getChunkIdentifier(chunk);
2122
if(map[ident]) {
22-
map[ident].integrate(chunk, "duplicate");
23-
chunks.splice(chunks.indexOf(chunk), 1);
23+
if(map[ident].integrate(chunk, "duplicate"))
24+
chunks.splice(chunks.indexOf(chunk), 1);
2425
return;
2526
}
2627
map[ident] = chunk;

lib/optimize/MinChunkSizePlugin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ MinChunkSizePlugin.prototype.apply = function(compiler) {
3838
pair.unshift(a + b - ab, ab);
3939
});
4040

41+
combinations = combinations.filter(function(pair) {
42+
return pair[1] !== false;
43+
});
44+
4145
combinations.sort(function(a,b) {
4246
var diff = b[0] - a[0];
4347
if(diff != 0) return diff;

test/Errors.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,28 @@ describe("Errors", function() {
5858
errors.length.should.be.eql(0);
5959
warnings.length.should.be.eql(1);
6060
var lines = warnings[0].split("\n");
61-
lines[0].should.match(/require.extensions.js/);
61+
lines[0].should.match(/require.extensions\.js/);
6262
lines[1].should.match(/require.extensions is not supported by webpack/);
6363
done();
6464
});
6565
});
66+
it("should throw an error if you try to require an entry point", function(done) {
67+
getErrors({
68+
entry: {
69+
a: "./require-entry-point",
70+
b: "./entry-point",
71+
c: ["./entry-point2"]
72+
}
73+
}, function(errors, warnings) {
74+
errors.length.should.be.eql(2);
75+
warnings.length.should.be.eql(0);
76+
var lines = errors[0].split("\n");
77+
lines[0].should.match(/require-entry-point\.js/);
78+
lines[1].should.match(/a dependency to an entry point is not allowed/);
79+
lines = errors[1].split("\n");
80+
lines[0].should.match(/require-entry-point\.js/);
81+
lines[1].should.match(/a dependency to an entry point is not allowed/);
82+
done();
83+
});
84+
});
6685
});

test/browsertest/lib/index.web.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ describe("main", function() {
8787

8888
it("should polyfill process and module", function(done) {
8989
module.id.should.have.type("number");
90-
module.id.should.be.eql(require.resolve("./index.web.js"));
9190
require.ensure([], function(require) {
9291
test(Array.isArray(process.argv), "process.argv should be an array");
9392
process.nextTick(function() {

test/cases/chunks/context/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
it("should also work in a chunk", function(done) {
22
require.ensure([], function(require) {
3-
var contextRequire = require.context(".");
3+
var contextRequire = require.context(".", false, /two/);
44
contextRequire("./two").should.be.eql(2);
55
var tw = "tw";
66
require("." + "/" + tw + "o").should.be.eql(2);

test/cases/parsing/extract-amd/index.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,6 @@ it("should parse a bound function expression 4", function(done) {
186186
}.bind(null, 123));
187187
});
188188

189-
it("should create a context if require passed to IIFE (renaming todo)", function(done) {
190-
require.ensure([], function(require) {
191-
(function(req) {
192-
req.keys.should.be.type("function");
193-
done();
194-
}(require));
195-
});
196-
});
197-
198189
it("should not fail issue #138 second", function() {
199190
(function(define, global) { 'use strict';
200191
define(function (require) {

test/cases/parsing/extract-amd/warnings.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)