Problem
[It only infects typescript library creators]
if the code base contains absolute paths (by configuring tsconfig.json
and webpack), then the typescript compiler will generate all the d.ts files with the same absolute paths that are useless because my lib consumers can't do a thing with them.
Workarounds
Every library that I saw are doing one of the following:
- creating their own single-file.d.ts file manually
- using relative path in their code base so the output d.ts files also contain relative paths.
Clearly, both alternatives suck.
Other solution that I thought about
- creating a single d.ts file (there will be no imports).
I couldn't find a working library for that.
- not sure if it's possible: before running ts-loader, we need to run a magic babel-plugin to transform every absolute path to a relative by looking in the webpack-resolve-module section in webpack.config file.
My current status
I created a library that generates broken d.ts files with absolute paths:
https://github.com/stavalfi/lerna-yarn-workspaces-example/tree/master/packages/x-core
index.ts:
import { z, x } from 'shalom' // problem
export default function awesomeFn(y: number): x {
return z(1)
}
export { z, x } from './shalom' . // not a problem
generated index.d.ts:
import { x } from './shalom'; /// GOOD - becuase I used relative
export default function awesomeFn(y: number): x;
export { z, x } from 'shalom'; /// BAD - because I used absolute
//# sourceMappingURL=index.d.ts.map .
Question
Is there any sort of solution/workaround that is not stop using an absolute path or creating my own single.d.ts file manually?