@@ -12,7 +12,6 @@ export default class ProjectBuildCache {
1212 #project;
1313 #buildSignature;
1414 #cacheManager;
15- // #cacheDir;
1615
1716 #invalidatedTasks = new Map ( ) ;
1817 #updatedResources = new Set ( ) ;
@@ -30,10 +29,6 @@ export default class ProjectBuildCache {
3029 this . #project = project ;
3130 this . #buildSignature = buildSignature ;
3231 this . #cacheManager = cacheManager ;
33- // this.#cacheRoot = cacheDir && createAdapter({
34- // fsBasePath: cacheDir,
35- // virBasePath: "/"
36- // });
3732 }
3833
3934 static async create ( project , buildSignature , cacheManager ) {
@@ -347,52 +342,7 @@ export default class ProjectBuildCache {
347342 return Array . from ( this . #invalidatedTasks. keys ( ) ) ;
348343 }
349344
350- // async createBuildManifest() {
351- // // const globalResourceIndex = Object.create(null);
352- // // function addResourcesToIndex(taskName, resourceMap) {
353- // // for (const resourcePath of Object.keys(resourceMap)) {
354- // // const resource = resourceMap[resourcePath];
355- // // const resourceKey = `${resourcePath}:${resource.hash}`;
356- // // if (!globalResourceIndex[resourceKey]) {
357- // // globalResourceIndex[resourceKey] = {
358- // // hash: resource.hash,
359- // // lastModified: resource.lastModified,
360- // // tasks: [taskName]
361- // // };
362- // // } else if (!globalResourceIndex[resourceKey].tasks.includes(taskName)) {
363- // // globalResourceIndex[resourceKey].tasks.push(taskName);
364- // // }
365- // // }
366- // // }
367- // const taskCache = [];
368- // for (const cache of this.#taskCache.values()) {
369- // const cacheObject = await cache.toJSON();
370- // taskCache.push(cacheObject);
371- // // addResourcesToIndex(taskName, cacheObject.resources.project.resourcesRead);
372- // // addResourcesToIndex(taskName, cacheObject.resources.project.resourcesWritten);
373- // // addResourcesToIndex(taskName, cacheObject.resources.dependencies.resourcesRead);
374- // }
375- // // Collect metadata for all relevant source files
376- // const sourceReader = this.#project.getSourceReader();
377- // // const resourceMetadata = await Promise.all(Array.from(relevantSourceFiles).map(async (resourcePath) => {
378- // const resources = await sourceReader.byGlob("/**/*");
379- // const sourceMetadata = Object.create(null);
380- // await Promise.all(resources.map(async (resource) => {
381- // sourceMetadata[resource.getOriginalPath()] = {
382- // lastModified: resource.getStatInfo()?.mtimeMs,
383- // hash: await resource.getHash(),
384- // };
385- // }));
386-
387- // return {
388- // timestamp: Date.now(),
389- // cacheKey: this.#cacheKey,
390- // taskCache,
391- // sourceMetadata,
392- // // globalResourceIndex,
393- // };
394- // }
395-
345+ // ===== SERIALIZATION =====
396346 async #createCacheManifest( ) {
397347 const cache = Object . create ( null ) ;
398348 cache . index = await this . #createIndex( this . #project. getSourceReader ( ) , true ) ;
@@ -419,45 +369,8 @@ export default class ProjectBuildCache {
419369
420370 await this . #cacheManager. writeBuildManifest (
421371 this . #project, this . #buildSignature, buildManifest ) ;
422-
423- // const serializedCache = await this.toJSON();
424- // const cacheContent = JSON.stringify(serializedCache, null, 2);
425- // const res = createResource({
426- // path: `/cache-info.json`,
427- // string: cacheContent,
428- // });
429- // await this.#cacheRoot.write(res);
430372 }
431373
432- // async #serializeTaskOutputs() {
433- // log.info(`Serializing task outputs for project ${this.#project.getName()}`);
434- // const stageCache = await Promise.all(Array.from(this.#taskCache.keys()).map(async (taskName, idx) => {
435- // const reader = this.#project.getDeltaReader(taskName);
436- // if (!reader) {
437- // log.verbose(
438- // `Skipping serialization of empty writer for task ${taskName} in project ${this.#project.getName()}`
439- // );
440- // return;
441- // }
442- // const resources = await reader.byGlob("/**/*");
443-
444- // const target = createAdapter({
445- // fsBasePath: path.join(this.#cacheDir, "taskCache", `${idx}-${taskName}`),
446- // virBasePath: "/"
447- // });
448-
449- // for (const res of resources) {
450- // await target.write(res);
451- // }
452- // return {
453- // reader: target,
454- // stage: taskName
455- // };
456- // }));
457- // // Re-import cache as base layer to reduce memory pressure
458- // this.#project.importCachedStages(stageCache.filter((entry) => entry));
459- // }
460-
461374 async #getStageNameForTask( taskName ) {
462375 return `tasks/${ taskName } ` ;
463376 }
@@ -481,6 +394,7 @@ export default class ProjectBuildCache {
481394 this . #buildSignature, stageName ,
482395 res . getOriginalPath ( ) , await res . getStreamAsync ( )
483396 ) ;
397+ // TODO: Decide whether to use stream or buffer
484398 // const integrity = await this.#cacheManager.writeStage(
485399 // this.#buildSignature, stageName,
486400 // res.getOriginalPath(), await res.getBuffer()
@@ -510,27 +424,27 @@ export default class ProjectBuildCache {
510424 }
511425 // Check against index
512426 const resourcePath = resource . getOriginalPath ( ) ;
513- if ( ! index . hasOwnProperty ( resourcePath ) ) {
427+ if ( Object . hasOwn ( index , resourcePath ) ) {
514428 // New resource encountered
515429 log . verbose ( `New source file: ${ resourcePath } ` ) ;
516430 changedResources . add ( resourcePath ) ;
517431 continue ;
518432 }
519433 const { lastModified, size, inode, integrity} = index [ resourcePath ] ;
520434
521- if ( resourceMetadata . lastModified !== currentLastModified ) {
435+ if ( lastModified !== currentLastModified ) {
522436 log . verbose ( `Source file modified: ${ resourcePath } (timestamp change)` ) ;
523437 changedResources . add ( resourcePath ) ;
524438 continue ;
525439 }
526440
527- if ( resourceMetadata . inode !== resource . getInode ( ) ) {
441+ if ( inode !== resource . getInode ( ) ) {
528442 log . verbose ( `Source file modified: ${ resourcePath } (inode change)` ) ;
529443 changedResources . add ( resourcePath ) ;
530444 continue ;
531445 }
532446
533- if ( resourceMetadata . size !== await resource . getSize ( ) ) {
447+ if ( size !== await resource . getSize ( ) ) {
534448 log . verbose ( `Source file modified: ${ resourcePath } (size change)` ) ;
535449 changedResources . add ( resourcePath ) ;
536450 continue ;
@@ -601,23 +515,6 @@ export default class ProjectBuildCache {
601515 }
602516
603517 async #importCachedStages( stages ) {
604- // const cachedStages = await Promise.all(Array.from(this.#taskCache.keys()).map(async (taskName, idx) => {
605- // // const fsBasePath = path.join(this.#cacheDir, "taskCache", `${idx}-${taskName}`);
606- // // let cacheReader;
607- // // if (await exists(fsBasePath)) {
608- // // cacheReader = createAdapter({
609- // // name: `Cache reader for task ${taskName} in project ${this.#project.getName()}`,
610- // // fsBasePath,
611- // // virBasePath: "/",
612- // // project: this.#project,
613- // // });
614- // // }
615-
616- // return {
617- // stage: taskName,
618- // reader: cacheReader
619- // };
620- // }));
621518 const cachedStages = await Promise . all ( Object . entries ( stages ) . map ( async ( [ stageName , resourceMetadata ] ) => {
622519 const reader = await this . #createReaderForStageCache( stageName , resourceMetadata ) ;
623520 return {
@@ -688,17 +585,3 @@ export default class ProjectBuildCache {
688585 }
689586 }
690587}
691-
692- // async function exists(filePath) {
693- // try {
694- // await stat(filePath);
695- // return true;
696- // } catch (err) {
697- // // "File or directory does not exist"
698- // if (err.code === "ENOENT") {
699- // return false;
700- // } else {
701- // throw err;
702- // }
703- // }
704- // }
0 commit comments