Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@file-services/utils

Package Overview
Dependencies
Maintainers
2
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@file-services/utils - npm Package Compare versions

Comparing version 0.4.10 to 0.4.11

82

cjs/directory-fs.js

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

const posixPath = path_1.default.posix || path_1.default;
const POSIX_ROOT = '/';
/**

@@ -21,10 +22,9 @@ * Creates a wrapped `IFileSystem` which scopes the provided `fs`

const { join, relative, sep } = fs.path;
function joinPath(path) {
const joinedPath = join(directoryPath, path);
const relativePath = relative(directoryPath, joinedPath);
if (relativePath.startsWith(`..${sep}`)) {
throw new Error(`path ${path} is outside of scoped directory`);
}
return joinedPath;
let workingDirectoryPath = POSIX_ROOT;
function resolveScopedPath(...pathSegments) {
return posixPath.resolve(workingDirectoryPath, ...pathSegments);
}
function resolveFullPath(path) {
return join(directoryPath, resolveScopedPath(path));
}
const scopedListeners = new WeakMap();

@@ -39,3 +39,3 @@ function createScopedListener(listener) {

// use posixPath to ensure we give posix-style paths back
path: posixPath.join('/', relativeEventPath)
path: posixPath.join(POSIX_ROOT, relativeEventPath)
});

@@ -52,3 +52,3 @@ }

}
return watchService.watchPath(joinPath(path), listener);
return watchService.watchPath(resolveFullPath(path), listener);
},

@@ -59,3 +59,3 @@ async unwatchPath(path, listener) {

}
return watchService.unwatchPath(joinPath(path), listener);
return watchService.unwatchPath(resolveFullPath(path), listener);
},

@@ -76,76 +76,88 @@ async unwatchAllPaths() {

const scopedBaseFs = {
path: fs.path,
path: Object.assign({}, fs.path, { resolve: resolveScopedPath }),
caseSensitive: fs.caseSensitive,
watchService: scopedWatchService,
cwd() {
return workingDirectoryPath;
},
chdir(path) {
workingDirectoryPath = resolveScopedPath(path);
},
async copyFile(src, dest, flags) {
return fs.copyFile(joinPath(src), joinPath(dest), flags);
return fs.copyFile(resolveFullPath(src), resolveFullPath(dest), flags);
},
copyFileSync(src, dest, flags) {
return fs.copyFileSync(joinPath(src), joinPath(dest), flags);
return fs.copyFileSync(resolveFullPath(src), resolveFullPath(dest), flags);
},
async lstat(path) {
return fs.lstat(joinPath(path));
return fs.lstat(resolveFullPath(path));
},
lstatSync(path) {
return fs.lstatSync(joinPath(path));
return fs.lstatSync(resolveFullPath(path));
},
async mkdir(path) {
return fs.mkdir(joinPath(path));
return fs.mkdir(resolveFullPath(path));
},
mkdirSync(path) {
return fs.mkdirSync(joinPath(path));
return fs.mkdirSync(resolveFullPath(path));
},
async readdir(path) {
return fs.readdir(joinPath(path));
return fs.readdir(resolveFullPath(path));
},
readdirSync(path) {
return fs.readdirSync(joinPath(path));
return fs.readdirSync(resolveFullPath(path));
},
async readFile(path, encoding) {
return fs.readFile(joinPath(path), encoding);
return fs.readFile(resolveFullPath(path), encoding);
},
readFileSync(path, encoding) {
return fs.readFileSync(joinPath(path), encoding);
return fs.readFileSync(resolveFullPath(path), encoding);
},
async readFileRaw(path) {
return fs.readFileRaw(joinPath(path));
return fs.readFileRaw(resolveFullPath(path));
},
readFileRawSync(path) {
return fs.readFileRawSync(joinPath(path));
return fs.readFileRawSync(resolveFullPath(path));
},
async realpath(path) {
return fs.realpath(joinPath(path));
return fs.realpath(resolveFullPath(path));
},
realpathSync(path) {
return fs.realpathSync(joinPath(path));
return fs.realpathSync(resolveFullPath(path));
},
async rename(path, newPath) {
return fs.rename(joinPath(path), joinPath(newPath));
return fs.rename(resolveFullPath(path), resolveFullPath(newPath));
},
renameSync(path, newPath) {
return fs.renameSync(joinPath(path), joinPath(newPath));
return fs.renameSync(resolveFullPath(path), resolveFullPath(newPath));
},
async rmdir(path) {
return fs.rmdir(joinPath(path));
return fs.rmdir(resolveFullPath(path));
},
rmdirSync(path) {
return fs.rmdirSync(joinPath(path));
return fs.rmdirSync(resolveFullPath(path));
},
async exists(path) {
return fs.exists(resolveFullPath(path));
},
existsSync(path) {
return fs.existsSync(resolveFullPath(path));
},
async stat(path) {
return fs.stat(joinPath(path));
return fs.stat(resolveFullPath(path));
},
statSync(path) {
return fs.statSync(joinPath(path));
return fs.statSync(resolveFullPath(path));
},
async unlink(path) {
return fs.unlink(joinPath(path));
return fs.unlink(resolveFullPath(path));
},
unlinkSync(path) {
return fs.unlinkSync(joinPath(path));
return fs.unlinkSync(resolveFullPath(path));
},
async writeFile(path, content, encoding) {
return fs.writeFile(joinPath(path), content, encoding);
return fs.writeFile(resolveFullPath(path), content, encoding);
},
writeFileSync(path, content, encoding) {
return fs.writeFileSync(joinPath(path), content, encoding);
return fs.writeFileSync(resolveFullPath(path), content, encoding);
}

@@ -152,0 +164,0 @@ };

@@ -8,3 +8,5 @@ "use strict";

get size() {
return Array.from(this.map.values()).map(({ size }) => size).reduce((sum, size) => sum + size, 0);
return Array.from(this.map.values())
.map(({ size }) => size)
.reduce((sum, size) => sum + size, 0);
}

@@ -11,0 +13,0 @@ get(key) {

@@ -29,2 +29,5 @@ "use strict";

},
async exists(nodePath) {
return syncFs.existsSync(nodePath);
},
async stat(nodePath) {

@@ -31,0 +34,0 @@ return syncFs.statSync(nodePath);

@@ -5,2 +5,3 @@ import pathMain from 'path';

const posixPath = pathMain.posix || pathMain;
const POSIX_ROOT = '/';
/**

@@ -16,10 +17,9 @@ * Creates a wrapped `IFileSystem` which scopes the provided `fs`

const { join, relative, sep } = fs.path;
function joinPath(path) {
const joinedPath = join(directoryPath, path);
const relativePath = relative(directoryPath, joinedPath);
if (relativePath.startsWith(`..${sep}`)) {
throw new Error(`path ${path} is outside of scoped directory`);
}
return joinedPath;
let workingDirectoryPath = POSIX_ROOT;
function resolveScopedPath(...pathSegments) {
return posixPath.resolve(workingDirectoryPath, ...pathSegments);
}
function resolveFullPath(path) {
return join(directoryPath, resolveScopedPath(path));
}
const scopedListeners = new WeakMap();

@@ -34,3 +34,3 @@ function createScopedListener(listener) {

// use posixPath to ensure we give posix-style paths back
path: posixPath.join('/', relativeEventPath)
path: posixPath.join(POSIX_ROOT, relativeEventPath)
});

@@ -47,3 +47,3 @@ }

}
return watchService.watchPath(joinPath(path), listener);
return watchService.watchPath(resolveFullPath(path), listener);
},

@@ -54,3 +54,3 @@ async unwatchPath(path, listener) {

}
return watchService.unwatchPath(joinPath(path), listener);
return watchService.unwatchPath(resolveFullPath(path), listener);
},

@@ -71,76 +71,88 @@ async unwatchAllPaths() {

const scopedBaseFs = {
path: fs.path,
path: Object.assign({}, fs.path, { resolve: resolveScopedPath }),
caseSensitive: fs.caseSensitive,
watchService: scopedWatchService,
cwd() {
return workingDirectoryPath;
},
chdir(path) {
workingDirectoryPath = resolveScopedPath(path);
},
async copyFile(src, dest, flags) {
return fs.copyFile(joinPath(src), joinPath(dest), flags);
return fs.copyFile(resolveFullPath(src), resolveFullPath(dest), flags);
},
copyFileSync(src, dest, flags) {
return fs.copyFileSync(joinPath(src), joinPath(dest), flags);
return fs.copyFileSync(resolveFullPath(src), resolveFullPath(dest), flags);
},
async lstat(path) {
return fs.lstat(joinPath(path));
return fs.lstat(resolveFullPath(path));
},
lstatSync(path) {
return fs.lstatSync(joinPath(path));
return fs.lstatSync(resolveFullPath(path));
},
async mkdir(path) {
return fs.mkdir(joinPath(path));
return fs.mkdir(resolveFullPath(path));
},
mkdirSync(path) {
return fs.mkdirSync(joinPath(path));
return fs.mkdirSync(resolveFullPath(path));
},
async readdir(path) {
return fs.readdir(joinPath(path));
return fs.readdir(resolveFullPath(path));
},
readdirSync(path) {
return fs.readdirSync(joinPath(path));
return fs.readdirSync(resolveFullPath(path));
},
async readFile(path, encoding) {
return fs.readFile(joinPath(path), encoding);
return fs.readFile(resolveFullPath(path), encoding);
},
readFileSync(path, encoding) {
return fs.readFileSync(joinPath(path), encoding);
return fs.readFileSync(resolveFullPath(path), encoding);
},
async readFileRaw(path) {
return fs.readFileRaw(joinPath(path));
return fs.readFileRaw(resolveFullPath(path));
},
readFileRawSync(path) {
return fs.readFileRawSync(joinPath(path));
return fs.readFileRawSync(resolveFullPath(path));
},
async realpath(path) {
return fs.realpath(joinPath(path));
return fs.realpath(resolveFullPath(path));
},
realpathSync(path) {
return fs.realpathSync(joinPath(path));
return fs.realpathSync(resolveFullPath(path));
},
async rename(path, newPath) {
return fs.rename(joinPath(path), joinPath(newPath));
return fs.rename(resolveFullPath(path), resolveFullPath(newPath));
},
renameSync(path, newPath) {
return fs.renameSync(joinPath(path), joinPath(newPath));
return fs.renameSync(resolveFullPath(path), resolveFullPath(newPath));
},
async rmdir(path) {
return fs.rmdir(joinPath(path));
return fs.rmdir(resolveFullPath(path));
},
rmdirSync(path) {
return fs.rmdirSync(joinPath(path));
return fs.rmdirSync(resolveFullPath(path));
},
async exists(path) {
return fs.exists(resolveFullPath(path));
},
existsSync(path) {
return fs.existsSync(resolveFullPath(path));
},
async stat(path) {
return fs.stat(joinPath(path));
return fs.stat(resolveFullPath(path));
},
statSync(path) {
return fs.statSync(joinPath(path));
return fs.statSync(resolveFullPath(path));
},
async unlink(path) {
return fs.unlink(joinPath(path));
return fs.unlink(resolveFullPath(path));
},
unlinkSync(path) {
return fs.unlinkSync(joinPath(path));
return fs.unlinkSync(resolveFullPath(path));
},
async writeFile(path, content, encoding) {
return fs.writeFile(joinPath(path), content, encoding);
return fs.writeFile(resolveFullPath(path), content, encoding);
},
writeFileSync(path, content, encoding) {
return fs.writeFileSync(joinPath(path), content, encoding);
return fs.writeFileSync(resolveFullPath(path), content, encoding);
}

@@ -147,0 +159,0 @@ };

@@ -6,3 +6,5 @@ export class SetMultiMap {

get size() {
return Array.from(this.map.values()).map(({ size }) => size).reduce((sum, size) => sum + size, 0);
return Array.from(this.map.values())
.map(({ size }) => size)
.reduce((sum, size) => sum + size, 0);
}

@@ -9,0 +11,0 @@ get(key) {

@@ -27,2 +27,5 @@ export function syncToAsyncFs(syncFs) {

},
async exists(nodePath) {
return syncFs.existsSync(nodePath);
},
async stat(nodePath) {

@@ -29,0 +32,0 @@ return syncFs.statSync(nodePath);

{
"name": "@file-services/utils",
"description": "Common file system utility functions.",
"version": "0.4.10",
"version": "0.4.11",
"main": "cjs/index.js",

@@ -17,3 +17,3 @@ "module": "esm/index.js",

"dependencies": {
"@file-services/types": "^0.4.10"
"@file-services/types": "^0.4.11"
},

@@ -33,3 +33,3 @@ "files": [

"sideEffects": false,
"gitHead": "2c80218e713807c3ec965708c78e14af3433bcba"
"gitHead": "d077e3795b175547ed2dbb821b90c12fbd29bcb5"
}

@@ -6,3 +6,4 @@ import { IBaseFileSystem, IFileSystem, WatchEventListener, IWatchService } from '@file-services/types'

// ugly workaround for webpack's polyfilled path not implementing posix
const posixPath = pathMain.posix as typeof pathMain || pathMain
const posixPath = (pathMain.posix as typeof pathMain) || pathMain
const POSIX_ROOT = '/'

@@ -20,11 +21,12 @@ /**

function joinPath(path: string) {
const joinedPath = join(directoryPath, path)
const relativePath = relative(directoryPath, joinedPath)
if (relativePath.startsWith(`..${sep}`)) {
throw new Error(`path ${path} is outside of scoped directory`)
}
return joinedPath
let workingDirectoryPath: string = POSIX_ROOT
function resolveScopedPath(...pathSegments: string[]): string {
return posixPath.resolve(workingDirectoryPath, ...pathSegments)
}
function resolveFullPath(path: string): string {
return join(directoryPath, resolveScopedPath(path))
}
const scopedListeners: WeakMap<WatchEventListener, WatchEventListener> = new WeakMap()

@@ -40,3 +42,3 @@

// use posixPath to ensure we give posix-style paths back
path: posixPath.join('/', relativeEventPath)
path: posixPath.join(POSIX_ROOT, relativeEventPath)
})

@@ -54,3 +56,3 @@ }

}
return watchService.watchPath(joinPath(path), listener)
return watchService.watchPath(resolveFullPath(path), listener)
},

@@ -61,3 +63,3 @@ async unwatchPath(path, listener) {

}
return watchService.unwatchPath(joinPath(path), listener)
return watchService.unwatchPath(resolveFullPath(path), listener)
},

@@ -79,76 +81,91 @@ async unwatchAllPaths() {

const scopedBaseFs: IBaseFileSystem = {
path: fs.path,
path: {
...fs.path,
resolve: resolveScopedPath
},
caseSensitive: fs.caseSensitive,
watchService: scopedWatchService,
cwd() {
return workingDirectoryPath
},
chdir(path) {
workingDirectoryPath = resolveScopedPath(path)
},
async copyFile(src, dest, flags) {
return fs.copyFile(joinPath(src), joinPath(dest), flags)
return fs.copyFile(resolveFullPath(src), resolveFullPath(dest), flags)
},
copyFileSync(src, dest, flags) {
return fs.copyFileSync(joinPath(src), joinPath(dest), flags)
return fs.copyFileSync(resolveFullPath(src), resolveFullPath(dest), flags)
},
async lstat(path) {
return fs.lstat(joinPath(path))
return fs.lstat(resolveFullPath(path))
},
lstatSync(path) {
return fs.lstatSync(joinPath(path))
return fs.lstatSync(resolveFullPath(path))
},
async mkdir(path) {
return fs.mkdir(joinPath(path))
return fs.mkdir(resolveFullPath(path))
},
mkdirSync(path) {
return fs.mkdirSync(joinPath(path))
return fs.mkdirSync(resolveFullPath(path))
},
async readdir(path) {
return fs.readdir(joinPath(path))
return fs.readdir(resolveFullPath(path))
},
readdirSync(path) {
return fs.readdirSync(joinPath(path))
return fs.readdirSync(resolveFullPath(path))
},
async readFile(path, encoding) {
return fs.readFile(joinPath(path), encoding)
return fs.readFile(resolveFullPath(path), encoding)
},
readFileSync(path, encoding) {
return fs.readFileSync(joinPath(path), encoding)
return fs.readFileSync(resolveFullPath(path), encoding)
},
async readFileRaw(path) {
return fs.readFileRaw(joinPath(path))
return fs.readFileRaw(resolveFullPath(path))
},
readFileRawSync(path) {
return fs.readFileRawSync(joinPath(path))
return fs.readFileRawSync(resolveFullPath(path))
},
async realpath(path) {
return fs.realpath(joinPath(path))
return fs.realpath(resolveFullPath(path))
},
realpathSync(path) {
return fs.realpathSync(joinPath(path))
return fs.realpathSync(resolveFullPath(path))
},
async rename(path, newPath) {
return fs.rename(joinPath(path), joinPath(newPath))
return fs.rename(resolveFullPath(path), resolveFullPath(newPath))
},
renameSync(path, newPath) {
return fs.renameSync(joinPath(path), joinPath(newPath))
return fs.renameSync(resolveFullPath(path), resolveFullPath(newPath))
},
async rmdir(path) {
return fs.rmdir(joinPath(path))
return fs.rmdir(resolveFullPath(path))
},
rmdirSync(path) {
return fs.rmdirSync(joinPath(path))
return fs.rmdirSync(resolveFullPath(path))
},
async exists(path) {
return fs.exists(resolveFullPath(path))
},
existsSync(path) {
return fs.existsSync(resolveFullPath(path))
},
async stat(path) {
return fs.stat(joinPath(path))
return fs.stat(resolveFullPath(path))
},
statSync(path) {
return fs.statSync(joinPath(path))
return fs.statSync(resolveFullPath(path))
},
async unlink(path) {
return fs.unlink(joinPath(path))
return fs.unlink(resolveFullPath(path))
},
unlinkSync(path) {
return fs.unlinkSync(joinPath(path))
return fs.unlinkSync(resolveFullPath(path))
},
async writeFile(path, content, encoding) {
return fs.writeFile(joinPath(path), content, encoding)
return fs.writeFile(resolveFullPath(path), content, encoding)
},
writeFileSync(path, content, encoding) {
return fs.writeFileSync(joinPath(path), content, encoding)
return fs.writeFileSync(resolveFullPath(path), content, encoding)
}

@@ -155,0 +172,0 @@ }

@@ -5,3 +5,5 @@ export class SetMultiMap<K, V> implements Iterable<[K, V]> {

public get size(): number {
return Array.from(this.map.values()).map(({ size }) => size).reduce((sum, size) => sum + size, 0)
return Array.from(this.map.values())
.map(({ size }) => size)
.reduce((sum, size) => sum + size, 0)
}

@@ -8,0 +10,0 @@

@@ -37,2 +37,6 @@ import { IBaseFileSystemSync, IBaseFileSystemAsync } from '@file-services/types'

async exists(nodePath) {
return syncFs.existsSync(nodePath)
},
async stat(nodePath) {

@@ -39,0 +43,0 @@ return syncFs.statSync(nodePath)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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