gitnexus 1.6.4-rc.33 → 1.6.4-rc.34
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Parser from 'tree-sitter';
|
|
2
2
|
import { SupportedLanguages } from '../../_shared/index.js';
|
|
3
|
-
export declare const isLanguageAvailable: (language: SupportedLanguages) => boolean;
|
|
4
3
|
export declare const resolveLanguageKey: (language: SupportedLanguages, filePath?: string) => string;
|
|
5
|
-
export declare const
|
|
4
|
+
export declare const isLanguageAvailable: (language: SupportedLanguages, filePath?: string) => boolean;
|
|
5
|
+
export declare const getLanguageGrammar: (language: SupportedLanguages, filePath?: string) => unknown;
|
|
6
6
|
export declare const loadParser: () => Promise<Parser>;
|
|
7
7
|
export declare const loadLanguage: (language: SupportedLanguages, filePath?: string) => Promise<void>;
|
|
8
8
|
export declare const createParserForLanguage: (language: SupportedLanguages, filePath?: string) => Promise<Parser>;
|
|
@@ -1,84 +1,183 @@
|
|
|
1
1
|
import Parser from 'tree-sitter';
|
|
2
|
-
import JavaScript from 'tree-sitter-javascript';
|
|
3
|
-
import TypeScript from 'tree-sitter-typescript';
|
|
4
|
-
import Python from 'tree-sitter-python';
|
|
5
|
-
import Java from 'tree-sitter-java';
|
|
6
|
-
import C from 'tree-sitter-c';
|
|
7
|
-
import CPP from 'tree-sitter-cpp';
|
|
8
|
-
// Explicit subpath import: tree-sitter-c-sharp declares `type: "module"` with
|
|
9
|
-
// `main: "bindings/node"` (no extension) and no `exports` field, which triggers
|
|
10
|
-
// Node 22's DEP0151 deprecation warning on the bare-package import. Importing
|
|
11
|
-
// the built entrypoint directly bypasses the deprecated ESM main-field
|
|
12
|
-
// resolution. (#1013)
|
|
13
|
-
import CSharp from 'tree-sitter-c-sharp/bindings/node/index.js';
|
|
14
|
-
import Go from 'tree-sitter-go';
|
|
15
|
-
import Rust from 'tree-sitter-rust';
|
|
16
|
-
import PHP from 'tree-sitter-php';
|
|
17
|
-
import Ruby from 'tree-sitter-ruby';
|
|
18
2
|
import { createRequire } from 'node:module';
|
|
19
3
|
import { SupportedLanguages } from '../../_shared/index.js';
|
|
20
|
-
// tree-sitter-swift and tree-sitter-dart are optionalDependencies — may not be installed
|
|
21
4
|
const _require = createRequire(import.meta.url);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
[
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
5
|
+
const ISSUES_URL = 'https://github.com/abhigyanpatwari/GitNexus/issues';
|
|
6
|
+
const SOURCES = {
|
|
7
|
+
[SupportedLanguages.JavaScript]: {
|
|
8
|
+
load: () => _require('tree-sitter-javascript'),
|
|
9
|
+
unavailableNote: 'JavaScript parsing requires `tree-sitter-javascript`. ' +
|
|
10
|
+
'Check that the package and its native binding installed cleanly (`npm ci`).',
|
|
11
|
+
},
|
|
12
|
+
[SupportedLanguages.TypeScript]: {
|
|
13
|
+
load: () => _require('tree-sitter-typescript').typescript,
|
|
14
|
+
unavailableNote: 'TypeScript parsing requires `tree-sitter-typescript`. ' +
|
|
15
|
+
'Check that the package and its native binding installed cleanly (`npm ci`).',
|
|
16
|
+
},
|
|
17
|
+
[`${SupportedLanguages.TypeScript}:tsx`]: {
|
|
18
|
+
load: () => _require('tree-sitter-typescript').tsx,
|
|
19
|
+
unavailableNote: 'TSX parsing requires `tree-sitter-typescript` (re-uses the same native binding as TS).',
|
|
20
|
+
},
|
|
21
|
+
[SupportedLanguages.Python]: {
|
|
22
|
+
load: () => _require('tree-sitter-python'),
|
|
23
|
+
unavailableNote: 'Python parsing requires `tree-sitter-python`. Check the install and native binding.',
|
|
24
|
+
},
|
|
25
|
+
[SupportedLanguages.Java]: {
|
|
26
|
+
load: () => _require('tree-sitter-java'),
|
|
27
|
+
unavailableNote: 'Java parsing requires `tree-sitter-java`. Check the install and native binding.',
|
|
28
|
+
},
|
|
29
|
+
// tree-sitter-c-sharp declares `type: "module"` with `main: "bindings/node"`
|
|
30
|
+
// (no extension) and no `exports` field, which triggers Node 22's DEP0151
|
|
31
|
+
// deprecation warning on the bare-package import. The explicit subpath
|
|
32
|
+
// bypasses the deprecated ESM main-field resolution. (#1013)
|
|
33
|
+
[SupportedLanguages.CSharp]: {
|
|
34
|
+
load: () => _require('tree-sitter-c-sharp/bindings/node/index.js'),
|
|
35
|
+
unavailableNote: 'C# parsing requires `tree-sitter-c-sharp/bindings/node/index.js`. ' +
|
|
36
|
+
`If the subpath is missing, see ${ISSUES_URL}/1013.`,
|
|
37
|
+
},
|
|
38
|
+
[SupportedLanguages.CPlusPlus]: {
|
|
39
|
+
load: () => _require('tree-sitter-cpp'),
|
|
40
|
+
unavailableNote: 'C++ parsing requires `tree-sitter-cpp`. Check the install and native binding.',
|
|
41
|
+
},
|
|
42
|
+
[SupportedLanguages.Go]: {
|
|
43
|
+
load: () => _require('tree-sitter-go'),
|
|
44
|
+
unavailableNote: 'Go parsing requires `tree-sitter-go`. Check the install and native binding.',
|
|
45
|
+
},
|
|
46
|
+
[SupportedLanguages.Rust]: {
|
|
47
|
+
load: () => _require('tree-sitter-rust'),
|
|
48
|
+
unavailableNote: 'Rust parsing requires `tree-sitter-rust`. Check the install and native binding.',
|
|
49
|
+
},
|
|
50
|
+
[SupportedLanguages.PHP]: {
|
|
51
|
+
load: () => _require('tree-sitter-php').php_only,
|
|
52
|
+
unavailableNote: 'PHP parsing requires `tree-sitter-php` (the `php_only` export). ' +
|
|
53
|
+
'Check the install and native binding.',
|
|
54
|
+
},
|
|
55
|
+
[SupportedLanguages.Ruby]: {
|
|
56
|
+
load: () => _require('tree-sitter-ruby'),
|
|
57
|
+
unavailableNote: 'Ruby parsing requires `tree-sitter-ruby`. Check the install and native binding.',
|
|
58
|
+
},
|
|
59
|
+
[SupportedLanguages.Vue]: {
|
|
60
|
+
load: () => _require('tree-sitter-typescript').typescript,
|
|
61
|
+
unavailableNote: 'Vue parsing piggybacks on `tree-sitter-typescript`. Check the install and native binding.',
|
|
62
|
+
},
|
|
63
|
+
// tree-sitter-c is a required dependency, but its native binding has
|
|
64
|
+
// historically been ABI-incompatible with the bundled tree-sitter@0.21.1
|
|
65
|
+
// runtime on some platforms (#1242, #858). Loading it through the
|
|
66
|
+
// optional machinery turns a would-be segfault into a clean degradation
|
|
67
|
+
// while preserving every other language's analysis. Severity is pinned
|
|
68
|
+
// to `error` because the package is in `dependencies`: a failure here
|
|
69
|
+
// is always an install/platform problem the user needs to see, never an
|
|
70
|
+
// expected "user opted out" condition like Swift/Dart/Kotlin.
|
|
71
|
+
[SupportedLanguages.C]: {
|
|
72
|
+
load: () => _require('tree-sitter-c'),
|
|
73
|
+
optional: true,
|
|
74
|
+
severity: 'error',
|
|
75
|
+
unavailableNote: 'C parsing disabled: `tree-sitter-c` could not be loaded. ' +
|
|
76
|
+
'This package is in `dependencies` and prebuilds ship for all supported ' +
|
|
77
|
+
'platforms (win32/darwin/linux x64+arm64, Node 18/20/22), so this ' +
|
|
78
|
+
'usually indicates a corrupted install, an unsupported Node version, ' +
|
|
79
|
+
'or a native ABI mismatch with the bundled tree-sitter runtime. ' +
|
|
80
|
+
'Try `npm rebuild tree-sitter-c` or reinstalling, then re-run analyze. ' +
|
|
81
|
+
`If the failure persists, file details at ${ISSUES_URL}/1242.`,
|
|
82
|
+
},
|
|
83
|
+
// optionalDependencies — may be absent on platforms without prebuilds
|
|
84
|
+
// or when users skip optional installs.
|
|
85
|
+
[SupportedLanguages.Swift]: {
|
|
86
|
+
load: () => _require('tree-sitter-swift'),
|
|
87
|
+
optional: true,
|
|
88
|
+
unavailableNote: 'Swift parsing disabled: vendored `tree-sitter-swift` (under ' +
|
|
89
|
+
'`gitnexus/vendor/tree-sitter-swift`) failed to load. ' +
|
|
90
|
+
'Likely cause: no prebuilt `.node` for this platform/architecture. ' +
|
|
91
|
+
`See ${ISSUES_URL}/1130.`,
|
|
92
|
+
},
|
|
93
|
+
[SupportedLanguages.Dart]: {
|
|
94
|
+
load: () => _require('tree-sitter-dart'),
|
|
95
|
+
optional: true,
|
|
96
|
+
unavailableNote: 'Dart parsing disabled: vendored `tree-sitter-dart` (under ' +
|
|
97
|
+
'`gitnexus/vendor/tree-sitter-dart`) failed to load. ' +
|
|
98
|
+
'Likely cause: native compile failed at install (missing python3/make/g++). ' +
|
|
99
|
+
`See ${ISSUES_URL}/1125.`,
|
|
100
|
+
},
|
|
101
|
+
[SupportedLanguages.Kotlin]: {
|
|
102
|
+
load: () => _require('tree-sitter-kotlin'),
|
|
103
|
+
optional: true,
|
|
104
|
+
unavailableNote: 'Kotlin parsing disabled: `tree-sitter-kotlin` is an optionalDependency ' +
|
|
105
|
+
'and is not installed (or its native binding failed to build).',
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
const loadCache = new Map();
|
|
109
|
+
const logged = new Set();
|
|
110
|
+
const logFailure = (key, result) => {
|
|
111
|
+
if (result.ok === true)
|
|
112
|
+
return;
|
|
113
|
+
if (logged.has(key))
|
|
114
|
+
return;
|
|
115
|
+
logged.add(key);
|
|
116
|
+
const message = `[gitnexus] ${result.note} (${result.error.message})`;
|
|
117
|
+
if (result.severity === 'error')
|
|
118
|
+
console.error(message);
|
|
119
|
+
else
|
|
120
|
+
console.warn(message);
|
|
56
121
|
};
|
|
57
|
-
export const isLanguageAvailable = (language) => language in languageMap;
|
|
58
122
|
export const resolveLanguageKey = (language, filePath) => language === SupportedLanguages.TypeScript && filePath?.endsWith('.tsx')
|
|
59
123
|
? `${language}:tsx`
|
|
60
124
|
: language;
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
125
|
+
const loadGrammar = (key) => {
|
|
126
|
+
const cached = loadCache.get(key);
|
|
127
|
+
if (cached)
|
|
128
|
+
return cached;
|
|
129
|
+
const source = SOURCES[key];
|
|
130
|
+
if (!source) {
|
|
131
|
+
const result = {
|
|
132
|
+
ok: false,
|
|
133
|
+
error: new Error(`Unsupported language: ${key}`),
|
|
134
|
+
note: `No grammar registered for language key \`${key}\`. Add a row to SOURCES.`,
|
|
135
|
+
fatal: true,
|
|
136
|
+
severity: 'error',
|
|
137
|
+
};
|
|
138
|
+
loadCache.set(key, result);
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
let result;
|
|
142
|
+
try {
|
|
143
|
+
result = { ok: true, grammar: source.load() };
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
const fatal = !source.optional;
|
|
147
|
+
result = {
|
|
148
|
+
ok: false,
|
|
149
|
+
error: err,
|
|
150
|
+
note: source.unavailableNote,
|
|
151
|
+
fatal,
|
|
152
|
+
severity: source.severity ?? (fatal ? 'error' : 'warn'),
|
|
153
|
+
};
|
|
66
154
|
}
|
|
67
|
-
|
|
155
|
+
loadCache.set(key, result);
|
|
156
|
+
if (result.ok === false)
|
|
157
|
+
logFailure(key, result);
|
|
158
|
+
return result;
|
|
68
159
|
};
|
|
69
|
-
export const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
160
|
+
export const isLanguageAvailable = (language, filePath) => loadGrammar(resolveLanguageKey(language, filePath)).ok;
|
|
161
|
+
export const getLanguageGrammar = (language, filePath) => {
|
|
162
|
+
const key = resolveLanguageKey(language, filePath);
|
|
163
|
+
const result = loadGrammar(key);
|
|
164
|
+
if (result.ok === true)
|
|
165
|
+
return result.grammar;
|
|
166
|
+
// Fatal failures throw the original underlying error (preserving stack)
|
|
167
|
+
// after the note has been logged. Optional failures fall through to the
|
|
168
|
+
// standard "Unsupported language" message that callers already handle.
|
|
169
|
+
if (result.fatal)
|
|
170
|
+
throw result.error;
|
|
171
|
+
throw new Error(`Unsupported language: ${language}`);
|
|
74
172
|
};
|
|
173
|
+
let sharedParser = null;
|
|
174
|
+
export const loadParser = async () => (sharedParser ??= new Parser());
|
|
75
175
|
export const loadLanguage = async (language, filePath) => {
|
|
76
|
-
|
|
77
|
-
await loadParser();
|
|
176
|
+
const parser = await loadParser();
|
|
78
177
|
parser.setLanguage(getLanguageGrammar(language, filePath));
|
|
79
178
|
};
|
|
80
179
|
export const createParserForLanguage = async (language, filePath) => {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
return
|
|
180
|
+
const parser = new Parser();
|
|
181
|
+
parser.setLanguage(getLanguageGrammar(language, filePath));
|
|
182
|
+
return parser;
|
|
84
183
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitnexus",
|
|
3
|
-
"version": "1.6.4-rc.
|
|
3
|
+
"version": "1.6.4-rc.34",
|
|
4
4
|
"description": "Graph-powered code intelligence for AI agents. Index any codebase, query via MCP or CLI.",
|
|
5
5
|
"author": "Abhigyan Patwari",
|
|
6
6
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"onnxruntime-node": "^1.24.0",
|
|
73
73
|
"pandemonium": "^2.4.0",
|
|
74
74
|
"tree-sitter": "^0.21.1",
|
|
75
|
-
"tree-sitter-c": "0.
|
|
75
|
+
"tree-sitter-c": "0.21.4",
|
|
76
76
|
"tree-sitter-c-sharp": "0.23.1",
|
|
77
|
-
"tree-sitter-cpp": "
|
|
77
|
+
"tree-sitter-cpp": "0.23.2",
|
|
78
78
|
"tree-sitter-go": "^0.23.0",
|
|
79
79
|
"tree-sitter-java": "^0.23.5",
|
|
80
80
|
"tree-sitter-javascript": "^0.23.0",
|
|
@@ -109,8 +109,7 @@
|
|
|
109
109
|
"overrides": {
|
|
110
110
|
"@huggingface/transformers": {
|
|
111
111
|
"onnxruntime-node": "$onnxruntime-node"
|
|
112
|
-
}
|
|
113
|
-
"tree-sitter-c": "0.23.2"
|
|
112
|
+
}
|
|
114
113
|
},
|
|
115
114
|
"engines": {
|
|
116
115
|
"node": ">=20.0.0"
|