@yarnpkg/fslib
Advanced tools
Comparing version 2.0.0-rc.16 to 2.0.0-rc.17
@@ -41,2 +41,3 @@ /// <reference types="node" /> | ||
}; | ||
export declare type SymlinkType = 'file' | 'dir' | 'junction'; | ||
export declare abstract class FakeFS<P extends Path> { | ||
@@ -97,4 +98,4 @@ static DEFAULT_TIME: number; | ||
abstract rmdirSync(p: P): void; | ||
abstract symlinkPromise(target: P, p: P): Promise<void>; | ||
abstract symlinkSync(target: P, p: P): void; | ||
abstract symlinkPromise(target: P, p: P, type?: SymlinkType): Promise<void>; | ||
abstract symlinkSync(target: P, p: P, type?: SymlinkType): void; | ||
abstract renamePromise(oldP: P, newP: P): Promise<void>; | ||
@@ -101,0 +102,0 @@ abstract renameSync(oldP: P, newP: P): void; |
@@ -34,2 +34,3 @@ /// <reference types="node" /> | ||
export declare type XFS = NodeFS & { | ||
detachTemp(p: PortablePath): void; | ||
mktempSync(): PortablePath; | ||
@@ -36,0 +37,0 @@ mktempSync<T>(cb: (p: PortablePath) => T): T; |
150
lib/index.js
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const os_1 = __importDefault(require("os")); | ||
const util_1 = require("util"); | ||
@@ -10,2 +14,3 @@ const NodeFS_1 = require("./NodeFS"); | ||
exports.PortablePath = path_2.PortablePath; | ||
exports.Filename = path_2.Filename; | ||
var path_3 = require("./path"); | ||
@@ -39,2 +44,7 @@ exports.npath = path_3.npath; | ||
exports.ZipOpenFS = ZipOpenFS_1.ZipOpenFS; | ||
function getTempName(prefix) { | ||
const tmpdir = path_1.npath.toPortablePath(os_1.default.tmpdir()); | ||
const hash = Math.ceil(Math.random() * 0x100000000).toString(16).padStart(8, `0`); | ||
return path_1.ppath.join(tmpdir, `${prefix}${hash}`); | ||
} | ||
function patchFs(patchedFs, fakeFs) { | ||
@@ -159,61 +169,103 @@ const SYNC_IMPLEMENTATIONS = new Set([ | ||
exports.extendFs = extendFs; | ||
const tmpdirs = new Set(); | ||
let cleanExitRegistered = false; | ||
function registerCleanExit() { | ||
if (!cleanExitRegistered) | ||
cleanExitRegistered = true; | ||
else | ||
return; | ||
const cleanExit = () => { | ||
process.off(`exit`, cleanExit); | ||
for (const p of tmpdirs) { | ||
tmpdirs.delete(p); | ||
try { | ||
exports.xfs.removeSync(p); | ||
} | ||
catch (_a) { | ||
// Too bad if there's an error | ||
} | ||
} | ||
}; | ||
process.on(`exit`, cleanExit); | ||
} | ||
exports.xfs = Object.assign(new NodeFS_1.NodeFS(), { | ||
detachTemp(p) { | ||
tmpdirs.delete(p); | ||
}, | ||
mktempSync(cb) { | ||
// We lazily load `tmp` because it injects itself into the `process` | ||
// events (to clean the folders at exit time), and it may lead to | ||
// large memory leaks. Better avoid loading it until we can't do | ||
// otherwise (ideally the fix would be for `tmp` itself to only | ||
// attach cleaners after the first call). | ||
const tmp = require(`tmp`); | ||
const { name, removeCallback } = tmp.dirSync({ unsafeCleanup: true }); | ||
if (typeof cb === `undefined`) { | ||
return path_1.npath.toPortablePath(name); | ||
} | ||
else { | ||
registerCleanExit(); | ||
while (true) { | ||
const p = getTempName(`xfs-`); | ||
try { | ||
return cb(path_1.npath.toPortablePath(name)); | ||
this.mkdirSync(p); | ||
} | ||
finally { | ||
removeCallback(); | ||
catch (error) { | ||
if (error.code === `EEXIST`) { | ||
continue; | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
const realP = this.realpathSync(p); | ||
tmpdirs.add(realP); | ||
if (typeof cb !== `undefined`) { | ||
try { | ||
return cb(realP); | ||
} | ||
finally { | ||
if (tmpdirs.has(realP)) { | ||
tmpdirs.delete(realP); | ||
try { | ||
this.removeSync(realP); | ||
} | ||
catch (_a) { | ||
// Too bad if there's an error | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
return p; | ||
} | ||
} | ||
}, | ||
mktempPromise(cb) { | ||
// We lazily load `tmp` because it injects itself into the `process` | ||
// events (to clean the folders at exit time), and it may lead to | ||
// large memory leaks. Better avoid loading it until we can't do | ||
// otherwise (ideally the fix would be for `tmp` itself to only | ||
// attach cleaners after the first call). | ||
const tmp = require(`tmp`); | ||
if (typeof cb === `undefined`) { | ||
return new Promise((resolve, reject) => { | ||
tmp.dir({ unsafeCleanup: true }, (err, path) => { | ||
if (err) { | ||
reject(err); | ||
async mktempPromise(cb) { | ||
registerCleanExit(); | ||
while (true) { | ||
const p = getTempName(`xfs-`); | ||
try { | ||
await this.mkdirPromise(p); | ||
} | ||
catch (error) { | ||
if (error.code === `EEXIST`) { | ||
continue; | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
const realP = await this.realpathPromise(p); | ||
tmpdirs.add(realP); | ||
if (typeof cb !== `undefined`) { | ||
try { | ||
return await cb(realP); | ||
} | ||
finally { | ||
if (tmpdirs.has(realP)) { | ||
tmpdirs.delete(realP); | ||
try { | ||
await this.removePromise(realP); | ||
} | ||
catch (_a) { | ||
// Too bad if there's an error | ||
} | ||
} | ||
else { | ||
resolve(path_1.npath.toPortablePath(path)); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
else { | ||
return realP; | ||
} | ||
} | ||
else { | ||
return new Promise((resolve, reject) => { | ||
tmp.dir({ unsafeCleanup: true }, (err, path, cleanup) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
Promise.resolve(path_1.npath.toPortablePath(path)).then(cb).then(result => { | ||
cleanup(); | ||
resolve(result); | ||
}, error => { | ||
cleanup(); | ||
reject(error); | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
}, | ||
}); |
/// <reference types="node" /> | ||
import fs from 'fs'; | ||
import { CreateReadStreamOptions, CreateWriteStreamOptions } from './FakeFS'; | ||
import { Dirent } from './FakeFS'; | ||
import { Dirent, SymlinkType } from './FakeFS'; | ||
import { BasePortableFakeFS, WriteFileOptions } from './FakeFS'; | ||
@@ -53,4 +53,4 @@ import { MkdirOptions, WatchOptions, WatchCallback, Watcher } from './FakeFS'; | ||
rmdirSync(p: PortablePath): void; | ||
symlinkPromise(target: PortablePath, p: PortablePath): Promise<void>; | ||
symlinkSync(target: PortablePath, p: PortablePath): void; | ||
symlinkPromise(target: PortablePath, p: PortablePath, type?: SymlinkType): Promise<void>; | ||
symlinkSync(target: PortablePath, p: PortablePath, type?: SymlinkType): void; | ||
readFilePromise(p: FSPath<PortablePath>, encoding: 'utf8'): Promise<string>; | ||
@@ -57,0 +57,0 @@ readFilePromise(p: FSPath<PortablePath>, encoding?: string): Promise<Buffer>; |
@@ -215,11 +215,11 @@ "use strict"; | ||
} | ||
async symlinkPromise(target, p) { | ||
const type = target.endsWith(`/`) ? `dir` : `file`; | ||
async symlinkPromise(target, p, type) { | ||
const symlinkType = type || (target.endsWith(`/`) ? `dir` : `file`); | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.symlink(path_1.npath.fromPortablePath(target.replace(/\/+$/, ``)), path_1.npath.fromPortablePath(p), type, this.makeCallback(resolve, reject)); | ||
this.realFs.symlink(path_1.npath.fromPortablePath(target.replace(/\/+$/, ``)), path_1.npath.fromPortablePath(p), symlinkType, this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
symlinkSync(target, p) { | ||
const type = target.endsWith(`/`) ? `dir` : `file`; | ||
return this.realFs.symlinkSync(path_1.npath.fromPortablePath(target.replace(/\/+$/, ``)), path_1.npath.fromPortablePath(p), type); | ||
symlinkSync(target, p, type) { | ||
const symlinkType = type || (target.endsWith(`/`) ? `dir` : `file`); | ||
return this.realFs.symlinkSync(path_1.npath.fromPortablePath(target.replace(/\/+$/, ``)), path_1.npath.fromPortablePath(p), symlinkType); | ||
} | ||
@@ -226,0 +226,0 @@ async readFilePromise(p, encoding) { |
@@ -15,2 +15,7 @@ export declare type PortablePath = string & { | ||
export declare type Path = PortablePath | NativePath; | ||
export declare const Filename: { | ||
nodeModules: Filename; | ||
manifest: Filename; | ||
lockfile: Filename; | ||
}; | ||
export declare type FSPath<T extends Path> = T | number; | ||
@@ -17,0 +22,0 @@ export declare const npath: PathUtils<NativePath> & ConvertUtils; |
@@ -11,2 +11,7 @@ "use strict"; | ||
}; | ||
exports.Filename = { | ||
nodeModules: `node_modules`, | ||
manifest: `package.json`, | ||
lockfile: `yarn.lock`, | ||
}; | ||
exports.npath = Object.create(path_1.default); | ||
@@ -13,0 +18,0 @@ exports.ppath = Object.create(path_1.default.posix); |
/// <reference types="node" /> | ||
import { CreateReadStreamOptions, CreateWriteStreamOptions, FakeFS, ExtractHintOptions } from './FakeFS'; | ||
import { Dirent } from './FakeFS'; | ||
import { Dirent, SymlinkType } from './FakeFS'; | ||
import { MkdirOptions, WriteFileOptions, WatchCallback, WatchOptions, Watcher } from './FakeFS'; | ||
@@ -59,4 +59,4 @@ import { FSPath, Filename, Path } from './path'; | ||
rmdirSync(p: P): void; | ||
symlinkPromise(target: P, p: P): Promise<void>; | ||
symlinkSync(target: P, p: P): void; | ||
symlinkPromise(target: P, p: P, type?: SymlinkType): Promise<void>; | ||
symlinkSync(target: P, p: P, type?: SymlinkType): void; | ||
readFilePromise(p: FSPath<P>, encoding: 'utf8'): Promise<string>; | ||
@@ -63,0 +63,0 @@ readFilePromise(p: FSPath<P>, encoding?: string): Promise<Buffer>; |
@@ -138,7 +138,7 @@ "use strict"; | ||
} | ||
symlinkPromise(target, p) { | ||
return this.baseFs.symlinkPromise(this.mapToBase(target), this.mapToBase(p)); | ||
symlinkPromise(target, p, type) { | ||
return this.baseFs.symlinkPromise(this.mapToBase(target), this.mapToBase(p), type); | ||
} | ||
symlinkSync(target, p) { | ||
return this.baseFs.symlinkSync(this.mapToBase(target), this.mapToBase(p)); | ||
symlinkSync(target, p, type) { | ||
return this.baseFs.symlinkSync(this.mapToBase(target), this.mapToBase(p), type); | ||
} | ||
@@ -145,0 +145,0 @@ readFilePromise(p, encoding) { |
/// <reference types="node" /> | ||
import { Libzip } from '@yarnpkg/libzip'; | ||
import { CreateReadStreamOptions, CreateWriteStreamOptions, BasePortableFakeFS, ExtractHintOptions } from './FakeFS'; | ||
import { Dirent } from './FakeFS'; | ||
import { Dirent, SymlinkType } from './FakeFS'; | ||
import { FakeFS, MkdirOptions, WriteFileOptions } from './FakeFS'; | ||
@@ -74,4 +74,4 @@ import { WatchOptions, WatchCallback, Watcher } from './FakeFS'; | ||
rmdirSync(p: PortablePath): void; | ||
symlinkPromise(target: PortablePath, p: PortablePath): Promise<void>; | ||
symlinkSync(target: PortablePath, p: PortablePath): void; | ||
symlinkPromise(target: PortablePath, p: PortablePath, type?: SymlinkType): Promise<void>; | ||
symlinkSync(target: PortablePath, p: PortablePath, type?: SymlinkType): void; | ||
readFilePromise(p: FSPath<PortablePath>, encoding: 'utf8'): Promise<string>; | ||
@@ -78,0 +78,0 @@ readFilePromise(p: FSPath<PortablePath>, encoding?: string): Promise<Buffer>; |
@@ -447,5 +447,5 @@ "use strict"; | ||
} | ||
async symlinkPromise(target, p) { | ||
async symlinkPromise(target, p, type) { | ||
return await this.makeCallPromise(p, async () => { | ||
return await this.baseFs.symlinkPromise(target, p); | ||
return await this.baseFs.symlinkPromise(target, p, type); | ||
}, async (zipFs, { subPath }) => { | ||
@@ -455,5 +455,5 @@ return await zipFs.symlinkPromise(target, subPath); | ||
} | ||
symlinkSync(target, p) { | ||
symlinkSync(target, p, type) { | ||
return this.makeCallSync(p, () => { | ||
return this.baseFs.symlinkSync(target, p); | ||
return this.baseFs.symlinkSync(target, p, type); | ||
}, (zipFs, { subPath }) => { | ||
@@ -460,0 +460,0 @@ return zipFs.symlinkSync(target, subPath); |
{ | ||
"name": "@yarnpkg/fslib", | ||
"version": "2.0.0-rc.16", | ||
"version": "2.0.0-rc.17", | ||
"main": "./lib/index.js", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@yarnpkg/libzip": "^2.0.0-rc.10", | ||
"tmp": "^0.1.0" | ||
"@yarnpkg/libzip": "^2.0.0-rc.10" | ||
}, | ||
@@ -10,0 +9,0 @@ "scripts": { |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
157428
1
4040
4
- Removedtmp@^0.1.0
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedtmp@0.1.0(transitive)
- Removedwrappy@1.0.2(transitive)