Skip to content

Commit

Permalink
feat(fslib): add FileHandle.readLines (#5121)
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Dec 12, 2022
1 parent 49a27aa commit bd380f9
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 71 deletions.
127 changes: 67 additions & 60 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
39 changes: 39 additions & 0 deletions .yarn/versions/f12a955a.yml
@@ -0,0 +1,39 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch
"@yarnpkg/fslib": minor
"@yarnpkg/plugin-pnp": patch
"@yarnpkg/pnp": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/libzip"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
- "@yarnpkg/shell"
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -79,6 +79,7 @@ The following changes only affect people writing Yarn plugins:
### Compatibility

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

## 3.3.0

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -14,7 +14,7 @@
"@babel/preset-typescript": "^7.18.6",
"@babel/register": "^7.18.9",
"@types/jest": "^28.1.6",
"@types/node": "^18.7.6",
"@types/node": "^18.11.11",
"@yarnpkg/cli": "workspace:^",
"@yarnpkg/core": "workspace:^",
"@yarnpkg/eslint-config": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-core/package.json
Expand Up @@ -44,7 +44,7 @@
"@types/diff": "^5.0.0",
"@types/lodash": "^4.14.136",
"@types/micromatch": "^4.0.1",
"@types/node": "^18.7.6",
"@types/node": "^18.11.11",
"@types/tar": "^4.0.4",
"@types/tunnel": "^0.0.0",
"@yarnpkg/cli": "workspace:^",
Expand Down
8 changes: 8 additions & 0 deletions packages/yarnpkg-fslib/sources/patchFs/FileHandle.ts
@@ -1,4 +1,5 @@
import type {BigIntStats, ReadStream, StatOptions, Stats, WriteStream, WriteVResult} from 'fs';
import {createInterface} from 'readline';

import type {CreateReadStreamOptions, CreateWriteStreamOptions, FakeFS} from '../FakeFS';
import type {Path} from '../path';
Expand Down Expand Up @@ -212,6 +213,13 @@ export class FileHandle<P extends Path> {
}
}

readLines(options?: CreateReadStreamOptions) {
return createInterface({
input: this.createReadStream(options),
crlfDelay: Infinity,
});
}

stat(
opts?: StatOptions & {
bigint?: false | undefined;
Expand Down
17 changes: 17 additions & 0 deletions packages/yarnpkg-fslib/tests/patchedFs.test.ts
Expand Up @@ -553,6 +553,23 @@ describe(`patchedFs`, () => {
});
});

it(`should support FileHandle.readLines`, async () => {
const patchedFs = extendFs(fs, new PosixFS(new NodeFS()));

await xfs.mktempPromise(async dir => {
const filepath = npath.join(npath.fromPortablePath(dir), `foo.txt`);
await patchedFs.promises.writeFile(filepath, `1\n\n2\n`);

const fd = await patchedFs.promises.open(filepath);

const lines: Array<string> = [];
for await (const line of fd.readLines())
lines.push(line);

expect(lines).toStrictEqual([`1`, ``, `2`]);
});
});

ifNotWin32It(`should support FileHandle.chmod`, async () => {
const patchedFs = extendFs(fs, new PosixFS(new NodeFS()));

Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/package.json
Expand Up @@ -10,7 +10,7 @@
"./package.json": "./package.json"
},
"dependencies": {
"@types/node": "^18.7.6",
"@types/node": "^18.11.11",
"@yarnpkg/fslib": "workspace:^"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions yarn.lock
Expand Up @@ -5917,10 +5917,10 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:*, @types/node@npm:^18.7.6":
version: 18.7.6
resolution: "@types/node@npm:18.7.6"
checksum: 5a8817b093c8a6dfb2b7c4be1efdde2c58ca262417de1fe8cc8a62fe294a33293417796281d98f3a3a36051aca8f9ab309811bf8121bbeb9086360d689d02a55
"@types/node@npm:*, @types/node@npm:^18.11.11":
version: 18.11.11
resolution: "@types/node@npm:18.11.11"
checksum: 7ff6dfb616544cf046b95a988435b2eddf31ea839864454fedb9b0512bbe0b9abbf7f61c3e9d3c6160b626ec8d15cf6b2255a242827ba8e599c5525952b696a5
languageName: node
linkType: hard

Expand Down Expand Up @@ -7081,7 +7081,7 @@ __metadata:
"@types/diff": "npm:^5.0.0"
"@types/lodash": "npm:^4.14.136"
"@types/micromatch": "npm:^4.0.1"
"@types/node": "npm:^18.7.6"
"@types/node": "npm:^18.11.11"
"@types/semver": "npm:^7.1.0"
"@types/tar": "npm:^4.0.4"
"@types/treeify": "npm:^1.0.0"
Expand Down Expand Up @@ -7365,7 +7365,7 @@ __metadata:
"@babel/preset-typescript": "npm:^7.18.6"
"@babel/register": "npm:^7.18.9"
"@types/jest": "npm:^28.1.6"
"@types/node": "npm:^18.7.6"
"@types/node": "npm:^18.11.11"
"@yarnpkg/cli": "workspace:^"
"@yarnpkg/core": "workspace:^"
"@yarnpkg/eslint-config": "workspace:^"
Expand Down Expand Up @@ -7862,7 +7862,7 @@ __metadata:
dependencies:
"@rollup/plugin-commonjs": "npm:^21.0.1"
"@rollup/plugin-node-resolve": "npm:^11.0.1"
"@types/node": "npm:^18.7.6"
"@types/node": "npm:^18.11.11"
"@yarnpkg/fslib": "workspace:^"
"@yarnpkg/libzip": "workspace:^"
esbuild: "npm:esbuild-wasm@^0.15.15"
Expand Down

0 comments on commit bd380f9

Please sign in to comment.