mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-02-16 03:13:08 +08:00
fix: add cwd to prettier hook, consistent process.exit(0), and stdout pass-through
- post-edit-format.js: add cwd based on file directory so npx resolves correct local prettier binary - post-edit-typecheck.js, post-edit-format.js: replace console.log(data) with process.stdout.write(data) to avoid trailing newline corruption - Add process.exit(0) to 4 hooks for consistent termination (check-console-log, post-edit-console-warn, post-edit-format, post-edit-typecheck) - run-all.js: switch from execSync to spawnSync so stderr is visible on the success path (hook warnings were silently discarded) - Add 21 tests: cwd verification, process.exit(0) checks, exact stdout pass-through, extension edge cases, exclusion pattern matching, threshold boundary values (630 → 651)
This commit is contained in:
@@ -66,4 +66,5 @@ process.stdin.on('end', () => {
|
||||
|
||||
// Always output the original data
|
||||
process.stdout.write(data);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
@@ -49,4 +49,5 @@ process.stdin.on('end', () => {
|
||||
}
|
||||
|
||||
process.stdout.write(data);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
const { execFileSync } = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
const MAX_STDIN = 1024 * 1024; // 1MB limit
|
||||
let data = '';
|
||||
@@ -30,6 +31,7 @@ process.stdin.on('end', () => {
|
||||
// Use npx.cmd on Windows to avoid shell: true which enables command injection
|
||||
const npxBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
||||
execFileSync(npxBin, ['prettier', '--write', filePath], {
|
||||
cwd: path.dirname(path.resolve(filePath)),
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
timeout: 15000
|
||||
});
|
||||
@@ -41,5 +43,6 @@ process.stdin.on('end', () => {
|
||||
// Invalid input — pass through
|
||||
}
|
||||
|
||||
console.log(data);
|
||||
process.stdout.write(data);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
@@ -31,7 +31,8 @@ process.stdin.on("end", () => {
|
||||
if (filePath && /\.(ts|tsx)$/.test(filePath)) {
|
||||
const resolvedPath = path.resolve(filePath);
|
||||
if (!fs.existsSync(resolvedPath)) {
|
||||
console.log(data);
|
||||
process.stdout.write(data);
|
||||
process.exit(0);
|
||||
return;
|
||||
}
|
||||
// Find nearest tsconfig.json by walking up (max 20 levels to prevent infinite loop)
|
||||
@@ -90,5 +91,6 @@ process.stdin.on("end", () => {
|
||||
// Invalid input — pass through
|
||||
}
|
||||
|
||||
console.log(data);
|
||||
process.stdout.write(data);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user