-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisland.ts
45 lines (40 loc) · 1.09 KB
/
island.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Plugin } from "$fresh/server.ts";
import fileUrl from "npm:file-url";
import { yellow } from "std/fmt/colors.ts";
import { expandGlob } from "std/fs/expand_glob.ts";
const start = performance.now();
const islands = new Set<string>();
const denoJson = JSON.parse(await Deno.readTextFile("deno.json"));
// const decoder = new TextDecoder();
for await (
const file of expandGlob("**/*.tsx", {
exclude: denoJson.exclude ?? [],
})
) {
if ((await Deno.readTextFile(file.path)).match(/['"]use client['"]/)) {
islands.add(fileUrl(file.path));
}
// const of = await Deno.open(file.path);
// const buffer = new Uint8Array(11);
// await Deno.read(of.rid, buffer);
// if (decoder.decode(buffer.slice(1)) === "use client") {
// islands.add(fileUrl(file.path));
// }
// Deno.close(of.rid);
}
console.log(
yellow(
`\u26A1 Found ${islands.size} islands in ${
Math.floor(performance.now() - start)
}ms`,
),
);
export default function islandsPlugin(): Plugin {
return {
name: "@island",
islands: {
baseLocation: "",
paths: [...islands],
},
};
}