Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Browser Build for Deno 2 #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Owner

@dyedgreen dyedgreen Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can look down permissions a bit more here?

--allow-run isn’t required, and we can scope reading to the repo and writing to just the bundle.

```

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/[email protected]/mod.js'
import { denoPlugins } from 'jsr:@luca/[email protected]'

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
Loading