scan-compromised 1.0.16 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/index.js +35 -11
package/package.json
CHANGED
package/scripts/index.js
CHANGED
|
@@ -1,24 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, readFileSync } from "fs";
|
|
3
|
-
import { join } from "path";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { join, isAbsolute, dirname } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import CONFIG from "../config/config.js";
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
|
|
10
|
+
const { threatsFile } = CONFIG;
|
|
11
|
+
if (!threatsFile) throw new Error("Set threatsFile in config");
|
|
12
|
+
|
|
13
|
+
// Try resolving from project root first
|
|
14
|
+
const projectPath = isAbsolute(threatsFile)
|
|
15
|
+
? threatsFile
|
|
16
|
+
: join(process.cwd(), threatsFile);
|
|
17
|
+
|
|
18
|
+
// Fallback to CLI-relative path
|
|
19
|
+
const fallbackPath = isAbsolute(threatsFile)
|
|
20
|
+
? threatsFile
|
|
21
|
+
: join(__dirname, threatsFile);
|
|
22
|
+
|
|
23
|
+
// Final path
|
|
24
|
+
const resolvedThreatsPath = existsSync(projectPath)
|
|
25
|
+
? projectPath
|
|
26
|
+
: existsSync(fallbackPath)
|
|
27
|
+
? fallbackPath
|
|
28
|
+
: null;
|
|
29
|
+
|
|
30
|
+
if (!resolvedThreatsPath) {
|
|
31
|
+
console.error(`❌ ${threatsFile} not found in project or CLI directory.`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
9
34
|
|
|
10
|
-
if (!threatsFile) throw new Error('Set threatsFile in config');
|
|
11
35
|
|
|
12
36
|
function loadThreats() {
|
|
13
|
-
if (!existsSync(
|
|
14
|
-
console.error(`❌ ${
|
|
37
|
+
if (!existsSync(resolvedThreatsPath)) {
|
|
38
|
+
console.error(`❌ ${resolvedThreatsPath} not found.`);
|
|
15
39
|
process.exit(1);
|
|
16
40
|
}
|
|
17
41
|
try {
|
|
18
|
-
const raw = readFileSync(
|
|
42
|
+
const raw = readFileSync(resolvedThreatsPath, "utf8");
|
|
19
43
|
return JSON.parse(raw);
|
|
20
44
|
} catch (err) {
|
|
21
|
-
console.error(
|
|
45
|
+
console.error(`❌ Failed to parse ${resolvedThreatsPath}:`, err.message);
|
|
22
46
|
process.exit(1);
|
|
23
47
|
}
|
|
24
48
|
}
|