@file-services/utils
Advanced tools
Comparing version 0.2.3 to 0.3.0
export { syncToAsyncFs } from './sync-to-async-fs'; | ||
export { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api'; | ||
export { createDirectoryFs } from './directory-fs'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -8,2 +8,4 @@ "use strict"; | ||
exports.createSyncFileSystem = create_extended_api_1.createSyncFileSystem; | ||
var directory_fs_1 = require("./directory-fs"); | ||
exports.createDirectoryFs = directory_fs_1.createDirectoryFs; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function syncToAsyncFs(syncFs) { | ||
async function readFile(filePath) { | ||
return syncFs.readFileSync(filePath); | ||
} | ||
async function writeFile(filePath, content) { | ||
return syncFs.writeFileSync(filePath, content); | ||
} | ||
async function unlink(filePath) { | ||
return syncFs.unlinkSync(filePath); | ||
} | ||
async function readdir(directoryPath) { | ||
return syncFs.readdirSync(directoryPath); | ||
} | ||
async function mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
} | ||
async function rmdir(directoryPath) { | ||
return syncFs.rmdirSync(directoryPath); | ||
} | ||
async function stat(nodePath) { | ||
return syncFs.statSync(nodePath); | ||
} | ||
async function lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath); | ||
} | ||
async function realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath); | ||
} | ||
return { | ||
@@ -35,11 +8,32 @@ path: syncFs.path, | ||
caseSensitive: syncFs.caseSensitive, | ||
readFile, | ||
writeFile, | ||
unlink, | ||
readdir, | ||
mkdir, | ||
rmdir, | ||
stat, | ||
lstat, | ||
realpath | ||
async readFile(filePath, encoding) { | ||
return syncFs.readFileSync(filePath, encoding); | ||
}, | ||
async readFileRaw(filePath) { | ||
return syncFs.readFileRawSync(filePath); | ||
}, | ||
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 stat(nodePath) { | ||
return syncFs.statSync(nodePath); | ||
}, | ||
async lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath); | ||
}, | ||
async realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath); | ||
} | ||
}; | ||
@@ -46,0 +40,0 @@ } |
export { syncToAsyncFs } from './sync-to-async-fs'; | ||
export { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api'; | ||
export { createDirectoryFs } from './directory-fs'; | ||
//# sourceMappingURL=index.d.ts.map |
export { syncToAsyncFs } from './sync-to-async-fs'; | ||
export { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api'; | ||
export { createDirectoryFs } from './directory-fs'; | ||
//# sourceMappingURL=index.js.map |
export function syncToAsyncFs(syncFs) { | ||
async function readFile(filePath) { | ||
return syncFs.readFileSync(filePath); | ||
} | ||
async function writeFile(filePath, content) { | ||
return syncFs.writeFileSync(filePath, content); | ||
} | ||
async function unlink(filePath) { | ||
return syncFs.unlinkSync(filePath); | ||
} | ||
async function readdir(directoryPath) { | ||
return syncFs.readdirSync(directoryPath); | ||
} | ||
async function mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
} | ||
async function rmdir(directoryPath) { | ||
return syncFs.rmdirSync(directoryPath); | ||
} | ||
async function stat(nodePath) { | ||
return syncFs.statSync(nodePath); | ||
} | ||
async function lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath); | ||
} | ||
async function realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath); | ||
} | ||
return { | ||
@@ -33,13 +6,34 @@ path: syncFs.path, | ||
caseSensitive: syncFs.caseSensitive, | ||
readFile, | ||
writeFile, | ||
unlink, | ||
readdir, | ||
mkdir, | ||
rmdir, | ||
stat, | ||
lstat, | ||
realpath | ||
async readFile(filePath, encoding) { | ||
return syncFs.readFileSync(filePath, encoding); | ||
}, | ||
async readFileRaw(filePath) { | ||
return syncFs.readFileRawSync(filePath); | ||
}, | ||
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 stat(nodePath) { | ||
return syncFs.statSync(nodePath); | ||
}, | ||
async lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath); | ||
}, | ||
async realpath(nodePath) { | ||
return syncFs.realpathSync(nodePath); | ||
} | ||
}; | ||
} | ||
//# sourceMappingURL=sync-to-async-fs.js.map |
{ | ||
"name": "@file-services/utils", | ||
"description": "Common file system utility functions.", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"main": "cjs/index.js", | ||
@@ -10,13 +10,13 @@ "module": "esm/index.js", | ||
"clean": "rimraf ./cjs ./esm", | ||
"build": "run-p build:cjs build:esm", | ||
"build:cjs": "tsc --project src --outDir cjs --module commonjs", | ||
"build:esm": "tsc --project src --outDir esm --module esnext", | ||
"build": "ts-build ./src --cjs --esm", | ||
"lint": "run-p lint:src", | ||
"lint:src": "tslint --project src" | ||
"lint:src": "tslint --project src", | ||
"test": "mocha -r @ts-tools/node \"test/**/*.spec.ts?(x)\" --watch-extensions ts,tsx", | ||
"prepack": "yarn build" | ||
}, | ||
"dependencies": { | ||
"@file-services/types": "^0.2.2" | ||
"@file-services/types": "^0.3.0" | ||
}, | ||
"devDependencies": { | ||
"@file-services/test-kit": "^0.2.3" | ||
"@file-services/test-kit": "^0.3.0" | ||
}, | ||
@@ -35,3 +35,3 @@ "files": [ | ||
"sideEffects": false, | ||
"gitHead": "68f9be20d4e252e45d5b79a33730e831c355113f" | ||
"gitHead": "6203b5b30191f38c522498dfb1a3a31ef42c5cba" | ||
} |
@@ -9,1 +9,24 @@ # @file-services/utils | ||
- `syncToAsyncFs`: convert a sync-only file system implementation into an async one. | ||
- `createDirectoryFs`: A file system wrapper that adds directory scoping to any `IFileSystem` implementation. | ||
# Usage | ||
## Directory scoped file system | ||
Install library in project: | ||
```sh | ||
yarn add @file-services/utils | ||
``` | ||
Then, use the programmatic API: | ||
```ts | ||
import { nodeFs } from '@file-services/node' | ||
import { createDirectoryFs } from '@file-services/utils' | ||
const directoryFs = createDirectoryFs(nodeFs, '/path/to/some/folder') | ||
// will be written to /path/to/some/folder/file.js | ||
directoryFs.writeFileSync('/file.js', 'SAMPLE') | ||
// returns 'SAMPLE' | ||
directoryFs.readFileSync('/file.js') | ||
``` |
export { syncToAsyncFs } from './sync-to-async-fs' | ||
export { createAsyncFileSystem, createSyncFileSystem } from './create-extended-api' | ||
export { createDirectoryFs } from './directory-fs' |
@@ -1,57 +0,49 @@ | ||
import { IBaseFileSystemSync, IBaseFileSystemAsync, IFileSystemStats } from '@file-services/types' | ||
import { IBaseFileSystemSync, IBaseFileSystemAsync } from '@file-services/types' | ||
export function syncToAsyncFs(syncFs: IBaseFileSystemSync): IBaseFileSystemAsync { | ||
async function readFile(filePath: string): Promise<string> { | ||
return syncFs.readFileSync(filePath) | ||
} | ||
return { | ||
path: syncFs.path, | ||
watchService: syncFs.watchService, | ||
caseSensitive: syncFs.caseSensitive, | ||
async function writeFile(filePath: string, content: string): Promise<void> { | ||
return syncFs.writeFileSync(filePath, content) | ||
} | ||
async readFile(filePath, encoding) { | ||
return syncFs.readFileSync(filePath, encoding) | ||
}, | ||
async function unlink(filePath: string): Promise<void> { | ||
return syncFs.unlinkSync(filePath) | ||
} | ||
async readFileRaw(filePath) { | ||
return syncFs.readFileRawSync(filePath) | ||
}, | ||
async function readdir(directoryPath: string): Promise<string[]> { | ||
return syncFs.readdirSync(directoryPath) | ||
} | ||
async writeFile(filePath, content, encoding) { | ||
return syncFs.writeFileSync(filePath, content, encoding) | ||
}, | ||
async function mkdir(directoryPath: string): Promise<void> { | ||
return syncFs.mkdirSync(directoryPath) | ||
} | ||
async unlink(filePath) { | ||
return syncFs.unlinkSync(filePath) | ||
}, | ||
async function rmdir(directoryPath: string): Promise<void> { | ||
return syncFs.rmdirSync(directoryPath) | ||
} | ||
async readdir(directoryPath) { | ||
return syncFs.readdirSync(directoryPath) | ||
}, | ||
async function stat(nodePath: string): Promise<IFileSystemStats> { | ||
return syncFs.statSync(nodePath) | ||
} | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath) | ||
}, | ||
async function lstat(nodePath: string): Promise<IFileSystemStats> { | ||
return syncFs.lstatSync(nodePath) | ||
} | ||
async rmdir(directoryPath) { | ||
return syncFs.rmdirSync(directoryPath) | ||
}, | ||
async function realpath(nodePath: string): Promise<string> { | ||
return syncFs.realpathSync(nodePath) | ||
} | ||
async stat(nodePath) { | ||
return syncFs.statSync(nodePath) | ||
}, | ||
return { | ||
path: syncFs.path, | ||
watchService: syncFs.watchService, | ||
caseSensitive: syncFs.caseSensitive, | ||
async lstat(nodePath) { | ||
return syncFs.lstatSync(nodePath) | ||
}, | ||
readFile, | ||
writeFile, | ||
unlink, | ||
readdir, | ||
mkdir, | ||
rmdir, | ||
stat, | ||
lstat, | ||
realpath | ||
async realpath(nodePath) { | ||
return syncFs.realpathSync(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
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
52556
40
856
32
+ Added@file-services/types@0.3.0(transitive)
- Removed@file-services/types@0.2.2(transitive)
Updated@file-services/types@^0.3.0