Add return type to webpack-hot-client default function (#42413)

This commit is contained in:
Brian Armstrong
2020-02-25 12:35:58 -08:00
committed by GitHub
parent e3368f2e55
commit a2ef096f8f
2 changed files with 63 additions and 38 deletions
+55 -37
View File
@@ -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 <https://github.com/rynclark>
// ZSkycat <https://github.com/ZSkycat>
// Brian Armstrong <https://github.com/barm>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
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<Options>;
}
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[];
}
}
@@ -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;