From 4489af10a94b840103997ba6d020981217525b74 Mon Sep 17 00:00:00 2001 From: Khafra Date: Sun, 7 Jan 2024 17:57:25 -0500 Subject: [PATCH] cleanup index --- index.js | 24 ++++-------------------- lib/fetch/index.js | 4 ++-- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 5fc0d9727ef..2594140d09e 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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) @@ -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) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index f16ce4b4536..73d57f49be0 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -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. @@ -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.