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
31 lines (24 loc) · 989 Bytes
/
Copy pathrequirements_parser.js
File metadata and controls
31 lines (24 loc) · 989 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
31
import { readFile } from 'node:fs/promises';
import { Language, Parser, Query } from 'web-tree-sitter';
const wasmUrl = new URL('./tree-sitter-requirements.wasm', import.meta.url);
async function init() {
await Parser.init();
const wasmBytes = new Uint8Array(await readFile(wasmUrl));
return await Language.load(wasmBytes);
}
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 "=="))');
}