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

@file-services/utils

Package Overview
Dependencies
Maintainers
3
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 2.0.1 to 2.1.0

1

cjs/callbackify.js

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

catch (e) {
// tslint:disable-next-line: semicolon
callback(e);

@@ -17,0 +16,0 @@ }

72

cjs/create-extended-api.js

@@ -5,11 +5,11 @@ "use strict";

function createFileSystem(baseFs) {
return Object.assign({}, baseFs, createExtendedSyncActions(baseFs), { promises: Object.assign({}, baseFs.promises, createExtendedFileSystemPromiseActions(baseFs)) });
return Object.assign(Object.assign(Object.assign({}, baseFs), createExtendedSyncActions(baseFs)), { promises: Object.assign(Object.assign({}, baseFs.promises), createExtendedFileSystemPromiseActions(baseFs)) });
}
exports.createFileSystem = createFileSystem;
function createSyncFileSystem(baseFs) {
return Object.assign({}, baseFs, createExtendedSyncActions(baseFs));
return Object.assign(Object.assign({}, baseFs), createExtendedSyncActions(baseFs));
}
exports.createSyncFileSystem = createSyncFileSystem;
function createExtendedSyncActions(baseFs) {
const { statSync, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync, dirname, join, resolve } = baseFs;
const { statSync, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync, copyFileSync, dirname, join, resolve } = baseFs;
function fileExistsSync(filePath, statFn = statSync) {

@@ -35,5 +35,2 @@ try {

function ensureDirectorySync(directoryPath) {
if (directoryExistsSync(directoryPath)) {
return;
}
try {

@@ -43,2 +40,5 @@ mkdirSync(directoryPath);

catch (e) {
if (e && e.code === 'EEXIST') {
return;
}
const parentPath = dirname(directoryPath);

@@ -49,3 +49,10 @@ if (parentPath === directoryPath) {

ensureDirectorySync(parentPath);
mkdirSync(directoryPath);
try {
mkdirSync(directoryPath);
}
catch (e) {
if (!e || e.code !== 'EEXIST') {
throw e;
}
}
}

@@ -69,2 +76,3 @@ }

}
// TODO: replace with rmdirSync(path, {recursive: true}) once Node 12+
function removeSync(entryPath) {

@@ -102,3 +110,2 @@ const stats = lstatSync(entryPath);

if (printErrors) {
// tslint:disable-next-line: no-console
console.error(e);

@@ -137,2 +144,15 @@ }

}
function copyDirectorySync(sourcePath, destinationPath) {
ensureDirectorySync(destinationPath);
for (const item of readdirSync(sourcePath, { withFileTypes: true })) {
const sourceItemPath = join(sourcePath, item.name);
const destinationItemPath = join(destinationPath, item.name);
if (item.isFile()) {
copyFileSync(sourceItemPath, destinationItemPath);
}
else if (item.isDirectory()) {
copyDirectorySync(sourceItemPath, destinationItemPath);
}
}
}
return {

@@ -146,2 +166,3 @@ fileExistsSync,

findFilesSync: (rootDirectory, options) => findFilesSync(resolve(rootDirectory), options),
copyDirectorySync: (sourcePath, destinationPath) => copyDirectorySync(resolve(sourcePath), resolve(destinationPath)),
findClosestFileSync,

@@ -154,7 +175,7 @@ findFilesInAncestorsSync,

function createAsyncFileSystem(baseFs) {
return Object.assign({}, baseFs, { promises: Object.assign({}, baseFs.promises, createExtendedFileSystemPromiseActions(baseFs)) });
return Object.assign(Object.assign({}, baseFs), { promises: Object.assign(Object.assign({}, baseFs.promises), createExtendedFileSystemPromiseActions(baseFs)) });
}
exports.createAsyncFileSystem = createAsyncFileSystem;
function createExtendedFileSystemPromiseActions(baseFs) {
const { dirname, resolve, join, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } } = baseFs;
const { dirname, resolve, join, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile, copyFile } } = baseFs;
async function fileExists(filePath, statFn = stat) {

@@ -180,5 +201,2 @@ try {

async function ensureDirectory(directoryPath) {
if (await directoryExists(directoryPath)) {
return;
}
try {

@@ -188,2 +206,5 @@ await mkdir(directoryPath);

catch (e) {
if (e && e.code === 'EEXIST') {
return;
}
const parentPath = dirname(directoryPath);

@@ -194,3 +215,10 @@ if (parentPath === directoryPath) {

await ensureDirectory(parentPath);
await mkdir(directoryPath);
try {
await mkdir(directoryPath);
}
catch (e) {
if (!e || e.code !== 'EEXIST') {
throw e;
}
}
}

@@ -214,2 +242,3 @@ }

}
// TODO: replace with rmdir(path, {recursive: true}) once Node 12+
async function remove(entryPath) {

@@ -245,3 +274,2 @@ const stats = await lstat(entryPath);

if (printErrors) {
// tslint:disable-next-line: no-console
console.error(e);

@@ -280,2 +308,15 @@ }

}
async function copyDirectory(sourcePath, destinationPath) {
await ensureDirectory(destinationPath);
for (const item of await readdir(sourcePath, { withFileTypes: true })) {
const sourceItemPath = join(sourcePath, item.name);
const destinationItemPath = join(destinationPath, item.name);
if (item.isFile()) {
await copyFile(sourceItemPath, destinationItemPath);
}
else if (item.isDirectory()) {
await copyDirectory(sourceItemPath, destinationItemPath);
}
}
}
return {

@@ -288,2 +329,3 @@ fileExists,

findFiles: (rootDirectory, options) => findFiles(resolve(rootDirectory), options),
copyDirectory: (sourcePath, destinationPath) => copyDirectory(resolve(sourcePath), resolve(destinationPath)),
findClosestFile,

@@ -290,0 +332,0 @@ findFilesInAncestors,

export declare class SetMultiMap<K, V> implements Iterable<[K, V]> {
private map;
readonly size: number;
get size(): number;
get(key: K): ReadonlySet<V> | undefined;

@@ -5,0 +5,0 @@ add(key: K, value: V): this;

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

function syncToAsyncFs(syncFs) {
return Object.assign({}, syncFs, { watchService: syncFs.watchService, caseSensitive: syncFs.caseSensitive, promises: {
return Object.assign(Object.assign({}, syncFs), { watchService: syncFs.watchService, caseSensitive: syncFs.caseSensitive, promises: {
readFile: async function readFile(...args) {

@@ -8,0 +8,0 @@ return syncFs.readFileSync(...args);

@@ -12,3 +12,2 @@ export function callbackify(fn) {

catch (e) {
// tslint:disable-next-line: semicolon
callback(e);

@@ -15,0 +14,0 @@ }

const returnsTrue = () => true;
export function createFileSystem(baseFs) {
return Object.assign({}, baseFs, createExtendedSyncActions(baseFs), { promises: Object.assign({}, baseFs.promises, createExtendedFileSystemPromiseActions(baseFs)) });
return Object.assign(Object.assign(Object.assign({}, baseFs), createExtendedSyncActions(baseFs)), { promises: Object.assign(Object.assign({}, baseFs.promises), createExtendedFileSystemPromiseActions(baseFs)) });
}
export function createSyncFileSystem(baseFs) {
return Object.assign({}, baseFs, createExtendedSyncActions(baseFs));
return Object.assign(Object.assign({}, baseFs), createExtendedSyncActions(baseFs));
}
export function createExtendedSyncActions(baseFs) {
const { statSync, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync, dirname, join, resolve } = baseFs;
const { statSync, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync, copyFileSync, dirname, join, resolve } = baseFs;
function fileExistsSync(filePath, statFn = statSync) {

@@ -30,5 +30,2 @@ try {

function ensureDirectorySync(directoryPath) {
if (directoryExistsSync(directoryPath)) {
return;
}
try {

@@ -38,2 +35,5 @@ mkdirSync(directoryPath);

catch (e) {
if (e && e.code === 'EEXIST') {
return;
}
const parentPath = dirname(directoryPath);

@@ -44,3 +44,10 @@ if (parentPath === directoryPath) {

ensureDirectorySync(parentPath);
mkdirSync(directoryPath);
try {
mkdirSync(directoryPath);
}
catch (e) {
if (!e || e.code !== 'EEXIST') {
throw e;
}
}
}

@@ -64,2 +71,3 @@ }

}
// TODO: replace with rmdirSync(path, {recursive: true}) once Node 12+
function removeSync(entryPath) {

@@ -97,3 +105,2 @@ const stats = lstatSync(entryPath);

if (printErrors) {
// tslint:disable-next-line: no-console
console.error(e);

@@ -132,2 +139,15 @@ }

}
function copyDirectorySync(sourcePath, destinationPath) {
ensureDirectorySync(destinationPath);
for (const item of readdirSync(sourcePath, { withFileTypes: true })) {
const sourceItemPath = join(sourcePath, item.name);
const destinationItemPath = join(destinationPath, item.name);
if (item.isFile()) {
copyFileSync(sourceItemPath, destinationItemPath);
}
else if (item.isDirectory()) {
copyDirectorySync(sourceItemPath, destinationItemPath);
}
}
}
return {

@@ -141,2 +161,3 @@ fileExistsSync,

findFilesSync: (rootDirectory, options) => findFilesSync(resolve(rootDirectory), options),
copyDirectorySync: (sourcePath, destinationPath) => copyDirectorySync(resolve(sourcePath), resolve(destinationPath)),
findClosestFileSync,

@@ -148,6 +169,6 @@ findFilesInAncestorsSync,

export function createAsyncFileSystem(baseFs) {
return Object.assign({}, baseFs, { promises: Object.assign({}, baseFs.promises, createExtendedFileSystemPromiseActions(baseFs)) });
return Object.assign(Object.assign({}, baseFs), { promises: Object.assign(Object.assign({}, baseFs.promises), createExtendedFileSystemPromiseActions(baseFs)) });
}
export function createExtendedFileSystemPromiseActions(baseFs) {
const { dirname, resolve, join, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } } = baseFs;
const { dirname, resolve, join, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile, copyFile } } = baseFs;
async function fileExists(filePath, statFn = stat) {

@@ -173,5 +194,2 @@ try {

async function ensureDirectory(directoryPath) {
if (await directoryExists(directoryPath)) {
return;
}
try {

@@ -181,2 +199,5 @@ await mkdir(directoryPath);

catch (e) {
if (e && e.code === 'EEXIST') {
return;
}
const parentPath = dirname(directoryPath);

@@ -187,3 +208,10 @@ if (parentPath === directoryPath) {

await ensureDirectory(parentPath);
await mkdir(directoryPath);
try {
await mkdir(directoryPath);
}
catch (e) {
if (!e || e.code !== 'EEXIST') {
throw e;
}
}
}

@@ -207,2 +235,3 @@ }

}
// TODO: replace with rmdir(path, {recursive: true}) once Node 12+
async function remove(entryPath) {

@@ -238,3 +267,2 @@ const stats = await lstat(entryPath);

if (printErrors) {
// tslint:disable-next-line: no-console
console.error(e);

@@ -273,2 +301,15 @@ }

}
async function copyDirectory(sourcePath, destinationPath) {
await ensureDirectory(destinationPath);
for (const item of await readdir(sourcePath, { withFileTypes: true })) {
const sourceItemPath = join(sourcePath, item.name);
const destinationItemPath = join(destinationPath, item.name);
if (item.isFile()) {
await copyFile(sourceItemPath, destinationItemPath);
}
else if (item.isDirectory()) {
await copyDirectory(sourceItemPath, destinationItemPath);
}
}
}
return {

@@ -281,2 +322,3 @@ fileExists,

findFiles: (rootDirectory, options) => findFiles(resolve(rootDirectory), options),
copyDirectory: (sourcePath, destinationPath) => copyDirectory(resolve(sourcePath), resolve(destinationPath)),
findClosestFile,

@@ -283,0 +325,0 @@ findFilesInAncestors,

export declare class SetMultiMap<K, V> implements Iterable<[K, V]> {
private map;
readonly size: number;
get size(): number;
get(key: K): ReadonlySet<V> | undefined;

@@ -5,0 +5,0 @@ add(key: K, value: V): this;

import { callbackify } from './callbackify';
export function syncToAsyncFs(syncFs) {
return Object.assign({}, syncFs, { watchService: syncFs.watchService, caseSensitive: syncFs.caseSensitive, promises: {
return Object.assign(Object.assign({}, syncFs), { watchService: syncFs.watchService, caseSensitive: syncFs.caseSensitive, promises: {
readFile: async function readFile(...args) {

@@ -5,0 +5,0 @@ return syncFs.readFileSync(...args);

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

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

"dependencies": {
"@file-services/types": "^2.0.1"
"@file-services/types": "^2.1.0"
},

@@ -20,4 +20,3 @@ "files": [

"esm",
"src",
"!src/tsconfig.json"
"src"
],

@@ -31,3 +30,3 @@ "license": "MIT",

"sideEffects": false,
"gitHead": "fc4bf2d1f67151dfd6357fcda60bc0c43f6a10d6"
"gitHead": "d0f4daec4165377749c39bb159c24b6e0808fae4"
}

@@ -33,3 +33,2 @@ import { CallbackFn, ErrorCallbackFn } from '@file-services/types';

} catch (e) {
// tslint:disable-next-line: semicolon
(callback as ErrorCallbackFn)(e);

@@ -36,0 +35,0 @@ }

@@ -46,2 +46,3 @@ import {

readFileSync,
copyFileSync,
dirname,

@@ -76,8 +77,8 @@ join,

function ensureDirectorySync(directoryPath: string): void {
if (directoryExistsSync(directoryPath)) {
return;
}
try {
mkdirSync(directoryPath);
} catch (e) {
if (e && e.code === 'EEXIST') {
return;
}
const parentPath = dirname(directoryPath);

@@ -88,3 +89,9 @@ if (parentPath === directoryPath) {

ensureDirectorySync(parentPath);
mkdirSync(directoryPath);
try {
mkdirSync(directoryPath);
} catch (e) {
if (!e || e.code !== 'EEXIST') {
throw e;
}
}
}

@@ -109,2 +116,3 @@ }

// TODO: replace with rmdirSync(path, {recursive: true}) once Node 12+
function removeSync(entryPath: string): void {

@@ -140,3 +148,2 @@ const stats = lstatSync(entryPath);

if (printErrors) {
// tslint:disable-next-line: no-console
console.error(e);

@@ -183,2 +190,15 @@ }

function copyDirectorySync(sourcePath: string, destinationPath: string): void {
ensureDirectorySync(destinationPath);
for (const item of readdirSync(sourcePath, { withFileTypes: true })) {
const sourceItemPath = join(sourcePath, item.name);
const destinationItemPath = join(destinationPath, item.name);
if (item.isFile()) {
copyFileSync(sourceItemPath, destinationItemPath);
} else if (item.isDirectory()) {
copyDirectorySync(sourceItemPath, destinationItemPath);
}
}
}
return {

@@ -192,2 +212,4 @@ fileExistsSync,

findFilesSync: (rootDirectory, options) => findFilesSync(resolve(rootDirectory), options),
copyDirectorySync: (sourcePath, destinationPath) =>
copyDirectorySync(resolve(sourcePath), resolve(destinationPath)),
findClosestFileSync,

@@ -216,3 +238,3 @@ findFilesInAncestorsSync,

join,
promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile }
promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile, copyFile }
} = baseFs;

@@ -244,8 +266,8 @@

async function ensureDirectory(directoryPath: string): Promise<void> {
if (await directoryExists(directoryPath)) {
return;
}
try {
await mkdir(directoryPath);
} catch (e) {
if (e && e.code === 'EEXIST') {
return;
}
const parentPath = dirname(directoryPath);

@@ -256,3 +278,9 @@ if (parentPath === directoryPath) {

await ensureDirectory(parentPath);
await mkdir(directoryPath);
try {
await mkdir(directoryPath);
} catch (e) {
if (!e || e.code !== 'EEXIST') {
throw e;
}
}
}

@@ -277,2 +305,3 @@ }

// TODO: replace with rmdir(path, {recursive: true}) once Node 12+
async function remove(entryPath: string): Promise<void> {

@@ -310,3 +339,2 @@ const stats = await lstat(entryPath);

if (printErrors) {
// tslint:disable-next-line: no-console
console.error(e);

@@ -319,2 +347,3 @@ }

}
async function findClosestFile(initialDirectoryPath: string, fileName: string): Promise<string | undefined> {

@@ -353,2 +382,15 @@ let currentPath = resolve(initialDirectoryPath);

async function copyDirectory(sourcePath: string, destinationPath: string): Promise<void> {
await ensureDirectory(destinationPath);
for (const item of await readdir(sourcePath, { withFileTypes: true })) {
const sourceItemPath = join(sourcePath, item.name);
const destinationItemPath = join(destinationPath, item.name);
if (item.isFile()) {
await copyFile(sourceItemPath, destinationItemPath);
} else if (item.isDirectory()) {
await copyDirectory(sourceItemPath, destinationItemPath);
}
}
}
return {

@@ -361,2 +403,3 @@ fileExists,

findFiles: (rootDirectory, options) => findFiles(resolve(rootDirectory), options),
copyDirectory: (sourcePath, destinationPath) => copyDirectory(resolve(sourcePath), resolve(destinationPath)),
findClosestFile,

@@ -363,0 +406,0 @@ findFilesInAncestors,

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