cspell 7.0.0-alpha.1 → 7.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/esm/application.d.mts +1 -1
  2. package/dist/esm/cli-reporter.mjs +2 -1
  3. package/dist/esm/util/constants.d.mts +1 -1
  4. package/dist/esm/util/fileHelper.d.mts +1 -1
  5. package/dist/lib/file-entry-cache.cjs +3 -2
  6. package/dist/lib/file-entry-cache.d.cts +2 -2
  7. package/dist/lib/pkgInfo.cjs +3 -25
  8. package/package.json +31 -36
  9. package/bin.js +0 -16
  10. package/dist/cjs/app.d.ts +0 -5
  11. package/dist/cjs/app.js +0 -50
  12. package/dist/cjs/application.d.ts +0 -16
  13. package/dist/cjs/application.js +0 -121
  14. package/dist/cjs/cli-reporter.d.ts +0 -16
  15. package/dist/cjs/cli-reporter.js +0 -247
  16. package/dist/cjs/commandCheck.d.ts +0 -3
  17. package/dist/cjs/commandCheck.js +0 -78
  18. package/dist/cjs/commandLink.d.ts +0 -3
  19. package/dist/cjs/commandLink.js +0 -51
  20. package/dist/cjs/commandLint.d.ts +0 -3
  21. package/dist/cjs/commandLint.js +0 -150
  22. package/dist/cjs/commandSuggestion.d.ts +0 -3
  23. package/dist/cjs/commandSuggestion.js +0 -88
  24. package/dist/cjs/commandTrace.d.ts +0 -3
  25. package/dist/cjs/commandTrace.js +0 -87
  26. package/dist/cjs/emitters/DictionaryPathFormat.d.ts +0 -3
  27. package/dist/cjs/emitters/DictionaryPathFormat.js +0 -16
  28. package/dist/cjs/emitters/suggestionsEmitter.d.ts +0 -13
  29. package/dist/cjs/emitters/suggestionsEmitter.js +0 -84
  30. package/dist/cjs/emitters/traceEmitter.d.ts +0 -21
  31. package/dist/cjs/emitters/traceEmitter.js +0 -171
  32. package/dist/cjs/featureFlags/featureFlags.d.ts +0 -4
  33. package/dist/cjs/featureFlags/featureFlags.js +0 -25
  34. package/dist/cjs/featureFlags/index.d.ts +0 -2
  35. package/dist/cjs/featureFlags/index.js +0 -7
  36. package/dist/cjs/index.d.ts +0 -5
  37. package/dist/cjs/index.js +0 -22
  38. package/dist/cjs/link.d.ts +0 -8
  39. package/dist/cjs/link.js +0 -47
  40. package/dist/cjs/lint/LintRequest.d.ts +0 -23
  41. package/dist/cjs/lint/LintRequest.js +0 -48
  42. package/dist/cjs/lint/index.d.ts +0 -3
  43. package/dist/cjs/lint/index.js +0 -8
  44. package/dist/cjs/lint/lint.d.ts +0 -4
  45. package/dist/cjs/lint/lint.js +0 -499
  46. package/dist/cjs/options.d.ts +0 -178
  47. package/dist/cjs/options.js +0 -12
  48. package/dist/cjs/repl/index.d.ts +0 -18
  49. package/dist/cjs/repl/index.js +0 -75
  50. package/dist/cjs/util/InMemoryReporter.d.ts +0 -28
  51. package/dist/cjs/util/InMemoryReporter.js +0 -47
  52. package/dist/cjs/util/async.d.ts +0 -3
  53. package/dist/cjs/util/async.js +0 -12
  54. package/dist/cjs/util/cache/CSpellLintResultCache.d.ts +0 -20
  55. package/dist/cjs/util/cache/CSpellLintResultCache.js +0 -3
  56. package/dist/cjs/util/cache/CacheOptions.d.ts +0 -34
  57. package/dist/cjs/util/cache/CacheOptions.js +0 -3
  58. package/dist/cjs/util/cache/DiskCache.d.ts +0 -63
  59. package/dist/cjs/util/cache/DiskCache.js +0 -237
  60. package/dist/cjs/util/cache/DummyCache.d.ts +0 -11
  61. package/dist/cjs/util/cache/DummyCache.js +0 -22
  62. package/dist/cjs/util/cache/ObjectCollection.d.ts +0 -17
  63. package/dist/cjs/util/cache/ObjectCollection.js +0 -136
  64. package/dist/cjs/util/cache/createCache.d.ts +0 -31
  65. package/dist/cjs/util/cache/createCache.js +0 -77
  66. package/dist/cjs/util/cache/fileEntryCache.d.ts +0 -9
  67. package/dist/cjs/util/cache/fileEntryCache.js +0 -107
  68. package/dist/cjs/util/cache/index.d.ts +0 -4
  69. package/dist/cjs/util/cache/index.js +0 -8
  70. package/dist/cjs/util/constants.d.ts +0 -6
  71. package/dist/cjs/util/constants.js +0 -8
  72. package/dist/cjs/util/errors.d.ts +0 -23
  73. package/dist/cjs/util/errors.js +0 -60
  74. package/dist/cjs/util/fileHelper.d.ts +0 -63
  75. package/dist/cjs/util/fileHelper.js +0 -226
  76. package/dist/cjs/util/glob.d.ts +0 -45
  77. package/dist/cjs/util/glob.js +0 -175
  78. package/dist/cjs/util/prefetch.d.ts +0 -2
  79. package/dist/cjs/util/prefetch.js +0 -23
  80. package/dist/cjs/util/reporters.d.ts +0 -14
  81. package/dist/cjs/util/reporters.js +0 -68
  82. package/dist/cjs/util/stdin.d.ts +0 -2
  83. package/dist/cjs/util/stdin.js +0 -32
  84. package/dist/cjs/util/table.d.ts +0 -10
  85. package/dist/cjs/util/table.js +0 -40
  86. package/dist/cjs/util/timer.d.ts +0 -8
  87. package/dist/cjs/util/timer.js +0 -17
  88. package/dist/cjs/util/types.d.ts +0 -7
  89. package/dist/cjs/util/types.js +0 -6
  90. package/dist/cjs/util/util.d.ts +0 -13
  91. package/dist/cjs/util/util.js +0 -55
