Skip to content

Commit b4eec47

Browse files
bartlomiejuclaude
andauthored
docs: add cross-links for APIs, deno.json, and std library (#3003)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4b3da3f commit b4eec47

33 files changed

Lines changed: 283 additions & 169 deletions

api_links_test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { walk } from "@std/fs";
2+
import { assert } from "@std/assert";
3+
4+
const DIRS_TO_CHECK = ["./runtime"];
5+
6+
/**
7+
* Find unlinked `Deno.*` API references in markdown prose.
8+
*
9+
* Matches: `Deno.serve` `Deno.readFile()` `Deno.FsFile`
10+
* Ignores: [`Deno.serve`](/api/deno/~/Deno.serve) (already linked)
11+
* Ignores: references inside fenced code blocks
12+
*/
13+
function findUnlinkedDenoApis(
14+
content: string,
15+
): { line: number; api: string }[] {
16+
const lines = content.split("\n");
17+
const results: { line: number; api: string }[] = [];
18+
let inCodeBlock = false;
19+
20+
for (let i = 0; i < lines.length; i++) {
21+
const line = lines[i];
22+
23+
if (/^```/.test(line)) {
24+
inCodeBlock = !inCodeBlock;
25+
continue;
26+
}
27+
if (inCodeBlock) continue;
28+
29+
// Match `Deno.something` or `Deno.something()` NOT preceded by [
30+
const regex = /(?<!\[)`(Deno\.[a-zA-Z]\w+(?:\.\w+)*?)(?:\(\))?`/g;
31+
let match;
32+
while ((match = regex.exec(line)) !== null) {
33+
results.push({ line: i + 1, api: match[1] });
34+
}
35+
}
36+
37+
return results;
38+
}
39+
40+
Deno.test("`Deno.*` API references should be linked to /api/deno/", async () => {
41+
const allUnlinked: { file: string; line: number; api: string }[] = [];
42+
43+
for (const dir of DIRS_TO_CHECK) {
44+
for await (
45+
const entry of walk(dir, {
46+
exts: [".md", ".mdx"],
47+
skip: [/migration_guide\.md$/],
48+
})
49+
) {
50+
const content = await Deno.readTextFile(entry.path);
51+
for (const { line, api } of findUnlinkedDenoApis(content)) {
52+
allUnlinked.push({ file: entry.path, line, api });
53+
}
54+
}
55+
}
56+
57+
if (allUnlinked.length > 0) {
58+
const report = allUnlinked.map(
59+
({ file, line, api }) =>
60+
`${file}:${line} — \`${api}\` → [\`${api}\`](/api/deno/~/${api})`,
61+
);
62+
console.log(
63+
`\nFound ${allUnlinked.length} unlinked Deno API references:\n`,
64+
);
65+
console.log(report.join("\n"));
66+
console.log();
67+
}
68+
69+
assert(
70+
allUnlinked.length === 0,
71+
`${allUnlinked.length} unlinked Deno API references found (see above)`,
72+
);
73+
});

runtime/fundamentals/debugging.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ deno run --inspect-brk your_script.ts
6767
## Example with Chrome DevTools
6868

