Skip to content
Open
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
467 changes: 241 additions & 226 deletions .pnp.cjs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .pnp.loader.mjs

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

39 changes: 39 additions & 0 deletions .yarn/versions/5d7f533f.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/fslib": minor
"@yarnpkg/libzip": minor
"@yarnpkg/pnp": patch

declined:
- "@yarnpkg/plugin-catalog"
- "@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-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-jsr"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
- "@yarnpkg/shell"
3 changes: 3 additions & 0 deletions packages/yarnpkg-fslib/sources/FakeFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import {EOL} from 'os';

import {copyPromise, LinkStrategy} from './algorithms/copyPromise';
import {FileHandle, Handle} from './patchFs/FileHandle';

Check warning on line 9 in packages/yarnpkg-fslib/sources/FakeFS.ts

View workflow job for this annotation

GitHub Actions / Testing chores

'FileHandle' is defined but never used
import {FSPath, Path, PortablePath, PathUtils, Filename} from './path';
import {convertPath, ppath} from './path';

Expand Down Expand Up @@ -161,6 +162,8 @@
abstract opendirPromise(p: P, opts?: OpendirOptions): Promise<Dir<P>>;
abstract opendirSync(p: P, opts?: OpendirOptions): Dir<P>;

abstract openHandle(p: P, flags: string, mode?: number): Promise<Handle>;

abstract openPromise(p: P, flags: string, mode?: number): Promise<number>;
abstract openSync(p: P, flags: string, mode?: number): number;

