@@ -75,7 +75,7 @@ const changeInterpretations = Object.freeze(Object.assign(Object.create(null), {
7575} ) ) ;
7676
7777export default function typescriptProvider ( { negotiateProtocol} ) {
78- const protocol = negotiateProtocol ( [ 'ava-6' , 'ava-3.2' ] , { version : pkg . version } ) ;
78+ const protocol = negotiateProtocol ( [ 'ava-6' ] , { version : pkg . version } ) ;
7979 if ( protocol === null ) {
8080 return ;
8181 }
@@ -100,141 +100,110 @@ export default function typescriptProvider({negotiateProtocol}) {
100100 ] ) ;
101101 const testFileExtension = new RegExp ( `\\.(${ extensions . map ( ext => escapeStringRegexp ( ext ) ) . join ( '|' ) } )$` ) ;
102102
103- const watchMode = protocol . identifier === 'ava-3.2'
104- ? {
105- ignoreChange ( filePath ) {
106- if ( ! testFileExtension . test ( filePath ) ) {
107- return false ;
108- }
109-
110- return rewritePaths . some ( ( [ from ] ) => filePath . startsWith ( from ) ) ;
111- } ,
112-
113- resolveTestFile ( testfile ) { // Used under AVA 3.2 protocol by legacy watcher implementation.
114- if ( ! testFileExtension . test ( testfile ) ) {
115- return testfile ;
116- }
117-
118- const rewrite = rewritePaths . find ( ( [ from ] ) => testfile . startsWith ( from ) ) ;
119- if ( rewrite === undefined ) {
120- return testfile ;
121- }
122-
123- const [ from , to ] = rewrite ;
124- let newExtension = '.js' ;
125- if ( testfile . endsWith ( '.cts' ) ) {
126- newExtension = '.cjs' ;
127- } else if ( testfile . endsWith ( '.mts' ) ) {
128- newExtension = '.mjs' ;
129- }
130-
131- return `${ to } ${ testfile . slice ( from . length ) } ` . replace ( testFileExtension , newExtension ) ;
132- } ,
133- }
134- : {
135- changeInterpretations,
136- interpretChange ( filePath ) {
137- if ( config . compile === false ) {
138- for ( const [ from ] of rewritePaths ) {
139- if ( testFileExtension . test ( filePath ) && filePath . startsWith ( from ) ) {
140- return changeInterpretations . waitForOutOfBandCompilation ;
141- }
103+ const watchMode = {
104+ changeInterpretations,
105+ interpretChange ( filePath ) {
106+ if ( config . compile === false ) {
107+ for ( const [ from ] of rewritePaths ) {
108+ if ( testFileExtension . test ( filePath ) && filePath . startsWith ( from ) ) {
109+ return changeInterpretations . waitForOutOfBandCompilation ;
142110 }
143111 }
112+ }
144113
145- if ( config . compile === 'tsc' ) {
146- for ( const [ , to ] of rewritePaths ) {
147- if ( filePath . startsWith ( to ) ) {
148- return changeInterpretations . ignoreCompiled ;
149- }
114+ if ( config . compile === 'tsc' ) {
115+ for ( const [ , to ] of rewritePaths ) {
116+ if ( filePath . startsWith ( to ) ) {
117+ return changeInterpretations . ignoreCompiled ;
150118 }
151119 }
120+ }
152121
153- return changeInterpretations . unspecified ;
154- } ,
155-
156- resolvePossibleOutOfBandCompilationSources ( filePath ) {
157- if ( config . compile !== false ) {
158- return null ;
159- }
122+ return changeInterpretations . unspecified ;
123+ } ,
160124
161- // Only recognize .cjs, .mjs and .js files.
162- if ( ! / \. ( c | m ) ? j s $ / . test ( filePath ) ) {
163- return null ;
164- }
125+ resolvePossibleOutOfBandCompilationSources ( filePath ) {
126+ if ( config . compile !== false ) {
127+ return null ;
128+ }
165129
166- for ( const [ from , to ] of rewritePaths ) {
167- if ( ! filePath . startsWith ( to ) ) {
168- continue ;
169- }
130+ // Only recognize .cjs, .mjs and .js files.
131+ if ( ! / \. ( c | m ) ? j s $ / . test ( filePath ) ) {
132+ return null ;
133+ }
170134
171- const rewritten = `${ from } ${ filePath . slice ( to . length ) } ` ;
172- const possibleExtensions = [ ] ;
135+ for ( const [ from , to ] of rewritePaths ) {
136+ if ( ! filePath . startsWith ( to ) ) {
137+ continue ;
138+ }
173139
174- if ( filePath . endsWith ( '.cjs' ) ) {
175- if ( extensions . includes ( 'cjs' ) ) {
176- possibleExtensions . push ( { replace : / \. c j s $ / , extension : 'cjs' } ) ;
177- }
140+ const rewritten = `${ from } ${ filePath . slice ( to . length ) } ` ;
141+ const possibleExtensions = [ ] ;
178142
179- if ( extensions . includes ( 'cts' ) ) {
180- possibleExtensions . push ( { replace : / \. c j s $ / , extension : 'cts' } ) ;
181- }
143+ if ( filePath . endsWith ( '.cjs' ) ) {
144+ if ( extensions . includes ( 'cjs' ) ) {
145+ possibleExtensions . push ( { replace : / \. c j s $ / , extension : 'cjs' } ) ;
146+ }
182147
183- if ( possibleExtensions . length === 0 ) {
184- return null ;
185- }
148+ if ( extensions . includes ( 'cts' ) ) {
149+ possibleExtensions . push ( { replace : / \. c j s $ / , extension : 'cts' } ) ;
186150 }
187151
188- if ( filePath . endsWith ( '.mjs' ) ) {
189- if ( extensions . includes ( 'mjs' ) ) {
190- possibleExtensions . push ( { replace : / \. m j s $ / , extension : 'mjs' } ) ;
191- }
152+ if ( possibleExtensions . length === 0 ) {
153+ return null ;
154+ }
155+ }
192156
193- if ( extensions . includes ( 'mts' ) ) {
194- possibleExtensions . push ( { replace : / \. m j s $ / , extension : 'mts' } ) ;
195- }
157+ if ( filePath . endsWith ( '.mjs' ) ) {
158+ if ( extensions . includes ( 'mjs' ) ) {
159+ possibleExtensions . push ( { replace : / \. m j s $ / , extension : 'mjs' } ) ;
160+ }
196161
197- if ( possibleExtensions . length === 0 ) {
198- return null ;
199- }
162+ if ( extensions . includes ( 'mts' ) ) {
163+ possibleExtensions . push ( { replace : / \. m j s $ / , extension : 'mts' } ) ;
200164 }
201165
202- if ( filePath . endsWith ( '.js' ) ) {
203- if ( extensions . includes ( 'js' ) ) {
204- possibleExtensions . push ( { replace : / \. j s $ / , extension : 'js' } ) ;
205- }
166+ if ( possibleExtensions . length === 0 ) {
167+ return null ;
168+ }
169+ }
206170
207- if ( extensions . includes ( 'ts' ) ) {
208- possibleExtensions . push ( { replace : / \. j s $ / , extension : 'ts' } ) ;
209- }
171+ if ( filePath . endsWith ( '.js' ) ) {
172+ if ( extensions . includes ( 'js' ) ) {
173+ possibleExtensions . push ( { replace : / \. j s $ / , extension : 'js' } ) ;
174+ }
210175
211- if ( extensions . includes ( 'tsx ' ) ) {
212- possibleExtensions . push ( { replace : / \. j s $ / , extension : 'tsx ' } ) ;
213- }
176+ if ( extensions . includes ( 'ts ' ) ) {
177+ possibleExtensions . push ( { replace : / \. j s $ / , extension : 'ts ' } ) ;
178+ }
214179
215- if ( possibleExtensions . length === 0 ) {
216- return null ;
217- }
180+ if ( extensions . includes ( 'tsx' ) ) {
181+ possibleExtensions . push ( { replace : / \. j s $ / , extension : 'tsx' } ) ;
218182 }
219183
220- const possibleDeletedFiles = [ ] ;
221- for ( const { replace, extension} of possibleExtensions ) {
222- const possibleFilePath = rewritten . replace ( replace , `.${ extension } ` ) ;
184+ if ( possibleExtensions . length === 0 ) {
185+ return null ;
186+ }
187+ }
223188
224- // Pick the first file path that exists.
225- if ( fs . existsSync ( possibleFilePath ) ) {
226- return [ possibleFilePath ] ;
227- }
189+ const possibleDeletedFiles = [ ] ;
190+ for ( const { replace, extension} of possibleExtensions ) {
191+ const possibleFilePath = rewritten . replace ( replace , `.${ extension } ` ) ;
228192
229- possibleDeletedFiles . push ( possibleFilePath ) ;
193+ // Pick the first file path that exists.
194+ if ( fs . existsSync ( possibleFilePath ) ) {
195+ return [ possibleFilePath ] ;
230196 }
231197
232- return possibleDeletedFiles ;
198+ possibleDeletedFiles . push ( possibleFilePath ) ;
233199 }
234200
235- return null ;
236- } ,
237- } ;
201+ return possibleDeletedFiles ;
202+ }
203+
204+ return null ;
205+ } ,
206+ } ;
238207
239208 return {
240209 ...watchMode ,
0 commit comments