cspell 5.14.0 → 5.15.3

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.
package/README.md CHANGED
@@ -56,6 +56,12 @@ cspell lint "src/**/*.js"
56
56
  cspell "**"
57
57
  ```
58
58
 
59
+ **Git: Check Only Changed Files**
60
+
61
+ ```sh
62
+ git diff --name-only | npx cspell --file-list stdin
63
+ ```
64
+
59
65
  ## Command: `lint` -- Spell Checking
60
66
 
61
67
  The `lint` command is used for spell checking files.
@@ -110,8 +116,8 @@ Options:
110
116
  --show-suggestions Show spelling suggestions.
111
117
  --no-must-find-files Do not error if no files are found.
112
118
 
113
- --cache Only check changed files. (default: false)
114
-
119
+ --cache Use cache to only check changed files.
120
+ --no-cache Do not use cache.
115
121
  --cache-strategy <strategy> Strategy to use for detecting changed files.
116
122
  (choices: "metadata", "content")
117
123
 
@@ -73,12 +73,13 @@ function commandLint(prog) {
73
73
  // .option('--force', 'Force the exit value to always be 0')
74
74
  .addOption(new commander_1.Option('--legacy', 'Legacy output').hideHelp())
75
75
  .addOption(new commander_1.Option('--local <local>', 'Deprecated -- Use: --locale').hideHelp())
76
- .option('--cache', 'Only check changed files.', false)
76
+ .option('--cache', 'Use cache to only check changed files.')
77
+ .option('--no-cache', 'Do not use cache.')
77
78
  .addOption(new commander_1.Option('--cache-strategy <strategy>', 'Strategy to use for detecting changed files.').choices([
78
79
  'metadata',
79
80
  'content',
80
81
  ]))
81
- .option('--cache-location <path>', `Path to the cache file or directory.`, cache_1.DEFAULT_CACHE_LOCATION)
82
+ .option('--cache-location <path>', `Path to the cache file or directory. (default: "${cache_1.DEFAULT_CACHE_LOCATION}")`)
82
83
  .option('--dot', 'Include files and directories starting with `.` (period) when matching globs.')
83
84
  .option('--gitignore', 'Ignore files matching glob patterns found in .gitignore files.')
84
85
  .option('--no-gitignore', 'Do NOT use .gitignore files.')
@@ -14,6 +14,7 @@ export declare function readConfig(configFile: string | undefined, root: string
14
14
  export interface FileInfo {
15
15
  filename: string;
16
16
  text?: string;
17
+ errorCode?: string;
17
18
  }
18
19
  export interface FileResult {
19
20
  fileInfo: FileInfo;
@@ -25,7 +26,10 @@ export interface FileResult {
25
26
  cached?: boolean;
26
27
  }
27
28
  export declare function fileInfoToDocument(fileInfo: FileInfo, languageId: string | undefined, locale: string | undefined): Document;
28
- export declare function readFileInfo(filename: string, encoding?: string): Promise<Required<FileInfo>>;
29
+ interface ReadFileInfoResult extends FileInfo {
30
+ text: string;
31
+ }
32
+ export declare function readFileInfo(filename: string, encoding?: string, handleNotFound?: boolean): Promise<ReadFileInfoResult>;
29
33
  export declare function readFile(filename: string, encoding?: string): Promise<string>;
30
34
  /**
31
35
  * Looks for matching glob patterns or stdin
@@ -47,4 +51,5 @@ export declare function readFileListFiles(listFiles: string[]): Promise<string[]
47
51
  * @returns - a list of files to be processed.
48
52
  */
49
53
  export declare function readFileListFile(listFile: string): Promise<string[]>;
54
+ export {};
50
55
  //# sourceMappingURL=fileHelper.d.ts.map
@@ -57,12 +57,15 @@ function fileInfoToDocument(fileInfo, languageId, locale) {
57
57
  return (0, cspell_lib_1.fileToDocument)(filename, text, languageId, locale);
58
58
  }
59
59
  exports.fileInfoToDocument = fileInfoToDocument;
60
- function readFileInfo(filename, encoding = UTF8) {
60
+ function readFileInfo(filename, encoding = UTF8, handleNotFound = false) {
61
61
  const pText = filename === STDIN ? (0, get_stdin_1.default)() : fsp.readFile(filename, encoding);
62
- return pText.then((text) => ({ text, filename }), (error) => {
63
- return error.code === 'EISDIR'
64
- ? Promise.resolve({ text: '', filename })
65
- : Promise.reject((0, errors_1.toApplicationError)(error, `Error reading file: "${filename}"`));
62
+ return pText.then((text) => ({ text, filename }), (e) => {
63
+ const error = (0, errors_1.toError)(e);
64
+ return handleNotFound && error.code === 'EISDIR'
65
+ ? Promise.resolve({ text: '', filename, errorCode: error.code })
66
+ : handleNotFound && error.code === 'ENOENT'
67
+ ? Promise.resolve({ text: '', filename, errorCode: error.code })
68
+ : Promise.reject(new errors_1.IOError(`Error reading file: "${filename}"`, error));
66
69
  });
67
70
  }
68
71
  exports.readFileInfo = readFileInfo;
package/dist/lint/lint.js CHANGED
@@ -45,23 +45,34 @@ async function runLint(cfg) {
45
45
  return lintResult;
46
46
  async function processFile(filename, configInfo, cache) {
47
47
  var _a, _b, _c, _d;
48
- const cachedResult = await cache.getCachedLintResults(filename, configInfo);
48
+ const cachedResult = await cache.getCachedLintResults(filename);
49
49
  if (cachedResult) {
50
50
  reporter.debug(`Filename: ${filename}, using cache`);
51
51
  return cachedResult;
52
52
  }
53
- const fileInfo = await (0, fileHelper_1.readFileInfo)(filename);
54
- const doc = (0, fileHelper_1.fileInfoToDocument)(fileInfo, cfg.options.languageId, cfg.locale);
55
- const { text } = fileInfo;
56
- reporter.debug(`Filename: ${filename}, LanguageIds: ${(_a = doc.languageId) !== null && _a !== void 0 ? _a : 'default'}`);
57
53
  const result = {
58
- fileInfo,
54
+ fileInfo: {
55
+ filename,
56
+ },
59
57
  issues: [],
60
58
  processed: false,
61
59
  errors: 0,
62
60
  configErrors: 0,
63
61
  elapsedTimeMs: 0,
64
62
  };
63
+ const fileInfo = await (0, fileHelper_1.readFileInfo)(filename, undefined, true);
64
+ if (fileInfo.errorCode) {
65
+ if (fileInfo.errorCode !== 'EISDIR' && cfg.options.mustFindFiles) {
66
+ const err = (0, errors_1.toError)(`File not found: "${filename}"`);
67
+ reporter.error('Linter:', err);
68
+ result.errors += 1;
69
+ }
70
+ return result;
71
+ }
72
+ const doc = (0, fileHelper_1.fileInfoToDocument)(fileInfo, cfg.options.languageId, cfg.locale);
73
+ const { text } = fileInfo;
74
+ reporter.debug(`Filename: ${filename}, LanguageIds: ${(_a = doc.languageId) !== null && _a !== void 0 ? _a : 'default'}`);
75
+ result.fileInfo = fileInfo;
65
76
  const getElapsedTimeMs = (0, timer_1.getTimeMeasurer)();
66
77
  let spellResult = {};
67
78
  reporter.info(`Checking: ${filename}, File type: ${(_b = doc.languageId) !== null && _b !== void 0 ? _b : 'auto'}, Language: ${(_c = doc.locale) !== null && _c !== void 0 ? _c : 'default'}`, cspell_types_1.MessageTypes.Info);
@@ -86,7 +97,8 @@ async function runLint(cfg) {
86
97
  reporter.info(`Checked: ${filename}, File type: ${config.languageId}, Language: ${config.language} ... Issues: ${result.issues.length} ${elapsed}S`, cspell_types_1.MessageTypes.Info);
87
98
  reporter.info(`Config file Used: ${spellResult.localConfigFilepath || configInfo.source}`, cspell_types_1.MessageTypes.Info);
88
99
  reporter.info(`Dictionaries Used: ${dictionaries.join(', ')}`, cspell_types_1.MessageTypes.Info);
89
- cache.setCachedLintResults(result, configInfo);
100
+ const dep = calcDependencies(config);
101
+ cache.setCachedLintResults(result, dep.files);
90
102
  return result;
91
103
  }
92
104
  function mapIssue({ doc: _, ...tdo }) {
@@ -95,9 +107,10 @@ async function runLint(cfg) {
95
107
  : { text: tdo.line.text.trimEnd(), offset: tdo.line.offset };
96
108
  return { ...tdo, context };
97
109
  }
98
- async function processFiles(files, configInfo, fileCount) {
110
+ async function processFiles(files, configInfo, cacheSettings) {
111
+ const fileCount = files.length;
99
112
  const status = runResult();
100
- const cache = (0, cache_1.createCache)({ ...cfg.options, root: cfg.root });
113
+ const cache = (0, cache_1.createCache)(cacheSettings);
101
114
  const emitProgress = (filename, fileNum, result) => reporter.progress({
102
115
  type: 'ProgressFileComplete',
103
116
  fileNum,
@@ -105,7 +118,7 @@ async function runLint(cfg) {
105
118
  filename,
106
119
  elapsedTimeMs: result === null || result === void 0 ? void 0 : result.elapsedTimeMs,
107
120
  processed: result === null || result === void 0 ? void 0 : result.processed,
108
- numErrors: result === null || result === void 0 ? void 0 : result.issues.length,
121
+ numErrors: (result === null || result === void 0 ? void 0 : result.issues.length) || (result === null || result === void 0 ? void 0 : result.errors),
109
122
  cached: result === null || result === void 0 ? void 0 : result.cached,
110
123
  });
111
124
  async function* loadAndProcessFiles() {
@@ -117,12 +130,8 @@ async function runLint(cfg) {
117
130
  }
118
131
  for await (const fileP of loadAndProcessFiles()) {
119
132
  const { filename, fileNum, result } = await fileP;
120
- if (!result.fileInfo.text === undefined) {
121
- status.files += result.cached ? 1 : 0;
122
- emitProgress(filename, fileNum, result);
123
- continue;
124
- }
125
133
  status.files += 1;
134
+ status.cachedFiles = (status.cachedFiles || 0) + (result.cached ? 1 : 0);
126
135
  emitProgress(filename, fileNum, result);
127
136
  // Show the spelling errors after emitting the progress.
128
137
  result.issues.filter(cfg.uniqueFilter).forEach((issue) => reporter.issue(issue));
@@ -136,6 +145,10 @@ async function runLint(cfg) {
136
145
  cache.reconcile();
137
146
  return status;
138
147
  }
148
+ function calcDependencies(config) {
149
+ const { configFiles, dictionaryFiles } = cspell.extractDependencies(config);
150
+ return { files: configFiles.concat(dictionaryFiles) };
151
+ }
139
152
  async function reportConfigurationErrors(config) {
140
153
  const errors = cspell.extractImportErrors(config);
141
154
  let count = 0;
@@ -212,12 +225,13 @@ async function runLint(cfg) {
212
225
  globOptions.dot = enableGlobDot;
213
226
  }
214
227
  try {
228
+ const cacheSettings = await (0, cache_1.calcCacheSettings)(configInfo.config, cfg.options, root);
215
229
  const foundFiles = await (hasFileLists
216
230
  ? useFileLists(fileLists, allGlobs, root, enableGlobDot)
217
231
  : (0, fileHelper_1.findFiles)(fileGlobs, globOptions));
218
232
  const filtered = gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles;
219
233
  const files = filterFiles(filtered, globMatcher);
220
- return await processFiles(files, configInfo, files.length);
234
+ return await processFiles(files, configInfo, cacheSettings);
221
235
  }
222
236
  catch (e) {
223
237
  const err = (0, errors_1.toApplicationError)(e);
@@ -300,8 +314,8 @@ function extractContext(tdo, contextRange) {
300
314
  return context;
301
315
  }
302
316
  function runResult(init = {}) {
303
- const { files = 0, filesWithIssues = new Set(), issues = 0, errors = 0 } = init;
304
- return { files, filesWithIssues, issues, errors };
317
+ const { files = 0, filesWithIssues = new Set(), issues = 0, errors = 0, cachedFiles = 0 } = init;
318
+ return { files, filesWithIssues, issues, errors, cachedFiles };
305
319
  }
306
320
  function yesNo(value) {
307
321
  return value ? 'Yes' : 'No';
package/dist/options.d.ts CHANGED
@@ -54,15 +54,31 @@ export interface LinterOptions extends BaseOptions, CacheOptions {
54
54
  * - an entry of `stdin` means to read the file list from **`stdin`**
55
55
  */
56
56
  fileLists?: string[] | undefined;
57
+ /**
58
+ * Files must be found and processed otherwise it is considered an error.
59
+ */
60
+ mustFindFiles?: boolean;
57
61
  }
58
62
  export interface TraceOptions extends BaseOptions {
59
63
  allowCompoundWords?: boolean;
60
64
  ignoreCase?: boolean;
61
65
  }
62
66
  export interface BaseOptions {
67
+ /**
68
+ * Path to configuration file.
69
+ */
63
70
  config?: string;
71
+ /**
72
+ * Programming Language ID.
73
+ */
64
74
  languageId?: string;
75
+ /**
76
+ * Locale to use.
77
+ */
65
78
  locale?: string;
79
+ /**
80
+ * @deprecated
81
+ */
66
82
  local?: string;
67
83
  }
68
84
  export interface LinterCliOptions extends Omit<LinterOptions, 'fileLists'> {
@@ -1,13 +1,13 @@
1
- import { ConfigInfo, FileResult } from '../../fileHelper';
1
+ import { FileResult } from '../../fileHelper';
2
2
  export interface CSpellLintResultCache {
3
3
  /**
4
4
  * Retrieve cached lint results for a given file name, if present in the cache.
5
5
  */
6
- getCachedLintResults(filename: string, configInfo: ConfigInfo): Promise<FileResult | undefined>;
6
+ getCachedLintResults(filename: string): Promise<FileResult | undefined>;
7
7
  /**
8
8
  * Set the cached lint results.
9
9
  */
10
- setCachedLintResults(result: FileResult, configInfo: ConfigInfo): void;
10
+ setCachedLintResults(result: FileResult, dependsUponFiles: string[]): void;
11
11
  /**
12
12
  * Persists the in-memory cache to disk.
13
13
  */
@@ -1,3 +1,4 @@
1
+ import type { CacheStrategy } from '@cspell/cspell-types';
1
2
  export interface CacheOptions {
2
3
  /**
3
4
  * Store the info about processed files in order to only operate on the changed ones.
@@ -12,6 +13,6 @@ export interface CacheOptions {
12
13
  /**
13
14
  * Strategy to use for detecting changed files, default: metadata
14
15
  */
15
- cacheStrategy?: 'metadata' | 'content';
16
+ cacheStrategy?: CacheStrategy;
16
17
  }
17
18
  //# sourceMappingURL=CacheOptions.d.ts.map
@@ -1,13 +1,34 @@
1
- import type { ConfigInfo, FileResult } from '../../fileHelper';
1
+ import type { FileDescriptor } from 'file-entry-cache';
2
+ import type { FileResult } from '../../fileHelper';
2
3
  import type { CSpellLintResultCache } from './CSpellLintResultCache';
4
+ export declare type CachedFileResult = Omit<FileResult, 'fileInfo' | 'elapsedTimeMs'>;
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
+ /** results */
11
+ r: CachedFileResult;
12
+ /** dependencies */
13
+ d: string[];
14
+ }
15
+ interface CSpellCachedMetaData {
16
+ data?: CachedData;
17
+ }
18
+ export declare type CSpellCacheMeta = (FileDescriptor['meta'] & CSpellCachedMetaData) | undefined;
3
19
  /**
4
20
  * Caches cspell results on disk
5
21
  */
6
22
  export declare class DiskCache implements CSpellLintResultCache {
7
23
  private fileEntryCache;
24
+ private changedDependencies;
25
+ private knownDependencies;
8
26
  constructor(cacheFileLocation: string, useCheckSum: boolean);
9
- getCachedLintResults(filename: string, configInfo: ConfigInfo): Promise<FileResult | undefined>;
10
- setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result }: FileResult, configInfo: ConfigInfo): void;
27
+ getCachedLintResults(filename: string): Promise<FileResult | undefined>;
28
+ setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result }: FileResult, dependsUponFiles: string[]): void;
11
29
  reconcile(): void;
30
+ private cacheDependencies;
31
+ private checkDependencies;
12
32
  }
33
+ export {};
13
34
  //# sourceMappingURL=DiskCache.d.ts.map
@@ -1,53 +1,95 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.DiskCache = void 0;
4
- const file_entry_cache_1 = require("file-entry-cache");
23
+ const fileEntryCache = __importStar(require("file-entry-cache"));
24
+ const path_1 = require("path");
5
25
  const fileHelper_1 = require("../../fileHelper");
6
- const getConfigHash_1 = require("./getConfigHash");
7
26
  /**
8
27
  * Caches cspell results on disk
9
28
  */
10
29
  class DiskCache {
11
30
  constructor(cacheFileLocation, useCheckSum) {
12
- this.fileEntryCache = (0, file_entry_cache_1.create)(cacheFileLocation, undefined, useCheckSum);
31
+ this.changedDependencies = new Set();
32
+ this.knownDependencies = new Set();
33
+ this.fileEntryCache = fileEntryCache.createFromFile((0, path_1.resolve)(cacheFileLocation), useCheckSum);
13
34
  }
14
- async getCachedLintResults(filename, configInfo) {
35
+ async getCachedLintResults(filename) {
15
36
  const fileDescriptor = this.fileEntryCache.getFileDescriptor(filename);
16
37
  const meta = fileDescriptor.meta;
38
+ const data = meta === null || meta === void 0 ? void 0 : meta.data;
39
+ const result = data === null || data === void 0 ? void 0 : data.r;
17
40
  // Cached lint results are valid if and only if:
18
41
  // 1. The file is present in the filesystem
19
42
  // 2. The file has not changed since the time it was previously linted
20
43
  // 3. The CSpell configuration has not changed since the time the file was previously linted
21
44
  // If any of these are not true, we will not reuse the lint results.
22
- if (fileDescriptor.notFound ||
23
- fileDescriptor.changed ||
24
- !meta ||
25
- meta.configHash !== (0, getConfigHash_1.getConfigHash)(configInfo)) {
45
+ if (fileDescriptor.notFound || fileDescriptor.changed || !meta || !result || !this.checkDependencies(data.d)) {
26
46
  return undefined;
27
47
  }
28
48
  // Skip reading empty files and files without lint error
29
- const hasErrors = meta.result.errors > 0 || meta.result.configErrors > 0 || meta.result.issues.length > 0;
30
- const cached = !!meta.size;
49
+ const hasErrors = !!result && (result.errors > 0 || result.configErrors > 0 || result.issues.length > 0);
50
+ const cached = true;
31
51
  const shouldReadFile = cached && hasErrors;
32
52
  return {
33
- ...meta.result,
53
+ ...result,
34
54
  elapsedTimeMs: undefined,
35
55
  fileInfo: shouldReadFile ? await (0, fileHelper_1.readFileInfo)(filename) : { filename },
36
56
  cached,
37
57
  };
38
58
  }
39
- setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result }, configInfo) {
59
+ setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result }, dependsUponFiles) {
40
60
  const fileDescriptor = this.fileEntryCache.getFileDescriptor(fileInfo.filename);
41
61
  const meta = fileDescriptor.meta;
42
62
  if (fileDescriptor.notFound || !meta) {
43
63
  return;
44
64
  }
45
- meta.result = result;
46
- meta.configHash = (0, getConfigHash_1.getConfigHash)(configInfo);
65
+ const data = {
66
+ r: result,
67
+ d: dependsUponFiles,
68
+ };
69
+ meta.data = data;
70
+ this.cacheDependencies(dependsUponFiles);
47
71
  }
48
72
  reconcile() {
49
73
  this.fileEntryCache.reconcile();
50
74
  }
75
+ cacheDependencies(files) {
76
+ this.fileEntryCache.analyzeFiles(files);
77
+ }
78
+ checkDependencies(files) {
79
+ for (const file of files) {
80
+ if (this.changedDependencies.has(file)) {
81
+ return false;
82
+ }
83
+ }
84
+ const unknown = files.filter((f) => !this.knownDependencies.has(f));
85
+ if (!unknown.length) {
86
+ return true;
87
+ }
88
+ const { changedFiles, notFoundFiles } = this.fileEntryCache.analyzeFiles(files);
89
+ changedFiles.map((f) => this.changedDependencies.add(f));
90
+ unknown.forEach((f) => this.knownDependencies.add(f));
91
+ return changedFiles.length === 0 && notFoundFiles.length === 0;
92
+ }
51
93
  }
52
94
  exports.DiskCache = DiskCache;
53
95
  //# sourceMappingURL=DiskCache.js.map
@@ -1,11 +1,11 @@
1
- import { CacheOptions } from './CacheOptions';
1
+ import { CacheSettings, CSpellSettings } from '@cspell/cspell-types';
2
+ import { CacheOptions } from '.';
2
3
  import { CSpellLintResultCache } from './CSpellLintResultCache';
3
4
  export declare const DEFAULT_CACHE_LOCATION = ".cspellcache";
4
- export interface CreateCacheOptions extends CacheOptions {
5
- root: string;
6
- }
5
+ export declare type CreateCacheSettings = Required<CacheSettings>;
7
6
  /**
8
7
  * Creates CSpellLintResultCache (disk cache if caching is enabled in config or dummy otherwise)
9
8
  */
10
- export declare function createCache(options: CreateCacheOptions): CSpellLintResultCache;
9
+ export declare function createCache(options: CreateCacheSettings): CSpellLintResultCache;
10
+ export declare function calcCacheSettings(config: CSpellSettings, cacheOptions: CacheOptions, root: string): Promise<CreateCacheSettings>;
11
11
  //# sourceMappingURL=createCache.d.ts.map
@@ -3,18 +3,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createCache = exports.DEFAULT_CACHE_LOCATION = void 0;
6
+ exports.calcCacheSettings = exports.createCache = exports.DEFAULT_CACHE_LOCATION = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const DiskCache_1 = require("./DiskCache");
9
9
  const DummyCache_1 = require("./DummyCache");
10
+ const fs_extra_1 = require("fs-extra");
11
+ const errors_1 = require("../errors");
10
12
  // cspell:word cspellcache
11
13
  exports.DEFAULT_CACHE_LOCATION = '.cspellcache';
12
14
  /**
13
15
  * Creates CSpellLintResultCache (disk cache if caching is enabled in config or dummy otherwise)
14
16
  */
15
17
  function createCache(options) {
16
- const { cache, cacheLocation = exports.DEFAULT_CACHE_LOCATION, cacheStrategy = 'metadata', root } = options;
17
- return cache ? new DiskCache_1.DiskCache(path_1.default.resolve(root, cacheLocation), cacheStrategy === 'content') : new DummyCache_1.DummyCache();
18
+ const { useCache, cacheLocation, cacheStrategy } = options;
19
+ return useCache ? new DiskCache_1.DiskCache(path_1.default.resolve(cacheLocation), cacheStrategy === 'content') : new DummyCache_1.DummyCache();
18
20
  }
19
21
  exports.createCache = createCache;
22
+ async function calcCacheSettings(config, cacheOptions, root) {
23
+ var _a, _b, _c, _d, _e, _f, _g;
24
+ const cs = (_a = config.cache) !== null && _a !== void 0 ? _a : {};
25
+ const useCache = (_c = (_b = cacheOptions.cache) !== null && _b !== void 0 ? _b : cs.useCache) !== null && _c !== void 0 ? _c : false;
26
+ const cacheLocation = await resolveCacheLocation(path_1.default.resolve(root, (_e = (_d = cacheOptions.cacheLocation) !== null && _d !== void 0 ? _d : cs.cacheLocation) !== null && _e !== void 0 ? _e : exports.DEFAULT_CACHE_LOCATION));
27
+ const cacheStrategy = (_g = (_f = cacheOptions.cacheStrategy) !== null && _f !== void 0 ? _f : cs.cacheStrategy) !== null && _g !== void 0 ? _g : 'metadata';
28
+ return {
29
+ useCache,
30
+ cacheLocation,
31
+ cacheStrategy,
32
+ };
33
+ }
34
+ exports.calcCacheSettings = calcCacheSettings;
35
+ async function resolveCacheLocation(cacheLocation) {
36
+ try {
37
+ const s = await (0, fs_extra_1.stat)(cacheLocation);
38
+ if (s.isFile())
39
+ return cacheLocation;
40
+ return path_1.default.join(cacheLocation, exports.DEFAULT_CACHE_LOCATION);
41
+ }
42
+ catch (err) {
43
+ if ((0, errors_1.isError)(err) && err.code === 'ENOENT') {
44
+ return cacheLocation;
45
+ }
46
+ throw err;
47
+ }
48
+ }
20
49
  //# sourceMappingURL=createCache.js.map
@@ -1,5 +1,4 @@
1
- export { createCache, DEFAULT_CACHE_LOCATION } from './createCache';
2
- export type { CreateCacheOptions } from './createCache';
1
+ export { createCache, calcCacheSettings, DEFAULT_CACHE_LOCATION, type CreateCacheSettings } from './createCache';
3
2
  export type { CSpellLintResultCache } from './CSpellLintResultCache';
4
3
  export type { CacheOptions } from './CacheOptions';
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_CACHE_LOCATION = exports.createCache = void 0;
3
+ exports.DEFAULT_CACHE_LOCATION = exports.calcCacheSettings = exports.createCache = void 0;
4
4
  var createCache_1 = require("./createCache");
5
5
  Object.defineProperty(exports, "createCache", { enumerable: true, get: function () { return createCache_1.createCache; } });
6
+ Object.defineProperty(exports, "calcCacheSettings", { enumerable: true, get: function () { return createCache_1.calcCacheSettings; } });
6
7
  Object.defineProperty(exports, "DEFAULT_CACHE_LOCATION", { enumerable: true, get: function () { return createCache_1.DEFAULT_CACHE_LOCATION; } });
7
8
  //# sourceMappingURL=index.js.map
@@ -7,7 +7,17 @@ export declare class ApplicationError extends Error {
7
7
  readonly cause?: Error | undefined;
8
8
  constructor(message: string, exitCode?: number, cause?: Error | undefined);
9
9
  }
10
- export declare function toError(e: unknown): Error;
11
- export declare function isError(e: unknown): e is Error;
10
+ export declare class IOError extends ApplicationError {
11
+ readonly cause: NodeError;
12
+ constructor(message: string, cause: NodeError);
13
+ get code(): string | undefined;
14
+ isNotFound(): boolean;
15
+ }
16
+ export declare function toError(e: unknown): NodeError;
17
+ export declare function isError(e: unknown): e is NodeError;
12
18
  export declare function toApplicationError(e: unknown, message?: string): ApplicationError;
19
+ export interface NodeError extends Error {
20
+ code?: string;
21
+ toString?: () => string;
22
+ }
13
23
  //# sourceMappingURL=errors.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toApplicationError = exports.isError = exports.toError = exports.ApplicationError = exports.CheckFailed = void 0;
3
+ exports.toApplicationError = exports.isError = exports.toError = exports.IOError = exports.ApplicationError = exports.CheckFailed = void 0;
4
4
  const util_1 = require("util");
5
5
  class CheckFailed extends Error {
6
6
  constructor(message, exitCode = 1) {
@@ -17,12 +17,27 @@ class ApplicationError extends Error {
17
17
  }
18
18
  }
19
19
  exports.ApplicationError = ApplicationError;
20
+ class IOError extends ApplicationError {
21
+ constructor(message, cause) {
22
+ super(message, undefined, cause);
23
+ this.cause = cause;
24
+ }
25
+ get code() {
26
+ return this.cause.code;
27
+ }
28
+ isNotFound() {
29
+ return this.cause.code === 'ENOENT';
30
+ }
31
+ }
32
+ exports.IOError = IOError;
20
33
  function toError(e) {
21
34
  if (isError(e))
22
35
  return e;
36
+ const message = (0, util_1.format)(e);
23
37
  return {
24
38
  name: 'error',
25
- message: (0, util_1.format)(e),
39
+ message,
40
+ toString: () => message,
26
41
  };
27
42
  }
28
43
  exports.toError = toError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell",
3
- "version": "5.14.0",
3
+ "version": "5.15.3",
4
4
  "description": "A Spelling Checker for Code!",
5
5
  "funding": "https://github.com/streetsidesoftware/cspell?sponsor=1",
6
6
  "main": "dist/index.js",
@@ -72,9 +72,9 @@
72
72
  "chalk": "^4.1.2",
73
73
  "commander": "^8.3.0",
74
74
  "comment-json": "^4.1.1",
75
- "cspell-gitignore": "^5.14.0",
76
- "cspell-glob": "^5.14.0",
77
- "cspell-lib": "^5.14.0",
75
+ "cspell-gitignore": "^5.15.3",
76
+ "cspell-glob": "^5.15.3",
77
+ "cspell-lib": "^5.15.3",
78
78
  "fast-json-stable-stringify": "^2.1.0",
79
79
  "file-entry-cache": "^6.0.1",
80
80
  "fs-extra": "^10.0.0",
@@ -89,8 +89,8 @@
89
89
  "node": ">=12.13.0"
90
90
  },
91
91
  "devDependencies": {
92
- "@cspell/cspell-json-reporter": "^5.14.0",
93
- "@cspell/cspell-types": "^5.14.0",
92
+ "@cspell/cspell-json-reporter": "^5.15.3",
93
+ "@cspell/cspell-types": "^5.15.3",
94
94
  "@types/file-entry-cache": "^5.0.2",
95
95
  "@types/fs-extra": "^9.0.13",
96
96
  "@types/glob": "^7.2.0",
@@ -98,10 +98,10 @@
98
98
  "@types/micromatch": "^4.0.2",
99
99
  "@types/minimatch": "^3.0.5",
100
100
  "@types/semver": "^7.3.9",
101
- "jest": "^27.4.5",
101
+ "jest": "^27.4.7",
102
102
  "micromatch": "^4.0.4",
103
103
  "minimatch": "^3.0.4",
104
104
  "rimraf": "^3.0.2"
105
105
  },
106
- "gitHead": "8c8dfb70479584839e8035094771762f77118667"
106
+ "gitHead": "8a7c55b7d0b340d3c4e964ba91390a405f2cda2d"
107
107
  }