Skip to content

Commit 3c66c18

Browse files
BendingBendersindresorhus
authored andcommitted
Refactor TypeScript definition to CommonJS compatible export (sindresorhus#72)
1 parent dd55906 commit 3c66c18

4 files changed

Lines changed: 86 additions & 64 deletions

File tree

index.d.ts

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,76 @@
11
import {BrowserWindow} from 'electron';
22

3-
export interface Options {
3+
declare namespace electronDebug {
4+
interface Options {
5+
/**
6+
Default: [Only in development](https://github.com/sindresorhus/electron-is-dev)
7+
*/
8+
readonly enabled?: boolean;
9+
10+
/**
11+
Show DevTools on each created `BrowserWindow`.
12+
13+
@default true
14+
*/
15+
readonly showDevTools?: boolean;
16+
17+
/**
18+
The dock state to open DevTools in.
19+
20+
@default 'undocked'
21+
*/
22+
readonly devToolsMode?:
23+
| 'undocked'
24+
| 'right'
25+
| 'bottom'
26+
| 'previous'
27+
| 'detach';
28+
}
29+
}
30+
31+
declare const electronDebug: {
32+
/**
33+
Install keyboard shortcuts and optionally activate DevTools on each created `BrowserWindow`.
34+
35+
@example
36+
```
37+
import {app, BrowserWindow} from 'electron';
38+
import electronDebug = require('electron-debug');
39+
40+
electronDebug();
41+
42+
let win;
43+
(async () => {
44+
await app.whenReady();
45+
win = new BrowserWindow();
46+
});
47+
```
48+
*/
49+
(options?: electronDebug.Options): void;
50+
451
/**
5-
* Default: [Only in development](https://github.com/sindresorhus/electron-is-dev)
6-
*/
7-
readonly enabled?: boolean;
52+
Reload the specified `BrowserWindow` instance or the focused one.
53+
54+
@param window - Default: `BrowserWindow.getFocusedWindow()`
55+
*/
56+
refresh(window?: BrowserWindow): void;
857

958
/**
10-
* Show DevTools on each created `BrowserWindow`.
11-
*
12-
* @default true
13-
*/
14-
readonly showDevTools?: boolean;
59+
Toggle DevTools for the specified `BrowserWindow` instance or the focused one.
60+
61+
@param window - Default: `BrowserWindow.getFocusedWindow()`
62+
*/
63+
devTools(window?: BrowserWindow): void;
1564

1665
/**
17-
* The dock state to open DevTools in.
18-
*
19-
* @default 'undocked'
20-
*/
21-
readonly devToolsMode?: 'undocked' | 'right' | 'bottom' | 'previous' | 'detach';
22-
}
66+
Open DevTools for the specified `BrowserWindow` instance or the focused one.
67+
68+
@param window - Default: `BrowserWindow.getFocusedWindow()`
69+
*/
70+
openDevTools(window?: BrowserWindow): void;
71+
72+
// TODO: Remove this for the next major release
73+
default: typeof electronDebug;
74+
};
2375

24-
/**
25-
* Install keyboard shortcuts and optionally activate DevTools on each created `BrowserWindow`.
26-
*
27-
* @example
28-
*
29-
* import {app, BrowserWindow} from 'electron';
30-
* import electronDebug from 'electron-debug';
31-
*
32-
* electronDebug();
33-
*
34-
* let win;
35-
* (async () => {
36-
* await app.whenReady();
37-
* win = new BrowserWindow();
38-
* });
39-
*/
40-
export default function electronDebug(options?: Options): void;
41-
42-
/**
43-
* Reload the specified `BrowserWindow` instance or the focused one.
44-
*
45-
* @param window - Default: `BrowserWindow.getFocusedWindow()`
46-
*/
47-
export function refresh(window?: BrowserWindow): void;
48-
49-
/**
50-
* Toggle DevTools for the specified `BrowserWindow` instance or the focused one.
51-
*
52-
* @param window - Default: `BrowserWindow.getFocusedWindow()`
53-
*/
54-
export function devTools(window?: BrowserWindow): void;
55-
56-
/**
57-
* Open DevTools for the specified `BrowserWindow` instance or the focused one.
58-
*
59-
* @param window - Default: `BrowserWindow.getFocusedWindow()`
60-
*/
61-
export function openDevTools(window?: BrowserWindow): void;
76+
export = electronDebug;

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ module.exports = options => {
110110
});
111111
};
112112

113+
// TODO: Remove this for the next major release
113114
module.exports.default = module.exports;
114115

115116
module.exports.refresh = refresh;

index.test-d.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import {expectType} from 'tsd-check';
1+
/// <reference lib="dom"/>
2+
/// <reference types="node"/>
3+
import {expectType} from 'tsd';
24
import {BrowserWindow} from 'electron';
3-
import electronDebug, {refresh, devTools, openDevTools} from '.';
5+
import electronDebug = require('.');
6+
import {refresh, devTools, openDevTools} from '.';
47

5-
expectType<void>(electronDebug({
6-
enabled: true,
7-
showDevTools: true
8-
}));
8+
expectType<void>(
9+
electronDebug({
10+
enabled: true,
11+
showDevTools: true
12+
})
13+
);
914

1015
expectType<void>(refresh(new BrowserWindow()));
1116
expectType<void>(devTools());

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"start": "electron test.js",
14-
"test": "xo && tsd-check"
14+
"test": "xo && tsd"
1515
},
1616
"files": [
1717
"index.js",
@@ -28,14 +28,15 @@
2828
],
2929
"dependencies": {
3030
"electron-is-dev": "^0.3.0",
31-
"electron-localshortcut": "^3.0.0"
31+
"electron-localshortcut": "^3.1.0"
3232
},
3333
"devDependencies": {
34-
"devtron": "^1.1.0",
34+
"@types/node": "^11.13.0",
35+
"devtron": "^1.4.0",
3536
"electron": "^2.0.2",
3637
"electron-react-devtools": "^0.5.3",
37-
"tsd-check": "^0.3.0",
38-
"xo": "*"
38+
"tsd": "^0.7.2",
39+
"xo": "^0.24.0"
3940
},
4041
"xo": {
4142
"envs": [

0 commit comments

Comments
 (0)