UNPKG

7.88 kBTypeScriptView Raw
1export = CopyPlugin;
2/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
3/** @typedef {import("webpack").Compiler} Compiler */
4/** @typedef {import("webpack").Compilation} Compilation */
5/** @typedef {import("webpack").WebpackError} WebpackError */
6/** @typedef {import("webpack").Asset} Asset */
7/** @typedef {import("globby").Options} GlobbyOptions */
8/** @typedef {import("globby").GlobEntry} GlobEntry */
9/** @typedef {ReturnType<Compilation["getLogger"]>} WebpackLogger */
10/** @typedef {ReturnType<Compilation["getCache"]>} CacheFacade */
11/** @typedef {ReturnType<ReturnType<Compilation["getCache"]>["getLazyHashedEtag"]>} Etag */
12/** @typedef {ReturnType<Compilation["fileSystemInfo"]["mergeSnapshots"]>} Snapshot */
13/**
14 * @typedef {boolean} Force
15 */
16/**
17 * @typedef {Object} CopiedResult
18 * @property {string} sourceFilename
19 * @property {string} absoluteFilename
20 * @property {string} filename
21 * @property {Asset["source"]} source
22 * @property {Force | undefined} force
23 * @property {Record<string, any>} info
24 */
25/**
26 * @typedef {string} StringPattern
27 */
28/**
29 * @typedef {boolean} NoErrorOnMissing
30 */
31/**
32 * @typedef {string} Context
33 */
34/**
35 * @typedef {string} From
36 */
37/**
38 * @callback ToFunction
39 * @param {{ context: string, absoluteFilename?: string }} pathData
40 * @return {string | Promise<string>}
41 */
42/**
43 * @typedef {string | ToFunction} To
44 */
45/**
46 * @typedef {"dir" | "file" | "template"} ToType
47 */
48/**
49 * @callback TransformerFunction
50 * @param {Buffer} input
51 * @param {string} absoluteFilename
52 * @returns {string | Buffer | Promise<string> | Promise<Buffer>}
53 */
54/**
55 * @typedef {{ keys: { [key: string]: any } } | { keys: ((defaultCacheKeys: { [key: string]: any }, absoluteFilename: string) => Promise<{ [key: string]: any }>) }} TransformerCacheObject
56 */
57/**
58 * @typedef {Object} TransformerObject
59 * @property {TransformerFunction} transformer
60 * @property {boolean | TransformerCacheObject} [cache]
61 */
62/**
63 * @typedef {TransformerFunction | TransformerObject} Transform
64 */
65/**
66 * @callback Filter
67 * @param {string} filepath
68 * @returns {boolean | Promise<boolean>}
69 */
70/**
71 * @callback TransformAllFunction
72 * @param {{ data: Buffer, sourceFilename: string, absoluteFilename: string }[]} data
73 * @returns {string | Buffer | Promise<string> | Promise<Buffer>}
74 */
75/**
76 * @typedef { Record<string, any> | ((item: { absoluteFilename: string, sourceFilename: string, filename: string, toType: ToType }) => Record<string, any>) } Info
77 */
78/**
79 * @typedef {Object} ObjectPattern
80 * @property {From} from
81 * @property {GlobbyOptions} [globOptions]
82 * @property {Context} [context]
83 * @property {To} [to]
84 * @property {ToType} [toType]
85 * @property {Info} [info]
86 * @property {Filter} [filter]
87 * @property {Transform} [transform]
88 * @property {TransformAllFunction} [transformAll]
89 * @property {Force} [force]
90 * @property {number} [priority]
91 * @property {NoErrorOnMissing} [noErrorOnMissing]
92 */
93/**
94 * @typedef {StringPattern | ObjectPattern} Pattern
95 */
96/**
97 * @typedef {Object} AdditionalOptions
98 * @property {number} [concurrency]
99 */
100/**
101 * @typedef {Object} PluginOptions
102 * @property {Pattern[]} patterns
103 * @property {AdditionalOptions} [options]
104 */
105declare class CopyPlugin {
106 /**
107 * @private
108 * @param {Compilation} compilation
109 * @param {number} startTime
110 * @param {string} dependency
111 * @returns {Promise<Snapshot | undefined>}
112 */
113 private static createSnapshot;
114 /**
115 * @private
116 * @param {Compilation} compilation
117 * @param {Snapshot} snapshot
118 * @returns {Promise<boolean | undefined>}
119 */
120 private static checkSnapshotValid;
121 /**
122 * @private
123 * @param {Compiler} compiler
124 * @param {Compilation} compilation
125 * @param {Buffer} source
126 * @returns {string}
127 */
128 private static getContentHash;
129 /**
130 * @private
131 * @param {typeof import("globby").globby} globby
132 * @param {Compiler} compiler
133 * @param {Compilation} compilation
134 * @param {WebpackLogger} logger
135 * @param {CacheFacade} cache
136 * @param {ObjectPattern & { context: string }} inputPattern
137 * @param {number} index
138 * @returns {Promise<Array<CopiedResult | undefined> | undefined>}
139 */
140 private static runPattern;
141 /**
142 * @param {PluginOptions} [options]
143 */
144 constructor(options?: PluginOptions | undefined);
145 /**
146 * @private
147 * @type {Pattern[]}
148 */
149 private patterns;
150 /**
151 * @private
152 * @type {AdditionalOptions}
153 */
154 private options;
155 /**
156 * @param {Compiler} compiler
157 */
158 apply(compiler: Compiler): void;
159}
160declare namespace CopyPlugin {
161 export {
162 Schema,
163 Compiler,
164 Compilation,
165 WebpackError,
166 Asset,
167 GlobbyOptions,
168 GlobEntry,
169 WebpackLogger,
170 CacheFacade,
171 Etag,
172 Snapshot,
173 Force,
174 CopiedResult,
175 StringPattern,
176 NoErrorOnMissing,
177 Context,
178 From,
179 ToFunction,
180 To,
181 ToType,
182 TransformerFunction,
183 TransformerCacheObject,
184 TransformerObject,
185 Transform,
186 Filter,
187 TransformAllFunction,
188 Info,
189 ObjectPattern,
190 Pattern,
191 AdditionalOptions,
192 PluginOptions,
193 };
194}
195type Compiler = import("webpack").Compiler;
196type PluginOptions = {
197 patterns: Pattern[];
198 options?: AdditionalOptions | undefined;
199};
200type Schema = import("schema-utils/declarations/validate").Schema;
201type Compilation = import("webpack").Compilation;
202type WebpackError = import("webpack").WebpackError;
203type Asset = import("webpack").Asset;
204type GlobbyOptions = import("globby").Options;
205type GlobEntry = import("globby").GlobEntry;
206type WebpackLogger = ReturnType<Compilation["getLogger"]>;
207type CacheFacade = ReturnType<Compilation["getCache"]>;
208type Etag = ReturnType<
209 ReturnType<Compilation["getCache"]>["getLazyHashedEtag"]
210>;
211type Snapshot = ReturnType<Compilation["fileSystemInfo"]["mergeSnapshots"]>;
212type Force = boolean;
213type CopiedResult = {
214 sourceFilename: string;
215 absoluteFilename: string;
216 filename: string;
217 source: Asset["source"];
218 force: Force | undefined;
219 info: Record<string, any>;
220};
221type StringPattern = string;
222type NoErrorOnMissing = boolean;
223type Context = string;
224type From = string;
225type ToFunction = (pathData: {
226 context: string;
227 absoluteFilename?: string;
228}) => string | Promise<string>;
229type To = string | ToFunction;
230type ToType = "dir" | "file" | "template";
231type TransformerFunction = (
232 input: Buffer,
233 absoluteFilename: string
234) => string | Buffer | Promise<string> | Promise<Buffer>;
235type TransformerCacheObject =
236 | {
237 keys: {
238 [key: string]: any;
239 };
240 }
241 | {
242 keys: (
243 defaultCacheKeys: {
244 [key: string]: any;
245 },
246 absoluteFilename: string
247 ) => Promise<{
248 [key: string]: any;
249 }>;
250 };
251type TransformerObject = {
252 transformer: TransformerFunction;
253 cache?: boolean | TransformerCacheObject | undefined;
254};
255type Transform = TransformerFunction | TransformerObject;
256type Filter = (filepath: string) => boolean | Promise<boolean>;
257type TransformAllFunction = (
258 data: {
259 data: Buffer;
260 sourceFilename: string;
261 absoluteFilename: string;
262 }[]
263) => string | Buffer | Promise<string> | Promise<Buffer>;
264type Info =
265 | Record<string, any>
266 | ((item: {
267 absoluteFilename: string;
268 sourceFilename: string;
269 filename: string;
270 toType: ToType;
271 }) => Record<string, any>);
272type ObjectPattern = {
273 from: From;
274 globOptions?: import("globby").Options | undefined;
275 context?: string | undefined;
276 to?: To | undefined;
277 toType?: ToType | undefined;
278 info?: Info | undefined;
279 filter?: Filter | undefined;
280 transform?: Transform | undefined;
281 transformAll?: TransformAllFunction | undefined;
282 force?: boolean | undefined;
283 priority?: number | undefined;
284 noErrorOnMissing?: boolean | undefined;
285};
286type Pattern = StringPattern | ObjectPattern;
287type AdditionalOptions = {
288 concurrency?: number | undefined;
289};