@@ -88,36 +88,44 @@ export default class ScriptTransformer {
88
88
89
89
private _getCacheKey (
90
90
fileData : string ,
91
- filename : Config . Path ,
91
+ filename : Config . RPth ,
92
92
instrument : boolean ,
93
93
) : string {
94
94
const configString = this . _cache . configString ;
95
- const transformer = this . _getTransformer ( filename ) ;
95
+ const transformer = this . _getTransformer ( filename . path ) ;
96
96
97
97
if ( transformer && typeof transformer . getCacheKey === 'function' ) {
98
- return createHash ( 'md5' )
99
- . update (
100
- transformer . getCacheKey ( fileData , filename , configString , {
101
- config : this . _config ,
102
- instrument,
103
- rootDir : this . _config . rootDir ,
104
- } ) ,
105
- )
106
- . update ( CACHE_VERSION )
107
- . digest ( 'hex' ) ;
98
+ return (
99
+ createHash ( 'md5' )
100
+ . update (
101
+ transformer . getCacheKey ( fileData , filename . path , configString , {
102
+ config : this . _config ,
103
+ instrument,
104
+ rootDir : this . _config . rootDir ,
105
+ } ) ,
106
+ )
107
+ . update ( CACHE_VERSION )
108
+ // required for the query string support
109
+ . update ( filename . id )
110
+ . digest ( 'hex' )
111
+ ) ;
108
112
} else {
109
- return createHash ( 'md5' )
110
- . update ( fileData )
111
- . update ( configString )
112
- . update ( instrument ? 'instrument' : '' )
113
- . update ( filename )
114
- . update ( CACHE_VERSION )
115
- . digest ( 'hex' ) ;
113
+ return (
114
+ createHash ( 'md5' )
115
+ . update ( fileData )
116
+ . update ( configString )
117
+ . update ( instrument ? 'instrument' : '' )
118
+ . update ( filename . path )
119
+ // required for the query string support
120
+ . update ( filename . id )
121
+ . update ( CACHE_VERSION )
122
+ . digest ( 'hex' )
123
+ ) ;
116
124
}
117
125
}
118
126
119
127
private _getFileCachePath (
120
- filename : Config . Path ,
128
+ filename : Config . RPth ,
121
129
content : string ,
122
130
instrument : boolean ,
123
131
) : Config . Path {
@@ -131,7 +139,7 @@ export default class ScriptTransformer {
131
139
// directory with many files.
132
140
const cacheDir = path . join ( baseCacheDir , cacheKey [ 0 ] + cacheKey [ 1 ] ) ;
133
141
const cacheFilenamePrefix = path
134
- . basename ( filename , path . extname ( filename ) )
142
+ . basename ( filename . path , path . extname ( filename . path ) )
135
143
. replace ( / \W / g, '' ) ;
136
144
const cachePath = slash (
137
145
path . join ( cacheDir , cacheFilenamePrefix + '_' + cacheKey ) ,
@@ -251,13 +259,13 @@ export default class ScriptTransformer {
251
259
}
252
260
253
261
transformSource (
254
- filepath : Config . Path ,
262
+ filepath : Config . RPth ,
255
263
content : string ,
256
264
instrument : boolean ,
257
265
) : TransformResult {
258
- const filename = this . _getRealPath ( filepath ) ;
266
+ const filename = this . _getRealPath ( filepath . path ) ;
259
267
const transform = this . _getTransformer ( filename ) ;
260
- const cacheFilePath = this . _getFileCachePath ( filename , content , instrument ) ;
268
+ const cacheFilePath = this . _getFileCachePath ( filepath , content , instrument ) ;
261
269
let sourceMapPath : Config . Path | null = cacheFilePath + '.map' ;
262
270
// Ignore cache if `config.cache` is set (--no-cache)
263
271
let code = this . _config . cache ? readCodeCacheFile ( cacheFilePath ) : null ;
@@ -373,15 +381,15 @@ export default class ScriptTransformer {
373
381
}
374
382
375
383
private _transformAndBuildScript (
376
- filename : Config . Path ,
384
+ filename : Config . RPth ,
377
385
options : Options | null ,
378
386
instrument : boolean ,
379
387
fileSource ?: string ,
380
388
) : TransformResult {
381
389
const isInternalModule = ! ! ( options && options . isInternalModule ) ;
382
390
const isCoreModule = ! ! ( options && options . isCoreModule ) ;
383
391
const content = stripShebang (
384
- fileSource || fs . readFileSync ( filename , 'utf8' ) ,
392
+ fileSource || fs . readFileSync ( filename . path , 'utf8' ) ,
385
393
) ;
386
394
387
395
let code = content ;
@@ -391,7 +399,7 @@ export default class ScriptTransformer {
391
399
const willTransform =
392
400
! isInternalModule &&
393
401
! isCoreModule &&
394
- ( this . shouldTransform ( filename ) || instrument ) ;
402
+ ( this . shouldTransform ( filename . path ) || instrument ) ;
395
403
396
404
try {
397
405
if ( willTransform ) {
@@ -418,7 +426,7 @@ export default class ScriptTransformer {
418
426
}
419
427
420
428
transform (
421
- filename : Config . Path ,
429
+ filename : Config . RPth ,
422
430
options : Options ,
423
431
fileSource ?: string ,
424
432
) : TransformResult {
@@ -428,7 +436,7 @@ export default class ScriptTransformer {
428
436
if ( ! options . isCoreModule ) {
429
437
instrument =
430
438
options . coverageProvider === 'babel' &&
431
- shouldInstrument ( filename , options , this . _config ) ;
439
+ shouldInstrument ( filename . path , options , this . _config ) ;
432
440
scriptCacheKey = getScriptCacheKey ( filename , instrument ) ;
433
441
const result = this . _cache . transformedFiles . get ( scriptCacheKey ) ;
434
442
if ( result ) {
@@ -462,6 +470,7 @@ export default class ScriptTransformer {
462
470
463
471
if ( willTransform ) {
464
472
const { code : transformedJsonSource } = this . transformSource (
473
+ // @ts -ignore
465
474
filename ,
466
475
fileSource ,
467
476
false ,
@@ -493,6 +502,7 @@ export default class ScriptTransformer {
493
502
( code , filename ) => {
494
503
try {
495
504
transforming = true ;
505
+ // @ts -ignore
496
506
return this . transformSource ( filename , code , false ) . code || code ;
497
507
} finally {
498
508
transforming = false ;
@@ -689,8 +699,8 @@ const readCacheFile = (cachePath: Config.Path): string | null => {
689
699
return fileData ;
690
700
} ;
691
701
692
- const getScriptCacheKey = ( filename : Config . Path , instrument : boolean ) => {
693
- const mtime = fs . statSync ( filename ) . mtime ;
702
+ const getScriptCacheKey = ( filename : Config . RPth , instrument : boolean ) => {
703
+ const mtime = fs . statSync ( filename . path ) . mtime ;
694
704
return filename + '_' + mtime . getTime ( ) + ( instrument ? '_instrumented' : '' ) ;
695
705
} ;
696
706
0 commit comments