Skip to content

Commit 4a67182

Browse files
committed
refactor: move files into logical folders
1 parent e7b4714 commit 4a67182

28 files changed

+60
-60
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict'
22

3-
const Client = require('./lib/client')
4-
const Dispatcher = require('./lib/dispatcher')
3+
const Client = require('./lib/dispatcher/client')
4+
const Dispatcher = require('./lib/dispatcher/dispatcher')
5+
const Pool = require('./lib/dispatcher/pool')
6+
const BalancedPool = require('./lib/dispatcher/balanced-pool')
7+
const Agent = require('./lib/dispatcher/agent')
8+
const ProxyAgent = require('./lib/dispatcher/proxy-agent')
9+
const RetryAgent = require('./lib/dispatcher/retry-agent')
510
const errors = require('./lib/core/errors')
6-
const Pool = require('./lib/pool')
7-
const BalancedPool = require('./lib/balanced-pool')
8-
const Agent = require('./lib/agent')
911
const util = require('./lib/core/util')
1012
const { InvalidArgumentError } = errors
1113
const api = require('./lib/api')
@@ -14,8 +16,6 @@ const MockClient = require('./lib/mock/mock-client')
1416
const MockAgent = require('./lib/mock/mock-agent')
1517
const MockPool = require('./lib/mock/mock-pool')
1618
const mockErrors = require('./lib/mock/mock-errors')
17-
const ProxyAgent = require('./lib/proxy-agent')
18-
const RetryAgent = require('./lib/retry-agent')
1919
const RetryHandler = require('./lib/handler/RetryHandler')
2020
const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global')
2121
const DecoratorHandler = require('./lib/handler/DecoratorHandler')

lib/agent.js renamed to lib/dispatcher/agent.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict'
22

3-
const { InvalidArgumentError } = require('./core/errors')
4-
const { kClients, kRunning, kClose, kDestroy, kDispatch, kInterceptors } = require('./core/symbols')
3+
const { InvalidArgumentError } = require('../core/errors')
4+
const { kClients, kRunning, kClose, kDestroy, kDispatch, kInterceptors } = require('../core/symbols')
55
const DispatcherBase = require('./dispatcher-base')
66
const Pool = require('./pool')
77
const Client = require('./client')
8-
const util = require('./core/util')
9-
const createRedirectInterceptor = require('./interceptor/redirectInterceptor')
8+
const util = require('../core/util')
9+
const createRedirectInterceptor = require('../interceptor/redirectInterceptor')
1010

1111
const kOnConnect = Symbol('onConnect')
1212
const kOnDisconnect = Symbol('onDisconnect')

