From 5241fe2018af7d6b6c92103525b482c1b0b215a0 Mon Sep 17 00:00:00 2001 From: Thomas Neil James Shadwell Date: Mon, 29 May 2023 00:40:29 +0900 Subject: [PATCH] Minor refactor of ts/fs/index.ts This makes the fake root duck typed. The type of the fakeroot was breaking a couple of patch integrations like https://github.com/Zemnmez/monorepo/pull/3143. I tried a fix in https://github.com/Zemnmez/monorepo/pull/3145, but it seems to have weird effects on the node exection environment, I'm guessing due to a bad lockfile change. --- ts/fs/index.ts | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/ts/fs/index.ts b/ts/fs/index.ts index 3b939d4ecd..1e7b6191bc 100644 --- a/ts/fs/index.ts +++ b/ts/fs/index.ts @@ -21,32 +21,34 @@ export function getPath(...d: Pick[]) { async function* _walk( path: Promise | 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( // 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()