diff --git a/README.md b/README.md index b0223b5..90e142f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/browser/bundle.js b/browser/bundle.js new file mode 100644 index 0000000..19b4d92 --- /dev/null +++ b/browser/bundle.js @@ -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() diff --git a/browser/deno.browser.json b/browser/deno.browser.json new file mode 100644 index 0000000..15ba30f --- /dev/null +++ b/browser/deno.browser.json @@ -0,0 +1,5 @@ +{ + "imports": { + "../build/vfs.js": "./vfs.js" + } +} \ No newline at end of file diff --git a/browser/import_map.json b/browser/import_map.json deleted file mode 100644 index 4b57f9a..0000000 --- a/browser/import_map.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "imports": { - "../build/vfs.js": "../browser/vfs.js" - } -} diff --git a/browser/vfs.js b/browser/vfs.js index 529a074..d1d2a66 100644 --- a/browser/vfs.js +++ b/browser/vfs.js @@ -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) => { @@ -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 };