From c96320313a762ed8db63d8395841b08e3756446b Mon Sep 17 00:00:00 2001 From: avin-kavish <48435155+avin-kavish@users.noreply.github.com> Date: Fri, 26 Apr 2019 23:39:06 +0530 Subject: [PATCH] [@types/copy-webpack-plugin] Update to v5.0 of copy-webpack-plugin (#34880) * ADD: 'test' option and relavant documentation to CopyPattern * Update types to copy-webpack-plugin version 5 * Update header * Update header --- .../copy-webpack-plugin-tests.ts | 14 +++- types/copy-webpack-plugin/index.d.ts | 76 ++++++++++++------- 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/types/copy-webpack-plugin/copy-webpack-plugin-tests.ts b/types/copy-webpack-plugin/copy-webpack-plugin-tests.ts index 9a1331a502..810285cf19 100644 --- a/types/copy-webpack-plugin/copy-webpack-plugin-tests.ts +++ b/types/copy-webpack-plugin/copy-webpack-plugin-tests.ts @@ -63,10 +63,22 @@ const c: Configuration = { // Copy glob results (without dot files) to {output}/to/directory/ { from: '**/*.png', - fromArgs: { dot: false }, to: 'to/directory' }, + + // Turns 1st and 2nd level directory names into file name seperated by a dash for png files + { + from: '*/*', + to: '[1]-[2].[hash].[ext]', + test: /([^/]+)\/(.+)\.png$/, + }, ], { + // Log only errors + logLevel: 'error', + + // All 'from' paths will be intepreted from this context + context: 'app/', + ignore: [ // Doesn't copy any files with a txt extension '*.txt', diff --git a/types/copy-webpack-plugin/index.d.ts b/types/copy-webpack-plugin/index.d.ts index 8f7940d738..b6644d2a46 100644 --- a/types/copy-webpack-plugin/index.d.ts +++ b/types/copy-webpack-plugin/index.d.ts @@ -1,12 +1,13 @@ -// Type definitions for copy-webpack-plugin 4.4 +// Type definitions for copy-webpack-plugin 5.0 // Project: https://github.com/webpack-contrib/copy-webpack-plugin -// Definitions by: flying-sheep +// Definitions by: flying-sheep +// avin-kavish // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 /// -import { Plugin } from 'webpack' +import { Plugin, compiler } from 'webpack' import { IOptions } from 'minimatch' interface MiniMatchGlob extends IOptions { @@ -20,46 +21,69 @@ interface MiniMatchOptions extends IOptions { interface CopyPattern { /** File source path or glob */ from: string | MiniMatchGlob - /** See the `node-glob` options in addition to the ones below. (default: `{ cwd: context }`) */ - fromArgs?: MiniMatchOptions /** * Path or webpack file-loader patterns. defaults: * output root if `from` is file or dir. * resolved glob path if `from` is glob. */ to?: string - /** - * How to interpret `to`. defaults: - * 'file' if to has extension or from is file. - * 'dir' if from is directory, to has no extension or ends in '/'. - * 'template' if to contains a template pattern. - */ - toType?: 'file' | 'dir' | 'template' - /** A path that determines how to interpret the `from` path. (default: `compiler.options.context`) */ + /** A path that determines how to interpret the `from` path. + * + * (default: `options.context | compiler.options.context`) + * */ context?: string /** - * Removes all directory references and only copies file names. - * - * If files have the same name, the result is non-deterministic. (default: `false`) + * How to interpret `to`. default: undefined + * + * `file` - if 'to' has extension or 'from' is file. + * `dir` - if 'from' is directory, 'to' has no extension or ends in '/'. + * `template` - if 'to' contains a template pattern. */ - flatten?: boolean - /** Additional globs to ignore for this pattern. (default: `[]`) */ - ignore?: Array - /** Function that modifies file contents before writing to webpack. (default: `(content, path) => content`) */ - transform?: (content: Buffer, path: string) => string | Buffer - /** Enable transform caching. You can use `{ cache: { key: 'my-cache-key' } }` to invalidate the cache. (default: `false`) */ - cache?: boolean | { key: string } + toType?: 'file' | 'dir' | 'template' + /** + * Pattern for extracting elements to be used in `to` templates. + * + * Defines a `RegExp` to match some parts of the file path. These capture groups can be reused in the name property using [N] + * placeholder. Note that [0] will be replaced by the entire path of the file, whereas [1] will contain the first capturing + * parenthesis of your RegExp and so on... + * + * */ + test?: RegExp /** Overwrites files already in `compilation.assets` (usually added by other plugins; default: `false`) */ force?: boolean + /** Additional globs to ignore for this pattern. (default: `[]`) */ + ignore?: Array + /** + * Removes all directory references and only copies file names. (default: `false`) + * + * If files have the same name, the result is non-deterministic. + */ + flatten?: boolean + /** Function that modifies file contents before writing to webpack. (default: `(content, path) => content`) */ + transform?: (content: Buffer, path: string) => string | Buffer | Promise + /** + * Enable transform caching. (default: `false`) + * + * You can use `{ key: 'my-cache-key' }` to invalidate the cache. + * */ + cache?: boolean | { key: string } + /** + * Allows to modify the writing path. + * + * Returns the new path or a promise that resolves into the new path + */ + transformPath?: (targetPath: string, absolutePath: string) => string | Promise } interface CopyWebpackPluginConfiguration { - /** Array of globs to ignore. (applied to from; default: `[]`) */ + /** Level of messages that the module will log. (default: `'warn'`) */ + logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent' + /** Array of globs to ignore. (applied to `from`; default: `[]`) */ ignore?: Array + /** A path that determines how to interpret the from path, shared for all patterns. default: `'compiler.options.context'` */ + context?: string /** Copies files, regardless of modification when using `watch` or `webpack-dev-server`. All files are copied on first build, regardless of this option. (default: `false`) */ copyUnmodified?: boolean - /** Debug level. warning: only warnings, info/true: file location and read info, debug: very detailed debugging info. (default: `'warning'`) */ - debug?: 'warning' | 'info'|true | 'debug' } interface CopyWebpackPlugin {