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.
Description
When a child tsconfig extends a parent that defines
rootDirswith relative paths, the paths are normalized relative to the child's directory instead of the parent's directory.Reproduction
Root cause
In
extend_tsconfig(),root_dirsare cloned from the parent as-is (raw relative paths). Thenbuild()normalizes them relative toconfig_dir(the child's directory), not the parent's directory where they were defined.Compare with
pathswhich carriespaths_baseto preserve the correct base directory through the extends chain.rootDirshas no equivalent mechanism.Real-world impact
This affects SvelteKit projects where
tsconfig.jsonextends.svelte-kit/tsconfig.jsonwhich definesrootDirs: ["..", "./types"]for virtual module resolution.