From 098b6ddbea8640f008cf5d786f7ae9d12cc54bb8 Mon Sep 17 00:00:00 2001 From: shellscape Date: Thu, 29 Jul 2021 07:40:24 -0400 Subject: [PATCH] fix: improve types --- README.md | 2 +- src/helpers.ts | 4 ++-- src/index.ts | 16 +++++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c87390a..cbbe981 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ A path prefix that will be added to values of the manifest. ### `removeKeyHash` -Type: `RegExp | Boolean`
+Type: `RegExp | false`
Default: `/([a-f0-9]{32}\.?)/gi` If set to a valid `RegExp`, removes hashes from manifest keys. e.g. diff --git a/src/helpers.ts b/src/helpers.ts index b5eba95..9b524c1 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -2,7 +2,7 @@ import { dirname, join, basename } from 'path'; import webpack, { AssetInfo, Chunk } from 'webpack'; -import { InternalOptions } from './'; +import { InternalOptions, Manifest } from './'; export interface FileDescriptor { chunk?: ProperChunk; @@ -34,7 +34,7 @@ const generateManifest = ( files: FileDescriptor[], { generate, seed = {} }: InternalOptions ) => { - let result; + let result: Manifest; if (generate) { const entrypointsArray = Array.from(compilation.entrypoints.entries()); const entrypoints = entrypointsArray.reduce( diff --git a/src/index.ts b/src/index.ts index 59677de..5f3b7c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,17 +10,23 @@ import { beforeRunHook, emitHook, getCompilerHooks, normalModuleLoaderHook } fro const emitCountMap: EmitCountMap = new Map(); +export type Manifest = Record; + export interface InternalOptions { [key: string]: any; basePath: string; fileName: string; filter: (file: FileDescriptor) => Boolean; - generate: (seed: Record, files: FileDescriptor[], entries: Record) => any; + generate: ( + seed: Record, + files: FileDescriptor[], + entries: Record + ) => Manifest; map: (file: FileDescriptor) => FileDescriptor; publicPath: string; - removeKeyHash: RegExp; - seed: Record | any[]; - serialize: (manifest: any) => string; + removeKeyHash: RegExp | false; + seed: Record; + serialize: (manifest: Manifest) => string; sort: (fileA: FileDescriptor, fileB: FileDescriptor) => Number; transformExtensions: RegExp; useEntryKeys: Boolean; @@ -103,4 +109,4 @@ class WebpackManifestPlugin implements WebpackPluginInstance { } } -module.exports = { getCompilerHooks, WebpackManifestPlugin }; +export { getCompilerHooks, WebpackManifestPlugin };