Skip to content

Commit e7fec40

Browse files
authored
fix(dev): CLI now properly cleans up the store dir on dev CLI exit (#2744)
1 parent d279988 commit e7fec40

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/cli-v3/src/dev/devSession.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ResolvedConfig } from "@trigger.dev/core/v3/build";
22
import * as esbuild from "esbuild";
3-
import { existsSync, mkdirSync, rmSync } from "node:fs";
43
import { CliApiClient } from "../apiClient.js";
54
import {
65
BundleResult,
@@ -59,7 +58,7 @@ export async function startDevSession({
5958
clearTmpDirs(rawConfig.workingDir);
6059
const destination = getTmpDir(rawConfig.workingDir, "build", keepTmpFiles);
6160
// Create shared store directory for deduplicating chunk files across rebuilds
62-
const storeDir = getStoreDir(rawConfig.workingDir);
61+
const storeDir = getStoreDir(rawConfig.workingDir, keepTmpFiles);
6362

6463
const runtime = await startWorkerRuntime({
6564
name,

packages/cli-v3/src/utilities/tempDirectories.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,23 @@ export function clearTmpDirs(projectRoot: string | undefined) {
6363
* Gets the shared store directory for content-addressable build outputs.
6464
* This directory persists across rebuilds and is used to deduplicate
6565
* identical chunk files between build versions.
66+
* Automatically cleaned up when the process exits.
6667
*/
67-
export function getStoreDir(projectRoot: string | undefined): string {
68+
export function getStoreDir(projectRoot: string | undefined, keep: boolean = false): string {
6869
projectRoot ??= process.cwd();
6970
const storeDir = path.join(projectRoot, ".trigger", "tmp", "store");
7071
fs.mkdirSync(storeDir, { recursive: true });
72+
73+
// Register exit handler to clean up the store directory
74+
if (!keep && !process.env.KEEP_TMP_DIRS) {
75+
onExit(() => {
76+
try {
77+
fs.rmSync(storeDir, { recursive: true, force: true });
78+
} catch (e) {
79+
// This sometimes fails on Windows with EBUSY
80+
}
81+
});
82+
}
83+
7184
return storeDir;
7285
}

0 commit comments

Comments
 (0)