Skip to content

Commit 434aea0

Browse files
Update build for #542 (#549)
1 parent 4281bc0 commit 434aea0

File tree

13 files changed

+203
-155
lines changed

13 files changed

+203
-155
lines changed

Diff for: build/build.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { headers } from './headers.mjs'
1515
import { replacements } from './replacements.mjs'
1616

1717
const baseMatcher = /^(?:lib|test)/
18-
const strictMatcher = /^(['"']use strict.+)/
18+
const strictMatcher = /^(['"]use strict.+)/m
1919

2020
function highlightFile(file, color) {
2121
return `\x1b[${color}m${file.replace(process.cwd() + '/', '')}\x1b[0m`
@@ -195,6 +195,7 @@ async function main() {
195195
contents.push(['lib/ours/errors.js', await readFile('src/errors.js', 'utf-8')])
196196
contents.push(['lib/ours/primordials.js', await readFile('src/primordials.js', 'utf-8')])
197197
contents.push(['lib/ours/util.js', await readFile('src/util.js', 'utf-8')])
198+
contents.push(['lib/ours/util/inspect.js', await readFile('src/util/inspect.js', 'utf-8')])
198199

199200
for (const file of await readdir('src/test/ours')) {
200201
contents.push([`test/ours/${file}`, await readFile(`src/test/ours/${file}`, 'utf-8')])

Diff for: 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')

Diff for: 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,

Diff for: 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,

Diff for: lib/ours/errors.js

+3-2
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.

Diff for: lib/ours/primordials.js

+18-1
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
},

Diff for: lib/ours/util.js

+7-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
@@ -28,22 +32,6 @@ const validateFunction = (value, name) => {
2832
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
2933
}
3034
}
31-
32-
// This is a simplified version of AggregateError
33-
class AggregateError extends Error {
34-
constructor(errors) {
35-
if (!Array.isArray(errors)) {
36-
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
37-
}
38-
let message = ''
39-
for (let i = 0; i < errors.length; i++) {
40-
message += ` ${errors[i].stack}\n`
41-
}
42-
super(message)
43-
this.name = 'AggregateError'
44-
this.errors = errors
45-
}
46-
}
4735
module.exports = {
4836
AggregateError,
4937
kEmptyObject: Object.freeze({}),
@@ -85,50 +73,8 @@ module.exports = {
8573
debuglog() {
8674
return function () {}
8775
},
88-
format(format, ...args) {
89-
// Simplified version of https://nodejs.org/api/util.html#utilformatformat-args
90-
return format.replace(/%([sdifj])/g, function (...[_unused, type]) {
91-
const replacement = args.shift()
92-
if (type === 'f') {
93-
return replacement.toFixed(6)
94-
} else if (type === 'j') {
95-
return JSON.stringify(replacement)
96-
} else if (type === 's' && typeof replacement === 'object') {
97-
const ctor = replacement.constructor !== Object ? replacement.constructor.name : ''
98-
return `${ctor} {}`.trim()
99-
} else {
100-
return replacement.toString()
101-
}
102-
})
103-
},
104-
inspect(value) {
105-
// Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options
106-
switch (typeof value) {
107-
case 'string':
108-
if (value.includes("'")) {
109-
if (!value.includes('"')) {
110-
return `"${value}"`
111-
} else if (!value.includes('`') && !value.includes('${')) {
112-
return `\`${value}\``
113-
}
114-
}
115-
return `'${value}'`
116-
case 'number':
117-
if (isNaN(value)) {
118-
return 'NaN'
119-
} else if (Object.is(value, -0)) {
120-
return String(value)
121-
}
122-
return value
123-
case 'bigint':
124-
return `${String(value)}n`
125-
case 'boolean':
126-
case 'undefined':
127-
return String(value)
128-
case 'object':
129-
return '{}'
130-
}
131-
},
76+
format,
77+
inspect,
13278
types: {
13379
isAsyncFunction(fn) {
13480
return fn instanceof AsyncFunction

Diff for: 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+
}

Diff for: 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 }

Diff for: src/errors.js

+3-2
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.

Diff for: src/primordials.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,31 @@
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
*/
1010

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+
18+
let message = ''
19+
for (let i = 0; i < errors.length; i++) {
20+
message += ` ${errors[i].stack}\n`
21+
}
22+
23+
super(message)
24+
this.name = 'AggregateError'
25+
this.errors = errors
26+
}
27+
}
28+
1129
module.exports = {
30+
AggregateError,
1231
ArrayIsArray(self) {
1332
return Array.isArray(self)
1433
},

0 commit comments

Comments
 (0)