Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
d48b522
doc: fix module.md headings
legendecas Dec 6, 2024
f1c2d2f
doc: update blog release-post link
ruyadorno Dec 6, 2024
a4a8361
stream: commit pull-into descriptors after filling from queue
MattiasBuelens Nov 27, 2024
041a490
test: update streams wpt
MattiasBuelens Nov 28, 2024
5aec513
lib: disable default memory leak warning for AbortSignal
phryneas Dec 7, 2024
c2fb38c
crypto: graduate WebCryptoAPI Ed25519 and X25519 algorithms as stable
panva Dec 5, 2024
a6f0cfa
sea: only assert snapshot main function for main threads
joyeecheung Dec 7, 2024
889094f
lib: handle Float16Array in node:v8 serdes
bartlomieju Dec 7, 2024
08e5309
Revert "build: avoid compiling with VS v17.12"
Flarna Dec 7, 2024
84f98e0
v8,tools: expose experimental wasm revectorize feature
yolanda15 Dec 7, 2024
fd55d3c
lib: clean up persisted signals when they are settled
geeksilva97 Dec 8, 2024
5620b2b
tools: improve release proposal PR opening
aduh95 Dec 8, 2024
cfbdff7
assert: make partialDeepStrictEqual work with ArrayBuffers
Dec 8, 2024
fcaa2c8
build: fix GN build on macOS
joyeecheung Dec 9, 2024
efcc829
tools: bump the eslint group in /tools/eslint with 4 updates
dependabot[bot] Dec 9, 2024
e20eef6
tools: update gyp-next to 0.19.0
nodejs-github-bot Dec 9, 2024
a0e3926
test: remove `hasOpenSSL3x` utils
aduh95 Dec 9, 2024
28a4b6f
tools: use commit title as PR title when creating release proposal
aduh95 Dec 9, 2024
114a3e5
doc: fix c++ addon hello world sample
geeksilva97 Dec 9, 2024
65b541e
tools: enable linter for `tools/icu/**`
LiviaMedeiros Dec 9, 2024
e5bb6c2
module: implement module.registerHooks()
joyeecheung Oct 29, 2024
8e780bc
module: use synchronous hooks for preparsing in import(cjs)
joyeecheung Nov 2, 2024
a0c4a5f
test: update WPT for url to 6fa3fe8a92
nodejs-github-bot Dec 10, 2024
54308c5
deps: update sqlite to 3.47.2
nodejs-github-bot Dec 10, 2024
fa667d6
tools: remove has_absl_stringify from gyp file
targos Dec 10, 2024
f10239f
lib: remove redundant global regexps
gurgunday Dec 10, 2024
595851b
fs,win: fix readdir for named pipe
huseyinacacak-janea Dec 10, 2024
e4922ab
doc: fix incorrect link to style guide
technic960183 Dec 10, 2024
a9e6728
doc: add ambassador message - benefits of Node.js
mhdawson Nov 29, 2024
683cc15
test: move localizationd data from `test-icu-env` to external file
LiviaMedeiros Dec 10, 2024
5665e86
module: prevent main thread exiting before esm worker ends
islandryu Dec 10, 2024
f3b3ff8
doc: call out import.meta is only supported in ES modules
antonk52 Dec 11, 2024
77397c5
util: do not rely on mutable `Object` and `Function`' `constructor` prop
aduh95 Dec 11, 2024
b0ebd23
http2: support ALPNCallback option
ZYSzys Dec 11, 2024
8325fa5
worker: fix crash when a worker joins after exit
Qard Dec 11, 2024
9863d27
module: only emit require(esm) warning under --trace-require-module
joyeecheung Dec 9, 2024
2314e49
assert: make Maps be partially compared in partialDeepStrictEqual
Dec 11, 2024
6f49c80
build: use variable for simdutf path
codebytere Dec 11, 2024
53cc0cc
sqlite: support `db.loadExtension`
himself65 Dec 3, 2024
3968599
src: fix outdated js2c.cc references
legendecas Dec 11, 2024
2974667
doc: update blog link to /vulnerability
RafaelGSS Dec 11, 2024
8092dcf
doc: update announce documentation for releases
RafaelGSS Dec 11, 2024
a5aaf31
tools: fix release proposal linter to support more than 1 folk preparing
aduh95 Dec 12, 2024
7b2a6ee
doc: `sea.getRawAsset(key)` always returns an ArrayBuffer
ShenHongFei Dec 12, 2024
efcc5d9
src,lib: stabilize permission model
RafaelGSS Dec 12, 2024
febd969
http2: remove duplicate codeblock
AVVS Dec 12, 2024
075b36b
http: add setDefaultHeaders option to http.request
pimterry Dec 12, 2024
4745798
sqlite: add support for custom functions
cjihrig Dec 12, 2024
b395e0c
tools: update gyp-next to 0.19.1
addaleax Dec 10, 2024
f4faedf
build: fix C string encoding for `PRODUCT_DIR_ABS`
addaleax Dec 2, 2024
8288f57
test: fix test-abortsignal-drop-settled-signals flakiness
geeksilva97 Dec 12, 2024
8d485f1
fs: make mutating `options` in Promises `readdir()` not affect results
LiviaMedeiros Nov 28, 2024
4cc0493
fs: make mutating `options` in Callback `readdir()` not affect results
LiviaMedeiros Dec 7, 2024
394fffb
doc: add esm examples to node:perf_hooks
mfdebian Dec 12, 2024
5d252b7
test: remove exludes for sea tests on PPC
mhdawson Dec 12, 2024
d25d16e
Revert "tools: disable automated libuv updates"
lpinca Dec 13, 2024
65bc8e8
report: fix typos in report keys and bump the version
technic960183 Dec 13, 2024
f883bed
node-api: allow napi_delete_reference in finalizers
legendecas Dec 13, 2024
71c38a2
doc: add esm examples to node:tls
mfdebian Dec 13, 2024
002ee71
tools: use `github.actor` instead of bot username for release proposals
aduh95 Dec 13, 2024
c5b0862
doc: fix winget config path
himself65 Dec 13, 2024
b5a2c07
module: add prefix-only modules to `module.builtinModules`
ljharb Dec 14, 2024
cc7a7c3
doc: fix 'which' to 'that' and add commas
selveter Dec 14, 2024
1d8cc61
test: use --permission over --experimental-permission
RafaelGSS Dec 14, 2024
1381541
util: fix Latin1 decoding to return string output
mertcanaltin Dec 14, 2024
7a10ef8
doc: add esm examples to node:readline
mfdebian Dec 14, 2024
f94f210
doc: add esm examples to node:repl
mfdebian Dec 14, 2024
59cae91
dgram: support blocklist in udp
theanarkh Dec 15, 2024
f264dd6
buffer: document concat zero-fill
duncpro Dec 15, 2024
0d08756
doc: clarify util.aborted resource usage
KunalKumar-1 Dec 15, 2024
25bb462
deps: define V8_PRESERVE_MOST as no-op on Windows
StefanStojanovic Dec 16, 2024
3e17a8e
util: harden more built-in classes against prototype pollution
aduh95 Dec 16, 2024
445c8c7
build: add major release action
RafaelGSS Dec 16, 2024
db6aba1
deps: update c-ares to v1.34.4
nodejs-github-bot Dec 17, 2024
78743b1
tools: add REPLACEME check to workflow
mertcanaltin Dec 17, 2024
ea9a675
test_runner: exclude test files from coverage by default
pmarchini Dec 17, 2024
3298ef4
test: remove test-sqlite-statement-sync flaky designation
lpinca Dec 17, 2024
4e9113e
deps: update libuv to 1.49.2
lpinca Dec 17, 2024
7c941d4
deps: update simdutf to 5.6.4
nodejs-github-bot Dec 17, 2024
8658833
deps: update nghttp3 to 1.6.0
nodejs-github-bot Dec 17, 2024
c4c56da
tools: update github_reporter to 1.7.2
nodejs-github-bot Dec 17, 2024
118cd99
tools: fix `node:` enforcement for docs
aduh95 Dec 17, 2024
0ab36e1
sqlite: aggregate constants in a single property
geeksilva97 Dec 17, 2024
72f79b4
doc: stabilize util.styleText
RafaelGSS Dec 17, 2024
1497bb4
build: fix missing fp16 dependency in d8 builds
joyeecheung Dec 17, 2024
4831b87
build: set DESTCPU correctly for 'make binary' on loongarch64
wojiushixiaobai Dec 18, 2024
52c18e6
doc: fix color contrast issue in light mode
Trott Dec 18, 2024
d8c3089
2024-12-19, Version 23.5.0 (Current)
aduh95 Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
doc: fix module.md headings
PR-URL: #56131
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
  • Loading branch information
