Skip to content

Commit b445f8e

Browse files
committed
fix(hook): adopt fleet-gold check-new-deps improvements
Two improvements from the socket-repo-template gold standard: - Canonical isMainModule: fileURLToPath(import.meta.url) === path.resolve(process.argv[1]) — widest cross-platform support. - Local errorMessage() helper: replaces (e as Error).message casts which print 'undefined' when the caught value isn't an Error.
1 parent e6cc45a commit b445f8e

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

.claude/hooks/check-new-deps/index.mts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
// 0 = allow (no new deps, all clean, or non-dep file)
1818
// 2 = block (malware detected by Socket.dev)
1919

20+
import path from 'node:path'
21+
import { fileURLToPath } from 'node:url'
22+
2023
import {
2124
parseNpmSpecifier,
2225
stringify,
@@ -32,6 +35,13 @@ import {
3235
import { SocketSdk } from '@socketsecurity/sdk'
3336
import type { MalwareCheckPackage } from '@socketsecurity/sdk'
3437

38+
// Local mirror of build-infra/lib/error-utils#errorMessage. Hook runs
39+
// standalone (no workspace deps beyond @socketsecurity/*) so we can't import
40+
// the shared helper, but the contract is identical.
41+
function errorMessage(error: unknown): string {
42+
return error instanceof Error ? error.message : String(error)
43+
}
44+
3545
const logger = getDefaultLogger()
3646

3747
// Per-request timeout (ms) to avoid blocking the hook on slow responses.
@@ -273,7 +283,7 @@ const extractors: Record<string, Extractor> = {
273283

274284
// --- main (only when executed directly, not imported) ---
275285

276-
if (import.meta.filename === process.argv[1]) {
286+
if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
277287
// Read the full JSON blob from stdin (piped by Claude Code).
278288
let input = ''
279289
for await (const chunk of process.stdin) input += chunk
@@ -402,10 +412,7 @@ async function checkDepsBatch(
402412
}
403413
} catch (e) {
404414
// Network failure — log and allow all deps through.
405-
logger.warn(
406-
`Socket: network error`
407-
+ ` (${(e as Error).message}), allowing all`
408-
)
415+
logger.warn(`Socket: network error (${errorMessage(e)}), allowing all`)
409416
}
410417
411418
return blocked

0 commit comments

Comments
 (0)