@@ -61,6 +61,15 @@ function cleanAll() {
6161 ] ) ;
6262}
6363
64+ function cleanUnwantedFilesInDist ( ) {
65+ return del ( [
66+ 'dist/nls/*/expertTranslations.json' ,
67+ 'dist/nls/*/lastTranslated.json' ,
68+ 'dist/nls/*/lastTranslatedLocale.json' ,
69+ 'dist/nls/*/*.js.map'
70+ ] ) ;
71+ }
72+
6473/**
6574 * TODO: Release scripts to merge and min src js/css/html resources into dist.
6675 * Links that might help:
@@ -380,11 +389,25 @@ const ALLOWED_EXTENSIONS_TO_CACHE = ["js", "html", "htm", "xml", "xhtml", "mjs",
380389const DISALLOWED_EXTENSIONS_TO_CACHE = [ "map" , "nuspec" , "partial" , "pre" , "post" ,
381390 "webmanifest" , "rb" , "ts" ] ;
382391
392+ const EXCLUDE_PATTERNS_FROM_CACHE = [
393+ / s r c \/ n l s \/ .* e x p e r t T r a n s l a t i o n s \. j s o n $ / ,
394+ / s r c \/ n l s \/ .* l a s t T r a n s l a t e d \. j s o n $ / ,
395+ / s r c \/ n l s \/ .* l a s t T r a n s l a t e d L o c a l e \. j s o n $ / ,
396+ / e x t e n s i o n s \/ r e g i s t r y \/ r e g i s t r y \. j s o n $ /
397+ ] ;
398+
383399function _isCacheableFile ( path ) {
384400 if ( path . indexOf ( "." ) === - 1 ) {
385401 // no extension. dont cache
386402 return false ;
387403 }
404+ for ( const pattern of EXCLUDE_PATTERNS_FROM_CACHE ) {
405+ if ( pattern . test ( path ) ) {
406+ // If the path matches any excluded pattern, do not cache
407+ return false ;
408+ }
409+ }
410+
388411 let ext = path . split ( "." ) ;
389412 ext = ext [ ext . length - 1 ] ;
390413 if ( ALLOWED_EXTENSIONS_TO_CACHE . includes ( ext . toLocaleString ( ) ) ) {
@@ -422,11 +445,23 @@ function _getFileDetails(path) {
422445
423446function _computeCacheManifest ( baseDir , filePaths ) {
424447 let manifest = { } , fileDetails , totalSize = 0 ;
448+ let fileSizes = [ ] ;
425449 for ( let filePath of filePaths ) {
426450 fileDetails = _getFileDetails ( baseDir + "/" + filePath ) ;
427451 manifest [ filePath ] = fileDetails . hash ;
428452 totalSize += fileDetails . sizeBytes ;
453+ fileSizes . push ( { path : filePath , sizeBytes : fileDetails . sizeBytes } ) ;
429454 }
455+
456+ // Sort files by size in descending order
457+ fileSizes . sort ( ( a , b ) => b . sizeBytes - a . sizeBytes ) ;
458+
459+ // Log file sizes in descending order. uncomment to debug large cache size
460+ // console.log("Files sorted by size (in bytes):");
461+ // for (let file of fileSizes) {
462+ // console.log(`${file.path}: ${file.sizeBytes} bytes`);
463+ // }
464+
430465 totalSize = Math . round ( totalSize / 1024 ) ; // KB
431466 console . log ( "Total size of cache in KB: " , totalSize ) ;
432467 if ( totalSize > 75000 ) {
@@ -717,14 +752,14 @@ exports.clean = series(cleanDist);
717752exports . reset = series ( cleanAll ) ;
718753
719754exports . releaseDev = series ( cleanDist , exports . buildDebug , makeBracketsConcatJS , _compileLessSrc ,
720- makeDistAll , releaseDev ,
755+ makeDistAll , cleanUnwantedFilesInDist , releaseDev ,
721756 createDistCacheManifest , createDistTest , _cleanReleaseBuildArtefactsInSrc ) ;
722757exports . releaseStaging = series ( cleanDist , exports . build , makeBracketsConcatJS , _compileLessSrc ,
723- makeDistNonJS , makeJSDist , makeJSPrettierDist , makeNonMinifyDist ,
758+ makeDistNonJS , makeJSDist , makeJSPrettierDist , makeNonMinifyDist , cleanUnwantedFilesInDist ,
724759 _renameBracketsConcatAsBracketsJSInDist , _patchMinifiedCSSInDistIndex , releaseStaging ,
725760 createDistCacheManifest , createDistTest , _cleanReleaseBuildArtefactsInSrc ) ;
726761exports . releaseProd = series ( cleanDist , exports . build , makeBracketsConcatJS , _compileLessSrc ,
727- makeDistNonJS , makeJSDist , makeJSPrettierDist , makeNonMinifyDist ,
762+ makeDistNonJS , makeJSDist , makeJSPrettierDist , makeNonMinifyDist , cleanUnwantedFilesInDist ,
728763 _renameBracketsConcatAsBracketsJSInDist , _patchMinifiedCSSInDistIndex , releaseProd ,
729764 createDistCacheManifest , createDistTest , _cleanReleaseBuildArtefactsInSrc ) ;
730765exports . releaseWebCache = series ( makeDistWebCache ) ;
0 commit comments