Merge 'Fix JavaScript bindings packaging' from Nikita Sivukhin

This PR configure `#entry-point` import alias for javascript bindings in
order to use `browser.js` napi-rs generated file in browser context.
Also, this PR forces napi-rs to emit `index.js` entrypoint using ESM and
also use typescript for writing our wrapper code around napi-rs
bindings.
In order to make behaviour consistent when lib is imported through ESM
or CommonJS this PR also replace default export of `Database` by named
on. The problem is that `export default Database` will be logically
equivalent to `modules.export.default = Database` which is not the same
thing as `modules.export = Database` and this will need to access
additional `.default` field with CommonJs style imports (e.g. `new
require('@tursodatabase/turso').default(...)`). In order to remove this
difference - I just replaced default export with named one.

Closes #2488
This commit is contained in:
Pekka Enberg
2025-08-08 10:42:21 +03:00
committed by GitHub
17 changed files with 207 additions and 128 deletions

View File

@@ -484,9 +484,9 @@ const connect = async (path, options = {}) => {
}
const provider = process.env.PROVIDER;
if (provider === "turso") {
const x = await import("@tursodatabase/turso");
const db = new x.default(path, options);
return [db, path, x.SqliteError];
const { Database, SqliteError } = await import("@tursodatabase/turso");
const db = new Database(path, options);
return [db, path, SqliteError];
}
if (provider === "libsql") {
const x = await import("libsql/promise");