mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
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:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user