|
1 | 1 | import { parse, walk } from "./deps.ts";
|
2 |
| - |
3 |
| -// Async |
4 |
| -async function printFilesNames({ skip }: { skip?: RegExp | RegExp[] }) { |
| 2 | +import AsyncLimiterClass, { |
| 3 | + AsyncCurrentLimiter, |
| 4 | +} from "https://cdn.skypack.dev/@masx200/async-task-current-limiter?dts"; |
| 5 | +import { WalkEntry } from "https://deno.land/[email protected]/fs/_util.ts"; |
| 6 | +function searchFilesNames({ |
| 7 | + skip, |
| 8 | +}: // limiter, |
| 9 | + { |
| 10 | + skip?: RegExp | RegExp[]; |
| 11 | + // limiter: AsyncCurrentLimiter; |
| 12 | + }) { |
5 | 13 | console.log("type check start!");
|
| 14 | + |
| 15 | + const entry_iter = walk(".", { |
| 16 | + includeFiles: true, |
| 17 | + includeDirs: false, |
| 18 | + exts: ["ts"], |
| 19 | + skip: [/node_modules/, skip].flat().filter(Boolean) as RegExp[], |
| 20 | + }); |
| 21 | + return entry_iter; |
| 22 | +} |
| 23 | +if (import.meta.main) { |
| 24 | + /* deno run -A "check.ts" "--skip=npm|utils" */ |
| 25 | + await start(); |
| 26 | + // .catch(console.error); |
| 27 | +} |
| 28 | + |
| 29 | +async function parallel_check( |
| 30 | + entry_iter: AsyncIterableIterator<WalkEntry>, |
| 31 | + limiter: AsyncCurrentLimiter, |
| 32 | +) { |
6 | 33 | const stack: string[] = [];
|
7 |
| - for await ( |
8 |
| - const entry of walk(".", { |
9 |
| - includeFiles: true, |
10 |
| - includeDirs: false, |
11 |
| - exts: ["ts"], |
12 |
| - skip: [/node_modules/, skip].flat().filter(Boolean) as RegExp[], |
13 |
| - }) |
14 |
| - ) { |
| 34 | + |
| 35 | + const ps: Array<Promise<void>> = []; |
| 36 | + for await (const entry of entry_iter) { |
15 | 37 | console.log(entry.path);
|
16 | 38 | if (stack.length < 15) {
|
17 | 39 | stack.push(entry.path);
|
18 | 40 | } else {
|
19 |
| - await runDenoCheck([...stack, entry.path]); |
| 41 | + ps.push(limiter.run(() => runDenoCheck([...stack, entry.path]))); |
20 | 42 | stack.length = 0;
|
21 | 43 | // console.log({ status, stdout, stderr });
|
22 | 44 | }
|
23 | 45 | }
|
24 | 46 | if (stack.length) {
|
25 |
| - await runDenoCheck(stack); |
| 47 | + ps.push(limiter.run(() => runDenoCheck(stack))); |
26 | 48 | }
|
27 |
| -} |
28 |
| -if (import.meta.main) { |
29 |
| - /* deno run -A "check.ts" "--skip=npm|utils" */ |
30 |
| - await start(); |
31 |
| - // .catch(console.error); |
| 49 | + await Promise.all(ps); |
32 | 50 | }
|
33 | 51 |
|
34 | 52 | async function start() {
|
| 53 | + const limiter = new AsyncLimiterClass(navigator.hardwareConcurrency); |
35 | 54 | const args = parse(Deno.args);
|
36 | 55 | console.log(args);
|
37 | 56 | const skip = typeof args.skip === "string"
|
38 | 57 | ? new RegExp(String(args.skip))
|
39 | 58 | : Array.isArray(args.skip)
|
40 | 59 | ? args.skip.map((s) => new RegExp(s))
|
41 | 60 | : undefined;
|
42 |
| - await printFilesNames({ skip }).then(() => console.log("type check Done!")); |
| 61 | + const entry_iter = searchFilesNames({ skip }); |
| 62 | + await parallel_check(entry_iter, limiter); |
| 63 | + console.log("type check Done!"); |
43 | 64 | }
|
44 | 65 |
|
45 | 66 | async function runDenoCheck(stack: string[]) {
|
|
0 commit comments