Skip to content

Commit

Permalink
Rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Dec 31, 2024
1 parent 2bad0eb commit 409c87e
Show file tree
Hide file tree
Showing 22 changed files with 409 additions and 356 deletions.
8 changes: 5 additions & 3 deletions lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Ported from https://github.com/mafintosh/end-of-stream with
// permission from the author, Mathias Buus (@mafintosh).

'use strict'

/* replacement start */

const process = require('process/')

/* replacement end */
// Ported from https://github.com/mafintosh/end-of-stream with
// permission from the author, Mathias Buus (@mafintosh).

;('use strict')
const { AbortError, codes } = require('../../ours/errors')
const { ERR_INVALID_ARG_TYPE, ERR_STREAM_PREMATURE_CLOSE } = codes
const { kEmptyObject, once } = require('../../ours/util')
Expand Down
14 changes: 8 additions & 6 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* replacement start */

const process = require('process/')

/* replacement end */
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -24,7 +19,14 @@ const process = require('process/')
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

;('use strict')
'use strict'

/* replacement start */

const process = require('process/')

/* replacement end */

const {
ArrayPrototypeIndexOf,
NumberIsInteger,
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
14 changes: 8 additions & 6 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* replacement start */

const process = require('process/')

/* replacement end */
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -28,7 +23,14 @@ const process = require('process/')
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
// the drain event emission and buffering.

;('use strict')
'use strict'

/* replacement start */

const process = require('process/')

/* replacement end */

const {
ArrayPrototypeSlice,
Error,
Expand Down
8 changes: 5 additions & 3 deletions lib/ours/errors.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict'

const { format, inspect, AggregateError: CustomAggregateError } = require('./util')
const { format, inspect } = require('./util/inspect')
const { AggregateError: CustomAggregateError } = require('./primordials')

/*
This file is a reduced and adapted version of the main lib/internal/errors.js file defined at
https://github.com/nodejs/node/blob/master/lib/internal/errors.js
https://github.com/nodejs/node/blob/main/lib/internal/errors.js
Don't try to replace with the original file and keep it up to date (starting from E(...) definitions)
with the upstream file.
Expand Down Expand Up @@ -311,7 +312,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
21 changes: 19 additions & 2 deletions lib/ours/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,28 @@
/*
This file is a reduced and adapted version of the main lib/internal/per_context/primordials.js file defined at
https://github.com/nodejs/node/blob/master/lib/internal/per_context/primordials.js
https://github.com/nodejs/node/blob/main/lib/internal/per_context/primordials.js
Don't try to replace with the original file and keep it up to date with the upstream file.
*/

// This is a simplified version of AggregateError
class AggregateError extends Error {
constructor(errors) {
if (!Array.isArray(errors)) {
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
}
let message = ''
for (let i = 0; i < errors.length; i++) {
message += ` ${errors[i].stack}\n`
}
super(message)
this.name = 'AggregateError'
this.errors = errors
}
}
module.exports = {
AggregateError,
ArrayIsArray(self) {
return Array.isArray(self)
},
Expand Down Expand Up @@ -102,6 +119,6 @@ module.exports = {
TypedArrayPrototypeSet(self, buf, len) {
return self.set(buf, len)
},
Boolean: Boolean,
Boolean,
Uint8Array
}
70 changes: 9 additions & 61 deletions lib/ours/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict'

const bufferModule = require('buffer')
const { kResistStopPropagation, SymbolDispose } = require('./primordials')
const { format, inspect } = require('./util/inspect')
const {
codes: { ERR_INVALID_ARG_TYPE }
} = require('./errors')
const { kResistStopPropagation, AggregateError, SymbolDispose } = require('./primordials')
const AbortSignal = globalThis.AbortSignal || require('abort-controller').AbortSignal
const AbortController = globalThis.AbortController || require('abort-controller').AbortController
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
Expand All @@ -24,22 +28,8 @@ const validateAbortSignal = (signal, name) => {
}
}
const validateFunction = (value, name) => {
if (typeof value !== 'function') throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
}

// This is a simplified version of AggregateError
class AggregateError extends Error {
constructor(errors) {
if (!Array.isArray(errors)) {
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
}
let message = ''
for (let i = 0; i < errors.length; i++) {
message += ` ${errors[i].stack}\n`
}
super(message)
this.name = 'AggregateError'
this.errors = errors
if (typeof value !== 'function') {
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
}
}
module.exports = {
Expand Down Expand Up @@ -83,50 +73,8 @@ module.exports = {
debuglog() {
return function () {}
},
format(format, ...args) {
// Simplified version of https://nodejs.org/api/util.html#utilformatformat-args
return format.replace(/%([sdifj])/g, function (...[_unused, type]) {
const replacement = args.shift()
if (type === 'f') {
return replacement.toFixed(6)
} else if (type === 'j') {
return JSON.stringify(replacement)
} else if (type === 's' && typeof replacement === 'object') {
const ctor = replacement.constructor !== Object ? replacement.constructor.name : ''
return `${ctor} {}`.trim()
} else {
return replacement.toString()
}
})
},
inspect(value) {
// Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options
switch (typeof value) {
case 'string':
if (value.includes("'")) {
if (!value.includes('"')) {
return `"${value}"`
} else if (!value.includes('`') && !value.includes('${')) {
return `\`${value}\``
}
}
return `'${value}'`
case 'number':
if (isNaN(value)) {
return 'NaN'
} else if (Object.is(value, -0)) {
return String(value)
}
return value
case 'bigint':
return `${String(value)}n`
case 'boolean':
case 'undefined':
return String(value)
case 'object':
return '{}'
}
},
format,
inspect,
types: {
isAsyncFunction(fn) {
return fn instanceof AsyncFunction
Expand Down
55 changes: 55 additions & 0 deletions lib/ours/util/inspect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict'

/*
This file is a reduced and adapted version of the main lib/internal/util/inspect.js file defined at
https://github.com/nodejs/node/blob/main/lib/internal/util/inspect.js
Don't try to replace with the original file and keep it up to date with the upstream file.
*/
module.exports = {
format(format, ...args) {
// Simplified version of https://nodejs.org/api/util.html#utilformatformat-args
return format.replace(/%([sdifj])/g, function (...[_unused, type]) {
const replacement = args.shift()
if (type === 'f') {
return replacement.toFixed(6)
} else if (type === 'j') {
return JSON.stringify(replacement)
} else if (type === 's' && typeof replacement === 'object') {
const ctor = replacement.constructor !== Object ? replacement.constructor.name : ''
return `${ctor} {}`.trim()
} else {
return replacement.toString()
}
})
},
inspect(value) {
// Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options
switch (typeof value) {
case 'string':
if (value.includes("'")) {
if (!value.includes('"')) {
return `"${value}"`
} else if (!value.includes('`') && !value.includes('${')) {
return `\`${value}\``
}
}
return `'${value}'`
case 'number':
if (isNaN(value)) {
return 'NaN'
} else if (Object.is(value, -0)) {
return String(value)
}
return value
case 'bigint':
return `${String(value)}n`
case 'boolean':
case 'undefined':
return String(value)
case 'object':
return '{}'
}
}
}
14 changes: 8 additions & 6 deletions lib/stream.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* replacement start */

const { Buffer } = require('buffer')

/* replacement end */
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -24,7 +19,14 @@ const { Buffer } = require('buffer')
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

;('use strict')
'use strict'

/* replacement start */

const { Buffer } = require('buffer')

/* replacement end */

const { ObjectDefineProperty, ObjectKeys, ReflectApply } = require('./ours/primordials')
const {
promisify: { custom: customPromisify }
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 }
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

0 comments on commit 409c87e

Please sign in to comment.