@lzehrung/codegraph-native 1.9.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/index.d.ts +94 -0
- package/index.js +64 -0
- package/package.json +61 -0
- package/platform.js +17 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Compact capture with only name and text -- used by graph-mode imports
|
|
5
|
+
* where position and node-type data are not consumed by the caller.
|
|
6
|
+
*/
|
|
7
|
+
export interface CompactCapture {
|
|
8
|
+
name: string
|
|
9
|
+
text: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CompactMatch {
|
|
13
|
+
patternIndex: number
|
|
14
|
+
captures: Array<CompactCapture>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CompactQueryResults {
|
|
18
|
+
imports: Array<CompactMatch>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export declare function extractLanguage(source: string, languageId: string, importsQuery: string, exportsQuery: string, localsQuery: string, importBindingsQuery: string): NativeLanguageExtraction
|
|
22
|
+
|
|
23
|
+
export interface NativeCapture {
|
|
24
|
+
name: string
|
|
25
|
+
text: string
|
|
26
|
+
nodeType: string
|
|
27
|
+
start: NativePoint
|
|
28
|
+
end: NativePoint
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface NativeDuplicateTokens {
|
|
32
|
+
normalizedTokens: Array<string>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface NativeLanguageExtraction {
|
|
36
|
+
results: NativeQueryResults
|
|
37
|
+
syntaxTree: NativeSyntaxTree
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface NativeMatch {
|
|
41
|
+
patternIndex: number
|
|
42
|
+
captures: Array<NativeCapture>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface NativePoint {
|
|
46
|
+
row: number
|
|
47
|
+
column: number
|
|
48
|
+
index: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface NativeQueryResults {
|
|
52
|
+
imports: Array<NativeMatch>
|
|
53
|
+
exports: Array<NativeMatch>
|
|
54
|
+
locals: Array<NativeMatch>
|
|
55
|
+
importBindings: Array<NativeMatch>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface NativeQueryRunResult {
|
|
59
|
+
matches: Array<NativeMatch>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface NativeSyntaxNode {
|
|
63
|
+
id: number
|
|
64
|
+
parentId: number
|
|
65
|
+
nodeType: string
|
|
66
|
+
named: boolean
|
|
67
|
+
start: NativePoint
|
|
68
|
+
end: NativePoint
|
|
69
|
+
childIds: Array<number>
|
|
70
|
+
namedChildIds: Array<number>
|
|
71
|
+
childFieldNames: Array<string>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface NativeSyntaxTree {
|
|
75
|
+
rootId: number
|
|
76
|
+
nodes: Array<NativeSyntaxNode>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export declare function parseSyntaxTree(source: string, languageId: string): NativeSyntaxTree
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Run only the imports query and return compact results (name + text only).
|
|
83
|
+
* This is the graph-mode entrypoint optimized for minimal marshaling.
|
|
84
|
+
*/
|
|
85
|
+
export declare function runImportsQueryCompact(source: string, languageId: string, importsQuery: string): CompactQueryResults
|
|
86
|
+
|
|
87
|
+
export declare function runLanguageQueries(source: string, languageId: string, importsQuery: string, exportsQuery: string, localsQuery: string, importBindingsQuery: string): NativeQueryResults
|
|
88
|
+
|
|
89
|
+
/** Execute a single arbitrary query and return full capture metadata. */
|
|
90
|
+
export declare function runQuery(source: string, languageId: string, queryText: string): NativeQueryRunResult
|
|
91
|
+
|
|
92
|
+
export declare function supportedLanguageIds(): Array<string>
|
|
93
|
+
|
|
94
|
+
export declare function tokenizeDuplicateSource(source: string): NativeDuplicateTokens
|
package/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import childProcess from "node:child_process";
|
|
6
|
+
import { nativeTargetSuffixForPlatform } from "./platform.js";
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
|
|
12
|
+
function isMusl() {
|
|
13
|
+
if (process.platform !== "linux") return false;
|
|
14
|
+
const report = process.report?.getReport();
|
|
15
|
+
if (report?.header?.glibcVersionRuntime) return false;
|
|
16
|
+
try {
|
|
17
|
+
return childProcess.execSync("ldd --version", { encoding: "utf8" }).toLowerCase().includes("musl");
|
|
18
|
+
} catch {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function platformPackageSuffix() {
|
|
24
|
+
const linuxAbi = isMusl() ? "musl" : "gnu";
|
|
25
|
+
return nativeTargetSuffixForPlatform(process.platform, process.arch, linuxAbi);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function findLocalNativeBinary() {
|
|
29
|
+
const suffix = platformPackageSuffix();
|
|
30
|
+
if (!suffix) return null;
|
|
31
|
+
const expectedName = `index.${suffix}.node`;
|
|
32
|
+
const files = fs.readdirSync(__dirname);
|
|
33
|
+
const binary = files.find((file) => file === expectedName);
|
|
34
|
+
return binary ? path.join(__dirname, binary) : null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function loadBinding() {
|
|
38
|
+
const localBinary = findLocalNativeBinary();
|
|
39
|
+
if (localBinary) return require(localBinary);
|
|
40
|
+
|
|
41
|
+
const suffix = platformPackageSuffix();
|
|
42
|
+
if (suffix) {
|
|
43
|
+
try {
|
|
44
|
+
return require(`@lzehrung/codegraph-native-${suffix}`);
|
|
45
|
+
} catch {
|
|
46
|
+
// Fall through to the final error below.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Codegraph native addon is unavailable for this platform. Build it locally with `npm run build:native` or install a published native package for this target.",
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const binding = loadBinding();
|
|
56
|
+
|
|
57
|
+
export const parseSyntaxTree = binding.parseSyntaxTree;
|
|
58
|
+
export const extractLanguage = binding.extractLanguage;
|
|
59
|
+
export const runImportsQueryCompact = binding.runImportsQueryCompact;
|
|
60
|
+
export const runLanguageQueries = binding.runLanguageQueries;
|
|
61
|
+
export const runQuery = binding.runQuery;
|
|
62
|
+
export const tokenizeDuplicateSource = binding.tokenizeDuplicateSource;
|
|
63
|
+
export const supportedLanguageIds = binding.supportedLanguageIds;
|
|
64
|
+
export default binding;
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lzehrung/codegraph-native",
|
|
3
|
+
"version": "1.9.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"import": "./index.js",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"index.d.ts",
|
|
17
|
+
"platform.js"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/lzehrung/codegraph.git",
|
|
23
|
+
"directory": "packages/codegraph-native"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "node ../../node_modules/@napi-rs/cli/dist/cli.js build --platform --release --cwd . --no-js --dts index.d.ts",
|
|
27
|
+
"build:debug": "node ../../node_modules/@napi-rs/cli/dist/cli.js build --platform --cwd . --no-js --dts index.d.ts",
|
|
28
|
+
"clean": "cargo clean",
|
|
29
|
+
"create-npm-dirs": "node ../../node_modules/@napi-rs/cli/dist/cli.js create-npm-dirs --cwd .",
|
|
30
|
+
"artifacts": "node ../../node_modules/@napi-rs/cli/dist/cli.js artifacts --cwd .",
|
|
31
|
+
"prepublish:napi": "node ../../node_modules/@napi-rs/cli/dist/cli.js pre-publish --cwd ."
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"registry": "https://registry.npmjs.org"
|
|
36
|
+
},
|
|
37
|
+
"napi": {
|
|
38
|
+
"binaryName": "index",
|
|
39
|
+
"packageName": "@lzehrung/codegraph-native",
|
|
40
|
+
"targets": [
|
|
41
|
+
"x86_64-pc-windows-msvc",
|
|
42
|
+
"aarch64-pc-windows-msvc",
|
|
43
|
+
"x86_64-apple-darwin",
|
|
44
|
+
"aarch64-apple-darwin",
|
|
45
|
+
"x86_64-unknown-linux-gnu",
|
|
46
|
+
"aarch64-unknown-linux-gnu",
|
|
47
|
+
"x86_64-unknown-linux-musl",
|
|
48
|
+
"aarch64-unknown-linux-musl"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"optionalDependencies": {
|
|
52
|
+
"@lzehrung/codegraph-native-darwin-arm64": "1.9.0",
|
|
53
|
+
"@lzehrung/codegraph-native-darwin-x64": "1.9.0",
|
|
54
|
+
"@lzehrung/codegraph-native-linux-arm64-gnu": "1.9.0",
|
|
55
|
+
"@lzehrung/codegraph-native-linux-arm64-musl": "1.9.0",
|
|
56
|
+
"@lzehrung/codegraph-native-linux-x64-gnu": "1.9.0",
|
|
57
|
+
"@lzehrung/codegraph-native-linux-x64-musl": "1.9.0",
|
|
58
|
+
"@lzehrung/codegraph-native-win32-arm64-msvc": "1.9.0",
|
|
59
|
+
"@lzehrung/codegraph-native-win32-x64-msvc": "1.9.0"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/platform.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function nativeTargetSuffixForPlatform(platform, arch, linuxAbi) {
|
|
2
|
+
if (platform === "win32") {
|
|
3
|
+
if (arch === "x64") return "win32-x64-msvc";
|
|
4
|
+
if (arch === "arm64") return "win32-arm64-msvc";
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
if (platform === "darwin") {
|
|
8
|
+
if (arch === "x64") return "darwin-x64";
|
|
9
|
+
if (arch === "arm64") return "darwin-arm64";
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (platform === "linux") {
|
|
13
|
+
if (arch === "x64") return `linux-x64-${linuxAbi}`;
|
|
14
|
+
if (arch === "arm64") return `linux-arm64-${linuxAbi}`;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|