From f9aa66f353bcdbbb3c89d5eefb165a0d4b2ccff6 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 6 May 2019 01:10:35 -0700 Subject: [PATCH] [react-dev-utils] Add new arguments to createCompiler arguments (#35215) * [react-dev-utils] Add new arguments to createCompiler arguments * lint * nits --- .../WebpackDevServerUtils.d.ts | 61 ++++++++++++++++--- .../formatWebpackMessages.d.ts | 4 +- types/react-dev-utils/tsconfig.json | 1 + .../react-dev-utils/webpackHotDevClient.d.ts | 4 ++ 4 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 types/react-dev-utils/webpackHotDevClient.d.ts diff --git a/types/react-dev-utils/WebpackDevServerUtils.d.ts b/types/react-dev-utils/WebpackDevServerUtils.d.ts index fc86c927cd..c0a615091b 100644 --- a/types/react-dev-utils/WebpackDevServerUtils.d.ts +++ b/types/react-dev-utils/WebpackDevServerUtils.d.ts @@ -16,25 +16,66 @@ export interface Urls { */ export function choosePort(host: string, defaultPort: number): Promise; +export interface CreateCompilerOptions { + /** + * The name that will be printed to the terminal. + */ + appName: string; + /** + * The webpack configuration options to be provided to the webpack constructor. + */ + config: webpack.Configuration; + /** + * To provide the `urls` argument, use `prepareUrls()` described below. + */ + urls: Urls; + /** + * If `true`; yarn instructions will be emitted in the terminal instead of npm. + */ + useYarn?: boolean; + /** + * Takes the `require('webpack')` entry point. + */ + webpack: typeof webpack; +} +export interface CreateCompilerOptionsTypescript extends CreateCompilerOptions { + /** + * Required if useTypeScript is `true`. + * This is useful when running fork-ts-checker-webpack-plugin with `async: true` to + * report errors that are emitted after the webpack build is complete. + */ + devSocket: { + /** + * Called when there are build errors. + */ + errors: (errors: string[]) => void; + /** + * Called when there are build warnings. + */ + warnings: (warnings: string[]) => void; + }; + /** + * If `true`, TypeScript type checking will be enabled. + * Be sure to provide the `devSocket` argument above if this is set to `true`. + */ + useTypeScript: boolean; +} + /** * Creates a Webpack compiler instance for WebpackDevServer with built-in - * helpful messages. Takes the `require('webpack')` entry point. - * To provide the `urls` argument, use `prepareUrls()` described below. + * helpful messages. */ -export function createCompiler(opts: { - webpack: typeof webpack, - config: webpack.Configuration, - appName: string, - urls: Urls, - useYarn: boolean, -}): webpack.Compiler; +export function createCompiler(opts: CreateCompilerOptions): webpack.Compiler; +// if the signatures are merged, TS will not enforce that both useTypeScript and devSocket are provided +// tslint:disable-next-line:unified-signatures +export function createCompiler(opts: CreateCompilerOptionsTypescript): webpack.Compiler; /** * Creates a WebpackDevServer `proxy` configuration object from the `proxy` * setting in `package.json`. */ export function prepareProxy( - proxySetting: any, + proxySetting: string | undefined, appPublicFolder: string, ): WebpackDevServer.ProxyConfigArray; diff --git a/types/react-dev-utils/formatWebpackMessages.d.ts b/types/react-dev-utils/formatWebpackMessages.d.ts index 769c5f0639..6885d2c88b 100644 --- a/types/react-dev-utils/formatWebpackMessages.d.ts +++ b/types/react-dev-utils/formatWebpackMessages.d.ts @@ -4,9 +4,7 @@ import { Stats } from 'webpack'; * Extracts and prettifies warning and error messages from webpack * [stats](https://github.com/webpack/docs/wiki/node.js-api#stats) object. */ -declare function formatWebpackMessages( - json: Stats.ToJsonOutput, -): { +declare function formatWebpackMessages(json: Stats.ToJsonOutput): { errors: string[]; warnings: string[]; }; diff --git a/types/react-dev-utils/tsconfig.json b/types/react-dev-utils/tsconfig.json index 01022ecf4d..72ac8a8a45 100644 --- a/types/react-dev-utils/tsconfig.json +++ b/types/react-dev-utils/tsconfig.json @@ -38,6 +38,7 @@ "printHostingInstructions.d.ts", "WatchMissingNodeModulesPlugin.d.ts", "WebpackDevServerUtils.d.ts", + "webpackHotDevClient.d.ts", "test/eslintFormatter.ts", "test/noopServiceWorkerMiddleware.ts", "test/utils.ts", diff --git a/types/react-dev-utils/webpackHotDevClient.d.ts b/types/react-dev-utils/webpackHotDevClient.d.ts new file mode 100644 index 0000000000..69c1b30975 --- /dev/null +++ b/types/react-dev-utils/webpackHotDevClient.d.ts @@ -0,0 +1,4 @@ +/** This is an alternative client for WebpackDevServer that shows a syntax error overlay. */ +export {}; + +// Note - this file doesn't actually export anything