@@ -9,7 +9,8 @@ import { generateCacheName } from './utils/generateCacheName.js';
9
9
import { path } from './utils/path.js' ;
10
10
import { promiseAllConcurrent } from './utils/promiseAllConcurrent.js' ;
11
11
12
- import type { Asset , TransformStats } from './Asset.js' ;
12
+ import type { Asset } from './Asset.js' ;
13
+ import type { CachedAsset } from './AssetCache.js' ;
13
14
import type { AssetPackConfig } from './config.js' ;
14
15
import type { AssetPipe } from './pipes/AssetPipe.js' ;
15
16
import type { AssetSettings } from './pipes/PipeSystem.js' ;
@@ -58,7 +59,8 @@ export class AssetPack
58
59
const { pipes, cache, cacheLocation } = this . config ;
59
60
60
61
AssetCache . location = cacheLocation ! ;
61
- let assetCache : AssetCache | undefined ;
62
+ let assetCacheData : Record < string , CachedAsset > | null = null ;
63
+ let assetCache : AssetCache | null = null ;
62
64
63
65
// if there is no cache, lets just go ahead and remove the output folder
64
66
// and the cached info folder
@@ -77,7 +79,9 @@ export class AssetPack
77
79
78
80
// read the cache data, this will be used to restore the asset graph
79
81
// by the AssetWatcher
80
- if ( assetCache . exists ( ) )
82
+ assetCacheData = assetCache . read ( ) ;
83
+
84
+ if ( assetCacheData )
81
85
{
82
86
Logger . info ( '[AssetPack] cache found.' ) ;
83
87
}
@@ -112,7 +116,7 @@ export class AssetPack
112
116
// so it can be restored even if the process is terminated
113
117
this . _assetWatcher = new AssetWatcher ( {
114
118
entryPath : this . _entryPath ,
115
- assetCache ,
119
+ assetCacheData ,
116
120
ignore : this . config . ignore ,
117
121
assetSettingsData : this . config . assetSettings as AssetSettings [ ] || [ ] ,
118
122
onUpdate : async ( root : Asset ) =>
@@ -175,7 +179,7 @@ export class AssetPack
175
179
* @param onComplete - optional callback that will be called after each time asset pack has finished transforming the assets
176
180
* @returns a promise that will resolve when the first time asset pack has finished transforming the assets
177
181
*/
178
- public watch ( onComplete : ( root : Asset ) => void )
182
+ public watch ( onComplete ? : ( root : Asset ) => void )
179
183
{
180
184
this . _onWatchTransformComplete = onComplete ;
181
185
@@ -194,11 +198,6 @@ export class AssetPack
194
198
return this . _assetWatcher . stop ( ) ;
195
199
}
196
200
197
- public get rootAsset ( )
198
- {
199
- return this . _assetWatcher . root ;
200
- }
201
-
202
201
private async _transform ( asset : Asset )
203
202
{
204
203
await this . _pipeSystem . start ( asset ) ;
@@ -214,25 +213,11 @@ export class AssetPack
214
213
{
215
214
if ( asset . skip ) return ;
216
215
217
- const stats = asset . stats = {
218
- date : Date . now ( ) ,
219
- duration : 0 ,
220
- success : true ,
221
- } as TransformStats ;
222
-
223
- const now = performance . now ( ) ;
224
-
225
216
await this . _pipeSystem . transform ( asset ) . catch ( ( e ) =>
226
217
{
227
- stats . success = false ;
228
- stats . error = e . message ;
229
-
230
218
// eslint-disable-next-line max-len
231
219
Logger . error ( `[AssetPack] Transform failed:\ntransform: ${ e . name } \nasset:${ asset . path } \nerror:${ e . message } ` ) ;
232
220
} ) ;
233
-
234
- stats . duration = performance . now ( ) - now ;
235
-
236
221
index ++ ;
237
222
238
223
const percent = Math . round ( ( index / assetsToTransform . length ) * 100 ) ;
0 commit comments