1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-09 07:39:15 -05:00

feat: add $STD_VERSION replacement variable in docs (#6922)

This commit is contained in:
Luca Casonato 2020-07-31 11:12:20 +02:00 committed by GitHub
parent 6e7208bec2
commit 4afb4b6e46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 59 additions and 58 deletions

View file

@ -278,7 +278,7 @@ test myTestFunction ... ok
Example of test: Example of test:
```ts ```ts
import { assertEquals } from "https://deno.land/std@v0.11/testing/asserts.ts"; import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
import { foo } from "./mod.ts"; import { foo } from "./mod.ts";
Deno.test("myTestFunction" function() { Deno.test("myTestFunction" function() {

View file

@ -3,14 +3,14 @@
This one serves a local directory in HTTP. This one serves a local directory in HTTP.
```shell ```shell
deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts deno install --allow-net --allow-read https://deno.land/std@$STD_VERSION/http/file_server.ts
``` ```
Run it: Run it:
```shell ```shell
$ file_server . $ file_server .
Downloading https://deno.land/std/http/file_server.ts... Downloading https://deno.land/std@$STD_VERSION/http/file_server.ts...
[...] [...]
HTTP server listening on http://0.0.0.0:4500/ HTTP server listening on http://0.0.0.0:4500/
``` ```

View file

@ -38,7 +38,7 @@ const p = Deno.run({
"deno", "deno",
"run", "run",
"--allow-read", "--allow-read",
"https://deno.land/std/examples/cat.ts", "https://deno.land/std@$STD_VERSION/examples/cat.ts",
...fileNames, ...fileNames,
], ],
stdout: "piped", stdout: "piped",

View file

@ -14,7 +14,7 @@ for await (const conn of listener) {
When this program is started, it throws PermissionDenied error. When this program is started, it throws PermissionDenied error.
```shell ```shell
$ deno run https://deno.land/std/examples/echo_server.ts $ deno run https://deno.land/std@$STD_VERSION/examples/echo_server.ts
error: Uncaught PermissionDenied: network access to "0.0.0.0:8080", run again with the --allow-net flag error: Uncaught PermissionDenied: network access to "0.0.0.0:8080", run again with the --allow-net flag
► $deno$/dispatch_json.ts:40:11 ► $deno$/dispatch_json.ts:40:11
at DenoError ($deno$/errors.ts:20:5) at DenoError ($deno$/errors.ts:20:5)
@ -25,7 +25,7 @@ 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: explicit permission. To allow accessing the network, use a command-line flag:
```shell ```shell
deno run --allow-net https://deno.land/std/examples/echo_server.ts deno run --allow-net https://deno.land/std@$STD_VERSION/examples/echo_server.ts
``` ```
To test it, try sending data to it with netcat: To test it, try sending data to it with netcat:

View file

@ -20,5 +20,5 @@ I/O streams in Deno.
Try the program: Try the program:
```shell ```shell
deno run --allow-read https://deno.land/std/examples/cat.ts /etc/passwd deno run --allow-read https://deno.land/std@$STD_VERSION/examples/cat.ts /etc/passwd
``` ```

View file

@ -23,7 +23,7 @@ console.log("Welcome to Deno 🦕");
Try the program: Try the program:
```shell ```shell
deno run https://deno.land/std/examples/welcome.ts deno run https://deno.land/std@$STD_VERSION/examples/welcome.ts
``` ```
### Making an HTTP request ### Making an HTTP request
@ -59,7 +59,7 @@ Let's walk through what this application does:
Try it out: Try it out:
```shell ```shell
deno run https://deno.land/std/examples/curl.ts https://example.com 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 You will see this program returns an error regarding network access, so what did
@ -70,7 +70,7 @@ permission to do certain 'privileged' actions, such as access the network.
Try it out again with the correct permission flag: Try it out again with the correct permission flag:
```shell ```shell
deno run --allow-net=example.com https://deno.land/std/examples/curl.ts https://example.com deno run --allow-net=example.com https://deno.land/std@$STD_VERSION/examples/curl.ts https://example.com
``` ```
### Reading a file ### Reading a file
@ -102,7 +102,7 @@ I/O streams in Deno.
Try the program: Try the program:
```shell ```shell
deno run --allow-read https://deno.land/std/examples/cat.ts /etc/passwd deno run --allow-read https://deno.land/std@$STD_VERSION/examples/cat.ts /etc/passwd
``` ```
### TCP server ### TCP server
@ -124,7 +124,7 @@ 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: explicit permission. To allow accessing the network, use a command-line flag:
```shell ```shell
deno run --allow-net https://deno.land/std/examples/echo_server.ts deno run --allow-net https://deno.land/std@$STD_VERSION/examples/echo_server.ts
``` ```
To test it, try sending data to it with netcat: To test it, try sending data to it with netcat:

View file

@ -47,7 +47,7 @@ directory, however the execution fails as the process was attempting to access a
file in the `/etc` directory: file in the `/etc` directory:
```shell ```shell
$ deno run --allow-read=/usr https://deno.land/std/examples/cat.ts /etc/passwd $ 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 error: Uncaught PermissionDenied: read access to "/etc/passwd", run again with the --allow-read flag
► $deno$/dispatch_json.ts:40:11 ► $deno$/dispatch_json.ts:40:11
at DenoError ($deno$/errors.ts:20:5) at DenoError ($deno$/errors.ts:20:5)
@ -57,7 +57,7 @@ error: Uncaught PermissionDenied: read access to "/etc/passwd", run again with t
Try it out again with the correct permissions by allow-listing `/etc` instead: Try it out again with the correct permissions by allow-listing `/etc` instead:
```shell ```shell
deno run --allow-read=/etc https://deno.land/std/examples/cat.ts /etc/passwd deno run --allow-read=/etc https://deno.land/std@$STD_VERSION/examples/cat.ts /etc/passwd
``` ```
`--allow-write` works the same as `--allow-read`. `--allow-write` works the same as `--allow-read`.

View file

@ -10,7 +10,7 @@ no "magical" module resolution. Instead, imported modules are specified as files
directly imported. E.g. directly imported. E.g.
``` ```
import { Response } from "https://deno.land/std@0.53.0/http/server.ts"; import { Response } from "https://deno.land/std@$STD_VERSION/http/server.ts";
import { queue } from "./collections.ts"; import { queue } from "./collections.ts";
``` ```

View file

@ -60,7 +60,7 @@ have been historically written with bash or python.
imported via URLs: imported via URLs:
```javascript ```javascript
import * as log from "https://deno.land/std/log/mod.ts"; import * as log from "https://deno.land/std@$STD_VERSION/log/mod.ts";
``` ```
## Other key behaviors ## Other key behaviors

View file

@ -7,7 +7,7 @@ directly from URLs. This example uses a URL to import an assertion library:
**test.ts** **test.ts**
```ts ```ts
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
assertEquals("hello", "hello"); assertEquals("hello", "hello");
assertEquals("world", "world"); assertEquals("world", "world");
@ -20,9 +20,9 @@ Try running this:
```shell ```shell
$ deno run test.ts $ deno run test.ts
Compile file:///mnt/f9/Projects/github.com/denoland/deno/docs/test.ts Compile file:///mnt/f9/Projects/github.com/denoland/deno/docs/test.ts
Download https://deno.land/std/testing/asserts.ts Download https://deno.land/std@$STD_VERSION/testing/asserts.ts
Download https://deno.land/std/fmt/colors.ts Download https://deno.land/std@$STD_VERSION/fmt/colors.ts
Download https://deno.land/std/testing/diff.ts Download https://deno.land/std@$STD_VERSION/testing/diff.ts
Asserted! ✓ Asserted! ✓
``` ```
@ -57,8 +57,9 @@ being run: `https://unpkg.com/liltest@0.0.5/dist/liltest.js`.
The solution is to import and re-export your external libraries in a central The solution is to import and re-export your external libraries in a central
`deps.ts` file (which serves the same purpose as Node's `package.json` file). `deps.ts` file (which serves the same purpose as Node's `package.json` file).
For example, let's say you were using the above assertion library across a large For example, let's say you were using the above assertion library across a large
project. Rather than importing `"https://deno.land/std/testing/asserts.ts"` project. Rather than importing
everywhere, you could create a `deps.ts` file that exports the third-party code: `"https://deno.land/std@$STD_VERSION/testing/asserts.ts"` everywhere, you could
create a `deps.ts` file that exports the third-party code:
**deps.ts** **deps.ts**
@ -67,7 +68,7 @@ export {
assert, assert,
assertEquals, assertEquals,
assertStrContains, assertStrContains,
} from "https://deno.land/std/testing/asserts.ts"; } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
``` ```
And throughout the same project, you can import from the `deps.ts` and avoid And throughout the same project, you can import from the `deps.ts` and avoid

View file

@ -21,7 +21,7 @@ Example:
```js ```js
{ {
"imports": { "imports": {
"fmt/": "https://deno.land/std@0.55.0/fmt/" "fmt/": "https://deno.land/std@$STD_VERSION/fmt/"
} }
} }
``` ```

View file

@ -25,9 +25,9 @@ dependency:
```json ```json
{ {
"https://deno.land/std@v0.50.0/textproto/mod.ts": "3118d7a42c03c242c5a49c2ad91c8396110e14acca1324e7aaefd31a999b71a4", "https://deno.land/std@$STD_VERSION/textproto/mod.ts": "3118d7a42c03c242c5a49c2ad91c8396110e14acca1324e7aaefd31a999b71a4",
"https://deno.land/std@v0.50.0/io/util.ts": "ae133d310a0fdcf298cea7bc09a599c49acb616d34e148e263bcb02976f80dee", "https://deno.land/std@$STD_VERSION/io/util.ts": "ae133d310a0fdcf298cea7bc09a599c49acb616d34e148e263bcb02976f80dee",
"https://deno.land/std@v0.50.0/async/delay.ts": "35957d585a6e3dd87706858fb1d6b551cb278271b03f52c5a2cb70e65e00c26a", "https://deno.land/std@$STD_VERSION/async/delay.ts": "35957d585a6e3dd87706858fb1d6b551cb278271b03f52c5a2cb70e65e00c26a",
... ...
} }
``` ```

View file

@ -17,17 +17,17 @@ deno cache --reload my_module.ts
Sometimes we want to upgrade only some modules. You can control it by passing an Sometimes we want to upgrade only some modules. You can control it by passing an
argument to a `--reload` flag. argument to a `--reload` flag.
To reload all v0.55.0 standard modules To reload all \$STD_VERSION standard modules
```ts ```ts
deno cache --reload=https://deno.land/std@v0.55.0 my_module.ts deno cache --reload=https://deno.land/std@$STD_VERSION my_module.ts
``` ```
To reload specific modules (in this example - colors and file system copy) use a To reload specific modules (in this example - colors and file system copy) use a
comma to separate URLs comma to separate URLs
```ts ```ts
deno cache --reload=https://deno.land/std/fs/copy.ts,https://deno.land/std/fmt/colors.ts my_module.ts deno cache --reload=https://deno.land/std@$STD_VERSION/fs/copy.ts,https://deno.land/std@$STD_VERSION/fmt/colors.ts my_module.ts
``` ```
<!-- Should this be part of examples? --> <!-- Should this be part of examples? -->

View file

@ -48,7 +48,7 @@ could do on the command line. So you could do something like this:
```ts ```ts
const [diagnostics, emitMap] = await Deno.compile( const [diagnostics, emitMap] = await Deno.compile(
"https://deno.land/std/examples/welcome.ts", "https://deno.land/std@$STD_VERSION/examples/welcome.ts",
); );
``` ```
@ -95,7 +95,7 @@ could do on the command line. So you could do something like this:
```ts ```ts
const [diagnostics, emit] = await Deno.bundle( const [diagnostics, emit] = await Deno.bundle(
"https://deno.land/std/http/server.ts", "https://deno.land/std@$STD_VERSION/http/server.ts",
); );
``` ```

View file

@ -27,7 +27,7 @@ change:
```typescript ```typescript
// imports from v0.50.0 of std, never changes // imports from v0.50.0 of std, never changes
import { copy } from "https://deno.land/std@0.50.0/fs/copy.ts"; import { copy } from "https://deno.land/std@$STD_VERSION/fs/copy.ts";
``` ```
## Troubleshooting ## Troubleshooting
@ -40,7 +40,7 @@ exist:
```typescript ```typescript
// main.ts // main.ts
import { copy } from "https://deno.land/std@0.50.0/fs/copy.ts"; import { copy } from "https://deno.land/std@$STD_VERSION/fs/copy.ts";
copy("log.txt", "log-old.txt"); copy("log.txt", "log-old.txt");
``` ```
@ -48,18 +48,18 @@ copy("log.txt", "log-old.txt");
```shell ```shell
$ deno run --allow-read --allow-write main.ts $ deno run --allow-read --allow-write main.ts
Compile file:///dev/deno/main.ts Compile file:///dev/deno/main.ts
Download https://deno.land/std@0.50.0/fs/copy.ts Download https://deno.land/std@$STD_VERSION/fs/copy.ts
Download https://deno.land/std@0.50.0/fs/ensure_dir.ts Download https://deno.land/std@$STD_VERSION/fs/ensure_dir.ts
Download https://deno.land/std@0.50.0/fs/_util.ts Download https://deno.land/std@$STD_VERSION/fs/_util.ts
error: TS2339 [ERROR]: Property 'utime' does not exist on type 'typeof Deno'. error: TS2339 [ERROR]: Property 'utime' does not exist on type 'typeof Deno'.
await Deno.utime(dest, statInfo.atime, statInfo.mtime); await Deno.utime(dest, statInfo.atime, statInfo.mtime);
~~~~~ ~~~~~
at https://deno.land/std@0.50.0/fs/copy.ts:90:16 at https://deno.land/std@$STD_VERSION/fs/copy.ts:90:16
TS2339 [ERROR]: Property 'utimeSync' does not exist on type 'typeof Deno'. TS2339 [ERROR]: Property 'utimeSync' does not exist on type 'typeof Deno'.
Deno.utimeSync(dest, statInfo.atime, statInfo.mtime); Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
~~~~~~~~~ ~~~~~~~~~
at https://deno.land/std@0.50.0/fs/copy.ts:101:10 at https://deno.land/std@$STD_VERSION/fs/copy.ts:101:10
``` ```
Solution to that problem requires adding `--unstable` flag: Solution to that problem requires adding `--unstable` flag:

View file

@ -27,14 +27,14 @@ Deno.test({
## Assertions ## Assertions
There are some useful assertion utilities at https://deno.land/std/testing#usage There are some useful assertion utilities at
to make testing easier: https://deno.land/std@$STD_VERSION/testing#usage to make testing easier:
```ts ```ts
import { import {
assertEquals, assertEquals,
assertArrayContains, assertArrayContains,
} from "https://deno.land/std/testing/asserts.ts"; } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
Deno.test("hello world", () => { Deno.test("hello world", () => {
const x = 1 + 2; const x = 1 + 2;
@ -49,7 +49,7 @@ You can also test asynchronous code by passing a test function that returns a
promise. For this you can use the `async` keyword when defining a function: promise. For this you can use the `async` keyword when defining a function:
```ts ```ts
import { delay } from "https://deno.land/std/async/delay.ts"; import { delay } from "https://deno.land/std@$STD_VERSION/async/delay.ts";
Deno.test("async hello world", async () => { Deno.test("async hello world", async () => {
const x = 1 + 2; const x = 1 + 2;

View file

@ -1,11 +1,11 @@
## Assertions ## Assertions
To help developers write tests the Deno standard library comes with a built in To help developers write tests the Deno standard library comes with a built in
[assertions module](https://deno.land/std/testing/asserts.ts) which can be [assertions module](https://deno.land/std@$STD_VERSION/testing/asserts.ts) which
imported from `https://deno.land/std/testing/asserts.ts`. can be imported from `https://deno.land/std@$STD_VERSION/testing/asserts.ts`.
```js ```js
import { assert } from "https://deno.land/std/testing/asserts.ts"; import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
Deno.test("Hello Test", () => { Deno.test("Hello Test", () => {
assert("Hello"); assert("Hello");

View file

@ -4,7 +4,7 @@
dependencies of the specified input. For example: dependencies of the specified input. For example:
``` ```
> deno bundle https://deno.land/std/examples/colors.ts colors.bundle.js > deno bundle https://deno.land/std@$STD_VERSION/examples/colors.ts colors.bundle.js
Bundling "colors.bundle.js" Bundling "colors.bundle.js"
Emitting bundle to "colors.bundle.js" Emitting bundle to "colors.bundle.js"
9.2 kB emitted. 9.2 kB emitted.

View file

@ -15,16 +15,16 @@ the first line of code.
### Chrome Devtools ### Chrome Devtools
Let's try debugging a program using Chrome Devtools. For this, we'll use Let's try debugging a program using Chrome Devtools. For this, we'll use
[file_server.ts](https://deno.land/std@v0.50.0/http/file_server.ts) from `std`, [file_server.ts](https://deno.land/std@$STD_VERSION/http/file_server.ts) from
a static file server. `std`, a static file server.
Use the `--inspect-brk` flag to break execution on the first line: Use the `--inspect-brk` flag to break execution on the first line:
```shell ```shell
$ deno run --inspect-brk --allow-read --allow-net https://deno.land/std@v0.50.0/http/file_server.ts $ 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 Debugger listening on ws://127.0.0.1:9229/ws/1e82c406-85a9-44ab-86b6-7341583480b1
Download https://deno.land/std@v0.50.0/http/file_server.ts Download https://deno.land/std@$STD_VERSION/http/file_server.ts
Compile https://deno.land/std@v0.50.0/http/file_server.ts Compile https://deno.land/std@$STD_VERSION/http/file_server.ts
... ...
``` ```
@ -110,7 +110,7 @@ with a script name if you want a fixed entry point.
Let's try out debugging a local source file. Create `server.ts`: Let's try out debugging a local source file. Create `server.ts`:
```ts ```ts
import { serve } from "https://deno.land/std@v0.50.0/http/server.ts"; import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts";
const server = serve({ port: 8000 }); const server = serve({ port: 8000 });
console.log("http://localhost:8000/"); console.log("http://localhost:8000/");

View file

@ -12,8 +12,8 @@ the specified CLI flags and main module. It is placed in the installation root's
Example: Example:
```shell ```shell
$ deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts $ deno install --allow-net --allow-read https://deno.land/std@$STD_VERSION/http/file_server.ts
[1/1] Compiling https://deno.land/std/http/file_server.ts [1/1] Compiling https://deno.land/std@$STD_VERSION/http/file_server.ts
✅ Successfully installed file_server. ✅ Successfully installed file_server.
/Users/deno/.deno/bin/file_server /Users/deno/.deno/bin/file_server
@ -22,7 +22,7 @@ $ deno install --allow-net --allow-read https://deno.land/std/http/file_server.t
To change the executable name, use `-n`/`--name`: To change the executable name, use `-n`/`--name`:
```shell ```shell
deno install --allow-net --allow-read -n serve https://deno.land/std/http/file_server.ts deno install --allow-net --allow-read -n serve https://deno.land/std@$STD_VERSION/http/file_server.ts
``` ```
The executable name is inferred by default: The executable name is inferred by default:
@ -36,7 +36,7 @@ The executable name is inferred by default:
To change the installation root, use `--root`: To change the installation root, use `--root`:
```shell ```shell
deno install --allow-net --allow-read --root /usr/local https://deno.land/std/http/file_server.ts deno install --allow-net --allow-read --root /usr/local https://deno.land/std@$STD_VERSION/http/file_server.ts
``` ```
The installation root is determined, in order of precedence: The installation root is determined, in order of precedence:
@ -55,7 +55,7 @@ You must specify permissions that will be used to run the script at installation
time. time.
```shell ```shell
deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts -p 8080 deno install --allow-net --allow-read https://deno.land/std@$STD_VERSION/http/file_server.ts -p 8080
``` ```
The above command creates an executable called `file_server` that runs with The above command creates an executable called `file_server` that runs with