Repository navigation
TypeScript umbrella members resolve imports between unbuilt workspace packages - #1964
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
zlareb1
left a comment
There was a problem hiding this comment.
The workspace rewrite restores cross-package imports in the supplied fixture. It also changes the resolution of aliases inherited from a base tsconfig.
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
left a comment
There was a problem hiding this comment.
The inherited exact alias retains its configured base. Inferred workspace paths can still override an existing wildcard alias.
…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
left a comment
There was a problem hiding this comment.
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.
…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>
|
Main ( 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 |
…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>
|
Merged One file conflicted, The TypeScript harness and umbrella tests pass (88 across |
zlareb1
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
The generated tsconfig now receives the workspace aliases. Preserve quoted path values when reading the config.
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
left a comment
There was a problem hiding this comment.
The tsconfig reader preserves quoted values containing ,] while removing trailing commas outside strings. All 37 focused config and umbrella-harness tests passed.
Related: #1958
Related: #1782
Changelog category (leave one):
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_pathsto member runs as it does to a whole-root run, and keeps the aliases a member's tsconfig inherits throughextends.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 theSCIP_TS_PROJECTSbranch above it, where an operator names the projects; for a discovered umbrella it overrodecode_scip_ts_pathswithout anyone choosing that. In an unbuilt workspace a package'sexportspoint atdist/, 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.pywrote itspathsinto thetsconfig.jsonof 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 itstsconfig.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'stsconfig.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.jsonrewritten in the same pass gets the samepathsin 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
pathsorbaseUrlwritten into a tsconfig replaces the one itsextendschain sets. Before this change the helper wrote its ownpathsandbaseUrl: ".", 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 theextendschain, keeps thepathsin effect, and adds only the workspace entries, relative to thebaseUrlin effect. It no longer writes abaseUrl. With nobaseUrlin 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
extendsends at once. It strips a leading byte order mark before parsing, as TypeScript does. When anextendsentry cannot be resolved or parsed, the helper leaves that package's tsconfig unpatched and logs it, because apathswritten 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--restoregives back a CRLF file as it was.TypeScript tries an exact
pathskey before any pattern (matchPatternOrExact), so an added exact entry would take a specifier from a configured wildcard: with@pkg/*configured, an added@pkg/featuremoved 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--configinscripts/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 ownbaseUrl, entries that were written relative to the package and not to thatbaseUrl. 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 apackage.jsongets the entries too. Limit: anextendsis followed as a relative or rooted path, or as a config found undernode_modulesby its path. A package whose config TypeScript finds through itsexportsor itstsconfigfield is not resolved; the helper leaves that package unpatched and logs it, so its edges between workspace packages stay as they are onmain. The whole-root run indexed each workspace package through itstsconfig.jsonand kept those edges, so that case is not fixed here. TheSCIP_TS_PROJECTSbranch and the handling of files a member compiles from outside its directory are unchanged.An inferred entry is skipped whenever a configured
pathskey already matches its specifier, so a configured catch-all"*"key suppresses every inferred entry and such a repository keepsmain's resolution.Compatibility, rollout and rollback
Tests
tests/unit/test_run_typescript_delta_umbrella.py::test_umbrella_workspace_members_resolve_unbuilt_packages: an umbrella over a pnpm workspace where@x/libexports./dist/index.js. The stub indexer records each member'stsconfig.jsonas it reads it;packages/appcarriespaths: {"@x/lib": ["../lib/src/index.ts"]}, and the file is restored afterwards. Onmainit fails withKeyError: 'compilerOptions'. The stub Python now forwardsscip_ts_paths.pyto 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/appextends../../tsconfig.base.json, which setsbaseUrl: "."and maps@local/internal. The tsconfig the indexer reads carries both aliases, the added one relative to the inheritedbaseUrl, and nobaseUrlof its own.test_scip_ts_paths.py::test_patch_keeps_inherited_paths_and_their_base: a base withpathsand nobaseUrl(entries rebased to the package) and a package with its ownbaseUrl: "src"(entries written against it). Both fail before the helper change.test_scip_ts_paths.py, five tests for theextendswalk: a three-config cycle through arrayextendsreturns (the run is bounded at 20 s); a base with a byte order mark still gives itspaths; anextendsthat 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};--restoregives 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./featuresubpath export keeps the specifier (no@acme/kit/featurewritten,@acme/kitstill added);@acme/other/*,@acme/kit/*/xand@acme/*/*do not match, so the subpath entry is written; a configured exact@acme/kit/featurekeeps its target and the count reports only the entries added. The first and the third fail on5f11ff284. With TypeScript 5.9.3, the same workspace unbuilt: after the rewrite at5f11ff284,--traceResolutionshows@acme/kit/featurematching the added exact key andtscreports TS2305 for a member only the configured file exports; at 3c08380 it matches@acme/kit/*, resolves to the configured file, andtscexits 0.3c08380a3.test_run_typescript_delta_umbrella.py::test_umbrella_member_named_by_its_config_file_gets_the_paths: the umbrella referencespackages/app/tsconfig.build.jsonbeside an unbuilt@x/lib; the config the indexer reads carries@x/lib, the unusedtsconfig.jsonis unchanged, andgit status --ignoredis empty afterwards.test_scip_ts_paths.py::test_a_named_config_is_patched_and_restored_alone: a CRLFtsconfig.build.jsonis patched and restored byte for byte, and thetsconfig.jsonbeside it is not touched.test_scip_ts_paths.py::test_a_named_config_over_a_rewritten_tsconfig_reads_what_the_project_wrote: atsconfig.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 at3c08380a3patchedpackages/app/tsconfig.jsonand the delta had no edges; at85e5b5a58it patchespackages/app/tsconfig.build.jsonand the delta has the calla → bintopackages/lib.tsc -p packages/app/tsconfig.build.json(TypeScript 5.9.3) reports TS2307 for@x/libafter the old rewrite and exits 0 after the new one. The checkout was clean after each run.run_typescript_delta.shinDELTA_OUT --fullmode from the harness of three trees, over a pnpm umbrella withpackages/appandpackages/lib(@x/libexports./dist/index.js, nothing built).appimports@x/liband@local/internal. Edges in the delta; "lost" and "gained" are againstmain(e89cc858f), "previous head" is9e87a5f87, "this head" is5f11ff284. The later change for keys in effect reaches only row F among these, where@x/*already maps@x/libto source and@x/libis no longer added; F was not run again:app's tsconfig extendsmainbaseUrl: "."andpathspaths, nobaseUrl@acme/tsconfiginnode_modules,${configDir}paths[base, strict]@x/*and@local/internalapp's own tsconfig with CRLF line ends@co/tsconfig/base, named throughexportsWhere
mainhas 1 edge, this head adds the cross-package callappfn → libfnand keepsmain's. F'smainedges already include it, and J keepsmain'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--restoreleft the CRLF file modified. A cycle through arrayextends(aextends[b, c],bextends[a, c],cextends[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.16c32dd36, withmainat82dc31216merged 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.pyandtest_scip_to_delta_cli.py, withtest_tunable_constants.pyandtest_public_copy.py: 149 passed.ruff check,ruff format --check, the function-length gate andscripts/gates/mypy_gate.pypass, and mypy onscip_ts_paths.pyreports the same errors as before the change (seven, none new);bash -non the script passes. The full unit suite was not run here; CI runs it.DELTA_OUTmode, counts from the delta JSON. These rows were measured at9e87a5f87, before the helper change above, and not repeated at this head; the helper change reaches only a tsconfig that sets or inheritspaths:maina1faa174, 36 membersmainOn 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.jsonfiles, so up to3c08380a3the rewrite did not reach any config that is compiled, and the per-process peak stays below the whole-root run. At85e5b5a58the rewrite patches those 36 configs. Against the harness at3c08380a3(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 fromtypescript-estreeinto its owndeclare module 'typescript'augmentation intypings/typescript.d.ts. The member's addedpathschange four resolutions, all sibling imports that were TS2307 and now reach source. Some of those sources importtypescript/lib/tsserverlibrary, whose declaration file isimport ts = require("./typescript.js"); export = ts;. With TypeScript 5.9.3, that one import, added as a root file to the unpatched config, leavests.getModifierswith only thelibdeclaration, so the indexer has no augmentation to reference. The checkout was clean after both runs. The file and symbol still missing areshared/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
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.main; no merged migration is edited: no migration.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version: no plugin file changed.npm --prefix frontend run build) and its tests pass, iffrontend/changed: it did not.docs/describe the system as it now is, and this description names any operator steps and wire changes: thecode_scip_ts_pathsrow already says the rewrite applies before indexing an unbuilt checkout.tests/unit/test_public_copy.py).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, andscip_ts_paths.pyis invoked with--configfor exactly the tsconfig files each member uses (includingtsconfig.build.jsonand harness-generatedtsconfig.scip.json).scip_ts_paths.pyis reworked to merge workspacepathswithout clobbering project setup: it walksextends, keeps inherited aliases andbaseUrl, 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.