Skip to content

Commit bffe378

Browse files
authored
fix: Remove dependency upon fs-extra (#4079)
1 parent 37cb289 commit bffe378

22 files changed

+28
-59
lines changed

packages/cspell-trie-lib/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"dependencies": {
4040
"@cspell/cspell-pipe": "workspace:*",
4141
"@cspell/cspell-types": "workspace:*",
42-
"fs-extra": "^11.1.0",
4342
"gensequence": "^4.0.3"
4443
},
4544
"engines": {
@@ -48,7 +47,6 @@
4847
"devDependencies": {
4948
"@cspell/dict-en_us": "^3.0.0",
5049
"@cspell/dict-es-es": "^2.2.3",
51-
"@types/fs-extra": "^9.0.13",
5250
"@types/node": "^18.11.18",
5351
"jest": "^29.4.1"
5452
}

packages/cspell-trie-lib/src/lib/consolidate.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFile } from 'fs-extra';
1+
import { readFile } from 'fs/promises';
22
import { genSequence } from 'gensequence';
33
import * as path from 'path';
44

packages/cspell-trie-lib/src/lib/find.dutch.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs-extra';
1+
import * as fs from 'fs/promises';
22
import * as zlib from 'zlib';
33

44
import { resolveGlobalDict } from '../test/samples';

packages/cspell-trie-lib/src/lib/io/importExport.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFile } from 'fs-extra';
1+
import { readFile } from 'fs/promises';
22

33
import { resolveSample } from '../../test/samples';
44
import * as Trie from '../index';

packages/cspell-trie-lib/src/lib/io/importExportV1.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFile } from 'fs-extra';
1+
import { readFile } from 'fs/promises';
22

33
import { resolveSample } from '../../test/samples';
44
import { consolidate } from '../consolidate';

packages/cspell-trie-lib/src/lib/io/importExportV2.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFile } from 'fs-extra';
1+
import { readFile } from 'fs/promises';
22

33
import { resolveSample } from '../../test/samples';
44
import * as Trie from '../index';

packages/cspell-trie-lib/src/lib/io/importExportV3.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFile, writeFile } from 'fs-extra';
1+
import { readFile, writeFile } from 'fs/promises';
22
import { genSequence } from 'gensequence';
33

44
import { resolveSample as resolveSamplePath } from '../../test/samples';

packages/cspell-trie-lib/src/lib/io/importExportV4.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFile, writeFile } from 'fs-extra';
1+
import { readFile, writeFile } from 'fs/promises';
22
import { genSequence } from 'gensequence';
33

44
import { resolveSample as resolveSamplePath } from '../../test/samples';

packages/cspell-trie-lib/src/test/reader.test.helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs-extra';
1+
import * as fs from 'fs/promises';
22
import * as path from 'path';
33
import * as zlib from 'zlib';
44

packages/cspell-trie/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@
4242
"dependencies": {
4343
"commander": "^10.0.0",
4444
"cspell-trie-lib": "workspace:*",
45-
"fs-extra": "^11.1.0",
4645
"gensequence": "^4.0.3"
4746
},
4847
"engines": {
4948
"node": ">=14"
5049
},
5150
"devDependencies": {
52-
"@types/fs-extra": "^9.0.13",
5351
"@types/node": "^18.11.18",
5452
"jest": "^29.4.1"
5553
}

packages/cspell-trie/src/app.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type * as commander from 'commander';
22
import * as Trie from 'cspell-trie-lib';
3-
import * as fs from 'fs-extra';
4-
import { mkdirp } from 'fs-extra';
3+
import { createWriteStream as fsCreateWriteStream } from 'fs';
4+
import * as fsp from 'fs/promises';
55
import type { Sequence } from 'gensequence';
66
import { genSequence } from 'gensequence';
77
import * as path from 'path';
@@ -76,15 +76,15 @@ export function run(program: commander.Command, argv: string[]): Promise<command
7676
}
7777

