deno
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeno
Deno
Use Deno as the default runtime/tooling when the repo contains /, uses , or scripts/documentation reference , , , etc.
deno.jsondeno.jsoncdeno.lockdeno taskdeno rundeno test当代码仓库包含/、使用,或者脚本/文档提及、、等内容时,将Deno作为默认运行时/工具使用。
deno.jsondeno.jsoncdeno.lockdeno taskdeno rundeno testQuick decision rules
快速决策规则
- Prefer if the repo defines tasks.
deno task <name> - Use /
deno addto manage dependencies (writes to config).deno remove - Be explicit about permissions for /
deno run.deno test
- 如果代码仓库定义了任务,优先使用。
deno task <name> - 使用/
deno add管理依赖(会写入配置文件)。deno remove - 为/
deno run明确指定权限。deno test
Common operations
常用操作
Initialize a new project
初始化新项目
bash
deno initbash
deno initAdd dependencies (JSR and npm)
添加依赖(JSR和npm)
bash
undefinedbash
undefinedJSR (recommended for Deno-first packages)
JSR(推荐优先用于Deno原生包)
deno add jsr:@std/path
deno add jsr:@std/path
npm packages are supported too
也支持npm包
deno add npm:react
deno add npm:react
multiple at once
一次性添加多个
deno add jsr:@std/assert npm:chalk
undefineddeno add jsr:@std/assert npm:chalk
undefinedRemove dependencies
移除依赖
bash
deno remove jsr:@std/pathbash
deno remove jsr:@std/pathRun a script
运行脚本
bash
undefinedbash
undefinedMinimal permissions: only what the program needs
最小权限原则:仅授予程序所需的权限
Examples:
示例:
--allow-net=api.example.com
--allow-net=api.example.com
--allow-read=./data
--allow-read=./data
--allow-env=FOO,BAR
--allow-env=FOO,BAR
deno run --allow-net --allow-read main.ts
undefineddeno run --allow-net --allow-read main.ts
undefinedRun tasks
运行任务
bash
undefinedbash
undefinedlist tasks
列出所有任务
deno task
deno task
run a task defined in deno.json/deno.jsonc
运行在deno.json/deno.jsonc中定义的任务
deno task dev
undefineddeno task dev
undefinedFormatting, linting, testing
格式化、代码检查、测试
bash
deno fmt
deno lint
deno testbash
deno fmt
deno lint
deno testcommon permissioned test run
常用带权限的测试运行命令
deno test --allow-net --allow-read
undefineddeno test --allow-net --allow-read
undefinedInstall / run CLIs
安装/运行CLI
bash
undefinedbash
undefinedRun a JSR or npm package's CLI without installing globally
无需全局安装即可运行JSR或npm包的CLI
deno x jsr:@std/http/file-server -p 8080
deno x jsr:@std/http/file-server -p 8080
Install globally (requires choosing permissions at install time)
全局安装(安装时需要选择权限)
Prefer the smallest set of permissions; avoid blanket flags unless necessary.
推荐使用最小权限集;除非必要,避免使用笼统的权限标志
deno install -g -N -R jsr:@std/http/file-server -- -p 8080
undefineddeno install -g -N -R jsr:@std/http/file-server -- -p 8080
undefinedNotes / pitfalls
注意事项/常见陷阱
- Deno is secure-by-default: missing permissions cause runtime errors; add the smallest set of flags needed.
--allow-* - Dependency specifiers:
- for JSR registry packages
jsr: - for npm packages
npm: - URL imports are also supported (and cached)
- Lockfile: helps ensure reproducible dependency resolution.
deno.lock
- Deno默认安全:缺少权限会导致运行时错误,请添加所需的最小标志集。
--allow-* - 依赖说明符:
- 对应JSR registry的包
jsr: - 对应npm包
npm: - 也支持URL导入(且会被缓存)
- 锁文件:用于确保依赖解析的可复现性。
deno.lock