mirror of
https://github.com/denoland/deno.git
synced 2025-09-21 18:10:02 +00:00

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.
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
// deno-lint-ignore-file
|
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
|
|
import { primordials } from "ext:core/mod.js";
|
|
import stream from "node:stream";
|
|
// LazyTransform is a special type of Transform stream that is lazily loaded.
|
|
// This is used for performance with bi-API-ship: when two APIs are available
|
|
// for the stream, one conventional and one non-conventional.
|
|
"use strict";
|
|
|
|
const {
|
|
ObjectDefineProperties,
|
|
ObjectDefineProperty,
|
|
ObjectSetPrototypeOf,
|
|
} = primordials;
|
|
|
|
function LazyTransform(options) {
|
|
this._options = options;
|
|
}
|
|
ObjectSetPrototypeOf(LazyTransform.prototype, stream.Transform.prototype);
|
|
ObjectSetPrototypeOf(LazyTransform, stream.Transform);
|
|
|
|
function makeGetter(name) {
|
|
return function () {
|
|
stream.Transform.call(this, this._options);
|
|
this._writableState.decodeStrings = false;
|
|
return this[name];
|
|
};
|
|
}
|
|
|
|
function makeSetter(name) {
|
|
return function (val) {
|
|
ObjectDefineProperty(this, name, {
|
|
__proto__: null,
|
|
value: val,
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
});
|
|
};
|
|
}
|
|
|
|
ObjectDefineProperties(LazyTransform.prototype, {
|
|
_readableState: {
|
|
__proto__: null,
|
|
get: makeGetter("_readableState"),
|
|
set: makeSetter("_readableState"),
|
|
configurable: true,
|
|
enumerable: true,
|
|
},
|
|
_writableState: {
|
|
__proto__: null,
|
|
get: makeGetter("_writableState"),
|
|
set: makeSetter("_writableState"),
|
|
configurable: true,
|
|
enumerable: true,
|
|
},
|
|
});
|
|
export default LazyTransform;
|
|
export { LazyTransform };
|