Skip to content

Commit 1b5855e

Browse files
committed
fix: build break as cache size too big, remove unwated trasnlation metadata and registry cache
1 parent f9d7c4d commit 1b5855e

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

gulpfile.js/index.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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",
380389
const DISALLOWED_EXTENSIONS_TO_CACHE = ["map", "nuspec", "partial", "pre", "post",
381390
"webmanifest", "rb", "ts"];
382391

392+
const EXCLUDE_PATTERNS_FROM_CACHE = [
393+
/src\/nls\/.*expertTranslations\.json$/,
394+
/src\/nls\/.*lastTranslated\.json$/,
395+
/src\/nls\/.*lastTranslatedLocale\.json$/,
396+
/extensions\/registry\/registry\.json$/
397+
];
398+
383399
function _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

423446
function _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);
717752
exports.reset = series(cleanAll);
718753

719754
exports.releaseDev = series(cleanDist, exports.buildDebug, makeBracketsConcatJS, _compileLessSrc,
720-
makeDistAll, releaseDev,
755+
makeDistAll, cleanUnwantedFilesInDist, releaseDev,
721756
createDistCacheManifest, createDistTest, _cleanReleaseBuildArtefactsInSrc);
722757
exports.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);
726761
exports.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);
730765
exports.releaseWebCache = series(makeDistWebCache);

0 commit comments

Comments
 (0)