tursodatabase / libsql-client-ts

TypeScript/JavaScript client API for libSQL
https://docs.turso.tech/sdk/ts/quickstart
MIT License
226 stars 32 forks source link

Make better-sqlite3 dependency optional #69

Open penberg opened 1 year ago

penberg commented 1 year ago

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.

honzasp commented 1 year ago

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? :)

Hebilicious commented 1 year ago

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.

jansuchomel commented 1 year ago

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 commented 1 year ago

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