dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.8k stars 100 forks source link

paths in extended tsconfig not resolved correctly #226

Closed xania closed 1 year ago

xania commented 1 year ago

This line can be improved,

https://github.com/dividab/tsconfig-paths/blob/1b71683fa7d48a2e7b9cbae4825410594a1c7c81/src/tsconfig-loader.ts#L162

I have here a draft but working implementation for fixing these issues, will create a PR for that soon.

        if (base.compilerOptions) {
            const basePath = path.resolve(
                path.join(path.dirname(configFilePath), config.compilerOptions?.baseUrl ?? '.')
            );
            var extendsDir = path.dirname(extendedConfigPath);
            if (base.compilerOptions.paths) {
                for(const key in base.compilerOptions.paths) {
                    const paths = base.compilerOptions.paths[key];
                    for(let i=0 ; i<paths.length ; i++) {
                        const fullPath = path.resolve(
                            path.join(extendsDir, base.compilerOptions.baseUrl || '.', paths[i])
                        );
                        paths[i] = path.relative(
                            basePath,
                            fullPath
                        );
                    }
                }
            }
            delete base.compilerOptions.baseUrl;
        }