Skip to content

Commit ddc9988

Browse files
committed
Merge branch 'master' of https://github.com/webpack/webpack into jest
2 parents 002b04f + 56170c3 commit ddc9988

File tree

25 files changed

+296
-31
lines changed

25 files changed

+296
-31
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@ Most of the time, if webpack is not working correctly for you it is a simple con
1111

1212
If you are still having difficulty after looking over your configuration carefully, please post
1313
a question to [StackOverflow with the webpack tag](http://stackoverflow.com/tags/webpack). Questions
14-
that include your webpack.config.js and relevant files are more likely to receive responses.
14+
that include your webpack.config.js, relevant files, and the full error message are more likely to receive responses.
1515

1616
**If you have discovered a bug or have a feature suggestion, please [create an issue on GitHub](https://github.com/webpack/webpack/issues/new).**
1717

18+
Do you want to fix an issue? Look at the issues with a tag of [X5: work required (PR / Help Wanted)](https://github.com/webpack/webpack/labels/X5%3A%20work%20required%20%28PR%20%2F%20Help%20Wanted%29). Each issue should be tagged with a difficulty tag -
19+
20+
- D0: My First Commit (Contribution Difficulty)
21+
- D1: Easy (Contribution Difficulty)
22+
- D2: Medium (Contribution Difficulty)
23+
- D3: Hard (Contribution Difficulty)
24+
1825
## Contributing to the webpack ecosystem
1926

20-
If you have created your own loader/plugin please include it on the relevant
21-
documentation pages:
27+
If you have created your own loader/plugin please include it on the relevant documentation pages:
2228

23-
[List of loaders](https://webpack.js.org/loaders/) or [awesome-webpack](https://github.com/webpack-contrib/awesome-webpack#loaders)
24-
[List of plugins](https://webpack.js.org/plugins) or [awesome-webpack](https://github.com/webpack-contrib/awesome-webpack#webpack-plugins)
29+
- [List of loaders](https://webpack.js.org/loaders/) or [awesome-webpack](https://github.com/webpack-contrib/awesome-webpack#loaders)
30+
- [List of plugins](https://webpack.js.org/plugins) or [awesome-webpack](https://github.com/webpack-contrib/awesome-webpack#webpack-plugins)
2531

2632
## Setup
2733

@@ -43,7 +49,7 @@ Some things that will increase the chance that your pull request is accepted:
4349

4450
webpack is insanely feature rich and documentation is a huge time sink. We
4551
greatly appreciate any time spent fixing typos or clarifying sections in the
46-
documentation.
52+
documentation. [See a list of issues with the documentation tag.](https://github.com/webpack/webpack/labels/documentation)
4753

4854
## Discussions
4955

SECURITY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Reporting Security Issues
2+
3+
If you discover a security issue in webpack, please report it by sending an
4+
email to [webpack@opencollective.com](mailto:webpack@opencollective.com).
5+
6+
This will allow us to assess the risk, and make a fix available before we add a
7+
bug report to the GitHub repository.
8+
9+
Thanks for helping make webpack safe for everyone.

_SETUP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Setup your local webpack repository
1616
git clone https://github.com/webpack/webpack.git
1717
cd webpack
1818
npm install -g yarn
19-
yarn install
19+
yarn
2020
yarn link
2121
yarn link webpack
2222
```

lib/Stats.js

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class Stats {
135135
const showBuiltAt = optionOrLocalFallback(options.builtAt, true);
136136
const showAssets = optionOrLocalFallback(options.assets, true);
137137
const showEntrypoints = optionOrLocalFallback(options.entrypoints, true);
138+
const showChunkGroups = optionOrLocalFallback(
139+
options.chunkGroups,
140+
!forToString
141+
);
138142
const showChunks = optionOrLocalFallback(options.chunks, !forToString);
139143
const showChunkModules = optionOrLocalFallback(options.chunkModules, true);
140144
const showChunkOrigins = optionOrLocalFallback(
@@ -396,15 +400,15 @@ class Stats {
396400
obj.assets.sort(sortByField(sortAssets));
397401
}
398402

399-
if (showEntrypoints) {
400-
obj.entrypoints = {};
401-
for (const keyValuePair of compilation.entrypoints) {
403+
const fnChunkGroup = groupMap => {
404+
const obj = {};
405+
for (const keyValuePair of groupMap) {
402406
const name = keyValuePair[0];
403-
const ep = keyValuePair[1];
404-
const children = ep.getChildrenByOrders();
405-
obj.entrypoints[name] = {
406-
chunks: ep.chunks.map(c => c.id),
407-
assets: ep.chunks.reduce(
407+
const cg = keyValuePair[1];
408+
const children = cg.getChildrenByOrders();
409+
obj[name] = {
410+
chunks: cg.chunks.map(c => c.id),
411+
assets: cg.chunks.reduce(
408412
(array, c) => array.concat(c.files || []),
409413
[]
410414
),
@@ -436,9 +440,19 @@ class Stats {
436440
}, Object.create(null))
437441
};
438442
if (showPerformance) {
439-
obj.entrypoints[name].isOverSizeLimit = ep.isOverSizeLimit;
443+
obj[name].isOverSizeLimit = cg.isOverSizeLimit;
440444
}
441445
}
446+
447+
return obj;
448+
};
449+
450+
if (showEntrypoints) {
451+
obj.entrypoints = fnChunkGroup(compilation.entrypoints);
452+
}
453+
454+
if (showChunkGroups) {
455+
obj.namedChunkGroups = fnChunkGroup(compilation.namedChunkGroups);
442456
}
443457

444458
const fnModule = module => {
@@ -866,22 +880,23 @@ class Stats {
866880
colors.normal(obj.filteredAssets !== 1 ? " assets" : " asset");
867881
newline();
868882
}
869-
if (obj.entrypoints) {
870-
for (const name of Object.keys(obj.entrypoints)) {
871-
const ep = obj.entrypoints[name];
872-
colors.normal("Entrypoint ");
883+
884+
const processChunkGroups = (namedGroups, prefix) => {
885+
for (const name of Object.keys(namedGroups)) {
886+
const cg = namedGroups[name];
887+
colors.normal(`${prefix} `);
873888
colors.bold(name);
874-
if (ep.isOverSizeLimit) {
889+
if (cg.isOverSizeLimit) {
875890
colors.normal(" ");
876891
colors.yellow("[big]");
877892
}
878893
colors.normal(" =");
879-
for (const asset of ep.assets) {
894+
for (const asset of cg.assets) {
880895
colors.normal(" ");
881896
colors.green(asset);
882897
}
883-
for (const name of Object.keys(ep.childAssets)) {
884-
const assets = ep.childAssets[name];
898+
for (const name of Object.keys(cg.childAssets)) {
899+
const assets = cg.childAssets[name];
885900
if (assets && assets.length > 0) {
886901
colors.normal(" ");
887902
colors.magenta(`(${name}:`);
@@ -894,7 +909,25 @@ class Stats {
894909
}
895910
newline();
896911
}
912+
};
913+
914+
if (obj.entrypoints) {
915+
processChunkGroups(obj.entrypoints, "Entrypoint");
897916
}
917+
918+
if (obj.namedChunkGroups) {
919+
let outputChunkGroups = obj.namedChunkGroups;
920+
if (obj.entrypoints) {
921+
outputChunkGroups = Object.keys(outputChunkGroups)
922+
.filter(name => !obj.entrypoints[name])
923+
.reduce((result, name) => {
924+
result[name] = obj.namedChunkGroups[name];
925+
return result;
926+
}, {});
927+
}
928+
processChunkGroups(outputChunkGroups, "Chunk Group");
929+
}
930+
898931
const modulesByIdentifier = {};
899932
if (obj.modules) {
900933
for (const module of obj.modules) {
@@ -1260,6 +1293,7 @@ class Stats {
12601293
case "verbose":
12611294
return {
12621295
entrypoints: true,
1296+
chunkGroups: true,
12631297
modules: false,
12641298
chunks: true,
12651299
chunkModules: true,
@@ -1278,6 +1312,7 @@ class Stats {
12781312
case "detailed":
12791313
return {
12801314
entrypoints: true,
1315+
chunkGroups: true,
12811316
chunks: true,
12821317
chunkModules: false,
12831318
chunkOrigins: true,

lib/dependencies/ImportParserPlugin.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ class ImportParserPlugin {
3333

3434
const importOptions = parser.getCommentOptions(expr.range);
3535
if (importOptions) {
36+
if (typeof importOptions.webpackIgnore !== "undefined") {
37+
if (typeof importOptions.webpackIgnore !== "boolean") {
38+
parser.state.module.warnings.push(
39+
new UnsupportedFeatureWarning(
40+
parser.state.module,
41+
`\`webpackIgnore\` expected a boolean, but received: ${
42+
importOptions.webpackIgnore
43+
}.`
44+
)
45+
);
46+
} else {
47+
// Do not instrument `import()` is `webpackIgnore` is `true`
48+
if (importOptions.webpackIgnore) {
49+
return false;
50+
}
51+
}
52+
}
3653
if (typeof importOptions.webpackChunkName !== "undefined") {
3754
if (typeof importOptions.webpackChunkName !== "string") {
3855
parser.state.module.warnings.push(

lib/util/Queue.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
11
"use strict";
22

3-
module.exports = class Queue {
3+
/**
4+
* @template T
5+
*/
6+
class Queue {
7+
/**
8+
* @param {IterableIterator<T>=} items The initial elements.
9+
*/
410
constructor(items) {
11+
/** @private @type {Set<T>} */
512
this.set = new Set(items);
13+
/** @private @type {Iterator<T>} */
614
this.iterator = this.set[Symbol.iterator]();
715
}
816

17+
/**
18+
* Returns the number of elements in this queue.
19+
* @return {number} The number of elements in this queue.
20+
*/
921
get length() {
1022
return this.set.size;
1123
}
1224

25+
/**
26+
* Appends the specified element to this queue.
27+
* @param {T} item The element to add.
28+
* @return {void}
29+
*/
1330
enqueue(item) {
1431
this.set.add(item);
1532
}
1633

34+
/**
35+
* Retrieves and removes the head of this queue.
36+
* @return {T | undefined} The head of the queue of `undefined` if this queue is empty.
37+
*/
1738
dequeue() {
1839
const result = this.iterator.next();
1940
if (result.done) return undefined;
2041
this.set.delete(result.value);
2142
return result.value;
2243
}
23-
};
44+
}
45+
46+
module.exports = Queue;

lib/util/identifier.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
"use strict";
22
const path = require("path");
33

4+
/**
5+
* @typedef {Object} MakeRelativePathsCache
6+
* @property {Map<string, Map<string, string>>=} relativePaths
7+
*/
8+
9+
/**
10+
*
11+
* @param {string} maybeAbsolutePath path to check
12+
* @return {boolean} returns true if path is "Absolute Path"-like
13+
*/
414
const looksLikeAbsolutePath = maybeAbsolutePath => {
515
return /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
616
};
717

18+
/**
19+
*
20+
* @param {string} p path to normalize
21+
* @return {string} normalized version of path
22+
*/
823
const normalizePathSeparator = p => p.replace(/\\/g, "/");
924

25+
/**
26+
*
27+
* @param {string} context context for relative path
28+
* @param {string} identifier identifier for path
29+
* @return {string} a converted relative path
30+
*/
1031
const _makePathsRelative = (context, identifier) => {
1132
return identifier
1233
.split(/([|! ])/)
@@ -19,6 +40,13 @@ const _makePathsRelative = (context, identifier) => {
1940
.join("");
2041
};
2142

43+
/**
44+
*
45+
* @param {string} context context used to create relative path
46+
* @param {string} identifier identifier used to create relative path
47+
* @param {MakeRelativePathsCache=} cache the cache object being set
48+
* @return {string} the returned relative path
49+
*/
2250
exports.makePathsRelative = (context, identifier, cache) => {
2351
if (!cache) return _makePathsRelative(context, identifier);
2452

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"simple-git": "^1.65.0",
6464
"sinon": "^2.3.2",
6565
"style-loader": "^0.19.1",
66-
"typescript": "^2.9.0-dev.20180412",
66+
"typescript": "^2.9.0-dev.20180424",
6767
"url-loader": "^0.6.2",
6868
"val-loader": "^1.0.2",
6969
"vm-browserify": "~0.0.0",
@@ -88,7 +88,8 @@
8888
"buildin/",
8989
"hot/",
9090
"web_modules/",
91-
"schemas/"
91+
"schemas/",
92+
"SECURITY.md"
9293
],
9394
"scripts": {
9495
"setup": "node ./setup/setup.js",

schemas/WebpackOptions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,10 @@
18531853
"type": "boolean",
18541854
"description": "Display the entry points with the corresponding bundles"
18551855
},
1856+
"chunkGroups": {
1857+
"type": "boolean",
1858+
"description": "Display all chunk groups with the corresponding bundles"
1859+
},
18561860
"errorDetails": {
18571861
"type": "boolean",
18581862
"description": "add details to errors (like resolving log)"

test/Stats.unittest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ describe(
114114
warnings: [],
115115
assets: [],
116116
entrypoints: new Map(),
117+
namedChunkGroups: new Map(),
117118
chunks: [],
118119
modules: [],
119120
children: [],
@@ -140,6 +141,7 @@ describe(
140141
assets: [],
141142
entrypoints: new Map(),
142143
chunks: [],
144+
namedChunkGroups: new Map(),
143145
modules: [],
144146
children: [],
145147
hash: "1234",
@@ -160,6 +162,7 @@ describe(
160162
children: [],
161163
chunks: [],
162164
entrypoints: {},
165+
namedChunkGroups: {},
163166
filteredAssets: 0,
164167
filteredModules: 0,
165168
errors: [],
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const should = require("should");
4+
5+
it("should be able to ignore import()", () => {
6+
const source = fs.readFileSync(path.join(__dirname, "bundle1.js"), "utf-8");
7+
should(source).containEql(`import(/* webpackIgnore: true */ "./other2.js")`);
8+
should(source).not.containEql(`import(/* webpackIgnore: false */ "./other3.js")`);
9+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import(/* webpackIgnore: true */ "./other2.js");
2+
import(/* webpackIgnore: false */ "./other3.js");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "other2";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "other3";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
entry: {
3+
bundle0: "./index.js",
4+
bundle1: "./other.js"
5+
},
6+
output: {
7+
filename: "[name].js"
8+
},
9+
node: {
10+
__dirname: false
11+
}
12+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./shared";
2+
3+
export default "a";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./shared";
2+
3+
export default "b";

0 commit comments

Comments
 (0)