Run with deno:
deno task deps <path to source dir>
| { | |
| "tasks": { | |
| "deps": "deno run --allow-read ./deps.ts" | |
| }, | |
| "imports": { | |
| "std/fs/": "https://deno.land/[email protected]/fs/", | |
| "std/path/": "https://deno.land/[email protected]/path/" | |
| } | |
| } |
| import { walk } from "std/fs/walk.ts"; | |
| import { toFileUrl } from "std/path/mod.ts"; | |
| const importMatcher = /^import.*?from\s+['"](.*?)['"];?$/gm; | |
| const sourceMatcher = /\.[tj]sx?$/; | |
| const enumerateFiles = async ( | |
| packageMatch: (name: string) => boolean, | |
| dir: URL | |
| ) => { | |
| const packages = new Set<string>(); | |
| for await (const entry of walk(dir, { | |
| includeFiles: true, | |
| includeDirs: false, | |
| match: [sourceMatcher], | |
| })) { | |
| const file = await Deno.open(entry.path, { read: true }); | |
| const reader = file.readable | |
| .pipeThrough(new TextDecoderStream()) | |
| .getReader(); | |
| while (true) { | |
| const { done, value } = await reader.read(); | |
| if (done) break; | |
| const matches = value.matchAll(importMatcher); | |
| for (const match of matches) { | |
| if (packageMatch(match[1])) packages.add(match[1]); | |
| } | |
| } | |
| } | |
| return packages; | |
| }; | |
| const target = new URL(Deno.args[0], toFileUrl(Deno.cwd()) + "/"); | |
| const packages = await enumerateFiles( | |
| (packageName) => | |
| !packageName.startsWith(".") && !packageName.startsWith("@blotoutio/"), | |
| target | |
| ); | |
| for (const code of packages) { | |
| console.log(code.toString()); | |
| } |