fix(hooks): include module extensions in edit and Stop checks

This commit is contained in:
Afloat committed 2026-11-17 11:02:44 +08:00
1 parent 8abdf329ec
commit d96596b4e0
5 files changed
+182 -7

No files matched your search

+1 -1
View File
@@ -36,7 +36,7 @@ function getAccumFile(rawSessionId) {
* @param {string} rawInput - Raw JSON string from stdin
* @returns {string} The original input (pass-through)
*/
const JS_TS_EXT = /\.(ts|tsx|js|jsx)$/;
const JS_TS_EXT = /\.(?:[cm]?[jt]s|[jt]sx)$/;
function appendPath(filePath, sessionId) {
if (filePath && JS_TS_EXT.test(filePath)) {
+1 -1
View File
@@ -39,7 +39,7 @@ function run(rawInput) {
const input = JSON.parse(rawInput);
const filePath = input.tool_input?.file_path;
if (filePath && /\.(ts|tsx|js|jsx)$/.test(filePath)) {
if (filePath && /\.(?:[cm]?[jt]s|[jt]sx)$/.test(filePath)) {
try {
const resolvedFilePath = path.resolve(filePath);
const projectRoot = findProjectRoot(path.dirname(resolvedFilePath));
+2 -2
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env node
/**
* PostToolUse Hook: TypeScript check after editing .ts/.tsx files
* PostToolUse Hook: TypeScript check after editing .ts/.tsx/.mts/.cts files
*
* Cross-platform (Windows, macOS, Linux)
*
@@ -56,7 +56,7 @@ if (require.main === module) {
const input = JSON.parse(data);
const filePath = input.tool_input?.file_path;
if (filePath && /\.(ts|tsx)$/.test(filePath)) {
if (filePath && /\.(?:[cm]?ts|tsx)$/.test(filePath)) {
const resolvedPath = path.resolve(filePath);
if (!fs.existsSync(resolvedPath)) {
process.stdout.write(data, () => process.exit(0));
+3 -3
View File
@@ -6,7 +6,7 @@
*
* Reads the accumulator written by post-edit-accumulator.js and processes all
* edited files in one pass: groups files by project root for a single formatter
* invocation per root, and groups .ts/.tsx files by tsconfig dir for a single
* invocation per root, and groups .ts/.tsx/.mts/.cts files by tsconfig dir for a single
* tsc --noEmit per tsconfig. The accumulator is cleared on read so repeated
* Stop calls do not double-process files.
*
@@ -204,7 +204,7 @@ function main(sessionId) {
const byProjectRoot = new Map();
for (const filePath of files) {
if (!/\.(ts|tsx|js|jsx)$/.test(filePath)) continue;
if (!/\.(?:[cm]?[jt]s|[jt]sx)$/.test(filePath)) continue;
if (isPluginClonePath(filePath)) continue;
const resolved = path.resolve(filePath);
if (!fs.existsSync(resolved)) continue;
@@ -215,7 +215,7 @@ function main(sessionId) {
const byTsConfigDir = new Map();
for (const filePath of files) {
if (!/\.(ts|tsx)$/.test(filePath)) continue;
if (!/\.(?:[cm]?ts|tsx)$/.test(filePath)) continue;
if (isPluginClonePath(filePath)) continue;
const resolved = path.resolve(filePath);
if (!fs.existsSync(resolved)) continue;