deno.land / std@0.224.0 / _tools / check_browser_compat.ts

check_browser_compat.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
46
47
48
49
50
51
52
53
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/** * Running this script provides a list of suggested files that might be browser-compatible. * It skips test code, benchmark code, internal code and `version.ts` at the root. * * Run using: deno run --allow-read --allow-run _tools/check_browser_compat.ts */
import { walk } from "../fs/walk.ts";import { COPYRIGHT } from "./check_licence.ts";
const ROOT = new URL("../", import.meta.url);const SKIP = [/(test|bench|\/_|\\_|testdata|version.ts)/];const DECLARATION = "// This module is browser compatible.";const CHECK = Deno.args.includes("--check");
function isBrowserCompatible(filePath: string): boolean { const command = new Deno.Command(Deno.execPath(), { args: [ "check", "--no-lock", "--config", "browser-compat.tsconfig.json", filePath, ], }); const { success } = command.outputSync(); return success;}
function hasBrowserCompatibleComment(source: string): boolean { return source.includes(DECLARATION);}
for await (const { path } of walk(ROOT, { exts: [".ts"], skip: SKIP })) { const source = await Deno.readTextFile(path); if (isBrowserCompatible(path) && !hasBrowserCompatibleComment(source)) { if (CHECK) { console.log( `${path} is likely browser-compatible and can have the "${DECLARATION}" comment added.`, ); } else { const index = source.indexOf(COPYRIGHT); await Deno.writeTextFile( path, source.slice(0, index + COPYRIGHT.length) + "\n" + DECLARATION + source.slice(index + COPYRIGHT.length), ); } }}
std

Version Info

Tagged at
3 weeks ago