@cspell/cspell-tools 9.4.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.
Files changed (110) hide show
  1. package/bin.mjs +1 -1
  2. package/cspell-tools.config.schema.json +50 -24
  3. package/dist/app.d.mts +35 -0
  4. package/dist/app.mjs +292 -0
  5. package/dist/build-OgMPaXPZ.mjs +1403 -0
  6. package/dist/index.d.mts +35 -0
  7. package/dist/index.mjs +3 -0
  8. package/package.json +10 -9
  9. package/dist/AppOptions.d.ts +0 -31
  10. package/dist/AppOptions.js +0 -2
  11. package/dist/FeatureFlags/FeatureFlags.d.ts +0 -34
  12. package/dist/FeatureFlags/FeatureFlags.js +0 -94
  13. package/dist/FeatureFlags/index.d.ts +0 -3
  14. package/dist/FeatureFlags/index.js +0 -3
  15. package/dist/FeatureFlags/parseFlags.d.ts +0 -3
  16. package/dist/FeatureFlags/parseFlags.js +0 -20
  17. package/dist/app.d.ts +0 -4
  18. package/dist/app.js +0 -86
  19. package/dist/build.d.ts +0 -12
  20. package/dist/build.js +0 -36
  21. package/dist/compile.d.ts +0 -5
  22. package/dist/compile.js +0 -41
  23. package/dist/compiler/CompileOptions.d.ts +0 -35
  24. package/dist/compiler/CompileOptions.js +0 -2
  25. package/dist/compiler/Reader.d.ts +0 -3
  26. package/dist/compiler/Reader.js +0 -24
  27. package/dist/compiler/SourceReader.d.ts +0 -28
  28. package/dist/compiler/SourceReader.js +0 -44
  29. package/dist/compiler/WordsCollection.d.ts +0 -20
  30. package/dist/compiler/WordsCollection.js +0 -3
  31. package/dist/compiler/compile.d.ts +0 -26
  32. package/dist/compiler/compile.js +0 -263
  33. package/dist/compiler/createCompileRequest.d.ts +0 -4
  34. package/dist/compiler/createCompileRequest.js +0 -84
  35. package/dist/compiler/createWordsCollection.d.ts +0 -9
  36. package/dist/compiler/createWordsCollection.js +0 -108
  37. package/dist/compiler/fileWriter.d.ts +0 -3
  38. package/dist/compiler/fileWriter.js +0 -6
  39. package/dist/compiler/index.d.ts +0 -5
  40. package/dist/compiler/index.js +0 -4
  41. package/dist/compiler/legacyLineToWords.d.ts +0 -4
  42. package/dist/compiler/legacyLineToWords.js +0 -20
  43. package/dist/compiler/logWithTimestamp.d.ts +0 -3
  44. package/dist/compiler/logWithTimestamp.js +0 -5
  45. package/dist/compiler/logger.d.ts +0 -4
  46. package/dist/compiler/logger.js +0 -9
  47. package/dist/compiler/readers/ReaderOptions.d.ts +0 -19
  48. package/dist/compiler/readers/ReaderOptions.js +0 -2
  49. package/dist/compiler/readers/readHunspellFiles.d.ts +0 -3
  50. package/dist/compiler/readers/readHunspellFiles.js +0 -57
  51. package/dist/compiler/readers/readTextFile.d.ts +0 -3
  52. package/dist/compiler/readers/readTextFile.js +0 -20
  53. package/dist/compiler/readers/regHunspellFile.d.ts +0 -2
  54. package/dist/compiler/readers/regHunspellFile.js +0 -2
  55. package/dist/compiler/readers/textFileReader.d.ts +0 -3
  56. package/dist/compiler/readers/textFileReader.js +0 -11
  57. package/dist/compiler/readers/trieFileReader.d.ts +0 -3
  58. package/dist/compiler/readers/trieFileReader.js +0 -16
  59. package/dist/compiler/splitCamelCaseIfAllowed.d.ts +0 -5
  60. package/dist/compiler/splitCamelCaseIfAllowed.js +0 -65
  61. package/dist/compiler/streamSourceWordsFromFile.d.ts +0 -3
  62. package/dist/compiler/streamSourceWordsFromFile.js +0 -6
  63. package/dist/compiler/text.d.ts +0 -10
  64. package/dist/compiler/text.js +0 -28
  65. package/dist/compiler/wordListCompiler.d.ts +0 -17
  66. package/dist/compiler/wordListCompiler.js +0 -199
  67. package/dist/compiler/wordListParser.d.ts +0 -61
  68. package/dist/compiler/wordListParser.js +0 -184
  69. package/dist/compiler/writeTextToFile.d.ts +0 -3
  70. package/dist/compiler/writeTextToFile.js +0 -15
  71. package/dist/config/config.d.ts +0 -194
  72. package/dist/config/config.js +0 -2
  73. package/dist/config/configDefaults.d.ts +0 -9
  74. package/dist/config/configDefaults.js +0 -9
  75. package/dist/config/configUtils.d.ts +0 -5
  76. package/dist/config/configUtils.js +0 -14
  77. package/dist/config/index.d.ts +0 -4
  78. package/dist/config/index.js +0 -3
  79. package/dist/config/normalizeConfig.d.ts +0 -8
  80. package/dist/config/normalizeConfig.js +0 -13
  81. package/dist/gzip/compressFiles.d.ts +0 -16
  82. package/dist/gzip/compressFiles.js +0 -42
  83. package/dist/gzip/gzip.d.ts +0 -3
  84. package/dist/gzip/gzip.js +0 -10
  85. package/dist/gzip/index.d.ts +0 -3
  86. package/dist/gzip/index.js +0 -3
  87. package/dist/shasum/checksum.d.ts +0 -7
  88. package/dist/shasum/checksum.js +0 -19
  89. package/dist/shasum/index.d.ts +0 -3
  90. package/dist/shasum/index.js +0 -3
  91. package/dist/shasum/shasum.d.ts +0 -38
  92. package/dist/shasum/shasum.js +0 -150
  93. package/dist/test/TestHelper.d.ts +0 -53
  94. package/dist/test/TestHelper.js +0 -121
  95. package/dist/test/console.d.ts +0 -9
  96. package/dist/test/console.js +0 -34
  97. package/dist/test/escapeRegEx.d.ts +0 -7
  98. package/dist/test/escapeRegEx.js +0 -9
  99. package/dist/test/normalizeOutput.d.ts +0 -3
  100. package/dist/test/normalizeOutput.js +0 -20
  101. package/dist/types.d.ts +0 -7
  102. package/dist/types.js +0 -2
  103. package/dist/util/errors.d.ts +0 -6
  104. package/dist/util/errors.js +0 -11
  105. package/dist/util/globP.d.ts +0 -7
  106. package/dist/util/globP.js +0 -7
  107. package/dist/util/index.d.ts +0 -2
  108. package/dist/util/index.js +0 -4
  109. package/dist/util/textRegex.d.ts +0 -3
  110. package/dist/util/textRegex.js +0 -109
