@@ -28,8 +28,13 @@ const Watching = require("./Watching");
28
28
const { makePathsRelative } = require ( "./util/identifier" ) ;
29
29
30
30
/** @typedef {import("../declarations/WebpackOptions").Entry } Entry */
31
+ /** @typedef {import("../declarations/WebpackOptions").OutputOptions } OutputOptions */
32
+ /** @typedef {import("../declarations/WebpackOptions").WatchOptions } WatchOptions */
31
33
/** @typedef {import("../declarations/WebpackOptions").WebpackOptions } WebpackOptions */
34
+ /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance } WebpackPluginInstance */
35
+ /** @typedef {import("./Chunk") } Chunk */
32
36
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry } FileSystemInfoEntry */
37
+ /** @typedef {import("./Stats") } Stats */
33
38
34
39
/**
35
40
* @typedef {Object } CompilationParams
@@ -38,7 +43,24 @@ const { makePathsRelative } = require("./util/identifier");
38
43
* @property {Set<string> } compilationDependencies
39
44
*/
40
45
46
+ /**
47
+ * @template T
48
+ * @callback Callback
49
+ * @param {Error= } err
50
+ * @param {T= } result
51
+ */
52
+
53
+ /**
54
+ * @callback RunAsChildCallback
55
+ * @param {Error= } err
56
+ * @param {Chunk[]= } entries
57
+ * @param {Compilation= } compilation
58
+ */
59
+
41
60
class Compiler {
61
+ /**
62
+ * @param {string } context the compilation path
63
+ */
42
64
constructor ( context ) {
43
65
this . hooks = Object . freeze ( {
44
66
/** @type {SyncBailHook<Compilation> } */
@@ -142,16 +164,29 @@ class Compiler {
142
164
this . watchMode = false ;
143
165
}
144
166
167
+ /**
168
+ * @param {WatchOptions } watchOptions the watcher's options
169
+ * @param {Callback<Stats> } handler signals when the call finishes
170
+ * @returns {Watching } a compiler watcher
171
+ */
145
172
watch ( watchOptions , handler ) {
146
- if ( this . running ) return handler ( new ConcurrentCompilationError ( ) ) ;
173
+ if ( this . running ) {
174
+ return handler ( new ConcurrentCompilationError ( ) ) ;
175
+ }
147
176
148
177
this . running = true ;
149
178
this . watchMode = true ;
150
179
return new Watching ( this , watchOptions , handler ) ;
151
180
}
152
181
182
+ /**
183
+ * @param {Callback<Stats> } callback signals when the call finishes
184
+ * @returns {void }
185
+ */
153
186
run ( callback ) {
154
- if ( this . running ) return callback ( new ConcurrentCompilationError ( ) ) ;
187
+ if ( this . running ) {
188
+ return callback ( new ConcurrentCompilationError ( ) ) ;
189
+ }
155
190
156
191
const finalCallback = ( err , stats ) => {
157
192
this . cache . beginIdle ( ) ;
@@ -231,6 +266,10 @@ class Compiler {
231
266
} ) ;
232
267
}
233
268
269
+ /**
270
+ * @param {RunAsChildCallback } callback signals when the call finishes
271
+ * @returns {void }
272
+ */
234
273
runAsChild ( callback ) {
235
274
this . compile ( ( err , compilation ) => {
236
275
if ( err ) return callback ( err ) ;
@@ -257,6 +296,11 @@ class Compiler {
257
296
}
258
297
}
259
298
299
+ /**
300
+ * @param {Compilation } compilation the compilation
301
+ * @param {Callback<void> } callback signals when the assets are emitted
302
+ * @returns {void }
303
+ */
260
304
emitAssets ( compilation , callback ) {
261
305
let outputPath ;
262
306
@@ -322,6 +366,10 @@ class Compiler {
322
366
} ) ;
323
367
}
324
368
369
+ /**
370
+ * @param {Callback<void> } callback signals when the call finishes
371
+ * @returns {void }
372
+ */
325
373
emitRecords ( callback ) {
326
374
if ( ! this . recordsOutputPath ) return callback ( ) ;
327
375
const idx1 = this . recordsOutputPath . lastIndexOf ( "/" ) ;
@@ -350,6 +398,10 @@ class Compiler {
350
398
} ) ;
351
399
}
352
400
401
+ /**
402
+ * @param {Callback<void> } callback signals when the call finishes
403
+ * @returns {void }
404
+ */
353
405
readRecords ( callback ) {
354
406
if ( ! this . recordsInputPath ) {
355
407
this . records = { } ;
@@ -375,6 +427,14 @@ class Compiler {
375
427
} ) ;
376
428
}
377
429
430
+ /**
431
+ * @param {Compilation } compilation the compilation
432
+ * @param {string } compilerName the compiler's name
433
+ * @param {number } compilerIndex the compiler's index
434
+ * @param {OutputOptions } outputOptions the output options
435
+ * @param {WebpackPluginInstance[] } plugins the plugins to apply
436
+ * @returns {Compiler } a child compiler
437
+ */
378
438
createChildCompiler (
379
439
compilation ,
380
440
compilerName ,
@@ -454,6 +514,10 @@ class Compiler {
454
514
return new Compilation ( this ) ;
455
515
}
456
516
517
+ /**
518
+ * @param {CompilationParams } params the compilation parameters
519
+ * @returns {Compilation } the created compilation
520
+ */
457
521
newCompilation ( params ) {
458
522
const compilation = this . createCompilation ( ) ;
459
523
compilation . name = this . name ;
@@ -489,6 +553,10 @@ class Compiler {
489
553
return params ;
490
554
}
491
555
556
+ /**
557
+ * @param {Callback<Compilation> } callback signals when the compilation finishes
558
+ * @returns {void }
559
+ */
492
560
compile ( callback ) {
493
561
const params = this . newCompilationParams ( ) ;
494
562
this . hooks . beforeCompile . callAsync ( params , err => {
@@ -516,6 +584,10 @@ class Compiler {
516
584
} ) ;
517
585
}
518
586
587
+ /**
588
+ * @param {Callback<void> } callback signals when the compiler closes
589
+ * @returns {void }
590
+ */
519
591
close ( callback ) {
520
592
this . cache . shutdown ( callback ) ;
521
593
}
0 commit comments