Skip to content

Commit

Permalink
Update Browser Build for Deno 2
Browse files Browse the repository at this point in the history
  • Loading branch information
aunyks committed Oct 27, 2024
1 parent c7d4365 commit dcd0872
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ There is **experimental** support for using `deno-sqlite` in the browser. You
can generate a browser compatible module by running:

```bash
deno bundle --import-map browser/import_map.json browser/mod.ts [output_bundle_path]
deno run --allow-run --allow-env --allow-read --allow-write ./browser/bundle.js
```

The modules documentation can be seen by running
Expand Down
20 changes: 20 additions & 0 deletions browser/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as esbuild from 'https://deno.land/x/esbuild@v0.20.1/mod.js'
import { denoPlugins } from 'jsr:@luca/esbuild-deno-loader@0.9'

esbuild.build({
plugins: [
...denoPlugins({
configPath: await Deno.realPath('./browser/deno.browser.json'),
}),
],
entryPoints: [await Deno.realPath('./browser/mod.ts')],
outdir: await Deno.realPath('./'),
bundle: true,
platform: 'browser',
format: 'esm',
target: 'esnext',
minify: true,
sourcemap: true,
treeShaking: true,
})
await esbuild.stop()
5 changes: 5 additions & 0 deletions browser/deno.browser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"../build/vfs.js": "./vfs.js"
}
}
5 changes: 0 additions & 5 deletions browser/import_map.json

This file was deleted.

12 changes: 9 additions & 3 deletions browser/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ class Buffer {
}
}

const indexedDB = window.indexedDB || window.mozIndexedDB ||
window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
const indexedDB = window.indexedDB ||
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB ||
window.shimIndexedDB;

// Web browser indexedDB database
const database = new Promise((resolve, reject) => {
Expand Down Expand Up @@ -195,13 +198,16 @@ export default function env(inst) {
return Date.now();
},
js_timezone: () => {
return (new Date()).getTimezoneOffset();
return new Date().getTimezoneOffset();
},
js_exists: (path_ptr) => {
const path = getStr(inst.exports, path_ptr);
return LOADED_FILES.has(path) ? 1 : 0;
},
js_access: (_path_ptr) => 1,
js_call_user_func: (func_idx, arg_count) => {
inst.functions[func_idx](arg_count);
},
};

return { env };
Expand Down

0 comments on commit dcd0872

Please sign in to comment.