(cwd, state)
| 90 | } |
| 91 | |
| 92 | export function saveState(cwd, state) { |
| 93 | const previousJobs = loadState(cwd).jobs; |
| 94 | ensureStateDir(cwd); |
| 95 | const nextJobs = pruneJobs(state.jobs ?? []); |
| 96 | const nextState = { |
| 97 | version: STATE_VERSION, |
| 98 | config: { |
| 99 | ...defaultState().config, |
| 100 | ...(state.config ?? {}) |
| 101 | }, |
| 102 | jobs: nextJobs |
| 103 | }; |
| 104 | |
| 105 | const retainedIds = new Set(nextJobs.map((job) => job.id)); |
| 106 | for (const job of previousJobs) { |
| 107 | if (retainedIds.has(job.id)) { |
| 108 | continue; |
| 109 | } |
| 110 | removeJobFile(resolveJobFile(cwd, job.id)); |
| 111 | removeFileIfExists(job.logFile); |
| 112 | } |
| 113 | |
| 114 | fs.writeFileSync(resolveStateFile(cwd), `${JSON.stringify(nextState, null, 2)}\n`, "utf8"); |
| 115 | return nextState; |
| 116 | } |
| 117 | |
| 118 | export function updateState(cwd, mutate) { |
| 119 | const state = loadState(cwd); |
no test coverage detected