1 | interface PackageMeta {
|
2 | name: string;
|
3 | version: string;
|
4 | [key: string]: any;
|
5 | }
|
6 |
|
7 | interface ToString {
|
8 | toString(): string;
|
9 | }
|
10 |
|
11 | type StringOrToString = string | ToString;
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | type resolveCallback = (err: Error | null, resolved?: string, pkg?: PackageMeta) => void;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | type existsCallback = (err: Error | null, isFile?: boolean) => void;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | type readFileCallback = (err: Error | null, file?: StringOrToString) => void;
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | type realpathCallback = (err: Error | null, resolved?: string) => void;
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | type readPackageCallback = (err: Error | null, package?: Record<string, unknown>) => void;
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | declare function resolve(id: string, cb: resolveCallback): void;
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | declare function resolve(id: string, opts: resolve.AsyncOpts, cb: resolveCallback): void;
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | declare function resolveSync(id: string, opts?: resolve.SyncOpts): string;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | declare function resolveIsCore(id: string): boolean | undefined;
|
82 |
|
83 |
|
84 | type JSONValue = string | number | boolean | JSONObject | JSONArray;
|
85 | interface JSONObject {
|
86 | [x: string]: JSONValue;
|
87 | }
|
88 | interface JSONArray extends Array<JSONValue> {}
|
89 |
|
90 | declare namespace resolve {
|
91 | export type PackageJSON = JSONObject;
|
92 |
|
93 | interface Opts {
|
94 |
|
95 | basedir?: string | undefined;
|
96 |
|
97 | package?: any;
|
98 |
|
99 | includeCoreModules?: boolean | undefined;
|
100 |
|
101 | extensions?: string | readonly string[] | undefined;
|
102 |
|
103 | packageFilter?: ((pkg: PackageJSON, pkgFile: string, dir: string) => PackageJSON) | undefined;
|
104 | /** transform a path within a package */
|
105 | pathFilter?: ((pkg: PackageJSON, path: string, relativePath: string) => string) | undefined;
|
106 | /** require.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this) */
|
107 | paths?: string | readonly string[] | undefined;
|
108 | /** return the list of candidate paths where the packages sources may be found (probably don't use this) */
|
109 | packageIterator?:
|
110 | | ((request: string, start: string, getPackageCandidates: () => string[], opts: Opts) => string[])
|
111 | | undefined;
|
112 | /** directory (or directories) in which to recursively look for modules. (default to 'node_modules') */
|
113 | moduleDirectory?: string | readonly string[] | undefined;
|
114 | /**
|
115 | * if true, doesn't resolve `basedir` to real path before resolving.
|
116 | * This is the way Node resolves dependencies when executed with the --preserve-symlinks flag.
|
117 | *
|
118 | * Note: this property is currently true by default but it will be changed to false in the next major version because Node's resolution
|
119 | * algorithm does not preserve symlinks by default.
|
120 | */
|
121 | preserveSymlinks?: boolean | undefined;
|
122 | }
|
123 |
|
124 | interface BaseAsyncOpts extends Opts {
|
125 | /** function to asynchronously test whether a file exists */
|
126 | isFile?: ((file: string, cb: existsCallback) => void) | undefined;
|
127 | /** function to asynchronously test whether a directory exists */
|
128 | isDirectory?: ((directory: string, cb: existsCallback) => void) | undefined;
|
129 | /** function to asynchronously resolve a potential symlink to its real path */
|
130 | realpath?: ((file: string, cb: realpathCallback) => void) | undefined;
|
131 | }
|
132 |
|
133 | export type AsyncOpts =
|
134 | & BaseAsyncOpts
|
135 | & ({
|
136 |
|
137 | readFile?: ((file: string, cb: readFileCallback) => void) | undefined;
|
138 |
|
139 | readPackage?: never | undefined;
|
140 | } | {
|
141 |
|
142 | readFile?: never | undefined;
|
143 |
|
144 | readPackage?:
|
145 | | ((
|
146 | readFile: (file: string, cb: readFileCallback) => void,
|
147 | pkgfile: string,
|
148 | cb: readPackageCallback,
|
149 | ) => void)
|
150 | | undefined;
|
151 | });
|
152 |
|
153 | interface BaseSyncOpts extends Opts {
|
154 | /** function to synchronously test whether a file exists */
|
155 | isFile?: ((file: string) => boolean) | undefined;
|
156 | /** function to synchronously test whether a directory exists */
|
157 | isDirectory?: ((directory: string) => boolean) | undefined;
|
158 | /** function to synchronously resolve a potential symlink to its real path */
|
159 | realpathSync?: ((file: string) => string) | undefined;
|
160 | }
|
161 |
|
162 | export type SyncOpts =
|
163 | & BaseSyncOpts
|
164 | & ({
|
165 |
|
166 | readFileSync?: ((file: string) => StringOrToString) | undefined;
|
167 |
|
168 | readPackageSync?: never | undefined;
|
169 | } | {
|
170 |
|
171 | readFileSync?: never | undefined;
|
172 |
|
173 | readPackageSync?:
|
174 | | ((
|
175 | readFileSync: (file: string) => StringOrToString,
|
176 | pkgfile: string,
|
177 | ) => Record<string, unknown> | undefined)
|
178 | | undefined;
|
179 | });
|
180 |
|
181 | export var sync: typeof resolveSync;
|
182 | export var isCore: typeof resolveIsCore;
|
183 | }
|
184 |
|
185 | export = resolve;
|
186 |
|
\ | No newline at end of file |