webpack 4.8.2 → 4.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +95 -52
  2. package/bin/webpack.js +128 -43
  3. package/lib/AmdMainTemplatePlugin.js +10 -0
  4. package/lib/AsyncDependencyToInitialChunkError.js +12 -2
  5. package/lib/BannerPlugin.js +115 -101
  6. package/lib/CaseSensitiveModulesWarning.js +20 -2
  7. package/lib/Chunk.js +1 -0
  8. package/lib/ChunkGroup.js +465 -465
  9. package/lib/ChunkRenderError.js +8 -0
  10. package/lib/ChunkTemplate.js +71 -71
  11. package/lib/Compilation.js +1 -1
  12. package/lib/Compiler.js +2 -1
  13. package/lib/ContextModule.js +8 -8
  14. package/lib/DllPlugin.js +3 -1
  15. package/lib/DllReferencePlugin.js +2 -1
  16. package/lib/Entrypoint.js +54 -54
  17. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +115 -115
  18. package/lib/ExportPropertyMainTemplatePlugin.js +13 -0
  19. package/lib/Generator.js +52 -52
  20. package/lib/HotModuleReplacement.runtime.js +633 -633
  21. package/lib/JsonParser.js +2 -1
  22. package/lib/LibManifestPlugin.js +9 -0
  23. package/lib/LibraryTemplatePlugin.js +66 -33
  24. package/lib/MainTemplate.js +468 -468
  25. package/lib/Module.js +3 -3
  26. package/lib/ModuleDependencyError.js +12 -2
  27. package/lib/NormalModuleFactory.js +5 -3
  28. package/lib/Parser.js +27 -23
  29. package/lib/ProgressPlugin.js +1 -1
  30. package/lib/RecordIdsPlugin.js +3 -1
  31. package/lib/RuntimeTemplate.js +1 -1
  32. package/lib/SetVarMainTemplatePlugin.js +12 -0
  33. package/lib/SourceMapDevToolPlugin.js +11 -13
  34. package/lib/Template.js +289 -290
  35. package/lib/UmdMainTemplatePlugin.js +67 -32
  36. package/lib/WebpackError.js +8 -2
  37. package/lib/compareLocations.js +20 -0
  38. package/lib/debug/ProfilingPlugin.js +416 -416
  39. package/lib/dependencies/ContextDependencyHelpers.js +142 -142
  40. package/lib/dependencies/WebpackMissingModule.js +2 -2
  41. package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -40
  42. package/lib/optimize/RuntimeChunkPlugin.js +9 -5
  43. package/lib/optimize/SplitChunksPlugin.js +195 -124
  44. package/lib/util/Queue.js +46 -46
  45. package/lib/util/SetHelpers.js +48 -48
  46. package/lib/util/SortableSet.js +106 -106
  47. package/lib/util/StackedSetMap.js +128 -128
  48. package/lib/util/cachedMerge.js +13 -0
  49. package/lib/util/identifier.js +5 -0
  50. package/lib/util/objectToMap.js +16 -16
  51. package/lib/wasm/WebAssemblyGenerator.js +280 -280
  52. package/lib/wasm/WebAssemblyParser.js +79 -79
  53. package/lib/web/JsonpMainTemplatePlugin.js +2 -2
  54. package/package.json +21 -17
  55. package/schemas/WebpackOptions.json +12 -1
  56. package/schemas/plugins/BannerPlugin.json +96 -85
  57. package/schemas/plugins/DllPlugin.json +4 -0
