Skip to content

Commit 6af362e

Browse files
committed
stream: gate stream/iter behind --experimental-stream-iter
Add the `--experimental-stream-iter`` CLI flag to gate access to the `node:stream/iter` module. When the flag is not specified, attempting to import the module will throw `ERR_UNKNOWN_BUILTIN_MODULE`. The module is added to the `experimentalModuleList` in `realm.js` and to the `cannot_be_required` set in `node_builtins.cc`. A setup function in `pre_execution.js` enables access at runtime when the flag is present. An experimental warning is emitted on first load. The module is accessible both with and without the node: prefix when the flag is enabled.
1 parent 42da7ad commit 6af362e

22 files changed

+88
-5
lines changed

benchmark/fs/bench-filehandle-pull-vs-webstream.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --experimental-stream-iter
12
// Compare FileHandle.createReadStream() vs readableWebStream() vs pull()
23
// reading a large file through two transforms: uppercase then gzip compress.
34
'use strict';

doc/api/cli.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,16 @@ added:
12771277
12781278
Enable experimental support for storage inspection
12791279

1280+
### `--experimental-stream-iter`
1281+
1282+
<!-- YAML
1283+
added: REPLACEME
1284+
-->
1285+
1286+
> Stability: 1 - Experimental
1287+
1288+
Enable the experimental [`node:stream/iter`][] module.
1289+
12801290
### `--experimental-test-coverage`
12811291

12821292
<!-- YAML
@@ -3612,6 +3622,7 @@ one is included in the list below.
36123622
* `--experimental-require-module`
36133623
* `--experimental-shadow-realm`
36143624
* `--experimental-specifier-resolution`
3625+
* `--experimental-stream-iter`
36153626
* `--experimental-test-isolation`
36163627
* `--experimental-top-level-await`
36173628
* `--experimental-vm-modules`
@@ -4251,6 +4262,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
42514262
[`import` specifier]: esm.md#import-specifiers
42524263
[`net.getDefaultAutoSelectFamilyAttemptTimeout()`]: net.md#netgetdefaultautoselectfamilyattempttimeout
42534264
[`node:sqlite`]: sqlite.md
4265+
[`node:stream/iter`]: stream_iter.md
42544266
[`process.setUncaughtExceptionCaptureCallback()`]: process.md#processsetuncaughtexceptioncapturecallbackfn
42554267
[`tls.DEFAULT_MAX_VERSION`]: tls.md#tlsdefault_max_version
42564268
[`tls.DEFAULT_MIN_VERSION`]: tls.md#tlsdefault_min_version

doc/api/stream_iter.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# Stream (new)
1+
# Iterable Streams
22

33
<!--introduced_in=REPLACEME-->
44

55
> Stability: 1 - Experimental
66
77
<!-- source_link=lib/stream/iter.js -->
88

9-
The `node:stream/iter` module provides a new streaming API built on iterables
10-
rather than the event-driven `Readable`/`Writable`/`Transform` class hierarchy.
9+
The `node:stream/iter` module provides a streaming API built on iterables
10+
rather than the event-driven `Readable`/`Writable`/`Transform` class hierarchy,
11+
or the Web Streams `ReadableStream`/`WritableStream`/`TransformStream` interfaces.
12+
13+
This module is available only when the `--experimental-stream-iter` CLI flag
14+
is enabled.
1115

1216
Streams are represented as `AsyncIterable<Uint8Array[]>` (async) or
1317
`Iterable<Uint8Array[]>` (sync). There are no base classes to extend -- any

doc/node.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ top-level awaits, and print their location to help users find them.
720720
.It Fl -experimental-quic
721721
Enable experimental support for the QUIC protocol.
722722
.
723+
.It Fl -experimental-stream-iter
724+
Enable the experimental
725+
.Sy node:stream/iter
726+
module.
727+
.
723728
.It Fl -experimental-sea-config
724729
Use this flag to generate a blob that can be injected into the Node.js
725730
binary to produce a single executable application. See the documentation

lib/internal/bootstrap/realm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const schemelessBlockList = new SafeSet([
131131
'test/reporters',
132132
]);
133133
// Modules that will only be enabled at run time.
134-
const experimentalModuleList = new SafeSet(['sqlite', 'quic']);
134+
const experimentalModuleList = new SafeSet(['sqlite', 'quic', 'stream/iter']);
135135

136136
// Set up process.binding() and process._linkedBinding().
137137
{

lib/internal/process/pre_execution.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function prepareExecution(options) {
115115
setupNavigator();
116116
setupWarningHandler();
117117
setupSQLite();
118+
setupStreamIter();
118119
setupQuic();
119120
setupWebStorage();
120121
setupWebsocket();
@@ -392,6 +393,15 @@ function initializeConfigFileSupport() {
392393
}
393394
}
394395

396+
function setupStreamIter() {
397+
if (!getOptionValue('--experimental-stream-iter')) {
398+
return;
399+
}
400+
401+
const { BuiltinModule } = require('internal/bootstrap/realm');
402+
BuiltinModule.allowRequireByUsers('stream/iter');
403+
}
404+
395405
function setupQuic() {
396406
if (!getOptionValue('--experimental-quic')) {
397407
return;

lib/stream/iter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
'use strict';
22

3-
// Public entry point for the new streams API.
3+
// Public entry point for the iterable streams API.
44
// Usage: require('stream/iter') or require('node:stream/iter')
5+
// Requires: --experimental-stream-iter
56

67
const {
78
ObjectFreeze,
89
} = primordials;
910

11+
const { emitExperimentalWarning } = require('internal/util');
12+
emitExperimentalWarning('stream/iter');
13+
1014
// Protocol symbols
1115
const {
1216
toStreamable,

src/node_builtins.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
141141
#endif // !OPENSSL_NO_QUIC
142142
"quic", // Experimental.
143143
"sqlite", // Experimental.
144+
"stream/iter", // Experimental.
144145
"sys", // Deprecated.
145146
"wasi", // Experimental.
146147
#if !HAVE_SQLITE

src/node_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
599599
&EnvironmentOptions::experimental_sqlite,
600600
kAllowedInEnvvar,
601601
true);
602+
AddOption("--experimental-stream-iter",
603+
"experimental iterable streams API (node:stream/iter)",
604+
&EnvironmentOptions::experimental_stream_iter,
605+
kAllowedInEnvvar);
602606
AddOption("--experimental-quic",
603607
#ifndef OPENSSL_NO_QUIC
604608
"experimental QUIC support",

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class EnvironmentOptions : public Options {
127127
bool experimental_fetch = true;
128128
bool experimental_websocket = true;
129129
bool experimental_sqlite = true;
130+
bool experimental_stream_iter = false;
130131
bool webstorage = HAVE_SQLITE;
131132
#ifndef OPENSSL_NO_QUIC
132133
bool experimental_quic = false;

0 commit comments

Comments
 (0)