Skip to content

Commit 19bc688

Browse files
authored
Merge pull request #9 from andrea9293/andrea9293/issue8
fix(indexing): avoid fs-extra ESM/CJS interop causing fs.readdir error
2 parents 9425fc1 + ccd92e1 commit 19bc688

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

package-lock.json

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

src/indexing/document-index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createHash } from 'crypto';
2-
import * as fs from 'fs-extra';
2+
import fse from 'fs-extra';
3+
import { promises as fsp } from 'fs';
34
import * as path from 'path';
45

56
/**
@@ -224,18 +225,18 @@ export class DocumentIndex {
224225
lastUpdated: new Date().toISOString()
225226
};
226227

227-
await fs.writeJSON(this.indexFilePath, indexData, { spaces: 2 });
228+
await fse.writeJSON(this.indexFilePath, indexData, { spaces: 2 });
228229
}
229230

230231
/**
231232
* Load index from disk
232233
*/
233234
private async loadIndex(): Promise<void> {
234-
if (!await fs.pathExists(this.indexFilePath)) {
235+
if (!await fse.pathExists(this.indexFilePath)) {
235236
throw new Error('Index file does not exist');
236237
}
237238

238-
const indexData = await fs.readJSON(this.indexFilePath);
239+
const indexData = await fse.readJSON(this.indexFilePath);
239240

240241
this.documentMap = new Map(Object.entries(indexData.documentMap || {}));
241242
this.chunkMap = new Map(Object.entries(indexData.chunkMap || {}));
@@ -257,13 +258,13 @@ export class DocumentIndex {
257258
this.keywordIndex.clear();
258259

259260
try {
260-
const files = await fs.readdir(dataDir);
261+
const files = await fsp.readdir(dataDir);
261262
const documentFiles = files.filter(file => file.endsWith('.json') && file !== 'document-index.json');
262263

263264
for (const file of documentFiles) {
264265
try {
265266
const filePath = path.join(dataDir, file);
266-
const document = await fs.readJSON(filePath);
267+
const document = await fse.readJSON(filePath);
267268

268269
if (document.id && document.content) {
269270
this.addDocument(document.id, filePath, document.content, document.chunks);

0 commit comments

Comments
 (0)