legendecas authored and aduh95 committed Dec 10, 2024
commit d48b5224c09f0791fa89985e38eb574b2b43f280
338 changes: 169 additions & 169 deletions doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,159 +64,6 @@ const require = createRequire(import.meta.url);
const siblingModule = require('./sibling-module');
```

### `module.constants.compileCacheStatus`

<!-- YAML
added: v22.8.0
-->

> Stability: 1.1 - Active Development

The following constants are returned as the `status` field in the object returned by
[`module.enableCompileCache()`][] to indicate the result of the attempt to enable the
[module compile cache][].

<table>
<tr>
<th>Constant</th>
<th>Description</th>
</tr>
<tr>
<td><code>ENABLED</code></td>
<td>
Node.js has enabled the compile cache successfully. The directory used to store the
compile cache will be returned in the <code>directory</code> field in the
returned object.
</td>
</tr>
<tr>
<td><code>ALREADY_ENABLED</code></td>
<td>
The compile cache has already been enabled before, either by a previous call to
<code>module.enableCompileCache()</code>, or by the <code>NODE_COMPILE_CACHE=dir</code>
environment variable. The directory used to store the
compile cache will be returned in the <code>directory</code> field in the
returned object.
</td>
</tr>
<tr>
<td><code>FAILED</code></td>
<td>
Node.js fails to enable the compile cache. This can be caused by the lack of
permission to use the specified directory, or various kinds of file system errors.
The detail of the failure will be returned in the <code>message</code> field in the
returned object.
</td>
</tr>
<tr>
<td><code>DISABLED</code></td>
<td>
Node.js cannot enable the compile cache because the environment variable
<code>NODE_DISABLE_COMPILE_CACHE=1</code> has been set.
</td>
</tr>
</table>

### `module.enableCompileCache([cacheDir])`

<!-- YAML
added: v22.8.0
-->

> Stability: 1.1 - Active Development

* `cacheDir` {string|undefined} Optional path to specify the directory where the compile cache
will be stored/retrieved.
* Returns: {Object}
* `status` {integer} One of the [`module.constants.compileCacheStatus`][]
* `message` {string|undefined} If Node.js cannot enable the compile cache, this contains
the error message. Only set if `status` is `module.constants.compileCacheStatus.FAILED`.
* `directory` {string|undefined} If the compile cache is enabled, this contains the directory
where the compile cache is stored. Only set if `status` is
`module.constants.compileCacheStatus.ENABLED` or
`module.constants.compileCacheStatus.ALREADY_ENABLED`.

Enable [module compile cache][] in the current Node.js instance.

If `cacheDir` is not specified, Node.js will either use the directory specified by the
[`NODE_COMPILE_CACHE=dir`][] environment variable if it's set, or use
`path.join(os.tmpdir(), 'node-compile-cache')` otherwise. For general use cases, it's
recommended to call `module.enableCompileCache()` without specifying the `cacheDir`,
so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment
variable when necessary.

Since compile cache is supposed to be a quiet optimization that is not required for the
application to be functional, this method is designed to not throw any exception when the
compile cache cannot be enabled. Instead, it will return an object containing an error
message in the `message` field to aid debugging.
If compile cache is enabled successfully, the `directory` field in the returned object
contains the path to the directory where the compile cache is stored. The `status`
field in the returned object would be one of the `module.constants.compileCacheStatus`
values to indicate the result of the attempt to enable the [module compile cache][].

This method only affects the current Node.js instance. To enable it in child worker threads,
either call this method in child worker threads too, or set the
`process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can
be inherited into the child workers. The directory can be obtained either from the
`directory` field returned by this method, or with [`module.getCompileCacheDir()`][].

