| 1 |
/* (c) 2015 Ari Porad (@ariporad) <http://ariporad.com>. License: ariporad.mit-license.org */ |
| 2 |
|
| 3 |
/** |
| 4 |
* The hook. Accepts the code of the module and the filename. |
| 5 |
*/ |
| 6 |
declare type Hook = (code: string, filename: string) => string; |
| 7 |
|
| 8 |
/** |
| 9 |
* A matcher function, will be called with path to a file. |
| 10 |
* |
| 11 |
* Should return truthy if the file should be hooked, falsy otherwise. |
| 12 |
*/ |
| 13 |
declare type Matcher = (path: string) => boolean; |
| 14 |
|
| 15 |
/** |
| 16 |
* Reverts the hook when called. |
| 17 |
*/ |
| 18 |
declare type RevertFunction = () => void; |
| 19 |
interface Options { |
| 20 |
/** |
| 21 |
* The extensions to hook. Should start with '.' (ex. ['.js']). |
| 22 |
* |
| 23 |
* Takes precedence over `exts`, `extension` and `ext`. |
| 24 |
* |
| 25 |
* @alias exts |
| 26 |
* @alias extension |
| 27 |
* @alias ext |
| 28 |
* @default ['.js'] |
| 29 |
*/ |
| 30 |
extensions?: ReadonlyArray<string> | string; |
| 31 |
|
| 32 |
/** |
| 33 |
* The extensions to hook. Should start with '.' (ex. ['.js']). |
| 34 |
* |
| 35 |
* Takes precedence over `extension` and `ext`. |
| 36 |
* |
| 37 |
* @alias extension |
| 38 |
* @alias ext |
| 39 |
* @default ['.js'] |
| 40 |
*/ |
| 41 |
exts?: ReadonlyArray<string> | string; |
| 42 |
|
| 43 |
/** |
| 44 |
* The extensions to hook. Should start with '.' (ex. ['.js']). |
| 45 |
* |
| 46 |
* Takes precedence over `ext`. |
| 47 |
* |
| 48 |
* @alias ext |
| 49 |
* @default ['.js'] |
| 50 |
*/ |
| 51 |
extension?: ReadonlyArray<string> | string; |
| 52 |
|
| 53 |
/** |
| 54 |
* The extensions to hook. Should start with '.' (ex. ['.js']). |
| 55 |
* |
| 56 |
* @default ['.js'] |
| 57 |
*/ |
| 58 |
ext?: ReadonlyArray<string> | string; |
| 59 |
|
| 60 |
/** |
| 61 |
* A matcher function, will be called with path to a file. |
| 62 |
* |
| 63 |
* Should return truthy if the file should be hooked, falsy otherwise. |
| 64 |
*/ |
| 65 |
matcher?: Matcher | null; |
| 66 |
|
| 67 |
/** |
| 68 |
* Auto-ignore node_modules. Independent of any matcher. |
| 69 |
* |
| 70 |
* @default true |
| 71 |
*/ |
| 72 |
ignoreNodeModules?: boolean; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Add a require hook. |
| 77 |
* |
| 78 |
* @param hook The hook. Accepts the code of the module and the filename. Required. |
| 79 |
* @returns The `revert` function. Reverts the hook when called. |
| 80 |
*/ |
| 81 |
export declare function addHook(hook: Hook, opts?: Options): RevertFunction; |
| 82 |
export {}; |