Skip to content

Commit cc7aa3d

Browse files
fiskerJason3S
andauthored
fix: Replace get-stdin with native alternative (#7229)
Co-authored-by: Jason Dent <[email protected]>
1 parent 3755749 commit cc7aa3d

File tree

6 files changed

+12
-24
lines changed

6 files changed

+12
-24
lines changed

packages/cspell/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
"cspell-lib": "workspace:*",
9797
"fast-json-stable-stringify": "^2.1.0",
9898
"file-entry-cache": "^9.1.0",
99-
"get-stdin": "^9.0.0",
10099
"semver": "^7.7.1",
101100
"tinyglobby": "^0.2.13"
102101
},

packages/cspell/src/app/application.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as fs from 'node:fs/promises';
22
import * as path from 'node:path';
33
import { resolve as r } from 'node:path';
4+
import streamConsumers from 'node:stream/consumers';
45

56
import type { Issue, RunResult } from '@cspell/cspell-types';
6-
import getStdin from 'get-stdin';
77
import { afterEach, describe, expect, test, vi } from 'vitest';
88

99
import * as App from './application.mjs';
@@ -23,7 +23,7 @@ const sampleOptions = { root: samplesRoot };
2323
const oc = <T>(obj: T) => expect.objectContaining(obj);
2424
const ac = <T>(a: Array<T>) => expect.arrayContaining(a);
2525

26-
vi.mock('get-stdin', () => ({ default: vi.fn() }));
26+
vi.mock('node:stream/consumers', () => ({ default: { text: vi.fn() } }));
2727

2828
const timeout = 10_000;
2929

@@ -126,7 +126,7 @@ describe('Validate the Application', () => {
126126
cspell:ignore badspellingintext
127127
We can ignore values within the text: badspellingintext
128128
`;
129-
vi.mocked(getStdin).mockImplementation((async () => text) as typeof getStdin);
129+
vi.mocked(streamConsumers.text).mockImplementation(async () => text);
130130

131131
const lint = App.lint(files, options, reporter);
132132
const result = await lint;

packages/cspell/src/app/util/fileHelper.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'node:path';
2+
import streamConsumers from 'node:stream/consumers';
23
import { fileURLToPath, pathToFileURL } from 'node:url';
34

4-
import getStdin from 'get-stdin';
55
import { afterEach, describe, expect, test, vi } from 'vitest';
66

77
import { pathPackageRoot } from '../test/test.helper.js';
@@ -20,9 +20,7 @@ import {
2020
const __filename = fileURLToPath(import.meta.url);
2121
const __dirname = path.dirname(__filename);
2222

23-
vi.mock('get-stdin', () => ({
24-
default: vi.fn(),
25-
}));
23+
vi.mock('node:stream/consumers', () => ({ default: { text: vi.fn() } }));
2624

2725
const packageRoot = pathPackageRoot;
2826
const fixtures = path.join(packageRoot, 'fixtures/fileHelper');
@@ -40,8 +38,8 @@ describe('fileHelper', () => {
4038
test('readFileListFile', async () => {
4139
try {
4240
const files = ['a', 'b', 'c'];
43-
const mockGetStdin = vi.mocked(getStdin);
44-
mockGetStdin.mockImplementation((async () => files.join('\n')) as typeof getStdin);
41+
const mockStreamConsumersText = vi.mocked(streamConsumers.text);
42+
mockStreamConsumersText.mockImplementation(async () => files.join('\n'));
4543
const pResult = readFileListFile('stdin');
4644
const r = await pResult;
4745
expect(r).toEqual(files.map((f) => path.resolve(f)));

packages/cspell/src/app/util/fileHelper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { promises as fsp } from 'node:fs';
22
import * as path from 'node:path';
3+
import streamConsumers from 'node:stream/consumers';
34
import { fileURLToPath } from 'node:url';
45

56
import { toFileDirURL, toFilePathOrHref, toFileURL } from '@cspell/url';
@@ -8,7 +9,6 @@ import { readFileText as cioReadFile, toURL } from 'cspell-io';
89
import type { CSpellUserSettings, Document, Issue } from 'cspell-lib';
910
import * as cspell from 'cspell-lib';
1011
import { fileToDocument, isBinaryFile as isUriBinaryFile } from 'cspell-lib';
11-
import getStdin from 'get-stdin';
1212

1313
import { CSpellConfigFile } from '../options.js';
1414
import { asyncAwait, asyncFlatten, asyncMap, asyncPipe, mergeAsyncIterables } from './async.js';
@@ -149,7 +149,9 @@ export function readFileInfo(
149149
handleNotFound = false,
150150
): Promise<ReadFileInfoResult> {
151151
filename = resolveFilename(filename);
152-
const pText = filename.startsWith(STDINProtocol) ? getStdin() : cioReadFile(filename, encoding);
152+
const pText = filename.startsWith(STDINProtocol)
153+
? streamConsumers.text(process.stdin)
154+
: cioReadFile(filename, encoding);
153155
return pText.then(
154156
(text) => ({ text, filename }),
155157
(e) => {

packages/cspell/src/app/util/glob.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Glob } from 'cspell-lib';
55
import type { Options as MicromatchOptions } from 'micromatch';
66
import micromatch from 'micromatch';
77
import { minimatch } from 'minimatch';
8-
import { describe, expect, test, vi } from 'vitest';
8+
import { describe, expect, test } from 'vitest';
99

1010
import { calcGlobs, normalizeGlobsToRoot } from './glob.js';
1111

@@ -19,14 +19,6 @@ interface MinimatchOptions {
1919
preserveMultipleSlashes?: boolean;
2020
}
2121

22-
const getStdinResult = {
23-
value: '',
24-
};
25-
26-
vi.mock('get-stdin', () => {
27-
return vi.fn(() => Promise.resolve(getStdinResult.value));
28-
});
29-
3022
describe('Validate minimatch assumptions', () => {
3123
interface TestCase {
3224
pattern: string;

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)