From ba111072b0009718ca2eea9e02061e548781df98 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Tue, 31 Jan 2023 21:11:56 +0100 Subject: [PATCH] fix: Remove dependency upon fs-extra --- packages/cspell-trie-lib/package.json | 2 -- .../src/lib/consolidate.test.ts | 2 +- .../src/lib/find.dutch.test.ts | 2 +- .../src/lib/io/importExport.test.ts | 2 +- .../src/lib/io/importExportV1.test.ts | 2 +- .../src/lib/io/importExportV2.test.ts | 2 +- .../src/lib/io/importExportV3.test.ts | 2 +- .../src/lib/io/importExportV4.test.ts | 2 +- .../src/test/reader.test.helper.ts | 2 +- packages/cspell-trie/package.json | 2 -- packages/cspell-trie/src/app.ts | 8 +++---- packages/cspell/package.json | 2 -- packages/cspell/src/application.test.ts | 4 ++-- packages/cspell/src/util/cache/createCache.ts | 2 +- .../cspell/src/util/cache/fileEntryCache.ts | 4 ++-- packages/hunspell-reader/package.json | 2 -- .../src/IterableHunspellReader.test.ts | 5 ++-- .../src/IterableHunspellReader.ts | 2 +- packages/hunspell-reader/src/aff.test.ts | 5 ++-- packages/hunspell-reader/src/affReader.ts | 2 +- packages/hunspell-reader/src/app.ts | 8 +++---- pnpm-lock.yaml | 23 +------------------ 22 files changed, 28 insertions(+), 59 deletions(-) diff --git a/packages/cspell-trie-lib/package.json b/packages/cspell-trie-lib/package.json index 3388ca368ce..0a2e5c39c40 100644 --- a/packages/cspell-trie-lib/package.json +++ b/packages/cspell-trie-lib/package.json @@ -39,7 +39,6 @@ "dependencies": { "@cspell/cspell-pipe": "workspace:*", "@cspell/cspell-types": "workspace:*", - "fs-extra": "^11.1.0", "gensequence": "^4.0.3" }, "engines": { @@ -48,7 +47,6 @@ "devDependencies": { "@cspell/dict-en_us": "^3.0.0", "@cspell/dict-es-es": "^2.2.3", - "@types/fs-extra": "^9.0.13", "@types/node": "^18.11.18", "jest": "^29.4.1" } diff --git a/packages/cspell-trie-lib/src/lib/consolidate.test.ts b/packages/cspell-trie-lib/src/lib/consolidate.test.ts index b98026c75e5..7ee0950eb77 100644 --- a/packages/cspell-trie-lib/src/lib/consolidate.test.ts +++ b/packages/cspell-trie-lib/src/lib/consolidate.test.ts @@ -1,4 +1,4 @@ -import { readFile } from 'fs-extra'; +import { readFile } from 'fs/promises'; import { genSequence } from 'gensequence'; import * as path from 'path'; diff --git a/packages/cspell-trie-lib/src/lib/find.dutch.test.ts b/packages/cspell-trie-lib/src/lib/find.dutch.test.ts index b91e3f3f34e..2fbc1ab41f2 100644 --- a/packages/cspell-trie-lib/src/lib/find.dutch.test.ts +++ b/packages/cspell-trie-lib/src/lib/find.dutch.test.ts @@ -1,4 +1,4 @@ -import * as fs from 'fs-extra'; +import * as fs from 'fs/promises'; import * as zlib from 'zlib'; import { resolveGlobalDict } from '../test/samples'; diff --git a/packages/cspell-trie-lib/src/lib/io/importExport.test.ts b/packages/cspell-trie-lib/src/lib/io/importExport.test.ts index 4a4ca80d0de..23fce91a1d4 100644 --- a/packages/cspell-trie-lib/src/lib/io/importExport.test.ts +++ b/packages/cspell-trie-lib/src/lib/io/importExport.test.ts @@ -1,4 +1,4 @@ -import { readFile } from 'fs-extra'; +import { readFile } from 'fs/promises'; import { resolveSample } from '../../test/samples'; import * as Trie from '../index'; diff --git a/packages/cspell-trie-lib/src/lib/io/importExportV1.test.ts b/packages/cspell-trie-lib/src/lib/io/importExportV1.test.ts index c3eaf70de84..eb6220a4996 100644 --- a/packages/cspell-trie-lib/src/lib/io/importExportV1.test.ts +++ b/packages/cspell-trie-lib/src/lib/io/importExportV1.test.ts @@ -1,4 +1,4 @@ -import { readFile } from 'fs-extra'; +import { readFile } from 'fs/promises'; import { resolveSample } from '../../test/samples'; import { consolidate } from '../consolidate'; diff --git a/packages/cspell-trie-lib/src/lib/io/importExportV2.test.ts b/packages/cspell-trie-lib/src/lib/io/importExportV2.test.ts index a51149e4c39..4b9965e5243 100644 --- a/packages/cspell-trie-lib/src/lib/io/importExportV2.test.ts +++ b/packages/cspell-trie-lib/src/lib/io/importExportV2.test.ts @@ -1,4 +1,4 @@ -import { readFile } from 'fs-extra'; +import { readFile } from 'fs/promises'; import { resolveSample } from '../../test/samples'; import * as Trie from '../index'; diff --git a/packages/cspell-trie-lib/src/lib/io/importExportV3.test.ts b/packages/cspell-trie-lib/src/lib/io/importExportV3.test.ts index f042289123f..1a5b1bbb2ed 100644 --- a/packages/cspell-trie-lib/src/lib/io/importExportV3.test.ts +++ b/packages/cspell-trie-lib/src/lib/io/importExportV3.test.ts @@ -1,4 +1,4 @@ -import { readFile, writeFile } from 'fs-extra'; +import { readFile, writeFile } from 'fs/promises'; import { genSequence } from 'gensequence'; import { resolveSample as resolveSamplePath } from '../../test/samples'; diff --git a/packages/cspell-trie-lib/src/lib/io/importExportV4.test.ts b/packages/cspell-trie-lib/src/lib/io/importExportV4.test.ts index c9ec7d2370d..0f29681286d 100644 --- a/packages/cspell-trie-lib/src/lib/io/importExportV4.test.ts +++ b/packages/cspell-trie-lib/src/lib/io/importExportV4.test.ts @@ -1,4 +1,4 @@ -import { readFile, writeFile } from 'fs-extra'; +import { readFile, writeFile } from 'fs/promises'; import { genSequence } from 'gensequence'; import { resolveSample as resolveSamplePath } from '../../test/samples'; diff --git a/packages/cspell-trie-lib/src/test/reader.test.helper.ts b/packages/cspell-trie-lib/src/test/reader.test.helper.ts index b019cccd0b4..5f36f356a73 100644 --- a/packages/cspell-trie-lib/src/test/reader.test.helper.ts +++ b/packages/cspell-trie-lib/src/test/reader.test.helper.ts @@ -1,4 +1,4 @@ -import * as fs from 'fs-extra'; +import * as fs from 'fs/promises'; import * as path from 'path'; import * as zlib from 'zlib'; diff --git a/packages/cspell-trie/package.json b/packages/cspell-trie/package.json index 5ceb704688b..70bb9cf5337 100644 --- a/packages/cspell-trie/package.json +++ b/packages/cspell-trie/package.json @@ -42,14 +42,12 @@ "dependencies": { "commander": "^10.0.0", "cspell-trie-lib": "workspace:*", - "fs-extra": "^11.1.0", "gensequence": "^4.0.3" }, "engines": { "node": ">=14" }, "devDependencies": { - "@types/fs-extra": "^9.0.13", "@types/node": "^18.11.18", "jest": "^29.4.1" } diff --git a/packages/cspell-trie/src/app.ts b/packages/cspell-trie/src/app.ts index dadb35cbad5..412d6eff133 100644 --- a/packages/cspell-trie/src/app.ts +++ b/packages/cspell-trie/src/app.ts @@ -1,7 +1,7 @@ import type * as commander from 'commander'; import * as Trie from 'cspell-trie-lib'; -import * as fs from 'fs-extra'; -import { mkdirp } from 'fs-extra'; +import { createWriteStream as fsCreateWriteStream } from 'fs'; +import * as fsp from 'fs/promises'; import type { Sequence } from 'gensequence'; import { genSequence } from 'gensequence'; import * as path from 'path'; @@ -76,7 +76,7 @@ export function run(program: commander.Command, argv: string[]): Promise> { - const buffer = await fs.readFile(filename); + const buffer = await fsp.readFile(filename); const file = (filename.match(/\.gz$/) ? zlib.gunzipSync(buffer) : buffer).toString(UTF8); return genSequence(file.split(/\r?\n/)); } @@ -84,7 +84,7 @@ async function fileToLines(filename: string): Promise> { function createWriteStream(filename?: string): Promise { return !filename ? Promise.resolve(process.stdout) - : mkdirp(path.dirname(filename)).then(() => fs.createWriteStream(filename)); + : fsp.mkdir(path.dirname(filename), { recursive: true }).then(() => fsCreateWriteStream(filename)); } // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/packages/cspell/package.json b/packages/cspell/package.json index 0b44ce52ced..f212e67f1c6 100644 --- a/packages/cspell/package.json +++ b/packages/cspell/package.json @@ -83,7 +83,6 @@ "fast-glob": "^3.2.12", "fast-json-stable-stringify": "^2.1.0", "file-entry-cache": "^6.0.1", - "fs-extra": "^11.1.0", "get-stdin": "^8.0.0", "imurmurhash": "^0.1.4", "semver": "^7.3.8", @@ -97,7 +96,6 @@ "@cspell/cspell-json-reporter": "workspace:*", "@cspell/cspell-types": "workspace:*", "@types/file-entry-cache": "^5.0.2", - "@types/fs-extra": "^9.0.13", "@types/glob": "^8.0.1", "@types/imurmurhash": "^0.1.1", "@types/micromatch": "^4.0.2", diff --git a/packages/cspell/src/application.test.ts b/packages/cspell/src/application.test.ts index 70e4bed0185..e2736fd7d8b 100644 --- a/packages/cspell/src/application.test.ts +++ b/packages/cspell/src/application.test.ts @@ -1,5 +1,5 @@ import type { Issue, RunResult } from '@cspell/cspell-types'; -import * as fs from 'fs-extra'; +import * as fs from 'fs/promises'; import * as path from 'path'; import { resolve as r } from 'path'; @@ -221,7 +221,7 @@ describe('Linter File Caching', () => { `('lint caching with $root $comment', async ({ runs, root }: TestCase) => { const reporter = new InMemoryReporter(); const cacheLocation = tempLocation('.cspellcache'); - await fs.remove(cacheLocation).catch(() => undefined); + await fs.rm(cacheLocation, { recursive: true }).catch(() => undefined); for (const run of runs) { const { fileGlobs, options, expected } = run; diff --git a/packages/cspell/src/util/cache/createCache.ts b/packages/cspell/src/util/cache/createCache.ts index d9f2eb1f05e..f29982948b2 100644 --- a/packages/cspell/src/util/cache/createCache.ts +++ b/packages/cspell/src/util/cache/createCache.ts @@ -1,6 +1,6 @@ import type { CacheSettings, CSpellSettings } from '@cspell/cspell-types'; import assert from 'assert'; -import { stat } from 'fs-extra'; +import { stat } from 'fs/promises'; import path from 'path'; import { isError } from '../errors'; diff --git a/packages/cspell/src/util/cache/fileEntryCache.ts b/packages/cspell/src/util/cache/fileEntryCache.ts index 4294ad45c9a..826be41b0fc 100644 --- a/packages/cspell/src/util/cache/fileEntryCache.ts +++ b/packages/cspell/src/util/cache/fileEntryCache.ts @@ -5,7 +5,7 @@ export type { FileDescriptor } from 'file-entry-cache'; import type { FileEntryCache as FecFileEntryCache } from 'file-entry-cache'; import * as file_entry_cache from 'file-entry-cache'; -import * as fs from 'fs-extra'; +import { mkdirSync } from 'fs'; import * as path from 'path'; export type FileEntryCache = FecFileEntryCache; @@ -13,7 +13,7 @@ export type FileEntryCache = FecFileEntryCache; export function createFromFile(pathToCache: string, useCheckSum: boolean, useRelative: boolean): FileEntryCache { const absPathToCache = path.resolve(pathToCache); const relDir = path.dirname(absPathToCache); - fs.mkdirpSync(relDir); + mkdirSync(relDir, { recursive: true }); const create = wrap(() => file_entry_cache.createFromFile(absPathToCache, useCheckSum)); const feCache = create(); const cacheWrapper: FileEntryCache = { diff --git a/packages/hunspell-reader/package.json b/packages/hunspell-reader/package.json index ac319559799..179f1eccf60 100644 --- a/packages/hunspell-reader/package.json +++ b/packages/hunspell-reader/package.json @@ -37,7 +37,6 @@ }, "homepage": "https://github.com/Jason-Rev/hunspell-reader#readme", "devDependencies": { - "@types/fs-extra": "^9.0.13", "@types/jest": "^29.4.0", "@types/node": "^18.11.18", "jest": "^29.4.1", @@ -46,7 +45,6 @@ }, "dependencies": { "commander": "^10.0.0", - "fs-extra": "^11.1.0", "gensequence": "^4.0.3", "iconv-lite": "^0.6.3" }, diff --git a/packages/hunspell-reader/src/IterableHunspellReader.test.ts b/packages/hunspell-reader/src/IterableHunspellReader.test.ts index 81b7fbd6436..a9a907208e7 100644 --- a/packages/hunspell-reader/src/IterableHunspellReader.test.ts +++ b/packages/hunspell-reader/src/IterableHunspellReader.test.ts @@ -1,4 +1,4 @@ -import * as fs from 'fs-extra'; +import { readdirSync } from 'fs'; import { genSequence } from 'gensequence'; import * as path from 'path'; @@ -131,8 +131,7 @@ describe('HunspellReader read dictionaries', function () { }); describe('Validated loading all dictionaries in the `dictionaries` directory.', () => { - const dictionaries = fs - .readdirSync(DICTIONARY_LOCATIONS) + const dictionaries = readdirSync(DICTIONARY_LOCATIONS) .filter((dic) => !!dic.match(/\.aff$/)) .map((base) => path.join(DICTIONARY_LOCATIONS, base)); it('Make sure we found some sample dictionaries', () => { diff --git a/packages/hunspell-reader/src/IterableHunspellReader.ts b/packages/hunspell-reader/src/IterableHunspellReader.ts index 26a44ae0977..a647249ae0c 100644 --- a/packages/hunspell-reader/src/IterableHunspellReader.ts +++ b/packages/hunspell-reader/src/IterableHunspellReader.ts @@ -1,4 +1,4 @@ -import * as fs from 'fs-extra'; +import * as fs from 'fs/promises'; import type { Sequence } from 'gensequence'; import { genSequence } from 'gensequence'; import { decode } from 'iconv-lite'; diff --git a/packages/hunspell-reader/src/aff.test.ts b/packages/hunspell-reader/src/aff.test.ts index cfed54e5331..4da7ab7d42e 100644 --- a/packages/hunspell-reader/src/aff.test.ts +++ b/packages/hunspell-reader/src/aff.test.ts @@ -1,5 +1,5 @@ import assert from 'assert'; -import * as fs from 'fs-extra'; +import { readdirSync } from 'fs'; import * as path from 'path'; import { Aff, affWordToColoredString, asAffWord, compareAff, filterAff, flagsToString } from './aff'; @@ -196,8 +196,7 @@ describe('Test Aff', () => { describe('Validated loading all dictionaries in the `dictionaries` directory.', () => { function getDictionaries() { - return fs - .readdirSync(DICTIONARY_LOCATIONS) + return readdirSync(DICTIONARY_LOCATIONS) .filter((dic) => !!dic.match(/\.aff$/)) .map((base) => path.join(DICTIONARY_LOCATIONS, base)); } diff --git a/packages/hunspell-reader/src/affReader.ts b/packages/hunspell-reader/src/affReader.ts index 3ae73df2e47..068c13b4185 100644 --- a/packages/hunspell-reader/src/affReader.ts +++ b/packages/hunspell-reader/src/affReader.ts @@ -1,5 +1,5 @@ import assert from 'assert'; -import { readFile } from 'fs-extra'; +import { readFile } from 'fs/promises'; import { decode } from 'iconv-lite'; import { Aff } from './aff'; diff --git a/packages/hunspell-reader/src/app.ts b/packages/hunspell-reader/src/app.ts index a4a4d9c2f03..252bca1e2cf 100644 --- a/packages/hunspell-reader/src/app.ts +++ b/packages/hunspell-reader/src/app.ts @@ -1,6 +1,6 @@ // cSpell:ignore findup import { program as commander } from 'commander'; -import * as fs from 'fs-extra'; +import { createWriteStream, openSync, writeSync } from 'fs'; import type { Sequence } from 'gensequence'; import { genSequence } from 'gensequence'; @@ -69,7 +69,7 @@ function appendRules(aff: AffWord): AffWord { function writeSeqToFile(seq: Sequence, outFile: string | undefined): Promise { return new Promise((resolve, reject) => { let resolved = false; - const out = outFile ? fs.createWriteStream(outFile) : process.stdout; + const out = outFile ? createWriteStream(outFile) : process.stdout; const bufferedSeq = genSequence(batch(seq, 500)).map((batch) => batch.join('')); const dataStream = iterableToStream(bufferedSeq); const fileStream = dataStream.pipe(out); @@ -209,8 +209,8 @@ async function actionPrime(hunspellDicFilename: string, options: Options) { if (sort) { log('Sorting...'); const data = words.toArray().sort().join(''); - const fd = outputFile ? fs.openSync(outputFile, 'w') : 1; - fs.writeSync(fd, data); + const fd = outputFile ? openSync(outputFile, 'w') : 1; + writeSync(fd, data); } else { await writeSeqToFile(words, outputFile); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7724b6f45e2..84586e2cf2a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -135,7 +135,6 @@ importers: '@cspell/cspell-pipe': workspace:* '@cspell/cspell-types': workspace:* '@types/file-entry-cache': ^5.0.2 - '@types/fs-extra': ^9.0.13 '@types/glob': ^8.0.1 '@types/imurmurhash': ^0.1.1 '@types/micromatch': ^4.0.2 @@ -148,7 +147,6 @@ importers: fast-glob: ^3.2.12 fast-json-stable-stringify: ^2.1.0 file-entry-cache: ^6.0.1 - fs-extra: ^11.1.0 get-stdin: ^8.0.0 imurmurhash: ^0.1.4 jest: ^29.4.1 @@ -169,7 +167,6 @@ importers: fast-glob: 3.2.12 fast-json-stable-stringify: 2.1.0 file-entry-cache: 6.0.1 - fs-extra: 11.1.0 get-stdin: 8.0.0 imurmurhash: 0.1.4 semver: 7.3.8 @@ -179,7 +176,6 @@ importers: '@cspell/cspell-json-reporter': link:../cspell-json-reporter '@cspell/cspell-types': link:../cspell-types '@types/file-entry-cache': 5.0.2 - '@types/fs-extra': 9.0.13 '@types/glob': 8.0.1 '@types/imurmurhash': 0.1.1 '@types/micromatch': 4.0.2 @@ -614,20 +610,16 @@ importers: packages/cspell-trie: specifiers: - '@types/fs-extra': ^9.0.13 '@types/node': ^18.11.18 commander: ^10.0.0 cspell-trie-lib: workspace:* - fs-extra: ^11.1.0 gensequence: ^4.0.3 jest: ^29.4.1 dependencies: commander: 10.0.0 cspell-trie-lib: link:../cspell-trie-lib - fs-extra: 11.1.0 gensequence: 4.0.3 devDependencies: - '@types/fs-extra': 9.0.13 '@types/node': 18.11.18 jest: 29.4.1_@types+node@18.11.18 @@ -637,20 +629,16 @@ importers: '@cspell/cspell-types': workspace:* '@cspell/dict-en_us': ^3.0.0 '@cspell/dict-es-es': ^2.2.3 - '@types/fs-extra': ^9.0.13 '@types/node': ^18.11.18 - fs-extra: ^11.1.0 gensequence: ^4.0.3 jest: ^29.4.1 dependencies: '@cspell/cspell-pipe': link:../cspell-pipe '@cspell/cspell-types': link:../cspell-types - fs-extra: 11.1.0 gensequence: 4.0.3 devDependencies: '@cspell/dict-en_us': 3.0.0 '@cspell/dict-es-es': 2.2.3 - '@types/fs-extra': 9.0.13 '@types/node': 18.11.18 jest: 29.4.1_@types+node@18.11.18 @@ -670,11 +658,9 @@ importers: packages/hunspell-reader: specifiers: - '@types/fs-extra': ^9.0.13 '@types/jest': ^29.4.0 '@types/node': ^18.11.18 commander: ^10.0.0 - fs-extra: ^11.1.0 gensequence: ^4.0.3 iconv-lite: ^0.6.3 jest: ^29.4.1 @@ -682,11 +668,9 @@ importers: typescript: ^4.9.4 dependencies: commander: 10.0.0 - fs-extra: 11.1.0 gensequence: 4.0.3 iconv-lite: 0.6.3 devDependencies: - '@types/fs-extra': 9.0.13 '@types/jest': 29.4.0 '@types/node': 18.11.18 jest: 29.4.1_@types+node@18.11.18 @@ -5175,12 +5159,6 @@ packages: '@types/node': 18.11.18 dev: true - /@types/fs-extra/9.0.13: - resolution: {integrity: sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==} - dependencies: - '@types/node': 18.11.18 - dev: true - /@types/glob/8.0.1: resolution: {integrity: sha512-8bVUjXZvJacUFkJXHdyZ9iH1Eaj5V7I8c4NdH5sQJsdXkqT4CA5Dhb4yb4VE/3asyx4L9ayZr1NIhTsWHczmMw==} dependencies: @@ -9032,6 +9010,7 @@ packages: graceful-fs: 4.2.10 jsonfile: 6.1.0 universalify: 2.0.0 + dev: true /fs-extra/9.1.0: resolution: {integrity: sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==}