libsql-client-ts icon indicating copy to clipboard operation
libsql-client-ts copied to clipboard

Make better-sqlite3 dependency optional

Open penberg opened this issue 2 years ago • 4 comments

Jökull Sólberg asks the following:

Could it be an optional dependency? Because Vercel installs better-sqlite3 and it slows down the build process significantly.

penberg avatar Aug 18 '23 11:08 penberg

Looking at the docs, it seems that putting a dependency into optionalDependencies only makes npm install not fail if the dependency fails to install; it does not provide a way for users to choose whether or not to install the dependency. It also does not provide the package with a way to check whether the dependency is installed (other than using dynamic imports and catching the resulting errors).

What we could do is to provide two packages, Web-only (WebSocket + HTTP) and full (WebSocket + HTTP + better-sqlite3), instead of multiple imports from a single package. However, that would be more awkward to use and to develop.

However, I'm not an expert in the JavaScript ecosystem, so perhaps Jökull Sólberg might have some tips how to accomplish this better? :)

honzasp avatar Aug 21 '23 07:08 honzasp

Just chiming in here, perhaps the best cleanest way to handle this scenario is to use optional peerDependencies ? Following this discussions it might work https://github.com/npm/feedback/discussions/225

As an optional peer deps, the package manager should not auto-install them. Which is desired in production environments where web or http will be used. Users who need it locally can add better-sqlite3 to their own package.json dev dependencies.

Hebilicious avatar Aug 29 '23 20:08 Hebilicious

It would be really helpful to provide web only packaging, because as of now the deployment fails on Cloudflare workers a netlify edge functions.

jansuchomel avatar Sep 08 '23 12:09 jansuchomel

For now I've forked this repo and deleted local support https://github.com/jansuchomel/libsql-client-ts for using in Cloudflare workers..

jansuchomel avatar Sep 08 '23 13:09 jansuchomel