@@ -44,6 +44,8 @@ export const makeCompiler = (
44
44
const tsConfigPath =
45
45
resolveSync ( cwd , typeof project === 'string' ? project : undefined ) || ''
46
46
47
+ const compiledPathsHash : Record < string , true > = { }
48
+
47
49
const tmpDir = options [ 'cache-directory' ]
48
50
? path . resolve ( options [ 'cache-directory' ] )
49
51
: fs . mkdtempSync ( path . join ( os . tmpdir ( ) , '.ts-node' ) )
@@ -170,6 +172,9 @@ export const makeCompiler = (
170
172
clearTimeout ( _errorCompileTimeout )
171
173
}
172
174
const registerTsNode = ( ) => {
175
+ Object . keys ( compiledPathsHash ) . forEach ( ( key ) => {
176
+ delete compiledPathsHash [ key ]
177
+ } )
173
178
// revert back original handler extensions
174
179
// in case of re-registering
175
180
; [ '.js' , '.jsx' , '.ts' , '.tsx' ] . forEach ( function ( ext ) {
@@ -232,9 +237,20 @@ export const makeCompiler = (
232
237
const fileName = params . compile
233
238
const code = fs . readFileSync ( fileName , 'utf-8' )
234
239
const compiledPath = params . compiledPath
240
+
241
+ // Prevent occasional duplicate compilation requests
242
+ if ( compiledPathsHash [ compiledPath ] ) {
243
+ return
244
+ }
245
+ compiledPathsHash [ compiledPath ] = true
246
+
235
247
function writeCompiled ( code : string , fileName ?: string ) {
236
- fs . writeFileSync ( compiledPath , code )
237
- fs . writeFileSync ( compiledPath + '.done' , '' )
248
+ fs . writeFile ( compiledPath , code , ( err ) => {
249
+ err && log . error ( err )
250
+ fs . writeFile ( compiledPath + '.done' , '' , ( err ) => {
251
+ err && log . error ( err )
252
+ } )
253
+ } )
238
254
}
239
255
if ( fs . existsSync ( compiledPath ) ) {
240
256
return
0 commit comments