@cspell/cspell-tools 7.3.1 → 7.3.3

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.
@@ -1,4 +1,3 @@
1
1
  import type { Reader, ReaderOptions } from './readers/ReaderOptions.js';
2
- export declare const regHunspellFile: RegExp;
3
2
  export declare function createReader(filename: string, options: ReaderOptions): Promise<Reader>;
4
3
  //# sourceMappingURL=Reader.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { readHunspellFiles } from './readers/readHunspellFiles.js';
2
+ import { regHunspellFile } from './readers/regHunspellFile.js';
2
3
  import { textFileReader } from './readers/textFileReader.js';
3
4
  import { trieFileReader } from './readers/trieFileReader.js';
4
- export const regHunspellFile = /\.(dic|aff)$/i;
5
5
  // Readers first match wins
6
6
  const readers = [
7
7
  { test: /\.trie\b/, method: trieFileReader },
@@ -1,7 +1,7 @@
1
1
  import { pipe } from '@cspell/cspell-pipe/sync';
2
2
  import { COMPOUND_FIX, FORBID_PREFIX } from 'cspell-trie-lib';
3
3
  import * as HR from 'hunspell-reader';
4
- import { regHunspellFile } from '../Reader.js';
4
+ import { regHunspellFile } from './regHunspellFile.js';
5
5
  const DEDUPE_SIZE = 1000;
6
6
  export async function readHunspellFiles(filename, options) {
7
7
  const dicFile = filename.replace(regHunspellFile, '.dic');
@@ -1,17 +1,19 @@
1
+ import assert from 'assert';
1
2
  import { promises as fs } from 'fs';
2
- import { promisify } from 'util';
3
- import * as zlib from 'zlib';
4
- const gunzip = promisify(zlib.gunzip);
3
+ import { decompress } from '../../gzip/index.js';
5
4
  const isGzFile = /\.gz$/;
6
5
  export function readTextFile(filename) {
7
6
  const content = fs
8
7
  .readFile(filename)
9
- .then((buffer) => (isGzFile.test(filename) ? gunzip(buffer) : buffer))
10
- .then((buffer) => buffer.toString('utf8'));
8
+ .then(async (buffer) => (isGzFile.test(filename) ? decompress(buffer) : buffer))
9
+ .then((buffer) => (assertIsBuffer(buffer), buffer.toString('utf8')));
11
10
  return content;
12
11
  }
13
12
  export async function readTextFileLines(filename) {
14
13
  const content = await readTextFile(filename);
15
14
  return content.split('\n');
16
15
  }
16
+ function assertIsBuffer(value) {
17
+ assert(Buffer.isBuffer(value));
18
+ }
17
19
  //# sourceMappingURL=readTextFile.js.map
@@ -0,0 +1,2 @@
1
+ export declare const regHunspellFile: RegExp;
2
+ //# sourceMappingURL=regHunspellFile.d.ts.map
@@ -0,0 +1,2 @@
1
+ export const regHunspellFile = /\.(dic|aff)$/i;
2
+ //# sourceMappingURL=regHunspellFile.js.map
@@ -106,7 +106,8 @@ export function createParseFileLineMapper(options) {
106
106
  function splitLine(line) {
107
107
  line = line.replace(/#.*/, ''); // remove comment
108
108
  line = line.trim();
109
- line = line.replace(/\bU\+[0-9A-F]+\b/gi, '|'); // Remove Unicode Definitions
109
+ line = line.replace(/\bU\+[0-9A-F]{4}\b/gi, '|'); // Remove Unicode Definitions
110
+ line = line.replace(/\\U[0-9A-F]{4}/gi, '|'); // Remove Unicode Definitions
110
111
  line = line.replace(regNonWordOrDigit, '|');
111
112
  line = line.replace(/'(?=\|)/g, ''); // remove trailing '
112
113
  line = line.replace(/'$/, ''); // remove trailing '
@@ -121,8 +122,7 @@ export function createParseFileLineMapper(options) {
121
122
  .map((a) => a.trim())
122
123
  .filter((a) => !!a)
123
124
  .filter((a) => !a.match(/^[0-9_-]+$/)) // pure numbers and symbols
124
- .filter((a) => !a.match(/^[ux][0-9A-F]*$/i)) // hex digits
125
- .filter((a) => !a.match(/^0[xo][0-9A-F]*$/i)); // c-style hex/octal digits
125
+ .filter((a) => !a.match(/^0[xo][0-9A-F]+$/i)); // c-style hex/octal digits
126
126
  return lines;
127
127
  }
128
128
  function* splitWords(lines) {
@@ -1,12 +1,10 @@
1
1
  import { promises as fs } from 'fs';
2
- import { promisify } from 'util';
3
- import * as zlib from 'zlib';
4
- const gzip = promisify(zlib.gzip);
2
+ import { compress } from '../gzip/index.js';
5
3
  const isGzFile = /\.gz$/;
6
4
  export async function writeTextToFile(filename, data) {
7
5
  const useGz = isGzFile.test(filename);
8
6
  const buf = Buffer.from(data, 'utf-8');
9
- const buffer = useGz ? await gzip(buf) : buf;
7
+ const buffer = useGz ? await compress(buf) : buf;
10
8
  await fs.writeFile(filename, buffer);
11
9
  }
12
10
  export function writeTextLinesToFile(filename, lines) {
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  export declare enum OSFlags {
3
+ auto = -1,
3
4
  FAT = 0,
4
5
  Unix = 3,
5
6
  HPFS = 6,
@@ -8,6 +9,7 @@ export declare enum OSFlags {
8
9
  }
9
10
  export declare function compressFile(file: string, os?: OSFlags): Promise<string>;
10
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;
11
13
  export declare function decompress(buf: Uint8Array | Buffer, encoding?: undefined): Promise<Uint8Array>;
12
14
  export declare function decompress(buf: Uint8Array | Buffer, encoding: 'utf8'): Promise<string>;
13
15
  export declare function decompress(buf: Uint8Array | Buffer, encoding: 'utf8' | undefined): Promise<string | Uint8Array>;
@@ -1,10 +1,11 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
2
  import { promisify } from 'node:util';
3
- import { gunzip as gunzipCB, gzip as gz } from 'node:zlib';
3
+ import { gunzip as gunzipCB, gzip as gz, gzipSync } from 'node:zlib';
4
4
  const gzip = promisify(gz);
5
5
  const gunzip = promisify(gunzipCB);
6
6
  export var OSFlags;
7
7
  (function (OSFlags) {
8
+ OSFlags[OSFlags["auto"] = -1] = "auto";
8
9
  OSFlags[OSFlags["FAT"] = 0] = "FAT";
9
10
  OSFlags[OSFlags["Unix"] = 3] = "Unix";
10
11
  OSFlags[OSFlags["HPFS"] = 6] = "HPFS";
@@ -22,8 +23,13 @@ export async function compressFile(file, os) {
22
23
  return targetFile;
23
24
  }
24
25
  export async function compress(buf, os) {
25
- const zBuf = await gzip(buf);
26
- const osFlag = os ?? zBuf[OSSystemIDOffset];
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;
27
33
  zBuf[OSSystemIDOffset] = osFlag;
28
34
  return zBuf;
29
35
  }
@@ -1,3 +1,3 @@
1
- export { compressFile, OSFlags } from './compressFiles.js';
1
+ export { compress, compressFile, decompress, OSFlags } from './compressFiles.js';
2
2
  export { gzip } from './gzip.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
- export { compressFile, OSFlags } from './compressFiles.js';
1
+ export { compress, compressFile, decompress, OSFlags } from './compressFiles.js';
2
2
  export { gzip } from './gzip.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -29,12 +29,11 @@ export interface TestHelper {
29
29
  */
30
30
  mkdir(...parts: string[]): void;
31
31
  /**
32
- * copy files
33
- * same as shell.cp
32
+ * copy file
34
33
  * @param from
35
34
  * @param to
36
35
  */
37
- cp(from: string, to: string): void;
36
+ cpFileSync(from: string, to: string): void;
38
37
  packageTemp(...parts: string[]): string;
39
38
  /**
40
39
  * Signal the start of a test.
@@ -1,7 +1,6 @@
1
1
  import assert from 'assert';
2
- import { promises as fs } from 'fs';
2
+ import { mkdirSync, promises as fs, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
3
3
  import * as path from 'path';
4
- import * as shell from 'shelljs';
5
4
  import { fileURLToPath } from 'url';
6
5
  import { expect } from 'vitest';
7
6
  const _dirname = test_dirname(import.meta.url);
@@ -41,7 +40,7 @@ class TestHelperImpl {
41
40
  * delete the contents of the temp directory for the current test.
42
41
  */
43
42
  clearTempDir() {
44
- shell.rm('-rf', this.resolveTemp());
43
+ rmSync(this.resolveTemp(), { force: true, recursive: true });
45
44
  }
46
45
  /**
47
46
  * resolve a path relative to the
@@ -59,15 +58,17 @@ class TestHelperImpl {
59
58
  */
60
59
  mkdir(...parts) {
61
60
  const pTemp = this.resolveTemp(...parts);
62
- shell.mkdir('-p', pTemp);
61
+ mkdirSync(pTemp, { recursive: true });
63
62
  }
64
63
  /**
65
64
  * Copy files from src to dest
66
65
  * @param src - glob
67
66
  * @param dest - directory or file
68
67
  */
69
- cp(src, dest) {
70
- shell.cp(this.resolveTemp(src), this.resolveTemp(dest));
68
+ cpFileSync(src, dest) {
69
+ const srcT = this.resolveTemp(src);
70
+ const dstT = this.resolveTemp(dest);
71
+ cpFileSync(srcT, dstT);
71
72
  }
72
73
  /**
73
74
  * resolve a path to the fixtures.
@@ -102,9 +103,17 @@ export function resolvePathToFixture(...segments) {
102
103
  return path.resolve(fixtureDir, ...segments);
103
104
  }
104
105
  export function test_dirname(importMetaUrl) {
105
- return path.dirname(test_filename(importMetaUrl));
106
+ return fileURLToPath(new URL('.', importMetaUrl));
106
107
  }
107
108
  export function test_filename(importMetaUrl) {
108
109
  return fileURLToPath(importMetaUrl);
109
110
  }
111
+ function cpFileSync(srcFile, dst) {
112
+ const statDst = statSync(dst, { throwIfNoEntry: false });
113
+ if (statDst && statDst.isDirectory()) {
114
+ dst = path.join(dst, path.basename(srcFile));
115
+ }
116
+ const buf = readFileSync(srcFile);
117
+ writeFileSync(dst, buf);
118
+ }
110
119
  //# sourceMappingURL=TestHelper.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cspell/cspell-tools",
3
- "version": "7.3.1",
3
+ "version": "7.3.3",
4
4
  "description": "Tools to assist with the development of cSpell",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -48,13 +48,13 @@
48
48
  },
49
49
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
50
50
  "dependencies": {
51
- "@cspell/cspell-pipe": "7.3.1",
51
+ "@cspell/cspell-pipe": "7.3.3",
52
52
  "commander": "^11.0.0",
53
53
  "cosmiconfig": "8.0.0",
54
- "cspell-trie-lib": "7.3.1",
54
+ "cspell-trie-lib": "7.3.3",
55
55
  "gensequence": "^5.0.2",
56
56
  "glob": "^10.3.4",
57
- "hunspell-reader": "7.3.1",
57
+ "hunspell-reader": "7.3.3",
58
58
  "yaml": "^2.3.2"
59
59
  },
60
60
  "engines": {
@@ -64,9 +64,8 @@
64
64
  "@types/glob": "^8.1.0",
65
65
  "@types/shelljs": "^0.8.12",
66
66
  "lorem-ipsum": "^2.0.8",
67
- "shelljs": "^0.8.5",
68
67
  "ts-json-schema-generator": "^1.3.0"
69
68
  },
70
69
  "module": "bin.mjs",
71
- "gitHead": "999b382d928e8288ebb8be5b056d04116213f4ee"
70
+ "gitHead": "da65ffafaa6a039cedc52d9e029c53ddd273a1fb"
72
71
  }