@file-services/utils
Advanced tools
Comparing version 1.0.4 to 2.0.0
@@ -13,3 +13,3 @@ "use strict"; | ||
function createExtendedSyncActions(baseFs) { | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync } = baseFs; | ||
const { statSync, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync, dirname, join, resolve } = baseFs; | ||
function fileExistsSync(filePath, statFn = statSync) { | ||
@@ -42,3 +42,3 @@ try { | ||
catch (e) { | ||
const parentPath = path.dirname(directoryPath); | ||
const parentPath = dirname(directoryPath); | ||
if (parentPath === directoryPath) { | ||
@@ -55,5 +55,5 @@ throw e; | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
const nodePath = join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
ensureDirectorySync(path.dirname(nodePath)); | ||
ensureDirectorySync(dirname(nodePath)); | ||
writeFileSync(nodePath, nodeValue); | ||
@@ -73,3 +73,3 @@ filePaths.push(nodePath); | ||
for (const entryName of directoryItems) { | ||
removeSync(path.join(entryPath, entryName)); | ||
removeSync(join(entryPath, entryName)); | ||
} | ||
@@ -88,3 +88,3 @@ rmdirSync(entryPath); | ||
for (const nodeName of readdirSync(rootDirectory)) { | ||
const nodePath = path.join(rootDirectory, nodeName); | ||
const nodePath = join(rootDirectory, nodeName); | ||
try { | ||
@@ -110,6 +110,6 @@ const nodeStats = statSync(nodePath); | ||
function findClosestFileSync(initialDirectoryPath, fileName) { | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (fileExistsSync(filePath)) { | ||
@@ -119,3 +119,3 @@ return filePath; | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -126,6 +126,6 @@ return null; | ||
const filePaths = []; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (fileExistsSync(filePath)) { | ||
@@ -135,3 +135,3 @@ filePaths.push(filePath); | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -144,6 +144,6 @@ return filePaths; | ||
// 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), | ||
ensureDirectorySync: directoryPath => ensureDirectorySync(resolve(directoryPath)), | ||
populateDirectorySync: (directoryPath, contents) => populateDirectorySync(resolve(directoryPath), contents), | ||
removeSync: entryPath => removeSync(resolve(entryPath)), | ||
findFilesSync: (rootDirectory, options) => findFilesSync(resolve(rootDirectory), options), | ||
findClosestFileSync, | ||
@@ -160,3 +160,3 @@ findFilesInAncestorsSync, | ||
function createExtendedFileSystemPromiseActions(baseFs) { | ||
const { path, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } } = baseFs; | ||
const { dirname, resolve, join, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } } = baseFs; | ||
async function fileExists(filePath, statFn = stat) { | ||
@@ -189,3 +189,3 @@ try { | ||
catch (e) { | ||
const parentPath = path.dirname(directoryPath); | ||
const parentPath = dirname(directoryPath); | ||
if (parentPath === directoryPath) { | ||
@@ -202,5 +202,5 @@ throw e; | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
const nodePath = join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
await ensureDirectory(path.dirname(nodePath)); | ||
await ensureDirectory(dirname(nodePath)); | ||
await writeFile(nodePath, nodeValue); | ||
@@ -219,3 +219,3 @@ filePaths.push(nodePath); | ||
const directoryItems = await readdir(entryPath); | ||
await Promise.all(directoryItems.map(entryName => remove(path.join(entryPath, entryName)))); | ||
await Promise.all(directoryItems.map(entryName => remove(join(entryPath, entryName)))); | ||
await rmdir(entryPath); | ||
@@ -233,3 +233,3 @@ } | ||
for (const nodeName of await readdir(rootDirectory)) { | ||
const nodePath = path.join(rootDirectory, nodeName); | ||
const nodePath = join(rootDirectory, nodeName); | ||
try { | ||
@@ -255,6 +255,6 @@ const nodeStats = await stat(nodePath); | ||
async function findClosestFile(initialDirectoryPath, fileName) { | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (await fileExists(filePath)) { | ||
@@ -264,3 +264,3 @@ return filePath; | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -271,6 +271,6 @@ return null; | ||
const filePaths = []; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (await fileExists(filePath)) { | ||
@@ -280,3 +280,3 @@ filePaths.push(filePath); | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -288,6 +288,6 @@ return filePaths; | ||
directoryExists, | ||
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), | ||
ensureDirectory: directoryPath => ensureDirectory(resolve(directoryPath)), | ||
populateDirectory: (directoryPath, contents) => populateDirectory(resolve(directoryPath), contents), | ||
remove: entryPath => remove(resolve(entryPath)), | ||
findFiles: (rootDirectory, options) => findFiles(resolve(rootDirectory), options), | ||
findClosestFile, | ||
@@ -294,0 +294,0 @@ findFilesInAncestors, |
@@ -5,7 +5,3 @@ "use strict"; | ||
function syncToAsyncFs(syncFs) { | ||
return { | ||
path: syncFs.path, | ||
watchService: syncFs.watchService, | ||
caseSensitive: syncFs.caseSensitive, | ||
promises: { | ||
return Object.assign({}, syncFs, { watchService: syncFs.watchService, caseSensitive: syncFs.caseSensitive, promises: { | ||
readFile: async function readFile(...args) { | ||
@@ -50,21 +46,7 @@ return syncFs.readFileSync(...args); | ||
} | ||
}, | ||
exists(nodePath, callback) { | ||
}, exists(nodePath, callback) { | ||
callback(syncFs.existsSync(nodePath)); | ||
}, | ||
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) | ||
}; | ||
}, 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) }); | ||
} | ||
exports.syncToAsyncFs = syncToAsyncFs; | ||
//# sourceMappingURL=sync-to-async-fs.js.map |
@@ -9,3 +9,3 @@ const returnsTrue = () => true; | ||
export function createExtendedSyncActions(baseFs) { | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync } = baseFs; | ||
const { statSync, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync, readFileSync, dirname, join, resolve } = baseFs; | ||
function fileExistsSync(filePath, statFn = statSync) { | ||
@@ -38,3 +38,3 @@ try { | ||
catch (e) { | ||
const parentPath = path.dirname(directoryPath); | ||
const parentPath = dirname(directoryPath); | ||
if (parentPath === directoryPath) { | ||
@@ -51,5 +51,5 @@ throw e; | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
const nodePath = join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
ensureDirectorySync(path.dirname(nodePath)); | ||
ensureDirectorySync(dirname(nodePath)); | ||
writeFileSync(nodePath, nodeValue); | ||
@@ -69,3 +69,3 @@ filePaths.push(nodePath); | ||
for (const entryName of directoryItems) { | ||
removeSync(path.join(entryPath, entryName)); | ||
removeSync(join(entryPath, entryName)); | ||
} | ||
@@ -84,3 +84,3 @@ rmdirSync(entryPath); | ||
for (const nodeName of readdirSync(rootDirectory)) { | ||
const nodePath = path.join(rootDirectory, nodeName); | ||
const nodePath = join(rootDirectory, nodeName); | ||
try { | ||
@@ -106,6 +106,6 @@ const nodeStats = statSync(nodePath); | ||
function findClosestFileSync(initialDirectoryPath, fileName) { | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (fileExistsSync(filePath)) { | ||
@@ -115,3 +115,3 @@ return filePath; | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -122,6 +122,6 @@ return null; | ||
const filePaths = []; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (fileExistsSync(filePath)) { | ||
@@ -131,3 +131,3 @@ filePaths.push(filePath); | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -140,6 +140,6 @@ return filePaths; | ||
// 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), | ||
ensureDirectorySync: directoryPath => ensureDirectorySync(resolve(directoryPath)), | ||
populateDirectorySync: (directoryPath, contents) => populateDirectorySync(resolve(directoryPath), contents), | ||
removeSync: entryPath => removeSync(resolve(entryPath)), | ||
findFilesSync: (rootDirectory, options) => findFilesSync(resolve(rootDirectory), options), | ||
findClosestFileSync, | ||
@@ -154,3 +154,3 @@ findFilesInAncestorsSync, | ||
export function createExtendedFileSystemPromiseActions(baseFs) { | ||
const { path, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } } = baseFs; | ||
const { dirname, resolve, join, promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } } = baseFs; | ||
async function fileExists(filePath, statFn = stat) { | ||
@@ -183,3 +183,3 @@ try { | ||
catch (e) { | ||
const parentPath = path.dirname(directoryPath); | ||
const parentPath = dirname(directoryPath); | ||
if (parentPath === directoryPath) { | ||
@@ -196,5 +196,5 @@ throw e; | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
const nodePath = join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
await ensureDirectory(path.dirname(nodePath)); | ||
await ensureDirectory(dirname(nodePath)); | ||
await writeFile(nodePath, nodeValue); | ||
@@ -213,3 +213,3 @@ filePaths.push(nodePath); | ||
const directoryItems = await readdir(entryPath); | ||
await Promise.all(directoryItems.map(entryName => remove(path.join(entryPath, entryName)))); | ||
await Promise.all(directoryItems.map(entryName => remove(join(entryPath, entryName)))); | ||
await rmdir(entryPath); | ||
@@ -227,3 +227,3 @@ } | ||
for (const nodeName of await readdir(rootDirectory)) { | ||
const nodePath = path.join(rootDirectory, nodeName); | ||
const nodePath = join(rootDirectory, nodeName); | ||
try { | ||
@@ -249,6 +249,6 @@ const nodeStats = await stat(nodePath); | ||
async function findClosestFile(initialDirectoryPath, fileName) { | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (await fileExists(filePath)) { | ||
@@ -258,3 +258,3 @@ return filePath; | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -265,6 +265,6 @@ return null; | ||
const filePaths = []; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (await fileExists(filePath)) { | ||
@@ -274,3 +274,3 @@ filePaths.push(filePath); | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -282,6 +282,6 @@ return filePaths; | ||
directoryExists, | ||
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), | ||
ensureDirectory: directoryPath => ensureDirectory(resolve(directoryPath)), | ||
populateDirectory: (directoryPath, contents) => populateDirectory(resolve(directoryPath), contents), | ||
remove: entryPath => remove(resolve(entryPath)), | ||
findFiles: (rootDirectory, options) => findFiles(resolve(rootDirectory), options), | ||
findClosestFile, | ||
@@ -288,0 +288,0 @@ findFilesInAncestors, |
import { callbackify } from './callbackify'; | ||
export function syncToAsyncFs(syncFs) { | ||
return { | ||
path: syncFs.path, | ||
watchService: syncFs.watchService, | ||
caseSensitive: syncFs.caseSensitive, | ||
promises: { | ||
return Object.assign({}, syncFs, { watchService: syncFs.watchService, caseSensitive: syncFs.caseSensitive, promises: { | ||
readFile: async function readFile(...args) { | ||
@@ -47,20 +43,6 @@ return syncFs.readFileSync(...args); | ||
} | ||
}, | ||
exists(nodePath, callback) { | ||
}, exists(nodePath, callback) { | ||
callback(syncFs.existsSync(nodePath)); | ||
}, | ||
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) | ||
}; | ||
}, 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": "1.0.4", | ||
"version": "2.0.0", | ||
"main": "cjs/index.js", | ||
@@ -14,3 +14,3 @@ "module": "esm/index.js", | ||
"dependencies": { | ||
"@file-services/types": "^1.0.4" | ||
"@file-services/types": "^2.0.0" | ||
}, | ||
@@ -30,3 +30,3 @@ "files": [ | ||
"sideEffects": false, | ||
"gitHead": "5324bae9c23054284cb0727692dae2b6a1cb1560" | ||
"gitHead": "1a5d5c8e7ab35d213ba47fe0585ec5887df08d7c" | ||
} |
@@ -39,3 +39,2 @@ import { | ||
statSync, | ||
path, | ||
mkdirSync, | ||
@@ -47,3 +46,6 @@ writeFileSync, | ||
readdirSync, | ||
readFileSync | ||
readFileSync, | ||
dirname, | ||
join, | ||
resolve | ||
} = baseFs; | ||
@@ -81,3 +83,3 @@ | ||
} catch (e) { | ||
const parentPath = path.dirname(directoryPath); | ||
const parentPath = dirname(directoryPath); | ||
if (parentPath === directoryPath) { | ||
@@ -95,5 +97,5 @@ throw e; | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
const nodePath = join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
ensureDirectorySync(path.dirname(nodePath)); | ||
ensureDirectorySync(dirname(nodePath)); | ||
writeFileSync(nodePath, nodeValue); | ||
@@ -113,3 +115,3 @@ filePaths.push(nodePath); | ||
for (const entryName of directoryItems) { | ||
removeSync(path.join(entryPath, entryName)); | ||
removeSync(join(entryPath, entryName)); | ||
} | ||
@@ -128,3 +130,3 @@ rmdirSync(entryPath); | ||
for (const nodeName of readdirSync(rootDirectory)) { | ||
const nodePath = path.join(rootDirectory, nodeName); | ||
const nodePath = join(rootDirectory, nodeName); | ||
try { | ||
@@ -150,7 +152,7 @@ const nodeStats = statSync(nodePath); | ||
function findClosestFileSync(initialDirectoryPath: string, fileName: string): string | null { | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath: string | undefined; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (fileExistsSync(filePath)) { | ||
@@ -160,3 +162,3 @@ return filePath; | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -169,7 +171,7 @@ | ||
const filePaths: string[] = []; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath: string | undefined; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (fileExistsSync(filePath)) { | ||
@@ -179,3 +181,3 @@ filePaths.push(filePath); | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -190,7 +192,6 @@ | ||
// 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), | ||
ensureDirectorySync: directoryPath => ensureDirectorySync(resolve(directoryPath)), | ||
populateDirectorySync: (directoryPath, contents) => populateDirectorySync(resolve(directoryPath), contents), | ||
removeSync: entryPath => removeSync(resolve(entryPath)), | ||
findFilesSync: (rootDirectory, options) => findFilesSync(resolve(rootDirectory), options), | ||
findClosestFileSync, | ||
@@ -216,3 +217,5 @@ findFilesInAncestorsSync, | ||
const { | ||
path, | ||
dirname, | ||
resolve, | ||
join, | ||
promises: { stat, mkdir, writeFile, lstat, rmdir, unlink, readdir, readFile } | ||
@@ -251,3 +254,3 @@ } = baseFs; | ||
} catch (e) { | ||
const parentPath = path.dirname(directoryPath); | ||
const parentPath = dirname(directoryPath); | ||
if (parentPath === directoryPath) { | ||
@@ -265,5 +268,5 @@ throw e; | ||
for (const [nodeName, nodeValue] of Object.entries(contents)) { | ||
const nodePath = path.join(directoryPath, nodeName); | ||
const nodePath = join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
await ensureDirectory(path.dirname(nodePath)); | ||
await ensureDirectory(dirname(nodePath)); | ||
await writeFile(nodePath, nodeValue); | ||
@@ -282,3 +285,3 @@ filePaths.push(nodePath); | ||
const directoryItems = await readdir(entryPath); | ||
await Promise.all(directoryItems.map(entryName => remove(path.join(entryPath, entryName)))); | ||
await Promise.all(directoryItems.map(entryName => remove(join(entryPath, entryName)))); | ||
await rmdir(entryPath); | ||
@@ -300,3 +303,3 @@ } else if (stats.isFile() || stats.isSymbolicLink()) { | ||
for (const nodeName of await readdir(rootDirectory)) { | ||
const nodePath = path.join(rootDirectory, nodeName); | ||
const nodePath = join(rootDirectory, nodeName); | ||
try { | ||
@@ -321,7 +324,7 @@ const nodeStats = await stat(nodePath); | ||
async function findClosestFile(initialDirectoryPath: string, fileName: string): Promise<string | null> { | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath: string | undefined; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (await fileExists(filePath)) { | ||
@@ -331,3 +334,3 @@ return filePath; | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -340,7 +343,7 @@ | ||
const filePaths: string[] = []; | ||
let currentPath = path.resolve(initialDirectoryPath); | ||
let currentPath = resolve(initialDirectoryPath); | ||
let lastPath: string | undefined; | ||
while (currentPath !== lastPath) { | ||
const filePath = path.join(currentPath, fileName); | ||
const filePath = join(currentPath, fileName); | ||
if (await fileExists(filePath)) { | ||
@@ -350,3 +353,3 @@ filePaths.push(filePath); | ||
lastPath = currentPath; | ||
currentPath = path.dirname(currentPath); | ||
currentPath = dirname(currentPath); | ||
} | ||
@@ -360,6 +363,6 @@ | ||
directoryExists, | ||
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), | ||
ensureDirectory: directoryPath => ensureDirectory(resolve(directoryPath)), | ||
populateDirectory: (directoryPath, contents) => populateDirectory(resolve(directoryPath), contents), | ||
remove: entryPath => remove(resolve(entryPath)), | ||
findFiles: (rootDirectory, options) => findFiles(resolve(rootDirectory), options), | ||
findClosestFile, | ||
@@ -366,0 +369,0 @@ findFilesInAncestors, |
@@ -6,3 +6,3 @@ import { IBaseFileSystemSync, IBaseFileSystemAsync, IBaseFileSystemPromiseActions } from '@file-services/types'; | ||
return { | ||
path: syncFs.path, | ||
...syncFs, | ||
watchService: syncFs.watchService, | ||
@@ -9,0 +9,0 @@ caseSensitive: syncFs.caseSensitive, |
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
90721
1346
+ Added@file-services/types@2.2.0(transitive)
- Removed@file-services/types@1.0.4(transitive)
Updated@file-services/types@^2.0.0