7878
async function fileToLines(filename: string): Promise<Sequence<string>> {
79-
const buffer = await fs.readFile(filename);
79+
const buffer = await fsp.readFile(filename);
8080
const file = (filename.match(/\.gz$/) ? zlib.gunzipSync(buffer) : buffer).toString(UTF8);
8181
return genSequence(file.split(/\r?\n/));
8282
}
8383

8484
function createWriteStream(filename?: string): Promise<NodeJS.WritableStream> {
8585
return !filename
8686
? Promise.resolve(process.stdout)
87-
: mkdirp(path.dirname(filename)).then(() => fs.createWriteStream(filename));
87+
: fsp.mkdir(path.dirname(filename), { recursive: true }).then(() => fsCreateWriteStream(filename));
8888
}
8989

9090
// eslint-disable-next-line @typescript-eslint/no-explicit-any

packages/cspell/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"fast-glob": "^3.2.12",
8484
"fast-json-stable-stringify": "^2.1.0",
8585
"file-entry-cache": "^6.0.1",
86-
"fs-extra": "^11.1.0",
8786
"get-stdin": "^8.0.0",
8887
"imurmurhash": "^0.1.4",
8988
"semver": "^7.3.8",
@@ -97,7 +96,6 @@
9796
"@cspell/cspell-json-reporter": "workspace:*",
9897
"@cspell/cspell-types": "workspace:*",
9998
"@types/file-entry-cache": "^5.0.2",
100-
"@types/fs-extra": "^9.0.13",
10199
"@types/glob": "^8.0.1",
102100
"@types/imurmurhash": "^0.1.1",
103101
"@types/micromatch": "^4.0.2",

packages/cspell/src/application.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Issue, RunResult } from '@cspell/cspell-types';
2-
import * as fs from 'fs-extra';
2+
import * as fs from 'fs/promises';
33
import * as path from 'path';
44
import { resolve as r } from 'path';
55

