Created
April 1, 2020 02:15
-
-
Save soswow/baad1cf8890a2d963f70685f6bbfe911 to your computer and use it in GitHub Desktop.
Async generator walk in nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const extractSubNodeModules = async function*( | |
dir: string, | |
): AsyncGenerator<string, void, void> { | |
const files = await readdir(dir); | |
for (let i = 0; i < files.length; i++) { | |
const filepath = join(dir, files[i]); | |
const stats = await stat(filepath); | |
if (stats.isDirectory()) { | |
if (files[i] === 'node_modules') { | |
yield filepath; | |
} else { | |
yield* await extractSubNodeModules(filepath); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment