From a294b4765e5a01429de186d488fe4860d5c974eb Mon Sep 17 00:00:00 2001 From: Stephan Troyer Date: Sun, 16 Dec 2018 12:37:58 +0100 Subject: [PATCH 1/2] Update webpack-manifest-plugin ...to match https://github.com/danethurber/webpack-manifest-plugin --- types/webpack-manifest-plugin/index.d.ts | 43 +++++++++++++++--------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/types/webpack-manifest-plugin/index.d.ts b/types/webpack-manifest-plugin/index.d.ts index 22cf2e6eba..c0d9067a1c 100644 --- a/types/webpack-manifest-plugin/index.d.ts +++ b/types/webpack-manifest-plugin/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for webpack-manifest-plugin 1.3 +// Type definitions for webpack-manifest-plugin 2.0 // Project: https://github.com/danethurber/webpack-manifest-plugin // Definitions by: Andrew Makarov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -19,13 +19,16 @@ declare namespace WebpackManifestPlugin { [propName: string]: any; } - interface HooksOptions { + interface FileDescriptor { path: string; - chunk: Chunk; name: string | null; - isChunk: boolean; + /** Is required to run you app. Cannot be true if isChunk is false. */ isInitial: boolean; + isChunk: boolean; + /** Only available is isChunk is true. */ + chunk?: Chunk; isAsset: boolean; + /** Is required by a module. Cannot be true if isAsset is false. */ isModuleAsset: boolean; } @@ -37,15 +40,16 @@ declare namespace WebpackManifestPlugin { fileName?: string; /** - * A path prefix for all file references. Useful for including your output path in the manifest. - */ - basePath?: string; - - /** - * A path prefix used only on output files, similar to Webpack's output.publicPath. Ignored if basePath was also provided. + * A path prefix that will be added to values of the manifest. + * Default: output.publicPath */ publicPath?: string; + /** + * A path prefix for all keys. Useful for including your output path in the manifest. + */ + basePath?: string; + /** * If set to true will emit to build folder and memory in combination with webpack-dev-server * Default: false @@ -63,17 +67,26 @@ declare namespace WebpackManifestPlugin { /** * Filter out files. */ - filter?: (options: HooksOptions) => void; + filter?: (file: FileDescriptor) => boolean; /** * Modify files details before the manifest is created. */ - map?: (options: HooksOptions) => void; + map?: (file: FileDescriptor) => FileDescriptor; /** - * Create the manifest. It can return anything as long as it's serialisable by JSON.stringify. Use the seed options to populate manifest. - * Default: (manifest, {name, path}) => ({...manifest, [name]: path}) + * Sort files before they are passed to generate. */ - reduce?: (manifest: any, options: HooksOptions) => void; + sort?: (file: FileDescriptor) => number; + + /** + * Create the manifest. It can return anything as long as it's serialisable by JSON.stringify. + */ + generate?: (seed: object, files: FileDescriptor[]) => object; + + /** + * Output manifest file in different format then json (i.e. yaml). + */ + serialize?: (manifest: object) => string; } } From cd4954e1f4ef92bfd3347974acee9707bab7ebba Mon Sep 17 00:00:00 2001 From: Stephan Troyer Date: Sun, 16 Dec 2018 13:04:33 +0100 Subject: [PATCH 2/2] update definition, add tests --- types/webpack-manifest-plugin/index.d.ts | 2 +- .../webpack-manifest-plugin-tests.ts | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/types/webpack-manifest-plugin/index.d.ts b/types/webpack-manifest-plugin/index.d.ts index c0d9067a1c..59222d838e 100644 --- a/types/webpack-manifest-plugin/index.d.ts +++ b/types/webpack-manifest-plugin/index.d.ts @@ -77,7 +77,7 @@ declare namespace WebpackManifestPlugin { /** * Sort files before they are passed to generate. */ - sort?: (file: FileDescriptor) => number; + sort?: (a: FileDescriptor, b: FileDescriptor) => number; /** * Create the manifest. It can return anything as long as it's serialisable by JSON.stringify. diff --git a/types/webpack-manifest-plugin/webpack-manifest-plugin-tests.ts b/types/webpack-manifest-plugin/webpack-manifest-plugin-tests.ts index 3c34f052fa..b52ae5555b 100644 --- a/types/webpack-manifest-plugin/webpack-manifest-plugin-tests.ts +++ b/types/webpack-manifest-plugin/webpack-manifest-plugin-tests.ts @@ -14,14 +14,12 @@ const options: WebpackManifestPlugin.Options = { map: (file) => { if (file.name) { file.name = path.join(path.dirname(file.path), file.name); - return file; - } - }, - reduce: (manifest, { name, path }) => { - if (name) { - return { ...manifest, [name]: path }; } + return file; }, + sort: (a, b) => a.path.localeCompare(b.path), + generate: (seed, files) => files.reduce((manifest, {name, path}) => name ? {...manifest, [name]: path} : manifest, seed), + serialize: (manifest) => JSON.stringify(manifest, null, 2) }; const c: Configuration = {