Skip to content

Commit f2173e2

Browse files
committed
check
1 parent c768893 commit f2173e2

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

check.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,66 @@
11
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+
}) {
513
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+
) {
633
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) {
1537
console.log(entry.path);
1638
if (stack.length < 15) {
1739
stack.push(entry.path);
1840
} else {
19-
await runDenoCheck([...stack, entry.path]);
41+
ps.push(limiter.run(() => runDenoCheck([...stack, entry.path])));
2042
stack.length = 0;
2143
// console.log({ status, stdout, stderr });
2244
}
2345
}
2446
if (stack.length) {
25-
await runDenoCheck(stack);
47+
ps.push(limiter.run(() => runDenoCheck(stack)));
2648
}
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);
3250
}
3351

3452
async function start() {
53+
const limiter = new AsyncLimiterClass(navigator.hardwareConcurrency);
3554
const args = parse(Deno.args);
3655
console.log(args);
3756
const skip = typeof args.skip === "string"
3857
? new RegExp(String(args.skip))
3958
: Array.isArray(args.skip)
4059
? args.skip.map((s) => new RegExp(s))
4160
: 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!");
4364
}
4465

4566
async function runDenoCheck(stack: string[]) {

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"fmt": " deno fmt --config deno.json",
1010
"test": "deno test --parallel --unstable -A --config deno.json",
1111
"lint": "deno lint --config deno.json",
12-
"check": "deno run --unstable -A check.ts"
12+
"check": "deno run --unstable -A --config deno.json check.ts "
1313
},
1414
"fmt": {
1515
"options": {

0 commit comments

Comments
 (0)