#### Module compile cache

<!-- YAML
added: v22.1.0
changes:
- version: v22.8.0
pr-url: https://github.com/nodejs/node/pull/54501
description: add initial JavaScript APIs for runtime access.
-->

The module compile cache can be enabled either using the [`module.enableCompileCache()`][]
method or the [`NODE_COMPILE_CACHE=dir`][] environment variable. After it is enabled,
whenever Node.js compiles a CommonJS or a ECMAScript Module, it will use on-disk
[V8 code cache][] persisted in the specified directory to speed up the compilation.
This may slow down the first load of a module graph, but subsequent loads of the same module
graph may get a significant speedup if the contents of the modules do not change.

To clean up the generated compile cache on disk, simply remove the cache directory. The cache
directory will be recreated the next time the same directory is used for for compile cache
storage. To avoid filling up the disk with stale cache, it is recommended to use a directory
under the [`os.tmpdir()`][]. If the compile cache is enabled by a call to
[`module.enableCompileCache()`][] without specifying the directory, Node.js will use
the [`NODE_COMPILE_CACHE=dir`][] environment variable if it's set, or defaults
to `path.join(os.tmpdir(), 'node-compile-cache')` otherwise. To locate the compile cache
directory used by a running Node.js instance, use [`module.getCompileCacheDir()`][].

