Advanced operations for analyzing multiple files and performing bulk cache operations.
Analyze multiple files at once to determine which have changed, which are missing, and which are unchanged.
/**
* Analyzes an array of files and categorizes them by status
* @param files - Array of file paths to analyze
* @returns AnalyzedFiles object with categorized file arrays
*/
analyzeFiles(files: string[]): AnalyzedFiles;
interface AnalyzedFiles {
changedFiles: string[];
notFoundFiles: string[];
notChangedFiles: string[];
}Usage Examples:
import { create } from "file-entry-cache";
const cache = create("build-cache");
const sourceFiles = [
"src/app.js",
"src/utils.js",
"src/config.js",
"deleted-file.js"
];
const analysis = cache.analyzeFiles(sourceFiles);
console.log("Changed files:", analysis.changedFiles);
console.log("Missing files:", analysis.notFoundFiles);
console.log("Unchanged files:", analysis.notChangedFiles);
// Process only changed files
for (const file of analysis.changedFiles) {
console.log(`Processing ${file}...`);
// Rebuild or reprocess this file
}Get a simple array of files that have changed since last analysis.
/**
* Returns array of files that have changed since last check
* @param files - Array of file paths to check
* @returns Array of file paths that have changed
*/
getUpdatedFiles(files: string[]): string[];Usage Examples:
import { create } from "file-entry-cache";
const cache = create("lint-cache");
const allFiles = [
"src/app.js",
"src/components/header.js",
"src/components/footer.js",
"src/utils/helpers.js"
];
const updatedFiles = cache.getUpdatedFiles(allFiles);
if (updatedFiles.length > 0) {
console.log(`${updatedFiles.length} files need processing:`);
updatedFiles.forEach(file => console.log(` - ${file}`));
// Run linter only on changed files
runLinter(updatedFiles);
} else {
console.log("No files have changed");
}Get file descriptors for a set of files, with automatic filtering of problematic entries.
/**
* Gets file descriptors for specified files, or all cached files if none specified
* Automatically filters out files with errors or that weren't found
* @param files - Optional array of file paths. If not provided, uses all cached entries
* @returns Array of FileDescriptor objects for valid files
*/
normalizeEntries(files?: string[]): FileDescriptor[];
interface FileDescriptor {
key: string;
changed?: boolean;
meta: FileDescriptorMeta;
notFound?: boolean;
err?: Error;
}Usage Examples:
import { create } from "file-entry-cache";
const cache = create("project-cache");
// Get descriptors for specific files
const specificFiles = cache.normalizeEntries([
"src/app.js",
"src/config.js",
"package.json"
]);
specificFiles.forEach(descriptor => {
console.log(`${descriptor.key}: ${descriptor.changed ? 'changed' : 'unchanged'}`);
});
// Get all valid cached entries
const allEntries = cache.normalizeEntries();
console.log(`Total cached files: ${allEntries.length}`);
// Process all changed files
const changedEntries = allEntries.filter(entry => entry.changed);
changedEntries.forEach(entry => {
console.log(`Processing changed file: ${entry.key}`);
// Custom processing logic
});Get file descriptors for all cached files that start with a specific path.
/**
* Gets file descriptors for all cached files that start with the specified path
* Useful for directory-based operations or filtering by path prefix
* @param filePath - Path prefix to match against cached file keys
* @returns Array of FileDescriptor objects matching the path
*/
getFileDescriptorsByPath(filePath: string): FileDescriptor[];Usage Examples:
import { create } from "file-entry-cache";
const cache = create("project-cache");
// Get all files in src directory
const srcFiles = cache.getFileDescriptorsByPath("src/");
srcFiles.forEach(descriptor => {
console.log(`Source file: ${descriptor.key}`);
});
// Get all test files
const testFiles = cache.getFileDescriptorsByPath("test/");
const changedTests = testFiles.filter(file => file.changed);
if (changedTests.length > 0) {
console.log("Running tests for changed test files:");
changedTests.forEach(test => console.log(` - ${test.key}`));
}
// Get files in specific subdirectory
const componentFiles = cache.getFileDescriptorsByPath("src/components/");
console.log(`Found ${componentFiles.length} component files`);Conditional Processing:
import { create } from "file-entry-cache";
const cache = create("build-cache");
const allSources = ["src/app.js", "src/utils.js", "config/settings.js"];
const analysis = cache.analyzeFiles(allSources);
// Handle missing files
if (analysis.notFoundFiles.length > 0) {
console.warn("Missing files detected:", analysis.notFoundFiles);
// Maybe remove from build configuration
}
// Process only changed files
if (analysis.changedFiles.length > 0) {
console.log("Rebuilding changed files...");
buildFiles(analysis.changedFiles);
} else {
console.log("No changes detected, skipping build");
}
// Report unchanged files for debugging
console.log(`${analysis.notChangedFiles.length} files unchanged`);Directory-based Processing:
import { create } from "file-entry-cache";
const cache = create("watch-cache");
// Process different directories separately
const srcChanges = cache.getFileDescriptorsByPath("src/")
.filter(file => file.changed);
const testChanges = cache.getFileDescriptorsByPath("test/")
.filter(file => file.changed);
if (srcChanges.length > 0) {
console.log("Source files changed, running build...");
runBuild();
}
if (testChanges.length > 0) {
console.log("Test files changed, running tests...");
runTests();
}