( filePath: string, content: string, rootDir: string, )
| 43 | * (e.g., DSL-to-JS compilation) does not require additional gating. |
| 44 | */ |
| 45 | export async function writeFile( |
| 46 | filePath: string, |
| 47 | content: string, |
| 48 | rootDir: string, |
| 49 | ): Promise<string> { |
| 50 | const resolved = await resolveAndValidate(filePath, rootDir); |
| 51 | const ext = path.extname(resolved).toLowerCase(); |
| 52 | if (!ALLOWED_WRITE_EXTENSIONS.includes(ext)) { |
| 53 | throw new Error( |
| 54 | `Write rejected: only ${ALLOWED_WRITE_EXTENSIONS.join(', ')} files are allowed`, |
| 55 | ); |
| 56 | } |
| 57 | await fs.mkdir(path.dirname(resolved), { recursive: true }); |
| 58 | await fs.writeFile(resolved, content, 'utf-8'); |
| 59 | return resolved; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Read a file relative to rootDir. Truncates returned text at MAX_FILE_SIZE |
no test coverage detected
searching dependent graphs…