@cspell/cspell-tools 7.0.0-alpha.1 → 7.0.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 (90) hide show
  1. package/bin.js +6 -6
  2. package/cspell-tools.config.schema.json +12 -0
  3. package/dist/AppOptions.d.ts +4 -1
  4. package/dist/AppOptions.js +1 -2
  5. package/dist/FeatureFlags/FeatureFlags.js +4 -11
  6. package/dist/FeatureFlags/index.d.ts +2 -2
  7. package/dist/FeatureFlags/index.js +2 -9
  8. package/dist/FeatureFlags/parseFlags.d.ts +1 -1
  9. package/dist/FeatureFlags/parseFlags.js +3 -7
  10. package/dist/app.d.ts +1 -1
  11. package/dist/app.js +52 -43
  12. package/dist/build.d.ts +7 -2
  13. package/dist/build.js +18 -41
  14. package/dist/compile.d.ts +3 -2
  15. package/dist/compile.js +34 -17
  16. package/dist/compiler/CompileOptions.js +1 -2
  17. package/dist/compiler/Reader.d.ts +1 -1
  18. package/dist/compiler/Reader.js +8 -12
  19. package/dist/compiler/SourceReader.d.ts +1 -1
  20. package/dist/compiler/SourceReader.js +5 -9
  21. package/dist/compiler/WordsCollection.js +2 -5
  22. package/dist/compiler/compile.d.ts +16 -2
  23. package/dist/compiler/compile.js +92 -66
  24. package/dist/compiler/createCompileRequest.d.ts +3 -3
  25. package/dist/compiler/createCompileRequest.js +36 -38
  26. package/dist/compiler/createWordsCollection.d.ts +2 -2
  27. package/dist/compiler/createWordsCollection.js +12 -21
  28. package/dist/compiler/fileWriter.d.ts +1 -1
  29. package/dist/compiler/fileWriter.js +4 -9
  30. package/dist/compiler/index.d.ts +4 -4
  31. package/dist/compiler/index.js +3 -11
  32. package/dist/compiler/legacyLineToWords.d.ts +1 -1
  33. package/dist/compiler/legacyLineToWords.js +5 -10
  34. package/dist/compiler/logWithTimestamp.d.ts +1 -1
  35. package/dist/compiler/logWithTimestamp.js +1 -5
  36. package/dist/compiler/logger.js +2 -7
  37. package/dist/compiler/readers/ReaderOptions.js +1 -2
  38. package/dist/compiler/readers/readHunspellFiles.d.ts +1 -1
  39. package/dist/compiler/readers/readHunspellFiles.js +10 -37
  40. package/dist/compiler/readers/readTextFile.js +7 -35
  41. package/dist/compiler/readers/textFileReader.d.ts +1 -1
  42. package/dist/compiler/readers/textFileReader.js +3 -7
  43. package/dist/compiler/readers/trieFileReader.d.ts +1 -1
  44. package/dist/compiler/readers/trieFileReader.js +5 -9
  45. package/dist/compiler/splitCamelCaseIfAllowed.d.ts +1 -1
  46. package/dist/compiler/splitCamelCaseIfAllowed.js +7 -34
  47. package/dist/compiler/streamSourceWordsFromFile.d.ts +1 -1
  48. package/dist/compiler/streamSourceWordsFromFile.js +3 -7
  49. package/dist/compiler/text.js +1 -5
  50. package/dist/compiler/wordListCompiler.d.ts +1 -1
  51. package/dist/compiler/wordListCompiler.js +17 -45
  52. package/dist/compiler/wordListParser.d.ts +2 -2
  53. package/dist/compiler/wordListParser.js +19 -25
  54. package/dist/compiler/writeTextToFile.js +7 -35
  55. package/dist/config/config.d.ts +10 -0
  56. package/dist/config/config.js +1 -2
  57. package/dist/config/configUtils.d.ts +1 -1
  58. package/dist/config/configUtils.js +3 -9
  59. package/dist/config/index.d.ts +3 -3
  60. package/dist/config/index.js +2 -9
  61. package/dist/config/normalizeConfig.js +2 -29
  62. package/dist/gzip/compressFiles.d.ts +2 -0
  63. package/dist/gzip/compressFiles.js +14 -0
  64. package/dist/gzip/gzip.d.ts +2 -0
  65. package/dist/gzip/gzip.js +10 -0
  66. package/dist/gzip/index.d.ts +3 -0
  67. package/dist/gzip/index.js +3 -0
  68. package/dist/shasum/checksum.d.ts +8 -0
  69. package/dist/shasum/checksum.js +19 -0
  70. package/dist/shasum/index.d.ts +3 -0
  71. package/dist/shasum/index.js +3 -0
  72. package/dist/shasum/shasum.d.ts +38 -0
  73. package/dist/shasum/shasum.js +148 -0
  74. package/dist/test/TestHelper.d.ts +3 -3
  75. package/dist/test/TestHelper.js +19 -49
  76. package/dist/test/console.d.ts +0 -3
  77. package/dist/test/console.js +14 -13
  78. package/dist/test/escapeRegEx.js +1 -5
  79. package/dist/test/normalizeOutput.js +9 -35
  80. package/dist/util/errors.d.ts +6 -0
  81. package/dist/util/errors.js +11 -0
  82. package/dist/util/globP.d.ts +7 -0
  83. package/dist/util/globP.js +7 -0
  84. package/dist/util/index.d.ts +2 -0
  85. package/dist/util/index.js +4 -0
  86. package/package.json +15 -15
  87. package/dist/compiler/globP.d.ts +0 -2
  88. package/dist/compiler/globP.js +0 -16
  89. package/dist/compiler/inlineSettings.d.ts +0 -7
  90. package/dist/compiler/inlineSettings.js +0 -39
