feat: 在退出前输出指令序列

This commit is contained in:
2026-02-06 01:56:17 +08:00
parent fea1fe84bf
commit 7b1c87f2a4
2 changed files with 10 additions and 3 deletions

View File

@@ -3,6 +3,14 @@ import type { TracerCommand } from '../types';
const createTracerContext = () => {
const commands: TracerCommand[] = [];
if (typeof process !== 'undefined' && typeof process.on === 'function') {
process.on('exit', () => {
if (commands.length > 0) {
console.log(commands);
}
});
}
const getTracerContext = () => {
const command = (command: TracerCommand) => {
commands.push(command);

View File

@@ -1,4 +1,3 @@
import { getTracerContext } from './context';
import {
createArrayTracer,
createControlTracer,
@@ -15,6 +14,6 @@ const arrayTracer = createArrayTracer({
arrayTracer.patch(0, 100);
controlTracer.step();
logTracer.log(`patch array[0] to 100`);
console.log(getTracerContext().commands);
controlTracer.step();