Skip to content

Commit c0c9489

Browse files
committed
chore: tsconfig sourcemaps off + check-new-deps hook cleanup
tsconfig: explicit sourceMap: false and declarationMap: false on every config, keys alphanumerically sorted. Never ship sourcemaps. hook: remove low-score warnings and fix inaccurate comments. The malware API only checks for malware, not quality scores; warned/score logic was dead code and the SDK batch comment was wrong.
1 parent 5a130eb commit c0c9489

File tree

8 files changed

+44
-66
lines changed

8 files changed

+44
-66
lines changed

.claude/hooks/check-new-deps/README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ When Claude edits a file like `package.json`, `requirements.txt`, `Cargo.toml`,
88

99
1. **Detects the file type** and extracts dependency names from the content
1010
2. **Diffs against the old content** (for edits) so only *newly added* deps are checked
11-
3. **Queries the Socket.dev API** to check for malware and critical security alerts
12-
4. **Blocks the edit** (exit code 2) if malware or critical alerts are found
13-
5. **Warns** (but allows) if a package has a low quality score
14-
6. **Allows** (exit code 0) if everything is clean or the file isn't a manifest
11+
3. **Queries the Socket.dev API** to check for malware
12+
4. **Blocks the edit** (exit code 2) if malware is detected
13+
5. **Allows** (exit code 0) if everything is clean or the file isn't a manifest
1514

1615
## How it works
1716

