cspell 5.19.4 → 5.19.7

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.
@@ -43,11 +43,13 @@ function lint(fileGlobs, options, emitters) {
43
43
  }
44
44
  exports.lint = lint;
45
45
  async function* trace(words, options) {
46
+ var _a, _b;
46
47
  options = (0, options_1.fixLegacy)(options);
47
48
  const iWords = options.stdin ? (0, cspell_pipe_1.toAsyncIterable)(words, (0, stdin_1.readStdin)()) : words;
48
49
  const { languageId, locale, allowCompoundWords, ignoreCase } = options;
49
50
  const configFile = await (0, fileHelper_1.readConfig)(options.config, undefined);
50
- const config = (0, cspell_lib_1.mergeSettings)((0, cspell_lib_1.getDefaultSettings)(), (0, cspell_lib_1.getGlobalSettings)(), configFile.config);
51
+ const loadDefault = (_b = (_a = options.defaultConfiguration) !== null && _a !== void 0 ? _a : configFile.config.loadDefaultConfiguration) !== null && _b !== void 0 ? _b : true;
52
+ const config = (0, cspell_lib_1.mergeSettings)((0, cspell_lib_1.getDefaultSettings)(loadDefault), (0, cspell_lib_1.getGlobalSettings)(), configFile.config);
51
53
  yield* (0, cspell_lib_1.traceWordsAsync)(iWords, config, { languageId, locale, ignoreCase, allowCompoundWords });
52
54
  }
53
55
  exports.trace = trace;
