Skip to content
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

Fix string_decoder import #548

Merged
merged 5 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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',
},
},
]

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/')
MattiasBuelens marked this conversation as resolved.
Show resolved Hide resolved
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.19.0",
"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
}
100 changes: 53 additions & 47 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ const isBlob =
/* eslint-enable indent */

const validateAbortSignal = (signal, name) => {
if (signal !== undefined &&
(signal === null ||
typeof signal !== 'object' ||
!('aborted' in signal))) {
throw new ERR_INVALID_ARG_TYPE(name, 'AbortSignal', signal);
if (signal !== undefined && (signal === null || typeof signal !== 'object' || !('aborted' in 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 @@ -153,45 +151,53 @@ module.exports = {
deprecate(fn, message) {
return fn
},
addAbortListener: require('events').addAbortListener || function addAbortListener(signal, listener) {
if (signal === undefined) {
throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal);
}
validateAbortSignal(signal, 'signal');
validateFunction(listener, 'listener');

let removeEventListener;
if (signal.aborted) {
queueMicrotask(() => listener());
} else {
signal.addEventListener('abort', listener, { __proto__: null, once: true, [kResistStopPropagation]: true });
removeEventListener = () => {
signal.removeEventListener('abort', listener);
};
}
return {
__proto__: null,
[SymbolDispose]() {
removeEventListener?.();
},
};
},
AbortSignalAny: AbortSignal.any || function AbortSignalAny(signals) {
// Fast path if there is only one signal.
if (signals.length === 1) {
return signals[0]
addAbortListener:
require('events').addAbortListener ||
function addAbortListener(signal, listener) {
if (signal === undefined) {
throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal)
}
validateAbortSignal(signal, 'signal')
validateFunction(listener, 'listener')

let removeEventListener
if (signal.aborted) {
queueMicrotask(() => listener())
} else {
signal.addEventListener('abort', listener, { __proto__: null, once: true, [kResistStopPropagation]: true })
removeEventListener = () => {
signal.removeEventListener('abort', listener)
}
}
return {
__proto__: null,
[SymbolDispose]() {
removeEventListener?.()
}
}
},
AbortSignalAny:
AbortSignal.any ||
function AbortSignalAny(signals) {
// Fast path if there is only one signal.
if (signals.length === 1) {
return signals[0]
}
const ac = new AbortController()
const abort = () => ac.abort()
signals.forEach((signal) => {
validateAbortSignal(signal, 'signals')
signal.addEventListener('abort', abort, { once: true })
})
ac.signal.addEventListener(
'abort',
() => {
signals.forEach((signal) => signal.removeEventListener('abort', abort))
},
{ once: true }
)
return ac.signal
}
const ac = new AbortController()
const abort = () => ac.abort()
signals.forEach(signal => {
validateAbortSignal(signal, 'signals')
signal.addEventListener('abort', abort, { once: true })
})
ac.signal.addEventListener('abort', () => {
signals.forEach(signal => signal.removeEventListener('abort', abort))
}, { once: true })
return ac.signal
}
}

module.exports.promisify.custom = Symbol.for('nodejs.util.promisify.custom')
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 }
1 change: 0 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,6 @@ const common = {
get enoughTestMem() {
return require('os').totalmem() > 0x70000000 /* 1.75 Gb */
},

get hasFipsCrypto() {
return hasCrypto && require('crypto').getFips()
},
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
}
Loading
Loading