From 3bf54dc3a591948e523ace8f75d767119648b61b Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Wed, 14 Jan 2026 13:53:08 +0900 Subject: [PATCH 1/2] chore: fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c1776b..998a84b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This is a custom build of SQLite that only supports the "opfs-sahpool" VFS. It's "nice" because: -- It remove the "opfs" VFS and worker parts of the JS bindings making for a +- It removes the "opfs" VFS and worker parts of the JS bindings making for a smaller bundle size. - It allows passing in a custom path for the WASM module in order to support cache-busting filenames / bundlers. From 4aa8b0afd71b904c384b1d21cd120df0148c1c19 Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Wed, 14 Jan 2026 14:05:47 +0900 Subject: [PATCH 2/2] feat: allow returning a Response or Promise from locateFile --- .changeset/proud-beers-win.md | 5 ++++ README.md | 1 + patches/0003-locatefile-with-response.patch | 28 +++++++++++++++++++++ src/sqlite3.d.ts | 5 +++- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .changeset/proud-beers-win.md create mode 100644 patches/0003-locatefile-with-response.patch diff --git a/.changeset/proud-beers-win.md b/.changeset/proud-beers-win.md new file mode 100644 index 0000000..8cb4a59 --- /dev/null +++ b/.changeset/proud-beers-win.md @@ -0,0 +1,5 @@ +--- +"@birchill/nice-sqlite-wasm": minor +--- + +Allow returning a `Response` or `Promise` from `locateFile` diff --git a/README.md b/README.md index 998a84b..cf8f813 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Then update the table below. | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `0001-locatefile-nullish-coalesce.patch` | Allow a user-provided `locateFile` function to be used (rather than clobbered). | | `0002-hardcode-locatefile-path.patch` | Hardcodes the path used in the default `locateFile` implementation so that bundlers don't complain about dependencies based on expressions. | +| `0003-locatefile-with-response.patch` | Allows a user-provided `locateFile` function to return a `Response` or a `Promise`. | ### Building the WASM module diff --git a/patches/0003-locatefile-with-response.patch b/patches/0003-locatefile-with-response.patch new file mode 100644 index 0000000..2c38739 --- /dev/null +++ b/patches/0003-locatefile-with-response.patch @@ -0,0 +1,28 @@ +diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js +index da399df..9ec48b3 100644 +--- a/ext/wasm/api/pre-js.c-pp.js ++++ b/ext/wasm/api/pre-js.c-pp.js +@@ -101,7 +101,9 @@ + ? "" : scriptDirectory) + ); + sims.debugModule("instantiateWasm() uri =", uri, "sIMS =",this); +- const wfetch = ()=>fetch(uri, {credentials: 'same-origin'}); ++ const response = uri instanceof Response || uri instanceof Promise ++ ? uri ++ : fetch(uri, { credentials: 'same-origin' }); + const finalThen = (arg)=>{ + arg.imports = imports; + sims.instantiateWasm = arg /* used by sqlite3-api-prologue.c-pp.js */; +@@ -110,10 +112,10 @@ + const loadWasm = WebAssembly.instantiateStreaming + ? async ()=> + WebAssembly +- .instantiateStreaming(wfetch(), imports) ++ .instantiateStreaming(response, imports) + .then(finalThen) + : async ()=>// Safari < v15 +- wfetch() ++ Promise.resolve(response) + .then(response => response.arrayBuffer()) + .then(bytes => WebAssembly.instantiate(bytes, imports)) + .then(finalThen) diff --git a/src/sqlite3.d.ts b/src/sqlite3.d.ts index 986c972..84e1b17 100644 --- a/src/sqlite3.d.ts +++ b/src/sqlite3.d.ts @@ -2241,7 +2241,10 @@ declare type Sqlite3Static = { }; declare type InitOptions = { - locateFile?: (path: string, prefix: string) => string; + locateFile?: ( + path: string, + prefix: string, + ) => string | Response | Promise; print?: (msg: string) => void; printErr?: (msg: string) => void; };