UNPKG

@nxworker/workspace

Version:

Nx plugin providing generators for managing workspace files, including the move-file generator for safely moving files between projects while updating all imports

86 lines (85 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { TreeReadCache: function() { return TreeReadCache; }, treeReadCache: function() { return treeReadCache; } }); let TreeReadCache = class TreeReadCache { /** * Cached wrapper for tree.read() * @param tree - The Tree instance * @param filePath - Path to the file * @param encoding - File encoding * @returns File content or null if file doesn't exist */ read(tree, filePath, encoding = 'utf-8') { // Check cache first const cached = this.contentCache.get(filePath); if (cached !== undefined) { return cached; } // Read from tree and cache result const content = tree.read(filePath, encoding); this.contentCache.set(filePath, content); return content; } /** * Cached wrapper for tree.children() * @param tree - The Tree instance * @param dirPath - Directory path * @returns Array of child file/directory names */ children(tree, dirPath) { // Check cache first const cached = this.childrenCache.get(dirPath); if (cached !== undefined) { return cached; } // Get children from tree and cache result const children = tree.children(dirPath); this.childrenCache.set(dirPath, children); return children; } /** * Invalidates cache entry for a file after it's been written * @param filePath - Path to invalidate */ invalidateFile(filePath) { this.contentCache.delete(filePath); } /** * Invalidates cache entry for a directory * @param dirPath - Directory path to invalidate */ invalidateDirectory(dirPath) { this.childrenCache.delete(dirPath); } /** * Clears all caches. Should be called when starting a new operation. */ clear() { this.contentCache.clear(); this.childrenCache.clear(); } /** * Returns cache statistics for monitoring/debugging */ getStats() { return { contentCacheSize: this.contentCache.size, childrenCacheSize: this.childrenCache.size }; } constructor(){ this.contentCache = new Map(); this.childrenCache = new Map(); } }; const treeReadCache = new TreeReadCache(); //# sourceMappingURL=tree-cache.js.map