Skip to content

rootDirs paths incorrectly normalized when inherited via extends #1075

Description

@webpro

Description

When a child tsconfig extends a parent that defines rootDirs with relative paths, the paths are normalized relative to the child's directory instead of the parent's directory.

Reproduction

project/
├── tsconfig.json          # { "extends": "./.svelte-kit/tsconfig.json" }
├── src/routes/+page.ts    # import type { PageLoad } from './$types'
└── .svelte-kit/
    ├── tsconfig.json       # { "compilerOptions": { "rootDirs": ["..", "./types"] } }
    └── types/src/routes/
        └── $types.d.ts
import { ResolverFactory } from 'oxc-resolver';

// Works: pointing directly at the config that defines rootDirs
const r1 = new ResolverFactory({
  tsconfig: { configFile: 'project/.svelte-kit/tsconfig.json' },
  extensions: ['.ts', '.d.ts'],
});
r1.resolveFileSync('project/src/routes/+page.ts', './$types');
// Resolves to project/.svelte-kit/types/src/routes/$types.d.ts

// Broken: using the child that extends the parent
const r2 = new ResolverFactory({
  tsconfig: { configFile: 'project/tsconfig.json' },
  extensions: ['.ts', '.d.ts'],
});
r2.resolveFileSync('project/src/routes/+page.ts', './$types');
// Cannot find module './$types'

Root cause

In extend_tsconfig(), root_dirs are cloned from the parent as-is (raw relative paths). Then build() normalizes them relative to config_dir (the child's directory), not the parent's directory where they were defined.

Compare with paths which carries paths_base to preserve the correct base directory through the extends chain. rootDirs has no equivalent mechanism.

Real-world impact

This affects SvelteKit projects where tsconfig.json extends .svelte-kit/tsconfig.json which defines rootDirs: ["..", "./types"] for virtual module resolution.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions