1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

More work on creating a separate sqlite3.js build which is hopefully friendly to JS bundlers.

FossilOrigin-Name: b7b896fb448a7f46eb88eadadb1359255aec637a384cabcdd526276a02f4f0b4
This commit is contained in:
stephan
2023-01-27 03:18:16 +00:00
parent 67bfea4ea6
commit a0013fbe87
8 changed files with 53 additions and 24 deletions

View File

@ -704,7 +704,9 @@ $(sqlite3-bundler-friendly.mjs):
# (and harmless, just a waste of build time).
$(sqlite3.wasm): $(sqlite3.js)
$(sqlite3.mjs): $(sqlite3.js)
$(sqlite3-bundler-friendly.mjs): $(sqlite3.js)
$(sqlite3-bundler-friendly.mjs): $(sqlite3.mjs)
# maintenance reminder: the deps on ^^^ must all be such that they are
# never built in parallel.
CLEAN_FILES += $(sqlite3.js) $(sqlite3.mjs) $(sqlite3-bundler-friendly.mjs) \
$(sqlite3.wasm)
all: $(sqlite3.js) $(sqlite3.mjs) $(sqlite3-bundler-friendly.mjs)

View File

@ -45,14 +45,23 @@ const toExportForES6 =
moduleScript: self?.document?.currentScript,
isWorker: ('undefined' !== typeof WorkerGlobalScope),
location: self.location,
urlParams: new URL(self.location.href).searchParams
urlParams:
//#if target=es6-bundler-friendly
undefined
//#else
new URL(self.location.href).searchParams
//#endif
});
initModuleState.debugModule =
(new URL(self.location.href).searchParams).has('sqlite3.debugModule')
//#if target=es6-bundler-friendly
()=>{}
//#else
(new URL(self.location.href).searchParams).has('sqlite3.debugModule')
? (...args)=>console.warn('sqlite3.debugModule:',...args)
: ()=>{};
//#endif
if(initModuleState.urlParams.has('sqlite3.dir')){
if(initModuleState.urlParams && initModuleState.urlParams.has('sqlite3.dir')){
initModuleState.sqlite3Dir = initModuleState.urlParams.get('sqlite3.dir') +'/';
}else if(initModuleState.moduleScript){
const li = initModuleState.moduleScript.src.split('/');

View File

@ -6,7 +6,10 @@
*/
// See notes in extern-post-js.js
const sqlite3InitModuleState = self.sqlite3InitModuleState || Object.create(null);
const sqlite3InitModuleState = self.sqlite3InitModuleState
|| Object.assign(Object.create(null),{
debugModule: ()=>{}
});
delete self.sqlite3InitModuleState;
sqlite3InitModuleState.debugModule('self.location =',self.location);

View File

@ -100,13 +100,20 @@ const installOpfsVfs = function callee(options){
if(!options || 'object'!==typeof options){
options = Object.create(null);
}
const urlParams = new URL(self.location.href).searchParams;
if(undefined===options.verbose){
options.verbose = urlParams.has('opfs-verbose')
? (+urlParams.get('opfs-verbose') || 2) : 1;
}
if(undefined===options.sanityChecks){
options.sanityChecks = urlParams.has('opfs-sanity-check');
const urlParams =
//#if target=es6-bundler-friendly
undefined;
//#else
new URL(self.location.href).searchParams;
//#endif
if(urlParams){
if(undefined===options.verbose){
options.verbose = urlParams.has('opfs-verbose')
? (+urlParams.get('opfs-verbose') || 2) : 1;
}
if(undefined===options.sanityChecks){
options.sanityChecks = urlParams.has('opfs-sanity-check');
}
}
if(undefined===options.proxyUri){
options.proxyUri = callee.defaultProxyUri;

View File

@ -238,6 +238,9 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
}/*sqlite3Worker1Promiser()*/;
self.sqlite3Worker1Promiser.defaultConfig = {
worker: function(){
//#if target=es6-bundler-friendly
return new Worker("sqlite3-worker1.js");
//#else
let theJs = "sqlite3-worker1.js";
if(this.currentScript){
const src = this.currentScript.src.split('/');
@ -252,6 +255,7 @@ self.sqlite3Worker1Promiser.defaultConfig = {
}
}
return new Worker(theJs + self.location.search);
//#endif
}.bind({
currentScript: self?.document?.currentScript
}),

View File

@ -33,6 +33,9 @@
*/
"use strict";
(()=>{
//#if target=es6-bundler-friendly
importScripts('sqlite3.js');
//#else
const urlParams = new URL(self.location.href).searchParams;
let theJs = 'sqlite3.js';
if(urlParams.has('sqlite3.dir')){
@ -40,6 +43,7 @@
}
//console.warn("worker1 theJs =",theJs);
importScripts(theJs);
//#endif
sqlite3InitModule().then((sqlite3)=>{
sqlite3.initWorker1API();
});