Skip to content
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

runTsc breaks in Typescript v5.7 when providing extraSupportedExtensions #251

Closed
kitsune7 opened this issue Dec 5, 2024 · 2 comments · Fixed by #252
Closed

runTsc breaks in Typescript v5.7 when providing extraSupportedExtensions #251

kitsune7 opened this issue Dec 5, 2024 · 2 comments · Fixed by #252
Labels
bug Something isn't working

Comments

@kitsune7
Copy link
Contributor

kitsune7 commented Dec 5, 2024

When using the runTsc function from the @volar/typescript npm package, the code will break if the user has Typescript v5.7 or higher and they have a non-empty array provided on the extraSupportedExtensions option (see this issue for an example).

This happens because in Typescript v5.7, they start making use of a shim in order enable Node.js/v8 compile caching. This means that the tscPath provided to runTsc may be a shim that pulls in the main code. It's no longer safe to assume like we do in transformTscContent that the tsc argument includes any of the code we want to update.

I spent quite a while digging through to code to figure out the exact issue. I'm happy to submit a PR to fix the issue, but I thought it might be best to submit an issue first in case we wanted to discuss what the ideal solution would look before I start messing with code.

The easiest way I can see to solve it off the top of my head would be to add a check for the file that gets required at the end of the file at the tscPath if it's missing the content that we expect, but that could be finicky. I'm open to suggestions.

@kitsune7 kitsune7 changed the title runTsc breaks in Typescript v5.7.2 when providing extraSupportedExtensions runTsc breaks in Typescript v5.7 when providing extraSupportedExtensions Dec 5, 2024
dispatchrabbi added a commit to dispatchrabbi/trackbear that referenced this issue Dec 6, 2024
@kitsune7
Copy link
Contributor Author

kitsune7 commented Dec 6, 2024

Since Volar relies on parsing Typescript's source code, it's not immune to updates, but I put up a PR that makes the safest assumptions about the structure of the code that I can think to make. I'm happy to change things if someone has a better idea on how to handle it, but the changes do fix the problem while maintaining backwards compatibility.

@johnsoncodehk johnsoncodehk added the bug Something isn't working label Dec 13, 2024
@silverwind
Copy link

parsing Typescript's source code

This seems insane. Why not contribute the necessary APIs that you need to Typescript and have volar function as a plugin to typescript, enabling users to run the official tsc? Would be much cleaner and not break every new Typescript release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants