Files
pnpm/__utils__/assert-project/src/isExecutable.ts
Zoltan Kochan 5d5818e44f style: enforce node: protocol for builtin imports (#10951)
Add n/prefer-node-protocol rule and autofix all bare builtin imports
to use the node: prefix. Simplify the simple-import-sort builtins
pattern to just ^node: since all imports now use the prefix.
2026-03-13 07:59:51 +01:00

23 lines
637 B
TypeScript

import fs from 'node:fs'
import isWindows from 'is-windows'
import isExe from 'isexe'
const IS_WINDOWS = isWindows()
// eslint-disable-next-line
export default (ok: (value: any, comment: string) => void, filePath: string): void => {
if (IS_WINDOWS) {
if (fs.existsSync(`${filePath}.cmd`)) {
ok(isExe.sync(`${filePath}.cmd`), `${filePath}.cmd is executable`)
} else {
ok(isExe.sync(`${filePath}.exe`), `${filePath}.exe is executable`)
}
return
}
const stat = fs.statSync(filePath)
ok((stat.mode & 0o111) === 0o111, `${filePath} is executable`)
ok(stat.isFile(), `${filePath} refers to a file`)
}