docusaurus-search-local icon indicating copy to clipboard operation
docusaurus-search-local copied to clipboard

fix(deps): fix cheerio version to rc.12

Open slorber opened this issue 1 year ago • 4 comments

Cheerio just released v1.0.0 after 7 years of RC

https://cheerio.js.org/blog/cheerio-1.0

The only problem is that RC users used semver ranges (^) and the 1.0 is not retro-compatible with the latest RC.12, published 2 years ago

Notably:

  • Bumps required Node.js version 18.17+ (https://github.com/cheeriojs/cheerio/issues/3993)
  • Bumps required TS version to 5.0+ (https://github.com/cheeriojs/cheerio/issues/4011)
  • Breaks default import, now requires import * as Cheerio from 'cheerio' instead of import Cheerio from 'cheerio'

Docusaurus users installing this plugin will now get Cheerio v1.0, and the following error:

[ERROR] Error: Unable to build website for locale en.
  ...
  [cause]: TypeError: Cannot read properties of undefined (reading 'load')
      at getDocusaurusTag (.../@cmfcmf/docusaurus-search-local/lib/server/parse.js:194:33)
      at .../@cmfcmf/docusaurus-search-local/lib/server/index.js:288:60

A temporary solution: fix the Cheerio version to rc.12 in this lib so that users never use Cheerio v1.0, until you fix the problems, or Cheerio adds back retrocompatibility.

-  "cheerio": "^1.0.0-rc.9",
+  "cheerio": "1.0.0-rc.12",

Until this PR gets merged/released, users will have to force resolution to rc.12 on their side using their package managers features.

For example, Yarn users can do:

  "resolutions": {
    "cheerio": "1.0.0-rc.12"
  },

slorber avatar Aug 13 '24 11:08 slorber

I think you need to amend your commit and push again based on this rules 😉 https://github.com/cmfcmf/docusaurus-search-local/blob/main/CONTRIBUTING.md#commit-message-guidelines probably adding fix(deps): at the start should do

Alevale avatar Aug 13 '24 11:08 Alevale

Well summed up @slorber

garronej avatar Aug 13 '24 13:08 garronej

Pinning the version to the RC is a viable workaround. Nevertheless, the real fix in order to use v1.0.0 of cheerio is also fairly easy (see: https://github.com/cmfcmf/docusaurus-search-local/issues/219).

Instead of using cheerio.default.load(...), this just needs to be changed to cheerio.load(...) (so just removing the usage of "default"). According to my tests, everything works fine with this change (which BTW is also used in other parts of the docusaurus-search-local plugin).

rbcm1 avatar Aug 20 '24 12:08 rbcm1

Yes, that would also work but you'd have to also change deps to ensure all RC users upgrade to v1.0 stable

v1.0 stable only works for Node 18.17+ and Docusaurus v3 has support for 18.0. If you upgrade Cheerio to v1.0 stable, you also ask your users to potentially upgrade Node, which is a breaking change.

My suggestion is to release this PR as a minor/patch, and then upgrade Cheerio in the next major, mentioning it requires upgrading Node.

slorber avatar Aug 20 '24 12:08 slorber

Thank you for the PR and the detailed explanation - I'll land this fix as part of #228. I also raised the minimum Node.js version to 18.18 since other (dev) dependencies like syncpack require it and Node.js 16 has been EOL for more than a year.

cmfcmf avatar Nov 09 '24 21:11 cmfcmf