Deno v1.0:JavaScript和TypeScript的安全运行时。功能概述


  1. 介绍
  2. 安装
  3. 里面看起来像什么
  4. 功能性
  5. WASM,RUST,插件
  6. 调试,IDE
  7. 测试中
  8. 编译器API

介绍


, Ryan Dahl, NodeJS, JSConf, , NodeJS. : Deno, .


, .


2 , , .


, Deno. , , . Deno, . , Deno .



, , , , .


deno.land, .


Using Shell:


curl -fsSL https://deno.land/x/install/install.sh | sh

Or using PowerShell:


iwr https://deno.land/x/install/install.ps1 -useb | iex

, scoop, homebrew. , . . URL https://github.com/denoland/deno_install .


, , deno upgrade


Windows. , , Deno.


Windows,


, Deno, github, , .


, deno , {username}\AppData\Local\deno
:


  • deps,

, , , response headers, , , url. , , , Deno. , , -r deno run. , lock , “ Deno”


  • gen

js, typescript . , , .
. , gen/file/C/dev/my_first_project


  • deno_history.txt

deno .


  • lib.deno.d.ts, lib.deno_runtime.d.ts

deno core. , Deno.



Typescript. , API , . API https://deno.land/typedoc. std x : https://doc.deno.land/. std, x “ Deno”.


Typescript/ Javascript , ( V8, “”). Rust, “”. API- Deno ( ) Typescript , Rust Rusty V8 ( ) . Deno.core.send(), Deno.core.recv() .


Rusty V8 — Typescript Rust, V8 . V8 / V8. V8 V8 https://v8.dev/blog/custom-startup-snapshots. , Deno Typescript. .


Rust Backend. , « », , , Rust. , , Rust — , Mozilla, . , Servo. Rust Go, Deno, 2018 . GC.


V8 — JavaScript / WebAssembly Google. C++, Google Chrome Node.js. V8 TypeScript. TypeScript, Deno, JavaScript TS, .deno. , JS.


Tokio — Rust. . Deno . Tokio Rust Future, , Promise JavaScript.


TS Rust. , Flutbuffers, . , , . , . Deno : https://www.youtube.com/watch?v=qt7fbmypAFk



, , CLI Deno. deno help, deno [subcommand] -- help :


>deno help
deno 1.0.0-rc2
A secure JavaScript and TypeScript runtime

Docs: [https://deno.land/std/manual.md](https://deno.land/std/manual.md)
Modules: [https://deno.land/std/](https://deno.land/std/) [https://deno.land/x/](https://deno.land/x/)
Bugs: [https://github.com/denoland/deno/issues](https://github.com/denoland/deno/issues)

To start the REPL:
  deno

To execute a script:
  deno run [https://deno.land/std/examples/welcome.ts](https://deno.land/std/examples/welcome.ts)

To evaluate code in the shell:
  deno eval "console.log(30933 + 404)"

USAGE:
    deno [OPTIONS] [SUBCOMMAND]

OPTIONS:
    -h, --help                     Prints help information
    -L, --log-level <log-level>    Set log level [possible values: debug, info]
    -q, --quiet                    Suppress diagnostic output
    -V, --version                  Prints version information

SUBCOMMANDS:
    bundle         Bundle module and dependencies into single file
    cache          Cache the dependencies
    completions    Generate shell completions
    doc            Show documentation for a module
    eval           Eval script
    fmt            Format source files
    help           Prints this message or the help of the given subcommand(s)
    info           Show info about cache or info related to source file
    install        Install script as an executable
    repl           Read Eval Print Loop
    run            Run a program given a filename or url to the module
    test           Run tests
    types          Print runtime TypeScript declarations
    upgrade        Upgrade deno executable to given version

ENVIRONMENT VARIABLES:
    DENO_DIR             Set deno's base directory (defaults to $HOME/.deno)
    DENO_INSTALL_ROOT    Set deno install's output directory
                         (defaults to $HOME/.deno/bin)
    NO_COLOR             Set to disable color
    HTTP_PROXY           Proxy address for HTTP requests
                         (module downloads, fetch)
    HTTPS_PROXY          Same but for HTTPS

-unstable, Deno core API.



Deno . , Node.js .



deno run main.ts 

, :


error: Uncaught PermissionDenied: ...

Deno , . :


  • environment

, . , , -allow-read, url -allow-net


deno run --allow-read=/path --allow-net=localhost:4545 file.ts

, bash script -A ( -- allow-all), . Drake — make Deno.


, deno , deno install . , $PATH.


Strict: true


- , . , , .


tsconfig.json


Deno , , , , . typescript, . :


deno run -c tsconfig.json main.ts


Deno Node.js , Deno ECMAScript, CommonJS. Node.js es 2019 , 13.2.0, , - .mjs. Deno , - .


import * as framework from "https://deno.land/x/alosaur/src/mod.ts";
import { assert } from "https://deno.land/std/testing/mod.ts";

, typescript , . . Ryan Dahl, require, N1 Node.js.


3 : Core, Std, X.


Deno.core


, c Rust .


Deno Standard Modules


https://deno.land/std/ — , Deno, Deno. , . Go. , , , .


Deno X


. Deno, .


https://deno.land/x — . , pull request.


JSPM, Pika.dev — , npm es . :


import HandlebarsJS from ‘https://dev.jspm.io/handlebars@4.7.6';


, Deno. , , . . , npm, Deno .


package.json, deps.ts, :


export { assert } from "https://deno.land/std@v0.42.0/testing/asserts.ts";

-importmap (-unstable), json :


{
  "imports": {
    "moment": "./moment/moment.ts",
    "moment/": "./moment/",
    "lodash": "./lodash/lodash.ts",
    "lodash/": "./lodash/",
    "https://www.unpkg.com/vue/dist/vue.runtime.esm.js": "./vue.ts"
  },
  "scopes": {
    "scope/": {
      "moment": "./scoped_moment.ts"
    }
  }
}

std , , , : file:, http:, https:


Lock file


Deno , JSON. -- lock = lock.json, . , -- lock = lock.json -- lock-write.


Web standards


, Deno, , , Deno c , Deno. :


> reverse=a=>a.sort(n=>1)
> reverse([1,2,3])

- node (10.13.0): [3,2,1]
- deno (0.4.0) [1,2,3]
- chrome (74.0) [1,2,3]
- other browsers: [1,2,3]

, , , fetch.


, , Nodejs, Deno, . , , Deno.


Compat Table deno: https://deno.dev/wpt/


WASM, RUST,


, Deno wasm . , .


. Deno , , import, , , Deno.openPlugin. , , .deno_plugins . , :


https://github.com/manyuanrong/deno-plugin-prepare


:


const pluginOptions: PerpareOptions = {
  name: "test_plugin",

  // Whether to output log. Optional, default is true
  // printLog: true,

  // Whether to use locally cached files. Optional, default is true
  // checkCache: true,

  // Support "http://", "https://", "file://"
  urls: {
    mac: `${releaseUrl}/libtest_plugin.dylib`,
    win: `${releaseUrl}/test_plugin.dll`,
    linux: `${releaseUrl}/libtest_plugin.so`,
  },
};
const rid = await prepare(pluginOptions);
//@ts-ignore
const { testSync } = Deno.core.ops();

const response = Deno.core.dispatch(
  testSync,
  new Uint8Array([116, 101, 115, 116])
)!;

console.log(response);

, Deno webView. :


https://denotutorials.net/making-desktop-gui-applications-using-deno-webview.html


Debugging, IDE


Deno , Visual Studio Code . :


deno run -A -- inspect-brk fileToDebug.ts

Chrome chrome://inspect, Target Deno, Inspect. .


Deno Rust API Deno.watchFs (). Deno API , . -- watch, .


Visual Studio Code c justjavac.vscode-deno


WebStorm, star jetbrains https://youtrack.jetbrains.com/issue/WEB-41607



​​Deno Deno.test(). , assert, assertEquals .. . , :


import { assert, assertEquals } from "https://deno.land/std/testing/asserts.ts";

Deno.test({
  name: "Test name",
  fn(): void {
    assert("test" === "test");
    assertEquals("test", "test");
  },
});

:


deno test

.



Deno (https://github.com/alosaur/alosaur), , . , Deno . — Deno.run(). : . : https://github.com/alosaur/alosaur/tree/master/e2e


Compiler API


Deno Typescript. Deno , : Deno.compile() Deno.bundle() Deno.transpileOnly()


compile() — tsc Nodejs,


bundle() — compile, , , es , . CLI deno bundle.


, :


export { foo } from "./foo.js";

export const bar = "bar";

:


import { foo, bar } from "./lib.bundle.js";

Bundle -. Bundle ES, type «module». :


<script type="module">
  import * as website from "website.bundle.js";
</script>

transpileOnly() — , transpileModule Typescript. , , «» JavaScript. .


dev_server


transpileOnly dev_server (https://github.com/zhmushan/dev_server) — deno.


?
index.html, main.ts,


( tsconfig), js url.


?
jspm, cdn.pika, unpkg. , importmap.


, JIT, systemjs.
: dev .


, , , , Angular CLI


:


deno run -- allow-net -- allow-read -- allow-write -- unstable
https://deno.land/x/dev_server/mod.ts — template angular


, Angular, Angular , telegram https://t.me/ngFanatic.


CI, CD


, , . Deno github actions. , Ryan Dahl travis, ( ), . github actions , , . : https://github.com/alosaur/alosaur/blob/master/.github/workflows/ci.yml



Deno install


Deno deno install . , deno, CLI.


$ deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts
[1/1] Compiling https://deno.land/std/http/file_server.ts

 Successfully installed file_server.
/Users/deno/.deno/bin/file_server

, file_server.


: https://github.com/denoland/deno/blob/master/docs/tools/script_installer.md


Deno.run()


, , deno , , python:


// --allow-run
const cmd = Deno.run({
  cmd: ["python3", "test.py"], 
  stdout: "piped",
  stderr: "piped"
});

const output = await cmd.output();
const outStr = new TextDecoder().decode(output);

const error = await p.stderrOutput();
const errorStr = new TextDecoder().decode(error);

cmd.close();

console.log(outStr, errorStr);

Deno doc


doc.deno.land. typescript type checker (https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#using-the-type-checker) , JSdoc.


Deno format


Deno , JavaScript Typescript. Prettier.


Deno playground


deno , : https://deno.town https://deno-play.app


Deno awesome


Deno, , !


https://github.com/denolib/awesome-deno



希望通过我的文章,现在能够吸引您尝试Deno。如果您有任何疑问,那么我邀请所有人通过电报进行舒适的交谈:


https://t.me/denoland


如果您需要最新的信息(有关Deno的摘要),那么将为此创建Deno Fanatic频道。


https://t.me/denoFanatic


ps


我已经在装饰器上开发了我的Web框架超过一年,我将很高兴收到任何反馈:


https://github.com/alosaur/alosaur


All Articles