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");

View File

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

View File

@@ -17,13 +17,15 @@
},
"../../bindings/javascript": {
"name": "@tursodatabase/turso",
"version": "0.1.3",
"version": "0.1.4-pre.2",
"license": "MIT",
"devDependencies": {
"@napi-rs/cli": "^3.0.4",
"@napi-rs/wasm-runtime": "^1.0.1",
"ava": "^6.0.1",
"better-sqlite3": "^11.9.1"
"better-sqlite3": "^11.9.1",
"tsc": "^2.0.4",
"typescript": "^5.9.2"
},
"engines": {
"node": ">= 10"
@@ -31,7 +33,7 @@
},
"../../packages/turso-serverless": {
"name": "@tursodatabase/serverless",
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",
"devDependencies": {
"@types/node": "^24.0.13",