dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

paths in extended tsconfig not resolved correctly

xania opened this issue · comments

This line can be improved,

  • in case baseUrl is not specified in parent config then we can still have paths defined that need to be mapped
  • baseUrl of the extended config should remain intact / unchanged

if (base.compilerOptions && base.compilerOptions.baseUrl) {

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;
        }