Skip to content

Commit 32bbb84

Browse files
authored
Merge branch 'master' into feature/import_ignore
2 parents f65e9da + a0bfab2 commit 32bbb84

File tree

120 files changed

+1237
-207
lines changed

Some content is hidden

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

120 files changed

+1237
-207
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

_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
```

declarations.d.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
declare module "*.json";
2+
declare module "webpack-cli";
3+
4+
// Deprecated NodeJS API usages in Webpack
5+
declare namespace NodeJS {
6+
interface Process {
7+
binding(internalModule: string): any;
8+
}
9+
}
10+
11+
// There are no typings for chrome-trace-event
12+
declare module 'chrome-trace-event' {
13+
interface Event {
14+
name: string
15+
id?: number
16+
cat: string[]
17+
args?: Object
18+
}
19+
20+
export class Tracer {
21+
constructor(options: {
22+
noStream: boolean
23+
})
24+
pipe(stream: NodeJS.WritableStream) : void
25+
instantEvent(event: Event) : void
26+
counter: number
27+
trace: {
28+
begin(event: Event) : void
29+
end(event: Event) : void
30+
}
31+
}
32+
}
33+
34+
/**
35+
* Global variable declarations
36+
* @todo Once this issue is resolved, remove these globals and add JSDoc onsite instead
37+
* https://github.com/Microsoft/TypeScript/issues/15626
38+
*/
39+
declare const $hash$;
40+
declare const $requestTimeout$;
41+
declare const installedModules;
42+
declare const $require$;
43+
declare const hotDownloadManifest;
44+
declare const hotDownloadUpdateChunk;
45+
declare const hotDisposeChunk;
46+
declare const modules;
47+
declare const installedChunks;
48+
declare const hotAddUpdateChunk;
49+
declare const parentHotUpdateCallback;
50+
declare const $hotChunkFilename$;
51+
declare const $hotMainFilename$;
52+
declare const WebAssembly;
53+
declare const importScripts;
54+
declare const $crossOriginLoading$;
55+
declare const chunkId;

lib/AsyncDependenciesBlock.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,28 @@
66
const DependenciesBlock = require("./DependenciesBlock");
77

88
module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
9-
constructor(name, module, loc, request) {
9+
constructor(groupOptions, module, loc, request) {
1010
super();
11-
this.chunkName = name;
11+
if (typeof groupOptions === "string") {
12+
groupOptions = { name: groupOptions };
13+
} else if (!groupOptions) {
14+
groupOptions = { name: undefined };
15+
}
16+
this.groupOptions = groupOptions;
1217
this.chunkGroup = undefined;
1318
this.module = module;
1419
this.loc = loc;
1520
this.request = request;
1621
}
1722

23+
get chunkName() {
24+
return this.groupOptions.name;
25+
}
26+
27+
set chunkName(value) {
28+
this.groupOptions.name = value;
29+
}
30+
1831
get chunks() {
1932
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
2033
}
@@ -24,7 +37,7 @@ module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
2437
}
2538

2639
updateHash(hash) {
27-
hash.update(this.chunkName || "");
40+
hash.update(JSON.stringify(this.groupOptions));
2841
hash.update(
2942
(this.chunkGroup &&
3043
this.chunkGroup.chunks

lib/Chunk.js

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const util = require("util");
88
const SortableSet = require("./util/SortableSet");
9+
const intersect = require("./util/SetHelpers").intersect;
910
const GraphHelpers = require("./GraphHelpers");
1011
let debugId = 1000;
1112
const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
@@ -170,8 +171,8 @@ class Chunk {
170171
if (aItem.done) return 0;
171172
const aModuleIdentifier = aItem.value.identifier();
172173
const bModuleIdentifier = bItem.value.identifier();
173-
if (aModuleIdentifier > bModuleIdentifier) return -1;
174-
if (aModuleIdentifier < bModuleIdentifier) return 1;
174+
if (aModuleIdentifier < bModuleIdentifier) return -1;
175+
if (aModuleIdentifier > bModuleIdentifier) return 1;
175176
}
176177
}
177178

@@ -321,12 +322,15 @@ class Chunk {
321322
}
322323

323324
getAllAsyncChunks() {
324-
const initialChunks = new Set();
325-
const queue = new Set(this.groupsIterable);
325+
const queue = new Set();
326326
const chunks = new Set();
327327

328-
for (const chunkGroup of queue) {
329-
for (const chunk of chunkGroup.chunks) initialChunks.add(chunk);
328+
const initialChunks = intersect(
329+
Array.from(this.groupsIterable, g => new Set(g.chunks))
330+
);
331+
332+
for (const chunkGroup of this.groupsIterable) {
333+
for (const child of chunkGroup.childrenIterable) queue.add(child);
330334
}
331335

332336
for (const chunkGroup of queue) {
@@ -361,6 +365,62 @@ class Chunk {
361365
};
362366
}
363367

368+
getChildIdsByOrders() {
369+
const lists = new Map();
370+
for (const group of this.groupsIterable) {
371+
if (group.chunks[group.chunks.length - 1] === this) {
372+
for (const childGroup of group.childrenIterable) {
373+
// TODO webpack 5 remove this check for options
374+
if (typeof childGroup.options === "object") {
375+
for (const key of Object.keys(childGroup.options)) {
376+
if (key.endsWith("Order")) {
377+
const name = key.substr(0, key.length - "Order".length);
378+
let list = lists.get(name);
379+
if (list === undefined) lists.set(name, (list = []));
380+
list.push({
381+
order: childGroup.options[key],
382+
group: childGroup
383+
});
384+
}
385+
}
386+
}
387+
}
388+
}
389+
}
390+
const result = Object.create(null);
391+
for (const [name, list] of lists) {
392+
list.sort((a, b) => {
393+
const cmp = b.order - a.order;
394+
if (cmp !== 0) return cmp;
395+
// TOOD webpack 5 remove this check of compareTo
396+
if (a.group.compareTo) return a.group.compareTo(b.group);
397+
return 0;
398+
});
399+
result[name] = Array.from(
400+
list.reduce((set, item) => {
401+
for (const chunk of item.group.chunks) set.add(chunk.id);
402+
return set;
403+
}, new Set())
404+
);
405+
}
406+
return result;
407+
}
408+
409+
getChildIdsByOrdersMap() {
410+
const chunkMaps = Object.create(null);
411+
412+
for (const chunk of this.getAllAsyncChunks()) {
413+
const data = chunk.getChildIdsByOrders();
414+
for (const key of Object.keys(data)) {
415+
let chunkMap = chunkMaps[key];
416+
if (chunkMap === undefined)
417+
chunkMaps[key] = chunkMap = Object.create(null);
418+
chunkMap[chunk.id] = data[key];
419+
}
420+
}
421+
return chunkMaps;
422+
}
423+
364424
getChunkModuleMaps(filterFn) {
365425
const chunkModuleIdMap = Object.create(null);
366426
const chunkModuleHashMap = Object.create(null);

lib/ChunkGroup.js

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,45 @@ const sortOrigin = (a, b) => {
2626
};
2727

2828
class ChunkGroup {
29-
constructor(name) {
29+
constructor(options) {
30+
if (typeof options === "string") {
31+
options = { name: options };
32+
} else if (!options) {
33+
options = { name: undefined };
34+
}
3035
this.groupDebugId = debugId++;
31-
this.name = name;
36+
this.options = options;
3237
this._children = new SortableSet(undefined, sortById);
3338
this._parents = new SortableSet(undefined, sortById);
3439
this._blocks = new SortableSet();
3540
this.chunks = [];
3641
this.origins = [];
3742
}
3843

44+
addOptions(options) {
45+
for (const key of Object.keys(options)) {
46+
if (this.options[key] === undefined) {
47+
this.options[key] = options[key];
48+
} else if (this.options[key] !== options[key]) {
49+
if (key.endsWith("Order")) {
50+
this.options[key] = Math.max(this.options[key], options[key]);
51+
} else {
52+
throw new Error(
53+
`ChunkGroup.addOptions: No option merge strategy for ${key}`
54+
);
55+
}
56+
}
57+
}
58+
}
59+
60+
get name() {
61+
return this.options.name;
62+
}
63+
64+
set name(value) {
65+
this.options.name = value;
66+
}
67+
3968
/* istanbul ignore next */
4069
get debugId() {
4170
return Array.from(this.chunks, x => x.debugId).join("+");
@@ -222,6 +251,18 @@ class ChunkGroup {
222251
return false;
223252
}
224253

254+
getFiles() {
255+
const files = new Set();
256+
257+
for (const chunk of this.chunks) {
258+
for (const file of chunk.files) {
259+
files.add(file);
260+
}
261+
}
262+
263+
return Array.from(files);
264+
}
265+
225266
remove(reason) {
226267
// cleanup parents
227268
for (const parentChunkGroup of this._parents) {
@@ -269,6 +310,53 @@ class ChunkGroup {
269310
this._children.sort();
270311
}
271312

313+
compareTo(otherGroup) {
314+
if (this.chunks.length > otherGroup.chunks.length) return -1;
315+
if (this.chunks.length < otherGroup.chunks.length) return 1;
316+
const a = this.chunks[Symbol.iterator]();
317+
const b = otherGroup.chunks[Symbol.iterator]();
318+
// eslint-disable-next-line
319+
while (true) {
320+
const aItem = a.next();
321+
const bItem = b.next();
322+
if (aItem.done) return 0;
323+
const cmp = aItem.value.compareTo(bItem.value);
324+
if (cmp !== 0) return cmp;
325+
}
326+
}
327+
328+
getChildrenByOrders() {
329+
const lists = new Map();
330+
for (const childGroup of this._children) {
331+
// TODO webpack 5 remove this check for options
332+
if (typeof childGroup.options === "object") {
333+
for (const key of Object.keys(childGroup.options)) {
334+
if (key.endsWith("Order")) {
335+
const name = key.substr(0, key.length - "Order".length);
336+
let list = lists.get(name);
337+
if (list === undefined) lists.set(name, (list = []));
338+
list.push({
339+
order: childGroup.options[key],
340+
group: childGroup
341+
});
342+
}
343+
}
344+
}
345+
}
346+
const result = Object.create(null);
347+
for (const [name, list] of lists) {
348+
list.sort((a, b) => {
349+
const cmp = b.order - a.order;
350+
if (cmp !== 0) return cmp;
351+
// TOOD webpack 5 remove this check of compareTo
352+
if (a.group.compareTo) return a.group.compareTo(b.group);
353+
return 0;
354+
});
355+
result[name] = list.map(i => i.group);
356+
}
357+
return result;
358+
}
359+
272360
checkConstraints() {
273361
const chunk = this;
274362
for (const child of chunk._children) {

0 commit comments

Comments
 (0)