webpack 2.2.0 → 2.2.1

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 (61) hide show
  1. package/README.md +39 -63
  2. package/lib/APIPlugin.js +2 -8
  3. package/lib/AsyncDependenciesBlock.js +46 -55
  4. package/lib/ChunkTemplate.js +25 -26
  5. package/lib/CompatibilityPlugin.js +49 -46
  6. package/lib/Compilation.js +279 -138
  7. package/lib/ConstPlugin.js +2 -6
  8. package/lib/DefinePlugin.js +9 -27
  9. package/lib/EnvironmentPlugin.js +25 -9
  10. package/lib/EvalDevToolModulePlugin.js +15 -10
  11. package/lib/EvalSourceMapDevToolPlugin.js +24 -18
  12. package/lib/ExtendedAPIPlugin.js +1 -6
  13. package/lib/FlagDependencyExportsPlugin.js +72 -79
  14. package/lib/FlagInitialModulesAsUsedPlugin.js +17 -13
  15. package/lib/FunctionModulePlugin.js +17 -11
  16. package/lib/HotModuleReplacementPlugin.js +3 -13
  17. package/lib/HotUpdateChunkTemplate.js +21 -22
  18. package/lib/JsonpTemplatePlugin.js +15 -11
  19. package/lib/LoaderTargetPlugin.js +14 -10
  20. package/lib/MainTemplate.js +193 -191
  21. package/lib/MultiWatching.js +16 -14
  22. package/lib/NoEmitOnErrorsPlugin.js +14 -11
  23. package/lib/NodeStuffPlugin.js +6 -30
  24. package/lib/NormalModuleFactory.js +2 -2
  25. package/lib/NormalModuleReplacementPlugin.js +36 -31
  26. package/lib/Parser.js +8 -7
  27. package/lib/ParserHelpers.js +19 -5
  28. package/lib/ProvidePlugin.js +2 -6
  29. package/lib/RequestShortener.js +49 -47
  30. package/lib/RequireJsStuffPlugin.js +5 -20
  31. package/lib/RuleSet.js +28 -20
  32. package/lib/Template.js +133 -132
  33. package/lib/compareLocations.js +9 -8
  34. package/lib/dependencies/AMDPlugin.js +111 -115
  35. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +157 -154
  36. package/lib/dependencies/CommonJsPlugin.js +81 -85
  37. package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +73 -75
  38. package/lib/dependencies/ContextDependencyTemplateAsId.js +21 -18
  39. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +23 -29
  40. package/lib/dependencies/CriticalDependencyWarning.js +13 -8
  41. package/lib/dependencies/{HarmonyCompatiblilityDependency.js → HarmonyCompatibilityDependency.js} +3 -3
  42. package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
  43. package/lib/dependencies/HarmonyModulesPlugin.js +51 -49
  44. package/lib/dependencies/ImportParserPlugin.js +31 -28
  45. package/lib/dependencies/ImportPlugin.js +28 -24
  46. package/lib/dependencies/LocalModule.js +17 -13
  47. package/lib/dependencies/ModuleDependencyTemplateAsId.js +15 -17
  48. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +15 -17
  49. package/lib/dependencies/RequireContextPlugin.js +59 -57
  50. package/lib/dependencies/RequireEnsurePlugin.js +22 -26
  51. package/lib/dependencies/RequireIncludePlugin.js +18 -23
  52. package/lib/dependencies/RequireResolveDependencyParserPlugin.js +59 -56
  53. package/lib/dependencies/SystemPlugin.js +34 -36
  54. package/lib/dependencies/WebpackMissingModule.js +10 -18
  55. package/lib/node/NodeTargetPlugin.js +8 -5
  56. package/lib/node/NodeWatchFileSystem.js +54 -53
  57. package/lib/optimize/CommonsChunkPlugin.js +163 -166
  58. package/lib/optimize/RemoveParentModulesPlugin.js +36 -27
  59. package/lib/validateSchema.js +18 -18
  60. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +22 -20
  61. package/package.json +12 -6
@@ -2,64 +2,65 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var Watchpack = require("watchpack");
5
+ "use strict";
6
6
 
