Skip to content

Commit 958828b

Browse files
KhafraDevcrysmags
authored andcommitted
cleanup index (nodejs#2598)
1 parent fa77bad commit 958828b

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

index.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ const DecoratorHandler = require('./lib/handler/DecoratorHandler')
2121
const RedirectHandler = require('./lib/handler/RedirectHandler')
2222
const createRedirectInterceptor = require('./lib/interceptor/redirectInterceptor')
2323

24-
let hasCrypto
25-
try {
26-
require('crypto')
27-
hasCrypto = true
28-
} catch {
29-
hasCrypto = false
30-
}
31-
3224
Object.assign(Dispatcher.prototype, api)
3325

3426
module.exports.Dispatcher = Dispatcher
@@ -102,14 +94,10 @@ function makeDispatcher (fn) {
10294
module.exports.setGlobalDispatcher = setGlobalDispatcher
10395
module.exports.getGlobalDispatcher = getGlobalDispatcher
10496

105-
let fetchImpl = null
106-
module.exports.fetch = async function fetch (resource) {
107-
if (!fetchImpl) {
108-
fetchImpl = require('./lib/fetch').fetch
109-
}
110-
97+
const fetchImpl = require('./lib/fetch').fetch
98+
module.exports.fetch = async function fetch (init, options = undefined) {
11199
try {
112-
return await fetchImpl(...arguments)
100+
return await fetchImpl(init, options)
113101
} catch (err) {
114102
if (typeof err === 'object') {
115103
Error.captureStackTrace(err, this)
@@ -149,11 +137,7 @@ const { parseMIMEType, serializeAMimeType } = require('./lib/fetch/dataURL')
149137
module.exports.parseMIMEType = parseMIMEType
150138
module.exports.serializeAMimeType = serializeAMimeType
151139

152-
if (hasCrypto) {
153-
const { WebSocket } = require('./lib/websocket/websocket')
154-
155-
module.exports.WebSocket = WebSocket
156-
}
140+
module.exports.WebSocket = require('./lib/websocket/websocket').WebSocket
157141

158142
module.exports.request = makeDispatcher(api.request)
159143
module.exports.stream = makeDispatcher(api.stream)

lib/fetch/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Fetch extends EE {
122122
}
123123

124124
// https://fetch.spec.whatwg.org/#fetch-method
125-
function fetch (input, init = {}) {
125+
function fetch (input, init = undefined) {
126126
webidl.argumentLengthCheck(arguments, 1, { header: 'globalThis.fetch' })
127127

128128
// 1. Let p be a new promise.
@@ -248,7 +248,7 @@ function fetch (input, init = {}) {
248248
request,
249249
processResponseEndOfBody: handleFetchDone,
250250
processResponse,
251-
dispatcher: init.dispatcher ?? getGlobalDispatcher() // undici
251+
dispatcher: init?.dispatcher ?? getGlobalDispatcher() // undici
252252
})
253253

254254
// 14. Return p.

0 commit comments

Comments
 (0)