Skip to content

TypeScript umbrella members resolve imports between unbuilt workspace packages - #1964

Merged
zlareb1 merged 10 commits into
ClickHouse:mainfrom
KaloyanNaumov:pr/ts-cross-package-edges
Dec 2, 2026
Merged

zlareb1 merged 10 commits into
ClickHouse:mainfrom
KaloyanNaumov:pr/ts-cross-package-edges

Conversation

@KaloyanNaumov

@KaloyanNaumov KaloyanNaumov commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Related: #1958
Related: #1782

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A pnpm or yarn workspace whose root tsconfig is an umbrella over member projects keeps its compiler call and type edges between packages again: the TypeScript pass applies code_scip_ts_paths to member runs as it does to a whole-root run, and keeps the aliases a member's tsconfig inherits through extends.

Why

Since #1782 the harness indexes a discovered umbrella one member at a time, and that branch also set SCIP_TS_PATHS=0. The line came from the SCIP_TS_PROJECTS branch above it, where an operator names the projects; for a discovered umbrella it overrode code_scip_ts_paths without anyone choosing that. In an unbuilt workspace a package's exports point at dist/, which does not exist, and scip-typescript 0.4.0 does not redirect a project reference to source, so the import of a sibling package resolves to nothing and its edges are lost.

The fix removes the override. WORKSPACES="" stays: each member is indexed through its own tsconfig. scip_ts_paths.py wrote its paths into the tsconfig.json of every named workspace package, but an umbrella can also reference a member by its config file (packages/app/tsconfig.build.json), and the indexer then read a file the rewrite never touched. For a member list the harness now passes the helper the configs it gives the indexer, with --config: a member named by its directory gives its tsconfig.json, an explicit reference gives that file. The helper rewrites and restores exactly those files. A regular root, with no member list, keeps the rewrite of every package's tsconfig.json.

Each selected config is computed from the configs as the project wrote them, read from the backup when one exists, so a named config that extends a tsconfig.json rewritten in the same pass gets the same paths in either order. It carries the parent's own aliases once and its own workspace entries, never the entries added for the parent, which can name the config's own package when the parent belongs to another one.

A paths or baseUrl written into a tsconfig replaces the one its extends chain sets. Before this change the helper wrote its own paths and baseUrl: ".", so a member that extends a base with its own aliases lost them, and its import of such an alias failed with TS2307. The helper now follows the extends chain, keeps the paths in effect, and adds only the workspace entries, relative to the baseUrl in effect. It no longer writes a baseUrl. With no baseUrl in the chain, inherited entries are rebased to the package's directory, because they resolve from the config that set them.

The walk keeps the configs it has entered and skips one it meets again, as TypeScript's resolution stack does, so a cycle through array extends ends at once. It strips a leading byte order mark before parsing, as TypeScript does. When an extends entry cannot be resolved or parsed, the helper leaves that package's tsconfig unpatched and logs it, because a paths written over options it cannot see could replace aliases it never read. ${configDir} is matched in any case, and the backup is a byte copy of the tsconfig, so --restore gives back a CRLF file as it was.

