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

feat: support TypeScript code in eval flag #190

Closed
wants to merge 2 commits into from
Closed

feat: support TypeScript code in eval flag #190

wants to merge 2 commits into from

Conversation

rayrw
Copy link
Contributor

@rayrw rayrw commented Feb 28, 2023

fixes #162

This PR is my attempt to add support of TypeScript code in the eval flag.
Not sure if it's the correct approach. I've got inspired by the preEval function of repl.ts, so I tried doing something similar by using transformSync from @esbuild-kit/core-utils. After transforming it, I tried swapping the original TS code's argv with the transformed code.

There are still several things I'm not sure (e.g. the filePath parameter of transformSync).
Please guide me if I've done it wrong.

@privatenumber
Copy link
Owner

Thanks, I haven't played with it yet, but the code looks good.

Can you add a test with the --input-type flag to make sure module works expectedly?

Off the top of my head, maybe something like console.log(import.meta.url) or making sure this fails console.log(__dirname).

@rayrw
Copy link
Contributor Author

rayrw commented Feb 28, 2023

@privatenumber Thanks for the quick replies!
Yeah, testing the --input-type flag sounds very useful.
I've compared the output between normal node cli and tsx, and added the test cases.
Hopefully it's the expected behavior (eval import.meta.url returns undefined under --input-type=module flag).

@rayrw rayrw closed this Jun 23, 2023
@rayrw rayrw deleted the add-eval-flag-to-exec-ts-code branch June 23, 2023 15:43
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--eval support
2 participants