Skip to content

Commit e982fc4

Browse files
committed
centralise dev branch path hashing
1 parent 2475580 commit e982fc4

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@ import { devBranchPathSegment } from "../utilities/devBranch.js";
55
import { logger } from "../utilities/logger.js";
66
import { mkdir, writeFile } from "node:fs/promises";
77
import { existsSync, unlinkSync } from "node:fs";
8-
import { createHash } from "node:crypto";
98
import { onExit } from "signal-exit";
109

1110
const LOCK_FILE_NAME = "dev.lock";
1211

1312
/**
1413
* Builds the lock file name for a given branch. The default branch keeps the
1514
* original `dev.lock` name (backwards compatible).
16-
* Throws in a SHA1 of the non-sanitized filename to prevent collision
1715
*/
1816
function lockFileName(branch?: string) {
1917
const safeBranch = devBranchPathSegment(branch);
20-
if (!safeBranch || !branch) return LOCK_FILE_NAME;
21-
const branchHash = createHash("sha1").update(branch).digest("hex").slice(0, 8);
22-
return `dev.${safeBranch}.${branchHash}.lock`;
18+
if (!safeBranch) return LOCK_FILE_NAME;
19+
return `dev.${safeBranch}.lock`;
2320
}
2421

2522
export async function createLockFile(cwd: string, branch?: string) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createHash } from "node:crypto";
12
import { isDefaultDevBranch } from "@trigger.dev/core/v3/utils/gitBranch";
23

34
/**
@@ -15,5 +16,7 @@ export function devBranchPathSegment(branch?: string): string | undefined {
1516
}
1617

1718
// Branch names can contain filesystem-unsafe characters (e.g. "/"), so sanitize.
18-
return branch.replace(/[^a-zA-Z0-9-_]/g, "-");
19+
const sanitized = branch.replace(/[^a-zA-Z0-9-_]/g, "-");
20+
const branchHash = createHash("sha1").update(branch).digest("hex").slice(0, 8);
21+
return `${sanitized}-${branchHash}`;
1922
}

0 commit comments

Comments
 (0)