Skip to content

Commit

Permalink
Merge pull request #3147 from Zemnmez/minor-refactor-fakeroot
Browse files Browse the repository at this point in the history
Minor refactor of ts/fs/index.ts
  • Loading branch information
Zemnmez authored May 28, 2023
2 parents 6f5fd24 + 5241fe2 commit 2ed37a1
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions ts/fs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,34 @@ export function getPath(...d: Pick<fs.Dirent, 'name'>[]) {
async function* _walk(
path: Promise<string> | string
): AsyncGenerator<[value: Dirent, ...parents: Dirent[]], void, unknown> {
const fakeRoot = {
name: await path,
isDirectory() {
return true;
},
isFile() {
return false;
},
isBlockDevice() {
return false;
},
isCharacterDevice() {
return false;
},
isSymbolicLink() {
throw new Error('possibly.');
},
isFIFO() {
return false;
},
isSocket() {
return false;
},
path: await path,
};
yield* iter.asyncWalkPath<Dirent>(
// this is a fake root dir to make the code simpler.
{
name: await path,
isDirectory() {
return true;
},
isFile() {
return false;
},
isBlockDevice() {
return false;
},
isCharacterDevice() {
return false;
},
isSymbolicLink() {
throw new Error('possibly.');
},
isFIFO() {
return false;
},
isSocket() {
return false;
},
},
fakeRoot,
// if the current node is a directory, walk its children.
async ([v, ...parents]) =>
v.isDirectory()
Expand Down

0 comments on commit 2ed37a1

Please sign in to comment.