@@ -1,18 +0,0 @@
1
- export declare function simpleRepl(): AsyncIterable<string>;
2
- export type CompleterResult = [string[], string];
3
- export type Completer = (line: string) => CompleterResult;
4
- export declare class SimpleRepl implements AsyncIterable<string> {
5
- prompt: string;
6
- beforeEach: undefined | (() => void);
7
- completer: undefined | Completer;
8
- private _history;
9
- private rl;
10
- constructor(prompt?: string);
11
- question(query: string): Promise<string>;
12
- private _completer;
13
- get history(): string[];
14
- [Symbol.asyncIterator](): {
15
- next: () => Promise<IteratorResult<string, undefined>>;
16
- };
17
- }
18
- //# sourceMappingURL=index.d.ts.map
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.SimpleRepl = exports.simpleRepl = void 0;
27
- const readline = __importStar(require("readline"));
28
- function simpleRepl() {
29
- return new SimpleRepl();
30
- }
31
- exports.simpleRepl = simpleRepl;
32
- class SimpleRepl {
33
- constructor(prompt = '> ') {
34
- this.prompt = prompt;
35
- this._history = [];
36
- this.rl = readline.createInterface({
37
- input: process.stdin,
38
- output: process.stdout,
39
- prompt,
40
- history: this._history,
41
- historySize: 100,
42
- completer: (line) => this._completer(line),
43
- });
44
- this.rl.on('history', (h) => ((this._history = h), undefined));
45
- }
46
- question(query) {
47
- return new Promise((resolve) => {
48
- this.rl.question(query, resolve);
49
- });
50
- }
51
- _completer(line) {
52
- // console.log('Complete: %s', line);
53
- // console.log('History: %o', this._history);
54
- if (this.completer)
55
- return this.completer(line);
56
- const hist = this._history.filter((h) => h.startsWith(line));
57
- return [hist, line];
58
- }
59
- get history() {
60
- return this._history;
61
- }
62
- [Symbol.asyncIterator]() {
63
- const next = () => {
64
- if (this.beforeEach)
65
- this.beforeEach();
66
- // console.log('%o', this.rl);
67
- return this.question(this.prompt)
68
- .then((value) => ({ value }))
69
- .catch(() => ({ done: true, value: undefined }));
70
- };
71
- return { next };
72
- }
73
- }
74
- exports.SimpleRepl = SimpleRepl;
75
- //# sourceMappingURL=index.js.map
@@ -1,28 +0,0 @@
1
- import type { CSpellReporter, Issue, ProgressItem, RunResult } from '@cspell/cspell-types';
2
- export interface InMemoryResult {
3
- log: string[];
4
- issues: Issue[];
5
- runResult: RunResult | undefined;
6
- }
7
- /**
8
- * Simple reporter for test purposes
9
- */
10
- export declare class InMemoryReporter implements CSpellReporter, InMemoryResult {
11
- log: string[];
12
- errors: Error[];
13
- issueCount: number;
14
- errorCount: number;
15
- debugCount: number;
16
- infoCount: number;
17
- progressCount: number;
18
- issues: Issue[];
19
- runResult: RunResult | undefined;
20
- issue: (issue: Issue) => void;
21
- error: (message: string, error: Error) => void;
22
- info: (message: string) => void;
23
- debug: (message: string) => void;
24
- progress: (p: ProgressItem) => void;
25
- result: (r: RunResult) => void;
26
- dump: () => InMemoryResult;
27
- }
28
- //# sourceMappingURL=InMemoryReporter.d.ts.map
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InMemoryReporter = void 0;
4
- /**
5
- * Simple reporter for test purposes
6
- */
7
- class InMemoryReporter {
8
- constructor() {
9
- this.log = [];
10
- this.errors = [];
11
- this.issueCount = 0;
12
- this.errorCount = 0;
13
- this.debugCount = 0;
14
- this.infoCount = 0;
15
- this.progressCount = 0;
16
- this.issues = [];
17
- this.issue = (issue) => {
18
- this.issues.push(issue);
19
- this.issueCount += 1;
20
- const { uri, row, col, text } = issue;
21
- this.log.push(`Issue: ${uri}[${row}, ${col}]: Unknown word: ${text}`);
22
- };
23
- this.error = (message, error) => {
24
- this.errorCount += 1;
25
- this.errors.push(error);
26
- this.log.push(`Error: ${message} ${error.toString()}`);
27
- };
28
- this.info = (message) => {
29
- this.infoCount += 1;
30
- this.log.push(`Info: ${message}`);
31
- };
32
- this.debug = (message) => {
33
- this.debugCount += 1;
34
- this.log.push(`Debug: ${message}`);
35
- };
36
- this.progress = (p) => {
37
- this.progressCount += 1;
38
- this.log.push(`Progress: ${p.type} ${p.fileNum} ${p.fileCount} ${p.filename}`);
39
- };
40
- this.result = (r) => {
41
- this.runResult = r;
42
- };
43
- this.dump = () => ({ log: this.log, issues: this.issues, runResult: this.runResult });
44
- }
45
- }
46
- exports.InMemoryReporter = InMemoryReporter;
47
- //# sourceMappingURL=InMemoryReporter.js.map
@@ -1,3 +0,0 @@
1
- export { helpers as asyncHelpers, toArray as asyncIterableToArray, operators as asyncOperators, pipeAsync as asyncPipe, toAsyncIterable as mergeAsyncIterables, } from '@cspell/cspell-pipe';
2
- export declare const asyncMap: typeof import("@cspell/cspell-pipe/operators").opMapAsync, asyncFilter: typeof import("@cspell/cspell-pipe/operators").opFilterAsync, asyncAwait: typeof import("@cspell/cspell-pipe").opAwaitAsync, asyncFlatten: typeof import("@cspell/cspell-pipe/operators").opFlattenAsync;
3
- //# sourceMappingURL=async.d.ts.map
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asyncFlatten = exports.asyncAwait = exports.asyncFilter = exports.asyncMap = exports.mergeAsyncIterables = exports.asyncPipe = exports.asyncOperators = exports.asyncIterableToArray = exports.asyncHelpers = void 0;
4
- const cspell_pipe_1 = require("@cspell/cspell-pipe");
5
- var cspell_pipe_2 = require("@cspell/cspell-pipe");
6
- Object.defineProperty(exports, "asyncHelpers", { enumerable: true, get: function () { return cspell_pipe_2.helpers; } });
7
- Object.defineProperty(exports, "asyncIterableToArray", { enumerable: true, get: function () { return cspell_pipe_2.toArray; } });
8
- Object.defineProperty(exports, "asyncOperators", { enumerable: true, get: function () { return cspell_pipe_2.operators; } });
9
- Object.defineProperty(exports, "asyncPipe", { enumerable: true, get: function () { return cspell_pipe_2.pipeAsync; } });
10
- Object.defineProperty(exports, "mergeAsyncIterables", { enumerable: true, get: function () { return cspell_pipe_2.toAsyncIterable; } });
11
- exports.asyncMap = cspell_pipe_1.operators.opMapAsync, exports.asyncFilter = cspell_pipe_1.operators.opFilterAsync, exports.asyncAwait = cspell_pipe_1.operators.opAwaitAsync, exports.asyncFlatten = cspell_pipe_1.operators.opFlattenAsync;
12
- //# sourceMappingURL=async.js.map
@@ -1,20 +0,0 @@
1
- import type { FileResult } from '../../util/fileHelper.js';
2
- export interface CSpellLintResultCache {
3
- /**
4
- * Retrieve cached lint results for a given file name, if present in the cache.
5
- */
6
- getCachedLintResults(filename: string): Promise<FileResult | undefined>;
7
- /**
8
- * Set the cached lint results.
9
- */
10
- setCachedLintResults(result: FileResult, dependsUponFiles: string[]): void;
11
- /**
12
- * Persists the in-memory cache to disk.
13
- */
14
- reconcile(): void;
15
- /**
16
- * Resets the cache.
17
- */
18
- reset(): void;
19
- }
20
- //# sourceMappingURL=CSpellLintResultCache.d.ts.map
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=CSpellLintResultCache.js.map
@@ -1,34 +0,0 @@
1
- import type { CacheFormat, CacheStrategy } from '@cspell/cspell-types';
2
- export interface CacheOptions {
3
- /**
4
- * The version of `cspell` that made the cache entry.
5
- * Cache entries must match the `major.minor` version.
6
- */
7
- version: string;
8
- /**
9
- * Store the info about processed files in order to only operate on the changed ones.
10
- */
11
- cache?: boolean;
12
- /**
13
- * Path to the cache location. Can be a file or a directory.
14
- * If none specified .cspellcache will be used.
15
- * The file will be created in the directory where the cspell command is executed.
16
- */
17
- cacheLocation?: string;
18
- /**
19
- * Strategy to use for detecting changed files, default: metadata
20
- */
21
- cacheStrategy?: CacheStrategy;
22
- /**
23
- * Resets the cache
24
- */
25
- cacheReset?: boolean;
26
- /**
27
- * Format of the cache file.
28
- * - `legacy` - use absolute paths in the cache file
29
- * - `universal` - use a sharable format.
30
- * @default 'legacy'
31
- */
32
- cacheFormat?: CacheFormat;
33
- }
34
- //# sourceMappingURL=CacheOptions.d.ts.map
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=CacheOptions.js.map
@@ -1,63 +0,0 @@
1
- import type { FileResult } from '../../util/fileHelper.js';
2
- import type { CSpellLintResultCache } from './CSpellLintResultCache.js';
3
- import type { FileDescriptor } from './fileEntryCache.js';
4
- export type CachedFileResult = Omit<FileResult, 'fileInfo' | 'elapsedTimeMs' | 'cached'>;
5
- /**
6
- * This is the data cached.
7
- * Property names are short to help keep the cache file size small.
8
- */
9
- interface CachedData {
10
- /** meta version + suffix */
11
- v?: string | undefined;
12
- /** results */
13
- r?: CachedFileResult | undefined;
14
- /** dependencies */
15
- d?: Dependency[] | undefined;
16
- }
17
- interface Dependency {
18
- /** filename */
19
- f: string;
20
- /** hash of file contents */
21
- h?: string | undefined;
22
- }
23
- interface CSpellCachedMetaData {
24
- data?: CachedData;
25
- }
26
- type Meta = FileDescriptor['meta'];
27
- export type CSpellCacheMeta = (Meta & CSpellCachedMetaData) | undefined;
28
- /**
29
- * Caches cspell results on disk
30
- */
31
- export declare class DiskCache implements CSpellLintResultCache {
32
- readonly useCheckSum: boolean;
33
- readonly cspellVersion: string;
34
- readonly useUniversalCache: boolean;
35
- readonly cacheFileLocation: string;
36
- private cacheDir;
37
- private fileEntryCache;
38
- private dependencyCache;
39
- private dependencyCacheTree;
40
- private objectCollection;
41
- private ocCacheFileResult;
42
- readonly version: string;
43
- constructor(cacheFileLocation: string, useCheckSum: boolean, cspellVersion: string, useUniversalCache: boolean);
44
- getCachedLintResults(filename: string): Promise<FileResult | undefined>;
45
- setCachedLintResults({ fileInfo, elapsedTimeMs, cached, ...result }: FileResult, dependsUponFiles: string[]): void;
46
- reconcile(): void;
47
- reset(): void;
48
- private normalizeResult;
49
- private calcDependencyHashes;
50
- private checkDependency;
51
- private getDependency;
52
- private getFileDep;
53
- private checkDependencies;
54
- private getHash;
55
- private resolveFile;
56
- private toRelFile;
57
- }
58
- declare function calcVersion(version: string): string;
59
- export declare const __testing__: {
60
- calcVersion: typeof calcVersion;
61
- };
62
- export {};
63
- //# sourceMappingURL=DiskCache.d.ts.map
@@ -1,237 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.__testing__ = exports.DiskCache = void 0;
30
- const assert_1 = __importDefault(require("assert"));
31
- const crypto = __importStar(require("crypto"));
32
- const fs = __importStar(require("fs"));
33
- const path_1 = require("path");
34
- const fileHelper_js_1 = require("../../util/fileHelper.js");
35
- const fileEntryCache_js_1 = require("./fileEntryCache.js");
36
- const ObjectCollection_js_1 = require("./ObjectCollection.js");
37
- const cacheDataKeys = {
38
- v: 'v',
39
- r: 'r',
40
- d: 'd',
41
- };
42
- /**
43
- * Meta Data Version is used to detect if the structure of the meta data has changed.
44
- * This is used in combination with the Suffix and the version of CSpell.
45
- */
46
- const META_DATA_BASE_VERSION = '1';
47
- const META_DATA_VERSION_SUFFIX = '-' + META_DATA_BASE_VERSION + '-' + Object.keys(cacheDataKeys).join('|');
48
- /**
49
- * Caches cspell results on disk
50
- */
51
- class DiskCache {
52
- constructor(cacheFileLocation, useCheckSum, cspellVersion, useUniversalCache) {
53
- this.useCheckSum = useCheckSum;
54
- this.cspellVersion = cspellVersion;
55
- this.useUniversalCache = useUniversalCache;
56
- this.dependencyCache = new Map();
57
- this.dependencyCacheTree = {};
58
- this.objectCollection = new ObjectCollection_js_1.ShallowObjectCollection();
59
- this.ocCacheFileResult = new ObjectCollection_js_1.ShallowObjectCollection();
60
- this.cacheFileLocation = (0, path_1.resolve)(cacheFileLocation);
61
- this.cacheDir = (0, path_1.dirname)(this.cacheFileLocation);
62
- this.fileEntryCache = (0, fileEntryCache_js_1.createFromFile)(this.cacheFileLocation, useCheckSum, useUniversalCache);
63
- this.version = calcVersion(cspellVersion);
64
- }
65
- async getCachedLintResults(filename) {
66
- filename = (0, fileEntryCache_js_1.normalizePath)(filename);
67
- const fileDescriptor = this.fileEntryCache.getFileDescriptor(filename);
68
- const meta = fileDescriptor.meta;
69
- const data = meta?.data;
70
- const result = data?.r;
71
- const versionMatches = this.version === data?.v;
72
- // Cached lint results are valid if and only if:
73
- // 1. The file is present in the filesystem
74
- // 2. The file has not changed since the time it was previously linted
75
- // 3. The CSpell configuration has not changed since the time the file was previously linted
76
- // If any of these are not true, we will not reuse the lint results.
77
- if (fileDescriptor.notFound ||
78
- fileDescriptor.changed ||
79
- !meta ||
80
- !result ||
81
- !versionMatches ||
82
- !this.checkDependencies(data.d)) {
83
- return undefined;
84
- }
85
- const dd = { ...data };
86
- if (dd.d) {
87
- dd.d = setTreeEntry(this.dependencyCacheTree, dd.d);
88
- }
89
- dd.r = dd.r && this.normalizeResult(dd.r);
90
- meta.data = this.objectCollection.get(dd);
91
- // Skip reading empty files and files without lint error
92
- const hasErrors = !!result && (result.errors > 0 || result.configErrors > 0 || result.issues.length > 0);
93
- const cached = true;
94
- const shouldReadFile = cached && hasErrors;
95
- return {
96
- ...result,
97
- elapsedTimeMs: undefined,
98
- fileInfo: shouldReadFile ? await (0, fileHelper_js_1.readFileInfo)(filename) : { filename },
99
- cached,
100
- };
101
- }
102
- setCachedLintResults({ fileInfo, elapsedTimeMs: _, cached: __, ...result }, dependsUponFiles) {
103
- const fileDescriptor = this.fileEntryCache.getFileDescriptor(fileInfo.filename);
104
- const meta = fileDescriptor.meta;
105
- if (fileDescriptor.notFound || !meta) {
106
- return;
107
- }
108
- const data = this.objectCollection.get({
109
- v: this.version,
110
- r: this.normalizeResult(result),
111
- d: this.calcDependencyHashes(dependsUponFiles),
112
- });
113
- meta.data = data;
114
- }
115
- reconcile() {
116
- this.fileEntryCache.reconcile();
117
- }
118
- reset() {
119
- this.fileEntryCache.destroy();
120
- this.dependencyCache.clear();
121
- this.dependencyCacheTree = {};
122
- this.objectCollection = new ObjectCollection_js_1.ShallowObjectCollection();
123
- this.ocCacheFileResult = new ObjectCollection_js_1.ShallowObjectCollection();
124
- }
125
- normalizeResult(result) {
126
- const { issues, processed, errors, configErrors, ...rest } = result;
127
- if (!Object.keys(rest).length) {
128
- return this.ocCacheFileResult.get(result);
129
- }
130
- return this.ocCacheFileResult.get({ issues, processed, errors, configErrors });
131
- }
132
- calcDependencyHashes(dependsUponFiles) {
133
- dependsUponFiles.sort();
134
- const c = getTreeEntry(this.dependencyCacheTree, dependsUponFiles);
135
- if (c?.d) {
136
- return c.d;
137
- }
138
- const dependencies = dependsUponFiles.map((f) => this.getDependency(f));
139
- return setTreeEntry(this.dependencyCacheTree, dependencies);
140
- }
141
- checkDependency(dep) {
142
- const depFile = this.resolveFile(dep.f);
143
- const cDep = this.dependencyCache.get(depFile);
144
- if (cDep && compDep(dep, cDep))
145
- return true;
146
- if (cDep)
147
- return false;
148
- const d = this.getFileDep(depFile);
149
- if (compDep(dep, d)) {
150
- this.dependencyCache.set(depFile, dep);
151
- return true;
152
- }
153
- this.dependencyCache.set(depFile, d);
154
- return false;
155
- }
156
- getDependency(file) {
157
- const dep = this.dependencyCache.get(file);
158
- if (dep)
159
- return dep;
160
- const d = this.getFileDep(file);
161
- this.dependencyCache.set(file, d);
162
- return d;
163
- }
164
- getFileDep(file) {
165
- (0, assert_1.default)((0, path_1.isAbsolute)(file), `Dependency must be absolute "${file}"`);
166
- const f = this.toRelFile(file);
167
- let h;
168
- try {
169
- const buffer = fs.readFileSync(file);
170
- h = this.getHash(buffer);
171
- }
172
- catch (e) {
173
- return { f };
174
- }
175
- return { f, h };
176
- }
177
- checkDependencies(dependencies) {
178
- if (!dependencies)
179
- return false;
180
- for (const dep of dependencies) {
181
- if (!this.checkDependency(dep)) {
182
- return false;
183
- }
184
- }
185
- return true;
186
- }
187
- getHash(buffer) {
188
- return crypto.createHash('md5').update(buffer).digest('hex');
189
- }
190
- resolveFile(file) {
191
- return (0, fileEntryCache_js_1.normalizePath)((0, path_1.resolve)(this.cacheDir, file));
192
- }
193
- toRelFile(file) {
194
- return (0, fileEntryCache_js_1.normalizePath)(this.useUniversalCache ? (0, path_1.relative)(this.cacheDir, file) : file);
195
- }
196
- }
197
- exports.DiskCache = DiskCache;
198
- function getTreeEntry(tree, keys) {
199
- let r = tree;
200
- for (const k of keys) {
201
- r = r.c?.get(k);
202
- if (!r)
203
- return r;
204
- }
205
- return r;
206
- }
207
- function setTreeEntry(tree, deps, update = false) {
208
- let r = tree;
209
- for (const d of deps) {
210
- const k = d.f;
211
- if (!r.c) {
212
- r.c = new Map();
213
- }
214
- const cn = r.c.get(k);
215
- const n = cn ?? {};
216
- if (!cn) {
217
- r.c.set(k, n);
218
- }
219
- r = n;
220
- }
221
- let d = r.d;
222
- if (!d || (r.d && update)) {
223
- r.d = deps;
224
- d = deps;
225
- }
226
- return d;
227
- }
228
- function compDep(a, b) {
229
- return a.f === b.f && a.h === b.h;
230
- }
231
- function calcVersion(version) {
232
- return version + META_DATA_VERSION_SUFFIX;
233
- }
234
- exports.__testing__ = {
235
- calcVersion,
236
- };
237
- //# sourceMappingURL=DiskCache.js.map
@@ -1,11 +0,0 @@
1
- import type { CSpellLintResultCache } from './CSpellLintResultCache.js';
2
- /**
3
- * Dummy cache implementation that should be usd if caching option is disabled.
4
- */
5
- export declare class DummyCache implements CSpellLintResultCache {
6
- getCachedLintResults(): Promise<undefined>;
7
- setCachedLintResults(): void;
8
- reconcile(): void;
9
- reset(): void;
10
- }
11
- //# sourceMappingURL=DummyCache.d.ts.map
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DummyCache = void 0;
4
- /**
5
- * Dummy cache implementation that should be usd if caching option is disabled.
6
- */
7
- class DummyCache {
8
- getCachedLintResults() {
9
- return Promise.resolve(undefined);
10
- }
11
- setCachedLintResults() {
12
- return;
13
- }
14
- reconcile() {
15
- return;
16
- }
17
- reset() {
18
- return;
19
- }
20
- }
21
- exports.DummyCache = DummyCache;
22
- //# sourceMappingURL=DummyCache.js.map
@@ -1,17 +0,0 @@
1
- export declare class ShallowObjectCollection<T extends object> {
2
- private tree;
3
- get(v: T): T;
4
- }
5
- export declare class Collection {
6
- private col;
7
- /**
8
- * Add a plain object to the collection.
9
- * The actual object used is returned.
10
- * By adding the object to the collection, it is now owned by the collection.
11
- * Do not add class objects.
12
- * @param v any object or primitive
13
- * @returns v or the matching object.
14
- */
15
- add<T>(v: T): T;
16
- }
17
- //# sourceMappingURL=ObjectCollection.d.ts.map