Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(typescript): support .mts/.cts as TypeScript (#310)

joptimus950269f5dd79
diff --git a/packages/core/src/repowise/core/analysis/dead_code/constants.py b/packages/core/src/repowise/core/analysis/dead_code/constants.py
index d2960e03c..2ef670826 100644
--- a/packages/core/src/repowise/core/analysis/dead_code/constants.py
+++ b/packages/core/src/repowise/core/analysis/dead_code/constants.py
@@ -580,11 +580,16 @@ _NEVER_FLAG_PATTERNS: tuple[str, ...] = (
"*.test.jsx",
"*.test.mjs",
"*.test.cjs",
+ "*.test.mts",
+ "*.test.cts",
"*.spec.ts",
"*.spec.tsx",
"*.spec.js",
"*.spec.jsx",
"*.spec.mjs",
+ "*.spec.cjs",
+ "*.spec.mts",
+ "*.spec.cts",
"*/__tests__/*",
"*/__mocks__/*",
# Storybook stories — loaded by Storybook indexer via glob.
diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/coverage_gap.py b/packages/core/src/repowise/core/analysis/health/biomarkers/coverage_gap.py
index 52238fe77..4510a1cc6 100644
--- a/packages/core/src/repowise/core/analysis/health/biomarkers/coverage_gap.py
+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/coverage_gap.py
@@ -79,7 +79,19 @@ def _looks_like_test_path(path: str) -> bool:
or "/__tests__/" in p
or p.startswith(("test/", "tests/", "__tests__/"))
or p.endswith(
- ("_test.py", "_test.go", ".test.ts", ".test.tsx", ".test.js", ".spec.ts", ".spec.js")
+ (
+ "_test.py",
+ "_test.go",
+ ".test.ts",
+ ".test.tsx",
+ ".test.js",
+ ".test.mts",
+ ".test.cts",
+ ".spec.ts",
+ ".spec.js",
+ ".spec.mts",
+ ".spec.cts",
+ )
)
or p.rsplit("/", 1)[-1].startswith("test_")
)
diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/hidden_coupling.py b/packages/core/src/repowise/core/analysis/health/biomarkers/hidden_coupling.py
index 199f13139..eb86fd420 100644
--- a/packages/core/src/repowise/core/analysis/health/biomarkers/hidden_coupling.py
+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/hidden_coupling.py
@@ -46,8 +46,12 @@ _TEST_SUFFIXES: tuple[str, ...] = (
".test.ts",
".test.tsx",
".test.js",
+ ".test.mts",
+ ".test.cts",
".spec.ts",
".spec.js",
+ ".spec.mts",
+ ".spec.cts",
"_test.go",
)
_TEST_DIR_FRAGMENTS: tuple[str, ...] = (
diff --git a/packages/core/src/repowise/core/analysis/health/coverage/detector.py b/packages/core/src/repowise/core/analysis/health/coverage/detector.py
index 4f05f1ea5..bbae4e0f9 100644
--- a/packages/core/src/repowise/core/analysis/health/coverage/detector.py
+++ b/packages/core/src/repowise/core/analysis/health/coverage/detector.py
@@ -42,10 +42,14 @@ _TEST_FILE_SUFFIXES = (
".test.tsx",
".test.js",
".test.jsx",
+ ".test.mts",
+ ".test.cts",
".spec.ts",
".spec.tsx",
".spec.js",
".spec.jsx",
+ ".spec.mts",
+ ".spec.cts",
"_spec.rb",
"Test.java",
"Tests.java",
@@ -144,8 +148,12 @@ def paired_test_file(rel_path: str, all_paths: set[str]) -> str | None:
f"{stem}.test.tsx",
f"{stem}.test.js",
f"{stem}.test.jsx",
+ f"{stem}.test.mts",
+ f"{stem}.test.cts",
f"{stem}.spec.ts",
f"{stem}.spec.js",
+ f"{stem}.spec.mts",
+ f"{stem}.spec.cts",
f"{stem}_test.go",
f"{stem}_spec.rb",
f"{stem}Test.java",
diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.py
index 3e81151b4..e3b287ce4 100644
--- a/packages/core/src/repowise/core/analysis/health/engine.py
+++ b/packages/core/src/repowise/core/analysis/health/engine.py
@@ -52,8 +52,12 @@ def _is_test_file(rel_path: str) -> bool:
or p.endswith(".test.ts")
or p.endswith(".test.tsx")
or p.endswith(".test.js")
+ or p.endswith(".test.mts")
+ or p.endswith(".test.cts")
or p.endswith(".spec.ts")
or p.endswith(".spec.js")
+ or p.endswith(".spec.mts")
+ or p.endswith(".spec.cts")
or p.endswith("_test.go")
)
@@ -187,8 +191,12 @@ def _has_paired_test_file(rel_path: str, all_paths: set[str]) -> bool:
f"{stem}.test.ts",
f"{stem}.test.tsx",
f"{stem}.test.js",
+ f"{stem}.test.mts",
+ f"{stem}.test.cts",
f"{stem}.spec.ts",
f"{stem}.spec.js",
+ f"{stem}.spec.mts",
+ f"{stem}.spec.cts",
f"{stem}_test.go",
}
return any(
diff --git a/packages/core/src/repowise/core/ingestion/languages/specs/typescript.py b/packages/core/src/repowise/core/ingestion/languages/specs/typescript.py
index a7ff99541..77955ed5b 100644
--- a/packages/core/src/repowise/core/ingestion/languages/specs/typescript.py
+++ b/packages/core/src/repowise/core/ingestion/languages/specs/typescript.py
@@ -5,7 +5,7 @@ from ..spec import LanguageSpec
SPEC = LanguageSpec(
tag="typescript",
display_name="TypeScript",
- extensions=frozenset({".ts", ".tsx"}),
+ extensions=frozenset({".ts", ".tsx", ".mts", ".cts"}),
grammar_package="tree_sitter_typescript",
grammar_loader="language_typescript",
scm_file="typescript.scm",
diff --git a/packages/core/src/repowise/core/ingestion/resolvers/ts_workspace.py b/packages/core/src/repowise/core/ingestion/resolvers/ts_workspace.py
index 3ec38bad9..594db4d21 100644
--- a/packages/core/src/repowise/core/ingestion/resolvers/ts_workspace.py
+++ b/packages/core/src/repowise/core/ingestion/resolvers/ts_workspace.py
@@ -220,7 +220,16 @@ def get_or_build_workspace_map(ctx: "ResolverContext") -> dict[str, str]:
return {name: info["dir"] for name, info in get_or_build_workspace_info(ctx).items()}
-_PROBE_EXTENSIONS: tuple[str, ...] = (".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs")
+_PROBE_EXTENSIONS: tuple[str, ...] = (
+ ".ts",
+ ".tsx",
+ ".mts",
+ ".cts",
+ ".js",
+ ".jsx",
+ ".mjs",
+ ".cjs",
+)
def _probe_path(base: str, path_set: set[str]) -> str | None:
diff --git a/packages/core/src/repowise/core/ingestion/resolvers/typescript.py b/packages/core/src/repowise/core/ingestion/resolvers/typescript.py
index d19e200fa..fc161e8a6 100644
--- a/packages/core/src/repowise/core/ingestion/resolvers/typescript.py
+++ b/packages/core/src/repowise/core/ingestion/resolvers/typescript.py
@@ -22,7 +22,18 @@ def resolve_ts_js_import(module_path: str, importer_path: str, ctx: ResolverCont
base_posix = posixpath.normpath(
posixpath.join(importer_dir.as_posix(), module_path)
)
- exts: tuple[str, ...] = (".ts", ".tsx", ".js", ".jsx", "/index.ts", "/index.js")
+ exts: tuple[str, ...] = (
+ ".ts",
+ ".tsx",
+ ".mts",
+ ".cts",
+ ".js",
+ ".jsx",
+ "/index.ts",
+ "/index.mts",
+ "/index.cts",
+ "/index.js",
+ )
if ctx.has_sfc_files:
exts = exts + (".vue", ".svelte", ".astro")
for ext in exts:
@@ -37,7 +48,7 @@ def resolve_ts_js_import(module_path: str, importer_path: str, ctx: ResolverCont
stem_dot = base_posix.rfind(".")
if stem_dot > base_posix.rfind("/"):
real_stem = base_posix[:stem_dot]
- for ext in (".ts", ".tsx"):
+ for ext in (".ts", ".tsx", ".mts", ".cts"):
candidate = real_stem + ext
if candidate in ctx.path_set:
return candidate
diff --git a/packages/core/src/repowise/core/ingestion/tsconfig_resolver.py b/packages/core/src/repowise/core/ingestion/tsconfig_resolver.py
index 87591f41a..851843f37 100644
--- a/packages/core/src/repowise/core/ingestion/tsconfig_resolver.py
+++ b/packages/core/src/repowise/core/ingestion/tsconfig_resolver.py
@@ -31,8 +31,15 @@ import structlog
log = structlog.get_logger(__name__)
# Extensions probed in TypeScript module resolution order.
-_TS_EXTENSIONS = (".ts", ".tsx", ".js", ".jsx")
-_INDEX_FILES = ("index.ts", "index.tsx", "index.js", "index.jsx")
+_TS_EXTENSIONS = (".ts", ".tsx", ".mts", ".cts", ".js", ".jsx")
+_INDEX_FILES = (
+ "index.ts",
+ "index.tsx",
+ "index.mts",
+ "index.cts",
+ "index.js",
+ "index.jsx",
+)
# ---------------------------------------------------------------------------
diff --git a/tests/unit/dead_code/test_mts_never_flag.py b/tests/unit/dead_code/test_mts_never_flag.py
new file mode 100644
index 000000000..7b146ef2c
--- /dev/null
+++ b/tests/unit/dead_code/test_mts_never_flag.py
@@ -0,0 +1,16 @@
+"""`.mts`/`.cts` test files must be in the dead-code never-flag set (#288)."""
+
+from __future__ import annotations
+
+import pytest
+
+from repowise.core.analysis.dead_code import DeadCodeAnalyzer
+from tests.unit.dead_code._helpers import _build_graph
+
+
+ "path", ["src/foo.test.mts", "src/foo.test.cts", "src/foo.spec.mts", "src/foo.spec.cts"]
+)
+def test_mts_cts_test_files_never_flagged(path: str) -> None:
+ analyzer = DeadCodeAnalyzer(_build_graph(nodes={}), git_meta_map={})
+ assert analyzer._should_never_flag(path, set())
diff --git a/tests/unit/health/test_mts_cts_test_classification.py b/tests/unit/health/test_mts_cts_test_classification.py
new file mode 100644
index 000000000..bf4805791
--- /dev/null
+++ b/tests/unit/health/test_mts_cts_test_classification.py
@@ -0,0 +1,45 @@
+"""`.mts`/`.cts` test files must be classified as tests across health logic (#288)."""
+
+from __future__ import annotations
+
+import pytest
+
+from repowise.core.analysis.health.biomarkers.coverage_gap import _looks_like_test_path
+from repowise.core.analysis.health.biomarkers.hidden_coupling import (
+ _is_test_path as _coupling_is_test_path,
+)
+from repowise.core.analysis.health.coverage import is_test_file, paired_test_file
+from repowise.core.analysis.health.engine import (
+ _has_paired_test_file,
+ _is_test_file as _engine_is_test_file,
+)
+
+
[email protected]("path", ["src/foo.test.mts", "src/foo.test.cts", "src/foo.spec.mts", "src/foo.spec.cts"])
+def test_engine_is_test_file(path: str) -> None:
+ assert _engine_is_test_file(path)
+
+
[email protected]("path", ["src/foo.test.mts", "src/foo.spec.cts"])
+def test_coverage_is_test_file(path: str) -> None:
+ assert is_test_file(path)
+
+
[email protected]("path", ["src/foo.test.mts", "src/foo.spec.cts"])
+def test_hidden_coupling_is_test_path(path: str) -> None:
+ assert _coupling_is_test_path(path)
+
+
[email protected]("path", ["src/foo.test.mts", "src/foo.spec.cts"])
+def test_coverage_gap_looks_like_test_path(path: str) -> None:
+ assert _looks_like_test_path(path)
+
+
+def test_paired_test_file_finds_mts_cts() -> None:
+ assert paired_test_file("src/foo.ts", {"src/foo.ts", "src/foo.test.mts"}) == "src/foo.test.mts"
+ assert paired_test_file("src/bar.ts", {"src/bar.ts", "src/bar.spec.cts"}) == "src/bar.spec.cts"
+
+
+def test_engine_has_paired_test_file_for_mts_source() -> None:
+ assert _has_paired_test_file("src/foo.mts", {"src/foo.mts", "src/foo.test.mts"})
+ assert _has_paired_test_file("src/bar.cts", {"src/bar.cts", "src/bar.spec.cts"})
diff --git a/tests/unit/ingestion/parser/test_typescript.py b/tests/unit/ingestion/parser/test_typescript.py
index 945ad4158..c62955d74 100644
--- a/tests/unit/ingestion/parser/test_typescript.py
+++ b/tests/unit/ingestion/parser/test_typescript.py
@@ -207,3 +207,15 @@ export class Service {
result = parser.parse_file(fi, src)
method_names = {s.name for s in result.symbols if s.kind == "method"}
assert {"run", "helper"} <= method_names
+
+
+def test_mts_file_uses_typescript_parser(parser: ASTParser) -> None:
+ fi = _make_file_info("src/module.mts", "typescript")
+ parsed = parser.parse_file(fi, b"export function load(): number { return 1; }\n")
+ assert any(s.name == "load" for s in parsed.symbols)
+
+
+def test_cts_file_uses_typescript_parser(parser: ASTParser) -> None:
+ fi = _make_file_info("src/module.cts", "typescript")
+ parsed = parser.parse_file(fi, b"export function load(): number { return 1; }\n")
+ assert any(s.name == "load" for s in parsed.symbols)
diff --git a/tests/unit/ingestion/test_traverser.py b/tests/unit/ingestion/test_traverser.py
index b4e1545af..3845f7fcc 100644
--- a/tests/unit/ingestion/test_traverser.py
+++ b/tests/unit/ingestion/test_traverser.py
@@ -29,6 +29,16 @@ class TestLanguageDetection:
f.write_text("<div />")
assert _detect_language(f) == "typescript"
+ def test_mts_extension(self, tmp_path: Path) -> None:
+ f = tmp_path / "module.mts"
+ f.write_text("export const x = 1;")
+ assert _detect_language(f) == "typescript"
+
+ def test_cts_extension(self, tmp_path: Path) -> None:
+ f = tmp_path / "module.cts"
+ f.write_text("export const x = 1;")
+ assert _detect_language(f) == "typescript"
+
def test_go_extension(self, tmp_path: Path) -> None:
assert _detect_language(tmp_path / "main.go") == "go"
diff --git a/tests/unit/ingestion/test_tsconfig_resolver.py b/tests/unit/ingestion/test_tsconfig_resolver.py
index d9e6b853a..e8ec41f20 100644
--- a/tests/unit/ingestion/test_tsconfig_resolver.py
+++ b/tests/unit/ingestion/test_tsconfig_resolver.py
@@ -530,3 +530,31 @@ class TestMatchAlias:
def test_wildcard_empty_capture(self) -> None:
assert TsconfigResolver._match_alias("@/*", "@/") == ""
+
+
+class TestMtsCtsAliasResolution:
+ def _resolver(self, tmp_path: Path, path_set: set[str]) -> TsconfigResolver:
+ return _make_resolver(
+ tmp_path,
+ configs={
+ "tsconfig.json": {
+ "compilerOptions": {"baseUrl": ".", "paths": {"@/*": ["./src/*"]}}
+ }
+ },
+ path_set=path_set,
+ )
+
+ def test_alias_resolves_to_mts(self, tmp_path: Path) -> None:
+ resolver = self._resolver(tmp_path, {"src/module.mts"})
+ result = resolver.resolve("@/module", _importer(tmp_path, "src/app.ts"))
+ assert result == "src/module.mts"
+
+ def test_alias_resolves_to_cts(self, tmp_path: Path) -> None:
+ resolver = self._resolver(tmp_path, {"src/module.cts"})
+ result = resolver.resolve("@/module", _importer(tmp_path, "src/app.ts"))
+ assert result == "src/module.cts"
+
+ def test_alias_directory_resolves_to_index_mts(self, tmp_path: Path) -> None:
+ resolver = self._resolver(tmp_path, {"src/pkg/index.mts"})
+ result = resolver.resolve("@/pkg", _importer(tmp_path, "src/app.ts"))
+ assert result == "src/pkg/index.mts"
diff --git a/tests/unit/ingestion/test_typescript_resolver.py b/tests/unit/ingestion/test_typescript_resolver.py
index 1a58a8441..2a355d0e5 100644
--- a/tests/unit/ingestion/test_typescript_resolver.py
+++ b/tests/unit/ingestion/test_typescript_resolver.py
@@ -96,6 +96,24 @@ class TestWorkspaceResolution:
# would then return external:).
assert resolve_via_workspaces("@unknown/pkg", ctx) is None
+ def test_resolves_workspace_subpath_to_mts(self, tmp_path: Path) -> None:
+ (tmp_path / "package.json").write_text(json.dumps({"workspaces": ["packages/*"]}))
+ pkg = tmp_path / "packages" / "core"
+ pkg.mkdir(parents=True)
+ (pkg / "package.json").write_text(json.dumps({"name": "@org/core"}))
+ ctx = _ctx(tmp_path, ["packages/core/src/index.mts"])
+ result = resolve_via_workspaces("@org/core/src/index", ctx)
+ assert result == "packages/core/src/index.mts"
+
+ def test_resolves_workspace_index_cts(self, tmp_path: Path) -> None:
+ (tmp_path / "package.json").write_text(json.dumps({"workspaces": ["packages/*"]}))
+ pkg = tmp_path / "packages" / "core"
+ pkg.mkdir(parents=True)
+ (pkg / "package.json").write_text(json.dumps({"name": "@org/core"}))
+ ctx = _ctx(tmp_path, ["packages/core/index.cts"])
+ result = resolve_via_workspaces("@org/core", ctx)
+ assert result == "packages/core/index.cts"
+
def _setup_workspace(
tmp_path: Path,
@@ -263,3 +281,21 @@ class TestWorkspaceExportsField:
resolve_via_workspaces("@org/ui/secret", ctx)
== "packages/ui/src/secret.ts"
)
+
+
+class TestMtsCtsResolution:
+ def test_extensionless_import_resolves_to_mts(self, tmp_path: Path) -> None:
+ ctx = _ctx(tmp_path, ["src/module.mts", "src/main.ts"])
+ assert resolve_ts_js_import("./module", "src/main.ts", ctx) == "src/module.mts"
+
+ def test_extensionless_import_resolves_to_cts(self, tmp_path: Path) -> None:
+ ctx = _ctx(tmp_path, ["src/module.cts", "src/main.ts"])
+ assert resolve_ts_js_import("./module", "src/main.ts", ctx) == "src/module.cts"
+
+ def test_directory_import_resolves_to_index_mts(self, tmp_path: Path) -> None:
+ ctx = _ctx(tmp_path, ["src/pkg/index.mts", "src/main.ts"])
+ assert resolve_ts_js_import("./pkg", "src/main.ts", ctx) == "src/pkg/index.mts"
+
+ def test_directory_import_resolves_to_index_cts(self, tmp_path: Path) -> None:
+ ctx = _ctx(tmp_path, ["src/pkg/index.cts", "src/main.ts"])
+ assert resolve_ts_js_import("./pkg", "src/main.ts", ctx) == "src/pkg/index.cts"