UNPKG

2.33 kBTypeScriptView Raw
1// Type definitions for browser-resolve 2.0
2// Project: https://github.com/defunctzombie/node-browser-resolve
3// Definitions by: Mario Nebl <https://github.com/marionebl>
4// Piotr Błażejewicz <https://github.com/peterblazejewicz>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7import * as resv from 'resolve';
8
9/**
10 * Resolve a module path and call cb(err, path)
11 *
12 * @param id Identifier to resolve
13 * @param callback
14 */
15declare function resolve(id: string, cb: resolve.Callback): void;
16
17/**
18 * Resolve a module path and call cb(err, path)
19 *
20 * @param id Identifier to resolve
21 * @param options Options to use for resolving, optional.
22 * @param callback
23 */
24declare function resolve(id: string, opts: resolve.AsyncOpts, cb: resolve.Callback): void;
25
26declare namespace resolve {
27 interface Opts {
28 /**
29 * directory to begin resolving from
30 */
31 basedir?: string | undefined;
32 /**
33 * the 'browser' property to use from package.json
34 * @default 'browser'
35 */
36 browser?: string | undefined;
37 /**
38 * the calling filename where the require() call originated (in the source)
39 */
40 filename?: string | undefined;
41 /**
42 * modules object with id to path mappings to consult before doing manual resolution
43 * (use to provide core modules)
44 */
45 modules?: { [id: string]: string } | undefined;
46 /**
47 * transform the parsed package.json contents before looking at the main field
48 */
49 packageFilter?: ((info: any, pkgdir: string) => any) | undefined;
50 /**
51 * require.paths array to use if nothing is found on the normal node_modules recursive walk
52 */
53 paths?: string[] | undefined;
54 }
55
56 type AsyncOpts = resv.AsyncOpts & Opts;
57 type SyncOpts = resv.SyncOpts & Opts;
58
59 /**
60 * Callback invoked when resolving asynchronously
61 * @param error
62 * @param resolved Absolute path to resolved identifier
63 */
64 type Callback = (err: Error | null, resolved?: string) => void;
65
66 /**
67 * Returns a module path
68 * @param id Identifier to resolve
69 * @param options Options to use for resolving.
70 */
71 function sync(id: string, opts?: SyncOpts): string;
72}
73
74export = resolve;