Commit f7f98095 authored by Tim Neutkens's avatar Tim Neutkens

Upgrade experimental-fast-webstreams

parent 6fae0c5d
...@@ -206,7 +206,7 @@ ...@@ -206,7 +206,7 @@
"execa": "2.0.3", "execa": "2.0.3",
"expect": "29.7.0", "expect": "29.7.0",
"expect-type": "0.14.2", "expect-type": "0.14.2",
"experimental-fast-webstreams": "0.0.5", "experimental-fast-webstreams": "0.0.18",
"express": "4.17.0", "express": "4.17.0",
"faker": "5.5.3", "faker": "5.5.3",
"faunadb": "2.6.1", "faunadb": "2.6.1",
...@@ -345,8 +345,7 @@ ...@@ -345,8 +345,7 @@
"@types/node@20.17.6": "patches/@types__node@20.17.6.patch", "@types/node@20.17.6": "patches/@types__node@20.17.6.patch",
"taskr@1.1.0": "patches/taskr@1.1.0.patch", "taskr@1.1.0": "patches/taskr@1.1.0.patch",
"minizlib@3.1.0": "patches/minizlib@3.1.0.patch", "minizlib@3.1.0": "patches/minizlib@3.1.0.patch",
"http-proxy@1.18.1": "patches/http-proxy@1.18.1.patch", "http-proxy@1.18.1": "patches/http-proxy@1.18.1.patch"
"experimental-fast-webstreams@0.0.5": "patches/experimental-fast-webstreams@0.0.5.patch"
} }
} }
} }
{"name":"experimental-fast-webstreams","main":"patch.js","license":"ISC"}
This source diff could not be displayed because it is too large. You can view the blob instead.
diff --git a/src/pipe-to.js b/src/pipe-to.js
index 714522c631bedf917da079546b08fda462e6e430..3cb5388f29a4ab6d2b56538bc4f13a09eb9760ac 100644
--- a/src/pipe-to.js
+++ b/src/pipe-to.js
@@ -12,21 +12,10 @@
import { kNodeReadable, kWritableState, noop, RESOLVED_UNDEFINED } from './utils.js';
/**
- * Wait for all promises in a set to settle, resolving to undefined (not an array).
- * Unlike Promise.all(), this avoids creating an intermediate array result that would
- * trigger observable thenable resolution on Object.prototype.then monkey-patching.
+ * Wait for a write promise to settle, resolving to undefined regardless of outcome.
*/
-function _waitForAll(promiseSet) {
- let p = RESOLVED_UNDEFINED;
- for (const w of promiseSet) {
- p = p
- .then(
- () => w,
- () => w,
- )
- .then(noop, noop);
- }
- return p;
+function _waitForWrite(writePromise) {
+ return writePromise.then(noop, noop);
}
export function specPipeTo(source, dest, options = {}) {
@@ -40,7 +29,6 @@ export function specPipeTo(source, dest, options = {}) {
let shuttingDown = false;
let currentWrite = RESOLVED_UNDEFINED;
- const pendingWrites = new Set();
// Track dest state for WritableStreamDefaultWriterCloseWithErrorPropagation
let destClosed = false;
@@ -91,28 +79,19 @@ export function specPipeTo(source, dest, options = {}) {
);
// --- Source close/error handler ---
+ // NOTE: Don't trigger shutdown on source close here. The reader.closed
+ // promise can resolve (via Node.js 'end'/'close' events) before the pump
+ // has drained all buffered data from the underlying Node.js readable.
+ // Instead, just set the flag and kick the pump. The pump will read done
+ // and trigger shutdown after draining all buffered chunks.
reader.closed.then(
() => {
- // Source closed
+ // Source closed — let the pump drain remaining data and handle shutdown
sourceClosed = true;
- if (shuttingDown) return;
- if (!preventClose) {
- shutdownWithAction(() => {
- // WritableStreamDefaultWriterCloseWithErrorPropagation
- if (destErrored) return Promise.reject(destStoredError);
- if (destClosed) return RESOLVED_UNDEFINED;
- // writer.close() may reject if already closed; treat as success
- return writer.close().catch((e) => {
- if (e instanceof TypeError) return; // Already closed/closing
- throw e;
- });
- });
- } else {
- shutdown();
- }
+ if (!shuttingDown) pipeLoop();
},
(storedError) => {
- // Source errored
+ // Source errored — immediate shutdown is correct (no data to drain)
if (shuttingDown) return;
if (!preventAbort) {
shutdownWithAction(() => writer.abort(storedError), true, storedError);
@@ -171,45 +150,66 @@ export function specPipeTo(source, dest, options = {}) {
}
}
+ // Close-shutdown helper (called when pump reads done)
+ function pumpClose() {
+ sourceClosed = true;
+ if (shuttingDown) return;
+ if (!preventClose) {
+ shutdownWithAction(() => {
+ if (destErrored) return Promise.reject(destStoredError);
+ if (destClosed) return RESOLVED_UNDEFINED;
+ return writer.close().catch((e) => {
+ if (e instanceof TypeError) return;
+ throw e;
+ });
+ });
+ } else {
+ shutdown();
+ }
+ }
+
function pumpRead() {
if (shuttingDown) return;
- // Sync fast path: read directly from Node buffer via reader._readSync
- // (saves 2 promises per chunk: the read result Promise + the .then Promise).
- // Must yield to microtask queue after each read for close/error handler interleaving.
+ // Sync fast path: batch-read directly from Node buffer via reader._readSync.
+ // Drains all available buffered chunks in one go before yielding to the
+ // microtask queue, amortizing the yield cost across multiple chunks.
if (hasSyncRead) {
- const syncResult = reader._readSync();
- if (syncResult !== null) {
+ let didSync = false;
+ let syncResult = reader._readSync();
+ while (syncResult !== null) {
if (syncResult.done) {
- sourceClosed = true;
+ pumpClose();
return;
}
+ didSync = true;
currentWrite = writer.write(syncResult.value);
- pendingWrites.add(currentWrite);
- const w = currentWrite;
- currentWrite.then(
- () => pendingWrites.delete(w),
- () => pendingWrites.delete(w),
- );
+ if (shuttingDown) return;
+ // Check backpressure before reading more
+ if (writer.desiredSize <= 0) {
+ queueMicrotask(pipeLoop);
+ return;
+ }
+ syncResult = reader._readSync();
+ }
+ // _readSync returned null — no more buffered data.
+ if (didSync) {
+ // We processed at least one chunk. Yield to allow events to fire,
+ // then re-enter pipeLoop which will try sync again or fall to async.
queueMicrotask(pipeLoop);
return;
}
+ // No sync data available at all — fall through to async read below.
}
- // Async fallback
+ // Async fallback: wait for data via 'readable' event
reader.read().then(({ value, done }) => {
if (shuttingDown) return;
if (done) {
- sourceClosed = true;
+ pumpClose();
return;
}
currentWrite = writer.write(value);
- pendingWrites.add(currentWrite);
- const w = currentWrite;
- currentWrite.then(
- () => pendingWrites.delete(w),
- () => pendingWrites.delete(w),
- );
pipeLoop();
}, noop);
}
@@ -233,17 +233,15 @@ export function specPipeTo(source, dest, options = {}) {
);
};
- // Wait for all in-flight writes to complete before running action
- const allWrites = pendingWrites.size > 0 ? _waitForAll(pendingWrites) : currentWrite;
- allWrites.then(doAction, doAction);
+ // Wait for the last in-flight write to settle before running action
+ _waitForWrite(currentWrite).then(doAction, doAction);
}
// --- Shutdown without action ---
function shutdown(isError = false, error) {
if (shuttingDown) return;
shuttingDown = true;
- const allWrites = pendingWrites.size > 0 ? _waitForAll(pendingWrites) : currentWrite;
- allWrites.then(
+ _waitForWrite(currentWrite).then(
() => finalize(isError, error),
() => finalize(isError, error),
);
...@@ -28,9 +28,6 @@ patchedDependencies: ...@@ -28,9 +28,6 @@ patchedDependencies:
'@types/node@20.17.6': '@types/node@20.17.6':
hash: rvl3vkomen3tospgr67bzubfyu hash: rvl3vkomen3tospgr67bzubfyu
path: patches/@types__node@20.17.6.patch path: patches/@types__node@20.17.6.patch
experimental-fast-webstreams@0.0.5:
hash: 45ceg3shibzyxkompnbutv5bma
path: patches/experimental-fast-webstreams@0.0.5.patch
http-proxy@1.18.1: http-proxy@1.18.1:
hash: qqiqxx62zlcu62nljjmhlvexni hash: qqiqxx62zlcu62nljjmhlvexni
path: patches/http-proxy@1.18.1.patch path: patches/http-proxy@1.18.1.patch
...@@ -299,7 +296,7 @@ importers: ...@@ -299,7 +296,7 @@ importers:
version: 5.2.1(eslint@9.37.0(jiti@2.5.1)) version: 5.2.1(eslint@9.37.0(jiti@2.5.1))
eslint-plugin-import: eslint-plugin-import:
specifier: 2.31.0 specifier: 2.31.0
version: 2.31.0(eslint@9.37.0(jiti@2.5.1)) version: 2.31.0(@typescript-eslint/parser@8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint@9.37.0(jiti@2.5.1))
eslint-plugin-jest: eslint-plugin-jest:
specifier: 27.6.3 specifier: 27.6.3
version: 27.6.3(eslint@9.37.0(jiti@2.5.1))(jest@29.7.0(@types/node@20.17.6(patch_hash=rvl3vkomen3tospgr67bzubfyu))(babel-plugin-macros@3.1.0))(typescript@5.9.2) version: 27.6.3(eslint@9.37.0(jiti@2.5.1))(jest@29.7.0(@types/node@20.17.6(patch_hash=rvl3vkomen3tospgr67bzubfyu))(babel-plugin-macros@3.1.0))(typescript@5.9.2)
...@@ -328,8 +325,8 @@ importers: ...@@ -328,8 +325,8 @@ importers:
specifier: 0.14.2 specifier: 0.14.2
version: 0.14.2 version: 0.14.2
experimental-fast-webstreams: experimental-fast-webstreams:
specifier: 0.0.5 specifier: 0.0.18
version: 0.0.5(patch_hash=45ceg3shibzyxkompnbutv5bma) version: 0.0.18
express: express:
specifier: 4.17.0 specifier: 4.17.0
version: 4.17.0 version: 4.17.0
...@@ -766,7 +763,7 @@ importers: ...@@ -766,7 +763,7 @@ importers:
version: 9.37.0(jiti@2.5.1) version: 9.37.0(jiti@2.5.1)
eslint-config-next: eslint-config-next:
specifier: canary specifier: canary
version: link:../../packages/eslint-config-next version: 16.2.0-canary.58(@typescript-eslint/parser@8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint-plugin-import-x@4.3.1(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2)
tailwindcss: tailwindcss:
specifier: 4.1.13 specifier: 4.1.13
version: 4.1.13 version: 4.1.13
...@@ -4412,6 +4409,9 @@ packages: ...@@ -4412,6 +4409,9 @@ packages:
'@next/env@16.0.8': '@next/env@16.0.8':
resolution: {integrity: sha512-xP4WrQZuj9MdmLJy3eWFHepo+R3vznsMSS8Dy3wdA7FKpjCiesQ6DxZvdGziQisj0tEtCgBKJzjcAc4yZOgLEQ==} resolution: {integrity: sha512-xP4WrQZuj9MdmLJy3eWFHepo+R3vznsMSS8Dy3wdA7FKpjCiesQ6DxZvdGziQisj0tEtCgBKJzjcAc4yZOgLEQ==}
'@next/eslint-plugin-next@16.2.0-canary.58':
resolution: {integrity: sha512-YVDf4uCEmEHqg9voFhTbHmpCU8jjtgxx9e+1AkTkH1/azdWUc89FQfDqRF6OrfByDlaBzK6jaqKNXAQIEKshhQ==}
'@next/rspack-binding-android-arm-eabi@1.0.2': '@next/rspack-binding-android-arm-eabi@1.0.2':
resolution: {integrity: sha512-ayoNrm5Z9xYIHdYfhUSvzPzNXRunMXx5B6Bonch9pJBfyC/3tUlcqVlI5+1HS+H4euWtPMeGqe8bARjQ71J/ug==} resolution: {integrity: sha512-ayoNrm5Z9xYIHdYfhUSvzPzNXRunMXx5B6Bonch9pJBfyC/3tUlcqVlI5+1HS+H4euWtPMeGqe8bARjQ71J/ug==}
cpu: [arm] cpu: [arm]
...@@ -9926,6 +9926,15 @@ packages: ...@@ -9926,6 +9926,15 @@ packages:
engines: {node: '>=6.0'} engines: {node: '>=6.0'}
hasBin: true hasBin: true
eslint-config-next@16.2.0-canary.58:
resolution: {integrity: sha512-8PPJLUVlTy8Zt1ovE5lSHJdFeq5x6+fT7ax9FFQqYVhwMFSJi+8dEKRqE9l1BlC1QH6/xyv/hS++axBMdW11jA==}
peerDependencies:
eslint: '>=9.0.0'
typescript: '>=3.3.1'
peerDependenciesMeta:
typescript:
optional: true
eslint-formatter-codeframe@7.32.1: eslint-formatter-codeframe@7.32.1:
resolution: {integrity: sha512-DK/3Q3+zVKq/7PdSYiCxPrsDF8H/TRMK5n8Hziwr4IMkMy+XiKSwbpj25AdajS63I/B61Snetq4uVvX9fOLyAg==} resolution: {integrity: sha512-DK/3Q3+zVKq/7PdSYiCxPrsDF8H/TRMK5n8Hziwr4IMkMy+XiKSwbpj25AdajS63I/B61Snetq4uVvX9fOLyAg==}
engines: {node: ^10.12.0 || >=12.0.0} engines: {node: ^10.12.0 || >=12.0.0}
...@@ -10320,8 +10329,8 @@ packages: ...@@ -10320,8 +10329,8 @@ packages:
resolution: {integrity: sha512-WVi2V4iHKw/vHEyye00Q9CSZz7KHDbJkJyteUI8kTih9jiyMl3bIk7wLYFcY9D1Blnadlyb5w5NBuNjQBow99g==} resolution: {integrity: sha512-WVi2V4iHKw/vHEyye00Q9CSZz7KHDbJkJyteUI8kTih9jiyMl3bIk7wLYFcY9D1Blnadlyb5w5NBuNjQBow99g==}
engines: {node: ^16.10.0 || ^18.12.0 || >=20.0.0} engines: {node: ^16.10.0 || ^18.12.0 || >=20.0.0}
experimental-fast-webstreams@0.0.5: experimental-fast-webstreams@0.0.18:
resolution: {integrity: sha512-VsKpdIur3SL8DCMANpxu6jxyVnVrWOUuqlTlaxFa+8SUd2NIZISAsiwNBx0NG4OZ6xHuuZBBSx/QnAeFmv6oXw==} resolution: {integrity: sha512-ahV5nGjjIJVe3Y/SaiBFAtAaKYRnvlA8do9iE3Cb5Qe45g7WQzUoNXvqDC0+srYm9VspR3WtBVBSzjhw9NO5nQ==}
engines: {node: '>=20'} engines: {node: '>=20'}
exponential-backoff@3.1.3: exponential-backoff@3.1.3:
...@@ -17302,7 +17311,7 @@ packages: ...@@ -17302,7 +17311,7 @@ packages:
superagent@3.8.3: superagent@3.8.3:
resolution: {integrity: sha512-GLQtLMCoEIK4eDv6OGtkOoSMt3D+oq0y3dsxMuYuDvaNUvuT8eFBuLmfR0iYYzHC1e8hpzC6ZsxbuP6DIalMFA==} resolution: {integrity: sha512-GLQtLMCoEIK4eDv6OGtkOoSMt3D+oq0y3dsxMuYuDvaNUvuT8eFBuLmfR0iYYzHC1e8hpzC6ZsxbuP6DIalMFA==}
engines: {node: '>= 4.0'} engines: {node: '>= 4.0'}
deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net
superstruct@1.0.3: superstruct@1.0.3:
resolution: {integrity: sha512-8iTn3oSS8nRGn+C2pgXSKPI3jmpm6FExNazNpjvqS6ZUJQCej3PUXEKM8NjHBOs54ExM+LPW/FBRhymrdcCiSg==} resolution: {integrity: sha512-8iTn3oSS8nRGn+C2pgXSKPI3jmpm6FExNazNpjvqS6ZUJQCej3PUXEKM8NjHBOs54ExM+LPW/FBRhymrdcCiSg==}
...@@ -21621,6 +21630,10 @@ snapshots: ...@@ -21621,6 +21630,10 @@ snapshots:
'@next/env@16.0.8': {} '@next/env@16.0.8': {}
'@next/eslint-plugin-next@16.2.0-canary.58':
dependencies:
fast-glob: 3.3.1
'@next/rspack-binding-android-arm-eabi@1.0.2': '@next/rspack-binding-android-arm-eabi@1.0.2':
optional: true optional: true
...@@ -27923,6 +27936,26 @@ snapshots: ...@@ -27923,6 +27936,26 @@ snapshots:
optionalDependencies: optionalDependencies:
source-map: 0.6.1 source-map: 0.6.1
eslint-config-next@16.2.0-canary.58(@typescript-eslint/parser@8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint-plugin-import-x@4.3.1(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2):
dependencies:
'@next/eslint-plugin-next': 16.2.0-canary.58
eslint: 9.37.0(jiti@2.5.1)
eslint-import-resolver-node: 0.3.9
eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import-x@4.3.1(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint-plugin-import@2.32.0)(eslint@9.37.0(jiti@2.5.1))
eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint-import-resolver-typescript@3.10.1)(eslint@9.37.0(jiti@2.5.1))
eslint-plugin-jsx-a11y: 6.10.2(eslint@9.37.0(jiti@2.5.1))
eslint-plugin-react: 7.37.0(eslint@9.37.0(jiti@2.5.1))
eslint-plugin-react-hooks: 7.0.0(eslint@9.37.0(jiti@2.5.1))
globals: 16.4.0
typescript-eslint: 8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2)
optionalDependencies:
typescript: 5.9.2
transitivePeerDependencies:
- '@typescript-eslint/parser'
- eslint-import-resolver-webpack
- eslint-plugin-import-x
- supports-color
eslint-formatter-codeframe@7.32.1: eslint-formatter-codeframe@7.32.1:
dependencies: dependencies:
'@babel/code-frame': 7.12.11 '@babel/code-frame': 7.12.11
...@@ -27973,10 +28006,11 @@ snapshots: ...@@ -27973,10 +28006,11 @@ snapshots:
- bluebird - bluebird
- supports-color - supports-color
eslint-module-utils@2.12.0(eslint-import-resolver-node@0.3.9)(eslint@9.37.0(jiti@2.5.1)): eslint-module-utils@2.12.0(@typescript-eslint/parser@8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint-import-resolver-node@0.3.9)(eslint@9.37.0(jiti@2.5.1)):
dependencies: dependencies:
debug: 3.2.7 debug: 3.2.7
optionalDependencies: optionalDependencies:
'@typescript-eslint/parser': 8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2)
eslint: 9.37.0(jiti@2.5.1) eslint: 9.37.0(jiti@2.5.1)
eslint-import-resolver-node: 0.3.9 eslint-import-resolver-node: 0.3.9
transitivePeerDependencies: transitivePeerDependencies:
...@@ -28017,7 +28051,7 @@ snapshots: ...@@ -28017,7 +28051,7 @@ snapshots:
- typescript - typescript
optional: true optional: true
eslint-plugin-import@2.31.0(eslint@9.37.0(jiti@2.5.1)): eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint@9.37.0(jiti@2.5.1)):
dependencies: dependencies:
'@rtsao/scc': 1.1.0 '@rtsao/scc': 1.1.0
array-includes: 3.1.8 array-includes: 3.1.8
...@@ -28028,7 +28062,7 @@ snapshots: ...@@ -28028,7 +28062,7 @@ snapshots:
doctrine: 2.1.0 doctrine: 2.1.0
eslint: 9.37.0(jiti@2.5.1) eslint: 9.37.0(jiti@2.5.1)
eslint-import-resolver-node: 0.3.9 eslint-import-resolver-node: 0.3.9
eslint-module-utils: 2.12.0(eslint-import-resolver-node@0.3.9)(eslint@9.37.0(jiti@2.5.1)) eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2))(eslint-import-resolver-node@0.3.9)(eslint@9.37.0(jiti@2.5.1))
hasown: 2.0.2 hasown: 2.0.2
is-core-module: 2.15.1 is-core-module: 2.15.1
is-glob: 4.0.3 is-glob: 4.0.3
...@@ -28039,6 +28073,8 @@ snapshots: ...@@ -28039,6 +28073,8 @@ snapshots:
semver: 6.3.1 semver: 6.3.1
string.prototype.trimend: 1.0.9 string.prototype.trimend: 1.0.9
tsconfig-paths: 3.15.0 tsconfig-paths: 3.15.0
optionalDependencies:
'@typescript-eslint/parser': 8.46.0(eslint@9.37.0(jiti@2.5.1))(typescript@5.9.2)
transitivePeerDependencies: transitivePeerDependencies:
- eslint-import-resolver-typescript - eslint-import-resolver-typescript
- eslint-import-resolver-webpack - eslint-import-resolver-webpack
...@@ -28562,7 +28598,7 @@ snapshots: ...@@ -28562,7 +28598,7 @@ snapshots:
jest-mock: 30.0.0-alpha.6 jest-mock: 30.0.0-alpha.6
jest-util: 30.0.0-alpha.6 jest-util: 30.0.0-alpha.6
experimental-fast-webstreams@0.0.5(patch_hash=45ceg3shibzyxkompnbutv5bma): {} experimental-fast-webstreams@0.0.18: {}
exponential-backoff@3.1.3: {} exponential-backoff@3.1.3: {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment