@computesdk/cmd

中文文档
0.4.1发布于 2026/01/07MITTypeScriptESM + CJS零依赖近 30 天下载 3.6万

计算SDK 沙盒的安全外壳命令构建器

中文使用文档
文档目录23 节
  1. 安装
  2. 使用量
  3. 基本命令
  4. 使用运行命令选项
  5. 壳包 (高级)
  6. 可用命令
  7. 文件系统
  8. 文件系统测试
  9. 进程/执行
  10. 软件包管理器( JavaScript)
  11. 软件包管理器( Python)
  12. 软件包运行器
  13. 图形
  14. 网络
  15. 港口
  16. 档案
  17. 文本处理
  18. 系统
  19. 编码/检查和
  20. 公用事业
  21. 公用事业
  22. esc(string)
  23. 许可证

@comcomputesdk/cmd (英语)

类型安全 shell 命令构建器,用于计算SDK沙盒.

安装

npm install @computesdk/cmd

使用量

基本命令

import { cmd, npm, node, git } from '@computesdk/cmd';

// Build command tuples
npm.install('express')        // ['npm', 'install', 'express']
node('server.js')             // ['node', 'server.js']
git.clone('https://...')      // ['git', 'clone', 'https://...']

// Use with sandbox.runCommand()
await sandbox.runCommand(npm.install('express'));
await sandbox.runCommand(node('server.js'));

使用运行命令选项

现代计算SDK沙盒手柄 cwd, (中文(简体) ), env,以及 background 直接选项 :

import { npm, node } from '@computesdk/cmd';

// Let the sandbox handle execution options
await sandbox.runCommand('npm install', { cwd: '/app' })
await sandbox.runCommand('node server.js', { background: true })
await sandbox.runCommand('npm run dev', { 
  cwd: '/app', 
  background: true,
  env: { NODE_ENV: 'production' }
})

壳包 (高级)

对于需要明确外壳包装的情况,请使用 shell(), (中文(简体) ), sh(), (中文(简体) ), bash(),或 zsh()数字 :

import { shell, bash, zsh, npm } from '@computesdk/cmd';

// Default shell wrapper (sh)
shell(npm.install(), { cwd: '/app' })
// => ['sh', '-c', 'cd "/app" && npm install']

// Bash-specific
bash(npm.install(), { cwd: '/app' })
// => ['bash', '-c', 'cd "/app" && npm install']

// Zsh with background
zsh(npm.run('dev'), { background: true })
// => ['zsh', '-c', 'nohup npm run dev > /dev/null 2>&1 &']

说明: 很少需要壳包 - 喜欢使用 runCommand() 选项.

可用命令

文件系统

  • mkdir(path, options?) - 创建目录(默认重复)
  • rm(path, options?) - 删除文件/目录
  • cp(src, dest, options?) - 收到了吗
  • mv(src, dest) - 移动/重命名
  • ls(path?, options?) - 列表目录
  • pwd() - 打印工作目录
  • chmod(mode, path, options?) - 更改权限
  • chown(owner, path, options?) - 改变所有者
  • touch(path) - 创建文件/更新时间戳
  • cat(path) - 读取文件
  • ln(target, link, options?) - 创建链接
  • readlink(path, options?) - 解开连锁
  • rsync(src, dest, options?) - 同步文件/目录

文件系统测试

  • test.exists(path) - 文件/目录存在
  • test.isFile(path) - 是一个文件
  • test.isDir(path) - 是个目录
  • test.isReadable(path) - 是可读
  • test.isWritable(path) - 是可写
  • test.isExecutable(path) - 是可执行的
  • test.notEmpty(path) - 文件不是空的
  • test.isSymlink(path) - 是连锁

进程/执行

  • node(script, args?) - 运行节点.js脚本
  • python(script, args?) - 运行 Python 脚本
  • kill(pid, signal?) - 由 PID 制作的杀戮程序
  • pkill(name, options?) - 杀人的名字
  • ps(options?) - 清单进程
  • timeout(seconds, command, args?) - 与超时运行

软件包管理器( JavaScript)

  • npm.install(pkg?, options?), (中文(简体) ), npm.run(script), (中文(简体) ), npm.init(), (中文(简体) ), npm.uninstall(pkg)
  • pnpm.install(pkg?, options?), (中文(简体) ), pnpm.run(script)
  • yarn.install(), (中文(简体) ), yarn.add(pkg, options?), (中文(简体) ), yarn.run(script)
  • bun.install(pkg?, options?), (中文(简体) ), bun.run(script), (中文(简体) ), bun.exec(file)
  • deno.run(file, options?), (中文(简体) ), deno.install(url, options?)

软件包管理器( Python)

  • pip.install(pkg), (中文(简体) ), pip.uninstall(pkg)
  • uv.install(pkg), (中文(简体) ), uv.run(script), (中文(简体) ), uv.sync(), (中文(简体) ), uv.venv(path?)
  • poetry.install(options?), (中文(简体) ), poetry.add(pkg, options?), (中文(简体) ), poetry.run(cmd), (中文(简体) ), poetry.build()
  • pipx.install(pkg), (中文(简体) ), pipx.run(pkg, args?), (中文(简体) ), pipx.uninstall(pkg), (中文(简体) ), pipx.upgrade(pkg)

软件包运行器

  • npx(pkg, args?) - 运行与npx
  • npx.concurrently(commands, options?) - 并行运行命令
  • bunx(pkg, args?) - 和Bunx一起跑吗
  • bunx.concurrently(commands, options?)

图形

  • git.init() - 初始化仓库
  • git.clone(url, options?) - 克隆存储器
  • git.add(path, options?) - 阶段文件
  • git.commit(message, options?) - 提交更改
  • git.push(options?) - 推到遥控器
  • git.pull() - 拉变化
  • git.fetch(options?) - 从远程获取
  • git.checkout(branch, options?) - 离职分支
  • git.branch(name?, options?) - 列表/创建分支
  • git.status() - 显示状态
  • git.diff(options?) - 显示更改
  • git.log(options?) - 显示承诺的历史
  • git.stash(options?) - 结构变化
  • git.reset(options?) - 重置更改

网络

  • curl(url, options?) - 用卷曲下载
  • wget(url, options?) - 用 wget 下载
  • net.ping(host, count?) - 主持人
  • net.check(host, port) - 检查连接
  • net.publicIp() - 获取公开IP
  • net.interfaces() - 显示网络接口

港口

  • port.find(port) - 利用端口查找进程
  • port.kill(port) - 在端口上杀死进程
  • port.isUsed(port) - 检查端口是否在使用中
  • port.list() - 列出监听端口
  • port.waitFor(port, timeout?) - 等待开口

档案

  • tar.extract(file, options?) - 提取焦油归档
  • tar.create(output, source) - 创建沥青档案
  • unzip(file, options?) - 提取 zip 归档

文本处理

  • grep(pattern, file?, options?) - 寻找模式
  • sed(expression, file, options?) - 流编辑器
  • awk(program, file?, options?) - 图案扫描
  • head(file, lines?) - 文件的第一行
  • tail(file, lines?, options?) - 文件的最后行
  • wc(file, options?) - 单词/行数
  • sort(file, options?) - 排序行
  • uniq(file, options?) - 过滤复制
  • jq(filter, file?, options?) - JSON进程
  • cut(file, options) - 提取列
  • tr(set1, set2?, options?) - 翻译字符
  • xargs(command, args?, options?) - 从 stdin 构建命令

系统

  • df(path?, options?) - 磁盘空间
  • du(path, options?) - 目录大小
  • whoami() - 当前用户
  • uname(options?) - 系统信息
  • hostname() - 主机名称
  • env() - 环境变量
  • printenv(name?) - 打印掩体变量
  • which(command) - 寻找命令位置

编码/检查和

  • base64.encode(file?) - 编码到基地64
  • base64.decode(file?) - 从64基地解码
  • md5sum(file, options?) - MD5核对和
  • sha256sum(file, options?) - SHA256支票和
  • sha1sum(file, options?) - SHA1支票和

公用事业

  • sleep(seconds) - 延迟执行
  • date(format?) - 打印日期/时间
  • find(path, options?) - 查找文件
  • tee(file, options?) - 写到文件 和 stdout
  • diff(file1, file2, options?) - 比较文件
  • echo(text) - 打印文本
  • parallel(commands, options?) - 并行运行命令
  • raw(command, args?) - 自定义命令

公用事业

esc(string)

为 shell 安全起见, 跳出字符串中的双引号 :

import { esc } from '@computesdk/cmd';

esc('path with "quotes"')  // 'path with \\"quotes\\"'

许可证

麻省理工学院

版本与发布记录

@computesdk/cmd 共发布 6 个版本,首次发布于 2025/12/18;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.4.1latest2026/01/0710 个月前
0.4.02026/01/0210 个月前
0.3.12025/12/2310 个月前
0.3.02025/12/2010 个月前
0.2.02025/12/1910 个月前
0.1.02025/12/1810 个月前

关于 @computesdk/cmd 的常见问题

@computesdk/cmd 是什么?

计算SDK 沙盒的安全外壳命令构建器

如何安装 @computesdk/cmd?

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

@computesdk/cmd 支持 TypeScript 吗?

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

@computesdk/cmd 支持 ESM 还是 CommonJS?

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

@computesdk/cmd 可以商用吗?

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

@computesdk/cmd 的下载量有多少?

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

@computesdk/cmd 还在维护吗?

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