front-end-monorepo
front-end-monorepo copied to clipboard
PanoptesJS: remove superagent
PR Overview
Package: panoptes-js
This PR attempts to remove superagent
from the PanoptesJS client
- Reason:
superagent
is a dependency that we don't technically need anymore, since the standardfetch
API works fine, while maintaining superagent can be a bit of a faff. - Observation: superagent() is only used in the get(), post(), put(), and del() (i.e. delete) functions of
panoptes.js
, so replacing the dependency should be very easy.- (Spoiler: it wasn't)
- Priority: low priority, for now. Removing superagent is a "nice to have" item that will eventually escalate to "gotta get it done" once the maintenance cost gets too high in the future (or the library stops getting updates, whichever comes first).
Dev Notes
As of 12 Sep 2024, this PR is in an experimental stage. The biggest lessons we've learnt are:
- it's actually easy to replace the
superagent()
calls inpanoptes.js
, as initially observed. - however, there are MULTIPLE places in the FEM code that expects a very specific superagent-shaped response from
panoptes.get()/panoptes.put()/panoptes.post()/panoptes.del()
,
Comparison of the default response data we get from superagent vs the default response data we get from fetch().
Superagent response:
Fetch API response:
So in practice, we either need to...
- accept the cost of going through the hundred(s?) instances in the FEM code (and any other project that uses PanoptesJS) that expects a superagent response and make changes there, OR
- create a transformer/adapter that transform Fetch API responses into superagent-compatible responses.
Status
Experimental. Put on pause as of 12 Sep 2024 while higher priority items in PanoptesJS is addressed.
As of commit 96096e: panoptes.get experimental: replace superagent with fetch, the get() function has superagent() successfully replaced with fetch(), with a very rudimentary fetch-response-to-superagent-response transformer in place. You can run lib-classifier > yarn dev
and load a local test project, and the data will be fetched fine for this instance.