()
| 45 | } |
| 46 | |
| 47 | const cleanup = async () => { |
| 48 | if (cleanupPromise) { |
| 49 | return cleanupPromise |
| 50 | } |
| 51 | |
| 52 | cleanupStarted = true |
| 53 | cleanupPromise = (async () => { |
| 54 | logger.debug(`${logPrefix} Cleanup start`) |
| 55 | restoreTerminalState() |
| 56 | |
| 57 | try { |
| 58 | options.stopKeepAlive?.() |
| 59 | await options.onBeforeClose?.() |
| 60 | await archiveAndClose() |
| 61 | logger.debug(`${logPrefix} Cleanup complete`) |
| 62 | } finally { |
| 63 | try { |
| 64 | await options.onAfterClose?.() |
| 65 | } catch (error) { |
| 66 | logger.debug(`${logPrefix} Error during post-cleanup:`, error) |
| 67 | } |
| 68 | } |
| 69 | })() |
| 70 | |
| 71 | return cleanupPromise |
| 72 | } |
| 73 | |
| 74 | const cleanupAndExit = async (codeOverride?: number) => { |
| 75 | if (codeOverride !== undefined) { |
no test coverage detected