@@ -1,15 +0,0 @@
1
- import { Buffer } from 'node:buffer';
2
- import { promises as fs } from 'node:fs';
3
- import { compress } from '../gzip/index.js';
4
- const isGzFile = /\.gz$/;
5
- export async function writeTextToFile(filename, data) {
6
- const useGz = isGzFile.test(filename);
7
- const buf = Buffer.from(data, 'utf8');
8
- const buffer = useGz ? await compress(buf) : buf;
9
- await fs.writeFile(filename, buffer);
10
- }
11
- export function writeTextLinesToFile(filename, lines) {
12
- const data = Array.isArray(lines) ? lines.join('') : [...lines].join('');
13
- return writeTextToFile(filename, data);
14
- }
15
- //# sourceMappingURL=writeTextToFile.js.map
@@ -1,194 +0,0 @@
1
- export interface RunConfig extends Partial<Omit<CompileRequest, 'targets'>> {
2
- /**
3
- * Url to JSON Schema
4
- * @default "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-tools/cspell-tools.config.schema.json"
5
- */
6
- $schema?: string | undefined;
7
- /**
8
- * Optional Target Dictionaries to create.
9
- */
10
- targets?: Target[] | undefined;
11
- /**
12
- * Specify the directory where all relative paths will resolved against.
13
- * By default, all relative paths are relative to the location of the
14
- * config file.
15
- */
16
- rootDir?: string | undefined;
17
- }
18
- export interface CompileRequest extends CompileTargetOptions, CompileSourceOptions {
19
- /**
20
- * Specify the directory where all relative paths will resolved against.
21
- * By default, all relative paths are relative to the current directory.
22
- */
23
- rootDir?: string | undefined;
24
- /**
25
- * Target Dictionaries to create.
26
- */
27
- targets: Target[];
28
- /**
29
- * Path to checksum file. `true` - defaults to `./checksum.txt`.
30
- */
31
- checksumFile?: string | boolean | undefined;
32
- }
33
- export interface Experimental {
34
- /**
35
- * Experimental flags
36
- */
37
- experimental?: string[] | undefined;
38
- }
39
- export interface CompileTargetOptions {
40
- /**
41
- * Generate lower case / accent free versions of words.
42
- * @default false
43
- */
44
- generateNonStrict?: boolean | undefined;
45
- /**
46
- * Sort the words in the resulting dictionary.
47
- * Does not apply to `trie` based formats.
48
- * @default true
49
- */
50
- sort?: boolean | undefined;
51
- /**
52
- * Words in the `allowedSplitWords` are considered correct and can be used
53
- * as a basis for splitting compound words.
54
- *
55
- * If entries can be split so that all the words in the entry are allowed,
56
- * then only the individual words are added, otherwise the entire entry is added.
57
- * This is to prevent misspellings in CamelCase words from being introduced into the
58
- * dictionary.
59
- */
60
- allowedSplitWords?: FilePath | FilePath[] | undefined;
61
- /**
62
- * Injects `cspell-dictionary` directives into the dictionary header.
63
- *
64
- * Example:
65
- *
66
- * ```ini
67
- * # cspell-dictionary: no-generate-alternatives
68
- * ```
69
- *
70
- * Known Directives:
71
- * ```yaml
72
- * - split # Tell the dictionary loader to split words
73
- * - no-split # Tell the dictionary loader to not split words (default)
74
- * - generate-alternatives # Tell the dictionary loader to generate alternate spellings (default)
75
- * - no-generate-alternatives # Tell the dictionary loader to not generate alternate spellings
76
- * ```
77
- */
78
- dictionaryDirectives?: string[] | undefined;
79
- /**
80
- * Remove duplicate words, favor lower case words over mixed case words.
81
- * Combine compound prefixes where possible.
82
- * @default false
83
- */
84
- removeDuplicates?: boolean | undefined;
85
- }
86
- export interface Target extends CompileTargetOptions {
87
- /**
88
- * Name of target, used as the basis of target file name.
89
- */
90
- name: string;
91
- /**
92
- * The target directory
93
- * @default current directory
94
- */
95
- targetDirectory?: FilePath | undefined;
96
- /**
97
- * gzip the file?
98
- * @default: false
99
- */
100
- compress?: boolean | undefined;
101
- /**
102
- * Format of the dictionary.
103
- */
104
- format: DictionaryFormats;
105
- /**
106
- * File sources used to build the dictionary.
107
- */
108
- sources: DictionarySource[];
109
- /**
110
- * Words from the sources that are found in `excludeWordsFrom` files
111
- * will NOT be added to the dictionary.
112
- *
113
- * @since 8.3.2
114
- */
115
- excludeWordsFrom?: FilePath[] | undefined;
116
- /**
117
- * Words from the sources that are NOT found in `excludeWordsNotFoundIn` files
118
- * will NOT be added to the dictionary.
119
- *
120
- * @since 8.19.4
121
- */
122
- excludeWordsNotFoundIn?: FilePath[] | undefined;
123
- /**
124
- * Words from the sources that match the regex in `excludeWordsMatchingRegex`
125
- * will NOT be added to the dictionary.
126
- *
127
- * Note: The regex must be a valid JavaScript literal regex expression including the `/` delimiters.
128
- *
129
- * @since 8.19.4
130
- */
131
- excludeWordsMatchingRegex?: string[] | undefined;
132
- /**
133
- * Advanced: Set the trie base number. A value between 10 and 36
134
- * Set numeric base to use.
135
- * 10 is the easiest to read.
136
- * 16 is common hex format.
137
- * 36 is the most compact.
138
- */
139
- trieBase?: number | undefined;
140
- }
141
- export type DictionaryFormats = 'plaintext' | 'trie' | 'trie3' | 'trie4';
142
- /**
143
- * Note: All relative paths are relative to the config file location.
144
- */
145
- export type FilePath = string;
146
- export type DictionarySource = FilePath | FileSource | FileListSource;
147
- export interface FileSource extends CompileSourceOptions {
148
- filename: FilePath;
149
- }
150
- export interface FileListSource extends CompileSourceOptions {
151
- listFile: FilePath;
152
- }
153
- export interface CompileSourceOptions {
154
- /**
155
- * Maximum number of nested Hunspell Rules to apply.
156
- * This is needed for recursive dictionaries like Hebrew.
157
- */
158
- maxDepth?: number | undefined;
159
- /**
160
- * Split lines into words.
161
- * @default false
162
- */
163
- split?: boolean | 'legacy' | undefined;
164
- /**
165
- * Do not generate lower case / accent free versions of words.
166
- * @default false
167
- */
168
- keepRawCase?: boolean | undefined;
169
- /**
170
- * Words in the `allowedSplitWords` are considered correct and can be used
171
- * as a basis for splitting compound words.
172
- *
173
- * If entries can be split so that all the words in the entry are allowed,
174
- * then only the individual words are added, otherwise the entire entry is added.
175
- * This is to prevent misspellings in CamelCase words from being introduced into the
176
- * dictionary.
177
- */
178
- allowedSplitWords?: FilePath | FilePath[] | undefined;
179
- /**
180
- * Camel case words that have been split using the `allowedSplitWords` are added to the dictionary as compoundable words.
181
- * These words are prefixed / suffixed with `*`.
182
- * @default false
183
- */
184
- storeSplitWordsAsCompounds?: boolean | undefined;
185
- /**
186
- * Controls the minimum length of a compound word when storing words using `storeSplitWordsAsCompounds`.
187
- * The compound words are prefixed / suffixed with `*`, to allow them to be combined with other compound words.
188
- * If the length is too low, then the dictionary will consider many misspelled words as correct.
189
- * @default 4
190
- */
191
- minCompoundLength?: number | undefined;
192
- }
193
- export declare const configFileSchemaURL = "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-tools/cspell-tools.config.schema.json";
194
- //# sourceMappingURL=config.d.ts.map
@@ -1,2 +0,0 @@
1
- export const configFileSchemaURL = 'https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-tools/cspell-tools.config.schema.json';
2
- //# sourceMappingURL=config.js.map
@@ -1,9 +0,0 @@
1
- export declare const defaultCompileSourceOptions: {
2
- readonly maxDepth: undefined;
3
- readonly split: false;
4
- readonly keepRawCase: false;
5
- readonly allowedSplitWords: undefined;
6
- readonly storeSplitWordsAsCompounds: false;
7
- readonly minCompoundLength: 4;
8
- };
9
- //# sourceMappingURL=configDefaults.d.ts.map
@@ -1,9 +0,0 @@
1
- export const defaultCompileSourceOptions = {
2
- maxDepth: undefined,
3
- split: false,
4
- keepRawCase: false,
5
- allowedSplitWords: undefined,
6
- storeSplitWordsAsCompounds: false,
7
- minCompoundLength: 4,
8
- };
9
- //# sourceMappingURL=configDefaults.js.map
@@ -1,5 +0,0 @@
1
- import type { DictionarySource, FileListSource, FilePath, FileSource } from '../config/index.js';
2
- export declare function isFilePath(source: DictionarySource): source is FilePath;
3
- export declare function isFileSource(source: DictionarySource): source is FileSource;
4
- export declare function isFileListSource(source: DictionarySource): source is FileListSource;
5
- //# sourceMappingURL=configUtils.d.ts.map
@@ -1,14 +0,0 @@
1
- export function isFilePath(source) {
2
- return typeof source === 'string';
3
- }
4
- export function isFileSource(source) {
5
- if (!source || isFilePath(source))
6
- return false;
7
- return source.filename !== undefined;
8
- }
9
- export function isFileListSource(source) {
10
- if (!source || isFilePath(source))
11
- return false;
12
- return source.listFile !== undefined;
13
- }
14
- //# sourceMappingURL=configUtils.js.map
@@ -1,4 +0,0 @@
1
- export type { CompileRequest, CompileSourceOptions, CompileTargetOptions, DictionaryFormats, DictionarySource, FileListSource, FilePath, FileSource, RunConfig, Target, } from './config.js';
2
- export { isFileListSource, isFilePath, isFileSource } from './configUtils.js';
3
- export { normalizeConfig } from './normalizeConfig.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +0,0 @@
1
- export { isFileListSource, isFilePath, isFileSource } from './configUtils.js';
2
- export { normalizeConfig } from './normalizeConfig.js';
3
- //# sourceMappingURL=index.js.map
@@ -1,8 +0,0 @@
1
- type CosmiconfigResult = {
2
- config: any;
3
- filepath: string;
4
- isEmpty?: boolean | undefined;
5
- } | null;
6
- export declare function normalizeConfig(cfg: CosmiconfigResult): CosmiconfigResult;
7
- export {};
8
- //# sourceMappingURL=normalizeConfig.d.ts.map
@@ -1,13 +0,0 @@
1
- import * as path from 'node:path';
2
- export function normalizeConfig(cfg) {
3
- if (!cfg)
4
- return cfg;
5
- const dir = path.dirname(cfg.filepath);
6
- const config = cfg.config;
7
- const result = { ...config, rootDir: path.resolve(dir, config.rootDir || '.') };
8
- return {
9
- config: result,
10
- filepath: cfg.filepath,
11
- };
12
- }
13
- //# sourceMappingURL=normalizeConfig.js.map
@@ -1,16 +0,0 @@
1
- import type { Buffer } from 'node:buffer';
2
- export declare enum OSFlags {
3
- auto = -1,
4
- FAT = 0,
5
- Unix = 3,
6
- HPFS = 6,// cspell:ignore hpfs
7
- MACOS = 7,
8
- NTFS = 11
9
- }
10
- export declare function compressFile(file: string, os?: OSFlags): Promise<string>;
11
- export declare function compress(buf: string | Uint8Array | Buffer, os?: OSFlags): Promise<Uint8Array>;
12
- export declare function compressSync(buf: string | Uint8Array | Buffer, os?: OSFlags): Uint8Array;
13
- export declare function decompress(buf: Uint8Array | Buffer, encoding?: undefined): Promise<Uint8Array>;
14
- export declare function decompress(buf: Uint8Array | Buffer, encoding: 'utf8'): Promise<string>;
15
- export declare function decompress(buf: Uint8Array | Buffer, encoding: 'utf8' | undefined): Promise<string | Uint8Array>;
16
- //# sourceMappingURL=compressFiles.d.ts.map
@@ -1,42 +0,0 @@
1
- import { readFile, writeFile } from 'node:fs/promises';
2
- import { promisify } from 'node:util';
3
- import { gunzip as gunzipCB, gzip as gz, gzipSync } from 'node:zlib';
4
- const gzip = promisify(gz);
5
- const gunzip = promisify(gunzipCB);
6
- export var OSFlags;
7
- (function (OSFlags) {
8
- OSFlags[OSFlags["auto"] = -1] = "auto";
9
- OSFlags[OSFlags["FAT"] = 0] = "FAT";
10
- OSFlags[OSFlags["Unix"] = 3] = "Unix";
11
- OSFlags[OSFlags["HPFS"] = 6] = "HPFS";
12
- OSFlags[OSFlags["MACOS"] = 7] = "MACOS";
13
- OSFlags[OSFlags["NTFS"] = 11] = "NTFS";
14
- })(OSFlags || (OSFlags = {}));
15
- // https://docs.fileformat.com/compression/gz/#:~:text=A%20GZ%20file%20is%20a,compression%20formats%20on%20UNIX%20systems.
16
- const OSSystemIDOffset = 9;
17
- export async function compressFile(file, os) {
18
- if (file.endsWith('.gz'))
19
- return file;
20
- const targetFile = file + '.gz';
21
- const zBuf = await compress(await readFile(file), os);
22
- await writeFile(targetFile, zBuf);
23
- return targetFile;
24
- }
25
- export async function compress(buf, os) {
26
- return fixOSSystemID(await gzip(buf), os);
27
- }
28
- export function compressSync(buf, os) {
29
- return fixOSSystemID(gzipSync(buf), os);
30
- }
31
- function fixOSSystemID(zBuf, os = OSFlags.Unix) {
32
- const osFlag = os == OSFlags.auto ? zBuf[OSSystemIDOffset] : os;
33
- zBuf[OSSystemIDOffset] = osFlag;
34
- return zBuf;
35
- }
36
- export async function decompress(buf, encoding) {
37
- const dBuf = gunzip(buf);
38
- if (!encoding)
39
- return dBuf;
40
- return (await dBuf).toString(encoding);
41
- }
42
- //# sourceMappingURL=compressFiles.js.map
@@ -1,3 +0,0 @@
1
- import type { OSFlags } from './compressFiles.js';
2
- export declare function gzip(globs: string[], os?: OSFlags): Promise<void>;
3
- //# sourceMappingURL=gzip.d.ts.map
package/dist/gzip/gzip.js DELETED
@@ -1,10 +0,0 @@
1
- import { globP } from '../util/globP.js';
2
- import { compressFile } from './compressFiles.js';
3
- // cspell:ignore nodir
4
- export async function gzip(globs, os) {
5
- const files = await globP(globs, { nodir: true });
6
- for (const fileName of files) {
7
- await compressFile(fileName, os);
8
- }
9
- }
10
- //# sourceMappingURL=gzip.js.map
@@ -1,3 +0,0 @@
1
- export { compress, compressFile, decompress, OSFlags } from './compressFiles.js';
2
- export { gzip } from './gzip.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +0,0 @@
1
- export { compress, compressFile, decompress, OSFlags } from './compressFiles.js';
2
- export { gzip } from './gzip.js';
3
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- type HashAlgorithm = 'SHA1';
2
- export declare function calcChecksum(buf: Buffer, alg?: HashAlgorithm): string;
3
- export declare function checkChecksum(checksum: string, buf: Buffer, alg?: HashAlgorithm): boolean;
4
- export declare function calcFileChecksum(filename: string, alg?: HashAlgorithm): Promise<string>;
5
- export declare function checkFile(checksum: string, filename: string, alg?: HashAlgorithm): Promise<boolean>;
6
- export {};
7
- //# sourceMappingURL=checksum.d.ts.map
@@ -1,19 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { readFile } from 'node:fs/promises';
3
- export function calcChecksum(buf, alg = 'SHA1') {
4
- const hash = createHash(alg);
5
- hash.update(buf);
6
- return hash.digest('hex');
7
- }
8
- export function checkChecksum(checksum, buf, alg) {
9
- const value = calcChecksum(buf, alg);
10
- return value === checksum;
11
- }
12
- export async function calcFileChecksum(filename, alg) {
13
- const buf = await readFile(filename);
14
- return calcChecksum(buf, alg);
15
- }
16
- export async function checkFile(checksum, filename, alg) {
17
- return (await calcFileChecksum(filename, alg)) === checksum;
18
- }
19
- //# sourceMappingURL=checksum.js.map
@@ -1,3 +0,0 @@
1
- export { calcFileChecksum } from './checksum.js';
2
- export { checkShasumFile, updateChecksumForFiles } from './shasum.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +0,0 @@
1
- export { calcFileChecksum } from './checksum.js';
2
- export { checkShasumFile, updateChecksumForFiles } from './shasum.js';
3
- //# sourceMappingURL=index.js.map
@@ -1,38 +0,0 @@
1
- export interface CheckShasumFileResult {
2
- passed: boolean;
3
- results: CheckFileResult[];
4
- }
5
- export interface CheckFileResult {
6
- filename: string;
7
- passed: boolean;
8
- error?: Error;
9
- }
10
- export declare function shasumFile(filename: string, root: string | undefined): Promise<string>;
11
- /**
12
- *
13
- * @param filename - name of checksum file
14
- * @param files - optional list of files to check
15
- * @param root - optional root, default cwd.
16
- */
17
- export declare function checkShasumFile(filename: string, files: string[] | undefined, root?: string): Promise<CheckShasumFileResult>;
18
- export interface ChecksumEntry {
19
- filename: string;
20
- checksum: string;
21
- lineNumber: number;
22
- }
23
- export declare function readAndParseShasumFile(filename: string): Promise<ChecksumEntry[]>;
24
- export declare function parseShasumFile(content: string): ChecksumEntry[];
25
- interface ReportResult {
26
- report: string;
27
- passed: boolean;
28
- }
29
- interface ReportOptions {
30
- root?: string | undefined;
31
- listFile?: string[] | undefined;
32
- }
33
- export declare function reportChecksumForFiles(files: string[], options: ReportOptions): Promise<ReportResult>;
34
- export declare function reportCheckChecksumFile(filename: string, files: string[] | undefined, options: ReportOptions): Promise<ReportResult>;
35
- export declare function calcUpdateChecksumForFiles(filename: string, files: string[], options: ReportOptions): Promise<string>;
36
- export declare function updateChecksumForFiles(filename: string, files: string[], options: ReportOptions): Promise<ReportResult>;
37
- export {};
38
- //# sourceMappingURL=shasum.d.ts.map
@@ -1,150 +0,0 @@
1
- import { readFile, writeFile } from 'node:fs/promises';
2
- import { resolve, sep as pathSep } from 'node:path';
3
- import { toError } from '../util/errors.js';
4
- import { isDefined } from '../util/index.js';
5
- import { calcFileChecksum, checkFile } from './checksum.js';
6
- export async function shasumFile(filename, root) {
7
- try {
8
- const file = resolve(root || '.', filename);
9
- const checksum = await calcFileChecksum(file);
10
- return `${checksum} ${filename}`;
11
- }
12
- catch {
13
- // const err = toError(error);
14
- // Reject with a string.
15
- // eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
16
- return Promise.reject(`shasum: ${filename}: Unable to read file.`);
17
- }
18
- }
19
- /**
20
- *
21
- * @param filename - name of checksum file
22
- * @param files - optional list of files to check
23
- * @param root - optional root, default cwd.
24
- */
25
- export async function checkShasumFile(filename, files, root) {
26
- files = !files ? files : files.length ? files : undefined;
27
- const shaFiles = await readAndParseShasumFile(filename);
28
- const filesToCheck = !files ? shaFiles.map(({ filename }) => filename) : files;
29
- const mapNameToChecksum = new Map(shaFiles.map((r) => [normalizeFilename(r.filename), r.checksum]));
30
- const resolvedRoot = resolve(root || '.');
31
- const results = await Promise.all(filesToCheck.map(normalizeFilename).map((filename) => {
32
- return tryToCheckFile(filename, resolvedRoot, mapNameToChecksum.get(filename));
33
- }));
34
- const passed = !results.some((v) => !v.passed);
35
- return { passed, results };
36
- }
37
- async function tryToCheckFile(filename, root, checksum) {
38
- if (!checksum) {
39
- return { filename, passed: false, error: new Error('Missing Checksum.') };
40
- }
41
- const file = resolve(root, filename);
42
- try {
43
- const passed = await checkFile(checksum, file);
44
- return { filename, passed };
45
- }
46
- catch {
47
- return { filename, passed: false, error: new Error('Failed to read file.') };
48
- }
49
- }
50
- const regLine = /([a-f0-9]{40,}) {2}(.*)/;
51
- export async function readAndParseShasumFile(filename) {
52
- const content = await readFile(resolve(filename), 'utf8');
53
- const shaFiles = parseShasumFile(content);
54
- return shaFiles;
55
- }
56
- export function parseShasumFile(content) {
57
- const lines = content.split(/\r?\n|\r/g);
58
- return lines.map(parseLine).filter(isDefined);
59
- function parseLine(line, index) {
60
- const m = line.match(regLine);
61
- const lineNumber = index + 1;
62
- if (!m) {
63
- if (line.trim()) {
64
- throw new Error(`Failed to parse line ${lineNumber} of checksum file.`);
65
- }
66
- return undefined;
67
- }
68
- const checksum = m[1];
69
- const filename = m[2];
70
- return { checksum, filename, lineNumber };
71
- }
72
- }
73
- export async function reportChecksumForFiles(files, options) {
74
- const root = options.root;
75
- const filesToCheck = await resolveFileList(files, options.listFile);
76
- let numFailed = 0;
77
- const result = await Promise.all(filesToCheck.map((file) => shasumFile(file, root).catch((e) => {
78
- ++numFailed;
79
- if (typeof e !== 'string')
80
- throw e;
81
- return e;
82
- })));
83
- const report = result.join('\n');
84
- const passed = !numFailed;
85
- return { report, passed };
86
- }
87
- export async function reportCheckChecksumFile(filename, files, options) {
88
- const root = options.root;
89
- const filesToCheck = await resolveFileList(files, options.listFile);
90
- const checkResult = await checkShasumFile(filename, filesToCheck, root);
91
- const results = checkResult.results;
92
- const lines = results.map(({ filename, passed, error }) => `${filename}: ${passed ? 'OK' : 'FAILED'} ${error ? '- ' + error.message : ''}`.trim());
93
- const withErrors = results.filter((a) => !a.passed);
94
- const passed = !withErrors.length;
95
- if (!passed) {
96
- lines.push(`shasum: WARNING: ${withErrors.length} computed checksum${withErrors.length > 1 ? 's' : ''} did NOT match`);
97
- }
98
- return { report: lines.join('\n'), passed };
99
- }
100
- async function resolveFileList(files, listFile) {
101
- files = files || [];
102
- listFile = listFile || [];
103
- const setOfFiles = new Set(files);
104
- const pending = listFile.map((filename) => readFile(filename, 'utf8'));
105
- for await (const content of pending) {
106
- content
107
- .split('\n')
108
- .map((a) => a.trim())
109
- .filter((a) => a)
110
- .forEach((file) => setOfFiles.add(file));
111
- }
112
- return [...setOfFiles].map(normalizeFilename);
113
- }
114
- export async function calcUpdateChecksumForFiles(filename, files, options) {
115
- const root = options.root || '.';
116
- const filesToCheck = await resolveFileList(files, options.listFile);
117
- const currentEntries = (await readAndParseShasumFile(filename).catch((err) => {
118
- const e = toError(err);
119
- if (e.code !== 'ENOENT')
120
- throw e;
121
- return [];
122
- })).map((entry) => ({ ...entry, filename: normalizeFilename(entry.filename) }));
123
- const entriesToUpdate = new Set([...filesToCheck, ...currentEntries.map((e) => e.filename)]);
124
- const mustExist = new Set(filesToCheck);
125
- const checksumMap = new Map(currentEntries.map(({ filename, checksum }) => [filename, checksum]));
126
- for (const file of entriesToUpdate) {
127
- try {
128
- const checksum = await calcFileChecksum(resolve(root, file));
129
- checksumMap.set(file, checksum);
130
- }
131
- catch (e) {
132
- if (mustExist.has(file) || toError(e).code !== 'ENOENT')
133
- throw e;
134
- checksumMap.delete(file);
135
- }
136
- }
137
- const updatedEntries = [...checksumMap]
138
- .map(([filename, checksum]) => ({ filename, checksum }))
139
- .sort((a, b) => (a.filename < b.filename ? -1 : 1));
140
- return updatedEntries.map((e) => `${e.checksum} ${e.filename}`).join('\n') + '\n';
141
- }
142
- export async function updateChecksumForFiles(filename, files, options) {
143
- const content = await calcUpdateChecksumForFiles(filename, files, options);
144
- await writeFile(filename, content);
145
- return { passed: true, report: content };
146
- }
147
- function normalizeFilename(filename) {
148
- return filename.split(pathSep).join('/');
149
- }
150
- //# sourceMappingURL=shasum.js.map
@@ -1,53 +0,0 @@
1
- export interface TestHelper {
2
- /** path to `.../cspell/package/cspell-tools/` */
3
- readonly packageRoot: string;
4
- /** path to `...cspell/` */
5
- readonly repoRoot: string;
6
- readonly tempDir: string;
7
- /**
8
- * delete the contents of the temp directory for the current test.
9
- */
10
- clearTempDir(): void;
11
- /**
12
- * Resolves the parts to be an absolute path in the temp directory
13
- * for a given test.
14
- * @param parts
15
- */
16
- resolveTemp(...parts: string[]): string;
17
- createTempDir(...parts: string[]): void;
18
- /**
19
- * Resolves a fixture path to an absolute path
20
- * @param parts - relative path to fixture
21
- */
22
- resolveFixture(...parts: string[]): string;
23
- /**
24
- * Resolves a path to an absolute path in Samples
25
- * @param parts - relative path to sample
26
- */
27
- resolveSample(...parts: string[]): string;
28
- /**
29
- * Make the temp directory
30
- * @param parts
31
- */
32
- mkdir(...parts: string[]): void;
33
- /**
34
- * copy file
35
- * @param from
36
- * @param to
37
- */
38
- cpFileSync(from: string, to: string): void;
39
- packageTemp(...parts: string[]): string;
40
- /**
41
- * Signal the start of a test.
42
- * Use to make test.each unique.
43
- * @param name
44
- */
45
- beginTest(name?: string): void;
46
- getCurrentTestName(): string;
47
- fileExists(path: string): Promise<boolean>;
48
- }
49
- export declare function createTestHelper(testFilenameUrl: string): TestHelper;
50
- export declare function resolvePathToFixture(...segments: string[]): string;
51
- export declare function test_dirname(importMetaUrl: string): string;
52
- export declare function test_filename(importMetaUrl: string): string;
53
- //# sourceMappingURL=TestHelper.d.ts.map