webpack 4.1.0 → 4.4.0

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 (118) hide show
  1. package/README.md +719 -721
  2. package/bin/webpack.js +69 -10
  3. package/lib/APIPlugin.js +84 -84
  4. package/lib/AmdMainTemplatePlugin.js +75 -77
  5. package/lib/AsyncDependencyToInitialChunkError.js +21 -23
  6. package/lib/BannerPlugin.js +101 -101
  7. package/lib/Chunk.js +477 -469
  8. package/lib/ChunkTemplate.js +51 -53
  9. package/lib/Compilation.js +1858 -1851
  10. package/lib/Compiler.js +493 -478
  11. package/lib/ConcurrentCompilationError.js +19 -0
  12. package/lib/ContextModule.js +696 -685
  13. package/lib/ContextModuleFactory.js +245 -243
  14. package/lib/DefinePlugin.js +197 -197
  15. package/lib/DelegatedModule.js +101 -101
  16. package/lib/DependenciesBlockVariable.js +51 -52
  17. package/lib/Dependency.js +53 -52
  18. package/lib/DllModule.js +54 -54
  19. package/lib/DllModuleFactory.js +29 -29
  20. package/lib/EnvironmentPlugin.js +65 -67
  21. package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
  22. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
  23. package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
  24. package/lib/ExternalModule.js +159 -159
  25. package/lib/FunctionModuleTemplatePlugin.js +98 -98
  26. package/lib/HotModuleReplacement.runtime.js +631 -631
  27. package/lib/HotModuleReplacementPlugin.js +407 -406
  28. package/lib/HotUpdateChunkTemplate.js +78 -80
  29. package/lib/JavascriptGenerator.js +228 -229
  30. package/lib/JavascriptModulesPlugin.js +184 -158
  31. package/lib/JsonGenerator.js +42 -42
  32. package/lib/MainTemplate.js +406 -402
  33. package/lib/Module.js +343 -340
  34. package/lib/ModuleBuildError.js +42 -42
  35. package/lib/ModuleError.js +28 -28
  36. package/lib/ModuleFilenameHelpers.js +166 -166
  37. package/lib/ModuleTemplate.js +77 -79
  38. package/lib/ModuleWarning.js +30 -30
  39. package/lib/MultiCompiler.js +271 -259
  40. package/lib/MultiModule.js +78 -75
  41. package/lib/MultiModuleFactory.js +23 -23
  42. package/lib/MultiWatching.js +38 -37
  43. package/lib/NoModeWarning.js +23 -21
  44. package/lib/NormalModule.js +478 -470
  45. package/lib/NormalModuleFactory.js +483 -481
  46. package/lib/OptionsDefaulter.js +80 -86
  47. package/lib/Parser.js +2074 -2071
  48. package/lib/ProgressPlugin.js +231 -231
  49. package/lib/RawModule.js +54 -55
  50. package/lib/RecordIdsPlugin.js +160 -160
  51. package/lib/RemovedPluginError.js +13 -13
  52. package/lib/ResolverFactory.js +64 -67
  53. package/lib/RuntimeTemplate.js +267 -297
  54. package/lib/SetVarMainTemplatePlugin.js +57 -57
  55. package/lib/SourceMapDevToolPlugin.js +302 -308
  56. package/lib/Stats.js +1234 -1212
  57. package/lib/Template.js +205 -205
  58. package/lib/TemplatedPathPlugin.js +170 -143
  59. package/lib/UmdMainTemplatePlugin.js +264 -269
  60. package/lib/Watching.js +193 -193
  61. package/lib/WebAssemblyParser.js +50 -54
  62. package/lib/WebpackOptionsApply.js +401 -401
  63. package/lib/WebpackOptionsDefaulter.js +337 -317
  64. package/lib/WebpackOptionsValidationError.js +316 -319
  65. package/lib/debug/ProfilingPlugin.js +409 -405
  66. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
  67. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  68. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
  69. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  70. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
  71. package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
  74. package/lib/dependencies/ImportDependenciesBlock.js +17 -17
  75. package/lib/dependencies/ImportDependency.js +34 -34
  76. package/lib/dependencies/ImportEagerDependency.js +32 -32
  77. package/lib/dependencies/ImportParserPlugin.js +175 -179
  78. package/lib/dependencies/ImportWeakDependency.js +34 -34
  79. package/lib/dependencies/JsonExportsDependency.js +25 -25
  80. package/lib/dependencies/ModuleDependency.js +20 -20
  81. package/lib/dependencies/NullDependency.js +20 -20
  82. package/lib/dependencies/RequireContextDependency.js +22 -22
  83. package/lib/dependencies/RequireIncludeDependency.js +40 -40
  84. package/lib/dependencies/WebpackMissingModule.js +20 -22
  85. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  86. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  87. package/lib/node/NodeMainTemplatePlugin.js +320 -273
  88. package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
  89. package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
  90. package/lib/optimize/ConcatenatedModule.js +1364 -1366
  91. package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
  92. package/lib/optimize/SplitChunksPlugin.js +519 -491
  93. package/lib/performance/SizeLimitsPlugin.js +105 -105
  94. package/lib/util/TrackingSet.js +35 -35
  95. package/lib/util/objectToMap.js +10 -10
  96. package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
  97. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  98. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  99. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  100. package/lib/web/JsonpMainTemplatePlugin.js +425 -403
  101. package/lib/webpack.js +182 -179
  102. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  103. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  104. package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
  105. package/package.json +9 -8
  106. package/schemas/WebpackOptions.json +1973 -1951
  107. package/schemas/ajv.absolutePath.js +55 -29
  108. package/schemas/plugins/BannerPlugin.json +85 -85
  109. package/schemas/plugins/DllPlugin.json +28 -28
  110. package/schemas/plugins/DllReferencePlugin.json +99 -99
  111. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  112. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  113. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  114. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  115. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  116. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  117. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  118. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,30 +1,30 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const WebpackError = require("./WebpackError");
