Skip to content

Commit

Permalink
cleanup index (nodejs#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent fa77bad commit 958828b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
24 changes: 4 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ const DecoratorHandler = require('./lib/handler/DecoratorHandler')
const RedirectHandler = require('./lib/handler/RedirectHandler')
const createRedirectInterceptor = require('./lib/interceptor/redirectInterceptor')

let hasCrypto
try {
require('crypto')
hasCrypto = true
} catch {
hasCrypto = false
}

Object.assign(Dispatcher.prototype, api)

module.exports.Dispatcher = Dispatcher
Expand Down Expand Up @@ -102,14 +94,10 @@ function makeDispatcher (fn) {
module.exports.setGlobalDispatcher = setGlobalDispatcher
module.exports.getGlobalDispatcher = getGlobalDispatcher

let fetchImpl = null
module.exports.fetch = async function fetch (resource) {
if (!fetchImpl) {
fetchImpl = require('./lib/fetch').fetch
}

const fetchImpl = require('./lib/fetch').fetch
module.exports.fetch = async function fetch (init, options = undefined) {
try {
return await fetchImpl(...arguments)
return await fetchImpl(init, options)
} catch (err) {
if (typeof err === 'object') {
Error.captureStackTrace(err, this)
Expand Down Expand Up @@ -149,11 +137,7 @@ const { parseMIMEType, serializeAMimeType } = require('./lib/fetch/dataURL')
module.exports.parseMIMEType = parseMIMEType
module.exports.serializeAMimeType = serializeAMimeType

if (hasCrypto) {
const { WebSocket } = require('./lib/websocket/websocket')

module.exports.WebSocket = WebSocket
}
module.exports.WebSocket = require('./lib/websocket/websocket').WebSocket

module.exports.request = makeDispatcher(api.request)
module.exports.stream = makeDispatcher(api.stream)
Expand Down
4 changes: 2 additions & 2 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Fetch extends EE {
}

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

// 1. Let p be a new promise.
Expand Down Expand Up @@ -248,7 +248,7 @@ function fetch (input, init = {}) {
request,
processResponseEndOfBody: handleFetchDone,
processResponse,
dispatcher: init.dispatcher ?? getGlobalDispatcher() // undici
dispatcher: init?.dispatcher ?? getGlobalDispatcher() // undici
})

// 14. Return p.
Expand Down

0 comments on commit 958828b

Please sign in to comment.