@@ -9,6 +9,7 @@ import JestWorker from 'jest-worker';
9
9
import * as os from 'os' ;
10
10
import * as path from 'path' ;
11
11
import * as v8 from 'v8' ;
12
+ import { I18nOptions } from '../utils/i18n-options' ;
12
13
import { InlineOptions , ProcessBundleOptions , ProcessBundleResult } from '../utils/process-bundle' ;
13
14
import { BundleActionCache } from './action-cache' ;
14
15
@@ -36,14 +37,16 @@ workerFile =
36
37
export class BundleActionExecutor {
37
38
private largeWorker ?: JestWorker ;
38
39
private smallWorker ?: JestWorker ;
39
- private cache : BundleActionCache ;
40
+ private cache ? : BundleActionCache ;
40
41
41
42
constructor (
42
- private workerOptions : unknown ,
43
+ private workerOptions : { cachePath ?: string ; i18n : I18nOptions } ,
43
44
integrityAlgorithm ?: string ,
44
45
private readonly sizeThreshold = 32 * 1024 ,
45
46
) {
46
- this . cache = new BundleActionCache ( integrityAlgorithm ) ;
47
+ if ( workerOptions . cachePath ) {
48
+ this . cache = new BundleActionCache ( workerOptions . cachePath , integrityAlgorithm ) ;
49
+ }
47
50
}
48
51
49
52
private static executeMethod < O > ( worker : JestWorker , method : string , input : unknown ) : Promise < O > {
@@ -87,16 +90,18 @@ export class BundleActionExecutor {
87
90
}
88
91
89
92
async process ( action : ProcessBundleOptions ) : Promise < ProcessBundleResult > {
90
- const cacheKeys = this . cache . generateCacheKeys ( action ) ;
91
- action . cacheKeys = cacheKeys ;
92
-
93
- // Try to get cached data, if it fails fallback to processing
94
- try {
95
- const cachedResult = await this . cache . getCachedBundleResult ( action ) ;
96
- if ( cachedResult ) {
97
- return cachedResult ;
98
- }
99
- } catch { }
93
+ if ( this . cache ) {
94
+ const cacheKeys = this . cache . generateCacheKeys ( action ) ;
95
+ action . cacheKeys = cacheKeys ;
96
+
97
+ // Try to get cached data, if it fails fallback to processing
98
+ try {
99
+ const cachedResult = await this . cache . getCachedBundleResult ( action ) ;
100
+ if ( cachedResult ) {
101
+ return cachedResult ;
102
+ }
103
+ } catch { }
104
+ }
100
105
101
106
return this . executeAction < ProcessBundleResult > ( 'process' , action ) ;
102
107
}
@@ -107,7 +112,7 @@ export class BundleActionExecutor {
107
112
108
113
async inline (
109
114
action : InlineOptions ,
110
- ) : Promise < { file : string ; diagnostics : { type : string ; message : string } [ ] ; count : number ; } > {
115
+ ) : Promise < { file : string ; diagnostics : { type : string ; message : string } [ ] ; count : number } > {
111
116
return this . executeAction ( 'inlineLocales' , action ) ;
112
117
}
113
118
0 commit comments