mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(ext/node): upgrade node:stream
(#28855)
Ref https://github.com/denoland/deno/issues/28836 This PR replaces the _stream.mjs bundle with a file-by-file port instead. A codemod transpiles Node.js internals to ESM. The codemod performs three tasks: translating CJS to ESM, remapping internal dependencies, and hoisting lazy requires as imports. The process is fully automated through the `update_node_stream.ts` script, simplifying future internal updates. The script checks out Node.js from a specific tag defined in the `tests/node_compat/runner`. Additionally, the update enables new tests in our Node test runner and adds features (like compose()) that were missing from the outdated bundle. ## Performance There is a 140KB+ binary size increase on aarch64-apple-darwin and nop startup time stays the same.
This commit is contained in:
parent
6e49a4b3bd
commit
01b6da9d9b
76 changed files with 11145 additions and 7032 deletions
52
ext/node/polyfills/stream/promises.js
Normal file
52
ext/node/polyfills/stream/promises.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
// deno-lint-ignore-file
|
||||
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||
|
||||
import { primordials } from "ext:core/mod.js";
|
||||
import {
|
||||
isIterable,
|
||||
isNodeStream,
|
||||
isWebStream,
|
||||
} from "ext:deno_node/internal/streams/utils.js";
|
||||
import { pipelineImpl as pl } from "ext:deno_node/internal/streams/pipeline.js";
|
||||
import { finished } from "ext:deno_node/internal/streams/end-of-stream.js";
|
||||
import * as _mod2 from "node:stream";
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
ArrayPrototypePop,
|
||||
Promise,
|
||||
} = primordials;
|
||||
|
||||
_mod2;
|
||||
|
||||
function pipeline(...streams) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let signal;
|
||||
let end;
|
||||
const lastArg = streams[streams.length - 1];
|
||||
if (
|
||||
lastArg && typeof lastArg === "object" &&
|
||||
!isNodeStream(lastArg) && !isIterable(lastArg) && !isWebStream(lastArg)
|
||||
) {
|
||||
const options = ArrayPrototypePop(streams);
|
||||
signal = options.signal;
|
||||
end = options.end;
|
||||
}
|
||||
|
||||
pl(streams, (err, value) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(value);
|
||||
}
|
||||
}, { signal, end });
|
||||
});
|
||||
}
|
||||
|
||||
const _defaultExport1 = {
|
||||
finished,
|
||||
pipeline,
|
||||
};
|
||||
|
||||
export default _defaultExport1;
|
||||
export { finished, pipeline };
|
Loading…
Add table
Add a link
Reference in a new issue