diff options
author | Bartek Iwańczuk <biwanczuk@gmail.com> | 2021-07-20 16:25:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-20 16:25:36 +0200 |
commit | d744c0c6d9a557bbaa2a23571ffb3acabf19c35a (patch) | |
tree | 6f7fb8a71b786e79c48f4b2c11a5a9ca988717e8 /docs/getting_started | |
parent | 9b9becf1ae256b645e37a7eecf3441f3ae4b8ea5 (diff) |
chore: move docs to separate repository
Diffstat (limited to 'docs/getting_started')
-rw-r--r-- | docs/getting_started/command_line_interface.md | 145 | ||||
-rw-r--r-- | docs/getting_started/debugging_your_code.md | 145 | ||||
-rw-r--r-- | docs/getting_started/first_steps.md | 146 | ||||
-rw-r--r-- | docs/getting_started/installation.md | 92 | ||||
-rw-r--r-- | docs/getting_started/permissions.md | 96 | ||||
-rw-r--r-- | docs/getting_started/setup_your_environment.md | 329 | ||||
-rw-r--r-- | docs/getting_started/typescript.md | 4 | ||||
-rw-r--r-- | docs/getting_started/webassembly.md | 43 |
8 files changed, 0 insertions, 1000 deletions
diff --git a/docs/getting_started/command_line_interface.md b/docs/getting_started/command_line_interface.md deleted file mode 100644 index 191c1e756..000000000 --- a/docs/getting_started/command_line_interface.md +++ /dev/null @@ -1,145 +0,0 @@ -## Command line interface - -Deno is a command line program. You should be familiar with some simple commands -having followed the examples thus far and already understand the basics of shell -usage. - -There are multiple ways of viewing the main help text: - -```shell -# Using the subcommand. -deno help - -# Using the short flag -- outputs the same as above. -deno -h - -# Using the long flag -- outputs more detailed help text where available. -deno --help -``` - -Deno's CLI is subcommand-based. The above commands should show you a list of -those supported, such as `deno bundle`. To see subcommand-specific help for -`bundle`, you can similarly run one of: - -```shell -deno help bundle -deno bundle -h -deno bundle --help -``` - -Detailed guides to each subcommand can be found [here](../tools.md). - -### Script source - -Deno can grab the scripts from multiple sources, a filename, a url, and '-' to -read the file from stdin. The last is useful for integration with other -applications. - -```shell -deno run main.ts -deno run https://mydomain.com/main.ts -cat main.ts | deno run - -``` - -### Script arguments - -Separately from the Deno runtime flags, you can pass user-space arguments to the -script you are running by specifying them after the script name: - -```shell -deno run main.ts a b -c --quiet -``` - -```ts -// main.ts -console.log(Deno.args); // [ "a", "b", "-c", "--quiet" ] -``` - -**Note that anything passed after the script name will be passed as a script -argument and not consumed as a Deno runtime flag.** This leads to the following -pitfall: - -```shell -# Good. We grant net permission to net_client.ts. -deno run --allow-net net_client.ts - -# Bad! --allow-net was passed to Deno.args, throws a net permission error. -deno run net_client.ts --allow-net -``` - -Some see it as unconventional that: - -> a non-positional flag is parsed differently depending on its position. - -However: - -1. This is the most logical and ergonomic way of distinguishing between runtime - flags and script arguments. -2. This is, in fact, the same behaviour as that of any other popular runtime. - - Try `node -c index.js` and `node index.js -c`. The first will only do a - syntax check on `index.js` as per Node's `-c` flag. The second will - _execute_ `index.js` with `-c` passed to `require("process").argv`. - ---- - -There exist logical groups of flags that are shared between related subcommands. -We discuss these below. - -### Watch mode - -You can supply the `--watch` flag to `deno run` to enable the built in file -watcher. When Deno starts up with this flag it watches the entrypoint, and all -local files the entrypoint statically imports. Whenever one of these files is -changed on disk, the program will automatically be restarted. - -``` -deno run --watch main.ts -``` - -### Integrity flags - -Affect commands which can download resources to the cache: `deno cache`, -`deno run` and `deno test`. - -``` ---lock <FILE> Check the specified lock file ---lock-write Write lock file. Use with --lock. -``` - -Find out more about these -[here](../linking_to_external_code/integrity_checking.md). - -### Cache and compilation flags - -Affect commands which can populate the cache: `deno cache`, `deno run` and -`deno test`. As well as the flags above this includes those which affect module -resolution, compilation configuration etc. - -``` ---config <FILE> Load tsconfig.json configuration file ---import-map <FILE> UNSTABLE: Load import map file ---no-remote Do not resolve remote modules ---reload=<CACHE_BLOCKLIST> Reload source code cache (recompile TypeScript) ---unstable Enable unstable APIs -``` - -### Runtime flags - -Affect commands which execute user code: `deno run` and `deno test`. These -include all of the above as well as the following. - -#### Permission flags - -These are listed [here](./permissions.md#permissions-list). - -#### Other runtime flags - -More flags which affect the execution environment. - -``` ---cached-only Require that remote dependencies are already cached ---inspect=<HOST:PORT> activate inspector on host:port ... ---inspect-brk=<HOST:PORT> activate inspector on host:port and break at ... ---seed <NUMBER> Seed Math.random() ---v8-flags=<v8-flags> Set V8 command line options. For help: ... -``` diff --git a/docs/getting_started/debugging_your_code.md b/docs/getting_started/debugging_your_code.md deleted file mode 100644 index 04bd711cd..000000000 --- a/docs/getting_started/debugging_your_code.md +++ /dev/null @@ -1,145 +0,0 @@ -## Debugging your code - -Deno supports the [V8 Inspector Protocol](https://v8.dev/docs/inspector). - -It's possible to debug Deno programs using Chrome Devtools or other clients that -support the protocol (eg. VSCode). - -To activate debugging capabilities run Deno with the `--inspect` or -`--inspect-brk` flags. - -The `--inspect` flag allows attaching the debugger at any point in time, while -`--inspect-brk` will wait for the debugger to attach and will pause execution on -the first line of code. - -### Chrome Devtools - -Let's try debugging a program using Chrome Devtools. For this, we'll use -[file_server.ts](https://deno.land/std@$STD_VERSION/http/file_server.ts) from -`std`, a static file server. - -Use the `--inspect-brk` flag to break execution on the first line: - -```shell -$ deno run --inspect-brk --allow-read --allow-net https://deno.land/std@$STD_VERSION/http/file_server.ts -Debugger listening on ws://127.0.0.1:9229/ws/1e82c406-85a9-44ab-86b6-7341583480b1 -Download https://deno.land/std@$STD_VERSION/http/file_server.ts -Compile https://deno.land/std@$STD_VERSION/http/file_server.ts -... -``` - -Open `chrome://inspect` and click `Inspect` next to target: - - - -It might take a few seconds after opening the Devtools to load all modules. - - - -You might notice that Devtools paused execution on the first line of -`_constants.ts` instead of `file_server.ts`. This is expected behavior and is -caused by the way ES modules are evaluated by V8 (`_constants.ts` is left-most, -bottom-most dependency of `file_server.ts` so it is evaluated first). - -At this point all source code is available in the Devtools, so let's open up -`file_server.ts` and add a breakpoint there; go to "Sources" pane and expand the -tree: - - - -_Looking closely you'll find duplicate entries for each file; one written -regularly and one in italics. The former is compiled source file (so in the case -of `.ts` files it will be emitted JavaScript source), while the latter is a -source map for the file._ - -Next, add a breakpoint in the `listenAndServe` method: - - - -As soon as we've added the breakpoint Devtools automatically opened up the -source map file, which allows us step through the actual source code that -includes types. - -Now that we have our breakpoints set, we can resume the execution of our script -so that we might inspect an incoming request. Hit the Resume script execution -button to do so. You might even need to hit it twice! - -Once our script is running again, let's send a request and inspect it in -Devtools: - -``` -$ curl http://0.0.0.0:4507/ -``` - - - -At this point we can introspect the contents of the request and go step-by-step -to debug the code. - -### VSCode - -Deno can be debugged using VSCode. - -Official support via the plugin is being worked on - -https://github.com/denoland/vscode_deno/issues/12 - -We can still attach the debugger by manually providing a -[`launch.json`](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations) -config: - -```json -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Deno", - "type": "pwa-node", - "request": "launch", - "cwd": "${workspaceFolder}", - "runtimeExecutable": "deno", - "runtimeArgs": ["run", "--inspect-brk", "-A", "${file}"], - "attachSimplePort": 9229 - } - ] -} -``` - -**NOTE**: This uses the file you have open as the entry point; replace `${file}` -with a script name if you want a fixed entry point. - -Let's try out debugging a local source file. Create `server.ts`: - -```ts -import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts"; -const server = serve({ port: 8000 }); -console.log("http://localhost:8000/"); - -for await (const req of server) { - req.respond({ body: "Hello World\n" }); -} -``` - -Then we can set a breakpoint, and run the created configuration: - - - -### JetBrains IDEs - -You can debug Deno using your JetBrains IDE by right-clicking the file you want -to debug and selecting the `Debug 'Deno: <file name>'` option. This will create -a run/debug configuration with no permission flags set. To configure these flags -edit the run/debug configuration and modify the `Arguments` field with the -required flags. - -### Other - -Any client that implements the Devtools protocol should be able to connect to a -Deno process. - -### Limitations - -Devtools support is still immature. There is some functionality that is known to -be missing or buggy: - -- autocomplete in Devtools' console causes the Deno process to exit. -- profiling and memory dumps might not work correctly. diff --git a/docs/getting_started/first_steps.md b/docs/getting_started/first_steps.md deleted file mode 100644 index fda5bc47b..000000000 --- a/docs/getting_started/first_steps.md +++ /dev/null @@ -1,146 +0,0 @@ -## First steps - -This page contains some examples to teach you about the fundamentals of Deno. - -This document assumes that you have some prior knowledge of JavaScript, -especially about `async`/`await`. If you have no prior knowledge of JavaScript, -you might want to follow a guide -[on the basics of JavaScript](https://developer.mozilla.org/en-US/docs/Learn/JavaScript) -before attempting to start with Deno. - -### Hello World - -Deno is a runtime for JavaScript/TypeScript which tries to be web compatible and -use modern features wherever possible. - -Browser compatibility means a `Hello World` program in Deno is the same as the -one you can run in the browser: - -```ts -console.log("Welcome to Deno!"); -``` - -Try the program: - -```shell -deno run https://deno.land/std@$STD_VERSION/examples/welcome.ts -``` - -### Making an HTTP request - -Many programs use HTTP requests to fetch data from a webserver. Let's write a -small program that fetches a file and prints its contents out to the terminal. - -Just like in the browser you can use the web standard -[`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API to -make HTTP calls: - -```ts -const url = Deno.args[0]; -const res = await fetch(url); - -const body = new Uint8Array(await res.arrayBuffer()); -await Deno.stdout.write(body); -``` - -Let's walk through what this application does: - -1. We get the first argument passed to the application, and store it in the - `url` constant. -2. We make a request to the url specified, await the response, and store it in - the `res` constant. -3. We parse the response body as an - [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), - await the response, and convert it into a - [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) - to store in the `body` constant. -4. We write the contents of the `body` constant to `stdout`. - -Try it out: - -```shell -deno run https://deno.land/std@$STD_VERSION/examples/curl.ts https://example.com -``` - -You will see this program returns an error regarding network access, so what did -we do wrong? You might remember from the introduction that Deno is a runtime -which is secure by default. This means you need to explicitly give programs the -permission to do certain 'privileged' actions, such as access the network. - -Try it out again with the correct permission flag: - -```shell -deno run --allow-net=example.com https://deno.land/std@$STD_VERSION/examples/curl.ts https://example.com -``` - -### Reading a file - -Deno also provides APIs which do not come from the web. These are all contained -in the `Deno` global. You can find documentation for these APIs on -[doc.deno.land](https://doc.deno.land/builtin/stable#Deno). - -Filesystem APIs for example do not have a web standard form, so Deno provides -its own API. - -In this program each command-line argument is assumed to be a filename, the file -is opened, and printed to stdout. - -```ts -import { copy } from "https://deno.land/std@$STD_VERSION/io/util.ts"; -const filenames = Deno.args; -for (const filename of filenames) { - const file = await Deno.open(filename); - await copy(file, Deno.stdout); - file.close(); -} -``` - -The `copy()` function here actually makes no more than the necessary -kernel→userspace→kernel copies. That is, the same memory from which data is read -from the file, is written to stdout. This illustrates a general design goal for -I/O streams in Deno. - -Try the program: - -```shell -deno run --allow-read https://deno.land/std@$STD_VERSION/examples/cat.ts /etc/passwd -``` - -### TCP server - -This is an example of a server which accepts connections on port 8080, and -returns to the client anything it sends. - -```ts -import { copy } from "https://deno.land/std@$STD_VERSION/io/util.ts"; -const hostname = "0.0.0.0"; -const port = 8080; -const listener = Deno.listen({ hostname, port }); -console.log(`Listening on ${hostname}:${port}`); -for await (const conn of listener) { - copy(conn, conn); -} -``` - -For security reasons, Deno does not allow programs to access the network without -explicit permission. To allow accessing the network, use a command-line flag: - -```shell -deno run --allow-net https://deno.land/std@$STD_VERSION/examples/echo_server.ts -``` - -To test it, try sending data to it with netcat: - -```shell -$ nc localhost 8080 -hello world -hello world -``` - -Like the `cat.ts` example, the `copy()` function here also does not make -unnecessary memory copies. It receives a packet from the kernel and sends it -back, without further complexity. - -### More examples - -You can find more examples, like an HTTP file server, in the `Examples` chapter. diff --git a/docs/getting_started/installation.md b/docs/getting_started/installation.md deleted file mode 100644 index 781d6f980..000000000 --- a/docs/getting_started/installation.md +++ /dev/null @@ -1,92 +0,0 @@ -## Installation - -Deno works on macOS, Linux, and Windows. Deno is a single binary executable. It -has no external dependencies. - -### Download and install - -[deno_install](https://github.com/denoland/deno_install) provides convenience -scripts to download and install the binary. - -Using Shell (macOS and Linux): - -```shell -curl -fsSL https://deno.land/x/install/install.sh | sh -``` - -Using PowerShell (Windows): - -```shell -iwr https://deno.land/x/install/install.ps1 -useb | iex -``` - -Using [Scoop](https://scoop.sh/) (Windows): - -```shell -scoop install deno -``` - -Using [Chocolatey](https://chocolatey.org/packages/deno) (Windows): - -```shell -choco install deno -``` - -Using [Homebrew](https://formulae.brew.sh/formula/deno) (macOS): - -```shell -brew install deno -``` - -Using [Nix](https://nixos.org/download.html) (macOS and Linux): - -```shell -nix-shell -p deno -``` - -Build and install from source using [Cargo](https://crates.io/crates/deno): - -```shell -cargo install deno --locked -``` - -Deno binaries can also be installed manually, by downloading a zip file at -[github.com/denoland/deno/releases](https://github.com/denoland/deno/releases). -These packages contain just a single executable file. You will have to set the -executable bit on macOS and Linux. - -### Docker - -For more information and instructions on the official Docker images: -[https://github.com/denoland/deno_docker](https://github.com/denoland/deno_docker) - -### Testing your installation - -To test your installation, run `deno --version`. If this prints the Deno version -to the console the installation was successful. - -Use `deno help` to see help text documenting Deno's flags and usage. Get a -detailed guide on the CLI [here](./command_line_interface.md). - -### Updating - -To update a previously installed version of Deno, you can run: - -```shell -deno upgrade -``` - -This will fetch the latest release from -[github.com/denoland/deno/releases](https://github.com/denoland/deno/releases), -unzip it, and replace your current executable with it. - -You can also use this utility to install a specific version of Deno: - -```shell -deno upgrade --version 1.0.1 -``` - -### Building from source - -Information about how to build from source can be found in the `Contributing` -chapter. diff --git a/docs/getting_started/permissions.md b/docs/getting_started/permissions.md deleted file mode 100644 index 0a8eda6bf..000000000 --- a/docs/getting_started/permissions.md +++ /dev/null @@ -1,96 +0,0 @@ -## Permissions - -Deno is secure by default. Therefore, unless you specifically enable it, a deno -module has no file, network, or environment access for example. Access to -security-sensitive areas or functions requires the use of permissions to be -granted to a deno process on the command line. - -For the following example, `mod.ts` has been granted read-only access to the -file system. It cannot write to it, or perform any other security-sensitive -functions. - -```shell -deno run --allow-read mod.ts -``` - -### Permissions list - -The following permissions are available: - -- **-A, --allow-all** Allow all permissions. This disables all security. -- **--allow-env=\<allow-env\>** Allow environment access for things like getting - and setting of environment variables. Since Deno 1.9, you can specify a - optional, comma-separated list of environment variables to provide an - allow-list of allowed environment variables. -- **--allow-hrtime** Allow high-resolution time measurement. High-resolution - time can be used in timing attacks and fingerprinting. -- **--allow-net=\<allow-net\>** Allow network access. You can specify an - optional, comma-separated list of domains to provide an allow-list of allowed - domains. -- **--allow-plugin** Allow loading plugins. Please note that --allow-plugin is - an unstable feature. -- **--allow-read=\<allow-read\>** Allow file system read access. You can specify - an optional, comma-separated list of directories or files to provide an - allow-list of allowed file system access. -- **--allow-run=\<allow-run\>** Allow running subprocesses. Since Deno 1.9, You - can specify an options, comma-separated list of subprocesses to provide an - allow-list of allowed subprocesses. Be aware that subprocesses are not run in - a sandbox and therefore do not have the same security restrictions as the deno - process. Therefore, use with caution. -- **--allow-write=\<allow-write\>** Allow file system write access. You can - specify an optional, comma-separated list of directories or files to provide - an allow-list of allowed file system access. - -### Permissions allow-list - -Deno also allows you to control the granularity of some permissions with -allow-lists. - -This example restricts file system access by allow-listing only the `/usr` -directory, however the execution fails as the process was attempting to access a -file in the `/etc` directory: - -```shell -$ deno run --allow-read=/usr https://deno.land/std@$STD_VERSION/examples/cat.ts /etc/passwd -error: Uncaught PermissionDenied: read access to "/etc/passwd", run again with the --allow-read flag -► $deno$/dispatch_json.ts:40:11 - at DenoError ($deno$/errors.ts:20:5) - ... -``` - -Try it out again with the correct permissions by allow-listing `/etc` instead: - -```shell -deno run --allow-read=/etc https://deno.land/std@$STD_VERSION/examples/cat.ts /etc/passwd -``` - -`--allow-write` works the same as `--allow-read`. - -### Network access: - -_fetch.ts_: - -```ts -const result = await fetch("https://deno.land/"); -``` - -This is an example of how to allow-list hosts/urls: - -```shell -deno run --allow-net=github.com,deno.land fetch.ts -``` - -If `fetch.ts` tries to establish network connections to any other domain, the -process will fail. - -Allow net calls to any host/url: - -```shell -deno run --allow-net fetch.ts -``` - -### Conference - -Ryan Dahl. (September 25, 2020). -[The Deno security model](https://www.youtube.com/watch?v=r5F6dekUmdE#t=34m57). -Speakeasy JS. diff --git a/docs/getting_started/setup_your_environment.md b/docs/getting_started/setup_your_environment.md deleted file mode 100644 index 769528b74..000000000 --- a/docs/getting_started/setup_your_environment.md +++ /dev/null @@ -1,329 +0,0 @@ -## Set up your environment - -To productively get going with Deno you should set up your environment. This -means setting up shell autocomplete, environmental variables and your editor or -IDE of choice. - -### Environmental variables - -There are several env vars that control how Deno behaves: - -`DENO_DIR` defaults to `$HOME/.cache/deno` but can be set to any path to control -where generated and cached source code is written and read to. - -`NO_COLOR` will turn off color output if set. See https://no-color.org/. User -code can test if `NO_COLOR` was set without having `--allow-env` by using the -boolean constant `Deno.noColor`. - -### Shell autocomplete - -You can generate completion script for your shell using the -`deno completions <shell>` command. The command outputs to stdout so you should -redirect it to an appropriate file. - -The supported shells are: - -- zsh -- bash -- fish -- powershell -- elvish - -Example (bash): - -```shell -deno completions bash > /usr/local/etc/bash_completion.d/deno.bash -source /usr/local/etc/bash_completion.d/deno.bash -``` - -Example (zsh without framework): - -```shell -mkdir ~/.zsh # create a folder to save your completions. it can be anywhere -deno completions zsh > ~/.zsh/_deno -``` - -then add this to your `.zshrc` - -```shell -fpath=(~/.zsh $fpath) -autoload -Uz compinit -compinit -u -``` - -and restart your terminal. note that if completions are still not loading, you -may need to run `rm ~/.zcompdump/` to remove previously generated completions -and then `compinit` to generate them again. - -Example (zsh + oh-my-zsh) [recommended for zsh users] : - -```shell -mkdir ~/.oh-my-zsh/custom/plugins/deno -deno completions zsh > ~/.oh-my-zsh/custom/plugins/deno/_deno -``` - -After this add deno plugin under plugins tag in `~/.zshrc` file. for tools like -`antigen` path will be `~/.antigen/bundles/robbyrussell/oh-my-zsh/plugins` and -command will be `antigen bundle deno` and so on. - -Example (Powershell): - -```shell -deno completions powershell >> $profile -.$profile -``` - -This will be create a Powershell profile at -`$HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1` by default, -and it will be run whenever you launch the PowerShell. - -### Editors and IDEs - -Because Deno requires the use of file extensions for module imports and allows -http imports, and most editors and language servers do not natively support this -at the moment, many editors will throw errors about being unable to find files -or imports having unnecessary file extensions. - -The community has developed extensions for some editors to solve these issues: - -#### VS Code - -The beta version of [vscode_deno](https://github.com/denoland/vscode_deno) is -published on the -[Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno). -Please report any issues. - -#### JetBrains IDEs - -Support for JetBrains IDEs is available through -[the Deno plugin](https://plugins.jetbrains.com/plugin/14382-deno). - -Once installed, replace the content of -`External Libraries > Deno Library > lib > lib.deno.d.ts` with the output of -`deno types`. This will ensure the typings for the extension match the current -version. You will have to do this every time you update the version of Deno. For -more information on how to set-up your JetBrains IDE for Deno, read -[this comment](https://youtrack.jetbrains.com/issue/WEB-41607#focus=streamItem-27-4160152.0-0) -on YouTrack. - -#### Vim and NeoVim - -Vim works fairly well for Deno/TypeScript if you install -[CoC](https://github.com/neoclide/coc.nvim) (intellisense engine and language -server protocol) or [ALE](https://github.com/dense-analysis/ale) (syntax checker -and language server protocol client). - -##### CoC - -After CoC is installed, from inside Vim, run`:CocInstall coc-tsserver` and -`:CocInstall coc-deno`. Run `:CocCommand deno.initializeWorkspace` in your -project to initialize workspace configurations. From now on, things like `gd` -(go to definition) and `gr` (goto/find references) should work. - -##### ALE - -ALE integrates with Deno's LSP out of the box and should not require any extra -configuration. However, if your Deno executable is not located in `$PATH`, has a -different name than `deno` or you want to use unstable features/APIs, you need -to override ALE's default values. See -[`:help ale-typescript`](https://github.com/dense-analysis/ale/blob/master/doc/ale-typescript.txt). - -ALE provides support for autocompletion, refactoring, going to definition, -finding references and more, however, key bindings need to be configured -manually. Copy the snippet below into your `vimrc`/`init.vim` for basic -configuration or consult the -[official documentation](https://github.com/dense-analysis/ale#table-of-contents) -for a more in-depth look at how to configure ALE. - -ALE can fix linter issues by running `deno fmt`. To instruct ALE to use the Deno -formatter the `ale_linter` setting needs to be set either on a per buffer basis -(`let b:ale_linter = ['deno']`) or globally for all TypeScript files -(`let g:ale_fixers={'typescript': ['deno']}`) - -```vim -" Use ALE autocompletion with Vim's 'omnifunc' setting (press <C-x><C-o> in insert mode) -autocmd FileType typescript set omnifunc=ale#completion#OmniFunc - -" Make sure to use map instead of noremap when using a <Plug>(...) expression as the {rhs} -nmap gr <Plug>(ale_rename) -nmap gR <Plug>(ale_find_reference) -nmap gd <Plug>(ale_go_to_definition) -nmap gD <Plug>(ale_go_to_type_definition) - -let g:ale_fixers = {'typescript': ['deno']} -let g:ale_fix_on_save = 1 " run deno fmt when saving a buffer -``` - -#### Emacs - -Emacs works pretty well for a TypeScript project targeted to Deno by using a -combination of [tide](https://github.com/ananthakumaran/tide) which is the -canonical way of using TypeScript within Emacs and -[typescript-deno-plugin](https://github.com/justjavac/typescript-deno-plugin) -which is what is used by the -[official VSCode extension for Deno](https://github.com/denoland/vscode_deno). - -To use it, first make sure that `tide` is setup for your instance of Emacs. -Next, as instructed on the -[typescript-deno-plugin](https://github.com/justjavac/typescript-deno-plugin) -page, first `npm install --save-dev typescript-deno-plugin typescript` in your -project (`npm init -y` as necessary), then add the following block to your -`tsconfig.json` and you are off to the races! - -```jsonc -{ - "compilerOptions": { - "plugins": [ - { - "name": "typescript-deno-plugin", - "enable": true, // default is `true` - "importmap": "import_map.json" - } - ] - } -} -``` - -You can also use built-in Deno language server by using -[`eglot`](https://github.com/joaotavora/eglot). - -Example configuration: - -```elisp -(add-to-list 'eglot-server-programs '((js-mode typescript-mode) . (eglot-deno "deno" "lsp"))) - - (defclass eglot-deno (eglot-lsp-server) () - :documentation "A custom class for deno lsp.") - - (cl-defmethod eglot-initialization-options ((server eglot-deno)) - "Passes through required deno initialization options" - (list :enable t - :lint t)) -``` - -#### Atom - -Install [atom-ide-base](https://atom.io/packages/atom-ide-base) package and -[atom-ide-deno](https://atom.io/packages/atom-ide-deno) package on Atom. - -#### LSP clients - -Deno has builtin support for the -[Language server protocol](https://langserver.org) as of version 1.6.0 or later. - -If your editor supports the LSP, you can use Deno as a language server for -TypeScript and JavaScript. - -The editor can start the server with `deno lsp`. - -##### Example for Kakoune - -After installing the [`kak-lsp`](https://github.com/kak-lsp/kak-lsp) LSP client -you can add the Deno language server by adding the following to your -`kak-lsp.toml` - -```toml -[language.deno] -filetypes = ["typescript", "javascript"] -roots = [".git"] -command = "deno" -args = ["lsp"] - -[language.deno.initialization_options] -enable = true -lint = true -``` - -##### Example for Vim/Neovim - -After installing the [`vim-lsp`](https://github.com/prabirshrestha/vim-lsp) LSP -client you can add the Deno language server by adding the following to your -`vimrc`/`init.vim`: - -```vim -if executable("deno") - augroup LspTypeScript - autocmd! - autocmd User lsp_setup call lsp#register_server({ - \ "name": "deno lsp", - \ "cmd": {server_info -> ["deno", "lsp"]}, - \ "root_uri": {server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), "tsconfig.json"))}, - \ "allowlist": ["typescript", "typescript.tsx"], - \ "initialization_options": { - \ "enable": v:true, - \ "lint": v:true, - \ "unstable": v:true, - \ }, - \ }) - augroup END -endif -``` - -##### Example for Sublime Text - -- Install the [Sublime LSP package](https://packagecontrol.io/packages/LSP) -- Install the - [TypeScript package](https://packagecontrol.io/packages/TypeScript) to get - syntax highlighting -- Add the following `.sublime-project` file to your project folder - -```jsonc -{ - "settings": { - "LSP": { - "deno": { - "command": [ - "deno", - "lsp" - ], - "initializationOptions": { - // "config": "", // Sets the path for the config file in your project - "enable": true, - // "importMap": "", // Sets the path for the import-map in your project - "lint": true, - "unstable": false - }, - "enabled": true, - "languages": [ - { - "languageId": "javascript", - "scopes": ["source.js"], - "syntaxes": [ - "Packages/Babel/JavaScript (Babel).sublime-syntax", - "Packages/JavaScript/JavaScript.sublime-syntax" - ] - }, - { - "languageId": "javascriptreact", - "scopes": ["source.jsx"], - "syntaxes": [ - "Packages/Babel/JavaScript (Babel).sublime-syntax", - "Packages/JavaScript/JavaScript.sublime-syntax" - ] - }, - { - "languageId": "typescript", - "scopes": ["source.ts"], - "syntaxes": [ - "Packages/TypeScript-TmLanguage/TypeScript.tmLanguage", - "Packages/TypeScript Syntax/TypeScript.tmLanguage" - ] - }, - { - "languageId": "typescriptreact", - "scopes": ["source.tsx"], - "syntaxes": [ - "Packages/TypeScript-TmLanguage/TypeScriptReact.tmLanguage", - "Packages/TypeScript Syntax/TypeScriptReact.tmLanguage" - ] - } - ] - } - } - } -} -``` - -If you don't see your favorite IDE on this list, maybe you can develop an -extension. Our [community Discord group](https://discord.gg/deno) can give you -some pointers on where to get started. diff --git a/docs/getting_started/typescript.md b/docs/getting_started/typescript.md deleted file mode 100644 index 5ece3d873..000000000 --- a/docs/getting_started/typescript.md +++ /dev/null @@ -1,4 +0,0 @@ -## Using TypeScript - -> ℹ️ This section has been moved to -> [Using TypeScript Chapter](../typescript.md). diff --git a/docs/getting_started/webassembly.md b/docs/getting_started/webassembly.md deleted file mode 100644 index 307aba452..000000000 --- a/docs/getting_started/webassembly.md +++ /dev/null @@ -1,43 +0,0 @@ -## WebAssembly support - -Deno can execute [WebAssembly](https://webassembly.org/) modules with the same -interfaces that -[browsers provide](https://developer.mozilla.org/en-US/docs/WebAssembly). - -<!-- deno-fmt-ignore --> - -```ts -const wasmCode = new Uint8Array([ - 0, 97, 115, 109, 1, 0, 0, 0, 1, 133, 128, 128, 128, 0, 1, 96, 0, 1, 127, - 3, 130, 128, 128, 128, 0, 1, 0, 4, 132, 128, 128, 128, 0, 1, 112, 0, 0, - 5, 131, 128, 128, 128, 0, 1, 0, 1, 6, 129, 128, 128, 128, 0, 0, 7, 145, - 128, 128, 128, 0, 2, 6, 109, 101, 109, 111, 114, 121, 2, 0, 4, 109, 97, - 105, 110, 0, 0, 10, 138, 128, 128, 128, 0, 1, 132, 128, 128, 128, 0, 0, - 65, 42, 11 -]); -const wasmModule = new WebAssembly.Module(wasmCode); -const wasmInstance = new WebAssembly.Instance(wasmModule); -const main = wasmInstance.exports.main as CallableFunction -console.log(main().toString()); -``` - -For files: - -```ts -const wasmCode = await Deno.readFile("main.wasm"); -const wasmModule = new WebAssembly.Module(wasmCode); -const wasmInstance = new WebAssembly.Instance(wasmModule); -const main = wasmInstance.exports.main as CallableFunction; -console.log(main().toString()); -``` - -And for loading WebAssembly modules over the network (note that the file must be -served with `application/wasm` MIME type): - -```ts -const { instance, module } = await WebAssembly.instantiateStreaming( - fetch("https://wpt.live/wasm/incrementer.wasm"), -); -const increment = instance.exports.increment as (input: number) => number; -console.log(increment(41)); -``` |