Skip to content

Commit

Permalink
doc: add dynamic source code links
Browse files Browse the repository at this point in the history
Fixes: #33977

PR-URL: #33996
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
aw-davidson authored and MylesBorins committed Jul 16, 2020
1 parent 2ca6a45 commit eb04ba3
Show file tree
Hide file tree
Showing 42 changed files with 88 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doc/api/assert.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/assert.js -->

The `assert` module provides a set of assertion functions for verifying
invariants.

Expand Down
2 changes: 2 additions & 0 deletions doc/api/async_hooks.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 1 - Experimental
<!-- source_link=lib/async_hooks.js -->

The `async_hooks` module provides an API to track asynchronous resources. It
can be accessed using:

Expand Down
2 changes: 2 additions & 0 deletions doc/api/buffer.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/buffer.js -->

In Node.js, `Buffer` objects are used to represent binary data in the form
of a sequence of bytes. Many Node.js APIs, for example streams and file system
operations, support `Buffer`s, as interactions with the operating system or
Expand Down
2 changes: 2 additions & 0 deletions doc/api/child_process.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/child_process.js -->

The `child_process` module provides the ability to spawn child processes in
a manner that is similar, but not identical, to popen(3). This capability
is primarily provided by the [`child_process.spawn()`][] function:
Expand Down
2 changes: 2 additions & 0 deletions doc/api/cluster.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/cluster.js -->

A single instance of Node.js runs in a single thread. To take advantage of
multi-core systems, the user will sometimes want to launch a cluster of Node.js
processes to handle the load.
Expand Down
2 changes: 2 additions & 0 deletions doc/api/console.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/console.js -->

The `console` module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.

Expand Down
2 changes: 2 additions & 0 deletions doc/api/crypto.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/crypto.js -->

The `crypto` module provides cryptographic functionality that includes a set of
wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.

Expand Down
2 changes: 2 additions & 0 deletions doc/api/dgram.md
Expand Up @@ -6,6 +6,8 @@
<!-- name=dgram -->

<!-- source_link=lib/dgram.js -->

The `dgram` module provides an implementation of UDP datagram sockets.

