Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions gulpfile.js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ const ALLOWED_EXTENSIONS_TO_CACHE = ["js", "html", "htm", "xml", "xhtml", "mjs",
const DISALLOWED_EXTENSIONS_TO_CACHE = ["map", "nuspec", "partial", "pre", "post",
"webmanifest", "rb", "ts"];

// Ceiling for the PWA service worker cache, in KB. Dev builds ship unminified sources and keep the
// phoenix-pro sources in dist, so they are legitimately larger than prod - dev gets the looser
// limit, mirroring DEV_MAX_TOTAL_SIZE_MB / PROD_MAX_TOTAL_SIZE_MB in validate-build.js. Prod is the
// number that actually matters for users, so keep that one tight.
const MAX_CACHE_SIZE_KB_PROD = 78000;
const MAX_CACHE_SIZE_KB_DEV = 100000;

const EXCLUDE_PATTERNS_FROM_CACHE = [
/src\/nls\/.*expertTranslations\.json$/,
/src\/nls\/.*lastTranslated\.json$/,
Expand Down Expand Up @@ -512,7 +519,7 @@ function _getFileDetails(path) {
};
}

function _computeCacheManifest(baseDir, filePaths) {
function _computeCacheManifest(baseDir, filePaths, maxSizeKB) {
let manifest = {}, fileDetails, totalSize = 0;
let fileSizes = [];
for(let filePath of filePaths){
Expand All @@ -533,8 +540,9 @@ function _computeCacheManifest(baseDir, filePaths) {

totalSize = Math.round(totalSize/1024); // KB
console.log("Total size of cache in KB: ", totalSize);
if(totalSize > 78000){
throw new Error("The total size of the src or dist folder core assets exceeds 78MB." +
if(totalSize > maxSizeKB){
throw new Error(`The total size of the src or dist folder core assets exceeds ` +
`${Math.round(maxSizeKB / 1000)}MB (got ${Math.round(totalSize / 1000)}MB).` +
"\nPlease review and trim storage. This significantly impacts the distribution size." +
"\nEither trim down the size or increase the limit after careful review.");
}
Expand Down Expand Up @@ -954,24 +962,32 @@ async function _renameConcatExtensionsinDist() {
}
}

function createCacheManifest(srcFolder) {
function createCacheManifest(srcFolder, maxSizeKB) {
return new Promise((resolve, reject)=>{
_listFilesInDir(srcFolder).then((files)=>{
files = _fixAndFilterPaths(srcFolder, files);
console.log("Files in cache: ", files.length);
let cache = _computeCacheManifest(srcFolder, files);
let cache = _computeCacheManifest(srcFolder, files, maxSizeKB);
fs.writeFileSync(srcFolder + "/cacheManifest.json", JSON.stringify(cache, null, 2));
resolve();
}).catch(reject);
});
}

// src/cacheManifest.json only matters when the src tree itself is served (npm run serve) - releases
// ship dist/, whose manifest is regenerated by createDistCacheManifest and overwrites the copy that
// makeDistNonJS carried over. So this is a dev-serving artefact in every chain and takes the dev
// limit; the shipped artefact is guarded by createDistCacheManifest + validateDistSizeRestrictions.
function createSrcCacheManifest() {
return createCacheManifest("src");
return createCacheManifest("src", MAX_CACHE_SIZE_KB_DEV);
}

function createDistCacheManifest() {
return createCacheManifest("dist");
return createCacheManifest("dist", MAX_CACHE_SIZE_KB_PROD);
}

function createDistCacheManifestDev() {
return createCacheManifest("dist", MAX_CACHE_SIZE_KB_DEV);
}

function copyDistToDistTestFolder() {
Expand Down Expand Up @@ -1101,7 +1117,7 @@ exports.reset = series(cleanAll);

exports.releaseDev = series(cleanDist, exports.buildDebug, makeBracketsConcatJS, makeConcatExtensions, _compileLessSrc,
makeDistAll, cleanUnwantedFilesInDistDev, releaseDev, _renameConcatExtensionsinDist,
createDistCacheManifest, createDistTest,
createDistCacheManifestDev, createDistTest,
_cleanPhoenixProGitFolder, _cleanReleaseBuildArtefactsInSrc, validateBuild.validateDistSizeRestrictions);
exports.releaseStaging = series(cleanDist, exports.build, makeBracketsConcatJSWithMinifiedBrowserScripts,
makeConcatExtensions, _compileLessSrc, makeDistNonJS, makeJSDist, makeJSPrettierDist, makeNonMinifyDist,
Expand Down
2 changes: 1 addition & 1 deletion tracking-repos.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"phoenixPro": {
"commitID": "11fc9899d481d9781b2a8d850d8c7209db4c010a"
"commitID": "5886d202574264a2c4c70b4126618b9fae4950ff"
}
}
Loading