bennycode/ts2esm

feature request: TS paths support

temeke opened this issue ยท 5 comments

Thanks for the tool ๐Ÿ‘๐Ÿผ I noticed that this library does not support typescript path variables. Support for those would be a nice feature. Thank you!

Hi @temeke, can you provide an example of a path alias configuration in your tsconfig.json file and how you use such a path in your source code?

{ "compilerOptions": { ... "paths": { "@database/*": ["apps/database/*"], } }, "ts-node": { "require": ["tsconfig-paths/register"] } }
And how I'm using the path
import { item } from '@database/src/item'

I think the ts2esm should convert the path to
import { item } from '@database/src/item.js'

Now I added the .js manually to all imports that used the @database.

Thanks for the info @temeke! ts-morph supports project.getCompilerOptions().paths which should return the paths resolution and therefor make it very easy to implement support for it in ts2esm.

I created an example repo (with CommonJS module syntax & TS Path aliases): https://github.com/bennycode/ts-demo-npm-cjs/

I also started working on implementing the paths support: #53

@temeke I just released ts2esm@2.0.0 with support for path aliases. Can you test it in your project? Best is to make a backup before running ts2esm in case something goes wrong!