@cspell/cspell-tools 7.0.1-alpha.5 → 7.0.1-alpha.7
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.js +2 -0
- package/dist/app.js +8 -4
- package/dist/compile.d.ts +1 -0
- package/dist/compile.js +2 -1
- package/dist/compiler/compile.js +16 -2
- package/dist/compiler/createCompileRequest.js +26 -8
- package/dist/shasum/shasum.d.ts +8 -2
- package/dist/shasum/shasum.js +57 -5
- package/dist/util/errors.d.ts +4 -1
- package/package.json +5 -5
package/bin.js
CHANGED
package/dist/app.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// For large dictionaries, it is necessary to increase the memory limit.
|
|
2
|
-
import { CommanderError } from 'commander';
|
|
2
|
+
import { CommanderError, Option } from 'commander';
|
|
3
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';
|
|
7
7
|
import { logWithTimestamp } from './compiler/logWithTimestamp.js';
|
|
8
8
|
import { gzip } from './gzip/index.js';
|
|
9
|
-
import { reportCheckChecksumFile, reportChecksumForFiles } from './shasum/shasum.js';
|
|
9
|
+
import { reportCheckChecksumFile, reportChecksumForFiles, updateChecksumForFiles } from './shasum/shasum.js';
|
|
10
10
|
import { toError } from './util/errors.js';
|
|
11
11
|
const npmPackageRaw = readFileSync(new URL('../package.json', import.meta.url), 'utf8');
|
|
12
12
|
const npmPackage = JSON.parse(npmPackageRaw);
|
|
@@ -43,8 +43,10 @@ export async function run(program, argv, flags) {
|
|
|
43
43
|
}
|
|
44
44
|
async function shasum(files, options) {
|
|
45
45
|
const report = options.check
|
|
46
|
-
? await reportCheckChecksumFile(options.check, files, options
|
|
47
|
-
:
|
|
46
|
+
? await reportCheckChecksumFile(options.check, files, options)
|
|
47
|
+
: options.update
|
|
48
|
+
? await updateChecksumForFiles(options.update, files, options)
|
|
49
|
+
: await reportChecksumForFiles(files, options);
|
|
48
50
|
console.log('%s', report.report);
|
|
49
51
|
if (!report.passed) {
|
|
50
52
|
throw new CommanderError(1, 'Failed Checksum', 'One or more files had issues.');
|
|
@@ -73,7 +75,9 @@ export async function run(program, argv, flags) {
|
|
|
73
75
|
program
|
|
74
76
|
.command('shasum [files...]')
|
|
75
77
|
.description('Calculate the checksum for files.')
|
|
78
|
+
.option('--list-file <list-file.txt...>', 'Specify one or more files that contain paths of files to check.')
|
|
76
79
|
.option('-c, --check <checksum.txt>', 'Verify the checksum of files against those stored in the checksum.txt file.')
|
|
80
|
+
.addOption(new Option('-u, --update <checksum.txt>', 'Update checksums found in the file.').conflicts('--check'))
|
|
77
81
|
.option('-r, --root <root>', 'Specify the root to use for relative paths. The current working directory is used by default.')
|
|
78
82
|
.action(shasum);
|
|
79
83
|
await program.parseAsync(argv);
|
package/dist/compile.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CompileCommonAppOptions } from './AppOptions.js';
|
|
2
2
|
import type { FeatureFlags } from './FeatureFlags/index.js';
|
|
3
|
+
export declare const configFileHeader = "# yaml-language-server: $schema=https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-tools/cspell-tools.config.schema.json\n\n";
|
|
3
4
|
export declare function processCompileAction(src: string[], options: CompileCommonAppOptions, featureFlags: FeatureFlags | undefined): Promise<void>;
|
|
4
5
|
//# sourceMappingURL=compile.d.ts.map
|
package/dist/compile.js
CHANGED
|
@@ -7,6 +7,7 @@ import { getSystemFeatureFlags, parseFlags } from './FeatureFlags/index.js';
|
|
|
7
7
|
import { globP } from './util/globP.js';
|
|
8
8
|
getSystemFeatureFlags().register('compound', 'Enable compound dictionary sources.');
|
|
9
9
|
const defaultConfigFile = 'cspell-tools.config.yaml';
|
|
10
|
+
export const configFileHeader = '# yaml-language-server: $schema=https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-tools/cspell-tools.config.schema.json\n\n';
|
|
10
11
|
export async function processCompileAction(src, options, featureFlags) {
|
|
11
12
|
const ff = featureFlags || getSystemFeatureFlags();
|
|
12
13
|
parseFlags(ff, options.experimental || []);
|
|
@@ -26,7 +27,7 @@ async function useCompile(src, options) {
|
|
|
26
27
|
return options.init ? initConfig(request) : compile(request);
|
|
27
28
|
}
|
|
28
29
|
async function initConfig(request) {
|
|
29
|
-
const content = YAML.stringify(request, null, 2);
|
|
30
|
+
const content = configFileHeader + YAML.stringify(request, null, 2);
|
|
30
31
|
console.log('Writing config file: %s', defaultConfigFile);
|
|
31
32
|
await writeFile(defaultConfigFile, content);
|
|
32
33
|
console.log(`Init complete.
|
package/dist/compiler/compile.js
CHANGED
|
@@ -67,9 +67,9 @@ async function processFiles(action, filesToProcess, mergeTarget) {
|
|
|
67
67
|
}), opConcatMap(function* (ftp) {
|
|
68
68
|
yield* ftp.words;
|
|
69
69
|
logWithTimestamp('Done processing %s', rel(ftp.src));
|
|
70
|
-
})
|
|
70
|
+
}),
|
|
71
71
|
// opMap((a) => (console.warn(a), a))
|
|
72
|
-
);
|
|
72
|
+
logProgress());
|
|
73
73
|
await action(words, dst);
|
|
74
74
|
logWithTimestamp('Done "%s"', rel(dst));
|
|
75
75
|
}
|
|
@@ -134,4 +134,18 @@ async function readFileSource(fileSource, sourceOptions) {
|
|
|
134
134
|
function normalizeTargetName(name) {
|
|
135
135
|
return name.replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '').replace(/[^\p{L}\p{M}.\w\\/-]/gu, '_');
|
|
136
136
|
}
|
|
137
|
+
function logProgress(freq = 100000) {
|
|
138
|
+
function* logProgress(iter) {
|
|
139
|
+
const _freq = freq;
|
|
140
|
+
let count = 0;
|
|
141
|
+
for (const v of iter) {
|
|
142
|
+
++count;
|
|
143
|
+
if (!(count % _freq)) {
|
|
144
|
+
logWithTimestamp('Progress: Words Processed - %s', count.toLocaleString());
|
|
145
|
+
}
|
|
146
|
+
yield v;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return logProgress;
|
|
150
|
+
}
|
|
137
151
|
//# sourceMappingURL=compile.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
export function createCompileRequest(sourceFiles, options) {
|
|
3
|
-
|
|
3
|
+
options = { ...options };
|
|
4
|
+
options.maxDepth ??= options.max_depth;
|
|
5
|
+
const { maxDepth, split, keepRawCase, useLegacySplitter } = options;
|
|
4
6
|
const sources = [...sourceFiles, ...(options.listFile || []).map((listFile) => ({ listFile }))];
|
|
5
7
|
const targets = calcTargets(sources, options);
|
|
6
|
-
const generateNonStrict = experimental.includes('compound') || undefined;
|
|
7
8
|
const req = {
|
|
8
9
|
targets,
|
|
9
|
-
|
|
10
|
-
maxDepth: parseNumber(maxDepth) ?? parseNumber(max_depth),
|
|
10
|
+
maxDepth: parseNumber(maxDepth),
|
|
11
11
|
split: useLegacySplitter ? 'legacy' : split,
|
|
12
12
|
/**
|
|
13
13
|
* Do not generate lower case / accent free versions of words.
|
|
@@ -18,17 +18,21 @@ export function createCompileRequest(sourceFiles, options) {
|
|
|
18
18
|
return req;
|
|
19
19
|
}
|
|
20
20
|
function calcTargets(sources, options) {
|
|
21
|
-
const { merge, output = '.' } = options;
|
|
21
|
+
const { merge, output = '.', experimental = [] } = options;
|
|
22
|
+
const generateNonStrict = experimental.includes('compound') || undefined;
|
|
23
|
+
// console.log('%o', sources);
|
|
22
24
|
const format = calcFormat(options);
|
|
25
|
+
const sort = (format === 'plaintext' && options.sort) || undefined;
|
|
23
26
|
if (merge) {
|
|
24
27
|
const target = {
|
|
25
28
|
name: merge,
|
|
26
29
|
targetDirectory: output,
|
|
27
30
|
compress: options.compress,
|
|
28
31
|
format,
|
|
29
|
-
sources,
|
|
30
|
-
sort
|
|
32
|
+
sources: sources.map(normalizeSource),
|
|
33
|
+
sort,
|
|
31
34
|
trieBase: parseNumber(options.trieBase),
|
|
35
|
+
generateNonStrict,
|
|
32
36
|
};
|
|
33
37
|
return [target];
|
|
34
38
|
}
|
|
@@ -39,9 +43,10 @@ function calcTargets(sources, options) {
|
|
|
39
43
|
targetDirectory: output,
|
|
40
44
|
compress: options.compress,
|
|
41
45
|
format,
|
|
42
|
-
sources: [source],
|
|
46
|
+
sources: [normalizeSource(source)],
|
|
43
47
|
sort: options.sort,
|
|
44
48
|
trieBase: parseNumber(options.trieBase),
|
|
49
|
+
generateNonStrict,
|
|
45
50
|
};
|
|
46
51
|
return target;
|
|
47
52
|
});
|
|
@@ -63,4 +68,17 @@ function baseNameOfSource(source) {
|
|
|
63
68
|
function isFileSource(source) {
|
|
64
69
|
return typeof source !== 'string' && source.filename !== undefined;
|
|
65
70
|
}
|
|
71
|
+
function normalizeSource(source) {
|
|
72
|
+
if (typeof source === 'string') {
|
|
73
|
+
return normalizeSourcePath(source);
|
|
74
|
+
}
|
|
75
|
+
if (isFileSource(source))
|
|
76
|
+
return { ...source, filename: normalizeSourcePath(source.filename) };
|
|
77
|
+
return { ...source, listFile: normalizeSourcePath(source.listFile) };
|
|
78
|
+
}
|
|
79
|
+
function normalizeSourcePath(source) {
|
|
80
|
+
const cwd = process.cwd();
|
|
81
|
+
const rel = path.relative(cwd, source);
|
|
82
|
+
return rel.split('\\').join('/');
|
|
83
|
+
}
|
|
66
84
|
//# sourceMappingURL=createCompileRequest.js.map
|
package/dist/shasum/shasum.d.ts
CHANGED
|
@@ -22,7 +22,13 @@ interface ReportResult {
|
|
|
22
22
|
report: string;
|
|
23
23
|
passed: boolean;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
interface ReportOptions {
|
|
26
|
+
root?: string | undefined;
|
|
27
|
+
listFile?: string[];
|
|
28
|
+
}
|
|
29
|
+
export declare function reportChecksumForFiles(files: string[], options: ReportOptions): Promise<ReportResult>;
|
|
30
|
+
export declare function reportCheckChecksumFile(filename: string, files: string[] | undefined, options: ReportOptions): Promise<ReportResult>;
|
|
31
|
+
export declare function calcUpdateChecksumForFiles(filename: string, files: string[], options: ReportOptions): Promise<string>;
|
|
32
|
+
export declare function updateChecksumForFiles(filename: string, files: string[], options: ReportOptions): Promise<ReportResult>;
|
|
27
33
|
export {};
|
|
28
34
|
//# sourceMappingURL=shasum.d.ts.map
|
package/dist/shasum/shasum.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
+
import { toError } from '../util/errors.js';
|
|
3
4
|
import { isDefined } from '../util/index.js';
|
|
4
5
|
import { calcFileChecksum, checkFile } from './checksum.js';
|
|
5
6
|
export async function shasumFile(filename, root) {
|
|
@@ -66,9 +67,11 @@ export function parseShasumFile(content) {
|
|
|
66
67
|
return { checksum, filename, lineNumber };
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
export async function reportChecksumForFiles(files,
|
|
70
|
+
export async function reportChecksumForFiles(files, options) {
|
|
71
|
+
const root = options.root;
|
|
72
|
+
const filesToCheck = await resolveFileList(files, options.listFile);
|
|
70
73
|
let numFailed = 0;
|
|
71
|
-
const result = await Promise.all(
|
|
74
|
+
const result = await Promise.all(filesToCheck.map((file) => shasumFile(file, root).catch((e) => {
|
|
72
75
|
++numFailed;
|
|
73
76
|
if (typeof e !== 'string')
|
|
74
77
|
throw e;
|
|
@@ -78,8 +81,10 @@ export async function reportChecksumForFiles(files, root) {
|
|
|
78
81
|
const passed = !numFailed;
|
|
79
82
|
return { report, passed };
|
|
80
83
|
}
|
|
81
|
-
export async function reportCheckChecksumFile(filename, files,
|
|
82
|
-
const
|
|
84
|
+
export async function reportCheckChecksumFile(filename, files, options) {
|
|
85
|
+
const root = options.root;
|
|
86
|
+
const filesToCheck = await resolveFileList(files, options.listFile);
|
|
87
|
+
const result = await checkShasumFile(filename, filesToCheck, root);
|
|
83
88
|
const lines = result.map(({ filename, passed, error }) => `${filename}: ${passed ? 'OK' : 'FAILED'} ${error ? '- ' + error.message : ''}`.trim());
|
|
84
89
|
const withErrors = result.filter((a) => !a.passed);
|
|
85
90
|
const passed = !withErrors.length;
|
|
@@ -88,4 +93,51 @@ export async function reportCheckChecksumFile(filename, files, root) {
|
|
|
88
93
|
}
|
|
89
94
|
return { report: lines.join('\n'), passed };
|
|
90
95
|
}
|
|
96
|
+
async function resolveFileList(files, listFile) {
|
|
97
|
+
files = files || [];
|
|
98
|
+
listFile = listFile || [];
|
|
99
|
+
const setOfFiles = new Set(files);
|
|
100
|
+
const pending = listFile.map((filename) => readFile(filename, 'utf8'));
|
|
101
|
+
for await (const content of pending) {
|
|
102
|
+
content
|
|
103
|
+
.split('\n')
|
|
104
|
+
.map((a) => a.trim())
|
|
105
|
+
.filter((a) => a)
|
|
106
|
+
.forEach((file) => setOfFiles.add(file));
|
|
107
|
+
}
|
|
108
|
+
return [...setOfFiles];
|
|
109
|
+
}
|
|
110
|
+
export async function calcUpdateChecksumForFiles(filename, files, options) {
|
|
111
|
+
const root = options.root || '.';
|
|
112
|
+
const filesToCheck = await resolveFileList(files, options.listFile);
|
|
113
|
+
const currentEntries = await readAndParseShasumFile(filename).catch((err) => {
|
|
114
|
+
const e = toError(err);
|
|
115
|
+
if (e.code !== 'ENOENT')
|
|
116
|
+
throw e;
|
|
117
|
+
return [];
|
|
118
|
+
});
|
|
119
|
+
const entriesToUpdate = new Set([...filesToCheck, ...currentEntries.map((e) => e.filename)]);
|
|
120
|
+
const mustExist = new Set(filesToCheck);
|
|
121
|
+
const checksumMap = new Map(currentEntries.map(({ filename, checksum }) => [filename, checksum]));
|
|
122
|
+
for (const file of entriesToUpdate) {
|
|
123
|
+
try {
|
|
124
|
+
const checksum = await calcFileChecksum(resolve(root, file));
|
|
125
|
+
checksumMap.set(file, checksum);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
if (mustExist.has(file) || toError(e).code !== 'ENOENT')
|
|
129
|
+
throw e;
|
|
130
|
+
checksumMap.delete(file);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const updatedEntries = [...checksumMap]
|
|
134
|
+
.map(([filename, checksum]) => ({ filename, checksum }))
|
|
135
|
+
.sort((a, b) => (a.filename < b.filename ? -1 : 1));
|
|
136
|
+
return updatedEntries.map((e) => `${e.checksum} ${e.filename}`).join('\n') + '\n';
|
|
137
|
+
}
|
|
138
|
+
export async function updateChecksumForFiles(filename, files, options) {
|
|
139
|
+
const content = await calcUpdateChecksumForFiles(filename, files, options);
|
|
140
|
+
await writeFile(filename, content);
|
|
141
|
+
return { passed: true, report: content };
|
|
142
|
+
}
|
|
91
143
|
//# sourceMappingURL=shasum.js.map
|
package/dist/util/errors.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface NodeError extends Error {
|
|
2
|
+
code?: string;
|
|
3
|
+
}
|
|
4
|
+
export declare function toError(err: unknown): NodeError;
|
|
2
5
|
export declare function isError(err: unknown): err is Error;
|
|
3
6
|
//# sourceMappingURL=errors.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cspell/cspell-tools",
|
|
3
|
-
"version": "7.0.1-alpha.
|
|
3
|
+
"version": "7.0.1-alpha.7",
|
|
4
4
|
"description": "Tools to assist with the development of cSpell",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@cspell/cspell-pipe": "7.0.1-alpha.
|
|
53
|
+
"@cspell/cspell-pipe": "7.0.1-alpha.7",
|
|
54
54
|
"commander": "^11.0.0",
|
|
55
55
|
"cosmiconfig": "8.0.0",
|
|
56
|
-
"cspell-trie-lib": "7.0.1-alpha.
|
|
56
|
+
"cspell-trie-lib": "7.0.1-alpha.7",
|
|
57
57
|
"gensequence": "^5.0.2",
|
|
58
58
|
"glob": "^10.3.3",
|
|
59
|
-
"hunspell-reader": "7.0.1-alpha.
|
|
59
|
+
"hunspell-reader": "7.0.1-alpha.7",
|
|
60
60
|
"yaml": "^2.3.1"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"ts-json-schema-generator": "^1.2.0"
|
|
73
73
|
},
|
|
74
74
|
"main": "bin.js",
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "719c2f9f55c79d35074f8493a37de6f40077325d"
|
|
76
76
|
}
|