deno/ext/node/polyfills/internal/streams/state.js
Divy Srivastava 01b6da9d9b
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.
2025-04-14 21:35:34 +05:30

66 lines
1.7 KiB
JavaScript

// deno-lint-ignore-file
// Copyright 2018-2025 the Deno authors. MIT license.
import process from "node:process";
import { primordials } from "ext:core/mod.js";
import { validateInteger } from "ext:deno_node/internal/validators.mjs";
import _mod1 from "ext:deno_node/internal/errors.ts";
const { ERR_INVALID_ARG_VALUE } = _mod1.codes;
"use strict";
const {
MathFloor,
NumberIsInteger,
} = primordials;
// TODO (fix): For some reason Windows CI fails with bigger hwm.
let defaultHighWaterMarkBytes = process.platform === "win32"
? 16 * 1024
: 64 * 1024;
let defaultHighWaterMarkObjectMode = 16;
function highWaterMarkFrom(options, isDuplex, duplexKey) {
return options.highWaterMark != null
? options.highWaterMark
: isDuplex
? options[duplexKey]
: null;
}
function getDefaultHighWaterMark(objectMode) {
return objectMode
? defaultHighWaterMarkObjectMode
: defaultHighWaterMarkBytes;
}
function setDefaultHighWaterMark(objectMode, value) {
validateInteger(value, "value", 0);
if (objectMode) {
defaultHighWaterMarkObjectMode = value;
} else {
defaultHighWaterMarkBytes = value;
}
}
function getHighWaterMark(state, options, duplexKey, isDuplex) {
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
if (hwm != null) {
if (!NumberIsInteger(hwm) || hwm < 0) {
const name = isDuplex ? `options.${duplexKey}` : "options.highWaterMark";
throw new ERR_INVALID_ARG_VALUE(name, hwm);
}
return MathFloor(hwm);
}
// Default value
return getDefaultHighWaterMark(state.objectMode);
}
const _defaultExport2 = {
getHighWaterMark,
getDefaultHighWaterMark,
setDefaultHighWaterMark,
};
export default _defaultExport2;
export { getDefaultHighWaterMark, getHighWaterMark, setDefaultHighWaterMark };