* @param {Compiler} compiler compiler
(compiler)
| 95 | * @param {Compiler} compiler compiler |
| 96 | */ |
| 97 | apply(compiler) { |
| 98 | compiler.hooks.beforeRun.tapPromise( |
| 99 | "ServerPlugin", |
| 100 | async () => { |
| 101 | this.refs++; |
| 102 | if (!this.server) { |
| 103 | this.server = createServer(); |
| 104 | await new Promise( |
| 105 | /** |
| 106 | * @param {(value: void) => void} resolve resolve |
| 107 | * @param {(reason?: Error) => void} _reject reject |
| 108 | */ |
| 109 | (resolve, _reject) => { |
| 110 | /** @type {import("http").Server} */ |
| 111 | (this.server).listen( |
| 112 | this.port, |
| 113 | () => { |
| 114 | resolve(); |
| 115 | } |
| 116 | ); |
| 117 | }); |
| 118 | } |
| 119 | } |
| 120 | ); |
| 121 | |
| 122 | compiler.hooks.done.tapAsync("ServerPlugin", (stats, callback) => { |
| 123 | const s = this.server; |
| 124 | if (s && --this.refs === 0) { |
| 125 | this.server = undefined; |
| 126 | s.close(callback); |
| 127 | } else { |
| 128 | callback(); |
| 129 | } |
| 130 | }); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | module.exports = ServerPlugin; |
nothing calls this directly
no test coverage detected