Skip to content

Commit 92594d6

Browse files
committed
lib: enable fetch by default
1 parent dde2f78 commit 92594d6

File tree

8 files changed

+36
-27
lines changed

8 files changed

+36
-27
lines changed

doc/api/cli.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,6 @@ effort to report stack traces relative to the original source file.
280280
Overriding `Error.prepareStackTrace` prevents `--enable-source-maps` from
281281
modifying the stack trace.
282282

283-
### `--experimental-fetch`
284-
285-
<!-- YAML
286-
added: v17.5.0
287-
-->
288-
289-
Enable experimental support for the [Fetch API][].
290-
291283
### `--experimental-global-webcrypto`
292284

293285
<!-- YAML
@@ -333,6 +325,14 @@ added: v11.8.0
333325

334326
Use the specified file as a security policy.
335327

328+
### `--no-experimental-fetch`
329+
330+
<!-- YAML
331+
added: REPLACEME
332+
-->
333+
334+
Disable experimental support for the [Fetch API][].
335+
336336
### `--no-experimental-repl-await`
337337

338338
<!-- YAML
@@ -1587,7 +1587,6 @@ Node.js options that are allowed are:
15871587
* `--enable-fips`
15881588
* `--enable-source-maps`
15891589
* `--experimental-abortcontroller`
1590-
* `--experimental-fetch`
15911590
* `--experimental-global-webcrypto`
15921591
* `--experimental-import-meta-resolve`
15931592
* `--experimental-json-modules`
@@ -1617,6 +1616,7 @@ Node.js options that are allowed are:
16171616
* `--napi-modules`
16181617
* `--no-addons`
16191618
* `--no-deprecation`
1619+
* `--no-experimental-fetch`
16201620
* `--no-experimental-repl-await`
16211621
* `--no-extra-info-on-fatal-exception`
16221622
* `--no-force-async-hooks-checks`

doc/api/globals.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ This variable may appear to be global but is not. See [`exports`][].
384384
added: v17.5.0
385385
-->
386386

387-
> Stability: 1 - Experimental. Enable this API with the [`--experimental-fetch`][]
387+
> Stability: 1 - Experimental. Disable this API with the [`--no-experimental-fetch`][]
388388
> CLI flag.
389389
390390
A browser-compatible implementation of the [`fetch()`][] function.
@@ -395,7 +395,7 @@ A browser-compatible implementation of the [`fetch()`][] function.
395395
added: REPLACEME
396396
-->
397397

398-
> Stability: 1 - Experimental. Enable this API with the [`--experimental-fetch`][]
398+
> Stability: 1 - Experimental. Disable this API with the [`--no-experimental-fetch`][]
399399
> CLI flag.
400400
401401
A browser-compatible implementation of {FormData}.
@@ -421,7 +421,7 @@ Node.js this is different. The top-level scope is not the global scope;
421421
added: v17.5.0
422422
-->
423423

424-
> Stability: 1 - Experimental. Enable this API with the [`--experimental-fetch`][]
424+
> Stability: 1 - Experimental. Disable this API with the [`--no-experimental-fetch`][]
425425
> CLI flag.
426426
427427
A browser-compatible implementation of {Headers}.
@@ -526,7 +526,7 @@ This variable may appear to be global but is not. See [`require()`][].
526526
added: v17.5.0
527527
-->
528528

529-
> Stability: 1 - Experimental. Enable this API with the [`--experimental-fetch`][]
529+
> Stability: 1 - Experimental. Disable this API with the [`--no-experimental-fetch`][]
530530
> CLI flag.
531531
532532
A browser-compatible implementation of {Response}.
@@ -537,7 +537,7 @@ A browser-compatible implementation of {Response}.
537537
added: v17.5.0
538538
-->
539539

540-
> Stability: 1 - Experimental. Enable this API with the [`--experimental-fetch`][]
540+
> Stability: 1 - Experimental. Disable this API with the [`--no-experimental-fetch`][]
541541
> CLI flag.
542542
543543
A browser-compatible implementation of {Request}.
@@ -660,8 +660,8 @@ The object that acts as the namespace for all W3C
660660
[Mozilla Developer Network][webassembly-mdn] for usage and compatibility.
661661

