Skip to content

Commit

Permalink
chore: don't bundle undici (peter-evans#3475)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Nov 4, 2024
1 parent 5da4e80 commit 2aadff0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
13 changes: 11 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"@octokit/plugin-paginate-rest": "^11.3.5",
"@octokit/plugin-rest-endpoint-methods": "^13.2.6",
"@octokit/plugin-throttling": "^9.3.2",
"node-fetch-native": "^1.6.4",
"p-limit": "^6.1.0",
"proxy-from-env": "^1.1.0",
"undici": "^6.20.1",
"uuid": "^9.0.1"
},
"devDependencies": {
Expand All @@ -58,6 +58,7 @@
"js-yaml": "^4.1.0",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3"
"typescript": "^5.6.3",
"undici": "^6.20.1"
}
}
15 changes: 2 additions & 13 deletions src/octokit-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {paginateRest} from '@octokit/plugin-paginate-rest'
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
import {throttling} from '@octokit/plugin-throttling'
import {getProxyForUrl} from 'proxy-from-env'
import {ProxyAgent, fetch as undiciFetch} from 'undici'
import {createFetch} from 'node-fetch-native/proxy'
export {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
// eslint-disable-next-line import/no-unresolved
export {OctokitOptions} from '@octokit/core/dist-types/types'
Expand Down Expand Up @@ -33,23 +33,12 @@ export const throttleOptions = {
}
}

const proxyFetch =
(proxyUrl: string): typeof undiciFetch =>
(url, opts) => {
return undiciFetch(url, {
...opts,
dispatcher: new ProxyAgent({
uri: proxyUrl
})
})
}

// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
function autoProxyAgent(octokit: OctokitCore) {
octokit.hook.before('request', options => {
const proxy = getProxyForUrl(options.baseUrl)
if (proxy) {
options.request.fetch = proxyFetch(proxy)
options.request.fetch = createFetch(proxy)
}
})
}

0 comments on commit 2aadff0

Please sign in to comment.