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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/index.js +35 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scan-compromised",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "A simple npm CLI tool (starter template)",
5
5
  "main": "scripts/index.js",
6
6
  "type": "module",
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 CONFIG from '../config/config.js';
5
-
6
- const {
7
- threatsFile,
8
- } = CONFIG;
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(threatsFile)) {
14
- console.error(`❌ ${threatsFile} not found in CLI directory.`);
37
+ if (!existsSync(resolvedThreatsPath)) {
38
+ console.error(`❌ ${resolvedThreatsPath} not found.`);
15
39
  process.exit(1);
16
40
  }
17
41
  try {
18
- const raw = readFileSync(threatsFile, "utf8");
42
+ const raw = readFileSync(resolvedThreatsPath, "utf8");
19
43
  return JSON.parse(raw);
20
44
  } catch (err) {
21
- console.error(`"❌ Failed to parse ${threatsFile}:"`, err.message);
45
+ console.error(`❌ Failed to parse ${resolvedThreatsPath}:`, err.message);
22
46
  process.exit(1);
23
47
  }
24
48
  }