diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..c050b589 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-23 - [File Read Opt] +**Learning:** Prefer `await fs.promises.readFile` over `fs.readFileSync` for reading files inside async functions, to avoid blocking the event loop and improve server performance. +**Action:** Replace `fs.readFileSync` with `await fs.promises.readFile` in `src/init-server.ts`. diff --git a/src/init-server.ts b/src/init-server.ts index d459fe7d..28aad4b3 100644 --- a/src/init-server.ts +++ b/src/init-server.ts @@ -17,7 +17,8 @@ async function loadOpenApiSpec(specPath: string, baseUrl: string | undefined): P let rawSpec: string try { - rawSpec = fs.readFileSync(path.resolve(process.cwd(), specPath), 'utf-8') + // ⚡ Bolt Optimization: Use async readFile instead of readFileSync to avoid blocking the event loop during initialization + rawSpec = await fs.promises.readFile(path.resolve(process.cwd(), specPath), 'utf-8') } catch (error) { console.error('Failed to read OpenAPI specification file:', (error as Error).message) process.exit(1)