@cspell/cspell-tools 6.11.1 → 6.13.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/AppOptions.d.ts +28 -0
- package/dist/AppOptions.js +3 -0
- package/dist/FeatureFlags/FeatureFlags.d.ts +34 -0
- package/dist/FeatureFlags/FeatureFlags.js +99 -0
- package/dist/FeatureFlags/index.d.ts +3 -0
- package/dist/FeatureFlags/index.js +10 -0
- package/dist/FeatureFlags/parseFlags.d.ts +3 -0
- package/dist/FeatureFlags/parseFlags.js +24 -0
- package/dist/app.d.ts +2 -21
- package/dist/app.js +25 -144
- package/dist/build.d.ts +7 -0
- package/dist/build.js +59 -0
- package/dist/compile.d.ts +4 -0
- package/dist/compile.js +24 -0
- package/dist/compiler/CompileOptions.d.ts +12 -0
- package/dist/compiler/CompileOptions.js +3 -0
- package/dist/compiler/Reader.d.ts +16 -11
- package/dist/compiler/Reader.js +38 -91
- package/dist/compiler/compile.d.ts +11 -0
- package/dist/compiler/compile.js +157 -0
- package/dist/compiler/createCompileRequest.d.ts +4 -0
- package/dist/compiler/createCompileRequest.js +86 -0
- package/dist/compiler/fileWriter.d.ts +2 -3
- package/dist/compiler/fileWriter.js +5 -7
- package/dist/compiler/globP.d.ts +2 -0
- package/dist/compiler/globP.js +16 -0
- package/dist/compiler/index.d.ts +4 -1
- package/dist/compiler/index.js +9 -15
- package/dist/compiler/iterateWordsFromFile.d.ts +1 -2
- package/dist/compiler/iterateWordsFromFile.js +1 -1
- package/dist/compiler/legacyLineToWords.d.ts +3 -0
- package/dist/compiler/legacyLineToWords.js +54 -0
- package/dist/compiler/logWithTimestamp.d.ts +3 -0
- package/dist/compiler/logWithTimestamp.js +9 -0
- package/dist/compiler/logger.d.ts +4 -0
- package/dist/compiler/logger.js +14 -0
- package/dist/compiler/readTextFile.d.ts +3 -0
- package/dist/compiler/readTextFile.js +45 -0
- package/dist/compiler/wordListCompiler.d.ts +3 -33
- package/dist/compiler/wordListCompiler.js +13 -169
- package/dist/compiler/wordListParser.d.ts +46 -0
- package/dist/compiler/wordListParser.js +171 -0
- package/dist/compiler/writeTextToFile.d.ts +3 -0
- package/dist/compiler/writeTextToFile.js +44 -0
- package/dist/config/config.d.ts +109 -0
- package/dist/config/config.js +3 -0
- package/dist/config/configUtils.d.ts +5 -0
- package/dist/config/configUtils.js +20 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.js +10 -0
- package/dist/config/normalizeConfig.d.ts +8 -0
- package/dist/config/normalizeConfig.js +40 -0
- package/dist/test/TestHelper.d.ts +42 -0
- package/dist/test/TestHelper.js +131 -0
- package/dist/test/console.d.ts +10 -0
- package/dist/test/console.js +23 -0
- package/dist/test/escapeRegEx.d.ts +7 -0
- package/dist/test/escapeRegEx.js +13 -0
- package/dist/test/normalizeOutput.d.ts +3 -0
- package/dist/test/normalizeOutput.js +46 -0
- package/package.json +15 -11
package/dist/compiler/Reader.js
CHANGED
|
@@ -23,16 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const
|
|
28
|
-
const HR = __importStar(require("hunspell-reader"));
|
|
29
|
-
const fs = __importStar(require("fs-extra"));
|
|
26
|
+
exports.readHunspellFiles = exports.createReader = void 0;
|
|
27
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
30
28
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
31
|
-
const
|
|
29
|
+
const HR = __importStar(require("hunspell-reader"));
|
|
30
|
+
const readTextFile_1 = require("./readTextFile");
|
|
31
|
+
const wordListParser_1 = require("./wordListParser");
|
|
32
32
|
const regHunspellFile = /\.(dic|aff)$/i;
|
|
33
33
|
// cspell:word dedupe
|
|
34
34
|
const DEDUPE_SIZE = 1000;
|
|
35
|
-
const regExMatchComments = /\s*(#|\/\/).*/;
|
|
36
35
|
// Readers first match wins
|
|
37
36
|
const readers = [
|
|
38
37
|
{ test: /\.trie\b/, method: trieFileReader },
|
|
@@ -49,115 +48,66 @@ function findMatchingReader(filename, options) {
|
|
|
49
48
|
async function createReader(filename, options) {
|
|
50
49
|
const baseReader = await findMatchingReader(filename, options);
|
|
51
50
|
return Object.assign(baseReader, {
|
|
52
|
-
[Symbol.iterator]:
|
|
51
|
+
[Symbol.iterator]: () => baseReader.words[Symbol.iterator](),
|
|
53
52
|
});
|
|
54
53
|
}
|
|
55
54
|
exports.createReader = createReader;
|
|
56
|
-
function createArrayReader(lines) {
|
|
57
|
-
const rawWords = () => (0, gensequence_1.genSequence)(lines);
|
|
58
|
-
const annotatedWords = () => (0, gensequence_1.genSequence)(lines).pipe(_mapText, dedupeAndSort);
|
|
59
|
-
return {
|
|
60
|
-
size: lines.length,
|
|
61
|
-
annotatedWords,
|
|
62
|
-
rawWords,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
exports.createArrayReader = createArrayReader;
|
|
66
55
|
async function readHunspellFiles(filename, options) {
|
|
67
56
|
const dicFile = filename.replace(regHunspellFile, '.dic');
|
|
68
57
|
const affFile = filename.replace(regHunspellFile, '.aff');
|
|
69
58
|
const reader = await HR.IterableHunspellReader.createFromFiles(affFile, dicFile);
|
|
70
59
|
reader.maxDepth = options.maxDepth !== undefined ? options.maxDepth : reader.maxDepth;
|
|
71
|
-
const
|
|
72
|
-
const rawWords = () => reader.seqWords();
|
|
60
|
+
const words = (0, sync_1.pipe)(reader.seqAffWords(), _mapAffWords, dedupeAndSort);
|
|
73
61
|
return {
|
|
74
62
|
size: reader.dic.length,
|
|
75
|
-
|
|
76
|
-
return reader.seqAffWords().pipe(_mapAffWords, normalizeAndDedupe);
|
|
77
|
-
},
|
|
78
|
-
rawWords,
|
|
63
|
+
words,
|
|
79
64
|
};
|
|
80
65
|
}
|
|
81
66
|
exports.readHunspellFiles = readHunspellFiles;
|
|
82
67
|
async function trieFileReader(filename) {
|
|
83
|
-
const trieRoot = (0, cspell_trie_lib_1.importTrie)(await
|
|
68
|
+
const trieRoot = (0, cspell_trie_lib_1.importTrie)(await (0, readTextFile_1.readTextFileLines)(filename));
|
|
84
69
|
const trie = new cspell_trie_lib_1.Trie(trieRoot);
|
|
85
|
-
const
|
|
70
|
+
const words = trie.words();
|
|
86
71
|
return {
|
|
87
72
|
get size() {
|
|
88
73
|
return trie.size();
|
|
89
74
|
},
|
|
90
|
-
|
|
91
|
-
rawWords,
|
|
75
|
+
words,
|
|
92
76
|
};
|
|
93
77
|
}
|
|
94
|
-
function
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
async function textFileReader(filename, _options) {
|
|
103
|
-
const lines = await readTextFile(filename);
|
|
104
|
-
return createArrayReader(lines);
|
|
105
|
-
}
|
|
106
|
-
const _mapText = gensequence_1.operators.pipe(_comments, _compoundBegin, _compoundEnd, _stripCaseAndAccents);
|
|
107
|
-
function* _comments(lines) {
|
|
108
|
-
for (const line of lines) {
|
|
109
|
-
const w = line.replace(regExMatchComments, '').trim();
|
|
110
|
-
if (w)
|
|
111
|
-
yield w;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function* _compoundEnd(lines) {
|
|
115
|
-
for (const line of lines) {
|
|
116
|
-
if (line[0] !== cspell_trie_lib_1.OPTIONAL_COMPOUND_FIX) {
|
|
117
|
-
yield line;
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
const w = line.slice(1);
|
|
121
|
-
yield w;
|
|
122
|
-
yield cspell_trie_lib_1.COMPOUND_FIX + w;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function* _compoundBegin(lines) {
|
|
126
|
-
for (const line of lines) {
|
|
127
|
-
if (line[line.length - 1] !== cspell_trie_lib_1.OPTIONAL_COMPOUND_FIX) {
|
|
128
|
-
yield line;
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const w = line.slice(0, -1);
|
|
132
|
-
yield w;
|
|
133
|
-
yield w + cspell_trie_lib_1.COMPOUND_FIX;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function* _stripCaseAndAccents(words) {
|
|
137
|
-
for (const word of words) {
|
|
138
|
-
// Words are normalized to the compact format: e + ` => è
|
|
139
|
-
yield word.normalize();
|
|
140
|
-
// covert to lower case and strip accents.
|
|
141
|
-
const n = word.toLowerCase().normalize('NFD').replace(/\p{M}/gu, '');
|
|
142
|
-
// All words are added for case-insensitive searches.
|
|
143
|
-
// It is a space / speed trade-off. In this case, speed is more important.
|
|
144
|
-
yield cspell_trie_lib_1.CASE_INSENSITIVE_PREFIX + n;
|
|
145
|
-
}
|
|
78
|
+
async function textFileReader(filename, options) {
|
|
79
|
+
const content = await (0, readTextFile_1.readTextFile)(filename);
|
|
80
|
+
const words = [...(0, wordListParser_1.parseFileLines)(content, { legacy: options.legacy, split: options.splitWords })];
|
|
81
|
+
return {
|
|
82
|
+
size: words.length,
|
|
83
|
+
words,
|
|
84
|
+
};
|
|
146
85
|
}
|
|
86
|
+
// function* _stripCaseAndAccents(words: Iterable<AnnotatedWord>): Iterable<AnnotatedWord> {
|
|
87
|
+
// for (const word of words) {
|
|
88
|
+
// // Words are normalized to the compact format: e + ` => è
|
|
89
|
+
// yield word.normalize();
|
|
90
|
+
// // covert to lower case and strip accents.
|
|
91
|
+
// const n = word.toLowerCase().normalize('NFD').replace(/\p{M}/gu, '');
|
|
92
|
+
// // All words are added for case-insensitive searches.
|
|
93
|
+
// // It is a space / speed trade-off. In this case, speed is more important.
|
|
94
|
+
// yield CASE_INSENSITIVE_PREFIX + n;
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
147
97
|
function* dedupeAndSort(words) {
|
|
148
|
-
const buffer =
|
|
149
|
-
function
|
|
150
|
-
const
|
|
151
|
-
buffer.
|
|
152
|
-
return
|
|
98
|
+
const buffer = new Set();
|
|
99
|
+
function flush() {
|
|
100
|
+
const result = [...buffer].sort();
|
|
101
|
+
buffer.clear();
|
|
102
|
+
return result;
|
|
153
103
|
}
|
|
154
104
|
for (const word of words) {
|
|
155
|
-
buffer.
|
|
156
|
-
if (buffer.
|
|
157
|
-
yield*
|
|
105
|
+
buffer.add(word);
|
|
106
|
+
if (buffer.size >= DEDUPE_SIZE) {
|
|
107
|
+
yield* flush();
|
|
158
108
|
}
|
|
159
109
|
}
|
|
160
|
-
yield*
|
|
110
|
+
yield* flush();
|
|
161
111
|
}
|
|
162
112
|
function* _mapAffWords(affWords) {
|
|
163
113
|
const hasSpecial = /[~+!]/;
|
|
@@ -183,7 +133,4 @@ function* _mapAffWords(affWords) {
|
|
|
183
133
|
}
|
|
184
134
|
}
|
|
185
135
|
}
|
|
186
|
-
exports.__testing__ = {
|
|
187
|
-
_stripCaseAndAccents,
|
|
188
|
-
};
|
|
189
136
|
//# sourceMappingURL=Reader.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CompileRequest, CompileSourceOptions, Target } from '../config';
|
|
2
|
+
interface CompileOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Optional filter function to filter targets.
|
|
5
|
+
*/
|
|
6
|
+
filter?: (target: Target) => boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function compile(request: CompileRequest, options?: CompileOptions): Promise<void>;
|
|
9
|
+
export declare function compileTarget(target: Target, options: CompileSourceOptions, rootDir: string): Promise<void>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.compileTarget = exports.compile = void 0;
|
|
27
|
+
const cspell_pipe_1 = require("@cspell/cspell-pipe");
|
|
28
|
+
const operators_1 = require("@cspell/cspell-pipe/operators");
|
|
29
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
30
|
+
const path = __importStar(require("path"));
|
|
31
|
+
const config_1 = require("../config");
|
|
32
|
+
const iterateWordsFromFile_1 = require("./iterateWordsFromFile");
|
|
33
|
+
const logWithTimestamp_1 = require("./logWithTimestamp");
|
|
34
|
+
const readTextFile_1 = require("./readTextFile");
|
|
35
|
+
const wordListCompiler_1 = require("./wordListCompiler");
|
|
36
|
+
const wordListParser_1 = require("./wordListParser");
|
|
37
|
+
async function compile(request, options) {
|
|
38
|
+
const { targets } = request;
|
|
39
|
+
// console.log('Request: %o', request);
|
|
40
|
+
const rootDir = path.resolve(request.rootDir || '.');
|
|
41
|
+
const targetOptions = {
|
|
42
|
+
sort: request.sort,
|
|
43
|
+
generateNonStrict: request.generateNonStrict,
|
|
44
|
+
};
|
|
45
|
+
for (const target of targets) {
|
|
46
|
+
const keep = options?.filter?.(target) ?? true;
|
|
47
|
+
if (!keep)
|
|
48
|
+
continue;
|
|
49
|
+
const adjustedTarget = { ...targetOptions, ...target };
|
|
50
|
+
await compileTarget(adjustedTarget, request, rootDir);
|
|
51
|
+
}
|
|
52
|
+
(0, logWithTimestamp_1.logWithTimestamp)(`Complete.`);
|
|
53
|
+
}
|
|
54
|
+
exports.compile = compile;
|
|
55
|
+
async function compileTarget(target, options, rootDir) {
|
|
56
|
+
(0, logWithTimestamp_1.logWithTimestamp)(`Start compile: ${target.name}`);
|
|
57
|
+
// console.log('Target: %o', target);
|
|
58
|
+
const { format, sources, trieBase, sort = true, generateNonStrict = false } = target;
|
|
59
|
+
const targetDirectory = path.resolve(rootDir, target.targetDirectory ?? process.cwd());
|
|
60
|
+
const generateNonStrictTrie = target.generateNonStrict ?? true;
|
|
61
|
+
const name = normalizeTargetName(target.name);
|
|
62
|
+
const useTrie = format.startsWith('trie');
|
|
63
|
+
const filename = resolveTarget(name, targetDirectory, useTrie, target.compress ?? false);
|
|
64
|
+
const filesToProcessAsync = (0, cspell_pipe_1.pipeAsync)(readSourceList(sources, rootDir), (0, operators_1.opMapAsync)((src) => readFileSource(src, options)), (0, operators_1.opAwaitAsync)());
|
|
65
|
+
const filesToProcess = await (0, cspell_pipe_1.toArray)(filesToProcessAsync);
|
|
66
|
+
const normalizer = (0, wordListParser_1.normalizeTargetWords)({ sort: useTrie || sort, generateNonStrict });
|
|
67
|
+
const action = useTrie
|
|
68
|
+
? async (words, dst) => {
|
|
69
|
+
return (0, wordListCompiler_1.compileTrie)((0, sync_1.pipe)(words, normalizer), dst, {
|
|
70
|
+
base: trieBase,
|
|
71
|
+
sort: false,
|
|
72
|
+
trie3: format === 'trie3',
|
|
73
|
+
trie4: format === 'trie4',
|
|
74
|
+
generateNonStrict: generateNonStrictTrie,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
: async (words, dst) => {
|
|
78
|
+
return (0, wordListCompiler_1.compileWordList)((0, sync_1.pipe)(words, normalizer), dst, { sort, generateNonStrict });
|
|
79
|
+
};
|
|
80
|
+
await processFiles(action, filesToProcess, filename);
|
|
81
|
+
(0, logWithTimestamp_1.logWithTimestamp)(`Done compile: ${target.name}`);
|
|
82
|
+
}
|
|
83
|
+
exports.compileTarget = compileTarget;
|
|
84
|
+
function rel(filePath) {
|
|
85
|
+
return path.relative(process.cwd(), filePath);
|
|
86
|
+
}
|
|
87
|
+
async function processFiles(action, filesToProcess, mergeTarget) {
|
|
88
|
+
const toProcess = filesToProcess;
|
|
89
|
+
const dst = mergeTarget;
|
|
90
|
+
const words = (0, sync_1.pipe)(toProcess, (0, sync_1.opMap)((ftp) => {
|
|
91
|
+
const { src } = ftp;
|
|
92
|
+
(0, logWithTimestamp_1.logWithTimestamp)('Process "%s" to "%s"', rel(src), rel(dst));
|
|
93
|
+
return ftp;
|
|
94
|
+
}), (0, sync_1.opConcatMap)(function* (ftp) {
|
|
95
|
+
yield* ftp.words;
|
|
96
|
+
(0, logWithTimestamp_1.logWithTimestamp)('Done processing %s', rel(ftp.src));
|
|
97
|
+
})
|
|
98
|
+
// opMap((a) => (console.warn(a), a))
|
|
99
|
+
);
|
|
100
|
+
await action(words, dst);
|
|
101
|
+
(0, logWithTimestamp_1.logWithTimestamp)('Done "%s"', rel(dst));
|
|
102
|
+
}
|
|
103
|
+
function resolveTarget(name, directory, useTrie, useGzCompress) {
|
|
104
|
+
const ext = ((useTrie && '.trie') || '.txt') + ((useGzCompress && '.gz') || '');
|
|
105
|
+
const filename = name + ext;
|
|
106
|
+
return path.resolve(directory, filename);
|
|
107
|
+
}
|
|
108
|
+
function readSourceList(sources, rootDir) {
|
|
109
|
+
async function* mapSrc() {
|
|
110
|
+
for (const src of sources) {
|
|
111
|
+
if ((0, config_1.isFilePath)(src)) {
|
|
112
|
+
yield { filename: path.resolve(rootDir, src) };
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if ((0, config_1.isFileSource)(src)) {
|
|
116
|
+
yield { ...src, filename: path.resolve(rootDir, src.filename) };
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if ((0, config_1.isFileListSource)(src)) {
|
|
120
|
+
const { listFile, ...rest } = src;
|
|
121
|
+
const absListFile = path.resolve(rootDir, listFile);
|
|
122
|
+
const listFileDir = path.dirname(absListFile);
|
|
123
|
+
const files = await readFileList(absListFile);
|
|
124
|
+
for (const filename of files) {
|
|
125
|
+
yield { ...rest, filename: path.resolve(listFileDir, filename) };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return mapSrc();
|
|
131
|
+
}
|
|
132
|
+
async function readFileList(fileList) {
|
|
133
|
+
const content = await (0, readTextFile_1.readTextFile)(fileList);
|
|
134
|
+
return content
|
|
135
|
+
.split('\n')
|
|
136
|
+
.map((a) => a.trim())
|
|
137
|
+
.filter((a) => !!a);
|
|
138
|
+
}
|
|
139
|
+
async function readFileSource(fileSource, sourceOptions) {
|
|
140
|
+
const { filename, keepRawCase = sourceOptions.keepRawCase || false, split = sourceOptions.split || false, maxDepth, } = fileSource;
|
|
141
|
+
const legacy = split === 'legacy';
|
|
142
|
+
const splitWords = legacy ? false : split;
|
|
143
|
+
// console.warn('fileSource: %o,\n targetOptions %o, \n opt: %o', fileSource, targetOptions, opt);
|
|
144
|
+
const readerOptions = { maxDepth, legacy, splitWords, keepCase: keepRawCase };
|
|
145
|
+
(0, logWithTimestamp_1.logWithTimestamp)(`Reading ${path.basename(filename)}`);
|
|
146
|
+
const stream = await (0, iterateWordsFromFile_1.streamWordsFromFile)(filename, readerOptions);
|
|
147
|
+
(0, logWithTimestamp_1.logWithTimestamp)(`Done reading ${path.basename(filename)}`);
|
|
148
|
+
const f = {
|
|
149
|
+
src: filename,
|
|
150
|
+
words: stream,
|
|
151
|
+
};
|
|
152
|
+
return f;
|
|
153
|
+
}
|
|
154
|
+
function normalizeTargetName(name) {
|
|
155
|
+
return name.replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '').replace(/[^\p{L}\p{M}.\w\\/-]/gu, '_');
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createCompileRequest = void 0;
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
function createCompileRequest(sources, options) {
|
|
29
|
+
const { max_depth, maxDepth, experimental = [], split, keepRawCase, useLegacySplitter } = options;
|
|
30
|
+
const targets = calcTargets(sources, options);
|
|
31
|
+
const generateNonStrict = experimental.includes('compound') || undefined;
|
|
32
|
+
const req = {
|
|
33
|
+
targets,
|
|
34
|
+
generateNonStrict,
|
|
35
|
+
maxDepth: parseNumber(maxDepth) ?? parseNumber(max_depth),
|
|
36
|
+
split: useLegacySplitter ? 'legacy' : split,
|
|
37
|
+
/**
|
|
38
|
+
* Do not generate lower case / accent free versions of words.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
keepRawCase,
|
|
42
|
+
};
|
|
43
|
+
return req;
|
|
44
|
+
}
|
|
45
|
+
exports.createCompileRequest = createCompileRequest;
|
|
46
|
+
function calcTargets(sources, options) {
|
|
47
|
+
const { merge, output = '.' } = options;
|
|
48
|
+
const format = calcFormat(options);
|
|
49
|
+
if (merge) {
|
|
50
|
+
const target = {
|
|
51
|
+
name: merge,
|
|
52
|
+
targetDirectory: output,
|
|
53
|
+
compress: options.compress,
|
|
54
|
+
format,
|
|
55
|
+
sources,
|
|
56
|
+
sort: options.sort,
|
|
57
|
+
trieBase: parseNumber(options.trieBase),
|
|
58
|
+
};
|
|
59
|
+
return [target];
|
|
60
|
+
}
|
|
61
|
+
const targets = sources.map((source) => {
|
|
62
|
+
const name = toTargetName(path.basename(source));
|
|
63
|
+
const target = {
|
|
64
|
+
name,
|
|
65
|
+
targetDirectory: output,
|
|
66
|
+
compress: options.compress,
|
|
67
|
+
format,
|
|
68
|
+
sources: [source],
|
|
69
|
+
sort: options.sort,
|
|
70
|
+
trieBase: parseNumber(options.trieBase),
|
|
71
|
+
};
|
|
72
|
+
return target;
|
|
73
|
+
});
|
|
74
|
+
return targets;
|
|
75
|
+
}
|
|
76
|
+
function calcFormat(options) {
|
|
77
|
+
return (options.trie4 && 'trie4') || (options.trie3 && 'trie3') || (options.trie && 'trie') || 'plaintext';
|
|
78
|
+
}
|
|
79
|
+
function toTargetName(sourceFile) {
|
|
80
|
+
return path.basename(sourceFile).replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '');
|
|
81
|
+
}
|
|
82
|
+
function parseNumber(s) {
|
|
83
|
+
const n = parseInt(s ?? '');
|
|
84
|
+
return isNaN(n) ? undefined : n;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=createCompileRequest.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export declare function writeSeqToFile(seq: Sequence<string>, outFile: string): Promise<void>;
|
|
1
|
+
export { writeTextLinesToFile as writeToFileIterableP } from './writeTextToFile';
|
|
2
|
+
export declare function writeSeqToFile(seq: Iterable<string>, outFile: string): Promise<void>;
|
|
4
3
|
//# sourceMappingURL=fileWriter.d.ts.map
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeSeqToFile = exports.
|
|
4
|
-
const
|
|
5
|
-
var
|
|
6
|
-
Object.defineProperty(exports, "
|
|
7
|
-
Object.defineProperty(exports, "writeToFileIterableP", { enumerable: true, get: function () { return cspell_io_2.writeToFileIterableP; } });
|
|
8
|
-
Object.defineProperty(exports, "writeToFileIterable", { enumerable: true, get: function () { return cspell_io_2.writeToFileIterable; } });
|
|
3
|
+
exports.writeSeqToFile = exports.writeToFileIterableP = void 0;
|
|
4
|
+
const writeTextToFile_1 = require("./writeTextToFile");
|
|
5
|
+
var writeTextToFile_2 = require("./writeTextToFile");
|
|
6
|
+
Object.defineProperty(exports, "writeToFileIterableP", { enumerable: true, get: function () { return writeTextToFile_2.writeTextLinesToFile; } });
|
|
9
7
|
function writeSeqToFile(seq, outFile) {
|
|
10
|
-
return (0,
|
|
8
|
+
return (0, writeTextToFile_1.writeTextLinesToFile)(outFile, seq);
|
|
11
9
|
}
|
|
12
10
|
exports.writeSeqToFile = writeSeqToFile;
|
|
13
11
|
//# sourceMappingURL=fileWriter.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
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.globP = void 0;
|
|
7
|
+
const glob_1 = __importDefault(require("glob"));
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
const pGlob = (0, util_1.promisify)(glob_1.default);
|
|
10
|
+
function globP(pattern) {
|
|
11
|
+
// Convert windows separators.
|
|
12
|
+
pattern = pattern.replace(/\\/g, '/');
|
|
13
|
+
return pGlob(pattern);
|
|
14
|
+
}
|
|
15
|
+
exports.globP = globP;
|
|
16
|
+
//# sourceMappingURL=globP.js.map
|
package/dist/compiler/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { compileWordList, compileTrie } from './wordListCompiler';
|
|
2
|
+
export { type Logger, setLogger } from './logger';
|
|
3
|
+
export { compile, compileTarget } from './compile';
|
|
4
|
+
export type { CompileRequest, CompileTargetOptions, RunConfig } from '../config';
|
|
2
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/compiler/index.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.compileTarget = exports.compile = exports.setLogger = exports.compileTrie = exports.compileWordList = void 0;
|
|
4
|
+
var wordListCompiler_1 = require("./wordListCompiler");
|
|
5
|
+
Object.defineProperty(exports, "compileWordList", { enumerable: true, get: function () { return wordListCompiler_1.compileWordList; } });
|
|
6
|
+
Object.defineProperty(exports, "compileTrie", { enumerable: true, get: function () { return wordListCompiler_1.compileTrie; } });
|
|
7
|
+
var logger_1 = require("./logger");
|
|
8
|
+
Object.defineProperty(exports, "setLogger", { enumerable: true, get: function () { return logger_1.setLogger; } });
|
|
9
|
+
var compile_1 = require("./compile");
|
|
10
|
+
Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return compile_1.compile; } });
|
|
11
|
+
Object.defineProperty(exports, "compileTarget", { enumerable: true, get: function () { return compile_1.compileTarget; } });
|
|
18
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Sequence } from 'gensequence';
|
|
2
1
|
import { ReaderOptions } from './Reader';
|
|
3
|
-
export declare function streamWordsFromFile(filename: string, options: ReaderOptions): Promise<
|
|
2
|
+
export declare function streamWordsFromFile(filename: string, options: ReaderOptions): Promise<Iterable<string>>;
|
|
4
3
|
//# sourceMappingURL=iterateWordsFromFile.d.ts.map
|
|
@@ -4,7 +4,7 @@ exports.streamWordsFromFile = void 0;
|
|
|
4
4
|
const Reader_1 = require("./Reader");
|
|
5
5
|
async function streamWordsFromFile(filename, options) {
|
|
6
6
|
const reader = await (0, Reader_1.createReader)(filename, options);
|
|
7
|
-
return reader
|
|
7
|
+
return reader;
|
|
8
8
|
}
|
|
9
9
|
exports.streamWordsFromFile = streamWordsFromFile;
|
|
10
10
|
//# sourceMappingURL=iterateWordsFromFile.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.legacyLinesToWords = exports.legacyLineToWords = void 0;
|
|
27
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
28
|
+
const Text = __importStar(require("./text"));
|
|
29
|
+
const regNonWord = /[^\p{L}\p{M}' ]+/giu;
|
|
30
|
+
const regExpSpaceOrDash = /[- ]+/g;
|
|
31
|
+
const regExpRepeatChars = /(.)\1{4,}/i;
|
|
32
|
+
function legacyLineToWords(line, keepCase) {
|
|
33
|
+
// Remove punctuation and non-letters.
|
|
34
|
+
const filteredLine = line.replace(regNonWord, '|');
|
|
35
|
+
const wordGroups = filteredLine.split('|');
|
|
36
|
+
const words = (0, sync_1.pipe)(wordGroups, (0, sync_1.opConcatMap)((a) => [a, ...a.split(regExpSpaceOrDash)]), (0, sync_1.opConcatMap)((a) => splitCamelCase(a)), (0, sync_1.opMap)((a) => a.trim()), (0, sync_1.opFilter)((a) => !!a), (0, sync_1.opFilter)((s) => !regExpRepeatChars.test(s)), (0, sync_1.opMap)((a) => (keepCase ? a : a.toLowerCase())));
|
|
37
|
+
return words;
|
|
38
|
+
}
|
|
39
|
+
exports.legacyLineToWords = legacyLineToWords;
|
|
40
|
+
function* legacyLinesToWords(lines, keepCase = false) {
|
|
41
|
+
for (const line of lines) {
|
|
42
|
+
yield* legacyLineToWords(line, keepCase);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.legacyLinesToWords = legacyLinesToWords;
|
|
46
|
+
function splitCamelCase(word) {
|
|
47
|
+
const splitWords = Text.splitCamelCaseWord(word);
|
|
48
|
+
// We only want to preserve this: "New York" and not "Namespace DNSLookup"
|
|
49
|
+
if (splitWords.length > 1 && regExpSpaceOrDash.test(word)) {
|
|
50
|
+
return (0, sync_1.pipe)(splitWords, (0, sync_1.opConcatMap)((w) => w.split(regExpSpaceOrDash)));
|
|
51
|
+
}
|
|
52
|
+
return splitWords;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=legacyLineToWords.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logWithTimestamp = void 0;
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
const logWithTimestamp = (message, ...optionalParams) => {
|
|
6
|
+
console.log(`${new Date().toISOString()} ${message}`, ...optionalParams);
|
|
7
|
+
};
|
|
8
|
+
exports.logWithTimestamp = logWithTimestamp;
|
|
9
|
+
//# sourceMappingURL=logWithTimestamp.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogger = exports.setLogger = void 0;
|
|
4
|
+
const defaultLogger = console.log;
|
|
5
|
+
let log = defaultLogger;
|
|
6
|
+
function setLogger(logger) {
|
|
7
|
+
log = logger ?? defaultLogger;
|
|
8
|
+
}
|
|
9
|
+
exports.setLogger = setLogger;
|
|
10
|
+
function getLogger() {
|
|
11
|
+
return log;
|
|
12
|
+
}
|
|
13
|
+
exports.getLogger = getLogger;
|
|
14
|
+
//# sourceMappingURL=logger.js.map
|