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

fix: support TS resolution in JS files when allowJs is set #535

Merged
merged 4 commits into from
Apr 25, 2024

Conversation

nwalters512
Copy link
Contributor

Closes #135.

I tested this locally and it works as expected in my project. I also added a new test which fails on develop but passes after these changes.

Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tsx ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2024 10:01am

Copy link
Contributor Author

@nwalters512 nwalters512 Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't fully understand how the tests are structured/split up; I'd be more than happy to adjust things here in response to feedback.

Copy link
Owner

@privatenumber privatenumber Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, the idea behind the smoke tests here is to test with minimal number of child processes; the other tests are slow primarily because it spawns so many children.

@@ -218,6 +218,14 @@ const files = {

'file.txt': 'hello',

'import-typescript-parent.js': sourcemap.tag`
import './import-typescript-child.js';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this inside import-from-js.js?

Copy link
Contributor Author

@nwalters512 nwalters512 Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can, though that will require adding --tsconfig tsconfig/tsconfig-allowJs.json to that test's arguments, at which point I think there wouldn't be any tests that cover the case where TS resolution rules aren't followed. If that's good with you, I'll do the move and delete the allowJs in tsconfig.json test.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, let's keep it this way then. Thanks for catching it!

`,

'import-typescript-child.ts': sourcemap.tag`
console.log('imported');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this allowJs or something more unique that can be matched from within the 'from .js' test

@privatenumber
Copy link
Owner

Really appreciate this PR, thanks @nwalters512 !

BTW I had a vision to leverage get-tsconfig like this https://github.com/esbuild-kit/cjs-loader/pull/34/files but I think there are other problems with that approach and this is a good solution for now. 🙌

@nwalters512
Copy link
Contributor Author

And thank you for maintaining this excellent package! It's been a breath of fresh air after ts-node. Looking forward to seeing this land 🎉

@privatenumber privatenumber changed the title Support TS resolution in JS files when allowJs is set fix: support TS resolution in JS files when allowJs is set Apr 25, 2024
@privatenumber privatenumber merged commit 081853e into privatenumber:develop Apr 25, 2024
4 checks passed
@privatenumber
Copy link
Owner

🎉 This issue has been resolved in v4.7.3

If you appreciate this project, please consider supporting this project by sponsoring ❤️ 🙏

@nwalters512 nwalters512 deleted the support-allowjs branch April 25, 2024 13:08
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript resolution not working from JS files (even with allowJs)
2 participants