7
- function NodeWatchFileSystem(inputFileSystem) {
8
- this.inputFileSystem = inputFileSystem;
9
- this.watcherOptions = {
10
- aggregateTimeout: 0
11
- };
12
- this.watcher = new Watchpack(this.watcherOptions);
13
- }
7
+ const Watchpack = require("watchpack");
14
8
 
15
- module.exports = NodeWatchFileSystem;
9
+ class NodeWatchFileSystem {
10
+ constructor(inputFileSystem) {
11
+ this.inputFileSystem = inputFileSystem;
12
+ this.watcherOptions = {
13
+ aggregateTimeout: 0
14
+ };
15
+ this.watcher = new Watchpack(this.watcherOptions);
16
+ }
16
17
 
17
- NodeWatchFileSystem.prototype.watch = function watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
18
- if(!Array.isArray(files))
19
- throw new Error("Invalid arguments: 'files'");
20
- if(!Array.isArray(dirs))
21
- throw new Error("Invalid arguments: 'dirs'");
22
- if(!Array.isArray(missing))
23
- throw new Error("Invalid arguments: 'missing'");
24
- if(typeof callback !== "function")
25
- throw new Error("Invalid arguments: 'callback'");
26
- if(typeof startTime !== "number" && startTime)
27
- throw new Error("Invalid arguments: 'startTime'");
28
- if(typeof options !== "object")
29
- throw new Error("Invalid arguments: 'options'");
30
- if(typeof callbackUndelayed !== "function" && callbackUndelayed)
31
- throw new Error("Invalid arguments: 'callbackUndelayed'");
32
- var oldWatcher = this.watcher;
33
- this.watcher = new Watchpack(options);
18
+ watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
19
+ if(!Array.isArray(files))
20
+ throw new Error("Invalid arguments: 'files'");
21
+ if(!Array.isArray(dirs))
22
+ throw new Error("Invalid arguments: 'dirs'");
23
+ if(!Array.isArray(missing))
24
+ throw new Error("Invalid arguments: 'missing'");
25
+ if(typeof callback !== "function")
26
+ throw new Error("Invalid arguments: 'callback'");
27
+ if(typeof startTime !== "number" && startTime)
28
+ throw new Error("Invalid arguments: 'startTime'");
29
+ if(typeof options !== "object")
30
+ throw new Error("Invalid arguments: 'options'");
31
+ if(typeof callbackUndelayed !== "function" && callbackUndelayed)
32
+ throw new Error("Invalid arguments: 'callbackUndelayed'");
33
+ const oldWatcher = this.watcher;
34
+ this.watcher = new Watchpack(options);
34
35
 
35
- if(callbackUndelayed)
36
- this.watcher.once("change", callbackUndelayed);
36
+ if(callbackUndelayed)
37
+ this.watcher.once("change", callbackUndelayed);
37
38
 
38
- this.watcher.once("aggregated", function(changes) {
39
- if(this.inputFileSystem && this.inputFileSystem.purge) {
40
- this.inputFileSystem.purge(changes);
41
- }
42
- var times = this.watcher.getTimes();
43
- callback(null, changes.filter(function(file) {
44
- return files.indexOf(file) >= 0;
45
- }).sort(), changes.filter(function(file) {
46
- return dirs.indexOf(file) >= 0;
47
- }).sort(), changes.filter(function(file) {
48
- return missing.indexOf(file) >= 0;
49
- }).sort(), times, times);
50
- }.bind(this));
39
+ this.watcher.once("aggregated", (changes) => {
40
+ if(this.inputFileSystem && this.inputFileSystem.purge) {
41
+ this.inputFileSystem.purge(changes);
42
+ }
43
+ const times = this.watcher.getTimes();
44
+ callback(null,
45
+ changes.filter(file => files.indexOf(file) >= 0).sort(),
46
+ changes.filter(file => dirs.indexOf(file) >= 0).sort(),
47
+ changes.filter(file => missing.indexOf(file) >= 0).sort(), times, times);
48
+ });
51
49
 
52
- this.watcher.watch(files.concat(missing), dirs, startTime);
50
+ this.watcher.watch(files.concat(missing), dirs, startTime);
53
51
 
54
- if(oldWatcher) {
55
- oldWatcher.close();
52
+ if(oldWatcher) {
53
+ oldWatcher.close();
54
+ }
55
+ return {
56
+ close: () => {
57
+ this.watcher.close();
58
+ },
59
+ pause: () => {
60
+ this.watcher.pause();
61
+ }
62
+ };
56
63
  }
57
- return {
58
- close: function() {
59
- this.watcher.close();
60
- }.bind(this),
61
- pause: function() {
62
- this.watcher.pause();
63
- }.bind(this)
64
- };
65
- };
64
+ }
65
+
66
+ module.exports = NodeWatchFileSystem;
@@ -2,183 +2,180 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var nextIdent = 0;
5
+ "use strict";
6
+ let nextIdent = 0;
7
+ class CommonsChunkPlugin {
8
+ constructor(options) {
9
+ if(arguments.length > 1) {
10
+ throw new Error(`Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options
11
+ object *or* the name of the chunk.
12
+ Example: if your old code looked like this:
13
+ new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js')
14
+ You would change it to:
15
+ new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.bundle.js' })
16
+ The available options are:
17
+ name: string
18
+ names: string[]
19
+ filename: string
20
+ minChunks: number
21
+ chunks: string[]
22
+ children: boolean
23
+ async: boolean
24
+ minSize: number`);
25
+ }
6
26
 
7
- function CommonsChunkPlugin(options) {
8
- if(arguments.length > 1) {
9
- throw new Error("Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options " +
10
- "object *or* the name of the chunk.\n" +
11
- "Example: if your old code looked like this:\n" +
12
- " new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js')\n\n" +
13
- "You would change it to:\n" +
14
- " new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.bundle.js' })\n\n" +
15
- "The available options are:\n" +
16
- " name: string\n" +
17
- " names: string[]\n" +
18
- " filename: string\n" +
19
- " minChunks: number\n" +
20
- " chunks: string[]\n" +
21
- " children: boolean\n" +
22
- " async: boolean\n" +
23
- " minSize: number\n");
27
+ if(Array.isArray(options) || typeof options === "string") {
28
+ options = {
29
+ name: options
30
+ };
31
+ }
32
+ this.chunkNames = options.name || options.names;
33
+ this.filenameTemplate = options.filename;
34
+ this.minChunks = options.minChunks;
35
+ this.selectedChunks = options.chunks;
36
+ if(options.children) this.selectedChunks = false;
37
+ this.async = options.async;
38
+ this.minSize = options.minSize;
39
+ this.ident = __filename + (nextIdent++);
24
40
  }
25
- if(Array.isArray(options) || typeof options === "string") {
26
- options = {
27
- name: options
28
- };
29
- }
30
- this.chunkNames = options.name || options.names;
31
- this.filenameTemplate = options.filename;
32
- this.minChunks = options.minChunks;
33
- this.selectedChunks = options.chunks;
34
- if(options.children) this.selectedChunks = false;
35
- this.async = options.async;
36
- this.minSize = options.minSize;
37
- this.ident = __filename + (nextIdent++);
38
- }
39
-
40
- module.exports = CommonsChunkPlugin;
41
- CommonsChunkPlugin.prototype.apply = function(compiler) {
42
- var chunkNames = this.chunkNames;
43
- var filenameTemplate = this.filenameTemplate;
44
- var minChunks = this.minChunks;
45
- var selectedChunks = this.selectedChunks;
46
- var asyncOption = this.async;
47
- var minSize = this.minSize;
48
- var ident = this.ident;
49
- compiler.plugin("this-compilation", function(compilation) {
50
- compilation.plugin(["optimize-chunks", "optimize-extracted-chunks"], function(chunks) {
51
- // only optimize once
52
- if(compilation[ident]) return;
53
- compilation[ident] = true;
41
+ apply(compiler) {
42
+ const chunkNames = this.chunkNames;
43
+ const filenameTemplate = this.filenameTemplate;
44
+ const minChunks = this.minChunks;
45
+ const selectedChunks = this.selectedChunks;
46
+ const asyncOption = this.async;
47
+ const minSize = this.minSize;
48
+ const ident = this.ident;
49
+ compiler.plugin("this-compilation", (compilation) => {
50
+ compilation.plugin(["optimize-chunks", "optimize-extracted-chunks"], (chunks) => {
51
+ // only optimize once
52
+ if(compilation[ident]) return;
53
+ compilation[ident] = true;
54
54
 
55
- var commonChunks;
56
- if(!chunkNames && (selectedChunks === false || asyncOption)) {
57
- commonChunks = chunks;
58
- } else if(Array.isArray(chunkNames) || typeof chunkNames === "string") {
59
- commonChunks = [].concat(chunkNames).map(function(chunkName) {
60
- var chunk = chunks.filter(function(chunk) {
61
- return chunk.name === chunkName;
62
- })[0];
63
- if(!chunk) {
64
- chunk = this.addChunk(chunkName);
65
- }
66
- return chunk;
67
- }, this);
68
- } else {
69
- throw new Error("Invalid chunkNames argument");
70
- }
71
- commonChunks.forEach(function processCommonChunk(commonChunk, idx) {
72
- var usedChunks;
73
- if(Array.isArray(selectedChunks)) {
74
- usedChunks = chunks.filter(function(chunk) {
75
- if(chunk === commonChunk) return false;
76
- return selectedChunks.indexOf(chunk.name) >= 0;
77
- });
78
- } else if(selectedChunks === false || asyncOption) {
79
- usedChunks = (commonChunk.chunks || []).filter(function(chunk) {
80
- // we can only move modules from this chunk if the "commonChunk" is the only parent
81
- return asyncOption || chunk.parents.length === 1;
55
+ let commonChunks;
56
+ if(!chunkNames && (selectedChunks === false || asyncOption)) {
57
+ commonChunks = chunks;
58
+ } else if(Array.isArray(chunkNames) || typeof chunkNames === "string") {
59
+ commonChunks = [].concat(chunkNames).map((chunkName) => {
60
+ let chunk = chunks.filter((chunk) => chunk.name === chunkName)[0];
61
+ if(!chunk) {
62
+ chunk = compilation.addChunk(chunkName);
63
+ }
64
+ return chunk;
82
65
  });
83
66
  } else {
84
- if(commonChunk.parents.length > 0) {
85
- compilation.errors.push(new Error("CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (" + commonChunk.name + ")"));
86
- return;
87
- }
88
- usedChunks = chunks.filter(function(chunk) {
89
- var found = commonChunks.indexOf(chunk);
90
- if(found >= idx) return false;
91
- return chunk.hasRuntime();
92
- });
67
+ throw new Error("Invalid chunkNames argument");
93
68
  }
94
- if(asyncOption) {
95
- var asyncChunk = this.addChunk(typeof asyncOption === "string" ? asyncOption : undefined);
96
- asyncChunk.chunkReason = "async commons chunk";
97
- asyncChunk.extraAsync = true;
98
- asyncChunk.addParent(commonChunk);
99
- commonChunk.addChunk(asyncChunk);
100
- commonChunk = asyncChunk;
101
- }
102
- var reallyUsedModules = [];
103
- if(minChunks !== Infinity) {
104
- var commonModulesCount = [];
105
- var commonModules = [];
106
- usedChunks.forEach(function(chunk) {
107
- chunk.modules.forEach(function(module) {
108
- var idx = commonModules.indexOf(module);
109
- if(idx < 0) {
110
- commonModules.push(module);
111
- commonModulesCount.push(1);
112
- } else {
113
- commonModulesCount[idx]++;
114
- }
69
+ commonChunks.forEach(function processCommonChunk(commonChunk, idx) {
70
+ let usedChunks;
71
+ if(Array.isArray(selectedChunks)) {
72
+ usedChunks = chunks.filter(chunk => chunk !== commonChunk && selectedChunks.indexOf(chunk.name) >= 0);
73
+ } else if(selectedChunks === false || asyncOption) {
74
+ usedChunks = (commonChunk.chunks || []).filter((chunk) => {
75
+ // we can only move modules from this chunk if the "commonChunk" is the only parent
76
+ return asyncOption || chunk.parents.length === 1;
115
77
  });
116
- });
117
- var _minChunks = (minChunks || Math.max(2, usedChunks.length));
118
- commonModulesCount.forEach(function(count, idx) {
119
- var module = commonModules[idx];
120
- if(typeof minChunks === "function") {
121
- if(!minChunks(module, count))
122
- return;
123
- } else if(count < _minChunks) {
78
+ } else {
79
+ if(commonChunk.parents.length > 0) {
80
+ compilation.errors.push(new Error("CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (" + commonChunk.name + ")"));
124
81
  return;
125
82
  }
126
- if(module.chunkCondition && !module.chunkCondition(commonChunk))
127
- return;
128
- reallyUsedModules.push(module);
129
- });
130
- }
131
- if(minSize) {
132
- var size = reallyUsedModules.reduce(function(a, b) {
133
- return a + b.size();
134
- }, 0);
135
- if(size < minSize)
136
- return;
137
- }
138
- var reallyUsedChunks = [];
139
- reallyUsedModules.forEach(function(module) {
140
- usedChunks.forEach(function(chunk) {
141
- if(module.removeChunk(chunk)) {
142
- if(reallyUsedChunks.indexOf(chunk) < 0)
143
- reallyUsedChunks.push(chunk);
144
- }
145
- });
146
- commonChunk.addModule(module);
147
- module.addChunk(commonChunk);
148
- });
149
- if(asyncOption) {
150
- reallyUsedChunks.forEach(function(chunk) {
151
- if(chunk.isInitial())
152
- return;
153
- chunk.blocks.forEach(function(block) {
154
- block.chunks.unshift(commonChunk);
155
- commonChunk.addBlock(block);
83
+ usedChunks = chunks.filter((chunk) => {
84
+ const found = commonChunks.indexOf(chunk);
85
+ if(found >= idx) return false;
86
+ return chunk.hasRuntime();
156
87
  });
157
- });
158
- asyncChunk.origins = reallyUsedChunks.map(function(chunk) {
159
- return chunk.origins.map(function(origin) {
160
- var newOrigin = Object.create(origin);
161
- newOrigin.reasons = (origin.reasons || []).slice();
162
- newOrigin.reasons.push("async commons");
163
- return newOrigin;
88
+ }
89
+ let asyncChunk;
90
+ if(asyncOption) {
91
+ asyncChunk = compilation.addChunk(typeof asyncOption === "string" ? asyncOption : undefined);
92
+ asyncChunk.chunkReason = "async commons chunk";
93
+ asyncChunk.extraAsync = true;
94
+ asyncChunk.addParent(commonChunk);
95
+ commonChunk.addChunk(asyncChunk);
96
+ commonChunk = asyncChunk;
97
+ }
98
+ const reallyUsedModules = [];
99
+ if(minChunks !== Infinity) {
100
+ const commonModulesCount = [];
101
+ const commonModules = [];
102
+ usedChunks.forEach((chunk) => {
103
+ chunk.modules.forEach((module) => {
104
+ const idx = commonModules.indexOf(module);
105
+ if(idx < 0) {
106
+ commonModules.push(module);
107
+ commonModulesCount.push(1);
108
+ } else {
109
+ commonModulesCount[idx]++;
110
+ }
111
+ });
164
112
  });
165
- }).reduce(function(arr, a) {
166
- arr.push.apply(arr, a);
167
- return arr;
168
- }, []);
169
- } else {
170
- usedChunks.forEach(function(chunk) {
171
- chunk.parents = [commonChunk];
172
- chunk.entrypoints.forEach(function(ep) {
173
- ep.insertChunk(commonChunk, chunk);
113
+ const _minChunks = (minChunks || Math.max(2, usedChunks.length));
114
+ commonModulesCount.forEach((count, idx) => {
115
+ const module = commonModules[idx];
116
+ if(typeof minChunks === "function") {
117
+ if(!minChunks(module, count))
118
+ return;
119
+ } else if(count < _minChunks) {
120
+ return;
121
+ }
122
+ if(module.chunkCondition && !module.chunkCondition(commonChunk))
123
+ return;
124
+ reallyUsedModules.push(module);
174
125
  });
175
- commonChunk.addChunk(chunk);
126
+ }
127
+ if(minSize) {
128
+ const size = reallyUsedModules.reduce((a, b) => {
129
+ return a + b.size();
130
+ }, 0);
131
+ if(size < minSize)
132
+ return;
133
+ }
134
+ const reallyUsedChunks = new Set();
135
+ reallyUsedModules.forEach((module) => {
136
+ usedChunks.forEach((chunk) => {
137
+ if(module.removeChunk(chunk)) {
138
+ reallyUsedChunks.add(chunk);
139
+ }
140
+ });
141
+ commonChunk.addModule(module);
142
+ module.addChunk(commonChunk);
176
143
  });
177
- }
178
- if(filenameTemplate)
179
- commonChunk.filenameTemplate = filenameTemplate;
180
- }, this);
181
- return true;
144
+ if(asyncOption) {
145
+ for(const chunk of reallyUsedChunks) {
146
+ if(chunk.isInitial()) continue;
147
+ chunk.blocks.forEach((block) => {
148
+ block.chunks.unshift(commonChunk);
149
+ commonChunk.addBlock(block);
150
+ });
151
+ }
152
+ asyncChunk.origins = Array.from(reallyUsedChunks).map((chunk) => {
153
+ return chunk.origins.map((origin) => {
154
+ const newOrigin = Object.create(origin);
155
+ newOrigin.reasons = (origin.reasons || []).slice();
156
+ newOrigin.reasons.push("async commons");
157
+ return newOrigin;
158
+ });
159
+ }).reduce((arr, a) => {
160
+ arr.push.apply(arr, a);
161
+ return arr;
162
+ }, []);
163
+ } else {
164
+ usedChunks.forEach((chunk) => {
165
+ chunk.parents = [commonChunk];
166
+ chunk.entrypoints.forEach((ep) => {
167
+ ep.insertChunk(commonChunk, chunk);
168
+ });
169
+ commonChunk.addChunk(chunk);
170
+ });
171
+ }
172
+ if(filenameTemplate)
173
+ commonChunk.filenameTemplate = filenameTemplate;
174
+ });
175
+ return true;
176
+ });
182
177
  });
183
- });
184
- };
178
+ }
179
+ }
180
+
181
+ module.exports = CommonsChunkPlugin;
@@ -24,32 +24,35 @@ function hasModule(chunk, module, checkedChunks) {
24
24
 
25
25
  function allHaveModule(someChunks, module, checkedChunks) {
26
26
  if(!checkedChunks) checkedChunks = [];
27
- let chunks = [];
27
+ var chunks = [];
28
28
  for(var i = 0; i < someChunks.length; i++) {
29
29
  checkedChunks.push(someChunks[i]);
30
- const subChunks = hasModule(someChunks[i], module, checkedChunks);
30
+ var subChunks = hasModule(someChunks[i], module, checkedChunks);
31
31
  if(!subChunks) return false;
32
- addToSet(chunks, subChunks);
32
+
33
+ for(var index = 0; index < subChunks.length; index++) {
34
+ var item = subChunks[index];
35
+
36
+ if(!chunks.length || chunks.indexOf(item) < 0) {
37
+ chunks.push(item);
38
+ }
39
+ }
33
40
  }
34
41
  return chunks;
35
42
  }
36
43
 
37
- function addToSet(set, items) {
38
- items.forEach((item) => {
39
- if(set.indexOf(item) < 0)
40
- set.push(item);
41
- });
42
- }
43
-
44
44
  function debugIds(chunks) {
45
- const list = chunks.map((chunk) => {
46
- return chunk.debugId;
47
- });
48
- const debugIdMissing = list.some((dId) => {
49
- return typeof dId !== "number";
50
- });
51
- if(debugIdMissing)
52
- return "no";
45
+ var list = [];
46
+ for(var i = 0; i < chunks.length; i++) {
47
+ var debugId = chunks[i].debugId;
48
+
49
+ if(typeof debugId !== "number") {
50
+ return "no";
51
+ }
52
+
53
+ list.push(debugId);
54
+ }
55
+
53
56
  list.sort();
54
57
  return list.join(",");
55
58
  }
@@ -58,13 +61,19 @@ class RemoveParentModulesPlugin {
58
61
  apply(compiler) {
59
62
  compiler.plugin("compilation", (compilation) => {
60
63
  compilation.plugin(["optimize-chunks-basic", "optimize-extracted-chunks-basic"], (chunks) => {
61
- chunks.forEach((chunk) => {
62
- const cache = {};
63
- chunk.modules.slice().forEach((module) => {
64
- if(chunk.parents.length === 0) return;
65
- const dId = "$" + debugIds(module.chunks);
66
- let parentChunksWithModule;
67
- if((dId in cache) && dId !== "$no") {
64
+ for(var index = 0; index < chunks.length; index++) {
65
+ var chunk = chunks[index];
66
+
67
+ // TODO consider Map when performance has improved https://gist.github.com/sokra/b36098368da7b8f6792fd7c85fca6311
68
+ var cache = Object.create(null);
69
+ var modules = chunk.modules.slice();
70
+ for(var i = 0; i < modules.length; i++) {
71
+ var module = modules[i];
72
+
73
+ if(chunk.parents.length === 0) continue;
74
+ var dId = debugIds(module.chunks);
75
+ var parentChunksWithModule;
76
+ if((dId in cache) && dId !== "no") {
68
77
  parentChunksWithModule = cache[dId];
69
78
  } else {
70
79
  parentChunksWithModule = cache[dId] = allHaveModule(chunk.parents, module);
@@ -73,8 +82,8 @@ class RemoveParentModulesPlugin {
73
82
  module.rewriteChunkInReasons(chunk, parentChunksWithModule);
74
83
  chunk.removeModule(module);
75
84
  }
76
- });
77
- });
85
+ }
86
+ }
78
87
  });
79
88
  });
80
89
  }
@@ -2,8 +2,10 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Gajus Kuizinas @gajus
4
4
  */
5
- var Ajv = require("ajv");
6
- var ajv = new Ajv({
5
+ "use strict";
6
+
7
+ const Ajv = require("ajv");
8
+ const ajv = new Ajv({
7
9
  errorDataPath: "configuration",
8
10
  allErrors: true,
9
11
  verbose: true
@@ -12,16 +14,16 @@ require("ajv-keywords")(ajv, ["instanceof"]);
12
14
 
13
15
  function validateSchema(schema, options) {
14
16
  if(Array.isArray(options)) {
15
- var errors = options.map(validateObject.bind(this, schema));
16
- errors.forEach(function(list, idx) {
17
+ const errors = options.map((options) => validateObject(schema, options));
18
+ errors.forEach((list, idx) => {
17
19
  list.forEach(function applyPrefix(err) {
18
- err.dataPath = "[" + idx + "]" + err.dataPath;
20
+ err.dataPath = `[${idx}]${err.dataPath}`;
19
21
  if(err.children) {
20
22
  err.children.forEach(applyPrefix);
21
23
  }
22
24
  });
23
25
  });
24
- return errors.reduce(function(arr, items) {
26
+ return errors.reduce((arr, items) => {
25
27
  return arr.concat(items);
26
28
  }, []);
27
29
  } else {
@@ -30,22 +32,20 @@ function validateSchema(schema, options) {
30
32
  }
31
33
 
32
34
  function validateObject(schema, options) {
33
- var validate = ajv.compile(schema);
34
- var valid = validate(options);
35
+ const validate = ajv.compile(schema);
36
+ const valid = validate(options);
35
37
  return valid ? [] : filterErrors(validate.errors);
36
38
  }
37
39
 
38
40
  function filterErrors(errors) {
39
- var newErrors = [];
40
- errors.forEach(function(err) {
41
- var dataPath = err.dataPath;
42
- var children = [];
43
- newErrors = newErrors.filter(function(oldError) {
44
- if(oldError.dataPath.indexOf(dataPath) >= 0) {
41
+ let newErrors = [];
42
+ errors.forEach((err) => {
43
+ const dataPath = err.dataPath;
44
+ let children = [];
45
+ newErrors = newErrors.filter((oldError) => {
46
+ if(oldError.dataPath.includes(dataPath)) {
45
47
  if(oldError.children) {
46
- oldError.children.forEach(function(child) {
47
- children.push(child);
48
- });
48
+ children = children.concat(oldError.children.slice(0));
49
49
  }
50
50
  oldError.children = undefined;
51
51
  children.push(oldError);
@@ -58,7 +58,7 @@ function filterErrors(errors) {
58
58
  }
59
59
  newErrors.push(err);
60
60
  });
61
- //console.log(JSON.stringify(newErrors, 0, 2));
61
+
62
62
  return newErrors;
63
63
  }
64
64