| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| export interface CompileError { |
| file: string; |
| error: string; |
| } |
|
|
| let pendingErrors: CompileError[] = []; |
| let stagingErrors: CompileError[] = []; |
|
|
| |
| |
| |
| export function beginCompilation(): void { |
| stagingErrors = []; |
| } |
|
|
| |
| |
| |
| |
| export function pushCompileError(file: string, error: string): void { |
| stagingErrors.push({ file, error }); |
| } |
|
|
| |
| |
| |
| |
| export function commitCompilation(): void { |
| pendingErrors = stagingErrors; |
| stagingErrors = []; |
|
|
| |
| if (typeof window !== 'undefined') { |
| window.dispatchEvent(new CustomEvent('compilationComplete', { |
| detail: { |
| errors: [...pendingErrors], |
| success: pendingErrors.length === 0, |
| timestamp: Date.now(), |
| }, |
| })); |
| } |
| } |
|
|
| |
| |
| |
| |
| export function drainCompileErrors(): CompileError[] { |
| const errors = pendingErrors; |
| pendingErrors = []; |
| return errors; |
| } |
|
|
| |
| |
| |
| export function formatCompileErrors(errors: CompileError[]): string { |
| const grouped = new Map<string, string[]>(); |
| for (const { file, error } of errors) { |
| const list = grouped.get(file) || []; |
| list.push(error); |
| grouped.set(file, list); |
| } |
|
|
| const parts: string[] = []; |
| for (const [file, errs] of grouped) { |
| parts.push(`${file}:\n${errs.map(e => ` - ${e}`).join('\n')}`); |
| } |
|
|
| const hasEsbuildErrors = errors.some(e => e.error.startsWith('[esbuild]')); |
| const hasScriptErrors = errors.some(e => e.file === 'script' || e.file.endsWith('.py') || e.file.endsWith('.lua')); |
| const prefix = hasScriptErrors |
| ? 'Runtime errors detected during script execution. Fix these issues:\n\n' |
| : hasEsbuildErrors |
| ? 'Build errors detected during compilation. Fix these issues:\n\n' |
| : 'The preview detected possible Handlebars template issues after compilation. Verify whether these are still present — they may already be resolved by recent edits:\n\n'; |
|
|
| return `${prefix}${parts.join('\n\n')}`; |
| } |
|
|