@@ -221,7 +221,7 @@ describe('Linter File Caching', () => {
221221
`('lint caching with $root $comment', async ({ runs, root }: TestCase) => {
222222
const reporter = new InMemoryReporter();
223223
const cacheLocation = tempLocation('.cspellcache');
224-
await fs.remove(cacheLocation).catch(() => undefined);
224+
await fs.rm(cacheLocation, { recursive: true }).catch(() => undefined);
225225

226226
for (const run of runs) {
227227
const { fileGlobs, options, expected } = run;

packages/cspell/src/util/cache/createCache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CacheSettings, CSpellSettings } from '@cspell/cspell-types';
22
import assert from 'assert';
3-
import { stat } from 'fs-extra';
3+
import { stat } from 'fs/promises';
44
import path from 'path';
55

66
import { isError } from '../errors';

packages/cspell/src/util/cache/fileEntryCache.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
export type { FileDescriptor } from 'file-entry-cache';
66
import type { FileEntryCache as FecFileEntryCache } from 'file-entry-cache';
77
import * as file_entry_cache from 'file-entry-cache';
8-
import * as fs from 'fs-extra';
8+
import { mkdirSync } from 'fs';
99
import * as path from 'path';
1010

1111
export type FileEntryCache = FecFileEntryCache;
1212

1313
export function createFromFile(pathToCache: string, useCheckSum: boolean, useRelative: boolean): FileEntryCache {
1414
const absPathToCache = path.resolve(pathToCache);
1515
const relDir = path.dirname(absPathToCache);
16-
fs.mkdirpSync(relDir);
16+
mkdirSync(relDir, { recursive: true });
1717
const create = wrap(() => file_entry_cache.createFromFile(absPathToCache, useCheckSum));
1818
const feCache = create();
1919
const cacheWrapper: FileEntryCache = {

packages/hunspell-reader/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
},
3838
"homepage": "https://github.com/Jason-Rev/hunspell-reader#readme",
3939
"devDependencies": {
40-
"@types/fs-extra": "^9.0.13",
4140
"@types/jest": "^29.4.0",
4241
"@types/node": "^18.11.18",
4342
"jest": "^29.4.1",
@@ -46,7 +45,6 @@
4645
},
4746
"dependencies": {
4847
"commander": "^10.0.0",
49-
"fs-extra": "^11.1.0",
5048
"gensequence": "^4.0.3",
5149
"iconv-lite": "^0.6.3"
5250
},

packages/hunspell-reader/src/IterableHunspellReader.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs-extra';
1+
import { readdirSync } from 'fs';
22
import { genSequence } from 'gensequence';
33
import * as path from 'path';
44

@@ -131,8 +131,7 @@ describe('HunspellReader read dictionaries', function () {
131131
});
132132

133133
describe('Validated loading all dictionaries in the `dictionaries` directory.', () => {
134-
const dictionaries = fs
135-
.readdirSync(DICTIONARY_LOCATIONS)
134+
const dictionaries = readdirSync(DICTIONARY_LOCATIONS)
136135
.filter((dic) => !!dic.match(/\.aff$/))
137136
.map((base) => path.join(DICTIONARY_LOCATIONS, base));
138137
it('Make sure we found some sample dictionaries', () => {

packages/hunspell-reader/src/IterableHunspellReader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs-extra';
1+
import * as fs from 'fs/promises';
22
import type { Sequence } from 'gensequence';
33
import { genSequence } from 'gensequence';
44
import { decode } from 'iconv-lite';

packages/hunspell-reader/src/aff.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from 'assert';
2-
import * as fs from 'fs-extra';
2+
import { readdirSync } from 'fs';
33
import * as path from 'path';
44

55
import { Aff, affWordToColoredString, asAffWord, compareAff, filterAff, flagsToString } from './aff';
@@ -196,8 +196,7 @@ describe('Test Aff', () => {
196196

197197
describe('Validated loading all dictionaries in the `dictionaries` directory.', () => {
198198
function getDictionaries() {
199-
return fs
200-
.readdirSync(DICTIONARY_LOCATIONS)
199+
return readdirSync(DICTIONARY_LOCATIONS)
201200
.filter((dic) => !!dic.match(/\.aff$/))
202201
.map((base) => path.join(DICTIONARY_LOCATIONS, base));
203202
}

packages/hunspell-reader/src/affReader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from 'assert';
2-
import { readFile } from 'fs-extra';
2+
import { readFile } from 'fs/promises';
33
import { decode } from 'iconv-lite';
44

55
import { Aff } from './aff';

packages/hunspell-reader/src/app.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// cSpell:ignore findup
22
import { program as commander } from 'commander';
3-
import * as fs from 'fs-extra';
3+
import { createWriteStream, openSync, writeSync } from 'fs';
44
import type { Sequence } from 'gensequence';
55
import { genSequence } from 'gensequence';
66

@@ -69,7 +69,7 @@ function appendRules(aff: AffWord): AffWord {
6969
function writeSeqToFile(seq: Sequence<string>, outFile: string | undefined): Promise<void> {
7070
return new Promise((resolve, reject) => {
7171
let resolved = false;
72-
const out = outFile ? fs.createWriteStream(outFile) : process.stdout;
72+
const out = outFile ? createWriteStream(outFile) : process.stdout;
7373
const bufferedSeq = genSequence(batch(seq, 500)).map((batch) => batch.join(''));
7474
const dataStream = iterableToStream(bufferedSeq);
7575
const fileStream = dataStream.pipe(out);
@@ -209,8 +209,8 @@ async function actionPrime(hunspellDicFilename: string, options: Options) {
209209
if (sort) {
210210
log('Sorting...');
211211
const data = words.toArray().sort().join('');
212-
const fd = outputFile ? fs.openSync(outputFile, 'w') : 1;
213-
fs.writeSync(fd, data);
212+
const fd = outputFile ? openSync(outputFile, 'w') : 1;
213+
writeSync(fd, data);
214214
} else {
215215
await writeSeqToFile(words, outputFile);
216216
}

pnpm-lock.yaml

+1-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)