Skip to content

Commit

Permalink
Remove the use of Dirent.path as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
surilindur committed May 14, 2024
1 parent c9836a7 commit e46c15f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 10 additions & 8 deletions lib/QueryLoaderFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export class QueryLoaderFile implements IQueryLoader {
public async loadQueries(): Promise<Record<string, string[]>> {
const querySets: Record<string, string[]> = {};
const querySeparator = '\n\n';
for (const file of await readdir(this.path, { encoding: 'utf-8', withFileTypes: true })) {
const extension = extname(file.name);
if (file.isFile() && this.extensions.has(extension)) {
const fileContents = await readFile(join(file.path, file.name), { encoding: 'utf-8' });
const queries = fileContents.split(querySeparator)
.map(query => query.trim())
.filter(query => query.length > 0);
querySets[file.name.replace(extension, '')] = queries;
for (const dirent of await readdir(this.path, { encoding: 'utf-8', withFileTypes: true })) {
if (dirent.isFile()) {
const extension = extname(dirent.name);
if (this.extensions.has(extension)) {
const fileContents = await readFile(join(this.path, dirent.name), { encoding: 'utf-8' });
const queries = fileContents.split(querySeparator)
.map(query => query.trim())
.filter(query => query.length > 0);
querySets[dirent.name.replace(extension, '')] = queries;
}
}
}
return querySets;
Expand Down
1 change: 0 additions & 1 deletion test/QueryLoaderFile-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jest.mock<typeof fsPromises>('node:fs/promises', () => <typeof fsPromises> <unkn
if (path === queryFilesPath) {
return Object.keys(queryFiles).map(file => (<Dirent> {
name: file,
path: queryFilesPath,
isFile: () => true,
}));
}
Expand Down

0 comments on commit e46c15f

Please sign in to comment.