Repository navigation
Index TypeScript monorepos by member project, not the umbrella root #1782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zlareb1
merged 18 commits into
ClickHouse:main
from
ZYZ666-RGB:fix-1678-ts-umbrella-delta
Dec 1, 2026
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
38c6a4f
Index TypeScript monorepos by member project, not the umbrella root
ZYZ666-RGB 315c4d7
Fix TypeScript umbrella discovery and delta fallbacks
ZYZ666-RGB c0d7465
Isolate TypeScript member index runs and keep paths with spaces
ZYZ666-RGB 7a6c9a2
Index a regular root TypeScript project as the workspace
ZYZ666-RGB 11c0a52
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB 61465f5
Dedupe merged TypeScript indexes and keep hidden member paths
ZYZ666-RGB ff13773
Keep sibling tsconfig documents and reindex config-only windows
ZYZ666-RGB 445d783
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB b198ae2
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB 2c7d09a
Convert full member indexes on mixed TypeScript windows
ZYZ666-RGB 2eade0f
Keep documents from root-level tsconfigs and rebuild on member config…
ZYZ666-RGB 6e72312
Drop followed root-tsconfig docs and skip unowned config rebuilds
ZYZ666-RGB c24cf1d
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB 9dd7f42
Format the has-config guard the way shfmt expects
ZYZ666-RGB b123531
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB 53f1006
Keep merge docs when a generated tsconfig.scip.json matches a known dir
ZYZ666-RGB e8fbb33
Keep the most specific directory when sibling tsconfigs tie
ZYZ666-RGB d848bd1
Prefer a one-character member over a root tsconfig on a length tie
ZYZ666-RGB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| #!/usr/bin/env python3 | ||
| """Merge SCIP Index files into one index. | ||
|
|
||
| Each input is a complete Index (scip-typescript --output). Documents are | ||
| keyed by relative_path so a file emitted by more than one isolated run | ||
| appears once. When --project is given for each input, a document is taken | ||
| from the member that uniquely owns it (the longest matching project | ||
| scope); that drops copies a dependent emitted by following TypeScript | ||
| project references. Sibling tsconfigs in the same directory share a | ||
| scope, so each keeps the documents it emitted and a path present in more | ||
| than one of those indexes keeps the last copy. Metadata is taken from | ||
| the first non-empty input. External | ||
| symbols are concatenated. An all-empty input list, or only empty files, | ||
| writes a zero-byte output so the converter treats it as an empty index. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import importlib.util | ||
| import sys | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| _HARNESS = Path(__file__).resolve().parent | ||
| _VENDOR = _HARNESS / "vendor" | ||
|
|
||
|
|
||
| def _load_ts_projects() -> Any: | ||
| spec = importlib.util.spec_from_file_location( | ||
| "scip_ts_projects", _HARNESS / "scip_ts_projects.py" | ||
| ) | ||
| if spec is None or spec.loader is None: | ||
| raise SystemExit(f"cannot load {_HARNESS / 'scip_ts_projects.py'}") | ||
| mod = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(mod) | ||
| return mod | ||
|
|
||
|
|
||
| _ts_projects = _load_ts_projects() | ||
| project_owns = _ts_projects.project_owns | ||
| project_scope = _ts_projects.project_scope | ||
|
|
||
|
|
||
| def _ensure_scip_pb2() -> Any: | ||
| if str(_VENDOR) not in sys.path: | ||
| sys.path.insert(0, str(_VENDOR)) | ||
| try: | ||
| import scip_pb2 | ||
| except Exception as e: # ImportError, or protobuf VersionError | ||
| raise SystemExit( | ||
| f"cannot load vendor/scip_pb2.py ({e}): merging indexes needs protobuf>=7.35.1" | ||
| ) from e | ||
| return scip_pb2 | ||
|
|
||
|
|
||
| def _scope_specificity(project: str) -> int: | ||
| """Longer directory scopes win. The root scope '.' has length 1, which | ||
| would otherwise tie a one-character member directory such as 'a'.""" | ||
| scope = project_scope(project) | ||
| if scope in (".", ""): | ||
| return 0 | ||
| return len(scope) | ||
|
|
||
|
|
||
| def _preferred_owner(projects: list[str], relpath: str) -> str | None: | ||
| owners = [project for project in projects if project_owns(project, relpath)] | ||
| if not owners: | ||
| return None | ||
| best_scope = max(_scope_specificity(project) for project in owners) | ||
| tied = [project for project in owners if _scope_specificity(project) == best_scope] | ||
| # Sibling explicit tsconfigs share a directory scope. Returning one of | ||
| # them still lets each sibling keep its documents (scopes match) while | ||
| # a shorter ancestor, such as a root tsconfig, is dropped. | ||
| return tied[0] | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| def merge_indexes( | ||
| paths: list[Path], | ||
| output: Path, | ||
| projects: list[str] | None = None, | ||
| known_projects: list[str] | None = None, | ||
| ) -> None: | ||
| if projects is not None and len(projects) != len(paths): | ||
| raise SystemExit("--project count must match the number of indexes") | ||
| scip_pb2 = _ensure_scip_pb2() | ||
| merged = scip_pb2.Index() | ||
| documents: dict[str, object] = {} | ||
| has_payload = False | ||
| for i, path in enumerate(paths): | ||
| data = path.read_bytes() if path.is_file() else b"" | ||
| if not data: | ||
| continue | ||
| idx = scip_pb2.Index() | ||
| idx.ParseFromString(data) | ||
| if not has_payload and idx.HasField("metadata"): | ||
| merged.metadata.CopyFrom(idx.metadata) | ||
| project = projects[i] if projects is not None else None | ||
| for doc in idx.documents: | ||
| rel = doc.relative_path | ||
| if projects is not None and project is not None: | ||
| # Keep documents this member owns. Documents followed through | ||
| # TypeScript project references into another package are | ||
| # dropped even when that package is not in this merge, so a | ||
| # subset rebuild cannot overwrite the other package's rows. | ||
| # known_projects is the full discovered set: a root-level | ||
| # tsconfig owns every path, so ownership still prefers a | ||
| # longer member that was not indexed in this run. | ||
| if not project_owns(project, rel): | ||
| continue | ||
| owners = known_projects if known_projects is not None else projects | ||
| owner = _preferred_owner(owners, rel) | ||
| # Compare scopes, not raw project strings: a generated | ||
| # member target is dir/tsconfig.scip.json, while | ||
| # --known-project still names dir. | ||
| if owner is not None and project_scope(owner) != project_scope(project): | ||
|
zlareb1 marked this conversation as resolved.
Resolved
|
||
| continue | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
cursor[bot] marked this conversation as resolved.
Resolved
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| copied = scip_pb2.Document() | ||
| copied.CopyFrom(doc) | ||
| documents[rel] = copied | ||
| merged.external_symbols.extend(idx.external_symbols) | ||
| has_payload = True | ||
| if not has_payload: | ||
| output.write_bytes(b"") | ||
| return | ||
| for doc in documents.values(): | ||
| merged.documents.append(doc) | ||
| output.write_bytes(merged.SerializeToString()) | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--output", required=True, type=Path) | ||
| parser.add_argument( | ||
| "--project", | ||
| action="append", | ||
| default=[], | ||
| help="member path for the corresponding index (same order); " | ||
| "documents are kept from the owning member", | ||
| ) | ||
| parser.add_argument( | ||
| "--known-project", | ||
| action="append", | ||
| default=[], | ||
| help="full discovered member set used for ownership; a document is " | ||
| "dropped when a more specific member owns it, even if that member " | ||
| "was not indexed in this run", | ||
| ) | ||
| parser.add_argument("indexes", nargs="+", type=Path) | ||
| args = parser.parse_args(argv) | ||
| projects = args.project or None | ||
| known = args.known_project or None | ||
| merge_indexes(args.indexes, args.output, projects, known) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.