@akiojin/unity-mcp-server 2.45.2 → 2.45.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/core/codeIndex.js
CHANGED
|
@@ -72,8 +72,17 @@ export class CodeIndex {
|
|
|
72
72
|
|
|
73
73
|
// Use shared connection for all CodeIndex instances
|
|
74
74
|
if (sharedConnections.db && sharedConnections.dbPath === dbPath) {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
// Verify the DB file still exists before returning cached connection
|
|
76
|
+
if (!fs.existsSync(dbPath)) {
|
|
77
|
+
// File was deleted or never created, invalidate cache
|
|
78
|
+
logger.info('[index] DB file missing, invalidating cached connection');
|
|
79
|
+
sharedConnections.db = null;
|
|
80
|
+
sharedConnections.dbPath = null;
|
|
81
|
+
sharedConnections.schemaInitialized = false;
|
|
82
|
+
} else {
|
|
83
|
+
this.db = sharedConnections.db;
|
|
84
|
+
return this.db;
|
|
85
|
+
}
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
try {
|
|
@@ -31,9 +31,24 @@ function saveDatabase(db, dbPath) {
|
|
|
31
31
|
try {
|
|
32
32
|
const data = db.exportDb();
|
|
33
33
|
const buffer = Buffer.from(data);
|
|
34
|
+
|
|
35
|
+
// Ensure parent directory exists
|
|
36
|
+
const dir = path.dirname(dbPath);
|
|
37
|
+
if (!fs.existsSync(dir)) {
|
|
38
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
fs.writeFileSync(dbPath, buffer);
|
|
42
|
+
|
|
43
|
+
// Verify file was written
|
|
44
|
+
if (!fs.existsSync(dbPath)) {
|
|
45
|
+
throw new Error('Database file was not created');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
log('info', `[worker] Database saved successfully: ${dbPath} (${buffer.length} bytes)`);
|
|
35
49
|
} catch (e) {
|
|
36
|
-
log('
|
|
50
|
+
log('error', `[worker] Failed to save database: ${e.message}`);
|
|
51
|
+
throw e; // Re-throw to fail the build
|
|
37
52
|
}
|
|
38
53
|
}
|
|
39
54
|
|
|
@@ -184,23 +199,25 @@ async function runBuild() {
|
|
|
184
199
|
let db = null;
|
|
185
200
|
|
|
186
201
|
try {
|
|
187
|
-
// Dynamic import fast-sql
|
|
188
|
-
let
|
|
202
|
+
// Dynamic import fast-sql Database class (uses better-sqlite3 when available, sql.js fallback)
|
|
203
|
+
let Database;
|
|
189
204
|
try {
|
|
190
|
-
const
|
|
191
|
-
|
|
205
|
+
const fastSql = await import('@akiojin/fast-sql');
|
|
206
|
+
Database = fastSql.Database;
|
|
192
207
|
} catch (e) {
|
|
193
208
|
throw new Error(`fast-sql unavailable in worker: ${e.message}`);
|
|
194
209
|
}
|
|
195
210
|
|
|
196
|
-
// Open or create database
|
|
211
|
+
// Open or create database using Database.create() for better-sqlite3 support
|
|
197
212
|
if (fs.existsSync(dbPath)) {
|
|
198
213
|
const buffer = fs.readFileSync(dbPath);
|
|
199
|
-
db =
|
|
214
|
+
db = await Database.create(buffer);
|
|
200
215
|
} else {
|
|
201
|
-
db =
|
|
216
|
+
db = await Database.create();
|
|
202
217
|
}
|
|
203
218
|
|
|
219
|
+
log('info', `[worker] Using backend: ${db.backendType || 'unknown'}`);
|
|
220
|
+
|
|
204
221
|
// Initialize schema if needed (fast-sql applies optimal PRAGMAs automatically)
|
|
205
222
|
runSQL(
|
|
206
223
|
db,
|