@whatwg-node/node-fetch 0.7.23-alpha-20250725192842-30aa375091fdb305ec731d51c061cc2c21f3b773 → 0.7.23-alpha-20250725194603-2942304cbf1226c9014b2f3f4c3c94b84b410273

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/utils.js CHANGED
@@ -11,7 +11,6 @@ exports.pipeThrough = pipeThrough;
11
11
  exports.endStream = endStream;
12
12
  exports.safeWrite = safeWrite;
13
13
  const node_events_1 = require("node:events");
14
- const node_stream_1 = require("node:stream");
15
14
  function isHeadersInstance(obj) {
16
15
  return obj?.forEach != null;
17
16
  }
@@ -65,7 +64,12 @@ function pipeThrough({ src, dest, signal, onError, }) {
65
64
  dest.destroy(e);
66
65
  });
67
66
  if (signal) {
68
- (0, node_stream_1.addAbortSignal)(signal, src);
67
+ // this is faster than `import('node:signal').addAbortSignal(signal, src)`
68
+ function onAbort() {
69
+ src.destroy(new AbortError());
70
+ }
71
+ signal.addEventListener('abort', onAbort, { once: true });
72
+ src.once('close', () => signal.removeEventListener('abort', onAbort));
69
73
  }
70
74
  src.pipe(dest, { end: true /* already default */ });
71
75
  }
@@ -79,3 +83,10 @@ function safeWrite(chunk, stream) {
79
83
  return (0, node_events_1.once)(stream, 'drain');
80
84
  }
81
85
  }
86
+ // https://github.com/nodejs/node/blob/f692878dec6354c0a82241f224906981861bc840/lib/internal/errors.js#L961-L973
87
+ class AbortError extends Error {
88
+ constructor(message = 'The operation was aborted', options = undefined) {
89
+ super(message, options);
90
+ this.name = 'AbortError';
91
+ }
92
+ }
package/esm/utils.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { once } from 'node:events';
2
- import { addAbortSignal } from 'node:stream';
3
2
  function isHeadersInstance(obj) {
4
3
  return obj?.forEach != null;
5
4
  }
@@ -52,7 +51,12 @@ export function pipeThrough({ src, dest, signal, onError, }) {
52
51
  dest.destroy(e);
53
52
  });
54
53
  if (signal) {
55
- addAbortSignal(signal, src);
54
+ // this is faster than `import('node:signal').addAbortSignal(signal, src)`
55
+ function onAbort() {
56
+ src.destroy(new AbortError());
57
+ }
58
+ signal.addEventListener('abort', onAbort, { once: true });
59
+ src.once('close', () => signal.removeEventListener('abort', onAbort));
56
60
  }
57
61
  src.pipe(dest, { end: true /* already default */ });
58
62
  }
@@ -66,3 +70,10 @@ export function safeWrite(chunk, stream) {
66
70
  return once(stream, 'drain');
67
71
  }
68
72
  }
73
+ // https://github.com/nodejs/node/blob/f692878dec6354c0a82241f224906981861bc840/lib/internal/errors.js#L961-L973
74
+ class AbortError extends Error {
75
+ constructor(message = 'The operation was aborted', options = undefined) {
76
+ super(message, options);
77
+ this.name = 'AbortError';
78
+ }
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.23-alpha-20250725192842-30aa375091fdb305ec731d51c061cc2c21f3b773",
3
+ "version": "0.7.23-alpha-20250725194603-2942304cbf1226c9014b2f3f4c3c94b84b410273",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {