@whatwg-node/node-fetch 0.7.23-alpha-20250725200303-1aa414e0bcfe4d59328e3cadb7df04ea1f293ff7 → 0.7.23-alpha-20250725224534-bbeeaa7718aa0727bc87514020a30777a0675fe6

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
  }
@@ -66,11 +65,23 @@ function pipeThrough({ src, dest, signal, onError, }) {
66
65
  });
67
66
  if (signal) {
68
67
  // this is faster than `import('node:signal').addAbortSignal(signal, src)`
68
+ const srcRef = new WeakRef(src);
69
+ const signalRef = new WeakRef(signal);
70
+ function cleanup() {
71
+ signalRef.deref()?.removeEventListener('abort', onAbort);
72
+ srcRef.deref()?.removeListener('end', cleanup);
73
+ srcRef.deref()?.removeListener('error', cleanup);
74
+ srcRef.deref()?.removeListener('close', cleanup);
75
+ }
69
76
  function onAbort() {
70
- src.destroy(new AbortError());
77
+ srcRef.deref()?.destroy(new AbortError());
78
+ cleanup();
71
79
  }
72
80
  signal.addEventListener('abort', onAbort, { once: true });
73
- (0, node_stream_1.finished)(src, () => signal.removeEventListener('abort', onAbort));
81
+ // this is faster than `import('node:signal').finished(src, cleanup)`
82
+ src.once('end', cleanup);
83
+ src.once('error', cleanup);
84
+ src.once('close', cleanup);
74
85
  }
75
86
  src.pipe(dest, { end: true /* already default */ });
76
87
  }
package/esm/utils.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { once } from 'node:events';
2
- import { finished } from 'node:stream';
3
2
  function isHeadersInstance(obj) {
4
3
  return obj?.forEach != null;
5
4
  }
@@ -53,11 +52,23 @@ export function pipeThrough({ src, dest, signal, onError, }) {
53
52
  });
54
53
  if (signal) {
55
54
  // this is faster than `import('node:signal').addAbortSignal(signal, src)`
55
+ const srcRef = new WeakRef(src);
56
+ const signalRef = new WeakRef(signal);
57
+ function cleanup() {
58
+ signalRef.deref()?.removeEventListener('abort', onAbort);
59
+ srcRef.deref()?.removeListener('end', cleanup);
60
+ srcRef.deref()?.removeListener('error', cleanup);
61
+ srcRef.deref()?.removeListener('close', cleanup);
62
+ }
56
63
  function onAbort() {
57
- src.destroy(new AbortError());
64
+ srcRef.deref()?.destroy(new AbortError());
65
+ cleanup();
58
66
  }
59
67
  signal.addEventListener('abort', onAbort, { once: true });
60
- finished(src, () => signal.removeEventListener('abort', onAbort));
68
+ // this is faster than `import('node:signal').finished(src, cleanup)`
69
+ src.once('end', cleanup);
70
+ src.once('error', cleanup);
71
+ src.once('close', cleanup);
61
72
  }
62
73
  src.pipe(dest, { end: true /* already default */ });
63
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.23-alpha-20250725200303-1aa414e0bcfe4d59328e3cadb7df04ea1f293ff7",
3
+ "version": "0.7.23-alpha-20250725224534-bbeeaa7718aa0727bc87514020a30777a0675fe6",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {