Skip to content

Fix string_decoder import #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
npm install readable-stream
```

This package is a mirror of the streams implementations in Node.js 18.19.0.
This package is a mirror of the streams implementations in Node.js 18.20.5.

Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v18.19.0/docs/api/stream.html).
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v18.20.5/docs/api/stream.html).

If you want to guarantee a stable streams base, regardless of what version of
Node you, or the users of your libraries are using, use **readable-stream** _only_ and avoid the _"stream"_ module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).
Expand Down
5 changes: 4 additions & 1 deletion build/replacements.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ const streamsRequireInternal = ["require\\('internal/(.+)'\\)", "require('../int

const streamsRequirePrimordials = ['= primordials', "= require('../ours/primordials')"]

const stringDecoderRequirePackage = ["require\\('string_decoder'\\)", "require('string_decoder/')"]

const testCommonKnownGlobals = [
'let knownGlobals = \\[(\\n\\s+)',
`
Expand Down Expand Up @@ -312,7 +314,8 @@ export const replacements = {
],
'lib/internal/streams/readable.js': [
removefromWebReadableMethod,
removetoWebReadableMethod
removetoWebReadableMethod,
stringDecoderRequirePackage
],
'lib/internal/streams/.+': [
internalStreamsRequireErrors,
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default [
'space-before-function-paren': 0,
curly: [2, 'all'],
'local/no-big-int': 'error',
'no-undef': 'warn',
},
},
]

5 changes: 1 addition & 4 deletions lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function constructNT(stream) {
} else if (err) {
errorOrDestroy(stream, err, true)
} else {
process.nextTick(emitConstructNT, stream)
stream.emit(kConstruct)
}
}
try {
Expand All @@ -236,9 +236,6 @@ function constructNT(stream) {
process.nextTick(onConstruct, err)
}
}
function emitConstructNT(stream) {
stream.emit(kConstruct)
}
function isRequest(stream) {
return (stream === null || stream === undefined ? undefined : stream.setHeader) && typeof stream.abort === 'function'
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const {
} = require('../../ours/errors')
const { validateObject } = require('../validators')
const kPaused = Symbol('kPaused')
const { StringDecoder } = require('string_decoder')
const { StringDecoder } = require('string_decoder/')
const from = require('./from')
ObjectSetPrototypeOf(Readable.prototype, Stream.prototype)
ObjectSetPrototypeOf(Readable, Stream)
Expand Down
2 changes: 0 additions & 2 deletions lib/internal/streams/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function isReadableNodeStream(obj, strict = false) {
) // Writable has .pipe.
)
}

function isWritableNodeStream(obj) {
var _obj$_writableState
return !!(
Expand All @@ -45,7 +44,6 @@ function isWritableNodeStream(obj) {
) // Duplex
)
}

function isDuplexNodeStream(obj) {
return !!(
obj &&
Expand Down
3 changes: 2 additions & 1 deletion lib/ours/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ E(
received = addNumericalSeparator(String(input))
} else if (typeof input === 'bigint') {
received = String(input)
if (input > 2n ** 32n || input < -(2n ** 32n)) {
const limit = BigInt(2) ** BigInt(32)
if (input > limit || input < -limit) {
received = addNumericalSeparator(received)
}
received += 'n'
Expand Down
2 changes: 1 addition & 1 deletion lib/ours/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ module.exports = {
TypedArrayPrototypeSet(self, buf, len) {
return self.set(buf, len)
},
Boolean: Boolean,
Boolean,
Uint8Array
}
4 changes: 3 additions & 1 deletion lib/ours/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const validateAbortSignal = (signal, name) => {
}
}
const validateFunction = (value, name) => {
if (typeof value !== 'function') throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
if (typeof value !== 'function') {
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
}
}

// This is a simplified version of AggregateError
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"./lib/ours/index.js": "./lib/ours/browser.js"
},
"scripts": {
"build": "node build/build.mjs",
"build": "node build/build.mjs 18.20.5",
"postbuild": "prettier -w lib test",
"test": "tap --rcfile=./tap.yml test/parallel/test-*.js test/ours/test-*.js",
"test:prepare": "node test/browser/runner-prepare.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ module.exports = {
TypedArrayPrototypeSet(self, buf, len) {
return self.set(buf, len)
},
Boolean: Boolean,
Boolean,
Uint8Array
}
31 changes: 15 additions & 16 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ const validateAbortSignal = (signal, name) => {
(signal === null ||
typeof signal !== 'object' ||
!('aborted' in signal))) {
throw new ERR_INVALID_ARG_TYPE(name, 'AbortSignal', signal);
throw new ERR_INVALID_ARG_TYPE(name, 'AbortSignal', signal)
}
};
}
const validateFunction = (value, name) => {
if (typeof value !== 'function')
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value);
};
if (typeof value !== 'function') { throw new ERR_INVALID_ARG_TYPE(name, 'Function', value) }
}

// This is a simplified version of AggregateError
class AggregateError extends Error {
Expand Down Expand Up @@ -155,26 +154,26 @@ module.exports = {
},
addAbortListener: require('events').addAbortListener || function addAbortListener(signal, listener) {
if (signal === undefined) {
throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal);
throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal)
}
validateAbortSignal(signal, 'signal');
validateFunction(listener, 'listener');
validateAbortSignal(signal, 'signal')
validateFunction(listener, 'listener')

let removeEventListener;
let removeEventListener
if (signal.aborted) {
queueMicrotask(() => listener());
queueMicrotask(() => listener())
} else {
signal.addEventListener('abort', listener, { __proto__: null, once: true, [kResistStopPropagation]: true });
signal.addEventListener('abort', listener, { __proto__: null, once: true, [kResistStopPropagation]: true })
removeEventListener = () => {
signal.removeEventListener('abort', listener);
};
signal.removeEventListener('abort', listener)
}
}
return {
__proto__: null,
[SymbolDispose]() {
removeEventListener?.();
},
};
removeEventListener?.()
}
}
},
AbortSignalAny: AbortSignal.any || function AbortSignalAny(signals) {
// Fast path if there is only one signal.
Expand Down
1 change: 0 additions & 1 deletion test/browser/test-stream2-readable-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ module.exports = function (test) {
old.emit('data', item)
// console.log('after emit', chunks, flowing);
}

if (chunks <= 0) {
oldEnded = true
// console.log('old end', chunks, flowing);
Expand Down
18 changes: 3 additions & 15 deletions test/common/fixtures.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import fixtures from './fixtures.js';
import fixtures from './fixtures.js'

const {
fixturesDir,
path,
fileURL,
readSync,
readKey,
} = fixtures;
const { fixturesDir, path, fileURL, readSync, readKey } = fixtures

export {
fixturesDir,
path,
fileURL,
readSync,
readKey,
};
export { fixturesDir, path, fileURL, readSync, readKey }
33 changes: 28 additions & 5 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,24 @@ const { atob, btoa } = require('buffer')
if (isMainThread) process.umask(0o022)
const noop = () => {}
const hasCrypto = Boolean(process.versions.openssl) && !process.env.NODE_SKIP_CRYPTO
const hasOpenSSL3 = hasCrypto && require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30000000
const hasOpenSSL31 = hasCrypto && require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30100000

// Synthesize OPENSSL_VERSION_NUMBER format with the layout 0xMNN00PPSL
const opensslVersionNumber = (major = 0, minor = 0, patch = 0) => {
assert(major >= 0 && major <= 0xf)
assert(minor >= 0 && minor <= 0xff)
assert(patch >= 0 && patch <= 0xff)
return (major << 28) | (minor << 20) | (patch << 4)
}
let OPENSSL_VERSION_NUMBER
const hasOpenSSL = (major = 0, minor = 0, patch = 0) => {
if (!hasCrypto) return false
if (OPENSSL_VERSION_NUMBER === undefined) {
const regexp = /(?<m>\d+)\.(?<n>\d+)\.(?<p>\d+)/
const { m, n, p } = process.versions.openssl.match(regexp).groups
OPENSSL_VERSION_NUMBER = opensslVersionNumber(m, n, p)
}
return OPENSSL_VERSION_NUMBER >= opensslVersionNumber(major, minor, patch)
}
const hasQuic = hasCrypto && !!process.config.variables.openssl_quic
function parseTestFlags(filename = process.argv[1]) {
// The copyright notice is relatively big and the flags could come afterwards.
Expand Down Expand Up @@ -826,8 +842,7 @@ const common = {
getTTYfd,
hasIntl,
hasCrypto,
hasOpenSSL3,
hasOpenSSL31,
hasOpenSSL,
hasQuic,
hasMultiLocalhost,
invalidArgTypeHelper,
Expand Down Expand Up @@ -866,7 +881,6 @@ const common = {
get enoughTestMem() {
return require('os').totalmem() > 0x70000000 /* 1.75 Gb */
},

get hasFipsCrypto() {
return hasCrypto && require('crypto').getFips()
},
Expand All @@ -884,6 +898,15 @@ const common = {
return re.test(name) && iFaces[name].some(({ family }) => family === 'IPv6')
})
},
get hasOpenSSL3() {
return hasOpenSSL(3)
},
get hasOpenSSL31() {
return hasOpenSSL(3, 1)
},
get hasOpenSSL32() {
return hasOpenSSL(3, 2)
},
get inFreeBSDJail() {
if (inFreeBSDJail !== null) return inFreeBSDJail
if (exports.isFreeBSD && execSync('sysctl -n security.jail.jailed').toString() === '1\n') {
Expand Down
16 changes: 8 additions & 8 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRequire } from 'module';
import { createRequire } from 'module'

const require = createRequire(import.meta.url);
const common = require('./index.js');
const require = createRequire(import.meta.url)
const common = require('./index.js')

const {
allowGlobals,
Expand Down Expand Up @@ -50,10 +50,10 @@ const {
skipIfDumbTerminal,
skipIfEslintMissing,
skipIfInspectorDisabled,
spawnPromisified,
} = common;
spawnPromisified
} = common

const getPort = () => common.PORT;
const getPort = () => common.PORT

export {
allowGlobals,
Expand Down Expand Up @@ -104,5 +104,5 @@ export {
skipIfDumbTerminal,
skipIfEslintMissing,
skipIfInspectorDisabled,
spawnPromisified,
};
spawnPromisified
}
2 changes: 1 addition & 1 deletion test/fixtures/tz-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023c
2024a
Loading
Loading