TypeScript tries an exact paths key before any pattern (matchPatternOrExact), so an added exact entry would take a specifier from a configured wildcard: with @pkg/* configured, an added @pkg/feature moved the import to another file and the type check failed. A workspace entry is added only when no key in effect, own or inherited, matches its specifier: the same key, or a pattern with one * whose prefix and suffix fit around it.

Scope and risk

scripts/scip_harness/run_typescript_delta.sh (the override removed, the selected configs passed to the rewrite), the merge with inherited options and --config in scripts/scip_harness/scip_ts_paths.py, and tests. The helper change also applies to a regular root, where it fixes the same loss of inherited aliases and, for a package that sets its own baseUrl, entries that were written relative to the package and not to that baseUrl. A member's program now also compiles the source files its imports resolve to, as the whole-root run did; the merge keeps each document only for the member that owns it, so those copies are dropped. For a member list the rewrite now edits only the configs the indexer reads, so a delta that selects some members leaves the others' files alone, and a member directory without a package.json gets the entries too. Limit: an extends is followed as a relative or rooted path, or as a config found under node_modules by its path. A package whose config TypeScript finds through its exports or its tsconfig field is not resolved; the helper leaves that package unpatched and logs it, so its edges between workspace packages stay as they are on main. The whole-root run indexed each workspace package through its tsconfig.json and kept those edges, so that case is not fixed here. The SCIP_TS_PROJECTS branch and the handling of files a member compiles from outside its directory are unchanged.

An inferred entry is skipped whenever a configured paths key already matches its specifier, so a configured catch-all "*" key suppresses every inferred entry and such a repository keeps main's resolution.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none. A later delta restores the edges of the files it converts; a full pass restores all of them.
  • Rollback: reverting drops the edges again on the next pass; nothing else is stored.

Tests

  • tests/unit/test_run_typescript_delta_umbrella.py::test_umbrella_workspace_members_resolve_unbuilt_packages: an umbrella over a pnpm workspace where @x/lib exports ./dist/index.js. The stub indexer records each member's tsconfig.json as it reads it; packages/app carries paths: {"@x/lib": ["../lib/src/index.ts"]}, and the file is restored afterwards. On main it fails with KeyError: 'compilerOptions'. The stub Python now forwards scip_ts_paths.py to the real helper, as it does for discovery and the merge.
  • test_run_typescript_delta_umbrella.py::test_umbrella_member_keeps_aliases_inherited_from_a_base_tsconfig: packages/app extends ../../tsconfig.base.json, which sets baseUrl: "." and maps @local/internal. The tsconfig the indexer reads carries both aliases, the added one relative to the inherited baseUrl, and no baseUrl of its own.
  • test_scip_ts_paths.py::test_patch_keeps_inherited_paths_and_their_base: a base with paths and no baseUrl (entries rebased to the package) and a package with its own baseUrl: "src" (entries written against it). Both fail before the helper change.
  • test_scip_ts_paths.py, five tests for the extends walk: a three-config cycle through array extends returns (the run is bounded at 20 s); a base with a byte order mark still gives its paths; an extends that names a package config or a file that does not parse leaves the package unpatched, with its bytes unchanged and no backup; ${CONFIGDIR} and ${ConfigDir} are read as ${configDir}; --restore gives back a CRLF tsconfig byte for byte. All five fail on the previous head.
  • test_scip_ts_paths.py, three tests for keys in effect: @acme/kit/* configured beside the ./feature subpath export keeps the specifier (no @acme/kit/feature written, @acme/kit still added); @acme/other/*, @acme/kit/*/x and @acme/*/* do not match, so the subpath entry is written; a configured exact @acme/kit/feature keeps its target and the count reports only the entries added. The first and the third fail on 5f11ff284. With TypeScript 5.9.3, the same workspace unbuilt: after the rewrite at 5f11ff284, --traceResolution shows @acme/kit/feature matching the added exact key and tsc reports TS2305 for a member only the configured file exports; at 3c08380 it matches @acme/kit/*, resolves to the configured file, and tsc exits 0.
  • Three tests for selected configs, all failing on 3c08380a3. test_run_typescript_delta_umbrella.py::test_umbrella_member_named_by_its_config_file_gets_the_paths: the umbrella references packages/app/tsconfig.build.json beside an unbuilt @x/lib; the config the indexer reads carries @x/lib, the unused tsconfig.json is unchanged, and git status --ignored is empty afterwards. test_scip_ts_paths.py::test_a_named_config_is_patched_and_restored_alone: a CRLF tsconfig.build.json is patched and restored byte for byte, and the tsconfig.json beside it is not touched. test_scip_ts_paths.py::test_a_named_config_over_a_rewritten_tsconfig_reads_what_the_project_wrote: a tsconfig.json, a named config extending it in the same package and one extending it from another package, selected in both orders, give the same result, each alias once, and no entry for the config's own package. With real scip-typescript 0.4.0 on that workspace, unbuilt, the harness at 3c08380a3 patched packages/app/tsconfig.json and the delta had no edges; at 85e5b5a58 it patches packages/app/tsconfig.build.json and the delta has the call a → b into packages/lib. tsc -p packages/app/tsconfig.build.json (TypeScript 5.9.3) reports TS2307 for @x/lib after the old rewrite and exits 0 after the new one. The checkout was clean after each run.
  • Real scip-typescript 0.4.0 (TypeScript 5.9.3), run_typescript_delta.sh in DELTA_OUT --full mode from the harness of three trees, over a pnpm umbrella with packages/app and packages/lib (@x/lib exports ./dist/index.js, nothing built). app imports @x/lib and @local/internal. Edges in the delta; "lost" and "gained" are against main (e89cc858f), "previous head" is 9e87a5f87, "this head" is 5f11ff284. The later change for keys in effect reaches only row F among these, where @x/* already maps @x/lib to source and @x/lib is no longer added; F was not run again:
app's tsconfig extends main previous head this head
A: a base with baseUrl: "." and paths 1 1, lost 1 2, lost 0
B: a base with paths, no baseUrl 1 1, lost 1 2, lost 0
C: @acme/tsconfig in node_modules, ${configDir} paths 1 1, lost 1 2, lost 0
D: an array, [base, strict] 1 1, lost 1 2, lost 0
E: a base with comments and trailing commas 1 1, lost 1 2, lost 0
F: a base that maps @x/* and @local/internal 2 1, lost 1 2, lost 0, none gained
G: a base with a byte order mark 1 1, lost 1 2, lost 0
H: the base as in A, app's own tsconfig with CRLF line ends 1 1, lost 1 2, lost 0
J: @co/tsconfig/base, named through exports 1 1, lost 1 1, lost 0, package left unpatched

Where main has 1 edge, this head adds the cross-package call appfn → libfn and keeps main's. F's main edges already include it, and J keeps main's edge only. After each harness run the checkout was clean (git status) on this head in every row. On the previous head it was not in H, where --restore left the CRLF file modified. A cycle through array extends (a extends [b, c], b extends [a, c], c extends [a, b]) is a TypeScript error (TS18000) in every tree, so the indexer writes nothing. The helper before this change did not return within a 300 s bound on it; on this head the harness returns at once with TypeScript's error.

  • Run at 16c32dd36, with main at 82dc31216 merged in: test_run_typescript_delta_umbrella.py, test_run_typescript_delta_projects.py, test_scip_ts_projects.py, test_scip_merge_indexes.py, test_scip_ts_paths.py, test_scip_harness_windows.py, test_scip_harness_checkout_path.py, test_code_scip_ts_delta_worker.py and test_scip_to_delta_cli.py, with test_tunable_constants.py and test_public_copy.py: 149 passed. ruff check, ruff format --check, the function-length gate and scripts/gates/mypy_gate.py pass, and mypy on scip_ts_paths.py reports the same errors as before the change (seven, none new); bash -n on the script passes. The full unit suite was not run here; CI runs it.
  • Real scip-typescript 0.4.0 (node 22, pnpm), DELTA_OUT mode, counts from the delta JSON. These rows were measured at 9e87a5f87, before the helper change above, and not repeated at this head; the helper change reaches only a tsconfig that sets or inherits paths:
repository harness indexer processes wall peak RSS, one process files / symbols / edges
4-package pnpm workspace, umbrella root, nothing built before #1782 1 2.0 s 0.17 GiB 5 / 7 / 7
same main 4 6.7 s 0.16 GiB 4 / 6 / 2
same this branch 4 6.0 s 0.16 GiB 4 / 6 / 7
typescript-eslint/typescript-eslint a1faa174, 36 members before #1782 1 85 s 1.32 GiB 1,368 / 6,735 / 4,220
same main 36 390 s 0.92 GiB 1,358 / 6,628 / 4,220
same this branch 36 388 s 0.90 GiB 1,358 / 6,628 / 4,220

On the fixture the edge list of this branch is identical to the run before #1782, line for line. On typescript-eslint the three edge lists in the table are identical. Its 36 members are named configs behind per-package solution tsconfig.json files, so up to 3c08380a3 the rewrite did not reach any config that is compiled, and the per-process peak stays below the whole-root run. At 85e5b5a58 the rewrite patches those 36 configs. Against the harness at 3c08380a3 (4,220 edges, 387 s), files and symbols are unchanged and edges are 4,689 (401 s): 475 gained, 470 of them between packages. Six are absent: references from typescript-estree into its own declare module 'typescript' augmentation in typings/typescript.d.ts. The member's added paths change four resolutions, all sibling imports that were TS2307 and now reach source. Some of those sources import typescript/lib/tsserverlibrary, whose declaration file is import ts = require("./typescript.js"); export = ts;. With TypeScript 5.9.3, that one import, added as a root file to the unpatched config, leaves ts.getModifiers with only the lib declaration, so the indexer has no augmentation to reference. The checkout was clean after both runs. The file and symbol still missing are shared/util.ts, which a member compiles from outside its directory; that is the other half of the linked issue and is not part of this change.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code wrote the diff, the helper change and the tests. Checked: I reviewed the diff and its tests; the runs listed under Tests are the agent's.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: none are affected.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited: no migration.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version: no plugin file changed.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed: it did not.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes: the code_scip_ts_paths row already says the rewrite applies before indexing an unbuilt checkout.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

Note

Medium Risk
Changes TypeScript delta indexing and in-place tsconfig mutation for many monorepos; behavior is well-tested but mistakes could drop or mis-resolve cross-package edges.

Overview
Restores compiler path rewriting when an umbrella root indexes monorepo members one-at-a-time: discovered umbrella runs no longer force SCIP_TS_PATHS=0, and scip_ts_paths.py is invoked with --config for exactly the tsconfig files each member uses (including tsconfig.build.json and harness-generated tsconfig.scip.json).

scip_ts_paths.py is reworked to merge workspace paths without clobbering project setup: it walks extends, keeps inherited aliases and baseUrl, rebases relative entries, skips specifiers already covered by existing keys/wildcards, and can patch/restore named configs independently with byte-accurate backups.

New unit tests cover umbrella indexing, inherited bases, named configs, extends edge cases, and restore behavior.

Reviewed by Cursor Bugbot for commit fb9b3c8. Bugbot is set up for automated code reviews on this repo. Configure here.

A discovered umbrella set SCIP_TS_PATHS=0, a line copied from the
SCIP_TS_PROJECTS branch. scip_ts_paths.py writes its paths into the
tsconfig.json of every named workspace package that has one. A member
referenced by its directory is indexed through that file, and a named
config that extends it inherits the paths; in an unbuilt pnpm or yarn
workspace they are what resolve imports between members. Without them a
member's import of another resolves to nothing and its call and type
edges are lost.

The new harness test reads the member's tsconfig.json as the indexer sees
it: the import's paths entry is there, and the file is restored afterwards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@vercel

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 2, 2026 9:21am UTC
loom-telemetry Ready Ready Preview Dec 2, 2026 9:21am UTC

Request Review

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workspace rewrite restores cross-package imports in the supplied fixture. It also changes the resolution of aliases inherited from a base tsconfig.

KaloyanNaumov and others added 3 commits December 1, 2026 23:58
A paths or baseUrl written into a tsconfig replaces the one its extends
chain sets. An app that extends a base with its own aliases lost them
once the rewrite reached umbrella members: its import of such an alias
failed with TS2307 and the call edges through it were dropped.

scip_ts_paths.py now follows the extends chain, keeps the paths in
effect, and writes only the workspace entries beside them, relative to
the baseUrl in effect. It no longer sets a baseUrl. Inherited entries
with no baseUrl are rebased to the package's directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
…ot read unpatched

A cycle through array extends made the walk exponential: the depth cap
bounded a chain, not the branching. The walk now keeps the configs it has
entered and skips one it meets again, as TypeScript's resolution stack
does.

A base tsconfig with a byte order mark did not parse, so its paths were
replaced by the written ones. The BOM is stripped before parsing. An
extends entry that cannot be resolved or parsed, such as a package that
names its config through exports, now leaves that package's tsconfig
unpatched and says so, instead of writing a paths over aliases the
script cannot see.

The ${configDir} template is matched in any case, as TypeScript does, and
the backup is a byte copy, so --restore gives back a CRLF tsconfig as it
was.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inherited exact alias retains its configured base. Inferred workspace paths can still override an existing wildcard alias.

Comment thread scripts/scip_harness/scip_ts_paths.py Resolved
…hes it

TypeScript takes an exact paths key before any pattern
(matchPatternOrExact), so an added @pkg/feature took the import from a
configured @pkg/* and resolved it to another file. A workspace entry is
added only when no key in effect matches its specifier: the same key,
or a single-star pattern whose prefix and suffix fit around it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 11 path-rewrite tests pass, and configured wildcard aliases retain precedence. A discovered umbrella member can still be indexed with a config the rewrite never edits.

KaloyanNaumov and others added 2 commits December 2, 2026 04:59
…through

An umbrella may reference a member by its config file, such as
packages/app/tsconfig.build.json, but the rewrite patched only each
package's tsconfig.json. The harness now passes the configs it gives the
indexer to scip_ts_paths.py with --config, and restores those same files.
Each config is computed from the configs as the project wrote them, so a
named config that extends a rewritten tsconfig.json gets the same entries
in either order, and never the entries added for that parent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Main (897a1d613) is merged in. Git merged run_typescript_delta.sh and the umbrella test file without conflicts. The rewrite is gated on the full member list, as #1976 now does for the root pass, so a delta that selects no member also rewrites nothing.

This also closes the case I added to #1958: a member listed through a standalone named config, one that does not extend its package's tsconfig.json, now gets the workspace entries in the config it is indexed through.

…e-edges-r29

One conflict, in tests/unit/test_run_typescript_delta_umbrella.py: both
sides appended tests after the same line, so both blocks are kept.

Assisted-by: Claude Code
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Merged main (82dc312) into this branch to clear the conflict.

One file conflicted, tests/unit/test_run_typescript_delta_umbrella.py. This PR and #1976 both appended tests after the same line, so I kept both sets of tests. No code changed; the merge brought in nothing else that touches the files this PR edits.

The TypeScript harness and umbrella tests pass (88 across test_run_typescript_delta_umbrella.py, test_run_typescript_delta_projects.py, test_scip_ts_projects.py, test_scip_typescript.py, test_typescript_dependency_preparation.py and test_code_lang_typescript.py), as do ruff, the function-length gate and test_tunable_constants.py.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explicit tsconfig case is fixed, and all 35 focused tests pass. An umbrella member that uses the generated config still misses the workspace aliases.

A member directory with no tsconfig.json is indexed through the
tsconfig.scip.json the harness writes, but that file was not in the
--config list, so a sibling exporting unbuilt dist files had no alias in
the config the indexer read. Add it to the list. The restore puts the
generated bytes back and the exit hook removes the file, so the tree is
clean afterwards.

Assisted-by: Claude Code
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The analyzer job reports the same mentor evidence shape mismatch on this head's tested base. The focused test passes on current main with the snapshot update from #1957. The existing digest repair in #1990 addresses the SQL comment that made the literal affect the shape. Failed CI job · Digest repair

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated tsconfig now receives the workspace aliases. Preserve quoted path values when reading the config.

Comment thread scripts/scip_harness/scip_ts_paths.py Resolved
The trailing-comma substitution also ran inside quoted values, so an alias
such as "./file,].ts" lost its comma and the rewritten config carried the
changed path. Match a quoted string first and keep it, as the comment pass
before it does.

Assisted-by: Claude Code
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tsconfig reader preserves quoted values containing ,] while removing trailing commas outside strings. All 37 focused config and umbrella-harness tests passed.

@zlareb1
zlareb1 merged commit 7ec9135 into ClickHouse:main Dec 2, 2026
77 checks passed
@KaloyanNaumov
KaloyanNaumov deleted the pr/ts-cross-package-edges branch December 4, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants