Skip to content

Commit

Permalink
Merge branch 'master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jun 3, 2017
2 parents 302289c + ce74935 commit 9cd0cac
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 22 deletions.
3 changes: 3 additions & 0 deletions lib/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ class Module extends DependenciesBlock {
if(sortChunks)
this._ensureChunksSorted();
this.reasons.sort((a, b) => byId(a.module, b.module));
if(Array.isArray(this.usedExports)) {
this.usedExports.sort();
}
}

unbuild() {
Expand Down
6 changes: 5 additions & 1 deletion lib/SourceMapDevToolPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"use strict";

const path = require("path");
const crypto = require("crypto");
const RequestShortener = require("./RequestShortener");
const ConcatSource = require("webpack-sources").ConcatSource;
const RawSource = require("webpack-sources").RawSource;
Expand Down Expand Up @@ -145,7 +146,10 @@ class SourceMapDevToolPlugin {
query,
basename: basename(filename)
});
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
let sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
if(sourceMapUrl.indexOf("[contenthash]") !== -1) {
sourceMapUrl = sourceMapUrl.replace(/\[contenthash\]/g, crypto.createHash("md5").update(source).digest("hex"));
}
if(currentSourceMappingURLComment !== false) {
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
}
Expand Down
1 change: 1 addition & 0 deletions lib/UmdMainTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class UmdMainTemplatePlugin {
let expr;
let request = m.request;
if(typeof request === "object") request = request[type];
if(typeof request === "undefined") throw new Error("Missing external configuration for type:" + type);
if(Array.isArray(request)) {
expr = `require(${JSON.stringify(request[0])})${accessorToObjectAccess(request.slice(1))}`;
} else
Expand Down
4 changes: 3 additions & 1 deletion lib/optimize/CommonsChunkPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ Take a look at the "name"/"names" or async/children option.`);
moveExtractedChunkBlocksToTargetChunk(chunks, targetChunk) {
for(let chunk of chunks) {
for(let block of chunk.blocks) {
block.chunks.unshift(targetChunk);
if(block.chunks.indexOf(targetChunk) === -1) {
block.chunks.unshift(targetChunk);
}
targetChunk.addBlock(block);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"script-loader": "~0.7.0",
"should": "^11.1.1",
"simple-git": "^1.65.0",
"sinon": "^1.17.7",
"sinon": "^2.3.2",
"style-loader": "~0.13.0",
"url-loader": "~0.5.0",
"val-loader": "~0.5.0",
Expand Down
1 change: 1 addition & 0 deletions test/configCases/async-commons-chunk/existing-name/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "a";
1 change: 1 addition & 0 deletions test/configCases/async-commons-chunk/existing-name/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "b";
1 change: 1 addition & 0 deletions test/configCases/async-commons-chunk/existing-name/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "c";
33 changes: 33 additions & 0 deletions test/configCases/async-commons-chunk/existing-name/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require("should");
const sinon = require("sinon");
const chunkLoadingSpy = sinon.spy(__webpack_require__, 'e');

it("should not have duplicate chunks in blocks", function(done) {
// This split point should contain: a
require.ensure([], function(require) {
require("./a").should.be.eql("a");
}, 'a');

// This split point should contain: a and b - we use CommonsChunksPlugin to
// have it only contain b and make chunk a be an async dependency.
require.ensure([], function(require) {
require("./a").should.be.eql("a");
require("./b").should.be.eql("b");
}, 'a+b');

// This split point should contain: a, b and c - we use CommonsChunksPlugin to
// have it only contain c and make chunks a and a+b be async dependencies.
require.ensure([], function(require) {
require("./a").should.be.eql("a");
require("./b").should.be.eql("b");
require("./c").should.be.eql("c");
}, 'a+b+c');

// Each of the require.ensures above should end up resolving chunks:
// - a
// - a, a+b
// - a, a+b, a+b+c
chunkLoadingSpy.callCount.should.be.eql(6);
chunkLoadingSpy.args.should.be.eql([[0], [0], [1], [0], [1], [2]]);
done();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var webpack = require("../../../../");

module.exports = {
plugins: [
new webpack.optimize.CommonsChunkPlugin({
chunks: ["a+b", "a+b+c"],
async: "a+b",
}),
new webpack.optimize.CommonsChunkPlugin({
chunks: ["a", "a+b"],
async: "a",
}),
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
it("should contain contenthash as query parameter and path", function() {
var fs = require("fs");
var source = fs.readFileSync(__filename, "utf-8");
var match = /sourceMappingURL\s*=.*-([A-Fa-f0-9]{32})\.map\?([A-Fa-f0-9]{32})-([A-Fa-f0-9]{32})/.exec(source);
match.length.should.be.eql(4);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var webpack = require("../../../../");
module.exports = {
node: {
__dirname: false,
__filename: false
},
devtool: "source-map",
output: {
sourceMapFilename: "[file]-[contenthash].map?[contenthash]-[contenthash]",
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
})
]
};
5 changes: 5 additions & 0 deletions test/statsCases/commons-plugin-issue-4980/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const a = "a";
export const b = "b";
export const c = "c";

export default "d";
2 changes: 2 additions & 0 deletions test/statsCases/commons-plugin-issue-4980/entry-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import subA from './submodule-a';
import subB from './submodule-b'
2 changes: 2 additions & 0 deletions test/statsCases/commons-plugin-issue-4980/entry-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import subB from './submodule-a'
import subC from './submodule-c';
29 changes: 29 additions & 0 deletions test/statsCases/commons-plugin-issue-4980/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Hash: 7d3a56317b2e339b1d822897fe6052020598632c
Child
Hash: 7d3a56317b2e339b1d82
Time: Xms
Asset Size Chunks Chunk Names
app.js 1.27 kB 0 [emitted] app
vendor.bd2b4219dfda1a951495.js 443 bytes 1 [emitted] vendor
runtime.js 5.94 kB 2 [emitted] runtime
chunk {0} app.js (app) 185 bytes {1} [initial] [rendered]
[./entry-1.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-1.js 67 bytes {0} [built]
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
[./submodule-b.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-b.js 59 bytes {0} [built]
chunk {1} vendor.bd2b4219dfda1a951495.js (vendor) 87 bytes {2} [initial] [rendered]
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
chunk {2} runtime.js (runtime) 0 bytes [entry] [rendered]
Child
Hash: 2897fe6052020598632c
Time: Xms
Asset Size Chunks Chunk Names
app.js 1.32 kB 0 [emitted] app
vendor.bd2b4219dfda1a951495.js 443 bytes 1 [emitted] vendor
runtime.js 5.94 kB 2 [emitted] runtime
chunk {0} app.js (app) 192 bytes {1} [initial] [rendered]
[./entry-2.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-2.js 67 bytes {0} [built]
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
[./submodule-c.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-c.js 66 bytes {0} [built]
chunk {1} vendor.bd2b4219dfda1a951495.js (vendor) 87 bytes {2} [initial] [rendered]
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
chunk {2} runtime.js (runtime) 0 bytes [entry] [rendered]
3 changes: 3 additions & 0 deletions test/statsCases/commons-plugin-issue-4980/submodule-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import d, { a } from './constants';

export default d + a;
3 changes: 3 additions & 0 deletions test/statsCases/commons-plugin-issue-4980/submodule-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { b, c } from './constants';

export default b + c;
3 changes: 3 additions & 0 deletions test/statsCases/commons-plugin-issue-4980/submodule-c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { a, b, c } from './constants';

export default a + b + c;
35 changes: 35 additions & 0 deletions test/statsCases/commons-plugin-issue-4980/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var CommonsChunkPlugin = require("../../../lib/optimize/CommonsChunkPlugin");
var NamedModulesPlugin = require("../../../lib/NamedModulesPlugin");

// should generate vendor chunk with the same chunkhash for both entries
module.exports = [{
entry: {
app: "./entry-1.js"
},
plugins: [
new NamedModulesPlugin(),
new CommonsChunkPlugin({
name: "vendor",
filename: "[name].[chunkhash].js",
minChunks: m => /constants/.test(m.resource)
}),
new CommonsChunkPlugin({
name: "runtime"
})
]
},{
entry: {
app: "./entry-2.js"
},
plugins: [
new NamedModulesPlugin(),
new CommonsChunkPlugin({
name: "vendor",
filename: "[name].[chunkhash].js",
minChunks: m => /constants/.test(m.resource)
}),
new CommonsChunkPlugin({
name: "runtime"
})
]
}];
60 changes: 41 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ destroy@~1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"

[email protected]:
[email protected], diff@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9"

Expand Down Expand Up @@ -1500,11 +1500,11 @@ form-data@~2.1.1:
combined-stream "^1.0.5"
mime-types "^2.1.12"

formatio@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/formatio/-/formatio-1.1.1.tgz#5ed3ccd636551097383465d996199100e86161e9"
formatio@1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/formatio/-/formatio-1.2.0.tgz#f3b2167d9068c4698a8d51f4f760a39a54d818eb"
dependencies:
samsam "~1.1"
samsam "1.x"

forwarded@~0.1.0:
version "0.1.0"
Expand Down Expand Up @@ -2371,9 +2371,9 @@ [email protected], log-driver@^1.x:
version "1.2.5"
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.5.tgz#7ae4ec257302fd790d557cb10c97100d857b0056"

lolex@1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/lolex/-/lolex-1.3.2.tgz#7c3da62ffcb30f0f5a80a2566ca24e45d8a01f31"
lolex@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/lolex/-/lolex-1.6.0.tgz#3a9a0283452a47d7439e72731b9e07d7386e49f6"

longest@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -2541,6 +2541,10 @@ nan@^2.3.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45"

native-promise-only@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/native-promise-only/-/native-promise-only-0.8.1.tgz#20a318c30cb45f71fe7adfbf7b21c99c1472ef11"

natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
Expand Down Expand Up @@ -2823,6 +2827,12 @@ [email protected]:
version "0.1.7"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"

path-to-regexp@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
dependencies:
isarray "0.0.1"

path-type@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
Expand Down Expand Up @@ -3551,9 +3561,9 @@ safe-buffer@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7"

samsam@1.1.2, samsam@~1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.2.tgz#bec11fdc83a9fda063401210e40176c3024d1567"
samsam@1.x, samsam@^1.1.3:
version "1.2.1"
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.2.1.tgz#edd39093a3184370cb859243b2bdf255e7d8ea67"

sax@~1.2.1:
version "1.2.2"
Expand Down Expand Up @@ -3693,14 +3703,18 @@ simple-git@^1.65.0:
dependencies:
debug "^2.6.7"

sinon@^1.17.7:
version "1.17.7"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-1.17.7.tgz#4542a4f49ba0c45c05eb2e9dd9d203e2b8efe0bf"
sinon@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-2.3.2.tgz#c43a9c570f32baac1159505cfeed19108855df89"
dependencies:
formatio "1.1.1"
lolex "1.3.2"
samsam "1.1.2"
util ">=0.10.3 <1"
diff "^3.1.0"
formatio "1.2.0"
lolex "^1.6.0"
native-promise-only "^0.8.1"
path-to-regexp "^1.7.0"
samsam "^1.1.3"
text-encoding "0.6.4"
type-detect "^4.0.0"

[email protected]:
version "0.0.4"
Expand Down Expand Up @@ -3969,6 +3983,10 @@ tar@^2.2.1:
fstream "^1.0.2"
inherits "2"

[email protected]:
version "0.6.4"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"

text-table@~0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
Expand Down Expand Up @@ -4035,6 +4053,10 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

type-detect@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.3.tgz#0e3f2670b44099b0b46c284d136a7ef49c74c2ea"

type-is@~1.6.6:
version "1.6.15"
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.15.tgz#cab10fb4909e441c82842eafe1ad646c81804410"
Expand Down Expand Up @@ -4122,7 +4144,7 @@ util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"

[email protected], "util@>=0.10.3 <1", util@^0.10.3:
[email protected], util@^0.10.3:
version "0.10.3"
resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9"
dependencies:
Expand Down

0 comments on commit 9cd0cac

Please sign in to comment.