Skip to content

Commit 9951a45

Browse files
committed
Replace top-level await with synchronous fs calls.
1 parent a451868 commit 9951a45

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

lib/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
/*!
2-
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
2+
* Copyright (c) 2023-2026 Digital Bazaar, Inc. All rights reserved.
33
*/
44
import {fileURLToPath} from 'node:url';
5-
import fs from 'node:fs/promises';
5+
import fs from 'node:fs';
66
import path from 'node:path';
77

88
const __dirname = path.dirname(fileURLToPath(import.meta.url));
99

1010
export const contextsDir = path.resolve(__dirname, '..', 'contexts');
1111
export const credentialsDir = path.resolve(__dirname, '..', 'credentials');
12-
13-
const entries = await fs.readdir(credentialsDir, {withFileTypes: true});
12+
/**
13+
* TODO: Add an async `loadExamples()` API as additional surface.
14+
* - Should be idempotent (loads once, caches result).
15+
* - Sync loading remains for backward compatibility.
16+
*/
17+
const entries = fs.readdirSync(credentialsDir, {withFileTypes: true});
1418
const credentialDirs = entries.filter(e => e.isDirectory()).map(d => d.name);
1519

1620
const credentials = {};
@@ -23,14 +27,14 @@ for(const dirName of credentialDirs) {
2327
let queries = null;
2428

2529
try {
26-
const credText = await fs.readFile(credentialJsonPath, 'utf8');
30+
const credText = fs.readFileSync(credentialJsonPath, 'utf8');
2731
credential = JSON.parse(credText);
2832
} catch(e) {
2933
throw new Error(`Failed to read/parse ${credentialJsonPath}: ${e.message}`);
3034
}
3135

3236
try {
33-
const queriesText = await fs.readFile(queriesJsonPath, 'utf8');
37+
const queriesText = fs.readFileSync(queriesJsonPath, 'utf8');
3438
queries = JSON.parse(queriesText);
3539
} catch{
3640
// if queries.json is missing or invalid, keep as null

0 commit comments

Comments
 (0)