Skip to content

Commit

Permalink
fix: use 'node-fetch' as Octokit's fetch
Browse files Browse the repository at this point in the history
In v6.1.0 Octokit started using Node.js's built-in `fetch`[^1] (provided by [undici][1]. Unfortunately, it is not 100% compatible with `node-fetch`, and notably it doesn't support `HTTP_PROXY` environment variables[^2].

This change switches `osv-offline` to explicitly use `node-fetch`.

Closes #252

[1]: https://github.com/nodejs/undici

[^1]: octokit/request.js@d000a0a
[^2]: nodejs/undici#1650
  • Loading branch information
JamieMagee committed Mar 27, 2023
1 parent d33b020 commit a764d68
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
87 changes: 86 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion packages/osv-offline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"adm-zip": "~0.5.10",
"fs-extra": "^11.1.0",
"got": "^11.8.6",
"luxon": "^3.3.0"
"luxon": "^3.3.0",
"node-fetch": "^3.3.1"
},
"devDependencies": {
"@types/adm-zip": "0.5.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/osv-offline/src/lib/download.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs-extra';
import fetch from 'node-fetch';
import { Octokit } from '@octokit/rest';
import got from 'got';
import { Stream } from 'stream';
Expand Down Expand Up @@ -34,9 +35,7 @@ export async function tryDownloadDb(): Promise<boolean> {
return true;
}

const octokitOptions = process.env.GITHUB_COM_TOKEN
? { auth: process.env.GITHUB_COM_TOKEN }
: undefined;
const octokitOptions = { auth: process.env.GITHUB_COM_TOKEN, request: { fetch } };

let latestRelease = null;
try {
Expand Down

0 comments on commit a764d68

Please sign in to comment.