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

Can't specify just `cwd` #271

Open anthony-hayes opened 2 months ago

anthony-hayes commented 2 months ago

I want to specify just cwd and have the tool infer the baseUrl read the paths from the tsconfig in my specified cwd.

However, register does not permit that

export interface ExplicitParams {
  baseUrl: string;
  paths: { [key: string]: Array<string> };
  mainFields?: (string | string[])[];
  addMatchAll?: boolean;
  cwd?: string;
}

It'd be nice if I could just specify cwd

For context, I'm using ts-node and tsconfig-paths in a script like the following

const { register } = require('ts-node');
const tsConfigPaths = require('tsconfig-paths');

const cwd = '/path/to/tsconfig/';

// this works
register({ cwd });

// this does not work, need to specify baseUrl and paths
tsConfigPaths.register( { cwd } );