@@ -1,10 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeConfig = exports.isFileSource = exports.isFilePath = exports.isFileListSource = void 0;
4
- var configUtils_1 = require("./configUtils");
5
- Object.defineProperty(exports, "isFileListSource", { enumerable: true, get: function () { return configUtils_1.isFileListSource; } });
6
- Object.defineProperty(exports, "isFilePath", { enumerable: true, get: function () { return configUtils_1.isFilePath; } });
7
- Object.defineProperty(exports, "isFileSource", { enumerable: true, get: function () { return configUtils_1.isFileSource; } });
8
- var normalizeConfig_1 = require("./normalizeConfig");
9
- Object.defineProperty(exports, "normalizeConfig", { enumerable: true, get: function () { return normalizeConfig_1.normalizeConfig; } });
1
+ export { isFileListSource, isFilePath, isFileSource } from './configUtils.js';
2
+ export { normalizeConfig } from './normalizeConfig.js';
10
3
  //# sourceMappingURL=index.js.map
@@ -1,31 +1,5 @@
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.normalizeConfig = void 0;
27
- const path = __importStar(require("path"));
28
- function normalizeConfig(cfg) {
1
+ import * as path from 'path';
2
+ export function normalizeConfig(cfg) {
29
3
  if (!cfg)
30
4
  return cfg;
31
5
  const dir = path.dirname(cfg.filepath);
@@ -36,5 +10,4 @@ function normalizeConfig(cfg) {
36
10
  filepath: cfg.filepath,
37
11
  };
38
12
  }
39
- exports.normalizeConfig = normalizeConfig;
40
13
  //# sourceMappingURL=normalizeConfig.js.map
@@ -0,0 +1,2 @@
1
+ export declare function compressFile(file: string): Promise<string>;
2
+ //# sourceMappingURL=compressFiles.d.ts.map
@@ -0,0 +1,14 @@
1
+ import { readFile, writeFile } from 'node:fs/promises';
2
+ import { promisify } from 'node:util';
3
+ import { gzip as gz } from 'node:zlib';
4
+ const gzip = promisify(gz);
5
+ export async function compressFile(file) {
6
+ if (file.endsWith('.gz'))
7
+ return file;
8
+ const targetFile = file + '.gz';
9
+ const buf = await readFile(file);
10
+ const zBuf = await gzip(buf);
11
+ await writeFile(targetFile, zBuf);
12
+ return targetFile;
13
+ }
14
+ //# sourceMappingURL=compressFiles.js.map
@@ -0,0 +1,2 @@
1
+ export declare function gzip(globs: string[]): Promise<void>;
2
+ //# sourceMappingURL=gzip.d.ts.map
@@ -0,0 +1,10 @@
1
+ import { globP } from '../util/globP.js';
2
+ import { compressFile } from './compressFiles.js';
3
+ // cspell:ignore nodir
4
+ export async function gzip(globs) {
5
+ const files = await globP(globs, { nodir: true });
6
+ for (const fileName of files) {
7
+ await compressFile(fileName);
8
+ }
9
+ }
10
+ //# sourceMappingURL=gzip.js.map
@@ -0,0 +1,3 @@
1
+ export { compressFile } from './compressFiles.js';
2
+ export { gzip } from './gzip.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { compressFile } from './compressFiles.js';
2
+ export { gzip } from './gzip.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ type HashAlgorithm = 'SHA1';
3
+ export declare function calcChecksum(buf: Buffer, alg?: HashAlgorithm): string;
4
+ export declare function checkChecksum(checksum: string, buf: Buffer, alg?: HashAlgorithm): boolean;
5
+ export declare function calcFileChecksum(filename: string, alg?: HashAlgorithm): Promise<string>;
6
+ export declare function checkFile(checksum: string, filename: string, alg?: HashAlgorithm): Promise<boolean>;
7
+ export {};
8
+ //# sourceMappingURL=checksum.d.ts.map
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,3 @@
1
+ export { calcFileChecksum } from './checksum.js';
2
+ export { checkShasumFile, updateChecksumForFiles } from './shasum.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { calcFileChecksum } from './checksum.js';
2
+ export { checkShasumFile, updateChecksumForFiles } from './shasum.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,38 @@
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[];
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
@@ -0,0 +1,148 @@
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 (error) {
13
+ // const err = toError(error);
14
+ return Promise.reject(`shasum: ${filename}: Unable to read file.`);
15
+ }
16
+ }
17
+ /**
18
+ *
19
+ * @param filename - name of checksum file
20
+ * @param files - optional list of files to check
21
+ * @param root - optional root, default cwd.
22
+ */
23
+ export async function checkShasumFile(filename, files, root) {
24
+ files = !files ? files : files.length ? files : undefined;
25
+ const shaFiles = await readAndParseShasumFile(filename);
26
+ const filesToCheck = !files ? shaFiles.map(({ filename }) => filename) : files;
27
+ const mapNameToChecksum = new Map(shaFiles.map((r) => [normalizeFilename(r.filename), r.checksum]));
28
+ const resolvedRoot = resolve(root || '.');
29
+ const results = await Promise.all(filesToCheck.map(normalizeFilename).map((filename) => {
30
+ return tryToCheckFile(filename, resolvedRoot, mapNameToChecksum.get(filename));
31
+ }));
32
+ const passed = !results.find((v) => !v.passed);
33
+ return { passed, results };
34
+ }
35
+ async function tryToCheckFile(filename, root, checksum) {
36
+ if (!checksum) {
37
+ return { filename, passed: false, error: Error('Missing Checksum.') };
38
+ }
39
+ const file = resolve(root, filename);
40
+ try {
41
+ const passed = await checkFile(checksum, file);
42
+ return { filename, passed };
43
+ }
44
+ catch (error) {
45
+ return { filename, passed: false, error: Error('Failed to read file.') };
46
+ }
47
+ }
48
+ const regLine = /([a-f0-9]{40,}) {2}(.*)/;
49
+ export async function readAndParseShasumFile(filename) {
50
+ const content = await readFile(resolve(filename), 'utf8');
51
+ const shaFiles = parseShasumFile(content);
52
+ return shaFiles;
53
+ }
54
+ export function parseShasumFile(content) {
55
+ const lines = content.split(/\r?\n|\r/g);
56
+ return lines.map(parseLine).filter(isDefined);
57
+ function parseLine(line, index) {
58
+ const m = line.match(regLine);
59
+ const lineNumber = index + 1;
60
+ if (!m) {
61
+ if (line.trim()) {
62
+ throw new Error(`Failed to parse line ${lineNumber} of checksum file.`);
63
+ }
64
+ return undefined;
65
+ }
66
+ const checksum = m[1];
67
+ const filename = m[2];
68
+ return { checksum, filename, lineNumber };
69
+ }
70
+ }
71
+ export async function reportChecksumForFiles(files, options) {
72
+ const root = options.root;
73
+ const filesToCheck = await resolveFileList(files, options.listFile);
74
+ let numFailed = 0;
75
+ const result = await Promise.all(filesToCheck.map((file) => shasumFile(file, root).catch((e) => {
76
+ ++numFailed;
77
+ if (typeof e !== 'string')
78
+ throw e;
79
+ return e;
80
+ })));
81
+ const report = result.join('\n');
82
+ const passed = !numFailed;
83
+ return { report, passed };
84
+ }
85
+ export async function reportCheckChecksumFile(filename, files, options) {
86
+ const root = options.root;
87
+ const filesToCheck = await resolveFileList(files, options.listFile);
88
+ const checkResult = await checkShasumFile(filename, filesToCheck, root);
89
+ const results = checkResult.results;
90
+ const lines = results.map(({ filename, passed, error }) => `${filename}: ${passed ? 'OK' : 'FAILED'} ${error ? '- ' + error.message : ''}`.trim());
91
+ const withErrors = results.filter((a) => !a.passed);
92
+ const passed = !withErrors.length;
93
+ if (!passed) {
94
+ lines.push(`shasum: WARNING: ${withErrors.length} computed checksum${withErrors.length > 1 ? 's' : ''} did NOT match`);
95
+ }
96
+ return { report: lines.join('\n'), passed };
97
+ }
98
+ async function resolveFileList(files, listFile) {
99
+ files = files || [];
100
+ listFile = listFile || [];
101
+ const setOfFiles = new Set(files);
102
+ const pending = listFile.map((filename) => readFile(filename, 'utf8'));
103
+ for await (const content of pending) {
104
+ content
105
+ .split('\n')
106
+ .map((a) => a.trim())
107
+ .filter((a) => a)
108
+ .forEach((file) => setOfFiles.add(file));
109
+ }
110
+ return [...setOfFiles].map(normalizeFilename);
111
+ }
112
+ export async function calcUpdateChecksumForFiles(filename, files, options) {
113
+ const root = options.root || '.';
114
+ const filesToCheck = await resolveFileList(files, options.listFile);
115
+ const currentEntries = (await readAndParseShasumFile(filename).catch((err) => {
116
+ const e = toError(err);
117
+ if (e.code !== 'ENOENT')
118
+ throw e;
119
+ return [];
120
+ })).map((entry) => ({ ...entry, filename: normalizeFilename(entry.filename) }));
121
+ const entriesToUpdate = new Set([...filesToCheck, ...currentEntries.map((e) => e.filename)]);
122
+ const mustExist = new Set(filesToCheck);
123
+ const checksumMap = new Map(currentEntries.map(({ filename, checksum }) => [filename, checksum]));
124
+ for (const file of entriesToUpdate) {
125
+ try {
126
+ const checksum = await calcFileChecksum(resolve(root, file));
127
+ checksumMap.set(file, checksum);
128
+ }
129
+ catch (e) {
130
+ if (mustExist.has(file) || toError(e).code !== 'ENOENT')
131
+ throw e;
132
+ checksumMap.delete(file);
133
+ }
134
+ }
135
+ const updatedEntries = [...checksumMap]
136
+ .map(([filename, checksum]) => ({ filename, checksum }))
137
+ .sort((a, b) => (a.filename < b.filename ? -1 : 1));
138
+ return updatedEntries.map((e) => `${e.checksum} ${e.filename}`).join('\n') + '\n';
139
+ }
140
+ export async function updateChecksumForFiles(filename, files, options) {
141
+ const content = await calcUpdateChecksumForFiles(filename, files, options);
142
+ await writeFile(filename, content);
143
+ return { passed: true, report: content };
144
+ }
145
+ function normalizeFilename(filename) {
146
+ return filename.split(pathSep).join('/');
147
+ }
148
+ //# sourceMappingURL=shasum.js.map
@@ -26,8 +26,6 @@ export interface TestHelper {
26
26
  * @param to
27
27
  */
28
28
  cp(from: string, to: string): void;
29
- cd(dir: string): void;
30
- cdToTempDir(...parts: string[]): void;
31
29
  packageTemp(...parts: string[]): string;
32
30
  /**
33
31
  * Signal the start of a test.
@@ -38,6 +36,8 @@ export interface TestHelper {
38
36
  getCurrentTestName(): string;
39
37
  fileExists(path: string): Promise<boolean>;
40
38
  }
41
- export declare function createTestHelper(testFilename?: string): TestHelper;
39
+ export declare function createTestHelper(testFilenameUrl: string): TestHelper;
42
40
  export declare function resolvePathToFixture(...segments: string[]): string;
41
+ export declare function test_dirname(importMetaUrl: string): string;
42
+ export declare function test_filename(importMetaUrl: string): string;
43
43
  //# sourceMappingURL=TestHelper.d.ts.map
@@ -1,39 +1,18 @@
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.resolvePathToFixture = exports.createTestHelper = void 0;
27
- const fs_1 = require("fs");
28
- const path = __importStar(require("path"));
29
- const shell = __importStar(require("shelljs"));
30
- const packageRoot = path.join(__dirname, '../..');
1
+ import assert from 'assert';
2
+ import { promises as fs } from 'fs';
3
+ import * as path from 'path';
4
+ import * as shell from 'shelljs';
5
+ import { fileURLToPath } from 'url';
6
+ import { expect } from 'vitest';
7
+ const _dirname = test_dirname(import.meta.url);
8
+ const packageRoot = path.join(_dirname, '../..');
31
9
  const repoRoot = path.join(packageRoot, '../..');
32
10
  const tempDirBase = path.join(packageRoot, 'temp');
33
- function createTestHelper(testFilename) {
11
+ export function createTestHelper(testFilenameUrl) {
12
+ testFilenameUrl && assert(testFilenameUrl.startsWith('file:'));
13
+ const testFilename = testFilenameUrl && test_filename(testFilenameUrl);
34
14
  return new TestHelperImpl(testFilename || expect.getState().testPath || 'test');
35
15
  }
36
- exports.createTestHelper = createTestHelper;
37
16
  const fixtureDir = path.join(packageRoot, 'fixtures');
38
17
  class TestHelperImpl {
39
18
  constructor(testFilename) {
@@ -89,20 +68,6 @@ class TestHelperImpl {
89
68
  cp(src, dest) {
90
69
  shell.cp(this.resolveTemp(src), this.resolveTemp(dest));
91
70
  }
92
- /**
93
- * Change the current directory
94
- * @param dir
95
- */
96
- cd(dir) {
97
- shell.cd(this.resolveTemp(dir));
98
- }
99
- /**
100
- * Change dir to temp directory unique to the current test.
101
- */
102
- cdToTempDir(...parts) {
103
- this.createTempDir(...parts);
104
- this.cd('.');
105
- }
106
71
  /**
107
72
  * resolve a path to the fixtures.
108
73
  * @param parts
@@ -121,7 +86,7 @@ class TestHelperImpl {
121
86
  }
122
87
  async fileExists(path) {
123
88
  try {
124
- await fs_1.promises.stat(path);
89
+ await fs.stat(path);
125
90
  return true;
126
91
  }
127
92
  catch (e) {
@@ -129,8 +94,13 @@ class TestHelperImpl {
129
94
  }
130
95
  }
131
96
  }
132
- function resolvePathToFixture(...segments) {
97
+ export function resolvePathToFixture(...segments) {
133
98
  return path.resolve(fixtureDir, ...segments);
134
99
  }
135
- exports.resolvePathToFixture = resolvePathToFixture;
100
+ export function test_dirname(importMetaUrl) {
101
+ return path.dirname(test_filename(importMetaUrl));
102
+ }
103
+ export function test_filename(importMetaUrl) {
104
+ return fileURLToPath(importMetaUrl);
105
+ }
136
106
  //# sourceMappingURL=TestHelper.js.map
@@ -1,7 +1,4 @@
1
- /// <reference types="jest" />
2
1
  export declare function spyOnConsole(): {
3
- log: jest.SpyInstance<void, [message?: any, ...optionalParams: any[]], any>;
4
- error: jest.SpyInstance<void, [message?: any, ...optionalParams: any[]], any>;
5
2
  consoleOutput: () => {
6
3
  log: string;
7
4
  error: string;
@@ -1,11 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.spyOnConsole = void 0;
4
- const normalizeOutput_1 = require("./normalizeOutput");
5
- function spyOnConsole() {
1
+ import { vi } from 'vitest';
2
+ import { normalizeOutput } from './normalizeOutput.js';
3
+ export function spyOnConsole() {
6
4
  const con = {
7
- log: jest.spyOn(console, 'log').mockImplementation(),
8
- error: jest.spyOn(console, 'error').mockImplementation(),
5
+ log: vi.spyOn(console, 'log').mockImplementation(() => undefined),
6
+ error: vi.spyOn(console, 'error').mockImplementation(() => undefined),
9
7
  consoleOutput,
10
8
  attach,
11
9
  reset,
@@ -14,20 +12,23 @@ function spyOnConsole() {
14
12
  const _error = con.error.mock.calls.map((c) => c.join(',')).join('\n');
15
13
  const _log = con.log.mock.calls.map((c) => c.join(',')).join('\n');
16
14
  return {
17
- log: (0, normalizeOutput_1.normalizeOutput)(_log),
18
- error: (0, normalizeOutput_1.normalizeOutput)(_error),
15
+ log: normalizeOutput(_log),
16
+ error: normalizeOutput(_error),
19
17
  };
20
18
  }
21
19
  function attach() {
22
20
  reset();
23
- con.log = jest.spyOn(console, 'log').mockImplementation();
24
- con.error = jest.spyOn(console, 'error').mockImplementation();
21
+ con.log = vi.spyOn(console, 'log').mockImplementation(() => undefined);
22
+ con.error = vi.spyOn(console, 'error').mockImplementation(() => undefined);
25
23
  }
26
24
  function reset() {
27
25
  con.log.mockRestore();
28
26
  con.error.mockRestore();
29
27
  }
30
- return con;
28
+ return {
29
+ consoleOutput,
30
+ attach,
31
+ reset,
32
+ };
31
33
  }
32
- exports.spyOnConsole = spyOnConsole;
33
34
  //# sourceMappingURL=console.js.map
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.escapeRegEx = void 0;
4
1
  /**
5
2
  * Escape a string so it can be used as an exact match within a RegExp.
6
3
  * @param s - string to escape
7
4
  * @returns - the escaped string.
8
5
  */
9
- function escapeRegEx(s) {
6
+ export function escapeRegEx(s) {
10
7
  return s.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
11
8
  }
12
- exports.escapeRegEx = escapeRegEx;
13
9
  //# sourceMappingURL=escapeRegEx.js.map
@@ -1,46 +1,20 @@
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.normalizeDirectorySeparator = exports.normalizeOutput = void 0;
27
- const path = __importStar(require("path"));
28
- const escapeRegEx_1 = require("./escapeRegEx");
29
- const rootCspellTools = path.join(__dirname, '../..');
1
+ import * as path from 'path';
2
+ import { escapeRegEx } from './escapeRegEx.js';
3
+ import { test_dirname } from './TestHelper.js';
4
+ const _dirname = test_dirname(import.meta.url);
5
+ const rootCspellTools = path.join(_dirname, '../..');
30
6
  const rootRepo = path.join(rootCspellTools, '../..');
31
7
  /**
32
8
  * Example: `2022-10-02T17:10:04.681Z`
33
9
  */
34
10
  const regexpDate = /\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?Z/gi;
35
- const rxRootRepo = new RegExp((0, escapeRegEx_1.escapeRegEx)(rootRepo) + '|' + (0, escapeRegEx_1.escapeRegEx)(normalizeDirectorySeparator(rootRepo)), 'gi');
36
- function normalizeOutput(output, cwd = process.cwd()) {
37
- const rxCwd = new RegExp((0, escapeRegEx_1.escapeRegEx)(cwd) + '|' + (0, escapeRegEx_1.escapeRegEx)(normalizeDirectorySeparator(cwd)), 'gi');
11
+ const rxRootRepo = new RegExp(escapeRegEx(rootRepo) + '|' + escapeRegEx(normalizeDirectorySeparator(rootRepo)), 'gi');
12
+ export function normalizeOutput(output, cwd = process.cwd()) {
13
+ const rxCwd = new RegExp(escapeRegEx(cwd) + '|' + escapeRegEx(normalizeDirectorySeparator(cwd)), 'gi');
38
14
  const normalizeDirs = normalizeDirectorySeparator(output.replace(rxCwd, '{cwd}').replace(rxRootRepo, '{repo-root}'));
39
15
  return normalizeDirs.replace(regexpDate, '2022-01-01T00:00:00.000Z');
40
16
  }
41
- exports.normalizeOutput = normalizeOutput;
42
- function normalizeDirectorySeparator(path) {
17
+ export function normalizeDirectorySeparator(path) {
43
18
  return path.replace(/\\/g, '/');
44
19
  }
45
- exports.normalizeDirectorySeparator = normalizeDirectorySeparator;
46
20
  //# sourceMappingURL=normalizeOutput.js.map
@@ -0,0 +1,6 @@
1
+ export interface NodeError extends Error {
2
+ code?: string;
3
+ }
4
+ export declare function toError(err: unknown): NodeError;
5
+ export declare function isError(err: unknown): err is Error;
6
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,11 @@
1
+ export function toError(err) {
2
+ if (isError(err))
3
+ return err;
4
+ return new Error(`${err}`);
5
+ }
6
+ export function isError(err) {
7
+ if (err instanceof Error)
8
+ return true;
9
+ return false;
10
+ }
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,7 @@
1
+ interface Options {
2
+ cwd?: string | URL;
3
+ nodir?: boolean;
4
+ }
5
+ export declare function globP(pattern: string | string[], options?: Options): Promise<string[]>;
6
+ export {};
7
+ //# sourceMappingURL=globP.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { glob } from 'glob';
2
+ export function globP(pattern, options) {
3
+ // Convert windows separators.
4
+ const globs = (Array.isArray(pattern) ? pattern : [pattern]).map((pattern) => pattern.replace(/\\/g, '/'));
5
+ return glob(globs, options);
6
+ }
7
+ //# sourceMappingURL=globP.js.map
@@ -0,0 +1,2 @@
1
+ export declare function isDefined<T>(a: T | undefined | null): a is T;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ export function isDefined(a) {
2
+ return !!a || (a !== null && a !== undefined);
3
+ }
4
+ //# sourceMappingURL=index.js.map