Currently when using the compile cache with [V8 JavaScript code coverage][], the
coverage being collected by V8 may be less precise in functions that are
deserialized from the code cache. It's recommended to turn this off when
running tests to generate precise coverage.

The enabled module compile cache can be disabled by the [`NODE_DISABLE_COMPILE_CACHE=1`][]
environment variable. This can be useful when the compile cache leads to unexpected or
undesired behaviors (e.g. less precise test coverage).

Compilation cache generated by one version of Node.js can not be reused by a different
version of Node.js. Cache generated by different versions of Node.js will be stored
separately if the same base directory is used to persist the cache, so they can co-exist.

At the moment, when the compile cache is enabled and a module is loaded afresh, the
code cache is generated from the compiled code immediately, but will only be written
to disk when the Node.js instance is about to exit. This is subject to change. The
[`module.flushCompileCache()`][] method can be used to ensure the accumulated code cache
is flushed to disk in case the application wants to spawn other Node.js instances
and let them share the cache long before the parent exits.

### `module.getCompileCacheDir()`

<!-- YAML
added: v22.8.0
-->

> Stability: 1.1 - Active Development

* Returns: {string|undefined} Path to the [module compile cache][] directory if it is enabled,
or `undefined` otherwise.

### `module.findPackageJSON(specifier[, base])`

<!-- YAML
Expand Down Expand Up @@ -352,7 +199,7 @@ changes:
Register a module that exports [hooks][] that customize Node.js module
resolution and loading behavior. See [Customization hooks][].

## `module.stripTypeScriptTypes(code[, options])`
### `module.stripTypeScriptTypes(code[, options])`