8
- const cleanUp = require("./ErrorHelpers").cleanUp;
9
-
10
- class ModuleWarning extends WebpackError {
11
- constructor(module, warning) {
12
- super();
13
-
14
- this.name = "ModuleWarning";
15
- this.module = module;
16
- this.message =
17
- warning && typeof warning === "object" && warning.message
18
- ? warning.message
19
- : warning;
20
- this.warning = warning;
21
- this.details =
22
- warning && typeof warning === "object" && warning.stack
23
- ? cleanUp(warning.stack, this.message)
24
- : undefined;
25
-
26
- Error.captureStackTrace(this, this.constructor);
27
- }
28
- }
29
-
30
- module.exports = ModuleWarning;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const WebpackError = require("./WebpackError");
8
+ const { cleanUp } = require("./ErrorHelpers");
9
+
10
+ class ModuleWarning extends WebpackError {
11
+ constructor(module, warning) {
12
+ super();
13
+
14
+ this.name = "ModuleWarning";
15
+ this.module = module;
16
+ this.message =
17
+ warning && typeof warning === "object" && warning.message
18
+ ? warning.message
19
+ : warning;
20
+ this.warning = warning;
21
+ this.details =
22
+ warning && typeof warning === "object" && warning.stack
23
+ ? cleanUp(warning.stack, this.message)
24
+ : undefined;
25
+
26
+ Error.captureStackTrace(this, this.constructor);
27
+ }
28
+ }
29
+
30
+ module.exports = ModuleWarning;
@@ -1,259 +1,271 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const Tapable = require("tapable").Tapable;
8
- const SyncHook = require("tapable").SyncHook;
9
- const MultiHook = require("tapable").MultiHook;
10
- const asyncLib = require("neo-async");
11
- const MultiWatching = require("./MultiWatching");
12
- const MultiStats = require("./MultiStats");
13
-
14
- module.exports = class MultiCompiler extends Tapable {
15
- constructor(compilers) {
16
- super();
17
- this.hooks = {
18
- done: new SyncHook(["stats"]),
19
- invalid: new MultiHook(compilers.map(c => c.hooks.invalid)),
20
- run: new MultiHook(compilers.map(c => c.hooks.run)),
21
- watchClose: new SyncHook([]),
22
- watchRun: new MultiHook(compilers.map(c => c.hooks.watchRun))
23
- };
24
- if (!Array.isArray(compilers)) {
25
- compilers = Object.keys(compilers).map(name => {
26
- compilers[name].name = name;
27
- return compilers[name];
28
- });
29
- }
30
- this.compilers = compilers;
31
- let doneCompilers = 0;
32
- let compilerStats = [];
33
- let index = 0;
34
- for (const compiler of this.compilers) {
35
- let compilerDone = false;
36
- const compilerIndex = index++;
37
- // eslint-disable-next-line no-loop-func
38
- compiler.hooks.done.tap("MultiCompiler", stats => {
39
- if (!compilerDone) {
40
- compilerDone = true;
41
- doneCompilers++;
42
- }
43
- compilerStats[compilerIndex] = stats;
44
- if (doneCompilers === this.compilers.length) {
45
- this.hooks.done.call(new MultiStats(compilerStats));
46
- }
47
- });
48
- // eslint-disable-next-line no-loop-func
49
- compiler.hooks.invalid.tap("MultiCompiler", () => {
50
- if (compilerDone) {
51
- compilerDone = false;
52
- doneCompilers--;
53
- }
54
- });
55
- }
56
- }
57
-
58
- get outputPath() {
59
- let commonPath = this.compilers[0].outputPath;
60
- for (const compiler of this.compilers) {
61
- while (
62
- compiler.outputPath.indexOf(commonPath) !== 0 &&
63
- /[/\\]/.test(commonPath)
64
- ) {
65
- commonPath = commonPath.replace(/[/\\][^/\\]*$/, "");
66
- }
67
- }
68
-
69
- if (!commonPath && this.compilers[0].outputPath[0] === "/") return "/";
70
- return commonPath;
71
- }
72
-
73
- get inputFileSystem() {
74
- throw new Error("Cannot read inputFileSystem of a MultiCompiler");
75
- }
76
-
77
- get outputFileSystem() {
78
- throw new Error("Cannot read outputFileSystem of a MultiCompiler");
79
- }
80
-
81
- set inputFileSystem(value) {
82
- for (const compiler of this.compilers) {
83
- compiler.inputFileSystem = value;
84
- }
85
- }
86
-
87
- set outputFileSystem(value) {
88
- for (const compiler of this.compilers) {
89
- compiler.outputFileSystem = value;
90
- }
91
- }
92
-
93
- validateDependencies(callback) {
94
- const edges = new Set();
95
- const missing = [];
96
- const targetFound = compiler => {
97
- for (const edge of edges) {
98
- if (edge.target === compiler) {
99
- return true;
100
- }
101
- }
102
- return false;
103
- };
104
- const sortEdges = (e1, e2) => {
105
- return (
106
- e1.source.name.localeCompare(e2.source.name) ||
107
- e1.target.name.localeCompare(e2.target.name)
108
- );
109
- };
110
- for (const source of this.compilers) {
111
- if (source.dependencies) {
112
- for (const dep of source.dependencies) {
113
- const target = this.compilers.find(c => c.name === dep);
114
- if (!target) {
115
- missing.push(dep);
116
- } else {
117
- edges.add({
118
- source,
119
- target
120
- });
121
- }
122
- }
123
- }
124
- }
125
- const errors = missing.map(m => `Compiler dependency \`${m}\` not found.`);
126
- const stack = this.compilers.filter(c => !targetFound(c));
127
- while (stack.length > 0) {
128
- const current = stack.pop();
129
- for (const edge of edges) {
130
- if (edge.source === current) {
131
- edges.delete(edge);
132
- const target = edge.target;
133
- if (!targetFound(target)) {
134
- stack.push(target);
135
- }
136
- }
137
- }
138
- }
139
- if (edges.size > 0) {
140
- const lines = Array.from(edges)
141
- .sort(sortEdges)
142
- .map(edge => `${edge.source.name} -> ${edge.target.name}`);
143
- lines.unshift("Circular dependency found in compiler dependencies.");
144
- errors.unshift(lines.join("\n"));
145
- }
146
- if (errors.length > 0) {
147
- const message = errors.join("\n");
148
- callback(new Error(message));
149
- return false;
150
- }
151
- return true;
152
- }
153
-
154
- runWithDependencies(compilers, fn, callback) {
155
- const fulfilledNames = new Set();
156
- let remainingCompilers = compilers;
157
- const isDependencyFulfilled = d => fulfilledNames.has(d);
158
- const getReadyCompilers = () => {
159
- let readyCompilers = [];
160
- let list = remainingCompilers;
161
- remainingCompilers = [];
162
- for (const c of list) {
163
- const ready =
164
- !c.dependencies || c.dependencies.every(isDependencyFulfilled);
165
- if (ready) readyCompilers.push(c);
166
- else remainingCompilers.push(c);
167
- }
168
- return readyCompilers;
169
- };
170
- const runCompilers = callback => {
171
- if (remainingCompilers.length === 0) return callback();
172
- asyncLib.map(
173
- getReadyCompilers(),
174
- (compiler, callback) => {
175
- fn(compiler, err => {
176
- if (err) return callback(err);
177
- fulfilledNames.add(compiler.name);
178
- runCompilers(callback);
179
- });
180
- },
181
- callback
182
- );
183
- };
184
- runCompilers(callback);
185
- }
186
-
187
- watch(watchOptions, handler) {
188
- let watchings = [];
189
- let allStats = this.compilers.map(() => null);
190
- let compilerStatus = this.compilers.map(() => false);
191
- if (this.validateDependencies(handler)) {
192
- this.runWithDependencies(
193
- this.compilers,
194
- (compiler, callback) => {
195
- const compilerIdx = this.compilers.indexOf(compiler);
196
- let firstRun = true;
197
- let watching = compiler.watch(
198
- Array.isArray(watchOptions)
199
- ? watchOptions[compilerIdx]
200
- : watchOptions,
201
- (err, stats) => {
202
- if (err) handler(err);
203
- if (stats) {
204
- allStats[compilerIdx] = stats;
205
- compilerStatus[compilerIdx] = "new";
206
- if (compilerStatus.every(Boolean)) {
207
- const freshStats = allStats.filter((s, idx) => {
208
- return compilerStatus[idx] === "new";
209
- });
210
- compilerStatus.fill(true);
211
- const multiStats = new MultiStats(freshStats);
212
- handler(null, multiStats);
213
- }
214
- }
215
- if (firstRun && !err) {
216
- firstRun = false;
217
- callback();
218
- }
219
- }
220
- );
221
- watchings.push(watching);
222
- },
223
- () => {
224
- // ignore
225
- }
226
- );
227
- }
228
-
229
- return new MultiWatching(watchings, this);
230
- }
231
-
232
- run(callback) {
233
- const allStats = this.compilers.map(() => null);
234
- if (this.validateDependencies(callback)) {
235
- this.runWithDependencies(
236
- this.compilers,
237
- (compiler, callback) => {
238
- const compilerIdx = this.compilers.indexOf(compiler);
239
- compiler.run((err, stats) => {
240
- if (err) return callback(err);
241
- allStats[compilerIdx] = stats;
242
- callback();
243
- });
244
- },
245
- err => {
246
- if (err) return callback(err);
247
- callback(null, new MultiStats(allStats));
248
- }
249
- );
250
- }
251
- }
252
-
253
- purgeInputFileSystem() {
254
- for (const compiler of this.compilers) {
255
- if (compiler.inputFileSystem && compiler.inputFileSystem.purge)
256
- compiler.inputFileSystem.purge();
257
- }
258
- }
259
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const { Tapable, SyncHook, MultiHook } = require("tapable");
8
+ const asyncLib = require("neo-async");
9
+ const MultiWatching = require("./MultiWatching");
10
+ const MultiStats = require("./MultiStats");
11
+ const ConcurrentCompilationError = require("./ConcurrentCompilationError");
12
+
13
+ module.exports = class MultiCompiler extends Tapable {
14
+ constructor(compilers) {
15
+ super();
16
+ this.hooks = {
17
+ done: new SyncHook(["stats"]),
18
+ invalid: new MultiHook(compilers.map(c => c.hooks.invalid)),
19
+ run: new MultiHook(compilers.map(c => c.hooks.run)),
20
+ watchClose: new SyncHook([]),
21
+ watchRun: new MultiHook(compilers.map(c => c.hooks.watchRun))
22
+ };
23
+ if (!Array.isArray(compilers)) {
24
+ compilers = Object.keys(compilers).map(name => {
25
+ compilers[name].name = name;
26
+ return compilers[name];
27
+ });
28
+ }
29
+ this.compilers = compilers;
30
+ let doneCompilers = 0;
31
+ let compilerStats = [];
32
+ let index = 0;
33
+ for (const compiler of this.compilers) {
34
+ let compilerDone = false;
35
+ const compilerIndex = index++;
36
+ // eslint-disable-next-line no-loop-func
37
+ compiler.hooks.done.tap("MultiCompiler", stats => {
38
+ if (!compilerDone) {
39
+ compilerDone = true;
40
+ doneCompilers++;
41
+ }
42
+ compilerStats[compilerIndex] = stats;
43
+ if (doneCompilers === this.compilers.length) {
44
+ this.hooks.done.call(new MultiStats(compilerStats));
45
+ }
46
+ });
47
+ // eslint-disable-next-line no-loop-func
48
+ compiler.hooks.invalid.tap("MultiCompiler", () => {
49
+ if (compilerDone) {
50
+ compilerDone = false;
51
+ doneCompilers--;
52
+ }
53
+ });
54
+ }
55
+ this.running = false;
56
+ }
57
+
58
+ get outputPath() {
59
+ let commonPath = this.compilers[0].outputPath;
60
+ for (const compiler of this.compilers) {
61
+ while (
62
+ compiler.outputPath.indexOf(commonPath) !== 0 &&
63
+ /[/\\]/.test(commonPath)
64
+ ) {
65
+ commonPath = commonPath.replace(/[/\\][^/\\]*$/, "");
66
+ }
67
+ }
68
+
69
+ if (!commonPath && this.compilers[0].outputPath[0] === "/") return "/";
70
+ return commonPath;
71
+ }
72
+
73
+ get inputFileSystem() {
74
+ throw new Error("Cannot read inputFileSystem of a MultiCompiler");
75
+ }
76
+
77
+ get outputFileSystem() {
78
+ throw new Error("Cannot read outputFileSystem of a MultiCompiler");
79
+ }
80
+
81
+ set inputFileSystem(value) {
82
+ for (const compiler of this.compilers) {
83
+ compiler.inputFileSystem = value;
84
+ }
85
+ }
86
+
87
+ set outputFileSystem(value) {
88
+ for (const compiler of this.compilers) {
89
+ compiler.outputFileSystem = value;
90
+ }
91
+ }
92
+
93
+ validateDependencies(callback) {
94
+ const edges = new Set();
95
+ const missing = [];
96
+ const targetFound = compiler => {
97
+ for (const edge of edges) {
98
+ if (edge.target === compiler) {
99
+ return true;
100
+ }
101
+ }
102
+ return false;
103
+ };
104
+ const sortEdges = (e1, e2) => {
105
+ return (
106
+ e1.source.name.localeCompare(e2.source.name) ||
107
+ e1.target.name.localeCompare(e2.target.name)
108
+ );
109
+ };
110
+ for (const source of this.compilers) {
111
+ if (source.dependencies) {
112
+ for (const dep of source.dependencies) {
113
+ const target = this.compilers.find(c => c.name === dep);
114
+ if (!target) {
115
+ missing.push(dep);
116
+ } else {
117
+ edges.add({
118
+ source,
119
+ target
120
+ });
121
+ }
122
+ }
123
+ }
124
+ }
125
+ const errors = missing.map(m => `Compiler dependency \`${m}\` not found.`);
126
+ const stack = this.compilers.filter(c => !targetFound(c));
127
+ while (stack.length > 0) {
128
+ const current = stack.pop();
129
+ for (const edge of edges) {
130
+ if (edge.source === current) {
131
+ edges.delete(edge);
132
+ const target = edge.target;
133
+ if (!targetFound(target)) {
134
+ stack.push(target);
135
+ }
136
+ }
137
+ }
138
+ }
139
+ if (edges.size > 0) {
140
+ const lines = Array.from(edges)
141
+ .sort(sortEdges)
142
+ .map(edge => `${edge.source.name} -> ${edge.target.name}`);
143
+ lines.unshift("Circular dependency found in compiler dependencies.");
144
+ errors.unshift(lines.join("\n"));
145
+ }
146
+ if (errors.length > 0) {
147
+ const message = errors.join("\n");
148
+ callback(new Error(message));
149
+ return false;
150
+ }
151
+ return true;
152
+ }
153
+
154
+ runWithDependencies(compilers, fn, callback) {
155
+ const fulfilledNames = new Set();
156
+ let remainingCompilers = compilers;
157
+ const isDependencyFulfilled = d => fulfilledNames.has(d);
158
+ const getReadyCompilers = () => {
159
+ let readyCompilers = [];
160
+ let list = remainingCompilers;
161
+ remainingCompilers = [];
162
+ for (const c of list) {
163
+ const ready =
164
+ !c.dependencies || c.dependencies.every(isDependencyFulfilled);
165
+ if (ready) readyCompilers.push(c);
166
+ else remainingCompilers.push(c);
167
+ }
168
+ return readyCompilers;
169
+ };
170
+ const runCompilers = callback => {
171
+ if (remainingCompilers.length === 0) return callback();
172
+ asyncLib.map(
173
+ getReadyCompilers(),
174
+ (compiler, callback) => {
175
+ fn(compiler, err => {
176
+ if (err) return callback(err);
177
+ fulfilledNames.add(compiler.name);
178
+ runCompilers(callback);
179
+ });
180
+ },
181
+ callback
182
+ );
183
+ };
184
+ runCompilers(callback);
185
+ }
186
+
187
+ watch(watchOptions, handler) {
188
+ if (this.running) return handler(new ConcurrentCompilationError());
189
+
190
+ let watchings = [];
191
+ let allStats = this.compilers.map(() => null);
192
+ let compilerStatus = this.compilers.map(() => false);
193
+ if (this.validateDependencies(handler)) {
194
+ this.running = true;
195
+ this.runWithDependencies(
196
+ this.compilers,
197
+ (compiler, callback) => {
198
+ const compilerIdx = this.compilers.indexOf(compiler);
199
+ let firstRun = true;
200
+ let watching = compiler.watch(
201
+ Array.isArray(watchOptions)
202
+ ? watchOptions[compilerIdx]
203
+ : watchOptions,
204
+ (err, stats) => {
205
+ if (err) handler(err);
206
+ if (stats) {
207
+ allStats[compilerIdx] = stats;
208
+ compilerStatus[compilerIdx] = "new";
209
+ if (compilerStatus.every(Boolean)) {
210
+ const freshStats = allStats.filter((s, idx) => {
211
+ return compilerStatus[idx] === "new";
212
+ });
213
+ compilerStatus.fill(true);
214
+ const multiStats = new MultiStats(freshStats);
215
+ handler(null, multiStats);
216
+ }
217
+ }
218
+ if (firstRun && !err) {
219
+ firstRun = false;
220
+ callback();
221
+ }
222
+ }
223
+ );
224
+ watchings.push(watching);
225
+ },
226
+ () => {
227
+ // ignore
228
+ }
229
+ );
230
+ }
231
+
232
+ return new MultiWatching(watchings, this);
233
+ }
234
+
235
+ run(callback) {
236
+ if (this.running) return callback(new ConcurrentCompilationError());
237
+
238
+ const finalCallback = (err, stats) => {
239
+ this.running = false;
240
+
241
+ if (callback !== undefined) return callback(err, stats);
242
+ };
243
+
244
+ const allStats = this.compilers.map(() => null);
245
+ if (this.validateDependencies(callback)) {
246
+ this.running = true;
247
+ this.runWithDependencies(
248
+ this.compilers,
249
+ (compiler, callback) => {
250
+ const compilerIdx = this.compilers.indexOf(compiler);
251
+ compiler.run((err, stats) => {
252
+ if (err) return callback(err);
253
+ allStats[compilerIdx] = stats;
254
+ callback();
255
+ });
256
+ },
257
+ err => {
258
+ if (err) return finalCallback(err);
259
+ finalCallback(null, new MultiStats(allStats));
260
+ }
261
+ );
262
+ }
263
+ }
264
+
265
+ purgeInputFileSystem() {
266
+ for (const compiler of this.compilers) {
267
+ if (compiler.inputFileSystem && compiler.inputFileSystem.purge)
268
+ compiler.inputFileSystem.purge();
269
+ }
270
+ }
271
+ };