@@ -30,11 +29,8 @@ Build Package URLs (PURLs) for each dep
3029
3130
3231
Call sdk.checkMalware(components)
33-
- ≤5 deps: parallel firewall API (fast, full data)
34-
- >5 deps: batch PURL API (efficient)
3532
36-
├── Malware/critical alert → EXIT 2 (blocked)
37-
├── Low score → warn, EXIT 0 (allowed)
33+
├── Malware detected → EXIT 2 (blocked)
3834
└── Clean → EXIT 0 (allowed)
3935
```
4036

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

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//
1616
// Exit codes:
1717
// 0 = allow (no new deps, all clean, or non-dep file)
18-
// 2 = block (malware or critical alert from Socket.dev)
18+
// 2 = block (malware detected by Socket.dev)
1919

2020
import {
2121
parseNpmSpecifier,
@@ -36,8 +36,6 @@ const logger = getDefaultLogger()
3636

3737
// Per-request timeout (ms) to avoid blocking the hook on slow responses.
3838
const API_TIMEOUT = 5_000
39-
// Deps scoring below this threshold trigger a warning (not a block).
40-
const LOW_SCORE_THRESHOLD = 0.5
4139
// Max PURLs per batch request (API limit is 1024).
4240
const MAX_BATCH_SIZE = 1024
4341
// How long (ms) to cache a successful API response (5 minutes).
@@ -75,9 +73,7 @@ interface HookInput {
7573
interface CheckResult {
7674
purl: string
7775
blocked?: boolean
78-
warned?: boolean
7976
reason?: string
80-
score?: number
8177
}
8278

8379

@@ -324,14 +320,8 @@ async function check(hook: HookInput): Promise<number> {
324320
if (deps.length === 0) return 0
325321

326322
// Check all deps via SDK checkMalware().
327-
const { blocked, warned } = await checkDepsBatch(deps)
323+
const blocked = await checkDepsBatch(deps)
328324

329-
if (warned.length > 0) {
330-
logger.warn('Socket: low-scoring dependencies (not blocked):')
331-
for (const w of warned) {
332-
logger.warn(` ${w.purl}: overall score ${w.score}`)
333-
}
334-
}
335325
if (blocked.length > 0) {
336326
logger.error(`Socket: blocked ${blocked.length} dep(s):`)
337327
for (const b of blocked) {
@@ -343,14 +333,11 @@ async function check(hook: HookInput): Promise<number> {
343333
}
344334

345335
// Check deps against Socket.dev using SDK v4 checkMalware().
346-
// The SDK automatically routes small sets (<=5) to parallel firewall
347-
// requests and larger sets to the batch PURL API.
348336
// Deps already in cache are skipped; results are cached after lookup.
349337
async function checkDepsBatch(
350338
deps: Dep[],
351-
): Promise<{ blocked: CheckResult[]; warned: CheckResult[] }> {
339+
): Promise<CheckResult[]> {
352340
const blocked: CheckResult[] = []
353-
const warned: CheckResult[] = []
354341

355342
// Partition deps into cached vs uncached.
356343
const uncached: Array<{ dep: Dep; purl: string }> = []
@@ -359,13 +346,12 @@ async function checkDepsBatch(
359346
const cached = cacheGet(purl)
360347
if (cached) {
361348
if (cached.result?.blocked) blocked.push(cached.result)
362-
else if (cached.result?.warned) warned.push(cached.result)
363349
continue
364350
}
365351
uncached.push({ dep, purl })
366352
}
367353

368-
if (!uncached.length) return { blocked, warned }
354+
if (!uncached.length) return blocked
369355

370356
try {
371357
// Process in chunks to respect API batch size limit.
@@ -379,7 +365,7 @@ async function checkDepsBatch(
379365
logger.warn(
380366
`Socket: API returned ${result.status}, allowing all`
381367
)
382-
return { blocked, warned }
368+
return blocked
383369
}
384370

385371
// Build lookup keyed by full PURL (includes namespace + version).
@@ -395,37 +381,22 @@ async function checkDepsBatch(
395381
const purl = purlByKey.get(key)
396382
if (!purl) continue
397383
398-
// Check for malware or critical-severity alerts.
399-
const critical = pkg.alerts.find(
384+
// Check for malware alerts.
385+
const malware = pkg.alerts.find(
400386
a => a.severity === 'critical' || a.type === 'malware'
401387
)
402-
if (critical) {
388+
if (malware) {
403389
const cr: CheckResult = {
404390
purl,
405391
blocked: true,
406-
reason: `${critical.type}${critical.severity ?? 'critical'}`,
392+
reason: `${malware.type} ${malware.severity ?? 'critical'}`,
407393
}
408394
cacheSet(purl, cr)
409395
blocked.push(cr)
410396
continue
411397
}
412398
413-
// Warn on low quality score.
414-
if (
415-
pkg.score?.overall !== undefined
416-
&& pkg.score.overall < LOW_SCORE_THRESHOLD
417-
) {
418-
const wr: CheckResult = {
419-
purl,
420-
warned: true,
421-
score: pkg.score.overall,
422-
}
423-
cacheSet(purl, wr)
424-
warned.push(wr)
425-
continue
426-
}
427-
428-
// No blocking alerts — clean dep.
399+
// No malware alerts — clean dep.
429400
cacheSet(purl, undefined)
430401
}
431402
}
@@ -437,7 +408,7 @@ async function checkDepsBatch(
437408
)
438409
}
439410
440-
return { blocked, warned }
411+
return blocked
441412
}
442413
443414
// Return deps in `newDeps` that don't appear in `oldDeps` (by PURL).
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
22
"compilerOptions": {
3-
"noEmit": true,
4-
"target": "esnext",
3+
"declarationMap": false,
4+
"erasableSyntaxOnly": true,
55
"module": "nodenext",
66
"moduleResolution": "nodenext",
7+
"noEmit": true,
78
"rewriteRelativeImportExtensions": true,
8-
"erasableSyntaxOnly": true,
9-
"verbatimModuleSyntax": true,
9+
"skipLibCheck": true,
10+
"sourceMap": false,
1011
"strict": true,
11-
"skipLibCheck": true
12+
"target": "esnext",
13+
"useUnknownInCatchVariables": true,
14+
"verbatimModuleSyntax": true
1215
}
1316
}

.config/tsconfig.check.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4+
"declarationMap": false,
45
"noEmit": true,
56
"rootDir": "..",
6-
"types": ["node", "vitest"],
7-
"skipLibCheck": true
7+
"skipLibCheck": true,
8+
"sourceMap": false,
9+
"types": ["node", "vitest"]
810
},
911
"include": ["../src/**/*.ts", "../test/**/*.ts", "../test/**/*.mts"],
1012
"exclude": ["../node_modules", "../dist/**/*"]

.config/tsconfig.external-aliases.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "./tsconfig.check.json",
33
"compilerOptions": {
4+
"declarationMap": false,
45
"paths": {
56
"#constants/*": ["../src/constants/*"],
67
"#env/*": ["../src/env/*"],
@@ -25,6 +26,7 @@
2526
"@socketregistry/packageurl-js/*": ["../../socket-packageurl-js/dist/*"],
2627
"@socketsecurity/sdk": ["../../socket-sdk-js/dist/index.d.ts"],
2728
"@socketsecurity/sdk/*": ["../../socket-sdk-js/dist/*"]
28-
}
29+
},
30+
"sourceMap": false
2931
}
3032
}

tsconfig.dts.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"declaration": true,
5+
"declarationMap": false,
56
"emitDeclarationOnly": true,
6-
"noEmit": false
7+
"noEmit": false,
8+
"sourceMap": false
79
},
810
"include": ["src/**/*.ts"],
911
"exclude": ["node_modules", "dist/**/*", "lib", "test", "src/**/*.js"]

tsconfig.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
22
"extends": "./.config/tsconfig.base.json",
33
"compilerOptions": {
4+
"allowSyntheticDefaultImports": true,
5+
"declaration": false,
6+
"declarationMap": false,
47
"module": "commonjs",
58
"moduleResolution": "bundler",
6-
"outDir": "dist",
7-
"rootDir": "src",
89
"noEmit": false,
910
"noEmitOnError": false,
10-
"sourceMap": false,
11-
"declaration": false,
12-
"declarationMap": false,
13-
"verbatimModuleSyntax": false,
14-
"allowSyntheticDefaultImports": true,
15-
"types": ["node"],
11+
"outDir": "dist",
1612
"paths": {
1713
"adm-zip": ["./src/external/adm-zip"],
1814
"cacache": ["./src/external/cacache"],
1915
"make-fetch-happen": ["./src/external/make-fetch-happen"],
2016
"fast-sort": ["./src/external/fast-sort"],
2117
"pacote": ["./src/external/pacote"],
2218
"tar-fs": ["./src/external/tar-fs"]
23-
}
19+
},
20+
"rootDir": "src",
21+
"sourceMap": false,
22+
"types": ["node"],
23+
"verbatimModuleSyntax": false
2424
},
2525
"include": ["src/**/*.ts", "src/**/*.d.ts"],
2626
"exclude": ["node_modules", "dist/**/*", "lib", "test", "src/**/*.js"]

tsconfig.test.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4+
"declarationMap": false,
45
"rootDir": ".",
6+
"sourceMap": false,
57
"types": ["node", "vitest"]
68
},
79
"include": ["test/**/*.ts", "test/**/*.mts", "src/**/*.ts"],

0 commit comments

Comments
 (0)