@yarnpkg/fslib
Advanced tools
Comparing version 2.0.0-rc.5 to 2.0.0-rc.6
@@ -14,3 +14,3 @@ /// <reference types="node" /> | ||
export { ParsedPath, PathUtils, FormatInputPathObject } from './path'; | ||
export { npath, ppath, toFilename, fromPortablePath, toPortablePath } from './path'; | ||
export { npath, ppath, toFilename } from './path'; | ||
export { AliasFS } from './AliasFS'; | ||
@@ -21,2 +21,3 @@ export { FakeFS } from './FakeFS'; | ||
export { LazyFS } from './LazyFS'; | ||
export { NoFS } from './NoFS'; | ||
export { NodeFS } from './NodeFS'; | ||
@@ -23,0 +24,0 @@ export { PosixFS } from './PosixFS'; |
@@ -8,10 +8,9 @@ "use strict"; | ||
const NodeFS_1 = require("./NodeFS"); | ||
var path_1 = require("./path"); | ||
exports.PortablePath = path_1.PortablePath; | ||
const path_1 = require("./path"); | ||
var path_2 = require("./path"); | ||
exports.npath = path_2.npath; | ||
exports.ppath = path_2.ppath; | ||
exports.toFilename = path_2.toFilename; | ||
exports.fromPortablePath = path_2.fromPortablePath; | ||
exports.toPortablePath = path_2.toPortablePath; | ||
exports.PortablePath = path_2.PortablePath; | ||
var path_3 = require("./path"); | ||
exports.npath = path_3.npath; | ||
exports.ppath = path_3.ppath; | ||
exports.toFilename = path_3.toFilename; | ||
var AliasFS_1 = require("./AliasFS"); | ||
@@ -27,2 +26,4 @@ exports.AliasFS = AliasFS_1.AliasFS; | ||
exports.LazyFS = LazyFS_1.LazyFS; | ||
var NoFS_1 = require("./NoFS"); | ||
exports.NoFS = NoFS_1.NoFS; | ||
var NodeFS_2 = require("./NodeFS"); | ||
@@ -150,7 +151,7 @@ exports.NodeFS = NodeFS_2.NodeFS; | ||
if (typeof cb === `undefined`) { | ||
return NodeFS_1.NodeFS.toPortablePath(name); | ||
return path_1.npath.toPortablePath(name); | ||
} | ||
else { | ||
try { | ||
return cb(NodeFS_1.NodeFS.toPortablePath(name)); | ||
return cb(path_1.npath.toPortablePath(name)); | ||
} | ||
@@ -170,3 +171,3 @@ finally { | ||
else { | ||
resolve(NodeFS_1.NodeFS.toPortablePath(path)); | ||
resolve(path_1.npath.toPortablePath(path)); | ||
} | ||
@@ -183,3 +184,3 @@ }); | ||
else { | ||
Promise.resolve(NodeFS_1.NodeFS.toPortablePath(path)).then(cb).then(result => { | ||
Promise.resolve(path_1.npath.toPortablePath(path)).then(cb).then(result => { | ||
cleanup(); | ||
@@ -186,0 +187,0 @@ resolve(result); |
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
import { WatchOptions, WatchCallback, Watcher } from './FakeFS'; | ||
import { FSPath, PortablePath, NativePath, Filename, Path } from './path'; | ||
import { FSPath, PortablePath, Filename } from './path'; | ||
export declare class NodeFS extends BasePortableFakeFS { | ||
@@ -65,4 +65,2 @@ private readonly realFs; | ||
private makeCallback; | ||
static fromPortablePath(p: Path): NativePath; | ||
static toPortablePath(p: Path): PortablePath; | ||
} |
@@ -9,3 +9,2 @@ "use strict"; | ||
const path_1 = require("./path"); | ||
const path_2 = require("./path"); | ||
class NodeFS extends FakeFS_1.BasePortableFakeFS { | ||
@@ -21,7 +20,7 @@ constructor(realFs = fs_1.default) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.open(NodeFS.fromPortablePath(p), flags, mode, this.makeCallback(resolve, reject)); | ||
this.realFs.open(path_1.npath.fromPortablePath(p), flags, mode, this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
openSync(p, flags, mode) { | ||
return this.realFs.openSync(NodeFS.fromPortablePath(p), flags, mode); | ||
return this.realFs.openSync(path_1.npath.fromPortablePath(p), flags, mode); | ||
} | ||
@@ -70,7 +69,7 @@ async readPromise(fd, buffer, offset = 0, length = 0, position = -1) { | ||
createReadStream(p, opts) { | ||
const realPath = (p !== null ? NodeFS.fromPortablePath(p) : p); | ||
const realPath = (p !== null ? path_1.npath.fromPortablePath(p) : p); | ||
return this.realFs.createReadStream(realPath, opts); | ||
} | ||
createWriteStream(p, opts) { | ||
const realPath = (p !== null ? NodeFS.fromPortablePath(p) : p); | ||
const realPath = (p !== null ? path_1.npath.fromPortablePath(p) : p); | ||
return this.realFs.createWriteStream(realPath, opts); | ||
@@ -80,69 +79,69 @@ } | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.realpath(NodeFS.fromPortablePath(p), {}, this.makeCallback(resolve, reject)); | ||
this.realFs.realpath(path_1.npath.fromPortablePath(p), {}, this.makeCallback(resolve, reject)); | ||
}).then(path => { | ||
return NodeFS.toPortablePath(path); | ||
return path_1.npath.toPortablePath(path); | ||
}); | ||
} | ||
realpathSync(p) { | ||
return NodeFS.toPortablePath(this.realFs.realpathSync(NodeFS.fromPortablePath(p), {})); | ||
return path_1.npath.toPortablePath(this.realFs.realpathSync(path_1.npath.fromPortablePath(p), {})); | ||
} | ||
async existsPromise(p) { | ||
return await new Promise(resolve => { | ||
this.realFs.exists(NodeFS.fromPortablePath(p), resolve); | ||
this.realFs.exists(path_1.npath.fromPortablePath(p), resolve); | ||
}); | ||
} | ||
accessSync(p, mode) { | ||
return this.realFs.accessSync(NodeFS.fromPortablePath(p), mode); | ||
return this.realFs.accessSync(path_1.npath.fromPortablePath(p), mode); | ||
} | ||
async accessPromise(p, mode) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.access(NodeFS.fromPortablePath(p), mode, this.makeCallback(resolve, reject)); | ||
this.realFs.access(path_1.npath.fromPortablePath(p), mode, this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
existsSync(p) { | ||
return this.realFs.existsSync(NodeFS.fromPortablePath(p)); | ||
return this.realFs.existsSync(path_1.npath.fromPortablePath(p)); | ||
} | ||
async statPromise(p) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.stat(NodeFS.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
this.realFs.stat(path_1.npath.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
statSync(p) { | ||
return this.realFs.statSync(NodeFS.fromPortablePath(p)); | ||
return this.realFs.statSync(path_1.npath.fromPortablePath(p)); | ||
} | ||
async lstatPromise(p) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.lstat(NodeFS.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
this.realFs.lstat(path_1.npath.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
lstatSync(p) { | ||
return this.realFs.lstatSync(NodeFS.fromPortablePath(p)); | ||
return this.realFs.lstatSync(path_1.npath.fromPortablePath(p)); | ||
} | ||
async chmodPromise(p, mask) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.chmod(NodeFS.fromPortablePath(p), mask, this.makeCallback(resolve, reject)); | ||
this.realFs.chmod(path_1.npath.fromPortablePath(p), mask, this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
chmodSync(p, mask) { | ||
return this.realFs.chmodSync(NodeFS.fromPortablePath(p), mask); | ||
return this.realFs.chmodSync(path_1.npath.fromPortablePath(p), mask); | ||
} | ||
async renamePromise(oldP, newP) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.rename(NodeFS.fromPortablePath(oldP), NodeFS.fromPortablePath(newP), this.makeCallback(resolve, reject)); | ||
this.realFs.rename(path_1.npath.fromPortablePath(oldP), path_1.npath.fromPortablePath(newP), this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
renameSync(oldP, newP) { | ||
return this.realFs.renameSync(NodeFS.fromPortablePath(oldP), NodeFS.fromPortablePath(newP)); | ||
return this.realFs.renameSync(path_1.npath.fromPortablePath(oldP), path_1.npath.fromPortablePath(newP)); | ||
} | ||
async copyFilePromise(sourceP, destP, flags = 0) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.copyFile(NodeFS.fromPortablePath(sourceP), NodeFS.fromPortablePath(destP), flags, this.makeCallback(resolve, reject)); | ||
this.realFs.copyFile(path_1.npath.fromPortablePath(sourceP), path_1.npath.fromPortablePath(destP), flags, this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
copyFileSync(sourceP, destP, flags = 0) { | ||
return this.realFs.copyFileSync(NodeFS.fromPortablePath(sourceP), NodeFS.fromPortablePath(destP), flags); | ||
return this.realFs.copyFileSync(path_1.npath.fromPortablePath(sourceP), path_1.npath.fromPortablePath(destP), flags); | ||
} | ||
async appendFilePromise(p, content, opts) { | ||
return await new Promise((resolve, reject) => { | ||
const fsNativePath = typeof p === `string` ? NodeFS.fromPortablePath(p) : p; | ||
const fsNativePath = typeof p === `string` ? path_1.npath.fromPortablePath(p) : p; | ||
if (opts) { | ||
@@ -157,3 +156,3 @@ this.realFs.appendFile(fsNativePath, content, opts, this.makeCallback(resolve, reject)); | ||
appendFileSync(p, content, opts) { | ||
const fsNativePath = typeof p === `string` ? NodeFS.fromPortablePath(p) : p; | ||
const fsNativePath = typeof p === `string` ? path_1.npath.fromPortablePath(p) : p; | ||
if (opts) { | ||
@@ -168,3 +167,3 @@ this.realFs.appendFileSync(fsNativePath, content, opts); | ||
return await new Promise((resolve, reject) => { | ||
const fsNativePath = typeof p === `string` ? NodeFS.fromPortablePath(p) : p; | ||
const fsNativePath = typeof p === `string` ? path_1.npath.fromPortablePath(p) : p; | ||
if (opts) { | ||
@@ -179,3 +178,3 @@ this.realFs.writeFile(fsNativePath, content, opts, this.makeCallback(resolve, reject)); | ||
writeFileSync(p, content, opts) { | ||
const fsNativePath = typeof p === `string` ? NodeFS.fromPortablePath(p) : p; | ||
const fsNativePath = typeof p === `string` ? path_1.npath.fromPortablePath(p) : p; | ||
if (opts) { | ||
@@ -190,31 +189,31 @@ this.realFs.writeFileSync(fsNativePath, content, opts); | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.unlink(NodeFS.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
this.realFs.unlink(path_1.npath.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
unlinkSync(p) { | ||
return this.realFs.unlinkSync(NodeFS.fromPortablePath(p)); | ||
return this.realFs.unlinkSync(path_1.npath.fromPortablePath(p)); | ||
} | ||
async utimesPromise(p, atime, mtime) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.utimes(NodeFS.fromPortablePath(p), atime, mtime, this.makeCallback(resolve, reject)); | ||
this.realFs.utimes(path_1.npath.fromPortablePath(p), atime, mtime, this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
utimesSync(p, atime, mtime) { | ||
this.realFs.utimesSync(NodeFS.fromPortablePath(p), atime, mtime); | ||
this.realFs.utimesSync(path_1.npath.fromPortablePath(p), atime, mtime); | ||
} | ||
async mkdirPromise(p) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.mkdir(NodeFS.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
this.realFs.mkdir(path_1.npath.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
mkdirSync(p) { | ||
return this.realFs.mkdirSync(NodeFS.fromPortablePath(p)); | ||
return this.realFs.mkdirSync(path_1.npath.fromPortablePath(p)); | ||
} | ||
async rmdirPromise(p) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.rmdir(NodeFS.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
this.realFs.rmdir(path_1.npath.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
rmdirSync(p) { | ||
return this.realFs.rmdirSync(NodeFS.fromPortablePath(p)); | ||
return this.realFs.rmdirSync(path_1.npath.fromPortablePath(p)); | ||
} | ||
@@ -224,3 +223,3 @@ async symlinkPromise(target, p) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.symlink(NodeFS.fromPortablePath(target.replace(/\/+$/, ``)), NodeFS.fromPortablePath(p), type, this.makeCallback(resolve, reject)); | ||
this.realFs.symlink(path_1.npath.fromPortablePath(target.replace(/\/+$/, ``)), path_1.npath.fromPortablePath(p), type, this.makeCallback(resolve, reject)); | ||
}); | ||
@@ -230,7 +229,7 @@ } | ||
const type = target.endsWith(`/`) ? `dir` : `file`; | ||
return this.realFs.symlinkSync(NodeFS.fromPortablePath(target.replace(/\/+$/, ``)), NodeFS.fromPortablePath(p), type); | ||
return this.realFs.symlinkSync(path_1.npath.fromPortablePath(target.replace(/\/+$/, ``)), path_1.npath.fromPortablePath(p), type); | ||
} | ||
async readFilePromise(p, encoding) { | ||
return await new Promise((resolve, reject) => { | ||
const fsNativePath = typeof p === `string` ? NodeFS.fromPortablePath(p) : p; | ||
const fsNativePath = typeof p === `string` ? path_1.npath.fromPortablePath(p) : p; | ||
this.realFs.readFile(fsNativePath, encoding, this.makeCallback(resolve, reject)); | ||
@@ -240,3 +239,3 @@ }); | ||
readFileSync(p, encoding) { | ||
const fsNativePath = typeof p === `string` ? NodeFS.fromPortablePath(p) : p; | ||
const fsNativePath = typeof p === `string` ? path_1.npath.fromPortablePath(p) : p; | ||
return this.realFs.readFileSync(fsNativePath, encoding); | ||
@@ -246,20 +245,20 @@ } | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.readdir(NodeFS.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
this.realFs.readdir(path_1.npath.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
}); | ||
} | ||
readdirSync(p) { | ||
return this.realFs.readdirSync(NodeFS.fromPortablePath(p)); | ||
return this.realFs.readdirSync(path_1.npath.fromPortablePath(p)); | ||
} | ||
async readlinkPromise(p) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.readlink(NodeFS.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
this.realFs.readlink(path_1.npath.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
}).then(path => { | ||
return NodeFS.toPortablePath(path); | ||
return path_1.npath.toPortablePath(path); | ||
}); | ||
} | ||
readlinkSync(p) { | ||
return NodeFS.toPortablePath(this.realFs.readlinkSync(NodeFS.fromPortablePath(p))); | ||
return path_1.npath.toPortablePath(this.realFs.readlinkSync(path_1.npath.fromPortablePath(p))); | ||
} | ||
watch(p, a, b) { | ||
return this.realFs.watch(NodeFS.fromPortablePath(p), | ||
return this.realFs.watch(path_1.npath.fromPortablePath(p), | ||
// @ts-ignore | ||
@@ -278,9 +277,3 @@ a, b); | ||
} | ||
static fromPortablePath(p) { | ||
return path_2.fromPortablePath(p); | ||
} | ||
static toPortablePath(p) { | ||
return path_2.toPortablePath(p); | ||
} | ||
} | ||
exports.NodeFS = NodeFS; |
@@ -16,3 +16,3 @@ export declare type PortablePath = string & { | ||
export declare type FSPath<T extends Path> = T | number; | ||
export declare const npath: PathUtils<NativePath>; | ||
export declare const npath: PathUtils<NativePath> & ConvertUtils; | ||
export declare const ppath: PathUtils<PortablePath>; | ||
@@ -46,6 +46,9 @@ export interface ParsedPath<P extends Path> { | ||
format(pathObject: FormatInputPathObject<P>): P; | ||
contains(from: P, to: P): P | null; | ||
} | ||
export declare function fromPortablePath(p: Path): NativePath; | ||
export declare function toPortablePath(p: Path): PortablePath; | ||
export interface ConvertUtils { | ||
fromPortablePath: (p: PortablePath) => NativePath; | ||
toPortablePath: (p: NativePath) => PortablePath; | ||
} | ||
export declare function convertPath<P extends Path>(targetPathUtils: PathUtils<P>, sourcePath: Path): P; | ||
export declare function toFilename(filename: string): Filename; |
@@ -11,4 +11,22 @@ "use strict"; | ||
}; | ||
exports.npath = path_1.default; | ||
exports.ppath = path_1.default.posix; | ||
exports.npath = Object.create(path_1.default); | ||
exports.ppath = Object.create(path_1.default.posix); | ||
const contains = function (pathUtils, from, to) { | ||
from = pathUtils.normalize(from); | ||
to = pathUtils.normalize(to); | ||
if (from === to) | ||
return `.`; | ||
if (!from.endsWith(pathUtils.sep)) | ||
from = (from + pathUtils.sep); | ||
if (to.startsWith(from)) { | ||
return to.slice(from.length); | ||
} | ||
else { | ||
return null; | ||
} | ||
}; | ||
exports.npath.fromPortablePath = fromPortablePath; | ||
exports.npath.toPortablePath = toPortablePath; | ||
exports.npath.contains = (from, to) => contains(exports.npath, from, to); | ||
exports.ppath.contains = (from, to) => contains(exports.ppath, from, to); | ||
const WINDOWS_PATH_REGEXP = /^[a-zA-Z]:.*$/; | ||
@@ -23,3 +41,2 @@ const PORTABLE_PATH_REGEXP = /^\/[a-zA-Z]:.*$/; | ||
} | ||
exports.fromPortablePath = fromPortablePath; | ||
// Path should look like "N:/berry/scripts/plugin-pack.js" | ||
@@ -32,3 +49,2 @@ // And transform to "/N:/berry/scripts/plugin-pack.js" | ||
} | ||
exports.toPortablePath = toPortablePath; | ||
function convertPath(targetPathUtils, sourcePath) { | ||
@@ -35,0 +51,0 @@ return (targetPathUtils === exports.npath ? fromPortablePath(sourcePath) : toPortablePath(sourcePath)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const NodeFS_1 = require("./NodeFS"); | ||
const ProxiedFS_1 = require("./ProxiedFS"); | ||
@@ -12,8 +11,8 @@ const path_1 = require("./path"); | ||
mapFromBase(path) { | ||
return NodeFS_1.NodeFS.fromPortablePath(path); | ||
return path_1.npath.fromPortablePath(path); | ||
} | ||
mapToBase(path) { | ||
return NodeFS_1.NodeFS.toPortablePath(path); | ||
return path_1.npath.toPortablePath(path); | ||
} | ||
} | ||
exports.PosixFS = PosixFS; |
@@ -129,3 +129,3 @@ "use strict"; | ||
if (typeof source === `string`) { | ||
this.zip = libzip_1.default.open(NodeFS_1.NodeFS.fromPortablePath(source), flags, errPtr); | ||
this.zip = libzip_1.default.open(path_1.npath.fromPortablePath(source), flags, errPtr); | ||
} | ||
@@ -132,0 +132,0 @@ else { |
{ | ||
"name": "@yarnpkg/fslib", | ||
"version": "2.0.0-rc.5", | ||
"version": "2.0.0-rc.6", | ||
"main": "./lib/index.js", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
138311
29
3447