• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

streetsidesoftware / cspell / 16312309963

16 Jul 2025 06:39AM UTC coverage: 92.213% (-0.2%) from 92.398%
16312309963

Pull #6579

github

web-flow
Merge ccb5c8657 into b5c00c51b
Pull Request #6579: fix: Upgrade file-entry-cache to 10.x

13115 of 15521 branches covered (84.5%)

74 of 115 new or added lines in 1 file covered. (64.35%)

12 existing lines in 1 file now uncovered.

16104 of 17464 relevant lines covered (92.21%)

29623.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/packages/cspell/src/util/cache/fileEntryCache.ts
1
/**
2
 * This is a wrapper for 'file-entry-cache'
3
 */
4

5
export type { FileDescriptor } from './file-entry-cache.mjs';
6
import { mkdirSync } from 'node:fs';
7
import * as path from 'node:path';
8
import { isMainThread } from 'node:worker_threads';
9

10
import type { FileEntryCache as FecFileEntryCache } from './file-entry-cache.mjs';
11
import * as fec from './file-entry-cache.mjs';
12

13
export type FileEntryCache = FecFileEntryCache;
14

15
export function createFromFile(pathToCache: string, useCheckSum: boolean, useRelative: boolean): FileEntryCache {
16
    const absPathToCache = path.resolve(pathToCache);
31✔
17
    const relDir = path.dirname(absPathToCache);
31✔
18
    mkdirSync(relDir, { recursive: true });
31✔
19
    const create = wrap(() => fec.createFromFile(absPathToCache, useCheckSum));
31✔
20
    const feCache = create();
31✔
21
    const cacheWrapper: FileEntryCache = {
31✔
22
        currentWorkingDir: relDir,
23
        get cache() {
UNCOV
24
            return feCache.cache;
×
25
        },
26
        getHash(buffer: Buffer): string {
UNCOV
27
            return feCache.getHash(buffer);
×
28
        },
29
        hasFileChanged: wrap((cwd, file: string) => {
30
            // console.log(file);
UNCOV
31
            return feCache.hasFileChanged(resolveFile(cwd, file));
×
32
        }),
33
        analyzeFiles: wrap((cwd, files?: string[]) => {
UNCOV
34
            return feCache.analyzeFiles(resolveFiles(cwd, files));
×
35
        }),
36

37
        getFileDescriptor: wrap((cwd, file: string) => {
38
            return feCache.getFileDescriptor(resolveFile(cwd, file));
68✔
39
        }),
40
        getUpdatedFiles: wrap((cwd, files?: string[]) => {
UNCOV
41
            return feCache.getUpdatedFiles(resolveFiles(cwd, files));
×
42
        }),
43
        normalizeEntries: wrap((cwd, files?: string[]) => {
UNCOV
44
            return feCache.normalizeEntries(resolveFiles(cwd, files));
×
45
        }),
46
        removeEntry: wrap((cwd, file: string) => {
47
            // console.log(file);
UNCOV
48
            return feCache.removeEntry(resolveFile(cwd, file));
×
49
        }),
50
        deleteCacheFile(): void {
UNCOV
51
            feCache.deleteCacheFile();
×
52
        },
53
        destroy(): void {
54
            feCache.destroy();
3✔
55
        },
56
        reconcile: wrap((_cwd, noPrune?: boolean) => {
57
            feCache.reconcile(noPrune);
21✔
58
        }),
59
    };
60

61
    return cacheWrapper;
31✔
62

63
    function resolveFile(cwd: string, file: string): string {
64
        if (!useRelative) return normalizePath(file);
68!
UNCOV
65
        const r = path.relative(relDir, path.resolve(cwd, file));
×
UNCOV
66
        return normalizePath(r);
×
67
    }
68

69
    function resolveFiles(cwd: string, files: string[] | undefined): string[] | undefined {
UNCOV
70
        return files?.map((file) => resolveFile(cwd, file));
×
71
    }
72

73
    function wrap<P extends unknown[], T>(fn: (cwd: string, ...params: P) => T): (...params: P) => T {
74
        return (...params: P) => {
248✔
75
            const cwd = process.cwd();
120✔
76
            try {
120✔
77
                isMainThread && process.chdir(relDir);
120✔
78
                return fn(cwd, ...params);
120✔
79
            } finally {
80
                isMainThread && process.chdir(cwd);
120✔
81
            }
82
        };
83
    }
84
}
85

86
export function normalizePath(filePath: string): string {
87
    if (path.sep === '/') return filePath;
2,557!
UNCOV
88
    return filePath.split(path.sep).join('/');
×
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc