From 098609607bb8659cae4b10490bf7ec4ca4c2ab6d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 31 Oct 2024 11:16:36 +0000 Subject: [PATCH] Prefer native node fetch over node-fetch (#1970) --- package.json | 1 - scripts/fetch-package.ts | 3 ++- scripts/tsconfig.json | 3 ++- src/updater.ts | 4 ++-- src/webcontents-handler.ts | 1 - tsconfig.json | 2 +- yarn.lock | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 22e4ec0..e451328 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "electron-store": "^10.0.0", "electron-window-state": "^5.0.3", "minimist": "^1.2.6", - "node-fetch": "^2", "png-to-ico": "^2.1.1", "uuid": "^11.0.0" }, diff --git a/scripts/fetch-package.ts b/scripts/fetch-package.ts index 2ac6eb5..7282945 100644 --- a/scripts/fetch-package.ts +++ b/scripts/fetch-package.ts @@ -5,7 +5,6 @@ import { createWriteStream, promises as fs } from "node:fs"; import * as childProcess from "node:child_process"; import * as tar from "tar"; import * as asar from "@electron/asar"; -import fetch from "node-fetch"; import { promises as stream } from "node:stream"; import riotDesktopPackageJson from "../package.json"; @@ -125,6 +124,8 @@ async function main(): Promise { }); fetch(PUB_KEY_URL) .then((resp) => { + if (!resp.ok) throw new Error(`unexpected response ${resp.statusText}`); + if (!resp.body) throw new Error(`unexpected response has no body ${resp.statusText}`); stream.pipeline(resp.body, gpgProc.stdin!).catch(reject); }) .catch(reject); diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index af9cdf4..99e6def 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -2,12 +2,13 @@ "compilerOptions": { "resolveJsonModule": true, "moduleResolution": "node16", + "skipLibCheck": true, "esModuleInterop": true, "target": "es2022", "module": "node16", "sourceMap": false, "strict": true, - "lib": ["es2020", "dom"] + "lib": ["es2020"] }, "include": ["../src/@types", "./**/*.ts"] } diff --git a/src/updater.ts b/src/updater.ts index 447d49c..2351182 100644 --- a/src/updater.ts +++ b/src/updater.ts @@ -31,8 +31,8 @@ async function safeCheckForUpdate(): Promise { // To avoid this we check manually whether an update is available and call the // autoUpdater.checkForUpdates() when something new is there. try { - const res = await global.fetch(feedUrl); - const { currentRelease } = await res.json(); + const res = await fetch(feedUrl); + const { currentRelease } = (await res.json()) as { currentRelease: string }; const latestVersionDownloaded = latestUpdateDownloaded?.releaseName; console.info( `Latest version from release download: ${currentRelease} (current: ${app.getVersion()}, most recent downloaded ${latestVersionDownloaded}})`, diff --git a/src/webcontents-handler.ts b/src/webcontents-handler.ts index 024198c..8d3032a 100644 --- a/src/webcontents-handler.ts +++ b/src/webcontents-handler.ts @@ -23,7 +23,6 @@ import { } from "electron"; import url from "node:url"; import fs from "node:fs"; -import fetch from "node-fetch"; import { pipeline } from "node:stream/promises"; import path from "node:path"; diff --git a/tsconfig.json b/tsconfig.json index 04f8093..6248dcf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ "rootDir": "./src", "declaration": true, "typeRoots": ["src/@types", "node_modules/@types"], - "lib": ["es2022", "dom"], + "lib": ["es2022"], "types": ["node"], "strict": true }, diff --git a/yarn.lock b/yarn.lock index 21c8817..e432513 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5564,7 +5564,7 @@ node-api-version@^0.2.0: dependencies: semver "^7.3.5" -node-fetch@^2, node-fetch@^2.6.7: +node-fetch@^2.6.7: version "2.7.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==