Skip to content

Commit 282bd22

Browse files
authored
Merge pull request #3706 from github/koesie10/upgrade-node-fetch
Upgrade node-fetch to v3
2 parents 50329a8 + 1c146b9 commit 282bd22

File tree

13 files changed

+151
-95
lines changed

13 files changed

+151
-95
lines changed

extensions/ql-vscode/package-lock.json

Lines changed: 78 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@
19841984
"js-yaml": "^4.1.0",
19851985
"msw": "^2.2.13",
19861986
"nanoid": "^5.0.7",
1987-
"node-fetch": "^2.6.7",
1987+
"node-fetch": "^3.3.2",
19881988
"p-queue": "^8.0.1",
19891989
"react": "^18.3.1",
19901990
"react-dom": "^18.3.1",
@@ -2039,7 +2039,6 @@
20392039
"@types/js-yaml": "^4.0.6",
20402040
"@types/nanoid": "^3.0.0",
20412041
"@types/node": "20.15.*",
2042-
"@types/node-fetch": "^2.5.2",
20432042
"@types/react": "^18.3.1",
20442043
"@types/react-dom": "^18.3.0",
20452044
"@types/sarif": "^2.1.2",

extensions/ql-vscode/src/codeql-cli/distribution.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ class ExtensionSpecificDistributionManager {
404404
signal,
405405
);
406406

407+
const body = assetStream.body;
408+
if (!body) {
409+
throw new Error("No body in asset stream");
410+
}
411+
407412
const archivePath = join(tmpDirectory, "distributionDownload.zip");
408413
archiveFile = createWriteStream(archivePath);
409414

@@ -412,26 +417,23 @@ class ExtensionSpecificDistributionManager {
412417
? parseInt(contentLength, 10)
413418
: undefined;
414419
reportStreamProgress(
415-
assetStream.body,
420+
body,
416421
`Downloading CodeQL CLI ${release.name}…`,
417422
totalNumBytes,
418423
progressCallback,
419424
);
420425

421-
assetStream.body.on("data", onData);
426+
body.on("data", onData);
422427

423428
await new Promise((resolve, reject) => {
424429
if (!archiveFile) {
425430
throw new Error("Invariant violation: archiveFile not set");
426431
}
427432

428-
assetStream.body
429-
.pipe(archiveFile)
430-
.on("finish", resolve)
431-
.on("error", reject);
433+
body.pipe(archiveFile).on("finish", resolve).on("error", reject);
432434

433435
// If an error occurs on the body, we also want to reject the promise (e.g. during a timeout error).
434-
assetStream.body.on("error", reject);
436+
body.on("error", reject);
435437
});
436438

437439
disposeTimeout();

extensions/ql-vscode/src/codeql-cli/distribution/releases-api-consumer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export class ReleasesApiConsumer {
3434
additionalCompatibilityCheck?: (release: GithubRelease) => boolean,
3535
): Promise<Release> {
3636
const apiPath = `/repos/${this.repositoryNwo}/releases`;
37-
const allReleases: GithubRelease[] = await (
37+
const allReleases = (await (
3838
await this.makeApiCall(apiPath)
39-
).json();
39+
).json()) as GithubRelease[];
4040
const compatibleReleases = allReleases.filter((release) => {
4141
if (release.prerelease && !includePrerelease) {
4242
return false;

extensions/ql-vscode/src/common/mock-gh-api/gh-api-request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export interface GetVariantAnalysisRepoResultRequest {
6969
};
7070
response: {
7171
status: number;
72-
body?: Buffer | string;
72+
body?: ArrayBuffer | string;
7373
contentType: string;
7474
};
7575
}

extensions/ql-vscode/src/common/mock-gh-api/recorder.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ export class Recorder extends DisposableObject {
9191

9292
let bodyFileLink = undefined;
9393
if (writtenRequest.response.body) {
94-
await writeFile(bodyFilePath, writtenRequest.response.body);
94+
if (typeof writtenRequest.response.body === "string") {
95+
await writeFile(bodyFilePath, writtenRequest.response.body);
96+
} else {
97+
await writeFile(
98+
bodyFilePath,
99+
Buffer.from(writtenRequest.response.body),
100+
);
101+
}
95102
bodyFileLink = `file:${bodyFileName}`;
96103
}
97104

@@ -226,7 +233,7 @@ async function createGitHubApiRequest(
226233
"x-vscode-codeql-msw-bypass": "true",
227234
},
228235
});
229-
const responseBuffer = await response.buffer();
236+
const responseBuffer = await response.arrayBuffer();
230237

231238
return {
232239
request: {

extensions/ql-vscode/src/databases/database-fetcher.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -545,30 +545,27 @@ export class DatabaseFetcher {
545545
throw e;
546546
}
547547

548+
const body = response.body;
549+
if (!body) {
550+
throw new Error("No response body found");
551+
}
552+
548553
const archiveFileStream = createWriteStream(archivePath);
549554

550555
const contentLength = response.headers.get("content-length");
551556
const totalNumBytes = contentLength
552557
? parseInt(contentLength, 10)
553558
: undefined;
554-
reportStreamProgress(
555-
response.body,
556-
"Downloading database",
557-
totalNumBytes,
558-
progress,
559-
);
559+
reportStreamProgress(body, "Downloading database", totalNumBytes, progress);
560560

561-
response.body.on("data", onData);
561+
body.on("data", onData);
562562

563563
try {
564564
await new Promise((resolve, reject) => {
565-
response.body
566-
.pipe(archiveFileStream)
567-
.on("finish", resolve)
568-
.on("error", reject);
565+
body.pipe(archiveFileStream).on("finish", resolve).on("error", reject);
569566

570567
// If an error occurs on the body, we also want to reject the promise (e.g. during a timeout error).
571-
response.body.on("error", reject);
568+
body.on("error", reject);
572569
});
573570
} catch (e) {
574571
// Close and remove the file if an error occurs

extensions/ql-vscode/src/variant-analysis/variant-analysis-results-manager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ export class VariantAnalysisResultsManager extends DisposableObject {
9999
responseSize = response.size;
100100
}
101101

102+
if (!response.body) {
103+
throw new Error("No response body found");
104+
}
105+
102106
let amountDownloaded = 0;
103107
for await (const chunk of response.body) {
104108
await appendFile(zipFilePath, Buffer.from(chunk));

extensions/ql-vscode/test/jest-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ const transformPackages = [
55
"@vscode/webview-ui-toolkit",
66
"before-after-hook",
77
"d3",
8+
"data-uri-to-buffer",
89
"delaunator",
910
"exenv-es6",
11+
"fetch-blob",
12+
"formdata-polyfill",
1013
"internmap",
1114
"nanoid",
15+
"node-fetch",
1216
"p-queue",
1317
"p-timeout",
1418
"robust-predicates",

extensions/ql-vscode/test/vscode-tests/activated-extension/variant-analysis/variant-analysis-manager.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
remove,
1313
} from "fs-extra";
1414
import { join } from "path";
15-
import { Readable } from "stream";
1615
import * as fetchModule from "node-fetch";
1716
import { Response } from "node-fetch";
1817

@@ -227,8 +226,7 @@ describe("Variant Analysis Manager", () => {
227226
"data/variant-analysis-results.zip",
228227
);
229228
const fileContents = await readFile(sourceFilePath);
230-
const response = new Response(Readable.from(fileContents));
231-
response.size = fileContents.length;
229+
const response = new Response(fileContents);
232230
getVariantAnalysisRepoResultStub.mockResolvedValue(response);
233231
});
234232

0 commit comments

Comments
 (0)