From ab4dade120c91fe0804d2a00f7ae0aa48b48beea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Thu, 11 Jun 2020 20:38:04 +0200 Subject: [PATCH] feat(webpack-shell-plugin): definition types (#45295) - definition file - tests https://github.com/1337programming/webpack-shell-plugin https://www.npmjs.com/package/webpack-shell-plugin#example Thanks! --- types/webpack-shell-plugin/index.d.ts | 51 +++++++++++++++++++ types/webpack-shell-plugin/tsconfig.json | 23 +++++++++ types/webpack-shell-plugin/tslint.json | 1 + .../webpack-shell-plugin-tests.ts | 41 +++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 types/webpack-shell-plugin/index.d.ts create mode 100644 types/webpack-shell-plugin/tsconfig.json create mode 100644 types/webpack-shell-plugin/tslint.json create mode 100644 types/webpack-shell-plugin/webpack-shell-plugin-tests.ts diff --git a/types/webpack-shell-plugin/index.d.ts b/types/webpack-shell-plugin/index.d.ts new file mode 100644 index 0000000000..53a9aa86cd --- /dev/null +++ b/types/webpack-shell-plugin/index.d.ts @@ -0,0 +1,51 @@ +// Type definitions for webpack-shell-plugin 0.5 +// Project: https://github.com/1337programming/webpack-shell-plugin +// Definitions by: Piotr Błażejewicz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Plugin } from 'webpack'; + +declare class WebpackShellPlugin extends Plugin { + constructor(options?: WebpackShellPlugin.Options); +} + +declare namespace WebpackShellPlugin { + interface Options { + /** + * scripts to execute on the initial build + * @default [] + */ + onBuildStart?: string[]; + /** + * scripts to execute after files are emitted at the end of the compilation + * @default [] + */ + onBuildEnd?: string[]; + /** + * scripts to execute after webpack process is complete + * @default [] + */ + onBuildExit?: string[]; + /** + * Switch for development environments. + * This causes scripts to execute once. + * Useful for running HMR on webpack-dev-server or webpack watch mode. + * @default true + */ + dev?: boolean; + /** + * Switches script execution process from spawn to exec. + * If running into problems with spawn, turn this setting on. + * @default false + */ + safe?: boolean; + /** + * Enable for verbose output + * @deprecated + * @default false + */ + verbose?: boolean; + } +} + +export = WebpackShellPlugin; diff --git a/types/webpack-shell-plugin/tsconfig.json b/types/webpack-shell-plugin/tsconfig.json new file mode 100644 index 0000000000..e55c32902a --- /dev/null +++ b/types/webpack-shell-plugin/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-shell-plugin-tests.ts" + ] +} diff --git a/types/webpack-shell-plugin/tslint.json b/types/webpack-shell-plugin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/webpack-shell-plugin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/webpack-shell-plugin/webpack-shell-plugin-tests.ts b/types/webpack-shell-plugin/webpack-shell-plugin-tests.ts new file mode 100644 index 0000000000..4cc57e301a --- /dev/null +++ b/types/webpack-shell-plugin/webpack-shell-plugin-tests.ts @@ -0,0 +1,41 @@ +/// +import WebpackShellPlugin = require('webpack-shell-plugin'); +import path = require('path'); +import { Configuration, Plugin } from 'webpack'; +import { Options } from 'webpack-shell-plugin'; + +const options: Options = {}; + +const plugins: Plugin[] = [ + new WebpackShellPlugin(), + new WebpackShellPlugin({}), + new WebpackShellPlugin(options), + new WebpackShellPlugin({ + onBuildStart: ['echo "Starting"'], + onBuildEnd: ['python script.py && node script.js'], + dev: false, + onBuildExit: ['echo "Exit"', 'echo "Done"'], + safe: true, + }), +]; + +const _: Configuration = { + entry: { + app: path.resolve(__dirname, 'src/app.js'), + }, + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'bundle.js', + }, + devServer: { + contentBase: path.resolve(__dirname, 'src'), + }, + plugins, + module: { + rules: [ + { test: /\.js$/, loaders: 'babel' }, + { test: /\.scss$/, loader: 'style!css!scss?' }, + { test: /\.html$/, loader: 'html-loader' }, + ], + }, +};