Skip to content

Commit 409c87e

Browse files
Rebuild
1 parent 2bad0eb commit 409c87e

22 files changed

+409
-356
lines changed

lib/internal/streams/end-of-stream.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
// Ported from https://github.com/mafintosh/end-of-stream with
2+
// permission from the author, Mathias Buus (@mafintosh).
3+
4+
'use strict'
5+
16
/* replacement start */
27

38
const process = require('process/')
49

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

9-
;('use strict')
1012
const { AbortError, codes } = require('../../ours/errors')
1113
const { ERR_INVALID_ARG_TYPE, ERR_STREAM_PREMATURE_CLOSE } = codes
1214
const { kEmptyObject, once } = require('../../ours/util')

lib/internal/streams/readable.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/* replacement start */
2-
3-
const process = require('process/')
4-
5-
/* replacement end */
61
// Copyright Joyent, Inc. and other Node contributors.
72
//
83
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -24,7 +19,14 @@ const process = require('process/')
2419
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2520
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2621

27-
;('use strict')
22+
'use strict'
23+
24+
/* replacement start */
25+
26+
const process = require('process/')
27+
28+
/* replacement end */
29+
2830
const {
2931
ArrayPrototypeIndexOf,
3032
NumberIsInteger,

lib/internal/streams/utils.js

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function isReadableNodeStream(obj, strict = false) {
3030
) // Writable has .pipe.
3131
)
3232
}
33-
3433
function isWritableNodeStream(obj) {
3534
var _obj$_writableState
3635
return !!(
@@ -45,7 +44,6 @@ function isWritableNodeStream(obj) {
4544
) // Duplex
4645
)
4746
}
48-
4947
function isDuplexNodeStream(obj) {
5048
return !!(
5149
obj &&

lib/internal/streams/writable.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/* replacement start */
2-
3-
const process = require('process/')
4-
5-
/* replacement end */
61
// Copyright Joyent, Inc. and other Node contributors.
72
//
83
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -28,7 +23,14 @@ const process = require('process/')
2823
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
2924
// the drain event emission and buffering.
3025

31-
;('use strict')
26+
'use strict'
27+
28+
/* replacement start */
29+
30+
const process = require('process/')
31+
32+
/* replacement end */
33+
3234
const {
3335
ArrayPrototypeSlice,
3436
Error,

lib/ours/errors.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use strict'
22

3-
const { format, inspect, AggregateError: CustomAggregateError } = require('./util')
3+
const { format, inspect } = require('./util/inspect')
4+
const { AggregateError: CustomAggregateError } = require('./primordials')
45

56
/*
67
This file is a reduced and adapted version of the main lib/internal/errors.js file defined at
78
8-
https://github.com/nodejs/node/blob/master/lib/internal/errors.js
9+
https://github.com/nodejs/node/blob/main/lib/internal/errors.js
910
1011
Don't try to replace with the original file and keep it up to date (starting from E(...) definitions)
1112
with the upstream file.
@@ -311,7 +312,8 @@ E(
311312
received = addNumericalSeparator(String(input))
312313
} else if (typeof input === 'bigint') {
313314
received = String(input)
314-
if (input > 2n ** 32n || input < -(2n ** 32n)) {
315+
const limit = BigInt(2) ** BigInt(32)
316+
if (input > limit || input < -limit) {
315317
received = addNumericalSeparator(received)
316318
}
317319
received += 'n'

lib/ours/primordials.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,28 @@
33
/*
44
This file is a reduced and adapted version of the main lib/internal/per_context/primordials.js file defined at
55
6-
https://github.com/nodejs/node/blob/master/lib/internal/per_context/primordials.js
6+
https://github.com/nodejs/node/blob/main/lib/internal/per_context/primordials.js
77
88
Don't try to replace with the original file and keep it up to date with the upstream file.
99
*/
10+
11+
// This is a simplified version of AggregateError
12+
class AggregateError extends Error {
13+
constructor(errors) {
14+
if (!Array.isArray(errors)) {
15+
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
16+
}
17+
let message = ''
18+
for (let i = 0; i < errors.length; i++) {
19+
message += ` ${errors[i].stack}\n`
20+
}
21+
super(message)
22+
this.name = 'AggregateError'
23+
this.errors = errors
24+
}
25+
}
1026
module.exports = {
27+
AggregateError,
1128
ArrayIsArray(self) {
1229
return Array.isArray(self)
1330
},
@@ -102,6 +119,6 @@ module.exports = {
102119
TypedArrayPrototypeSet(self, buf, len) {
103120
return self.set(buf, len)
104121
},
105-
Boolean: Boolean,
122+
Boolean,
106123
Uint8Array
107124
}

lib/ours/util.js

+9-61
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
'use strict'
22

33
const bufferModule = require('buffer')
4-
const { kResistStopPropagation, SymbolDispose } = require('./primordials')
4+
const { format, inspect } = require('./util/inspect')
5+
const {
6+
codes: { ERR_INVALID_ARG_TYPE }
7+
} = require('./errors')
8+
const { kResistStopPropagation, AggregateError, SymbolDispose } = require('./primordials')
59
const AbortSignal = globalThis.AbortSignal || require('abort-controller').AbortSignal
610
const AbortController = globalThis.AbortController || require('abort-controller').AbortController
711
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
@@ -24,22 +28,8 @@ const validateAbortSignal = (signal, name) => {
2428
}
2529
}
2630
const validateFunction = (value, name) => {
27-
if (typeof value !== 'function') throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
28-
}
29-
30-
// This is a simplified version of AggregateError
31-
class AggregateError extends Error {
32-
constructor(errors) {
33-
if (!Array.isArray(errors)) {
34-
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
35-
}
36-
let message = ''
37-
for (let i = 0; i < errors.length; i++) {
38-
message += ` ${errors[i].stack}\n`
39-
}
40-
super(message)
41-
this.name = 'AggregateError'
42-
this.errors = errors
31+
if (typeof value !== 'function') {
32+
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
4333
}
4434
}
4535
module.exports = {
@@ -83,50 +73,8 @@ module.exports = {
8373
debuglog() {
8474
return function () {}
8575
},
86-
format(format, ...args) {
87-
// Simplified version of https://nodejs.org/api/util.html#utilformatformat-args
88-
return format.replace(/%([sdifj])/g, function (...[_unused, type]) {
89-
const replacement = args.shift()
90-
if (type === 'f') {
91-
return replacement.toFixed(6)
92-
} else if (type === 'j') {
93-
return JSON.stringify(replacement)
94-
} else if (type === 's' && typeof replacement === 'object') {
95-
const ctor = replacement.constructor !== Object ? replacement.constructor.name : ''
96-
return `${ctor} {}`.trim()
97-
} else {
98-
return replacement.toString()
99-
}
100-
})
101-
},
102-
inspect(value) {
103-
// Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options
104-
switch (typeof value) {
105-
case 'string':
106-
if (value.includes("'")) {
107-
if (!value.includes('"')) {
108-
return `"${value}"`
109-
} else if (!value.includes('`') && !value.includes('${')) {
110-
return `\`${value}\``
111-
}
112-
}
113-
return `'${value}'`
114-
case 'number':
115-
if (isNaN(value)) {
116-
return 'NaN'
117-
} else if (Object.is(value, -0)) {
118-
return String(value)
119-
}
120-
return value
121-
case 'bigint':
122-
return `${String(value)}n`
123-
case 'boolean':
124-
case 'undefined':
125-
return String(value)
126-
case 'object':
127-
return '{}'
128-
}
129-
},
76+
format,
77+
inspect,
13078
types: {
13179
isAsyncFunction(fn) {
13280
return fn instanceof AsyncFunction

lib/ours/util/inspect.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict'
2+
3+
/*
4+
This file is a reduced and adapted version of the main lib/internal/util/inspect.js file defined at
5+
6+
https://github.com/nodejs/node/blob/main/lib/internal/util/inspect.js
7+
8+
Don't try to replace with the original file and keep it up to date with the upstream file.
9+
*/
10+
module.exports = {
11+
format(format, ...args) {
12+
// Simplified version of https://nodejs.org/api/util.html#utilformatformat-args
13+
return format.replace(/%([sdifj])/g, function (...[_unused, type]) {
14+
const replacement = args.shift()
15+
if (type === 'f') {
16+
return replacement.toFixed(6)
17+
} else if (type === 'j') {
18+
return JSON.stringify(replacement)
19+
} else if (type === 's' && typeof replacement === 'object') {
20+
const ctor = replacement.constructor !== Object ? replacement.constructor.name : ''
21+
return `${ctor} {}`.trim()
22+
} else {
23+
return replacement.toString()
24+
}
25+
})
26+
},
27+
inspect(value) {
28+
// Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options
29+
switch (typeof value) {
30+
case 'string':
31+
if (value.includes("'")) {
32+
if (!value.includes('"')) {
33+
return `"${value}"`
34+
} else if (!value.includes('`') && !value.includes('${')) {
35+
return `\`${value}\``
36+
}
37+
}
38+
return `'${value}'`
39+
case 'number':
40+
if (isNaN(value)) {
41+
return 'NaN'
42+
} else if (Object.is(value, -0)) {
43+
return String(value)
44+
}
45+
return value
46+
case 'bigint':
47+
return `${String(value)}n`
48+
case 'boolean':
49+
case 'undefined':
50+
return String(value)
51+
case 'object':
52+
return '{}'
53+
}
54+
}
55+
}

lib/stream.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/* replacement start */
2-
3-
const { Buffer } = require('buffer')
4-
5-
/* replacement end */
61
// Copyright Joyent, Inc. and other Node contributors.
72
//
83
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -24,7 +19,14 @@ const { Buffer } = require('buffer')
2419
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2520
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2621

27-
;('use strict')
22+
'use strict'
23+
24+
/* replacement start */
25+
26+
const { Buffer } = require('buffer')
27+
28+
/* replacement end */
29+
2830
const { ObjectDefineProperty, ObjectKeys, ReflectApply } = require('./ours/primordials')
2931
const {
3032
promisify: { custom: customPromisify }

test/browser/test-stream2-readable-wrap.js

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ module.exports = function (test) {
4747
old.emit('data', item)
4848
// console.log('after emit', chunks, flowing);
4949
}
50-
5150
if (chunks <= 0) {
5251
oldEnded = true
5352
// console.log('old end', chunks, flowing);

test/common/fixtures.mjs

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
import fixtures from './fixtures.js';
1+
import fixtures from './fixtures.js'
22

3-
const {
4-
fixturesDir,
5-
path,
6-
fileURL,
7-
readSync,
8-
readKey,
9-
} = fixtures;
3+
const { fixturesDir, path, fileURL, readSync, readKey } = fixtures
104

11-
export {
12-
fixturesDir,
13-
path,
14-
fileURL,
15-
readSync,
16-
readKey,
17-
};
5+
export { fixturesDir, path, fileURL, readSync, readKey }

test/common/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,6 @@ const common = {
866866
get enoughTestMem() {
867867
return require('os').totalmem() > 0x70000000 /* 1.75 Gb */
868868
},
869-
870869
get hasFipsCrypto() {
871870
return hasCrypto && require('crypto').getFips()
872871
},

test/common/index.mjs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createRequire } from 'module';
1+
import { createRequire } from 'module'
22

3-
const require = createRequire(import.meta.url);
4-
const common = require('./index.js');
3+
const require = createRequire(import.meta.url)
4+
const common = require('./index.js')
55

66
const {
77
allowGlobals,
@@ -50,10 +50,10 @@ const {
5050
skipIfDumbTerminal,
5151
skipIfEslintMissing,
5252
skipIfInspectorDisabled,
53-
spawnPromisified,
54-
} = common;
53+
spawnPromisified
54+
} = common
5555

56-
const getPort = () => common.PORT;
56+
const getPort = () => common.PORT
5757

5858
export {
5959
allowGlobals,
@@ -104,5 +104,5 @@ export {
104104
skipIfDumbTerminal,
105105
skipIfEslintMissing,
106106
skipIfInspectorDisabled,
107-
spawnPromisified,
108-
};
107+
spawnPromisified
108+
}

0 commit comments

Comments
 (0)