@@ -58,6 +60,7 @@ async function checkText(filename, options) {
58
60
  const settingsFromCommandLine = util.clean({
59
61
  languageId: options.languageId || undefined,
60
62
  language: options.locale || options.local || undefined,
63
+ loadDefaultConfiguration: options.defaultConfiguration,
61
64
  });
62
65
  const info = (0, fileHelper_1.calcFinalConfigInfo)(foundSettings, settingsFromCommandLine, filename, text);
63
66
  return (0, cspell_lib_1.checkText)(text, info.configInfo.config);
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.commandCheck = void 0;
27
+ const commander_1 = require("commander");
27
28
  const App = __importStar(require("./application"));
28
29
  const application_1 = require("./application");
29
30
  const errors_1 = require("./util/errors");
@@ -35,6 +36,8 @@ function commandCheck(prog) {
35
36
  .option('-c, --config <cspell.json>', 'Configuration file to use. By default cspell looks for cspell.json in the current directory.')
36
37
  .option('--no-color', 'Turn off color.')
37
38
  .option('--color', 'Force color')
39
+ .addOption(new commander_1.Option('--default-configuration', 'Load the default configuration and dictionaries.').hideHelp())
40
+ .addOption(new commander_1.Option('--no-default-configuration', 'Do not load the default configuration and dictionaries.'))
38
41
  .action(async (files, options) => {
39
42
  let issueCount = 0;
40
43
  for (const filename of files) {
@@ -81,6 +81,7 @@ function commandLint(prog) {
81
81
  .addOption(new commander_1.Option('--local <local>', 'Deprecated -- Use: --locale').hideHelp())
82
82
  .option('--cache', 'Use cache to only check changed files.')
83
83
  .option('--no-cache', 'Do not use cache.')
84
+ .option('--cache-reset', 'Reset the cache file.')
84
85
  .addOption(new commander_1.Option('--cache-strategy <strategy>', 'Strategy to use for detecting changed files.').choices([
85
86
  'metadata',
86
87
  'content',
@@ -92,6 +93,8 @@ function commandLint(prog) {
92
93
  .option('--gitignore-root <path>', 'Prevent searching for .gitignore files past root.', collect)
93
94
  .option('--no-color', 'Turn off color.')
94
95
  .option('--color', 'Force color.')
96
+ .addOption(new commander_1.Option('--default-configuration', 'Load the default configuration and dictionaries.').hideHelp())
97
+ .addOption(new commander_1.Option('--no-default-configuration', 'Do not load the default configuration and dictionaries.'))
95
98
  .option('--debug', 'Output information useful for debugging cspell.json files.')
96
99
  .addHelpText('after', usage)
97
100
  .arguments('[globs...]')
@@ -43,6 +43,8 @@ function commandTrace(prog) {
43
43
  .option('--stdin', 'Read words from stdin.')
44
44
  .option('--no-color', 'Turn off color.')
45
45
  .option('--color', 'Force color')
46
+ .addOption(new commander_1.Option('--default-configuration', 'Load the default configuration and dictionaries.').hideHelp())
47
+ .addOption(new commander_1.Option('--no-default-configuration', 'Do not load the default configuration and dictionaries.'))
46
48
  .arguments('[words...]')
47
49
  .action(async (words, options) => {
48
50
  let numFound = 0;
package/dist/lint/lint.js CHANGED
@@ -43,6 +43,7 @@ const chalk = require("chalk");
43
43
  // eslint-disable-next-line @typescript-eslint/no-var-requires
44
44
  const npmPackage = require('../../package.json');
45
45
  const version = npmPackage.version;
46
+ const { opFilterAsync } = cspell_pipe_1.operators;
46
47
  async function runLint(cfg) {
47
48
  let { reporter } = cfg;
48
49
  cspell.setLogger(getLoggerFromReporter(reporter));
@@ -51,7 +52,7 @@ async function runLint(cfg) {
51
52
  await reporter.result(lintResult);
52
53
  return lintResult;
53
54
  async function processFile(filename, configInfo, cache) {
54
- var _a, _b, _c, _d;
55
+ var _a, _b, _c, _d, _e;
55
56
  const getElapsedTimeMs = (0, timer_1.getTimeMeasurer)();
56
57
  const cachedResult = await cache.getCachedLintResults(filename);
57
58
  if (cachedResult) {
@@ -79,10 +80,9 @@ async function runLint(cfg) {
79
80
  }
80
81
  const doc = (0, fileHelper_1.fileInfoToDocument)(fileInfo, cfg.options.languageId, cfg.locale);
81
82
  const { text } = fileInfo;
82
- reporter.debug(`Filename: ${filename}, LanguageIds: ${(_a = doc.languageId) !== null && _a !== void 0 ? _a : 'default'}`);
83
83
  result.fileInfo = fileInfo;
84
84
  let spellResult = {};
85
- 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);
85
+ reporter.info(`Checking: ${filename}, File type: ${(_a = doc.languageId) !== null && _a !== void 0 ? _a : 'auto'}, Language: ${(_b = doc.locale) !== null && _b !== void 0 ? _b : 'default'}`, cspell_types_1.MessageTypes.Info);
86
86
  try {
87
87
  const validateOptions = { generateSuggestions: cfg.options.showSuggestions, numSuggestions: 5 };
88
88
  const r = await cspell.spellCheckDocument(doc, validateOptions, configInfo.config);
@@ -95,18 +95,23 @@ async function runLint(cfg) {
95
95
  result.errors += 1;
96
96
  }
97
97
  result.elapsedTimeMs = getElapsedTimeMs();
98
- const config = (_d = spellResult.settingsUsed) !== null && _d !== void 0 ? _d : {};
98
+ const config = (_c = spellResult.settingsUsed) !== null && _c !== void 0 ? _c : {};
99
99
  result.configErrors += await reportConfigurationErrors(config);
100
- if (cfg.options.debug) {
101
- const { id: _id, name: _name, ...cfg } = config;
102
- const debugCfg = { config: { ...cfg, source: null }, source: spellResult.localConfigFilepath };
103
- reporter.debug(JSON.stringify(debugCfg, undefined, 2));
104
- }
105
100
  const elapsed = result.elapsedTimeMs / 1000.0;
106
101
  const dictionaries = config.dictionaries || [];
107
102
  reporter.info(`Checked: ${filename}, File type: ${config.languageId}, Language: ${config.language} ... Issues: ${result.issues.length} ${elapsed}S`, cspell_types_1.MessageTypes.Info);
108
103
  reporter.info(`Config file Used: ${spellResult.localConfigFilepath || configInfo.source}`, cspell_types_1.MessageTypes.Info);
109
104
  reporter.info(`Dictionaries Used: ${dictionaries.join(', ')}`, cspell_types_1.MessageTypes.Info);
105
+ if (cfg.options.debug) {
106
+ const { id: _id, name: _name, __imports, __importRef, ...cfg } = config;
107
+ const debugCfg = {
108
+ filename,
109
+ languageId: (_e = (_d = doc.languageId) !== null && _d !== void 0 ? _d : cfg.languageId) !== null && _e !== void 0 ? _e : 'default',
110
+ config: { ...cfg, source: null },
111
+ source: spellResult.localConfigFilepath,
112
+ };
113
+ reporter.debug(JSON.stringify(debugCfg, undefined, 2));
114
+ }
110
115
  const dep = calcDependencies(config);
111
116
  cache.setCachedLintResults(result, dep.files);
112
117
  return result;
@@ -122,6 +127,9 @@ async function runLint(cfg) {
122
127
  const fileCount = files instanceof Array ? files.length : undefined;
123
128
  const status = runResult();
124
129
  const cache = (0, cache_1.createCache)(cacheSettings);
130
+ if (cfg.options.cacheReset) {
131
+ cache.reset();
132
+ }
125
133
  const failFast = (_b = (_a = cfg.options.failFast) !== null && _a !== void 0 ? _a : configInfo.config.failFast) !== null && _b !== void 0 ? _b : false;
126
134
  const emitProgressBegin = (filename, fileNum, fileCount) => reporter.progress({
127
135
  type: 'ProgressFileBegin',
@@ -207,6 +215,9 @@ async function runLint(cfg) {
207
215
  process.env[cspell.ENV_CSPELL_GLOB_ROOT] = cfg.root;
208
216
  }
209
217
  const configInfo = await (0, fileHelper_1.readConfig)(cfg.configFile, cfg.root);
218
+ if (cfg.options.defaultConfiguration !== undefined) {
219
+ configInfo.config.loadDefaultConfiguration = cfg.options.defaultConfiguration;
220
+ }
210
221
  reporter = (0, reporters_1.mergeReporters)(cfg.reporter, ...(0, reporters_1.loadReporters)(configInfo.config));
211
222
  cspell.setLogger(getLoggerFromReporter(reporter));
212
223
  const globInfo = await determineGlobs(configInfo, cfg);
@@ -406,8 +417,8 @@ async function useFileLists(fileListFiles, includeGlobPatterns, root, dot) {
406
417
  options.dot = dot;
407
418
  }
408
419
  const globMatcher = new cspell_glob_1.GlobMatcher(includeGlobPatterns, options);
409
- const files = await (0, fileHelper_1.readFileListFiles)(fileListFiles);
410
420
  const filterFiles = (file) => globMatcher.match(file);
411
- return files instanceof Array ? files.filter(filterFiles) : (0, cspell_pipe_1.pipeAsync)(files, (0, cspell_pipe_1.opFilter)(filterFiles));
421
+ const files = (0, fileHelper_1.readFileListFiles)(fileListFiles);
422
+ return (0, cspell_pipe_1.pipeAsync)(files, (0, cspell_pipe_1.opFilter)(filterFiles), opFilterAsync(fileHelper_1.isNotDir));
412
423
  }
413
424
  //# sourceMappingURL=lint.js.map
package/dist/options.d.ts CHANGED
@@ -119,6 +119,11 @@ export interface BaseOptions {
119
119
  * Locale to use.
120
120
  */
121
121
  locale?: string;
122
+ /**
123
+ * Load the default configuration
124
+ * @default true
125
+ */
126
+ defaultConfiguration?: boolean;
122
127
  }
123
128
  export interface LinterCliOptions extends Omit<LinterOptions, 'fileLists'> {
124
129
  legacy?: boolean;
@@ -1,2 +1,3 @@
1
- export { toAsyncIterable as mergeAsyncIterables, toArray as asyncIterableToArray } from '@cspell/cspell-pipe';
1
+ export { helpers as asyncHelpers, operators as asyncOperators, pipeAsync as asyncPipe, toArray as asyncIterableToArray, 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;
2
3
  //# sourceMappingURL=async.d.ts.map
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asyncIterableToArray = exports.mergeAsyncIterables = void 0;
4
- var cspell_pipe_1 = require("@cspell/cspell-pipe");
5
- Object.defineProperty(exports, "mergeAsyncIterables", { enumerable: true, get: function () { return cspell_pipe_1.toAsyncIterable; } });
6
- Object.defineProperty(exports, "asyncIterableToArray", { enumerable: true, get: function () { return cspell_pipe_1.toArray; } });
3
+ exports.asyncFlatten = exports.asyncAwait = exports.asyncFilter = exports.asyncMap = exports.mergeAsyncIterables = exports.asyncIterableToArray = exports.asyncPipe = exports.asyncOperators = 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, "asyncOperators", { enumerable: true, get: function () { return cspell_pipe_2.operators; } });
8
+ Object.defineProperty(exports, "asyncPipe", { enumerable: true, get: function () { return cspell_pipe_2.pipeAsync; } });
9
+ Object.defineProperty(exports, "asyncIterableToArray", { enumerable: true, get: function () { return cspell_pipe_2.toArray; } });
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;
7
12
  //# sourceMappingURL=async.js.map
@@ -12,5 +12,9 @@ export interface CSpellLintResultCache {
12
12
  * Persists the in-memory cache to disk.
13
13
  */
14
14
  reconcile(): void;
15
+ /**
16
+ * Resets the cache.
17
+ */
18
+ reset(): void;
15
19
  }
16
20
  //# sourceMappingURL=CSpellLintResultCache.d.ts.map
@@ -19,5 +19,9 @@ export interface CacheOptions {
19
19
  * Strategy to use for detecting changed files, default: metadata
20
20
  */
21
21
  cacheStrategy?: CacheStrategy;
22
+ /**
23
+ * Resets the cache
24
+ */
25
+ cacheReset?: boolean;
22
26
  }
23
27
  //# sourceMappingURL=CacheOptions.d.ts.map
@@ -1,37 +1,58 @@
1
1
  import type { FileDescriptor } from 'file-entry-cache';
2
2
  import type { FileResult } from '../../util/fileHelper';
3
3
  import type { CSpellLintResultCache } from './CSpellLintResultCache';
4
- export declare type CachedFileResult = Omit<FileResult, 'fileInfo' | 'elapsedTimeMs'>;
4
+ export declare type CachedFileResult = Omit<FileResult, 'fileInfo' | 'elapsedTimeMs' | 'cached'>;
5
5
  /**
6
6
  * This is the data cached.
7
7
  * Property names are short to help keep the cache file size small.
8
8
  */
9
9
  interface CachedData {
10
+ /** meta version + suffix */
11
+ v?: string;
10
12
  /** results */
11
- r: CachedFileResult;
13
+ r?: CachedFileResult;
12
14
  /** dependencies */
13
- d: string[];
14
- /** meta version */
15
- v: string;
15
+ d?: Dependency[];
16
+ }
17
+ interface Dependency {
18
+ /** filename */
19
+ f: string;
20
+ /** hash of file contents */
21
+ h?: string | undefined;
16
22
  }
17
23
  interface CSpellCachedMetaData {
18
24
  data?: CachedData;
19
25
  }
20
- export declare type CSpellCacheMeta = (FileDescriptor['meta'] & CSpellCachedMetaData) | undefined;
26
+ declare type Meta = FileDescriptor['meta'];
27
+ export declare type CSpellCacheMeta = (Meta & CSpellCachedMetaData) | undefined;
21
28
  /**
22
29
  * Caches cspell results on disk
23
30
  */
24
31
  export declare class DiskCache implements CSpellLintResultCache {
25
- readonly version: string;
32
+ readonly useCheckSum: boolean;
33
+ readonly cspellVersion: string;
26
34
  private fileEntryCache;
27
- private changedDependencies;
28
- private knownDependencies;
29
- constructor(cacheFileLocation: string, useCheckSum: boolean, version: string);
35
+ private dependencyCache;
36
+ private dependencyCacheTree;
37
+ private objectCollection;
38
+ private ocCacheFileResult;
39
+ readonly version: string;
40
+ constructor(cacheFileLocation: string, useCheckSum: boolean, cspellVersion: string);
30
41
  getCachedLintResults(filename: string): Promise<FileResult | undefined>;
31
- setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result }: FileResult, dependsUponFiles: string[]): void;
42
+ setCachedLintResults({ fileInfo, elapsedTimeMs: _, cached: __, ...result }: FileResult, dependsUponFiles: string[]): void;
32
43
  reconcile(): void;
33
- private cacheDependencies;
44
+ reset(): void;
45
+ private normalizeResult;
46
+ private calcDependencyHashes;
47
+ private checkDependency;
48
+ private getDependency;
49
+ private getFileDep;
34
50
  private checkDependencies;
51
+ private getHash;
35
52
  }
53
+ declare function calcVersion(version: string): string;
54
+ export declare const __testing__: {
55
+ calcVersion: typeof calcVersion;
56
+ };
36
57
  export {};
37
58
  //# sourceMappingURL=DiskCache.d.ts.map
@@ -23,19 +23,37 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.DiskCache = void 0;
26
+ exports.__testing__ = exports.DiskCache = void 0;
27
+ const crypto = __importStar(require("crypto"));
27
28
  const fileEntryCache = __importStar(require("file-entry-cache"));
29
+ const fs = __importStar(require("fs"));
28
30
  const path_1 = require("path");
29
31
  const fileHelper_1 = require("../../util/fileHelper");
32
+ const ObjectCollection_1 = require("./ObjectCollection");
33
+ const cacheDataKeys = {
34
+ v: 'v',
35
+ r: 'r',
36
+ d: 'd',
37
+ };
38
+ /**
39
+ * Meta Data Version is used to detect if the structure of the meta data has changed.
40
+ * This is used in combination with the Suffix and the version of CSpell.
41
+ */
42
+ const META_DATA_BASE_VERSION = '1';
43
+ const META_DATA_VERSION_SUFFIX = '-' + META_DATA_BASE_VERSION + '-' + Object.keys(cacheDataKeys).join('|');
30
44
  /**
31
45
  * Caches cspell results on disk
32
46
  */
33
47
  class DiskCache {
34
- constructor(cacheFileLocation, useCheckSum, version) {
35
- this.version = version;
36
- this.changedDependencies = new Set();
37
- this.knownDependencies = new Set();
48
+ constructor(cacheFileLocation, useCheckSum, cspellVersion) {
49
+ this.useCheckSum = useCheckSum;
50
+ this.cspellVersion = cspellVersion;
51
+ this.dependencyCache = new Map();
52
+ this.dependencyCacheTree = {};
53
+ this.objectCollection = new ObjectCollection_1.ShallowObjectCollection();
54
+ this.ocCacheFileResult = new ObjectCollection_1.ShallowObjectCollection();
38
55
  this.fileEntryCache = fileEntryCache.createFromFile((0, path_1.resolve)(cacheFileLocation), useCheckSum);
56
+ this.version = calcVersion(cspellVersion);
39
57
  }
40
58
  async getCachedLintResults(filename) {
41
59
  const fileDescriptor = this.fileEntryCache.getFileDescriptor(filename);
@@ -56,6 +74,12 @@ class DiskCache {
56
74
  !this.checkDependencies(data.d)) {
57
75
  return undefined;
58
76
  }
77
+ const dd = { ...data };
78
+ if (dd.d) {
79
+ dd.d = setTreeEntry(this.dependencyCacheTree, dd.d);
80
+ }
81
+ dd.r = dd.r && this.normalizeResult(dd.r);
82
+ meta.data = this.objectCollection.get(dd);
59
83
  // Skip reading empty files and files without lint error
60
84
  const hasErrors = !!result && (result.errors > 0 || result.configErrors > 0 || result.issues.length > 0);
61
85
  const cached = true;
@@ -67,41 +91,131 @@ class DiskCache {
67
91
  cached,
68
92
  };
69
93
  }
70
- setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result }, dependsUponFiles) {
94
+ setCachedLintResults({ fileInfo, elapsedTimeMs: _, cached: __, ...result }, dependsUponFiles) {
71
95
  const fileDescriptor = this.fileEntryCache.getFileDescriptor(fileInfo.filename);
72
96
  const meta = fileDescriptor.meta;
73
97
  if (fileDescriptor.notFound || !meta) {
74
98
  return;
75
99
  }
76
- const data = {
77
- r: result,
78
- d: dependsUponFiles,
100
+ const data = this.objectCollection.get({
79
101
  v: this.version,
80
- };
102
+ r: this.normalizeResult(result),
103
+ d: this.calcDependencyHashes(dependsUponFiles),
104
+ });
81
105
  meta.data = data;
82
- this.cacheDependencies(dependsUponFiles);
83
106
  }
84
107
  reconcile() {
85
108
  this.fileEntryCache.reconcile();
86
109
  }
87
- cacheDependencies(files) {
88
- this.fileEntryCache.analyzeFiles(files);
110
+ reset() {
111
+ this.fileEntryCache.destroy();
112
+ this.dependencyCache.clear();
113
+ this.dependencyCacheTree = {};
114
+ this.objectCollection = new ObjectCollection_1.ShallowObjectCollection();
115
+ this.ocCacheFileResult = new ObjectCollection_1.ShallowObjectCollection();
89
116
  }
90
- checkDependencies(files) {
91
- for (const file of files) {
92
- if (this.changedDependencies.has(file)) {
93
- return false;
94
- }
117
+ normalizeResult(result) {
118
+ const { issues, processed, errors, configErrors, ...rest } = result;
119
+ if (!Object.keys(rest).length) {
120
+ return this.ocCacheFileResult.get(result);
95
121
  }
96
- const unknown = files.filter((f) => !this.knownDependencies.has(f));
97
- if (!unknown.length) {
122
+ return this.ocCacheFileResult.get({ issues, processed, errors, configErrors });
123
+ }
124
+ calcDependencyHashes(dependsUponFiles) {
125
+ dependsUponFiles.sort();
126
+ const c = getTreeEntry(this.dependencyCacheTree, dependsUponFiles);
127
+ if (c === null || c === void 0 ? void 0 : c.d) {
128
+ return c.d;
129
+ }
130
+ const dependencies = dependsUponFiles.map((f) => this.getDependency(f));
131
+ return setTreeEntry(this.dependencyCacheTree, dependencies);
132
+ }
133
+ checkDependency(dep) {
134
+ const cDep = this.dependencyCache.get(dep.f);
135
+ if (cDep && compDep(dep, cDep))
98
136
  return true;
137
+ if (cDep)
138
+ return false;
139
+ const d = this.getFileDep(dep.f);
140
+ if (compDep(dep, d)) {
141
+ this.dependencyCache.set(dep.f, dep);
142
+ return true;
143
+ }
144
+ this.dependencyCache.set(d.f, d);
145
+ return false;
146
+ }
147
+ getDependency(file) {
148
+ const dep = this.dependencyCache.get(file);
149
+ if (dep)
150
+ return dep;
151
+ const d = this.getFileDep(file);
152
+ this.dependencyCache.set(file, d);
153
+ return d;
154
+ }
155
+ getFileDep(file) {
156
+ let h;
157
+ try {
158
+ const buffer = fs.readFileSync(file);
159
+ h = this.getHash(buffer);
160
+ }
161
+ catch (e) {
162
+ return { f: file };
99
163
  }
100
- const { changedFiles, notFoundFiles } = this.fileEntryCache.analyzeFiles(files);
101
- changedFiles.map((f) => this.changedDependencies.add(f));
102
- unknown.forEach((f) => this.knownDependencies.add(f));
103
- return changedFiles.length === 0 && notFoundFiles.length === 0;
164
+ return { f: file, h };
165
+ }
166
+ checkDependencies(dependencies) {
167
+ if (!dependencies)
168
+ return false;
169
+ for (const dep of dependencies) {
170
+ if (!this.checkDependency(dep)) {
171
+ return false;
172
+ }
173
+ }
174
+ return true;
175
+ }
176
+ getHash(buffer) {
177
+ return crypto.createHash('md5').update(buffer).digest('hex');
104
178
  }
105
179
  }
106
180
  exports.DiskCache = DiskCache;
181
+ function getTreeEntry(tree, keys) {
182
+ var _a;
183
+ let r = tree;
184
+ for (const k of keys) {
185
+ r = (_a = r.c) === null || _a === void 0 ? void 0 : _a.get(k);
186
+ if (!r)
187
+ return r;
188
+ }
189
+ return r;
190
+ }
191
+ function setTreeEntry(tree, deps, update = false) {
192
+ let r = tree;
193
+ for (const d of deps) {
194
+ const k = d.f;
195
+ if (!r.c) {
196
+ r.c = new Map();
197
+ }
198
+ const cn = r.c.get(k);
199
+ const n = cn !== null && cn !== void 0 ? cn : {};
200
+ if (!cn) {
201
+ r.c.set(k, n);
202
+ }
203
+ r = n;
204
+ }
205
+ let d = r.d;
206
+ if (!d || (r.d && update)) {
207
+ r.d = deps;
208
+ d = deps;
209
+ }
210
+ return d;
211
+ }
212
+ function compDep(a, b) {
213
+ return a.f === b.f && a.h === b.h;
214
+ }
215
+ function calcVersion(version) {
216
+ return version + META_DATA_VERSION_SUFFIX;
217
+ }
218
+ exports.__testing__ = {
219
+ calcVersion,
220
+ };
107
221
  //# sourceMappingURL=DiskCache.js.map
@@ -6,5 +6,6 @@ export declare class DummyCache implements CSpellLintResultCache {
6
6
  getCachedLintResults(): Promise<undefined>;
7
7
  setCachedLintResults(): void;
8
8
  reconcile(): void;
9
+ reset(): void;
9
10
  }
10
11
  //# sourceMappingURL=DummyCache.d.ts.map
@@ -14,6 +14,9 @@ class DummyCache {
14
14
  reconcile() {
15
15
  return;
16
16
  }
17
+ reset() {
18
+ return;
19
+ }
17
20
  }
18
21
  exports.DummyCache = DummyCache;
19
22
  //# sourceMappingURL=DummyCache.js.map
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Collection = exports.ShallowObjectCollection = void 0;
5
+ const compare = Intl.Collator().compare;
6
+ class ShallowObjectCollection {
7
+ constructor() {
8
+ this.tree = {};
9
+ }
10
+ get(v) {
11
+ if (typeof v !== 'object' || v === null) {
12
+ return v;
13
+ }
14
+ const keys = Object.entries(v)
15
+ .filter((entry) => entry[1] !== undefined)
16
+ .sort((a, b) => compare(a[0], b[0]));
17
+ let t = this.tree;
18
+ for (const [key, obj] of keys) {
19
+ if (!t.c) {
20
+ t.c = new Map();
21
+ }
22
+ const c0 = t.c.get(key);
23
+ const cc = c0 || new Map();
24
+ if (!c0) {
25
+ t.c.set(key, cc);
26
+ }
27
+ const c1 = cc.get(obj);
28
+ const ccc = c1 || {};
29
+ if (!c1) {
30
+ cc.set(obj, ccc);
31
+ }
32
+ t = ccc;
33
+ }
34
+ if (t.v)
35
+ return t.v;
36
+ t.v = v;
37
+ return v;
38
+ }
39
+ }
40
+ exports.ShallowObjectCollection = ShallowObjectCollection;
41
+ class Collection {
42
+ constructor() {
43
+ this.col = { contains: new Map() };
44
+ }
45
+ /**
46
+ * Add a plain object to the collection.
47
+ * The actual object used is returned.
48
+ * By adding the object to the collection, it is now owned by the collection.
49
+ * Do not add class objects.
50
+ * @param v any object or primitive
51
+ * @returns v or the matching object.
52
+ */
53
+ add(v) {
54
+ return addToCollection(this.col, v);
55
+ }
56
+ }
57
+ exports.Collection = Collection;
58
+ // const objectLike: TypeMask = {
59
+ // array: true,
60
+ // object: true,
61
+ // };
62
+ function addToCollection(root, v) {
63
+ const known = root.contains;
64
+ function addValToCol(c, v) {
65
+ var _a;
66
+ const t = toValueType(v);
67
+ const val = c.v || Object.create(null);
68
+ const r = (_a = val[t]) !== null && _a !== void 0 ? _a : v;
69
+ val[t] = r;
70
+ c.v = val;
71
+ return val[t];
72
+ }
73
+ function walk(col, path) {
74
+ path = path.filter((entry) => entry[1] !== undefined).sort((a, b) => compare(a[0], b[0]));
75
+ for (const [k, v] of path) {
76
+ const c = col.c || Object.create(null);
77
+ col.c = c;
78
+ const m = c[k] || new Map();
79
+ c[k] = m;
80
+ const has = m.get(v);
81
+ col = has || Object.create(null);
82
+ if (!has) {
83
+ m.set(v, col);
84
+ }
85
+ }
86
+ return col;
87
+ }
88
+ function normalizeObjectEntries(entries) {
89
+ for (const entry of entries) {
90
+ entry[1] = add(entry[1]);
91
+ }
92
+ return entries;
93
+ }
94
+ function normalizeToPath(v) {
95
+ if (typeof v !== 'object' || !v) {
96
+ return [['', v]];
97
+ }
98
+ const entries = normalizeObjectEntries(Object.entries(v));
99
+ const obj = v;
100
+ if (!Object.isFrozen(v)) {
101
+ for (const [k, v] of entries) {
102
+ obj[k] = v;
103
+ }
104
+ Object.freeze(obj);
105
+ }
106
+ return entries;
107
+ }
108
+ function add(v) {
109
+ const isObjectLike = typeof v === 'object' && !!v;
110
+ if (isObjectLike) {
111
+ const cached = known.get(v);
112
+ if (cached !== undefined) {
113
+ return cached;
114
+ }
115
+ known.set(v, v);
116
+ }
117
+ const path = normalizeToPath(v);
118
+ const c = walk(root, path);
119
+ const r = addValToCol(c, v);
120
+ if (isObjectLike) {
121
+ known.set(v, r);
122
+ }
123
+ return r;
124
+ }
125
+ return add(v);
126
+ }
127
+ function toValueType(v) {
128
+ const t = typeof v;
129
+ if (t !== 'object')
130
+ return t;
131
+ if (v instanceof Array)
132
+ return 'array';
133
+ if (v === null)
134
+ return 'null';
135
+ return t;
136
+ }
137
+ //# sourceMappingURL=ObjectCollection.js.map
@@ -1,5 +1,6 @@
1
- import { GlobOptions } from './glob';
1
+ /// <reference types="node" />
2
2
  import { CSpellUserSettings, Document, Issue } from 'cspell-lib';
3
+ import { GlobOptions } from './glob';
3
4
  export interface ConfigInfo {
4
5
  source: string;
5
6
  config: CSpellUserSettings;
@@ -29,8 +30,8 @@ export declare function fileInfoToDocument(fileInfo: FileInfo, languageId: strin
29
30
  interface ReadFileInfoResult extends FileInfo {
30
31
  text: string;
31
32
  }
32
- export declare function readFileInfo(filename: string, encoding?: string, handleNotFound?: boolean): Promise<ReadFileInfoResult>;
33
- export declare function readFile(filename: string, encoding?: string): Promise<string>;
33
+ export declare function readFileInfo(filename: string, encoding?: BufferEncoding, handleNotFound?: boolean): Promise<ReadFileInfoResult>;
34
+ export declare function readFile(filename: string, encoding?: BufferEncoding): Promise<string>;
34
35
  /**
35
36
  * Looks for matching glob patterns or stdin
36
37
  * @param globPatterns patterns or stdin
@@ -43,7 +44,7 @@ export declare function calcFinalConfigInfo(configInfo: ConfigInfo, settingsFrom
43
44
  * file will be resolved relative to the containing file.
44
45
  * @returns - a list of files to be processed.
45
46
  */
46
- export declare function readFileListFiles(listFiles: string[]): Promise<string[] | AsyncIterable<string>>;
47
+ export declare function readFileListFiles(listFiles: string[]): AsyncIterable<string>;
47
48
  /**
48
49
  * Read a `listFile` and return the containing file paths resolved relative to the `listFile`.
49
50
  * @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
@@ -51,5 +52,8 @@ export declare function readFileListFiles(listFiles: string[]): Promise<string[]
51
52
  * @returns - a list of files to be processed.
52
53
  */
53
54
  export declare function readFileListFile(listFile: string): Promise<string[]>;
55
+ export declare function isFile(filename: string): Promise<boolean>;
56
+ export declare function isDir(filename: string): Promise<boolean>;
57
+ export declare function isNotDir(filename: string): Promise<boolean>;
54
58
  export {};
55
59
  //# sourceMappingURL=fileHelper.d.ts.map
@@ -26,15 +26,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.readFileListFile = exports.readFileListFiles = exports.calcFinalConfigInfo = exports.findFiles = exports.readFile = exports.readFileInfo = exports.fileInfoToDocument = exports.readConfig = void 0;
29
+ exports.isNotDir = exports.isDir = exports.isFile = exports.readFileListFile = exports.readFileListFiles = exports.calcFinalConfigInfo = exports.findFiles = exports.readFile = exports.readFileInfo = exports.fileInfoToDocument = exports.readConfig = void 0;
30
30
  const cspell = __importStar(require("cspell-lib"));
31
- const fsp = __importStar(require("fs-extra"));
31
+ const cspell_lib_1 = require("cspell-lib");
32
+ const fs_1 = require("fs");
32
33
  const get_stdin_1 = __importDefault(require("get-stdin"));
33
- const glob_1 = require("./glob");
34
34
  const path = __importStar(require("path"));
35
- const cspell_lib_1 = require("cspell-lib");
36
- const errors_1 = require("./errors");
37
35
  const async_1 = require("./async");
36
+ const errors_1 = require("./errors");
37
+ const glob_1 = require("./glob");
38
38
  const stdin_1 = require("./stdin");
39
39
  const UTF8 = 'utf8';
40
40
  const STDIN = 'stdin';
@@ -64,7 +64,7 @@ function fileInfoToDocument(fileInfo, languageId, locale) {
64
64
  }
65
65
  exports.fileInfoToDocument = fileInfoToDocument;
66
66
  function readFileInfo(filename, encoding = UTF8, handleNotFound = false) {
67
- const pText = filename === STDIN ? (0, get_stdin_1.default)() : fsp.readFile(filename, encoding);
67
+ const pText = filename === STDIN ? (0, get_stdin_1.default)() : fs_1.promises.readFile(filename, encoding);
68
68
  return pText.then((text) => ({ text, filename }), (e) => {
69
69
  const error = (0, errors_1.toError)(e);
70
70
  return handleNotFound && error.code === 'EISDIR'
@@ -92,9 +92,11 @@ async function findFiles(globPatterns, options) {
92
92
  }
93
93
  exports.findFiles = findFiles;
94
94
  function calcFinalConfigInfo(configInfo, settingsFromCommandLine, filename, text) {
95
+ var _a, _b, _c;
95
96
  const ext = path.extname(filename);
96
97
  const fileSettings = cspell.calcOverrideSettings(configInfo.config, path.resolve(filename));
97
- const settings = cspell.mergeSettings(cspell.getDefaultSettings(), cspell.getGlobalSettings(), fileSettings, settingsFromCommandLine);
98
+ const loadDefault = (_c = (_b = (_a = settingsFromCommandLine.loadDefaultConfiguration) !== null && _a !== void 0 ? _a : configInfo.config.loadDefaultConfiguration) !== null && _b !== void 0 ? _b : fileSettings.loadDefaultConfiguration) !== null && _c !== void 0 ? _c : true;
99
+ const settings = cspell.mergeSettings(cspell.getDefaultSettings(loadDefault), cspell.getGlobalSettings(), fileSettings, settingsFromCommandLine);
98
100
  const languageIds = settings.languageId ? [settings.languageId] : cspell.getLanguagesForExt(ext);
99
101
  const config = cspell.constructSettingsForText(settings, text, languageIds);
100
102
  return {
@@ -105,22 +107,27 @@ function calcFinalConfigInfo(configInfo, settingsFromCommandLine, filename, text
105
107
  };
106
108
  }
107
109
  exports.calcFinalConfigInfo = calcFinalConfigInfo;
110
+ function resolveFilename(filename) {
111
+ return path.resolve(filename);
112
+ }
113
+ const resolveFilenames = (0, async_1.asyncMap)(resolveFilename);
108
114
  /**
109
115
  * Read
110
116
  * @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
111
117
  * file will be resolved relative to the containing file.
112
118
  * @returns - a list of files to be processed.
113
119
  */
114
- async function readFileListFiles(listFiles) {
120
+ function readFileListFiles(listFiles) {
115
121
  let useStdin = false;
116
122
  const files = listFiles.filter((file) => {
117
123
  const isStdin = file === 'stdin';
118
124
  useStdin = useStdin || isStdin;
119
125
  return !isStdin;
120
126
  });
121
- const found = flatten(await Promise.all(files.map(readFileListFile)));
127
+ const found = (0, async_1.asyncPipe)(files, (0, async_1.asyncMap)((file) => readFileListFile(file)), (0, async_1.asyncAwait)(), (0, async_1.asyncFlatten)());
122
128
  // Move `stdin` to the end.
123
- return useStdin ? (0, async_1.mergeAsyncIterables)(found, (0, stdin_1.readStdin)()) : found;
129
+ const stdin = useStdin ? (0, stdin_1.readStdin)() : [];
130
+ return (0, async_1.asyncPipe)((0, async_1.mergeAsyncIterables)(found, stdin), resolveFilenames);
124
131
  }
125
132
  exports.readFileListFiles = readFileListFiles;
126
133
  /**
@@ -145,12 +152,28 @@ async function readFileListFile(listFile) {
145
152
  }
146
153
  }
147
154
  exports.readFileListFile = readFileListFile;
148
- function flatten(fileLists) {
149
- function* f() {
150
- for (const list of fileLists) {
151
- yield* list;
152
- }
155
+ async function isFile(filename) {
156
+ try {
157
+ const stat = await fs_1.promises.stat(filename);
158
+ return stat.isFile();
159
+ }
160
+ catch (e) {
161
+ return false;
153
162
  }
154
- return [...f()];
155
163
  }
164
+ exports.isFile = isFile;
165
+ async function isDir(filename) {
166
+ try {
167
+ const stat = await fs_1.promises.stat(filename);
168
+ return stat.isDirectory();
169
+ }
170
+ catch (e) {
171
+ return false;
172
+ }
173
+ }
174
+ exports.isDir = isDir;
175
+ function isNotDir(filename) {
176
+ return isDir(filename).then((a) => !a);
177
+ }
178
+ exports.isNotDir = isNotDir;
156
179
  //# sourceMappingURL=fileHelper.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell",
3
- "version": "5.19.4",
3
+ "version": "5.19.7",
4
4
  "description": "A Spelling Checker for Code!",
5
5
  "funding": "https://github.com/streetsidesoftware/cspell?sponsor=1",
6
6
  "main": "dist/index.js",
@@ -70,19 +70,19 @@
70
70
  },
71
71
  "homepage": "https://streetsidesoftware.github.io/cspell/",
72
72
  "dependencies": {
73
- "@cspell/cspell-pipe": "^5.19.4",
73
+ "@cspell/cspell-pipe": "^5.19.7",
74
74
  "chalk": "^4.1.2",
75
75
  "commander": "^9.1.0",
76
- "cspell-gitignore": "^5.19.4",
77
- "cspell-glob": "^5.19.4",
78
- "cspell-lib": "^5.19.4",
76
+ "cspell-gitignore": "^5.19.7",
77
+ "cspell-glob": "^5.19.7",
78
+ "cspell-lib": "^5.19.7",
79
79
  "fast-json-stable-stringify": "^2.1.0",
80
80
  "file-entry-cache": "^6.0.1",
81
81
  "fs-extra": "^10.0.1",
82
82
  "get-stdin": "^8.0.0",
83
83
  "glob": "^7.2.0",
84
84
  "imurmurhash": "^0.1.4",
85
- "semver": "^7.3.5",
85
+ "semver": "^7.3.6",
86
86
  "strip-ansi": "^6.0.1",
87
87
  "vscode-uri": "^3.0.3"
88
88
  },
@@ -90,8 +90,8 @@
90
90
  "node": ">=12.13.0"
91
91
  },
92
92
  "devDependencies": {
93
- "@cspell/cspell-json-reporter": "^5.19.4",
94
- "@cspell/cspell-types": "^5.19.4",
93
+ "@cspell/cspell-json-reporter": "^5.19.7",
94
+ "@cspell/cspell-types": "^5.19.7",
95
95
  "@types/file-entry-cache": "^5.0.2",
96
96
  "@types/fs-extra": "^9.0.13",
97
97
  "@types/glob": "^7.2.0",
@@ -104,7 +104,7 @@
104
104
  "minimatch": "^5.0.1",
105
105
  "rimraf": "^3.0.2",
106
106
  "rollup": "^2.70.1",
107
- "rollup-plugin-dts": "^4.2.0"
107
+ "rollup-plugin-dts": "^4.2.1"
108
108
  },
109
- "gitHead": "9f7e77c95eb1e8fabf53c5b74b7418b2d114ef02"
109
+ "gitHead": "1d33cd1b61250f8c4c5c2c218ec43675614784ca"
110
110
  }
@@ -1,6 +0,0 @@
1
- import { ConfigInfo } from '../../util/fileHelper';
2
- /**
3
- * Hashes ConfigInfo and cspell version for using in DiskCache
4
- */
5
- export declare function getConfigHash(configInfo: ConfigInfo): string;
6
- //# sourceMappingURL=getConfigHash.d.ts.map
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getConfigHash = void 0;
7
- const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
8
- const path_1 = __importDefault(require("path"));
9
- const hash_1 = require("./hash");
10
- // eslint-disable-next-line @typescript-eslint/no-var-requires
11
- const { version } = require(path_1.default.join(__dirname, '..', '..', '..', 'package.json'));
12
- const configHashes = new WeakMap();
13
- /**
14
- * Hashes ConfigInfo and cspell version for using in DiskCache
15
- */
16
- function getConfigHash(configInfo) {
17
- const cachedHash = configHashes.get(configInfo);
18
- if (cachedHash !== undefined) {
19
- return cachedHash;
20
- }
21
- const hashValue = (0, hash_1.hash)(`${version}_${(0, fast_json_stable_stringify_1.default)(configInfo)}`);
22
- configHashes.set(configInfo, hashValue);
23
- return hashValue;
24
- }
25
- exports.getConfigHash = getConfigHash;
26
- //# sourceMappingURL=getConfigHash.js.map
@@ -1,5 +0,0 @@
1
- /**
2
- * Hash the given string using MurmurHash3
3
- */
4
- export declare function hash(str: string): string;
5
- //# sourceMappingURL=hash.d.ts.map
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.hash = void 0;
7
- // cspell:word imurmurhash
8
- const imurmurhash_1 = __importDefault(require("imurmurhash"));
9
- /**
10
- * Hash the given string using MurmurHash3
11
- */
12
- function hash(str) {
13
- return (0, imurmurhash_1.default)(str).result().toString(36);
14
- }
15
- exports.hash = hash;
16
- //# sourceMappingURL=hash.js.map