@@ -1,106 +1,106 @@
1
- "use strict";
2
- //TODO: Make this a generic type
3
- //https://github.com/Microsoft/TypeScript/issues/23385
4
- //https://github.com/Microsoft/TypeScript/issues/23384
5
- class SortableSet extends Set {
6
- constructor(initialIterable, defaultSort) {
7
- super(initialIterable);
8
- this._sortFn = defaultSort;
9
- this._lastActiveSortFn = null;
10
- this._cache = undefined;
11
- this._cacheOrderIndependent = undefined;
12
- }
13
-
14
- /**
15
- * @param {TODO} value - value to add to set
16
- * @returns {this} - returns itself
17
- */
18
- add(value) {
19
- this._lastActiveSortFn = null;
20
- this._invalidateCache();
21
- this._invalidateOrderedCache();
22
- super.add(value);
23
- return this;
24
- }
25
-
26
- delete(value) {
27
- this._invalidateCache();
28
- this._invalidateOrderedCache();
29
- return super.delete(value);
30
- }
31
-
32
- clear() {
33
- this._invalidateCache();
34
- this._invalidateOrderedCache();
35
- return super.clear();
36
- }
37
-
38
- sortWith(/** @type {(a: TODO, b: TODO) => number} */ sortFn) {
39
- if (this.size <= 1 || sortFn === this._lastActiveSortFn) {
40
- // already sorted - nothing to do
41
- return;
42
- }
43
-
44
- const sortedArray = Array.from(this).sort(sortFn);
45
- super.clear();
46
- for (let i = 0; i < sortedArray.length; i += 1) {
47
- super.add(sortedArray[i]);
48
- }
49
- this._lastActiveSortFn = sortFn;
50
- this._invalidateCache();
51
- }
52
-
53
- /**
54
- * @returns {void}
55
- */
56
- sort() {
57
- this.sortWith(this._sortFn);
58
- }
59
-
60
- /**
61
- * @param {Function} fn - function to calculate value
62
- * @returns {TODO} - returns result of fn(this), cached until set changes
63
- */
64
- getFromCache(fn) {
65
- if (this._cache === undefined) {
66
- this._cache = new Map();
67
- } else {
68
- const data = this._cache.get(fn);
69
- if (data !== undefined) {
70
- return data;
71
- }
72
- }
73
- const newData = fn(this);
74
- this._cache.set(fn, newData);
75
- return newData;
76
- }
77
-
78
- /**
79
- * @param {Function} fn - function to calculate value
80
- * @returns {TODO} - returns result of fn(this), cached until set changes
81
- */
82
- getFromUnorderedCache(fn) {
83
- if (this._cacheOrderIndependent === undefined) {
84
- this._cacheOrderIndependent = new Map();
85
- } else {
86
- const data = this._cacheOrderIndependent.get(fn);
87
- if (data !== undefined) {
88
- return data;
89
- }
90
- }
91
- const newData = fn(this);
92
- this._cacheOrderIndependent.set(fn, newData);
93
- return newData;
94
- }
95
-
96
- _invalidateCache() {
97
- if (this._cache !== undefined) this._cache.clear();
98
- }
99
-
100
- _invalidateOrderedCache() {
101
- if (this._cacheOrderIndependent !== undefined)
102
- this._cacheOrderIndependent.clear();
103
- }
104
- }
105
-
106
- module.exports = SortableSet;
1
+ "use strict";
2
+ //TODO: Make this a generic type
3
+ //https://github.com/Microsoft/TypeScript/issues/23385
4
+ //https://github.com/Microsoft/TypeScript/issues/23384
5
+ class SortableSet extends Set {
6
+ constructor(initialIterable, defaultSort) {
7
+ super(initialIterable);
8
+ this._sortFn = defaultSort;
9
+ this._lastActiveSortFn = null;
10
+ this._cache = undefined;
11
+ this._cacheOrderIndependent = undefined;
12
+ }
13
+
14
+ /**
15
+ * @param {TODO} value - value to add to set
16
+ * @returns {this} - returns itself
17
+ */
18
+ add(value) {
19
+ this._lastActiveSortFn = null;
20
+ this._invalidateCache();
21
+ this._invalidateOrderedCache();
22
+ super.add(value);
23
+ return this;
24
+ }
25
+
26
+ delete(value) {
27
+ this._invalidateCache();
28
+ this._invalidateOrderedCache();
29
+ return super.delete(value);
30
+ }
31
+
32
+ clear() {
33
+ this._invalidateCache();
34
+ this._invalidateOrderedCache();
35
+ return super.clear();
36
+ }
37
+
38
+ sortWith(/** @type {(a: TODO, b: TODO) => number} */ sortFn) {
39
+ if (this.size <= 1 || sortFn === this._lastActiveSortFn) {
40
+ // already sorted - nothing to do
41
+ return;
42
+ }
43
+
44
+ const sortedArray = Array.from(this).sort(sortFn);
45
+ super.clear();
46
+ for (let i = 0; i < sortedArray.length; i += 1) {
47
+ super.add(sortedArray[i]);
48
+ }
49
+ this._lastActiveSortFn = sortFn;
50
+ this._invalidateCache();
51
+ }
52
+
53
+ /**
54
+ * @returns {void}
55
+ */
56
+ sort() {
57
+ this.sortWith(this._sortFn);
58
+ }
59
+
60
+ /**
61
+ * @param {Function} fn - function to calculate value
62
+ * @returns {TODO} - returns result of fn(this), cached until set changes
63
+ */
64
+ getFromCache(fn) {
65
+ if (this._cache === undefined) {
66
+ this._cache = new Map();
67
+ } else {
68
+ const data = this._cache.get(fn);
69
+ if (data !== undefined) {
70
+ return data;
71
+ }
72
+ }
73
+ const newData = fn(this);
74
+ this._cache.set(fn, newData);
75
+ return newData;
76
+ }
77
+
78
+ /**
79
+ * @param {Function} fn - function to calculate value
80
+ * @returns {TODO} - returns result of fn(this), cached until set changes
81
+ */
82
+ getFromUnorderedCache(fn) {
83
+ if (this._cacheOrderIndependent === undefined) {
84
+ this._cacheOrderIndependent = new Map();
85
+ } else {
86
+ const data = this._cacheOrderIndependent.get(fn);
87
+ if (data !== undefined) {
88
+ return data;
89
+ }
90
+ }
91
+ const newData = fn(this);
92
+ this._cacheOrderIndependent.set(fn, newData);
93
+ return newData;
94
+ }
95
+
96
+ _invalidateCache() {
97
+ if (this._cache !== undefined) this._cache.clear();
98
+ }
99
+
100
+ _invalidateOrderedCache() {
101
+ if (this._cacheOrderIndependent !== undefined)
102
+ this._cacheOrderIndependent.clear();
103
+ }
104
+ }
105
+
106
+ module.exports = SortableSet;
@@ -1,128 +1,128 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const util = require("util");
8
-
9
- const TOMBSTONE = {};
10
- const UNDEFINED_MARKER = {};
11
-
12
- class StackedSetMap {
13
- constructor(parentStack) {
14
- this.stack = parentStack === undefined ? [] : parentStack.slice();
15
- this.map = new Map();
16
- this.stack.push(this.map);
17
- }
18
-
19
- add(item) {
20
- this.map.set(item, true);
21
- }
22
-
23
- set(item, value) {
24
- this.map.set(item, value === undefined ? UNDEFINED_MARKER : value);
25
- }
26
-
27
- delete(item) {
28
- if (this.stack.length > 1) this.map.set(item, TOMBSTONE);
29
- else this.map.delete(item);
30
- }
31
-
32
- has(item) {
33
- const topValue = this.map.get(item);
34
- if (topValue !== undefined) return topValue !== TOMBSTONE;
35
- if (this.stack.length > 1) {
36
- for (var i = this.stack.length - 2; i >= 0; i--) {
37
- const value = this.stack[i].get(item);
38
- if (value !== undefined) {
39
- this.map.set(item, value);
40
- return value !== TOMBSTONE;
41
- }
42
- }
43
- this.map.set(item, TOMBSTONE);
44
- }
45
- return false;
46
- }
47
-
48
- get(item) {
49
- const topValue = this.map.get(item);
50
- if (topValue !== undefined)
51
- return topValue === TOMBSTONE || topValue === UNDEFINED_MARKER
52
- ? undefined
53
- : topValue;
54
- if (this.stack.length > 1) {
55
- for (var i = this.stack.length - 2; i >= 0; i--) {
56
- const value = this.stack[i].get(item);
57
- if (value !== undefined) {
58
- this.map.set(item, value);
59
- return value === TOMBSTONE || value === UNDEFINED_MARKER
60
- ? undefined
61
- : value;
62
- }
63
- }
64
- this.map.set(item, TOMBSTONE);
65
- }
66
- return undefined;
67
- }
68
-
69
- _compress() {
70
- if (this.stack.length === 1) return;
71
- this.map = new Map();
72
- for (const data of this.stack) {
73
- for (const pair of data) {
74
- if (pair[1] === TOMBSTONE) this.map.delete(pair[0]);
75
- else this.map.set(pair[0], pair[1]);
76
- }
77
- }
78
- this.stack = [this.map];
79
- }
80
-
81
- asArray() {
82
- this._compress();
83
- return Array.from(this.map.entries(), pair => pair[0]);
84
- }
85
-
86
- asSet() {
87
- return new Set(this.asArray());
88
- }
89
-
90
- asPairArray() {
91
- this._compress();
92
- return Array.from(
93
- this.map.entries(),
94
- pair =>
95
- /** @type {[TODO, TODO]} */ (pair[1] === UNDEFINED_MARKER
96
- ? [pair[0], undefined]
97
- : pair)
98
- );
99
- }
100
-
101
- asMap() {
102
- return new Map(this.asPairArray());
103
- }
104
-
105
- get size() {
106
- this._compress();
107
- return this.map.size;
108
- }
109
-
110
- createChild() {
111
- return new StackedSetMap(this.stack);
112
- }
113
-
114
- get length() {
115
- throw new Error("This is no longer an Array");
116
- }
117
-
118
- set length(value) {
119
- throw new Error("This is no longer an Array");
120
- }
121
- }
122
-
123
- // TODO remove in webpack 5
124
- StackedSetMap.prototype.push = util.deprecate(function(item) {
125
- this.add(item);
126
- }, "This is no longer an Array: Use add instead.");
127
-
128
- module.exports = StackedSetMap;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const util = require("util");
8
+
9
+ const TOMBSTONE = {};
10
+ const UNDEFINED_MARKER = {};
11
+
12
+ class StackedSetMap {
13
+ constructor(parentStack) {
14
+ this.stack = parentStack === undefined ? [] : parentStack.slice();
15
+ this.map = new Map();
16
+ this.stack.push(this.map);
17
+ }
18
+
19
+ add(item) {
20
+ this.map.set(item, true);
21
+ }
22
+
23
+ set(item, value) {
24
+ this.map.set(item, value === undefined ? UNDEFINED_MARKER : value);
25
+ }
26
+
27
+ delete(item) {
28
+ if (this.stack.length > 1) this.map.set(item, TOMBSTONE);
29
+ else this.map.delete(item);
30
+ }
31
+
32
+ has(item) {
33
+ const topValue = this.map.get(item);
34
+ if (topValue !== undefined) return topValue !== TOMBSTONE;
35
+ if (this.stack.length > 1) {
36
+ for (var i = this.stack.length - 2; i >= 0; i--) {
37
+ const value = this.stack[i].get(item);
38
+ if (value !== undefined) {
39
+ this.map.set(item, value);
40
+ return value !== TOMBSTONE;
41
+ }
42
+ }
43
+ this.map.set(item, TOMBSTONE);
44
+ }
45
+ return false;
46
+ }
47
+
48
+ get(item) {
49
+ const topValue = this.map.get(item);
50
+ if (topValue !== undefined)
51
+ return topValue === TOMBSTONE || topValue === UNDEFINED_MARKER
52
+ ? undefined
53
+ : topValue;
54
+ if (this.stack.length > 1) {
55
+ for (var i = this.stack.length - 2; i >= 0; i--) {
56
+ const value = this.stack[i].get(item);
57
+ if (value !== undefined) {
58
+ this.map.set(item, value);
59
+ return value === TOMBSTONE || value === UNDEFINED_MARKER
60
+ ? undefined
61
+ : value;
62
+ }
63
+ }
64
+ this.map.set(item, TOMBSTONE);
65
+ }
66
+ return undefined;
67
+ }
68
+
69
+ _compress() {
70
+ if (this.stack.length === 1) return;
71
+ this.map = new Map();
72
+ for (const data of this.stack) {
73
+ for (const pair of data) {
74
+ if (pair[1] === TOMBSTONE) this.map.delete(pair[0]);
75
+ else this.map.set(pair[0], pair[1]);
76
+ }
77
+ }
78
+ this.stack = [this.map];
79
+ }
80
+
81
+ asArray() {
82
+ this._compress();
83
+ return Array.from(this.map.entries(), pair => pair[0]);
84
+ }
85
+
86
+ asSet() {
87
+ return new Set(this.asArray());
88
+ }
89
+
90
+ asPairArray() {
91
+ this._compress();
92
+ return Array.from(
93
+ this.map.entries(),
94
+ pair =>
95
+ /** @type {[TODO, TODO]} */ (pair[1] === UNDEFINED_MARKER
96
+ ? [pair[0], undefined]
97
+ : pair)
98
+ );
99
+ }
100
+
101
+ asMap() {
102
+ return new Map(this.asPairArray());
103
+ }
104
+
105
+ get size() {
106
+ this._compress();
107
+ return this.map.size;
108
+ }
109
+
110
+ createChild() {
111
+ return new StackedSetMap(this.stack);
112
+ }
113
+
114
+ get length() {
115
+ throw new Error("This is no longer an Array");
116
+ }
117
+
118
+ set length(value) {
119
+ throw new Error("This is no longer an Array");
120
+ }
121
+ }
122
+
123
+ // TODO remove in webpack 5
124
+ StackedSetMap.prototype.push = util.deprecate(function(item) {
125
+ this.add(item);
126
+ }, "This is no longer an Array: Use add instead.");
127
+
128
+ module.exports = StackedSetMap;
@@ -6,6 +6,19 @@
6
6
 
