-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathreplacements.mjs
399 lines (316 loc) · 13.8 KB
/
replacements.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
const legacyStreamsRequireStream = ["require\\('stream'\\)", "require('./stream')"]
const internalStreamsBufferPolyfill = [
"'use strict'",
`
'use strict'
const bufferModule = require('buffer');
`
]
const noNodeColon = ["node:", '']
const internalStreamsAbortControllerPolyfill = [
"'use strict'",
`
'use strict'
`
]
const internalStreamsAbortControllerPolyfill2 = [
"'use strict'",
`
'use strict'
const AbortController = globalThis.AbortController || require(\'abort-controller\').AbortController;
`
]
const internalStreamsNoRequireBlob = [
"const \\{\\n isBlob,\\n\\} = require\\('internal/blob'\\);",
`
const Blob = globalThis.Blob || bufferModule.Blob;
const isBlob = typeof Blob !== 'undefined' ? function isBlob (b) { return b instanceof Blob } : function isBlob(b) { return false; }
`
]
const internalStreamsInspectCustom = ['inspect.custom', "Symbol.for('nodejs.util.inspect.custom')"]
const internalStreamsNoRequireAbortController = [
'const \\{ AbortController \\} = .+',
'const AbortController = globalThis.AbortController || require(\'abort-controller\').AbortController;'
]
const internalStreamsNoRequireAbortController2 = [
'const \\{ AbortController, AbortSignal \\} = .+',
'const AbortController = globalThis.AbortController || require(\'abort-controller\').AbortController;'
]
const internalStreamsRequireInternal = ["require\\('internal/([^']+)'\\)", "require('../$1')"]
const internalStreamsRequireErrors = ["require\\('internal/errors'\\)", "require('../../ours/errors')"]
const internalStreamsRequireEventEmitter = ['const EE =', 'const { EventEmitter: EE } =']
const internalStreamsRequirePrimordials = ['= primordials', "= require('../../ours/primordials')"]
const internalStreamsRequireRelativeUtil = [
'const \\{ (once|createDeferredPromise|) \\} = .+;',
"const { $1 } = require('../../ours/util');"
]
const internalStreamsRequireRelativeDuplex = ['instanceof Stream.Duplex', "instanceof require('./duplex')"]
const internalStreamsRequireStream = ["require\\('stream'\\)", "require('../../stream')"]
const internalStreamsRequireStreams = ["require\\('internal/streams/([^']+)'\\)", "require('./$1')"]
const streamSlashPromisesToStreamDotPromises= ["require\\('(node:)?stream/promises'\\)", "require('../../lib/stream').promises"]
const internalStreamsRequireUtil = [
"require\\('internal/util(?:/(?:debuglog|inspect))?'\\)",
"require('../../ours/util')"
]
const internalStreamsRequireUtilDebuglog = ["require\\('internal/util/debuglog'\\)", "require('../../ours/util')"]
const internalStreamsRequireWebStream = ["require\\('internal/webstreams/adapters'\\)", '{}']
const internalStreamsWeakHandler = [
"const \\{ kWeakHandler \\} = require\\('../event_target'\\);",
"require('../event_target');const kWeakHandler = require('../../ours/primordials').Symbol('kWeak');"
]
const internalStreamsWeakHandler2 = [
"const \\{ kWeakHandler, kResistStopPropagation \\} = .*;",
"const kWeakHandler = require('../../ours/primordials').Symbol('kWeak');\nconst kResistStopPropagation = require('../../ours/primordials').Symbol('kResistStopPropagation');"
]
const internalValidatorsNoCoalesceAssignment = [
'\\s*(.+) \\?\\?= (.+)',
`
if (typeof $1 === 'undefined') {
$1 = $2
}
`
]
const internalValidatorsNoRequireSignals = [
"const \\{ signals \\} = internalBinding\\('constants'\\).os;",
'const signals = {};'
]
const internalValidatorsRequireAssert = ["require\\('internal/assert'\\)", "require('assert')"]
const internalValidatorsRequireAsyncHooks = ["require\\('./async_hooks'\\)", "require('internal/async_hooks')"]
const internalValidatorsRequireErrors = ["require\\('internal/errors'\\)", "require('../ours/errors')"]
const internalValidatorsRequirePrimordials = ['= primordials', "= require('../ours/primordials')"]
const internalValidatorsRequireRelativeUtil = ["require\\('internal/util'\\)", "require('../ours/util')"]
const internalValidatorsRequireUtilTypes = ["require\\('internal/util/types'\\)", "require('../ours/util').types"]
const internalValidatorsNumericSeparator = ['4_294_967_295', '4294967295']
const streamIndexIsUint8Array = [
"Stream._isUint8Array = require\\('internal/util/types'\\).isUint8Array;",
`
Stream._isUint8Array = function isUint8Array(value) {
return value instanceof Uint8Array
};
`
]
const streamIndexRequireInternal = ["require\\('internal/([^']+)'\\)", "require('./internal/$1')"]
const streamIndexRequireInternalBuffer = ["require\\('internal/buffer'\\)", '{}']
const streamIndexRequireErrors = ["require\\('internal/errors'\\);", "require('./ours/errors');"]
const streamIndexRequirePrimordials = ['= primordials', "= require('./ours/primordials')"]
const streamIndexRequirePromises = ["require\\('stream/promises'\\);", "require('./stream/promises');"]
const streamIndexRequireUtil = ["require\\('internal/util'\\)", "require('./ours/util')"]
const streamIndexUint8ArrayToBuffer = ['new internalBuffer.FastBuffer', 'Buffer.from']
const streamsRequireErrors = ["require\\('internal/errors'\\)", "require('../ours/errors')"]
const streamsRequireInternal = ["require\\('internal/(.+)'\\)", "require('../internal/$1')"]
const streamsRequirePrimordials = ['= primordials', "= require('../ours/primordials')"]
const stringDecoderRequirePackage = ["require\\('string_decoder'\\)", "require('string_decoder/')"]
const testCommonKnownGlobals = [
'let knownGlobals = \\[(\\n\\s+)',
`
let knownGlobals = [\n
typeof AggregateError !== 'undefined' ? AggregateError : require('../../lib/ours/util').AggregateError,
typeof AbortController !== 'undefined' ? AbortController : require('abort-controller').AbortController,
typeof AbortSignal !== 'undefined' ? AbortSignal : require('abort-controller').AbortSignal,
typeof EventTarget !== 'undefined' ? EventTarget : require('event-target-shim').EventTarget,
typeof navigator !== 'undefined' ? navigator : {},
`
]
const testParallelBindings = [
"const \\{ internalBinding \\} = require\\('../../lib/internal/test/binding'\\);",
'const internalBinding = process.binding'
]
const testParallelHasOwn = ['Object.hasOwn\\(', 'Reflect.has(']
const testParallelIncludeTap = [
"('use strict')",
`
$1
const tap = require('tap');
const silentConsole = { log() {}, error() {} };
`
]
const testParallelImportStreamInMjs = [" from 'stream';", "from '../../lib/ours/index.js';"]
const testParallelImportTapInMjs = ["(from 'assert';)", "$1\nimport tap from 'tap';"]
const testParallelDuplexFromBlob = [
"const \\{ Blob \\} = require\\('buffer'\\);",
"const Blob = globalThis.Blob || require('buffer').Blob"
]
const testParallelDuplexSkipWithoutBlob = [
"(\\{\n const blob = new Blob\\(\\['blob'\\]\\))",
"if (typeof Blob !== 'undefined') $1"
]
const testParallelFinishedEvent = ["res.on\\('close", "res.on('finish"]
const testParallelFlatMapWinLineSeparator = [
"'xyz\\\\n'\\.repeat\\(5\\)",
"(process.platform === 'win32' ? 'xyz\\r\\n' : 'xyz\\n').repeat(5)"
]
const testParallelPreprocessWinLineSeparator = [
'assert.strictEqual\\(streamedData, modelData\\);',
"assert.strictEqual(streamedData, process.platform === 'win32' ? modelData.replace(/\\r\\n/g, '\\n') : modelData);"
]
const testParallelReadableBufferListInspect = [
'assert.strictEqual\\(\\n\\s+util.inspect\\(\\[ list \\], \\{ compact: false \\}\\),\\n\\s+`\\[\\n\\s+BufferList \\{\\n\\s+head: \\[Object\\],\\n\\s+tail: \\[Object\\],\\n\\s+length: 4\\n\\s+\\}\\n\\]`\\);',
`
assert.strictEqual(typeof list.head, 'object');
assert.strictEqual(typeof list.tail, 'object');
assert.strictEqual(list.length, 4);
`
]
const testParallelRequireStream = ["require\\('stream'\\)", "require('../../lib/ours/index')"]
const testParallelRequireStreamConsumer = ["require\\('stream/consumer'\\)", "require('../../lib/stream/consumer')"]
const testParallelRequireStreamInternals = ["require\\('(internal/.+)'\\)", "require('../../lib/$1')"]
const testParallelRequireStreamInternalsLegacy = ["require\\('(_stream_\\w+)'\\)", "require('../../lib/$1')"]
const testParallelRequireStreamPromises = ["require\\('stream/promises'\\)", "require('../../lib/stream/promises')"]
const testParallelRequireStreamWeb = ["require\\('stream/web'\\)", "require('../../lib/stream/web')"]
const testParallelSilentConsole = ['console.(log|error)', 'silentConsole.$1']
const testParallelTimersPromises = [
"const { setTimeout } = require\\('timers/promises'\\);",
`
const st = require('timers').setTimeout;
function setTimeout(ms) {
return new Promise(resolve => {
st(resolve, ms);
});
}
`
]
const testParallelTicksReenableConsoleLog = ['silentConsole.log\\(i\\);', 'console.log(i);']
const testParallelTickSaveHook = ['async_hooks.createHook\\(\\{', 'const hook = async_hooks.createHook({']
const removefromWebReadableMethod = ['Readable.fromWeb = function\\s\\s*\\([^)]*\\)\\s*{[^}]*}', '']
const removetoWebReadableMethod = ['Readable.toWeb = function\\s\\s*\\([^)]*\\)\\s*{[^}]*}', '']
const readmeInfo = ['(This package is a mirror of the streams implementations in Node.js) (\\d+.\\d+.\\d+).', '$1 $2.']
const readmeLink = ['(\\[Node.js website\\]\\(https://nodejs.org/dist/v)(\\d+.\\d+.\\d+)', '$1$2']
const streamRequire = [ "require\\('stream'\\)", "require('../../lib/stream.js')" ]
const removeWebStreamsFromDuplexFromTest= [
'const { ReadableStream, WritableStream } = .+;',
`function makeATestReadableStream(value) {
return Readable.from([value])
}
function makeATestWritableStream(writeFunc) {
return new Writable({
write(chunk, enc, cb) {
writeFunc(chunk)
cb()
}
})
}
`
]
const duplexFromTestWebStreamNeutralizeReadable = [
'makeATestReadableStream\\(value\\) {',
'makeATestReadableStreamOff(value) {'
]
const duplexFromTestWebStreamNeutralizeWritable = [
'makeATestWritableStream\\(writeFunc\\) {',
'makeATestWritableStreamOff(writeFunc) {'
]
const polyfillAddAbortListener = [
'addAbortListener \\?\\?= require\\(\'events\'\\)\\.addAbortListener',
'addAbortListener = addAbortListener || require(\'../../ours/util\').addAbortListener'
]
const abortSignalAny = [
'AbortSignal.any',
'require(\'../../ours/util\').AbortSignalAny'
]
const asyncDisposeTest = [
'Symbol.asyncDispose',
'require(\'../../lib/ours/primordials\').SymbolAsyncDispose'
]
export const replacements = {
'lib/_stream.+': [legacyStreamsRequireStream],
'lib/internal/streams/duplexify.+': [
internalStreamsBufferPolyfill,
internalStreamsAbortControllerPolyfill,
internalStreamsNoRequireBlob,
internalStreamsNoRequireAbortController
],
'lib/internal/streams/(operators|pipeline).+': [
internalStreamsAbortControllerPolyfill,
internalStreamsNoRequireAbortController,
internalStreamsNoRequireAbortController2,
internalStreamsWeakHandler2,
abortSignalAny
],
'lib/internal/streams/add-abort-signal.js': [
polyfillAddAbortListener
],
'lib/internal/streams/readable.js': [
removefromWebReadableMethod,
removetoWebReadableMethod,
stringDecoderRequirePackage
],
'lib/internal/streams/.+': [
internalStreamsRequireErrors,
internalStreamsRequireEventEmitter,
internalStreamsRequirePrimordials,
internalStreamsRequireRelativeDuplex,
internalStreamsRequireRelativeUtil,
internalStreamsRequireStream,
internalStreamsRequireStreams,
internalStreamsRequireUtil,
internalStreamsRequireUtilDebuglog,
internalStreamsRequireWebStream,
internalStreamsRequireInternal,
internalStreamsWeakHandler,
internalStreamsInspectCustom,
polyfillAddAbortListener
],
'lib/internal/validators.js': [
internalValidatorsRequireAssert,
internalValidatorsRequireAsyncHooks,
internalValidatorsRequireErrors,
internalValidatorsRequirePrimordials,
internalValidatorsRequireRelativeUtil,
internalValidatorsRequireUtilTypes,
internalValidatorsNoRequireSignals,
internalValidatorsNoCoalesceAssignment,
internalValidatorsNumericSeparator
],
'lib/stream.js': [
streamIndexIsUint8Array,
streamIndexUint8ArrayToBuffer,
streamIndexRequireInternalBuffer,
streamIndexRequireErrors,
streamIndexRequirePrimordials,
streamIndexRequirePromises,
streamIndexRequireUtil,
streamIndexRequireInternal
],
'lib/stream/.+': [streamsRequireErrors, streamsRequirePrimordials, streamsRequireInternal, streamRequire],
'test/common/index.js': [testCommonKnownGlobals],
'test/parallel/.+': [
testParallelIncludeTap,
testParallelRequireStream,
testParallelRequireStreamConsumer,
testParallelRequireStreamInternals,
testParallelRequireStreamInternalsLegacy,
testParallelRequireStreamPromises,
testParallelRequireStreamWeb,
testParallelImportStreamInMjs,
testParallelImportTapInMjs,
testParallelBindings,
testParallelHasOwn,
testParallelSilentConsole,
testParallelTimersPromises,
noNodeColon
],
'test/parallel/test-stream-duplex-from.js': [
testParallelDuplexFromBlob,
testParallelDuplexSkipWithoutBlob,
duplexFromTestWebStreamNeutralizeReadable,
duplexFromTestWebStreamNeutralizeWritable,
removeWebStreamsFromDuplexFromTest
],
'test/parallel/test-stream-finished.js': [testParallelFinishedEvent],
'test/parallel/test-stream-readable-dispose.js': [asyncDisposeTest],
'test/parallel/test-stream-flatMap.js': [testParallelFlatMapWinLineSeparator],
'test/parallel/test-stream-preprocess.js': [testParallelPreprocessWinLineSeparator],
'test/parallel/test-stream-writable-samecb-singletick.js': [
testParallelTicksReenableConsoleLog,
testParallelTickSaveHook
],
'test/parallel/test-stream3-pipeline-async-iterator.js': [
internalStreamsAbortControllerPolyfill2,
streamSlashPromisesToStreamDotPromises
],
'test/parallel/test-stream-compose-operator.js': [
internalStreamsAbortControllerPolyfill2
],
'test/parallel/test-stream2-readable-from-list.js': [testParallelReadableBufferListInspect],
'README.md': [readmeInfo, readmeLink]
}