```js
Expand Down
2 changes: 2 additions & 0 deletions doc/api/dns.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/dns.js -->

The `dns` module enables name resolution. For example, use it to look up IP
addresses of host names.

Expand Down
2 changes: 2 additions & 0 deletions doc/api/domain.md
Expand Up @@ -16,6 +16,8 @@ changes:

> Stability: 0 - Deprecated
<!-- source_link=lib/domain.js -->

**This module is pending deprecation**. Once a replacement API has been
finalized, this module will be fully deprecated. Most end users should
**not** have cause to use this module. Users who absolutely must have
Expand Down
2 changes: 2 additions & 0 deletions doc/api/events.md
Expand Up @@ -6,6 +6,8 @@
<!--type=module-->

<!-- source_link=lib/events.js -->

Much of the Node.js core API is built around an idiomatic asynchronous
event-driven architecture in which certain kinds of objects (called "emitters")
emit named events that cause `Function` objects ("listeners") to be called.
Expand Down
2 changes: 2 additions & 0 deletions doc/api/fs.md
Expand Up @@ -6,6 +6,8 @@
<!--name=fs-->

<!-- source_link=lib/fs.js -->

The `fs` module provides an API for interacting with the file system in a
manner closely modeled around standard POSIX functions.

Expand Down
2 changes: 2 additions & 0 deletions doc/api/http.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/http.js -->

To use the HTTP server and client one must `require('http')`.

The HTTP interfaces in Node.js are designed to support many features
Expand Down
2 changes: 2 additions & 0 deletions doc/api/http2.md
Expand Up @@ -10,6 +10,8 @@ changes:

> Stability: 2 - Stable
<!-- source_link=lib/http2.js -->

The `http2` module provides an implementation of the [HTTP/2][] protocol. It
can be accessed using:

Expand Down
2 changes: 2 additions & 0 deletions doc/api/https.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/https.js -->

HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a
separate module.

Expand Down
2 changes: 2 additions & 0 deletions doc/api/inspector.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 1 - Experimental
<!-- source_link=lib/inspector.js -->

The `inspector` module provides an API for interacting with the V8 inspector.

It can be accessed using:
Expand Down
2 changes: 2 additions & 0 deletions doc/api/net.md
Expand Up @@ -5,6 +5,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/net.js -->

The `net` module provides an asynchronous network API for creating stream-based
TCP or [IPC][] servers ([`net.createServer()`][]) and clients
([`net.createConnection()`][]).
Expand Down
2 changes: 2 additions & 0 deletions doc/api/os.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/os.js -->

The `os` module provides operating system-related utility methods and
properties. It can be accessed using:

Expand Down
2 changes: 2 additions & 0 deletions doc/api/path.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/path.js -->

The `path` module provides utilities for working with file and directory paths.
It can be accessed using:

Expand Down
2 changes: 2 additions & 0 deletions doc/api/perf_hooks.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/perf_hooks.js -->

This module provides an implementation of a subset of the W3C
[Web Performance APIs][] as well as additional APIs for
Node.js-specific performance measurements.
Expand Down
2 changes: 2 additions & 0 deletions doc/api/process.md
Expand Up @@ -3,6 +3,8 @@
<!-- introduced_in=v0.10.0 -->
<!-- type=global -->

<!-- source_link=lib/process.js -->

The `process` object is a `global` that provides information about, and control
over, the current Node.js process. As a global, it is always available to
Node.js applications without using `require()`. It can also be explicitly
Expand Down
2 changes: 2 additions & 0 deletions doc/api/punycode.md
Expand Up @@ -10,6 +10,8 @@ changes:

> Stability: 0 - Deprecated
<!-- source_link=lib/punycode.js -->

**The version of the punycode module bundled in Node.js is being deprecated**.
In a future major version of Node.js this module will be removed. Users
currently depending on the `punycode` module should switch to using the
Expand Down
2 changes: 2 additions & 0 deletions doc/api/querystring.md
Expand Up @@ -6,6 +6,8 @@
<!--name=querystring-->

<!-- source_link=lib/querystring.js -->

The `querystring` module provides utilities for parsing and formatting URL
query strings. It can be accessed using:

Expand Down
2 changes: 2 additions & 0 deletions doc/api/readline.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/readline.js -->

The `readline` module provides an interface for reading data from a [Readable][]
stream (such as [`process.stdin`][]) one line at a time. It can be accessed
using:
Expand Down
2 changes: 2 additions & 0 deletions doc/api/repl.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/repl.js -->

The `repl` module provides a Read-Eval-Print-Loop (REPL) implementation that
is available both as a standalone program or includible in other applications.
It can be accessed using:
Expand Down
2 changes: 2 additions & 0 deletions doc/api/stream.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable

<!-- source_link=lib/stream.js -->

A stream is an abstract interface for working with streaming data in Node.js.
The `stream` module provides an API for implementing the stream interface.

Expand Down
2 changes: 2 additions & 0 deletions doc/api/string_decoder.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/string_decoder.js -->

The `string_decoder` module provides an API for decoding `Buffer` objects into
strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16
characters. It can be accessed using:
Expand Down
2 changes: 2 additions & 0 deletions doc/api/timers.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/timers.js -->

The `timer` module exposes a global API for scheduling functions to
be called at some future period of time. Because the timer functions are
globals, there is no need to call `require('timers')` to use the API.
Expand Down
2 changes: 2 additions & 0 deletions doc/api/tls.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable

<!-- source_link=lib/tls.js -->

The `tls` module provides an implementation of the Transport Layer Security
(TLS) and Secure Socket Layer (SSL) protocols that is built on top of OpenSSL.
The module can be accessed using:
Expand Down
2 changes: 2 additions & 0 deletions doc/api/tracing.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 1 - Experimental

<!-- source_link=lib/trace_events.js -->

The `trace_events` module provides a mechanism to centralize tracing information
generated by V8, Node.js core, and userspace code.

Expand Down
2 changes: 2 additions & 0 deletions doc/api/tty.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable

<!-- source_link=lib/tty.js -->

The `tty` module provides the `tty.ReadStream` and `tty.WriteStream` classes.
In most cases, it will not be necessary or possible to use this module directly.
However, it can be accessed using:
Expand Down
2 changes: 2 additions & 0 deletions doc/api/url.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable

<!-- source_link=lib/url.js -->

The `url` module provides utilities for URL resolution and parsing. It can be
accessed using:

Expand Down
2 changes: 2 additions & 0 deletions doc/api/util.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable

<!-- source_link=lib/util.js -->

The `util` module supports the needs of Node.js internal APIs. Many of the
utilities are useful for application and module developers as well. To access
it:
Expand Down
2 changes: 2 additions & 0 deletions doc/api/v8.md
Expand Up @@ -2,6 +2,8 @@

<!--introduced_in=v4.0.0-->

<!-- source_link=lib/v8.js -->

The `v8` module exposes APIs that are specific to the version of [V8][]
built into the Node.js binary. It can be accessed using:

Expand Down
2 changes: 2 additions & 0 deletions doc/api/vm.md
Expand Up @@ -6,6 +6,8 @@

<!--name=vm-->

<!-- source_link=lib/vm.js -->

The `vm` module enables compiling and running code within V8 Virtual
Machine contexts. **The `vm` module is not a security mechanism. Do
not use it to run untrusted code**.
Expand Down
2 changes: 2 additions & 0 deletions doc/api/wasi.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 1 - Experimental

<!-- source_link=lib/wasi.js -->

The WASI API provides an implementation of the [WebAssembly System Interface][]
specification. WASI gives sandboxed WebAssembly applications access to the
underlying operating system via a collection of POSIX-like functions.
Expand Down
2 changes: 2 additions & 0 deletions doc/api/worker_threads.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable

<!-- source_link=lib/worker_threads.js -->

The `worker_threads` module enables the use of threads that execute JavaScript
in parallel. To access it:

Expand Down
2 changes: 2 additions & 0 deletions doc/api/zlib.md
Expand Up @@ -4,6 +4,8 @@

> Stability: 2 - Stable
<!-- source_link=lib/zlib.js -->

The `zlib` module provides compression functionality implemented using Gzip,
Deflate/Inflate, and Brotli.

Expand Down
2 changes: 1 addition & 1 deletion test/doctool/test-doctool-html.js
Expand Up @@ -41,7 +41,7 @@ function toHTML({ input, filename, nodeVersion, versions }) {
.use(replaceLinks, { filename, linksMapper: testLinksMapper })
.use(markdown)
.use(html.firstHeader)
.use(html.preprocessText)
.use(html.preprocessText, { nodeVersion })
.use(html.preprocessElements, { filename })
.use(html.buildToc, { filename, apilinks: {} })
.use(remark2rehype, { allowDangerousHTML: true })
Expand Down
6 changes: 5 additions & 1 deletion tools/doc/common.js
Expand Up @@ -7,6 +7,10 @@ function isYAMLBlock(text) {
return /^<!-- YAML/.test(text);
}

function isSourceLink(text) {
return /^<!-- source_link=([^\s/]+\/)+\w+\.\w+ -->/.test(text);
}

function arrify(value) {
return Array.isArray(value) ? value : [value];
}
Expand Down Expand Up @@ -43,4 +47,4 @@ function extractAndParseYAML(text) {
return meta;
}

module.exports = { arrify, isYAMLBlock, extractAndParseYAML };
module.exports = { arrify, isYAMLBlock, isSourceLink, extractAndParseYAML };
2 changes: 1 addition & 1 deletion tools/doc/generate.js
Expand Up @@ -82,7 +82,7 @@ async function main() {
const content = await unified()
.use(replaceLinks, { filename, linksMapper })
.use(markdown)
.use(html.preprocessText)
.use(html.preprocessText, { nodeVersion })
.use(json.jsonAPI, { filename })
.use(html.firstHeader)
.use(html.preprocessElements, { filename })
Expand Down
7 changes: 5 additions & 2 deletions tools/doc/html.js
Expand Up @@ -104,10 +104,13 @@ function firstHeader() {

// Handle general body-text replacements.
// For example, link man page references to the actual page.
function preprocessText() {
function preprocessText({ nodeVersion }) {
return (tree) => {
visit(tree, null, (node) => {
if (node.type === 'text' && node.value) {
if (common.isSourceLink(node.value)) {
const [path] = node.value.match(/(?<=<!-- source_link=).*(?= -->)/);
node.value = `<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/${nodeVersion}/${path}">${path}</a></p>`;
} else if (node.type === 'text' && node.value) {
const value = linkJsTypeDocs(linkManPages(node.value));
if (value !== node.value) {
node.type = 'html';
Expand Down

0 comments on commit eb04ba3

Please sign in to comment.