forked from guacsec/trustify-da-javascript-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequirements_parser.js
More file actions
30 lines (23 loc) · 954 Bytes
/
Copy pathrequirements_parser.js
File metadata and controls
30 lines (23 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { fileURLToPath } from 'url';
import { Language, Parser, Query } from 'web-tree-sitter';
const wasmPath = fileURLToPath(import.meta.resolve('tree-sitter-requirements/tree-sitter-requirements.wasm'));
async function init() {
await Parser.init();
return await Language.load(wasmPath);
}
export async function getParser() {
const language = await init();
return new Parser().setLanguage(language);
}
export async function getRequirementQuery() {
const language = await init();
return new Query(language, '(requirement (package) @name) @req');
}
export async function getIgnoreQuery() {
const language = await init();
return new Query(language, '((requirement (package) @name) @req . (comment) @comment (#match? @comment "^#[\\t ]*exhortignore"))');
}
export async function getPinnedVersionQuery() {
const language = await init();
return new Query(language, '(version_spec (version_cmp) @cmp (version) @version (#eq? @cmp "=="))');
}