diff options
author | stephan <stephan@noemail.net> | 2023-01-27 01:33:12 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2023-01-27 01:33:12 +0000 |
commit | 0cd38cd2b9adb966e4ff02596526725311fadf64 (patch) | |
tree | 1712db9a14f4c675e55f68eee1428006a4226ffd /ext/wasm/api | |
parent | 0945197a39896ec49ecfffd8f7b10ecc844020ac (diff) | |
download | sqlite-0cd38cd2b9adb966e4ff02596526725311fadf64.tar.gz sqlite-0cd38cd2b9adb966e4ff02596526725311fadf64.zip |
Beginnings of a bundler-friendly build of sqlite3.mjs. Not yet ready for downstream testing.
FossilOrigin-Name: 4271bf5f41df091696f1dcfc4ffe7a60d24066fc75c896941e0b56de95fe5f89
Diffstat (limited to 'ext/wasm/api')
-rw-r--r-- | ext/wasm/api/extern-post-js.c-pp.js | 5 | ||||
-rw-r--r-- | ext/wasm/api/pre-js.c-pp.js | 13 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 4 |
3 files changed, 17 insertions, 5 deletions
diff --git a/ext/wasm/api/extern-post-js.c-pp.js b/ext/wasm/api/extern-post-js.c-pp.js index 225869794..87d99eaba 100644 --- a/ext/wasm/api/extern-post-js.c-pp.js +++ b/ext/wasm/api/extern-post-js.c-pp.js @@ -105,6 +105,10 @@ const toExportForES6 = document?.currentScript?.src); } } +//#ifnot target=es6-module +// Emscripten does not inject these module-loader bits in ES6 module +// build and including them here breaks JS bundlers, so elide them +// from ES6 builds. /* Replace the various module exports performed by the Emscripten glue... */ if (typeof exports === 'object' && typeof module === 'object'){ @@ -114,6 +118,7 @@ const toExportForES6 = } /* AMD modules get injected in a way we cannot override, so we can't handle those here. */ +//#endif // !target=es6-module return self.sqlite3InitModule /* required for ESM */; })(); //#if target=es6-module diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js index 2e2fe66bc..d1ee3be19 100644 --- a/ext/wasm/api/pre-js.c-pp.js +++ b/ext/wasm/api/pre-js.c-pp.js @@ -29,7 +29,12 @@ sqlite3InitModuleState.debugModule('self.location =',self.location); 4) If none of the above apply, (prefix+path) is returned. */ Module['locateFile'] = function(path, prefix) { -//#if target=es6-module +//#if target=es6-bundler-friendly + // TEMPORARY KLUDGE to work around a c-pp nested blocks bug which is + // currently eluding a fix. We really should have (#ifnot + // target=es6-bundler-friendly) around this whole function. + return new URL('sqlite3.wasm', import.meta.url).href; +//#elif target=es6-module return new URL(path, import.meta.url).href; //#else 'use strict'; @@ -51,7 +56,7 @@ Module['locateFile'] = function(path, prefix) { "result =", theFile ); return theFile; -//#endif /* SQLITE_JS_EMS */ +//#endif //target=es6-module }.bind(sqlite3InitModuleState); /** @@ -62,7 +67,7 @@ Module['locateFile'] = function(path, prefix) { In such builds we must disable this. */ -const xNameOfInstantiateWasm = true +const xNameOfInstantiateWasm = false ? 'instantiateWasm' : 'emscripten-bug-17951'; Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){ @@ -102,4 +107,4 @@ Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){ Module[xNameOfInstantiateWasm].uri = 'sqlite3.wasm'; /* END FILE: api/pre-js.js, noting that the build process may add a line after this one to change the above .uri to a build-specific - one. */ + one. *//* END FILE: api/pre-js.js */ diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index 2ded905ad..451f0019c 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -198,7 +198,9 @@ const installOpfsVfs = function callee(options){ return promiseReject_(err); }; const W = -//#if target=es6-module +//#if target=es6-bundler-friendly + new Worker(new URL("sqlite3-opfs-async-proxy.js", import.meta.url)); +//#elif target=es6-module new Worker(new URL(options.proxyUri, import.meta.url)); //#else new Worker(options.proxyUri); |