| 41 | }; |
| 42 | |
| 43 | export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> { |
| 44 | name = 'webpack'; |
| 45 | |
| 46 | private isProd = false; |
| 47 | |
| 48 | // The root of the Electron app |
| 49 | private projectDir!: string; |
| 50 | |
| 51 | // Where the Webpack output is generated. Usually `$projectDir/.webpack` |
| 52 | private baseDir!: string; |
| 53 | |
| 54 | private _configGenerator!: WebpackConfigGenerator; |
| 55 | |
| 56 | private watchers: Watching[] = []; |
| 57 | |
| 58 | private servers: http.Server[] = []; |
| 59 | |
| 60 | private loggers: Logger[] = []; |
| 61 | |
| 62 | private port = DEFAULT_PORT; |
| 63 | |
| 64 | private loggerPort = DEFAULT_LOGGER_PORT; |
| 65 | |
| 66 | constructor(c: WebpackPluginConfig) { |
| 67 | super(c); |
| 68 | |
| 69 | if (c.port) { |
| 70 | if (this.isValidPort(c.port)) { |
| 71 | this.port = c.port; |
| 72 | } |
| 73 | } |
| 74 | if (c.loggerPort) { |
| 75 | if (this.isValidPort(c.loggerPort)) { |
| 76 | this.loggerPort = c.loggerPort; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | this.getHooks = this.getHooks.bind(this); |
| 81 | } |
| 82 | |
| 83 | private isValidPort = (port: number) => { |
| 84 | if (port < 1024) { |
| 85 | throw new Error( |
| 86 | `Cannot specify port (${port}) below 1024, as they are privileged`, |
| 87 | ); |
| 88 | } else if (port > 65535) { |
| 89 | throw new Error(`Port specified (${port}) is not a valid TCP port.`); |
| 90 | } else { |
| 91 | return true; |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | exitHandler = ( |
| 96 | options: { cleanup?: boolean; exit?: boolean }, |
| 97 | err?: Error, |
| 98 | ): void => { |
| 99 | d('handling process exit with:', options); |
| 100 | if (options.cleanup) { |
nothing calls this directly
no test coverage detected