6969
Let's try debugging a program using Chrome Devtools. For this, we'll use
70-
[@std/http/file-server](https://jsr.io/@std/http#file-server), a static file
71-
server.
70+
[`@std/http/file-server`](/runtime/reference/std/http/), a static file server.
7271

7372
Use the `--inspect-brk` flag to break execution on the first line:
7473

runtime/fundamentals/ffi.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ allows you to:
2020
- Access operating system APIs and hardware features not directly available in
2121
JavaScript
2222

23-
Deno's FFI implementation is based on the `Deno.dlopen` API, which loads dynamic
24-
libraries and creates JavaScript bindings to the functions they export.
23+
Deno's FFI implementation is based on the
24+
[`Deno.dlopen`](/api/deno/~/Deno.dlopen) API, which loads dynamic libraries and
25+
creates JavaScript bindings to the functions they export.
2526

2627
## Security considerations
2728

@@ -53,7 +54,7 @@ Always ensure you trust the native libraries you're loading through FFI.
5354
The basic pattern for using FFI in Deno involves:
5455

5556
1. Defining the interface for the native functions you want to call
56-
2. Loading the dynamic library using `Deno.dlopen()`
57+
2. Loading the dynamic library using [`Deno.dlopen()`](/api/deno/~/Deno.dlopen)
5758
3. Calling the loaded functions
5859

5960
Here's a simple example loading a C library:
@@ -300,8 +301,8 @@ Before using FFI, consider these alternatives:
300301

301302
- [WebAssembly](/runtime/reference/wasm/), for portable native code that runs
302303
within Deno's sandbox.
303-
- Use `Deno.command` to execute external binaries and subprocesses with
304-
controlled permissions.
304+
- Use [`Deno.command`](/api/deno/~/Deno.command) to execute external binaries
305+
and subprocesses with controlled permissions.
305306
- Check whether [Deno's native APIs](/api/deno) already provide the
306307
functionality you need.
307308

runtime/fundamentals/http_server.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ HTTP/1.1 and HTTP/2.
2525

2626
### A "Hello World" server
2727

28-
The `Deno.serve` function takes a handler function that will be called for each
29-
incoming request, and is expected to return a response (or a promise resolving
30-
to a response).
28+
The [`Deno.serve`](/api/deno/~/Deno.serve) function takes a handler function
29+
that will be called for each incoming request, and is expected to return a
30+
response (or a promise resolving to a response).
3131

3232
Here is an example of a server that returns a "Hello, World!" response for each
3333
request:
@@ -47,13 +47,14 @@ To run this server, you can use the `deno run` command:
4747
deno run --allow-net server.ts
4848
```
4949

50-
There are many more examples of using `Deno.serve` in the
51-
[Examples collection](/examples/#network).
50+
There are many more examples of using [`Deno.serve`](/api/deno/~/Deno.serve) in
51+
the [Examples collection](/examples/#network).
5252

5353
### Listening on a specific port
5454

55-
By default `Deno.serve` will listen on port `8000`, but this can be changed by
56-
passing in a port number in options bag as the first or second argument:
55+
By default [`Deno.serve`](/api/deno/~/Deno.serve) will listen on port `8000`,
56+
but this can be changed by passing in a port number in options bag as the first
57+
or second argument:
5758

5859
```js title="server.ts"
5960
// To listen on port 4242.
@@ -159,8 +160,10 @@ memory.
159160

160161
Be aware that the response body stream is "cancelled" when the client hangs up
161162
the connection. Make sure to handle this case. This can surface itself as an
162-
error in a `write()` call on a `WritableStream` object that is attached to the
163-
response body `ReadableStream` object (for example through a `TransformStream`).
163+
error in a `write()` call on a [`WritableStream`](/api/web/~/WritableStream)
164+
object that is attached to the response body
165+
[`ReadableStream`](/api/web/~/ReadableStream) object (for example through a
166+
[`TransformStream`](/api/web/~/TransformStream)).
164167

165168
### HTTPS support
166169

@@ -240,10 +243,11 @@ be compressed automatically:
240243
Deno can upgrade incoming HTTP requests to a WebSocket. This allows you to
241244
handle WebSocket endpoints on your HTTP servers.
242245

243-
To upgrade an incoming `Request` to a WebSocket you use the
244-
`Deno.upgradeWebSocket` function. This returns an object consisting of a
245-
`Response` and a web standard `WebSocket` object. The returned response should
246-
be used to respond to the incoming request.
246+
To upgrade an incoming [`Request`](/api/web/~/Request) to a WebSocket you use
247+
the [`Deno.upgradeWebSocket`](/api/deno/~/Deno.upgradeWebSocket) function. This
248+
returns an object consisting of a [`Response`](/api/web/~/Response) and a web
249+
standard [`WebSocket`](/api/web/~/WebSocket) object. The returned response
250+
should be used to respond to the incoming request.
247251

248252
Because the WebSocket protocol is symmetrical, the `WebSocket` object is
249253
identical to the one that can be used for client side communication.

runtime/fundamentals/linting_and_formatting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ specify custom settings to tailor the formatting process to your needs.
288288
To use the VSCode ESLint extension in your Deno projects, your project will need
289289
a `node_modules` directory in your project that VSCode extensions can pick up.
290290

291-
In your `deno.json` ensure a `node_modules` folder is created, so the editor can
292-
resolve packages:
291+
In your [`deno.json`](/runtime/fundamentals/configuration/) ensure a
292+
`node_modules` folder is created, so the editor can resolve packages:
293293

294294
```jsonc
295295
{

runtime/fundamentals/modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Starting with Deno 2.4 it's possible to import `text` and `bytes` modules too.
8181

8282
Support for importing `text` and `bytes` modules is experimental and requires
8383
`--unstable-raw-imports` CLI flag or `unstable.raw-import` option in
84-
`deno.json`.
84+
[`deno.json`](/runtime/fundamentals/configuration/).
8585

8686
:::
8787

runtime/fundamentals/open_telemetry.md

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ of the `deno` instrumentation scope. (e.g. `deno:2.1.4`).
104104

105105
Deno automatically creates spans for various operations, such as:
106106

107-
- Incoming HTTP requests served with `Deno.serve`.
108-
- Outgoing HTTP requests made with `fetch`.
107+
- Incoming HTTP requests served with [`Deno.serve`](/api/deno/~/Deno.serve).
108+
- Outgoing HTTP requests made with [`fetch`](/api/web/~/fetch).
109109

110-
#### `Deno.serve`
110+
#### [`Deno.serve`](/api/deno/~/Deno.serve)
111111

112-
When you use `Deno.serve` to create an HTTP server, a span is created for each
113-
incoming request. The span automatically ends when response headers are sent
114-
(not when the response body is done sending).
112+
When you use [`Deno.serve`](/api/deno/~/Deno.serve) to create an HTTP server, a
113+
span is created for each incoming request. The span automatically ends when
114+
response headers are sent (not when the response body is done sending).
115115

116116
The name of the created span is `${method}`. The span kind is `server`.
117117

@@ -158,10 +158,11 @@ Deno.serve(async (req) => {
158158
});
159159
```
160160

161-
#### `fetch`
161+
#### [`fetch`](/api/web/~/fetch)
162162

163-
When you use `fetch` to make an HTTP request, a span is created for the request.
164-
The span automatically ends when the response headers are received.
163+
When you use [`fetch`](/api/web/~/fetch) to make an HTTP request, a span is
164+
created for the request. The span automatically ends when the response headers
165+
are received.
165166

166167
The name of the created span is `${method}`. The span kind is `client`.
167168

@@ -181,15 +182,16 @@ After the response is received, the following attributes are added:
181182

182183
The following metrics are automatically collected and exported:
183184

184-
#### `Deno.serve` / `Deno.serveHttp`
185+
#### [`Deno.serve`](/api/deno/~/Deno.serve) / [`Deno.serveHttp`](/api/deno/~/Deno.serveHttp)
185186

186187
##### `http.server.request.duration`
187188

188-
A histogram of the duration of incoming HTTP requests served with `Deno.serve`
189-
or `Deno.serveHttp`. The time that is measured is from when the request is
190-
received to when the response headers are sent. This does not include the time
191-
to send the response body. The unit of this metric is seconds. The histogram
192-
buckets are
189+
A histogram of the duration of incoming HTTP requests served with
190+
[`Deno.serve`](/api/deno/~/Deno.serve) or
191+
[`Deno.serveHttp`](/api/deno/~/Deno.serveHttp). The time that is measured is
192+
from when the request is received to when the response headers are sent. This
193+
does not include the time to send the response body. The unit of this metric is
194+
seconds. The histogram buckets are
193195
`[0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0]`.
194196

195197
This metric is recorded with the following attributes:
@@ -207,10 +209,12 @@ This metric is recorded with the following attributes:
207209

208210
##### `http.server.active_requests`
209211

210-
A gauge of the number of active requests being handled by `Deno.serve` or
211-
`Deno.serveHttp` at any given time. This is the number of requests that have
212-
been received but not yet responded to (where the response headers have not yet
213-
been sent). This metric is recorded with the following attributes:
212+
A gauge of the number of active requests being handled by
213+
[`Deno.serve`](/api/deno/~/Deno.serve) or
214+
[`Deno.serveHttp`](/api/deno/~/Deno.serveHttp) at any given time. This is the
215+
number of requests that have been received but not yet responded to (where the
216+
response headers have not yet been sent). This metric is recorded with the
217+
following attributes:
214218

215219
- `http.request.method`: The HTTP method of the request.
216220
- `url.scheme`: The scheme of the request URL.
@@ -220,8 +224,9 @@ been sent). This metric is recorded with the following attributes:
220224
##### `http.server.request.body.size`
221225

222226
A histogram of the size of the request body of incoming HTTP requests served
223-
with `Deno.serve` or `Deno.serveHttp`. The unit of this metric is bytes. The
224-
histogram buckets are
227+
with [`Deno.serve`](/api/deno/~/Deno.serve) or
228+
[`Deno.serveHttp`](/api/deno/~/Deno.serveHttp). The unit of this metric is
229+
bytes. The histogram buckets are
225230
`[0, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]`.
226231

227232
This metric is recorded with the following attributes:
@@ -240,8 +245,9 @@ This metric is recorded with the following attributes:
240245
##### `http.server.response.body.size`
241246

242247
A histogram of the size of the response body of incoming HTTP requests served
243-
with `Deno.serve` or `Deno.serveHttp`. The unit of this metric is bytes. The
244-
histogram buckets are
248+
with [`Deno.serve`](/api/deno/~/Deno.serve) or
249+
[`Deno.serveHttp`](/api/deno/~/Deno.serveHttp). The unit of this metric is
250+
bytes. The histogram buckets are
245251
`[0, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]`.
246252

247253
This metric is recorded with the following attributes:
@@ -721,9 +727,9 @@ By default, Deno supports the following propagators:
721727

722728
:::note
723729

724-
These propagators automatically work with Deno's `fetch` API and `Deno.serve`,
725-
enabling end-to-end tracing across HTTP requests without manual context
726-
management.
730+
These propagators automatically work with Deno's [`fetch`](/api/web/~/fetch) API
731+
and [`Deno.serve`](/api/deno/~/Deno.serve), enabling end-to-end tracing across
732+
HTTP requests without manual context management.
727733

728734
:::
729735

@@ -778,9 +784,10 @@ limitations to be aware of:
778784
- HTTP methods are that are not known are not normalized to `_OTHER` in the
779785
`http.request.method` span attribute as per the OpenTelemetry semantic
780786
conventions.
781-
- The HTTP server span for `Deno.serve` does not have an OpenTelemetry status
782-
set, and if the handler throws (ie `onError` is invoked), the span will not
783-
have an error status set and the error will not be attached to the span via
784-
event.
787+
- The HTTP server span for [`Deno.serve`](/api/deno/~/Deno.serve) does not have
788+
an OpenTelemetry status set, and if the handler throws (ie `onError` is
789+
invoked), the span will not have an error status set and the error will not be
790+
attached to the span via event.
785791
- There is no mechanism to add a `http.route` attribute to the HTTP client span
786-
for `fetch`, or to update the span name to include the route.
792+
for [`fetch`](/api/web/~/fetch), or to update the span name to include the
793+
route.

runtime/fundamentals/security.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,14 @@ resolves to a sensitive system path, additional permissions are required:
230230
- **`/dev/null`, `/dev/zero`, `/dev/random`, `/dev/urandom`**: These safe device
231231
files are always accessible without additional permissions.
232232

233-
Creating symlinks with `Deno.symlink()` requires both `--allow-read` and
234-
`--allow-write` with full access (not path-specific), because symlinks can point
235-
to arbitrary locations.
233+
Creating symlinks with [`Deno.symlink()`](/api/deno/~/Deno.symlink) requires
234+
both `--allow-read` and `--allow-write` with full access (not path-specific),
235+
because symlinks can point to arbitrary locations.
236236

237237
> **Note**: Symlinks that already exist on the filesystem can be read through
238238
> using the permissions for the symlink's location. The full read/write
239239
> permission requirement only applies to _creating_ new symlinks with
240-
> `Deno.symlink()`.
240+
> [`Deno.symlink()`](/api/deno/~/Deno.symlink).
241241
242242
### Network access
243243

@@ -449,18 +449,21 @@ scripts for npm packages will be executed as a subprocess.
449449
Deno provides an
450450
[FFI mechanism for executing code written in other languages](/runtime/fundamentals/ffi/),
451451
such as Rust, C, or C++, from within a Deno runtime. This is done using the
452-
`Deno.dlopen` API, which can load shared libraries and call functions from them.
452+
[`Deno.dlopen`](/api/deno/~/Deno.dlopen) API, which can load shared libraries
453+
and call functions from them.
453454

454-
By default, executing code can not use the `Deno.dlopen` API, as this would
455-
constitute a violation of the principle that code can not escalate it's
456-
privileges without user consent.
455+
By default, executing code can not use the
456+
[`Deno.dlopen`](/api/deno/~/Deno.dlopen) API, as this would constitute a
457+
violation of the principle that code can not escalate it's privileges without
458+
user consent.
457459

458-
In addition to `Deno.dlopen`, FFI can also be used via Node-API (NAPI) native
459-
addons. These are also not allowed by default.
460+
In addition to [`Deno.dlopen`](/api/deno/~/Deno.dlopen), FFI can also be used
461+
via Node-API (NAPI) native addons. These are also not allowed by default.
460462

461-
Both `Deno.dlopen` and NAPI native addons require explicit permission using the
462-
`--allow-ffi` flag. This flag can be specified with a list of files or
463-
directories to allow access to specific dynamic libraries.
463+
Both [`Deno.dlopen`](/api/deno/~/Deno.dlopen) and NAPI native addons require
464+
explicit permission using the `--allow-ffi` flag. This flag can be specified
465+
with a list of files or directories to allow access to specific dynamic
466+
libraries.
464467

465468
_Like subprocesses, dynamic libraries are not run in a sandbox and therefore do
466469
not have the same security restrictions as the Deno process they are being

0 commit comments

Comments
 (0)