Wener Notes

deno

约 2 分钟阅读
  • denoland/denoGitHubdenoland/denodenoland/deno · MIT, Rust · 基于 V8 · 内置 包管理、tsc、fmt、test、bundle、lint、lsp 等功能 · 通过 url 引用外部模块 - 运行时下载 · 严格的权限管理 - 沙盒功能强 · 功能理念类似于 golang笔记:deno
    • MIT, Rust
    • 基于 V8
    • 内置 包管理、tsc、fmt、test、bundle、lint、lsp 等功能
    • 通过 url 引用外部模块 - 运行时下载
    • 严格的权限管理 - 沙盒功能强
    • 功能理念类似于 golang
      • stdlib 参照 go 实现
  • Deno 全局命名空间
  • ~/.deno/bin - deno install 位置
  • deno 非常难管理依赖版本 - 因为版本号 pin 在 import 路径上
    • 不方便修改和引用
    • 很可能引入多个版本
    • 不 pin 版本会使用 latest,导致依赖升级后脚本异常 - 默认没有 lock
    • import map 不方便依赖模块引入
  • deno 不支持 AlpineLinux, CentOS 7
  • deno 不支持 gRPC
TypeScript
// HTTP 服务器
const listener = Deno.listen({ port: 8000 });
console.log('http://localhost:8000/');

for await (const conn of listener) {
  serve(conn);
}

async function serve(conn: Deno.Conn) {
  for await (const { respondWith } of Deno.serveHttp(conn)) {
    respondWith(new Response('Hello world'));
  }
}
bash
# bundle 为单个文件 - 输出为 js
deno bundle scripts/main.ts cli.js
deno run cli.js

# compile 为可执行文件 - 打包 deno - 约 70MB
# -A 给所有权限
# --target 生成其他平台 - 第一次执行会下载 deno 到 DENO_DIR
# x86_64-unknown-linux-gnu, x86_64-pc-windows-msvc, x86_64-apple-darwin, aarch64-apple-darwin
deno compile -o cli --allow-write --allow-read scripts/main.ts
./cli

deno.json

bash
# 生成 lock.json
deno cache --lock=lock.json --lock-write --unstable main.ts

Node vs Deno

NodeDeno
npm i -gdeno install
npm inot needed
nodedeno run
eslintdeno lint
prettierdeno fmt
rollup/webpack/...deno bundle
package.jsonDeno.json, import_map.json
tscnot needed - built-in
documentationdeno doc
jest/ava/tap/...deno test
benchmarksdeno.land/std/testing/bench.ts
nodemondeno run/lint/test --watch
nexe/pkgdeno compile
npm explaindeno info
nvmdeno upgrade
tsserverdeno lsp
c8/istanbuldeno coverage

deno deploy

关联信息

反向链接、本文链接的其他页面和外部资料。

References

GitHub4 条
其他外链7 条
最近更新commit a455e0eEdit

On this page