diff --git a/types/webpack-hot-client/index.d.ts b/types/webpack-hot-client/index.d.ts index c8e6500394..e74dd9cf8d 100644 --- a/types/webpack-hot-client/index.d.ts +++ b/types/webpack-hot-client/index.d.ts @@ -1,54 +1,72 @@ -// Type definitions for webpack-hot-client 4.0 +// Type definitions for webpack-hot-client 4.1 // Project: https://github.com/webpack-contrib/webpack-hot-client // Definitions by: Ryan Clark // ZSkycat +// Brian Armstrong // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 /// -import * as webpack from 'webpack'; import * as net from 'net'; +import * as webpack from 'webpack'; +import { Server } from 'ws'; export = WebpackHotClient; declare function WebpackHotClient( - compiler: webpack.Compiler | webpack.MultiCompiler, - options: WebpackHotClient.Options -): void; + compiler: webpack.Compiler | webpack.MultiCompiler, + options: WebpackHotClient.Options, +): WebpackHotClient.Client; declare namespace WebpackHotClient { - interface WebpackHotHost { - /** Client hostname that is used in the browser by WebSockets */ - client: string; - /** Server hostname */ - server: string; - } + interface WebSocketServer extends Server { + /** Forwards a message to each open client on the WebSocketServer */ + broadcast(data: any): void; + /** Processes stats and sends messages through broadcast() */ + send(stats: webpack.Stats): void; + } - interface Options { - /** Automatically configure every entry */ - allEntries?: boolean; - /** Auto configure the given webpack config with the hot configuration */ - autoConfigure?: boolean; - /** Level of information for webpack-hot-client to output */ - host?: WebpackHotHost | string; - /** Enable hot module reloading */ - hmr?: boolean; - /** Enable HTTPS */ - https?: boolean; - /** Level of information for webpack-hot-client to output */ - logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent'; - /** Prepend timestamp to each log line */ - logTime?: boolean; - /** Port that the WebSocket listens on */ - port?: number; - /** Reload the page if a patch cannot be applied by webpack */ - reload?: boolean; - /** Server instance for webpack-hot-client to connect to */ - server?: net.Server; - /** Webpack stats configuration */ - stats?: webpack.Options.Stats; - /** Webpack compile target */ - validTargets?: string[]; - } + interface Client { + /** Function that closes the WebSocketServer opened by the module. */ + close(callback?: () => void): void; + /** WebSocketServer instance with some hot-client specific method overrides */ + server: WebSocketServer; + /** Readonly version of the options after applying defaults */ + options: Readonly; + } + + interface WebpackHotHost { + /** Client hostname that is used in the browser by WebSockets */ + client: string; + /** Server hostname */ + server: string; + } + + interface Options { + /** Automatically configure every entry */ + allEntries?: boolean; + /** Auto configure the given webpack config with the hot configuration */ + autoConfigure?: boolean; + /** Host that the WebSocket listens on */ + host?: WebpackHotHost | string; + /** Enable hot module reloading */ + hmr?: boolean; + /** Enable HTTPS */ + https?: boolean; + /** Level of information for webpack-hot-client to output */ + logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent'; + /** Prepend timestamp to each log line */ + logTime?: boolean; + /** Port that the WebSocket listens on */ + port?: number; + /** Reload the page if a patch cannot be applied by webpack */ + reload?: boolean; + /** Server instance for webpack-hot-client to connect to */ + server?: net.Server; + /** Webpack stats configuration */ + stats?: webpack.Options.Stats; + /** Webpack compile target */ + validTargets?: string[]; + } } diff --git a/types/webpack-hot-client/webpack-hot-client-tests.ts b/types/webpack-hot-client/webpack-hot-client-tests.ts index 433c704030..62816fdc63 100644 --- a/types/webpack-hot-client/webpack-hot-client-tests.ts +++ b/types/webpack-hot-client/webpack-hot-client-tests.ts @@ -5,4 +5,11 @@ const compiler = webpack(); hot(compiler, { logLevel: 'info', reload: false }); -hot(compiler, { logLevel: 'info', reload: false, validTargets: ['web', 'node'] }); +const client = hot(compiler, { logLevel: 'info', reload: false, validTargets: ['web', 'node'] }); + +const { close, server, options} = client; + +close(() => {}); +server.on('listening', () => {}); +server.broadcast({type: 'message'}); +const entries = options.allEntries;