fix-node-pty.ts 986 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bun
  2. import fs from "fs/promises"
  3. import path from "path"
  4. import { fileURLToPath } from "url"
  5. const __filename = fileURLToPath(import.meta.url)
  6. const __dirname = path.dirname(__filename)
  7. const dir = path.resolve(__dirname, "..")
  8. if (process.platform !== "win32") {
  9. const root = path.join(dir, "node_modules", "node-pty", "prebuilds")
  10. const dirs = await fs.readdir(root, { withFileTypes: true }).catch(() => [])
  11. const files = dirs.filter((x) => x.isDirectory()).map((x) => path.join(root, x.name, "spawn-helper"))
  12. const result = await Promise.all(
  13. files.map(async (file) => {
  14. const stat = await fs.stat(file).catch(() => undefined)
  15. if (!stat) return
  16. if ((stat.mode & 0o111) === 0o111) return
  17. await fs.chmod(file, stat.mode | 0o755)
  18. return file
  19. }),
  20. )
  21. const fixed = result.filter(Boolean)
  22. if (fixed.length) {
  23. console.log(`fixed node-pty permissions for ${fixed.length} helper${fixed.length === 1 ? "" : "s"}`)
  24. }
  25. }