@cspell/cspell-tools 8.7.0 → 8.8.1

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { program, CommanderError } from 'commander';
3
+ import { CommanderError, program } from 'commander';
4
+
4
5
  import { run } from './dist/app.js';
5
6
 
6
7
  run(program, process.argv).catch((e) => {
package/dist/app.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // For large dictionaries, it is necessary to increase the memory limit.
2
+ import { readFileSync } from 'node:fs';
2
3
  import { CommanderError, Option } from 'commander';
3
- import { readFileSync } from 'fs';
4
4
  import { build } from './build.js';
5
5
  import { processCompileAction } from './compile.js';
6
6
  import * as compiler from './compiler/index.js';
@@ -12,7 +12,7 @@ const npmPackageRaw = readFileSync(new URL('../package.json', import.meta.url),
12
12
  const npmPackage = JSON.parse(npmPackageRaw);
13
13
  compiler.setLogger(logWithTimestamp);
14
14
  function collect(value, previous) {
15
- return previous.concat([value]);
15
+ return [...previous, value];
16
16
  }
17
17
  function addCompileOptions(compileCommand) {
18
18
  return compileCommand
package/dist/build.js CHANGED
@@ -1,5 +1,5 @@
1
+ import * as path from 'node:path';
1
2
  import { cosmiconfig } from 'cosmiconfig';
2
- import * as path from 'path';
3
3
  import { compile } from './compiler/index.js';
4
4
  import { normalizeConfig } from './config/index.js';
5
5
  const moduleName = 'cspell-tools';
package/dist/compile.js CHANGED
@@ -15,7 +15,7 @@ export async function processCompileAction(src, options, featureFlags) {
15
15
  return useCompile(src, options);
16
16
  }
17
17
  async function useCompile(src, options) {
18
- console.log('Compile:\n output: %s\n compress: %s\n files:\n %s ', options.output || 'default', options.compress ? 'true' : 'false', src.join('\n '));
18
+ console.log('Compile:\n output: %s\n compress: %s\n files:\n %s', options.output || 'default', options.compress ? 'true' : 'false', src.join('\n '));
19
19
  if (options.listFile && options.listFile.length) {
20
20
  console.log(' list files:\n %s', options.listFile.join('\n '));
21
21
  }
@@ -30,7 +30,7 @@ async function useCompile(src, options) {
30
30
  async function initConfig(runConfig) {
31
31
  const { $schema = configFileSchemaURL, ...cfg } = runConfig;
32
32
  const config = { $schema, ...cfg };
33
- const content = configFileHeader + YAML.stringify(config, null, 2);
33
+ const content = configFileHeader + YAML.stringify(config, undefined, 2);
34
34
  console.log('Writing config file: %s', defaultConfigFile);
35
35
  await writeFile(defaultConfigFile, content);
36
36
  console.log(`Init complete.
@@ -1,7 +1,7 @@
1
+ import * as path from 'node:path';
1
2
  import { pipeAsync, toArray } from '@cspell/cspell-pipe';
2
3
  import { opAwaitAsync, opMapAsync } from '@cspell/cspell-pipe/operators';
3
4
  import { opConcatMap, opMap, pipe } from '@cspell/cspell-pipe/sync';
4
- import * as path from 'path';
5
5
  import { isFileListSource, isFilePath, isFileSource } from '../config/index.js';
6
6
  import { checkShasumFile, updateChecksumForFiles } from '../shasum/index.js';
7
7
  import { createAllowedSplitWordsFromFiles, createWordsCollectionFromFiles } from './createWordsCollection.js';
@@ -173,9 +173,9 @@ async function readFileSource(fileSource, sourceOptions) {
173
173
  return f;
174
174
  }
175
175
  function normalizeTargetName(name) {
176
- return name.replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '').replace(/[^\p{L}\p{M}.\w\\/-]/gu, '_');
176
+ return name.replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '').replaceAll(/[^\p{L}\p{M}.\w\\/-]/gu, '_');
177
177
  }
178
- function logProgress(freq = 100000) {
178
+ function logProgress(freq = 100_000) {
179
179
  function* logProgress(iter) {
180
180
  const _freq = freq;
181
181
  let count = 0;
@@ -1,4 +1,4 @@
1
- import * as path from 'path';
1
+ import * as path from 'node:path';
2
2
  export function createCompileRequest(sourceFiles, options) {
3
3
  options = { ...options };
4
4
  options.maxDepth ??= options.max_depth;
@@ -59,8 +59,8 @@ function toTargetName(sourceFile) {
59
59
  return path.basename(sourceFile).replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '');
60
60
  }
61
61
  function parseNumber(s) {
62
- const n = parseInt(s ?? '');
63
- return isNaN(n) ? undefined : n;
62
+ const n = Number.parseInt(s ?? '');
63
+ return Number.isNaN(n) ? undefined : n;
64
64
  }
65
65
  function baseNameOfSource(source) {
66
66
  return typeof source === 'string' ? source : isFileSource(source) ? source.filename : source.listFile;
@@ -33,7 +33,7 @@ export async function createWordsCollectionFromFiles(files) {
33
33
  if (cached)
34
34
  return cached;
35
35
  const sources = await Promise.all(files.map((file) => readFile(file)));
36
- const collection = createWordsCollection(sources.flatMap((a) => a));
36
+ const collection = createWordsCollection(sources.flat());
37
37
  cache.set(files, collection);
38
38
  return collection;
39
39
  }
@@ -4,9 +4,9 @@ const regNonWord = /[^\p{L}\p{M}' _\d]+/giu;
4
4
  const regExpRepeatChars = /(.)\1{5}/i;
5
5
  export function legacyLineToWords(line, keepCase, allowedSplitWords) {
6
6
  // Remove punctuation and non-letters.
7
- const filteredLine = line.replace(regNonWord, '|');
7
+ const filteredLine = line.replaceAll(regNonWord, '|');
8
8
  const wordGroups = filteredLine.split('|');
9
- const words = pipe(wordGroups, opConcatMap((a) => [...a.split(regExpSpaceOrDash)]), opConcatMap((a) => splitCamelCaseIfAllowed(a, allowedSplitWords, keepCase)), opMap((a) => a.trim()), opFilter((a) => !!a), opFilter((s) => !regExpRepeatChars.test(s)));
9
+ const words = pipe(wordGroups, opConcatMap((a) => a.split(regExpSpaceOrDash)), opConcatMap((a) => splitCamelCaseIfAllowed(a, allowedSplitWords, keepCase)), opMap((a) => a.trim()), opFilter((a) => !!a), opFilter((s) => !regExpRepeatChars.test(s)));
10
10
  return words;
11
11
  }
12
12
  export function* legacyLinesToWords(lines, keepCase, allowedSplitWords) {
@@ -1,5 +1,5 @@
1
- import assert from 'assert';
2
- import { promises as fs } from 'fs';
1
+ import assert from 'node:assert';
2
+ import { promises as fs } from 'node:fs';
3
3
  import { decompress } from '../../gzip/index.js';
4
4
  const isGzFile = /\.gz$/;
5
5
  export function readTextFile(filename) {
@@ -6,10 +6,10 @@ const regExSplitWords2 = /(\p{Lu})(\p{Lu}\p{Ll})/gu;
6
6
  * Split camelCase words into an array of strings.
7
7
  */
8
8
  export function splitCamelCaseWord(word, autoStem = true) {
9
- const wPrime = autoStem ? word.replace(regExUpperSOrIng, (s) => s[0] + s.slice(1).toLowerCase()) : word;
10
- const pass1 = wPrime.replace(regExSplitWords, '$1|$2');
11
- const pass2 = pass1.replace(regExSplitWords2, '$1|$2');
12
- const pass3 = pass2.replace(/[\d_]+/g, '|');
9
+ const wPrime = autoStem ? word.replaceAll(regExUpperSOrIng, (s) => s[0] + s.slice(1).toLowerCase()) : word;
10
+ const pass1 = wPrime.replaceAll(regExSplitWords, '$1|$2');
11
+ const pass2 = pass1.replaceAll(regExSplitWords2, '$1|$2');
12
+ const pass3 = pass2.replaceAll(/[\d_]+/g, '|');
13
13
  return pass3.split('|').filter((a) => !!a);
14
14
  }
15
15
  //# sourceMappingURL=text.js.map
@@ -1,7 +1,7 @@
1
+ import { mkdir } from 'node:fs/promises';
2
+ import * as path from 'node:path';
1
3
  import { opAppend, opMap, pipe } from '@cspell/cspell-pipe/sync';
2
4
  import * as Trie from 'cspell-trie-lib';
3
- import { mkdir } from 'fs/promises';
4
- import * as path from 'path';
5
5
  import { writeSeqToFile } from './fileWriter.js';
6
6
  import { getLogger } from './logger.js';
7
7
  import { normalizeTargetWords } from './wordListParser.js';
@@ -11,8 +11,8 @@ export function normalizeTargetWords(options) {
11
11
  const operations = [
12
12
  opFilter((a) => !!a),
13
13
  lineParser,
14
- options.sort ? createInlineBufferedSort(10000) : undefined,
15
- opFilter(uniqueFilter(10000)),
14
+ options.sort ? createInlineBufferedSort(10_000) : undefined,
15
+ opFilter(uniqueFilter(10_000)),
16
16
  options.filter ? opFilter(options.filter) : undefined,
17
17
  ].filter(isDefined);
18
18
  return opCombine(...operations);
@@ -78,23 +78,28 @@ export function createParseFileLineMapper(options) {
78
78
  .filter((a) => !!a);
79
79
  for (const flag of flags) {
80
80
  switch (flag) {
81
- case 'split':
81
+ case 'split': {
82
82
  split = true;
83
83
  break;
84
- case 'no-split':
84
+ }
85
+ case 'no-split': {
85
86
  split = false;
86
87
  break;
87
- case 'keep-case':
88
+ }
89
+ case 'keep-case': {
88
90
  keepCase = true;
89
91
  legacy = false;
90
92
  break;
91
- case 'no-keep-case':
93
+ }
94
+ case 'no-keep-case': {
92
95
  keepCase = false;
93
96
  break;
94
- case 'legacy':
97
+ }
98
+ case 'legacy': {
95
99
  keepCase = false;
96
100
  legacy = true;
97
101
  break;
102
+ }
98
103
  }
99
104
  }
100
105
  }
@@ -107,23 +112,23 @@ export function createParseFileLineMapper(options) {
107
112
  function splitLine(line) {
108
113
  line = line.replace(/#.*/, ''); // remove comment
109
114
  line = line.trim();
110
- line = line.replace(/\bU\+[0-9A-F]{4}\b/gi, '|'); // Remove Unicode Definitions
111
- line = line.replace(/\\U[0-9A-F]{4}/gi, '|'); // Remove Unicode Definitions
112
- line = line.replace(regNonWordOrDigit, '|');
113
- line = line.replace(/'(?=\|)/g, ''); // remove trailing '
115
+ line = line.replaceAll(/\bU\+[0-9A-F]{4}\b/gi, '|'); // Remove Unicode Definitions
116
+ line = line.replaceAll(/\\U[0-9A-F]{4}/gi, '|'); // Remove Unicode Definitions
117
+ line = line.replaceAll(regNonWordOrDigit, '|');
118
+ line = line.replaceAll(/'(?=\|)/g, ''); // remove trailing '
114
119
  line = line.replace(/'$/, ''); // remove trailing '
115
- line = line.replace(/(?<=\|)'/g, ''); // remove leading '
120
+ line = line.replaceAll(/(?<=\|)'/g, ''); // remove leading '
116
121
  line = line.replace(/^'/, ''); // remove leading '
117
- line = line.replace(/\s*\|\s*/g, '|'); // remove spaces around |
118
- line = line.replace(/[|]+/g, '|'); // reduce repeated |
122
+ line = line.replaceAll(/\s*\|\s*/g, '|'); // remove spaces around |
123
+ line = line.replaceAll(/[|]+/g, '|'); // reduce repeated |
119
124
  line = line.replace(/^\|/, ''); // remove leading |
120
125
  line = line.replace(/\|$/, ''); // remove trailing |
121
126
  const lines = line
122
127
  .split('|')
123
128
  .map((a) => a.trim())
124
129
  .filter((a) => !!a)
125
- .filter((a) => !a.match(/^[0-9_-]+$/)) // pure numbers and symbols
126
- .filter((a) => !a.match(/^0[xo][0-9A-F]+$/i)); // c-style hex/octal digits
130
+ .filter((a) => !/^[0-9_-]+$/.test(a)) // pure numbers and symbols
131
+ .filter((a) => !/^0[xo][0-9A-F]+$/i.test(a)); // c-style hex/octal digits
127
132
  return lines;
128
133
  }
129
134
  function* splitWords(lines) {
@@ -134,16 +139,13 @@ export function createParseFileLineMapper(options) {
134
139
  }
135
140
  if (split) {
136
141
  const words = splitLine(line);
137
- if (!allowedSplitWords.size) {
138
- yield* words;
139
- }
140
- else {
141
- yield* words.flatMap((word) => splitCamelCaseIfAllowed(word, allowedSplitWords, keepCase));
142
- }
142
+ yield* !allowedSplitWords.size
143
+ ? words
144
+ : words.flatMap((word) => splitCamelCaseIfAllowed(word, allowedSplitWords, keepCase));
143
145
  if (!splitKeepBoth)
144
146
  continue;
145
147
  }
146
- yield line.replace(/["]/g, '');
148
+ yield line.replaceAll(/["]/g, '');
147
149
  }
148
150
  }
149
151
  function* unique(lines) {
@@ -1,9 +1,9 @@
1
- import { promises as fs } from 'fs';
1
+ import { promises as fs } from 'node:fs';
2
2
  import { compress } from '../gzip/index.js';
3
3
  const isGzFile = /\.gz$/;
4
4
  export async function writeTextToFile(filename, data) {
5
5
  const useGz = isGzFile.test(filename);
6
- const buf = Buffer.from(data, 'utf-8');
6
+ const buf = Buffer.from(data, 'utf8');
7
7
  const buffer = useGz ? await compress(buf) : buf;
8
8
  await fs.writeFile(filename, buffer);
9
9
  }
@@ -86,7 +86,7 @@ export interface Target extends CompileTargetOptions {
86
86
  * Words from the sources that are found in `excludeWordsFrom` files
87
87
  * will not be added to the dictionary.
88
88
  *
89
- * @version 8.3.2
89
+ * @since 8.3.2
90
90
  */
91
91
  excludeWordsFrom?: FilePath[] | undefined;
92
92
  /**
@@ -1,4 +1,4 @@
1
- import * as path from 'path';
1
+ import * as path from 'node:path';
2
2
  export function normalizeConfig(cfg) {
3
3
  if (!cfg)
4
4
  return cfg;
@@ -9,8 +9,10 @@ export async function shasumFile(filename, root) {
9
9
  const checksum = await calcFileChecksum(file);
10
10
  return `${checksum} ${filename}`;
11
11
  }
12
- catch (error) {
12
+ catch {
13
13
  // const err = toError(error);
14
+ // Reject with a string.
15
+ // eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
14
16
  return Promise.reject(`shasum: ${filename}: Unable to read file.`);
15
17
  }
16
18
  }
@@ -29,7 +31,7 @@ export async function checkShasumFile(filename, files, root) {
29
31
  const results = await Promise.all(filesToCheck.map(normalizeFilename).map((filename) => {
30
32
  return tryToCheckFile(filename, resolvedRoot, mapNameToChecksum.get(filename));
31
33
  }));
32
- const passed = !results.find((v) => !v.passed);
34
+ const passed = !results.some((v) => !v.passed);
33
35
  return { passed, results };
34
36
  }
35
37
  async function tryToCheckFile(filename, root, checksum) {
@@ -41,7 +43,7 @@ async function tryToCheckFile(filename, root, checksum) {
41
43
  const passed = await checkFile(checksum, file);
42
44
  return { filename, passed };
43
45
  }
44
- catch (error) {
46
+ catch {
45
47
  return { filename, passed: false, error: Error('Failed to read file.') };
46
48
  }
47
49
  }
@@ -1,7 +1,7 @@
1
- import assert from 'assert';
2
- import { mkdirSync, promises as fs, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
3
- import * as path from 'path';
4
- import { fileURLToPath } from 'url';
1
+ import assert from 'node:assert';
2
+ import { mkdirSync, promises as fs, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
3
+ import * as path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
5
  import { expect } from 'vitest';
6
6
  const _dirname = test_dirname(import.meta.url);
7
7
  const packageRoot = path.join(_dirname, '../..');
@@ -50,7 +50,7 @@ class TestHelperImpl {
50
50
  */
51
51
  resolveTemp(...parts) {
52
52
  const currentTestName = this.getCurrentTestName();
53
- const testName = currentTestName.replace(/[^\w_.-]/g, '_');
53
+ const testName = currentTestName.replaceAll(/[^\w_.-]/g, '_');
54
54
  return path.resolve(this.tempDir, testName, ...parts);
55
55
  }
56
56
  /**
@@ -96,7 +96,7 @@ class TestHelperImpl {
96
96
  await fs.stat(path);
97
97
  return true;
98
98
  }
99
- catch (e) {
99
+ catch {
100
100
  return false;
101
101
  }
102
102
  }
@@ -4,6 +4,6 @@
4
4
  * @returns - the escaped string.
5
5
  */
6
6
  export function escapeRegEx(s) {
7
- return s.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
7
+ return s.replaceAll(/[|\\{}()[\]^$+*?.]/g, '\\$&').replaceAll('-', '\\x2d');
8
8
  }
9
9
  //# sourceMappingURL=escapeRegEx.js.map
@@ -1,4 +1,4 @@
1
- import * as path from 'path';
1
+ import * as path from 'node:path';
2
2
  import { escapeRegEx } from './escapeRegEx.js';
3
3
  import { test_dirname } from './TestHelper.js';
4
4
  const _dirname = test_dirname(import.meta.url);
@@ -12,9 +12,9 @@ const rxRootRepo = new RegExp(escapeRegEx(rootRepo) + '|' + escapeRegEx(normaliz
12
12
  export function normalizeOutput(output, cwd = process.cwd()) {
13
13
  const rxCwd = new RegExp(escapeRegEx(cwd) + '|' + escapeRegEx(normalizeDirectorySeparator(cwd)), 'gi');
14
14
  const normalizeDirs = normalizeDirectorySeparator(output.replace(rxCwd, '{cwd}').replace(rxRootRepo, '{repo-root}'));
15
- return normalizeDirs.replace(regexpDate, '2022-01-01T00:00:00.000Z');
15
+ return normalizeDirs.replaceAll(regexpDate, '2022-01-01T00:00:00.000Z');
16
16
  }
17
17
  export function normalizeDirectorySeparator(path) {
18
- return path.replace(/\\/g, '/');
18
+ return path.replaceAll('\\', '/');
19
19
  }
20
20
  //# sourceMappingURL=normalizeOutput.js.map
@@ -1,7 +1,7 @@
1
1
  import { glob } from 'glob';
2
2
  export function globP(pattern, options) {
3
3
  // Convert windows separators.
4
- const globs = (Array.isArray(pattern) ? pattern : [pattern]).map((pattern) => pattern.replace(/\\/g, '/'));
4
+ const globs = (Array.isArray(pattern) ? pattern : [pattern]).map((pattern) => pattern.replaceAll('\\', '/'));
5
5
  return glob(globs, options);
6
6
  }
7
7
  //# sourceMappingURL=globP.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cspell/cspell-tools",
3
- "version": "8.7.0",
3
+ "version": "8.8.1",
4
4
  "description": "Tools to assist with the development of cSpell",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -50,14 +50,14 @@
50
50
  },
51
51
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
52
52
  "dependencies": {
53
- "@cspell/cspell-pipe": "8.7.0",
53
+ "@cspell/cspell-pipe": "8.8.1",
54
54
  "commander": "^12.0.0",
55
55
  "cosmiconfig": "9.0.0",
56
- "cspell-trie-lib": "8.7.0",
56
+ "cspell-trie-lib": "8.8.1",
57
57
  "gensequence": "^7.0.0",
58
- "glob": "^10.3.12",
59
- "hunspell-reader": "8.7.0",
60
- "yaml": "^2.4.1"
58
+ "glob": "^10.3.14",
59
+ "hunspell-reader": "8.8.1",
60
+ "yaml": "^2.4.2"
61
61
  },
62
62
  "engines": {
63
63
  "node": ">=18"
@@ -65,8 +65,8 @@
65
65
  "devDependencies": {
66
66
  "@types/glob": "^8.1.0",
67
67
  "lorem-ipsum": "^2.0.8",
68
- "ts-json-schema-generator": "^1.5.1"
68
+ "ts-json-schema-generator": "^2.1.1"
69
69
  },
70
70
  "module": "bin.mjs",
71
- "gitHead": "5318079ed11fe77e981287ecf1c40d6f28dd91ed"
71
+ "gitHead": "6381846ffce8b9a349bfda03262297aa8e301ef5"
72
72
  }