Expand Down
9 changes: 9 additions & 0 deletions packages/yarnpkg-fslib/sources/MountFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {CreateReadStreamOptions, CreateWriteStreamOptions, BasePortableFakeFS, E
import {NodeFS} from './NodeFS';
import {watchFile, unwatchFile, unwatchAllFiles} from './algorithms/watchFile';
import * as errors from './errors';
import {FileHandle, Handle} from './patchFs/FileHandle';
import {Filename, FSPath, npath, PortablePath} from './path';

// Only file descriptors prefixed by those values will be forwarded to the MountFS
Expand Down Expand Up @@ -140,6 +141,14 @@ export class MountFS<MountedFS extends MountableFS> extends BasePortableFakeFS {
return remappedFd;
}

async openHandle(p: PortablePath, flags: string, mode?: number): Promise<Handle> {
return await this.makeCallPromise(p, async () => {
return await this.baseFs.openHandle(p, flags, mode);
}, async (mountFs, {subPath}) => {
return new FileHandle(this.remapFd(mountFs, await mountFs.openPromise(subPath, flags, mode)), this);
});
}

async openPromise(p: PortablePath, flags: string, mode?: number) {
return await this.makeCallPromise(p, async () => {
return await this.baseFs.openPromise(p, flags, mode);
Expand Down
5 changes: 5 additions & 0 deletions packages/yarnpkg-fslib/sources/NodeFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {CreateReadStreamOptions, CreateWriteStreamOptions, Dir, StatWatcher, Wat
import {Dirent, SymlinkType, StatSyncOptions, StatOptions} from './FakeFS';
import {BasePortableFakeFS, WriteFileOptions} from './FakeFS';
import {MkdirOptions, RmdirOptions, RmOptions, WatchOptions, WatchCallback, Watcher} from './FakeFS';
import {Handle} from './patchFs/FileHandle';
import {FSPath, PortablePath, Filename, ppath, npath, NativePath} from './path';

function direntToPortable(dirent: Dirent<NativePath>): Dirent<PortablePath> {
Expand Down Expand Up @@ -37,6 +38,10 @@ export class NodeFS extends BasePortableFakeFS {
return ppath.resolve(p);
}

async openHandle(p: PortablePath, flags: string, mode?: number): Promise<Handle> {
return await this.realFs.promises.open(npath.fromPortablePath(p), flags, mode);
}

async openPromise(p: PortablePath, flags: string, mode?: number) {
return await new Promise<number>((resolve, reject) => {
this.realFs.open(npath.fromPortablePath(p), flags, mode, this.makeCallback(resolve, reject));
Expand Down
5 changes: 5 additions & 0 deletions packages/yarnpkg-fslib/sources/ProxiedFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Stats, BigIntStats}
import {CreateReadStreamOptions, CreateWriteStreamOptions, FakeFS, ExtractHintOptions, WatchFileCallback, WatchFileOptions, StatWatcher, Dir, OpendirOptions, ReaddirOptions, DirentNoPath} from './FakeFS';
import {Dirent, SymlinkType, StatSyncOptions, StatOptions} from './FakeFS';
import {MkdirOptions, RmdirOptions, RmOptions, WriteFileOptions, WatchCallback, WatchOptions, Watcher} from './FakeFS';
import {Handle} from './patchFs/FileHandle';
import {FSPath, Filename, Path} from './path';

export abstract class ProxiedFS<P extends Path, IP extends Path> extends FakeFS<P> {
Expand Down Expand Up @@ -30,6 +31,10 @@ export abstract class ProxiedFS<P extends Path, IP extends Path> extends FakeFS<
return this.mapFromBase(this.baseFs.getRealPath());
}

async openHandle(p: P, flags: string, mode?: number): Promise<Handle> {
return this.baseFs.openHandle(this.mapToBase(p), flags, mode);
}

async openPromise(p: P, flags: string, mode?: number) {
return this.baseFs.openPromise(this.mapToBase(p), flags, mode);
}
Expand Down
1 change: 1 addition & 0 deletions packages/yarnpkg-fslib/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export {PosixFS} from './PosixFS';
export {ProxiedFS} from './ProxiedFS';
export {VirtualFS} from './VirtualFS';

export {type Handle, FileHandle} from './patchFs/FileHandle';
export {patchFs, extendFs} from './patchFs/patchFs';

export {xfs} from './xfs';
Expand Down
17 changes: 15 additions & 2 deletions packages/yarnpkg-fslib/sources/patchFs/FileHandle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {BigIntStats, ReadStream, StatOptions, Stats, WriteStream, WriteVResult} from 'fs';
import {createInterface} from 'readline';
import {createInterface, Interface} from 'readline';

import type {CreateReadStreamOptions, CreateWriteStreamOptions, FakeFS} from '../FakeFS';
import type {Path} from '../path';
Expand Down Expand Up @@ -67,7 +67,20 @@ const kRefs = Symbol(`kRefs`);
const kRef = Symbol(`kRef`);
const kUnref = Symbol(`kUnref`);

export class FileHandle<P extends Path> {
export interface Handle {
appendFile(data: string | Uint8Array, options?: (ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding | null): Promise<void>;
chown(uid: number, gid: number): Promise<void>;
chmod(mode: number): Promise<void>;
createReadStream(options?: CreateReadStreamOptions): ReadStream;
createWriteStream(options?: CreateWriteStreamOptions): WriteStream;
datasync(): Promise<void>;
sync(): Promise<void>;
read(options?: FileReadOptions<Buffer>): Promise<FileReadResult<Buffer>>;
readFile(options?: {encoding?: null | undefined, flag?: OpenMode | undefined}): Promise<Buffer>;
readLines(options?: CreateReadStreamOptions): Interface;
}

export class FileHandle<P extends Path> implements Handle {
[kBaseFs]: FakeFS<P>;
[kFd]: number;
[kRefs] = 1;
Expand Down
6 changes: 3 additions & 3 deletions packages/yarnpkg-fslib/sources/patchFs/patchFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export function patchFs(patchedFs: typeof fs, fakeFs: FakeFS<NativePath>): void
continue;

setupFn(patchedFsPromises, origName, (pathLike: string | FileHandle<any>, ...args: Array<any>) => {
if (pathLike instanceof FileHandle) {
if (typeof pathLike === `object` && pathLike !== null && `close` in pathLike) {
return ((pathLike as any)[origName] as Function).apply(pathLike, args);
} else {
return fakeImpl.call(fakeFs, pathLike, ...args);
Expand All @@ -328,8 +328,7 @@ export function patchFs(patchedFs: typeof fs, fakeFs: FakeFS<NativePath>): void

setupFn(patchedFsPromises, `open`, async (...args: Array<any>) => {
// @ts-expect-error - reason TBS
const fd = await fakeFs.openPromise(...args);
return new FileHandle(fd, fakeFs);
return await fakeFs.openHandle(...args);
});

// `fs.promises.realpath` doesn't have a `native` property
Expand Down Expand Up @@ -359,6 +358,7 @@ export function patchFs(patchedFs: typeof fs, fakeFs: FakeFS<NativePath>): void

export function extendFs(realFs: typeof fs, fakeFs: FakeFS<NativePath>): typeof fs {
const patchedFs = Object.create(realFs);
Object.defineProperty(patchedFs, `promises`, {value: Object.create(realFs.promises)});

patchFs(patchedFs, fakeFs);

Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-fslib/tests/patchedFs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ describe(`patchedFs`, () => {
await expect(fd.stat()).rejects.toMatchObject({
message: `file closed`,
code: `EBADF`,
syscall: `stat`,
syscall: `fstat`,
});
});
});
Expand Down
7 changes: 6 additions & 1 deletion packages/yarnpkg-libzip/sources/ZipFS.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Handle} from '@yarnpkg/fslib/sources/patchFs/FileHandle';
import {Dirent, DirentNoPath, ReaddirOptions} from '@yarnpkg/fslib';
import {WatchOptions, WatchCallback, Watcher, Dir, Stats, BigIntStats, StatSyncOptions, StatOptions} from '@yarnpkg/fslib';
import {FakeFS, MkdirOptions, RmdirOptions, RmOptions, WriteFileOptions, OpendirOptions} from '@yarnpkg/fslib';
import {CreateReadStreamOptions, CreateWriteStreamOptions, BasePortableFakeFS, ExtractHintOptions, WatchFileCallback, WatchFileOptions, StatWatcher} from '@yarnpkg/fslib';
import {NodeFS} from '@yarnpkg/fslib';
import {NodeFS, FileHandle} from '@yarnpkg/fslib';
import {opendir} from '@yarnpkg/fslib';
import {watchFile, unwatchFile, unwatchAllFiles} from '@yarnpkg/fslib';
import {errors, statUtils} from '@yarnpkg/fslib';
Expand Down Expand Up @@ -283,6 +284,10 @@ export class ZipFS extends BasePortableFakeFS {
return ppath.resolve(PortablePath.root, p);
}

async openHandle(p: PortablePath, flags: string, mode?: number): Promise<Handle> {
return new FileHandle(this.openSync(p, flags, mode), this);
}

async openPromise(p: PortablePath, flags: string, mode?: number) {
return this.openSync(p, flags, mode);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/esm-loader/built-loader.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/loader/_entryPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare var $$SETUP_STATE: (hrs: typeof hydrateRuntimeState, basePath?: NativePa
// We must copy the fs into a local, because otherwise
// 1. we would make the NodeFS instance use the function that we patched (infinite loop)
// 2. Object.create(fs) isn't enough, since it won't prevent the proto from being modified
const localFs: typeof fs = {...fs};
const localFs: typeof fs = {...fs, promises: {...fs.promises}};
const nodeFs = new NodeFS(localFs);

const defaultRuntimeState = $$SETUP_STATE(hydrateRuntimeState);
Expand Down
Loading