UNPKG

5.93 kBTypeScriptView Raw
1/// <reference types="node" />
2import { AsyncSeriesBailHook, AsyncSeriesHook, SyncHook } from "tapable";
3export interface ResolvePluginInstance {
4 apply: (resolver: Resolver) => void;
5}
6declare interface AliasOption {
7 alias: string | false | string[];
8 name: string;
9 onlyModule?: boolean;
10}
11declare interface BaseResolveRequest {
12 path: string | false;
13 descriptionFilePath?: string;
14 descriptionFileRoot?: string;
15 descriptionFileData?: object;
16 relativePath?: string;
17 ignoreSymlinks?: boolean;
18 fullySpecified?: boolean;
19}
20export declare interface FileSystem {
21 readFile: {
22 (arg0: string, arg1: FileSystemCallback<string | Buffer>): void;
23 (arg0: string, arg1: object, arg2: FileSystemCallback<string | Buffer>): void;
24 };
25 readdir: {
26 (arg0: string, arg1: FileSystemCallback<(string | Buffer)[] | FileSystemDirent[]>): void;
27 (arg0: string, arg1: object, arg2: FileSystemCallback<(string | Buffer)[] | FileSystemDirent[]>): void;
28 };
29 readJson?: {
30 (arg0: string, arg1: FileSystemCallback<object>): void;
31 (arg0: string, arg1: object, arg2: FileSystemCallback<object>): void;
32 };
33 readlink: {
34 (arg0: string, arg1: FileSystemCallback<string | Buffer>): void;
35 (arg0: string, arg1: object, arg2: FileSystemCallback<string | Buffer>): void;
36 };
37 lstat?: {
38 (arg0: string, arg1: FileSystemCallback<FileSystemStats>): void;
39 (arg0: string, arg1: object, arg2: FileSystemCallback<string | Buffer>): void;
40 };
41 stat: {
42 (arg0: string, arg1: FileSystemCallback<FileSystemStats>): void;
43 (arg0: string, arg1: object, arg2: FileSystemCallback<string | Buffer>): void;
44 };
45}
46declare interface FileSystemCallback<T> {
47 (err?: null | (PossibleFileSystemError & Error), result?: T): any;
48}
49declare interface FileSystemDirent {
50 name: string | Buffer;
51 isDirectory: () => boolean;
52 isFile: () => boolean;
53}
54declare interface FileSystemStats {
55 isDirectory: () => boolean;
56 isFile: () => boolean;
57}
58declare interface ParsedIdentifier {
59 request: string;
60 query: string;
61 fragment: string;
62 directory: boolean;
63 module: boolean;
64 file: boolean;
65 internal: boolean;
66}
67declare type Plugin = {
68 apply: (arg0: Resolver) => void;
69} | ((this: Resolver, arg1: Resolver) => void);
70declare interface PnpApiImpl {
71 resolveToUnqualified: (arg0: string, arg1: string, arg2: object) => string;
72}
73declare interface PossibleFileSystemError {
74 code?: string;
75 errno?: number;
76 path?: string;
77 syscall?: string;
78}
79/**
80 * Resolve context
81 */
82export declare interface ResolveContext {
83 contextDependencies?: WriteOnlySet<string>;
84 /**
85 * files that was found on file system
86 */
87 fileDependencies?: WriteOnlySet<string>;
88 /**
89 * dependencies that was not found on file system
90 */
91 missingDependencies?: WriteOnlySet<string>;
92 /**
93 * set of hooks' calls. For instance, `resolve → parsedResolve → describedResolve`,
94 */
95 stack?: Set<string>;
96 /**
97 * log function
98 */
99 log?: (arg0: string) => void;
100}
101declare interface ResolveOptions {
102 alias: AliasOption[];
103 fallback: AliasOption[];
104 aliasFields: Set<string | string[]>;
105 cachePredicate: (arg0: ResolveRequest) => boolean;
106 cacheWithContext: boolean;
107 /**
108 * A list of exports field condition names.
109 */
110 conditionNames: Set<string>;
111 descriptionFiles: string[];
112 enforceExtension: boolean;
113 exportsFields: Set<string | string[]>;
114 importsFields: Set<string | string[]>;
115 extensions: Set<string>;
116 fileSystem: FileSystem;
117 unsafeCache: false | object;
118 symlinks: boolean;
119 resolver?: Resolver;
120 modules: (string | string[])[];
121 mainFields: {
122 name: string[];
123 forceRelative: boolean;
124 }[];
125 mainFiles: Set<string>;
126 plugins: Plugin[];
127 pnpApi: null | PnpApiImpl;
128 roots: Set<string>;
129 fullySpecified: boolean;
130 resolveToContext: boolean;
131 restrictions: Set<string | RegExp>;
132 preferRelative: boolean;
133 preferAbsolute: boolean;
134}
135export declare type ResolveRequest = BaseResolveRequest & Partial<ParsedIdentifier>;
136export declare abstract class Resolver {
137 fileSystem: FileSystem;
138 options: ResolveOptions;
139 hooks: {
140 resolveStep: SyncHook<[
141 AsyncSeriesBailHook<[
142 ResolveRequest,
143 ResolveContext
144 ], null | ResolveRequest>,
145 ResolveRequest
146 ]>;
147 noResolve: SyncHook<[ResolveRequest, Error]>;
148 resolve: AsyncSeriesBailHook<[
149 ResolveRequest,
150 ResolveContext
151 ], null | ResolveRequest>;
152 result: AsyncSeriesHook<[ResolveRequest, ResolveContext]>;
153 };
154 ensureHook(name: string | AsyncSeriesBailHook<[
155 ResolveRequest,
156 ResolveContext
157 ], null | ResolveRequest>): AsyncSeriesBailHook<[
158 ResolveRequest,
159 ResolveContext
160 ], null | ResolveRequest>;
161 getHook(name: string | AsyncSeriesBailHook<[
162 ResolveRequest,
163 ResolveContext
164 ], null | ResolveRequest>): AsyncSeriesBailHook<[
165 ResolveRequest,
166 ResolveContext
167 ], null | ResolveRequest>;
168 resolveSync(context: object, path: string, request: string): string | false;
169 resolve(context: object, path: string, request: string, resolveContext: ResolveContext, callback: (arg0: null | Error, arg1?: string | false, arg2?: ResolveRequest) => void): void;
170 doResolve(hook?: any, request?: any, message?: any, resolveContext?: any, callback?: any): any;
171 parse(identifier: string): ParsedIdentifier;
172 isModule(path?: any): boolean;
173 isPrivate(path?: any): boolean;
174 isDirectory(path: string): boolean;
175 join(path?: any, request?: any): string;
176 normalize(path?: any): string;
177}
178declare interface WriteOnlySet<T> {
179 add: (T?: any) => void;
180}
181export {};