Skip to content

Commit

Permalink
fix: async to support
Browse files Browse the repository at this point in the history
  • Loading branch information
mlegenhausen authored Jan 29, 2022
1 parent b54ce95 commit fd095fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const template = /\[\\*([\w:]+)\\*\]/i;
/**
* @callback ToFunction
* @param {{ context: string, absoluteFilename?: string }} pathData
* @return {string}
* @return {string | Promise<string>}
*/

/**
Expand All @@ -74,7 +74,7 @@ const template = /\[\\*([\w:]+)\\*\]/i;
* @callback TransformerFunction
* @param {Buffer} input
* @param {string} absoluteFilename
* @returns {string | Buffer}
* @returns {string | Buffer | Promise<string> | Promise<Buffer>}
*/

/**
Expand All @@ -94,13 +94,13 @@ const template = /\[\\*([\w:]+)\\*\]/i;
/**
* @callback Filter
* @param {string} filepath
* @returns {boolean}
* @returns {boolean | Promise<boolean>}
*/

/**
* @callback TransformAllFunction
* @param {{ data: Buffer, sourceFilename: string, absoluteFilename: string }[]} data
* @returns {string | Buffer}
* @returns {string | Buffer | Promise<string> | Promise<Buffer>}
*/

/**
Expand Down Expand Up @@ -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)) {
Expand Down
16 changes: 8 additions & 8 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export = CopyPlugin;
/**
* @callback ToFunction
* @param {{ context: string, absoluteFilename?: string }} pathData
* @return {string}
* @return {string | Promise<string>}
*/
/**
* @typedef {string | ToFunction} To
Expand All @@ -49,7 +49,7 @@ export = CopyPlugin;
* @callback TransformerFunction
* @param {Buffer} input
* @param {string} absoluteFilename
* @returns {string | Buffer}
* @returns {string | Buffer | Promise<string> | Promise<Buffer>}
*/
/**
* @typedef {{ keys: { [key: string]: any } } | { keys: ((defaultCacheKeys: { [key: string]: any }, absoluteFilename: string) => Promise<{ [key: string]: any }>) }} TransformerCacheObject
Expand All @@ -65,12 +65,12 @@ export = CopyPlugin;
/**
* @callback Filter
* @param {string} filepath
* @returns {boolean}
* @returns {boolean | Promise<boolean>}
*/
/**
* @callback TransformAllFunction
* @param {{ data: Buffer, sourceFilename: string, absoluteFilename: string }[]} data
* @returns {string | Buffer}
* @returns {string | Buffer | Promise<string> | Promise<Buffer>}
*/
/**
* @typedef { { [key: string]: string } | ((item: { absoluteFilename: string, sourceFilename: string, filename: string, toType: ToType }) => { [key: string]: string }) } Info
Expand Down Expand Up @@ -227,13 +227,13 @@ type From = string;
type ToFunction = (pathData: {
context: string;
absoluteFilename?: string;
}) => string;
}) => string | Promise<string>;
type To = string | ToFunction;
type ToType = "dir" | "file" | "template";
type TransformerFunction = (
input: Buffer,
absoluteFilename: string
) => string | Buffer;
) => string | Buffer | Promise<string> | Promise<Buffer>;
type TransformerCacheObject =
| {
keys: {
Expand All @@ -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<boolean>;
type TransformAllFunction = (
data: {
data: Buffer;
sourceFilename: string;
absoluteFilename: string;
}[]
) => string | Buffer;
) => string | Buffer | Promise<string> | Promise<Buffer>;
type Info =
| {
[key: string]: string;
Expand Down

0 comments on commit fd095fb

Please sign in to comment.