Skip to content

Commit ea6995f

Browse files
committed
fix: use workaround loading process-shim for browserify
1 parent 7fdb3b4 commit ea6995f

File tree

272 files changed

+1953
-4666
lines changed

Some content is hidden

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

272 files changed

+1953
-4666
lines changed

README.md

+1-21
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,7 @@ shown in the example above.
8787

8888
## Usage In Browsers
8989

90-
You will need a bundler like [`browserify`](https://github.com/browserify/browserify#readme), [`webpack`](https://webpack.js.org/), [`parcel`](https://github.com/parcel-bundler/parcel#readme) or similar. With Webpack 5 (which unlike other bundlers does not polyfill Node.js core modules and globals like `process`) you will also need to:
91-
92-
1. Install polyfills by running `npm install buffer process --save-dev`
93-
2. Create a [`webpack.config.js`](https://webpack.js.org/guides/getting-started/#using-a-configuration) file containing:
94-
95-
```js
96-
const webpack = require('webpack')
97-
98-
module.exports = {
99-
plugins: [
100-
new webpack.ProvidePlugin({
101-
process: 'process/browser'
102-
})
103-
],
104-
resolve: {
105-
fallback: {
106-
buffer: require.resolve('buffer/')
107-
}
108-
}
109-
}
110-
```
90+
You will need a bundler like [`browserify`](https://github.com/browserify/browserify#readme), [`webpack`](https://webpack.js.org/), [`parcel`](https://github.com/parcel-bundler/parcel#readme) or similar. Polyfills are no longer required since version 4.2.0.
11191

11292
# Streams Working Group
11393

build/headers.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const bufferRequire = `
99
const processRequire = `
1010
/* replacement start */
1111
12-
const process = require('process')
12+
const process = require('process/')
1313
1414
/* replacement end */
1515
`

lib/_stream_duplex.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
'use strict' // Keep this file as an alias for the full stream module.
1+
'use strict'
22

3+
// Keep this file as an alias for the full stream module.
34
module.exports = require('./stream').Duplex

lib/_stream_passthrough.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
'use strict' // Keep this file as an alias for the full stream module.
1+
'use strict'
22

3+
// Keep this file as an alias for the full stream module.
34
module.exports = require('./stream').PassThrough

lib/_stream_readable.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
'use strict' // Keep this file as an alias for the full stream module.
1+
'use strict'
22

3+
// Keep this file as an alias for the full stream module.
34
module.exports = require('./stream').Readable

lib/_stream_transform.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
'use strict' // Keep this file as an alias for the full stream module.
1+
'use strict'
22

3+
// Keep this file as an alias for the full stream module.
34
module.exports = require('./stream').Transform

lib/_stream_writable.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
'use strict' // Keep this file as an alias for the full stream module.
1+
'use strict'
22

3+
// Keep this file as an alias for the full stream module.
34
module.exports = require('./stream').Writable
+2-11
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,43 @@
11
'use strict'
22

33
const { AbortError, codes } = require('../../ours/errors')
4-
54
const eos = require('./end-of-stream')
5+
const { ERR_INVALID_ARG_TYPE } = codes
66

7-
const { ERR_INVALID_ARG_TYPE } = codes // This method is inlined here for readable-stream
7+
// This method is inlined here for readable-stream
88
// It also does not allow for signal to not exist on the stream
99
// https://github.com/nodejs/node/pull/36061#discussion_r533718029
10-
1110
const validateAbortSignal = (signal, name) => {
1211
if (typeof signal !== 'object' || !('aborted' in signal)) {
1312
throw new ERR_INVALID_ARG_TYPE(name, 'AbortSignal', signal)
1413
}
1514
}
16-
1715
function isNodeStream(obj) {
1816
return !!(obj && typeof obj.pipe === 'function')
1917
}
20-
2118
module.exports.addAbortSignal = function addAbortSignal(signal, stream) {
2219
validateAbortSignal(signal, 'signal')
23-
2420
if (!isNodeStream(stream)) {
2521
throw new ERR_INVALID_ARG_TYPE('stream', 'stream.Stream', stream)
2622
}
27-
2823
return module.exports.addAbortSignalNoValidate(signal, stream)
2924
}
30-
3125
module.exports.addAbortSignalNoValidate = function (signal, stream) {
3226
if (typeof signal !== 'object' || !('aborted' in signal)) {
3327
return stream
3428
}
35-
3629
const onAbort = () => {
3730
stream.destroy(
3831
new AbortError(undefined, {
3932
cause: signal.reason
4033
})
4134
)
4235
}
43-
4436
if (signal.aborted) {
4537
onAbort()
4638
} else {
4739
signal.addEventListener('abort', onAbort)
4840
eos(stream, () => signal.removeEventListener('abort', onAbort))
4941
}
50-
5142
return stream
5243
}

lib/internal/streams/buffer_list.js

+10-33
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
'use strict'
22

33
const { StringPrototypeSlice, SymbolIterator, TypedArrayPrototypeSet, Uint8Array } = require('../../ours/primordials')
4-
54
const { Buffer } = require('buffer')
6-
75
const { inspect } = require('../../ours/util')
8-
96
module.exports = class BufferList {
107
constructor() {
118
this.head = null
129
this.tail = null
1310
this.length = 0
1411
}
15-
1612
push(v) {
1713
const entry = {
1814
data: v,
@@ -23,7 +19,6 @@ module.exports = class BufferList {
2319
this.tail = entry
2420
++this.length
2521
}
26-
2722
unshift(v) {
2823
const entry = {
2924
data: v,
@@ -33,7 +28,6 @@ module.exports = class BufferList {
3328
this.head = entry
3429
++this.length
3530
}
36-
3731
shift() {
3832
if (this.length === 0) return
3933
const ret = this.head.data
@@ -42,73 +36,62 @@ module.exports = class BufferList {
4236
--this.length
4337
return ret
4438
}
45-
4639
clear() {
4740
this.head = this.tail = null
4841
this.length = 0
4942
}
50-
5143
join(s) {
5244
if (this.length === 0) return ''
5345
let p = this.head
5446
let ret = '' + p.data
55-
5647
while ((p = p.next) !== null) ret += s + p.data
57-
5848
return ret
5949
}
60-
6150
concat(n) {
6251
if (this.length === 0) return Buffer.alloc(0)
6352
const ret = Buffer.allocUnsafe(n >>> 0)
6453
let p = this.head
6554
let i = 0
66-
6755
while (p) {
6856
TypedArrayPrototypeSet(ret, p.data, i)
6957
i += p.data.length
7058
p = p.next
7159
}
72-
7360
return ret
74-
} // Consumes a specified amount of bytes or characters from the buffered data.
61+
}
7562

63+
// Consumes a specified amount of bytes or characters from the buffered data.
7664
consume(n, hasStrings) {
7765
const data = this.head.data
78-
7966
if (n < data.length) {
8067
// `slice` is the same for buffers and strings.
8168
const slice = data.slice(0, n)
8269
this.head.data = data.slice(n)
8370
return slice
8471
}
85-
8672
if (n === data.length) {
8773
// First chunk is a perfect match.
8874
return this.shift()
89-
} // Result spans more than one buffer.
90-
75+
}
76+
// Result spans more than one buffer.
9177
return hasStrings ? this._getString(n) : this._getBuffer(n)
9278
}
93-
9479
first() {
9580
return this.head.data
9681
}
97-
9882
*[SymbolIterator]() {
9983
for (let p = this.head; p; p = p.next) {
10084
yield p.data
10185
}
102-
} // Consumes a specified amount of characters from the buffered data.
86+
}
10387

88+
// Consumes a specified amount of characters from the buffered data.
10489
_getString(n) {
10590
let ret = ''
10691
let p = this.head
10792
let c = 0
108-
10993
do {
11094
const str = p.data
111-
11295
if (n > str.length) {
11396
ret += str
11497
n -= str.length
@@ -123,26 +106,22 @@ module.exports = class BufferList {
123106
this.head = p
124107
p.data = StringPrototypeSlice(str, n)
125108
}
126-
127109
break
128110
}
129-
130111
++c
131112
} while ((p = p.next) !== null)
132-
133113
this.length -= c
134114
return ret
135-
} // Consumes a specified amount of bytes from the buffered data.
115+
}
136116

117+
// Consumes a specified amount of bytes from the buffered data.
137118
_getBuffer(n) {
138119
const ret = Buffer.allocUnsafe(n)
139120
const retLen = n
140121
let p = this.head
141122
let c = 0
142-
143123
do {
144124
const buf = p.data
145-
146125
if (n > buf.length) {
147126
TypedArrayPrototypeSet(ret, buf, retLen - n)
148127
n -= buf.length
@@ -157,17 +136,15 @@ module.exports = class BufferList {
157136
this.head = p
158137
p.data = buf.slice(n)
159138
}
160-
161139
break
162140
}
163-
164141
++c
165142
} while ((p = p.next) !== null)
166-
167143
this.length -= c
168144
return ret
169-
} // Make sure the linked list only shows the minimal necessary information.
145+
}
170146

147+
// Make sure the linked list only shows the minimal necessary information.
171148
[Symbol.for('nodejs.util.inspect.custom')](_, options) {
172149
return inspect(this, {
173150
...options,

0 commit comments

Comments
 (0)