Socket
Socket
Sign inDemoInstall

@yarnpkg/fslib

Package Overview
Dependencies
Maintainers
6
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yarnpkg/fslib - npm Package Compare versions

Comparing version 3.0.0-rc.14 to 3.0.0-rc.15

66

lib/algorithms/copyPromise.js

@@ -138,2 +138,8 @@ "use strict";

const indexPath = destinationFs.pathUtils.join(linkStrategy.indexPath, sourceHash.slice(0, 2), `${sourceHash}.dat`);
let AtomicBehavior;
(function (AtomicBehavior) {
AtomicBehavior[AtomicBehavior["Lock"] = 0] = "Lock";
AtomicBehavior[AtomicBehavior["Rename"] = 1] = "Rename";
})(AtomicBehavior || (AtomicBehavior = {}));
let atomicBehavior = AtomicBehavior.Rename;
let indexStat = await maybeLStat(destinationFs, indexPath);

@@ -143,5 +149,20 @@ if (destinationStat) {

const isIndexModified = (indexStat === null || indexStat === void 0 ? void 0 : indexStat.mtimeMs) !== defaultTimeMs;
if (isDestinationHardlinkedFromIndex)
if (isIndexModified && linkStrategy.autoRepair)
if (isDestinationHardlinkedFromIndex) {
// If the index is modified, we will want to repair it. However, the
// default logic ensuring atomicity (creating a file in a temporary
// place before atomically moving it into its final location) won't
// work: we'd lose all the existing hardlinks.
//
// To avoid that, when repairing a file, we fallback to the slow but
// safer `lockPromise`-based mutex, which will prevent multiple
// processes to modify the file without impacting their inode.
//
// Give that the repair mechanism should be very rarely needed in
// situation where performance is critical, it should be ok.
//
if (isIndexModified && linkStrategy.autoRepair) {
atomicBehavior = AtomicBehavior.Lock;
indexStat = null;
}
}
if (!isDestinationHardlinkedFromIndex) {

@@ -157,8 +178,39 @@ if (opts.overwrite) {

}
const tempPath = !indexStat && atomicBehavior === AtomicBehavior.Rename
? `${indexPath}.${Math.floor(Math.random() * 0x100000000).toString(16).padStart(8, `0`)}`
: null;
let tempPathCleaned = false;
prelayout.push(async () => {
if (!indexStat) {
await destinationFs.lockPromise(indexPath, async () => {
if (atomicBehavior === AtomicBehavior.Lock) {
await destinationFs.lockPromise(indexPath, async () => {
const content = await sourceFs.readFilePromise(source);
await destinationFs.writeFilePromise(indexPath, content);
});
}
if (atomicBehavior === AtomicBehavior.Rename && tempPath) {
const content = await sourceFs.readFilePromise(source);
await destinationFs.writeFilePromise(indexPath, content);
});
await destinationFs.writeFilePromise(tempPath, content);
// We use `linkPromise` rather than `renamePromise` because the later
// overwrites the destination if it already exists; usually this
// wouldn't be a problem, but since we care about preserving the
// hardlink identity of the destination, we can't do that.
//
// So instead we create a hardlink of the source file (which will
// fail with EEXIST if the destination already exists), and we remove
// the source in the postlayout steps.
//
try {
await destinationFs.linkPromise(tempPath, indexPath);
}
catch (err) {
if (err.code === `EEXIST`) {
tempPathCleaned = true;
await destinationFs.unlinkPromise(tempPath);
}
else {
throw err;
}
}
}
}

@@ -170,4 +222,6 @@ if (!destinationStat) {

postlayout.push(async () => {
if (!indexStat) {
if (!indexStat)
await updateTime(indexPath, defaultTime, defaultTime);
if (tempPath && !tempPathCleaned) {
await destinationFs.unlinkPromise(tempPath);
}

@@ -174,0 +228,0 @@ });

3

lib/algorithms/watchFile/CustomStatWatcher.d.ts
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { EventEmitter } from 'events';

@@ -41,3 +40,3 @@ import { BigIntStats, Stats } from 'fs';

*/
makeInterval(opts: ListenerOptions): NodeJS.Timeout;
makeInterval(opts: ListenerOptions): NodeJS.Timer;
/**

@@ -44,0 +43,0 @@ * Registers a listener and assigns it an interval.

@@ -5,3 +5,2 @@ /// <reference types="node" />

/// <reference types="node" />
/// <reference types="node" />
import { EventEmitter } from 'events';

@@ -13,2 +12,3 @@ import { Dirent as NodeDirent, ReadStream } from 'fs';

import { FSPath, Path, PortablePath, PathUtils, Filename } from './path';
export declare type BufferEncodingOrBuffer = BufferEncoding | 'buffer';
export declare type Stats = NodeStats & {

@@ -37,7 +37,7 @@ crc?: number;

export declare type CreateReadStreamOptions = Partial<{
encoding: string;
encoding: BufferEncoding;
fd: number;
}>;
export declare type CreateWriteStreamOptions = Partial<{
encoding: string;
encoding: BufferEncoding;
fd: number;

@@ -56,11 +56,11 @@ flags: 'a';

export declare type WriteFileOptions = Partial<{
encoding: string;
encoding: BufferEncoding;
mode: number;
flag: string;
}> | string;
}> | BufferEncoding;
export declare type WatchOptions = Partial<{
persistent: boolean;
recursive: boolean;
encoding: string;
}> | string;
encoding: BufferEncodingOrBuffer;
}> | BufferEncodingOrBuffer;
export declare type WatchFileOptions = Partial<{

@@ -177,3 +177,3 @@ bigint: boolean;

abstract fstatPromise(fd: number, opts?: {
bigint: boolean;
bigint?: boolean;
}): Promise<BigIntStats | Stats>;

@@ -185,3 +185,3 @@ abstract fstatSync(fd: number): Stats;

abstract fstatSync(fd: number, opts?: {
bigint: boolean;
bigint?: boolean;
}): BigIntStats | Stats;

@@ -234,6 +234,6 @@ abstract lstatPromise(p: P): Promise<Stats>;

abstract copyFileSync(sourceP: P, destP: P, flags?: number): void;
abstract appendFilePromise(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
abstract appendFileSync(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
abstract writeFilePromise(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
abstract writeFileSync(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
abstract appendFilePromise(p: FSPath<P>, content: string | Uint8Array, opts?: WriteFileOptions): Promise<void>;
abstract appendFileSync(p: FSPath<P>, content: string | Uint8Array, opts?: WriteFileOptions): void;
abstract writeFilePromise(p: FSPath<P>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): Promise<void>;
abstract writeFileSync(p: FSPath<P>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): void;
abstract unlinkPromise(p: P): Promise<void>;

@@ -245,6 +245,8 @@ abstract unlinkSync(p: P): void;

lutimesSync?(p: P, atime: Date | string | number, mtime: Date | string | number): void;
abstract readFilePromise(p: FSPath<P>, encoding: 'utf8'): Promise<string>;
abstract readFilePromise(p: FSPath<P>, encoding?: string): Promise<Buffer>;
abstract readFileSync(p: FSPath<P>, encoding: 'utf8'): string;
abstract readFileSync(p: FSPath<P>, encoding?: string): Buffer;
abstract readFilePromise(p: FSPath<P>, encoding?: null): Promise<Buffer>;
abstract readFilePromise(p: FSPath<P>, encoding: BufferEncoding): Promise<string>;
abstract readFilePromise(p: FSPath<P>, encoding?: BufferEncoding | null): Promise<Buffer | string>;
abstract readFileSync(p: FSPath<P>, encoding?: null): Buffer;
abstract readFileSync(p: FSPath<P>, encoding: BufferEncoding): string;
abstract readFileSync(p: FSPath<P>, encoding?: BufferEncoding | null): Buffer | string;
abstract readlinkPromise(p: P): Promise<P>;

@@ -251,0 +253,0 @@ abstract readlinkSync(p: P): P;

@@ -9,2 +9,3 @@ import * as constants from './constants';

export { normalizeLineEndings } from './FakeFS';
export type { BufferEncodingOrBuffer } from './FakeFS';
export type { CreateReadStreamOptions } from './FakeFS';

@@ -11,0 +12,0 @@ export type { CreateWriteStreamOptions } from './FakeFS';

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import fs, { BigIntStats, Stats } from 'fs';

@@ -113,6 +112,6 @@ import { CreateReadStreamOptions, CreateWriteStreamOptions, Dir, StatWatcher, WatchFileCallback, WatchFileOptions, OpendirOptions } from './FakeFS';

copyFileSync(sourceP: PortablePath, destP: PortablePath, flags?: number): void;
appendFilePromise(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
appendFileSync(p: PortablePath, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
writeFilePromise(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
writeFileSync(p: PortablePath, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
appendFilePromise(p: FSPath<PortablePath>, content: string | Uint8Array, opts?: WriteFileOptions): Promise<void>;
appendFileSync(p: PortablePath, content: string | Uint8Array, opts?: WriteFileOptions): void;
writeFilePromise(p: FSPath<PortablePath>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): Promise<void>;
writeFileSync(p: PortablePath, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): void;
unlinkPromise(p: PortablePath): Promise<void>;

@@ -132,6 +131,8 @@ unlinkSync(p: PortablePath): void;

symlinkSync(target: PortablePath, p: PortablePath, type?: SymlinkType): void;
readFilePromise(p: FSPath<PortablePath>, encoding: 'utf8'): Promise<string>;
readFilePromise(p: FSPath<PortablePath>, encoding?: string): Promise<Buffer>;
readFileSync(p: FSPath<PortablePath>, encoding: 'utf8'): string;
readFileSync(p: FSPath<PortablePath>, encoding?: string): Buffer;
readFilePromise(p: FSPath<PortablePath>, encoding?: null): Promise<Buffer>;
readFilePromise(p: FSPath<PortablePath>, encoding: BufferEncoding): Promise<string>;
readFilePromise(p: FSPath<PortablePath>, encoding?: BufferEncoding | null): Promise<Buffer | string>;
readFileSync(p: FSPath<PortablePath>, encoding?: null): Buffer;
readFileSync(p: FSPath<PortablePath>, encoding: BufferEncoding): string;
readFileSync(p: FSPath<PortablePath>, encoding?: BufferEncoding | null): Buffer | string;
readdirPromise(p: PortablePath): Promise<Array<Filename>>;

@@ -138,0 +139,0 @@ readdirPromise(p: PortablePath, opts: {

@@ -13,3 +13,2 @@ "use strict";

this.realFs = realFs;
// @ts-expect-error
if (typeof this.realFs.lutimes !== `undefined`) {

@@ -133,3 +132,2 @@ this.lutimesPromise = this.lutimesPromiseImpl;

if (opts) {
// @ts-expect-error The node types are out of date
this.realFs.stat(path_1.npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));

@@ -144,3 +142,2 @@ }

if (opts) {
// @ts-expect-error The node types are out of date
return this.realFs.statSync(path_1.npath.fromPortablePath(p), opts);

@@ -155,3 +152,2 @@ }

if (opts) {
// @ts-expect-error - The node typings doesn't know about the options
this.realFs.fstat(fd, opts, this.makeCallback(resolve, reject));

@@ -166,3 +162,2 @@ }

if (opts) {
// @ts-expect-error - The node typings doesn't know about the options
return this.realFs.fstatSync(fd, opts);

@@ -177,3 +172,2 @@ }

if (opts) {
// @ts-expect-error - TS does not know this takes options
this.realFs.lstat(path_1.npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));

@@ -188,3 +182,2 @@ }

if (opts) {
// @ts-expect-error - TS does not know this takes options
return this.realFs.lstatSync(path_1.npath.fromPortablePath(p), opts);

@@ -293,3 +286,2 @@ }

async lutimesPromiseImpl(p, atime, mtime) {
// @ts-expect-error: Not yet in DefinitelyTyped
const lutimes = this.realFs.lutimes;

@@ -303,3 +295,2 @@ if (typeof lutimes === `undefined`)

lutimesSyncImpl(p, atime, mtime) {
// @ts-expect-error: Not yet in DefinitelyTyped
const lutimesSync = this.realFs.lutimesSync;

@@ -312,3 +303,2 @@ if (typeof lutimesSync === `undefined`)

return await new Promise((resolve, reject) => {
// @ts-expect-error - Types are outdated, the second argument in the callback is either a string or undefined
this.realFs.mkdir(path_1.npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));

@@ -318,3 +308,2 @@ });

mkdirSync(p, opts) {
// @ts-expect-error - Types are outdated, returns either a string or undefined
return this.realFs.mkdirSync(path_1.npath.fromPortablePath(p), opts);

@@ -321,0 +310,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import type { BigIntStats, ReadStream, StatOptions, Stats, WriteStream, WriteVResult } from 'fs';

@@ -6,0 +5,0 @@ import type { CreateReadStreamOptions, CreateWriteStreamOptions, FakeFS } from '../FakeFS';

/// <reference types="node" />
/// <reference types="node" />
import fs from 'fs';

@@ -4,0 +3,0 @@ import { FakeFS } from '../FakeFS';

@@ -206,40 +206,30 @@ "use strict";

// so we can just patch `fs.promises` and both will be updated
const origEmitWarning = process.emitWarning;
process.emitWarning = () => { };
let patchedFsPromises;
try {
patchedFsPromises = patchedFs.promises;
}
finally {
process.emitWarning = origEmitWarning;
}
if (typeof patchedFsPromises !== `undefined`) {
// `fs.promises.exists` doesn't exist
for (const fnName of ASYNC_IMPLEMENTATIONS) {
const origName = fnName.replace(/Promise$/, ``);
if (typeof patchedFsPromises[origName] === `undefined`)
continue;
const fakeImpl = fakeFs[fnName];
if (typeof fakeImpl === `undefined`)
continue;
// Open is a bit particular with fs.promises: it returns a file handle
// instance instead of the traditional file descriptor number
if (fnName === `open`)
continue;
setupFn(patchedFsPromises, origName, (pathLike, ...args) => {
if (pathLike instanceof FileHandle_1.FileHandle) {
return pathLike[origName].apply(pathLike, args);
}
else {
return fakeImpl.call(fakeFs, pathLike, ...args);
}
});
}
setupFn(patchedFsPromises, `open`, async (...args) => {
// @ts-expect-error
const fd = await fakeFs.openPromise(...args);
return new FileHandle_1.FileHandle(fd, fakeFs);
const patchedFsPromises = patchedFs.promises;
// `fs.promises.exists` doesn't exist
for (const fnName of ASYNC_IMPLEMENTATIONS) {
const origName = fnName.replace(/Promise$/, ``);
if (typeof patchedFsPromises[origName] === `undefined`)
continue;
const fakeImpl = fakeFs[fnName];
if (typeof fakeImpl === `undefined`)
continue;
// Open is a bit particular with fs.promises: it returns a file handle
// instance instead of the traditional file descriptor number
if (fnName === `open`)
continue;
setupFn(patchedFsPromises, origName, (pathLike, ...args) => {
if (pathLike instanceof FileHandle_1.FileHandle) {
return pathLike[origName].apply(pathLike, args);
}
else {
return fakeImpl.call(fakeFs, pathLike, ...args);
}
});
// `fs.promises.realpath` doesn't have a `native` property
}
setupFn(patchedFsPromises, `open`, async (...args) => {
// @ts-expect-error
const fd = await fakeFs.openPromise(...args);
return new FileHandle_1.FileHandle(fd, fakeFs);
});
// `fs.promises.realpath` doesn't have a `native` property
}

@@ -246,0 +236,0 @@ /** util.promisify implementations */

@@ -31,2 +31,4 @@ declare enum PathType {

pnpCjs: Filename;
pnpData: Filename;
pnpEsmLoader: Filename;
rc: Filename;

@@ -33,0 +35,0 @@ };

@@ -27,2 +27,4 @@ "use strict";

pnpCjs: `.pnp.cjs`,
pnpData: `.pnp.data.json`,
pnpEsmLoader: `.pnp.loader.mjs`,
rc: `.yarnrc.yml`,

@@ -29,0 +31,0 @@ };

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { Stats, BigIntStats } from 'fs';

@@ -119,6 +118,6 @@ import { CreateReadStreamOptions, CreateWriteStreamOptions, FakeFS, ExtractHintOptions, WatchFileCallback, WatchFileOptions, StatWatcher, Dir, OpendirOptions } from './FakeFS';

copyFileSync(sourceP: P, destP: P, flags?: number): void;
appendFilePromise(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
appendFileSync(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
writeFilePromise(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
writeFileSync(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
appendFilePromise(p: FSPath<P>, content: string | Uint8Array, opts?: WriteFileOptions): Promise<void>;
appendFileSync(p: FSPath<P>, content: string | Uint8Array, opts?: WriteFileOptions): void;
writeFilePromise(p: FSPath<P>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): Promise<void>;
writeFileSync(p: FSPath<P>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): void;
unlinkPromise(p: P): Promise<void>;

@@ -136,6 +135,8 @@ unlinkSync(p: P): void;

symlinkSync(target: P, p: P, type?: SymlinkType): void;
readFilePromise(p: FSPath<P>, encoding: 'utf8'): Promise<string>;
readFilePromise(p: FSPath<P>, encoding?: string): Promise<Buffer>;
readFileSync(p: FSPath<P>, encoding: 'utf8'): string;
readFileSync(p: FSPath<P>, encoding?: string): Buffer;
readFilePromise(p: FSPath<P>, encoding?: null): Promise<Buffer>;
readFilePromise(p: FSPath<P>, encoding: BufferEncoding): Promise<string>;
readFilePromise(p: FSPath<P>, encoding?: BufferEncoding | null): Promise<Buffer | string>;
readFileSync(p: FSPath<P>, encoding?: null): Buffer;
readFileSync(p: FSPath<P>, encoding: BufferEncoding): string;
readFileSync(p: FSPath<P>, encoding?: BufferEncoding | null): Buffer | string;
readdirPromise(p: P): Promise<Array<Filename>>;

@@ -142,0 +143,0 @@ readdirPromise(p: P, opts: {

@@ -186,18 +186,6 @@ "use strict";

async readFilePromise(p, encoding) {
// This weird condition is required to tell TypeScript that the signatures are proper (otherwise it thinks that only the generic one is covered)
if (encoding === `utf8`) {
return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding);
}
else {
return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding);
}
return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding);
}
readFileSync(p, encoding) {
// This weird condition is required to tell TypeScript that the signatures are proper (otherwise it thinks that only the generic one is covered)
if (encoding === `utf8`) {
return this.baseFs.readFileSync(this.fsMapToBase(p), encoding);
}
else {
return this.baseFs.readFileSync(this.fsMapToBase(p), encoding);
}
return this.baseFs.readFileSync(this.fsMapToBase(p), encoding);
}

@@ -204,0 +192,0 @@ async readdirPromise(p, opts) {

/// <reference types="node" />
/// <reference types="node" />
import { BigIntStats, Stats } from 'fs';

@@ -4,0 +3,0 @@ import { Filename } from './path';

@@ -177,7 +177,7 @@ /// <reference types="node" />

private prepareCopyFile;
appendFilePromise(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
appendFileSync(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
appendFilePromise(p: FSPath<PortablePath>, content: string | Uint8Array, opts?: WriteFileOptions): Promise<void>;
appendFileSync(p: FSPath<PortablePath>, content: string | Uint8Array, opts?: WriteFileOptions): void;
private fdToPath;
writeFilePromise(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
writeFileSync(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
writeFilePromise(p: FSPath<PortablePath>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): Promise<void>;
writeFileSync(p: FSPath<PortablePath>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): void;
private prepareWriteFile;

@@ -200,6 +200,8 @@ unlinkPromise(p: PortablePath): Promise<void>;

symlinkSync(target: PortablePath, p: PortablePath): void;
readFilePromise(p: FSPath<PortablePath>, encoding: 'utf8'): Promise<string>;
readFilePromise(p: FSPath<PortablePath>, encoding?: string): Promise<Buffer>;
readFileSync(p: FSPath<PortablePath>, encoding: 'utf8'): string;
readFileSync(p: FSPath<PortablePath>, encoding?: string): Buffer;
readFilePromise(p: FSPath<PortablePath>, encoding?: null): Promise<Buffer>;
readFilePromise(p: FSPath<PortablePath>, encoding: BufferEncoding): Promise<string>;
readFilePromise(p: FSPath<PortablePath>, encoding?: BufferEncoding | null): Promise<Buffer | string>;
readFileSync(p: FSPath<PortablePath>, encoding?: null): Buffer;
readFileSync(p: FSPath<PortablePath>, encoding: BufferEncoding): string;
readFileSync(p: FSPath<PortablePath>, encoding?: BufferEncoding | null): Buffer | string;
private readFileBuffer;

@@ -206,0 +208,0 @@ readdirPromise(p: PortablePath): Promise<Array<Filename>>;

@@ -346,2 +346,4 @@ "use strict";

path: p,
// "This property is `true` if the underlying file has not been opened yet"
pending: false,
});

@@ -388,7 +390,9 @@ const immediate = setImmediate(async () => {

}), {
bytesWritten: 0,
path: p,
close() {
stream.destroy();
},
bytesWritten: 0,
path: p,
// "This property is `true` if the underlying file has not been opened yet"
pending: false,
});

@@ -872,2 +876,3 @@ stream.on(`data`, chunk => {

if (encoding !== null)
// @ts-expect-error: toString ignores unneeded arguments
content = content.toString(encoding);

@@ -886,2 +891,3 @@ const newIndex = this.setFileSource(resolvedP, content);

if (encoding !== null)
// @ts-expect-error: toString ignores unneeded arguments
content = content.toString(encoding);

@@ -888,0 +894,0 @@ const newIndex = this.setFileSource(resolvedP, content);

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { Libzip } from '@yarnpkg/libzip';

@@ -159,6 +158,6 @@ import { BigIntStats, Stats } from 'fs';

copyFileSync(sourceP: PortablePath, destP: PortablePath, flags?: number): void;
appendFilePromise(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
appendFileSync(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
writeFilePromise(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
writeFileSync(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
appendFilePromise(p: FSPath<PortablePath>, content: string | Uint8Array, opts?: WriteFileOptions): Promise<void>;
appendFileSync(p: FSPath<PortablePath>, content: string | Uint8Array, opts?: WriteFileOptions): void;
writeFilePromise(p: FSPath<PortablePath>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): Promise<void>;
writeFileSync(p: FSPath<PortablePath>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): void;
unlinkPromise(p: PortablePath): Promise<void>;

@@ -176,6 +175,8 @@ unlinkSync(p: PortablePath): void;

symlinkSync(target: PortablePath, p: PortablePath, type?: SymlinkType): void;
readFilePromise(p: FSPath<PortablePath>, encoding: 'utf8'): Promise<string>;
readFilePromise(p: FSPath<PortablePath>, encoding?: string): Promise<Buffer>;
readFileSync(p: FSPath<PortablePath>, encoding: 'utf8'): string;
readFileSync(p: FSPath<PortablePath>, encoding?: string): Buffer;
readFilePromise(p: FSPath<PortablePath>, encoding?: null): Promise<Buffer>;
readFilePromise(p: FSPath<PortablePath>, encoding: BufferEncoding): Promise<string>;
readFilePromise(p: FSPath<PortablePath>, encoding?: BufferEncoding | null): Promise<Buffer | string>;
readFileSync(p: FSPath<PortablePath>, encoding?: null): Buffer;
readFileSync(p: FSPath<PortablePath>, encoding: BufferEncoding): string;
readFileSync(p: FSPath<PortablePath>, encoding?: BufferEncoding | null): Buffer | string;
readdirPromise(p: PortablePath): Promise<Array<Filename>>;

@@ -182,0 +183,0 @@ readdirPromise(p: PortablePath, opts: {

@@ -12,3 +12,11 @@ "use strict";

const path_1 = require("./path");
const ZIP_FD = 0x80000000;
// Only file descriptors prefixed by those values will be forwarded to the ZipFS
// instances. Note that the highest ZIP_MAGIC bit MUST NOT be set, otherwise the
// resulting fd becomes a negative integer, which isn't supposed to happen per
// the unix rules (caused problems w/ Go).
//
// Those values must be synced with packages/yarnpkg-pnp/sources/esm-loader/fspatch.ts
//
const ZIP_MASK = 0xff000000;
const ZIP_MAGIC = 0x2a000000;
/**

@@ -101,3 +109,3 @@ * Extracts the archive part (ending in the first instance of `extension`) from a path.

remapFd(zipFs, fd) {
const remappedFd = this.nextFd++ | ZIP_FD;
const remappedFd = this.nextFd++ | ZIP_MAGIC;
this.fdMap.set(remappedFd, [zipFs, fd]);

@@ -139,3 +147,3 @@ return remappedFd;

async readPromise(fd, buffer, offset, length, position) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return await this.baseFs.readPromise(fd, buffer, offset, length, position);

@@ -149,3 +157,3 @@ const entry = this.fdMap.get(fd);

readSync(fd, buffer, offset, length, position) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return this.baseFs.readSync(fd, buffer, offset, length, position);

@@ -159,3 +167,3 @@ const entry = this.fdMap.get(fd);

async writePromise(fd, buffer, offset, length, position) {
if ((fd & ZIP_FD) === 0) {
if ((fd & ZIP_MASK) !== ZIP_MAGIC) {
if (typeof buffer === `string`) {

@@ -180,3 +188,3 @@ return await this.baseFs.writePromise(fd, buffer, offset);

writeSync(fd, buffer, offset, length, position) {
if ((fd & ZIP_FD) === 0) {
if ((fd & ZIP_MASK) !== ZIP_MAGIC) {
if (typeof buffer === `string`) {

@@ -201,3 +209,3 @@ return this.baseFs.writeSync(fd, buffer, offset);

async closePromise(fd) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return await this.baseFs.closePromise(fd);

@@ -212,3 +220,3 @@ const entry = this.fdMap.get(fd);

closeSync(fd) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return this.baseFs.closeSync(fd);

@@ -312,3 +320,3 @@ const entry = this.fdMap.get(fd);

async fstatPromise(fd, opts) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return this.baseFs.fstatPromise(fd, opts);

@@ -322,3 +330,3 @@ const entry = this.fdMap.get(fd);

fstatSync(fd, opts) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return this.baseFs.fstatSync(fd, opts);

@@ -346,3 +354,3 @@ const entry = this.fdMap.get(fd);

async fchmodPromise(fd, mask) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return this.baseFs.fchmodPromise(fd, mask);

@@ -356,3 +364,3 @@ const entry = this.fdMap.get(fd);

fchmodSync(fd, mask) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return this.baseFs.fchmodSync(fd, mask);

@@ -615,9 +623,3 @@ const entry = this.fdMap.get(fd);

return this.makeCallPromise(p, async () => {
// This weird switch is required to tell TypeScript that the signatures are proper (otherwise it thinks that only the generic one is covered)
switch (encoding) {
case `utf8`:
return await this.baseFs.readFilePromise(p, encoding);
default:
return await this.baseFs.readFilePromise(p, encoding);
}
return await this.baseFs.readFilePromise(p, encoding);
}, async (zipFs, { subPath }) => {

@@ -629,9 +631,3 @@ return await zipFs.readFilePromise(subPath, encoding);

return this.makeCallSync(p, () => {
// This weird switch is required to tell TypeScript that the signatures are proper (otherwise it thinks that only the generic one is covered)
switch (encoding) {
case `utf8`:
return this.baseFs.readFileSync(p, encoding);
default:
return this.baseFs.readFileSync(p, encoding);
}
return this.baseFs.readFileSync(p, encoding);
}, (zipFs, { subPath }) => {

@@ -688,3 +684,3 @@ return zipFs.readFileSync(subPath, encoding);

async ftruncatePromise(fd, len) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return this.baseFs.ftruncatePromise(fd, len);

@@ -698,3 +694,3 @@ const entry = this.fdMap.get(fd);

ftruncateSync(fd, len) {
if ((fd & ZIP_FD) === 0)
if ((fd & ZIP_MASK) !== ZIP_MAGIC)
return this.baseFs.ftruncateSync(fd, len);

@@ -701,0 +697,0 @@ const entry = this.fdMap.get(fd);

{
"name": "@yarnpkg/fslib",
"version": "3.0.0-rc.14",
"version": "3.0.0-rc.15",
"stableVersion": "2.7.0",

@@ -9,4 +9,4 @@ "license": "BSD-2-Clause",

"dependencies": {
"@yarnpkg/libzip": "^3.0.0-rc.14",
"tslib": "^1.13.0"
"@yarnpkg/libzip": "^3.0.0-rc.15",
"tslib": "^2.4.0"
},

@@ -13,0 +13,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc