Skip to content

Commit

Permalink
Add TypeScript definition (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
barmac and sindresorhus committed Jan 14, 2021
1 parent a92dc36 commit 559dbd3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
45 changes: 45 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/// <reference types="node"/>

declare namespace electronReloader {
interface Options {
/**
Watch files used in the renderer process and reload the window when they change.
@default true
*/
readonly watchRenderer?: boolean;

/**
Prints watched paths and when files change. Can be useful to make sure you set it up correctly.
@default false
*/
readonly debug?: boolean;

/**
Ignore patterns passed to [`chokidar`](https://github.com/paulmillr/chokidar#path-filtering).
By default, files/directories starting with a `.`, `.map` files, and `node_modules` directories are ignored. This option is additive to those.
*/
readonly ignore?: readonly (string | RegExp)[];
}
}

/**
@param moduleObject - Global `module` object.
@example
```
import electronReloader = require('electron-reloader');
try {
require('electron-reloader')(module);
} catch {}
```
*/
declare function electronReloader(
moduleObject: NodeModule,
options?: electronReloader.Options
): void;

export = electronReloader;
8 changes: 8 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {expectType} from 'tsd';
import electronReloader = require('.');

expectType<void>(electronReloader(module));
expectType<void>(electronReloader(module, {watchRenderer: true}));
expectType<void>(electronReloader(module, {debug: true, ignore: ['tmp', /dist/]}));
expectType<void>(electronReloader(module, {watchRenderer: true, ignore: ['tmp', /dist/]}));
expectType<void>(electronReloader(module, {watchRenderer: true, debug: true, ignore: ['tmp', /dist/]}));
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"url": "https://sindresorhus.com"
},
"scripts": {
"test": "xo",
"test": "xo && tsd",
"start": "electron test/main"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"electron",
Expand Down Expand Up @@ -44,7 +45,9 @@
"find-up": "^4.1.0"
},
"devDependencies": {
"@types/node": "^14.14.20",
"electron": "^8.0.0",
"tsd": "^0.14.0",
"xo": "^0.26.1"
},
"xo": {
Expand Down

0 comments on commit 559dbd3

Please sign in to comment.