@cspell/cspell-tools 9.5.0 → 9.6.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/bin.mjs +1 -1
- package/cspell-tools.config.schema.json +29 -0
- package/dist/app.d.mts +35 -0
- package/dist/app.mjs +292 -0
- package/dist/build-OgMPaXPZ.mjs +1403 -0
- package/dist/index.d.mts +35 -0
- package/dist/index.mjs +3 -0
- package/package.json +10 -9
- package/dist/AppOptions.d.ts +0 -31
- package/dist/AppOptions.js +0 -2
- package/dist/FeatureFlags/FeatureFlags.d.ts +0 -34
- package/dist/FeatureFlags/FeatureFlags.js +0 -94
- package/dist/FeatureFlags/index.d.ts +0 -3
- package/dist/FeatureFlags/index.js +0 -3
- package/dist/FeatureFlags/parseFlags.d.ts +0 -3
- package/dist/FeatureFlags/parseFlags.js +0 -20
- package/dist/app.d.ts +0 -4
- package/dist/app.js +0 -86
- package/dist/build.d.ts +0 -12
- package/dist/build.js +0 -36
- package/dist/compile.d.ts +0 -5
- package/dist/compile.js +0 -41
- package/dist/compiler/CompileOptions.d.ts +0 -35
- package/dist/compiler/CompileOptions.js +0 -2
- package/dist/compiler/CompilerDefinitions.d.ts +0 -2
- package/dist/compiler/CompilerDefinitions.js +0 -2
- package/dist/compiler/Reader.d.ts +0 -3
- package/dist/compiler/Reader.js +0 -24
- package/dist/compiler/SourceReader.d.ts +0 -28
- package/dist/compiler/SourceReader.js +0 -44
- package/dist/compiler/WordsCollection.d.ts +0 -20
- package/dist/compiler/WordsCollection.js +0 -3
- package/dist/compiler/compile.d.ts +0 -26
- package/dist/compiler/compile.js +0 -270
- package/dist/compiler/createCompileRequest.d.ts +0 -4
- package/dist/compiler/createCompileRequest.js +0 -84
- package/dist/compiler/createWordsCollection.d.ts +0 -10
- package/dist/compiler/createWordsCollection.js +0 -111
- package/dist/compiler/index.d.ts +0 -4
- package/dist/compiler/index.js +0 -3
- package/dist/compiler/legacyLineToWords.d.ts +0 -4
- package/dist/compiler/legacyLineToWords.js +0 -20
- package/dist/compiler/logWithTimestamp.d.ts +0 -3
- package/dist/compiler/logWithTimestamp.js +0 -5
- package/dist/compiler/logger.d.ts +0 -4
- package/dist/compiler/logger.js +0 -9
- package/dist/compiler/readers/ReaderOptions.d.ts +0 -19
- package/dist/compiler/readers/ReaderOptions.js +0 -2
- package/dist/compiler/readers/readHunspellFiles.d.ts +0 -3
- package/dist/compiler/readers/readHunspellFiles.js +0 -57
- package/dist/compiler/readers/readTextFile.d.ts +0 -3
- package/dist/compiler/readers/readTextFile.js +0 -20
- package/dist/compiler/readers/regHunspellFile.d.ts +0 -2
- package/dist/compiler/readers/regHunspellFile.js +0 -2
- package/dist/compiler/readers/textFileReader.d.ts +0 -3
- package/dist/compiler/readers/textFileReader.js +0 -11
- package/dist/compiler/readers/trieFileReader.d.ts +0 -3
- package/dist/compiler/readers/trieFileReader.js +0 -16
- package/dist/compiler/splitCamelCaseIfAllowed.d.ts +0 -5
- package/dist/compiler/splitCamelCaseIfAllowed.js +0 -65
- package/dist/compiler/streamSourceWordsFromFile.d.ts +0 -3
- package/dist/compiler/streamSourceWordsFromFile.js +0 -6
- package/dist/compiler/text.d.ts +0 -10
- package/dist/compiler/text.js +0 -28
- package/dist/compiler/wordListCompiler.d.ts +0 -21
- package/dist/compiler/wordListCompiler.js +0 -205
- package/dist/compiler/wordListParser.d.ts +0 -61
- package/dist/compiler/wordListParser.js +0 -184
- package/dist/compiler/writeTextToFile.d.ts +0 -2
- package/dist/compiler/writeTextToFile.js +0 -16
- package/dist/config/config.d.ts +0 -200
- package/dist/config/config.js +0 -2
- package/dist/config/configDefaults.d.ts +0 -9
- package/dist/config/configDefaults.js +0 -9
- package/dist/config/configUtils.d.ts +0 -5
- package/dist/config/configUtils.js +0 -14
- package/dist/config/index.d.ts +0 -4
- package/dist/config/index.js +0 -3
- package/dist/config/normalizeConfig.d.ts +0 -8
- package/dist/config/normalizeConfig.js +0 -13
- package/dist/gzip/compressFiles.d.ts +0 -16
- package/dist/gzip/compressFiles.js +0 -42
- package/dist/gzip/gzip.d.ts +0 -3
- package/dist/gzip/gzip.js +0 -10
- package/dist/gzip/index.d.ts +0 -3
- package/dist/gzip/index.js +0 -3
- package/dist/shasum/checksum.d.ts +0 -7
- package/dist/shasum/checksum.js +0 -19
- package/dist/shasum/index.d.ts +0 -3
- package/dist/shasum/index.js +0 -3
- package/dist/shasum/shasum.d.ts +0 -38
- package/dist/shasum/shasum.js +0 -150
- package/dist/test/TestHelper.d.ts +0 -53
- package/dist/test/TestHelper.js +0 -121
- package/dist/test/console.d.ts +0 -9
- package/dist/test/console.js +0 -34
- package/dist/test/escapeRegEx.d.ts +0 -7
- package/dist/test/escapeRegEx.js +0 -9
- package/dist/test/normalizeOutput.d.ts +0 -3
- package/dist/test/normalizeOutput.js +0 -20
- package/dist/types.d.ts +0 -7
- package/dist/types.js +0 -2
- package/dist/util/errors.d.ts +0 -6
- package/dist/util/errors.js +0 -11
- package/dist/util/globP.d.ts +0 -7
- package/dist/util/globP.js +0 -7
- package/dist/util/index.d.ts +0 -2
- package/dist/util/index.js +0 -4
- package/dist/util/textRegex.d.ts +0 -3
- package/dist/util/textRegex.js +0 -109
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { CompileRequest, CompileSourceOptions as CompileSourceConfig, Target } from '../config/index.js';
|
|
2
|
-
interface CompileOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Optional filter function to filter targets.
|
|
5
|
-
*/
|
|
6
|
-
filter?: ((target: Target) => boolean) | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* The current working directory. Defaults to process.cwd()
|
|
9
|
-
*/
|
|
10
|
-
cwd?: string | undefined;
|
|
11
|
-
/**
|
|
12
|
-
* `true` - only build if files do not match checksum.
|
|
13
|
-
*/
|
|
14
|
-
conditionalBuild: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare function compile(request: CompileRequest, options?: CompileOptions): Promise<void>;
|
|
17
|
-
interface CompileTargetOptions {
|
|
18
|
-
rootDir: string;
|
|
19
|
-
cwd: string | undefined;
|
|
20
|
-
conditional: boolean;
|
|
21
|
-
checksumFile: string | undefined;
|
|
22
|
-
dictionaryDirectives: string[] | undefined;
|
|
23
|
-
}
|
|
24
|
-
export declare function compileTarget(target: Target, options: CompileSourceConfig, compileOptions: CompileTargetOptions): Promise<string[]>;
|
|
25
|
-
export {};
|
|
26
|
-
//# sourceMappingURL=compile.d.ts.map
|
package/dist/compiler/compile.js
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
import { pipeAsync, toArray } from '@cspell/cspell-pipe';
|
|
3
|
-
import { opAwaitAsync, opMapAsync } from '@cspell/cspell-pipe/operators';
|
|
4
|
-
import { opConcatMap, opMap, pipe } from '@cspell/cspell-pipe/sync';
|
|
5
|
-
import { isFileListSource, isFilePath, isFileSource } from '../config/index.js';
|
|
6
|
-
import { checkShasumFile, updateChecksumForFiles } from '../shasum/index.js';
|
|
7
|
-
import { stringToRegExp } from '../util/textRegex.js';
|
|
8
|
-
import { createAllowedSplitWordsFromFiles, createWordsCollectionFromFiles } from './createWordsCollection.js';
|
|
9
|
-
import { logWithTimestamp } from './logWithTimestamp.js';
|
|
10
|
-
import { readTextFile } from './readers/readTextFile.js';
|
|
11
|
-
import { streamSourceWordsFromFile } from './streamSourceWordsFromFile.js';
|
|
12
|
-
import { createTargetFile, createTrieCompiler, createWordListCompiler } from './wordListCompiler.js';
|
|
13
|
-
import { normalizeTargetWords } from './wordListParser.js';
|
|
14
|
-
export async function compile(request, options) {
|
|
15
|
-
const { targets } = request;
|
|
16
|
-
// console.warn('Request: %o', request);
|
|
17
|
-
const rootDir = path.resolve(request.rootDir || '.');
|
|
18
|
-
const cwd = options?.cwd;
|
|
19
|
-
const targetOptions = {
|
|
20
|
-
sort: request.sort,
|
|
21
|
-
generateNonStrict: request.generateNonStrict,
|
|
22
|
-
removeDuplicates: request.removeDuplicates,
|
|
23
|
-
};
|
|
24
|
-
const conditional = options?.conditionalBuild || false;
|
|
25
|
-
const checksumFile = resolveChecksumFile(request.checksumFile || conditional, rootDir);
|
|
26
|
-
const dictionaryDirectives = request.dictionaryDirectives;
|
|
27
|
-
const dependencies = new Set();
|
|
28
|
-
for (const target of targets) {
|
|
29
|
-
const keep = options?.filter?.(target) ?? true;
|
|
30
|
-
if (!keep)
|
|
31
|
-
continue;
|
|
32
|
-
const adjustedTarget = { ...targetOptions, ...target };
|
|
33
|
-
// console.warn('adjustedTarget: %o', adjustedTarget);
|
|
34
|
-
const deps = await compileTarget(adjustedTarget, request, {
|
|
35
|
-
rootDir,
|
|
36
|
-
cwd,
|
|
37
|
-
conditional,
|
|
38
|
-
checksumFile,
|
|
39
|
-
dictionaryDirectives,
|
|
40
|
-
});
|
|
41
|
-
deps.forEach((dep) => dependencies.add(dep));
|
|
42
|
-
}
|
|
43
|
-
if (checksumFile && dependencies.size) {
|
|
44
|
-
logWithTimestamp('%s', `Update checksum: ${checksumFile}`);
|
|
45
|
-
await updateChecksumForFiles(checksumFile, [...dependencies], { root: path.dirname(checksumFile) });
|
|
46
|
-
}
|
|
47
|
-
logWithTimestamp(`Complete.`);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
function resolveChecksumFile(checksumFile, root) {
|
|
51
|
-
const cFilename = (typeof checksumFile === 'string' && checksumFile) || (checksumFile && './checksum.txt') || undefined;
|
|
52
|
-
const file = cFilename && path.resolve(root, cFilename);
|
|
53
|
-
// console.warn('%o', { checksumFile, cFilename, file });
|
|
54
|
-
return file;
|
|
55
|
-
}
|
|
56
|
-
export async function compileTarget(target, options, compileOptions) {
|
|
57
|
-
logWithTimestamp(`Start compile: ${target.name}`);
|
|
58
|
-
const { rootDir, cwd, checksumFile, conditional } = compileOptions;
|
|
59
|
-
const { format, sources, trieBase, sort = true, generateNonStrict = false, excludeWordsFrom = [], excludeWordsNotFoundIn = [], excludeWordsMatchingRegex, } = target;
|
|
60
|
-
const targetDirectory = path.resolve(rootDir, target.targetDirectory ?? cwd ?? process.cwd());
|
|
61
|
-
const dictionaryDirectives = target.dictionaryDirectives ?? compileOptions.dictionaryDirectives;
|
|
62
|
-
const removeDuplicates = target.removeDuplicates ?? false;
|
|
63
|
-
const excludeFromFilter = await createExcludeFilter(excludeWordsFrom);
|
|
64
|
-
const includeFromFilter = await createIncludeFilter(excludeWordsNotFoundIn);
|
|
65
|
-
const excludeRegexFilter = createExcludeRegexFilter(excludeWordsMatchingRegex);
|
|
66
|
-
const excludeFilter = (word) => {
|
|
67
|
-
return excludeFromFilter(word) && includeFromFilter(word) && excludeRegexFilter(word);
|
|
68
|
-
};
|
|
69
|
-
const name = normalizeTargetName(target.name);
|
|
70
|
-
const useTrie = format.startsWith('trie');
|
|
71
|
-
const generateCompressed = target.compress ?? false;
|
|
72
|
-
const generateUncompressed = target.keepUncompressed ?? false;
|
|
73
|
-
const genSet = new Set();
|
|
74
|
-
genSet.add(generateCompressed);
|
|
75
|
-
if (generateUncompressed) {
|
|
76
|
-
genSet.add(false);
|
|
77
|
-
}
|
|
78
|
-
const filename = resolveTarget(name, targetDirectory, useTrie);
|
|
79
|
-
const filesToProcessAsync = pipeAsync(readSourceList(sources, rootDir), opMapAsync((src) => readFileSource(src, options)), opAwaitAsync());
|
|
80
|
-
const filesToProcess = await toArray(filesToProcessAsync);
|
|
81
|
-
const normalizer = normalizeTargetWords({
|
|
82
|
-
sort: useTrie || sort,
|
|
83
|
-
generateNonStrict,
|
|
84
|
-
filter: excludeFilter,
|
|
85
|
-
dictionaryDirectives,
|
|
86
|
-
// removeDuplicates, // Add this in if we use it.
|
|
87
|
-
});
|
|
88
|
-
const checksumRoot = (checksumFile && path.dirname(checksumFile)) || rootDir;
|
|
89
|
-
const deps = [
|
|
90
|
-
...calculateDependencies(filename + (generateCompressed ? '.gz' : ''), filesToProcess, [...excludeWordsFrom, ...excludeWordsNotFoundIn], checksumRoot),
|
|
91
|
-
];
|
|
92
|
-
if (conditional && checksumFile) {
|
|
93
|
-
const check = await checkShasumFile(checksumFile, deps, checksumRoot).catch(() => undefined);
|
|
94
|
-
if (check?.passed) {
|
|
95
|
-
logWithTimestamp(`Skip ${target.name}, nothing changed.`);
|
|
96
|
-
return [];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async function action(words, dst) {
|
|
100
|
-
const compiler = useTrie
|
|
101
|
-
? createTrieCompiler({
|
|
102
|
-
base: trieBase,
|
|
103
|
-
trie3: format === 'trie3',
|
|
104
|
-
trie4: format === 'trie4',
|
|
105
|
-
})
|
|
106
|
-
: createWordListCompiler({
|
|
107
|
-
sort,
|
|
108
|
-
generateNonStrict,
|
|
109
|
-
dictionaryDirectives,
|
|
110
|
-
removeDuplicates,
|
|
111
|
-
});
|
|
112
|
-
const data = iterableToString(pipe(words, normalizer, compiler));
|
|
113
|
-
for (const compress of genSet) {
|
|
114
|
-
await createTargetFile(dst, data, compress);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
await processFiles({ action, filesToProcess, mergeTarget: filename });
|
|
118
|
-
logWithTimestamp(`Done compile: ${target.name}`);
|
|
119
|
-
return deps;
|
|
120
|
-
}
|
|
121
|
-
function calculateDependencies(targetFile, filesToProcess, extraDependencyFiles, rootDir) {
|
|
122
|
-
const dependencies = new Set();
|
|
123
|
-
addDependency(targetFile);
|
|
124
|
-
extraDependencyFiles?.forEach((f) => addDependency(f));
|
|
125
|
-
filesToProcess.forEach((f) => addDependency(f.src));
|
|
126
|
-
return dependencies;
|
|
127
|
-
function addDependency(filename) {
|
|
128
|
-
const rel = path.relative(rootDir, filename);
|
|
129
|
-
dependencies.add(rel);
|
|
130
|
-
dependencies.add(rel.replace(/\.aff$/, '.dic'));
|
|
131
|
-
dependencies.add(rel.replace(/\.dic$/, '.aff'));
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function rel(filePath) {
|
|
135
|
-
return path.relative(process.cwd(), filePath);
|
|
136
|
-
}
|
|
137
|
-
async function processFiles({ action, filesToProcess, mergeTarget }) {
|
|
138
|
-
const toProcess = filesToProcess;
|
|
139
|
-
const dst = mergeTarget;
|
|
140
|
-
const words = pipe(toProcess, opMap((ftp) => {
|
|
141
|
-
const { src } = ftp;
|
|
142
|
-
logWithTimestamp('Process "%s" to "%s"', rel(src), rel(dst));
|
|
143
|
-
return ftp;
|
|
144
|
-
}), opConcatMap(function* (ftp) {
|
|
145
|
-
yield* ftp.words;
|
|
146
|
-
logWithTimestamp('Done processing %s', rel(ftp.src));
|
|
147
|
-
}),
|
|
148
|
-
// opMap((a) => (console.warn(a), a))
|
|
149
|
-
logProgress());
|
|
150
|
-
await action(words, dst);
|
|
151
|
-
logWithTimestamp('Done "%s"', rel(dst));
|
|
152
|
-
}
|
|
153
|
-
function resolveTarget(name, directory, useTrie) {
|
|
154
|
-
const ext = (useTrie && '.trie') || '.txt';
|
|
155
|
-
const filename = name + ext;
|
|
156
|
-
return path.resolve(directory, filename);
|
|
157
|
-
}
|
|
158
|
-
function readSourceList(sources, rootDir) {
|
|
159
|
-
async function* mapSrc() {
|
|
160
|
-
for (const src of sources) {
|
|
161
|
-
if (isFilePath(src)) {
|
|
162
|
-
yield { filename: path.resolve(rootDir, src) };
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
if (isFileSource(src)) {
|
|
166
|
-
yield { ...src, filename: path.resolve(rootDir, src.filename) };
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if (isFileListSource(src)) {
|
|
170
|
-
const { listFile, ...rest } = src;
|
|
171
|
-
const absListFile = path.resolve(rootDir, listFile);
|
|
172
|
-
const listFileDir = path.dirname(absListFile);
|
|
173
|
-
const files = await readFileList(absListFile);
|
|
174
|
-
for (const filename of files) {
|
|
175
|
-
yield { ...rest, filename: path.resolve(listFileDir, filename) };
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return mapSrc();
|
|
181
|
-
}
|
|
182
|
-
async function readFileList(fileList) {
|
|
183
|
-
const content = await readTextFile(fileList);
|
|
184
|
-
return content
|
|
185
|
-
.split('\n')
|
|
186
|
-
.map((a) => a.trim())
|
|
187
|
-
.filter((a) => !!a);
|
|
188
|
-
}
|
|
189
|
-
async function readFileSource(fileSource, sourceOptions) {
|
|
190
|
-
const { filename, keepRawCase = sourceOptions.keepRawCase || false, split = sourceOptions.split || false, maxDepth, storeSplitWordsAsCompounds, minCompoundLength, } = fileSource;
|
|
191
|
-
const legacy = split === 'legacy';
|
|
192
|
-
const splitWords = legacy ? false : split;
|
|
193
|
-
// console.warn('fileSource: %o,\n targetOptions %o, \n opt: %o', fileSource, targetOptions, opt);
|
|
194
|
-
const allowedSplitWords = await createAllowedSplitWordsFromFiles(fileSource.allowedSplitWords || sourceOptions.allowedSplitWords);
|
|
195
|
-
const readerOptions = {
|
|
196
|
-
maxDepth,
|
|
197
|
-
legacy,
|
|
198
|
-
splitWords,
|
|
199
|
-
keepCase: keepRawCase,
|
|
200
|
-
allowedSplitWords,
|
|
201
|
-
storeSplitWordsAsCompounds,
|
|
202
|
-
minCompoundLength,
|
|
203
|
-
};
|
|
204
|
-
logWithTimestamp(`Reading ${path.basename(filename)}`);
|
|
205
|
-
const stream = await streamSourceWordsFromFile(filename, readerOptions);
|
|
206
|
-
logWithTimestamp(`Done reading ${path.basename(filename)}`);
|
|
207
|
-
const f = {
|
|
208
|
-
src: filename,
|
|
209
|
-
words: stream,
|
|
210
|
-
};
|
|
211
|
-
return f;
|
|
212
|
-
}
|
|
213
|
-
function normalizeTargetName(name) {
|
|
214
|
-
return name.replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '').replaceAll(/[^\p{L}\p{M}.\w\\/-]/gu, '_');
|
|
215
|
-
}
|
|
216
|
-
function logProgress(freq = 100_000) {
|
|
217
|
-
function* logProgress(iter) {
|
|
218
|
-
const _freq = freq;
|
|
219
|
-
let count = 0;
|
|
220
|
-
for (const v of iter) {
|
|
221
|
-
++count;
|
|
222
|
-
if (!(count % _freq)) {
|
|
223
|
-
logWithTimestamp('Progress: Words Processed - %s', count.toLocaleString());
|
|
224
|
-
}
|
|
225
|
-
yield v;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return logProgress;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* @param excludeWordsFrom - List of files to read words from.
|
|
232
|
-
* @returns a function that returns true if the word is not in the exclude list.
|
|
233
|
-
*/
|
|
234
|
-
async function createExcludeFilter(excludeWordsFrom) {
|
|
235
|
-
if (!excludeWordsFrom || !excludeWordsFrom.length)
|
|
236
|
-
return () => true;
|
|
237
|
-
const excludeWords = await createWordsCollectionFromFiles(excludeWordsFrom);
|
|
238
|
-
return (word) => !excludeWords.has(word, word.toUpperCase() !== word);
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* @param includeWordsFrom - List of files to read words from.
|
|
242
|
-
* @returns a function that returns true if the word is in the include list.
|
|
243
|
-
*/
|
|
244
|
-
async function createIncludeFilter(includeWordsFrom) {
|
|
245
|
-
if (!includeWordsFrom || !includeWordsFrom.length)
|
|
246
|
-
return () => true;
|
|
247
|
-
const excludeWords = await createWordsCollectionFromFiles(includeWordsFrom);
|
|
248
|
-
return (word) => excludeWords.has(word, word.toUpperCase() !== word);
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* @param excludeWordsMatchingRegex - List of regex patterns to exclude.
|
|
252
|
-
* @returns a function that returns true if the word does not match any of the regex patterns.
|
|
253
|
-
*/
|
|
254
|
-
function createExcludeRegexFilter(excludeWordsMatchingRegex) {
|
|
255
|
-
if (!excludeWordsMatchingRegex || !excludeWordsMatchingRegex.length)
|
|
256
|
-
return () => true;
|
|
257
|
-
const regexes = excludeWordsMatchingRegex
|
|
258
|
-
.map((a) => stringToRegExp(a))
|
|
259
|
-
.filter((a, i) => {
|
|
260
|
-
if (a)
|
|
261
|
-
return true;
|
|
262
|
-
console.warn('Invalid regex: "%s"', excludeWordsMatchingRegex[i]);
|
|
263
|
-
return false;
|
|
264
|
-
});
|
|
265
|
-
return (word) => !regexes.some((r) => r.test(word));
|
|
266
|
-
}
|
|
267
|
-
function iterableToString(iter) {
|
|
268
|
-
return Array.isArray(iter) ? iter.join('') : [...iter].join('');
|
|
269
|
-
}
|
|
270
|
-
//# sourceMappingURL=compile.js.map
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { CompileCommonAppOptions } from '../AppOptions.js';
|
|
2
|
-
import type { CompileRequest } from '../config/index.js';
|
|
3
|
-
export declare function createCompileRequest(sourceFiles: string[], options: CompileCommonAppOptions): CompileRequest;
|
|
4
|
-
//# sourceMappingURL=createCompileRequest.d.ts.map
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
export function createCompileRequest(sourceFiles, options) {
|
|
3
|
-
options = { ...options };
|
|
4
|
-
options.maxDepth ??= options.max_depth;
|
|
5
|
-
const { maxDepth, split, keepRawCase, useLegacySplitter } = options;
|
|
6
|
-
const sources = [...sourceFiles, ...(options.listFile || []).map((listFile) => ({ listFile }))];
|
|
7
|
-
const targets = calcTargets(sources, options);
|
|
8
|
-
const req = {
|
|
9
|
-
targets,
|
|
10
|
-
maxDepth: parseNumber(maxDepth),
|
|
11
|
-
split: useLegacySplitter ? 'legacy' : split,
|
|
12
|
-
/**
|
|
13
|
-
* Do not generate lower case / accent free versions of words.
|
|
14
|
-
* @default false
|
|
15
|
-
*/
|
|
16
|
-
keepRawCase,
|
|
17
|
-
};
|
|
18
|
-
return req;
|
|
19
|
-
}
|
|
20
|
-
function calcTargets(sources, options) {
|
|
21
|
-
const { merge, output = '.', experimental = [] } = options;
|
|
22
|
-
const generateNonStrict = experimental.includes('compound') || undefined;
|
|
23
|
-
// console.log('%o', sources);
|
|
24
|
-
const format = calcFormat(options);
|
|
25
|
-
const sort = (format === 'plaintext' && options.sort) || undefined;
|
|
26
|
-
if (merge) {
|
|
27
|
-
const target = {
|
|
28
|
-
name: merge,
|
|
29
|
-
targetDirectory: output,
|
|
30
|
-
compress: options.compress,
|
|
31
|
-
format,
|
|
32
|
-
sources: sources.map(normalizeSource),
|
|
33
|
-
sort,
|
|
34
|
-
trieBase: parseNumber(options.trieBase),
|
|
35
|
-
generateNonStrict,
|
|
36
|
-
};
|
|
37
|
-
return [target];
|
|
38
|
-
}
|
|
39
|
-
const targets = sources.map((source) => {
|
|
40
|
-
const name = toTargetName(baseNameOfSource(source));
|
|
41
|
-
const target = {
|
|
42
|
-
name,
|
|
43
|
-
targetDirectory: output,
|
|
44
|
-
compress: options.compress,
|
|
45
|
-
format,
|
|
46
|
-
sources: [normalizeSource(source)],
|
|
47
|
-
sort: options.sort,
|
|
48
|
-
trieBase: parseNumber(options.trieBase),
|
|
49
|
-
generateNonStrict,
|
|
50
|
-
};
|
|
51
|
-
return target;
|
|
52
|
-
});
|
|
53
|
-
return targets;
|
|
54
|
-
}
|
|
55
|
-
function calcFormat(options) {
|
|
56
|
-
return (options.trie4 && 'trie4') || (options.trie3 && 'trie3') || (options.trie && 'trie') || 'plaintext';
|
|
57
|
-
}
|
|
58
|
-
function toTargetName(sourceFile) {
|
|
59
|
-
return path.basename(sourceFile).replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '');
|
|
60
|
-
}
|
|
61
|
-
function parseNumber(s) {
|
|
62
|
-
const n = Number.parseInt(s ?? '');
|
|
63
|
-
return Number.isNaN(n) ? undefined : n;
|
|
64
|
-
}
|
|
65
|
-
function baseNameOfSource(source) {
|
|
66
|
-
return typeof source === 'string' ? source : isFileSource(source) ? source.filename : source.listFile;
|
|
67
|
-
}
|
|
68
|
-
function isFileSource(source) {
|
|
69
|
-
return typeof source !== 'string' && source.filename !== undefined;
|
|
70
|
-
}
|
|
71
|
-
function normalizeSource(source) {
|
|
72
|
-
if (typeof source === 'string') {
|
|
73
|
-
return normalizeSourcePath(source);
|
|
74
|
-
}
|
|
75
|
-
if (isFileSource(source))
|
|
76
|
-
return { ...source, filename: normalizeSourcePath(source.filename) };
|
|
77
|
-
return { ...source, listFile: normalizeSourcePath(source.listFile) };
|
|
78
|
-
}
|
|
79
|
-
function normalizeSourcePath(source) {
|
|
80
|
-
const cwd = process.cwd();
|
|
81
|
-
const rel = path.relative(cwd, source);
|
|
82
|
-
return rel.split('\\').join('/');
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=createCompileRequest.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { FilePath, FilePathOrFilePathArray } from '../config/config.js';
|
|
2
|
-
import type { AllowedSplitWordsCollection, ExcludeWordsCollection, WordsCollection } from './WordsCollection.js';
|
|
3
|
-
export declare function createAllowedSplitWordsFromFiles(files: FilePathOrFilePathArray | undefined): Promise<AllowedSplitWordsCollection>;
|
|
4
|
-
export declare function createAllowedSplitWords(words: Iterable<string> | undefined): AllowedSplitWordsCollection;
|
|
5
|
-
export declare function createWordsCollectionFromFiles(files: FilePathOrFilePathArray): Promise<WordsCollection>;
|
|
6
|
-
export declare function createWordsCollection(words: Iterable<string>): WordsCollection;
|
|
7
|
-
export declare function createExcludeWordsCollectionFromFiles(files: FilePathOrFilePathArray | undefined): Promise<ExcludeWordsCollection>;
|
|
8
|
-
export declare function createExcludeWordsCollection(words: Iterable<string> | undefined): ExcludeWordsCollection;
|
|
9
|
-
export declare function toFilePathArray(filePathOrArray: FilePathOrFilePathArray): FilePath[];
|
|
10
|
-
//# sourceMappingURL=createWordsCollection.d.ts.map
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { parseDictionary } from 'cspell-trie-lib';
|
|
2
|
-
import { createReader } from './Reader.js';
|
|
3
|
-
import { defaultAllowedSplitWords, defaultExcludeWordsCollection } from './WordsCollection.js';
|
|
4
|
-
class AllowedSplitWordsImpl {
|
|
5
|
-
collection;
|
|
6
|
-
size;
|
|
7
|
-
constructor(collection) {
|
|
8
|
-
this.collection = collection;
|
|
9
|
-
this.size = collection.size;
|
|
10
|
-
}
|
|
11
|
-
has(word, caseSensitive) {
|
|
12
|
-
return !this.size || this.collection.has(word, caseSensitive);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export async function createAllowedSplitWordsFromFiles(files) {
|
|
16
|
-
if (!files || !files.length)
|
|
17
|
-
return defaultAllowedSplitWords;
|
|
18
|
-
const collection = await createWordsCollectionFromFiles(files);
|
|
19
|
-
return new AllowedSplitWordsImpl(collection);
|
|
20
|
-
}
|
|
21
|
-
export function createAllowedSplitWords(words) {
|
|
22
|
-
if (!words)
|
|
23
|
-
return defaultAllowedSplitWords;
|
|
24
|
-
return new AllowedSplitWordsImpl(createWordsCollection(words));
|
|
25
|
-
}
|
|
26
|
-
function buildHasFn(dict) {
|
|
27
|
-
function has(word, caseSensitive) {
|
|
28
|
-
const r = dict.hasWord(word, true);
|
|
29
|
-
if (r || caseSensitive)
|
|
30
|
-
return r;
|
|
31
|
-
const lc = word.toLowerCase();
|
|
32
|
-
if (lc == word)
|
|
33
|
-
return false;
|
|
34
|
-
return dict.hasWord(lc, true);
|
|
35
|
-
}
|
|
36
|
-
return has;
|
|
37
|
-
}
|
|
38
|
-
async function readFile(filename) {
|
|
39
|
-
return await createReader(filename, {});
|
|
40
|
-
}
|
|
41
|
-
function readersToCollection(readers) {
|
|
42
|
-
const dictReaders = readers.filter(isDictionaryReader).map(dictReaderToCollection);
|
|
43
|
-
const nonDictCollection = lineReadersToCollection(readers.filter((a) => !isDictionaryReader(a)));
|
|
44
|
-
const collections = [...dictReaders, nonDictCollection];
|
|
45
|
-
const collection = {
|
|
46
|
-
size: collections.reduce((s, a) => s + a.size, 0),
|
|
47
|
-
has: (word, caseSensitive) => collections.some((a) => a.has(word, caseSensitive)),
|
|
48
|
-
};
|
|
49
|
-
return collection;
|
|
50
|
-
}
|
|
51
|
-
const cache = new WeakMap();
|
|
52
|
-
export async function createWordsCollectionFromFiles(files) {
|
|
53
|
-
files = toFilePathArray(files);
|
|
54
|
-
const cached = cache.get(files);
|
|
55
|
-
if (cached)
|
|
56
|
-
return cached;
|
|
57
|
-
const sources = await Promise.all(files.map((file) => readFile(file)));
|
|
58
|
-
const collection = readersToCollection(sources);
|
|
59
|
-
cache.set(files, collection);
|
|
60
|
-
return collection;
|
|
61
|
-
}
|
|
62
|
-
export function createWordsCollection(words) {
|
|
63
|
-
if (words instanceof Set)
|
|
64
|
-
return words;
|
|
65
|
-
const arrWords = (Array.isArray(words) ? words : [...words])
|
|
66
|
-
.map((a) => a.trim())
|
|
67
|
-
.filter((a) => !!a)
|
|
68
|
-
.filter((a) => !a.startsWith('#'));
|
|
69
|
-
const setOfWords = new Set(arrWords);
|
|
70
|
-
const has = buildHasFn({ hasWord: (word) => setOfWords.has(word) });
|
|
71
|
-
return { size: setOfWords.size, has };
|
|
72
|
-
}
|
|
73
|
-
class ExcludeWordsCollectionImpl {
|
|
74
|
-
collection;
|
|
75
|
-
size;
|
|
76
|
-
constructor(collection) {
|
|
77
|
-
this.collection = collection;
|
|
78
|
-
this.size = collection.size;
|
|
79
|
-
}
|
|
80
|
-
has(word, caseSensitive) {
|
|
81
|
-
return this.collection.has(word, caseSensitive);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
export async function createExcludeWordsCollectionFromFiles(files) {
|
|
85
|
-
if (!files || !files.length)
|
|
86
|
-
return defaultExcludeWordsCollection;
|
|
87
|
-
const collection = await createWordsCollectionFromFiles(files);
|
|
88
|
-
return new ExcludeWordsCollectionImpl(collection);
|
|
89
|
-
}
|
|
90
|
-
export function createExcludeWordsCollection(words) {
|
|
91
|
-
return new ExcludeWordsCollectionImpl(words ? createWordsCollection(words) : new Set());
|
|
92
|
-
}
|
|
93
|
-
function isDictionaryReader(reader) {
|
|
94
|
-
return 'hasWord' in reader && !!reader.hasWord;
|
|
95
|
-
}
|
|
96
|
-
function dictReaderToCollection(reader) {
|
|
97
|
-
return { size: reader.size, has: buildHasFn(reader) };
|
|
98
|
-
}
|
|
99
|
-
function lineReadersToCollection(readers) {
|
|
100
|
-
function* words() {
|
|
101
|
-
for (const reader of readers) {
|
|
102
|
-
yield* reader.lines;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const dict = parseDictionary(words(), { stripCaseAndAccents: false });
|
|
106
|
-
return { size: dict.size, has: buildHasFn(dict) };
|
|
107
|
-
}
|
|
108
|
-
export function toFilePathArray(filePathOrArray) {
|
|
109
|
-
return Array.isArray(filePathOrArray) ? filePathOrArray : [filePathOrArray];
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=createWordsCollection.js.map
|
package/dist/compiler/index.d.ts
DELETED
package/dist/compiler/index.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { AllowedSplitWordsCollection } from './WordsCollection.js';
|
|
2
|
-
export declare function legacyLineToWords(line: string, keepCase: boolean, allowedSplitWords: AllowedSplitWordsCollection): Iterable<string>;
|
|
3
|
-
export declare function legacyLinesToWords(lines: Iterable<string>, keepCase: boolean, allowedSplitWords: AllowedSplitWordsCollection): Iterable<string>;
|
|
4
|
-
//# sourceMappingURL=legacyLineToWords.d.ts.map
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { opConcatMap, opFilter, opMap, pipe } from '@cspell/cspell-pipe/sync';
|
|
2
|
-
import { defaultCompileSourceOptions } from '../config/configDefaults.js';
|
|
3
|
-
import { regExpSpaceOrDash, splitCamelCaseIfAllowed } from './splitCamelCaseIfAllowed.js';
|
|
4
|
-
const regNonWord = /[^\p{L}\p{M}' _\d]+/giu;
|
|
5
|
-
const regExpRepeatChars = /(.)\1{5}/i;
|
|
6
|
-
const minCompoundLength = defaultCompileSourceOptions.minCompoundLength;
|
|
7
|
-
export function legacyLineToWords(line, keepCase, allowedSplitWords) {
|
|
8
|
-
// Remove punctuation and non-letters.
|
|
9
|
-
const filteredLine = line.replaceAll(regNonWord, '|');
|
|
10
|
-
const wordGroups = filteredLine.split('|');
|
|
11
|
-
const _minCompoundLength = minCompoundLength;
|
|
12
|
-
const words = pipe(wordGroups, opConcatMap((a) => a.split(regExpSpaceOrDash)), opConcatMap((a) => splitCamelCaseIfAllowed(a, allowedSplitWords, keepCase, '', _minCompoundLength)), opMap((a) => a.trim()), opFilter((a) => !!a), opFilter((s) => !regExpRepeatChars.test(s)));
|
|
13
|
-
return words;
|
|
14
|
-
}
|
|
15
|
-
export function* legacyLinesToWords(lines, keepCase, allowedSplitWords) {
|
|
16
|
-
for (const line of lines) {
|
|
17
|
-
yield* legacyLineToWords(line, keepCase, allowedSplitWords);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=legacyLineToWords.js.map
|
package/dist/compiler/logger.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface ReaderOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Max Hunspell recursive depth.
|
|
4
|
-
*/
|
|
5
|
-
maxDepth?: number | undefined;
|
|
6
|
-
}
|
|
7
|
-
export type AnnotatedWord = string;
|
|
8
|
-
export interface BaseReader {
|
|
9
|
-
size: number;
|
|
10
|
-
type: 'Hunspell' | 'TextFile' | 'Trie';
|
|
11
|
-
lines: Iterable<AnnotatedWord>;
|
|
12
|
-
readonly hasWord?: (word: string, caseSensitive: boolean) => boolean;
|
|
13
|
-
}
|
|
14
|
-
export interface Reader extends BaseReader {
|
|
15
|
-
}
|
|
16
|
-
export interface DictionaryReader extends BaseReader {
|
|
17
|
-
readonly hasWord: (word: string, caseSensitive: boolean) => boolean;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=ReaderOptions.d.ts.map
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { pipe } from '@cspell/cspell-pipe/sync';
|
|
2
|
-
import { COMPOUND_FIX, FORBID_PREFIX } from 'cspell-trie-lib';
|
|
3
|
-
import * as HR from 'hunspell-reader';
|
|
4
|
-
import { regHunspellFile } from './regHunspellFile.js';
|
|
5
|
-
const DEDUPE_SIZE = 1000;
|
|
6
|
-
export async function readHunspellFiles(filename, options) {
|
|
7
|
-
const dicFile = filename.replace(regHunspellFile, '.dic');
|
|
8
|
-
const affFile = filename.replace(regHunspellFile, '.aff');
|
|
9
|
-
const reader = await HR.IterableHunspellReader.createFromFiles(affFile, dicFile);
|
|
10
|
-
reader.maxDepth = options.maxDepth !== undefined ? options.maxDepth : reader.maxDepth;
|
|
11
|
-
const words = pipe(reader.seqAffWords(), _mapAffWords, dedupeAndSort);
|
|
12
|
-
return {
|
|
13
|
-
type: 'Hunspell',
|
|
14
|
-
size: reader.dic.length,
|
|
15
|
-
lines: words,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function* dedupeAndSort(words) {
|
|
19
|
-
const buffer = new Set();
|
|
20
|
-
function flush() {
|
|
21
|
-
const result = [...buffer].sort();
|
|
22
|
-
buffer.clear();
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
for (const word of words) {
|
|
26
|
-
buffer.add(word);
|
|
27
|
-
if (buffer.size >= DEDUPE_SIZE) {
|
|
28
|
-
yield* flush();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
yield* flush();
|
|
32
|
-
}
|
|
33
|
-
function* _mapAffWords(affWords) {
|
|
34
|
-
const hasSpecial = /[~+!]/;
|
|
35
|
-
for (const affWord of affWords) {
|
|
36
|
-
const { word, flags } = affWord;
|
|
37
|
-
// For now do not include words with special characters.
|
|
38
|
-
if (hasSpecial.test(word))
|
|
39
|
-
continue;
|
|
40
|
-
const compound = flags.isCompoundForbidden ? '' : COMPOUND_FIX;
|
|
41
|
-
const forbid = flags.isForbiddenWord ? FORBID_PREFIX : '';
|
|
42
|
-
if (!forbid) {
|
|
43
|
-
if (flags.canBeCompoundBegin || flags.isCompoundPermitted)
|
|
44
|
-
yield word + compound;
|
|
45
|
-
if (flags.canBeCompoundEnd || flags.isCompoundPermitted)
|
|
46
|
-
yield compound + word;
|
|
47
|
-
if (flags.canBeCompoundMiddle || flags.isCompoundPermitted)
|
|
48
|
-
yield compound + word + compound;
|
|
49
|
-
if (!flags.isOnlyAllowedInCompound)
|
|
50
|
-
yield word;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
yield forbid + word;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=readHunspellFiles.js.map
|