danburzo / percollate

A command-line tool to turn web pages into readable PDF, EPUB, HTML, or Markdown docs.
https://danburzo.ro/projects/percollate/
MIT License
4.32k stars 166 forks source link

Notes on upgrading to node-fetch@3 #149

Closed danburzo closed 1 year ago

danburzo commented 1 year ago

Writing some things down, because every time dependencies need to be bumped, I forget the reason why we're not using node-fetch@latest.

We are using node-fetch@2 and upgrading to v3 requires adding a new dependency:

import fetch from 'node-fetch';
import convertBody from 'fetch-charset-detection';

fetch('https://somewebsite.com').then(async res => {
    const text = convertBody(await res.arrayBuffer(), res.headers);
});

The fetch-charset-detection package comes with some rather heavy dependencies of its own:

"dependencies": {
    "cheerio": "^1.0.0-rc.10",
    "content-type": "^1.0.4",
    "iconv-lite": "^0.6.3",
    "type-fest": "^2.0.0"
}

In particular cheerio's use-case is already covered with jsdom. We might end up doing our own, lighter, charset conversion.

Also worth investigating if charsets are still a problem for the native fetch() (Node v18+), and whether we are better off just waiting it out and removing node-fetch altogether when Node 16 reaches end of life.