1
+ import type { WatchOptions } from 'chokidar'
2
+
1
3
export type NodemonEventHandler =
2
4
| 'start'
3
5
| 'crash'
@@ -16,77 +18,34 @@ export type NodemonEventListener = {
16
18
on ( event : 'stdout' | 'stderr' , listener : ( e : string ) => void ) : Nodemon ;
17
19
on ( event : 'restart' , listener : ( e ?: NodemonEventRestart ) => void ) : Nodemon ;
18
20
on ( event : 'quit' , listener : ( e ?: NodemonEventQuit ) => void ) : Nodemon ;
19
- on ( event : 'exit' , listener : ( e ?: NodemonEventExit ) => void ) : Nodemon ;
20
- on (
21
- event : 'config:update' ,
22
- listener : ( e ?: NodemonEventConfig ) => void
23
- ) : Nodemon ;
21
+ on ( event : 'exit' , listener : ( e ?: number ) => void ) : Nodemon ;
22
+ on ( event : 'config:update' , listener : ( e ?: NodemonEventConfig ) => void ) : Nodemon ;
24
23
} ;
25
24
26
25
export type Nodemon = {
27
- ( options ?: NodemonSettings ) : Nodemon ;
28
- on ( event : 'start' | 'crash' , listener : ( ) => void ) : Nodemon ;
29
- on ( event : 'log' , listener : ( e : NodemonEventLog ) => void ) : Nodemon ;
30
- on ( event : 'restart' , listener : ( e ?: NodemonEventRestart ) => void ) : Nodemon ;
31
- on ( event : 'quit' , listener : ( e ?: NodemonEventQuit ) => void ) : Nodemon ;
32
- on ( event : 'exit' , listener : ( e ?: NodemonEventExit ) => void ) : Nodemon ;
33
- on (
34
- event : 'config:update' ,
35
- listener : ( e ?: NodemonEventConfig ) => void
36
- ) : Nodemon ;
37
-
38
- // this is repeated because VS Code doesn't autocomplete otherwise
39
- addEventListener ( event : 'start' | 'crash' , listener : ( ) => void ) : Nodemon ;
40
- addEventListener (
41
- event : 'log' ,
42
- listener : ( e : NodemonEventLog ) => void
43
- ) : Nodemon ;
44
- addEventListener (
45
- event : 'restart' ,
46
- listener : ( e ?: NodemonEventRestart ) => void
47
- ) : Nodemon ;
48
- addEventListener (
49
- event : 'quit' ,
50
- listener : ( e ?: NodemonEventQuit ) => void
51
- ) : Nodemon ;
52
- addEventListener (
53
- event : 'exit' ,
54
- listener : ( e ?: NodemonEventExit ) => void
55
- ) : Nodemon ;
56
- addEventListener (
57
- event : 'config:update' ,
58
- listener : ( e ?: NodemonEventConfig ) => void
59
- ) : Nodemon ;
60
-
61
- once ( event : 'start' | 'crash' , listener : ( ) => void ) : Nodemon ;
62
- once ( event : 'log' , listener : ( e : NodemonEventLog ) => void ) : Nodemon ;
63
- once ( event : 'restart' , listener : ( e ?: NodemonEventRestart ) => void ) : Nodemon ;
64
- once ( event : 'quit' , listener : ( e ?: NodemonEventQuit ) => void ) : Nodemon ;
65
- once ( event : 'exit' , listener : ( e ?: NodemonEventExit ) => void ) : Nodemon ;
66
- once (
67
- event : 'config:update' ,
68
- listener : ( e ?: NodemonEventConfig ) => void
69
- ) : Nodemon ;
70
-
71
26
removeAllListeners ( event : NodemonEventHandler ) : Nodemon ;
72
27
emit ( type : NodemonEventHandler , event ?: any ) : Nodemon ;
73
28
reset ( callback : Function ) : Nodemon ;
74
29
restart ( ) : Nodemon ;
75
30
config : NodemonSettings ;
31
+ } & NodemonEventListener & {
32
+ [ K in keyof NodemonEventListener as "addListener" ] : NodemonEventListener [ K ] ;
33
+ } & {
34
+ [ K in keyof NodemonEventListener as "once" ] : NodemonEventListener [ K ] ;
76
35
} ;
77
36
78
37
export type NodemonEventLog = {
79
38
/**
80
- detail* : what you get with nodemon --verbose.
81
- status: subprocess starting, restarting.
82
- fail: is the subprocess crashing.
83
- error: is a nodemon system error.
39
+ - detail: what you get with nodemon --verbose.
40
+ - status: subprocess starting, restarting.
41
+ - fail: is the subprocess crashing.
42
+ - error: is a nodemon system error.
84
43
*/
85
44
type : 'detail' | 'log' | 'status' | 'error' | 'fail' ;
86
45
/** the plain text message */
87
- message : String ;
46
+ message : string ;
88
47
/** contains the terminal escape codes to add colour, plus the "[nodemon]" prefix */
89
- colour : String ;
48
+ colour : string ;
90
49
} ;
91
50
92
51
export interface NodemonEventRestart {
@@ -97,15 +56,36 @@ export interface NodemonEventRestart {
97
56
}
98
57
99
58
export type NodemonEventQuit = 143 | 130 ;
100
- export type NodemonEventExit = number ;
101
59
102
- // TODO: Define the type of NodemonEventConfig
103
- export type NodemonEventConfig = any ;
60
+ export type NodemonEventConfig = {
61
+ run : boolean ;
62
+ system : {
63
+ cwd : string ;
64
+ } ;
65
+ required : boolean ;
66
+ dirs : string [ ] ;
67
+ timeout : number ;
68
+ options : NodemonConfig ;
69
+ lastStarted : number
70
+ loaded : string [ ]
71
+ load : ( settings : NodemonSettings , ready : ( config : NodemonEventConfig ) => void ) => void
72
+ reset : ( ) => void
73
+ } ;
74
+
75
+ export interface NodemonExecOptions {
76
+ script : string ;
77
+ scriptPosition ?: number ;
78
+ args ?: string [ ]
79
+ ext ?: string ; // "js,mjs" etc (should really support an array of strings, but I don't think it does right now)
80
+ exec ?: string ; // node, python, etc
81
+ execArgs ?: string [ ] ; // args passed to node, etc,
82
+ nodeArgs ?: string [ ] ; // args passed to node, etc,
83
+ }
104
84
105
85
export interface NodemonConfig {
106
- /* restartable defaults to "rs" as a string the user enters */
107
- restartable ?: false | String ;
108
- colours ?: Boolean ;
86
+ /** restartable defaults to "rs" as a string the user enters */
87
+ restartable ?: false | string ;
88
+ colours ?: boolean ;
109
89
execMap ?: { [ key : string ] : string } ;
110
90
ignoreRoot ?: string [ ] ;
111
91
watch ?: string [ ] ;
@@ -116,25 +96,28 @@ export interface NodemonConfig {
116
96
signal ?: string ;
117
97
stdout ?: boolean ;
118
98
watchOptions ?: WatchOptions ;
99
+ help ?: string
100
+ version ?: boolean
101
+ cwd ?: string
102
+ dump ?: boolean
103
+ ignore ?: string [ ]
104
+ watch ?: string [ ]
105
+ monitor ?: string [ ]
106
+ spawn ?: boolean
107
+ noUpdateNotifier ?: boolean
108
+ legacyWatch ?: boolean
109
+ pollingInterval ?: number
110
+ /** @deprecated as this is "on" by default */
111
+ js ?: boolean
112
+ quiet ?: boolean
113
+ configFile ?: string
114
+ exitCrash ?: boolean
115
+ execOptions ?: NodemonExecOptions
119
116
}
120
117
121
- export interface NodemonSettings extends NodemonConfig {
122
- script : string ;
123
- ext ?: string ; // "js,mjs" etc (should really support an array of strings, but I don't think it does right now)
118
+ export interface NodemonSettings extends NodemonConfig , NodemonExecOptions {
124
119
events ?: { [ key : string ] : string } ;
125
120
env ?: { [ key : string ] : string } ;
126
- exec ?: string ; // node, python, etc
127
- execArgs ?: string [ ] ; // args passed to node, etc,
128
- nodeArgs ?: string [ ] ; // args passed to node, etc,
129
- delay ?: number ;
130
- }
131
-
132
- export interface WatchOptions {
133
- ignorePermissionErrors : boolean ;
134
- ignored : string ;
135
- persistent : boolean ;
136
- usePolling : boolean ;
137
- interval : number ;
138
121
}
139
122
140
123
const nodemon : Nodemon = ( settings : NodemonSettings ) : Nodemon => { } ;
0 commit comments