cspell 5.19.5 → 5.20.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.
- package/dist/commandLint.js +1 -0
- package/dist/lint/lint.js +6 -2
- package/dist/util/async.d.ts +2 -1
- package/dist/util/async.js +9 -4
- package/dist/util/cache/CSpellLintResultCache.d.ts +4 -0
- package/dist/util/cache/CacheOptions.d.ts +4 -0
- package/dist/util/cache/DiskCache.d.ts +33 -12
- package/dist/util/cache/DiskCache.js +138 -24
- package/dist/util/cache/DummyCache.d.ts +1 -0
- package/dist/util/cache/DummyCache.js +3 -0
- package/dist/util/cache/ObjectCollection.d.ts +17 -0
- package/dist/util/cache/ObjectCollection.js +137 -0
- package/dist/util/fileHelper.d.ts +8 -4
- package/dist/util/fileHelper.js +36 -15
- package/package.json +14 -14
- package/dist/util/cache/getConfigHash.d.ts +0 -6
- package/dist/util/cache/getConfigHash.js +0 -26
- package/dist/util/cache/hash.d.ts +0 -5
- package/dist/util/cache/hash.js +0 -16
package/dist/commandLint.js
CHANGED
|
@@ -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',
|
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));
|
|
@@ -126,6 +127,9 @@ async function runLint(cfg) {
|
|
|
126
127
|
const fileCount = files instanceof Array ? files.length : undefined;
|
|
127
128
|
const status = runResult();
|
|
128
129
|
const cache = (0, cache_1.createCache)(cacheSettings);
|
|
130
|
+
if (cfg.options.cacheReset) {
|
|
131
|
+
cache.reset();
|
|
132
|
+
}
|
|
129
133
|
const failFast = (_b = (_a = cfg.options.failFast) !== null && _a !== void 0 ? _a : configInfo.config.failFast) !== null && _b !== void 0 ? _b : false;
|
|
130
134
|
const emitProgressBegin = (filename, fileNum, fileCount) => reporter.progress({
|
|
131
135
|
type: 'ProgressFileBegin',
|
|
@@ -413,8 +417,8 @@ async function useFileLists(fileListFiles, includeGlobPatterns, root, dot) {
|
|
|
413
417
|
options.dot = dot;
|
|
414
418
|
}
|
|
415
419
|
const globMatcher = new cspell_glob_1.GlobMatcher(includeGlobPatterns, options);
|
|
416
|
-
const files = await (0, fileHelper_1.readFileListFiles)(fileListFiles);
|
|
417
420
|
const filterFiles = (file) => globMatcher.match(file);
|
|
418
|
-
|
|
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));
|
|
419
423
|
}
|
|
420
424
|
//# sourceMappingURL=lint.js.map
|
package/dist/util/async.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
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
|
package/dist/util/async.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "
|
|
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
|
|
@@ -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
|
|
13
|
+
r?: CachedFileResult;
|
|
12
14
|
/** dependencies */
|
|
13
|
-
d
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
|
32
|
+
readonly useCheckSum: boolean;
|
|
33
|
+
readonly cspellVersion: string;
|
|
26
34
|
private fileEntryCache;
|
|
27
|
-
private
|
|
28
|
-
private
|
|
29
|
-
|
|
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
|
-
|
|
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,
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
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
|
-
|
|
88
|
-
this.fileEntryCache.
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
97
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
|
@@ -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
|
-
|
|
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?:
|
|
33
|
-
export declare function readFile(filename: string, encoding?:
|
|
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[]):
|
|
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
|
package/dist/util/fileHelper.js
CHANGED
|
@@ -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
|
|
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)() :
|
|
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'
|
|
@@ -107,22 +107,27 @@ function calcFinalConfigInfo(configInfo, settingsFromCommandLine, filename, text
|
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
exports.calcFinalConfigInfo = calcFinalConfigInfo;
|
|
110
|
+
function resolveFilename(filename) {
|
|
111
|
+
return path.resolve(filename);
|
|
112
|
+
}
|
|
113
|
+
const resolveFilenames = (0, async_1.asyncMap)(resolveFilename);
|
|
110
114
|
/**
|
|
111
115
|
* Read
|
|
112
116
|
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
113
117
|
* file will be resolved relative to the containing file.
|
|
114
118
|
* @returns - a list of files to be processed.
|
|
115
119
|
*/
|
|
116
|
-
|
|
120
|
+
function readFileListFiles(listFiles) {
|
|
117
121
|
let useStdin = false;
|
|
118
122
|
const files = listFiles.filter((file) => {
|
|
119
123
|
const isStdin = file === 'stdin';
|
|
120
124
|
useStdin = useStdin || isStdin;
|
|
121
125
|
return !isStdin;
|
|
122
126
|
});
|
|
123
|
-
const found =
|
|
127
|
+
const found = (0, async_1.asyncPipe)(files, (0, async_1.asyncMap)((file) => readFileListFile(file)), (0, async_1.asyncAwait)(), (0, async_1.asyncFlatten)());
|
|
124
128
|
// Move `stdin` to the end.
|
|
125
|
-
|
|
129
|
+
const stdin = useStdin ? (0, stdin_1.readStdin)() : [];
|
|
130
|
+
return (0, async_1.asyncPipe)((0, async_1.mergeAsyncIterables)(found, stdin), resolveFilenames);
|
|
126
131
|
}
|
|
127
132
|
exports.readFileListFiles = readFileListFiles;
|
|
128
133
|
/**
|
|
@@ -147,12 +152,28 @@ async function readFileListFile(listFile) {
|
|
|
147
152
|
}
|
|
148
153
|
}
|
|
149
154
|
exports.readFileListFile = readFileListFile;
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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;
|
|
155
162
|
}
|
|
156
|
-
return [...f()];
|
|
157
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;
|
|
158
179
|
//# sourceMappingURL=fileHelper.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.20.0",
|
|
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.
|
|
73
|
+
"@cspell/cspell-pipe": "^5.20.0",
|
|
74
74
|
"chalk": "^4.1.2",
|
|
75
|
-
"commander": "^9.
|
|
76
|
-
"cspell-gitignore": "^5.
|
|
77
|
-
"cspell-glob": "^5.
|
|
78
|
-
"cspell-lib": "^5.
|
|
75
|
+
"commander": "^9.2.0",
|
|
76
|
+
"cspell-gitignore": "^5.20.0",
|
|
77
|
+
"cspell-glob": "^5.20.0",
|
|
78
|
+
"cspell-lib": "^5.20.0",
|
|
79
79
|
"fast-json-stable-stringify": "^2.1.0",
|
|
80
80
|
"file-entry-cache": "^6.0.1",
|
|
81
|
-
"fs-extra": "^10.0
|
|
81
|
+
"fs-extra": "^10.1.0",
|
|
82
82
|
"get-stdin": "^8.0.0",
|
|
83
|
-
"glob": "^
|
|
83
|
+
"glob": "^8.0.1",
|
|
84
84
|
"imurmurhash": "^0.1.4",
|
|
85
|
-
"semver": "^7.3.
|
|
85
|
+
"semver": "^7.3.7",
|
|
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.
|
|
94
|
-
"@cspell/cspell-types": "^5.
|
|
93
|
+
"@cspell/cspell-json-reporter": "^5.20.0",
|
|
94
|
+
"@cspell/cspell-types": "^5.20.0",
|
|
95
95
|
"@types/file-entry-cache": "^5.0.2",
|
|
96
96
|
"@types/fs-extra": "^9.0.13",
|
|
97
97
|
"@types/glob": "^7.2.0",
|
|
@@ -103,8 +103,8 @@
|
|
|
103
103
|
"micromatch": "^4.0.5",
|
|
104
104
|
"minimatch": "^5.0.1",
|
|
105
105
|
"rimraf": "^3.0.2",
|
|
106
|
-
"rollup": "^2.
|
|
107
|
-
"rollup-plugin-dts": "^4.2.
|
|
106
|
+
"rollup": "^2.71.1",
|
|
107
|
+
"rollup-plugin-dts": "^4.2.1"
|
|
108
108
|
},
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "626dd9068d625c2100dee6a3fef4dea95ae83376"
|
|
110
110
|
}
|
|
@@ -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
|
package/dist/util/cache/hash.js
DELETED
|
@@ -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
|