<!-- YAML
added: v23.2.0
Expand Down Expand Up @@ -490,6 +337,174 @@ import('node:fs').then((esmFS) => {
});
```

## Module compile cache

<!-- YAML
added: v22.1.0
changes:
- version: v22.8.0
pr-url: https://github.com/nodejs/node/pull/54501
description: add initial JavaScript APIs for runtime access.
-->

The module compile cache can be enabled either using the [`module.enableCompileCache()`][]
method or the [`NODE_COMPILE_CACHE=dir`][] environment variable. After it is enabled,
whenever Node.js compiles a CommonJS or a ECMAScript Module, it will use on-disk
[V8 code cache][] persisted in the specified directory to speed up the compilation.
This may slow down the first load of a module graph, but subsequent loads of the same module
graph may get a significant speedup if the contents of the modules do not change.

To clean up the generated compile cache on disk, simply remove the cache directory. The cache
directory will be recreated the next time the same directory is used for for compile cache
storage. To avoid filling up the disk with stale cache, it is recommended to use a directory
under the [`os.tmpdir()`][]. If the compile cache is enabled by a call to
[`module.enableCompileCache()`][] without specifying the directory, Node.js will use
the [`NODE_COMPILE_CACHE=dir`][] environment variable if it's set, or defaults
to `path.join(os.tmpdir(), 'node-compile-cache')` otherwise. To locate the compile cache
directory used by a running Node.js instance, use [`module.getCompileCacheDir()`][].

Currently when using the compile cache with [V8 JavaScript code coverage][], the
coverage being collected by V8 may be less precise in functions that are
deserialized from the code cache. It's recommended to turn this off when
running tests to generate precise coverage.

The enabled module compile cache can be disabled by the [`NODE_DISABLE_COMPILE_CACHE=1`][]
environment variable. This can be useful when the compile cache leads to unexpected or
undesired behaviors (e.g. less precise test coverage).

Compilation cache generated by one version of Node.js can not be reused by a different
version of Node.js. Cache generated by different versions of Node.js will be stored
separately if the same base directory is used to persist the cache, so they can co-exist.

At the moment, when the compile cache is enabled and a module is loaded afresh, the
code cache is generated from the compiled code immediately, but will only be written
to disk when the Node.js instance is about to exit. This is subject to change. The
[`module.flushCompileCache()`][] method can be used to ensure the accumulated code cache
is flushed to disk in case the application wants to spawn other Node.js instances
and let them share the cache long before the parent exits.

### `module.constants.compileCacheStatus`

<!-- YAML
added: v22.8.0
-->

> Stability: 1.1 - Active Development

The following constants are returned as the `status` field in the object returned by
[`module.enableCompileCache()`][] to indicate the result of the attempt to enable the
[module compile cache][].

<table>
<tr>
<th>Constant</th>
<th>Description</th>
</tr>
<tr>
<td><code>ENABLED</code></td>
<td>
Node.js has enabled the compile cache successfully. The directory used to store the
compile cache will be returned in the <code>directory</code> field in the
returned object.
</td>
</tr>
<tr>
<td><code>ALREADY_ENABLED</code></td>
<td>
The compile cache has already been enabled before, either by a previous call to
<code>module.enableCompileCache()</code>, or by the <code>NODE_COMPILE_CACHE=dir</code>
environment variable. The directory used to store the
compile cache will be returned in the <code>directory</code> field in the
returned object.
</td>
</tr>
<tr>
<td><code>FAILED</code></td>
<td>
Node.js fails to enable the compile cache. This can be caused by the lack of
permission to use the specified directory, or various kinds of file system errors.
The detail of the failure will be returned in the <code>message</code> field in the
returned object.
</td>
</tr>
<tr>
<td><code>DISABLED</code></td>
<td>
Node.js cannot enable the compile cache because the environment variable
<code>NODE_DISABLE_COMPILE_CACHE=1</code> has been set.
</td>
</tr>
</table>

### `module.enableCompileCache([cacheDir])`

<!-- YAML
added: v22.8.0
-->

> Stability: 1.1 - Active Development

* `cacheDir` {string|undefined} Optional path to specify the directory where the compile cache
will be stored/retrieved.
* Returns: {Object}
* `status` {integer} One of the [`module.constants.compileCacheStatus`][]
* `message` {string|undefined} If Node.js cannot enable the compile cache, this contains
the error message. Only set if `status` is `module.constants.compileCacheStatus.FAILED`.
* `directory` {string|undefined} If the compile cache is enabled, this contains the directory
where the compile cache is stored. Only set if `status` is
`module.constants.compileCacheStatus.ENABLED` or
`module.constants.compileCacheStatus.ALREADY_ENABLED`.

Enable [module compile cache][] in the current Node.js instance.

If `cacheDir` is not specified, Node.js will either use the directory specified by the
[`NODE_COMPILE_CACHE=dir`][] environment variable if it's set, or use
`path.join(os.tmpdir(), 'node-compile-cache')` otherwise. For general use cases, it's
recommended to call `module.enableCompileCache()` without specifying the `cacheDir`,
so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment
variable when necessary.

Since compile cache is supposed to be a quiet optimization that is not required for the
application to be functional, this method is designed to not throw any exception when the
compile cache cannot be enabled. Instead, it will return an object containing an error
message in the `message` field to aid debugging.
If compile cache is enabled successfully, the `directory` field in the returned object
contains the path to the directory where the compile cache is stored. The `status`
field in the returned object would be one of the `module.constants.compileCacheStatus`
values to indicate the result of the attempt to enable the [module compile cache][].

This method only affects the current Node.js instance. To enable it in child worker threads,
either call this method in child worker threads too, or set the
`process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can
be inherited into the child workers. The directory can be obtained either from the
`directory` field returned by this method, or with [`module.getCompileCacheDir()`][].

### `module.flushCompileCache()`

<!-- YAML
added:
- v23.0.0
-->

> Stability: 1.1 - Active Development

Flush the [module compile cache][] accumulated from modules already loaded
in the current Node.js instance to disk. This returns after all the flushing
file system operations come to an end, no matter they succeed or not. If there
are any errors, this will fail silently, since compile cache misses should not
interfere with the actual operation of the application.

### `module.getCompileCacheDir()`

<!-- YAML
added: v22.8.0
-->

> Stability: 1.1 - Active Development

* Returns: {string|undefined} Path to the [module compile cache][] directory if it is enabled,
or `undefined` otherwise.

<i id="module_customization_hooks"></i>

## Customization Hooks
Expand Down Expand Up @@ -1285,21 +1300,6 @@ added:
`path` is the resolved path for the file for which a corresponding source map
should be fetched.

### `module.flushCompileCache()`

<!-- YAML
added:
- v23.0.0
-->

> Stability: 1.1 - Active Development

Flush the [module compile cache][] accumulated from modules already loaded
in the current Node.js instance to disk. This returns after all the flushing
file system operations come to an end, no matter they succeed or not. If there
are any errors, this will fail silently, since compile cache misses should not
interfere with the actual operation of the application.

### Class: `module.SourceMap`

<!-- YAML
Expand Down