UNPKG

1.77 kBTypeScriptView Raw
1/// <reference types="node" />
2
3export interface Loader {
4 path: string;
5 query: string;
6 request: string;
7 options: any;
8 normal: null | ((request: string) => string);
9 pitch: null | ((request: string) => string);
10 raw: string;
11 data: any;
12 pitchExecuted: boolean;
13 normalExecuted: boolean;
14}
15
16export interface RunLoaderOption {
17 resource: string;
18 loaders: any[];
19 context: any;
20 readResource: (
21 filename: string,
22 callback: (err: NodeJS.ErrnoException | null, data: Buffer | null) => void,
23 ) => void;
24}
25
26export interface RunLoaderResult {
27 result?: Array<Buffer | null> | undefined;
28 resourceBuffer?: Buffer | null | undefined;
29 cacheable: boolean;
30 fileDependencies: string[];
31 contextDependencies: string[];
32}
33
34export interface ExtendedLoaderContext {
35 context: string | null;
36 loaderIndex: number;
37 loaders: Loader[];
38 resourcePath: string | undefined;
39 resourceQuery: string | undefined;
40 async: (() => (() => void) | undefined) | null;
41 callback: (() => void) | null;
42 cacheable: (flag: boolean) => void;
43 dependency: (file: string) => void;
44 addDependency: (file: string) => void;
45 addContextDependency: (context: string) => void;
46 getDependencies: () => string[];
47 getContextDependencies: () => string[];
48 clearDependencies: () => void;
49 resource: string;
50 request: string;
51 remainingRequest: string;
52 currentRequest: string;
53 previousRequest: string;
54 query: {
55 [key: string]: any;
56 } | string;
57 data: any;
58}
59
60export function getContext(resource: string): string;
61
62export function runLoaders(
63 options: RunLoaderOption,
64 callback: (err: NodeJS.ErrnoException | null, result: RunLoaderResult) => any,
65): void;