isexe

中文文档
4.0.0发布于 2026/02/10BlueOak-1.0.0TypeScriptESM + CJS零依赖近 30 天下载 14亿

检查文件是否可执行的最小模块。

中文使用文档
文档目录6 节
  1. 用法
  2. API
  3. isexe(path, [options]) => Promise<boolean>
  4. sync(path, [options]) => boolean
  5. 平台特定实现
  6. 选项

isexe

用于检查文件是否可执行和正常文件的最小模块。

使用 fs.stat 并对 PATHEXT 环境变量on 窗户。

用法

// default export is a minified version that doesn't need to
// load more than one file. Load the 'isexe/raw' export if
// you want the non-minified version for some reason.
import { isexe, sync } from 'isexe'
// or require() works too
// const { isexe } = require('isexe')
isexe('some-file-name').then(
  isExe => {
    if (isExe) {
      console.error('this thing can be run')
    } else {
      console.error('cannot be run')
    }
  },
  err => {
    console.error('probably file doesnt exist or something')
  },
)

// same thing but synchronous, throws errors
isExe = sync('some-file-name')

// treat errors as just "not executable"
const isExe = await isexe('maybe-missing-file', { ignoreErrors: true })
const isExe = sync('maybe-missing-file', { ignoreErrors: true })

API

isexe(path, [options]) => Promise<boolean>

检查路径是否可执行。

会引起任何可能引起的错误吗 fs.stat,除非 options.ignoreErrors 设置为true。

sync(path, [options]) => boolean

一样 isexe 但是返回值并抛出引发的任何错误。

平台特定实现

如果出于某种原因你想使用a的实现 特定的平台,你可以这样做。

import { win32, posix } from 'isexe'
win32.isexe(...)
win32.sync(...)
// etc

// or:
import { isexe, sync } from 'isexe/posix'

默认的导出实现将基于以下选择 process.platform。

选项

import type IsexeOptions from 'isexe'
  • ignoreErrors 把所有的错误都当作“不,这不是。 可执行文件”,但不要提高它们。
  • uid 在posix上用作用户id的数字
  • gid 在posix上用作组id的号码
  • pathExt 要使用的路径扩展名列表 PATHEXT Windows上的环境变量。

版本与发布记录

isexe 共发布 14 个版本,首次发布于 2016/01/17;过去 12 个月发布了 5 个版本。

版本发布日期距今
4.0.0latest2026/02/108 个月前
3.1.52026/02/108 个月前
3.1.42026/02/088 个月前
3.1.32026/02/088 个月前
3.1.22026/02/069 个月前
3.1.12023/08/033 年前

关于 isexe 的常见问题

isexe 是什么?

检查文件是否可执行的最小模块。

如何安装 isexe?

在项目目录运行 npm install isexe,或使用 pnpm add / yarn add / bun add。

isexe 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

isexe 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

isexe 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

isexe 可以商用吗?

isexe 使用 BlueOak-1.0.0 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

isexe 的下载量有多少?

根据 npm 官方下载统计,isexe 在 2026/10/07 – 2026/11/05 这 30 天内被下载 1,403,228,467 次,日均约 46,774,282 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

isexe 还在维护吗?

最新版本 4.0.0 发布于 2026/02/10(8 个月前);至今共发布 14 个版本,其中过去 12 个月发布了 5 个;首次发布于 2016/01/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。