From f3c6f4aec35fc92dcaa44f50a4d7883569995aa2 Mon Sep 17 00:00:00 2001 From: Blaise Kal Date: Wed, 4 Jul 2018 00:11:41 +0200 Subject: [PATCH] New typings for zip-webpack-plugin (#27032) * Typings for zip-webpack-plugin * Switch to ReadonlyArray for include and exclude options * Fix linting errors * Fix TypeScript version --- types/zip-webpack-plugin/index.d.ts | 99 +++++++++++++++++++ types/zip-webpack-plugin/tsconfig.json | 23 +++++ types/zip-webpack-plugin/tslint.json | 1 + .../zip-webpack-plugin-tests.ts | 28 ++++++ 4 files changed, 151 insertions(+) create mode 100644 types/zip-webpack-plugin/index.d.ts create mode 100644 types/zip-webpack-plugin/tsconfig.json create mode 100644 types/zip-webpack-plugin/tslint.json create mode 100644 types/zip-webpack-plugin/zip-webpack-plugin-tests.ts diff --git a/types/zip-webpack-plugin/index.d.ts b/types/zip-webpack-plugin/index.d.ts new file mode 100644 index 0000000000..332e2936e2 --- /dev/null +++ b/types/zip-webpack-plugin/index.d.ts @@ -0,0 +1,99 @@ +// Type definitions for zip-webpack-plugin 3.0 +// Project: https://github.com/erikdesjardins/zip-webpack-plugin +// Definitions by: Blaise Kal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as webpack from 'webpack'; + +export = ZipPlugin; + +/** + * Webpack plugin to zip emitted files. Compresses all assets into a zip file. + * See https://www.npmjs.com/package/zip-webpack-plugin#usage + */ +declare class ZipPlugin extends webpack.Plugin { + /** + * @param options Options for ZipPlugin. + */ + constructor(options?: ZipPlugin.Options); +} + +declare namespace ZipPlugin { + interface Options { + /** + * Output path. Can be relative (to the webpack output path) or absolute. + * Defaults to the Webpack output path. + */ + path?: string; + /** + * Output file name. + * Defaults to the Webpack output filename or basename of the path. + */ + filename?: string; + /** + * The file extension to use instead of "zip". + * Defaults to "zip". + */ + extension?: string; + /** + * The path prefix for files included in the zip file. + * Default to no prefix. + */ + pathPrefix?: string; + /** + * Function to map asset paths to new paths. + */ + pathMapper?: (assetPath: string) => string; + /** + * Include file paths or patterns. + * Defaults to including all files in the webpack output path. + */ + include?: string | RegExp | ReadonlyArray; + /** + * Exclude file paths or patterns. Takes precedence over include. Defaults to no excluding. + */ + exclude?: string | RegExp | ReadonlyArray; + /** + * File options passed to yazl `addFile`. + * See https://github.com/thejoshwolfe/yazl#addfilerealpath-metadatapath-options + */ + fileOptions?: fileOptions; + /** + * File options passed to yazl `end`. + * See https://github.com/thejoshwolfe/yazl#endoptions-finalsizecallback + */ + zipOptions?: zipOptions; + } + + interface fileOptions { + /** + * Overwrite the last modified time. + * Defaults to the current date and time. + */ + mtime?: Date; + /** + * UNIX permission bits and file type. + */ + mode?: number; + /** + * Whether to compress the out[ut zip file. + * When true, the file data will be deflated (compression method 8). + * When false, the file data will be stored (compression method 0). + */ + compress?: boolean; + /** + * Force ZIP64 format. ZIP64 format is enabled by default where necessary. + * See https://github.com/thejoshwolfe/yazl#regarding-zip64-support + */ + forceZip64Format?: boolean; + } + + interface zipOptions { + /** + * Force ZIP64 format. ZIP64 format is enabled by default where necessary. + * See https://github.com/thejoshwolfe/yazl#regarding-zip64-support + */ + forceZip64Format?: boolean; + } +} diff --git a/types/zip-webpack-plugin/tsconfig.json b/types/zip-webpack-plugin/tsconfig.json new file mode 100644 index 0000000000..8c18bf81a0 --- /dev/null +++ b/types/zip-webpack-plugin/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true + }, + "files": [ + "index.d.ts", + "zip-webpack-plugin-tests.ts" + ] +} diff --git a/types/zip-webpack-plugin/tslint.json b/types/zip-webpack-plugin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/zip-webpack-plugin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/zip-webpack-plugin/zip-webpack-plugin-tests.ts b/types/zip-webpack-plugin/zip-webpack-plugin-tests.ts new file mode 100644 index 0000000000..f6396e5e7b --- /dev/null +++ b/types/zip-webpack-plugin/zip-webpack-plugin-tests.ts @@ -0,0 +1,28 @@ +import * as ZipPlugin from "zip-webpack-plugin"; + +new ZipPlugin(); + +const options: ZipPlugin.Options = { + include: "include.string", + exclude: "exclude.string", +}; +new ZipPlugin(options); + +new ZipPlugin({ + path: "path", + filename: "filename", + extension: "ext", + pathPrefix: "prefix", + pathMapper: (assetPath) => `pathMapper/${assetPath}`, + include: ["include.string", /include\.regexp/], + exclude: ["exclude.string", /exclude\.regexp/], + fileOptions: { + mtime: new Date(), + mode: parseInt("0100664", 8), + compress: false, + forceZip64Format: true, + }, + zipOptions: { + forceZip64Format: true, + } +});