直感に反して、Deno v1.19まではこのコードは動いてしまいます。
このコードを意図した通りに動かすためには、以下のようにpermissions
を指定する必要がありました。
permissions: { read: true, write: false }
この挙動は直感的ではないということで、v1.20で変更されました。
permissions
オプションで指定されなかった権限は、今後はデフォルトで無効化されます。
deno task
コマンドdeno.json
の"tasks"
でタスクを定義
{
"tasks": {
"start": "deno run --allow-net mod.ts"
}
}
定義したタスクを実行
$ deno task start
deno bench
コマンドfunction sum(...numbers: Array<number>): number {
return numbers.reduce((a, b) => a + b, 0);
}
Deno.bench("sum", () => {
sum(1, 2, 3, 4, 5);
});
$ deno bench --unstable
running 1 bench from file:///home/uki00a/ghq/github.com/uki00a/deno-sample/bench.ts
bench sum ... 1000 iterations 842 ns/iter (682..59,111 ns/iter) ok
(7ms)
bench result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (17ms)
import { serve } from "https://deno.land/std@0.130.0/http/mod.ts";
serve(async () => {
const json = await Deno.readTextFile("./data.json");
return new Response(json);
});
$ curl -I -H "Accept-Encoding: br" http://localhost:8000
HTTP/1.1 200 OK
content-type: text/plain;charset=UTF-8
vary: Accept-Encoding
content-encoding: br
content-length: 53
date: Sat, 19 Mar 2022 05:58:59 GMT
deno test --trace-ops
--trace-ops
を指定すると、リソースリーク検出時のエラー内容が改善されます。
$ deno test --trace-ops test.ts
...
trace_ops
Test case is leaking async ops.
- 1 async operation to sleep for a duration was started in this test, but never completed. This is often caused by not cancelling a `setTimeout` or `setInterval` call. The operation was started here:
at Object.opAsync (deno:core/01_core.js:161:42)
at runAfterTimeout (deno:ext/web/02_timers.js:234:31)
at initializeTimer (deno:ext/web/02_timers.js:200:5)
at setTimeout (deno:ext/web/02_timers.js:337:12)
at file:///home/uki00a/ghq/github.com/uki00a/deno-sample/test.ts:2:3
at testStepSanitizer (deno:runtime/js/40_testing.js:441:13)
at asyncOpSanitizer (deno:runtime/js/40_testing.js:145:15)
at resourceSanitizer (deno:runtime/js/40_testing.js:367:13)
at Object.exitSanitizer [as fn] (deno:runtime/js/40_testing.js
:424:15)
at runTest (deno:runtime/js/40_testing.js:784:18)
Deno.connect
のAPIが変更今まではDeno.Conn
というオブジェクトを返していましたが、v1.20からは下記のオブジェクトを返します:
transport: "tcp"
を指定するとDeno.TcpConn
transport: "unix"
を指定するとDeno.UnixConn
これに合わせて、Deno.Conn
に定義されていたsetNoDelay()
やsetKeepAlive()
メソッドがDeno.TcpConn
へ移動しています。
Deno.listenTls
でcert
とkey
オプションがサポートconst cert = await Deno.readTextFile("example.crt");
const key = await Deno.readTextFile("example.key");
// certとkeyオプションで証明書と秘密鍵を文字列で渡せます
const listener = Deno.listenTls({
hostname,
port,
cert,
key,
});
元々存在していたcertFile
とkeyFile
は非推奨化されています。
opの呼び出しが最大で60%程度まで高速化
その他にも、atob
/btoa
の大幅なパフォーマンス改善が実施されています (最大20倍程)
deno.json(c)
でimportMap
オプションがサポートDeno.upgradeHttp()
が追加AbortSignal.timeout()
が実装deno_stdの多くのモジュールはGoスタイルのAPIで実装されていました。 (Deno.Reader
/Deno.Writer
)
これらのモジュールのWeb Streams APIへの移行が徐々に行われています。
進捗については下記issueを参照ください。
dotenv
モジュールが追加import { config } from "https://deno.land/std@0.130.0/dotenv/mod.ts";
const env = await config({ path: ".envrc" });
console.log(env);
deno_std/node
の改善node-mysql2パッケージがある程度動くようになったようです。
deno_stdのリポジトリにexampleがあるので、詳しくはそちらを参照ください。
deno.landのバックエンドがNode.jsからDenoへ移行されました。
それに合わせて、使用されているフレームワークなども変更されています。
FreshでIsland architectureが実装されました。
それに合わせて、ディレクトリ構造の見直しやuseData()
や<Suspence>
などの削除も行われています。(<Suspence>
などは将来的に再び追加される予定のようです)
まだ実験的ですが、Remix v1.2.0からDenoのサポートが追加されています。
$ yarn create remix --template deno-ts
Oakのv10.3.0と10.4.0でNode.jsへの実験的サポートが追加されました。
npmレジストリには@oakserver/oakという名前で公開されています。
公式でも解説記事が公開されているので、興味のある方は参照するとよさそうです。