662662
[Web Crypto API]: webcrypto.md
663-
[`--experimental-fetch`]: cli.md#--experimental-fetch
664663
[`--experimental-global-webcrypto`]: cli.md#--experimental-global-webcrypto
664+
[`--no-experimental-fetch`]: cli.md#--no-experimental-fetch
665665
[`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
666666
[`DOMException`]: https://developer.mozilla.org/en-US/docs/Web/API/DOMException
667667
[`EventTarget` and `Event` API]: events.md#eventtarget-and-event-api

doc/node.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ Requires Node.js to be built with
139139
.It Fl -enable-source-maps
140140
Enable Source Map V3 support for stack traces.
141141
.
142-
.It Fl -experimental-fetch
143-
Enable experimental support for the Fetch API.
144-
.
145142
.It Fl -experimental-global-webcrypto
146143
Expose the Web Crypto API on the global scope.
147144
.
@@ -159,6 +156,9 @@ Enable experimental support for loading modules using `import` over `https:`.
159156
.It Fl -experimental-policy
160157
Use the specified file as a security policy.
161158
.
159+
.It Fl -no-experimental-fetch
160+
Disable experimental support for the Fetch API.
161+
.
162162
.It Fl -no-experimental-repl-await
163163
Disable top-level await keyword support in REPL.
164164
.

lib/internal/bootstrap/pre_execution.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,18 @@ function setupWarningHandler() {
152152
// https://fetch.spec.whatwg.org/
153153
function setupFetch() {
154154
if (process.config.variables.node_no_browser_globals ||
155-
!getOptionValue('--experimental-fetch')) {
155+
getOptionValue('--no-experimental-fetch')) {
156156
return;
157157
}
158158

159-
emitExperimentalWarning('Fetch');
160-
161159
const undici = require('internal/deps/undici/undici');
162-
defineOperation(globalThis, 'fetch', undici.fetch);
160+
161+
async function fetch(input, init = undefined) {
162+
emitExperimentalWarning('Fetch');
163+
return undici.fetch(input, init);
164+
}
165+
166+
defineOperation(globalThis, 'fetch', fetch);
163167
exposeInterface(globalThis, 'FormData', undici.FormData);
164168
exposeInterface(globalThis, 'Headers', undici.Headers);
165169
exposeInterface(globalThis, 'Request', undici.Request);

src/node_options.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
318318
AddOption("--experimental-fetch",
319319
"experimental Fetch API",
320320
&EnvironmentOptions::experimental_fetch,
321-
kAllowedInEnvironment);
321+
kAllowedInEnvironment,
322+
true);
322323
AddOption("--experimental-global-webcrypto",
323324
"expose experimental Web Crypto API on the global scope",
324325
&EnvironmentOptions::experimental_global_web_crypto,

src/node_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class EnvironmentOptions : public Options {
107107
std::vector<std::string> conditions;
108108
std::string dns_result_order;
109109
bool enable_source_maps = false;
110-
bool experimental_fetch = false;
110+
bool experimental_fetch = true;
111111
bool experimental_global_web_crypto = false;
112112
bool experimental_https_modules = false;
113113
std::string experimental_specifier_resolution;

test/parallel/test-fetch-disabled.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --no-experimental-fetch
12
import '../common/index.mjs';
23

34
import assert from 'assert';

test/parallel/test-fetch.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Flags: --experimental-fetch --no-warnings
2-
3-
import '../common/index.mjs';
1+
import * as common from '../common/index.mjs';
42

53
import assert from 'assert';
64
import events from 'events';
@@ -12,6 +10,11 @@ assert.strictEqual(typeof globalThis.Headers, 'function');
1210
assert.strictEqual(typeof globalThis.Request, 'function');
1311
assert.strictEqual(typeof globalThis.Response, 'function');
1412

13+
common.expectWarning(
14+
'ExperimentalWarning',
15+
'Fetch is an experimental feature. This feature could change at any time'
16+
);
17+
1518
const server = http.createServer((req, res) => {
1619
// TODO: Remove this once keep-alive behavior can be disabled from the client
1720
// side.

0 commit comments

Comments
 (0)