1
1
#! /usr/bin/env node
2
2
3
- /* c8 ignore start */
4
-
5
3
import process from 'node:process' ;
6
4
import { escapeRegExp } from '../modules/list-files.js' ;
7
5
import {
@@ -21,150 +19,148 @@ import { onSigint, poku } from '../modules/poku.js';
21
19
import { kill } from '../modules/processes.js' ;
22
20
import type { Configs } from '../@types/poku.js' ;
23
21
24
- ( async ( ) => {
25
- const dirs = ( ( ) => {
26
- const includeArg = getArg ( 'include' ) ;
27
- if ( includeArg !== undefined ) return includeArg . split ( ',' ) ;
28
-
29
- const lastParam = getLastParam ( ) ;
30
- if ( lastParam !== undefined ) return lastParam . split ( ',' ) ;
31
-
32
- return [ '.' ] ;
33
- } ) ( ) ;
34
-
35
- const platform = getArg ( 'platform' ) ;
36
- const filter = getArg ( 'filter' ) ;
37
- const exclude = getArg ( 'exclude' ) ;
38
- const killPort = getArg ( 'kill-port' ) ;
39
- const killRange = getArg ( 'kill-range' ) ;
40
- const killPID = getArg ( 'kill-pid' ) ;
41
- const denoAllow = argToArray ( 'deno-allow' ) ;
42
- const denoDeny = argToArray ( 'deno-deny' ) ;
43
- const denoCJS =
44
- getArg ( 'deno-cjs' )
45
- ?. split ( ',' )
46
- . map ( ( a ) => a . trim ( ) )
47
- . filter ( ( a ) => a ) || hasArg ( 'deno-cjs' ) ;
48
-
49
- const parallel = hasArg ( 'parallel' ) ;
50
- const quiet = hasArg ( 'quiet' ) ;
51
- const debug = hasArg ( 'debug' ) ;
52
- const failFast = hasArg ( 'fail-fast' ) ;
53
- const watchMode = hasArg ( 'watch' ) ;
54
-
55
- const concurrency = parallel
56
- ? Number ( getArg ( 'concurrency' ) ) || undefined
57
- : undefined ;
58
-
59
- if ( killPort ) {
60
- const ports = killPort . split ( ',' ) . map ( Number ) ;
61
-
62
- await kill . port ( ports ) ;
63
- }
64
-
65
- if ( killRange ) {
66
- const ranges = killRange . split ( ',' ) ;
67
-
68
- for ( const range of ranges ) {
69
- const ports = range . split ( '-' ) . map ( Number ) ;
70
-
71
- const startsAt = ports [ 0 ] ;
72
- const endsAt = ports [ 1 ] ;
73
-
74
- await kill . range ( startsAt , endsAt ) ;
75
- }
76
- }
22
+ const dirs = ( ( ) => {
23
+ const includeArg = getArg ( 'include' ) ;
24
+ if ( includeArg !== undefined ) return includeArg . split ( ',' ) ;
77
25
78
- if ( killPID ) {
79
- const PIDs = killPID . split ( ',' ) . map ( Number ) ;
26
+ const lastParam = getLastParam ( ) ;
27
+ if ( lastParam !== undefined ) return lastParam . split ( ',' ) ;
80
28
81
- await kill . pid ( PIDs ) ;
82
- }
29
+ return [ '.' ] ;
30
+ } ) ( ) ;
83
31
84
- const options : Configs = {
85
- platform : platformIsValid ( platform ) ? platform : undefined ,
86
- filter : filter ? new RegExp ( escapeRegExp ( filter ) ) : undefined ,
87
- exclude : exclude ? new RegExp ( escapeRegExp ( exclude ) ) : undefined ,
88
- parallel,
89
- quiet,
90
- debug,
91
- failFast,
92
- concurrency,
93
- noExit : watchMode ,
94
- deno : {
95
- allow : denoAllow ,
96
- deny : denoDeny ,
97
- cjs : denoCJS ,
98
- } ,
99
- } ;
100
-
101
- if ( debug ) {
102
- hr ( ) ;
103
- write ( `${ format . bg ( 104 , 'Debug Enabled' ) } \n` ) ;
104
- write ( `${ format . italic ( format . info ( '…' ) ) } ${ format . bold ( 'Paths' ) } ` ) ;
105
- console . table ( dirs ) ;
106
- write ( '\n' ) ;
107
- write ( `${ format . italic ( format . info ( '…' ) ) } ${ format . bold ( 'Options' ) } ` ) ;
108
- console . dir ( options , { depth : null , colors : true } ) ;
32
+ const platform = getArg ( 'platform' ) ;
33
+ const filter = getArg ( 'filter' ) ;
34
+ const exclude = getArg ( 'exclude' ) ;
35
+ const killPort = getArg ( 'kill-port' ) ;
36
+ const killRange = getArg ( 'kill-range' ) ;
37
+ const killPID = getArg ( 'kill-pid' ) ;
38
+ const denoAllow = argToArray ( 'deno-allow' ) ;
39
+ const denoDeny = argToArray ( 'deno-deny' ) ;
40
+ const denoCJS =
41
+ getArg ( 'deno-cjs' )
42
+ ?. split ( ',' )
43
+ . map ( ( a ) => a . trim ( ) )
44
+ . filter ( ( a ) => a ) || hasArg ( 'deno-cjs' ) ;
45
+
46
+ const parallel = hasArg ( 'parallel' ) ;
47
+ const quiet = hasArg ( 'quiet' ) ;
48
+ const debug = hasArg ( 'debug' ) ;
49
+ const failFast = hasArg ( 'fail-fast' ) ;
50
+ const watchMode = hasArg ( 'watch' ) ;
51
+
52
+ const concurrency = parallel
53
+ ? Number ( getArg ( 'concurrency' ) ) || undefined
54
+ : undefined ;
55
+
56
+ const tasks : Promise < unknown > [] = [];
57
+
58
+ if (killPort) {
59
+ const ports = killPort . split ( ',' ) . map ( Number ) ;
60
+ tasks . push ( kill . port ( ports ) ) ;
61
+ }
62
+
63
+ if (killRange) {
64
+ const ranges = killRange . split ( ',' ) ;
65
+
66
+ for ( const range of ranges ) {
67
+ const ports = range . split ( '-' ) . map ( Number ) ;
68
+ const startsAt = ports [ 0 ] ;
69
+ const endsAt = ports [ 1 ] ;
70
+ tasks . push ( kill . range ( startsAt , endsAt ) ) ;
109
71
}
72
+ }
73
+
74
+ if (killPID) {
75
+ const PIDs = killPID . split ( ',' ) . map ( Number ) ;
76
+ tasks . push ( kill . pid ( PIDs ) ) ;
77
+ }
78
+
79
+ const options: Configs = {
80
+ platform : platformIsValid ( platform ) ? platform : undefined ,
81
+ filter : filter ? new RegExp ( escapeRegExp ( filter ) ) : undefined ,
82
+ exclude : exclude ? new RegExp ( escapeRegExp ( exclude ) ) : undefined ,
83
+ parallel ,
84
+ quiet ,
85
+ debug ,
86
+ failFast ,
87
+ concurrency ,
88
+ noExit : watchMode ,
89
+ deno : {
90
+ allow : denoAllow ,
91
+ deny : denoDeny ,
92
+ cjs : denoCJS ,
93
+ } ,
94
+ } ;
95
+
96
+ if (debug) {
97
+ hr ( ) ;
98
+ write ( `${ format . bg ( 104 , 'Debug Enabled' ) } \n` ) ;
99
+ write ( `${ format . italic ( format . info ( '…' ) ) } ${ format . bold ( 'Paths' ) } ` ) ;
100
+ console . table ( dirs ) ;
101
+ write ( '\n' ) ;
102
+ write ( `${ format . italic ( format . info ( '…' ) ) } ${ format . bold ( 'Options' ) } ` ) ;
103
+ console . dir ( options , { depth : null , colors : true } ) ;
104
+ }
105
+
106
+ Promise.all(tasks).then(() => {
107
+ poku ( dirs , options ) . then ( ( ) => {
108
+ if ( watchMode ) {
109
+ const executing = new Set < string > ( ) ;
110
+ const interval = Number ( getArg ( 'watch-interval' ) ) || 1500 ;
111
+
112
+ const resultsClear = ( ) => {
113
+ fileResults . success . clear ( ) ;
114
+ fileResults . fail . clear ( ) ;
115
+ } ;
116
+
117
+ process . removeListener ( 'SIGINT' , onSigint ) ;
118
+ resultsClear ( ) ;
119
+
120
+ mapTests ( '.' , dirs , options . filter , options . exclude ) . then (
121
+ ( mappedTests ) => {
122
+ Array . from ( mappedTests . keys ( ) ) . forEach ( ( mappedTest ) => {
123
+ watch ( mappedTest , ( file , event ) => {
124
+ if ( event === 'change' ) {
125
+ const filePath = normalizePath ( file ) ;
126
+ if ( executing . has ( filePath ) ) return ;
127
+
128
+ executing . add ( filePath ) ;
129
+ resultsClear ( ) ;
130
+
131
+ const tests = mappedTests . get ( filePath ) ;
132
+ if ( ! tests ) return ;
133
+
134
+ poku ( Array . from ( tests ) , options ) . then ( ( ) => {
135
+ setTimeout ( ( ) => {
136
+ executing . delete ( filePath ) ;
137
+ } , interval ) ;
138
+ } ) ;
139
+ }
140
+ } ) ;
141
+ } ) ;
142
+ }
143
+ ) ;
110
144
111
- await poku ( dirs , options ) ;
112
-
113
- if ( watchMode ) {
114
- const executing = new Set < string > ( ) ;
115
- const interval = Number ( getArg ( 'watch-interval' ) ) || 1500 ;
116
-
117
- const resultsClear = ( ) => {
118
- fileResults . success . clear ( ) ;
119
- fileResults . fail . clear ( ) ;
120
- } ;
121
-
122
- process . removeListener ( 'SIGINT' , onSigint ) ;
123
- resultsClear ( ) ;
124
-
125
- mapTests ( '.' , dirs , options . filter , options . exclude ) . then ( ( mappedTests ) => {
126
- Array . from ( mappedTests . keys ( ) ) . forEach ( ( mappedTest ) => {
127
- watch ( mappedTest , ( file , event ) => {
145
+ dirs . forEach ( ( dir ) => {
146
+ watch ( dir , ( file , event ) => {
128
147
if ( event === 'change' ) {
129
- const filePath = normalizePath ( file ) ;
130
- if ( executing . has ( filePath ) ) return ;
148
+ if ( executing . has ( file ) ) return ;
131
149
132
- executing . add ( filePath ) ;
150
+ executing . add ( file ) ;
133
151
resultsClear ( ) ;
134
152
135
- const tests = mappedTests . get ( filePath ) ;
136
- if ( ! tests ) return ;
137
-
138
- poku ( Array . from ( tests ) , options ) . then ( ( ) => {
153
+ poku ( file , options ) . then ( ( ) => {
139
154
setTimeout ( ( ) => {
140
- executing . delete ( filePath ) ;
155
+ executing . delete ( file ) ;
141
156
} , interval ) ;
142
157
} ) ;
143
158
}
144
159
} ) ;
145
160
} ) ;
146
- } ) ;
147
-
148
- dirs . forEach ( ( dir ) => {
149
- watch ( dir , ( file , event ) => {
150
- if ( event === 'change' ) {
151
- if ( executing . has ( file ) ) return ;
152
-
153
- executing . add ( file ) ;
154
- resultsClear ( ) ;
155
-
156
- poku ( file , options ) . then ( ( ) => {
157
- setTimeout ( ( ) => {
158
- executing . delete ( file ) ;
159
- } , interval ) ;
160
- } ) ;
161
- }
162
- } ) ;
163
- } ) ;
164
161
165
- hr ( ) ;
166
- write ( `${ format . bold ( 'Watching:' ) } ${ format . underline ( dirs . join ( ', ' ) ) } ` ) ;
167
- }
168
- } ) ( ) ;
169
-
170
- /* c8 ignore stop */
162
+ hr ( ) ;
163
+ write ( `${ format . bold ( 'Watching:' ) } ${ format . underline ( dirs . join ( ', ' ) ) } ` ) ;
164
+ }
165
+ } ) ;
166
+ } );
0 commit comments