Move branch sanitization from contracts to new shared package
Create @t3tools/shared with explicit subpath exports (no barrel) for shared utility logic. Move sanitizeBranchFragment and sanitizeFeatureBranchName to @t3tools/shared/git, keeping contracts focused on schemas. Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
1 parent
b1608f41ad
commit
dde48e9414
10 files changed
+75
-43
No files matched your search
@@ -30,6 +30,7 @@
|
||||
"@effect/language-service": "0.75.1",
|
||||
"@effect/vitest": "catalog:",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@t3tools/web": "workspace:*",
|
||||
"@types/bun": "^1.3.9",
|
||||
"@types/node": "^24.10.13",
|
||||
|
||||
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { Effect, FileSystem, Layer, Option, Path, Schema, Stream } from "effect";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import { sanitizeBranchFragment, sanitizeFeatureBranchName } from "@t3tools/contracts";
|
||||
import { sanitizeBranchFragment, sanitizeFeatureBranchName } from "@t3tools/shared/git";
|
||||
|
||||
import { resolveAttachmentPath } from "../../attachmentStore.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
import { Effect, FileSystem, Layer, Path } from "effect";
|
||||
import { sanitizeFeatureBranchName } from "@t3tools/contracts";
|
||||
import { sanitizeFeatureBranchName } from "@t3tools/shared/git";
|
||||
|
||||
import { GitManagerError } from "../Errors.ts";
|
||||
import { GitManager, type GitManagerShape } from "../Services/GitManager.ts";
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"@lexical/react": "^0.41.0",
|
||||
"@pierre/diffs": "^1.1.0-beta.16",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@tanstack/react-pacer": "^0.19.4",
|
||||
"@tanstack/react-query": "^5.90.0",
|
||||
"@tanstack/react-router": "^1.160.2",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
type GitRunStackedActionResult,
|
||||
type GitStackedAction,
|
||||
type GitStatusResult,
|
||||
sanitizeBranchFragment,
|
||||
import type {
|
||||
GitRunStackedActionResult,
|
||||
GitStackedAction,
|
||||
GitStatusResult,
|
||||
} from "@t3tools/contracts";
|
||||
import { sanitizeBranchFragment } from "@t3tools/shared/git";
|
||||
|
||||
export type GitActionIconName = "commit" | "push" | "pr";
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
"@effect/language-service": "0.75.1",
|
||||
"@effect/vitest": "catalog:",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@t3tools/web": "workspace:*",
|
||||
"@types/bun": "^1.3.9",
|
||||
"@types/node": "^24.10.13",
|
||||
@@ -67,6 +68,7 @@
|
||||
"@lexical/react": "^0.41.0",
|
||||
"@pierre/diffs": "^1.1.0-beta.16",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@tanstack/react-pacer": "^0.19.4",
|
||||
"@tanstack/react-query": "^5.90.0",
|
||||
"@tanstack/react-router": "^1.160.2",
|
||||
@@ -110,6 +112,13 @@
|
||||
"typescript": "^5.7.3",
|
||||
},
|
||||
},
|
||||
"packages/shared": {
|
||||
"name": "@t3tools/shared",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"devDependencies": {
|
||||
"typescript": "^5.7.3",
|
||||
},
|
||||
},
|
||||
},
|
||||
"catalog": {
|
||||
"@effect/language-service": "0.75.1",
|
||||
@@ -537,6 +546,8 @@
|
||||
|
||||
"@t3tools/desktop": ["@t3tools/desktop@workspace:apps/desktop"],
|
||||
|
||||
"@t3tools/shared": ["@t3tools/shared@workspace:packages/shared"],
|
||||
|
||||
"@t3tools/web": ["@t3tools/web@workspace:apps/web"],
|
||||
|
||||
"@tailwindcss/node": ["@tailwindcss/[email protected]", "", { "dependencies": { "@jridgewell/remapping": "^2.3.4", "enhanced-resolve": "^5.18.3", "jiti": "^2.6.1", "lightningcss": "1.30.2", "magic-string": "^0.30.21", "source-map-js": "^1.2.1", "tailwindcss": "4.1.18" } }, "sha512-DoR7U1P7iYhw16qJ49fgXUlry1t4CpXeErJHnQ44JgTSKMaZUdf17cfn5mHchfJ4KRBZRFA/Coo+MUF5+gOaCQ=="],
|
||||
|
||||
@@ -179,39 +179,3 @@ export const GitPullResult = Schema.Struct({
|
||||
upstreamBranch: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),
|
||||
});
|
||||
export type GitPullResult = typeof GitPullResult.Type;
|
||||
|
||||
// Branch name utilities
|
||||
|
||||
/**
|
||||
* Sanitize an arbitrary string into a valid, lowercase git branch fragment.
|
||||
* Strips quotes, collapses separators, limits to 64 chars.
|
||||
*/
|
||||
export function sanitizeBranchFragment(raw: string): string {
|
||||
const normalized = raw
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/['"`]/g, "")
|
||||
.replace(/^[./\s_-]+|[./\s_-]+$/g, "");
|
||||
|
||||
const branchFragment = normalized
|
||||
.replace(/[^a-z0-9/_-]+/g, "-")
|
||||
.replace(/\/+/g, "/")
|
||||
.replace(/-+/g, "-")
|
||||
.replace(/^[./_-]+|[./_-]+$/g, "")
|
||||
.slice(0, 64)
|
||||
.replace(/[./_-]+$/g, "");
|
||||
|
||||
return branchFragment.length > 0 ? branchFragment : "update";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a string into a `feature/…` branch name.
|
||||
* Preserves an existing `feature/` prefix or slash-separated namespace.
|
||||
*/
|
||||
export function sanitizeFeatureBranchName(raw: string): string {
|
||||
const sanitized = sanitizeBranchFragment(raw);
|
||||
if (sanitized.includes("/")) {
|
||||
return sanitized.startsWith("feature/") ? sanitized : `feature/${sanitized}`;
|
||||
}
|
||||
return `feature/${sanitized}`;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@t3tools/shared",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./git": {
|
||||
"types": "./src/git.ts",
|
||||
"import": "./src/git.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.7.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Sanitize an arbitrary string into a valid, lowercase git branch fragment.
|
||||
* Strips quotes, collapses separators, limits to 64 chars.
|
||||
*/
|
||||
export function sanitizeBranchFragment(raw: string): string {
|
||||
const normalized = raw
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/['"`]/g, "")
|
||||
.replace(/^[./\s_-]+|[./\s_-]+$/g, "");
|
||||
|
||||
const branchFragment = normalized
|
||||
.replace(/[^a-z0-9/_-]+/g, "-")
|
||||
.replace(/\/+/g, "/")
|
||||
.replace(/-+/g, "-")
|
||||
.replace(/^[./_-]+|[./_-]+$/g, "")
|
||||
.slice(0, 64)
|
||||
.replace(/[./_-]+$/g, "");
|
||||
|
||||
return branchFragment.length > 0 ? branchFragment : "update";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a string into a `feature/…` branch name.
|
||||
* Preserves an existing `feature/` prefix or slash-separated namespace.
|
||||
*/
|
||||
export function sanitizeFeatureBranchName(raw: string): string {
|
||||
const sanitized = sanitizeBranchFragment(raw);
|
||||
if (sanitized.includes("/")) {
|
||||
return sanitized.startsWith("feature/") ? sanitized : `feature/${sanitized}`;
|
||||
}
|
||||
return `feature/${sanitized}`;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in new issue
Block a user