@cspell/cspell-tools 9.6.0 → 9.6.2
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/app.mjs +1 -1
- package/dist/{build-OgMPaXPZ.mjs → build-Dxf6sFCy.mjs} +70 -36
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +1 -1
- package/package.json +5 -5
package/dist/app.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as reportCheckChecksumFile, c as toError, d as compressFile, i as logWithTimestamp, l as generateBTrie, n as compile, o as reportChecksumForFiles, r as setLogger, s as updateChecksumForFiles, t as build, u as OSFlags } from "./build-
|
|
1
|
+
import { a as reportCheckChecksumFile, c as toError, d as compressFile, i as logWithTimestamp, l as generateBTrie, n as compile, o as reportChecksumForFiles, r as setLogger, s as updateChecksumForFiles, t as build, u as OSFlags } from "./build-Dxf6sFCy.mjs";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { CommanderError, Option } from "commander";
|
|
4
4
|
import { writeFile } from "node:fs/promises";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { promises } from "node:fs";
|
|
2
2
|
import fs, { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import fsPath, { resolve, sep } from "node:path";
|
|
4
|
+
import fsPath, { dirname, relative, resolve, sep } from "node:path";
|
|
5
5
|
import * as Trie from "cspell-trie-lib";
|
|
6
6
|
import { COMPOUND_FIX, FORBID_PREFIX, createDictionaryLineParser, decodeTrie, encodeTrieDataToBTrie, parseDictionary } from "cspell-trie-lib";
|
|
7
7
|
import { promisify } from "node:util";
|
|
@@ -238,15 +238,17 @@ async function createReader(filename, options) {
|
|
|
238
238
|
//#endregion
|
|
239
239
|
//#region src/compiler/bTrie.ts
|
|
240
240
|
async function generateBTrieFromFile(file, options) {
|
|
241
|
-
console.log(
|
|
241
|
+
const log$1 = options.logger || console.log.bind(console);
|
|
242
|
+
log$1(`Processing file: ${file}`);
|
|
242
243
|
const btrie = await createBTrieFromFile(file, options);
|
|
243
244
|
const outFile = bTrieFileName(file, options);
|
|
244
245
|
await mkdir(fsPath.dirname(outFile), { recursive: true });
|
|
245
246
|
await writeFile$1(outFile, btrie);
|
|
246
|
-
|
|
247
|
+
log$1(`Written BTrie to: ${outFile}`);
|
|
248
|
+
return outFile;
|
|
247
249
|
}
|
|
248
250
|
async function generateBTrieFromFiles(files, options) {
|
|
249
|
-
console.log(`Generating BTrie for ${files.length} file(s).`);
|
|
251
|
+
(options.logger || console.log.bind(console))(`Generating BTrie for ${files.length} file(s).`);
|
|
250
252
|
for (const file of files) await generateBTrieFromFile(file, options);
|
|
251
253
|
}
|
|
252
254
|
function bTrieFileName(inputFilename, options) {
|
|
@@ -343,16 +345,17 @@ async function shasumFile(filename, root) {
|
|
|
343
345
|
/**
|
|
344
346
|
*
|
|
345
347
|
* @param filename - name of checksum file
|
|
346
|
-
* @param files - optional list of files to check
|
|
348
|
+
* @param files - optional list of files to check - they will be resolved relative to the checksum file.
|
|
347
349
|
* @param root - optional root, default cwd.
|
|
348
350
|
*/
|
|
349
351
|
async function checkShasumFile(filename, files, root) {
|
|
350
352
|
files = !files ? files : files.length ? files : void 0;
|
|
353
|
+
const resolvedRoot = resolve(root || ".");
|
|
354
|
+
const fileDir = dirname(resolve(resolvedRoot, filename));
|
|
351
355
|
const shaFiles = await readAndParseShasumFile(filename);
|
|
352
|
-
const
|
|
356
|
+
const relFilesToCheck = (!files ? shaFiles.map(({ filename: filename$1 }) => filename$1) : files).map((f) => relative(fileDir, resolve(fileDir, f)));
|
|
353
357
|
const mapNameToChecksum = new Map(shaFiles.map((r) => [normalizeFilename(r.filename), r.checksum]));
|
|
354
|
-
const
|
|
355
|
-
const results = await Promise.all(filesToCheck.map(normalizeFilename).map((filename$1) => {
|
|
358
|
+
const results = await Promise.all(relFilesToCheck.map(normalizeFilename).map((filename$1) => {
|
|
356
359
|
return tryToCheckFile(filename$1, resolvedRoot, mapNameToChecksum.get(filename$1));
|
|
357
360
|
}));
|
|
358
361
|
return {
|
|
@@ -1160,11 +1163,36 @@ function resolveChecksumFile(checksumFile, root) {
|
|
|
1160
1163
|
}
|
|
1161
1164
|
async function compileTarget(target, options, compileOptions) {
|
|
1162
1165
|
logWithTimestamp(`Start compile: ${target.name}`);
|
|
1163
|
-
const
|
|
1164
|
-
const
|
|
1166
|
+
const buildOptions = genBuildTargetDictionaryOptions(target, compileOptions);
|
|
1167
|
+
const deps = /* @__PURE__ */ new Set();
|
|
1168
|
+
addToSet(deps, await buildTargetDictionary(target, options, compileOptions, buildOptions), await compressDictionaryFileIfNeeded(buildOptions), await genBTrieForTarget(target, buildOptions));
|
|
1169
|
+
logWithTimestamp(`Done compile: ${target.name}`);
|
|
1170
|
+
const checksumRoot = buildOptions.checksumRoot;
|
|
1171
|
+
return [...deps].map((d) => path.relative(checksumRoot, d));
|
|
1172
|
+
}
|
|
1173
|
+
function genBuildTargetDictionaryOptions(target, compileOptions) {
|
|
1174
|
+
const { rootDir, checksumFile, cwd } = compileOptions;
|
|
1165
1175
|
let targetDirectory = target.targetDirectory ?? cwd ?? process.cwd();
|
|
1166
1176
|
targetDirectory = targetDirectory.replace("${cwd}", cwd ?? process.cwd());
|
|
1167
1177
|
targetDirectory = path.resolve(rootDir, targetDirectory);
|
|
1178
|
+
const name = normalizeTargetName(target.name);
|
|
1179
|
+
const useTrie = target.format.startsWith("trie");
|
|
1180
|
+
const generateCompressed = target.compress ?? false;
|
|
1181
|
+
const generateUncompressed = target.keepUncompressed ?? false;
|
|
1182
|
+
const generateOnlyCompressedDictionary = generateCompressed && !generateUncompressed;
|
|
1183
|
+
return {
|
|
1184
|
+
name,
|
|
1185
|
+
filename: resolveTarget(name, targetDirectory, useTrie),
|
|
1186
|
+
useTrie,
|
|
1187
|
+
generateOnlyCompressedDictionary,
|
|
1188
|
+
generateCompressed,
|
|
1189
|
+
checksumRoot: checksumFile && path.dirname(checksumFile) || rootDir
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
async function buildTargetDictionary(target, options, compileOptions, buildOptions) {
|
|
1193
|
+
const { rootDir, checksumFile, conditional } = compileOptions;
|
|
1194
|
+
const { format, sources, trieBase, sort = true, generateNonStrict = false, excludeWordsFrom = [], excludeWordsNotFoundIn = [], excludeWordsMatchingRegex } = target;
|
|
1195
|
+
const { filename, useTrie, generateOnlyCompressedDictionary, checksumRoot } = buildOptions;
|
|
1168
1196
|
const dictionaryDirectives = target.dictionaryDirectives ?? compileOptions.dictionaryDirectives;
|
|
1169
1197
|
const removeDuplicates$1 = target.removeDuplicates ?? false;
|
|
1170
1198
|
const excludeFromFilter = await createExcludeFilter(excludeWordsFrom);
|
|
@@ -1173,14 +1201,7 @@ async function compileTarget(target, options, compileOptions) {
|
|
|
1173
1201
|
const excludeFilter = (word) => {
|
|
1174
1202
|
return excludeFromFilter(word) && includeFromFilter(word) && excludeRegexFilter(word);
|
|
1175
1203
|
};
|
|
1176
|
-
const
|
|
1177
|
-
const useTrie = format.startsWith("trie");
|
|
1178
|
-
const generateCompressed = target.compress ?? false;
|
|
1179
|
-
const generateUncompressed = target.keepUncompressed ?? false;
|
|
1180
|
-
const genSet = /* @__PURE__ */ new Set();
|
|
1181
|
-
genSet.add(generateCompressed);
|
|
1182
|
-
if (generateUncompressed) genSet.add(false);
|
|
1183
|
-
const filename = resolveTarget(name, targetDirectory, useTrie);
|
|
1204
|
+
const compress$1 = generateOnlyCompressedDictionary;
|
|
1184
1205
|
const filesToProcess = await toArray(pipeAsync(readSourceList(sources, rootDir), opMapAsync((src) => readFileSource(src, options)), opAwaitAsync()));
|
|
1185
1206
|
const normalizer = normalizeTargetWords({
|
|
1186
1207
|
sort: useTrie || sort,
|
|
@@ -1188,8 +1209,7 @@ async function compileTarget(target, options, compileOptions) {
|
|
|
1188
1209
|
filter: excludeFilter,
|
|
1189
1210
|
dictionaryDirectives
|
|
1190
1211
|
});
|
|
1191
|
-
const
|
|
1192
|
-
const deps = [...calculateDependencies(filename + (generateCompressed ? ".gz" : ""), filesToProcess, [...excludeWordsFrom, ...excludeWordsNotFoundIn], checksumRoot)];
|
|
1212
|
+
const deps = [...calculateDependencies(filename + (compress$1 ? ".gz" : ""), filesToProcess, [...excludeWordsFrom, ...excludeWordsNotFoundIn], checksumRoot)];
|
|
1193
1213
|
if (conditional && checksumFile) {
|
|
1194
1214
|
if ((await checkShasumFile(checksumFile, deps, checksumRoot).catch(() => void 0))?.passed) {
|
|
1195
1215
|
logWithTimestamp(`Skip ${target.name}, nothing changed.`);
|
|
@@ -1197,7 +1217,7 @@ async function compileTarget(target, options, compileOptions) {
|
|
|
1197
1217
|
}
|
|
1198
1218
|
}
|
|
1199
1219
|
async function action(words, dst) {
|
|
1200
|
-
|
|
1220
|
+
await createTargetFile(dst, iterableToString(pipe(words, normalizer, useTrie ? createTrieCompiler({
|
|
1201
1221
|
base: trieBase,
|
|
1202
1222
|
trie3: format === "trie3",
|
|
1203
1223
|
trie4: format === "trie4"
|
|
@@ -1206,34 +1226,45 @@ async function compileTarget(target, options, compileOptions) {
|
|
|
1206
1226
|
generateNonStrict,
|
|
1207
1227
|
dictionaryDirectives,
|
|
1208
1228
|
removeDuplicates: removeDuplicates$1
|
|
1209
|
-
})));
|
|
1210
|
-
for (const compress$1 of genSet) await createTargetFile(dst, data, compress$1);
|
|
1229
|
+
}))), compress$1);
|
|
1211
1230
|
}
|
|
1212
1231
|
await processFiles({
|
|
1213
1232
|
action,
|
|
1214
1233
|
filesToProcess,
|
|
1215
1234
|
mergeTarget: filename
|
|
1216
1235
|
});
|
|
1217
|
-
if (target.bTrie) await generateBTrieFromFile(filename, {
|
|
1218
|
-
compress: true,
|
|
1219
|
-
optimize: true,
|
|
1220
|
-
useStringTable: true,
|
|
1221
|
-
...typeof target.bTrie === "object" ? target.bTrie : {}
|
|
1222
|
-
});
|
|
1223
|
-
logWithTimestamp(`Done compile: ${target.name}`);
|
|
1224
1236
|
return deps;
|
|
1225
1237
|
}
|
|
1226
|
-
function
|
|
1238
|
+
async function compressDictionaryFileIfNeeded(buildOptions) {
|
|
1239
|
+
const { filename, generateCompressed, generateOnlyCompressedDictionary } = buildOptions;
|
|
1240
|
+
if (generateOnlyCompressedDictionary || !generateCompressed) return [];
|
|
1241
|
+
logWithTimestamp(`Compress: ${filename}`);
|
|
1242
|
+
return [filename, await compressFile(filename)];
|
|
1243
|
+
}
|
|
1244
|
+
async function genBTrieForTarget(target, buildOptions) {
|
|
1245
|
+
if (!target.bTrie) return [];
|
|
1246
|
+
const cfg = typeof target.bTrie === "object" ? target.bTrie : {};
|
|
1247
|
+
const { filename, generateOnlyCompressedDictionary } = buildOptions;
|
|
1248
|
+
const srcFilename = filename + (generateOnlyCompressedDictionary ? ".gz" : "");
|
|
1249
|
+
logWithTimestamp(`Generate BTrie from: ${srcFilename}`);
|
|
1250
|
+
return [srcFilename, await generateBTrieFromFile(srcFilename, {
|
|
1251
|
+
compress: cfg.compress ?? true,
|
|
1252
|
+
optimize: cfg.optimize ?? true,
|
|
1253
|
+
useStringTable: cfg.useStringTable ?? true,
|
|
1254
|
+
logger: logWithTimestamp
|
|
1255
|
+
})];
|
|
1256
|
+
}
|
|
1257
|
+
function calculateDependencies(targetFile, filesToProcess, extraDependencyFiles, checksumRoot) {
|
|
1227
1258
|
const dependencies = /* @__PURE__ */ new Set();
|
|
1228
1259
|
addDependency(targetFile);
|
|
1229
1260
|
extraDependencyFiles?.forEach((f) => addDependency(f));
|
|
1230
1261
|
filesToProcess.forEach((f) => addDependency(f.src));
|
|
1231
1262
|
return dependencies;
|
|
1232
1263
|
function addDependency(filename) {
|
|
1233
|
-
const
|
|
1234
|
-
dependencies.add(
|
|
1235
|
-
dependencies.add(
|
|
1236
|
-
dependencies.add(
|
|
1264
|
+
const abs = path.resolve(checksumRoot, filename);
|
|
1265
|
+
dependencies.add(abs);
|
|
1266
|
+
dependencies.add(abs.replace(/\.aff$/, ".dic"));
|
|
1267
|
+
dependencies.add(abs.replace(/\.dic$/, ".aff"));
|
|
1237
1268
|
}
|
|
1238
1269
|
}
|
|
1239
1270
|
function rel(filePath) {
|
|
@@ -1356,6 +1387,9 @@ function createExcludeRegexFilter(excludeWordsMatchingRegex) {
|
|
|
1356
1387
|
function iterableToString(iter) {
|
|
1357
1388
|
return Array.isArray(iter) ? iter.join("") : [...iter].join("");
|
|
1358
1389
|
}
|
|
1390
|
+
function addToSet(set, ...sources) {
|
|
1391
|
+
for (const items of sources) for (const item of items) set.add(item);
|
|
1392
|
+
}
|
|
1359
1393
|
|
|
1360
1394
|
//#endregion
|
|
1361
1395
|
//#region src/build.ts
|
|
@@ -1400,4 +1434,4 @@ function normalizeRequest(buildInfo, root) {
|
|
|
1400
1434
|
|
|
1401
1435
|
//#endregion
|
|
1402
1436
|
export { reportCheckChecksumFile as a, toError as c, compressFile as d, logWithTimestamp as i, generateBTrie as l, compile as n, reportChecksumForFiles as o, setLogger as r, updateChecksumForFiles as s, build as t, OSFlags as u };
|
|
1403
|
-
//# sourceMappingURL=build-
|
|
1437
|
+
//# sourceMappingURL=build-Dxf6sFCy.mjs.map
|
package/dist/index.d.mts
CHANGED
|
@@ -9,10 +9,14 @@ interface BTrieOptions {
|
|
|
9
9
|
useStringTable?: boolean | undefined;
|
|
10
10
|
}
|
|
11
11
|
//#endregion
|
|
12
|
+
//#region src/compiler/logger.d.ts
|
|
13
|
+
type Logger = (message?: any, ...optionalParams: any[]) => void;
|
|
14
|
+
//#endregion
|
|
12
15
|
//#region src/compiler/bTrie.d.ts
|
|
13
16
|
interface GenerateBTrieOptions extends BTrieOptions {
|
|
14
17
|
/** output directory */
|
|
15
18
|
output?: string;
|
|
19
|
+
logger?: Logger;
|
|
16
20
|
}
|
|
17
21
|
//#endregion
|
|
18
22
|
//#region src/bTrie.d.ts
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cspell/cspell-tools",
|
|
3
|
-
"version": "9.6.
|
|
3
|
+
"version": "9.6.2",
|
|
4
4
|
"description": "Tools to assist with the development of cSpell",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
},
|
|
65
65
|
"homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-tools#readme",
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@cspell/cspell-pipe": "9.6.
|
|
67
|
+
"@cspell/cspell-pipe": "9.6.2",
|
|
68
68
|
"commander": "^14.0.2",
|
|
69
69
|
"cosmiconfig": "9.0.0",
|
|
70
|
-
"cspell-trie-lib": "9.6.
|
|
70
|
+
"cspell-trie-lib": "9.6.2",
|
|
71
71
|
"glob": "^13.0.0",
|
|
72
|
-
"hunspell-reader": "9.6.
|
|
72
|
+
"hunspell-reader": "9.6.2",
|
|
73
73
|
"yaml": "^2.8.2"
|
|
74
74
|
},
|
|
75
75
|
"engines": {
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"ts-json-schema-generator": "^2.4.0"
|
|
81
81
|
},
|
|
82
82
|
"module": "bin.mjs",
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "646e18a04ff36d43f78a74e5055540e0f5297e91"
|
|
84
84
|
}
|