From 3db545b2e2ec38fc3f6dce1dc8fcd5f386b864e6 Mon Sep 17 00:00:00 2001 From: Jeow Li Huan Date: Wed, 31 Oct 2018 14:11:00 +0800 Subject: [PATCH] Add type definition for webpack-subresource-integrity plugin. (#30157) --- .../webpack-subresource-integrity/index.d.ts | 28 +++++++++++++++++++ .../tsconfig.json | 23 +++++++++++++++ .../webpack-subresource-integrity/tslint.json | 1 + .../webpack-subresource-integrity-tests.ts | 15 ++++++++++ 4 files changed, 67 insertions(+) create mode 100644 types/webpack-subresource-integrity/index.d.ts create mode 100644 types/webpack-subresource-integrity/tsconfig.json create mode 100644 types/webpack-subresource-integrity/tslint.json create mode 100644 types/webpack-subresource-integrity/webpack-subresource-integrity-tests.ts diff --git a/types/webpack-subresource-integrity/index.d.ts b/types/webpack-subresource-integrity/index.d.ts new file mode 100644 index 0000000000..d47d7d2275 --- /dev/null +++ b/types/webpack-subresource-integrity/index.d.ts @@ -0,0 +1,28 @@ +// Type definitions for webpack-subresource-integrity 1.2 +// Project: https://github.com/waysact/webpack-subresource-integrity +// Definitions by: Jeow Li Huan +// Definitions: https://github.com/huan086/webpack-subresource-integrity-typings +// TypeScript Version: 2.3 + +import { Plugin } from 'webpack'; + +declare namespace WebpackSubresourceIntegrityPlugin { + interface Options { + /** + * Default value: true + * When this value is falsy, the plugin doesn't run and no integrity values are calculated. It is recommended to disable the plugin in development mode. + */ + enabled?: boolean; + + /** + * An array of strings, each specifying the name of a hash function to be used for calculating integrity hash values. For example, ['sha256', 'sha512']. + */ + hashFuncNames: string[]; + } +} + +declare class WebpackSubresourceIntegrityPlugin extends Plugin { + constructor(options?: WebpackSubresourceIntegrityPlugin.Options); +} + +export = WebpackSubresourceIntegrityPlugin; diff --git a/types/webpack-subresource-integrity/tsconfig.json b/types/webpack-subresource-integrity/tsconfig.json new file mode 100644 index 0000000000..5461016c11 --- /dev/null +++ b/types/webpack-subresource-integrity/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "webpack-subresource-integrity-tests.ts" + ] +} diff --git a/types/webpack-subresource-integrity/tslint.json b/types/webpack-subresource-integrity/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/webpack-subresource-integrity/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/webpack-subresource-integrity/webpack-subresource-integrity-tests.ts b/types/webpack-subresource-integrity/webpack-subresource-integrity-tests.ts new file mode 100644 index 0000000000..810893429c --- /dev/null +++ b/types/webpack-subresource-integrity/webpack-subresource-integrity-tests.ts @@ -0,0 +1,15 @@ +import * as webpack from 'webpack'; +import SriPlugin = require('webpack-subresource-integrity'); + +const config: webpack.Configuration = { + plugins: [ + new SriPlugin(), + new SriPlugin({ + hashFuncNames: ['sha256', 'sha384'] + }), + new SriPlugin({ + enabled: false, + hashFuncNames: ['sha256'] + }) + ] +};