Skip to content

Commit

Permalink
feat: add TypeScript types (#67)
Browse files Browse the repository at this point in the history
Note that these types explicitly do not include the default
export of the `Hook` function. That default export is just
there for backwards compat at this point.
  • Loading branch information
trentm authored Apr 19, 2023
1 parent f902e00 commit f50ac96
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# require-in-the-middle changelog

## Unreleased

- Add [TypeScript types](./types/index.d.ts).
(/~https://github.com/elastic/require-in-the-middle/pull/67)


## v7.0.1

- Fix hooking of 'http2' with Node.js versions [8.0, 8.8) where the 'http2'
built-in module was behind the `--expose-http2` flag. Release v7.0.0
introduced a bug with this case. The process would crash with:
built-in module was behind the `--expose-http2` flag.
(/~https://github.com/elastic/require-in-the-middle/pull/68)
Release v7.0.0 introduced a bug with this case where the process would crash with:

```
AssertionError [ERR_ASSERTION]: unexpected that there is no Module entry for "http2" in require.cache
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "7.0.1",
"description": "Module to hook into the Node.js require function",
"main": "index.js",
"types": "types/index.d.ts",
"dependencies": {
"debug": "^4.1.1",
"module-details-from-path": "^1.0.3",
Expand Down Expand Up @@ -42,7 +43,9 @@
"module",
"load"
],
"files": [],
"files": [
"types"
],
"author": "Thomas Watson Steen <w@tson.dk> (https://twitter.com/wa7son)",
"license": "MIT",
"bugs": {
Expand Down
12 changes: 12 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface HookOptions {
internals?: boolean;
}

export type OnRequireFn = <T>(exports: T, name: string, basedir?: string) => T;

export class Hook {
constructor(modules: string[] | null, options: HookOptions | null, onrequire: OnRequireFn);
constructor(modules: string[] | null, onrequire: OnRequireFn);
constructor(onrequire: OnRequireFn);
unhook(): void;
}

0 comments on commit f50ac96

Please sign in to comment.