Skip to content

Commit bd380f9

Browse files
authored
feat(fslib): add FileHandle.readLines (#5121)
1 parent 49a27aa commit bd380f9

File tree

12 files changed

+143
-71
lines changed

12 files changed

+143
-71
lines changed

.pnp.cjs

Lines changed: 67 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
686 KB
Binary file not shown.
-338 KB
Binary file not shown.

.yarn/versions/f12a955a.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
"@yarnpkg/fslib": minor
5+
"@yarnpkg/plugin-pnp": patch
6+
"@yarnpkg/pnp": patch
7+
8+
declined:
9+
- "@yarnpkg/plugin-compat"
10+
- "@yarnpkg/plugin-constraints"
11+
- "@yarnpkg/plugin-dlx"
12+
- "@yarnpkg/plugin-essentials"
13+
- "@yarnpkg/plugin-exec"
14+
- "@yarnpkg/plugin-file"
15+
- "@yarnpkg/plugin-git"
16+
- "@yarnpkg/plugin-github"
17+
- "@yarnpkg/plugin-http"
18+
- "@yarnpkg/plugin-init"
19+
- "@yarnpkg/plugin-interactive-tools"
20+
- "@yarnpkg/plugin-link"
21+
- "@yarnpkg/plugin-nm"
22+
- "@yarnpkg/plugin-npm"
23+
- "@yarnpkg/plugin-npm-cli"
24+
- "@yarnpkg/plugin-pack"
25+
- "@yarnpkg/plugin-patch"
26+
- "@yarnpkg/plugin-pnpm"
27+
- "@yarnpkg/plugin-stage"
28+
- "@yarnpkg/plugin-typescript"
29+
- "@yarnpkg/plugin-version"
30+
- "@yarnpkg/plugin-workspace-tools"
31+
- vscode-zipfs
32+
- "@yarnpkg/builder"
33+
- "@yarnpkg/doctor"
34+
- "@yarnpkg/extensions"
35+
- "@yarnpkg/libzip"
36+
- "@yarnpkg/nm"
37+
- "@yarnpkg/pnpify"
38+
- "@yarnpkg/sdks"
39+
- "@yarnpkg/shell"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ The following changes only affect people writing Yarn plugins:
7979
### Compatibility
8080

8181
- Updates the PnP compatibility layer for TypeScript v4.9.4.
82+
- The patched filesystem now supports `FileHandle.readLines`.
8283

8384
## 3.3.0
8485

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@babel/preset-typescript": "^7.18.6",
1515
"@babel/register": "^7.18.9",
1616
"@types/jest": "^28.1.6",
17-
"@types/node": "^18.7.6",
17+
"@types/node": "^18.11.11",
1818
"@yarnpkg/cli": "workspace:^",
1919
"@yarnpkg/core": "workspace:^",
2020
"@yarnpkg/eslint-config": "workspace:^",

packages/yarnpkg-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@types/diff": "^5.0.0",
4545
"@types/lodash": "^4.14.136",
4646
"@types/micromatch": "^4.0.1",
47-
"@types/node": "^18.7.6",
47+
"@types/node": "^18.11.11",
4848
"@types/tar": "^4.0.4",
4949
"@types/tunnel": "^0.0.0",
5050
"@yarnpkg/cli": "workspace:^",

packages/yarnpkg-fslib/sources/patchFs/FileHandle.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {BigIntStats, ReadStream, StatOptions, Stats, WriteStream, WriteVResult} from 'fs';
2+
import {createInterface} from 'readline';
23

34
import type {CreateReadStreamOptions, CreateWriteStreamOptions, FakeFS} from '../FakeFS';
45
import type {Path} from '../path';
@@ -212,6 +213,13 @@ export class FileHandle<P extends Path> {
212213
}
213214
}
214215

216+
readLines(options?: CreateReadStreamOptions) {
217+
return createInterface({
218+
input: this.createReadStream(options),
219+
crlfDelay: Infinity,
220+
});
221+
}
222+
215223
stat(
216224
opts?: StatOptions & {
217225
bigint?: false | undefined;

packages/yarnpkg-fslib/tests/patchedFs.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,23 @@ describe(`patchedFs`, () => {
553553
});
554554
});
555555

556+
it(`should support FileHandle.readLines`, async () => {
557+
const patchedFs = extendFs(fs, new PosixFS(new NodeFS()));
558+
559+
await xfs.mktempPromise(async dir => {
560+
const filepath = npath.join(npath.fromPortablePath(dir), `foo.txt`);
561+
await patchedFs.promises.writeFile(filepath, `1\n\n2\n`);
562+
563+
const fd = await patchedFs.promises.open(filepath);
564+
565+
const lines: Array<string> = [];
566+
for await (const line of fd.readLines())
567+
lines.push(line);
568+
569+
expect(lines).toStrictEqual([`1`, ``, `2`]);
570+
});
571+
});
572+
556573
ifNotWin32It(`should support FileHandle.chmod`, async () => {
557574
const patchedFs = extendFs(fs, new PosixFS(new NodeFS()));
558575

packages/yarnpkg-pnp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"./package.json": "./package.json"
1111
},
1212
"dependencies": {
13-
"@types/node": "^18.7.6",
13+
"@types/node": "^18.11.11",
1414
"@yarnpkg/fslib": "workspace:^"
1515
},
1616
"devDependencies": {

0 commit comments

Comments
 (0)