公式の Getting Started にならって試していきます。
https://deno.land/manual/getting_started
$ curl -fsSL https://deno.land/x/install/install.sh | sh
Archive: /home/xxxxx/.deno/bin/deno.zip
inflating: deno
Deno was installed successfully to /home/xxxxx/.deno/bin/deno
Manually add the directory to your $HOME/.bash_profile (or similar)
export DENO_INSTALL="/home/xxxxx/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
Run '/home/xxxxx/.deno/bin/deno --help' to get started
(xxxxx は ユーザー名)
export DENO_INSTALL="/home/xxxxx/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
$ deno --version
deno 1.0.2
v8 8.4.300
typescript 3.9.2
(公式だと)
公式で VSCode 用が提供されていた。
https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno
JetBrains IDEs や Vim and NeoVim 用も一応あるっぽい。
(入れてはみたけど、どのようなサポートされているのかはいまいちわかっていない)
以下のように型定義を出力
$ deno types > ./deno.d.ts
以下のような tsconfig.json
を作成し、読み込むようにすれば deno の標準ライブラリは型サポートされるようになった。
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"deno": ["./deno.d.ts"]
}
}
}
TODO: http://deno.land/x/xxxxx とかで読み込んだライブラリの型サポートの仕方調べる
hello_deno.ts を作る
console.log("Welcome to Deno 🦕");
$ deno run hello_deno.ts
Compile file:///home/xxxxx/work/deno/first.ts
Welcome to Deno 🦕
ちゃんと走る様子。
hello_fetch.ts を作る
const url = Deno.args[0];
const res = await fetch(url);
const body = new Uint8Array(await res.arrayBuffer());
await Deno.stdout.write(body);
fetch を動かすためには --alow-net
フラグが必要
$ deno run --allow-net=example.com hello_fetch.ts https://example.com
<!doctype html>
<html>・・・・・</html>
つけないと以下のように permission エラーになる
$ deno run hello_fetch.ts https://example.com
error: Uncaught PermissionDenied: network access to "https://example.com/", run again with the --allow-net flag
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendAsync ($deno$/ops/dispatch_json.ts:98:10)
at async fetch ($deno$/web/fetch.ts:591:27)
at async file:///home/xxxxx/work/deno/hello_fetch.ts:2:13
hello_file.ts を作る
const filenames = Deno.args;
for (const filename of filenames) {
const file = await Deno.open(filename);
await Deno.copy(file, Deno.stdout);
file.close();
}
$ deno run --allow-read hello_file.ts ./deno.md
...略...
- まだよくわからない
- Permission の引数はセキュアかもしれないけど、ものすごくめんどい。