@whatwg-node/node-fetch 0.7.15-alpha-20250321162456-ed61b3d110e199e98204f2d2867357b5f82b1aa3 → 0.7.15-alpha-20250322121446-0a8732f1758546d618a797e18a1da953697eb27c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/Body.js CHANGED
@@ -130,12 +130,9 @@ class PonyfillBody {
130
130
  }
131
131
  const _body = this.generateBody();
132
132
  this._chunks = [];
133
- if (!_body) {
133
+ if (!_body || _body.readable?.destroyed) {
134
134
  return (0, utils_js_1.fakePromise)(this._chunks);
135
135
  }
136
- if (_body.readable?.destroyed) {
137
- return (0, promise_helpers_1.fakeRejectPromise)(new Error('Readable stream has already been consumed or destroyed.'));
138
- }
139
136
  _body.readable.on('data', chunk => {
140
137
  this._chunks.push(chunk);
141
138
  });
@@ -23,11 +23,6 @@ function fetchNodeHttp(fetchRequest) {
23
23
  return new Promise((resolve, reject) => {
24
24
  try {
25
25
  const requestFn = getRequestFnForProtocol(fetchRequest.parsedUrl?.protocol || fetchRequest.url);
26
- const nodeReadable = (fetchRequest.body != null
27
- ? (0, utils_js_1.isNodeReadable)(fetchRequest.body)
28
- ? fetchRequest.body
29
- : node_stream_1.Readable.from(fetchRequest.body)
30
- : null);
31
26
  const headersSerializer = fetchRequest.headersSerializer || utils_js_1.getHeadersObj;
32
27
  const nodeHeaders = headersSerializer(fetchRequest.headers);
33
28
  if (nodeHeaders['accept-encoding'] == null) {
@@ -115,11 +110,24 @@ function fetchNodeHttp(fetchRequest) {
115
110
  resolve(ponyfillResponse);
116
111
  });
117
112
  nodeRequest.once('error', reject);
118
- if (nodeReadable) {
119
- nodeReadable.pipe(nodeRequest);
113
+ if (fetchRequest['_buffer'] != null) {
114
+ nodeRequest.write(fetchRequest['_buffer']);
115
+ // @ts-expect-error Avoid arguments adaptor trampoline https://v8.dev/blog/adaptor-frame
116
+ nodeRequest.end(null, null, null);
120
117
  }
121
118
  else {
122
- nodeRequest.end();
119
+ const nodeReadable = (fetchRequest.body != null
120
+ ? (0, utils_js_1.isNodeReadable)(fetchRequest.body)
121
+ ? fetchRequest.body
122
+ : node_stream_1.Readable.from(fetchRequest.body)
123
+ : null);
124
+ if (nodeReadable) {
125
+ nodeReadable.pipe(nodeRequest);
126
+ }
127
+ else {
128
+ // @ts-expect-error Avoid arguments adaptor trampoline https://v8.dev/blog/adaptor-frame
129
+ nodeRequest.end(null, null, null);
130
+ }
123
131
  }
124
132
  }
125
133
  catch (e) {
package/esm/Body.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Buffer } from 'node:buffer';
3
3
  import { Readable } from 'node:stream';
4
4
  import busboy from 'busboy';
5
- import { fakeRejectPromise, handleMaybePromise } from '@whatwg-node/promise-helpers';
5
+ import { handleMaybePromise } from '@whatwg-node/promise-helpers';
6
6
  import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
7
7
  import { PonyfillFile } from './File.js';
8
8
  import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
@@ -126,12 +126,9 @@ export class PonyfillBody {
126
126
  }
127
127
  const _body = this.generateBody();
128
128
  this._chunks = [];
129
- if (!_body) {
129
+ if (!_body || _body.readable?.destroyed) {
130
130
  return fakePromise(this._chunks);
131
131
  }
132
- if (_body.readable?.destroyed) {
133
- return fakeRejectPromise(new Error('Readable stream has already been consumed or destroyed.'));
134
- }
135
132
  _body.readable.on('data', chunk => {
136
133
  this._chunks.push(chunk);
137
134
  });
@@ -20,11 +20,6 @@ export function fetchNodeHttp(fetchRequest) {
20
20
  return new Promise((resolve, reject) => {
21
21
  try {
22
22
  const requestFn = getRequestFnForProtocol(fetchRequest.parsedUrl?.protocol || fetchRequest.url);
23
- const nodeReadable = (fetchRequest.body != null
24
- ? isNodeReadable(fetchRequest.body)
25
- ? fetchRequest.body
26
- : Readable.from(fetchRequest.body)
27
- : null);
28
23
  const headersSerializer = fetchRequest.headersSerializer || getHeadersObj;
29
24
  const nodeHeaders = headersSerializer(fetchRequest.headers);
30
25
  if (nodeHeaders['accept-encoding'] == null) {
@@ -112,11 +107,24 @@ export function fetchNodeHttp(fetchRequest) {
112
107
  resolve(ponyfillResponse);
113
108
  });
114
109
  nodeRequest.once('error', reject);
115
- if (nodeReadable) {
116
- nodeReadable.pipe(nodeRequest);
110
+ if (fetchRequest['_buffer'] != null) {
111
+ nodeRequest.write(fetchRequest['_buffer']);
112
+ // @ts-expect-error Avoid arguments adaptor trampoline https://v8.dev/blog/adaptor-frame
113
+ nodeRequest.end(null, null, null);
117
114
  }
118
115
  else {
119
- nodeRequest.end();
116
+ const nodeReadable = (fetchRequest.body != null
117
+ ? isNodeReadable(fetchRequest.body)
118
+ ? fetchRequest.body
119
+ : Readable.from(fetchRequest.body)
120
+ : null);
121
+ if (nodeReadable) {
122
+ nodeReadable.pipe(nodeRequest);
123
+ }
124
+ else {
125
+ // @ts-expect-error Avoid arguments adaptor trampoline https://v8.dev/blog/adaptor-frame
126
+ nodeRequest.end(null, null, null);
127
+ }
120
128
  }
121
129
  }
122
130
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.15-alpha-20250321162456-ed61b3d110e199e98204f2d2867357b5f82b1aa3",
3
+ "version": "0.7.15-alpha-20250322121446-0a8732f1758546d618a797e18a1da953697eb27c",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -34,7 +34,7 @@ export declare class PonyfillBody<TJSON = any> implements Body {
34
34
  }, forceSet?: boolean): void;
35
35
  get body(): PonyfillReadableStream<Uint8Array> | null;
36
36
  _chunks: Uint8Array[] | null;
37
- _collectChunksFromReadable(): Promise<Buffer<ArrayBufferLike>[]> | MaybePromise<Uint8Array<ArrayBufferLike>[]>;
37
+ _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
38
38
  _blob: PonyfillBlob | null;
39
39
  blob(): Promise<PonyfillBlob>;
40
40
  _formData: PonyfillFormData | null;
package/typings/Body.d.ts CHANGED
@@ -34,7 +34,7 @@ export declare class PonyfillBody<TJSON = any> implements Body {
34
34
  }, forceSet?: boolean): void;
35
35
  get body(): PonyfillReadableStream<Uint8Array> | null;
36
36
  _chunks: Uint8Array[] | null;
37
- _collectChunksFromReadable(): Promise<Buffer<ArrayBufferLike>[]> | MaybePromise<Uint8Array<ArrayBufferLike>[]>;
37
+ _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
38
38
  _blob: PonyfillBlob | null;
39
39
  blob(): Promise<PonyfillBlob>;
40
40
  _formData: PonyfillFormData | null;