Skip to content

Commit fb4ae34

Browse files
committed
🤖 fix: replace existsSync with async access() in ExtensionMetadataService
Replaced all sync fs operations (existsSync) with async alternatives using fs/promises access(). This eliminates the last sync operations in the service. Changes: - Import access() and constants from fs/promises and fs - Replace existsSync checks with try/catch on access() - initialize(): Check directory existence with access() before mkdir - load(): Check file existence with access() before readFile Why ESLint didn't catch this: - The 'local/no-sync-fs-methods' rule only catches fs.methodSync() usage - Direct imports like 'import { existsSync } from "fs"' are not detected - Rule needs enhancement to check ImportSpecifier nodes Next steps: - Enhance ESLint rule to catch direct imports of sync methods - Or add src/utils/extensionMetadata.ts to allow list if sync is needed there
1 parent 0a73310 commit fb4ae34

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

‎src/services/ExtensionMetadataService.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { dirname } from "path";
2-
import { mkdir, readFile } from "fs/promises";
3-
import { existsSync } from "fs";
2+
import { mkdir, readFile, access } from "fs/promises";
3+
import { constants } from "fs";
44
import writeFileAtomic from "write-file-atomic";
55
import {
66
type ExtensionMetadata,
@@ -43,7 +43,9 @@ export class ExtensionMetadataService {
4343
async initialize(): Promise<void> {
4444
// Ensure directory exists
4545
const dir = dirname(this.filePath);
46-
if (!existsSync(dir)) {
46+
try {
47+
await access(dir, constants.F_OK);
48+
} catch {
4749
await mkdir(dir, { recursive: true });
4850
}
4951

@@ -52,7 +54,9 @@ export class ExtensionMetadataService {
5254
}
5355

5456
private async load(): Promise<ExtensionMetadataFile> {
55-
if (!existsSync(this.filePath)) {
57+
try {
58+
await access(this.filePath, constants.F_OK);
59+
} catch {
5660
return { version: 1, workspaces: {} };
5761
}
5862

0 commit comments

Comments
 (0)