-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Path mappings to files resolve incorrectly #253
Comments
Hi @jneuendorf-i4h, thanks for your issue and presenting it very clearly! Normally, I would import a JSON file using the import { ... } from "@schema/a.json";
// vs
import { ... } from "@schema/a"; I wasn't even aware that you could import a JSON file without using a I will note that if you don't have I can take a deeper look into your suggestion when I have time - or feel free to open a PR. Initial thoughts are that it looks like it could work, though it will need to be tested thoroughly. In the interim, is there a reason why you can't import the file with a |
Hey @benyap, thanks for the quick reply. I actually ended up, importing the JSON files explicitly (so like You mentioned that such a feature would need to be well tested and I agree. So if the requested behavior is a bit exotic (and most users don't need it), it may not be worth increasing the complexity of the project. However, it would be helpful to state this caveat1 in the README so people know what they're up to. 1 meaning that only file paths can be correctly resolved |
This issue is stale because it has been open for 30 days with no activity. |
Thanks @jneuendorf-i4h for the suggestion, will update the README! |
@all-contributors add @jneuendorf-i4h for documentation |
I've put up a pull request to add @jneuendorf-i4h! 🎉 |
Hi,
thanks for your package. It's a shame
tsc
doesn't compile its resolution behavior.Scenario
In my scenario, I generated JSON files from my TypeScript code (JSON schema from types).
In order to avoid import errors, I configured my path mappings so that JSON are preferred over source files:
The files are structured like this:
and an import like this:
import { definitions } from "@schema/a"
.Expected behavior
This setup works fine with TypeScript. Since I think this package aims to mimic TypeScript's resolution mechanism, just at compile time, I think, this setup should also work with your package.
Actual behavior
The JSON file is not resolved. Instead the compiled JS file is resolved.
At first I thought, the reason is that I used
--ext
incorrectly. But after some debugging, I found that the import is resolved to.../src/schema/*.json/a
and then disregarded. This result is produced by https://github.com/benyap/resolve-tspaths/blob/main/src/steps/generateChanges.ts#L143In my understand, this code assumes that all
aliasPaths
are pointing to directories, which is not necessarily true (as described above). I guess replacing"*"
in the path instead of appending to it (in case the alias is not a directory), could solve this issue.Let me know what you think. 😉
The text was updated successfully, but these errors were encountered: