From fd095fb79399df5edbd06d9dbd1ed30fe4f7eb24 Mon Sep 17 00:00:00 2001 From: Malte Legenhausen Date: Sat, 29 Jan 2022 14:05:43 +0100 Subject: [PATCH] fix: async `to` support --- src/index.js | 10 +++++----- types/index.d.ts | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/index.js b/src/index.js index 0cb3f9f..54fa203 100644 --- a/src/index.js +++ b/src/index.js @@ -59,7 +59,7 @@ const template = /\[\\*([\w:]+)\\*\]/i; /** * @callback ToFunction * @param {{ context: string, absoluteFilename?: string }} pathData - * @return {string} + * @return {string | Promise} */ /** @@ -74,7 +74,7 @@ const template = /\[\\*([\w:]+)\\*\]/i; * @callback TransformerFunction * @param {Buffer} input * @param {string} absoluteFilename - * @returns {string | Buffer} + * @returns {string | Buffer | Promise | Promise} */ /** @@ -94,13 +94,13 @@ const template = /\[\\*([\w:]+)\\*\]/i; /** * @callback Filter * @param {string} filepath - * @returns {boolean} + * @returns {boolean | Promise} */ /** * @callback TransformAllFunction * @param {{ data: Buffer, sourceFilename: string, absoluteFilename: string }[]} data - * @returns {string | Buffer} + * @returns {string | Buffer | Promise | Promise} */ /** @@ -959,7 +959,7 @@ class CopyPlugin { const filename = typeof normalizedPattern.to === "function" - ? normalizedPattern.to({ context }) + ? await normalizedPattern.to({ context }) : normalizedPattern.to; if (template.test(filename)) { diff --git a/types/index.d.ts b/types/index.d.ts index 9929913..4d6a5d4 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -37,7 +37,7 @@ export = CopyPlugin; /** * @callback ToFunction * @param {{ context: string, absoluteFilename?: string }} pathData - * @return {string} + * @return {string | Promise} */ /** * @typedef {string | ToFunction} To @@ -49,7 +49,7 @@ export = CopyPlugin; * @callback TransformerFunction * @param {Buffer} input * @param {string} absoluteFilename - * @returns {string | Buffer} + * @returns {string | Buffer | Promise | Promise} */ /** * @typedef {{ keys: { [key: string]: any } } | { keys: ((defaultCacheKeys: { [key: string]: any }, absoluteFilename: string) => Promise<{ [key: string]: any }>) }} TransformerCacheObject @@ -65,12 +65,12 @@ export = CopyPlugin; /** * @callback Filter * @param {string} filepath - * @returns {boolean} + * @returns {boolean | Promise} */ /** * @callback TransformAllFunction * @param {{ data: Buffer, sourceFilename: string, absoluteFilename: string }[]} data - * @returns {string | Buffer} + * @returns {string | Buffer | Promise | Promise} */ /** * @typedef { { [key: string]: string } | ((item: { absoluteFilename: string, sourceFilename: string, filename: string, toType: ToType }) => { [key: string]: string }) } Info @@ -227,13 +227,13 @@ type From = string; type ToFunction = (pathData: { context: string; absoluteFilename?: string; -}) => string; +}) => string | Promise; type To = string | ToFunction; type ToType = "dir" | "file" | "template"; type TransformerFunction = ( input: Buffer, absoluteFilename: string -) => string | Buffer; +) => string | Buffer | Promise | Promise; type TransformerCacheObject = | { keys: { @@ -255,14 +255,14 @@ type TransformerObject = { cache?: boolean | TransformerCacheObject | undefined; }; type Transform = TransformerFunction | TransformerObject; -type Filter = (filepath: string) => boolean; +type Filter = (filepath: string) => boolean | Promise; type TransformAllFunction = ( data: { data: Buffer; sourceFilename: string; absoluteFilename: string; }[] -) => string | Buffer; +) => string | Buffer | Promise | Promise; type Info = | { [key: string]: string;