@file-services/utils
Advanced tools
Comparing version 0.4.11 to 1.0.0
@@ -1,4 +0,7 @@ | ||
import { IBaseFileSystemAsync, IBaseFileSystemSync, IFileSystemAsync, IFileSystemSync } from '@file-services/types'; | ||
import { IBaseFileSystemAsync, IBaseFileSystemSync, IFileSystemAsync, IFileSystemSync, IBaseFileSystem, IFileSystem, IFileSystemExtendedSyncActions, IFileSystemExtendedPromiseActions } from '@file-services/types'; | ||
export declare function createFileSystem(baseFs: IBaseFileSystem): IFileSystem; | ||
export declare function createSyncFileSystem(baseFs: IBaseFileSystemSync): IFileSystemSync; | ||
export declare function createExtendedSyncActions(baseFs: IBaseFileSystemSync): IFileSystemExtendedSyncActions; | ||
export declare function createAsyncFileSystem(baseFs: IBaseFileSystemAsync): IFileSystemAsync; | ||
export declare function createExtendedFileSystemPromiseActions(baseFs: IBaseFileSystemAsync): IFileSystemExtendedPromiseActions; | ||
//# sourceMappingURL=create-extended-api.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const returnsTrue = () => true; | ||
function createFileSystem(baseFs) { | ||
return Object.assign({}, baseFs, createExtendedSyncActions(baseFs), { promises: Object.assign({}, baseFs.promises, createExtendedFileSystemPromiseActions(baseFs)) }); | ||
} | ||
exports.createFileSystem = createFileSystem; | ||
function createSyncFileSystem(baseFs) { | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync } = baseFs; | ||
return Object.assign({}, baseFs, createExtendedSyncActions(baseFs)); | ||
} | ||
exports.createSyncFileSystem = createSyncFileSystem; | ||
function createExtendedSyncActions(baseFs) { | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync } = baseFs; | ||
function fileExistsSync(filePath, statFn = statSync) { | ||
@@ -14,2 +22,5 @@ try { | ||
} | ||
function readJsonFileSync(filePath, options) { | ||
return JSON.parse(readFileSync(filePath, options || 'utf8')); | ||
} | ||
function directoryExistsSync(directoryPath, statFn = statSync) { | ||
@@ -87,3 +98,3 @@ try { | ||
function findClosestFileSync(initialDirectoryPath, fileName) { | ||
let currentPath = initialDirectoryPath; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath; | ||
@@ -102,3 +113,3 @@ while (currentPath !== lastPath) { | ||
const filePaths = []; | ||
let currentPath = initialDirectoryPath; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath; | ||
@@ -115,14 +126,22 @@ while (currentPath !== lastPath) { | ||
} | ||
return Object.assign({}, baseFs, { fileExistsSync, | ||
return { | ||
fileExistsSync, | ||
directoryExistsSync, | ||
ensureDirectorySync, | ||
populateDirectorySync, | ||
removeSync, | ||
findFilesSync, | ||
// resolve path once for recursive functions | ||
ensureDirectorySync: directoryPath => ensureDirectorySync(path.resolve(directoryPath)), | ||
populateDirectorySync: (directoryPath, contents) => populateDirectorySync(path.resolve(directoryPath), contents), | ||
removeSync: entryPath => removeSync(path.resolve(entryPath)), | ||
findFilesSync: (rootDirectory, options) => findFilesSync(path.resolve(rootDirectory), options), | ||
findClosestFileSync, | ||
findFilesInAncestorsSync }); | ||
findFilesInAncestorsSync, | ||
readJsonFileSync | ||
}; | ||
} | ||
exports.createSyncFileSystem = createSyncFileSystem; | ||
exports.createExtendedSyncActions = createExtendedSyncActions; | ||
function createAsyncFileSystem(baseFs) { | ||
const { stat, path, mkdir, writeFile, lstat, rmdir, unlink, readdir } = baseFs; | ||
return Object.assign({}, baseFs, { promises: Object.assign({}, baseFs.promises, createExtendedFileSystemPromiseActions(baseFs)) }); | ||
} | ||
exports.createAsyncFileSystem = createAsyncFileSystem; | ||
function createExtendedFileSystemPromiseActions(baseFs) { | ||
const { path, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } } = baseFs; | ||
async function fileExists(filePath, statFn = stat) { | ||
@@ -144,2 +163,5 @@ try { | ||
} | ||
async function readJsonFile(filePath, options) { | ||
return JSON.parse(await readFile(filePath, options || 'utf8')); | ||
} | ||
async function ensureDirectory(directoryPath) { | ||
@@ -207,3 +229,3 @@ if (await directoryExists(directoryPath)) { | ||
async function findClosestFile(initialDirectoryPath, fileName) { | ||
let currentPath = initialDirectoryPath; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath; | ||
@@ -222,3 +244,3 @@ while (currentPath !== lastPath) { | ||
const filePaths = []; | ||
let currentPath = initialDirectoryPath; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath; | ||
@@ -235,12 +257,15 @@ while (currentPath !== lastPath) { | ||
} | ||
return Object.assign({}, baseFs, { fileExists, | ||
return { | ||
fileExists, | ||
directoryExists, | ||
ensureDirectory, | ||
populateDirectory, | ||
remove, | ||
findFiles, | ||
ensureDirectory: directoryPath => ensureDirectory(path.resolve(directoryPath)), | ||
populateDirectory: (directoryPath, contents) => populateDirectory(path.resolve(directoryPath), contents), | ||
remove: entryPath => remove(path.resolve(entryPath)), | ||
findFiles: (rootDirectory, options) => findFiles(path.resolve(rootDirectory), options), | ||
findClosestFile, | ||
findFilesInAncestors }); | ||
findFilesInAncestors, | ||
readJsonFile | ||
}; | ||
} | ||
exports.createAsyncFileSystem = createAsyncFileSystem; | ||
exports.createExtendedFileSystemPromiseActions = createExtendedFileSystemPromiseActions; | ||
//# sourceMappingURL=create-extended-api.js.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const types_1 = require("@file-services/types"); | ||
const create_extended_api_1 = require("./create-extended-api"); | ||
// ugly workaround for webpack's polyfilled path not implementing posix | ||
const posixPath = path_1.default.posix || path_1.default; | ||
const POSIX_ROOT = '/'; | ||
/** | ||
@@ -19,5 +13,6 @@ * Creates a wrapped `IFileSystem` which scopes the provided `fs` | ||
function createDirectoryFs(fs, directoryPath) { | ||
const { watchService } = fs; | ||
const { watchService, promises } = fs; | ||
const { join, relative, sep } = fs.path; | ||
let workingDirectoryPath = POSIX_ROOT; | ||
const posixPath = fs.path.posix || fs.path; | ||
let workingDirectoryPath = types_1.POSIX_ROOT; | ||
function resolveScopedPath(...pathSegments) { | ||
@@ -38,3 +33,3 @@ return posixPath.resolve(workingDirectoryPath, ...pathSegments); | ||
// use posixPath to ensure we give posix-style paths back | ||
path: posixPath.join(POSIX_ROOT, relativeEventPath) | ||
path: posixPath.join(types_1.POSIX_ROOT, relativeEventPath) | ||
}); | ||
@@ -82,84 +77,125 @@ } | ||
}, | ||
async copyFile(src, dest, flags) { | ||
return fs.copyFile(resolveFullPath(src), resolveFullPath(dest), flags); | ||
promises: { | ||
copyFile(srcPath, destPath, ...restArgs) { | ||
return promises.copyFile(resolveFullPath(srcPath), resolveFullPath(destPath), ...restArgs); | ||
}, | ||
lstat(path) { | ||
return promises.lstat(resolveFullPath(path)); | ||
}, | ||
mkdir(path) { | ||
return promises.mkdir(resolveFullPath(path)); | ||
}, | ||
readdir(path) { | ||
return promises.readdir(resolveFullPath(path)); | ||
}, | ||
readFile: function readFile(path, ...restArgs) { | ||
return promises.readFile(resolveFullPath(path), ...restArgs); | ||
}, | ||
realpath(path) { | ||
return promises.realpath(resolveFullPath(path)); | ||
}, | ||
rename(srcPath, destPath) { | ||
return promises.rename(resolveFullPath(srcPath), resolveFullPath(destPath)); | ||
}, | ||
rmdir(path) { | ||
return promises.rmdir(resolveFullPath(path)); | ||
}, | ||
exists(path) { | ||
return promises.exists(resolveFullPath(path)); | ||
}, | ||
stat(path) { | ||
return promises.stat(resolveFullPath(path)); | ||
}, | ||
unlink(path) { | ||
return promises.unlink(resolveFullPath(path)); | ||
}, | ||
writeFile(path, ...restArgs) { | ||
return promises.writeFile(resolveFullPath(path), ...restArgs); | ||
}, | ||
readlink(path) { | ||
return promises.readlink(resolveFullPath(path)); | ||
} | ||
}, | ||
copyFileSync(src, dest, flags) { | ||
return fs.copyFileSync(resolveFullPath(src), resolveFullPath(dest), flags); | ||
copyFileSync(src, dest, ...restArgs) { | ||
return fs.copyFileSync(resolveFullPath(src), resolveFullPath(dest), ...restArgs); | ||
}, | ||
async lstat(path) { | ||
return fs.lstat(resolveFullPath(path)); | ||
}, | ||
lstatSync(path) { | ||
return fs.lstatSync(resolveFullPath(path)); | ||
}, | ||
async mkdir(path) { | ||
return fs.mkdir(resolveFullPath(path)); | ||
}, | ||
mkdirSync(path) { | ||
return fs.mkdirSync(resolveFullPath(path)); | ||
}, | ||
async readdir(path) { | ||
return fs.readdir(resolveFullPath(path)); | ||
}, | ||
readdirSync(path) { | ||
return fs.readdirSync(resolveFullPath(path)); | ||
}, | ||
async readFile(path, encoding) { | ||
return fs.readFile(resolveFullPath(path), encoding); | ||
readFileSync: function readFileSync(path, ...restArgs) { | ||
return fs.readFileSync(resolveFullPath(path), ...restArgs); | ||
}, | ||
readFileSync(path, encoding) { | ||
return fs.readFileSync(resolveFullPath(path), encoding); | ||
}, | ||
async readFileRaw(path) { | ||
return fs.readFileRaw(resolveFullPath(path)); | ||
}, | ||
readFileRawSync(path) { | ||
return fs.readFileRawSync(resolveFullPath(path)); | ||
}, | ||
async realpath(path) { | ||
return fs.realpath(resolveFullPath(path)); | ||
}, | ||
realpathSync(path) { | ||
return fs.realpathSync(resolveFullPath(path)); | ||
}, | ||
async rename(path, newPath) { | ||
return fs.rename(resolveFullPath(path), resolveFullPath(newPath)); | ||
readlinkSync(path) { | ||
return fs.readlinkSync(resolveFullPath(path)); | ||
}, | ||
renameSync(path, newPath) { | ||
return fs.renameSync(resolveFullPath(path), resolveFullPath(newPath)); | ||
renameSync(srcPath, destPath) { | ||
return fs.renameSync(resolveFullPath(srcPath), resolveFullPath(destPath)); | ||
}, | ||
async rmdir(path) { | ||
return fs.rmdir(resolveFullPath(path)); | ||
}, | ||
rmdirSync(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(resolveFullPath(path)); | ||
}, | ||
statSync(path) { | ||
return fs.statSync(resolveFullPath(path)); | ||
}, | ||
async unlink(path) { | ||
return fs.unlink(resolveFullPath(path)); | ||
}, | ||
unlinkSync(path) { | ||
return fs.unlinkSync(resolveFullPath(path)); | ||
}, | ||
async writeFile(path, content, encoding) { | ||
return fs.writeFile(resolveFullPath(path), content, encoding); | ||
writeFileSync(path, ...restArgs) { | ||
return fs.writeFileSync(resolveFullPath(path), ...restArgs); | ||
}, | ||
writeFileSync(path, content, encoding) { | ||
return fs.writeFileSync(resolveFullPath(path), content, encoding); | ||
copyFile: function copyFile(srcPath, destPath, ...restArgs) { | ||
fs.copyFile(resolveFullPath(srcPath), resolveFullPath(destPath), ...restArgs); | ||
}, | ||
lstat(path, callback) { | ||
fs.lstat(resolveFullPath(path), callback); | ||
}, | ||
mkdir(path, callback) { | ||
fs.mkdir(resolveFullPath(path), callback); | ||
}, | ||
readdir(path, callback) { | ||
return fs.readdir(resolveFullPath(path), callback); | ||
}, | ||
readFile: function readFile(path, ...restArgs) { | ||
return fs.readFile(resolveFullPath(path), ...restArgs); | ||
}, | ||
realpath(path, callback) { | ||
return fs.realpath(resolveFullPath(path), callback); | ||
}, | ||
rename(path, newPath, callback) { | ||
return fs.rename(resolveFullPath(path), resolveFullPath(newPath), callback); | ||
}, | ||
rmdir(path, callback) { | ||
return fs.rmdir(resolveFullPath(path), callback); | ||
}, | ||
exists(path, callback) { | ||
return fs.exists(resolveFullPath(path), callback); | ||
}, | ||
stat(path, callback) { | ||
return fs.stat(resolveFullPath(path), callback); | ||
}, | ||
unlink(path, callback) { | ||
return fs.unlink(resolveFullPath(path), callback); | ||
}, | ||
writeFile: function writeFile(path, ...restArgs) { | ||
return fs.writeFile(resolveFullPath(path), ...restArgs); | ||
}, | ||
readlink(path, callback) { | ||
return fs.readlink(resolveFullPath(path), callback); | ||
} | ||
}; | ||
return Object.assign({}, scopedBaseFs, create_extended_api_1.createAsyncFileSystem(scopedBaseFs), create_extended_api_1.createSyncFileSystem(scopedBaseFs)); | ||
return create_extended_api_1.createFileSystem(scopedBaseFs); | ||
} | ||
exports.createDirectoryFs = createDirectoryFs; | ||
//# sourceMappingURL=directory-fs.js.map |
@@ -1,5 +0,5 @@ | ||
export { syncToAsyncFs } from './sync-to-async-fs'; | ||
export { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api'; | ||
export { createDirectoryFs } from './directory-fs'; | ||
export { SetMultiMap } from './set-multi-map'; | ||
export * from './sync-to-async-fs'; | ||
export * from './create-extended-api'; | ||
export * from './directory-fs'; | ||
export * from './set-multi-map'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var sync_to_async_fs_1 = require("./sync-to-async-fs"); | ||
exports.syncToAsyncFs = sync_to_async_fs_1.syncToAsyncFs; | ||
var create_extended_api_1 = require("./create-extended-api"); | ||
exports.createAsyncFileSystem = create_extended_api_1.createAsyncFileSystem; | ||
exports.createSyncFileSystem = create_extended_api_1.createSyncFileSystem; | ||
var directory_fs_1 = require("./directory-fs"); | ||
exports.createDirectoryFs = directory_fs_1.createDirectoryFs; | ||
var set_multi_map_1 = require("./set-multi-map"); | ||
exports.SetMultiMap = set_multi_map_1.SetMultiMap; | ||
__export(require("./sync-to-async-fs")); | ||
__export(require("./create-extended-api")); | ||
__export(require("./directory-fs")); | ||
__export(require("./set-multi-map")); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const callbackify_1 = require("./callbackify"); | ||
function syncToAsyncFs(syncFs) { | ||
@@ -8,41 +9,58 @@ return { | ||
caseSensitive: syncFs.caseSensitive, | ||
async readFile(filePath, encoding) { | ||
return syncFs.readFileSync(filePath, encoding); | ||
promises: { | ||
readFile: async function readFile(...args) { | ||
return syncFs.readFileSync(...args); | ||
}, | ||
async writeFile(...args) { | ||
return syncFs.writeFileSync(...args); | ||
}, | ||
async unlink(filePath) { | ||
return syncFs.unlinkSync(filePath); | ||
}, | ||
async readdir(directoryPath) { | ||
return syncFs.readdirSync(directoryPath); | ||
}, | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
}, | ||
async rmdir(directoryPath) { | ||
return syncFs.rmdirSync(directoryPath); | ||
}, | ||
async exists(nodePath) { | ||
return syncFs.existsSync(nodePath); | ||
}, | ||
async stat(nodePath) { | ||
return syncFs.statSync(nodePath); | ||
}, | ||
async lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath); | ||
}, | ||
async realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath); | ||
}, | ||
async rename(srcPath, destPath) { | ||
return syncFs.renameSync(srcPath, destPath); | ||
}, | ||
async copyFile(...args) { | ||
return syncFs.copyFileSync(...args); | ||
}, | ||
async readlink(path) { | ||
return syncFs.readlinkSync(path); | ||
} | ||
}, | ||
async readFileRaw(filePath) { | ||
return syncFs.readFileRawSync(filePath); | ||
exists(nodePath, callback) { | ||
callback(syncFs.existsSync(nodePath)); | ||
}, | ||
async writeFile(filePath, content, encoding) { | ||
return syncFs.writeFileSync(filePath, content, encoding); | ||
}, | ||
async unlink(filePath) { | ||
return syncFs.unlinkSync(filePath); | ||
}, | ||
async readdir(directoryPath) { | ||
return syncFs.readdirSync(directoryPath); | ||
}, | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
}, | ||
async rmdir(directoryPath) { | ||
return syncFs.rmdirSync(directoryPath); | ||
}, | ||
async exists(nodePath) { | ||
return syncFs.existsSync(nodePath); | ||
}, | ||
async stat(nodePath) { | ||
return syncFs.statSync(nodePath); | ||
}, | ||
async lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath); | ||
}, | ||
async realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath); | ||
}, | ||
async rename(path, newPath) { | ||
return syncFs.renameSync(path, newPath); | ||
}, | ||
async copyFile(src, dest, flags) { | ||
return syncFs.copyFileSync(src, dest, flags); | ||
} | ||
readFile: callbackify_1.callbackify(syncFs.readFileSync), | ||
writeFile: callbackify_1.callbackify(syncFs.writeFileSync), | ||
copyFile: callbackify_1.callbackify(syncFs.copyFileSync), | ||
unlink: callbackify_1.callbackify(syncFs.unlinkSync), | ||
readdir: callbackify_1.callbackify(syncFs.readdirSync), | ||
mkdir: callbackify_1.callbackify(syncFs.mkdirSync), | ||
rmdir: callbackify_1.callbackify(syncFs.rmdirSync), | ||
stat: callbackify_1.callbackify(syncFs.statSync), | ||
lstat: callbackify_1.callbackify(syncFs.lstatSync), | ||
realpath: callbackify_1.callbackify(syncFs.realpathSync), | ||
rename: callbackify_1.callbackify(syncFs.renameSync), | ||
readlink: callbackify_1.callbackify(syncFs.readlinkSync) | ||
}; | ||
@@ -49,0 +67,0 @@ } |
@@ -1,4 +0,7 @@ | ||
import { IBaseFileSystemAsync, IBaseFileSystemSync, IFileSystemAsync, IFileSystemSync } from '@file-services/types'; | ||
import { IBaseFileSystemAsync, IBaseFileSystemSync, IFileSystemAsync, IFileSystemSync, IBaseFileSystem, IFileSystem, IFileSystemExtendedSyncActions, IFileSystemExtendedPromiseActions } from '@file-services/types'; | ||
export declare function createFileSystem(baseFs: IBaseFileSystem): IFileSystem; | ||
export declare function createSyncFileSystem(baseFs: IBaseFileSystemSync): IFileSystemSync; | ||
export declare function createExtendedSyncActions(baseFs: IBaseFileSystemSync): IFileSystemExtendedSyncActions; | ||
export declare function createAsyncFileSystem(baseFs: IBaseFileSystemAsync): IFileSystemAsync; | ||
export declare function createExtendedFileSystemPromiseActions(baseFs: IBaseFileSystemAsync): IFileSystemExtendedPromiseActions; | ||
//# sourceMappingURL=create-extended-api.d.ts.map |
const returnsTrue = () => true; | ||
export function createFileSystem(baseFs) { | ||
return Object.assign({}, baseFs, createExtendedSyncActions(baseFs), { promises: Object.assign({}, baseFs.promises, createExtendedFileSystemPromiseActions(baseFs)) }); | ||
} | ||
export function createSyncFileSystem(baseFs) { | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync } = baseFs; | ||
return Object.assign({}, baseFs, createExtendedSyncActions(baseFs)); | ||
} | ||
export function createExtendedSyncActions(baseFs) { | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync } = baseFs; | ||
function fileExistsSync(filePath, statFn = statSync) { | ||
@@ -12,2 +18,5 @@ try { | ||
} | ||
function readJsonFileSync(filePath, options) { | ||
return JSON.parse(readFileSync(filePath, options || 'utf8')); | ||
} | ||
function directoryExistsSync(directoryPath, statFn = statSync) { | ||
@@ -85,3 +94,3 @@ try { | ||
function findClosestFileSync(initialDirectoryPath, fileName) { | ||
let currentPath = initialDirectoryPath; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath; | ||
@@ -100,3 +109,3 @@ while (currentPath !== lastPath) { | ||
const filePaths = []; | ||
let currentPath = initialDirectoryPath; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath; | ||
@@ -113,13 +122,20 @@ while (currentPath !== lastPath) { | ||
} | ||
return Object.assign({}, baseFs, { fileExistsSync, | ||
return { | ||
fileExistsSync, | ||
directoryExistsSync, | ||
ensureDirectorySync, | ||
populateDirectorySync, | ||
removeSync, | ||
findFilesSync, | ||
// resolve path once for recursive functions | ||
ensureDirectorySync: directoryPath => ensureDirectorySync(path.resolve(directoryPath)), | ||
populateDirectorySync: (directoryPath, contents) => populateDirectorySync(path.resolve(directoryPath), contents), | ||
removeSync: entryPath => removeSync(path.resolve(entryPath)), | ||
findFilesSync: (rootDirectory, options) => findFilesSync(path.resolve(rootDirectory), options), | ||
findClosestFileSync, | ||
findFilesInAncestorsSync }); | ||
findFilesInAncestorsSync, | ||
readJsonFileSync | ||
}; | ||
} | ||
export function createAsyncFileSystem(baseFs) { | ||
const { stat, path, mkdir, writeFile, lstat, rmdir, unlink, readdir } = baseFs; | ||
return Object.assign({}, baseFs, { promises: Object.assign({}, baseFs.promises, createExtendedFileSystemPromiseActions(baseFs)) }); | ||
} | ||
export function createExtendedFileSystemPromiseActions(baseFs) { | ||
const { path, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } } = baseFs; | ||
async function fileExists(filePath, statFn = stat) { | ||
@@ -141,2 +157,5 @@ try { | ||
} | ||
async function readJsonFile(filePath, options) { | ||
return JSON.parse(await readFile(filePath, options || 'utf8')); | ||
} | ||
async function ensureDirectory(directoryPath) { | ||
@@ -204,3 +223,3 @@ if (await directoryExists(directoryPath)) { | ||
async function findClosestFile(initialDirectoryPath, fileName) { | ||
let currentPath = initialDirectoryPath; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath; | ||
@@ -219,3 +238,3 @@ while (currentPath !== lastPath) { | ||
const filePaths = []; | ||
let currentPath = initialDirectoryPath; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath; | ||
@@ -232,11 +251,14 @@ while (currentPath !== lastPath) { | ||
} | ||
return Object.assign({}, baseFs, { fileExists, | ||
return { | ||
fileExists, | ||
directoryExists, | ||
ensureDirectory, | ||
populateDirectory, | ||
remove, | ||
findFiles, | ||
ensureDirectory: directoryPath => ensureDirectory(path.resolve(directoryPath)), | ||
populateDirectory: (directoryPath, contents) => populateDirectory(path.resolve(directoryPath), contents), | ||
remove: entryPath => remove(path.resolve(entryPath)), | ||
findFiles: (rootDirectory, options) => findFiles(path.resolve(rootDirectory), options), | ||
findClosestFile, | ||
findFilesInAncestors }); | ||
findFilesInAncestors, | ||
readJsonFile | ||
}; | ||
} | ||
//# sourceMappingURL=create-extended-api.js.map |
@@ -1,6 +0,3 @@ | ||
import pathMain from 'path'; | ||
import { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api'; | ||
// ugly workaround for webpack's polyfilled path not implementing posix | ||
const posixPath = pathMain.posix || pathMain; | ||
const POSIX_ROOT = '/'; | ||
import { POSIX_ROOT } from '@file-services/types'; | ||
import { createFileSystem } from './create-extended-api'; | ||
/** | ||
@@ -14,4 +11,5 @@ * Creates a wrapped `IFileSystem` which scopes the provided `fs` | ||
export function createDirectoryFs(fs, directoryPath) { | ||
const { watchService } = fs; | ||
const { watchService, promises } = fs; | ||
const { join, relative, sep } = fs.path; | ||
const posixPath = fs.path.posix || fs.path; | ||
let workingDirectoryPath = POSIX_ROOT; | ||
@@ -76,83 +74,124 @@ function resolveScopedPath(...pathSegments) { | ||
}, | ||
async copyFile(src, dest, flags) { | ||
return fs.copyFile(resolveFullPath(src), resolveFullPath(dest), flags); | ||
promises: { | ||
copyFile(srcPath, destPath, ...restArgs) { | ||
return promises.copyFile(resolveFullPath(srcPath), resolveFullPath(destPath), ...restArgs); | ||
}, | ||
lstat(path) { | ||
return promises.lstat(resolveFullPath(path)); | ||
}, | ||
mkdir(path) { | ||
return promises.mkdir(resolveFullPath(path)); | ||
}, | ||
readdir(path) { | ||
return promises.readdir(resolveFullPath(path)); | ||
}, | ||
readFile: function readFile(path, ...restArgs) { | ||
return promises.readFile(resolveFullPath(path), ...restArgs); | ||
}, | ||
realpath(path) { | ||
return promises.realpath(resolveFullPath(path)); | ||
}, | ||
rename(srcPath, destPath) { | ||
return promises.rename(resolveFullPath(srcPath), resolveFullPath(destPath)); | ||
}, | ||
rmdir(path) { | ||
return promises.rmdir(resolveFullPath(path)); | ||
}, | ||
exists(path) { | ||
return promises.exists(resolveFullPath(path)); | ||
}, | ||
stat(path) { | ||
return promises.stat(resolveFullPath(path)); | ||
}, | ||
unlink(path) { | ||
return promises.unlink(resolveFullPath(path)); | ||
}, | ||
writeFile(path, ...restArgs) { | ||
return promises.writeFile(resolveFullPath(path), ...restArgs); | ||
}, | ||
readlink(path) { | ||
return promises.readlink(resolveFullPath(path)); | ||
} | ||
}, | ||
copyFileSync(src, dest, flags) { | ||
return fs.copyFileSync(resolveFullPath(src), resolveFullPath(dest), flags); | ||
copyFileSync(src, dest, ...restArgs) { | ||
return fs.copyFileSync(resolveFullPath(src), resolveFullPath(dest), ...restArgs); | ||
}, | ||
async lstat(path) { | ||
return fs.lstat(resolveFullPath(path)); | ||
}, | ||
lstatSync(path) { | ||
return fs.lstatSync(resolveFullPath(path)); | ||
}, | ||
async mkdir(path) { | ||
return fs.mkdir(resolveFullPath(path)); | ||
}, | ||
mkdirSync(path) { | ||
return fs.mkdirSync(resolveFullPath(path)); | ||
}, | ||
async readdir(path) { | ||
return fs.readdir(resolveFullPath(path)); | ||
}, | ||
readdirSync(path) { | ||
return fs.readdirSync(resolveFullPath(path)); | ||
}, | ||
async readFile(path, encoding) { | ||
return fs.readFile(resolveFullPath(path), encoding); | ||
readFileSync: function readFileSync(path, ...restArgs) { | ||
return fs.readFileSync(resolveFullPath(path), ...restArgs); | ||
}, | ||
readFileSync(path, encoding) { | ||
return fs.readFileSync(resolveFullPath(path), encoding); | ||
}, | ||
async readFileRaw(path) { | ||
return fs.readFileRaw(resolveFullPath(path)); | ||
}, | ||
readFileRawSync(path) { | ||
return fs.readFileRawSync(resolveFullPath(path)); | ||
}, | ||
async realpath(path) { | ||
return fs.realpath(resolveFullPath(path)); | ||
}, | ||
realpathSync(path) { | ||
return fs.realpathSync(resolveFullPath(path)); | ||
}, | ||
async rename(path, newPath) { | ||
return fs.rename(resolveFullPath(path), resolveFullPath(newPath)); | ||
readlinkSync(path) { | ||
return fs.readlinkSync(resolveFullPath(path)); | ||
}, | ||
renameSync(path, newPath) { | ||
return fs.renameSync(resolveFullPath(path), resolveFullPath(newPath)); | ||
renameSync(srcPath, destPath) { | ||
return fs.renameSync(resolveFullPath(srcPath), resolveFullPath(destPath)); | ||
}, | ||
async rmdir(path) { | ||
return fs.rmdir(resolveFullPath(path)); | ||
}, | ||
rmdirSync(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(resolveFullPath(path)); | ||
}, | ||
statSync(path) { | ||
return fs.statSync(resolveFullPath(path)); | ||
}, | ||
async unlink(path) { | ||
return fs.unlink(resolveFullPath(path)); | ||
}, | ||
unlinkSync(path) { | ||
return fs.unlinkSync(resolveFullPath(path)); | ||
}, | ||
async writeFile(path, content, encoding) { | ||
return fs.writeFile(resolveFullPath(path), content, encoding); | ||
writeFileSync(path, ...restArgs) { | ||
return fs.writeFileSync(resolveFullPath(path), ...restArgs); | ||
}, | ||
writeFileSync(path, content, encoding) { | ||
return fs.writeFileSync(resolveFullPath(path), content, encoding); | ||
copyFile: function copyFile(srcPath, destPath, ...restArgs) { | ||
fs.copyFile(resolveFullPath(srcPath), resolveFullPath(destPath), ...restArgs); | ||
}, | ||
lstat(path, callback) { | ||
fs.lstat(resolveFullPath(path), callback); | ||
}, | ||
mkdir(path, callback) { | ||
fs.mkdir(resolveFullPath(path), callback); | ||
}, | ||
readdir(path, callback) { | ||
return fs.readdir(resolveFullPath(path), callback); | ||
}, | ||
readFile: function readFile(path, ...restArgs) { | ||
return fs.readFile(resolveFullPath(path), ...restArgs); | ||
}, | ||
realpath(path, callback) { | ||
return fs.realpath(resolveFullPath(path), callback); | ||
}, | ||
rename(path, newPath, callback) { | ||
return fs.rename(resolveFullPath(path), resolveFullPath(newPath), callback); | ||
}, | ||
rmdir(path, callback) { | ||
return fs.rmdir(resolveFullPath(path), callback); | ||
}, | ||
exists(path, callback) { | ||
return fs.exists(resolveFullPath(path), callback); | ||
}, | ||
stat(path, callback) { | ||
return fs.stat(resolveFullPath(path), callback); | ||
}, | ||
unlink(path, callback) { | ||
return fs.unlink(resolveFullPath(path), callback); | ||
}, | ||
writeFile: function writeFile(path, ...restArgs) { | ||
return fs.writeFile(resolveFullPath(path), ...restArgs); | ||
}, | ||
readlink(path, callback) { | ||
return fs.readlink(resolveFullPath(path), callback); | ||
} | ||
}; | ||
return Object.assign({}, scopedBaseFs, createAsyncFileSystem(scopedBaseFs), createSyncFileSystem(scopedBaseFs)); | ||
return createFileSystem(scopedBaseFs); | ||
} | ||
//# sourceMappingURL=directory-fs.js.map |
@@ -1,5 +0,5 @@ | ||
export { syncToAsyncFs } from './sync-to-async-fs'; | ||
export { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api'; | ||
export { createDirectoryFs } from './directory-fs'; | ||
export { SetMultiMap } from './set-multi-map'; | ||
export * from './sync-to-async-fs'; | ||
export * from './create-extended-api'; | ||
export * from './directory-fs'; | ||
export * from './set-multi-map'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,5 +0,5 @@ | ||
export { syncToAsyncFs } from './sync-to-async-fs'; | ||
export { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api'; | ||
export { createDirectoryFs } from './directory-fs'; | ||
export { SetMultiMap } from './set-multi-map'; | ||
export * from './sync-to-async-fs'; | ||
export * from './create-extended-api'; | ||
export * from './directory-fs'; | ||
export * from './set-multi-map'; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
import { callbackify } from './callbackify'; | ||
export function syncToAsyncFs(syncFs) { | ||
@@ -6,43 +7,60 @@ return { | ||
caseSensitive: syncFs.caseSensitive, | ||
async readFile(filePath, encoding) { | ||
return syncFs.readFileSync(filePath, encoding); | ||
promises: { | ||
readFile: async function readFile(...args) { | ||
return syncFs.readFileSync(...args); | ||
}, | ||
async writeFile(...args) { | ||
return syncFs.writeFileSync(...args); | ||
}, | ||
async unlink(filePath) { | ||
return syncFs.unlinkSync(filePath); | ||
}, | ||
async readdir(directoryPath) { | ||
return syncFs.readdirSync(directoryPath); | ||
}, | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
}, | ||
async rmdir(directoryPath) { | ||
return syncFs.rmdirSync(directoryPath); | ||
}, | ||
async exists(nodePath) { | ||
return syncFs.existsSync(nodePath); | ||
}, | ||
async stat(nodePath) { | ||
return syncFs.statSync(nodePath); | ||
}, | ||
async lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath); | ||
}, | ||
async realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath); | ||
}, | ||
async rename(srcPath, destPath) { | ||
return syncFs.renameSync(srcPath, destPath); | ||
}, | ||
async copyFile(...args) { | ||
return syncFs.copyFileSync(...args); | ||
}, | ||
async readlink(path) { | ||
return syncFs.readlinkSync(path); | ||
} | ||
}, | ||
async readFileRaw(filePath) { | ||
return syncFs.readFileRawSync(filePath); | ||
exists(nodePath, callback) { | ||
callback(syncFs.existsSync(nodePath)); | ||
}, | ||
async writeFile(filePath, content, encoding) { | ||
return syncFs.writeFileSync(filePath, content, encoding); | ||
}, | ||
async unlink(filePath) { | ||
return syncFs.unlinkSync(filePath); | ||
}, | ||
async readdir(directoryPath) { | ||
return syncFs.readdirSync(directoryPath); | ||
}, | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
}, | ||
async rmdir(directoryPath) { | ||
return syncFs.rmdirSync(directoryPath); | ||
}, | ||
async exists(nodePath) { | ||
return syncFs.existsSync(nodePath); | ||
}, | ||
async stat(nodePath) { | ||
return syncFs.statSync(nodePath); | ||
}, | ||
async lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath); | ||
}, | ||
async realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath); | ||
}, | ||
async rename(path, newPath) { | ||
return syncFs.renameSync(path, newPath); | ||
}, | ||
async copyFile(src, dest, flags) { | ||
return syncFs.copyFileSync(src, dest, flags); | ||
} | ||
readFile: callbackify(syncFs.readFileSync), | ||
writeFile: callbackify(syncFs.writeFileSync), | ||
copyFile: callbackify(syncFs.copyFileSync), | ||
unlink: callbackify(syncFs.unlinkSync), | ||
readdir: callbackify(syncFs.readdirSync), | ||
mkdir: callbackify(syncFs.mkdirSync), | ||
rmdir: callbackify(syncFs.rmdirSync), | ||
stat: callbackify(syncFs.statSync), | ||
lstat: callbackify(syncFs.lstatSync), | ||
realpath: callbackify(syncFs.realpathSync), | ||
rename: callbackify(syncFs.renameSync), | ||
readlink: callbackify(syncFs.readlinkSync) | ||
}; | ||
} | ||
//# sourceMappingURL=sync-to-async-fs.js.map |
{ | ||
"name": "@file-services/utils", | ||
"description": "Common file system utility functions.", | ||
"version": "0.4.11", | ||
"version": "1.0.0", | ||
"main": "cjs/index.js", | ||
@@ -11,4 +11,5 @@ "module": "esm/index.js", | ||
"build": "ts-build ./src --cjs --esm", | ||
"lint": "run-p lint:src", | ||
"lint:src": "tslint --project src", | ||
"lint": "run-p lint:src lint:test", | ||
"lint:src": "tslint -p src", | ||
"lint:test": "tslint -p test", | ||
"test": "mocha -r @ts-tools/node/r \"test/**/*.spec.ts?(x)\" --watch-extensions ts,tsx --colors", | ||
@@ -18,3 +19,3 @@ "prepack": "yarn build" | ||
"dependencies": { | ||
"@file-services/types": "^0.4.11" | ||
"@file-services/types": "^1.0.0" | ||
}, | ||
@@ -34,3 +35,3 @@ "files": [ | ||
"sideEffects": false, | ||
"gitHead": "d077e3795b175547ed2dbb821b90c12fbd29bcb5" | ||
"gitHead": "b7770933845945aa3e9fe054c4ecbfb46b0c12c9" | ||
} |
@@ -8,23 +8,63 @@ import { | ||
IWalkOptions, | ||
IFileSystemDescriptor | ||
} from '@file-services/types' | ||
IFileSystemDescriptor, | ||
BufferEncoding, | ||
IBaseFileSystem, | ||
IFileSystem, | ||
IFileSystemExtendedSyncActions, | ||
IFileSystemExtendedPromiseActions | ||
} from '@file-services/types'; | ||
const returnsTrue = () => true | ||
const returnsTrue = () => true; | ||
export function createFileSystem(baseFs: IBaseFileSystem): IFileSystem { | ||
return { | ||
...baseFs, | ||
...createExtendedSyncActions(baseFs), | ||
promises: { | ||
...baseFs.promises, | ||
...createExtendedFileSystemPromiseActions(baseFs) | ||
} | ||
}; | ||
} | ||
export function createSyncFileSystem(baseFs: IBaseFileSystemSync): IFileSystemSync { | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync } = baseFs | ||
return { | ||
...baseFs, | ||
...createExtendedSyncActions(baseFs) | ||
}; | ||
} | ||
export function createExtendedSyncActions(baseFs: IBaseFileSystemSync): IFileSystemExtendedSyncActions { | ||
const { | ||
statSync, | ||
path, | ||
mkdirSync, | ||
writeFileSync, | ||
unlinkSync, | ||
rmdirSync, | ||
lstatSync, | ||
readdirSync, | ||
readFileSync | ||
} = baseFs; | ||
function fileExistsSync(filePath: string, statFn = statSync): boolean { | ||
try { | ||
return statFn(filePath).isFile() | ||
return statFn(filePath).isFile(); | ||
} catch { | ||
return false | ||
return false; | ||
} | ||
} | ||
function readJsonFileSync( | ||
filePath: string, | ||
options?: BufferEncoding | { encoding: BufferEncoding } | null | ||
): unknown { | ||
return JSON.parse(readFileSync(filePath, options || 'utf8')); | ||
} | ||
function directoryExistsSync(directoryPath: string, statFn = statSync): boolean { | ||
try { | ||
return statFn(directoryPath).isDirectory() | ||
return statFn(directoryPath).isDirectory(); | ||
} catch { | ||
return false | ||
return false; | ||
} | ||
@@ -35,13 +75,13 @@ } | ||
if (directoryExistsSync(directoryPath)) { | ||
return | ||
return; | ||
} | ||
try { | ||
mkdirSync(directoryPath) | ||
mkdirSync(directoryPath); | ||
} catch (e) { | ||
const parentPath = path.dirname(directoryPath) | ||
const parentPath = path.dirname(directoryPath); | ||
if (parentPath === directoryPath) { | ||
throw e | ||
throw e; | ||
} | ||
ensureDirectorySync(parentPath) | ||
mkdirSync(directoryPath) | ||
ensureDirectorySync(parentPath); | ||
mkdirSync(directoryPath); | ||
} | ||
@@ -51,29 +91,29 @@ } | ||
function populateDirectorySync(directoryPath: string, contents: IDirectoryContents): string[] { | ||
const filePaths: string[] = [] | ||
ensureDirectorySync(directoryPath) | ||
const filePaths: string[] = []; | ||
ensureDirectorySync(directoryPath); | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName) | ||
const nodePath = path.join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
ensureDirectorySync(path.dirname(nodePath)) | ||
writeFileSync(nodePath, nodeValue) | ||
filePaths.push(nodePath) | ||
ensureDirectorySync(path.dirname(nodePath)); | ||
writeFileSync(nodePath, nodeValue); | ||
filePaths.push(nodePath); | ||
} else { | ||
populateDirectorySync(nodePath, nodeValue) | ||
populateDirectorySync(nodePath, nodeValue); | ||
} | ||
} | ||
return filePaths | ||
return filePaths; | ||
} | ||
function removeSync(entryPath: string): void { | ||
const stats = lstatSync(entryPath) | ||
const stats = lstatSync(entryPath); | ||
if (stats.isDirectory()) { | ||
const directoryItems = readdirSync(entryPath) | ||
const directoryItems = readdirSync(entryPath); | ||
for (const entryName of directoryItems) { | ||
removeSync(path.join(entryPath, entryName)) | ||
removeSync(path.join(entryPath, entryName)); | ||
} | ||
rmdirSync(entryPath) | ||
rmdirSync(entryPath); | ||
} else if (stats.isFile() || stats.isSymbolicLink()) { | ||
unlinkSync(entryPath) | ||
unlinkSync(entryPath); | ||
} else { | ||
throw new Error(`unknown node type, cannot delete ${entryPath}`) | ||
throw new Error(`unknown node type, cannot delete ${entryPath}`); | ||
} | ||
@@ -83,72 +123,89 @@ } | ||
function findFilesSync(rootDirectory: string, options: IWalkOptions = {}, filePaths: string[] = []): string[] { | ||
const { filterFile = returnsTrue, filterDirectory = returnsTrue } = options | ||
const { filterFile = returnsTrue, filterDirectory = returnsTrue } = options; | ||
for (const nodeName of readdirSync(rootDirectory)) { | ||
const nodePath = path.join(rootDirectory, nodeName) | ||
const nodeStats = statSync(nodePath) | ||
const nodeDesc: IFileSystemDescriptor = { name: nodeName, path: nodePath, stats: nodeStats } | ||
const nodePath = path.join(rootDirectory, nodeName); | ||
const nodeStats = statSync(nodePath); | ||
const nodeDesc: IFileSystemDescriptor = { name: nodeName, path: nodePath, stats: nodeStats }; | ||
if (nodeStats.isFile() && filterFile(nodeDesc)) { | ||
filePaths.push(nodePath) | ||
filePaths.push(nodePath); | ||
} else if (nodeStats.isDirectory() && filterDirectory(nodeDesc)) { | ||
findFilesSync(nodePath, options, filePaths) | ||
findFilesSync(nodePath, options, filePaths); | ||
} | ||
} | ||
return filePaths | ||
return filePaths; | ||
} | ||
function findClosestFileSync(initialDirectoryPath: string, fileName: string): string | null { | ||
let currentPath = initialDirectoryPath | ||
let lastPath: string | undefined | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath: string | undefined; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName) | ||
const filePath = path.join(currentPath, fileName); | ||
if (fileExistsSync(filePath)) { | ||
return filePath | ||
return filePath; | ||
} | ||
lastPath = currentPath | ||
currentPath = path.dirname(currentPath) | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
} | ||
return null | ||
return null; | ||
} | ||
function findFilesInAncestorsSync(initialDirectoryPath: string, fileName: string): string[] { | ||
const filePaths: string[] = [] | ||
let currentPath = initialDirectoryPath | ||
let lastPath: string | undefined | ||
const filePaths: string[] = []; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath: string | undefined; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName) | ||
const filePath = path.join(currentPath, fileName); | ||
if (fileExistsSync(filePath)) { | ||
filePaths.push(filePath) | ||
filePaths.push(filePath); | ||
} | ||
lastPath = currentPath | ||
currentPath = path.dirname(currentPath) | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
} | ||
return filePaths | ||
return filePaths; | ||
} | ||
return { | ||
...baseFs, | ||
fileExistsSync, | ||
directoryExistsSync, | ||
ensureDirectorySync, | ||
populateDirectorySync, | ||
removeSync, | ||
findFilesSync, | ||
// resolve path once for recursive functions | ||
ensureDirectorySync: directoryPath => ensureDirectorySync(path.resolve(directoryPath)), | ||
populateDirectorySync: (directoryPath, contents) => | ||
populateDirectorySync(path.resolve(directoryPath), contents), | ||
removeSync: entryPath => removeSync(path.resolve(entryPath)), | ||
findFilesSync: (rootDirectory, options) => findFilesSync(path.resolve(rootDirectory), options), | ||
findClosestFileSync, | ||
findFilesInAncestorsSync | ||
} | ||
findFilesInAncestorsSync, | ||
readJsonFileSync | ||
}; | ||
} | ||
export function createAsyncFileSystem(baseFs: IBaseFileSystemAsync): IFileSystemAsync { | ||
const { stat, path, mkdir, writeFile, lstat, rmdir, unlink, readdir } = baseFs | ||
return { | ||
...baseFs, | ||
promises: { | ||
...baseFs.promises, | ||
...createExtendedFileSystemPromiseActions(baseFs) | ||
} | ||
}; | ||
} | ||
export function createExtendedFileSystemPromiseActions( | ||
baseFs: IBaseFileSystemAsync | ||
): IFileSystemExtendedPromiseActions { | ||
const { | ||
path, | ||
promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } | ||
} = baseFs; | ||
async function fileExists(filePath: string, statFn = stat): Promise<boolean> { | ||
try { | ||
return (await statFn(filePath)).isFile() | ||
return (await statFn(filePath)).isFile(); | ||
} catch { | ||
return false | ||
return false; | ||
} | ||
@@ -159,21 +216,28 @@ } | ||
try { | ||
return (await statFn(directoryPath)).isDirectory() | ||
return (await statFn(directoryPath)).isDirectory(); | ||
} catch { | ||
return false | ||
return false; | ||
} | ||
} | ||
async function readJsonFile( | ||
filePath: string, | ||
options?: BufferEncoding | { encoding: BufferEncoding } | null | ||
): Promise<unknown> { | ||
return JSON.parse(await readFile(filePath, options || 'utf8')); | ||
} | ||
async function ensureDirectory(directoryPath: string): Promise<void> { | ||
if (await directoryExists(directoryPath)) { | ||
return | ||
return; | ||
} | ||
try { | ||
await mkdir(directoryPath) | ||
await mkdir(directoryPath); | ||
} catch (e) { | ||
const parentPath = path.dirname(directoryPath) | ||
const parentPath = path.dirname(directoryPath); | ||
if (parentPath === directoryPath) { | ||
throw e | ||
throw e; | ||
} | ||
await ensureDirectory(parentPath) | ||
await mkdir(directoryPath) | ||
await ensureDirectory(parentPath); | ||
await mkdir(directoryPath); | ||
} | ||
@@ -183,27 +247,27 @@ } | ||
async function populateDirectory(directoryPath: string, contents: IDirectoryContents): Promise<string[]> { | ||
const filePaths: string[] = [] | ||
await ensureDirectory(directoryPath) | ||
const filePaths: string[] = []; | ||
await ensureDirectory(directoryPath); | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName) | ||
const nodePath = path.join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
await ensureDirectory(path.dirname(nodePath)) | ||
await writeFile(nodePath, nodeValue) | ||
filePaths.push(nodePath) | ||
await ensureDirectory(path.dirname(nodePath)); | ||
await writeFile(nodePath, nodeValue); | ||
filePaths.push(nodePath); | ||
} else { | ||
await populateDirectory(nodePath, nodeValue) | ||
await populateDirectory(nodePath, nodeValue); | ||
} | ||
} | ||
return filePaths | ||
return filePaths; | ||
} | ||
async function remove(entryPath: string): Promise<void> { | ||
const stats = await lstat(entryPath) | ||
const stats = await lstat(entryPath); | ||
if (stats.isDirectory()) { | ||
const directoryItems = await readdir(entryPath) | ||
await Promise.all(directoryItems.map(entryName => remove(path.join(entryPath, entryName)))) | ||
await rmdir(entryPath) | ||
const directoryItems = await readdir(entryPath); | ||
await Promise.all(directoryItems.map(entryName => remove(path.join(entryPath, entryName)))); | ||
await rmdir(entryPath); | ||
} else if (stats.isFile() || stats.isSymbolicLink()) { | ||
await unlink(entryPath) | ||
await unlink(entryPath); | ||
} else { | ||
throw new Error(`unknown node type, cannot delete ${entryPath}`) | ||
throw new Error(`unknown node type, cannot delete ${entryPath}`); | ||
} | ||
@@ -217,61 +281,61 @@ } | ||
): Promise<string[]> { | ||
const { filterFile = returnsTrue, filterDirectory = returnsTrue } = options | ||
const { filterFile = returnsTrue, filterDirectory = returnsTrue } = options; | ||
for (const nodeName of await readdir(rootDirectory)) { | ||
const nodePath = path.join(rootDirectory, nodeName) | ||
const nodeStats = await stat(nodePath) | ||
const nodeDesc: IFileSystemDescriptor = { name: nodeName, path: nodePath, stats: nodeStats } | ||
const nodePath = path.join(rootDirectory, nodeName); | ||
const nodeStats = await stat(nodePath); | ||
const nodeDesc: IFileSystemDescriptor = { name: nodeName, path: nodePath, stats: nodeStats }; | ||
if (nodeStats.isFile() && filterFile(nodeDesc)) { | ||
filePaths.push(nodePath) | ||
filePaths.push(nodePath); | ||
} else if (nodeStats.isDirectory() && filterDirectory(nodeDesc)) { | ||
await findFiles(nodePath, options, filePaths) | ||
await findFiles(nodePath, options, filePaths); | ||
} | ||
} | ||
return filePaths | ||
return filePaths; | ||
} | ||
async function findClosestFile(initialDirectoryPath: string, fileName: string): Promise<string | null> { | ||
let currentPath = initialDirectoryPath | ||
let lastPath: string | undefined | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath: string | undefined; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName) | ||
const filePath = path.join(currentPath, fileName); | ||
if (await fileExists(filePath)) { | ||
return filePath | ||
return filePath; | ||
} | ||
lastPath = currentPath | ||
currentPath = path.dirname(currentPath) | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
} | ||
return null | ||
return null; | ||
} | ||
async function findFilesInAncestors(initialDirectoryPath: string, fileName: string): Promise<string[]> { | ||
const filePaths: string[] = [] | ||
let currentPath = initialDirectoryPath | ||
let lastPath: string | undefined | ||
const filePaths: string[] = []; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let lastPath: string | undefined; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName) | ||
const filePath = path.join(currentPath, fileName); | ||
if (await fileExists(filePath)) { | ||
filePaths.push(filePath) | ||
filePaths.push(filePath); | ||
} | ||
lastPath = currentPath | ||
currentPath = path.dirname(currentPath) | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
} | ||
return filePaths | ||
return filePaths; | ||
} | ||
return { | ||
...baseFs, | ||
fileExists, | ||
directoryExists, | ||
ensureDirectory, | ||
populateDirectory, | ||
remove, | ||
findFiles, | ||
ensureDirectory: directoryPath => ensureDirectory(path.resolve(directoryPath)), | ||
populateDirectory: (directoryPath, contents) => populateDirectory(path.resolve(directoryPath), contents), | ||
remove: entryPath => remove(path.resolve(entryPath)), | ||
findFiles: (rootDirectory, options) => findFiles(path.resolve(rootDirectory), options), | ||
findClosestFile, | ||
findFilesInAncestors | ||
} | ||
findFilesInAncestors, | ||
readJsonFile | ||
}; | ||
} |
@@ -1,9 +0,18 @@ | ||
import { IBaseFileSystem, IFileSystem, WatchEventListener, IWatchService } from '@file-services/types' | ||
import pathMain from 'path' | ||
import { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api' | ||
import { | ||
IBaseFileSystem, | ||
IFileSystem, | ||
WatchEventListener, | ||
IWatchService, | ||
IFileSystemPath, | ||
POSIX_ROOT, | ||
CallbackFn, | ||
CallbackFnVoid, | ||
IBaseFileSystemSyncActions, | ||
IBaseFileSystemCallbackActions, | ||
IBaseFileSystemPromiseActions, | ||
ReadFileOptions, | ||
WriteFileOptions | ||
} from '@file-services/types'; | ||
import { createFileSystem } from './create-extended-api'; | ||
// ugly workaround for webpack's polyfilled path not implementing posix | ||
const posixPath = (pathMain.posix as typeof pathMain) || pathMain | ||
const POSIX_ROOT = '/' | ||
/** | ||
@@ -17,20 +26,21 @@ * Creates a wrapped `IFileSystem` which scopes the provided `fs` | ||
export function createDirectoryFs(fs: IFileSystem, directoryPath: string): IFileSystem { | ||
const { watchService } = fs | ||
const { join, relative, sep } = fs.path | ||
const { watchService, promises } = fs; | ||
const { join, relative, sep } = fs.path; | ||
const posixPath = ((fs.path as any).posix as IFileSystemPath) || fs.path; | ||
let workingDirectoryPath: string = POSIX_ROOT | ||
let workingDirectoryPath: string = POSIX_ROOT; | ||
function resolveScopedPath(...pathSegments: string[]): string { | ||
return posixPath.resolve(workingDirectoryPath, ...pathSegments) | ||
return posixPath.resolve(workingDirectoryPath, ...pathSegments); | ||
} | ||
function resolveFullPath(path: string): string { | ||
return join(directoryPath, resolveScopedPath(path)) | ||
return join(directoryPath, resolveScopedPath(path)); | ||
} | ||
const scopedListeners: WeakMap<WatchEventListener, WatchEventListener> = new WeakMap() | ||
const scopedListeners: WeakMap<WatchEventListener, WatchEventListener> = new WeakMap(); | ||
function createScopedListener(listener: WatchEventListener) { | ||
const scopedListener: WatchEventListener = e => { | ||
const relativeEventPath = relative(directoryPath, e.path) | ||
const relativeEventPath = relative(directoryPath, e.path); | ||
// we don't want to pass events outside of scoped directory | ||
@@ -42,7 +52,7 @@ if (!relativeEventPath.startsWith(`..${sep}`)) { | ||
path: posixPath.join(POSIX_ROOT, relativeEventPath) | ||
}) | ||
}); | ||
} | ||
} | ||
scopedListeners.set(listener, scopedListener) | ||
return scopedListener | ||
}; | ||
scopedListeners.set(listener, scopedListener); | ||
return scopedListener; | ||
} | ||
@@ -53,25 +63,25 @@ | ||
if (listener) { | ||
listener = scopedListeners.get(listener) || createScopedListener(listener) | ||
listener = scopedListeners.get(listener) || createScopedListener(listener); | ||
} | ||
return watchService.watchPath(resolveFullPath(path), listener) | ||
return watchService.watchPath(resolveFullPath(path), listener); | ||
}, | ||
async unwatchPath(path, listener) { | ||
if (listener) { | ||
listener = scopedListeners.get(listener) || listener | ||
listener = scopedListeners.get(listener) || listener; | ||
} | ||
return watchService.unwatchPath(resolveFullPath(path), listener) | ||
return watchService.unwatchPath(resolveFullPath(path), listener); | ||
}, | ||
async unwatchAllPaths() { | ||
return watchService.unwatchAllPaths() | ||
return watchService.unwatchAllPaths(); | ||
}, | ||
addGlobalListener(listener) { | ||
return watchService.addGlobalListener(scopedListeners.get(listener) || createScopedListener(listener)) | ||
return watchService.addGlobalListener(scopedListeners.get(listener) || createScopedListener(listener)); | ||
}, | ||
removeGlobalListener(listener) { | ||
return watchService.removeGlobalListener(scopedListeners.get(listener) || listener) | ||
return watchService.removeGlobalListener(scopedListeners.get(listener) || listener); | ||
}, | ||
clearGlobalListeners() { | ||
return watchService.clearGlobalListeners() | ||
return watchService.clearGlobalListeners(); | ||
} | ||
} | ||
}; | ||
@@ -86,92 +96,129 @@ const scopedBaseFs: IBaseFileSystem = { | ||
cwd() { | ||
return workingDirectoryPath | ||
return workingDirectoryPath; | ||
}, | ||
chdir(path) { | ||
workingDirectoryPath = resolveScopedPath(path) | ||
workingDirectoryPath = resolveScopedPath(path); | ||
}, | ||
async copyFile(src, dest, flags) { | ||
return fs.copyFile(resolveFullPath(src), resolveFullPath(dest), flags) | ||
promises: { | ||
copyFile(srcPath, destPath, ...restArgs) { | ||
return promises.copyFile(resolveFullPath(srcPath), resolveFullPath(destPath), ...restArgs); | ||
}, | ||
lstat(path) { | ||
return promises.lstat(resolveFullPath(path)); | ||
}, | ||
mkdir(path) { | ||
return promises.mkdir(resolveFullPath(path)); | ||
}, | ||
readdir(path) { | ||
return promises.readdir(resolveFullPath(path)); | ||
}, | ||
readFile: function readFile(path: string, ...restArgs: [ReadFileOptions]) { | ||
return promises.readFile(resolveFullPath(path), ...restArgs); | ||
} as IBaseFileSystemPromiseActions['readFile'], | ||
realpath(path) { | ||
return promises.realpath(resolveFullPath(path)); | ||
}, | ||
rename(srcPath, destPath) { | ||
return promises.rename(resolveFullPath(srcPath), resolveFullPath(destPath)); | ||
}, | ||
rmdir(path) { | ||
return promises.rmdir(resolveFullPath(path)); | ||
}, | ||
exists(path) { | ||
return promises.exists(resolveFullPath(path)); | ||
}, | ||
stat(path) { | ||
return promises.stat(resolveFullPath(path)); | ||
}, | ||
unlink(path) { | ||
return promises.unlink(resolveFullPath(path)); | ||
}, | ||
writeFile(path, ...restArgs) { | ||
return promises.writeFile(resolveFullPath(path), ...restArgs); | ||
}, | ||
readlink(path) { | ||
return promises.readlink(resolveFullPath(path)); | ||
} | ||
}, | ||
copyFileSync(src, dest, flags) { | ||
return fs.copyFileSync(resolveFullPath(src), resolveFullPath(dest), flags) | ||
copyFileSync(src, dest, ...restArgs) { | ||
return fs.copyFileSync(resolveFullPath(src), resolveFullPath(dest), ...restArgs); | ||
}, | ||
async lstat(path) { | ||
return fs.lstat(resolveFullPath(path)) | ||
}, | ||
lstatSync(path) { | ||
return fs.lstatSync(resolveFullPath(path)) | ||
return fs.lstatSync(resolveFullPath(path)); | ||
}, | ||
async mkdir(path) { | ||
return fs.mkdir(resolveFullPath(path)) | ||
}, | ||
mkdirSync(path) { | ||
return fs.mkdirSync(resolveFullPath(path)) | ||
return fs.mkdirSync(resolveFullPath(path)); | ||
}, | ||
async readdir(path) { | ||
return fs.readdir(resolveFullPath(path)) | ||
}, | ||
readdirSync(path) { | ||
return fs.readdirSync(resolveFullPath(path)) | ||
return fs.readdirSync(resolveFullPath(path)); | ||
}, | ||
async readFile(path, encoding) { | ||
return fs.readFile(resolveFullPath(path), encoding) | ||
readFileSync: function readFileSync(path: string, ...restArgs: [ReadFileOptions]) { | ||
return fs.readFileSync(resolveFullPath(path), ...restArgs); | ||
} as IBaseFileSystemSyncActions['readFileSync'], | ||
realpathSync(path) { | ||
return fs.realpathSync(resolveFullPath(path)); | ||
}, | ||
readFileSync(path, encoding) { | ||
return fs.readFileSync(resolveFullPath(path), encoding) | ||
readlinkSync(path) { | ||
return fs.readlinkSync(resolveFullPath(path)); | ||
}, | ||
async readFileRaw(path) { | ||
return fs.readFileRaw(resolveFullPath(path)) | ||
renameSync(srcPath, destPath) { | ||
return fs.renameSync(resolveFullPath(srcPath), resolveFullPath(destPath)); | ||
}, | ||
readFileRawSync(path) { | ||
return fs.readFileRawSync(resolveFullPath(path)) | ||
rmdirSync(path) { | ||
return fs.rmdirSync(resolveFullPath(path)); | ||
}, | ||
async realpath(path) { | ||
return fs.realpath(resolveFullPath(path)) | ||
existsSync(path) { | ||
return fs.existsSync(resolveFullPath(path)); | ||
}, | ||
realpathSync(path) { | ||
return fs.realpathSync(resolveFullPath(path)) | ||
statSync(path) { | ||
return fs.statSync(resolveFullPath(path)); | ||
}, | ||
async rename(path, newPath) { | ||
return fs.rename(resolveFullPath(path), resolveFullPath(newPath)) | ||
unlinkSync(path) { | ||
return fs.unlinkSync(resolveFullPath(path)); | ||
}, | ||
renameSync(path, newPath) { | ||
return fs.renameSync(resolveFullPath(path), resolveFullPath(newPath)) | ||
writeFileSync(path, ...restArgs: [string, WriteFileOptions]) { | ||
return fs.writeFileSync(resolveFullPath(path), ...restArgs); | ||
}, | ||
async rmdir(path) { | ||
return fs.rmdir(resolveFullPath(path)) | ||
copyFile: function copyFile(srcPath: string, destPath: string, ...restArgs: [CallbackFnVoid]) { | ||
fs.copyFile(resolveFullPath(srcPath), resolveFullPath(destPath), ...restArgs); | ||
} as IBaseFileSystemCallbackActions['copyFile'], | ||
lstat(path, callback) { | ||
fs.lstat(resolveFullPath(path), callback); | ||
}, | ||
rmdirSync(path) { | ||
return fs.rmdirSync(resolveFullPath(path)) | ||
mkdir(path, callback) { | ||
fs.mkdir(resolveFullPath(path), callback); | ||
}, | ||
async exists(path) { | ||
return fs.exists(resolveFullPath(path)) | ||
readdir(path, callback) { | ||
return fs.readdir(resolveFullPath(path), callback); | ||
}, | ||
existsSync(path) { | ||
return fs.existsSync(resolveFullPath(path)) | ||
readFile: function readFile(path: string, ...restArgs: [string, CallbackFn<string | Buffer>]) { | ||
return fs.readFile(resolveFullPath(path), ...restArgs); | ||
} as IBaseFileSystemCallbackActions['readFile'], | ||
realpath(path, callback) { | ||
return fs.realpath(resolveFullPath(path), callback); | ||
}, | ||
async stat(path) { | ||
return fs.stat(resolveFullPath(path)) | ||
rename(path, newPath, callback) { | ||
return fs.rename(resolveFullPath(path), resolveFullPath(newPath), callback); | ||
}, | ||
statSync(path) { | ||
return fs.statSync(resolveFullPath(path)) | ||
rmdir(path, callback) { | ||
return fs.rmdir(resolveFullPath(path), callback); | ||
}, | ||
async unlink(path) { | ||
return fs.unlink(resolveFullPath(path)) | ||
exists(path, callback) { | ||
return fs.exists(resolveFullPath(path), callback); | ||
}, | ||
unlinkSync(path) { | ||
return fs.unlinkSync(resolveFullPath(path)) | ||
stat(path, callback) { | ||
return fs.stat(resolveFullPath(path), callback); | ||
}, | ||
async writeFile(path, content, encoding) { | ||
return fs.writeFile(resolveFullPath(path), content, encoding) | ||
unlink(path, callback) { | ||
return fs.unlink(resolveFullPath(path), callback); | ||
}, | ||
writeFileSync(path, content, encoding) { | ||
return fs.writeFileSync(resolveFullPath(path), content, encoding) | ||
writeFile: function writeFile(path: string, ...restArgs: [string, CallbackFnVoid]) { | ||
return fs.writeFile(resolveFullPath(path), ...restArgs); | ||
} as IBaseFileSystemCallbackActions['writeFile'], | ||
readlink(path, callback) { | ||
return fs.readlink(resolveFullPath(path), callback); | ||
} | ||
} | ||
}; | ||
return { | ||
...scopedBaseFs, | ||
...createAsyncFileSystem(scopedBaseFs), | ||
...createSyncFileSystem(scopedBaseFs) | ||
} | ||
return createFileSystem(scopedBaseFs); | ||
} |
@@ -1,4 +0,4 @@ | ||
export { syncToAsyncFs } from './sync-to-async-fs' | ||
export { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api' | ||
export { createDirectoryFs } from './directory-fs' | ||
export { SetMultiMap } from './set-multi-map' | ||
export * from './sync-to-async-fs'; | ||
export * from './create-extended-api'; | ||
export * from './directory-fs'; | ||
export * from './set-multi-map'; |
export class SetMultiMap<K, V> implements Iterable<[K, V]> { | ||
private map: Map<K, Set<V>> = new Map() | ||
private map: Map<K, Set<V>> = new Map(); | ||
@@ -7,54 +7,54 @@ public get size(): number { | ||
.map(({ size }) => size) | ||
.reduce((sum, size) => sum + size, 0) | ||
.reduce((sum, size) => sum + size, 0); | ||
} | ||
public get(key: K): ReadonlySet<V> | undefined { | ||
return this.map.get(key) | ||
return this.map.get(key); | ||
} | ||
public add(key: K, value: V): this { | ||
const valueSet = this.map.get(key) | ||
const valueSet = this.map.get(key); | ||
if (valueSet) { | ||
valueSet.add(value) | ||
valueSet.add(value); | ||
} else { | ||
this.map.set(key, new Set([value])) | ||
this.map.set(key, new Set([value])); | ||
} | ||
return this | ||
return this; | ||
} | ||
public clear(): void { | ||
this.map.clear() | ||
this.map.clear(); | ||
} | ||
public delete(key: K, value: V): boolean { | ||
const valueSet = this.map.get(key) | ||
const valueSet = this.map.get(key); | ||
if (valueSet) { | ||
const wasInSet = valueSet.delete(value) | ||
const wasInSet = valueSet.delete(value); | ||
if (valueSet.size === 0) { | ||
this.map.delete(key) | ||
this.map.delete(key); | ||
} | ||
return wasInSet | ||
return wasInSet; | ||
} | ||
return false | ||
return false; | ||
} | ||
public deleteKey(key: K): boolean { | ||
return this.map.delete(key) | ||
return this.map.delete(key); | ||
} | ||
public has(key: K, value: V): boolean { | ||
const valueSet = this.map.get(key) | ||
return valueSet ? valueSet.has(value) : false | ||
const valueSet = this.map.get(key); | ||
return valueSet ? valueSet.has(value) : false; | ||
} | ||
public hasKey(key: K): boolean { | ||
const existingSet = this.map.get(key) | ||
return !!existingSet && existingSet.size > 0 | ||
const existingSet = this.map.get(key); | ||
return !!existingSet && existingSet.size > 0; | ||
} | ||
public *[Symbol.iterator](): IterableIterator<[K, V]> { | ||
const { map } = this | ||
const { map } = this; | ||
for (const [key, valueSet] of map.entries()) { | ||
for (const value of valueSet) { | ||
yield [key, value] | ||
yield [key, value]; | ||
} | ||
@@ -61,0 +61,0 @@ } |
@@ -1,2 +0,3 @@ | ||
import { IBaseFileSystemSync, IBaseFileSystemAsync } from '@file-services/types' | ||
import { IBaseFileSystemSync, IBaseFileSystemAsync, IBaseFileSystemPromiseActions } from '@file-services/types'; | ||
import { callbackify } from './callbackify'; | ||
@@ -9,54 +10,71 @@ export function syncToAsyncFs(syncFs: IBaseFileSystemSync): IBaseFileSystemAsync { | ||
async readFile(filePath, encoding) { | ||
return syncFs.readFileSync(filePath, encoding) | ||
}, | ||
promises: { | ||
readFile: async function readFile(...args: [string]) { | ||
return syncFs.readFileSync(...args); | ||
} as IBaseFileSystemPromiseActions['readFile'], | ||
async readFileRaw(filePath) { | ||
return syncFs.readFileRawSync(filePath) | ||
}, | ||
async writeFile(...args) { | ||
return syncFs.writeFileSync(...args); | ||
}, | ||
async writeFile(filePath, content, encoding) { | ||
return syncFs.writeFileSync(filePath, content, encoding) | ||
}, | ||
async unlink(filePath) { | ||
return syncFs.unlinkSync(filePath); | ||
}, | ||
async unlink(filePath) { | ||
return syncFs.unlinkSync(filePath) | ||
}, | ||
async readdir(directoryPath) { | ||
return syncFs.readdirSync(directoryPath); | ||
}, | ||
async readdir(directoryPath) { | ||
return syncFs.readdirSync(directoryPath) | ||
}, | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
}, | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath) | ||
}, | ||
async rmdir(directoryPath) { | ||
return syncFs.rmdirSync(directoryPath); | ||
}, | ||
async rmdir(directoryPath) { | ||
return syncFs.rmdirSync(directoryPath) | ||
}, | ||
async exists(nodePath) { | ||
return syncFs.existsSync(nodePath); | ||
}, | ||
async exists(nodePath) { | ||
return syncFs.existsSync(nodePath) | ||
}, | ||
async stat(nodePath) { | ||
return syncFs.statSync(nodePath); | ||
}, | ||
async stat(nodePath) { | ||
return syncFs.statSync(nodePath) | ||
}, | ||
async lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath); | ||
}, | ||
async lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath) | ||
}, | ||
async realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath); | ||
}, | ||
async realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath) | ||
}, | ||
async rename(srcPath, destPath) { | ||
return syncFs.renameSync(srcPath, destPath); | ||
}, | ||
async rename(path, newPath) { | ||
return syncFs.renameSync(path, newPath) | ||
async copyFile(...args) { | ||
return syncFs.copyFileSync(...args); | ||
}, | ||
async readlink(path) { | ||
return syncFs.readlinkSync(path); | ||
} | ||
}, | ||
async copyFile(src, dest, flags) { | ||
return syncFs.copyFileSync(src, dest, flags) | ||
} | ||
} | ||
exists(nodePath, callback) { | ||
callback(syncFs.existsSync(nodePath)); | ||
}, | ||
readFile: callbackify(syncFs.readFileSync) as IBaseFileSystemAsync['readFile'], | ||
writeFile: callbackify(syncFs.writeFileSync) as IBaseFileSystemAsync['writeFile'], | ||
copyFile: callbackify(syncFs.copyFileSync) as IBaseFileSystemAsync['copyFile'], | ||
unlink: callbackify(syncFs.unlinkSync), | ||
readdir: callbackify(syncFs.readdirSync), | ||
mkdir: callbackify(syncFs.mkdirSync), | ||
rmdir: callbackify(syncFs.rmdirSync), | ||
stat: callbackify(syncFs.statSync), | ||
lstat: callbackify(syncFs.lstatSync), | ||
realpath: callbackify(syncFs.realpathSync), | ||
rename: callbackify(syncFs.renameSync), | ||
readlink: callbackify(syncFs.readlinkSync) | ||
}; | ||
} |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
128677
57
1950
0
+ Added@file-services/types@1.0.4(transitive)
- Removed@file-services/types@0.4.11(transitive)
Updated@file-services/types@^1.0.0