From 6cb0c7530c0962b2f882ca9ea42f0ecebe56c584 Mon Sep 17 00:00:00 2001 From: Holger Dal Mogensen <61235930+sockmaster27@users.noreply.github.com> Date: Wed, 31 Jan 2024 07:23:11 +0100 Subject: [PATCH] chore: swap out node-fetch-commonjs with node-fetch (#329) --- client/package-lock.json | 41 ++++++++++++++++++++++----------- client/package.json | 2 +- client/src/services/releases.ts | 10 ++++---- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 6ac2ddb5..2c8c1f22 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "lodash": "^4.17.21", - "node-fetch-commonjs": "^3.2.4", + "node-fetch": "^3.3.2", "vscode-languageclient": "^8.0.1" }, "devDependencies": { @@ -138,6 +138,14 @@ "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", "dev": true }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "engines": { + "node": ">= 12" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -383,13 +391,14 @@ "node": ">=10.5.0" } }, - "node_modules/node-fetch-commonjs": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/node-fetch-commonjs/-/node-fetch-commonjs-3.2.4.tgz", - "integrity": "sha512-bZW7+ldcuuMPLTJk8DufhT6qHDRdljYD0jqBjmrYfcInaYcReX5kK42SQsu/jvtit/tER28yYjnk63PEEmNPtg==", + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", "dependencies": { - "formdata-polyfill": "^4.0.10", - "web-streams-polyfill": "^3.1.1" + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" }, "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" @@ -688,6 +697,11 @@ "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", "dev": true }, + "data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==" + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -868,13 +882,14 @@ "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" }, - "node-fetch-commonjs": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/node-fetch-commonjs/-/node-fetch-commonjs-3.2.4.tgz", - "integrity": "sha512-bZW7+ldcuuMPLTJk8DufhT6qHDRdljYD0jqBjmrYfcInaYcReX5kK42SQsu/jvtit/tER28yYjnk63PEEmNPtg==", + "node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", "requires": { - "formdata-polyfill": "^4.0.10", - "web-streams-polyfill": "^3.1.1" + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" } }, "once": { diff --git a/client/package.json b/client/package.json index 7dc8c977..6681bc6c 100644 --- a/client/package.json +++ b/client/package.json @@ -14,7 +14,7 @@ }, "dependencies": { "lodash": "^4.17.21", - "node-fetch-commonjs": "^3.2.4", + "node-fetch": "^3.3.2", "vscode-languageclient": "^8.0.1" }, "devDependencies": { diff --git a/client/src/services/releases.ts b/client/src/services/releases.ts index e8d15e90..fd16a507 100644 --- a/client/src/services/releases.ts +++ b/client/src/services/releases.ts @@ -2,8 +2,6 @@ // https://github.com/rust-analyzer/rust-analyzer/blob/master/editors/code/src/net.ts // The code in rust-analyzer is released under the same licence as this project. -// Replace with `import fetch from "node-fetch"` once this is fixed in rollup: -// https://github.com/rollup/plugins/issues/491 import * as vscode from 'vscode' import * as stream from 'stream' import * as crypto from 'crypto' @@ -13,7 +11,9 @@ import * as util from 'util' import * as path from 'path' import { strict as nativeAssert } from 'assert' import * as _ from 'lodash' -const fetch = require('node-fetch-commonjs') + +// Remove when support for Node.js 20 is dropped +import fetch from 'node-fetch' const pipeline = util.promisify(stream.pipeline) @@ -61,8 +61,8 @@ export async function fetchRelease( throw new Error(`Got response ${response.status} when trying to fetch ` + `release info for ${releaseTag} release`) } - // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`) - const release: GithubRelease = await response.json() + // We skip runtime type checks for simplicity (here we cast from `unknown` to `GithubRelease`) + const release = (await response.json()) as GithubRelease const flixRelease: FlixRelease = { url: _.get(release, 'url'), id: _.get(release, 'id'),