typecheck.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env bun
  2. /**
  3. * Cross-platform typecheck script that runs tsc and filters errors.
  4. *
  5. * Replaces the previous bash/grep pipeline so `bun run typecheck` works
  6. * on Windows without POSIX tools.
  7. *
  8. * Usage:
  9. * bun script/typecheck.ts # check extension
  10. * bun script/typecheck.ts --project webview-ui/tsconfig.json # check webview
  11. *
  12. * Filtering rules:
  13. * - Only lines matching "error TS" are reported
  14. * - Lines starting with ".." (parent node_modules) are excluded
  15. * - For the webview project, "@pierre/diffs" errors are also excluded
  16. */
  17. import { $ } from "bun"
  18. const args = process.argv.slice(2)
  19. const projectIdx = args.indexOf("--project")
  20. const project = projectIdx !== -1 ? args[projectIdx + 1] : undefined
  21. const webview = project?.includes("webview-ui")
  22. const tscArgs = project ? ["--noEmit", "--project", project] : ["--noEmit"]
  23. const result = await $`tsc ${tscArgs}`.nothrow().quiet()
  24. const output = result.stdout.toString() + result.stderr.toString()
  25. const errors = output
  26. .split("\n")
  27. .filter((line) => line.includes("error TS"))
  28. .filter((line) => !line.startsWith(".."))
  29. .filter((line) => !webview || !line.includes("@pierre/diffs"))
  30. if (errors.length > 0) {
  31. console.error(errors.join("\n"))
  32. process.exit(1)
  33. }