Last active
September 21, 2016 12:46
-
-
Save taichi/e39551fef298437ec45c1ce42e714ec8 to your computer and use it in GitHub Desktop.
typedef for https://github.com/substack/node-resolve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Asynchronously resolve the module path string id into cb(err, res [, pkg]), where pkg (if defined) is the data from package.json. | |
*/ | |
declare function resolve(id: string, opts?: Options, callback?: (err?: Error, res?: any, pkg?: any) => string); | |
interface readFile { (filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; } | |
interface readFile { (filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; } | |
interface readFile { (filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; } | |
interface readFile { (filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; } | |
declare interface Options { | |
/** | |
* directory to begin resolving from | |
*/ | |
basedir?: string; | |
/** | |
* package.json data applicable to the module being loaded | |
*/ | |
package?: string; | |
/** | |
* array of file extensions to search in order | |
*/ | |
extensions?: string[]; | |
/** | |
* how to read files asynchronously | |
*/ | |
readFile?: readFile; | |
/** | |
* function to asynchronously test whether a file exists | |
*/ | |
isFile?: (path: string, cb: (err: Error, isFile: boolean) => void) => void; | |
/** | |
* transform the parsed package.json contents before looking at the "main" field | |
*/ | |
packageFilter?: (pkg: any, path: string) => any; | |
/** | |
* transform a path within a package | |
* @param pkg - package data | |
* @param path - the path being resolved | |
* @param relativePath - the path relative from the package.json location | |
* @returns - a relative path that will be joined from the package.json location | |
*/ | |
pathFilter?: (pkg: any, path: string, relativePath: string) => string; | |
/** | |
* require.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this) | |
*/ | |
paths?: string[]; | |
/** | |
* directory (or directories) in which to recursively look for modules. default: "node_modules" | |
*/ | |
moduleDirectory?: string; | |
} | |
declare namespace resolve { | |
/** | |
* Synchronously resolve the module path string id, returning the result and throwing an error when id can't be resolved. | |
*/ | |
export function sync(id: string, options: Options): string[]; | |
/** | |
* Return whether a package is in core. | |
*/ | |
export function isCore(id: string): boolean; | |
export const core: string[]; | |
} | |
export = resolve; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment