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