Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

autoindex: recognise .mts/.cts as TypeScript

Pavel Radaev02e8422912f3
diff --git a/engine/crates/xerj-autoindex/src/extract/code.rs b/engine/crates/xerj-autoindex/src/extract/code.rs
index 10f88d110..cc8ae164e 100644
--- a/engine/crates/xerj-autoindex/src/extract/code.rs
+++ b/engine/crates/xerj-autoindex/src/extract/code.rs
@@ -66,9 +66,15 @@ fn registry() -> &'static [LangDef] {
tree_sitter_javascript::LANGUAGE.into(),
JS_Q,
),
+ // `.mts`/`.cts` are TypeScript's ESM/CJS extensions — the exact
+ // counterparts of the `.mjs`/`.cjs` that javascript already claims
+ // below. Omitting them did not merely skip the AST pass: an
+ // unclaimed extension is not code to the sniffer at all, so those
+ // files fell through to the prose extractor and were chunked into
+ // several body-only records with no `language`, `defs` or `symbols`.
def(
"typescript",
- &["ts"],
+ &["ts", "mts", "cts"],
tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(),
TS_Q,
),
@@ -584,6 +590,26 @@ mod tests {
assert!(has(&s, "Button", "function"), "got {s:?}");
assert!(has(&s, "Button", "const"), "got {s:?}");
}
+
+ /// `.mts`/`.cts` are TypeScript's ESM/CJS file extensions, the exact
+ /// counterparts of `.mjs`/`.cjs` which javascript already claims. Without
+ /// them a Node-ESM TypeScript file is not code to the sniffer at all: it
+ /// falls through to the prose extractor, so it yields no `language`, no
+ /// `defs`, no `symbols`, and gets chunked into several records instead of
+ /// one.
+ #[test]
+ fn typescript_module_extensions() {
+ assert!(is_code_ext("mts"), "mts must be recognised as code");
+ assert!(is_code_ext("cts"), "cts must be recognised as code");
+ for ext in ["mts", "cts"] {
+ let d = registry().iter().find(|d| d.exts.contains(&ext));
+ assert_eq!(
+ d.map(|d| d.name),
+ Some("typescript"),
+ "{ext} must route to the typescript grammar"
+ );
+ }
+ }
#[test]
fn rust() {
let s = syms(