Skip to content

Commit 08fb5c4

Browse files
committed
refactor(project): Cleanup
1 parent f3f484d commit 08fb5c4

File tree

5 files changed

+8
-197
lines changed

5 files changed

+8
-197
lines changed

packages/project/lib/build/TaskRunner.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,6 @@ class TaskRunner {
221221
},
222222
options,
223223
};
224-
// const invalidatedResources = this._buildCache.getDepsOfInvalidatedResourcesForTask(taskName);
225-
// if (invalidatedResources) {
226-
// params.invalidatedResources = invalidatedResources;
227-
// }
228224

229225
let dependencies;
230226
if (requiresDependencies) {

packages/project/lib/build/cache/BuildTaskCache.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const log = getLogger("build:cache:BuildTaskCache");
1919
* @typedef {object} TaskCacheMetadata
2020
* @property {RequestMetadata} [projectRequests] - Project resource requests
2121
* @property {RequestMetadata} [dependencyRequests] - Dependency resource requests
22-
* @property {Object.<string, ResourceMetadata>} [resourcesRead] - Resources read by task
23-
* @property {Object.<string, ResourceMetadata>} [resourcesWritten] - Resources written by task
22+
* @property {Object<string, ResourceMetadata>} [resourcesRead] - Resources read by task
23+
* @property {Object<string, ResourceMetadata>} [resourcesWritten] - Resources written by task
2424
*/
2525

2626
function unionArray(arr, items) {
@@ -38,24 +38,6 @@ function unionObject(target, obj) {
3838
}
3939
}
4040

41-
// async function createMetadataForResources(resourceMap) {
42-
// const metadata = Object.create(null);
43-
// await Promise.all(Object.keys(resourceMap).map(async (resourcePath) => {
44-
// const resource = resourceMap[resourcePath];
45-
// if (resource.hash) {
46-
// // Metadata object
47-
// metadata[resourcePath] = resource;
48-
// return;
49-
// }
50-
// // Resource instance
51-
// metadata[resourcePath] = {
52-
// integrity: await resource.getIntegrity(),
53-
// lastModified: resource.getLastModified(),
54-
// };
55-
// }));
56-
// return metadata;
57-
// }
58-
5941
/**
6042
* Manages the build cache for a single task
6143
*

packages/project/lib/build/cache/ProjectBuildCache.js

Lines changed: 6 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
// }

packages/project/lib/build/helpers/ProjectBuildContext.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ class ProjectBuildContext {
4545
allowedTags: ["ui5:OmitFromBuildResult", "ui5:IsBundle"],
4646
allowedNamespaces: ["build"]
4747
});
48-
// const buildManifest = this.#getBuildManifest();
49-
// if (buildManifest) {
50-
// this._buildCache.deserialize(buildManifest.buildManifest.cache);
51-
// }
5248
}
5349

5450
static async create(buildContext, project) {
@@ -162,10 +158,6 @@ class ProjectBuildContext {
162158
return false;
163159
}
164160

165-
// if (!this._buildCache.hasAnyCache()) {
166-
// await this._buildCache.attemptDeserializationFromDisk();
167-
// }
168-
169161
return this._buildCache.needsRebuild();
170162
}
171163

@@ -228,35 +220,6 @@ class ProjectBuildContext {
228220
getBuildSignature() {
229221
return this._buildSignature;
230222
}
231-
232-
// async watchFileChanges() {
233-
// // const paths = this._project.getSourcePaths();
234-
// // this._log.verbose(`Watching source paths: ${paths.join(", ")}`);
235-
// // const {default: chokidar} = await import("chokidar");
236-
// // const watcher = chokidar.watch(paths, {
237-
// // ignoreInitial: true,
238-
// // persistent: false,
239-
// // });
240-
// // watcher.on("add", async (filePath) => {
241-
// // });
242-
// // watcher.on("change", async (filePath) => {
243-
// // const resourcePath = this._project.getVirtualPath(filePath);
244-
// // this._log.info(`File changed: ${resourcePath} (${filePath})`);
245-
// // // Inform cache
246-
// // this._buildCache.fileChanged(resourcePath);
247-
// // // Inform dependents
248-
// // for (const dependent of this._buildContext.getGraph().getTransitiveDependents(this._project.getName())) {
249-
// // await this._buildContext.getProjectBuildContext(dependent).dependencyFileChanged(resourcePath);
250-
// // }
251-
// // // Inform build context
252-
// // await this._buildContext.fileChanged(this._project.getName(), resourcePath);
253-
// // });
254-
// }
255-
256-
// dependencyFileChanged(resourcePath) {
257-
// this._log.info(`Dependency file changed: ${resourcePath}`);
258-
// this._buildCache.fileChanged(resourcePath);
259-
// }
260223
}
261224

262225
export default ProjectBuildContext;

packages/project/lib/build/helpers/createBuildManifest.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ export default async function(project, graph, buildConfig, taskRepository, build
4848
`Unable to create archive metadata for project ${project.getName()}: ` +
4949
`Project type ${type} is currently not supported`);
5050
}
51-
// let buildManifest;
52-
// if (project.isFrameworkProject()) {
53-
// buildManifest = await createFrameworkManifest(project, buildConfig, taskRepository);
54-
// } else {
55-
// buildManifest = {
56-
// manifestVersion: "0.3",
57-
// timestamp: new Date().toISOString(),
58-
// dependencies: collectDepInfo(graph, project),
59-
// version: project.getVersion(),
60-
// namespace: project.getNamespace(),
61-
// tags: getSortedTags(project),
62-
// };
63-
// }
6451

6552
const metadata = {
6653
project: {

0 commit comments

Comments
 (0)