7
7
  const mergeCache = new WeakMap();
8
8
 
9
+ /**
10
+ * Merges two given objects and caches the result to avoid computation if same objects passed as arguements again.
11
+ * @example
12
+ * // performs Object.assign(first, second), stores the result in WeakMap and returns result
13
+ * cachedMerge({a: 1}, {a: 2})
14
+ * {a: 2}
15
+ * // when same arguments passed, gets the result from WeakMap and returns it.
16
+ * cachedMerge({a: 1}, {a: 2})
17
+ * {a: 2}
18
+ * @param {object} first first object
19
+ * @param {object} second second object
20
+ * @returns {object} merged object of first and second object
21
+ */
9
22
  const cachedMerge = (first, second) => {
10
23
  let innerCache = mergeCache.get(first);
11
24
  if (innerCache === undefined) {
@@ -12,6 +12,11 @@ const path = require("path");
12
12
  * @returns {boolean} returns true if path is "Absolute Path"-like
13
13
  */
14
14
  const looksLikeAbsolutePath = maybeAbsolutePath => {
15
+ if (/^\/.*\/$/.test(maybeAbsolutePath)) {
16
+ // this 'path' is actually a regexp generated by dynamic requires.
17
+ // Don't treat it as an absolute path.
18
+ return false;
19
+ }
15
20
  return /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
16
21
  };
17
22
 
@@ -1,16 +1,16 @@
1
- /**
2
- * convert an object into its 2D array equivalent to be turned
3
- * into an ES6 map
4
- *
5
- * @param {object} obj - any object type that works with Object.keys()
6
- * @returns {Map<TODO, TODO>} an ES6 Map of KV pairs
7
- */
8
- module.exports = function objectToMap(obj) {
9
- return new Map(
10
- Object.keys(obj).map(key => {
11
- /** @type {[string, string]} */
12
- const pair = [key, obj[key]];
13
- return pair;
14
- })
15
- );
16
- };
1
+ /**
2
+ * convert an object into its 2D array equivalent to be turned
3
+ * into an ES6 map
4
+ *
5
+ * @param {object} obj - any object type that works with Object.keys()
6
+ * @returns {Map<TODO, TODO>} an ES6 Map of KV pairs
7
+ */
8
+ module.exports = function objectToMap(obj) {
9
+ return new Map(
10
+ Object.keys(obj).map(key => {
11
+ /** @type {[string, string]} */
12
+ const pair = [key, obj[key]];
13
+ return pair;
14
+ })
15
+ );
16
+ };