Skip to content

Commit 1b52b4c

Browse files
committed
Bundle sql.js with production extension
1 parent 6231974 commit 1b52b4c

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
}
146146
}
147147
},
148+
"dependencies": {
149+
"sql.js": "^1.14.1"
150+
},
148151
"devDependencies": {
149152
"@types/adm-zip": "^0.5.7",
150153
"@types/azdata": "^1.46.6",
@@ -163,7 +166,6 @@
163166
"prettier": "3.6.2",
164167
"request": "2.88.2",
165168
"semver": "^7.7.3",
166-
"sql.js": "^1.14.1",
167169
"ts-loader": "^9.5.4",
168170
"tslib": "^2.8.1",
169171
"typescript": "^5.9.3",

src/transcript-watcher.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class TranscriptWatcher {
2525
private logger: Logger;
2626
private pollIntervalMs: number;
2727
private initializedAt: number;
28-
private sqlJsPromise: Promise<SqlJsModule> | null = null;
28+
private sqlJsPromise: Promise<SqlJsModule | null> | null = null;
2929

3030
constructor(logger: Logger) {
3131
this.logger = logger;
@@ -96,13 +96,20 @@ export class TranscriptWatcher {
9696
return found;
9797
}
9898

99-
private async getSqlJs(): Promise<SqlJsModule> {
99+
private async getSqlJs(): Promise<SqlJsModule | null> {
100100
if (!this.sqlJsPromise) {
101-
const initSqlJs = eval('require')('sql.js') as SqlJsInit;
102-
const wasmPath = eval('require').resolve('sql.js/dist/sql-wasm.wasm');
103-
this.sqlJsPromise = fsAsync
104-
.readFile(wasmPath)
105-
.then((wasmBinary) => initSqlJs({ wasmBinary: new Uint8Array(wasmBinary) }));
101+
try {
102+
const requireFunc = eval('require') as NodeRequire;
103+
const initSqlJs = requireFunc('sql.js') as SqlJsInit;
104+
const wasmPath = requireFunc.resolve('sql.js/dist/sql-wasm.wasm');
105+
this.sqlJsPromise = fsAsync
106+
.readFile(wasmPath)
107+
.then((wasmBinary) => initSqlJs({ wasmBinary: new Uint8Array(wasmBinary) }));
108+
} catch (e) {
109+
this.logger.warn('sql.js not available; SQLite transcript logs will be skipped.');
110+
this.logger.debugException(e);
111+
this.sqlJsPromise = Promise.resolve(null);
112+
}
106113
}
107114

108115
return this.sqlJsPromise;
@@ -219,6 +226,7 @@ export class TranscriptWatcher {
219226
fallbackTimestamp?: number,
220227
): Promise<TranscriptHeartbeat[]> {
221228
const SQL = await this.getSqlJs();
229+
if (!SQL) return [];
222230
const db = new SQL.Database(new Uint8Array(await fsAsync.readFile(filePath)));
223231

224232
try {

0 commit comments

Comments
 (0)