@@ -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 ) ,
@@ -252,13 +260,13 @@ export default class ScriptTransformer {
252
260
}
253
261
254
262
transformSource (
255
- filepath : Config . Path ,
263
+ filepath : Config . RPth ,
256
264
content : string ,
257
265
instrument : boolean ,
258
266
) : TransformResult {
259
- const filename = this . _getRealPath ( filepath ) ;
267
+ const filename = this . _getRealPath ( filepath . path ) ;
260
268
const transform = this . _getTransformer ( filename ) ;
261
- const cacheFilePath = this . _getFileCachePath ( filename , content , instrument ) ;
269
+ const cacheFilePath = this . _getFileCachePath ( filepath , content , instrument ) ;
262
270
let sourceMapPath : Config . Path | null = cacheFilePath + '.map' ;
263
271
// Ignore cache if `config.cache` is set (--no-cache)
264
272
let code = this . _config . cache ? readCodeCacheFile ( cacheFilePath ) : null ;
@@ -374,15 +382,15 @@ export default class ScriptTransformer {
374
382
}
375
383
376
384
private _transformAndBuildScript (
377
- filename : Config . Path ,
385
+ filename : Config . RPth ,
378
386
options : Options | null ,
379
387
instrument : boolean ,
380
388
fileSource ?: string ,
381
389
) : TransformResult {
382
390
const isInternalModule = ! ! ( options && options . isInternalModule ) ;
383
391
const isCoreModule = ! ! ( options && options . isCoreModule ) ;
384
392
const content = stripShebang (
385
- fileSource || fs . readFileSync ( filename , 'utf8' ) ,
393
+ fileSource || fs . readFileSync ( filename . path , 'utf8' ) ,
386
394
) ;
387
395
388
396
let code = content ;
@@ -392,7 +400,7 @@ export default class ScriptTransformer {
392
400
const willTransform =
393
401
! isInternalModule &&
394
402
! isCoreModule &&
395
- ( this . shouldTransform ( filename ) || instrument ) ;
403
+ ( this . shouldTransform ( filename . path ) || instrument ) ;
396
404
397
405
try {
398
406
if ( willTransform ) {
@@ -419,7 +427,7 @@ export default class ScriptTransformer {
419
427
}
420
428
421
429
transform (
422
- filename : Config . Path ,
430
+ filename : Config . RPth ,
423
431
options : Options ,
424
432
fileSource ?: string ,
425
433
) : TransformResult {
@@ -429,7 +437,7 @@ export default class ScriptTransformer {
429
437
if ( ! options . isCoreModule ) {
430
438
instrument =
431
439
options . coverageProvider === 'babel' &&
432
- shouldInstrument ( filename , options , this . _config ) ;
440
+ shouldInstrument ( filename . path , options , this . _config ) ;
433
441
scriptCacheKey = getScriptCacheKey ( filename , instrument ) ;
434
442
const result = this . _cache . transformedFiles . get ( scriptCacheKey ) ;
435
443
if ( result ) {
@@ -463,6 +471,7 @@ export default class ScriptTransformer {
463
471
464
472
if ( willTransform ) {
465
473
const { code : transformedJsonSource } = this . transformSource (
474
+ // @ts -ignore
466
475
filename ,
467
476
fileSource ,
468
477
false ,
@@ -494,6 +503,7 @@ export default class ScriptTransformer {
494
503
( code , filename ) => {
495
504
try {
496
505
transforming = true ;
506
+ // @ts -ignore
497
507
return this . transformSource ( filename , code , false ) . code || code ;
498
508
} finally {
499
509
transforming = false ;
@@ -690,8 +700,8 @@ const readCacheFile = (cachePath: Config.Path): string | null => {
690
700
return fileData ;
691
701
} ;
692
702
693
- const getScriptCacheKey = ( filename : Config . Path , instrument : boolean ) => {
694
- const mtime = fs . statSync ( filename ) . mtime ;
703
+ const getScriptCacheKey = ( filename : Config . RPth , instrument : boolean ) => {
704
+ const mtime = fs . statSync ( filename . path ) . mtime ;
695
705
return filename + '_' + mtime . getTime ( ) + ( instrument ? '_instrumented' : '' ) ;
696
706
} ;
697
707
0 commit comments