Skip to content

Commit a2a1689

Browse files
committed
feat: use buffer, events, process dependencies and require it
1 parent e95c761 commit a2a1689

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+209
-53
lines changed

build/headers.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
const bufferRequire = `
2+
/* replacement start */
3+
4+
const { Buffer } = require('buffer')
5+
6+
/* replacement end */
7+
`
8+
9+
const processRequire = `
10+
/* replacement start */
11+
12+
const process = require('process')
13+
14+
/* replacement end */
15+
`
16+
117
const testPolyfills = `
218
/* replacement start */
319
const AbortController = globalThis.AbortController || require('abort-controller').AbortController;
@@ -16,6 +32,16 @@ const testPolyfills = `
1632
`
1733

1834
export const headers = {
35+
'lib/stream.js':
36+
[bufferRequire],
37+
'lib/internal/streams/(destroy|duplexify|end-of-stream|from|pipeline|readable|writable).js':
38+
[processRequire],
39+
'test/browser/test-stream-(big-packet|pipe-cleanup-pause|pipeline|readable-event|transform-constructor-set-methods|transform-split-objectmode|unshift-empty-chunk|unshift-read-race|writable-change-default-encoding|writable-constructor-set-methods|writable-decoded-encoding|writev).js':
40+
[bufferRequire],
41+
'test/browser/test-stream2-(base64-single-char-read-end|compatibility|large-read-stall|pipe-error-handling|readable-empty-buffer-no-eof|readable-from-list|readable-legacy-drain|readable-non-empty-end|readable-wrap|set-encoding|transform|writable).js':
42+
[bufferRequire],
43+
'test/browser/test-stream3-pause-then-read.js':
44+
[bufferRequire],
1945
'test/parallel/test-stream-(add-abort-signal|drop-take|duplex-destroy|flatMap|forEach|filter|finished|readable-destroy|reduce|toArray|writable-destroy).js':
2046
[testPolyfills]
2147
}

build/replacements.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ const internalStreamsNoRequireAbortController = [
3434

3535
const internalStreamsRequireInternal = ["require\\('internal/([^']+)'\\)", "require('../$1')"]
3636

37-
const internalStreamsNoRequireBuffer = ["const \\{ Buffer \\} = require\\('buffer'\\);", '']
38-
3937
const internalStreamsRequireErrors = ["require\\('internal/errors'\\)", "require('../../ours/errors')"]
4038

4139
const internalStreamsRequireEventEmitter = ['const EE =', 'const { EventEmitter: EE } =']
@@ -233,7 +231,6 @@ export const replacements = {
233231
internalStreamsNoRequireAbortController
234232
],
235233
'lib/internal/streams/.+': [
236-
internalStreamsNoRequireBuffer,
237234
internalStreamsRequireErrors,
238235
internalStreamsRequireEventEmitter,
239236
internalStreamsRequirePrimordials,

lib/internal/streams/buffer_list.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const { StringPrototypeSlice, SymbolIterator, TypedArrayPrototypeSet, Uint8Array } = require('../../ours/primordials')
44

5+
const { Buffer } = require('buffer')
6+
57
const { inspect } = require('../../ours/util')
68

79
module.exports = class BufferList {

lib/internal/streams/destroy.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
'use strict'
1+
/* replacement start */
2+
const process = require('process')
3+
/* replacement end */
4+
5+
;('use strict')
26

37
const {
48
aggregateTwoErrors,

lib/internal/streams/duplexify.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
'use strict'
1+
/* replacement start */
2+
const process = require('process')
3+
/* replacement end */
4+
5+
;('use strict')
26

37
const bufferModule = require('buffer')
48

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
/* replacement start */
2+
const process = require('process')
3+
/* replacement end */
14
// Ported from https://github.com/mafintosh/end-of-stream with
25
// permission from the author, Mathias Buus (@mafintosh).
3-
'use strict'
6+
7+
;('use strict')
48

59
const { AbortError, codes } = require('../../ours/errors')
610

lib/internal/streams/from.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
'use strict'
1+
/* replacement start */
2+
const process = require('process')
3+
/* replacement end */
4+
5+
;('use strict')
26

37
const { PromisePrototypeThen, SymbolAsyncIterator, SymbolIterator } = require('../../ours/primordials')
48

9+
const { Buffer } = require('buffer')
10+
511
const { ERR_INVALID_ARG_TYPE, ERR_STREAM_NULL_VALUES } = require('../../ours/errors').codes
612

713
function from(Readable, iterable, opts) {

lib/internal/streams/pipeline.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
/* replacement start */
2+
const process = require('process')
3+
/* replacement end */
14
// Ported from https://github.com/mafintosh/pump with
25
// permission from the author, Mathias Buus (@mafintosh).
3-
'use strict'
6+
7+
;('use strict')
48

59
const { ArrayIsArray, Promise, SymbolAsyncIterator } = require('../../ours/primordials')
610

lib/internal/streams/readable.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* replacement start */
2+
const process = require('process')
3+
/* replacement end */
14
// Copyright Joyent, Inc. and other Node contributors.
25
//
36
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +21,8 @@
1821
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1922
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2023
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
'use strict'
24+
25+
;('use strict')
2226

2327
const {
2428
ArrayPrototypeIndexOf,
@@ -41,6 +45,8 @@ const { EventEmitter: EE } = require('events')
4145

4246
const { Stream, prependListener } = require('./legacy')
4347

48+
const { Buffer } = require('buffer')
49+
4450
const { addAbortSignal } = require('./add-abort-signal')
4551

4652
const eos = require('./end-of-stream')

lib/internal/streams/writable.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* replacement start */
2+
const process = require('process')
3+
/* replacement end */
14
// Copyright Joyent, Inc. and other Node contributors.
25
//
36
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -21,7 +24,8 @@
2124
// A bit simpler than readable streams.
2225
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
2326
// the drain event emission and buffering.
24-
'use strict'
27+
28+
;('use strict')
2529

2630
const {
2731
ArrayPrototypeSlice,
@@ -42,6 +46,8 @@ const { EventEmitter: EE } = require('events')
4246

4347
const Stream = require('./legacy').Stream
4448

49+
const { Buffer } = require('buffer')
50+
4551
const destroyImpl = require('./destroy')
4652

4753
const { addAbortSignal } = require('./add-abort-signal')

0 commit comments

Comments
 (0)