Skip to content

fix(import-map): resolve TS re-exports and tsconfig extends path aliases - #708

Draft
RGurevich wants to merge 1 commit into
Egonex-AI:mainfrom
RGurevich:fix/ts-reexports-and-tsconfig-extends
Draft

RGurevich wants to merge 1 commit into
Egonex-AI:mainfrom
RGurevich:fix/ts-reexports-and-tsconfig-extends

Conversation

@RGurevich

Copy link
Copy Markdown

Summary

extract-import-map.mjs missed most TypeScript imports in Nx/pnpm monorepos. There were two independent causes:

  1. Re-exports were never recorded as imports. TypeScriptExtractor.processExportStatement ignored its imports argument. As a result, export * from './a', export * as ns from './a' and export { x } from './a' produced no dependency, so barrel index.ts files looked edgeless. The fix: when an export_statement has a source field, it is now recorded as an import, with the re-exported names as specifiers. The exports themselves are unchanged.

  2. tsconfig extends was not followed. Only the nearest tsconfig.json's own compilerOptions.paths were read. Nx keeps every alias in a root tsconfig.base.json that package tsconfigs only extends, so @scope/lib/... imports stayed unresolved. The fix: loadTsConfigs now resolves relative/absolute extends chains, including TS 5 array extends, following TypeScript's rules:

    • paths and baseUrl from later configs replace earlier ones;
    • baseUrl is anchored at the config that declares it;
    • without baseUrl, paths are anchored at the config that declares them.

    Alias targets are now resolved through absolute paths. This also covers scanning a single package whose aliases come from a base config above the project root and point back into it. Missing extends targets and cycles produce a Warning: and contribute nothing. Package-specifier extends (@tsconfig/...) are skipped.

Linked issue(s)

None.

How I tested this

  • pnpm lint

  • pnpm --filter @understand-anything/core test: 1015 passed

  • pnpm vitest run tests/skill: all passed, including test_extract_import_map with 73 tests

  • Manual smoke test on a real Nx monorepo (≈14k tracked files, 131 paths aliases in tsconfig.base.json, package tsconfigs that only extends it). I compared against an import graph built with the TypeScript compiler API (ts.preProcessFile + ts.resolveModuleName):

    before (2.9.7) after
    resolved import edges 14,059 31,072
    agreement with TS compiler resolution 45.0% 99.5%

The new tests cover:

  • all re-export forms in the extractor;
  • barrel resolution in the import map;
  • an inherited Nx-style base config;
  • child paths overriding the base together with an inherited baseUrl;
  • a base config outside the scanned package root;
  • a missing extends target;
  • an extends cycle.

The re-export and inherited-config tests fail without the fix.

Note: the import lists of barrel files now include their re-exported modules, so their structural fingerprints change once after upgrading.

Versioning

  • Version bumped in all five manifests, OR
  • N/A — left for the maintainer to bump on merge

Record re-export statements (export * / export * as ns / export { x } from) as imports in the TypeScript extractor, and follow relative tsconfig extends chains so path aliases inherited from a base config (Nx tsconfig.base.json) resolve, anchored per TypeScript's baseUrl/paths rules.
@darcyk764

darcyk764 commented Oct 11, 2026 via email

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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