Skip to content

Commit 4aaa540

Browse files
committed
fix: Migrate from better-sqlite3 to node-sqlite3-wasm for improved compatibility
1 parent 2a81dc5 commit 4aaa540

File tree

13 files changed

+48
-67
lines changed

13 files changed

+48
-67
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
"applicationinsights": "^2.1.4",
104104
"async": "^3.2.4",
105105
"axios": "^0.27.2",
106-
"better-sqlite3": "^11.5.0",
107106
"body-parser": "^1.20.2",
108107
"boxen": "^5.0.1",
109108
"chalk": "^4.1.2",
@@ -131,6 +130,7 @@
131130
"lunr": "^2.3.9",
132131
"minimatch": "^5.1.2",
133132
"moo": "^0.5.1",
133+
"node-sqlite3-wasm": "^0.8.34",
134134
"open": "^8.2.1",
135135
"openapi-diff": "^0.23.6",
136136
"openapi-types": "^12.1.3",

packages/cli/src/cmds/search/search.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import sqlite3 from 'node-sqlite3-wasm';
12
import yargs from 'yargs';
2-
import sqlite3 from 'better-sqlite3';
33
import assert from 'assert';
44
import { readFileSync } from 'fs';
55
import { writeFile } from 'fs/promises';
@@ -186,7 +186,7 @@ export const handler = async (argv: ArgumentTypes) => {
186186
};
187187

188188
const index = await buildIndexInTempDir('appmaps', async (indexFile) => {
189-
const db = new sqlite3(indexFile);
189+
const db = new sqlite3.Database(indexFile);
190190
const fileIndex = new FileIndex(db);
191191
await buildAppMapIndex(fileIndex, [process.cwd()]);
192192
return fileIndex;

packages/cli/src/rpc/explain/index-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sqlite3 from 'better-sqlite3';
1+
import type sqlite3 from 'node-sqlite3-wasm';
22

33
import {
44
buildFileIndex,

packages/cli/src/rpc/explain/index-snippets.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sqlite3 from 'node-sqlite3-wasm';
2+
13
import {
24
buildSnippetIndex,
35
FileSearchResult,
@@ -6,7 +8,6 @@ import {
68
readFileSafe,
79
SnippetIndex,
810
} from '@appland/search';
9-
import sqlite3 from 'better-sqlite3';
1011

1112
export default async function indexSnippets(
1213
db: sqlite3.Database,

packages/cli/src/rpc/explain/index/appmap-file-index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sqlite3 from 'better-sqlite3';
1+
import sqlite3 from 'node-sqlite3-wasm';
22

33
import { FileIndex, SessionId } from '@appland/search';
44

@@ -10,7 +10,7 @@ export async function buildAppMapFileIndex(
1010
appmapDirectories: string[]
1111
): Promise<CloseableIndex<FileIndex>> {
1212
return await buildIndexInTempDir<FileIndex>('appmaps', async (indexFile) => {
13-
const db = new sqlite3(indexFile);
13+
const db = new sqlite3.Database(indexFile);
1414
const fileIndex = new FileIndex(db);
1515
await buildAppMapIndex(fileIndex, appmapDirectories);
1616
return fileIndex;

packages/cli/src/rpc/explain/index/project-file-index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import sqlite3 from 'better-sqlite3';
21
import makeDebug from 'debug';
2+
import sqlite3 from 'node-sqlite3-wasm';
33

44
import {
55
buildFileIndex,
@@ -71,7 +71,7 @@ export async function buildProjectFileIndex(
7171
excludePatterns: RegExp[] | undefined
7272
): Promise<CloseableIndex<FileIndex>> {
7373
return await buildIndexInTempDir('files', async (indexFile) => {
74-
const db = new sqlite3(indexFile);
74+
const db = new sqlite3.Database(indexFile);
7575
return await indexFiles(db, sourceDirectories, includePatterns, excludePatterns);
7676
});
7777
}

packages/cli/src/rpc/explain/index/project-file-snippet-index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import sqlite3 from 'better-sqlite3';
1+
import sqlite3 from 'node-sqlite3-wasm';
2+
23
import { FileSearchResult, SessionId, SnippetIndex } from '@appland/search';
34

45
import buildIndexInTempDir, { CloseableIndex } from './build-index-in-temp-dir';
@@ -76,7 +77,7 @@ export async function buildProjectFileSnippetIndex(
7677
fileSearchResults: FileSearchResult[]
7778
): Promise<ProjectFileSnippetIndex> {
7879
const snippetIndex = await buildIndexInTempDir('snippets', async (indexFile) => {
79-
const db = new sqlite3(indexFile);
80+
const db = new sqlite3.Database(indexFile);
8081
return await indexSnippets(db, fileSearchResults);
8182
});
8283

packages/cli/src/rpc/search/search.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { isAbsolute, join } from 'path';
2-
import sqlite3 from 'better-sqlite3';
2+
3+
import sqlite3 from 'node-sqlite3-wasm';
4+
35
import { FileIndex, generateSessionId } from '@appland/search';
46
import { SearchRpc } from '@appland/rpc';
57

@@ -62,7 +64,7 @@ export async function handler(
6264
// Search across all AppMaps, creating a map from AppMap id to AppMapSearchResult
6365
const maxResults = options.maxDiagrams || options.maxResults || DEFAULT_MAX_DIAGRAMS;
6466
const index = await buildIndexInTempDir('appmaps', async (indexFile) => {
65-
const db = new sqlite3(indexFile);
67+
const db = new sqlite3.Database(indexFile);
6668
const fileIndex = new FileIndex(db);
6769
await buildAppMapIndex(
6870
fileIndex,

packages/search/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"typescript-eslint": "^8.11.0"
4040
},
4141
"dependencies": {
42-
"better-sqlite3": "^11.5.0",
4342
"isbinaryfile": "^5.0.4",
43+
"node-sqlite3-wasm": "^0.8.34",
4444
"yargs": "^17.7.2"
4545
}
4646
}

packages/search/src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import yargs from 'yargs';
22
import { hideBin } from 'yargs/helpers';
3-
import sqlite3 from 'better-sqlite3';
43
import makeDebug from 'debug';
4+
import sqlite3 from 'node-sqlite3-wasm';
55

66
import { fileTokens } from './tokenize';
77
import FileIndex from './file-index';
@@ -62,7 +62,7 @@ const cli = yargs(hideBin(process.argv))
6262
return !filterRE.test(path);
6363
};
6464

65-
const db = new sqlite3(':memory:');
65+
const db = new sqlite3.Database(':memory:');
6666
const fileIndex = new FileIndex(db);
6767
const sessionId = generateSessionId();
6868

0 commit comments

Comments
 (0)