Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove dependency upon fs-extra #4079

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/cspell-trie-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"dependencies": {
"@cspell/cspell-pipe": "workspace:*",
"@cspell/cspell-types": "workspace:*",
"fs-extra": "^11.1.0",
"gensequence": "^4.0.3"
},
"engines": {
Expand All @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-trie-lib/src/lib/consolidate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from 'fs-extra';
import { readFile } from 'fs/promises';
import { genSequence } from 'gensequence';
import * as path from 'path';

Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-trie-lib/src/lib/find.dutch.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-trie-lib/src/lib/io/importExport.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from 'fs-extra';
import { readFile } from 'fs/promises';

import { resolveSample } from '../../test/samples';
import * as Trie from '../index';
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-trie-lib/src/lib/io/importExportV1.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from 'fs-extra';
import { readFile } from 'fs/promises';

import { resolveSample } from '../../test/samples';
import { consolidate } from '../consolidate';
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-trie-lib/src/lib/io/importExportV2.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from 'fs-extra';
import { readFile } from 'fs/promises';

import { resolveSample } from '../../test/samples';
import * as Trie from '../index';
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-trie-lib/src/lib/io/importExportV3.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-trie-lib/src/lib/io/importExportV4.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-trie-lib/src/test/reader.test.helper.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 0 additions & 2 deletions packages/cspell-trie/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
8 changes: 4 additions & 4 deletions packages/cspell-trie/src/app.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -76,15 +76,15 @@ export function run(program: commander.Command, argv: string[]): Promise<command
}

async function fileToLines(filename: string): Promise<Sequence<string>> {
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/));
}

function createWriteStream(filename?: string): Promise<NodeJS.WritableStream> {
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
Expand Down
2 changes: 0 additions & 2 deletions packages/cspell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell/src/application.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell/src/util/cache/createCache.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell/src/util/cache/fileEntryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
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;

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 = {
Expand Down
2 changes: 0 additions & 2 deletions packages/hunspell-reader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -46,7 +45,6 @@
},
"dependencies": {
"commander": "^10.0.0",
"fs-extra": "^11.1.0",
"gensequence": "^4.0.3",
"iconv-lite": "^0.6.3"
},
Expand Down
5 changes: 2 additions & 3 deletions packages/hunspell-reader/src/IterableHunspellReader.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from 'fs-extra';
import { readdirSync } from 'fs';
import { genSequence } from 'gensequence';
import * as path from 'path';

Expand Down Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/hunspell-reader/src/IterableHunspellReader.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
5 changes: 2 additions & 3 deletions packages/hunspell-reader/src/aff.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hunspell-reader/src/affReader.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
8 changes: 4 additions & 4 deletions packages/hunspell-reader/src/app.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -69,7 +69,7 @@ function appendRules(aff: AffWord): AffWord {
function writeSeqToFile(seq: Sequence<string>, outFile: string | undefined): Promise<void> {
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);
Expand Down Expand Up @@ -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);
}
Expand Down
23 changes: 1 addition & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.