@flagshark/core 1.0.1 → 1.3.0
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/dist/config/defaults.d.ts +3 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +6 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/excluder.d.ts +18 -0
- package/dist/config/excluder.d.ts.map +1 -0
- package/dist/config/excluder.js +51 -0
- package/dist/config/excluder.js.map +1 -0
- package/dist/config/ignore-file.d.ts +6 -0
- package/dist/config/ignore-file.d.ts.map +1 -0
- package/dist/config/ignore-file.js +23 -0
- package/dist/config/ignore-file.js.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +7 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +7 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +47 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/presets.d.ts +11 -0
- package/dist/config/presets.d.ts.map +1 -0
- package/dist/config/presets.js +70 -0
- package/dist/config/presets.js.map +1 -0
- package/dist/config/schema.d.ts +322 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +63 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/detection/detectors/go.d.ts +8 -2
- package/dist/detection/detectors/go.d.ts.map +1 -1
- package/dist/detection/detectors/go.js +8 -2
- package/dist/detection/detectors/go.js.map +1 -1
- package/dist/detection/detectors/javascript.d.ts +8 -2
- package/dist/detection/detectors/javascript.d.ts.map +1 -1
- package/dist/detection/detectors/javascript.js +8 -2
- package/dist/detection/detectors/javascript.js.map +1 -1
- package/dist/detection/detectors/python.d.ts +8 -2
- package/dist/detection/detectors/python.d.ts.map +1 -1
- package/dist/detection/detectors/python.js +8 -2
- package/dist/detection/detectors/python.js.map +1 -1
- package/dist/detection/detectors/typescript.d.ts +8 -2
- package/dist/detection/detectors/typescript.d.ts.map +1 -1
- package/dist/detection/detectors/typescript.js +8 -2
- package/dist/detection/detectors/typescript.js.map +1 -1
- package/dist/detection/helpers.d.ts +1 -1
- package/dist/detection/helpers.d.ts.map +1 -1
- package/dist/detection/helpers.js +9 -1
- package/dist/detection/helpers.js.map +1 -1
- package/dist/detection/index.d.ts +10 -0
- package/dist/detection/index.d.ts.map +1 -1
- package/dist/detection/index.js +31 -7
- package/dist/detection/index.js.map +1 -1
- package/dist/detection/interface.d.ts +1 -1
- package/dist/detection/interface.d.ts.map +1 -1
- package/dist/detection/registry.d.ts +1 -1
- package/dist/detection/registry.d.ts.map +1 -1
- package/dist/detection/tree-sitter/const-resolver.d.ts +8 -0
- package/dist/detection/tree-sitter/const-resolver.d.ts.map +1 -0
- package/dist/detection/tree-sitter/const-resolver.js +36 -0
- package/dist/detection/tree-sitter/const-resolver.js.map +1 -0
- package/dist/detection/tree-sitter/engine.d.ts +11 -0
- package/dist/detection/tree-sitter/engine.d.ts.map +1 -0
- package/dist/detection/tree-sitter/engine.js +81 -0
- package/dist/detection/tree-sitter/engine.js.map +1 -0
- package/dist/detection/tree-sitter/parser-cache.d.ts +6 -0
- package/dist/detection/tree-sitter/parser-cache.d.ts.map +1 -0
- package/dist/detection/tree-sitter/parser-cache.js +68 -0
- package/dist/detection/tree-sitter/parser-cache.js.map +1 -0
- package/dist/detection/tree-sitter/queries/go.scm +11 -0
- package/dist/detection/tree-sitter/queries/javascript.scm +13 -0
- package/dist/detection/tree-sitter/queries/python.scm +11 -0
- package/dist/detection/tree-sitter/queries/typescript.scm +11 -0
- package/dist/detection/tree-sitter/query-builder.d.ts +3 -0
- package/dist/detection/tree-sitter/query-builder.d.ts.map +1 -0
- package/dist/detection/tree-sitter/query-builder.js +7 -0
- package/dist/detection/tree-sitter/query-builder.js.map +1 -0
- package/dist/detection/tree-sitter/query-runner.d.ts +20 -0
- package/dist/detection/tree-sitter/query-runner.d.ts.map +1 -0
- package/dist/detection/tree-sitter/query-runner.js +83 -0
- package/dist/detection/tree-sitter/query-runner.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/scan-repo.d.ts +27 -0
- package/dist/scan-repo.d.ts.map +1 -1
- package/dist/scan-repo.js +26 -5
- package/dist/scan-repo.js.map +1 -1
- package/dist/scanner.d.ts +11 -2
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +22 -7
- package/dist/scanner.js.map +1 -1
- package/package.json +12 -4
package/dist/scanner.d.ts
CHANGED
|
@@ -6,13 +6,22 @@
|
|
|
6
6
|
*
|
|
7
7
|
* walkDir() → filterFiles() → readFiles() → PolyglotAnalyzer.analyzeFiles()
|
|
8
8
|
*/
|
|
9
|
+
import type { Excluder } from './config/excluder.js';
|
|
9
10
|
export interface ScanOptions {
|
|
10
11
|
root: string;
|
|
11
12
|
supportedExtensions: Set<string>;
|
|
12
13
|
diffRef?: string;
|
|
14
|
+
excluder?: Excluder;
|
|
15
|
+
collectExcludedPaths?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface CollectFilesResult {
|
|
18
|
+
files: Map<string, string>;
|
|
19
|
+
excludedCount: number;
|
|
20
|
+
excludedPaths?: string[];
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
|
-
* Collects files to scan, reads their contents, and returns a Map<filePath, content
|
|
23
|
+
* Collects files to scan, reads their contents, and returns a Map<filePath, content>
|
|
24
|
+
* along with the count of files excluded by the optional excluder.
|
|
16
25
|
*/
|
|
17
|
-
export declare function collectFiles(options: ScanOptions):
|
|
26
|
+
export declare function collectFiles(options: ScanOptions): CollectFilesResult;
|
|
18
27
|
//# sourceMappingURL=scanner.d.ts.map
|
package/dist/scanner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAoBpD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAChC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,kBAAkB,CAwCrE"}
|
package/dist/scanner.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { execFileSync } from 'node:child_process';
|
|
10
10
|
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
11
|
-
import { join, extname } from 'node:path';
|
|
11
|
+
import { join, extname, relative } from 'node:path';
|
|
12
12
|
const SKIP_DIRS = new Set([
|
|
13
13
|
'node_modules',
|
|
14
14
|
'vendor',
|
|
@@ -26,19 +26,32 @@ const SKIP_DIRS = new Set([
|
|
|
26
26
|
]);
|
|
27
27
|
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
|
|
28
28
|
/**
|
|
29
|
-
* Collects files to scan, reads their contents, and returns a Map<filePath, content
|
|
29
|
+
* Collects files to scan, reads their contents, and returns a Map<filePath, content>
|
|
30
|
+
* along with the count of files excluded by the optional excluder.
|
|
30
31
|
*/
|
|
31
32
|
export function collectFiles(options) {
|
|
32
|
-
const { root, supportedExtensions, diffRef } = options;
|
|
33
|
+
const { root, supportedExtensions, diffRef, excluder, collectExcludedPaths } = options;
|
|
33
34
|
const files = new Map();
|
|
35
|
+
let excludedCount = 0;
|
|
36
|
+
const excludedPaths = collectExcludedPaths ? [] : undefined;
|
|
34
37
|
let filePaths;
|
|
35
38
|
if (diffRef) {
|
|
36
|
-
filePaths = getDiffFiles(diffRef, supportedExtensions);
|
|
39
|
+
filePaths = getDiffFiles(diffRef, supportedExtensions, root);
|
|
37
40
|
}
|
|
38
41
|
else {
|
|
39
42
|
filePaths = walkDir(root, supportedExtensions);
|
|
40
43
|
}
|
|
41
44
|
for (const fp of filePaths) {
|
|
45
|
+
if (excluder) {
|
|
46
|
+
const relativePath = relative(root, fp);
|
|
47
|
+
if (excluder.shouldExclude(relativePath)) {
|
|
48
|
+
excludedCount++;
|
|
49
|
+
if (excludedPaths) {
|
|
50
|
+
excludedPaths.push(relativePath);
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
42
55
|
try {
|
|
43
56
|
const stat = statSync(fp);
|
|
44
57
|
if (stat.size > MAX_FILE_SIZE) {
|
|
@@ -53,22 +66,24 @@ export function collectFiles(options) {
|
|
|
53
66
|
// Skip unreadable files
|
|
54
67
|
}
|
|
55
68
|
}
|
|
56
|
-
return files;
|
|
69
|
+
return { files, excludedCount, excludedPaths };
|
|
57
70
|
}
|
|
58
71
|
/**
|
|
59
72
|
* Get files changed since a git ref.
|
|
60
73
|
*/
|
|
61
|
-
function getDiffFiles(ref, supportedExtensions) {
|
|
74
|
+
function getDiffFiles(ref, supportedExtensions, root) {
|
|
62
75
|
try {
|
|
63
76
|
const output = execFileSync('git', ['diff', ref, '--name-only', '--diff-filter=ACMR'], {
|
|
64
77
|
encoding: 'utf-8',
|
|
65
78
|
timeout: 30000,
|
|
79
|
+
cwd: root,
|
|
66
80
|
});
|
|
67
81
|
return output
|
|
68
82
|
.split('\n')
|
|
69
83
|
.map((line) => line.trim())
|
|
70
84
|
.filter((line) => line.length > 0)
|
|
71
|
-
.filter((line) => supportedExtensions.has(extname(line)))
|
|
85
|
+
.filter((line) => supportedExtensions.has(extname(line)))
|
|
86
|
+
.map((line) => join(root, line));
|
|
72
87
|
}
|
|
73
88
|
catch {
|
|
74
89
|
throw new Error(`Failed to get diff from ref "${ref}". Is this a git repository?`);
|
package/dist/scanner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAInD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,cAAc;IACd,QAAQ;IACR,MAAM;IACN,MAAM;IACN,OAAO;IACP,UAAU;IACV,aAAa;IACb,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,MAAM;IACN,KAAK;CACN,CAAC,CAAA;AAEF,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA,CAAC,MAAM;AAgB5C;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,OAAoB;IAC/C,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,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,CAAC,EAAE,CAAC;gBAC/B,SAAQ;YACV,CAAC;YAED,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;YAEtC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxB,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAA;YACzD,CAAC;iBAAM,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBAC/B,IAAI,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;oBACjC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,8BAA8B;IAChC,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flagshark/core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Detection engine for FlagShark — finds feature flag references across 13 languages.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,12 +20,20 @@
|
|
|
20
20
|
},
|
|
21
21
|
"files": ["dist/"],
|
|
22
22
|
"scripts": {
|
|
23
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
23
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && bun run copy-queries",
|
|
24
|
+
"copy-queries": "mkdir -p dist/detection/tree-sitter/queries && cp src/detection/tree-sitter/queries/*.scm dist/detection/tree-sitter/queries/",
|
|
24
25
|
"test": "vitest run",
|
|
25
26
|
"typecheck": "tsc --noEmit"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
29
|
+
"ignore": "^5.3.0",
|
|
28
30
|
"p-limit": "^6.0.0",
|
|
31
|
+
"tree-sitter-go": "^0.25.0",
|
|
32
|
+
"tree-sitter-javascript": "^0.25.0",
|
|
33
|
+
"tree-sitter-python": "^0.25.0",
|
|
34
|
+
"tree-sitter-typescript": "^0.23.0",
|
|
35
|
+
"web-tree-sitter": "^0.25.0",
|
|
36
|
+
"yaml": "^2.4.0",
|
|
29
37
|
"zod": "^3.23.0"
|
|
30
38
|
},
|
|
31
39
|
"devDependencies": {
|
|
@@ -34,6 +42,6 @@
|
|
|
34
42
|
"vitest": "^3.0.0"
|
|
35
43
|
},
|
|
36
44
|
"engines": {
|
|
37
|
-
|
|
38
|
-
}
|
|
45
|
+
"node": ">=18.0.0"
|
|
46
|
+
}
|
|
39
47
|
}
|