From 0a07cb89a23dd48861f6df6b7ee034af1eb8470e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Thu, 20 Feb 2020 23:25:05 +0100 Subject: [PATCH] feat(webpack-error-notification): definition files (#42517) - type definitions - tests https://github.com/vsolovyov/webpack-error-notification#usage Thanks! --- types/webpack-error-notification/index.d.ts | 30 +++++++++++++ .../webpack-error-notification/tsconfig.json | 23 ++++++++++ types/webpack-error-notification/tslint.json | 1 + .../webpack-error-notification-tests.ts | 43 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 types/webpack-error-notification/index.d.ts create mode 100644 types/webpack-error-notification/tsconfig.json create mode 100644 types/webpack-error-notification/tslint.json create mode 100644 types/webpack-error-notification/webpack-error-notification-tests.ts diff --git a/types/webpack-error-notification/index.d.ts b/types/webpack-error-notification/index.d.ts new file mode 100644 index 0000000000..c625fbb94f --- /dev/null +++ b/types/webpack-error-notification/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for webpack-error-notification 0.1 +// Project: https://github.com/vsolovyov/webpack-error-notification#readme +// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Plugin, Stats } from 'webpack'; + +declare class WebpackErrorNotificationPlugin extends Plugin { + /** + * You can supply some strategy for the plugin to display notification. + * If you don't supply anything, it will use process.platform as a strategy name. + * `darwin` and `linux` are supported out of the box now. + * You can also supply function(msg) {} as a strategy that will use your notification CLI tool of choice. + */ + constructor(strategy?: WebpackErrorNotificationPlugin.Strategy, options?: WebpackErrorNotificationPlugin.Options); + + compileMessage(stats: Stats): string; + compilationDone(stats: Stats): void; +} + +declare namespace WebpackErrorNotificationPlugin { + type Strategy = 'darwin' | 'linux' | ((msg: string) => void); + + interface Options { + /** if you do not want to notify warnings, set this to `false` */ + notifyWarnings?: boolean; + } +} + +export = WebpackErrorNotificationPlugin; diff --git a/types/webpack-error-notification/tsconfig.json b/types/webpack-error-notification/tsconfig.json new file mode 100644 index 0000000000..c789e3dca7 --- /dev/null +++ b/types/webpack-error-notification/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "webpack-error-notification-tests.ts" + ] +} diff --git a/types/webpack-error-notification/tslint.json b/types/webpack-error-notification/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/webpack-error-notification/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/webpack-error-notification/webpack-error-notification-tests.ts b/types/webpack-error-notification/webpack-error-notification-tests.ts new file mode 100644 index 0000000000..347d9f7ef7 --- /dev/null +++ b/types/webpack-error-notification/webpack-error-notification-tests.ts @@ -0,0 +1,43 @@ +import WebpackErrorNotificationPlugin = require('webpack-error-notification'); +import webpack = require('webpack'); + +let config: webpack.Configuration = { + plugins: [ + // defaults + new WebpackErrorNotificationPlugin(), + ], +}; + +config = { + plugins: [new WebpackErrorNotificationPlugin('darwin')], +}; +config = { + plugins: [ + new WebpackErrorNotificationPlugin('darwin', { + notifyWarnings: false, + }), + ], +}; + +config = { + plugins: [ + new WebpackErrorNotificationPlugin('linux', { + notifyWarnings: false, + }), + ], +}; + +const customStrategy: WebpackErrorNotificationPlugin.Strategy = (msg: string) => { + // todo +}; + +config = { + plugins: [new WebpackErrorNotificationPlugin(customStrategy)], +}; +config = { + plugins: [ + new WebpackErrorNotificationPlugin(customStrategy, { + notifyWarnings: false, + }), + ], +};