lib/balanced-pool.js renamed to lib/dispatcher/balanced-pool.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const {
44
BalancedPoolMissingUpstreamError,
55
InvalidArgumentError
6-
} = require('./core/errors')
6+
} = require('../core/errors')
77
const {
88
PoolBase,
99
kClients,
@@ -13,8 +13,8 @@ const {
1313
kGetDispatcher
1414
} = require('./pool-base')
1515
const Pool = require('./pool')
16-
const { kUrl, kInterceptors } = require('./core/symbols')
17-
const { parseOrigin } = require('./core/util')
16+
const { kUrl, kInterceptors } = require('../core/symbols')
17+
const { parseOrigin } = require('../core/util')
1818
const kFactory = Symbol('factory')
1919

2020
const kOptions = Symbol('options')

lib/client.js renamed to lib/dispatcher/client.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const assert = require('node:assert')
88
const net = require('node:net')
99
const http = require('node:http')
1010
const { pipeline } = require('node:stream')
11-
const util = require('./core/util')
12-
const { channels } = require('./core/diagnostics')
13-
const timers = require('./timers')
14-
const Request = require('./core/request')
11+
const util = require('../core/util.js')
12+
const { channels } = require('../core/diagnostics.js')
13+
const timers = require('../util/timers.js')
14+
const Request = require('../core/request.js')
1515
const DispatcherBase = require('./dispatcher-base')
1616
const {
1717
RequestContentLengthMismatchError,
@@ -26,8 +26,8 @@ const {
2626
HTTPParserError,
2727
ResponseExceededMaxSizeError,
2828
ClientDestroyedError
29-
} = require('./core/errors')
30-
const buildConnector = require('./core/connect')
29+
} = require('../core/errors.js')
30+
const buildConnector = require('../core/connect.js')
3131
const {
3232
kUrl,
3333
kReset,
@@ -79,7 +79,7 @@ const {
7979
kHTTP2BuildRequest,
8080
kHTTP2CopyHeaders,
8181
kHTTP1BuildRequest
82-
} = require('./core/symbols')
82+
} = require('../core/symbols.js')
8383

8484
/** @type {import('http2')} */
8585
let http2
@@ -112,13 +112,13 @@ const FastBuffer = Buffer[Symbol.species]
112112
const kClosedResolve = Symbol('kClosedResolve')
113113

114114
/**
115-
* @type {import('../types/client').default}
115+
* @type {import('../../types/client.js').default}
116116
*/
117117
class Client extends DispatcherBase {
118118
/**
119119
*
120120
* @param {string|URL} url
121-
* @param {import('../types/client').Client.Options} options
121+
* @param {import('../../types/client.js').Client.Options} options
122122
*/
123123
constructor (url, {
124124
interceptors,
@@ -472,24 +472,24 @@ function onHTTP2GoAway (code) {
472472
resume(client)
473473
}
474474

475-
const constants = require('./llhttp/constants')
476-
const createRedirectInterceptor = require('./interceptor/redirectInterceptor')
475+
const constants = require('../llhttp/constants.js')
476+
const createRedirectInterceptor = require('../interceptor/redirectInterceptor.js')
477477
const EMPTY_BUF = Buffer.alloc(0)
478478

479479
async function lazyllhttp () {
480-
const llhttpWasmData = process.env.JEST_WORKER_ID ? require('./llhttp/llhttp-wasm.js') : undefined
480+
const llhttpWasmData = process.env.JEST_WORKER_ID ? require('../llhttp/llhttp-wasm.js') : undefined
481481

482482
let mod
483483
try {
484-
mod = await WebAssembly.compile(require('./llhttp/llhttp_simd-wasm.js'))
484+
mod = await WebAssembly.compile(require('../llhttp/llhttp_simd-wasm.js'))
485485
} catch (e) {
486486
/* istanbul ignore next */
487487

488488
// We could check if the error was caused by the simd option not
489489
// being enabled, but the occurring of this other error
490490
// * https://github.com/emscripten-core/emscripten/issues/11495
491491
// got me to remove that check to avoid breaking Node 12.
492-
mod = await WebAssembly.compile(llhttpWasmData || require('./llhttp/llhttp-wasm.js'))
492+
mod = await WebAssembly.compile(llhttpWasmData || require('../llhttp/llhttp-wasm.js'))
493493
}
494494

495495
return await WebAssembly.instantiate(mod, {
@@ -1500,7 +1500,7 @@ function write (client, request) {
15001500

15011501
if (util.isFormDataLike(body)) {
15021502
if (!extractBody) {
1503-
extractBody = require('./web/fetch/body.js').extractBody
1503+
extractBody = require('../web/fetch/body.js').extractBody
15041504
}
15051505

15061506
const [bodyStream, contentType] = extractBody(body)

lib/dispatcher-base.js renamed to lib/dispatcher/dispatcher-base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const {
55
ClientDestroyedError,
66
ClientClosedError,
77
InvalidArgumentError
8-
} = require('./core/errors')
9-
const { kDestroy, kClose, kDispatch, kInterceptors } = require('./core/symbols')
8+
} = require('../core/errors')
9+
const { kDestroy, kClose, kDispatch, kInterceptors } = require('../core/symbols')
1010

1111
const kDestroyed = Symbol('destroyed')
1212
const kClosed = Symbol('closed')
File renamed without changes.

lib/pool-base.js renamed to lib/dispatcher/pool-base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

33
const DispatcherBase = require('./dispatcher-base')
4-
const FixedQueue = require('./node/fixed-queue')
5-
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('./core/symbols')
4+
const FixedQueue = require('../node/fixed-queue')
5+
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('../core/symbols')
66
const PoolStats = require('./pool-stats')
77

88
const kClients = Symbol('clients')

lib/pool-stats.js renamed to lib/dispatcher/pool-stats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { kFree, kConnected, kPending, kQueued, kRunning, kSize } = require('./core/symbols')
1+
const { kFree, kConnected, kPending, kQueued, kRunning, kSize } = require('../core/symbols')
22
const kPool = Symbol('pool')
33

44
class PoolStats {

lib/pool.js renamed to lib/dispatcher/pool.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const {
1010
const Client = require('./client')
1111
const {
1212
InvalidArgumentError
13-
} = require('./core/errors')
14-
const util = require('./core/util')
15-
const { kUrl, kInterceptors } = require('./core/symbols')
16-
const buildConnector = require('./core/connect')
13+
} = require('../core/errors')
14+
const util = require('../core/util')
15+
const { kUrl, kInterceptors } = require('../core/symbols')
16+
const buildConnector = require('../core/connect')
1717

1818
const kOptions = Symbol('options')
1919
const kConnections = Symbol('connections')

lib/proxy-agent.js renamed to lib/dispatcher/proxy-agent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict'
22

3-
const { kProxy, kClose, kDestroy, kInterceptors } = require('./core/symbols')
3+
const { kProxy, kClose, kDestroy, kInterceptors } = require('../core/symbols')
44
const { URL } = require('node:url')
55
const Agent = require('./agent')
66
const Pool = require('./pool')
77
const DispatcherBase = require('./dispatcher-base')
8-
const { InvalidArgumentError, RequestAbortedError } = require('./core/errors')
9-
const buildConnector = require('./core/connect')
8+
const { InvalidArgumentError, RequestAbortedError } = require('../core/errors')
9+
const buildConnector = require('../core/connect')
1010

1111
const kAgent = Symbol('proxy agent')
1212
const kClient = Symbol('proxy client')

0 commit comments

Comments
 (0)