francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
102 stars 24 forks source link

fix: resolve path aliases being extended from base configs #152

Closed KostiantynPopovych closed 2 months ago

KostiantynPopovych commented 2 months ago

Hey there! I'm using this great package in my NX monorepo project, but I'm encountering an issue with resolving relative imports through path aliases. Currently, paths are only taken from the nearest or specified tsconfig file, which disrupts the generation process in my application.

This pull request enhances how paths are fetched. It will now recursively collect paths from extended configurations and update them with the latest paths up to the nearest or specified tsconfig.

francescov1 commented 2 months ago

Great job man, thanks for the PR! Just a small cleanup comment and Ill merge it in

francescov1 commented 2 months ago

Live in v9.3.4 🚀

KostiantynPopovych commented 2 months ago

Hey @francescov1, I just tested the version with this fix in my project, and the problem is still present. I would try to investigate why it is still present, but I'm a bit more loaded now. Sorry for the not-finished fix yet.

francescov1 commented 2 months ago

Ah damn sorry to hear @KostiantynPopovych, let me know if there's anything I can do to help. If youre able to put together a boiled down simple repro I can take a look

KostiantynPopovych commented 2 months ago

Hey @francescov1, I prepared a real-world example of the lib usage with an NX monorepo where I use aliases to import stuff from shared packages. To reproduce the issue, you can install the modules, navigate to the apps/mongoose-tsgen app, and run the mongoose-tsgen script. This is failing at the moment, and there is another script mongoose-tsgen-fix that fixes the issue via using another extended ts-config, specifically configured to have the needed alias. Thanks in advance!

francescov1 commented 1 month ago

Awesome thanks @KostiantynPopovych! im about to go away on vacation for a couple weeks, Ill take a look if I have some downtime but no promises. Otherwise will look at fixing when im back. Sorry for the delay!

francescov1 commented 1 month ago

Something I noticed: the top level tsconfig file is using a baseUrl field. There's actually a PR that adds baseUrl to the tsconfig path parsing too https://github.com/francescov1/mongoose-tsgen/pull/155/files

I suspect that should fix it, but we may need to add that to your parseTSConfig function

francescov1 commented 1 month ago

Merged in the PR I previously mentioned, and going to merge this one once I have better internet and can run the tests - posting from crappy airplane wifi lol.

Once thats all in that should fix this problem, but ill try running it on your example repo. Thanks again for creating that!

francescov1 commented 1 month ago

Fix is live in v9.4.1 🚀

KostiantynPopovych commented 1 month ago

Hey @francescov1, that awesome, thank you a lot!