@@ -75,7 +75,7 @@ const changeInterpretations = Object.freeze(Object.assign(Object.create(null), {
75
75
} ) ) ;
76
76
77
77
export 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 } ) ;
79
79
if ( protocol === null ) {
80
80
return ;
81
81
}
@@ -100,141 +100,110 @@ export default function typescriptProvider({negotiateProtocol}) {
100
100
] ) ;
101
101
const testFileExtension = new RegExp ( `\\.(${ extensions . map ( ext => escapeStringRegexp ( ext ) ) . join ( '|' ) } )$` ) ;
102
102
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 ;
142
110
}
143
111
}
112
+ }
144
113
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 ;
150
118
}
151
119
}
120
+ }
152
121
153
- return changeInterpretations . unspecified ;
154
- } ,
155
-
156
- resolvePossibleOutOfBandCompilationSources ( filePath ) {
157
- if ( config . compile !== false ) {
158
- return null ;
159
- }
122
+ return changeInterpretations . unspecified ;
123
+ } ,
160
124
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
+ }
165
129
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
+ }
170
134
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
+ }
173
139
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 = [ ] ;
178
142
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
+ }
182
147
183
- if ( possibleExtensions . length === 0 ) {
184
- return null ;
185
- }
148
+ if ( extensions . includes ( 'cts' ) ) {
149
+ possibleExtensions . push ( { replace : / \. c j s $ / , extension : 'cts' } ) ;
186
150
}
187
151
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
+ }
192
156
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
+ }
196
161
197
- if ( possibleExtensions . length === 0 ) {
198
- return null ;
199
- }
162
+ if ( extensions . includes ( 'mts' ) ) {
163
+ possibleExtensions . push ( { replace : / \. m j s $ / , extension : 'mts' } ) ;
200
164
}
201
165
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
+ }
206
170
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
+ }
210
175
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
+ }
214
179
215
- if ( possibleExtensions . length === 0 ) {
216
- return null ;
217
- }
180
+ if ( extensions . includes ( 'tsx' ) ) {
181
+ possibleExtensions . push ( { replace : / \. j s $ / , extension : 'tsx' } ) ;
218
182
}
219
183
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
+ }
223
188
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 } ` ) ;
228
192
229
- possibleDeletedFiles . push ( possibleFilePath ) ;
193
+ // Pick the first file path that exists.
194
+ if ( fs . existsSync ( possibleFilePath ) ) {
195
+ return [ possibleFilePath ] ;
230
196
}
231
197
232
- return possibleDeletedFiles ;
198
+ possibleDeletedFiles . push ( possibleFilePath ) ;
233
199
}
234
200
235
- return null ;
236
- } ,
237
- } ;
201
+ return possibleDeletedFiles ;
202
+ }
203
+
204
+ return null ;
205
+ } ,
206
+ } ;
238
207
239
208
return {
240
209
...watchMode ,
0 commit comments