I want to get the directory of the source file, so I want to use __dirname in my .ts file as a value, not a variable.
in other words, I want this code to output the same value whatever the location of the output.
/src/index.ts
console.log(__dirname); // -> /src
when transpiling this file via tsc into a different location, it should log the new location.
but I want to log the same value each time
/dist/index.js
console.log(__dirname); // -> /dist
what I want is that when I open dist/index.js to see cosole.log("/src") instead of console.log(__dirname)
why I do that?
because sometimes you don't want to respect tsconfig.json, and output to a different path.
for instance using ts-node src/index.ts acts as if it outputs the compiled file into the same directory of the spurce file, so __dirname here gives the same path as the source file
another example using jest you need to transpile .ts files on the fly rather than compiling it into the dist folder then running the test.
you then need to refer to a path relatively to a fixe d point, whatever the output file lives.